File:  [Coherent Logic Development] / freem / src / ssvn_routine.c
Revision 1.5: download - view: text, annotated - select for diffs
Sun Apr 13 04:22:43 2025 UTC (3 months, 2 weeks ago) by snw
Branches: MAIN
CVS tags: HEAD
Fix snprintf calls

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

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