home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / new / util / cdity / colorsaver / src / rexxif.c < prev    next >
C/C++ Source or Header  |  1994-12-05  |  5KB  |  209 lines

  1.  
  2. #include <intuition/intuition.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. #include <stdio.h>
  6. #include <clib/dos_protos.h>
  7. #include <clib/utility_protos.h>
  8. #include <clib/graphics_protos.h>
  9.  
  10. #include "simplerexx.h"            /* ARexx stuff        */
  11. #include "protos.h"            /* Routine prototypes    */
  12. #include "defs.h"
  13.  
  14. extern UWORD          RedVal;        /* RGB red value    */
  15. extern UWORD         GreenVal;        /* RGB green value    */
  16. extern UWORD         BlueVal;        /* RGB blue value    */
  17. extern UWORD          HueLevel;        /* HSV hue         */
  18. extern UWORD          SatLevel;              /* HSV saturation    */
  19. extern UWORD         ValLevel;              /* HSV value         */
  20.  
  21. extern struct Screen    *Scr;                /* screen we open up on    */
  22. extern SHORT         CurrentColor;        /* Currently selected color */
  23. extern USHORT         ColorMode;         /* Color selection mode    */
  24. extern ULONG         NumColors;        /* # of colors in palette   */
  25. extern AREXXCONTEXT     RexxStuff;
  26.  
  27. extern UBYTE             FileSpec[224];
  28. extern UBYTE             LoadDir[224];
  29. extern UBYTE             CSIsOpen;          /* window open?          */
  30.  
  31. #ifdef CS_DEBUG
  32. extern FILE             *conwin;
  33. #endif
  34.  
  35. BOOL HandleARexxEvent( void )
  36. {
  37.     struct    RexxMsg        *rmsg;
  38.     char    buffer[133];
  39.     char    *nextarg;
  40.     char    *error=NULL;
  41.     char    *result=NULL;
  42.     long    errlevel=0;
  43.     UBYTE   running=TRUE;
  44.  
  45.         if (!CSIsOpen) GetScrInfo();
  46.  
  47.     while (rmsg=GetARexxMsg(RexxStuff))
  48.          {
  49.  
  50.        nextarg=strtok(ARG0(rmsg)," ,");
  51.  
  52.         if (!Stricmp("SHOW",ARG0(rmsg)))
  53.                   OpenTheWindow();
  54.  
  55.         else if (!Stricmp("HIDE",ARG0(rmsg)))
  56.           CloseTheWindow();
  57.  
  58.         else if (!Stricmp("CANCEL",ARG0(rmsg)))
  59.           ResetPalette(RETRIEVE_IT);
  60.  
  61.         else if (!Stricmp("STOREPALETTE",ARG0(rmsg)))
  62.           ResetPalette(STORE_IT);
  63.  
  64.         else if (!Stricmp("SHIFTR",ARG0(rmsg)))
  65.           ShiftColorsRight();
  66.  
  67.         else if (!Stricmp("SHIFTL",ARG0(rmsg)))
  68.           ShiftColorsLeft();
  69.  
  70.         else if (!Stricmp("HSVMODE",ARG0(rmsg)))
  71.           {
  72.             ColorMode = HSV_COLORMODE;
  73.                 SetColorMode(ColorMode);
  74.                 SetProps(CurrentColor);
  75.                   }
  76.  
  77.         else if (!Stricmp("RGBMODE",ARG0(rmsg)))
  78.           {
  79.             ColorMode = RGB_COLORMODE;
  80.                 SetColorMode(ColorMode);
  81.                 SetProps(CurrentColor);
  82.                   }
  83.  
  84.             else if (!Stricmp("LOAD",ARG0(rmsg)))
  85.           if (nextarg=strtok(NULL," ,"))
  86.             {
  87.                        strcpy(FileSpec,LoadDir);
  88.                    (void)AddPart(FileSpec,nextarg,(ULONG)sizeof(FileSpec));
  89.                    LoadColors(FileSpec, NumColors );
  90.             }
  91.           else
  92.             {
  93.                        strcpy(buffer,"No Filename given!");
  94.                        result = buffer;
  95.                        errlevel = 10;
  96.                     }
  97.  
  98.             else if (!Stricmp("SAVE",ARG0(rmsg)))
  99.           if (nextarg=strtok(NULL," ,"))
  100.             {
  101.                        strcpy(FileSpec,LoadDir);
  102.                    (void)AddPart(FileSpec,nextarg,(ULONG)sizeof(FileSpec));
  103.                    SaveColors(FileSpec, NumColors );
  104.             }
  105.           else
  106.             {
  107.                        strcpy(buffer,"No Filename given!");
  108.                        result = buffer;
  109.                        errlevel = 10;
  110.                     }
  111.  
  112.             else if(!Stricmp("SELECT",ARG0(rmsg)))
  113.           if (nextarg=strtok(NULL," ,"))
  114.             {
  115.                       CurrentColor = atoi(nextarg);                        
  116.                   SetPaletteColor(CurrentColor);
  117.                   SetProps(CurrentColor);
  118.             }
  119.           else
  120.             {
  121.                        result = "No Value given!";
  122.                        errlevel = 10;
  123.                     }
  124.  
  125.             else if(!Stricmp("GETRGB",ARG0(rmsg)))
  126.              {   
  127.                    GetColors(CurrentColor);
  128.            sprintf(buffer,"%d %d %d",RedVal, GreenVal, BlueVal);
  129.            result = buffer;
  130.          }
  131.  
  132.             else if(!Stricmp("NUMCOLORS",ARG0(rmsg)))
  133.              {   
  134.            sprintf(buffer,"%d",NumColors);
  135.            result = buffer;
  136.          }
  137.  
  138.             else if(!Stricmp("SETRGB",ARG0(rmsg)))
  139.              {   
  140.           while(nextarg=strtok(NULL," ,"))
  141.             {
  142.                        parsecolors(nextarg);
  143.                     } 
  144.                   SetRGB4(&Scr->ViewPort,CurrentColor,RedVal,GreenVal,BlueVal);
  145.               SetPaletteColor(CurrentColor);
  146.               SetProps(CurrentColor);
  147.          }
  148.  
  149.         else if (!Stricmp("QUIT",ARG0(rmsg)))
  150.                running=FALSE;
  151.  
  152.         ReplyARexxMsg(RexxStuff,rmsg,result,errlevel);
  153.           }
  154.  
  155. return(running);
  156. }
  157.  
  158.  
  159. void parsecolors(char *buffer)
  160. {
  161.  char ch;
  162.  char *arg;
  163.  
  164.  buffer = collapse(buffer);
  165.  
  166.    if(arg = strpbrk(buffer,"="))
  167.     {  
  168.      arg++;
  169.      ch = ToUpper(*buffer);
  170.  
  171.      if(ch == 'R')RedVal = RGBValid(arg,RedVal);
  172.      if(ch == 'G')GreenVal = RGBValid(arg,GreenVal);
  173.      if(ch == 'B')BlueVal = RGBValid(arg,BlueVal);
  174.      if(ch == 'H')HueLevel = HSVValid(arg,HueLevel);
  175.      if(ch == 'S')SatLevel = HSVValid(arg,SatLevel);
  176.      if(ch == 'V')ValLevel = HSVValid(arg,ValLevel);
  177.      if(ch == 'C')CurrentColor =COLORValid(atoi(arg),NumColors,CurrentColor); 
  178.          
  179.     }   
  180.  
  181. #ifdef CS_DEBUG
  182.  fprintf(conwin,"RedVal = %d\n",RedVal);
  183.  fprintf(conwin,"BlueVal = %d\n",BlueVal);
  184.  fprintf(conwin,"GreenVal = %d\n",GreenVal);
  185.  fflush(conwin);
  186. #endif
  187.  
  188. }
  189.  
  190.  
  191. #include <ctype.h>
  192.  
  193. char *collapse(string)
  194. char *string;
  195. {
  196.  register char *loop;
  197.  
  198.  /* skip over (ignore) leading whitespace */
  199.  while(isspace(*string))
  200.      string++;
  201.  
  202.  for (loop = string; *loop != '\0'; loop++)
  203.    while(isspace(*loop))   
  204.        strcpy(loop,loop+1);
  205.  
  206.  return(string);
  207.  
  208. }
  209.