source: SH_SHM/trunk/source/seismhan.c @ 30

Revision 30, 7.2 KB checked in by marcus, 14 years ago (diff)

r15 | svn | 2008-01-25 11:48:08 +0100 (Fr, 25 Jan 2008) | 1 line

command line parameter managment via cpar, deleted cmdargs.c

Line 
1
2/* File SEISMHAN.C
3 *      ==========
4 *
5 * $Revision: 15 $, $Date: 2008-01-25 11:48:08 +0100 (Fr, 25 Jan 2008) $
6 *
7 * main module of seismhandler program, command line version
8 *
9 * K. Stammler, 6-MAR-1990
10 */
11
12
13/*
14 *
15 *  SeismicHandler, seismic analysis software
16 *  Copyright (C) 1992,  Klaus Stammler, Federal Institute for Geosciences
17 *                                       and Natural Resources (BGR), Germany
18 *
19 *  This program is free software; you can redistribute it and/or modify
20 *  it under the terms of the GNU General Public License as published by
21 *  the Free Software Foundation; either version 2 of the License, or
22 *  (at your option) any later version.
23 *
24 *  This program is distributed in the hope that it will be useful,
25 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
26 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27 *  GNU General Public License for more details.
28 *
29 *  You should have received a copy of the GNU General Public License
30 *  along with this program; if not, write to the Free Software
31 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
32 *
33 */
34
35#include <stdio.h>
36#include <string.h>
37#include "basecnst.h"
38#ifdef BC_STDLIB_EX
39#include <stdlib.h>
40#endif /* BC_STDLIB_EX */
41#include BC_SYSBASE
42#include "seusrdef.h"
43#include "shconst.h"
44#include "sherrors.h"
45#include "uierrors.h"
46#include "cpusrdef.h"
47#include "uiusrdef.h"
48#include "trusrdef.h"
49#include BC_GCUSRDEF
50#include "erusrdef.h"
51#include "fctxmn0.h"
52#include "fctxdm.h"
53#include "seed_io/seedcfg.h"
54#include "seed_io/seed_lib.h"
55#include "globalparams.h"
56#include "sqliface.h"
57#ifdef SH_SOCKET
58#include "port_io.h"
59#endif
60
61/* VAX specific routines (usually FORTRAN subroutines) */
62#ifdef BC_GRFVAX
63#include "[-.local]fctxmngrf.h"
64#endif /* BC_GRFVAX */
65
66/* machine dependent path strings */
67#include BC_SHDIRS
68
69/* global variables */
70
71int     tc;                 /* local text channels */
72int     tc_shv;             /* global text channels */
73int     gc;                 /* local graphic channels */
74int     gc_shv;             /* global graphic channels */
75int     cc;                 /* local console channels */
76int     cc_shv;             /* global console channels */
77SHFLAGS shflags_shv;        /* local processing flags */
78SHFLAGS shglbflags_shv;     /* global processing flags */
79STATUS  shv_last_status;    /* status of last command */
80int     shv_maininput=0;    /* main input level for CP's */
81char    id_shv[11]={SHC_FILE_PREFIX}; /* session ID */
82
83char    protfile_shv[SHC_FILELTH+1]; /* protocol file */
84char    shd_scratch[SHC_FILELTH+1] =  {DD_SCRATCH};
85char    shd_inputs[SHC_FILELTH+1]  =  {DD_INPUTS};
86
87
88/* #ifdef BC_MAINARGS */
89int main( int argc, char *argv[] )
90/*#else*/
91/*int main( void )*/
92/*#endif */ /*BC_MAINARGS */
93
94{
95
96        /* variables */
97        STATUS   status;                /* return status */
98        BOOLEAN  quit;                  /* quit program */
99        char     cmdlin[cBcLongStrLth+1];  /* command read */
100        char     vfstr[BC_LINELTH+1];   /* verify string */
101        char     execstr[BC_LINELTH+1]; /* execute command (EXEC) */
102        BOOLEAN  exec_unshift;          /* perform EXEC ui_unshift */
103        int      exec_tcsave;           /* copy of tc for EXEC command */
104        char     prompt[BC_LINELTH+1];  /* prompt string */
105        PARAM    cmd;                   /* parsed command */
106        BOOLEAN  redraw;                /* redraw flag */
107        int      rdlevel = 0;           /* redraw level */
108        BOOLEAN  bench;                 /* bench mark */
109        BOOLEAN  iscmdproc;             /* command is not a built-in command */
110#ifdef SH_SOCKET
111        int      respsock;              /* response socket */
112#endif
113
114        /* executable code */
115
116        printf( "\n" );
117        printf( "SeismicHandler version %s, Copyright (C) 2006\n", SHC_VERSION );
118        printf( "Klaus Stammler, Federal Institute for Geosciences and Natural Resources (BGR)\n" );
119        printf( "SeismicHandler comes with ABSOLUTELY NO WARRANTY.\n" );
120        printf( "This is free software, and you are welcome to redistribute it\n" );
121        printf( "under certain conditions; type `HELP GPL' for details.\n" );
122        printf( "\n" );
123
124        status = BC_NOERROR;
125
126        sy_initprocess();
127        strcpy( prompt, "|sh> " );
128        GpReadParfile();
129
130        se_initialize( argc, argv, &status );
131        if  (Severe(&status))  {
132                se_dsplymsg( 0, status );
133                exit( status );
134        } /*endif*/
135
136        /* enter main loop */
137        *execstr = '\0';
138        exec_unshift = FALSE;
139        quit = FALSE;
140        do  {
141
142                /* read and translate command */
143                status = SHE_NOERROR;
144                err_clearcontext();
145                if  (*execstr == '\0')  {  /* get command line from input stream */
146                        gc_write( tc, prompt );
147                        ui_setconsole( cc );
148                        ui_read( tc, cmdlin, cBcLongStrLth, &status );
149                } else {   /* get EXEC command line */
150                        strcpy( cmdlin, execstr );
151                        *execstr = '\0';
152                        ui_shift( shv_maininput );  /* all prompts to the user */
153                        exec_tcsave = tc;
154                        tc = cc;
155                        exec_unshift = TRUE;
156                } /*endif*/
157                gc_update();
158                /* sy_debuginfo( cmdlin ); */
159                if  (shflags_shv & SHF_STEP && ui_stepflag() != '\0')
160                        se_do_step( ui_stepflag(), &status );
161                if  (status == BC_NOERROR)  cp_parse( cmdlin, &cmd, &status );
162                if  (status == BC_NOERROR)  tr_partrans( &cmd, &status );
163
164                /* if VERIFY flag set, print verification of command */
165                if  (shflags_shv & SHF_VERIFY)  {
166                        cp_verify( &cmd, BC_LINELTH, vfstr, &status );
167                        if  (status == SHE_NOERROR)  {
168                                gc_write( cc, vfstr );
169                                gc_wrtch( cc, '\n' );
170                        } /*endif*/
171                } /*endif*/
172
173                /* if benchmark, store current time */
174                bench = cp_qexist( &cmd, "BENCH" );
175                if  (bench)  sy_difftime();
176
177                /* execute command */
178                redraw = FALSE;
179                if  (status == SHE_NOERROR  && cmd.p[0][strlen(cmd.p[0])-1] != ':')
180                        se_execute_command( &cmd, cmdlin, execstr, &quit, &redraw,
181                                &iscmdproc, &rdlevel, prompt, &status );
182                if  (exec_unshift)  {
183                        ui_unshift();
184                        tc = exec_tcsave;
185                        exec_unshift = FALSE;
186                }/*endif*/
187                if  (cp_uncheckedqual(&cmd) != NULL && !Severe(&status) && !iscmdproc)
188                        se_check_qual( cc, &cmd );
189
190                /* if benchmark, print time */
191                if  (bench)  {
192                        sprintf( vfstr, "   time consumed: %f sec\n", sy_difftime() );
193                        gc_write( cc, vfstr );
194                } /*endif*/
195
196                /* redraw display if necessary and if no error occurred */
197                if  (status == SHE_NOERROR)  dm_setup( &status );
198                if  ((status == SHE_NOERROR) && redraw && (rdlevel == 0))
199                        dm_redraw( &status );
200
201                /* if an error occurred, display error message */
202                if  (status != 0)  {
203                        if  (!(shflags_shv & SHF_NOERRMSG))
204                                se_dsplymsg( cc, status );
205                        if  (ui_level() > 0)
206                                if  ((shflags_shv & SHF_CMDERRSTOP) || (shflags_shv & SHF_SHERRSTOP))  {
207                                        if  (!quit)  quit = (shflags_shv & SHF_SHERRSTOP);
208                                        se_cmdabort( &cmd, cmdlin, status );
209                                } else if  (status == UIE_READFILE)  {
210                                        status = SHE_NOERROR;
211                                        mn0_cmdreturn( &status );
212                                } /*endif*/
213                        if  (!quit)  quit = (shflags_shv & SHF_SHERRSTOP);
214                } /*endif*/
215                shv_last_status = status;
216
217#ifdef SH_SOCKET
218                respsock = ui_lastsocket();
219                if  (respsock > 0)  {
220                        char  msg[cBcShortStrLth+1];  /* message to client */
221                        sprintf( msg, "%d SH_status\n", status );
222                        /*printf( "--> writing response %s to client\n", msg );*/
223                        pio_write_to_client( respsock, msg );
224                        pio_write_to_client( respsock, cPio_TERM );
225                } /*endif*/
226#endif
227
228        } while (!quit);
229
230        se_terminate();
231        SqlDeleteScratchFile();
232
233#       ifndef BC_VAX
234        return 0;
235#       endif /* BC_VAX */
236
237} /* end of main */
Note: See TracBrowser for help on using the repository browser.