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

Revision 341, 7.0 KB checked in by marcus, 12 years ago (diff)

r180 | walther | 2011-03-09 16:27:03 +0100 (Mi, 09 Mär 2011) | 3 lines

Merging most of the changes from marcus' branch. For full details please see
http://www.seismic-handler.org/portal/log/SH_SHM/branches/marcus?revs=101-106,123-171

Line 
1
2/* File SEISMHAN.C
3 *      ==========
4 *
5 * $Revision: 180 $, $Date: 2011-03-09 16:27:03 +0100 (Mi, 09 MÀr 2011) $
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/* machine dependent path strings */
62#include BC_SHDIRS
63
64/* global variables */
65
66int     tc;                 /* local text channels */
67int     tc_shv;             /* global text channels */
68int     gc;                 /* local graphic channels */
69int     gc_shv;             /* global graphic channels */
70int     cc;                 /* local console channels */
71int     cc_shv;             /* global console channels */
72SHFLAGS shflags_shv;        /* local processing flags */
73SHFLAGS shglbflags_shv;     /* global processing flags */
74STATUS  shv_last_status;    /* status of last command */
75int     shv_maininput=0;    /* main input level for CP's */
76char    id_shv[11]={SHC_FILE_PREFIX}; /* session ID */
77
78char    protfile_shv[SHC_FILELTH+1]; /* protocol file */
79char    shd_scratch[SHC_FILELTH+1] =  {DD_SCRATCH};
80char    shd_inputs[SHC_FILELTH+1]  =  {DD_INPUTS};
81
82
83/* #ifdef BC_MAINARGS */
84int main( int argc, char *argv[] )
85/*#else*/
86/*int main( void )*/
87/*#endif */ /*BC_MAINARGS */
88
89{
90
91        /* variables */
92        STATUS   status;                /* return status */
93        BOOLEAN  quit;                  /* quit program */
94        char     cmdlin[cBcLongStrLth+1];  /* command read */
95        char     vfstr[BC_LINELTH+1];   /* verify string */
96        char     execstr[BC_LINELTH+1]; /* execute command (EXEC) */
97        BOOLEAN  exec_unshift;          /* perform EXEC ui_unshift */
98        int      exec_tcsave;           /* copy of tc for EXEC command */
99        char     prompt[BC_LINELTH+1];  /* prompt string */
100        PARAM    cmd;                   /* parsed command */
101        BOOLEAN  redraw;                /* redraw flag */
102        int      rdlevel = 0;           /* redraw level */
103        BOOLEAN  bench;                 /* bench mark */
104        BOOLEAN  iscmdproc;             /* command is not a built-in command */
105#ifdef SH_SOCKET
106        int      respsock;              /* response socket */
107#endif
108
109        /* executable code */
110
111        printf( "\n" );
112        printf( "SeismicHandler version %s, Copyright (C) 2011\n", SHC_VERSION );
113        printf( "Klaus Stammler, Federal Institute for Geosciences and Natural Resources (BGR)\n" );
114        printf( "SeismicHandler comes with ABSOLUTELY NO WARRANTY.\n" );
115        printf( "This is free software, and you are welcome to redistribute it\n" );
116        printf( "under certain conditions; type `HELP GPL' for details.\n" );
117        printf( "\n" );
118
119        status = BC_NOERROR;
120
121        sy_initprocess();
122        strcpy( prompt, "|sh> " );
123        GpReadParfile();
124
125        se_initialize( argc, argv, &status );
126        if  (Severe(&status))  {
127                se_dsplymsg( 0, status );
128                exit( status );
129        } /*endif*/
130
131        /* enter main loop */
132        *execstr = '\0';
133        exec_unshift = FALSE;
134        quit = FALSE;
135        do  {
136
137                /* read and translate command */
138                status = SHE_NOERROR;
139                err_clearcontext();
140                if  (*execstr == '\0')  {  /* get command line from input stream */
141                        gc_write( tc, prompt );
142                        ui_setconsole( cc );
143                        ui_read( tc, cmdlin, cBcLongStrLth, &status );
144                } else {   /* get EXEC command line */
145                        strcpy( cmdlin, execstr );
146                        *execstr = '\0';
147                        ui_shift( shv_maininput );  /* all prompts to the user */
148                        exec_tcsave = tc;
149                        tc = cc;
150                        exec_unshift = TRUE;
151                } /*endif*/
152                gc_update();
153                /* sy_debuginfo( cmdlin ); */
154                if  (shflags_shv & SHF_STEP && ui_stepflag() != '\0')
155                        se_do_step( ui_stepflag(), &status );
156                if  (status == BC_NOERROR)  cp_parse( cmdlin, &cmd, &status );
157                if  (status == BC_NOERROR)  tr_partrans( &cmd, &status );
158
159                /* if VERIFY flag set, print verification of command */
160                if  (shflags_shv & SHF_VERIFY)  {
161                        cp_verify( &cmd, BC_LINELTH, vfstr, &status );
162                        if  (status == SHE_NOERROR)  {
163                                gc_write( cc, vfstr );
164                                gc_wrtch( cc, '\n' );
165                        } /*endif*/
166                } /*endif*/
167
168                /* if benchmark, store current time */
169                bench = cp_qexist( &cmd, "BENCH" );
170                if  (bench)  sy_difftime();
171
172                /* execute command */
173                redraw = FALSE;
174                if  (status == SHE_NOERROR  && cmd.p[0][strlen(cmd.p[0])-1] != ':')
175                        se_execute_command( &cmd, cmdlin, execstr, &quit, &redraw,
176                                &iscmdproc, &rdlevel, prompt, &status );
177                if  (exec_unshift)  {
178                        ui_unshift();
179                        tc = exec_tcsave;
180                        exec_unshift = FALSE;
181                }/*endif*/
182                if  (cp_uncheckedqual(&cmd) != NULL && !Severe(&status) && !iscmdproc)
183                        se_check_qual( cc, &cmd );
184
185                /* if benchmark, print time */
186                if  (bench)  {
187                        sprintf( vfstr, "   time consumed: %f sec\n", sy_difftime() );
188                        gc_write( cc, vfstr );
189                } /*endif*/
190
191                /* redraw display if necessary and if no error occurred */
192                if  (status == SHE_NOERROR)  dm_setup( &status );
193                if  ((status == SHE_NOERROR) && redraw && (rdlevel == 0))
194                        dm_redraw( &status );
195
196                /* if an error occurred, display error message */
197                if  (status != 0)  {
198                        if  (!(shflags_shv & SHF_NOERRMSG))
199                                se_dsplymsg( cc, status );
200                        if  (ui_level() > 0)
201                                if  ((shflags_shv & SHF_CMDERRSTOP) || (shflags_shv & SHF_SHERRSTOP))  {
202                                        if  (!quit)  quit = (shflags_shv & SHF_SHERRSTOP);
203                                        se_cmdabort( &cmd, cmdlin, status );
204                                } else if  (status == UIE_READFILE)  {
205                                        status = SHE_NOERROR;
206                                        mn0_cmdreturn( &status );
207                                } /*endif*/
208                        if  (!quit)  quit = (shflags_shv & SHF_SHERRSTOP);
209                } /*endif*/
210                shv_last_status = status;
211
212#ifdef SH_SOCKET
213                respsock = ui_lastsocket();
214                if  (respsock > 0)  {
215                        char  msg[cBcShortStrLth+1];  /* message to client */
216                        sprintf( msg, "%d SH_status\n", status );
217                        /*printf( "--> writing response %s to client\n", msg );*/
218                        pio_write_to_client( respsock, msg );
219                        pio_write_to_client( respsock, cPio_TERM );
220                } /*endif*/
221#endif
222
223        } while (!quit);
224
225        se_terminate();
226        SqlDeleteScratchFile();
227
228
229} /* end of main */
Note: See TracBrowser for help on using the repository browser.