-
Notifications
You must be signed in to change notification settings - Fork 1
/
interp.cpp.in
4331 lines (3061 loc) · 124 KB
/
interp.cpp.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+ Mumps Compiler Run-Time Support Functions
//+ Copyright (c) 2001 2002 2006 2007 2008 2012 2103 2014 2015, 2016, 2017
//+ by Kevin C. O'Kane
//+
//+ kc.okane@gmail.com
//+ http://threadsafebooks.com/
//+ http://www.cs.uni.edu/~okane/
//+
//+ This library is free software; you can redistribute it and/or
//+ modify it under the terms of the GNU Lesser General Public
//+ License as published by the Free Software Foundation; either
//+ version 2.1 of the License, or (at your option) any later version.
//+
//+ This library is distributed in the hope that it will be useful,
//+ but WITHOUT ANY WARRANTY; without even the implied warranty of
//+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
//+ Lesser General Public License for more details.
//+
//+ You should have received a copy of the GNU Lesser General Public
//+ License along with this library; if not, write to the Free Software
//+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//+
// #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// formatted with astyle --style=banner
/*************************************************************************
interp.cpp - Mumps Runtime Library Mumps interpretation routines - can
be used for indirection operations in the compiled code.
**************************************************************************/
#include <iostream>
using namespace std;
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <mumpsc/defines.h>
#include <mumpsc/btree.h>
#include <sys/types.h>
#include <locale.h>
#include <monetary.h>
#include <unistd.h>
#include <time.h>
#include <mumpsc/arith.h>
#include <mumpsc/globalOrder.h>
@dbtype@
@cygwin@
@standalone@
#define _INTERP_
#include <mumpsc/global.h>
#include <mumpsc/fcns.h>
#include <mumpsc/sysparms.h>
#include <mumpsc/keyfix.h>
#define GOSUBMAX 50
#define SWAP 30
#define FORMAX 30
#define EXECLEVS 40
#define LBLS 80
#define CSTR (char *)
#define USTR (unsigned char *)
#define OPEN_PAREN 206
#define COMMA 207
#define CLOSE_PAREN 209
void lpad(unsigned char *, unsigned char *, short);
void substr(unsigned char *, unsigned char *, int, int);
void sigint(int);
void LocalName(unsigned char *, unsigned char *, unsigned char *, MSV *);
void GlobalQuery(unsigned char *, unsigned char *, char, MSV *);
void Qsub(unsigned char *, unsigned char *, unsigned char *, MSV*);
void Qlength(unsigned char *, unsigned char *, MSV*);
void ErrorMessage(const char *, long);
void zfcn(unsigned char *, unsigned char *, MSV *);
void fcn(struct MSV*);
int xindex(const unsigned char *, const unsigned char *, short);
int TimeOut(int, unsigned char *, char *, int);
int DirectRead (int, unsigned char *);
int TimeOut_getstr1(int, unsigned char *, char *, int);
int _SymFree(int, MSV *);
int pm(const unsigned char *, const unsigned char *, MSV *);
int sql(int, struct MSV *, char *DataSourceName, char *Command, char *, const char *);
char* makeLock(char *, char *, char *, char, char *); /* global array lock service */
char* cleanLocks(char *); /* global array lock service */
/***********************************************************
strcmp()-style function, where aa and bb look like numbers.
-1 if aa < bb
0 if aa == bb
1 if aa > bb
***********************************************************/
// Put numeric string into canonical format.
class InterpreterException {
public:
InterpreterException();
char *what();
private:
char * message;
};
// symbol table routing interface
char * sym_(int, unsigned char *, unsigned char *, MSV *);
// Pattern handling function left over from old '?' operator code
static void patrn1(short *jpx, short *ernbr, struct MSV *);
//===========================================================================
// Interpret
//===========================================================================
int Interpret (const char *parm1, struct MSV * svPtr) {
short getstr2 (short int lun, unsigned char area[], struct MSV * svPtr);
void readf_ (unsigned char zd[], short pd1org, struct MSV * svPtr);
void inout (unsigned char text[], short cmnd, short col, struct MSV * svPtr);
long int ilong, jlong;
short pd1hold1, pd1hold2, ibr, pd1cur, i, j, k;
short l, New;
static char *swp[SWAP]; /* swap pointers */
char XTAB[2]= {'\t', 0};
/*----------------------------------------------
| |
| gosub stack |
| |
| 0 - swapfile origin |
| 1 - pd1cur |
| 2 - addr in cmdstack |
| 3 - return point [label] |
| 4 - original pd1len |
| 5 - execlevel prior |
| 8 - New Flag |
| |
------------------------------------------------*/
short gosub[GOSUBMAX][9], gsbx, cmdx, forx, cmdxold, pd1Last;
int NewFlag,SymInc=0;
unsigned char cmdstack[8192];
unsigned char lbls[LBLS][20];
int lbloff[20], lblx, argless;
#ifdef NATIVE_STANDALONE
long PulseCount = 0; // cooperative multitasking count
#endif
unsigned char forv[FORMAX][256],
forit[FORMAX],
forlt[FORMAX],
ftmp[STR_MAX];
unsigned char forin[FORMAX][STR_MAX],
forlv[FORMAX][256];
unsigned short swapextent, shold;
short ExecLevel = 1;
short ExecLevNew[EXECLEVS] = {0};
short BreakFlag = 0;
unsigned char dosave[STR_MAX];
unsigned char cod206[2] = { OPEN_PAREN, 0 }; /* open */
unsigned char cod208 = 208; /* comma */
unsigned char cod207 = 207; /* close */
unsigned char cod209 = 209; /* comma */
unsigned char cod210 = 210; /* colon */
short retz, icmnd, p2px, ernbr, fileflg;
unsigned char tmp2[STR_MAX], tmp3[STR_MAX], dirflg, vd[STR_MAX];
char *pd1p;
int MergeFlag;
char MergeRHS[STR_MAX];
static unsigned char *to;
static unsigned char * from;
int sigc (), getche (void);
pd1p= (char *) &svPtr->pd1[1];
for (i = 0; i < SWAP; i++) swp[i] = NULL;
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
// init environment: io default io unit (5=terminal).
// pd1 is user partition (PS bytes long).
// gosub is stack for do's, for's and xecutes.
// symlen is bottom of symbol table (symbol table
// grows down from top of user partition).
// PS is size of user partition.
// pd1cur is current location in user partition.
// pd1len is length of user pgm in partition.
// initialize random nbr generator.
//
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
svPtr->io = 5;
for (pd1cur = 0; pd1cur < PS; pd1cur++) svPtr->pd1[pd1cur] = ' ';
svPtr->symlen = PS;
pd1cur = 1;
svPtr->pd1len = 0;
srand (time(NULL));
svPtr->bd[0]=0;
svPtr->bd[1]=0;
for (i = 0; i < GOSUBMAX; i++) for (j = 0; j < 9; j++) gosub[i][j] = 0;
setlocale(LC_ALL,"@locale@");
#if defined(POSTGRES) || defined(MYSQLDB) || defined(MYSQL) || defined(POSTGRESSDB)
//----------------------------------------------------------
// postgres auto connect - done at interp startup - disabled
//----------------------------------------------------------
{
unsigned char key[2]= {0}, bd[2]= {0};
btree(OPEN, key, bd, svPtr );
}
#endif
// ****************************************************************************
// *******
// ******* set trap for <interrupt>.
// ******* install default program to execute init.mps.
// *******
// ****************************************************************************
pd1cur = 1;
svPtr->pd1[svPtr->pd1len + 1] = 0;
svPtr->ctrlc = 0;
// ****************************************************************************
// *******
// ******* re-enter here after error.
// ******* re-set environment.
// ******* if user error trap set, copy user error cmnd line to pgm area.
// *******
// ****************************************************************************
restart:
BreakFlag = 0;
ExecLevel = 1;
for (i=0; i<EXECLEVS; i++) ExecLevNew[i]=0;
svPtr->ierr = 0;
svPtr->io = 5;
svPtr->t0px = 0;
svPtr->t2 = 0;
for (i = 0; i < SWAP; i++) { // clear the swap area
if (swp[i] != NULL) free (swp[i]);
swp[i] = NULL;
}
swapextent = 1;
lblx = 0;
// initialize execution buffer
strcpy ( (char *) &svPtr->pd1[2], (const char *) parm1);
svPtr->pd1[1] = TAB;
svPtr->pd1len = strlen ( (const char *) &svPtr->pd1[1]) + 1;
BreakFlag = 0;
pd1cur = 1;
cmdx = 0;
svPtr->setpiece = 0;
svPtr->LineNumber = 0;
lblx = 0;
forx = 0;
gsbx = 0;
svPtr->kflg = 0;
pd1Last = 0;
// ****************************************************************************
// *******
// ******* re-enter here for each new program command line
// ******* extract next command into xd.
// ******* re-enter here for running program.
// ******* quit running program if at end.
// *******
// ****************************************************************************
next_line:
BreakFlag=0;
if (pd1cur > svPtr->pd1len) {
svPtr->xd[svPtr->xpx] = 0;
goto quit;
}
svPtr->PD1 = PS1 - pd1cur;
svPtr->LineNumber ++;
/************************
comments or special code
*************************/
if (svPtr->pd1[pd1cur] == '#' ||
svPtr->pd1[pd1cur] == '%' ||
svPtr->pd1[pd1cur] == '+' ||
svPtr->pd1[pd1cur] == ';' ||
( svPtr->pd1[pd1cur] == '/' &&
svPtr->pd1[pd1cur+1] == '/') ) {
pd1cur++;
while (svPtr->pd1[pd1cur]) pd1cur++;
pd1cur++;
goto next_line;
}
if (!svPtr->pd1[pd1cur]) {
pd1cur++;
goto next_line;
}
i = pd1cur; // remember starting place
// skip label - find 1st blank or TAB
while ( svPtr->pd1[pd1cur] &&
svPtr->pd1[pd1cur] != TAB &&
svPtr->pd1[pd1cur] != ' ' ) pd1cur++;
/************
skip multiple TABs
************/
while (svPtr->pd1[pd1cur] == TAB || svPtr->pd1[pd1cur] == ' ' ) pd1cur++;
/*********************
copy source line to xd
*********************/
int dotcount;
argless = dotcount = 0;
while (svPtr->pd1[pd1cur+dotcount]=='.') dotcount++;
if (dotcount + 1 < ExecLevel) goto quit1;
if (dotcount)
if (svPtr->pd1[pd1cur] == '.') {
if (strncmp ( (const char *) &svPtr->pd1[pd1cur], ". ", 2) == 0) {
if (ExecLevel != 2) {
while (svPtr->pd1[pd1cur++]);
goto next_line;
}
pd1cur += 2;
}
else if (strncmp ( (const char *) &svPtr->pd1[pd1cur], ".. ", 3) == 0) {
if (ExecLevel != 3) {
while (svPtr->pd1[pd1cur++]);
goto next_line;
}
pd1cur += 3;
}
else if (strncmp ( (const char *) &svPtr->pd1[pd1cur], "... ", 4) == 0) {
if (ExecLevel != 4) {
while (svPtr->pd1[pd1cur++]);
goto next_line;
}
pd1cur += 4;
}
else if (strncmp ( (const char *) &svPtr->pd1[pd1cur], ".... ", 5) == 0) {
if (ExecLevel != 5) {
while (svPtr->pd1[pd1cur++]);
goto next_line;
}
pd1cur += 5;
}
else if (strncmp ( (const char *) &svPtr->pd1[pd1cur], "..... ", 6) == 0) {
if (ExecLevel != 6) {
while (svPtr->pd1[pd1cur++]);
goto next_line;
}
pd1cur += 6;
}
else if (strncmp ( (const char *) &svPtr->pd1[pd1cur], "...... ", 7) == 0) {
if (ExecLevel != 7) {
while (svPtr->pd1[pd1cur++]);
goto next_line;
}
pd1cur += 7;
}
else if (strncmp ( (const char *) &svPtr->pd1[pd1cur], "....... ", 8) == 0) {
if (ExecLevel != 8) {
while (svPtr->pd1[pd1cur++]);
goto next_line;
}
pd1cur += 8;
}
else if (strncmp ( (const char *) &svPtr->pd1[pd1cur], "........ ", 9) == 0) {
if (ExecLevel != 9) {
while (svPtr->pd1[pd1cur++]);
goto next_line;
}
pd1cur += 9;
}
else if (strncmp ( (const char *) &svPtr->pd1[pd1cur], "......... ", 10) == 0) {
if (ExecLevel != 10) {
while (svPtr->pd1[pd1cur++]);
goto next_line;
}
pd1cur += 10;
}
}
next_line_xecute:
pd1Last = pd1cur;
// svPtr->xpx = j = 1;
svPtr->xpx = 1;
// while ( (svPtr->xd[j++] = svPtr->pd1[pd1cur++]) != 0 );
// while ( svPtr->xd[j++] = svPtr->pd1[pd1cur++] );
to = &svPtr->xd[1];
from = &svPtr->pd1[pd1cur];
while ( *(to++) = *(from++) );
*to = 0;
pd1cur = from - svPtr->pd1;
// svPtr->xd[j] = 0;
// -----------------------------------------------------------------------------
//
// re-enter here for each new command on current line
// check for interrupt (crrlc)
// extract and de-code command word
//
// -----------------------------------------------------------------------------
next_cmnd: // continue line entry point
#ifdef NATIVE_STANDALONE
if ( !( ++PulseCount % @slice@ ) ) Mglobal(PULSE,tmp2,tmp3,svPtr); // deadlock preevntion
#endif
BuildLocal(-1,0,NULL,NULL,NULL); // stack cleaner
BuildGlobal(-1,0,NULL,NULL,NULL); // stack cleaner
while (1) {
if (svPtr->xd[svPtr->xpx] == 0 || svPtr->xpx >= STR_MAX)
if (forx > 0 && gosub[gsbx][3] == FOR) {
if (svPtr->ctrlc) {
svPtr->ctrlc = 0;
ernbr = 29;
goto err_call;
}
goto quit1;
}
else goto next_line;
if (svPtr->xd[svPtr->xpx] != ' ' && svPtr->xd[svPtr->xpx] != TAB) break;
svPtr->xpx++;
}
//--------------------
// decode command word
//--------------------
p2px = svPtr->xpx;
svPtr->t2 = svPtr->t0px = 0;
// if ( (icmnd = tolower (svPtr->xd[svPtr->xpx]) ) == CMMNT) {
// svPtr->xpx=STR_MAX;
// goto next_cmnd;
// }
icmnd = tolower (svPtr->xd[svPtr->xpx]);
while (isalpha (svPtr->xd[++svPtr->xpx])); // Ignore rest of word
if (svPtr->xd[svPtr->xpx] == ':') { // Postconditional
svPtr->xpx++;
if ((svPtr->ierr = parse_ (svPtr))) goto parse_err;
if (!atoi ( (const char *) &svPtr->pd1[svPtr->sdlim])) {
while (svPtr->xd[svPtr->xpx++] != 0) {
if (svPtr->xd[svPtr->xpx] == '"') {
svPtr->xpx++;
pc1:
while (svPtr->xd[svPtr->xpx] != '"' &&
svPtr->xd[svPtr->xpx] != 0) svPtr->xpx++;
svPtr->xpx++;
if (svPtr->xd[svPtr->xpx] == '"') {
svPtr->xpx++;
goto pc1;
}
}
if (svPtr->xd[svPtr->xpx] == ' ') {
goto next_cmnd;
}
}
svPtr->xpx--;
goto next_cmnd;
}
}
// -----------------------------------
// branch to correct command handler
// -----------------------------------
if (svPtr->xd[svPtr->xpx]) svPtr->xpx++; // post conditional return
switch (icmnd) { // go to command handler
case CMMNT:
case '/':
while (svPtr->xd[svPtr->xpx++]);
svPtr->xpx=STR_MAX;
goto next_cmnd; // comment command - do nothing
case FCN: // direct function execution
svPtr->xpx = p2px;
svPtr->t0px = 0;
svPtr->t2 = 1;
if ((svPtr->ierr = parse_ (svPtr))) goto parse_err;
svPtr->xpx++;
goto next_cmnd;
// vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
case BREAK: // non-standard use - end a FOR loop from a DO group
BreakFlag = 1;
goto quit;
// vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
case FILELOCK: // not meaningful - all files are locked.
if (svPtr->xd[svPtr->xpx] == ' ' || svPtr->xd[svPtr->xpx] == 0) {
goto next_cmnd;
}
char Lf; // type of lock
if (svPtr->xd[svPtr->xpx] == '-' || svPtr->xd[svPtr->xpx] == '+')
Lf=svPtr->xd[svPtr->xpx++];
else Lf=' ';
svPtr->t0px = 1;
if ((svPtr->ierr = parse_ (svPtr))) goto parse_err;
keyfix(&svPtr->v1d[1]);
strcpy((char *)tmp2, (char *) &svPtr->v1d[1]); // lock reference
strcpy((char *) dosave, "0"); // timeout
svPtr->tpx = 1;
if (svPtr->xd[svPtr->xpx + 1] == ':') {
svPtr->t2 = 1;
svPtr->xpx += 2;
if ((svPtr->ierr = parse_ (svPtr))) goto parse_err;
svPtr->xpx++;
j = atoi ( (const char *) &svPtr->pd1[svPtr->sdlim]);
strcpy((char *) dosave, (char *) &svPtr->pd1[svPtr->sdlim]); // timeout
svPtr->tpx = 0;
goto next_cmnd;
}
Mltoa(getpid(),tmp3); // process id
if (strcmp((const char *) makeLock((char *) tmp2, (char *) "1", (char *) tmp3, Lf, (char *) dosave),
(const char *) "1") == 0) svPtr->tpx=1;
else svPtr->tpx=0;
svPtr->LockDone=1;;
svPtr->xpx++;
goto next_cmnd;
// vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
case READ:
read_command:
if (svPtr->io != 5 && svPtr->in_file[svPtr->io] == NULL)
goto io_error;
#ifdef NATIVE_STANDALONE
Mglobal(PULSE,tmp2,tmp3,svPtr); // deadlock prevntion
PulseCount=0;
#endif
dirflg = 0;
if (svPtr->xd[svPtr->xpx] == '@') {
// indirect
svPtr->t0px = 1;
if ((svPtr->ierr = parse_ (svPtr))) goto parse_err;
}
if (svPtr->xd[svPtr->xpx] == '!' || svPtr->xd[svPtr->xpx] == '#') {
// carriage control
if (svPtr->xd[svPtr->xpx] != '#') i = 2;
else i = 1;
goto start_io;
}
if (svPtr->xd[svPtr->xpx] == '?') { // tab format
svPtr->t2 = 1;
svPtr->xpx--;
if ((svPtr->ierr = parse_ (svPtr))) goto parse_err;
j = atoi ( (const char *) &svPtr->pd1[svPtr->sdlim]);
i = 3;
goto start_io;
}
if (svPtr->xd[svPtr->xpx] == '"') { // text to be printed first
svPtr->t2 = 1;
if ((svPtr->ierr = parse_ (svPtr))) goto parse_err;
i = 4;
start_io:
inout (&svPtr->pd1[svPtr->sdlim], i, j, svPtr);
goto cont_read;
}
if (svPtr->xd[svPtr->xpx] == '*') { // direct mode
svPtr->xpx++;
dirflg = 1;
}
svPtr->t0px = 1; // extract variable name to be read
svPtr->setname[0] = 0;
if ((svPtr->ierr = parse_ (svPtr))) goto parse_err;
strcpy ( (char *) &vd[1], (const char *) &svPtr->v1d[1]);
//--------
// timeout
//--------
if (svPtr->xd[svPtr->xpx + 1] == ':') {
svPtr->t2 = 1;
svPtr->xpx += 2;
if ((svPtr->ierr = parse_ (svPtr))) goto parse_err;
j = atoi ( (const char *) &svPtr->pd1[svPtr->sdlim]);
svPtr->xpx--;
if (j <= 0) {
svPtr->xpx--;
svPtr->tpx = 0;
goto cont_read;
}
if (!dirflg) {
char timeout[64];
sprintf(timeout,"%d",j);
svPtr->tpx = TimeOut_getstr1(svPtr->io, &svPtr->pd1[svPtr->sdlim], timeout, 0);
}
else {
unsigned char i;
svPtr->tpx=DirectRead(svPtr->io, &i);
sprintf((char *) &svPtr->pd1[svPtr->sdlim],"%d",i);
}
goto store;
}
svPtr->hor[svPtr->io] = 0;
svPtr->ver[svPtr->io]++;
i = svPtr->io;
svPtr->sdlim = svPtr->pd1len + 2;
if (dirflg == 1 && svPtr->io == 5) {
unsigned char i;
svPtr->tpx=DirectRead(svPtr->io, &i);
sprintf((char *) &svPtr->pd1[svPtr->sdlim],"%d",i);
}
else {
svPtr->tpx = getstr2 (i, &svPtr->pd1[svPtr->sdlim], svPtr);
if (svPtr->tpx >= 0) svPtr->tpx = 1;
else svPtr->tpx = 0;
}
store:
retz = READ;
goto lhsref;
cont_read:
svPtr->xpx++;
dirflg = 0;
if (svPtr->xd[svPtr->xpx] == ',') svPtr->xpx++;
if (svPtr->xd[svPtr->xpx] == ' ' ||
svPtr->xd[svPtr->xpx] == 0 ||
svPtr->xd[svPtr->xpx] == TAB) goto next_cmnd;
goto read_command;
// vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
case FILEOPEN:
openf:
svPtr->t2 = 1;
if ((svPtr->ierr = parse_ (svPtr))) goto parse_err;
k = atoi ( (const char *) &svPtr->pd1[svPtr->sdlim]);
if (k <= 0 || k >= 5) goto file_error;
if (svPtr->in_file[k] != NULL ||
svPtr->out_file[k] != NULL) goto file_error;
if (svPtr->xd[svPtr->xpx] != ':') goto arg_list_error;
svPtr->xpx++;
svPtr->t2 = 1;
if ((svPtr->ierr = parse_ (svPtr))) goto parse_err;
for (i = 0; svPtr->pd1[svPtr->sdlim + i] != 0 && svPtr->pd1[svPtr->sdlim + i] != ','; i++)
tmp2[i] = svPtr->pd1[svPtr->sdlim + i];
if (svPtr->pd1[svPtr->sdlim + i] != ',') {
for (i = 0; svPtr->pd1[svPtr->sdlim + i] != 0 && svPtr->pd1[svPtr->sdlim + i] != '/'; i++)
tmp2[i] = svPtr->pd1[svPtr->sdlim + i];
}
tmp2[i++] = 0;
if (strcasecmp ( (const char *) &svPtr->pd1[svPtr->sdlim + i], "old") == 0 ) New = 0;
else if (strcasecmp ( (const char *) &svPtr->pd1[svPtr->sdlim + i], "new") == 0 ) New = 1;
else if (strcasecmp ( (const char *) &svPtr->pd1[svPtr->sdlim + i], "append") == 0) New = 2;
else goto arg_list_error;
if (New == 1) { /* output new */
if ((svPtr->out_file[k] = fopen ( (const char *) tmp2, "w")) == NULL) svPtr->tpx = 0;
else svPtr->tpx = 1;
goto opn1;
}
if (New == 2) { /* output append */
if ((svPtr->out_file[k] = fopen ( (const char *) tmp2, "a")) == NULL) svPtr->tpx = 0;
else svPtr->tpx = 1;
goto opn1;
}
if ((svPtr->in_file[k] = fopen ( (const char *) tmp2, "r")) == NULL) svPtr->tpx = 0;
else svPtr->tpx = 1;
opn1:
if (svPtr->xd[++svPtr->xpx] != ',') goto next_cmnd;
svPtr->xpx++;
goto openf;
// vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
case ZCMDS:
p2px++;
if (svPtr->xd[p2px] <= 90) svPtr->xd[p2px] += 32; // lower case
if (svPtr->xd[p2px] == 'g') { // zg
svPtr->v1d[0] = 0;
Mglobal (INIT, svPtr->v1d, svPtr->bd, svPtr);
goto next_cmnd;
}
if (svPtr->xd[p2px] == 'a') {
svPtr->gpad = 0;
goto next_cmnd;
}
if (svPtr->xd[p2px] == 'n') {
svPtr->gpad = 1;
goto next_cmnd;
}
if (tolower(svPtr->xd[p2px]) == 'h') { // zhalt
svPtr->t2 = 1;
if ((svPtr->ierr = parse_ (svPtr))) goto parse_err;
j = atoi ( (char *) &svPtr->pd1[svPtr->sdlim]);
printf("\n");
Mglobal(CLOSE,tmp2,tmp3,svPtr); /* Close Globals */
fflush(NULL);
_exit(j);
}
if (svPtr->xd[p2px] == 'e') { // zexit
return 1;
abrt:
#ifdef TERMINATE_ON_ERROR
if (svPtr->NOERR) {
svPtr->NOERR=-1;
if (gsbx <= 0) goto next_cmnd;
goto quit1;
}
printf("\n");
Mglobal(CLOSE,tmp2,tmp3,svPtr); /* Close Globals */
fflush(NULL);
_exit(ernbr);
#else
return 99;
#endif
}
goto next_line; // all others
// vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
case IF:
if (svPtr->xd[svPtr->xpx] == ' ') { // no argument form
svPtr->xpx++;
if (svPtr->tpx) goto next_cmnd;
svPtr->xpx = STR_MAX;
goto next_cmnd;
}
next_if_arg:
svPtr->t2 = 1;
if ((svPtr->ierr = parse_ (svPtr))) goto parse_err;
// if (numcomp ( (unsigned char *) &svPtr->pd1[svPtr->sdlim], (unsigned char *) "0") == 0) {
if ( ! atoi ( ( char *) &svPtr->pd1[svPtr->sdlim] ) ) {
svPtr->tpx = 0;
svPtr->xpx = STR_MAX;
goto next_cmnd;
}
svPtr->tpx = 1;
if (svPtr->xd[svPtr->xpx] == ',') {
svPtr->xpx++;
goto next_if_arg;
}
goto next_cmnd;
// vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
case WRITE:
if (svPtr->io != 5 && svPtr->out_file[svPtr->io] == NULL) goto io_error;
writeproc:
if (svPtr->xd[svPtr->xpx] == '!' || svPtr->xd[svPtr->xpx] == '#') {
// new line or page*/
i = 1;
if (svPtr->xd[svPtr->xpx] != '#') i = 2;
svPtr->xpx++;
goto iosub;
}
if (svPtr->xd[svPtr->xpx] == '*') { // "*" output
svPtr->xpx++;
svPtr->t2 = 1;
if ((svPtr->ierr = parse_ (svPtr))) goto parse_err;
svPtr->pd1[svPtr->sdlim] = atoi ( (const char *) &svPtr->pd1[svPtr->sdlim]);
svPtr->pd1[svPtr->sdlim + 1] = 0;
putchar (svPtr->pd1[svPtr->sdlim]);
i = 4;
goto iosub1;
}
if (svPtr->xd[svPtr->xpx] == '?') { // tab
svPtr->t2 = 1;
svPtr->xpx++;
if ((svPtr->ierr = parse_ (svPtr))) goto parse_err;
j = atoi ( (const char *) &svPtr->pd1[svPtr->sdlim]);
i = 3;
goto iosub;
}
svPtr->t2 = 1;
if ((svPtr->ierr = parse_ (svPtr))) goto parse_err;
i = 4;
iosub:
inout (&svPtr->pd1[svPtr->sdlim], i, j, svPtr);
iosub1:
if (svPtr->xd[svPtr->xpx] == ',') {
svPtr->xpx++;
goto writeproc;
}
if (svPtr->xd[svPtr->xpx] == 0 ||
svPtr->xd[svPtr->xpx] == ' ' ||
svPtr->xd[svPtr->xpx] == TAB) goto next_cmnd;
goto writeproc;
// vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
case JOB:
if (fork() != 0 ) goto next_line; // we are parent - continue executing - globals remain open
// treat argument as GOTO otherwise - drop thru
//*******************************************
// Close Globals or Disconnect from SQL server