File:  [Coherent Logic Development] / freem / src / frmgbl.c
Revision 1.5: download - view: text, annotated - select for diffs
Sun Mar 9 19:14:25 2025 UTC (6 months, 1 week ago) by snw
Branches: MAIN
CVS tags: v0-62-2, v0-62-1, v0-62-0, HEAD
First phase of REUSE compliance and header reformat

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

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