home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD1.bin
/
new
/
util
/
cdity
/
colorsaver
/
src
/
rexxif.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-12-05
|
5KB
|
209 lines
#include <intuition/intuition.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <clib/dos_protos.h>
#include <clib/utility_protos.h>
#include <clib/graphics_protos.h>
#include "simplerexx.h" /* ARexx stuff */
#include "protos.h" /* Routine prototypes */
#include "defs.h"
extern UWORD RedVal; /* RGB red value */
extern UWORD GreenVal; /* RGB green value */
extern UWORD BlueVal; /* RGB blue value */
extern UWORD HueLevel; /* HSV hue */
extern UWORD SatLevel; /* HSV saturation */
extern UWORD ValLevel; /* HSV value */
extern struct Screen *Scr; /* screen we open up on */
extern SHORT CurrentColor; /* Currently selected color */
extern USHORT ColorMode; /* Color selection mode */
extern ULONG NumColors; /* # of colors in palette */
extern AREXXCONTEXT RexxStuff;
extern UBYTE FileSpec[224];
extern UBYTE LoadDir[224];
extern UBYTE CSIsOpen; /* window open? */
#ifdef CS_DEBUG
extern FILE *conwin;
#endif
BOOL HandleARexxEvent( void )
{
struct RexxMsg *rmsg;
char buffer[133];
char *nextarg;
char *error=NULL;
char *result=NULL;
long errlevel=0;
UBYTE running=TRUE;
if (!CSIsOpen) GetScrInfo();
while (rmsg=GetARexxMsg(RexxStuff))
{
nextarg=strtok(ARG0(rmsg)," ,");
if (!Stricmp("SHOW",ARG0(rmsg)))
OpenTheWindow();
else if (!Stricmp("HIDE",ARG0(rmsg)))
CloseTheWindow();
else if (!Stricmp("CANCEL",ARG0(rmsg)))
ResetPalette(RETRIEVE_IT);
else if (!Stricmp("STOREPALETTE",ARG0(rmsg)))
ResetPalette(STORE_IT);
else if (!Stricmp("SHIFTR",ARG0(rmsg)))
ShiftColorsRight();
else if (!Stricmp("SHIFTL",ARG0(rmsg)))
ShiftColorsLeft();
else if (!Stricmp("HSVMODE",ARG0(rmsg)))
{
ColorMode = HSV_COLORMODE;
SetColorMode(ColorMode);
SetProps(CurrentColor);
}
else if (!Stricmp("RGBMODE",ARG0(rmsg)))
{
ColorMode = RGB_COLORMODE;
SetColorMode(ColorMode);
SetProps(CurrentColor);
}
else if (!Stricmp("LOAD",ARG0(rmsg)))
if (nextarg=strtok(NULL," ,"))
{
strcpy(FileSpec,LoadDir);
(void)AddPart(FileSpec,nextarg,(ULONG)sizeof(FileSpec));
LoadColors(FileSpec, NumColors );
}
else
{
strcpy(buffer,"No Filename given!");
result = buffer;
errlevel = 10;
}
else if (!Stricmp("SAVE",ARG0(rmsg)))
if (nextarg=strtok(NULL," ,"))
{
strcpy(FileSpec,LoadDir);
(void)AddPart(FileSpec,nextarg,(ULONG)sizeof(FileSpec));
SaveColors(FileSpec, NumColors );
}
else
{
strcpy(buffer,"No Filename given!");
result = buffer;
errlevel = 10;
}
else if(!Stricmp("SELECT",ARG0(rmsg)))
if (nextarg=strtok(NULL," ,"))
{
CurrentColor = atoi(nextarg);
SetPaletteColor(CurrentColor);
SetProps(CurrentColor);
}
else
{
result = "No Value given!";
errlevel = 10;
}
else if(!Stricmp("GETRGB",ARG0(rmsg)))
{
GetColors(CurrentColor);
sprintf(buffer,"%d %d %d",RedVal, GreenVal, BlueVal);
result = buffer;
}
else if(!Stricmp("NUMCOLORS",ARG0(rmsg)))
{
sprintf(buffer,"%d",NumColors);
result = buffer;
}
else if(!Stricmp("SETRGB",ARG0(rmsg)))
{
while(nextarg=strtok(NULL," ,"))
{
parsecolors(nextarg);
}
SetRGB4(&Scr->ViewPort,CurrentColor,RedVal,GreenVal,BlueVal);
SetPaletteColor(CurrentColor);
SetProps(CurrentColor);
}
else if (!Stricmp("QUIT",ARG0(rmsg)))
running=FALSE;
ReplyARexxMsg(RexxStuff,rmsg,result,errlevel);
}
return(running);
}
void parsecolors(char *buffer)
{
char ch;
char *arg;
buffer = collapse(buffer);
if(arg = strpbrk(buffer,"="))
{
arg++;
ch = ToUpper(*buffer);
if(ch == 'R')RedVal = RGBValid(arg,RedVal);
if(ch == 'G')GreenVal = RGBValid(arg,GreenVal);
if(ch == 'B')BlueVal = RGBValid(arg,BlueVal);
if(ch == 'H')HueLevel = HSVValid(arg,HueLevel);
if(ch == 'S')SatLevel = HSVValid(arg,SatLevel);
if(ch == 'V')ValLevel = HSVValid(arg,ValLevel);
if(ch == 'C')CurrentColor =COLORValid(atoi(arg),NumColors,CurrentColor);
}
#ifdef CS_DEBUG
fprintf(conwin,"RedVal = %d\n",RedVal);
fprintf(conwin,"BlueVal = %d\n",BlueVal);
fprintf(conwin,"GreenVal = %d\n",GreenVal);
fflush(conwin);
#endif
}
#include <ctype.h>
char *collapse(string)
char *string;
{
register char *loop;
/* skip over (ignore) leading whitespace */
while(isspace(*string))
string++;
for (loop = string; *loop != '\0'; loop++)
while(isspace(*loop))
strcpy(loop,loop+1);
return(string);
}