LocalMacroSpaceManager.hpp
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 #ifndef LocalMacroSpaceManager_HPP_INCLUDED
40 #define LocalMacroSpaceManager_HPP_INCLUDED
41 
42 #include "LocalAPISubsystem.hpp"
43 #include "ServiceMessage.hpp"
44 #include "rexx.h"
45 #include "Rxstring.hpp"
46 #include "Utilities.hpp"
47 #include "SysFile.hpp"
48 
49 // Macro space version information
50 #define RXVERSION "REXX-ooRexx 6.00"
51 #define RXVERSIZE (sizeof(RXVERSION) - 1)
52 // Macrospace signature
53 #define SIGNATURE 0xddd5
54 
56 {
57 public:
58 enum { MACRONAMESIZE = 256 };
59 
61  MacroSpaceDescriptor(const char *n, size_t s, size_t o)
62  {
63  strcpy(name, n);
64  image.strlength = s;
65  image.strptr = NULL;
66  imageSize = s;
67  position = o;
68  }
69 
70  void *reserved; // this is the next pointer in old platforms, but saved in file
71  char name[MACRONAMESIZE]; // function name
72  RXSTRING image; // place holder only
73  size_t imageSize; // size of image
74  size_t position; // preorder/postorder flag
75 };
76 
77 
79 {
80 public:
82 
84  {
85  memcpy(version, RXVERSION, RXVERSIZE);
87  count = c;
88  }
89 
90  char version[RXVERSIZE]; // version of the Rexx interpreter
91  size_t magicNumber; // macro space magic number
92  size_t count; // count of macros in the saved file
93 };
94 
95 
96 class NameTable
97 {
98 public:
99  NameTable(const char **n, size_t c)
100  {
101  names = n;
102  count = c;
103  }
104 
105  bool inTable(const char *name)
106  {
107  for (size_t i = 0; i < count; i++)
108  {
109  if (Utilities::strCaselessCompare(name, names[i]) == 0)
110  {
111  return true;
112  }
113  }
114  return false;
115  }
116 
117 protected:
118  const char **names; // pointer to list of names
119  size_t count; // name count
120 };
121 
123 {
124 public:
125  MacroSpaceFile(const char *name) : fileName(name), fileInst(NULL) { ; }
126 
127  ~MacroSpaceFile();
128  void close();
129  size_t openForLoading();
130  void nextMacro(char *name, ManagedRxstring &image, size_t &order);
131  void nextMacro(NameTable names, char *name, ManagedRxstring &image, size_t &order);
132  void setFilePosition(size_t p);
133  void create(size_t count);
134  void writeMacroDescriptor(const char *name, size_t size, size_t order);
135  void read(void *data, size_t length);
136  void read(ManagedRxstring &data, size_t length);
137  void write(const void *data, size_t length);
138 
139  inline void write(const char *str)
140  {
141  write(str, strlen(str) + 1);
142  }
143 
144  inline void write(size_t i)
145  {
146  write((void *)&i, sizeof(size_t));
147  }
148 
149  inline void write(RXSTRING &data)
150  {
151  write(data.strptr, data.strlength);
152  }
153 
154 protected:
155  bool creating; // indicates whether we are reading or creating
156  const char *fileName;
159  size_t imageBase;
160 };
161 
162 
163 
164 // local instance of the macro API...this is a proxy that communicates with the
165 // server that manages the macrospace
167 {
168 public:
169 
171 
172  RexxReturnCode loadMacroSpace(const char *target);
173  RexxReturnCode loadMacroSpace(const char *target, const char **nameList, size_t nameCount);
174  RexxReturnCode saveMacroSpace(const char *target);
175  RexxReturnCode queryMacro(const char *target, size_t *pos);
176  RexxReturnCode reorderMacro(const char *target, size_t pos);
177  RexxReturnCode getMacro(const char *target, RXSTRING &image);
178  RexxReturnCode saveMacroSpace(const char *target, const char **names, size_t count);
180  RexxReturnCode removeMacro(const char *name);
181  RexxReturnCode addMacroFromFile(const char *name, const char *sourceFile, size_t position);
182  RexxReturnCode addMacro(const char *name, ManagedRxstring &imageData, size_t position);
183  void translateRexxProgram(const char *sourcefile, ManagedRxstring &imageData);
184  void readRxstringFromFile(SysFile *file, ManagedRxstring &target, size_t size);
187 };
188 
189 
190 #endif
191 
#define RXVERSIZE
#define RXVERSION
#define SIGNATURE
RexxReturnCode addMacro(const char *name, ManagedRxstring &imageData, size_t position)
RexxReturnCode mapReturnResult(ServiceMessage &m)
RexxReturnCode removeMacro(const char *name)
void readRxstringFromFile(SysFile *file, ManagedRxstring &target, size_t size)
RexxReturnCode queryMacro(const char *target, size_t *pos)
RexxReturnCode loadMacroSpace(const char *target)
RexxReturnCode getMacro(const char *target, RXSTRING &image)
void translateRexxProgram(const char *sourcefile, ManagedRxstring &imageData)
virtual RexxReturnCode processServiceException(ServiceException *e)
RexxReturnCode saveMacroSpace(const char *target)
RexxReturnCode reorderMacro(const char *target, size_t pos)
RexxReturnCode addMacroFromFile(const char *name, const char *sourceFile, size_t position)
MacroSpaceDescriptor(const char *n, size_t s, size_t o)
void write(const char *str)
void write(RXSTRING &data)
MacroSpaceFile(const char *name)
void create(size_t count)
void setFilePosition(size_t p)
void nextMacro(char *name, ManagedRxstring &image, size_t &order)
void write(const void *data, size_t length)
void read(void *data, size_t length)
void writeMacroDescriptor(const char *name, size_t size, size_t order)
NameTable(const char **n, size_t c)
const char ** names
bool inTable(const char *name)
static int strCaselessCompare(const char *opt1, const char *opt2)
Definition: Utilities.cpp:102
int RexxReturnCode
Definition: rexx.h:73
size_t strlength
Definition: rexx.h:157
char * strptr
Definition: rexx.h:158