File:  [Coherent Logic Development] / freem / src / frmgbl.c
Revision 1.8: download - view: text, annotated - select for diffs
Wed Apr 2 03:02:42 2025 UTC (6 months, 3 weeks ago) by snw
Branches: MAIN
CVS tags: HEAD
Stop requiring users to pass -e to fmadm when -u or -g are passed

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

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