/**************************************************************************/
/*                                                                        */
/*                                 Sources                                */
/*                                from  the                               */
/*                           XSC SOFTWARE PACKAGE                         */
/*                                                                        */
/*                Copyright (c) 1997 University of Karlsruhe              */
/*                     Institute for Appl. Mathematics                    */
/*                                                                        */
/* This program is free software for non-commercial use. For details, see */
/* the file LICENSE.XSC, distributed with this software package.          */
/*                                                                        */
/* This program is distributed WITHOUT ANY WARRANTY. For details, see the */
/* file LICENSE.XSC, distributed with this software package.              */
/*                                                                        */
/**************************************************************************/

/* RCS $Id: p_init.c,v 1.5 1997/09/25 17:41:19 ae59 Exp $ */
/*
$Log: p_init.c,v $
 * Revision 1.5  1997/09/25  17:41:19  ae59
 * Copyright-message
 *
 * Revision 1.4  1996/03/22  15:15:43  ae59
 * Hardware support for RS6000 with precise and imprecise (default) traps
 *
 * Revision 1.3  1994/11/15  14:29:12  ae59
 * add DEC_arith
 *
 * Revision 1.2  1994/11/02  16:42:28  ae59
 * introduced REVISION_text, o_revs.h
 *
 * Revision 1.1  1994/01/27  13:23:43  ae59
 * Put under RCS control
 *
 */
/****************************************************************/
/*                                                              */
/*      Filename        : p_init.c                              */
/*                                                              */
/*      Entry           : void f_init(argc,argv)                */
/*                        int argc;                             */
/*                        char **argv;                          */
/*                                                              */
/*      Arguments       : argc   - number of arguments          */
/*                        argv   - list of argument strings     */
/*                                                              */
/*      Description     : Initialization of command line scanner*/
/*                                                              */
/*      Date            : 1993-12-01                            */
/*      1993-12-01 : VERSION_ARI_text                        =b=*/
/*      1993-03-31 : add setbuf, _cntrl87 4 OS2_ICc          =b=*/
/*      1993-02-16 : comments removed,add VERSION_SYS_TEXt   =b=*/
/*      1992-10-21 : changed filename from f_init to p_init=b=  */
/*      1992-08-19 : show product message for demo version =b=  */
/*      1992-06-23 : moved r_fini in front of pascal init       */
/*      1992-06-05 : call r_fini for trap handler init          */
/*      1992-05-14 : use e_[rs]*e for mod. of trap enables      */
/*      1992-01-15 : use predefined text array o_text           */
/*      1991-12-03 : f_orgc,f_orgv hold original main arguments */
/*      1991-11-13 : set rounding mode for tenbyte arithemtic   */
/*      1991-09-13 : dummy routines called to force linkage     */
/*      1991-09-06 : reduce maximum line length                 */
/*      1991-08-02 : call o_user() and initialize variables     */
/*      1991-05-02 : use status flags                           */
/*      1991-04-23 : initialization with std...                 */
/*      1991-02-22 : no initialization of f_errr,f_pmti,f_pmto  */
/*      1991-01-22 : VAX_VMS_C considered                       */
/*      1991-01-15 : b_popt() used                              */
/*      1991-01-07 : '-info:' lists all keys                    */
/*      1990-12-03 : _ENABLE flags considered                   */
/****************************************************************/

#ifndef ALL_IN_ONE
#ifdef AIX
#include "/u/p88c/runtime/o_defs.h"
#include "/u/p88c/runtime/o_revs.h"
#else
#include "o_defs.h"
#include "o_revs.h"
#endif
#define local
extern int f_argc;
extern int f_orgc;
extern char **f_orgv;
extern char **f_argv;
extern int f_apos;
extern a_bool f_pppd;
extern a_bool f_pppl;
extern f_text f_pmti;
extern f_text f_pmto;
extern f_text f_errr;
extern FILE *o_pmti;
extern FILE *o_pmto;
extern FILE *o_errr;
extern char *o_text[];
extern char *e_head;
extern int b_rflg;
#endif

#ifdef LINT_ARGS
local void p_init(int argc,char **argv)
#else
local void p_init(argc,argv)

int argc;
char **argv;
#endif

        {
        int i,k;

#if IBM_OS2_ICC_C
        /* special settings for os2 in order t use double for a_real 
	    * and direct output behaviour as used to
	    * position of code is IMPORTANT here !!
	    */
	   setbuf(stdout,(char*) 0);                /* unbuffered output */
	   _control87(EM_UNDERFLOW, EM_UNDERFLOW);  /* direct double trap*/
#endif

        /* user initialization of global variables */
        o_user();

        /* initialization of variables with values from o_user() */
        e_head = o_text[0];
        f_pmti.fp = o_pmti;
        f_pmto.fp = o_pmto;
        f_errr.fp = o_errr;

        f_pmti.win.ch[0] = ' ';

        /* force linkage of module containing global variables only */
#if VAX_VMS_C
        b_cmcp();
        b_glbl();
#ifndef DEC_ARITH
        t_glbl();
        t_cnst();
        t_ecst();
#endif
#endif


        /* initialisation of FP HW trap handler (Sun SPARC) */
        r_fini();

        /* initialization of PASCAL environment         */
        e_sofe();      /* enable overflow trap         */
        e_sioe();      /* enable invalid operation trap*/
        e_sdze();      /* enable divide-by-zero trap   */
        e_riee();      /* disable inexact reult trap   */
        e_rufe();      /* disable underflow trap       */
#ifndef DEC_ARITH
        t_srnd(b_rflg);      /* set rounding mode for ten-byte arithmetic */
#endif

#if IBM_RS6000_C
#ifndef RS6000_SYNC_TRAP	/* synchronous trapping mode not available */
	e_rofe();	/* disable overflow trap         */
	e_rioe();	/* disable invalid operation trap*/
	e_rdze();	/* disable divide-by-zero trap   */
#endif /* RS6000_SYNC_TRAP */
#endif /* IBM_RS6000_C */

        /* initializations for command line scanning    */
        f_orgc = f_argc = argc;
        f_orgv = argv;
        f_argv = (char **)malloc((argc+1)*sizeof(*argv));
        memcpy(f_argv,argv,(argc+1)*sizeof(*argv));
        f_apos = 1;

        /* indicates that program parameter list is handled */
        f_pppl = TRUE;

#ifdef DEMO_VERSION
        /* display version number */
        fprintf(stderr,"%s",PRODUCT_TEXT);
        fprintf(stderr,"%s %s %s %s %s\n",VERSION_TEXT, REVISION_TEXT,
			 VERSION_SYS_TEXT, VERSION_EXT_TEXT, VERSION_ARI_TEXT );
        fprintf(stderr,"%s\n",COPYRIGHT_TEXT);
#endif
        /* scan program parameter list for special options  */
        for (i=1;i<f_argc;)
           {
           switch (b_popt(f_pmto.fp,f_argv[i]))
              {
              case 2: f_pppd = TRUE;
              case 1: for (k=i+1;k<f_argc;k++)
                         f_argv[k-1] = f_argv[k];
                      f_argc--;
                      break;
              case 0: i++;
                      break;
              default: ;
              }
           }

        return;
        }
