Separated tty drivers for mbsebbs and mbnewusr
This commit is contained in:
@@ -2278,18 +2278,11 @@ char *TearLine(void);
|
||||
/*
|
||||
* From term.c
|
||||
*/
|
||||
void TermInit(int, int, int);
|
||||
void Enter(int);
|
||||
void pout(int, int, char *);
|
||||
void poutCR(int, int, char *);
|
||||
void poutCenter(int,int,char *);
|
||||
void colour(int, int);
|
||||
void Center(char *);
|
||||
void clear(void);
|
||||
void locate(int, int);
|
||||
void fLine(int);
|
||||
void sLine(void);
|
||||
void mvprintw(int, int, const char *, ...);
|
||||
void mbse_TermInit(int, int, int);
|
||||
void mbse_colour(int, int);
|
||||
void mbse_clear(void);
|
||||
void mbse_locate(int, int);
|
||||
void mbse_mvprintw(int, int, const char *, ...);
|
||||
|
||||
|
||||
|
||||
|
55
lib/msg.c
55
lib/msg.c
@@ -324,6 +324,55 @@ typedef struct {
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Changes ansi background and foreground color
|
||||
*/
|
||||
void msg_colour(int, int);
|
||||
void msg_colour(int fg, int bg)
|
||||
{
|
||||
int att=0, fore=37, back=40;
|
||||
|
||||
if (fg<0 || fg>31 || bg<0 || bg>7) {
|
||||
fprintf(stdout, "ANSI: Illegal colour specified: %i, %i\n", fg, bg);
|
||||
fflush(stdout);
|
||||
return;
|
||||
}
|
||||
fprintf(stdout, "ESC[");
|
||||
|
||||
if ( fg > WHITE) {
|
||||
fprintf(stdout, "5;");
|
||||
fg-= 16;
|
||||
}
|
||||
if (fg > LIGHTGRAY) {
|
||||
att=1;
|
||||
fg=fg-8;
|
||||
}
|
||||
|
||||
if (fg == BLACK) fore=30;
|
||||
else if (fg == BLUE) fore=34;
|
||||
else if (fg == GREEN) fore=32;
|
||||
else if (fg == CYAN) fore=36;
|
||||
else if (fg == RED) fore=31;
|
||||
else if (fg == MAGENTA) fore=35;
|
||||
else if (fg == BROWN) fore=33;
|
||||
else fore=37;
|
||||
|
||||
if (bg == BLUE) back=44;
|
||||
else if (bg == GREEN) back=42;
|
||||
else if (bg == CYAN) back=46;
|
||||
else if (bg == RED) back=41;
|
||||
else if (bg == MAGENTA) back=45;
|
||||
else if (bg == BROWN) back=43;
|
||||
else if (bg == LIGHTGRAY) back=47;
|
||||
else back=40;
|
||||
|
||||
fprintf(stdout, "%d;%d;%dm", att, fore, back);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Link messages in one area.
|
||||
* Returns -1 if error, else the number of linked messages.
|
||||
@@ -340,9 +389,9 @@ int Msg_Link(char *Path, int do_quiet, int slow_util)
|
||||
}
|
||||
|
||||
if (!do_quiet) {
|
||||
colour(12, 0);
|
||||
msg_colour(12, 0);
|
||||
printf(" (linking)");
|
||||
colour(13, 0);
|
||||
msg_colour(13, 0);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
@@ -439,6 +488,8 @@ int Msg_Link(char *Path, int do_quiet, int slow_util)
|
||||
return msg_link;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Fgets() is like fgets() but never returns the line terminator
|
||||
* at end of line and handles that line terminators:
|
||||
|
20
lib/rearc.c
20
lib/rearc.c
@@ -44,14 +44,14 @@ int rearc(char *filename, char *arctype, int do_quiet)
|
||||
Syslog('f', "rearc(%s, %s)", filename, arctype);
|
||||
|
||||
if (!do_quiet) {
|
||||
colour(12, 0);
|
||||
mbse_colour(12, 0);
|
||||
printf(" ReArc file %s ", filename);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
if (strchr(filename, '/') == NULL) {
|
||||
if (!do_quiet) {
|
||||
colour(LIGHTRED, BLACK);
|
||||
mbse_colour(LIGHTRED, BLACK);
|
||||
printf(" no path in filename\n");
|
||||
}
|
||||
Syslog('+', "rearc(%s, %s), no path in filename", filename, arctype);
|
||||
@@ -60,7 +60,7 @@ int rearc(char *filename, char *arctype, int do_quiet)
|
||||
|
||||
if ((unarc = unpacker(filename)) == NULL) {
|
||||
if (!do_quiet) {
|
||||
colour(LIGHTRED, BLACK);
|
||||
mbse_colour(LIGHTRED, BLACK);
|
||||
printf(" unknown archive type\n");
|
||||
}
|
||||
return -1;
|
||||
@@ -68,7 +68,7 @@ int rearc(char *filename, char *arctype, int do_quiet)
|
||||
|
||||
if (!getarchiver(unarc)) {
|
||||
if (!do_quiet) {
|
||||
colour(LIGHTRED, BLACK);
|
||||
mbse_colour(LIGHTRED, BLACK);
|
||||
printf(" no unarchiver available\n");
|
||||
}
|
||||
Syslog('+', "rearc(%s, %s), no unarchiver available", filename, arctype);
|
||||
@@ -78,7 +78,7 @@ int rearc(char *filename, char *arctype, int do_quiet)
|
||||
uncmd = xstrcpy(archiver.funarc);
|
||||
if ((uncmd == NULL) || (uncmd == "")) {
|
||||
if (!do_quiet) {
|
||||
colour(LIGHTRED, BLACK);
|
||||
mbse_colour(LIGHTRED, BLACK);
|
||||
printf(" no unarchive command available\n");
|
||||
}
|
||||
Syslog('+', "rearc(%s, %s), no unarchive command available", filename, arctype);
|
||||
@@ -93,7 +93,7 @@ int rearc(char *filename, char *arctype, int do_quiet)
|
||||
|
||||
if (!getarchiver(arctype)) {
|
||||
if (!do_quiet) {
|
||||
colour(LIGHTRED, BLACK);
|
||||
mbse_colour(LIGHTRED, BLACK);
|
||||
printf(" no archiver available\n");
|
||||
}
|
||||
Syslog('+', "rearc(%s, %s), no archiver available", filename, arctype);
|
||||
@@ -104,7 +104,7 @@ int rearc(char *filename, char *arctype, int do_quiet)
|
||||
|
||||
if (strcmp(unarc, archiver.name) == 0) {
|
||||
if (!do_quiet) {
|
||||
colour(LIGHTRED, BLACK);
|
||||
mbse_colour(LIGHTRED, BLACK);
|
||||
printf(" already in %s format\n", arctype);
|
||||
}
|
||||
Syslog('+', "rearc(%s, %s), already in %s format", filename, arctype, arctype);
|
||||
@@ -119,7 +119,7 @@ int rearc(char *filename, char *arctype, int do_quiet)
|
||||
arccmd = xstrcpy(archiver.farc);
|
||||
if ((arccmd == NULL) || (arccmd == "")) {
|
||||
if (!do_quiet) {
|
||||
colour(LIGHTRED, BLACK);
|
||||
mbse_colour(LIGHTRED, BLACK);
|
||||
printf(" no archive command available\n");
|
||||
}
|
||||
Syslog('+', "rearc(%s, %s), no archive command available", filename, arctype);
|
||||
@@ -145,7 +145,7 @@ int rearc(char *filename, char *arctype, int do_quiet)
|
||||
}
|
||||
|
||||
if (!do_quiet) {
|
||||
colour(11, 0);
|
||||
mbse_colour(11, 0);
|
||||
printf("\rUnpacking file %s ", filename);
|
||||
fflush(stdout);
|
||||
}
|
||||
@@ -165,7 +165,7 @@ int rearc(char *filename, char *arctype, int do_quiet)
|
||||
}
|
||||
|
||||
if (!do_quiet) {
|
||||
colour(10, 0);
|
||||
mbse_colour(10, 0);
|
||||
printf("\r Packing file %s ", newname);
|
||||
}
|
||||
|
||||
|
117
lib/term.c
117
lib/term.c
@@ -39,7 +39,7 @@ int termx = 80;
|
||||
int termy = 24;
|
||||
|
||||
|
||||
void TermInit(int mode, int x, int y)
|
||||
void mbse_TermInit(int mode, int x, int y)
|
||||
{
|
||||
termmode = mode;
|
||||
termx = x;
|
||||
@@ -48,52 +48,10 @@ void TermInit(int mode, int x, int y)
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Function will print about of enters specified
|
||||
*/
|
||||
void Enter(int num)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < num; i++)
|
||||
fprintf(stdout, "\n");
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void pout(int fg, int bg, char *Str)
|
||||
{
|
||||
colour(fg, bg);
|
||||
fprintf(stdout, Str);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void poutCenter(int fg, int bg, char *Str)
|
||||
{
|
||||
colour(fg, bg);
|
||||
Center(Str);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void poutCR(int fg, int bg, char *Str)
|
||||
{
|
||||
colour(fg, bg);
|
||||
fputs(Str, stdout);
|
||||
fprintf(stdout, "\n");
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Changes ansi background and foreground color
|
||||
*/
|
||||
void colour(int fg, int bg)
|
||||
void mbse_colour(int fg, int bg)
|
||||
{
|
||||
if (termmode == 1) {
|
||||
|
||||
@@ -140,42 +98,16 @@ void colour(int fg, int bg)
|
||||
|
||||
|
||||
|
||||
void Center(char *string)
|
||||
{
|
||||
int Strlen;
|
||||
int Maxlen = termx;
|
||||
int i, x, z;
|
||||
char *Str;
|
||||
|
||||
Str = calloc(1024, sizeof(char));
|
||||
Strlen = strlen(string);
|
||||
|
||||
if (Strlen == Maxlen)
|
||||
fprintf(stdout, "%s\n", string);
|
||||
else {
|
||||
x = Maxlen - Strlen;
|
||||
z = x / 2;
|
||||
for (i = 0; i < z; i++)
|
||||
strcat(Str, " ");
|
||||
strcat(Str, string);
|
||||
fprintf(stdout, "%s\n", Str);
|
||||
}
|
||||
|
||||
fflush(stdout);
|
||||
free(Str);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void clear()
|
||||
void mbse_clear()
|
||||
{
|
||||
if (termmode == 1) {
|
||||
colour(LIGHTGRAY, BLACK);
|
||||
mbse_colour(LIGHTGRAY, BLACK);
|
||||
fprintf(stdout, ANSI_HOME);
|
||||
fprintf(stdout, ANSI_CLEAR);
|
||||
fflush(stdout);
|
||||
} else
|
||||
Enter(1);
|
||||
} else {
|
||||
fprintf(stdout, "\n");
|
||||
}
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
|
||||
@@ -183,7 +115,7 @@ void clear()
|
||||
/*
|
||||
* Moves cursor to specified position
|
||||
*/
|
||||
void locate(int y, int x)
|
||||
void mbse_locate(int y, int x)
|
||||
{
|
||||
if (termmode > 0) {
|
||||
if (y > termy || x > termx) {
|
||||
@@ -198,36 +130,10 @@ void locate(int y, int x)
|
||||
|
||||
|
||||
|
||||
void fLine(int Len)
|
||||
{
|
||||
int x;
|
||||
|
||||
if (termmode == 0)
|
||||
for (x = 0; x < Len; x++)
|
||||
fprintf(stdout, "-");
|
||||
|
||||
if (termmode == 1)
|
||||
for (x = 0; x < Len; x++)
|
||||
fprintf(stdout, "%c", 196);
|
||||
|
||||
fprintf(stdout, " \n");
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void sLine()
|
||||
{
|
||||
fLine(termx -1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* curses compatible functions
|
||||
*/
|
||||
void mvprintw(int y, int x, const char *format, ...)
|
||||
void mbse_mvprintw(int y, int x, const char *format, ...)
|
||||
{
|
||||
char *outputstr;
|
||||
va_list va_ptr;
|
||||
@@ -238,11 +144,10 @@ void mvprintw(int y, int x, const char *format, ...)
|
||||
vsprintf(outputstr, format, va_ptr);
|
||||
va_end(va_ptr);
|
||||
|
||||
locate(y, x);
|
||||
mbse_locate(y, x);
|
||||
fprintf(stdout, outputstr);
|
||||
free(outputstr);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user