Improved linebuffering to stdout

This commit is contained in:
Michiel Broek 2002-07-29 20:31:18 +00:00
parent bc61853ff3
commit 1ed82f8b40
2 changed files with 242 additions and 230 deletions

View File

@ -58,8 +58,9 @@ void Enter(int num)
{
int i;
for(i = 0; i < num; i++)
printf("\n");
for (i = 0; i < num; i++)
fprintf(stdout, "\n");
fflush(stdout);
}
@ -68,7 +69,8 @@ void Enter(int num)
void pout(int fg, int bg, char *Str)
{
colour(fg, bg);
printf(Str);
fprintf(stdout, Str);
fflush(stdout);
}
@ -84,7 +86,8 @@ void poutCenter(int fg, int bg, char *Str)
void poutCR(int fg, int bg, char *Str)
{
colour(fg, bg);
puts(Str);
fputs(Str, stdout);
fflush(stdout);
}
@ -99,13 +102,14 @@ void colour(int fg, int bg)
int att=0, fore=37, back=40;
if (fg<0 || fg>31 || bg<0 || bg>7) {
printf("ANSI: Illegal colour specified: %i, %i\n", fg, bg);
fprintf(stdout, "ANSI: Illegal colour specified: %i, %i\n", fg, bg);
fflush(stdout);
return;
}
printf("[");
fprintf(stdout, "[");
if ( fg > 15) {
printf("5;");
fprintf(stdout, "5;");
fg-=16;
}
if (fg > 7) {
@ -131,7 +135,8 @@ void colour(int fg, int bg)
else if (bg==7) back=47;
else back=40;
printf("%d;%d;%dm", att, fore, back);
fprintf(stdout, "%d;%d;%dm", att, fore, back);
fflush(stdout);
}
}
@ -147,17 +152,18 @@ void Center(char *string)
Str = calloc(81, sizeof(char));
Strlen = strlen(string);
if(Strlen == Maxlen)
printf("%s\n", string);
if (Strlen == Maxlen)
fprintf(stdout, "%s\n", string);
else {
x = Maxlen - Strlen;
z = x / 2;
for(i = 0; i < z; i++)
for (i = 0; i < z; i++)
strcat(Str, " ");
strcat(Str, string);
printf("%s\n", Str);
fprintf(stdout, "%s\n", Str);
}
fflush(stdout);
free(Str);
}
@ -167,8 +173,9 @@ void clear()
{
if (termmode == 1) {
colour(LIGHTGRAY, BLACK);
printf(ANSI_HOME);
printf(ANSI_CLEAR);
fprintf(stdout, ANSI_HOME);
fprintf(stdout, ANSI_CLEAR);
fflush(stdout);
} else
Enter(1);
}
@ -183,17 +190,20 @@ void locate(int y, int x)
if (termmode > 0) {
if (exitinfo.iScreenLen != 0) {
if (y > exitinfo.iScreenLen || x > 80) {
printf("ANSI: Invalid screen coordinates: %i, %i\n", y, x);
printf("ANSI: exitinfo.iScreenLen: %i\n", exitinfo.iScreenLen);
fprintf(stdout, "ANSI: Invalid screen coordinates: %i, %i\n", y, x);
fprintf(stdout, "ANSI: exitinfo.iScreenLen: %i\n", exitinfo.iScreenLen);
fflush(stdout);
return;
}
} else {
if (y > 25 || x > 80) {
printf("ANSI: Invalid screen coordinates: %i, %i\n", y, x);
fprintf(stdout, "ANSI: Invalid screen coordinates: %i, %i\n", y, x);
fflush(stdout);
return;
}
}
printf("\x1B[%i;%iH", y, x);
fprintf(stdout, "\x1B[%i;%iH", y, x);
fflush(stdout);
}
}
@ -205,13 +215,14 @@ void fLine(int Len)
if (termmode == 0)
for (x = 0; x < Len; x++)
printf("-");
fprintf(stdout, "-");
if (termmode == 1)
for (x = 0; x < Len; x++)
printf("%c", 196);
fprintf(stdout, "%c", 196);
printf(" \n");
fprintf(stdout, " \n");
fflush(stdout);
}
@ -239,8 +250,9 @@ void mvprintw(int y, int x, const char *format, ...)
va_end(va_ptr);
locate(y, x);
printf(outputstr);
fprintf(stdout, outputstr);
free(outputstr);
fflush(stdout);
}

View File

@ -53,10 +53,10 @@ void clrtoeol()
{
int i;
printf("\r");
fprintf(stdout, "\r");
for (i = 0; i < COLS; i++)
putchar(' ');
printf("\r");
fputc(' ', stdout);
fprintf(stdout, "\r");
fflush(stdout);
}
@ -68,7 +68,7 @@ void hor_lin(int y, int x, int len)
locate(y, x);
for (i = 0; i < len; i++)
putchar('-');
fputc('-', stdout);
fflush(stdout);
}
@ -167,7 +167,7 @@ void screen_start(char *name)
colour(LIGHTGRAY, BLACK);
clrtoeol();
if (i < LINES)
printf("\n");
fprintf(stdout, "\n");
}
fflush(stdout);
@ -226,19 +226,19 @@ void working(int txno, int y, int x)
break;
case 2: mvprintw(4, 66, (char *)">>> ERROR <<<");
for (i = 1; i <= 5; i++) {
putchar(7);
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;
@ -295,7 +295,7 @@ void showhelp(char *T)
set_color(WHITE, RED);
}
} else {
putchar(T[i]);
fputc(T[i], stdout);
x++;
}
}