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)
41 rexxport
= FindPort("REXX");
44 if (SystemTags("RexxMast", SYS_Asynch
, TRUE
, TAG_DONE
) >= 0)
46 SystemTags("WaitForPort REXX", TAG_DONE
);
49 rexxport
= FindPort("REXX");
52 FPuts(out
, "Could not start RexxMast\n");
56 replyport
= CreatePort(NULL
, 0);
57 if (replyport
== NULL
)
59 FPuts(out
, "Could not create a port\n");
63 msg
= CreateRexxMsg(replyport
, NULL
, NULL
);
66 FPuts(out
, "Could not create RexxMsg\n");
69 msg
->rm_Action
= RXCOMM
| RXFF_RESULT
;
70 msg
->rm_Stdin
= Input();
71 msg
->rm_Stdout
= Output();
79 Close(msg
->rm_Stdout
);
83 DeletePort(replyport
);
84 if (olddir
!= (BPTR
)-1)
88 int main(int argc
, char **argv
)
90 struct RexxMsg
*reply
;
101 FPuts(out
, "Usage: RX <filename> [arguments]\n"
102 " RX \"commands\"\n");
109 struct WBStartup
*startup
= (struct WBStartup
*) argv
;
110 char *s
= startup
->sm_ArgList
[1].wa_Name
;
112 if (startup
->sm_NumArgs
< 2)
118 olddir
= CurrentDir(startup
->sm_ArgList
[1].wa_Lock
);
119 out
= msg
->rm_Stdout
= Open("CON:////RX Output/CLOSE/WAIT/AUTO", MODE_READWRITE
);
122 msg
->rm_Args
[0] = (IPTR
)CreateArgstring(s
, strlen(s
));
128 struct Process
*me
= (struct Process
*)FindTask(NULL
);
131 s
= me
->pr_Arguments
;
132 while(isspace(*s
)) s
++;
137 while((s
[length
] != '"') && (s
[length
] != '\0')) length
++;
140 FPuts(out
, "Empty command\n");
144 if (s
[length
] == '\0')
146 FPuts(out
, "Unterminated string\n");
151 msg
->rm_Args
[0] = (IPTR
)CreateArgstring(s
, length
);
152 /* It is a literal command with 1 argument */
153 msg
->rm_Action
|= (RXFF_STRING
| 1);
158 while((s
[length
] != '\'')
159 && (s
[length
] != '\0')
160 && (s
[length
] != '\n')
164 msg
->rm_Args
[0] = (IPTR
)CreateArgstring(s
, length
);
165 /* It is a literal command with 1 argument */
166 msg
->rm_Action
|= (RXFF_STRING
| 1);
170 if (s
[strlen(s
)-1] == '\n')
171 s
[strlen(s
)-1] = '\0';
173 msg
->rm_Args
[0] = (IPTR
)CreateArgstring(s
, strlen(s
));
179 PutMsg(rexxport
, (struct Message
*)msg
);
181 reply
= (struct RexxMsg
*)WaitPort(replyport
);
182 } while (reply
!= msg
);
184 ret
= msg
->rm_Result1
;
185 if (msg
->rm_Result1
== RC_OK
)
186 FPrintf(out
, "Script executed and returned: %ld\n", msg
->rm_Result2
);
188 FPrintf(out
, "Error executing script %ld/%ld\n",
189 msg
->rm_Result1
, msg
->rm_Result2
192 ClearRexxMsg(msg
, msg
->rm_Action
& RXARGMASK
);