_PORTABLE SCREEN HANDLING_ by Matt Weisfeld Listing One /*************************************************** FILE NAME : scrlibs.h AUTHOR : Matt Weisfeld DESCRIPTION : header file for scrlibs.c ***************************************************/ #ifdef VMS #define ANSI_COMPILER #define ANSI_SEQUENCES #define VT100 #endif #ifdef SLC #define UNIX #define K_R_COMPILER #define ANSI_SEQUENCES #define VT100 #endif #ifdef BCC #define DOS #define ANSI_COMPILER #define ANSI_SEQUENCES #endif #ifdef HPUX #define UNIX #define ANSI_COMPILER #define HPUX_SEQUENCES #endif #ifdef ANSI_COMPILER void do_bold(FILE *); void do_normal(FILE *); void do_blink(FILE *); void do_reverse(FILE *); void cursor_right(int); void cursor_left(int); void cursor_down(int); void cursor_up(int); void cursor_pos(int, int); void cursor_home(void); void erase_display(void); #else void do_bold(); void do_normal(); void do_blink(); void do_reverse(); void cursor_right(); void cursor_left(); void cursor_down(); void cursor_up(); void cursor_pos(); void cursor_home(); void cursor_bottom(); void erase_display(); #endif #ifdef ANSI_SEQUENCES #ifdef DOS static char bold[] = {"\033[36;1m"}; #else static char bold[] = {"\033[1m"}; #endif static char normal[] = {"\033[0m"}; static char blink[] = {"\033[5m"}; static char reverse[] = {"\033[7m"}; static char curright[] = {"\033[%dC"}; static char curleft[] = {"\033[%dD"}; static char curdown[] = {"\033[%dB"}; static char curup[] = {"\033[%dA"}; static char curpos[] = {"\033[%d;%dH"}; static char erasedisp[] = {"\033[2J"}; #endif #ifdef HPUX_SEQUENCES static char bold[] = {"\033&dH"}; static char normal[] = {"\033&d@"}; static char blink[] = {"\033&dA"}; static char reverse[] = {"\033&dK"}; static char underline[] = {"\033&dD"}; static char curfor[] = {"\033&a+%dC"}; static char curback[] = {"\033&a-%dC"}; static char curdown[] = {"\033&a+%dR"}; static char curup[] = {"\033&a-%dR"}; static char curpos[] = {"\033&a%dx%dY"}; static char erasedisp[] = {"\033J"}; #endif Listing Two /*************************************************** FILE NAME : scrlibs.c AUTHOR : Matt Weisfeld DESCRIPTION : screen handling libraries ***************************************************/ #include #include "scrlibs.h" void do_bold(stream) FILE *stream; { fprintf (stream, bold); fflush(stream); return; } void do_normal(stream) FILE *stream; { fprintf (stream, normal); fflush(stream); return; } void do_blink(stream) FILE *stream; { fprintf (stream, blink); fflush(stdout); return; } void do_reverse(stream) FILE *stream; { fprintf (stream, reverse); fflush(stdout); return; } void cursor_right(move) int move; { int i; printf (curright, move); fflush(stdout); return; } void cursor_left(move) int move; { int i; printf (curleft, move); fflush(stdout); return; } void cursor_down(move) int move; { int i; printf (curdown, move); fflush(stdout); return; } void cursor_up(move) int move; { int i; printf (curup, move); fflush(stdout); return; } void cursor_pos(row,col) int row,col; { #ifdef HPUX printf (curpos, col,row); #else printf (curpos, row,col); #endif fflush(stdout); return; } void cursor_home() { cursor_pos(0,0); fflush(stdout); return; } void cursor_bottom() { cursor_pos(23,0); fflush(stdout); return; } void erase_display() { int i; cursor_home(); printf (erasedisp); fflush(stdout); return; } Listing Three /*************************************************** FILE NAME : test.c AUTHOR : Matt Weisfeld DESCRIPTION : test file for screen libraries ***************************************************/ #include #include "scrlibs.h" #ifdef DOS #include #endif main() { erase_display(); do_bold(stdout); printf ("bold video\n"); do_normal(stdout); do_reverse(stdout); printf ("reverse video\n"); do_normal(stdout); do_blink(stdout); printf ("blink video\n"); do_normal(stdout); printf ("normal video\n"); printf ("\n"); cursor_right(20); printf ("Right"); cursor_left(10); printf ("Left"); cursor_down(10); printf ("Down"); cursor_up(5); printf ("Up"); cursor_bottom(); return; } ursor_down(10); printf ("Down"); cursor_up(5); printf ("Up"); Figure 1: static char normal[] = {"\033[0m"}; static char bold[] = {"\033[1m"}; static char blink[] = {"\033[5m"}; Figure 2: static char bold[] = {"\033&dH"}; static char reverse[] = {"\033&dK"}; static char underline[] = {"\033&dD"}; static char blink[] = {"\033&dA"}; static char normal[] = {"\033&d@"}; Example 1: (a) printf ("this is not bold\n"); do_bold(stdout); printf ("this is bold\n"); do_normal(stdout) printf ("this is not bold again\n"); (b) void do_bold(stream) FILE *stream; { fprintf (stream, bold); fflush(stream); return; } Example 2: (a) static char curpos[] = {"\033[%d;%dH"}; static char erasedisp[] = {"\033[J"}; (b) static char curpos[] = {"\033&a%dx%dY"}; static char erasedisp[] = {"\033J"}; Example 3: (a) void cursor_pos(row,col) int row, col; #ifdef HPUX printf (curpos, col,row); #else printf (curpos, row,col); #endif fflush(stdout); return; } (b) void cursor_home() { cursor_pos(0,0); fflush(stdout); return; } (c) void erase_display() { cursor_home(); printf (clear); fflush(stdout); return; } Example 4: (a) static char curfor[] = {"\033[%dC"}; static char curback[] = {"\033[%dD"}; static char curdown[] = {"\033[%dB"}; static char curup[] = {"\033[%dA"}; (b) static char curfor[] = {"\033&a+%dC"}; static char curback[] = {"\033&a-%dC"}; static char cursedown[] = {"\033&a+%dR"}; static char curseup[] = {"\033&a-%dR"}; (c) void cursor_up(move) int move; { int i; printf (curup, move); fflush(stdout); return; }