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