Annotation of freem/src/frmgbl.c, revision 1.11
1.1 snw 1: /*
1.11 ! snw 2: * $Id: frmgbl.c,v 1.10 2025/04/10 01:24:38 snw Exp $
1.1 snw 3: * freem global C variables
4: *
5: *
1.4 snw 6: * Author: Serena Willis <snw@coherent-logic.com>
1.1 snw 7: * Copyright (C) 1998 MUG Deutschland
1.5 snw 8: * Copyright (C) 2020, 2025 Coherent Logic Development LLC
1.1 snw 9: *
10: *
11: * This file is part of FreeM.
12: *
13: * FreeM is free software: you can redistribute it and/or modify
14: * it under the terms of the GNU Affero Public License as published by
15: * the Free Software Foundation, either version 3 of the License, or
16: * (at your option) any later version.
17: *
18: * FreeM is distributed in the hope that it will be useful,
19: * but WITHOUT ANY WARRANTY; without even the implied warranty of
20: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21: * GNU Affero Public License for more details.
22: *
23: * You should have received a copy of the GNU Affero Public License
24: * along with FreeM. If not, see <https://www.gnu.org/licenses/>.
25: *
1.6 snw 26: * $Log: frmgbl.c,v $
1.11 ! snw 27: * Revision 1.10 2025/04/10 01:24:38 snw
! 28: * Remove C++ style comments
! 29: *
1.10 snw 30: * Revision 1.9 2025/04/03 01:41:02 snw
31: * New features frozen; prepare 0.63.0-rc1
32: *
1.9 snw 33: * Revision 1.8 2025/04/02 03:02:42 snw
34: * Stop requiring users to pass -e to fmadm when -u or -g are passed
35: *
1.8 snw 36: * Revision 1.7 2025/04/01 16:37:12 snw
37: * Configure DEFAULT environment the same as others, and set permissions/ownership directly in fmadm configure. Add env.conf file as a centralized configuration listing all environments.
38: *
1.7 snw 39: * Revision 1.6 2025/03/24 04:05:36 snw
40: * Replace crlf with frm_crlf to avoid symbol conflict with readline on OS/2
41: *
1.6 snw 42: * Revision 1.5 2025/03/09 19:14:25 snw
43: * First phase of REUSE compliance and header reformat
44: *
1.5 snw 45: *
46: * SPDX-FileCopyrightText: (C) 2025 Coherent Logic Development LLC
47: * SPDX-License-Identifier: AGPL-3.0-or-later
1.1 snw 48: **/
49:
50: /* needed if byte data are to be interpreted as unsigned integer */
51: #include <stdlib.h>
52: #include <setjmp.h>
53: #include <signal.h>
54: #include <stdio.h>
55: #include "mpsdef0.h"
56: #include <fcntl.h>
57: #include <unistd.h>
58: #include <string.h>
59: #include <sys/types.h>
60: #include <sys/wait.h>
61: #include "transact.h"
62: #include "locktab.h"
63: #include <errno.h>
64:
65: #ifdef LIBFREEM
66: # include "errmsg.h"
67: #endif
68:
69: #define UNSIGN(A) ((A)&0377)
70:
71: #define g_EOL 30
72: #define POINT 28
73: #define MINUS 26
74:
75: #define ROOT 0L
76: /* length of blocks. status bytes defined as offset to blocklength */
77: #define DATALIM (BLOCKLEN-11)
78: #define LLPTR (BLOCKLEN-10)
79: #define NRBLK LLPTR
80: #define RLPTR (BLOCKLEN- 6)
81: #define FREE RLPTR
82: #define BTYP (BLOCKLEN- 3)
83: #define OFFS (BLOCKLEN- 2)
84:
85: #define EMPTY 0
86: #define FBLK 1
87: #define POINTER 2
88: #define BOTTOM 6
89: #define DATA 8
90:
91: #define PROTECT 30
92:
93:
94: #ifndef SYSFIVE
95: #define FreeM_timezone -3600
96: #else
97:
98: #ifdef __CYGWIN__
99: #define FreeM_timezone _timezone
100: #else
101: long FreeM_timezone;
102: #endif /* __CYGWIN__ */
103:
104: #endif /* SYSFIVE */
105:
106: #if defined(__CYGWIN__)
107: # define FreeM_timezone _timezone
108: #endif
109:
110: /* mumps commands */
111: #define BREAK 'b'
112: #define CLOSE 'c'
113: #define DO 'd'
114: #define DO_BLOCK 2
115: #define ELSE 'e'
116: #define FOR 'f'
117: #define GOTO 'g'
118: #define HA 'h'
119: #define HALT '0'
120: #define HANG '1'
121: #define IF 'i'
122: #define JOB 'j'
123: #define KILL 'k'
124: #define LOCK 'l'
125: #define NEW 'n'
126: #define OPEN 'o'
127: #define QUIT 'q'
128: #define READ 'r'
129: #define SET 's'
130: #define USE 'u'
131: #define VIEW 'v'
132: #define WRITE 'w'
133: #define XECUTE 'x'
134: #define ZBREAK 'B'
135: #define ZGO 'G'
136: #define ZHALT 'H'
137: #define ZINSERT 'I'
138: #define ZJOB 'J'
139: #define ZLOAD 'L'
140: #define ZNEW 'N'
141: #define ZPRINT 'P'
142: #define ZQUIT 'Q'
143: #define ZREMOVE 'R'
144: #define ZSAVE 'S'
145: #define ZTRAP 'T'
146: #define ZWRITE 'W'
147: #define PRIVATE SP
148:
149: #if defined(HAVE_MWAPI_MOTIF)
150: # include <Xm/Xm.h>
151: XtAppContext mwapi_context;
152: #endif
153:
154: short run_daemon = FALSE;
155: short nofork = FALSE;
156: char *pid_file_path;
157: int pid_fd;
158:
159: /* USING and WITH */
160: char i_using[STRLEN] = {'\201'};
161: char i_with[STRLEN] = {'\201'};
162:
163: /* common definitions for all mumps modules */
164: /* same as external definition in include_file mpsdef */
165:
166: extern int errno; /* external error code for systemcalls */
167:
168: int m_argc; /* arguments count */
169: char **m_argv; /* arguments string */
170: char **m_envp; /* environment pointer */
171:
172: short frm_throw_all_errors = 1;
173:
174: /* glvn size parameters */
175: union four_fl {
176: long unsigned all;
177: char one[4];
178: } glvnflag; /* [0] unique name chars 0=no limit */
179:
180: /* [1] case sensitivity flag 0=sensitive */
181: /* [2] max. name+subscripts 0=no limit */
182: /* [3] max. length of a subscript 0=no limit */
183: int libflag = FALSE; /* running as library? */
184: int lonelyflag = FALSE; /* single user flag */
185: int lowerflag = TRUE; /* lowercase everywhere flag */
186: int killerflag = TRUE; /* SIGTERM handling flag */
187: int huperflag = TRUE; /* SIGHUP handling flag */
188: int s_fun_flag = TRUE; /* VIEW 70: ZSORT/ZSYNTAX flag */
189: int n_fun_flag = TRUE; /* VIEW 71: ZNEXT/ZNAME flag */
190: int p_fun_flag = TRUE; /* VIEW 72: ZPREVIOUS/ZPIECE flag */
191: int d_fun_flag = TRUE; /* VIEW 73: ZDATA/ZDATE flag */
192: int zjobflag = TRUE; /* VIEW 79: old ZJOB vs. new ZJOB flag */
193: int eightbit = TRUE; /* VIEW 80: 7 vs. 8 bit flag */
194: int PF1flag = FALSE; /* VIEW 81: PF1 flag */
195: int ordercounter = 0; /* VIEW 82: order counter */
196: int etxtflag = FALSE; /* VIEW 83: text in $ZE flag */
197: char lvndefault[256] = "\201"; /* VIEW 89: UNDEF lvn default */
198: char gvndefault[256] = "\201"; /* VIEW 90: UNDEF gvn default */
199: char exfdefault[256] = "\201"; /* VIEW 91: missing QUIT expr default */
200: int typemmflag = FALSE; /* VIEW 92: EUR2DEM: type mismatch error */
201: int namespace = 0; /* VIEW 200: namespace index */
202: int config = 0; /* VIEW 201: configuration index */
203: char WHR[12][4] = { /* names of currencies */
204: "\201",
205: "EUR\201",
206: "ATS\201",
207: "BFR\201",
208: "DEM\201",
209: "ESP\201",
210: "FMK\201",
211: "FRF\201",
212: "IEP\201",
213: "ITL\201",
214: "NLG\201",
215: "PTE\201"
216: };
217:
218: char EUR2WHR[12][9] = { /* conversion factors EUR to ... */
219: "\201", /* dont care */
220: "1\201", /* to EUR */
221: "13.7603\201", /* to ATS */
222: "40.3399\201", /* to BFR */
223: "1.95583\201", /* to DEM (DM) */
224: "166.386\201", /* to ESP */
225: "5.94573\201", /* to FMK */
226: "6.55957\201", /* to FRF (FF) */
227: ".787564\201", /* to IEP */
228: "1936.27\201", /* to ITL */
229: "2.20371\201", /* to NLG */
230: "200.482\201" /* to PTE */
231: };
232:
233: long v93 = 1; /* VIEW 93: ASCII rule default */
234: char v93a[NO_V93][2560] = {
235: /* ASCII */
236: " :, :!,A:a,B:b,C:c,D:d,E:e,F:f,G:g,H:h,I:i,J:j,K:k,L:l,M:m,N:n,O:o,P:p,Q:q,R:r,S:s,T:t,U:u,V:v,W:w,X:x,Y:y,Z:z\201",
237: /* B - BELGIAN */
238: " :, :!,@:a,\\:c,{:e,}:e,\
239: A:a,B:b,C:c,D:d,E:e,F:f,G:g,H:h,I:i,J:j,K:k,L:l,M:m,N:n,O:o,P:p,Q:q,R:r,S:s,T:t,U:u,V:v,W:w,X:x,Y:y,Z:z\201,\200:e",
240: /* D - GERMAN */
241: " \001\002 \001\002!\001\002\042\001\002#\001\002$\001\002%\001\002&\001\002\
242: '\001\002(\001\002)\001\002*\001\002+\001\002,\001\002-\001\002.\001\002\
243: /\001\002:\001\002;\001\002<\001\002=\001\002>\001\002?\001\002@\001\002\
244: ^\001\002_\001\002`\001\002A\001a\002B\001b\002C\001c\002D\001d\002E\001e\002\
245: F\001f\002G\001g\002H\001h\002I\001i\002J\001j\002K\001k\002L\001l\002\
246: M\001m\002N\001n\002O\001o\002P\001p\002Q\001q\002R\001r\002S\001s\002\
247: T\001t\002U\001u\002V\001v\002W\001w\002X\001x\002Y\001y\002Z\001z\002\
248: {\001ae\002[\001ae\002|\001oe\002\134\001oe\002}\001ue\002]\001ue\002\
249: ~\001ss\002\200\001e\002\201",
250: /* DK - DANISH */
251: " :, :!,{:ae,|:oe,}:au,~:ue,\
252: A:a,B:b,C:c,D:d,E:e,F:f,G:g,H:h,I:i,J:j,K:k,L:l,M:m,N:n,O:o,P:p,Q:q,R:r,S:s,T:t,U:u,V:v,W:w,X:x,Y:y,Z:z,\
253: [:ae,\\:oe,]:ao,^:ue,\200:e\201",
254: /* E - SPANISH */
255: " :, :!,|:n,}:c,ll:l,\
256: A:a,B:b,C:c,D:d,E:e,F:f,G:g,H:h,I:i,J:j,K:k,L:l,M:m,N:n,O:o,P:p,Q:q,R:r,S:s,T:t,U:u,V:v,W:w,X:x,Y:y,Z:z,\200:e,\
257: \\:n,LL:l\201",
258: /* F - FRENCH */
259: " :, :!,\\:c,{:e,|:u,}:e,\
260: A:a,B:b,C:c,D:d,E:e,F:f,G:g,H:h,I:i,J:j,K:k,L:l,M:m,N:n,O:o,P:p,Q:q,R:r,S:s,T:t,U:u,V:v,W:w,X:x,Y:y,Z:z,\200:e,\201",
261: /* I - ITALIAN */
262: " :, :!,\\:c,]:e,`:u,{:a,|:o,}:e,~:i,\
263: A:a,B:b,C:c,D:d,E:e,F:f,G:g,H:h,I:i,J:j,K:k,L:l,M:m,N:n,O:o,P:p,Q:q,R:r,S:s,T:t,U:u,V:v,W:w,X:x,Y:y,Z:z,\200:e,\201",
264: /* S - SWEDISH */
265: " :, :!,`:e,{:ae,|:oe,}:ao,~:ue,\
266: A:a,B:b,C:c,D:d,E:e,F:f,G:g,H:h,I:i,J:j,K:k,L:l,M:m,N:n,O:o,P:p,Q:q,R:r,S:s,T:t,U:u,V:v,W:w,X:x,Y:y,Z:z,\
267: @:e,[:ae,\\:oe,]:ao,~:ue,\200:e,\201"
268: };
269:
270:
271: char glo_prefix[MONTH_LEN] = "^\201"; /* VIEW 96: global prefix */
272: char glo_ext[MONTH_LEN] = "\201"; /* VIEW 97: global postfix */
273: char rou_ext[MONTH_LEN] = ".m\201"; /* VIEW 98: routine extention */
274: long tzoffset = 0L; /* VIEW 99: timer offset */
275: int v100 = 0; /* VIEW 100: return value of kill */
276: char l_o_val[256] = "\201"; /* VIEW 110: local $o/$q data value */
277: char g_o_val[256] = "\201"; /* VIEW 111: global $o/$q data value */
278: int zsavestrategy = TRUE; /* VIEW 133: remember ZLOAD directory on ZSAVE */
279:
280: /* vars for screen save/restore */
281: struct vtstyp *screen = NULL; /* active screen */
282: short jour_flag = 0; /* journal flag 0/1/-1 */
283:
284: /* trace vars for global module */
285: unsigned long traceblk[TRLIM]; /* trace stack - block numbers */
286: short traceadr[TRLIM]; /* - status */
287: short trx; /* - stack pointer */
288: char compactkey[256]; /* internal form of key in global.c */
289:
290: short mcmnd; /* mumps command letter */
291: short arg; /* stack pointer for expr.c */
292: char *argstck[PARDEPTH + 1]; /* stack of pointers to */
293:
294: /* intermediate results */
295:
296: long ordercnt = 0L; /* repeater for $order/$query */
297: short setpiece = FALSE; /* TRUE: set$piece executing */
298: short setop = 0; /* SET op flag */
299: char rou_name[256] =
300: {EOL}; /* $T(+0)/$ZN routine name */
301: char *namstck; /* routine name stack */
302: char *namptr; /* routine name stack pointer */
303: char *framstck; /* DO_frame stack */
304: char *dofrmptr; /* DO_frame stack pointer */
305: char zb[40] = "\201"; /* $ZB last ESC_sequence */
306: char zerror[300] = "\201"; /* $ZE last error */
307: short DSM2err = FALSE; /* enable normal error processing */
308: short nesterr = 0; /* nesterr and callerr contain info */
309: char callerr[NESTLEVLS + 1][40]; /* about call situation at error */
310:
311: char stack0[256] = "\201";
312:
313: char zmc[128] = "\
314: \000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\
315: \020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037\177\201";
316:
317: /* $ZMC loadable match 'controls' */
318: char zmn[128] = "0123456789\201"; /* $ZMN loadable match 'numerics' */
319:
320: /* $ZMP loadable match 'punctuation' */
321: char zmp[128] = " !\042#$%&'()*+,-./:;<=>?@^_`\201";
322:
323: /* $ZML loadable match 'lowercase' */
324: char zml[128] = "abcdefghijklmnopqrstuvwxyz{|}~\201";
325:
326: /* $ZMU loadable match 'uppercase' */
327: char zmu[128] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]\201";
328:
329: short zerr = OK; /* $ZE numeric error code */
330: char zloc[256] = "\201"; /* $ZL last local reference */
331: char zref[256] = "\201"; /* $ZR last global reference */
332: short nakoffs = 0; /* offset to naked reference */
333: char zfunkey[44][FUNLEN]; /* $ZF function key */
334:
335: typedef struct frm_devstat {
336: short mdc_err;
337: short frm_err;
338: char err_txt[80];
339: } frm_devstat;
340:
341: frm_devstat devstat[MAXDEV + 1]; /* channel statuses for $DEVICE */
342:
343: short xpos[MAXDEV + 1]; /* $X-vector */
344: short ypos[MAXDEV + 1]; /* $Y-vector */
1.6 snw 345: short frm_crlf[MAXDEV + 1]; /* CR/LF flag vector */
1.1 snw 346: short fm_nodelay[MAXDEV + 1]; /* nodelay flag vector */
347:
348: int ESCflag[MAXDEV + 1] =
349: {0, 0, 0, 0, 0}; /* ESC flag */
350:
351: short RightMargin = 0; /* Output Margin. Default no */
352:
353: /* automatic CR/LF */
354: short InFieldLen = 255; /* Input Field length Def: 255 char */
355: long DSW = BIT2 + BIT21; /* Device Status word (Terminal) */
356: char LineTerm[32] = "\012\015\201"; /* Input Line Terminator chars */
357: char BrkKey = 3; /* <INTERRUPT> key Def: CTRL/C */
358: char ug_buf[MAXDEV + 1][256]; /* ungetc-buffers */
359: char devopen[MAXDEV + 1] =
360: {0, 0, 0, 0, 0}; /* 0 not open */
361:
362: /* 'r' input */
363: /* 'w' or 'a' output */
364:
365: /* names of IO devices */
366: char dev[MAXDEV + 1][40] = {
367: " ", /* HOME */
368: "/usr/tmp/mout.1/a\201", /* dev 1 */
369: "/usr/tmp/mout.2/a\201", /* dev 2 */
370: "/usr/tmp/mout.3/a\201", /* dev 3 */
371: "/usr/tmp/mout.4/a\201" /* dev 4 */
372: };
373:
374: char G0I[MAXDEV + 1][257]; /* G0 input translation table */
375: char G0O[MAXDEV + 1][257]; /* G0 output translation table */
376: char G1I[MAXDEV + 1][257]; /* G1 input translation table */
377: char G1O[MAXDEV + 1][257]; /* G1 output translation table */
378:
379: FILE *opnfile[MAXDEV + 1];
380: char act_oucpath[MAXDEV + 1][40] = {"\201", "\201", "\201", "\201", "\201"};
381: char sq_modes[MAXDEV + 1];
382:
383: short olddes[NO_GLOBLS]; /* filedescr of open global files */
384: char oldfil[NO_GLOBLS][1024]; /* names of open global files */
385: long g_ages[NO_GLOBLS]; /* last access of global files */
386: short usage[NO_GLOBLS]; /* usage count of global files */
387: short inuse = 0; /* file in use */
388:
389: int lio_mode = -1;
390: short io = HOME; /* $IO */
391: short test = FALSE; /* $TEST */
392: short pattrnflag = FALSE; /* incomplete match flag */
393: char pattrnchar = EOL; /* incomplete match flag supplement */
394: int zsystem = 0; /* $ZSYSTEM return status of UNIX call */
395: short zcc = FALSE; /* $ZC (ControlC-Flag) */
396:
397: char *rouptr; /* pointer to begin of routine */
398: char *roucur; /* cursor into routine */
399: char *rouend; /* pointer to end of pgm */
400: char *rouins; /* pointer for direct mode insert */
401: short breakon = ENABLE; /* BREAK enable/disable-flag */
402: short zbreakon = DISABLE; /* ZBREAK enable/disable-flag */
403: short zbflag = FALSE; /* 'ZBREAK from terminal'-flag */
404: short zprecise = 100; /* $ZPRECISION of arithmetic */
405: char fp_conversion[10]; /* sprintf conversion constant for ieee754 support */
406: long nrandom; /* random number seed */
407: long ran_a = 24298L; /* random number parameter a */
408: long ran_b = 99991L; /* random number parameter b */
409: long ran_c = 199017L; /* random number parameter c */
410:
411: short usermode = 1; /* 0=user mode 1=programmer mode */
412: int restricted_mode = FALSE; /* TRUE=restricted FALSE=unrestricted */
413: short demomode = FALSE; /* 0=no demo 1=demo mode */
414: int d0char = DEL; /* demomode ouput character */
415: int d1char = CAN; /* demomode '!' character */
416: short cset = FALSE; /* 0=mumps set 1='C' set flag */
417:
418: /* startup flags */
419: int hardcopy = DISABLE; /* hardcopy flag */
420: int frm_filter = FALSE; /* filter flag */
421: int noclear = FALSE; /* noclear flag */
422: int standard = D_FREEM; /* default dialect */
423: int quiet_mode = FALSE; /* quiet mode */
424: char config_file[4096]; /* path to configuration file */
1.7 snw 425: char env_config_file[4096]; /* path to environment config file */
426: char env_user[255];
427: char env_group[255];
1.9 snw 428: char env_enabled[10];
1.1 snw 429: char shm_env[255]; /* shared memory environment */
430:
431: short fp_mode = 0; /* set to 0 for fixed-point math, 1 for IEEE754 floating point */
432: short en_revstrf = 1; /* enable reverse forms of string intrinsics */
433:
434: short ierr; /* immediate error status */
435: short deferred_ierr; /* deferred error status (after returning from a private routine) */
436: char err_suppl[255]; /* supplemental information about an error */
437:
438: long PSIZE = DEFPSIZE; /* size of 'partition' */
439: char *mbpartition; /* memory-backed globals partition */
440: short writing_mb = FALSE;
441: char *partition; /* partition (symbol table) */
442: long symlen = DEFPSIZE; /* 'lower' bound of symbol table */
443: unsigned long alphptr[128] = /* pointers into symbol table */
444: {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
445: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
446: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
447: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
448: char *apartition; /* alternate partition */
449: long asymlen = DEFPSIZE; /* 'lower' bound of symbol table */
450: unsigned long aalphptr[128] = /* pointers into symbol table */
451: {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
452: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
453: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
454: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
455:
456: short autopsize = TRUE; /* automatic increase of PSIZE */
457: long svnlen = DEFUDFSVSIZ; /* 'lower' bound of udf_svn_tab */
458: long UDFSVSIZ = DEFUDFSVSIZ; /* size of userdef special var tab. */
459: char *svntable; /* udf special variable table */
460: unsigned long svnaptr[128] = /* pointers into udf_svn_tab */
461: {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
462: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
463: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
464: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
465:
466: short autousize = TRUE; /* automatic increase of UDFSVSIZ */
467: long NO_OF_RBUF = DEFNO_OF_RBUF; /* number of routine buffers */
468: long PSIZE0 = DEFPSIZE0; /* size of routine buffers */
469: short autorsize = TRUE; /* automatic increase of PSIZE0 */
470: short aliases = 0; /* aliases pointer */
471: char ali[2000]; /* aliases table */
472: long v22ptr = 0L; /* view 22 aliases pointer */
473: char *v22ali; /* view 22 aliases field */
474: long v22size = 0L; /* current size of aliases field */
475:
476:
477: long NSIZE = DEFNSIZE; /* size of newstack */
478: char *newstack; /* stack for NEWed variables */
479: char *newptr; /* pointer to NEW stack */
480: char *newlimit; /* pointer to NEW stack end */
481:
482: short nstx = 0; /* nest stack: */
483: short nestc[NESTLEVLS + 1]; /* - command (DO...) */
484: char *nestp[NESTLEVLS + 1]; /* - cmdptr */
485: char *nestn[NESTLEVLS + 1]; /* - namptr */
486: long nestr[NESTLEVLS + 1]; /* - roucur */
487: char *nestnew[NESTLEVLS + 1]; /* - newptr */
488: short neste[NESTLEVLS + 1]; /* - was this frame entered as the result of an error? */
489: short nestlt[NESTLEVLS + 1]; /* stack $T / stack levelcount */
490: short brkstk[NESTLEVLS + 1]; /* stack for BREAK information */
491:
492: char ztrap[NESTLEVLS + 2][ZTLEN]; /* $ZTRAP to be xecuted on error */
493:
494:
495: char *s; /* pointer to symlen_offset */
496: char *argptr; /* pointer to beg of tmp-storage */
497:
498: char code[512] =
499: {EOL, EOL}; /* currently interpreted code */
500: char *codptr = code; /* pointer within code[] */
501:
502: char dosave[20]; /* in a FOR range save DO label */
503: char *xdosave;
504:
505: int errfunlvl = 0; /* avoid wrong error message in $$FUN */
506: short repQUIT = 0; /* QUIT repeater */
507:
508: char varnam[256]; /* variable/array/function name */
509: char varerr[256] =
510: {EOL}; /* reference in error message */
511: char *buff; /* routine buffer pool */
512: char pgms[MAXNO_OF_RBUF][40]; /* names of alt.pgms */
513: long ages[MAXNO_OF_RBUF]; /* last call to this pgm */
514: char *ends[MAXNO_OF_RBUF]; /* saved rouend-pointer */
515: char path[MAXNO_OF_RBUF][256]; /* directory where routine was loaded */
516: rtn_flags rbuf_flags[MAXNO_OF_RBUF]; /* per-routine flags */
517:
518: char glopath[PATHLEN]; /* path to access globals */
519: char rou0path[PATHLEN]; /* routine access with DO,GOTO,JOB */
520: char rou1path[PATHLEN]; /* routine access with ZL,ZS */
521: char gloplib[PATHLEN]; /* path to access %globals */
522:
523: char gbl_u_engine[255]; /* user global engine */
524: char gbl_s_engine[255]; /* system global engine */
525: char loc_engine[255]; /* local engine */
526:
527: unsigned long int bdb_flush_threshold;
528:
529: char rou0plib[PATHLEN]; /* %routine path (DO..) */
530: char rou1plib[PATHLEN]; /* %routine path (ZL..) */
531: char oucpath[PATHLEN] = "\201"; /* OPEN/USE/CLOSE path */
532: char zargdefname[PATHLEN]= "%\201"; /* default varname for Z-commands */
533: FILE *jouraccess; /* dto. filedes */
534: char curdir[256] = "."; /* current directory */
535:
536: char startuprou[PATHLEN] = "\201"; /* start up routine from cmdline*/
537:
538: char zcommds[256] =
1.8 snw 539: " za zas zb zd zg zh zi zj zl zn zp zq zr zs zt zwr zbreak \
1.1 snw 540: zgo zhalt zinsert zjob zload znamespace zprint zquit zremove zsave ztrap zwrite \201"; /* intrinsic z-commands */
541: char zfunctions[256] = /* intrinsic z-functions */
542: " zb zc zd ze zh zht zk zl zm zn zo zp zr zs zt zboolean zcall zcr zcrc zdata zdate zedit zhorolog \
543: zkey zlength zlsd zname znext zorder zpiece zprevious zreplace zsyntax zsort ztime \201";
544: char zsvn[256] = /* intrinsic z-special variables */
545: " za zb zc zd ze zf zh zi zj zl zmc zmn zmp zma zml zmu zme zn zo zp zs zt zu zv \
546: zcontrolc zdate zerror zname zhorolog zinrpt zjob zlocal zorder zprecision zsystem ztime ztr ztrap zuuid zut zversion \201";
547: char brkaction[256] = "\201"; /* action in case of BREAK */
548: pid_t father = 0; /* JOB-ID of father process */
549: char jour_hostid[256];
550: /* date types parameters */
551: char month[NO_DATETYPE][12][MONTH_LEN] = {
552: {"01\201", "02\201", "03\201", "04\201", "05\201", "06\201", "07\201", "08\201", "09\201", "10\201", "11\201", "12\201"},
553: {"01\201", "02\201", "03\201", "04\201", "05\201", "06\201", "07\201", "08\201", "09\201", "10\201", "11\201", "12\201"},
554: {"JAN\201", "FEB\201", "MAR\201", "APR\201", "MAY\201", "JUN\201", "JUL\201", "AUG\201", "SEP\201", "OCT\201", "NOV\201", "DEC\201"},
555: {"01\201", "02\201", "03\201", "04\201", "05\201", "06\201", "07\201", "08\201", "09\201", "10\201", "11\201", "12\201"},
556: {"1\201", "2\201", "3\201", "4\201", "5\201", "6\201", "7\201", "8\201", "9\201", "10\201", "11\201", "12\201"},
557: {"1\201", "2\201", "3\201", "4\201", "5\201", "6\201", "7\201", "8\201", "9\201", "10\201", "11\201", "12\201"},
558: {"1\201", "2\201", "3\201", "4\201", "5\201", "6\201", "7\201", "8\201", "9\201", "10\201", "11\201", "12\201"},
559: {"01\201", "02\201", "03\201", "04\201", "05\201", "06\201", "07\201", "08\201", "09\201", "10\201", "11\201", "12\201"}
560: };
561: char dat1char[NO_DATETYPE][MONTH_LEN] = /* date 1st delimiter */
562: {"/\201", "/\201", " \201", "/\201", ".\201", ".\201", ".\201", ".\201"};
563: char dat2char[NO_DATETYPE][MONTH_LEN] = /* date 2nd delimmiter */
564: {"/\201", "/\201", " \201", "/\201", ".\201", ".\201", ".\201", ".\201"};
565: char dat3char[NO_DATETYPE] =
566: {'0', '0', '0', '0', '\201', '\201', '\201', '0'}; /* date day justify char */
567: char dat4flag[NO_DATETYPE] =
568: {2, 1, 0, 0, 0, 0, 0, 0}; /* 0=DMY, 1=MDY, 2=YMD */
569: char dat5flag[NO_DATETYPE] =
570: {0, 1, 1, 1, 1, 1, 0, 1}; /* suppress century digits */
571: long int datGRbeg[NO_DATETYPE] =
572: {578101L, 578101L, 578101L, 578101L, 578101L, 578101L, 578101L, 578101L};
573:
574: /* first day of gregorian calendar 15-OCT-1582 ($H+672411) */
575: int datetype = 0; /* type for $zd special variable */
576:
577: char tim1char[NO_TIMETYPE] =
578: {':', ':'}; /* time 1st delimiter */
579: char tim2char[NO_TIMETYPE] =
580: {':', ':'}; /* time 2nd delimiter */
581: char tim3char[NO_TIMETYPE] =
582: {SP, SP}; /* time hour justify char */
583: char tim4flag[NO_TIMETYPE] =
584: {0, 1}; /* 0=24 Hrs 1=12 Hrs */
585: char tim5flag[NO_TIMETYPE] =
586: {0, 0}; /* suppress seconds */
587: int timetype = 0; /* type for $zt special variable */
588:
589: jmp_buf sjbuf;
590: char *roucu0;
591: char *dofram0;
592:
593: short forx = 0; /* FOR stack pointer */
594: char forvar[NESTLEVLS + 1][40], /* FOR variable */
595: forinc[NESTLEVLS + 1][40], /* FOR increment */
596: forpost[NESTLEVLS + 1][128], /* FOR postconditional */
597: forlim[NESTLEVLS + 1][40]; /* FOR limit value */
598: short fortyp[NESTLEVLS + 1]; /* 0 = forever 1 = single, */
599:
600: /* 2 = unlim.iter,3 = limit iter. */
601: /* 4 = "" +inc=1 5 = "" + inc=1 */
602: short fori[NESTLEVLS + 1]; /* if fortyp=5 length of forlimit */
603:
604: char *fvar; /* current forvar */
605: char *finc; /* current forinc */
606: char *fpost; /* current forpost */
607: char *flim; /* current forlim */
608: short ftyp; /* current fortyp */
609: short fi; /* current fori */
610: short forsw = FALSE; /* FOR switch */
611: short loadsw = TRUE; /* flag to avoid redundant loads */
612: short argless_forsw_quit = FALSE; /* QUIT from argumentless FOR */
613: short sigint_in_for = FALSE;
614: short direct_mode = TRUE; /* are we in direct mode? */
615:
616: short extr_types[NESTLEVLS + 1]; /* return types of extrinsic functions */
1.11 ! snw 617: char destructors[MAX_DESTRUCTORS][OBJ_DSTRSIZE];
1.1 snw 618: int destructor_ct;
619: char private_keys[MAX_PRIVATE_KEYS][255];
620:
621: /* after XECUTEs */
622: short promflag = TRUE; /* prompt execute flag */
623: short privflag = FALSE; /* extrinsic z-command flag */
624:
625:
626: char *cmdstack;
627: char *cmdptr;
628:
629: short offset;
630: long frm_timeout;
631: short timeoutms;
632: char tmp4[80] = "\201";
633: short param = 0; /* parameter count */
634: short paramx = 0; /* current parameter */
635: short level = 0; /* level count */
636: pid_t pid; /* $J = process ID */
637:
638: char nsname[256] = "USER\0"; /* namespace name */
639: char nsroot[4096]; /* root path of namespace */
640: char *freem_path; /* path to the running instance of FreeM */
641: char history_file[256]; /* path to the history file */
642: int n_lines;
643: int n_columns;
644:
645: short ipc_pending = 0; /* 1 if an incoming IPC is pending, 0 otherwise */
646:
647: int strict_mode = 0;
648:
649: short first_process = FALSE;
650: size_t shm_init_size = 16777216;
651:
652: short inrpt_after_async = FALSE;
653:
654: void unnew (void)
655: {
656: char *xptr;
657: int i;
658: long j;
659: char tmp[256];
660:
661: #ifdef DEBUG_NEWPTR
662: int loop;
663: printf("Un-Newing: ");
664: printf("[nstx] nstx is %d\r\n",nstx);
665: printf("[nestnew] nestnew[nstx] is %d\r\n",nestnew[nstx]);
666: #endif
667:
668:
669: xptr = nestnew[nstx]; /* get position of newpointer */
670:
671: while (xptr < newptr) {
672: i = *--newptr;
673:
674: if (i != kill_all) {
675: j = UNSIGN (*--newptr);
676: newptr -= (j + 1);
677: stcpy0 (varnam, newptr, j + 1);
678:
679: if (i == set_sym) {
680: j = UNSIGN (*--newptr);
681: newptr -= (j + 1);
682: stcpy (tmp, newptr);
683: }
684: else {
685: tmp[0] = EOL;
686: }
687: }
688: else {
689: varnam[0] = EOL;
690: tmp[0] = EOL;
691: }
692:
693: if (varnam[0] == '$') {
694: if (varnam[1] == 't') test = tmp[0]; /* pop $TEST */
695: else if (varnam[1] == 'j') pid = UNSIGN (tmp[0]) * 256 + UNSIGN (tmp[1]); /* pop $job */
696: else if (varnam[1] == 'z' && varnam[2] == 'i') breakon = tmp[0]; /* pop $zinrpt */
697: else if (varnam[1] == 'e' && varnam[2] == 't') { /* pop $etrap */
698: stcpy (etrap, tmp);
699: }
700: else if (varnam[1] == 'e' && varnam[2] == 's') { /* pop $estack */
701: char esbuf[256];
702:
703: stcpy (esbuf, tmp);
704: stcnv_m2c (esbuf);
705:
706: estack = atoi (esbuf);
707: }
708: else { /* pop $reference/$zreference */
709: stcpy (zref, tmp);
710: nakoffs = UNSIGN (varnam[4]);
711: }
712:
713: continue;
714: }
715: symtab (i, varnam, tmp);
716: }
717:
718: newptr = nestnew[nstx];
719: nestnew[nstx] = 0; /* reset pointers */
720:
721: return;
722:
723: } /* end unnew() */
724:
725: void m_fatal(char *s)
726: {
727: int errno_sav;
728: errno_sav = errno;
729:
730: set_io (UNIX);
731:
732:
733: if (tp_level) {
734: fprintf (stderr, "freem [FATAL]: memory allocation failure in %s; rolling back %d transactions [errno %d %s]\n", s, tp_level, errno_sav, strerror (errno_sav));
735: tp_trollback (tp_level);
736: }
737: else {
738: fprintf (stderr, "freem [FATAL]: memory allocation failure in %s [errno %d %s]\n", s, errno_sav, strerror (errno_sav));
739: }
740:
741: exit (3);
742: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>