home *** CD-ROM | disk | FTP | other *** search
/ synchro.net / synchro.net.tar / synchro.net / modem.madness / SMMNETML / AMAX_230.ZIP / SOURCES.ZIP / AMAXANSI.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-15  |  6.2 KB  |  231 lines

  1. /*---------------------------------------------------------------------------*/
  2. /*                                                                           */
  3. /* Module Name:   AMAXANSI.C                                                 */
  4. /* Program Name:  AMAX                                                       */
  5. /* Revision:      2.xx                                                       */
  6. /* Purpose:       Screen Writing Routines Module                             */
  7. /* Programmer:    Alan D. Bryant                                             */
  8. /*                                                                           */
  9. /* Copyright (C) 1988, 89, 90, 92 Alan D. Bryant, All Rights Reserved.       */
  10. /*                                                                           */
  11. /* NOTICE:  This source code is copyrighted material.  You are granted a     */
  12. /* limited license to use and distribute the code.  The complete text of     */
  13. /* the license can be found in the document LICENSE.DOC which accompanies    */
  14. /* this source code, or can be obtained directly from the author.            */
  15. /*                                                                           */
  16. /* Inquiries regarding this package should be directed to:                   */
  17. /*                                                                           */
  18. /*     AMAX                                                                  */
  19. /*     Alan D. Bryant                                                        */
  20. /*     P. O. Box 101612                                                      */
  21. /*     Denver, CO  80250                                                     */
  22. /*     USA                                                                   */
  23. /*                                                                           */
  24. /*---------------------------------------------------------------------------*/
  25.  
  26. #include <stdio.h>
  27. #include "amax.h"
  28.  
  29. void output(char *);
  30. void outputi(char *);
  31. void cursor(int, int);
  32. void scolor(int);
  33. void vreverse();
  34. void vnormal();
  35. void vpanel(int);
  36. char *ansicode(int);
  37. void aputch(char);
  38.  
  39. extern char usecolor;
  40.  
  41. void output(char *line)
  42. {
  43.     int x;
  44.  
  45.     for (x = 0; x < strlen(line); x++) {
  46.         if (line[x] == '$') {
  47.             ++x;
  48.             switch (line[x]) {
  49.                 case '1':
  50.                     scolor(14);
  51.                     break;
  52.                 case '2':
  53.                     scolor(15);
  54.                     break;
  55.                 case '3':
  56.                     scolor(10);
  57.                     break;
  58.                 case '4':
  59.                     scolor(11);
  60.                     break;
  61.                 case '5':
  62.                     scolor(13);
  63.                     break;
  64.                 case '6':
  65.                     vreverse();
  66.                     break;
  67.                 case '7':
  68.                     scolor(3);
  69.                     break;
  70.                 case '8':
  71.                     scolor(4);
  72.                     break;
  73.                 case '9':
  74.                     scolor(2);
  75.                     break;
  76.                 case '$':
  77.                     if (direct) cprintf("%s", "$$");
  78.                     else printf("%s", "$$");
  79.                     break;
  80.                 default:
  81.                     scolor(7);
  82.                     break;
  83.             }
  84.         }
  85.         else {
  86.             if (direct) cprintf("%c", line[x]);
  87.             else printf("%c", line[x]);
  88.         }
  89.     }
  90.  
  91.  
  92. /*
  93.     if (! direct) printf(line);
  94.     else cprintf(line);   */
  95. }
  96.  
  97. void outputi(char *line)
  98. {
  99.     if (! kbhit()) output(line);
  100. }
  101.  
  102. void cursor(int x, int y)
  103. {
  104.     if (! direct) printf("%d;%dH", x+1, y+1);
  105.     else gotoxy(y+1, x+1);
  106. }
  107.  
  108. void scolor(int val)
  109. {
  110.     extern char direct;
  111.     char option[10] = "";
  112.  
  113.     /*
  114.  
  115.     AMAX COLOR TABLE
  116.  
  117.     00 - Black (Color Off)
  118.     01 - Blue
  119.     02 - Green
  120.     03 - Cyan
  121.     04 - Red
  122.     05 - Magenta
  123.     06 - Brown
  124.     07 - Light Gray (Normal)
  125.  
  126.     The following are the previous colors in high intensity...
  127.  
  128.     08 - Dark Gray
  129.     09 - Light Blue
  130.     10 - Light Green
  131.     11 - Light Cyan
  132.     12 - Light Red
  133.     13 - Light Magenta
  134.     14 - Yellow (Light Brown)
  135.     15 - White (Bright White)
  136.  
  137.     It is possible to pass higher values, but they will not work unless
  138.     direct screen writes are in operation.
  139.  
  140.     */
  141.  
  142.     if (! usecolor) return;
  143.  
  144.     if (direct) textattr(val+16);
  145.  
  146.     else {
  147.         if (val > 7) {
  148.             strcpy(option, "1;");
  149.             val = val - 8;
  150.         }
  151.         if (val == 0) strcat(option, "0");
  152.         if (val == 1) strcat(option, "34");
  153.         if (val == 2) strcat(option, "32");
  154.         if (val == 3) strcat(option, "36");
  155.         if (val == 4) strcat(option, "31");
  156.         if (val == 5) strcat(option, "35");
  157.         if (val == 6) strcat(option, "33");
  158.         if (val == 7) strcat(option, "37");
  159.  
  160.         printf("\x1B[0;44;%sm", option);
  161.     }
  162. }
  163.  
  164. void vreverse()
  165. {
  166.     if (! usecolor) return;
  167.  
  168.     if (direct) textattr(112);
  169.     else output("");
  170. }
  171.  
  172. void vnormal()
  173. {
  174.     if (! usecolor) return;
  175.  
  176.     if (direct) textattr(23);
  177.     else output("");
  178. }
  179.  
  180. void vpanel(int len)
  181. {
  182.     int x;
  183.     char string[100];
  184.  
  185.     vreverse();
  186.  
  187.     for (x = 0; x < len; x++) {
  188.         output(" ");
  189.     }
  190.     if (direct) gotoxy(wherex() - len, wherey());
  191.     else {
  192.         sprintf(string, "%dD", len);
  193.         output(string);
  194.     }
  195.  
  196.     vnormal();
  197. }
  198.  
  199.  
  200. char *ansicode(int attr)
  201. {
  202.     char ret[20];
  203.  
  204.     strcpy(ret, "");
  205.  
  206.     if (attr > 127) {
  207.         strcat(ret, ";5");
  208.         attr = attr - 128;
  209.     }
  210.  
  211.     if (attr > 0 && attr < 16) strcat(ret, ";40");
  212.     if (attr > 15 && attr < 32) strcat(ret, ";44");
  213.     if (attr > 31 && attr < 48) strcat(ret, ";42");
  214.     if (attr > 47 && attr < 64) strcat(ret, ";46");
  215.     if (attr > 63 && attr < 80) strcat(ret, ";41");
  216.     if (attr > 79 && attr < 96) strcat(ret, ";45");
  217.     if (attr > 95 && attr < 112) strcat(ret, ";43");
  218.     if (attr > 111 && attr < 128) strcat(ret, ";47");
  219.  
  220.     strcat(ret, "m");
  221.     return ret;
  222. }
  223.  
  224. void aputch(char ch)
  225. {
  226.     char dis[2];
  227.  
  228.     sprintf(dis, "%c", ch);
  229.     output(dis);
  230. }
  231.