source: trunk/src/win32k/rexx/kRx.c@ 3518

Last change on this file since 3518 was 3518, checked in by bird, 25 years ago

Initial coding.
Known bug: don't handle arguments before the script filename.

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