Annotation of freem/src/ssvn_routine.c, revision 1.5

1.1       snw         1: /*
1.5     ! snw         2:  *   $Id: ssvn_routine.c,v 1.4 2025/03/22 18:43:54 snw Exp $
1.3       snw         3:  *    ^$ROUTINE ssvn
1.1       snw         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.4       snw        26:  *   $Log: ssvn_routine.c,v $
1.5     ! snw        27:  *   Revision 1.4  2025/03/22 18:43:54  snw
        !            28:  *   Make STRLEN 255 chars and add BIGSTR macro for larger buffers
        !            29:  *
1.4       snw        30:  *   Revision 1.3  2025/03/09 19:50:47  snw
                     31:  *   Second phase of REUSE compliance and header reformat
                     32:  *
1.3       snw        33:  *
                     34:  * SPDX-FileCopyrightText:  (C) 2025 Coherent Logic Development LLC
                     35:  * SPDX-License-Identifier: AGPL-3.0-or-later
1.1       snw        36:  **/
                     37: 
                     38: #include <stdio.h>
                     39: #include <stdlib.h>
                     40: #include <string.h>
                     41: #include <dirent.h>
                     42: #include <time.h>
                     43: #include <unistd.h>
                     44: #include <sys/types.h>
                     45: #include <sys/stat.h>
                     46: #include <ctype.h>
                     47: #include <errno.h>
                     48: 
                     49: #include "mpsdef.h"
                     50: #include "mref.h"
                     51: 
                     52: 
                     53: void ssvn_routine_add_dir(char *);
                     54: 
                     55: void ssvn_routine_add_dir(char *rtndir)
                     56: {
                     57:     DIR *dir;
                     58:     struct dirent *ent;
1.4       snw        59:     char filename[PATHLEN];
                     60:     char rtnname[PATHLEN];
1.1       snw        61:     char *rtnext;
                     62:     
1.4       snw        63:     char k_buf[STRLEN];
                     64:     char d_buf[STRLEN];
                     65:     char t_buf[STRLEN];
1.1       snw        66:     
                     67:     dir = opendir (rtndir);
                     68:     while ((ent = readdir (dir)) != NULL) {
                     69: 
1.4       snw        70:         strncpy (filename, ent->d_name, PATHLEN);
1.1       snw        71: 
                     72:         rtnext = ent->d_name + (strlen (ent->d_name) - 2);
                     73:         
                     74:         if (strcmp (rtnext, ".m") == 0) {
                     75: 
                     76:             strcpy (rtnname, ent->d_name);
                     77:             rtnname[strlen (ent->d_name) - 2] = '\0';
                     78:             
1.5     ! snw        79:             snprintf (k_buf, STRLEN - 1, "^$ROUTINE\202%s\202CHARACTER\201", rtnname);
        !            80:             snprintf (d_buf, STRLEN - 1, "M\201");
1.1       snw        81:             symtab_bltin (set_sym, k_buf, d_buf);
                     82: 
1.5     ! snw        83:             snprintf (k_buf, STRLEN - 1, "^$ROUTINE\202%s\202NAMESPACE\201", rtnname);
1.1       snw        84:             if (rtnname[0] == '%') {
1.5     ! snw        85:                 snprintf (d_buf, STRLEN - 1, "SYSTEM\201");
1.1       snw        86:             }
                     87:             else {
1.5     ! snw        88:                 snprintf (d_buf, STRLEN - 1, "%s\201", nsname);
1.1       snw        89:             }
                     90: 
                     91:             symtab_bltin (set_sym, k_buf, d_buf);
                     92: 
1.5     ! snw        93:             snprintf (k_buf, STRLEN - 1, "^$ROUTINE\202%s\202PATH\201", rtnname);
1.1       snw        94: 
                     95:             if (rtnname[0] == '%') {
                     96:                 stcpy (t_buf, rou0plib);
                     97:             }
                     98:             else {
                     99:                 stcpy (t_buf, rou0path);
                    100:             }
                    101: 
                    102:             stcnv_m2c (t_buf);
1.5     ! snw       103:             snprintf (d_buf, STRLEN - 1, "%s/%s\201", t_buf, filename);
1.1       snw       104: 
                    105:             symtab_bltin (set_sym, k_buf, d_buf);
                    106:             
                    107:         }
                    108: 
                    109:     }
                    110: 
                    111:     closedir (dir);
                    112: 
                    113: }
                    114: 
                    115: void ssvn_routine_update(void)
                    116: {
                    117:     
                    118:     char t_buf[STRLEN];
                    119:     char k_buf[STRLEN];
                    120: 
                    121:     snprintf (k_buf, STRLEN - 1, "^$ROUTINE\201");
                    122:     
                    123:     stcpy (t_buf, rou0path);
                    124:     stcnv_m2c (t_buf);
                    125:     
                    126:     ssvn_routine_add_dir (t_buf);
                    127: 
                    128:     stcpy (t_buf, rou0plib);
                    129:     stcnv_m2c (t_buf);
                    130: 
                    131:     ssvn_routine_add_dir (t_buf);
                    132:     
                    133:     return;
                    134:     
                    135: }
                    136: 
                    137: void ssvn_routine(short action, char *key, char *data)
                    138: {
                    139: 
                    140:     freem_ref_t *r = (freem_ref_t *) malloc (sizeof (freem_ref_t));
                    141:     NULLPTRCHK(r,"ssvn_routine");
                    142: 
                    143:     mref_init (r, MREF_RT_SSV, "^$ROUTINE");
                    144:     internal_to_mref (r, key);
                    145:     
                    146:     ssvn_routine_update ();
                    147: 
                    148:     switch (action) {
                    149: 
                    150:         case get_sym:           
                    151:             
                    152:             symtab_bltin (action, key, data);
                    153:             merr_clear ();
                    154:             goto done;
                    155: 
                    156: 
                    157:         case fra_order:
                    158: 
                    159:             if (r->subscript_count > 2 || r->subscript_count < 1) {
                    160:                 merr_raise (M29);
                    161:                 goto done;
                    162:             }
                    163: 
                    164:             if (r->subscript_count == 1) {
                    165: 
                    166:                 /* likely ordering over routine names only */
                    167:                 symtab_bltin (action, key, data);
                    168: 
                    169:                 merr_clear ();
                    170:                 goto done;
                    171: 
                    172:             }
                    173: 
                    174:             if (r->subscript_count == 2) {
                    175: 
                    176:                 merr_raise (M38);
                    177:                 goto done;
                    178:                 
                    179:             }
                    180:         
                    181:     }
                    182: 
                    183:     
                    184: done:
                    185: 
                    186:     free (r);
                    187:     
                    188:     return;
                    189: }

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