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