![]() ![]() | ![]() |
1.1 snw 1: /*
2: * *
3: * * *
4: * * *
5: * ***************
6: * * * * *
7: * * MUMPS *
8: * * * * *
9: * ***************
10: * * *
11: * * *
12: * *
13: *
14: * ssvn_routine.c
15: * ^$ROUTINE ssv
16: *
17: *
1.2 ! snw 18: * Author: Serena Willis <snw@coherent-logic.com>
1.1 snw 19: * Copyright (C) 1998 MUG Deutschland
20: * Copyright (C) 2020 Coherent Logic Development LLC
21: *
22: *
23: * This file is part of FreeM.
24: *
25: * FreeM is free software: you can redistribute it and/or modify
26: * it under the terms of the GNU Affero Public License as published by
27: * the Free Software Foundation, either version 3 of the License, or
28: * (at your option) any later version.
29: *
30: * FreeM is distributed in the hope that it will be useful,
31: * but WITHOUT ANY WARRANTY; without even the implied warranty of
32: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33: * GNU Affero Public License for more details.
34: *
35: * You should have received a copy of the GNU Affero Public License
36: * along with FreeM. If not, see <https://www.gnu.org/licenses/>.
37: *
38: **/
39:
40: #include <stdio.h>
41: #include <stdlib.h>
42: #include <string.h>
43: #include <dirent.h>
44: #include <time.h>
45: #include <unistd.h>
46: #include <sys/types.h>
47: #include <sys/stat.h>
48: #include <ctype.h>
49: #include <errno.h>
50:
51: #include "mpsdef.h"
52: #include "mref.h"
53:
54:
55: void ssvn_routine_add_dir(char *);
56:
57: void ssvn_routine_add_dir(char *rtndir)
58: {
59: DIR *dir;
60: struct dirent *ent;
61: char filename[STRLEN];
62: char rtnname[256];
63: char *rtnext;
64:
65: char k_buf[512];
66: char d_buf[512];
67: char t_buf[512];
68:
69: dir = opendir (rtndir);
70: while ((ent = readdir (dir)) != NULL) {
71:
72: strncpy (filename, ent->d_name, STRLEN - 1);
73:
74: rtnext = ent->d_name + (strlen (ent->d_name) - 2);
75:
76: if (strcmp (rtnext, ".m") == 0) {
77:
78: strcpy (rtnname, ent->d_name);
79: rtnname[strlen (ent->d_name) - 2] = '\0';
80:
81: snprintf (k_buf, 512 - 1, "^$ROUTINE\202%s\202CHARACTER\201", rtnname);
82: snprintf (d_buf, 512 - 1, "M\201");
83: symtab_bltin (set_sym, k_buf, d_buf);
84:
85: snprintf (k_buf, 512 - 1, "^$ROUTINE\202%s\202NAMESPACE\201", rtnname);
86: if (rtnname[0] == '%') {
87: snprintf (d_buf, 512 - 1, "SYSTEM\201");
88: }
89: else {
90: snprintf (d_buf, 512 - 1, "%s\201", nsname);
91: }
92:
93: symtab_bltin (set_sym, k_buf, d_buf);
94:
95: snprintf (k_buf, 512 - 1, "^$ROUTINE\202%s\202PATH\201", rtnname);
96:
97: if (rtnname[0] == '%') {
98: stcpy (t_buf, rou0plib);
99: }
100: else {
101: stcpy (t_buf, rou0path);
102: }
103:
104: stcnv_m2c (t_buf);
105: snprintf (d_buf, 512 - 1, "%s/%s\201", t_buf, filename);
106:
107: symtab_bltin (set_sym, k_buf, d_buf);
108:
109: }
110:
111: }
112:
113: closedir (dir);
114:
115: }
116:
117: void ssvn_routine_update(void)
118: {
119:
120: char t_buf[STRLEN];
121: char k_buf[STRLEN];
122:
123: snprintf (k_buf, STRLEN - 1, "^$ROUTINE\201");
124:
125: stcpy (t_buf, rou0path);
126: stcnv_m2c (t_buf);
127:
128: ssvn_routine_add_dir (t_buf);
129:
130: stcpy (t_buf, rou0plib);
131: stcnv_m2c (t_buf);
132:
133: ssvn_routine_add_dir (t_buf);
134:
135: return;
136:
137: }
138:
139: void ssvn_routine(short action, char *key, char *data)
140: {
141:
142: freem_ref_t *r = (freem_ref_t *) malloc (sizeof (freem_ref_t));
143: NULLPTRCHK(r,"ssvn_routine");
144:
145: mref_init (r, MREF_RT_SSV, "^$ROUTINE");
146: internal_to_mref (r, key);
147:
148: ssvn_routine_update ();
149:
150: switch (action) {
151:
152: case get_sym:
153:
154: symtab_bltin (action, key, data);
155: merr_clear ();
156: goto done;
157:
158:
159: case fra_order:
160:
161: if (r->subscript_count > 2 || r->subscript_count < 1) {
162: merr_raise (M29);
163: goto done;
164: }
165:
166: if (r->subscript_count == 1) {
167:
168: /* likely ordering over routine names only */
169: symtab_bltin (action, key, data);
170:
171: merr_clear ();
172: goto done;
173:
174: }
175:
176: if (r->subscript_count == 2) {
177:
178: merr_raise (M38);
179: goto done;
180:
181: }
182:
183: }
184:
185:
186: done:
187:
188: free (r);
189:
190: return;
191: }