source: SH_SHM/trunk/source/shexec.c @ 374

Revision 341, 23.7 KB checked in by marcus, 13 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 shexec.c
3 *      ========
4 *
5 * $Revision: 180 $, $Date: 2011-03-09 16:27:03 +0100 (Mi, 09 MÀr 2011) $
6 *
7 * main subroutines of SH
8 * K. Stammler, 10-Feb-93
9 */
10
11
12/*
13 *
14 *  SeismicHandler, seismic analysis software
15 *  Copyright (C) 1992,  Klaus Stammler, Federal Institute for Geosciences
16 *                                       and Natural Resources (BGR), Germany
17 *
18 *  This program is free software; you can redistribute it and/or modify
19 *  it under the terms of the GNU General Public License as published by
20 *  the Free Software Foundation; either version 2 of the License, or
21 *  (at your option) any later version.
22 *
23 *  This program is distributed in the hope that it will be useful,
24 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
25 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26 *  GNU General Public License for more details.
27 *
28 *  You should have received a copy of the GNU General Public License
29 *  along with this program; if not, write to the Free Software
30 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
31 *
32 */
33
34
35#include <stdio.h>
36#include <string.h>
37#include "basecnst.h"
38#include "sysbase.h"
39#ifdef BC_INC_STDLIB
40#include BC_INC_STDLIB
41#ifdef BC_INC_UNISTD
42#include BC_INC_UNISTD
43#endif
44#endif
45#include "seusrdef.h"
46#include "cpusrdef.h"
47#include "fctxmn0.h"
48#include "fctxmn1.h"
49#include "fctxmn2.h"
50#include "fctxmn3.h"
51#include "fctxmn4.h"
52#include "fctxmn5.h"
53#include "fctxmni.h"
54#include "fctxmnx.h"
55#include "fctxdm.h"
56#include "fctxmt.h"
57#include "shvars.h"
58#include "erusrdef.h"
59#include "ssusrdef.h"
60#include "uiusrdef.h"
61#include "qiusrdef.h"
62#include "qfusrdef.h"
63#include "earthloc.h"
64#include "sherrors.h"
65#include "residual.h"
66
67
68
69/*------------------------------------------------------------------------*/
70
71
72
73void se_initialize( int argc, char *argv[], STATUS *status )
74
75/* initializes SH program:
76 * (i)    set session ID string
77 * (ii)   UNIX path names or path list file (set shd_... variables)
78 * (iii)  set input/output dirs for graphic (gc_...) routines
79 * (iv)   set global vars: shflags_shv, shglbflags_shv, graphic channels
80 * (v)    open protocol file
81 * (vi)   initialize q-file interface
82 * (vii)  set default names for earthloc input files (mb_...)
83 * (viii) open startup file (set ui_level to 1)
84 *
85 * parameters of routine
86 * int        argc;      input; command line parameters
87 * char       argv[];    input; -- " --
88 * STATUS     *status;   output; return status
89 */
90{
91        /* local variables */
92        char     str[BC_LINELTH+1];      /* scratch string */
93        BOOLEAN  ok;                     /* status ok ? */
94        PARAM    cmd;                    /* SH command block */
95
96        /* executable code */
97
98        /* get path names: either from UNIX environment ... */
99        se_get_sh_environment();
100
101        /* get session ID string */
102        strcpy( id_shv, SHC_FILE_PREFIX );
103        mt_randomstr( 4, id_shv+SHC_FILE_PREFIX_LENGTH );
104        strcat( id_shv, "_" );
105
106        strcpy( str, shd_scratch );
107#       ifdef SHC_HCFILE_WITH_RANDOM
108        strcat( str, id_shv );
109#       else
110        strcat( str, SHC_FILE_PREFIX );
111#       endif
112        gc_set_outputdir( str, status );
113        gc_set_inputdir( shd_inputs, status );
114
115        /* setup global flags */
116        shflags_shv = SHF_LOGCMD|SHF_CAPCNV|SHF_CMDERRSTOP|SHF_CHATTY;
117        shglbflags_shv = shflags_shv;
118
119        /* set preliminary output channels */
120        gc = gc_shv = tc = tc_shv = cc = cc_shv = 0;
121
122        /* initialize protocol file */
123        strcpy( protfile_shv, shd_scratch );
124        strcat( protfile_shv, id_shv );
125        strcat( protfile_shv, "PROT" );
126        ui_initialize( protfile_shv, status );
127        if  (Severe(status))  return;
128        ui_absflag( shflags_shv );
129
130        /* initialize q-file interface */
131        qi_initcnv();
132
133        /* initialize names of input files */
134        strcpy( str, shd_inputs );
135        strcat( str, "fereg.dat" );
136        mb_setindexfile( str, status );
137        if  (Severe(status))
138                sy_alert( "*** didn't set FER index file name properly ***\n" );
139        *status = BC_NOERROR;
140        strcpy( str, shd_inputs );
141        strcat( str, "fername.dat" );
142        mb_setfernamefile( str, status );
143        if  (Severe(status))
144                sy_alert( "*** didn't set FER name file name properly ***\n" );
145        *status = BC_NOERROR;
146
147        /* open startup command file */
148        cp_parse( "SHSTRTUP/FLAGS+=AF", &cmd, status );
149        mn0_callproc( &cmd, status );
150        if  (Severe(status))  {
151                sy_alert( "*** no startup file found ***" );
152                return;
153        } /*endif*/
154
155        RsReadTables( "default", status );
156        if  (Severe(status))  {
157                sy_alert( "*** error reading residual tables ***" );
158                *status = cBcNoError;
159        } /*endif*/
160
161} /* end of se_initialize */
162
163
164
165/*------------------------------------------------------------------------*/
166
167
168
169void se_terminate( void )
170
171/* closes all files and renames log file
172 *
173 * no parameters
174 */
175{
176        /* local variables */
177        STATUS   status;             /* return status */
178        char     str[BC_LINELTH+1];  /* scratch string */
179
180        /* executable code */
181
182        status = BC_NOERROR;
183        qf_rclose( &status );
184        strcpy( str, shd_scratch );
185        strcat( str, SHC_FILE_PREFIX );
186        strcat( str, "LAST" );
187        strcat( str, SHC_DE_CMD );
188        sy_fdelete( str );
189        strcpy( str, shd_scratch );
190        strcat( str, SHC_FILE_PREFIX );
191        strcat( str, "LAST" );
192        ui_exit( str );
193        gc_finish();
194
195} /* end of se_terminate */
196
197
198
199/*------------------------------------------------------------------------*/
200
201
202
203void se_execute_command( PARAM *cmd, char cmdlin[], char execstr[],
204        BOOLEAN *quit, BOOLEAN *redraw, BOOLEAN *iscmdproc, int *rdlevel,
205        char prompt[], STATUS *status )
206
207/* executes the command "cmd"
208 *
209 * parameters of routine
210 * PARAM      *cmd;      input; command verb & parameters
211 * char       cmdlin[];  input; command line
212 * char       execstr[]; output; next command line (from EXEC command)
213 * BOOLEAN    *quit;     output; quit program
214 * BOOLEAN    *redraw;   output; redraw screen after command
215 * int        *rdlevel;  modify; redraw level
216 * char       prompt[];  output; prompt string
217 * STATUS     *status;   output; return status
218 */
219{
220        /* executable code */
221
222        *iscmdproc = FALSE;
223
224        switch  (cmd->p[0][0])  {
225        case 'A':
226                if  (cp_cmdverb(cmd,"AL"))  {
227                        mnx_al( cmd, status );
228                        *redraw = TRUE;
229                } else if  (cp_cmdverb(cmd,"AM"))  {
230                        mnx_am( cmd, status );
231                } else if  (cp_cmdverb(cmd,"APPEND"))  {
232                        mn4_append( cmd, status );
233                        *redraw = TRUE;
234                } else if  (cp_cmdverb(cmd,"ARP"))  {
235                        mn3_arp( cmd, status );
236                        *redraw = TRUE;
237                } else {
238                        mn0_callproc( cmd, status );
239                        *iscmdproc = TRUE;
240                } /*endif*/
241                break;
242        case 'B':
243                if  (cp_cmdverb(cmd,"BEAM"))  {
244                        mnx_beam( cmd, status );
245                        *redraw = TRUE;
246                } else {
247                        mn0_callproc( cmd, status );
248                        *iscmdproc = TRUE;
249                } /*endif*/
250                break;
251        case 'C':
252                if  (cp_cmdverb(cmd,"CALC"))  {
253                        mn0_calc( cmd, status );
254                } else if  (cp_cmdverb(cmd,"CALL"))  {
255                        mn3_call( cmd, status );
256                } else if  (cp_cmdverb(cmd,"CMD"))  {
257                        mn2_cmd( cmd, status );
258                } else if  (cp_cmdverb(cmd,"CONNECT"))  {
259                        mn4_connect( cmd, status );
260                        *redraw = TRUE;
261                } else if  (cp_cmdverb(cmd,"COPY"))  {
262                        mn1_copy( cmd, status );
263                        *redraw = TRUE;
264                } else if  (cp_cmdverb(cmd,"CORR"))  {
265                        mn2_corr( cmd, status );
266                        *redraw = TRUE;
267                } else if  (cp_cmdverb(cmd,"CORRL"))  {
268                        mn2_corrl( cmd, status );
269                } else if  (cp_cmdverb(cmd,"CREATE"))  {
270                        mn1_create( cmd, status );
271                        *redraw = TRUE;
272                } else if  (cp_cmdverb(cmd,"CURVE"))  {
273                        mn3_curve( cmd, status );
274                } else if  (cp_cmdverb(cmd,"CUT"))  {
275                        mn3_cut( cmd, status );
276            *redraw = TRUE;
277                } else {
278                        mn0_callproc( cmd, status );
279                        *iscmdproc = TRUE;
280                } /*endif*/
281                break;
282        case 'D':
283                if  (cp_cmdverb(cmd,"DECIMATE"))  {
284                        mn5_decimate( cmd, status );
285                        *redraw = TRUE;
286                } else if  (cp_cmdverb(cmd,"DEFAULT"))  {
287                        mn0_default( cmd, status );
288                } else if  (cp_cmdverb(cmd,"DEL"))  {
289                        mn1_del( cmd, status );
290                        *redraw = TRUE;
291                } else if  (cp_cmdverb(cmd,"DEMEAN"))  {
292                        mn4_demean( cmd, status );
293                        *redraw = TRUE;
294                } else if  (cp_cmdverb(cmd,"DERIVE"))  {
295                        mn4_derive( cmd, status );
296                        *redraw = TRUE;
297                } else if  (cp_cmdverb(cmd,"DESPIKE"))  {
298                        mn3_despike( cmd, status );
299                        *redraw = TRUE;
300                } else if  (cp_cmdverb(cmd,"DISPLAY"))  {
301                        mn2_display( cmd, status );
302                        *redraw = TRUE;
303                } else if  (cp_cmdverb(cmd,"DTW"))  {
304                        dm_timewdw( 0.0, 0.0, status );
305                        *redraw = TRUE;
306                } else if  (cp_cmdverb(cmd,"DYW"))  {
307                        dm_ywdw( 0.0, 0.0, status );
308                        *redraw = TRUE;
309                } else {
310                        mn0_callproc( cmd, status );
311                        *iscmdproc = TRUE;
312                } /*endif*/
313                break;
314        case 'E':
315                if  (cp_cmdverb(cmd,"ECHO_CH"))  {
316                        mn0_ecch( cmd, status );
317                } else if  (cp_cmdverb(cmd,"ECHO"))  {
318                        mn0_echo( cmd, status );
319                } else if  (cp_cmdverb(cmd,"ENTER"))  {
320                        mn0_enter( cmd, status );
321                } else if  (cp_cmdverb(cmd,"ENTRY"))  {
322                        mn1_entry( cmd, status );
323                } else if  (cp_cmdverb(cmd,"EXEC"))  {
324                        if  (cp_pnexc(cmd,1,status))  return;
325                        cp_getstr( cmd, 1, tc, "   cmd: ", BC_LINELTH, execstr, status );
326                } else if  (cp_cmdverb(cmd,"EXTERNAL_ROUTINE"))  {
327                        mn5_external_routine( cmd, status );
328                } else if  (cp_cmdverb(cmd,"EXTRACT"))  {
329                        mn2_extract( cmd, status );
330                } else {
331                        mn0_callproc( cmd, status );
332                        *iscmdproc = TRUE;
333                } /*endif*/
334                break;
335        case 'F':
336                if  (cp_cmdverb(cmd,"FCT"))  {
337                        mn0_fct( cmd, status );
338                } else if  (cp_cmdverb(cmd,"FFT"))  {
339                        mn4_fft( cmd, status );
340                        *redraw = TRUE;
341                } else if  (cp_cmdverb(cmd,"FILI"))  {
342                        mn2_fili( cmd, status );
343                } else if  (cp_cmdverb(cmd,"FILTER"))  {
344                        mn2_filter( cmd, status );
345                        *redraw = TRUE;
346                } else if  (cp_cmdverb(cmd,"FINDGAP"))  {
347                        mn5_findgap( cmd, status );
348                } else if  (cp_cmdverb(cmd,"FIXGAP"))  {
349                        mn5_fixgap( cmd, status );
350                        *redraw = TRUE;
351                } else if  (cp_cmdverb(cmd,"FIT"))  {
352                        mn4_fit( cmd, status );
353                } else if  (cp_cmdverb(cmd,"FOLD"))  {
354                        mn3_fold( cmd, status );
355                        *redraw = TRUE;
356                } else {
357                        mn0_callproc( cmd, status );
358                        *iscmdproc = TRUE;
359                } /*endif*/
360                break;
361        case 'G':
362                if  (cp_cmdverb(cmd,"GOTO"))  {
363                        mn0_goto( cmd, status );
364                } else {
365                        mn0_callproc( cmd, status );
366                        *iscmdproc = TRUE;
367                } /*endif*/
368                break;
369        case 'H':
370                if  (cp_cmdverb(cmd,"HC"))  {
371                        mnx_hc( cmd, status );
372                } else if  (cp_cmdverb(cmd,"HELP"))  {
373                        mn0_help( cmd, status );
374                } else if  (cp_cmdverb(cmd,"HIDE"))  {
375                        mn2_hide( cmd, status );
376                        *redraw = TRUE;
377                } else if  (cp_cmdverb(cmd,"HOTKEY"))  {
378                        mn0_hotkey( cmd, status );
379                } else {
380                        mn0_callproc( cmd, status );
381                        *iscmdproc = TRUE;
382                } /*endif*/
383                break;
384        case 'I':
385                if  (cp_cmdverb(cmd,"IF"))  {
386                        mn0_if( cmd, status );
387                } else if  (cp_cmdverb(cmd,"INT"))  {
388                        mn4_int( cmd, status );
389                        *redraw = TRUE;
390                } else {
391                        mn0_callproc( cmd, status );
392                        *iscmdproc = TRUE;
393                } /*endif*/
394                break;
395        case 'J':
396        case 'K':
397        case 'L':
398                if  (cp_cmdverb(cmd,"LEVELDETEC"))  {
399                        mn4_leveldetec( cmd, status );
400                } else if  (cp_cmdverb(cmd,"LOCATE"))  {
401                        mnx_locate( cmd, status );
402                } else if  (cp_cmdverb(cmd,"LOG"))  {
403                        mn5_log( cmd, status );
404                } else {
405                        mn0_callproc( cmd, status );
406                        *iscmdproc = TRUE;
407                } /*endif*/
408                break;
409        case 'M':
410                if  (cp_cmdverb(cmd,"MARK"))  {
411                        mn2_mark( cmd, status );
412                } else if  (cp_cmdverb(cmd,"MAXAMPL"))  {
413                        mn1_maxampl( cmd, status );
414                        *redraw = TRUE;
415                } else if  (cp_cmdverb(cmd,"MAXIMUM"))  {
416                        mn5_maximum( cmd, status );
417                        *redraw = TRUE;
418                } else if  (cp_cmdverb(cmd,"MDIR"))  {
419                        mn2_mdir( cmd, status );
420                } else if  (cp_cmdverb(cmd,"MEAN"))  {
421                        mn5_mean( cmd, status );
422                        *redraw = TRUE;
423                } else if  (cp_cmdverb(cmd,"MEND"))  {
424                        mn3_mend( cmd, status );
425                        *redraw = TRUE;
426                } else if  (cp_cmdverb(cmd,"MERGE"))  {
427                        mn4_merge( cmd, status );
428                        *redraw = TRUE;
429                } else if  (cp_cmdverb(cmd,"MERGE_PAIR"))  {
430                        mn4_merge_pair( cmd, status );
431                        *redraw = FALSE;
432                } else if  (cp_cmdverb(cmd,"MIRROR"))  {
433                        mn3_mirror( cmd, status );
434                        *redraw = TRUE;
435                } else {
436                        mn0_callproc( cmd, status );
437                        *iscmdproc = TRUE;
438                } /*endif*/
439                break;
440        case 'N':
441                if  (cp_cmdverb(cmd,"NORM"))  {
442                        mn1_norm( cmd, redraw, status );
443                } else if  (cp_cmdverb(cmd,"NOP"))  {
444                } else if  (cp_cmdverb(cmd,"NR"))  {
445                        (*rdlevel)++;
446                } else {
447                        mn0_callproc( cmd, status );
448                        *iscmdproc = TRUE;
449                } /*endif*/
450                break;
451        case 'O':
452                if  (cp_cmdverb(cmd,"OVERLAY"))  {
453                        mn3_overlay( cmd, status );
454                } else {
455                        mn0_callproc( cmd, status );
456                        *iscmdproc = TRUE;
457                } /*endif*/
458                break;
459        case 'P':
460                if  (cp_cmdverb(cmd,"PICK"))  {
461                        mn2_pick( cmd, status );
462                } else if  (cp_cmdverb(cmd,"PM"))  {
463                        mnx_pm( cmd, status );
464                } else if  (cp_cmdverb(cmd,"PMCH"))  {
465                        mnx_pmch( cmd, status );
466                } else if  (cp_cmdverb(cmd,"POLFIL"))  {
467                        mn4_polfil( cmd, status );
468                        *redraw = TRUE;
469                } else if  (cp_cmdverb(cmd,"PROMPT"))  {
470                        mn5_prompt( cmd, BC_LINELTH, prompt, status );
471                } else {
472                        mn0_callproc( cmd, status );
473                        *iscmdproc = TRUE;
474                } /*endif*/
475                break;
476        case 'Q':
477                if  (cp_cmdverb(cmd,"QUIT"))  {
478                        mn0_quit( cmd, quit, status );
479                } else {
480                        mn0_callproc( cmd, status );
481                        *iscmdproc = TRUE;
482                } /*endif*/
483                break;
484        case 'R':
485                if  (cp_cmdverb(cmd,"RD"))  {
486                        mn1_rd( cmd, rdlevel, status );
487                        *redraw = TRUE;
488                } else if  (cp_cmdverb(cmd,"READ"))  {
489                        mni_read( cmd, status );
490                        *redraw = TRUE;
491                } else if  (cp_cmdverb(cmd,"READA"))  {
492                        mni_reada( cmd, status );
493                        *redraw = TRUE;
494                } else if  (cp_cmdverb(cmd,"READF"))  {
495                        mni_readf( cmd, status );
496                        *redraw = TRUE;
497                } else if  (cp_cmdverb(cmd,"READS"))  {
498                        mni_reads( cmd, status );
499                        *redraw = TRUE;
500                } else if  (cp_cmdverb(cmd,"REPLACE"))  {
501                        mn5_replace( cmd, status );
502                        *redraw = TRUE;
503                } else if  (cp_cmdverb(cmd,"RESAMPLE"))  {
504                        mnx_resample( cmd, status );
505                } else if  (cp_cmdverb(cmd,"RETURN"))  {
506                        mn0_cmdreturn( status );
507                } else if  (cp_cmdverb(cmd,"RMS"))  {
508                        mnx_rms( cmd, status );
509                } else if  (cp_cmdverb(cmd,"ROT"))  {
510                        mn1_rot( cmd, status );
511                        *redraw = TRUE;
512                } else {
513                        mn0_callproc( cmd, status );
514                        *iscmdproc = TRUE;
515                } /*endif*/
516                break;
517        case 'S':
518                if  (cp_cmdverb(cmd,"SAMPLE"))  {
519                        mn5_sample( cmd, status );
520                } else if  (cp_cmdverb(cmd,"SDEF"))  {
521                        mn0_sdef( cmd, status );
522                } else if  (cp_cmdverb(cmd,"SDEL"))  {
523                        mn0_sdel( cmd, status );
524                } else if  (cp_cmdverb(cmd,"SET"))  {
525                        mn1_set( cmd, status );
526                } else if  (cp_cmdverb(cmd,"SHIFT"))  {
527                        mnx_shift( cmd, status );
528                        *redraw = TRUE;
529                } else if  (cp_cmdverb(cmd,"SHMSETUP"))  {
530                        mn5_shmsetup( cmd, status );
531                } else if  (cp_cmdverb(cmd,"SMOOTH"))  {
532                        mn5_smooth( cmd, status );
533                        *redraw = TRUE;
534                } else if  (cp_cmdverb(cmd,"SPECDIV"))  {
535                        mn5_specdiv( cmd, status );
536                        *redraw = TRUE;
537                } else if  (cp_cmdverb(cmd,"SPECTRUM"))  {
538                        mn4_spectrum( cmd, status );
539                        *redraw = TRUE;
540                } else if  (cp_cmdverb(cmd,"SPECTROGRAM"))  {
541                        mn4_spectrogram( cmd, status );
542                        *redraw = FALSE;
543                } else if  (cp_cmdverb(cmd,"SPIKING"))  {
544                        mn3_spikefil( cmd, status );
545                        *redraw = TRUE;
546                } else if  (cp_cmdverb(cmd,"STABILITY"))  {
547                        mn4_stability( cmd, status );
548                        *redraw = TRUE;
549                } else if  (cp_cmdverb(cmd,"STALTA"))  {
550                        mn4_stalta( cmd, status );
551                        *redraw = TRUE;
552                } else if  (cp_cmdverb(cmd,"STW"))  {
553                        mn1_stw( cmd, status );
554                        *redraw = TRUE;
555                } else if  (cp_cmdverb(cmd,"STYW"))  {
556                        mnx_styw( cmd, status );
557                        *redraw = TRUE;
558                } else if  (cp_cmdverb(cmd,"SYW"))  {
559                        mnx_syw( cmd, status );
560                        *redraw = TRUE;
561                } else if  (cp_cmdverb(cmd,"SUM"))  {
562                        mn1_sum( cmd, status );
563                        *redraw = TRUE;
564                } else if  (cp_cmdverb(cmd,"SWITCH"))  {
565                        mn0_switch( cmd, &shflags_shv, status );
566                } else if  (cp_cmdverb(cmd,"SYSTEM"))  {
567                        mn0_system( cmd, status );
568                } else {
569                        mn0_callproc( cmd, status );
570                        *iscmdproc = TRUE;
571                } /*endif*/
572                break;
573        case 'T':
574                if  (cp_cmdverb(cmd,"TIME"))  {
575                        mn2_time( cmd, status );
576                } else if  (cp_cmdverb(cmd,"TITLE"))  {
577                        mnx_title( cmd, status );
578                        *redraw = TRUE;
579                } else if  (cp_cmdverb(cmd,"TRCFCT"))  {
580                        mn2_trcfct( cmd, status );
581                        *redraw = TRUE;
582                } else if  (cp_cmdverb(cmd,"TRCTXT"))  {
583                        dm_inftext( cmdlin, status );
584                        *redraw = TRUE;
585                } else if  (cp_cmdverb(cmd,"TRCTXTP"))  {
586                        mn1_trctxtp( cmd, status );
587                        *redraw = TRUE;
588                } else if  (cp_cmdverb(cmd,"TREND"))  {
589                        mn4_trend( cmd, status );
590                        *redraw = TRUE;
591                } else {
592                        mn0_callproc( cmd, status );
593                        *iscmdproc = TRUE;
594                } /*endif*/
595                break;
596        case 'U':
597                if  (cp_cmdverb(cmd,"UNIT"))  {
598                        mn3_unit( cmd, status );
599                } else {
600                        mn0_callproc( cmd, status );
601                        *iscmdproc = TRUE;
602                } /*endif*/
603                break;
604        case 'V':
605        case 'W':
606                if  (cp_cmdverb(cmd,"WDW"))  {
607                        mn0_wdw( cmd, status );
608                } else if  (cp_cmdverb(cmd,"WRITE"))  {
609                        mni_write( cmd, status );
610                } else if  (cp_cmdverb(cmd,"WRITEA"))  {
611                        mni_writea( cmd, status );
612                } else {
613                        mn0_callproc( cmd, status );
614                        *iscmdproc = TRUE;
615                } /*endif*/
616                break;
617        case 'X':
618        case 'Y':
619                if  (cp_cmdverb(cmd,"YINFO"))  {
620                        mnx_yinfo( cmd, status );
621                        *redraw = TRUE;
622                } else {
623                        mn0_callproc( cmd, status );
624                        *iscmdproc = TRUE;
625                } /*endif*/
626                break;
627        case 'Z':
628                if  (cp_cmdverb(cmd,"ZOOM"))  {
629                        mn1_zoom( cmd, status );
630                        *redraw = TRUE;
631                } else {
632                        mn0_callproc( cmd, status );
633                        *iscmdproc = TRUE;
634                } /*endif*/
635                break;
636        case '0': case '1': case '2': case '3': case '4':
637        case '5': case '6': case '7': case '8': case '9':
638        case '/': case '\\':
639                mn0_callproc( cmd, status );
640                *iscmdproc = TRUE;
641                break;
642        default:
643                if  (cmd->p[0][0] >= 'a' && cmd->p[0][0] <= 'z')
644                        *status = SHE_LOWRCASE;
645                break;
646        } /*endswitch*/
647
648} /* end of se_execute_command */
649
650
651
652/*------------------------------------------------------------------------*/
653
654
655
656void se_cmdabort( PARAM *par, char cmdline[], STATUS status )
657
658/* creates error file, aborts command procedure and returns to level 0
659 *
660 * parameters of routine
661 * PARAM    *par;           input; parameter block
662 * char     cmdline[];      input; user input
663 * STATUS   status;         input; error number
664 */
665{
666        /* local variables */
667        static int  errnum;              /* error number */
668        char     msg[BC_LINELTH+1];      /* error message */
669        char     context[BC_LINELTH+1];  /* error context */
670        char     fname[BC_LINELTH+1];    /* file name */
671        FILE     *err;                   /* file pointers */
672        int      *line;                  /* line in command procedure */
673        int      i;                      /* counter */
674        int      locstat;                /* local status */
675
676        /* executable code */
677
678        /* create error file */
679
680        locstat = 0;
681        strcpy( fname, shd_scratch );
682        strcat( fname, id_shv );
683        strcat( fname, "ERR" );
684        strcat( fname, SHC_DE_TEXT );
685        strcpy( msg, ">>> status report in error file " );
686        strcat( msg, fname );
687        strcat( msg, " <<<\n" );
688        gc_write( cc, msg );
689        err = sy_fopen( fname, "w" );
690        if  (err == NULL)  return;
691
692        err_msg( status, msg );
693        err_getcontext( context );
694        fprintf( err, "STATUS REPORT FILE\n" );
695        fprintf( err, "==================\n\n" );
696        fprintf( err, "session ID %s, error number %d\n", id_shv, ++errnum );
697        fprintf( err, "status code %d\n", status );
698        fprintf( err, "error message:\n" );
699        fprintf( err, "%s\n", msg );
700        if  (*context != '\0')  {
701                fprintf( err, "error context:\n" );
702                fprintf( err, "%s\n", context );
703        } /*endif*/
704        fprintf( err, "in source line\n%s\n", cmdline );
705        fprintf( err, "source line after translation\n" );
706        cp_verify( par, BC_LINELTH, msg, &locstat );
707        if  (locstat != SHE_NOERROR)  {
708                fprintf( err, ">>>  verify error  <<<\n\n" );
709        } else {
710                fprintf( err, "%s\n\n", msg );
711        } /*endif*/
712
713        fprintf( err, "traceback command levels (current level %d):\n",
714                ui_level() );
715        line = ui_lines();
716        for  (i=0;i<=ui_level();i++)
717                fprintf( err, "line %3d   in level %d (file %s)\n",
718                        *line++, i, ui_levelname(i) );
719
720        fprintf( err, "\nflag status $%04x (global: $%04x)\n",
721                shflags_shv, shglbflags_shv );
722        fprintf( err, "---------------------------------\n" );
723        if  (shflags_shv & SHF_LOGCMD)      fprintf( err, "PROTOCOL\n" );
724        if  (shflags_shv & SHF_ECHO)        fprintf( err, "ECHO\n" );
725        if  (shflags_shv & SHF_CAPCNV)      fprintf( err, "CAPCNV\n" );
726        if  (shflags_shv & SHF_STEP)        fprintf( err, "STEP\n" );
727        if  (shflags_shv & SHF_VERIFY)      fprintf( err, "VERIFY\n" );
728        if  (shflags_shv & SHF_CMDERRSTOP)  fprintf( err, "CMDERRSTOP\n" );
729        if  (shflags_shv & SHF_SHERRSTOP)   fprintf( err, "SHERRSTOP\n" );
730        if  (shflags_shv & SHF_NOERRMSG)    fprintf( err, "NOERRMSG\n" );
731        if  (shflags_shv & SHF_CHATTY)      fprintf( err, "CHATTY\n" );
732        if  (shflags_shv & SHF_STARTUP)     fprintf( err, "STARTUP\n" );
733
734        fprintf( err, "\n" );
735        ss_dump( err, -1 );
736        fprintf( err, "\n" );
737        ss_dump( err, SHC_SYMLOC );
738        fprintf( err, "\n" );
739        ss_dump( err, SHC_SYMGLB );
740        fprintf( err, "\n" );
741
742        fclose( err );
743
744        /* abort command procedure & return to interactive level */
745        locstat = SHE_NOERROR;
746        while (ui_level() > 0)
747                mn0_cmdreturn( &locstat );
748
749} /* end of se_cmdabort */
750
751
752
753/*------------------------------------------------------------------------*/
754
755
756
757void se_check_qual( CHMAP ch, PARAM *par )
758
759/* prints unchecked qualifiers
760 *
761 * parameters of routine
762 * CHMAP     ch;      input; output channel(s)
763 * PARAM     *par;    input; parameter block
764 */
765{
766        /* executable code */
767
768        printf( "%c", (char)7 );
769        gc_write( ch, "*** unrecognized qualifier \"" );
770        gc_write( ch, cp_uncheckedqual(par) );
771        gc_write( ch, "\" ***\n" );
772
773} /* end of se_check_qual */
774
775
776
777/*------------------------------------------------------------------------*/
778
779
780
781void se_do_step( char stepcmd, STATUS *status )
782
783/* processes step command entered by user
784 *
785 * parameters of routine
786 * char       stepcmd;     input; step command
787 * STATUS     *status;     output; return status
788 */
789{
790        /* local variables */
791        PARAM    scmd;     /* to call TT */
792
793        /* executable code */
794
795        switch  (stepcmd)  {
796        case '@':
797                cp_parse( "TT", &scmd, status );
798                if  (Severe(status))  return;
799                mn0_callproc( &scmd, status );
800                break;
801        } /*endswitch*/
802
803} /* end of se_do_step */
804
805
806
807/*------------------------------------------------------------------------*/
808
809
810
811void se_dsplymsg( wdw, status )
812
813/* displays error message */
814
815/* parameters of routine */
816int      wdw;            /* window number */
817int      status;         /* input; error number */
818
819{
820        /* local variables */
821        char     msg[BC_LINELTH+1];    /* error message */
822        char     str[BC_LONGSTRLTH+1];
823
824        /* executable code */
825        err_msg( status, msg );
826        printf( "%c", (char)7 );
827        if  (wdw == 0)  {
828                sy_alert( msg );
829        } else {
830                gc_write( wdw, msg );
831                gc_wrtch( wdw, '\n' );
832        } /*endif*/
833
834        err_getcontext( msg );
835        if  (*msg != '\0')  {
836                if  (wdw == 0)  {
837                        sprintf( str, ">>> context: %s", msg );
838                        sy_alert( str );
839                } else {
840                        gc_write( wdw, ">>> context: " );
841                        gc_write( wdw, msg );
842                        gc_wrtch( wdw, '\n' );
843                } /*endif*/
844        } /*endif*/
845
846} /* end of se_dsplymsg */
847
848
849
850/*------------------------------------------------------------------------*/
851
852
853
854void se_readshpaths( char file[], BOOLEAN *ok )
855
856/* reads SH paths from file
857 *
858 * parameters of routine
859 * char       file[];      input; name of input file
860 * BOOLEAN    *ok;         output; file found and read
861 */
862{
863        /* local variables */
864        FILE     *pf;                 /* file pointer */
865        char     line[BC_LINELTH+1];  /* current line */
866        char     item[BC_LINELTH+1];  /* item name */
867        char     dir[BC_LINELTH+1];   /* directory string */
868
869        /* executable code */
870
871        *ok = TRUE;
872        pf = sy_fopen( file, "r" );
873        if  (pf == NULL)  {
874                *ok = FALSE;
875                return;
876        } /*endif*/
877        while  (fgets(line,BC_LINELTH,pf) != NULL)  {
878                if  (*line != '!')  {
879                        sscanf( line, "%s %s", item, dir );
880                        if  (strcmp(item,"SCRATCH:") == 0)  {
881                                strcpy( shd_scratch, dir );
882                        } else if (strcmp(item,"INPUTS:") == 0)  {
883                                strcpy( shd_inputs, dir );
884                        } else {
885                                printf( "*** undefined SH path: %s ***\n", item );
886                        } /*endif*/
887                } /*endif*/
888        } /*endif*/
889        sy_fclose( pf );
890
891} /* end of se_readshpaths */
892
893
894
895/*------------------------------------------------------------------------*/
896
897
898void se_get_sh_environment( void )
899
900/* reads environment variables and copies directories to shd_... variables
901 *
902 * no parameters
903 */
904{
905        /* local variables */
906        char     *eptr;     /* pointer to translated value */
907
908        /* executable code */
909
910        eptr = (char *)getenv( "SH_SCRATCH" );
911        if  (eptr != NULL)
912                if  (strlen(eptr) < BC_FILELTH)
913                        strcpy( shd_scratch, eptr );
914        eptr = (char *)getenv( "SH_INPUTS" );
915        if  (eptr != NULL)
916                if  (strlen(eptr) < BC_FILELTH)
917                        strcpy( shd_inputs, eptr );
918
919} /* end of se_get_sh_environment */
920
921
922
923/*------------------------------------------------------------------------*/
Note: See TracBrowser for help on using the repository browser.