home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d1xx / d121 / wbcolors.lha / WBColors / WBColors.c < prev    next >
C/C++ Source or Header  |  1987-12-31  |  4KB  |  114 lines

  1.  
  2. /*************************************************************************/
  3. /* WBColors.c v1.0     Stefan Lindahl    HASTEF Software,  Sweden       */
  4. /*                                                                       */
  5. /*    Stefan Lindahl                                                     */
  6. /*    Drevkarlsgr. 8                                                     */
  7. /*    S-222 52  LUND                                                     */
  8. /*    SWEDEN                                                             */
  9. /*                                                                       */
  10. /* This program is placed in the Public Domain                           */
  11. /*************************************************************************/
  12.  
  13. #include <exec/types.h>
  14. #include <libraries/dosextens.h>
  15. #include <workbench/startup.h>
  16. #include <stdio.h>
  17. #include <graphics/view.h>
  18. #include <graphics/gfxbase.h>
  19.  
  20. #define BOLDON  "\2331m"
  21. #define BOLDOFF "\2330m"
  22.  
  23. extern struct WBStartup *WBenchMsg;         /* For WorkBench startup */
  24.  
  25. char KEYWORD1[]="colors=";     /* Lazy thing to do, but so what? */
  26. char KEYWORD2[]="COLORS="; 
  27.  
  28. extern struct DosBase *DosBase;
  29. struct GfxBase *GfxBase;
  30.  
  31. /** main() ****************************************************************/
  32. main(argc, argv)
  33. int argc;
  34. char **argv;
  35. {
  36.    int i,count;
  37.    LONG color;
  38.    BOOL   fromWB,An_Error=FALSE;
  39.    struct FileLock *lock;
  40.    struct FileInfoBlock FileIB;
  41.    char            *filename,*comment,bull[40];
  42.    UWORD cols[4];
  43.    struct ViewPort *vp;
  44.  
  45.    GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0);
  46.                            /* OpenLib always works  (I hope...) */
  47.  
  48.    fromWB = (argc==0);
  49.  
  50.    if (!fromWB)                 /* Passed filename via command line  */
  51.    {
  52.       filename = argv[0];
  53.    }
  54.    else if (WBenchMsg->sm_NumArgs > 0)
  55.    {                              /* Passed filename via  WorkBench */
  56.       filename = (char *) WBenchMsg->sm_ArgList->wa_Name;
  57.    }
  58.    else
  59.       An_Error = TRUE;       /* Something's wrong! */
  60.  
  61.    An_Error |= !(lock = (struct FileLock *) Lock(filename,ACCESS_READ) );
  62.    if (!An_Error) Examine(lock,&FileIB);        /* Get file lock */
  63.  
  64.    printf("** Set WorkBench Colors **\nA Program by %sStefan Lindahl%s.\n",
  65.                               BOLDON,BOLDOFF);
  66.    printf("%sHASTEF%s Software, Sweden.\nPlaced in the Public Domain.\n",
  67.                               BOLDON,BOLDOFF);
  68.  
  69.    while (!An_Error) /* Not used for a loop, just for a graceful exit with */
  70.    {                                                          /* continue. */
  71.       comment = FileIB.fib_Comment;
  72.  
  73.                         /* Does string start with 'COLORS=' or 'colors=' ? */
  74.       if (An_Error = !(!strncmp(comment,KEYWORD1,strlen(KEYWORD1)) ||
  75.           !strncmp(comment,KEYWORD2,strlen(KEYWORD2)) ) ) break;
  76.  
  77.       comment += strlen(KEYWORD1);
  78.  
  79.       for(i=0;i<4;i++)        /* Convert hex characters to colorvalues */
  80.       {
  81.          color=0L;
  82.  
  83.          count = stch_i(comment,&color);  /* Lattice hexascii to integer */
  84.          if (An_Error = !count) break;
  85.          if (An_Error = (color > 0xFFF)) break;
  86.          cols[i] = (UWORD)color;
  87.  
  88.          comment += count;
  89.  
  90.          if (*(comment++) != '|' && i<3) { An_Error = TRUE; break; }
  91.       }
  92.       if (An_Error) break;
  93.  
  94.       vp = GfxBase->ActiView->ViewPort;   /* Get first viewport (=top)    */
  95.                                           /* NOTE: Not neccessary the WB. */
  96.       LoadRGB4(vp,cols,4);          /* Set the colors */
  97.  
  98.       break;
  99.    }
  100.  
  101.    if (lock) UnLock(lock);
  102.    if (GfxBase) CloseLibrary(GfxBase);      /* Release */
  103.  
  104.    if (An_Error) printf("\n%sError! Check the comment field!%s\n",
  105.                               BOLDON,BOLDOFF);
  106.    else printf("\n\n");
  107.  
  108.    printf("\nPress %sRETURN%s to continue!\233\060\040\160",/*Remove Cursor*/
  109.                               BOLDON,BOLDOFF);
  110.    gets(bull);
  111.    printf("\233\040\160");   /* Cursor on again */
  112. }
  113.       /* Bye, Bye       SL     November 28, 1987 */
  114.