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