windows/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 /* Oryx Kernel rexx.c */
40 /* */
41 /* translate a program and save to an output file */
42 /* */
43 /******************************************************************************/
44 #include <stdlib.h>
45 #include <stdio.h>
46 #include <string.h>
47 #include "windows.h"
48 #include "rexx.h"
49 #include "PlatformDefinitions.h"
50 #include "RexxErrorCodes.h"
51 #include "RexxInternalApis.h"
52 
53 #define DLLNAME "rexx.dll"
54 
55 #define BUFFERLEN 256 /* Length of message bufs used */
56 
57 // TODO: Add these to the official API list
58 
59 void DisplayError(HINSTANCE hDll, int err_no)
60 {
61  char str[BUFFERLEN];
62  if (LoadString(hDll, err_no, str, BUFFERLEN))
63  printf("\n%s", str);
64  else
65  printf("\nError in service program but no error message found!");
66 }
67 
68 
69 int SysCall main(int argc, char **argv)
70 {
71  char fn[2][BUFFERLEN];
72  int silent = 0;
73  int j = 0;
74 
75  HINSTANCE hDll=NULL;
76 
77  hDll = LoadLibrary(DLLNAME);
78 
79  for (j=1; j<argc; j++)
80  {
81  if (((argv[j][0] == '/') || (argv[j][0] == '-'))
82  && ((argv[j][1] == 's') || (argv[j][1] == 'S'))) silent = j;
83  }
84  if (!silent)
85  {
86  char *ptr = RexxGetVersionInformation();
87  if (ptr) {
88  printf(ptr, "Tokenizer");
89  printf("\n");
90  RexxFreeMemory(ptr);
91  }
92  }
93 
94  /* check arguments: at least 1 argument, max. 2, /s must be last */
95  if ((argc < 2) || (argc > 4) || /* invalid no. of args */
96  (silent && (argc == 2)) || /* only /s */
97  (silent && (silent+1 != argc)) || /* /s not last arg */
98  (!silent && (argc == 4))) /* 3 args, no /s */
99  {
100  if (argc > 2) {
102  }
105  if (hDll) FreeLibrary(hDll);
106  exit(-1);
107  }
108 
109  strcpy(fn[0], argv[1]);
110  if (argc >= 3) strcpy(fn[1], argv[2]);
111 
112  if ( ((argc>3) || ((argc==3) && !silent)) &&
113  (strcmp(strupr(fn[0]), strupr(fn[1])) == 0))
114  {
116  if (hDll) FreeLibrary(hDll);
117  exit(-2);
118  }
119 
120  if (hDll) FreeLibrary(hDll);
121 
122  if ((argc == 2) || ((argc==3) && silent) ) /* just doing a syntax check? */
123  /* go perform the translation */
124  return RexxTranslateProgram(argv[1], NULL, NULL);
125  else /* translate and save the output */
126  return RexxTranslateProgram(argv[1], argv[2], NULL);
127 }
char *REXXENTRY RexxGetVersionInformation()
RexxReturnCode REXXENTRY RexxTranslateProgram(const char *inFile, const char *outFile, PRXSYSEXIT exits)
#define Error_REXXC_cmd_parm_incorrect
#define Error_REXXC_SynCheckInfo
#define Error_REXXC_wrongNrArg
#define Error_REXXC_outDifferent
RexxReturnCode REXXENTRY RexxFreeMemory(void *)
#define SysCall
void strupr(char *string)
#define BUFFERLEN
#define DLLNAME
int SysCall main(int argc, char **argv)
void DisplayError(HINSTANCE hDll, int err_no)