simplerexx updated:
[AROS.git] / test / rexx / simplerexx / SimpleRexxExample.c
blob2c332e687dd2f6846a7c3d3c9e3bc8f4a5d46d4c
1 /*
2 * This is an example of how to use the SimpleRexx code.
3 */
5 #include <exec/types.h>
6 #include <libraries/dos.h>
7 #include <libraries/dosextens.h>
8 #include <intuition/intuition.h>
9 #include <intuition/iobsolete.h>
11 #include <proto/exec.h>
12 #include <proto/intuition.h>
14 #include <rexx/storage.h>
15 #include <rexx/rxslib.h>
17 #include <stdio.h>
18 #include <string.h>
20 #include "SimpleRexx.h"
21 #include "stptok.h"
24 * Lattice control-c stop...
26 int CXBRK(void) { return(0); } /* Disable Lattice CTRL/C handling */
27 int chkabort(void) { return(0); } /* really */
30 * The strings in this program
32 char *strings[]=
34 "50: Window already open", /* STR_ID_WINDOW_OPEN */
35 "101: Window did not open", /* STR_ID_WINDOW_ERROR */
36 "50: No Window", /* STR_ID_WINDOW_NONE */
37 "80: Argument error to WINDOW command", /* STR_ID_WINDOW_ARG */
38 "100: Unknown command", /* STR_ID_COMMAND_ERROR */
39 "ARexx port name: %s\n", /* STR_ID_PORT_NAME */
40 "No ARexx on this system.\n", /* STR_ID_NO_AREXX */
41 "SimpleRexxExample Window" /* STR_ID_WINDOW_TITLE */
44 #define STR_ID_WINDOW_OPEN 0
45 #define STR_ID_WINDOW_ERROR 1
46 #define STR_ID_WINDOW_NONE 2
47 #define STR_ID_WINDOW_ARG 3
48 #define STR_ID_COMMAND_ERROR 4
49 #define STR_ID_PORT_NAME 5
50 #define STR_ID_NO_AREXX 6
51 #define STR_ID_WINDOW_TITLE 7
54 * NewWindow structure...
56 static struct NewWindow nw=
58 97,47,299,44,-1,-1,
59 CLOSEWINDOW,
60 WINDOWSIZING|WINDOWDRAG|WINDOWDEPTH|WINDOWCLOSE|SIMPLE_REFRESH|NOCAREREFRESH,
61 NULL,NULL,
62 NULL,
63 NULL,NULL,290,40,-1,-1,WBENCHSCREEN
67 * A *VERY* simple and simple-minded example of using the SimpleRexx.c code.
69 * This program, when run, will print out the name of the ARexx port it
70 * opens. Use that port to tell it to SHOW the window. You can also
71 * use the ARexx port to HIDE the window, to READTITLE the window's
72 * titlebar, and QUIT the program. You can also quit the program by
73 * pressing the close gadget in the window while the window is up.
75 * Note: You will want to RUN this program or have another shell available such
76 * that you can still have access to ARexx...
78 int main(int argc,char *argv[])
80 short loopflag=TRUE;
81 AREXXCONTEXT RexxStuff;
82 struct Window *win=NULL;
83 ULONG signals;
85 if (IntuitionBase=(struct IntuitionBase *)
86 OpenLibrary("intuition.library",0))
89 * Note that SimpleRexx is set up such that you do not
90 * need to check for an error to initialize your REXX port
91 * This is so your application could run without REXX...
93 RexxStuff=InitARexx("Example","test");
95 if (argc)
97 if (RexxStuff) printf(strings[STR_ID_PORT_NAME],
98 ARexxName(RexxStuff));
99 else printf(strings[STR_ID_NO_AREXX]);
102 while (loopflag)
104 signals=ARexxSignal(RexxStuff);
105 if (win) signals|=(1L << (win->UserPort->mp_SigBit));
107 if (signals)
109 struct RexxMsg *rmsg;
110 struct IntuiMessage *msg;
112 signals=Wait(signals);
115 * Process the ARexx messages...
117 while (rmsg=GetARexxMsg(RexxStuff))
119 char cBuf[24];
120 char *nextchar;
121 char *error=NULL;
122 char *result=NULL;
123 long errlevel=0;
125 nextchar=stptok(ARG0(rmsg),
126 cBuf,24," ,");
127 if (nextchar && *nextchar) nextchar++;
129 if (!stricmp("WINDOW",cBuf))
131 if (!stricmp("OPEN",nextchar))
133 if (win)
135 error=strings[STR_ID_WINDOW_OPEN];
136 errlevel=5;
138 else
140 nw.Title=strings[STR_ID_WINDOW_TITLE];
141 if (!(win=OpenWindow(&nw)))
143 error=strings[STR_ID_WINDOW_ERROR];
144 errlevel=30;
148 else if (!stricmp("CLOSE",nextchar))
150 if (win)
152 CloseWindow(win);
153 win=NULL;
155 else
157 error=strings[STR_ID_WINDOW_NONE];
158 errlevel=5;
161 else
163 error=strings[STR_ID_WINDOW_ARG];
164 errlevel=20;
167 else if (!stricmp("READTITLE",cBuf))
169 if (win)
171 result=win->Title;
173 else
175 error=strings[STR_ID_WINDOW_NONE];
176 errlevel=5;
179 else if (!stricmp("QUIT",cBuf))
181 loopflag=FALSE;
183 else
185 error=strings[STR_ID_COMMAND_ERROR];
186 errlevel=20;
189 if (error)
191 SetARexxLastError(RexxStuff,rmsg,error);
193 ReplyARexxMsg(RexxStuff,rmsg,result,errlevel);
197 * If we have a window, process those messages
199 if (win) while (msg=(struct IntuiMessage *)
200 GetMsg(win->UserPort))
202 if (msg->Class==CLOSEWINDOW)
205 * Quit if the close gadget...
207 loopflag=FALSE;
209 ReplyMsg((struct Message *)msg);
212 else loopflag=FALSE;
214 if (win) CloseWindow(win);
216 FreeARexx(RexxStuff);
217 CloseLibrary((struct Library *)IntuitionBase);
219 return 0;