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