1 /* Macro space functions for regutil
2 * note that you must add -DMACROSPACE to the CFLAGS to get useful
3 * versions of these
4 *
5 * The contents of this file are subject to the Mozilla Public License
6 * Version 1.0 (the "License"); you may not use this file except in
7 * compliance with the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS"
11 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
12 * License for the specific language governing rights and limitations
13 * under the License.
14 *
15 * The Original Code is regutil.
16 *
17 * The Initial Developer of the Original Code is Patrick TJ McPhee.
18 * Portions created by Patrick McPhee are Copyright � 1998, 2001
19 * Patrick TJ McPhee. All Rights Reserved.
20 *
21 * Contributors:
22 *
23 * $Header: /opt/cvs/Regina/regutil/regmacrospace.c,v 1.1 2009/10/07 07:51:51 mark Exp $
24 */
25 #include "regutil.h"
26
27 #include <ctype.h>
28
29 /* ******************************************************************** */
30 /* ********************** Macro Space Management ********************** */
31 /* ******************************************************************** */
32
33
34 /* functions defined in this file:
35 * sysaddrexxmacro(name, file, [order]) [support not in Regina]
36 * sysclearrexxmacrospace()
37 * sysdroprexxmacro(name)
38 * sysloadrexxmacrospace(file)
39 * sysqueryrexxmacro(name)
40 * sysreorderrexxmacro(name,order)
41 * syssaverexxmacrospace(file)
42 */
43
44 #ifdef MACROSPACE
45
46 /* sysaddrexxmacro(name, file [, order]) -- add a an external macro into the
47 * current macro space. The macro can be added to the front or back of the
48 * search order, allowing it to be over-ridden. */
rxfunc(sysaddrexxmacro)49 rxfunc(sysaddrexxmacro)
50 {
51 char * fn, * file;
52 unsigned long flags = RXMACRO_SEARCH_BEFORE;
53
54 checkparam(2,3);
55 rxstrdup(fn, argv[0]);
56 rxstrdup(file, argv[1]);
57
58 if (argc > 2 && tolower(argv[2].strptr[0]) == 'a') {
59 flags = RXMACRO_SEARCH_AFTER;
60 }
61
62 result->strlength = sprintf(result->strptr, "%lu", RexxAddMacro(fn, file, flags));
63
64 return 0;
65 }
66
67 /* clears all definitions from the macro space */
rxfunc(sysclearrexxmacrospace)68 rxfunc(sysclearrexxmacrospace)
69 {
70 checkparam(0, 0);
71
72 result->strlength = sprintf(result->strptr, "%lu", RexxClearMacroSpace());
73 return 0;
74 }
75
76 /* sysdroprexxmacro(name) removes the named macro from the macro space */
rxfunc(sysdroprexxmacro)77 rxfunc(sysdroprexxmacro)
78 {
79 char * fn;
80 checkparam(1, 1);
81
82 rxstrdup(fn, argv[0]);
83
84 result->strlength = sprintf(result->strptr, "%lu", RexxDropMacro(fn));
85 return 0;
86 }
87
88 /* sysloadrexxmacrospace(file) -- load a macro space from a previously saved file */
rxfunc(sysloadrexxmacrospace)89 rxfunc(sysloadrexxmacrospace)
90 {
91 char * file;
92
93 checkparam(1,1);
94
95 rxstrdup(file, argv[0]);
96
97 result->strlength = sprintf(result->strptr, "%lu", RexxLoadMacroSpace(0, NULL, file));
98 return 0;
99 }
100
101 /* sysqueryrexxmacro(name) -- determine whether a macro has been loaded (laden?) */
rxfunc(sysqueryrexxmacro)102 rxfunc(sysqueryrexxmacro)
103 {
104 static const char bef[] = "Before", aft[] = "After";
105 char * fn;
106 unsigned short pos = 0;
107 int rc;
108
109 checkparam(1,1);
110
111 rxstrdup(fn, argv[0]);
112
113 rc = RexxQueryMacro(fn, &pos);
114
115 if (pos == RXMACRO_SEARCH_AFTER) {
116 memcpy(result->strptr, aft, sizeof(aft)-1);
117 result->strlength = sizeof(aft)-1;
118 }
119 else if (pos == RXMACRO_SEARCH_BEFORE) {
120 memcpy(result->strptr, bef, sizeof(bef)-1);
121 result->strlength = sizeof(bef)-1;
122 }
123 else
124 result->strlength = 0;
125
126 return 0;
127 }
128
129
130 /* sysreorderrexxmacro(name,order) -- move the macro to the start or the end
131 * of the search order */
rxfunc(sysreorderrexxmacro)132 rxfunc(sysreorderrexxmacro)
133 {
134 char * fn, * file;
135 unsigned long flags;
136
137 checkparam(2,2);
138 rxstrdup(fn, argv[0]);
139
140 if (tolower(argv[1].strptr[0]) == 'a') {
141 flags = RXMACRO_SEARCH_AFTER;
142 }
143 else
144 flags = RXMACRO_SEARCH_BEFORE;
145
146 result->strlength = sprintf(result->strptr, "%lu", RexxReorderMacro(fn, flags));
147
148 return 0;
149 }
150
151 /* syssaverexxmacrospace(file) -- writes the macro space out to a file */
rxfunc(syssaverexxmacrospace)152 rxfunc(syssaverexxmacrospace)
153 {
154 char * file;
155
156 checkparam(1,1);
157
158 rxstrdup(file, argv[0]);
159
160 result->strlength = sprintf(result->strptr, "%lu", RexxSaveMacroSpace(0, NULL, file));
161 return 0;
162 }
163
164 #else
165
166 static const char notimp[] = "Macrospace Functions are not compiled. Add -DMACROSPACE to CFLAGS and recompile the library.";
167
168 #define STUB(x) rxfunc(x) { result->strlength = sizeof(notimp) - 1; memcpy(result->strptr, notimp, result->strlength); return 0; }
169
170 STUB(sysaddrexxmacro)
171 STUB(sysclearrexxmacrospace)
172 STUB(sysdroprexxmacro)
173 STUB(sysloadrexxmacrospace)
174 STUB(sysqueryrexxmacro)
175 STUB(sysreorderrexxmacro)
176 STUB(syssaverexxmacrospace)
177 #endif
178