Annotation of freem/src/ssvn.c, revision 1.3

1.1       snw         1: /*
1.3     ! snw         2:  *   $Id$
1.1       snw         3:  *    structured system variable support
                      4:  *
                      5:  *  
1.2       snw         6:  *   Author: Serena Willis <snw@coherent-logic.com>
1.1       snw         7:  *    Copyright (C) 1998 MUG Deutschland
1.3     ! snw         8:  *    Copyright (C) 2020, 2025 Coherent Logic Development LLC
1.1       snw         9:  *
                     10:  *
                     11:  *   This file is part of FreeM.
                     12:  *
                     13:  *   FreeM is free software: you can redistribute it and/or modify
                     14:  *   it under the terms of the GNU Affero Public License as published by
                     15:  *   the Free Software Foundation, either version 3 of the License, or
                     16:  *   (at your option) any later version.
                     17:  *
                     18:  *   FreeM is distributed in the hope that it will be useful,
                     19:  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
                     20:  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     21:  *   GNU Affero Public License for more details.
                     22:  *
                     23:  *   You should have received a copy of the GNU Affero Public License
                     24:  *   along with FreeM.  If not, see <https://www.gnu.org/licenses/>.
                     25:  *
1.3     ! snw        26:  *   $Log$
        !            27:  *
        !            28:  * SPDX-FileCopyrightText:  (C) 2025 Coherent Logic Development LLC
        !            29:  * SPDX-License-Identifier: AGPL-3.0-or-later
1.1       snw        30:  **/
                     31: 
                     32: #include <stdio.h>
                     33: #include <stdlib.h>
                     34: #include <string.h>
                     35: #include <sys/types.h>
                     36: #if !defined(__OpenBSD__) && !defined(__FreeBSD__)
                     37: # include <sys/timeb.h>
                     38: #endif
                     39: #include "mpsdef.h"
                     40: #include "freem.h"
                     41: #include "mref.h"
                     42: #include "mdebug.h"
                     43: 
                     44: #ifdef USE_SYS_TIME_H
                     45: # include <sys/time.h>
                     46: #endif
                     47: 
                     48: typedef struct ssvn_lut {
                     49:     const char *input_name;
                     50:     const char *canonical_name;
                     51: } ssvn_lut;
                     52: 
                     53:  ssvn_lut ssv_tab[] = {
                     54:     {"^$C", "^$CHARACTER"},
                     55:     {"^$CHARACTER", "^$CHARACTER"},
                     56:     {"^$D", "^$DEVICE"},
                     57:     {"^$DEVICE", "^$DEVICE"},
                     58:     {"^$DI", "^$DISPLAY"},
                     59:     {"^$DISPLAY", "^$DISPLAY"},
                     60:     {"^$E", "^$EVENT"},
                     61:     {"^$EVENT", "^$EVENT"},
                     62:     {"^$G", "^$GLOBAL"},
                     63:     {"^$GLOBAL", "^$GLOBAL"},
                     64:     {"^$J", "^$JOB"},
                     65:     {"^$JOB", "^$JOB"},
                     66:     {"^$LI","^$LIBRARY"},
                     67:     {"^$LIBRARY","^$LIBRARY"},
                     68:     {"^$L", "^$LOCK"},
                     69:     {"^$LOCK", "^$LOCK"},
                     70:     {"^$O", "^$OBJECT"},
                     71:     {"^$OBJECT", "^$OBJECT"},
                     72:     {"^$R", "^$ROUTINE"},
                     73:     {"^$ROUTINE", "^$ROUTINE"},
                     74:     {"^$S", "^$SYSTEM"},
                     75:     {"^$SYSTEM", "^$SYSTEM"},
                     76:     {"^$W", "^$WINDOW"},
                     77:     {"^$WINDOW", "^$WINDOW"},
                     78:     {"^$ZF", "^$ZFILE"},
                     79:     {"^$ZFILE", "^$ZFILE"},
                     80:     {"^$ZFR", "^$ZFREEM"},
                     81:     {"^$ZFREEM", "^$ZFREEM"},
                     82:     {"^$ZD", "^$ZDIRECTORY"},
                     83:     {"^$ZDIRECTORY", "^$ZDIRECTORY"},
                     84:     {"^$ZO", "^$ZOS"},
                     85:     {"^$ZOS", "^$ZOS"},
                     86:     {"^$ZP", "^$ZPROCESS"},
                     87:     {"^$ZPROCESS", "^$ZPROCESS"},
                     88:     {"^$ZR", "^$ZRPI"},
                     89:     {"^$ZRPI", "^$ZRPI"},
                     90:     {NULL, NULL}
                     91: };
                     92: 
                     93: 
                     94: void ssvn (short action, char *key, char *data);
                     95: void ssvn_normalize_key (char *key);
                     96: 
                     97: /* structured system variable management */
                     98: /* set_sym      get_sym   */
                     99: /* kill_sym     $data     */
                    100: /* kill_all     $fra_order    */
                    101: /* killexcl     $fra_query    */
                    102: /* new_sym                */
                    103: /* new_all      getinc    */
                    104: /* newexcl                */
                    105: /* killone      m_alias   */
                    106: /* merge_sym    zdata     */
                    107: void ssvn (short action, char *key, char *data)
                    108: {
                    109:     int i, j;
                    110:     char ch;
                    111:     char ptmp[256];
                    112: 
                    113:     if ((rtn_dialect () == D_M77) ||
                    114:         (rtn_dialect () == D_M84) ||
                    115:         (rtn_dialect () == D_M90)) {
                    116:         merr_raise (NOSTAND);
                    117:         return;
                    118:     }
                    119:     
                    120:     i = 1;
                    121:     j = 2;
                    122:     
                    123:     while ((ch = key[j]) != EOL) {
                    124: 
                    125:         if (ch >= 'a' && ch <= 'z') ch -= 32;
                    126:         if (ch == DELIM) break;
                    127:        
                    128:         ptmp[i++] = ch;
                    129:         j++;
                    130: 
                    131:     }
                    132:     
                    133:     ptmp[0] = SP;
                    134:     ptmp[i++] = SP;
                    135:     ptmp[i] = EOL;
                    136: 
                    137:     ssvn_normalize_key (key);
                    138: 
                    139:     if (dbg_enable_watch && (action == set_sym)) dbg_fire_watch (key);
                    140: 
                    141:     if (merr () > OK) return;
                    142: 
                    143: 
                    144:     if ((ptmp[1] != 'Z') && (ptmp[1] != 'Y')) {
                    145: 
                    146:         if (find (" C CHARACTER D DEVICE DI DISPLAY E EVENT G GLOBAL J JOB LI LIBRARY L LOCK O OBJECT P R ROUTINE S SYSTEM W WINDOW ", ptmp) == FALSE) {
                    147:             merr_raise (M60);
                    148:             return;
                    149:         }
                    150: 
                    151:         switch (ptmp[1]) {
                    152: 
                    153:             case 'C':                  /* ^$CHARACTER ssvn */
                    154:                 ssvn_character (action, key, data);
                    155:                 break;
                    156:                        
                    157:             case 'D':                  /* ^$DEVICE and ^$DISPLAY ssvns */
                    158:                 switch(ptmp[2]) {
                    159:             
                    160:                     case 'E':   /* ^$DEVICE */
                    161:                         ssvn_device (action, key, data);
                    162:                         break;
                    163:             
                    164:                     case 'I':   /* ^$DISPLAY */
                    165:                         ssvn_display (action, key, data);
                    166:                         break;
                    167:             
                    168:                     default:
                    169:                         merr_raise (INVREF);
                    170:                         break;
                    171:                 }  
                    172: 
                    173:                 break;                                  
                    174:             
                    175:             case 'E':                   /* ^$EVENT ssvn */
                    176:                 ssvn_event (action, key, data);
                    177:                 break;
                    178:                        
                    179:             case 'G':                  /* ^$GLOBAL ssvn */
                    180:                 ssvn_global (action, key, data);
                    181:                 break;
                    182:                        
                    183:             case 'J':                  /* ^$JOB ssvn */          
                    184:                 ssvn_job (action, key, data);
                    185:                 break;
                    186:                        
                    187:             case 'L':                  /* ^$LIBRARY/^$LOCK ssvns */
                    188:                 if (ptmp[2] == 'I') {
                    189:                     ssvn_library (action, key, data);
                    190:                 }
                    191:                 else {
                    192:                     ssvn_lock (action, key, data);
                    193:                 }
                    194:                 break;
                    195:                 
                    196:             case 'O':
                    197:                 ssvn_object (action, key, data);
                    198:                 break;
                    199:                 
                    200:             case 'R':                  /* ^$ROUTINE ssvn */
                    201:                 ssvn_routine (action, key, data);
                    202:                 break;
                    203:                        
                    204:             case 'S':                  /* ^$SYSTEM ssvn */
                    205:                 ssvn_system (action, key, data);
                    206:                 break;
                    207:                        
                    208:             case 'W':                  /* ^$WINDOW ssvn */
                    209:                 ssvn_window (action, key, data);
                    210:                 break;
                    211:                        
                    212:             default:
                    213:                 merr_raise (INVREF);
                    214:                 break;
                    215:         }
                    216:     } 
                    217:     else {                             /* implementation-specific ssvns */
                    218:         ssvn_z (action, key, data);
                    219:         return;
                    220:     }
                    221: 
                    222:     return;
                    223: }
                    224: 
                    225: /* convert SSVN names to canonical form (all caps, full-length name) */
                    226: void ssvn_normalize_key (char *key)
                    227: {
                    228:     freem_ref_t *ref;
                    229:     char *new_key;
                    230:     ssvn_lut *p;
                    231:     register int i;
                    232: 
                    233:     
                    234:     ref = malloc (sizeof (freem_ref_t));
                    235:     NULLPTRCHK(ref,"ssvn_normalize_key");
                    236:     
                    237:     mref_init (ref, MREF_RT_SSVN, "");
                    238:     internal_to_mref (ref, key);
                    239: 
                    240:     for (i = 0; i < strlen (ref->name); i++) {
                    241:         if (ref->name[i] >= 'a' && ref->name[i] <= 'z') ref->name[i] -= 32;
                    242:     }
                    243: 
                    244: 
                    245:     for (p = ssv_tab; p->input_name != NULL; ++p) {
                    246: 
                    247:         if (strcmp (ref->name, p->input_name) == 0) {
                    248:             
                    249:             strcpy (ref->name, p->canonical_name);
                    250: 
                    251:             new_key = mref_to_internal (ref);
                    252:             stcpy (key, new_key);
                    253: 
                    254:             free (ref);
                    255:             free (new_key);
                    256: 
                    257:             merr_clear ();
                    258:             return;
                    259: 
                    260:         }
                    261: 
                    262:     }
                    263: 
                    264:     merr_raise (M60);
                    265: 
                    266:     free (ref);
                    267:     
                    268:     return;
                    269: 
                    270: }

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