File:  [Coherent Logic Development] / freem / src / frmgbl.c
Revision 1.15: download - view: text, annotated - select for diffs
Wed Apr 30 14:41:03 2025 UTC (11 months ago) by snw
Branches: MAIN
CVS tags: HEAD
Further debugger work

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>