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