2 Copyright © 2007-2011, 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)
43 rexxport
= FindPort("REXX");
46 if (SystemTags("RexxMast", SYS_Asynch
, TRUE
, TAG_DONE
) >= 0)
48 SystemTags("WaitForPort REXX", TAG_DONE
);
51 rexxport
= FindPort("REXX");
54 FPuts(out
, "Could not start RexxMast\n");
58 replyport
= CreatePort(NULL
, 0);
59 if (replyport
== NULL
)
61 FPuts(out
, "Could not create a port\n");
65 msg
= CreateRexxMsg(replyport
, NULL
, NULL
);
68 FPuts(out
, "Could not create RexxMsg\n");
71 msg
->rm_Action
= RXCOMM
| RXFF_RESULT
;
72 msg
->rm_Stdin
= Input();
73 msg
->rm_Stdout
= Output();
81 Close(msg
->rm_Stdout
);
85 DeletePort(replyport
);
86 if (olddir
!= (BPTR
)-1)
90 int main(int argc
, char **argv
)
92 struct RexxMsg
*reply
;
103 FPuts(out
, "Usage: RX <filename> [arguments]\n"
104 " RX \"commands\"\n");
111 struct WBStartup
*startup
= (struct WBStartup
*) argv
;
112 char *s
= startup
->sm_ArgList
[1].wa_Name
;
114 if (startup
->sm_NumArgs
< 2)
120 olddir
= CurrentDir(startup
->sm_ArgList
[1].wa_Lock
);
121 out
= msg
->rm_Stdout
= Open("CON:////RX Output/CLOSE/WAIT/AUTO", MODE_READWRITE
);
124 msg
->rm_Args
[0] = (IPTR
)CreateArgstring(s
, strlen(s
));
130 struct Process
*me
= (struct Process
*)FindTask(NULL
);
133 s
= me
->pr_Arguments
;
134 while(isspace(*s
)) s
++;
139 while((s
[length
] != '"') && (s
[length
] != '\0')) length
++;
142 FPuts(out
, "Empty command\n");
146 if (s
[length
] == '\0')
148 FPuts(out
, "Unterminated string\n");
153 msg
->rm_Args
[0] = (IPTR
)CreateArgstring(s
, length
);
154 /* It is a literal command with 1 argument */
155 msg
->rm_Action
|= (RXFF_STRING
| 1);
160 while((s
[length
] != '\'')
161 && (s
[length
] != '\0')
162 && (s
[length
] != '\n')
166 msg
->rm_Args
[0] = (IPTR
)CreateArgstring(s
, length
);
167 /* It is a literal command with 1 argument */
168 msg
->rm_Action
|= (RXFF_STRING
| 1);
172 if (s
[strlen(s
)-1] == '\n')
173 s
[strlen(s
)-1] = '\0';
175 msg
->rm_Args
[0] = (IPTR
)CreateArgstring(s
, strlen(s
));
181 PutMsg(rexxport
, (struct Message
*)msg
);
183 reply
= (struct RexxMsg
*)WaitPort(replyport
);
184 } while (reply
!= msg
);
186 ret
= msg
->rm_Result1
;
187 if (msg
->rm_Result1
== RC_OK
)
188 FPrintf(out
, "Script executed and returned: %ld\n", msg
->rm_Result2
);
190 FPrintf(out
, "Error executing script %ld/%ld\n",
191 msg
->rm_Result1
, msg
->rm_Result2
194 ClearRexxMsg(msg
, msg
->rm_Action
& RXARGMASK
);