unix/RexxCompiler.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 /* REXX Kernel rexxc.c */
40 /* */
41 /* Translates a program and saves it in an output file */
42 /* */
43 /* Common code for AIX and LINUX */
44 /* */
45 /******************************************************************************/
46 #ifdef HAVE_CONFIG_H
47 # include "config.h"
48 #endif
49 
50 #include <limits.h>
51 #include <stdlib.h>
52 #include <stdio.h>
53 #include <string.h>
54 
55 #if defined( HAVE_FEATURES_H )
56 # include <features.h>
57 #endif
58 
59 #if defined( HAVE_NL_TYPES_H )
60 # include <nl_types.h>
61 #endif
62 
63 #include "rexx.h"
64 #include "RexxMessageNumbers.h"
65 #define REXXMESSAGEFILE "rexx.cat"
66 
67 #define BUFFERLEN 256 /* Length of message bufs used */
68 #ifdef LINUX
69 #define SECOND_PARAMETER 1 /* different sign. Lin-AIX */
70 #else
71 #define SECOND_PARAMETER 0 /* 0 for no NL_CAT_LOCALE */
72 #endif
73 
74 #ifndef CATD_ERR
75 #define CATD_ERR ((nl_catd)-1) /* Duplicate for AIX */
76 #endif
77 
78 void DisplayError(int msgid) /* simplified catalog access@MAE004M */
79 {
80 #if defined( HAVE_NL_TYPES_H )
81  nl_catd catd; /* catalog descriptor from catopen() */
82 #endif
83  int set_num = 1; /* message set 1 from catalog */
84  const char *message; /* message pointer */
85  char DataArea[256]; /* buf to return message */
86 
87 #if defined( HAVE_CATOPEN )
88  /* open message catalog in NLSPATH */
89  if ((catd = catopen(REXXMESSAGEFILE, SECOND_PARAMETER)) == (nl_catd)CATD_ERR)
90  {
91  sprintf(DataArea, "%s/%s", ORX_CATDIR, REXXMESSAGEFILE);
92  if ((catd = catopen(DataArea, SECOND_PARAMETER)) == (nl_catd)CATD_ERR)
93  {
94  printf("\n*** Cannot open REXX message catalog %s.\nNot in NLSPATH or %s.\n",
95  REXXMESSAGEFILE, ORX_CATDIR );
96  return; /* terminate program */
97  }
98  } /* retrieve message from repository */
99  message = catgets(catd, set_num, msgid, NULL);
100  if (!message) /* got a message ? */
101  {
102  sprintf(DataArea, "%s/%s", ORX_CATDIR, REXXMESSAGEFILE);
103  if ((catd = catopen(DataArea, SECOND_PARAMETER)) == (nl_catd)CATD_ERR)
104  {
105  printf("\nCannot open REXX message catalog %s.\nNot in NLSPATH or %s.\n",
106  REXXMESSAGEFILE, ORX_CATDIR);
107  }
108  else
109  {
110  message = catgets(catd, set_num, msgid, NULL);
111  if (!message) /* got a message ? */
112  {
113  printf("\n Error message not found!\n");
114  }
115  else
116  {
117  printf("\n%s\n", message); /* print the message */
118  }
119  }
120  }
121  else
122  {
123  printf("\n%s\n", message); /* print the message */
124  }
125  catclose(catd); /* close the catalog */
126 #else
127  printf("*** Cannot get description for error %d!", msgid);
128 #endif
129  return; /* terminate program */
130 }
131 
132 int main (int argc, char **argv)
133 {
134  bool silent = false;
135  int silentp;
136  char *ptr;
137  /* check for /s option */
138  for (silentp = 1; silentp < argc; silentp++)
139  {
140  if (argv[silentp][0] == '-' &&
141  (argv[silentp][1] == 's' || argv[silentp][1] == 'S'))
142  {
143  silent = true;
144  break;
145  }
146  }
147  if (!silent) /* display version and copyright */
148  {
150  printf(ptr);
151  printf("\n");
152  RexxFreeMemory(ptr);
153  }
154  /* Check validity of arguments */
155  if (argc < 2 || argc > 4 || /* # args exceeding bounds */
156  (silent && argc==2) || /* -s is the first argument */
157  (silent && (silentp + 1 < argc)) || /* -s is not the last argument */
158  (!silent && argc==4)) /* 3 arguments, but no /s */
159  {
160  if (argc > 2)
161  {
163  }
166  exit(-1); /* terminate with an error */
167  } /* end additions */
168  /* modified control logic */
169  if ((argc==4 && silent) || (argc==3 && !silent))
170  {
171  if (strcmp(argv[1], argv[2]) == 0)
172  {
174  exit(-2); /* terminate with an error */
175  }
176  /* translate and save the output */
177  return RexxTranslateProgram(argv[1], argv[2], NULL);
178  }
179  else /* just doing syntax check */
180  {
181  return RexxTranslateProgram(argv[1], NULL, NULL);
182  }
183 }
char *REXXENTRY RexxGetVersionInformation()
RexxReturnCode REXXENTRY RexxTranslateProgram(const char *inFile, const char *outFile, PRXSYSEXIT exits)
#define Error_REXXC_SynCheckInfo_msg
#define Error_REXXC_wrongNrArg_unix_msg
#define Error_REXXC_outDifferent_msg
#define Error_REXXC_cmd_parm_incorrect_msg
RexxReturnCode REXXENTRY RexxFreeMemory(void *)
int main(int argc, char **argv)
#define CATD_ERR
void DisplayError(int msgid)
#define REXXMESSAGEFILE
#define SECOND_PARAMETER