Improved linebuffering to stdout
This commit is contained in:
258
mbsetup/screen.c
258
mbsetup/screen.c
@@ -51,25 +51,25 @@ int bbs_free;
|
||||
|
||||
void clrtoeol()
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
|
||||
printf("\r");
|
||||
for (i = 0; i < COLS; i++)
|
||||
putchar(' ');
|
||||
printf("\r");
|
||||
fflush(stdout);
|
||||
fprintf(stdout, "\r");
|
||||
for (i = 0; i < COLS; i++)
|
||||
fputc(' ', stdout);
|
||||
fprintf(stdout, "\r");
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void hor_lin(int y, int x, int len)
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
|
||||
locate(y, x);
|
||||
for (i = 0; i < len; i++)
|
||||
putchar('-');
|
||||
fflush(stdout);
|
||||
locate(y, x);
|
||||
for (i = 0; i < len; i++)
|
||||
fputc('-', stdout);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
|
||||
@@ -99,51 +99,51 @@ static time_t lasttime;
|
||||
*/
|
||||
void show_date(int fg, int bg, int y, int x)
|
||||
{
|
||||
time_t now;
|
||||
char *p, buf[128];
|
||||
time_t now;
|
||||
char *p, buf[128];
|
||||
|
||||
now = time(NULL);
|
||||
if (now != lasttime) {
|
||||
lasttime = now;
|
||||
set_color(LIGHTGREEN, BLUE);
|
||||
p = ctime(&now);
|
||||
Striplf(p);
|
||||
mvprintw(1, 44, (char *)"%s TZUTC %s", p, gmtoffset(now));
|
||||
p = asctime(gmtime(&now));
|
||||
Striplf(p);
|
||||
mvprintw(2, 44, (char *)"%s UTC", p);
|
||||
now = time(NULL);
|
||||
if (now != lasttime) {
|
||||
lasttime = now;
|
||||
set_color(LIGHTGREEN, BLUE);
|
||||
p = ctime(&now);
|
||||
Striplf(p);
|
||||
mvprintw(1, 44, (char *)"%s TZUTC %s", p, gmtoffset(now));
|
||||
p = asctime(gmtime(&now));
|
||||
Striplf(p);
|
||||
mvprintw(2, 44, (char *)"%s UTC", p);
|
||||
|
||||
/*
|
||||
* Indicator if bbs is free
|
||||
*/
|
||||
strcpy(buf, SockR("SFRE:0;"));
|
||||
if (strncmp(buf, "100:0;", 6) == 0) {
|
||||
strcpy(buf, SockR("SBBS:0;"));
|
||||
if (strncmp(buf, "100:2,1", 7) == 0) {
|
||||
set_color(WHITE, RED);
|
||||
mvprintw(2,74, (char *)" Down ");
|
||||
} else {
|
||||
set_color(WHITE, BLUE);
|
||||
mvprintw(2,74, (char *)" Free ");
|
||||
}
|
||||
bbs_free = TRUE;
|
||||
} else {
|
||||
set_color(WHITE, RED);
|
||||
mvprintw(2,74, (char *)" Busy ");
|
||||
bbs_free = FALSE;
|
||||
}
|
||||
|
||||
if (y && x)
|
||||
locate(y, x);
|
||||
set_color(fg, bg);
|
||||
/*
|
||||
* Indicator if bbs is free
|
||||
*/
|
||||
strcpy(buf, SockR("SFRE:0;"));
|
||||
if (strncmp(buf, "100:0;", 6) == 0) {
|
||||
strcpy(buf, SockR("SBBS:0;"));
|
||||
if (strncmp(buf, "100:2,1", 7) == 0) {
|
||||
set_color(WHITE, RED);
|
||||
mvprintw(2,74, (char *)" Down ");
|
||||
} else {
|
||||
set_color(WHITE, BLUE);
|
||||
mvprintw(2,74, (char *)" Free ");
|
||||
}
|
||||
bbs_free = TRUE;
|
||||
} else {
|
||||
set_color(WHITE, RED);
|
||||
mvprintw(2,74, (char *)" Busy ");
|
||||
bbs_free = FALSE;
|
||||
}
|
||||
|
||||
if (y && x)
|
||||
locate(y, x);
|
||||
set_color(fg, bg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void center_addstr(int y, char *s)
|
||||
{
|
||||
mvprintw(y, (COLS / 2) - (strlen(s) / 2), s);
|
||||
mvprintw(y, (COLS / 2) - (strlen(s) / 2), s);
|
||||
}
|
||||
|
||||
|
||||
@@ -153,33 +153,33 @@ void center_addstr(int y, char *s)
|
||||
*/
|
||||
void screen_start(char *name)
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
|
||||
TermInit(1);
|
||||
/*
|
||||
* Overwrite screen the first time, if user had it black on white
|
||||
* it will change to white on black. clear() won't do the trick.
|
||||
*/
|
||||
set_color(LIGHTGRAY, BLUE);
|
||||
locate(1, 1);
|
||||
for (i = 0; i < LINES; i++) {
|
||||
if (i == 3)
|
||||
colour(LIGHTGRAY, BLACK);
|
||||
clrtoeol();
|
||||
if (i < LINES)
|
||||
printf("\n");
|
||||
}
|
||||
fflush(stdout);
|
||||
TermInit(1);
|
||||
/*
|
||||
* Overwrite screen the first time, if user had it black on white
|
||||
* it will change to white on black. clear() won't do the trick.
|
||||
*/
|
||||
set_color(LIGHTGRAY, BLUE);
|
||||
locate(1, 1);
|
||||
for (i = 0; i < LINES; i++) {
|
||||
if (i == 3)
|
||||
colour(LIGHTGRAY, BLACK);
|
||||
clrtoeol();
|
||||
if (i < LINES)
|
||||
fprintf(stdout, "\n");
|
||||
}
|
||||
fflush(stdout);
|
||||
|
||||
set_color(WHITE, BLUE);
|
||||
locate(1, 1);
|
||||
printf((char *)"%s for MBSE BBS version %s", name, VERSION);
|
||||
set_color(YELLOW, BLUE);
|
||||
locate(2, 1);
|
||||
printf((char *)SHORTRIGHT);
|
||||
set_color(LIGHTGRAY, BLACK);
|
||||
show_date(LIGHTGRAY, BLACK, 0, 0);
|
||||
fflush(stdout);
|
||||
set_color(WHITE, BLUE);
|
||||
locate(1, 1);
|
||||
printf((char *)"%s for MBSE BBS version %s", name, VERSION);
|
||||
set_color(YELLOW, BLUE);
|
||||
locate(2, 1);
|
||||
printf((char *)SHORTRIGHT);
|
||||
set_color(LIGHTGRAY, BLACK);
|
||||
show_date(LIGHTGRAY, BLACK, 0, 0);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
|
||||
@@ -189,9 +189,9 @@ void screen_start(char *name)
|
||||
*/
|
||||
void screen_stop()
|
||||
{
|
||||
set_color(LIGHTGRAY, BLACK);
|
||||
clear();
|
||||
fflush(stdout);
|
||||
set_color(LIGHTGRAY, BLACK);
|
||||
clear();
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
|
||||
@@ -201,56 +201,56 @@ void screen_stop()
|
||||
*/
|
||||
void working(int txno, int y, int x)
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
|
||||
if (init)
|
||||
return;
|
||||
if (init)
|
||||
return;
|
||||
|
||||
/*
|
||||
* If txno not 0 there will be something written. The
|
||||
* reversed attributes for mono, or white on red for
|
||||
* color screens is set. The cursor is turned off and
|
||||
* original cursor position is saved.
|
||||
*/
|
||||
show_date(LIGHTGRAY, BLACK, 0, 0);
|
||||
/*
|
||||
* If txno not 0 there will be something written. The
|
||||
* reversed attributes for mono, or white on red for
|
||||
* color screens is set. The cursor is turned off and
|
||||
* original cursor position is saved.
|
||||
*/
|
||||
show_date(LIGHTGRAY, BLACK, 0, 0);
|
||||
|
||||
if (txno != 0)
|
||||
set_color(YELLOW, RED);
|
||||
else
|
||||
set_color(LIGHTGRAY, BLACK);
|
||||
if (txno != 0)
|
||||
set_color(YELLOW, RED);
|
||||
else
|
||||
set_color(LIGHTGRAY, BLACK);
|
||||
|
||||
switch (txno) {
|
||||
switch (txno) {
|
||||
case 0: mvprintw(4, 66, (char *)" ");
|
||||
break;
|
||||
case 1: mvprintw(4, 66, (char *)"Working . . .");
|
||||
break;
|
||||
case 2: mvprintw(4, 66, (char *)">>> ERROR <<<");
|
||||
for (i = 1; i <= 5; i++) {
|
||||
putchar(7);
|
||||
fflush(stdout);
|
||||
usleep(150000);
|
||||
fputc(7, stdout);
|
||||
fflush(stdout);
|
||||
usleep(150000);
|
||||
}
|
||||
usleep(550000);
|
||||
break;
|
||||
case 3: mvprintw(4, 66, (char *)"Form inserted");
|
||||
putchar(7);
|
||||
fputc(7, stdout);
|
||||
fflush(stdout);
|
||||
sleep(1);
|
||||
break;
|
||||
case 4: mvprintw(4, 66, (char *)"Form deleted ");
|
||||
putchar(7);
|
||||
fputc(7, stdout);
|
||||
fflush(stdout);
|
||||
sleep(1);
|
||||
break;
|
||||
case 5: mvprintw(4, 66, (char *)"Moving . . . ");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
show_date(LIGHTGRAY, BLACK, 0, 0);
|
||||
set_color(LIGHTGRAY, BLACK);
|
||||
if (y && x)
|
||||
locate(y, x);
|
||||
fflush(stdout);
|
||||
show_date(LIGHTGRAY, BLACK, 0, 0);
|
||||
set_color(LIGHTGRAY, BLACK);
|
||||
if (y && x)
|
||||
locate(y, x);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
|
||||
@@ -260,13 +260,13 @@ void working(int txno, int y, int x)
|
||||
*/
|
||||
void clr_index()
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
|
||||
set_color(LIGHTGRAY, BLACK);
|
||||
for (i = 3; i <= (LINES - 1); i++) {
|
||||
locate(i, 1);
|
||||
clrtoeol();
|
||||
}
|
||||
set_color(LIGHTGRAY, BLACK);
|
||||
for (i = 3; i <= (LINES - 1); i++) {
|
||||
locate(i, 1);
|
||||
clrtoeol();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -276,31 +276,31 @@ void clr_index()
|
||||
*/
|
||||
void showhelp(char *T)
|
||||
{
|
||||
int f, i, x, forlim;
|
||||
int f, i, x, forlim;
|
||||
|
||||
f = FALSE;
|
||||
locate(LINES-1, 1);
|
||||
set_color(WHITE, RED);
|
||||
clrtoeol();
|
||||
x = 0;
|
||||
forlim = strlen(T);
|
||||
f = FALSE;
|
||||
locate(LINES-1, 1);
|
||||
set_color(WHITE, RED);
|
||||
clrtoeol();
|
||||
x = 0;
|
||||
forlim = strlen(T);
|
||||
|
||||
for (i = 0; i < forlim; i++) {
|
||||
if (T[i] == '^') {
|
||||
if (f == FALSE) {
|
||||
f = TRUE;
|
||||
set_color(YELLOW, RED);
|
||||
} else {
|
||||
f = FALSE;
|
||||
set_color(WHITE, RED);
|
||||
}
|
||||
} else {
|
||||
putchar(T[i]);
|
||||
x++;
|
||||
}
|
||||
for (i = 0; i < forlim; i++) {
|
||||
if (T[i] == '^') {
|
||||
if (f == FALSE) {
|
||||
f = TRUE;
|
||||
set_color(YELLOW, RED);
|
||||
} else {
|
||||
f = FALSE;
|
||||
set_color(WHITE, RED);
|
||||
}
|
||||
} else {
|
||||
fputc(T[i], stdout);
|
||||
x++;
|
||||
}
|
||||
set_color(LIGHTGRAY, BLACK);
|
||||
fflush(stdout);
|
||||
}
|
||||
set_color(LIGHTGRAY, BLACK);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user