grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / demos / 2View / ARexx.c
blob9a42a76cecf5e92289b486ce6b8f0b5f35e03229
2 /*ARexx.c: This is the ARexx support code module*/
3 #include <string.h>
4 #include <stdio.h>
6 #include <exec/types.h>
7 #include <intuition/intuition.h>
8 #include <proto/intuition.h>
9 #include "minrexx.h"
10 #include "arexx.h"
12 #include <proto/exec.h>
14 #define stcu_d(buf,val) sprintf(buf,"%d",(int)val)
15 #define stci_h(buf,val) sprintf(buf,"%x",(int)val)
16 #define stricmp strcasecmp
19 enum ButtonTypes {none=0,select,menu};
20 typedef enum ButtonTypes ButtonTypes;
22 /* extern struct Library *SysBase;
23 extern struct Library *IntuitionBase; */
24 extern BYTE specialModes;
26 struct RexxMsg *rexxMsg;
28 /*These variables are defined in 2View.c, and are used to enable the ARexx*/
29 /*routines to communicate with the rest of the program*/
31 /*This variable is used to tell 2View to quit or advance*/
32 extern ButtonTypes rexxAbort;
34 extern struct Screen *prevScreen; /*The current screen*/
36 extern char *picFilename; /*The filename of the current picture*/
37 extern char *playListFilename; /*The name of the playlist*/
39 extern UWORD ticks; /*The number of ticks remaining to show each picture*/
40 extern UWORD ticksRemaining; /*The time left to show the current picture*/
42 extern BOOL loop; /*TRUE if the user specified 'loop'*/
43 extern BOOL printPics; /*TRUE if we're printing each picture*/
45 extern BOOL cycle; /*TRUE if colors are cycling*/
46 extern UBYTE rate,numCycleColors;
48 extern char *version; /*2View's version string*/
50 void rQuit(char *p);
51 void rAdvance(char *p);
52 void rGet(char *p);
53 void rPicToFront(char *p);
54 void rPicToBack(char *p);
55 void rPrint(char *p);
56 void rCycle(char *p);
58 struct rexxCommandList commandList[] =
60 { "quit" , (APTR)&rQuit }, /*Abort a picture sequence*/
61 { "advance", (APTR)&rAdvance }, /*Show the next picture in the sequence*/
62 { "get", (APTR)&rGet }, /*Multi-purpose*/
63 { "pictofront", (APTR)&rPicToFront }, /*Bring the picture to the front*/
64 { "pictoback", (APTR)&rPicToBack }, /*Send the picture to the back*/
65 { "print", (APTR)&rPrint }, /*Print the picture*/
66 { "cycle", (APTR)&rCycle }, /*Turn color cycling on/off*/
67 { NULL, NULL }
70 char portName[16];
71 char arexxBuf[140];
74 /*Open the ARexx port*/
75 long initRexxPort(void)
77 determinePortName(portName); /*Get the port name*/
79 /*Ask minrexx to open the port and return the port's signal bit*/
80 return(upRexxPort(portName,commandList,"rx",(APTR)&disp));
83 char *result="RESULT";
84 UBYTE errorNum=0;
86 /*Determine what the ARexx port name should be. The first running instance*/
87 /*of 2View should have an ARexx port named '2View.1'. The second, '2View.2'*/
88 /*etc. This starts at '2View.1' and works up until it finds a free space*/
89 /*(up to 2View.99)*/
90 void determinePortName(char *portName)
92 ULONG c=1;
93 UBYTE len;
95 strcpy(portName,"2View.");
99 len=stcu_d(&portName[6],c++);
100 portName[6+len]='\0';
102 while(FindPort(portName)!=NULL && c<100);
103 if(FindPort(portName)!=NULL)
104 exit(50);
105 return;
108 /*The ARexx command dispatch function. This calls the functions associated*/
109 /*with a particular command*/
110 int disp(struct RexxMsg *msg,struct rexxCommandList *dat,char *p)
112 rexxMsg=msg;
114 /*Call the function that supports the command*/
115 ((int (*)())(dat->userdata))(p);
117 /*Reply to ARexx, using the reply string and error number set by the*/
118 /*function just called*/
119 replyRexxCmd(rexxMsg,errorNum,0,arexxBuf);
120 errorNum=0;
121 return(1); /*1 means that minrexx shouldn't reply to the rexx message*/
124 /*quit: Abort a sequence of pictures*/
125 void rQuit(char *p)
127 rexxAbort=menu; /*It's like the user pressed the right mouse button*/
128 strcpy(arexxBuf,result);
131 /*advance: Advance to the next picture in this sequence*/
132 void rAdvance(char *p)
134 rexxAbort=select; /*Like pressing the left mouse button*/
135 strcpy(arexxBuf,result);
138 /*get: This function gets information about the current picture/playlist*/
139 void rGet(char *p)
141 p++;
143 /*The picture's filename*/
144 if(stricmp(p,"name")==0)
145 strcpy(arexxBuf,picFilename);
147 /*The picture width*/
148 else if(stricmp(p,"width")==0)
149 stcu_d(arexxBuf,prevScreen->Width);
151 /*The height*/
152 else if(stricmp(p,"height")==0)
153 stcu_d(arexxBuf,prevScreen->Height);
155 /*The number of bitplanes*/
156 else if(stricmp(p,"depth")==0)
157 stcu_d(arexxBuf,prevScreen->BitMap.Depth);
159 /*The viewmodes of the picture (HAM, HIRES, LACE, etc.*/
160 else if(stricmp(p,"viewmodes")==0)
161 stci_h(arexxBuf,prevScreen->ViewPort.Modes);
163 else if(stricmp(p,"specialmodes")==0)
164 switch(specialModes)
166 case NORMAL:
167 strcpy(arexxBuf,"NONE");
168 break;
169 case SHAM:
170 strcpy(arexxBuf,"SHAM");
171 break;
172 case MACROPAINT:
173 strcpy(arexxBuf,"MACROPAINT");
174 break;
177 /*The time left to display this picture*/
178 else if(stricmp(p,"timeleft")==0)
179 stcu_d(arexxBuf,ticksRemaining);
181 /*The time to display each picture*/
182 else if(stricmp(p,"timeperpicture")==0)
183 stcu_d(arexxBuf,ticks);
185 /*The version number and date of this program*/
186 else if(stricmp(p,"version")==0)
187 strcpy(arexxBuf,&version[12]);
189 /*The name of the playlist, or '?NONE?' if there is no playlist*/
190 else if(stricmp(p,"playlistname")==0)
191 if(playListFilename==NULL)
192 strcpy(arexxBuf,"?NONE?");
193 else
194 strcpy(arexxBuf,playListFilename);
196 /*Returns 'TRUE' if the user specified 'loop' on the command line, 'FALSE'*/
197 /*if he didn't*/
198 else if(stricmp(p,"looping")==0)
199 if(loop)
200 strcpy(arexxBuf,"TRUE");
201 else
202 strcpy(arexxBuf,"FALSE");
204 /*Returns 'TRUE' if the user specified 'print' on the command line,*/
205 /*FALSE if she didn't*/
206 else if(stricmp(p,"printpictures")==0)
207 if(printPics)
208 strcpy(arexxBuf,"TRUE");
209 else
210 strcpy(arexxBuf,"FALSE");
212 else if(stricmp(p,"cyclerate")==0)
213 if(numCycleColors!=0)
214 stcu_d(arexxBuf,rate);
215 else
216 strcpy(arexxBuf,"-VOID-");
218 else if(stricmp(p,"cyclestatus")==0)
219 if(cycle)
220 strcpy(arexxBuf,"CYCLING");
221 else
222 if(numCycleColors!=0)
223 strcpy(arexxBuf,"CYCLINGPAUSED");
224 else
225 strcpy(arexxBuf,"NOCYCLING");
227 /*Otherwise, we don't understand, so return an error*/
228 else
230 errorNum=100;
231 strcpy(arexxBuf,"ERROR");
235 /*pictofront: Send the picture's screen to the front*/
236 void rPicToFront(char *p)
238 ScreenToFront(prevScreen);
239 strcpy(arexxBuf,result);
242 /*pictoback: Send the picture's screen to the back*/
243 void rPicToBack(char *p)
245 ScreenToBack(prevScreen);
246 strcpy(arexxBuf,result);
249 /*print: Print the currently displayed picture*/
250 void rPrint(char *p)
252 dumpRastPort(&(prevScreen->RastPort),&(prevScreen->ViewPort));
253 strcpy(arexxBuf,result);
256 /*cycle: Turn color cycling on and off*/
257 void rCycle(char *p)
259 p++;
261 if(stricmp(p,"on")==0)
263 if(!cycle)
264 toggleCycling();
266 else if(stricmp(p,"off")==0)
268 if(cycle)
269 toggleCycling();
271 else if(stricmp(p,"toggle")==0)
272 toggleCycling();
274 strcpy(arexxBuf,result);
275 return;
278 /*End of ARexx.c*/