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