unix/rxsubcom.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.oorexx.org/license.html */
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 /* */
40 /* Program Name: AIXRXCMD.C */
41 /* */
42 /* Descriptive Name: AIX/Linux Command Line Program for Subcommand */
43 /* Interface. */
44 /* */
45 /*********************************************************************/
46 #ifdef HAVE_CONFIG_H
47 # include "config.h"
48 #endif
49 
50 #if defined( HAVE_NL_TYPES_H )
51 # include <nl_types.h>
52 #endif
53 
54 #include <limits.h>
55 #include <string.h> /* Include string functions */
56 #include <stdio.h>
57 
58 #include "rexx.h" /* for REXXSAA functionality */
59  /* old msg constants replaced!*/
60 #include "RexxInternalApis.h" /* Get private REXXAPI API's */
61 #include "RexxErrorCodes.h"
62 #include "RexxMessageNumbers.h"
63 
64 #define REXXMESSAGEFILE "rexx.cat"
65 
66 #define BUFFERLEN 256 /* Length of message bufs used*/
67  /* Macro for argv[1] compares */
68 #define CASE(x) if(!strcasecmp(x,argv[1]))
69 
70 #ifdef LINUX /* AIX already defined */
71 #define SECOND_PARAMETER 1 /* different sign. Lin-AIX */
72 #else
73 #define SECOND_PARAMETER 0 /* 0 for no NL_CAT_LOCALE */
74 #endif
75 
76 #ifndef CATD_ERR
77 #define CATD_ERR ((nl_catd)-1) /* Duplicate for AIX */
78 #endif
79 
80 void parmerr(int );
81 
82 int main( int argc, char *argv[ ], char *envp[ ] )
83 { /* */
84  const char * scbname; /* registration name */
85  const char * scbdll_name; /* DLL file name */
86  const char * scbdll_proc; /* DLL procedure name */
87 
88  /* Must be at lease 1 argument*/
89  if (argc<2)
90  {
92  }
93 
94  CASE("REGISTER")
95  { /* Registration check */
96  /* requires 4 parameters */
97  if (argc<5)
98  {
100  }
101  scbname=argv[2]; /* Should be Environment Name */
102  scbdll_name=argv[3]; /* Should be Dll Name */
103  scbdll_proc=argv[4]; /* Should be Function Name */
104  /* Go register the environment*/
105  return RexxRegisterSubcomDll(argv[2], argv[3], argv[4], NULL, RXSUBCOM_DROPPABLE);
106  } /* */
107  CASE("QUERY")
108  { /* Query Check */
109  /* requires 3 parameters */
110  if (argc<3)
111  {
113  }
114  /* if only 3 passed, dummy 4 */
115  if (argc<4)
116  {
117  scbdll_name = "";
118  }
119  else
120  {
121  scbdll_name = argv[3];
122  }
123  unsigned short flags;
124  return RexxQuerySubcom(argv[2], scbdll_name, &flags, NULL);
125  } /* */
126  CASE("DROP")
127  { /* Drop Check */
128  /* Must pass at least 3 args*/
129  if (argc<3)
130  {
132  }
133  /* if only 3 passed, dummy 4 */
134  if (argc<4)
135  {
136  scbdll_name = "";
137  }
138  else
139  {
140  scbdll_name = argv[3];
141  }
142  return RexxDeregisterSubcom(argv[2], scbdll_name);
143  }
144  CASE("LOAD")
145  {
146  if (argc<3)
147  {
149  }
150  if (argc<4)
151  {
152  scbdll_name = "";
153  }
154  else
155  {
156  scbdll_name = argv[3];
157  }
158  return RexxLoadSubcom(argv[2], argv[3]);
159  }
160  parmerr(Error_RXSUBC_general_msg); /* Otherwise, must be a error */
161  return 0; /* dummy return */
162 }
163 
164 void parmerr( int msgid ) /* removed useless code */
165 {
166 #if defined( HAVE_NL_TYPES_H )
167  nl_catd catd; /* catalog descriptor from catopen() */
168 #endif
169  int set_num = 1; /* message set 1 from catalog */
170  char *message; /* message pointer */
171  char DataArea[BUFFERLEN]; /* buf to return message */
172 
173 #if defined( HAVE_CATOPEN )
174  /* open message catalog in NLSPATH */
175  if ((catd = catopen(REXXMESSAGEFILE, SECOND_PARAMETER)) == (nl_catd)CATD_ERR)
176  {
177  snprintf(DataArea, sizeof DataArea, "%s/%s", ORX_CATDIR, REXXMESSAGEFILE);
178  if ((catd = catopen(DataArea, SECOND_PARAMETER)) == (nl_catd)CATD_ERR)
179  {
180  fprintf(stderr, "\nCannot open REXX message catalog %s.\nNot in NLSPATH or %s.\n",
181  REXXMESSAGEFILE, ORX_CATDIR);
182  }
183  } /* retrieve message from repository */
184  if (catd != (nl_catd)CATD_ERR)
185  {
186  message = catgets(catd, set_num, msgid, NULL);
187 
188  if (!message) /* got a message ? */
189 #if defined(OPSYS_LINUX) && !defined(OPSYS_SUN)
190  {
191  snprintf(DataArea, sizeof DataArea, "%s/%s", ORX_CATDIR, REXXMESSAGEFILE);
192  if ((catd = catopen(DataArea, SECOND_PARAMETER)) == (nl_catd)CATD_ERR)
193  {
194  printf("\nCannot open REXX message catalog %s.\nNot in NLSPATH or %s.\n",
195  REXXMESSAGEFILE, ORX_CATDIR);
196  }
197  else
198  {
199  message = catgets(catd, set_num, msgid, NULL);
200  if (!message) /* got a message ? */
201  {
202  printf("\n Error message not found!\n");
203  }
204  else
205  {
206  printf("\n%s\n", message); /* print the message */
207  }
208  }
209  }
210 #else
211  {
212  printf("\n Error message not found!\n");
213  }
214  else
215  {
216  printf("\n%s\n", message); /* print the message */
217  }
218 #endif
219  catclose(catd); /* close the catalog */
220  }
221 #else
222  printf("\n Cannot get description for error %d!\n",msgid);
223 #endif
224 
225  exit(-1);
226 }
RexxReturnCode REXXENTRY RexxLoadSubcom(const char *, const char *)
#define Error_RXSUBC_general_msg
#define Error_RXSUBC_register_msg
#define Error_RXSUBC_query_msg
#define Error_RXSUBC_load_msg
#define Error_RXSUBC_drop_msg
RexxReturnCode REXXENTRY RexxQuerySubcom(CONSTANT_STRING, CONSTANT_STRING, unsigned short *, char *)
RexxReturnCode REXXENTRY RexxDeregisterSubcom(CONSTANT_STRING, CONSTANT_STRING)
RexxReturnCode REXXENTRY RexxRegisterSubcomDll(CONSTANT_STRING, CONSTANT_STRING, CONSTANT_STRING, CONSTANT_STRING, size_t)
#define RXSUBCOM_DROPPABLE
Definition: rexxapidefs.h:72
#define BUFFERLEN
#define CATD_ERR
#define CASE(x)
void parmerr(int)
#define REXXMESSAGEFILE
#define SECOND_PARAMETER
int main(int argc, char *argv[], char *envp[])