home *** CD-ROM | disk | FTP | other *** search
/ Power CD-ROM!! 7 / POWERCD7.ISO / prgmming / clipper / colorton.c < prev    next >
Text File  |  1993-05-10  |  3KB  |  99 lines

  1. /*
  2.  * File......: COLORTON.C
  3.  * Author....: Ian 'UnNamedDude' Day (L&W Computer Services Ltd.)
  4.  * BBS.......: The Dark Knight Returns
  5.  * Net/Node..: 050/069
  6.  * User Name.: Ian Day
  7.  * Date......: 02-25-92
  8.  * Revision..: 1.0
  9.  * Log file..: N/A
  10.  *
  11.  * This is an original work by Ian Day and is placed in the
  12.  * public domain.
  13.  *
  14.  * Modification history:
  15.  * ---------------------
  16.  *
  17.  * 04-30-93
  18.  * Initial Release
  19.  */
  20.  
  21. /*  $DOC$
  22.  *  $FUNCNAME$
  23.  *     GT_COLORTON()
  24.  *  $CATEGORY$
  25.  *     Video
  26.  *  $ONELINER$
  27.  *     Converts Clipper colour string to numeric attribute
  28.  *  $SYNTAX$
  29.  *     GT_ColorToN(<cColourString>) --> <nAttribute>
  30.  *  $ARGUMENTS$
  31.  *     <cColourString> is the Clipper colour string to convert to an
  32.  *                     numeric attribute
  33.  *  $RETURNS$
  34.  *     NIL
  35.  *  $DESCRIPTION$
  36.  *     Converts a Clipper colour string into an attribute numeric.  It only
  37.  *     looks at the first parameter of the string.  ie:
  38.  *
  39.  *     nAttribute := GT_ColorToN("W+/B,N/W")
  40.  *                             -This is used
  41.  *
  42.  *     Note: The module also includes a C/ASM callable function equivelant
  43.  *           in the form of:
  44.  *
  45.  *              void int gt_ColorToN (char *string);
  46.  *  $EXAMPLES$
  47.  *     nAttribute := GT_ColorToN("W+/B")     // Result: 31
  48.  *  $SEEALSO$
  49.  *     GT_NTOCOLOR()
  50.  *  $INCLUDE$
  51.  *
  52.  *  $END$
  53.  */
  54.  
  55. #include "extend.h"
  56. #include "string.h"
  57.  
  58. int gt_ColorToN (char *string);
  59.  
  60. /*╒═════════╤════════════════════════════════════════════════════════════════╕
  61.   │Function │GT_ColorToN(<cColorString>) --> <nColorAttribute>               │
  62.   │Purpose  │Convert clipper colour string into an attribute number          │
  63.   │Author   │Ian Day                                                         │
  64.   │Date&Time│04-30-93 05:23pm                                                │
  65.   ╘═════════╧════════════════════════════════════════════════════════════════╛*/
  66. CLIPPER gt_colorto()
  67. {
  68.    if (ISCHAR(1))
  69.       _retni (gt_ColorToN (_parc (1)));
  70.    else
  71.       _retni (0);
  72. }
  73.  
  74. int gt_ColorToN (char *string)
  75. {
  76.    int ret = 0, loop, flag = FALSE, len = strlen (string);
  77.  
  78.    for (loop = 0 ; loop < len; loop++)
  79.       {
  80.       if (string[loop] == ',')      /* End of colour string */
  81.          break;
  82.  
  83.       if (string[loop] >= 'a' && string[loop] <='z')
  84.          string[loop] -= 32;        /* Upper case please */
  85.  
  86.       switch (string[loop])
  87.          {
  88.          case '/': flag = TRUE; break;
  89.          case 'W': ret += 7 * (flag ? 16 : 1); break;  /* White */
  90.          case 'B': ret += 1 * (flag ? 16 : 1); break;  /* Blue */
  91.          case 'G': ret += 2 * (flag ? 16 : 1); break;  /* Green */
  92.          case 'R': ret += 4 * (flag ? 16 : 1); break;  /* Red */
  93.          case '+':                                     /* Intense Forground */
  94.          case '*': ret += 8 * (flag ? 16 : 1); break;  /* Intense Background|Blinking */
  95.          }
  96.       }
  97.    return (ret);
  98. }
  99.