1 | /* $Id: kRx.c,v 1.3 2000-12-11 06:53:56 bird Exp $
|
---|
2 | *
|
---|
3 | * kRx - Small rexx script interpreter.
|
---|
4 | *
|
---|
5 | * Will be re-written in assembly later!!!
|
---|
6 | *
|
---|
7 | * Copyright (c) 2000 knut st. osmundsen (knut.stange.osmundsen@mynd.no)
|
---|
8 | *
|
---|
9 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
10 | *
|
---|
11 | */
|
---|
12 |
|
---|
13 |
|
---|
14 |
|
---|
15 | /*******************************************************************************
|
---|
16 | * Defined Constants And Macros *
|
---|
17 | *******************************************************************************/
|
---|
18 | #define INCL_REXXSAA
|
---|
19 | #define INCL_DOSERRORS
|
---|
20 |
|
---|
21 | #undef DEBUGOUT
|
---|
22 |
|
---|
23 | /*******************************************************************************
|
---|
24 | * Internal Functions *
|
---|
25 | *******************************************************************************/
|
---|
26 | #include <os2.h>
|
---|
27 | #include <rexxsaa.h>
|
---|
28 |
|
---|
29 | #include <stdio.h>
|
---|
30 | #include <string.h>
|
---|
31 | /*#include <malloc.h> */
|
---|
32 |
|
---|
33 | /**
|
---|
34 | * Main function.
|
---|
35 | * @returns Return code from RexxStart.
|
---|
36 | * @param argc Argument count.
|
---|
37 | * @param argv Argument vector.
|
---|
38 | * All options ('/' or '-' prefixed words) before the
|
---|
39 | * REXX script name is ignored currently.
|
---|
40 | * The arguments after the rexx script name are passed
|
---|
41 | * ont to the rexx script.
|
---|
42 | * @sketch
|
---|
43 | * @status
|
---|
44 | * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
|
---|
45 | * @remark
|
---|
46 | */
|
---|
47 | int main(int argc, char **argv)
|
---|
48 | {
|
---|
49 | static char achArgs[4096]; /* Buffer for arguments. */
|
---|
50 | RXSTRING rxstrArgs; /* Rexx arguments - one string. */
|
---|
51 | int cArgs; /* Number of rexx arguments. */
|
---|
52 | SHORT sRexxRc; /* Rexx command return code (converted string). */
|
---|
53 | RXSTRING rxstrRexxRc; /* Rexx command return code string. */
|
---|
54 | int iScriptName; /* Argument index of the script name. */
|
---|
55 | int argi; /* Argument index loop variable. */
|
---|
56 | APIRET rc; /* Return code from RexxStart. */
|
---|
57 | ULONG ul; /* Dummy used by DosWrite. */
|
---|
58 |
|
---|
59 | /*
|
---|
60 | * Find Rexx script filename.
|
---|
61 | */
|
---|
62 | iScriptName = 1;
|
---|
63 | while (iScriptName < argc
|
---|
64 | && argv[iScriptName][0] == '/'
|
---|
65 | && argv[iScriptName][0] == '-'
|
---|
66 | )
|
---|
67 | iScriptName++;
|
---|
68 |
|
---|
69 | /*
|
---|
70 | * Did we find it?
|
---|
71 | */
|
---|
72 | if (iScriptName >= argc)
|
---|
73 | {
|
---|
74 | DosWrite(2, "Invalid parameters, script filename is missing.\r\n", 47, &ul);
|
---|
75 | return -10000;
|
---|
76 | }
|
---|
77 |
|
---|
78 | /*
|
---|
79 | * Create the rexx script arguments.
|
---|
80 | */
|
---|
81 | argi = iScriptName + 1;
|
---|
82 | if (argi < argc)
|
---|
83 | {
|
---|
84 | char *psz = &achArgs[0];
|
---|
85 |
|
---|
86 | while (argi < argc)
|
---|
87 | {
|
---|
88 | int cch = strlen(argv[argi]);
|
---|
89 | memcpy(psz, argv[argi], cch);
|
---|
90 | psz += cch;
|
---|
91 | *psz++ = ' ';
|
---|
92 | argi++;
|
---|
93 | }
|
---|
94 | *--psz = '\0';
|
---|
95 | cArgs = 1;
|
---|
96 | MAKERXSTRING(rxstrArgs, &achArgs[0], (int)psz - (int)&achArgs[0]);
|
---|
97 | }
|
---|
98 | else
|
---|
99 | { /* no arguments */
|
---|
100 | cArgs = 0;
|
---|
101 | MAKERXSTRING(rxstrArgs, NULL, 0);
|
---|
102 | }
|
---|
103 |
|
---|
104 |
|
---|
105 | /*
|
---|
106 | * Initiate return string.
|
---|
107 | */
|
---|
108 | MAKERXSTRING(rxstrRexxRc, NULL, 0);
|
---|
109 |
|
---|
110 | /*
|
---|
111 | * Call RexxStart
|
---|
112 | */
|
---|
113 | rc = RexxStart(cArgs, /* Number of arguments. */
|
---|
114 | &rxstrArgs, /* Pointer to argument array. */
|
---|
115 | argv[iScriptName], /* Name of REXX script. */
|
---|
116 | NULL, /* Pointer ot INSTORE? Not used. */
|
---|
117 | "HMM", /* Hmm? Command env. name */
|
---|
118 | RXCOMMAND, /* Program called as Command */
|
---|
119 | NULL, /*??*/ /* EXIT... fixme */
|
---|
120 | &sRexxRc, /* Rexx program return code. */
|
---|
121 | &rxstrRexxRc); /* Rexx program return string. */
|
---|
122 |
|
---|
123 | /*
|
---|
124 | * Debug display result.
|
---|
125 | */
|
---|
126 | #ifdef DEBUGOUT
|
---|
127 | printf(
|
---|
128 | "Interpreter rc: %d\n"
|
---|
129 | "Function rc: %d\n"
|
---|
130 | "Return string: '%s'\n",
|
---|
131 | rc,
|
---|
132 | sRexxRc,
|
---|
133 | rxstrRexxRc.strptr);
|
---|
134 | #endif
|
---|
135 |
|
---|
136 | DosFreeMem(rxstrRexxRc.strptr); /* Release storage from RexxStart. */
|
---|
137 |
|
---|
138 | if (rc == NO_ERROR)
|
---|
139 | return sRexxRc;
|
---|
140 | return -10002;
|
---|
141 | }
|
---|