home *** CD-ROM | disk | FTP | other *** search
- /*---------------------------------------------------------------------------*/
- /* */
- /* Module Name: AMAXANSI.C */
- /* Program Name: AMAX */
- /* Revision: 2.xx */
- /* Purpose: Screen Writing Routines Module */
- /* Programmer: Alan D. Bryant */
- /* */
- /* Copyright (C) 1988, 89, 90, 92 Alan D. Bryant, All Rights Reserved. */
- /* */
- /* NOTICE: This source code is copyrighted material. You are granted a */
- /* limited license to use and distribute the code. The complete text of */
- /* the license can be found in the document LICENSE.DOC which accompanies */
- /* this source code, or can be obtained directly from the author. */
- /* */
- /* Inquiries regarding this package should be directed to: */
- /* */
- /* AMAX */
- /* Alan D. Bryant */
- /* P. O. Box 101612 */
- /* Denver, CO 80250 */
- /* USA */
- /* */
- /*---------------------------------------------------------------------------*/
-
- #include <stdio.h>
- #include "amax.h"
-
- void output(char *);
- void outputi(char *);
- void cursor(int, int);
- void scolor(int);
- void vreverse();
- void vnormal();
- void vpanel(int);
- char *ansicode(int);
- void aputch(char);
-
- extern char usecolor;
-
- void output(char *line)
- {
- int x;
-
- for (x = 0; x < strlen(line); x++) {
- if (line[x] == '$') {
- ++x;
- switch (line[x]) {
- case '1':
- scolor(14);
- break;
- case '2':
- scolor(15);
- break;
- case '3':
- scolor(10);
- break;
- case '4':
- scolor(11);
- break;
- case '5':
- scolor(13);
- break;
- case '6':
- vreverse();
- break;
- case '7':
- scolor(3);
- break;
- case '8':
- scolor(4);
- break;
- case '9':
- scolor(2);
- break;
- case '$':
- if (direct) cprintf("%s", "$$");
- else printf("%s", "$$");
- break;
- default:
- scolor(7);
- break;
- }
- }
- else {
- if (direct) cprintf("%c", line[x]);
- else printf("%c", line[x]);
- }
- }
-
-
- /*
- if (! direct) printf(line);
- else cprintf(line); */
- }
-
- void outputi(char *line)
- {
- if (! kbhit()) output(line);
- }
-
- void cursor(int x, int y)
- {
- if (! direct) printf("%d;%dH", x+1, y+1);
- else gotoxy(y+1, x+1);
- }
-
- void scolor(int val)
- {
- extern char direct;
- char option[10] = "";
-
- /*
-
- AMAX COLOR TABLE
-
- 00 - Black (Color Off)
- 01 - Blue
- 02 - Green
- 03 - Cyan
- 04 - Red
- 05 - Magenta
- 06 - Brown
- 07 - Light Gray (Normal)
-
- The following are the previous colors in high intensity...
-
- 08 - Dark Gray
- 09 - Light Blue
- 10 - Light Green
- 11 - Light Cyan
- 12 - Light Red
- 13 - Light Magenta
- 14 - Yellow (Light Brown)
- 15 - White (Bright White)
-
- It is possible to pass higher values, but they will not work unless
- direct screen writes are in operation.
-
- */
-
- if (! usecolor) return;
-
- if (direct) textattr(val+16);
-
- else {
- if (val > 7) {
- strcpy(option, "1;");
- val = val - 8;
- }
- if (val == 0) strcat(option, "0");
- if (val == 1) strcat(option, "34");
- if (val == 2) strcat(option, "32");
- if (val == 3) strcat(option, "36");
- if (val == 4) strcat(option, "31");
- if (val == 5) strcat(option, "35");
- if (val == 6) strcat(option, "33");
- if (val == 7) strcat(option, "37");
-
- printf("\x1B[0;44;%sm", option);
- }
- }
-
- void vreverse()
- {
- if (! usecolor) return;
-
- if (direct) textattr(112);
- else output("");
- }
-
- void vnormal()
- {
- if (! usecolor) return;
-
- if (direct) textattr(23);
- else output("");
- }
-
- void vpanel(int len)
- {
- int x;
- char string[100];
-
- vreverse();
-
- for (x = 0; x < len; x++) {
- output(" ");
- }
- if (direct) gotoxy(wherex() - len, wherey());
- else {
- sprintf(string, "%dD", len);
- output(string);
- }
-
- vnormal();
- }
-
-
- char *ansicode(int attr)
- {
- char ret[20];
-
- strcpy(ret, "");
-
- if (attr > 127) {
- strcat(ret, ";5");
- attr = attr - 128;
- }
-
- if (attr > 0 && attr < 16) strcat(ret, ";40");
- if (attr > 15 && attr < 32) strcat(ret, ";44");
- if (attr > 31 && attr < 48) strcat(ret, ";42");
- if (attr > 47 && attr < 64) strcat(ret, ";46");
- if (attr > 63 && attr < 80) strcat(ret, ";41");
- if (attr > 79 && attr < 96) strcat(ret, ";45");
- if (attr > 95 && attr < 112) strcat(ret, ";43");
- if (attr > 111 && attr < 128) strcat(ret, ";47");
-
- strcat(ret, "m");
- return ret;
- }
-
- void aputch(char ch)
- {
- char dis[2];
-
- sprintf(dis, "%c", ch);
- output(dis);
- }
-