Annotation of freem/src/ssvn_library.c, revision 1.6

1.1       snw         1: /*
1.6     ! snw         2:  *   $Id: ssvn_library.c,v 1.5 2025/03/24 04:13:11 snw Exp $
1.3       snw         3:  *    ^$LIBRARY 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, 2023, 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_library.c,v $
1.6     ! snw        27:  *   Revision 1.5  2025/03/24 04:13:11  snw
        !            28:  *   Replace action macro dat with fra_dat to avoid symbol conflict on OS/2
        !            29:  *
1.5       snw        30:  *   Revision 1.4  2025/03/22 18:43:54  snw
                     31:  *   Make STRLEN 255 chars and add BIGSTR macro for larger buffers
                     32:  *
1.4       snw        33:  *   Revision 1.3  2025/03/09 19:50:47  snw
                     34:  *   Second phase of REUSE compliance and header reformat
                     35:  *
1.3       snw        36:  *
                     37:  * SPDX-FileCopyrightText:  (C) 2025 Coherent Logic Development LLC
                     38:  * SPDX-License-Identifier: AGPL-3.0-or-later
1.1       snw        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: void ssvn_library_add_dir(char *);
                     56: 
                     57: void ssvn_library_add_dir(char *libdir)
                     58: {
                     59: 
                     60:     DIR *dir;
                     61:     struct dirent *ent;
1.4       snw        62:     char filename[PATHLEN];
1.1       snw        63:     char rtnname[256];
                     64:     char *rtnext;
                     65:     
                     66:     char k_buf[512];
                     67:     char d_buf[512];
                     68:     register int i;
                     69:     
                     70:     dir = opendir (libdir);
                     71:     while ((ent = readdir (dir)) != NULL) {
                     72: 
1.4       snw        73:         strncpy (filename, ent->d_name, PATHLEN);
1.1       snw        74: 
                     75:         rtnext = ent->d_name + (strlen (ent->d_name) - 2);
                     76:         
                     77:         if ((strcmp (rtnext, ".m") == 0) && (strncmp (filename, "%ul", 3) == 0)) {
                     78: 
                     79:             strcpy (rtnname, ent->d_name + 3);
                     80:             rtnname[strlen (ent->d_name) - 5] = '\0';
                     81: 
                     82:             for (i = 0; i < strlen (rtnname); i++) {
                     83:                 if (rtnname[i] >= 'a' && rtnname[i] <= 'z') {
                     84:                     rtnname[i] -= 32;
                     85:                 }
                     86:             }
                     87:             
                     88:             snprintf (k_buf, 512 - 1, "^$LIBRARY\202%s\201", rtnname);
                     89:             snprintf (d_buf, 512 - 1, " \201");
                     90:             symtab_bltin (set_sym, k_buf, d_buf);
                     91:             
                     92:         }
                     93: 
                     94:     }
                     95: 
                     96:     closedir (dir);
                     97: 
                     98: }
                     99: 
                    100: void ssvn_library_update(void)
                    101: {
1.4       snw       102:     char t_buf[PATHLEN];
1.1       snw       103:     
                    104:     stcpy (t_buf, rou0plib);
                    105:     stcnv_m2c (t_buf);
                    106: 
                    107:     ssvn_library_add_dir (t_buf);
                    108:     
                    109:     return;
                    110: 
                    111: }
                    112: 
                    113: void ssvn_library(short action, char *key, char *data)
                    114: {
                    115:     freem_ref_t *r = (freem_ref_t *) malloc (sizeof (freem_ref_t));
                    116:     NULLPTRCHK(r,"ssvn_routine");
                    117: 
                    118:     mref_init (r, MREF_RT_SSV, "^$ROUTINE");
                    119:     internal_to_mref (r, key);
                    120:     
                    121:     ssvn_routine_update ();
                    122: 
                    123:     switch (action) {
                    124: 
                    125:         case get_sym:
                    126:         case fra_order:
                    127:         case fra_query:
                    128:         case bigquery:
1.5       snw       129:         case fra_dat:
1.1       snw       130: 
                    131:             symtab_bltin (action, key, data);
                    132:             goto done;
                    133: 
                    134:         default:
                    135: 
                    136:             merr_raise (M38);
                    137:             goto done;
                    138: 
                    139:     }
                    140: 
                    141: done:
                    142:     free (r);
                    143: 
                    144:     return;
                    145: }
                    146: 

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