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