2 Copyright © 2007-2013, The AROS Development Team. All rights reserved.
9 #include <dos/dosextens.h>
10 #include <dos/dostags.h>
11 #include <rexx/storage.h>
12 #include <rexx/errors.h>
13 #include <workbench/startup.h>
15 #include <proto/exec.h>
16 #include <proto/dos.h>
17 #include <proto/rexxsyslib.h>
18 #include <proto/alib.h>
27 static struct RexxMsg
*msg
= NULL
;
28 static struct MsgPort
*rexxport
= NULL
, *replyport
= NULL
;
30 static BOOL closestdout
= FALSE
;
31 static BPTR olddir
= (BPTR
)-1;
33 static BOOL
init(void)
41 rexxport
= FindPort("REXX");
44 if (SystemTags("RexxMast", SYS_Asynch
, TRUE
,
45 SYS_Input
, BNULL
, SYS_Output
, BNULL
,
50 SystemTags("WaitForPort REXX", TAG_DONE
);
53 rexxport
= FindPort("REXX");
56 FPuts(out
, "Could not start RexxMast; no Rexx interpreter seems to be installed\n");
60 replyport
= CreatePort(NULL
, 0);
61 if (replyport
== NULL
)
63 FPuts(out
, "Could not create a port\n");
67 msg
= CreateRexxMsg(replyport
, NULL
, NULL
);
70 FPuts(out
, "Could not create RexxMsg\n");
73 msg
->rm_Action
= RXCOMM
| RXFF_RESULT
;
74 msg
->rm_Stdin
= Input();
75 Flush(msg
->rm_Stdin
); /* Remove command line arguments */
76 msg
->rm_Stdout
= Output();
84 Close(msg
->rm_Stdout
);
88 DeletePort(replyport
);
89 if (olddir
!= (BPTR
)-1)
93 int main(int argc
, char **argv
)
95 struct RexxMsg
*reply
;
106 FPuts(out
, "Usage: RX <filename> [arguments]\n"
107 " RX \"commands\"\n");
114 struct WBStartup
*startup
= (struct WBStartup
*) argv
;
115 char *s
= startup
->sm_ArgList
[1].wa_Name
;
117 if (startup
->sm_NumArgs
< 2)
123 olddir
= CurrentDir(startup
->sm_ArgList
[1].wa_Lock
);
124 out
= msg
->rm_Stdout
= Open("CON:////RX Output/CLOSE/WAIT/AUTO", MODE_READWRITE
);
127 msg
->rm_Args
[0] = (IPTR
)CreateArgstring(s
, strlen(s
));
133 struct Process
*me
= (struct Process
*)FindTask(NULL
);
136 s
= me
->pr_Arguments
;
137 while(isspace(*s
)) s
++;
142 while((s
[length
] != '"') && (s
[length
] != '\0')) length
++;
145 FPuts(out
, "Empty command\n");
149 /* Lazy string termination like ARexx */
151 if (s
[length
] == '\0')
153 FPuts(out
, "Unterminated string\n");
159 msg
->rm_Args
[0] = (IPTR
)CreateArgstring(s
, length
);
160 /* It is a literal command with 1 argument */
161 msg
->rm_Action
|= (RXFF_STRING
| 1);
166 while((s
[length
] != '\'')
167 && (s
[length
] != '\0')
168 && (s
[length
] != '\n')
172 msg
->rm_Args
[0] = (IPTR
)CreateArgstring(s
, length
);
173 /* It is a literal command with 1 argument */
174 msg
->rm_Action
|= (RXFF_STRING
| 1);
178 if (s
[strlen(s
)-1] == '\n')
179 s
[strlen(s
)-1] = '\0';
181 msg
->rm_Args
[0] = (IPTR
)CreateArgstring(s
, strlen(s
));
187 PutMsg(rexxport
, (struct Message
*)msg
);
189 reply
= (struct RexxMsg
*)WaitPort(replyport
);
190 } while (reply
!= msg
);
192 ret
= msg
->rm_Result1
;
193 if (msg
->rm_Result1
== RC_OK
)
194 /* Less verbosity like ARexx, use "get Result2" */
196 FPrintf(out
, "Script executed and returned: %ld\n", msg
->rm_Result2
);
201 FPrintf(out
, "Error executing script %ld/%ld\n",
202 msg
->rm_Result1
, msg
->rm_Result2
205 ClearRexxMsg(msg
, msg
->rm_Action
& RXARGMASK
);