2 Copyright © 2007, The AROS Development Team. All rights reserved.
9 #include <dos/dosextens.h>
10 #include <rexx/storage.h>
11 #include <rexx/errors.h>
12 #include <workbench/startup.h>
14 #include <proto/exec.h>
15 #include <proto/dos.h>
16 #include <proto/rexxsyslib.h>
17 #include <proto/alib.h>
23 static struct RexxMsg
*msg
= NULL
;
24 static struct MsgPort
*rexxport
= NULL
, *replyport
= NULL
;
26 static BOOL closestdout
= FALSE
;
27 static BPTR olddir
= (BPTR
)-1;
29 static BOOL
init(void)
37 rexxport
= FindPort("REXX");
40 if (SystemTags("RexxMast", SYS_Asynch
, TRUE
, TAG_DONE
) >= 0)
42 SystemTags("WaitForPort REXX", TAG_DONE
);
45 rexxport
= FindPort("REXX");
48 FPuts(out
, "Could not start RexxMast\n");
52 replyport
= CreatePort(NULL
, 0);
53 if (replyport
== NULL
)
55 FPuts(out
, "Could not create a port\n");
59 msg
= CreateRexxMsg(replyport
, NULL
, NULL
);
62 FPuts(out
, "Could not create RexxMsg\n");
65 msg
->rm_Action
= RXCOMM
| RXFF_RESULT
;
66 msg
->rm_Stdin
= Input();
67 msg
->rm_Stdout
= Output();
75 Close(msg
->rm_Stdout
);
79 DeletePort(replyport
);
80 if (olddir
!= (BPTR
)-1)
84 int main(int argc
, char **argv
)
86 struct RexxMsg
*reply
;
97 FPuts(out
, "Required argument missing\n");
104 struct WBStartup
*startup
= (struct WBStartup
*) argv
;
105 char *s
= startup
->sm_ArgList
[1].wa_Name
;
107 if (startup
->sm_NumArgs
< 2)
113 olddir
= CurrentDir(startup
->sm_ArgList
[1].wa_Lock
);
114 out
= msg
->rm_Stdout
= Open("CON:////RX Output/CLOSE/WAIT/AUTO", MODE_READWRITE
);
117 msg
->rm_Args
[0] = (IPTR
)CreateArgstring(s
, strlen(s
));
123 struct Process
*me
= (struct Process
*)FindTask(NULL
);
126 s
= me
->pr_Arguments
;
127 while(isspace(*s
)) s
++;
132 while((s
[length
] != '"') && (s
[length
] != '\0')) length
++;
135 FPuts(out
, "Empty command\n");
139 if (s
[length
] == '\0')
141 FPuts(out
, "Unterminated string\n");
146 msg
->rm_Args
[0] = (IPTR
)CreateArgstring(s
, length
);
147 /* It is a literal command with 1 argument */
148 msg
->rm_Action
|= (RXFF_STRING
| 1);
153 while((s
[length
] != '\'')
154 && (s
[length
] != '\0')
155 && (s
[length
] != '\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);
165 if (s
[strlen(s
)-1] == '\n')
166 s
[strlen(s
)-1] = '\0';
168 msg
->rm_Args
[0] = (IPTR
)CreateArgstring(s
, strlen(s
));
174 PutMsg(rexxport
, (struct Message
*)msg
);
176 reply
= (struct RexxMsg
*)WaitPort(replyport
);
177 } while (reply
!= msg
);
179 ret
= msg
->rm_Result1
;
180 if (msg
->rm_Result1
== RC_OK
)
181 FPrintf(out
, "Script executed and returned: %ld\n", msg
->rm_Result2
);
183 FPrintf(out
, "Error executing script %ld/%ld\n",
184 msg
->rm_Result1
, msg
->rm_Result2
187 ClearRexxMsg(msg
, msg
->rm_Action
& RXARGMASK
);