2 /*ARexx.c: This is the ARexx support code module*/
6 #include <exec/types.h>
7 #include <intuition/intuition.h>
8 #include <proto/intuition.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*/
51 void rAdvance(char *p
);
53 void rPicToFront(char *p
);
54 void rPicToBack(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*/
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";
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*/
90 void determinePortName(char *portName
)
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
)
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
)
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
);
121 return(1); /*1 means that minrexx shouldn't reply to the rexx message*/
124 /*quit: Abort a sequence of pictures*/
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*/
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
);
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)
167 strcpy(arexxBuf
,"NONE");
170 strcpy(arexxBuf
,"SHAM");
173 strcpy(arexxBuf
,"MACROPAINT");
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?");
194 strcpy(arexxBuf
,playListFilename
);
196 /*Returns 'TRUE' if the user specified 'loop' on the command line, 'FALSE'*/
198 else if(stricmp(p
,"looping")==0)
200 strcpy(arexxBuf
,"TRUE");
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)
208 strcpy(arexxBuf
,"TRUE");
210 strcpy(arexxBuf
,"FALSE");
212 else if(stricmp(p
,"cyclerate")==0)
213 if(numCycleColors
!=0)
214 stcu_d(arexxBuf
,rate
);
216 strcpy(arexxBuf
,"-VOID-");
218 else if(stricmp(p
,"cyclestatus")==0)
220 strcpy(arexxBuf
,"CYCLING");
222 if(numCycleColors
!=0)
223 strcpy(arexxBuf
,"CYCLINGPAUSED");
225 strcpy(arexxBuf
,"NOCYCLING");
227 /*Otherwise, we don't understand, so return an error*/
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*/
252 dumpRastPort(&(prevScreen
->RastPort
),&(prevScreen
->ViewPort
));
253 strcpy(arexxBuf
,result
);
256 /*cycle: Turn color cycling on and off*/
261 if(stricmp(p
,"on")==0)
266 else if(stricmp(p
,"off")==0)
271 else if(stricmp(p
,"toggle")==0)
274 strcpy(arexxBuf
,result
);