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

  1. /*
  2.  * File......: NTOCOLOR.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_NTOCOLOR()
  24.  *  $CATEGORY$
  25.  *     Video
  26.  *  $ONELINER$
  27.  *     Converts numeric attribute to Clipper colour string
  28.  *  $SYNTAX$
  29.  *     GT_NToColor(<nAttribute>) --> <cColourString>
  30.  *  $ARGUMENTS$
  31.  *     <nAttribute> The integer attribute to convert to a Clipper colour
  32.  *     string
  33.  *  $RETURNS$
  34.  *     The Clipper Colour string
  35.  *  $DESCRIPTION$
  36.  *     Converts an attribute numeric into a Clipper colour string
  37.  *
  38.  *     Note: The module also includes a C/ASM callable function equivelant
  39.  *           in the form of:
  40.  *
  41.  *              char * gt_NToColor (int color);
  42.  *  $EXAMPLES$
  43.  *     ? GT_NToColor(31)         // Result: "W+/B"
  44.  *  $SEEALSO$
  45.  *     GT_COLORTON()
  46.  *  $INCLUDE$
  47.  *
  48.  *  $END$
  49.  */
  50.  
  51. #include "extend.h"
  52.  
  53. char * gt_NToColor (int color);
  54.  
  55. /*╒═════════╤════════════════════════════════════════════════════════════════╕
  56.   │Function │GT_NToColor(<nAttribute>) --> <cColorString>                    │
  57.   │Purpose  │Convert clipper colour string into an attribute number          │
  58.   │Author   │Ian Day                                                         │
  59.   │Date&Time│04-30-93 05:23pm                                                │
  60.   ╘═════════╧════════════════════════════════════════════════════════════════╛*/
  61. CLIPPER gt_ntocolo()
  62. {
  63.    char *string;
  64.  
  65.    if (ISNUM(1))
  66.       {
  67.       string = gt_NToColor (_parni (1));
  68.       _retc (string);
  69.       }
  70.    else
  71.       _retc ("");
  72. }
  73.  
  74. /******************************** C Stuff ***********************************/
  75.  
  76. char * gt_NToColor (int color)
  77. {
  78.    char *string = "       ";
  79.    int pos = 6;
  80.    int temp, loop;
  81.  
  82.    for (loop = 1 ; loop < 3 ; loop++)
  83.       {
  84.       if (loop == 1)
  85.          temp = color / 16;
  86.       else
  87.          {
  88.          string[pos--] = '/';
  89.          temp = color % 16;
  90.          }
  91.  
  92.       if (temp - 8 >= 0)
  93.          {
  94.          string[pos--] = (char)(loop == 1 ? '*' : '+');
  95.          temp -= 8;
  96.          }
  97.  
  98.       if (!temp)
  99.          string[pos--] = 'N';
  100.  
  101.       if (temp - 7 >= 0)
  102.          {
  103.          string[pos--] = 'W';
  104.          temp -= 7;
  105.          }
  106.  
  107.       if (temp - 4 >= 0)
  108.          {
  109.          string[pos--] = 'R';
  110.          temp -= 4;
  111.          }
  112.  
  113.       if (temp - 2 >= 0)
  114.          {
  115.          string[pos--] = 'G';
  116.          temp -= 2;
  117.          }
  118.  
  119.       if (temp - 1 >= 0)
  120.          string[pos--] = 'B';
  121.       }
  122.  
  123.    return (string + pos + 1);
  124. }
  125.  
  126.