MacroSpaceApi.cpp
Go to the documentation of this file.
1 /*----------------------------------------------------------------------------*/
2 /* */
3 /* Copyright (c) 1995, 2004 IBM Corporation. All rights reserved. */
4 /* Copyright (c) 2005-2009 Rexx Language Association. All rights reserved. */
5 /* */
6 /* This program and the accompanying materials are made available under */
7 /* the terms of the Common Public License v1.0 which accompanies this */
8 /* distribution. A copy is also available at the following address: */
9 /* http://www.ibm.com/developerworks/oss/CPLv1.0.htm */
10 /* */
11 /* Redistribution and use in source and binary forms, with or */
12 /* without modification, are permitted provided that the following */
13 /* conditions are met: */
14 /* */
15 /* Redistributions of source code must retain the above copyright */
16 /* notice, this list of conditions and the following disclaimer. */
17 /* Redistributions in binary form must reproduce the above copyright */
18 /* notice, this list of conditions and the following disclaimer in */
19 /* the documentation and/or other materials provided with the distribution. */
20 /* */
21 /* Neither the name of Rexx Language Association nor the names */
22 /* of its contributors may be used to endorse or promote products */
23 /* derived from this software without specific prior written permission. */
24 /* */
25 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */
26 /* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */
27 /* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS */
28 /* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */
29 /* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
30 /* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
31 /* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */
32 /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY */
33 /* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */
34 /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
35 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
36 /* */
37 /*----------------------------------------------------------------------------*/
38 
39 #include "rexx.h"
40 #include "LocalAPIManager.hpp"
42 #include "LocalAPIContext.hpp"
43 #include "RexxInternalApis.h"
44 #include "RexxAPI.h"
45 
46 /*********************************************************************/
47 /* */
48 /* Function Name: RexxAddMacro */
49 /* */
50 /* Description: change or insert a macro's compiled image */
51 /* image in the macrospace. */
52 /* */
53 /* Entry Point: RexxAddMacro */
54 /* */
55 /* Inputs: n - macro name asciiz string */
56 /* s - filename asciiz string */
57 /* pos - search order position */
58 /* */
59 /* Output: return code */
60 /* */
61 /*********************************************************************/
62 
64  const char *name, /* name of macro function */
65  const char *file, /* name of file */
66  size_t pos) /* search order pos request */
67 {
69  {
70  return lam->macroSpaceManager.addMacroFromFile(name, file, pos);
71  }
72  EXIT_REXX_API();
73 }
74 
75 
76 /*********************************************************************/
77 /* */
78 /* Function Name: RexxDropMacro */
79 /* */
80 /* Description: remove a macro's compiled image. */
81 /* */
82 /* Entry Point: RexxDropMacro */
83 /* */
84 /* Input: n - macro name asciiz string */
85 /* */
86 /* Output: return code */
87 /* */
88 /*********************************************************************/
89 
91  const char *name) /* name of macro to delete */
92 {
94  {
95  return lam->macroSpaceManager.removeMacro(name);
96  }
97  EXIT_REXX_API();
98 }
99 
100 
101 /*********************************************************************/
102 /* */
103 /* Function Name: RexxClearMacroSpace */
104 /* */
105 /* Description: erase all entries in the macro chain */
106 /* */
107 /* Entry Point: RexxCleanMacroSpace */
108 /* */
109 /* Output: return code */
110 /* */
111 /*********************************************************************/
112 
114 {
116  {
117  return lam->macroSpaceManager.clearMacroSpace();
118  }
119  EXIT_REXX_API();
120 }
121 
122 
123 /*********************************************************************/
124 /* */
125 /* Function Name: RexxSaveMacroSpace */
126 /* */
127 /* Description: saves all entries in the macro chain */
128 /* */
129 /* Notes: File Format: */
130 /* - REXXSAA interpreter version string */
131 /* - Macro Space file signature flag */
132 /* - MACRO structures for functions */
133 /* - RXSTRING structures for images */
134 /* */
135 /* Entry Point: RexxSaveMacroSpace */
136 /* */
137 /* Input: ac - number of requested functions (0=all) */
138 /* av - list of function names to save */
139 /* fnam - name of file to save macros in */
140 /* */
141 /* Output: return code */
142 /* */
143 /*********************************************************************/
145  size_t count, /* count of arguments */
146  const char ** names, /* argument list */
147  const char * targetFile) /* file name */
148 {
150  {
151  // save an explicit list of macros
152  if (names != NULL)
153  {
154  return lam->macroSpaceManager.saveMacroSpace(targetFile, names, count);
155  }
156  else
157  {
158  // saving everything
159  return lam->macroSpaceManager.saveMacroSpace(targetFile);
160  }
161  }
162  EXIT_REXX_API();
163 }
164 
165 
166 /*********************************************************************/
167 /* */
168 /* Function Name: RexxLoadMacroSpace */
169 /* */
170 /* Description: loads entries from a file into macro space */
171 /* */
172 /* Entry Point: RexxLoadMacroSpace */
173 /* */
174 /* Input: ac - number of requested functions (0=all) */
175 /* av - list of function names to load */
176 /* fnam - name of file to load macros from */
177 /* */
178 /* Output: return code */
179 /* */
180 /*********************************************************************/
182  size_t count, // argument count
183  const char **names, // list of argument strings
184  const char *macroFile) // file name to load functs
185 {
187  {
188  // load an explicit list of macros
189  if (names != NULL)
190  {
191  return lam->macroSpaceManager.loadMacroSpace(macroFile, names, count);
192  }
193  else
194  {
195  // loading everything
196  return lam->macroSpaceManager.loadMacroSpace(macroFile);
197  }
198  }
199  EXIT_REXX_API();
200 }
201 
202 /*********************************************************************/
203 /* */
204 /* Function Name: RexxQueryMacro */
205 /* */
206 /* Description: search for a function in the workspace */
207 /* */
208 /* Entry Point: RexxQueryMacro */
209 /* */
210 /* Input: name - name of function to look for */
211 /* pos - pointer to storage for return of pos */
212 /* */
213 /* Output: return code */
214 /* */
215 /*********************************************************************/
216 
218  const char *name, /* name to search for */
219  unsigned short *pos) /* pointer for return of pos */
220 {
222  {
223  size_t order = 0;
224 
225  RexxReturnCode ret = lam->macroSpaceManager.queryMacro(name, &order);
226  *pos = (unsigned short)order;
227  return ret;
228  }
229  EXIT_REXX_API();
230 }
231 
232 
233 /*********************************************************************/
234 /* */
235 /* Function Name: RxRecorderMacro */
236 /* */
237 /* Description: change a functions search order position */
238 /* */
239 /* Entry Point: RexxReorderMacro */
240 /* */
241 /* Input: name - name of function to change order for */
242 /* pos - new search order position */
243 /* */
244 /* Output: return code */
245 /* */
246 /*********************************************************************/
247 
249  const char *name, /* name of function to change */
250  size_t pos) /* new position for function */
251 {
253  {
254  return lam->macroSpaceManager.reorderMacro(name, pos);
255  }
256  EXIT_REXX_API();
257 }
258 
259 
260 /*********************************************************************/
261 /* */
262 /* Function Name: RexxResolveMacroFunction */
263 /* */
264 /* Description: find a macro's pcode and literal images in */
265 /* the workspace */
266 /* */
267 /* Entry Point: RexxResolveMacroFunction */
268 /* */
269 /* Inputs: name - macro name asciiz string */
270 /* p - pointer for return of pcode+lits buf */
271 /* */
272 /* Output: return code */
273 /* */
274 /*********************************************************************/
275 
277  const char * name, /* name of func to find */
278  RXSTRING *p) /* storage for image return */
279 {
281  {
282  return lam->macroSpaceManager.getMacro(name, *p);
283  }
284  EXIT_REXX_API();
285 }
286 
RexxReturnCode RexxEntry RexxDropMacro(const char *name)
RexxReturnCode RexxEntry RexxAddMacro(const char *name, const char *file, size_t pos)
RexxReturnCode RexxEntry RexxResolveMacroFunction(const char *name, RXSTRING *p)
RexxReturnCode RexxEntry RexxLoadMacroSpace(size_t count, const char **names, const char *macroFile)
RexxReturnCode RexxEntry RexxClearMacroSpace()
RexxReturnCode RexxEntry RexxQueryMacro(const char *name, unsigned short *pos)
RexxReturnCode RexxEntry RexxReorderMacro(const char *name, size_t pos)
RexxReturnCode RexxEntry RexxSaveMacroSpace(size_t count, const char **names, const char *targetFile)
#define ENTER_REXX_API(target)
Definition: RexxAPI.h:49
#define EXIT_REXX_API()
Definition: RexxAPI.h:55
@ MacroSpaceManager
int RexxReturnCode
Definition: rexx.h:73
#define RexxEntry
Definition: rexx.h:412