Commit 462c7819 authored by rswindell's avatar rswindell
Browse files

Simplified background attribute constants (using BG_ macros).

Added special values for ansi() to return escape sequence for normal and black background.
parent 41f82d9c
......@@ -48,8 +48,14 @@ char *sbbs_t::ansi(int atr)
{
switch(atr) {
/* Special case */
case ANSI_NORMAL:
return("\x1b[0m");
case BLINK:
return("\x1b[5m");
/* Foreground */
case HIGH:
return("\x1b[1m");
case BLACK:
......@@ -68,20 +74,25 @@ char *sbbs_t::ansi(int atr)
return("\x1b[36m");
case LIGHTGRAY:
return("\x1b[37m");
case (RED<<4):
/* Background */
case BG_BLACK:
return("\x1b[40m");
case BG_RED:
return("\x1b[41m");
case (GREEN<<4):
case BG_GREEN:
return("\x1b[42m");
case (BROWN<<4):
case BG_BROWN:
return("\x1b[43m");
case (BLUE<<4):
case BG_BLUE:
return("\x1b[44m");
case (MAGENTA<<4):
case BG_MAGENTA:
return("\x1b[45m");
case (CYAN<<4):
case BG_CYAN:
return("\x1b[46m");
case (LIGHTGRAY<<4):
return("\x1b[47m"); }
case BG_LIGHTGRAY:
return("\x1b[47m");
}
return("-Invalid use of ansi()-");
}
......
......@@ -302,11 +302,11 @@ void sbbs_t::ctrl_a(char x)
console&=~CON_ECHO_OFF;
break;
case '-': /* turn off all attributes if */
if(atr&(HIGH|BLINK|(LIGHTGRAY<<4))) /* high intensity, blink or */
if(atr&(HIGH|BLINK|BG_LIGHTGRAY)) /* high intensity, blink or */
attr(LIGHTGRAY); /* background bits are set */
break;
case '_': /* turn off all attributes if */
if(atr&(BLINK|(LIGHTGRAY<<4))) /* blink or background is set */
if(atr&(BLINK|BG_LIGHTGRAY)) /* blink or background is set */
attr(LIGHTGRAY);
break;
case 'P': /* Pause */
......@@ -411,35 +411,35 @@ void sbbs_t::ctrl_a(char x)
attr(atr);
break;
case '0': /* Black Background */
atr=(atr&0x8f)|(uchar)(BLACK<<4);
atr=(atr&0x8f);
attr(atr);
break;
case '1': /* Red Background */
atr=(atr&0x8f)|(uchar)(RED<<4);
atr=(atr&0x8f)|(uchar)BG_RED;
attr(atr);
break;
case '2': /* Green Background */
atr=(atr&0x8f)|(uchar)(GREEN<<4);
atr=(atr&0x8f)|(uchar)BG_GREEN;
attr(atr);
break;
case '3': /* Yellow Background */
atr=(atr&0x8f)|(uchar)(BROWN<<4);
atr=(atr&0x8f)|(uchar)BG_BROWN;
attr(atr);
break;
case '4': /* Blue Background */
atr=(atr&0x8f)|(uchar)(BLUE<<4);
atr=(atr&0x8f)|(uchar)BG_BLUE;
attr(atr);
break;
case '5': /* Magenta Background */
atr=(atr&0x8f)|(uchar)(MAGENTA<<4);
atr=(atr&0x8f)|(uchar)BG_MAGENTA;
attr(atr);
break;
case '6': /* Cyan Background */
atr=(atr&0x8f)|(uchar)(CYAN<<4);
atr=(atr&0x8f)|(uchar)BG_CYAN;
attr(atr);
break;
case '7': /* White Background */
atr=(atr&0x8f)|(uchar)(LIGHTGRAY<<4);
atr=(atr&0x8f)|(uchar)BG_LIGHTGRAY;
attr(atr);
break; }
}
......@@ -460,9 +460,9 @@ void sbbs_t::attr(int atr)
if(!(useron.misc&COLOR)) { /* eliminate colors if user doesn't have them */
if(atr&LIGHTGRAY) /* if any foreground bits set, set all */
atr|=LIGHTGRAY;
if(atr&(LIGHTGRAY<<4)) /* if any background bits set, set all */
atr|=(LIGHTGRAY<<4);
if(atr&LIGHTGRAY && atr&(LIGHTGRAY<<4))
if(atr&BG_LIGHTGRAY) /* if any background bits set, set all */
atr|=BG_LIGHTGRAY;
if(atr&LIGHTGRAY && atr&BG_LIGHTGRAY)
atr&=~LIGHTGRAY; /* if background is solid, foreground is black */
if(!atr)
atr|=LIGHTGRAY; } /* don't allow black on black */
......@@ -471,7 +471,7 @@ void sbbs_t::attr(int atr)
if((!(atr&HIGH) && curatr&HIGH) || (!(atr&BLINK) && curatr&BLINK)
|| atr==LIGHTGRAY) {
bputs("\x1b[0m");
bputs(ansi(ANSI_NORMAL));
curatr=LIGHTGRAY; }
if(atr==LIGHTGRAY) /* no attributes */
......@@ -509,30 +509,30 @@ void sbbs_t::attr(int atr)
if((curatr&0x7)!=LIGHTGRAY)
bputs(ansi(LIGHTGRAY)); }
if((atr&0x70)==(BLACK<<4)) { /* background colors */
if((curatr&0x70)!=(BLACK<<4))
bputs("\x1b[40m"); }
else if((atr&0x70)==(RED<<4)) {
if((curatr&0x70)!=(RED<<4))
bputs(ansi(RED<<4)); }
else if((atr&0x70)==(GREEN<<4)) {
if((curatr&0x70)!=(GREEN<<4))
bputs(ansi(GREEN<<4)); }
else if((atr&0x70)==(BROWN<<4)) {
if((curatr&0x70)!=(BROWN<<4))
bputs(ansi(BROWN<<4)); }
else if((atr&0x70)==(BLUE<<4)) {
if((curatr&0x70)!=(BLUE<<4))
bputs(ansi(BLUE<<4)); }
else if((atr&0x70)==(MAGENTA<<4)) {
if((curatr&0x70)!=(MAGENTA<<4))
bputs(ansi(MAGENTA<<4)); }
else if((atr&0x70)==(CYAN<<4)) {
if((curatr&0x70)!=(CYAN<<4))
bputs(ansi(CYAN<<4)); }
else if((atr&0x70)==(LIGHTGRAY<<4)) {
if((curatr&0x70)!=(LIGHTGRAY<<4))
bputs(ansi(LIGHTGRAY<<4)); }
if((atr&0x70)==0) { /* background colors */
if((curatr&0x70)!=0)
bputs(ansi(BG_BLACK)); }
else if((atr&0x70)==BG_RED) {
if((curatr&0x70)!=BG_RED)
bputs(ansi(BG_RED)); }
else if((atr&0x70)==BG_GREEN) {
if((curatr&0x70)!=BG_GREEN)
bputs(ansi(BG_GREEN)); }
else if((atr&0x70)==BG_BROWN) {
if((curatr&0x70)!=BG_BROWN)
bputs(ansi(BG_BROWN)); }
else if((atr&0x70)==BG_BLUE) {
if((curatr&0x70)!=BG_BLUE)
bputs(ansi(BG_BLUE)); }
else if((atr&0x70)==BG_MAGENTA) {
if((curatr&0x70)!=BG_MAGENTA)
bputs(ansi(BG_MAGENTA)); }
else if((atr&0x70)==BG_CYAN) {
if((curatr&0x70)!=BG_CYAN)
bputs(ansi(BG_CYAN)); }
else if((atr&0x70)==BG_LIGHTGRAY) {
if((curatr&0x70)!=BG_LIGHTGRAY)
bputs(ansi(BG_LIGHTGRAY)); }
curatr=atr;
}
......
......@@ -202,13 +202,7 @@ ulong sbbs_t::msgtoqwk(smbmsg_t* msg, FILE *qwk_fp, long mode, int subnum
strcpy(str,ansi(BLINK));
break;
case 'N': /* Normal */
strcpy(str,"\x1b[0m");
break;
case '0':
strcpy(str,"\x1b[40m");
break;
case '7':
strcpy(str,ansi(LIGHTGRAY<<4));
strcpy(str,ansi(ANSI_NORMAL));
break;
case 'R': /* Color codes */
strcpy(str,ansi(RED));
......@@ -228,28 +222,37 @@ ulong sbbs_t::msgtoqwk(smbmsg_t* msg, FILE *qwk_fp, long mode, int subnum
case 'Y': /* Yellow */
strcpy(str,ansi(BROWN));
break;
case '0':
strcpy(str,ansi(BG_BLACK));
break;
case '1':
strcpy(str,ansi(RED<<4));
strcpy(str,ansi(BG_RED));
break;
case '2':
strcpy(str,ansi(GREEN<<4));
strcpy(str,ansi(BG_GREEN));
break;
case '3':
strcpy(str,ansi(BROWN<<4));
strcpy(str,ansi(BG_BROWN));
break;
case '4':
strcpy(str,ansi(BLUE<<4));
strcpy(str,ansi(BG_BLUE));
break;
case '5':
strcpy(str,ansi(MAGENTA<<4));
strcpy(str,ansi(BG_MAGENTA));
break;
case '6':
strcpy(str,ansi(CYAN<<4));
break; }
strcpy(str,ansi(BG_CYAN));
break;
case '7':
strcpy(str,ansi(BG_LIGHTGRAY));
break;
}
if(str[0]) {
fwrite(str,strlen(str),1,qwk_fp);
size+=strlen(str); }
continue; } /* End Expand */
size+=strlen(str);
}
continue;
} /* End Expand */
if(mode&A_LEAVE) {
fputc(1,qwk_fp);
......
......@@ -177,7 +177,7 @@ char sbbs_t::putmsg(char HUGE16 *str, long mode)
attr(MAGENTA);
break;
case '4':
attr(LIGHTGRAY|HIGH|(BLUE<<4));
attr(LIGHTGRAY|HIGH|BG_BLUE);
break;
case '5':
attr(GREEN);
......
......@@ -577,7 +577,6 @@ typedef enum { /* Values for xtrn_t.event */
#define AUTOLOGON (1L<<22) /* AutoLogon via IP */
#define CLREOL 256 /* Character to erase to end of line */
#define HIGH 8 /* High intensity for curatr */
/* Online status (online) */
#define ON_LOCAL 1 /* Online locally */
......@@ -805,53 +804,19 @@ extern long crc32tbl[];
#define ucrc32(ch,crc) (crc32tbl[(crc^ch)&0xff]^(crc>>8))
#ifdef __WATCOMC__
#if !defined(__COLORS)
#define __COLORS
enum COLORS {
BLACK, /* dark colors */
BLUE,
GREEN,
CYAN,
RED,
MAGENTA,
BROWN,
LIGHTGRAY,
DARKGRAY, /* light colors */
LIGHTBLUE,
LIGHTGREEN,
LIGHTCYAN,
LIGHTRED,
LIGHTMAGENTA,
YELLOW,
WHITE
};
#endif
#define BLINK 128 /* blink bit */
#define ffblk find_t
#define findfirst(x,y,z) _dos_findfirst(x,z,y)
#define findnext(x) _dos_findnext(x)
#endif
#if DEBUG /* if DEBUG, call function */
#define DLOG(where,txt) dlog(where,txt)
#else /* else, do nothing - function isn't even valid */
#define DLOG(where,txt)
#endif
/**************************************/
/* Text Attribute (color) Definitions */
/**************************************/
#define HIGH 0x08 /* High intensity foreground text */
#ifndef BLINK
#define BLINK 128
#define BLINK 0x80 /* Blinking text */
#endif
#ifndef __COLORS
#define __COLORS
enum COLORS {
BLACK, /* dark colors */
BLACK, /* dark colors (HIGH bit unset) */
BLUE,
GREEN,
CYAN,
......@@ -859,7 +824,7 @@ enum COLORS {
MAGENTA,
BROWN,
LIGHTGRAY,
DARKGRAY, /* light colors */
DARKGRAY, /* light colors (HIGH bit set) */
LIGHTBLUE,
LIGHTGREEN,
LIGHTCYAN,
......@@ -869,7 +834,17 @@ enum COLORS {
WHITE
};
#endif
#endif /* __COLORS */
#define ANSI_NORMAL 0x100
#define BG_BLACK 0x200
#define BG_BLUE (BLUE<<4)
#define BG_GREEN (GREEN<<4)
#define BG_CYAN (CYAN<<4)
#define BG_RED (RED<<4)
#define BG_MAGENTA (MAGENTA<<4)
#define BG_BROWN (BROWN<<4)
#define BG_LIGHTGRAY (LIGHTGRAY<<4)
/********************/
/* Type Definitions */
......
......@@ -1045,12 +1045,6 @@ uchar attrstr(char *str)
case 'W': /* White */
atr=(atr&0xf8)|LIGHTGRAY;
break;
case '0': /* Black Background */
atr=(uchar)((atr&0x8f)|(BLACK<<4));
break;
case '7': /* White Background */
atr=(uchar)((atr&0x8f)|(LIGHTGRAY<<4));
break;
case 'R':
atr=(uchar)((atr&0xf8)|RED);
break;
......@@ -1069,25 +1063,33 @@ uchar attrstr(char *str)
case 'C':
atr=(uchar)((atr&0xf8)|CYAN);
break;
case '0': /* Black Background */
atr=(uchar)(atr&0x8f);
break;
case '1': /* Red Background */
atr=(uchar)((atr&0x8f)|(RED<<4));
atr=(uchar)((atr&0x8f)|BG_RED);
break;
case '2': /* Green Background */
atr=(uchar)((atr&0x8f)|(GREEN<<4));
atr=(uchar)((atr&0x8f)|BG_GREEN);
break;
case '3': /* Yellow Background */
atr=(uchar)((atr&0x8f)|(BROWN<<4));
atr=(uchar)((atr&0x8f)|BG_BROWN);
break;
case '4': /* Blue Background */
atr=(uchar)((atr&0x8f)|(BLUE<<4));
atr=(uchar)((atr&0x8f)|BG_BLUE);
break;
case '5': /* Magenta Background */
atr=(uchar)((atr&0x8f)|(MAGENTA<<4));
atr=(uchar)((atr&0x8f)|BG_MAGENTA);
break;
case '6': /* Cyan Background */
atr=(uchar)((atr&0x8f)|(CYAN<<4));
break; }
l++; }
atr=(uchar)((atr&0x8f)|BG_CYAN);
break;
case '7': /* White Background */
atr=(uchar)((atr&0x8f)|BG_LIGHTGRAY);
break;
}
l++;
}
return(atr);
}
......
......@@ -209,7 +209,7 @@ void sbbs_t::sif(char *fname, char *answers, long len)
if(useron.misc&COLOR)
attr(cfg.color[clr_inputline]);
else
attr(BLACK|(LIGHTGRAY<<4));
attr(BLACK|BG_LIGHTGRAY);
bputs(" \b");
m++; }
if((buf[m+1]&0xdf)=='R') { /* Add CRLF */
......@@ -343,7 +343,7 @@ void sbbs_t::sof(char *fname, char *answers, long len)
if(useron.misc&COLOR)
attr(cfg.color[clr_inputline]);
else
attr(BLACK|(LIGHTGRAY<<4));
attr(BLACK|BG_LIGHTGRAY);
bputs(" \b");
m++; }
if((buf[m+1]&0xdf)=='R') { /* Add CRLF */
......@@ -365,7 +365,7 @@ void sbbs_t::sof(char *fname, char *answers, long len)
if(useron.misc&COLOR)
attr(cfg.color[clr_inputline]);
else
attr(BLACK|(LIGHTGRAY<<4));
attr(BLACK|BG_LIGHTGRAY);
m++; }
if((buf[m+1]&0xdf)=='R') {
cr=1;
......@@ -464,7 +464,7 @@ uint sbbs_t::gettmplt(char *strout,char *templt, long mode)
if(useron.misc&COLOR)
attr(cfg.color[clr_inputline]);
else
attr(BLACK|(LIGHTGRAY<<4)); }
attr(BLACK|BG_LIGHTGRAY); }
while(c<t) {
if(tmplt[c]=='N' || tmplt[c]=='A' || tmplt[c]=='!')
outchar(SP);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment