Changeset View
Changeset View
Standalone View
Standalone View
head/contrib/less/screen.c
Show First 20 Lines • Show All 199 Lines • ▼ Show 20 Lines | |||||
public int can_goto_line; /* Can move cursor to any line */ | public int can_goto_line; /* Can move cursor to any line */ | ||||
public int clear_bg; /* Clear fills with background color */ | public int clear_bg; /* Clear fills with background color */ | ||||
public int missing_cap = 0; /* Some capability is missing */ | public int missing_cap = 0; /* Some capability is missing */ | ||||
static int attrmode = AT_NORMAL; | static int attrmode = AT_NORMAL; | ||||
extern int binattr; | extern int binattr; | ||||
#if !MSDOS_COMPILER | #if !MSDOS_COMPILER | ||||
static char *cheaper(); | static char *cheaper(char *t1, char *t2, char *def); | ||||
static void tmodes(); | static void tmodes(char *incap, char *outcap, char **instr, char **outstr, | ||||
char *def_instr, char *def_outstr, char **spp); | |||||
#endif | #endif | ||||
/* | /* | ||||
* These two variables are sometimes defined in, | * These two variables are sometimes defined in, | ||||
* and needed by, the termcap library. | * and needed by, the termcap library. | ||||
*/ | */ | ||||
#if MUST_DEFINE_OSPEED | #if MUST_DEFINE_OSPEED | ||||
extern short ospeed; /* Terminal output baud rate */ | extern short ospeed; /* Terminal output baud rate */ | ||||
Show All 30 Lines | |||||
* 2. Input is not echoed. | * 2. Input is not echoed. | ||||
* 3. On output, \n is mapped to \r\n. | * 3. On output, \n is mapped to \r\n. | ||||
* 4. \t is NOT expanded into spaces. | * 4. \t is NOT expanded into spaces. | ||||
* 5. Signal-causing characters such as ctrl-C (interrupt), | * 5. Signal-causing characters such as ctrl-C (interrupt), | ||||
* etc. are NOT disabled. | * etc. are NOT disabled. | ||||
* It doesn't matter whether an input \n is mapped to \r, or vice versa. | * It doesn't matter whether an input \n is mapped to \r, or vice versa. | ||||
*/ | */ | ||||
public void | public void | ||||
raw_mode(on) | raw_mode(int on) | ||||
int on; | |||||
{ | { | ||||
static int curr_on = 0; | static int curr_on = 0; | ||||
if (on == curr_on) | if (on == curr_on) | ||||
return; | return; | ||||
erase2_char = '\b'; /* in case OS doesn't know about erase2 */ | erase2_char = '\b'; /* in case OS doesn't know about erase2 */ | ||||
#if HAVE_TERMIOS_H && HAVE_TERMIOS_FUNCS | #if HAVE_TERMIOS_H && HAVE_TERMIOS_FUNCS | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 347 Lines • ▼ Show 20 Lines | |||||
#if !MSDOS_COMPILER | #if !MSDOS_COMPILER | ||||
/* | /* | ||||
* Some glue to prevent calling termcap functions if tgetent() failed. | * Some glue to prevent calling termcap functions if tgetent() failed. | ||||
*/ | */ | ||||
static int hardcopy; | static int hardcopy; | ||||
static char * | static char * | ||||
ltget_env(capname) | ltget_env(char *capname) | ||||
char *capname; | |||||
{ | { | ||||
char name[16]; | char name[16]; | ||||
char *s; | char *s; | ||||
s = lgetenv("LESS_TERMCAP_DEBUG"); | s = lgetenv("LESS_TERMCAP_DEBUG"); | ||||
if (s != NULL && *s != '\0') | if (s != NULL && *s != '\0') | ||||
{ | { | ||||
struct env { struct env *next; char *name; char *value; }; | struct env { struct env *next; char *name; char *value; }; | ||||
Show All 11 Lines | if (s != NULL && *s != '\0') | ||||
return p->value; | return p->value; | ||||
} | } | ||||
strcpy(name, "LESS_TERMCAP_"); | strcpy(name, "LESS_TERMCAP_"); | ||||
strcat(name, capname); | strcat(name, capname); | ||||
return (lgetenv(name)); | return (lgetenv(name)); | ||||
} | } | ||||
static int | static int | ||||
ltgetflag(capname) | ltgetflag(char *capname) | ||||
char *capname; | |||||
{ | { | ||||
char *s; | char *s; | ||||
if ((s = ltget_env(capname)) != NULL) | if ((s = ltget_env(capname)) != NULL) | ||||
return (*s != '\0' && *s != '0'); | return (*s != '\0' && *s != '0'); | ||||
if (hardcopy) | if (hardcopy) | ||||
return (0); | return (0); | ||||
return (tgetflag(capname)); | return (tgetflag(capname)); | ||||
} | } | ||||
static int | static int | ||||
ltgetnum(capname) | ltgetnum(char *capname) | ||||
char *capname; | |||||
{ | { | ||||
char *s; | char *s; | ||||
if ((s = ltget_env(capname)) != NULL) | if ((s = ltget_env(capname)) != NULL) | ||||
return (atoi(s)); | return (atoi(s)); | ||||
if (hardcopy) | if (hardcopy) | ||||
return (-1); | return (-1); | ||||
return (tgetnum(capname)); | return (tgetnum(capname)); | ||||
} | } | ||||
static char * | static char * | ||||
ltgetstr(capname, pp) | ltgetstr(char *capname, char **pp) | ||||
char *capname; | |||||
char **pp; | |||||
{ | { | ||||
char *s; | char *s; | ||||
if ((s = ltget_env(capname)) != NULL) | if ((s = ltget_env(capname)) != NULL) | ||||
return (s); | return (s); | ||||
if (hardcopy) | if (hardcopy) | ||||
return (NULL); | return (NULL); | ||||
return (tgetstr(capname, pp)); | return (tgetstr(capname, pp)); | ||||
} | } | ||||
#endif /* MSDOS_COMPILER */ | #endif /* MSDOS_COMPILER */ | ||||
/* | /* | ||||
* Get size of the output screen. | * Get size of the output screen. | ||||
*/ | */ | ||||
public void | public void | ||||
scrsize() | scrsize(void) | ||||
{ | { | ||||
register char *s; | char *s; | ||||
int sys_height; | int sys_height; | ||||
int sys_width; | int sys_width; | ||||
#if !MSDOS_COMPILER | #if !MSDOS_COMPILER | ||||
int n; | int n; | ||||
#endif | #endif | ||||
#define DEF_SC_WIDTH 80 | #define DEF_SC_WIDTH 80 | ||||
#if MSDOS_COMPILER | #if MSDOS_COMPILER | ||||
▲ Show 20 Lines • Show All 111 Lines • ▼ Show 20 Lines | if (sc_width <= 0) | ||||
sc_width = DEF_SC_WIDTH; | sc_width = DEF_SC_WIDTH; | ||||
} | } | ||||
#if MSDOS_COMPILER==MSOFTC | #if MSDOS_COMPILER==MSOFTC | ||||
/* | /* | ||||
* Figure out how many empty loops it takes to delay a millisecond. | * Figure out how many empty loops it takes to delay a millisecond. | ||||
*/ | */ | ||||
static void | static void | ||||
get_clock() | get_clock(void) | ||||
{ | { | ||||
clock_t start; | clock_t start; | ||||
/* | /* | ||||
* Get synchronized at the start of a tick. | * Get synchronized at the start of a tick. | ||||
*/ | */ | ||||
start = clock(); | start = clock(); | ||||
while (clock() == start) | while (clock() == start) | ||||
Show All 11 Lines | get_clock(void) | ||||
msec_loops *= CLOCKS_PER_SEC; | msec_loops *= CLOCKS_PER_SEC; | ||||
msec_loops /= 1000; | msec_loops /= 1000; | ||||
} | } | ||||
/* | /* | ||||
* Delay for a specified number of milliseconds. | * Delay for a specified number of milliseconds. | ||||
*/ | */ | ||||
static void | static void | ||||
dummy_func() | dummy_func(void) | ||||
{ | { | ||||
static long delay_dummy = 0; | static long delay_dummy = 0; | ||||
delay_dummy++; | delay_dummy++; | ||||
} | } | ||||
static void | static void | ||||
delay(msec) | delay(int msec) | ||||
int msec; | |||||
{ | { | ||||
long i; | long i; | ||||
while (msec-- > 0) | while (msec-- > 0) | ||||
{ | { | ||||
for (i = 0; i < msec_loops; i++) | for (i = 0; i < msec_loops; i++) | ||||
{ | { | ||||
/* | /* | ||||
* Make it look like we're doing something here, | * Make it look like we're doing something here, | ||||
* so the optimizer doesn't remove the whole loop. | * so the optimizer doesn't remove the whole loop. | ||||
*/ | */ | ||||
dummy_func(); | dummy_func(); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
#endif | #endif | ||||
/* | /* | ||||
* Return the characters actually input by a "special" key. | * Return the characters actually input by a "special" key. | ||||
*/ | */ | ||||
public char * | public char * | ||||
special_key_str(key) | special_key_str(int key) | ||||
int key; | |||||
{ | { | ||||
static char tbuf[40]; | static char tbuf[40]; | ||||
char *s; | char *s; | ||||
#if MSDOS_COMPILER || OS2 | #if MSDOS_COMPILER || OS2 | ||||
static char k_right[] = { '\340', PCK_RIGHT, 0 }; | static char k_right[] = { '\340', PCK_RIGHT, 0 }; | ||||
static char k_left[] = { '\340', PCK_LEFT, 0 }; | static char k_left[] = { '\340', PCK_LEFT, 0 }; | ||||
static char k_ctl_right[] = { '\340', PCK_CTL_RIGHT, 0 }; | static char k_ctl_right[] = { '\340', PCK_CTL_RIGHT, 0 }; | ||||
static char k_ctl_left[] = { '\340', PCK_CTL_LEFT, 0 }; | static char k_ctl_left[] = { '\340', PCK_CTL_LEFT, 0 }; | ||||
▲ Show 20 Lines • Show All 155 Lines • ▼ Show 20 Lines | #endif | ||||
} | } | ||||
return (s); | return (s); | ||||
} | } | ||||
/* | /* | ||||
* Get terminal capabilities via termcap. | * Get terminal capabilities via termcap. | ||||
*/ | */ | ||||
public void | public void | ||||
get_term() | get_term(void) | ||||
{ | { | ||||
#if MSDOS_COMPILER | #if MSDOS_COMPILER | ||||
auto_wrap = 1; | auto_wrap = 1; | ||||
ignaw = 0; | ignaw = 0; | ||||
can_goto_line = 1; | can_goto_line = 1; | ||||
clear_bg = 1; | clear_bg = 1; | ||||
/* | /* | ||||
* Set up default colors. | * Set up default colors. | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | #endif | ||||
*/ | */ | ||||
scrsize(); | scrsize(); | ||||
pos_init(); | pos_init(); | ||||
#else /* !MSDOS_COMPILER */ | #else /* !MSDOS_COMPILER */ | ||||
char *sp; | char *sp; | ||||
register char *t1, *t2; | char *t1, *t2; | ||||
char *term; | char *term; | ||||
char termbuf[TERMBUF_SIZE]; | char termbuf[TERMBUF_SIZE]; | ||||
static char sbuf[TERMSBUF_SIZE]; | static char sbuf[TERMSBUF_SIZE]; | ||||
#if OS2 | #if OS2 | ||||
/* | /* | ||||
* Make sure the termcap database is available. | * Make sure the termcap database is available. | ||||
▲ Show 20 Lines • Show All 215 Lines • ▼ Show 20 Lines | |||||
* we give it inc_costcount, which just increments "costcount". | * we give it inc_costcount, which just increments "costcount". | ||||
* This tells us how many chars would be printed by using this string. | * This tells us how many chars would be printed by using this string. | ||||
* {{ Couldn't we just use strlen? }} | * {{ Couldn't we just use strlen? }} | ||||
*/ | */ | ||||
static int costcount; | static int costcount; | ||||
/*ARGSUSED*/ | /*ARGSUSED*/ | ||||
static int | static int | ||||
inc_costcount(c) | inc_costcount(int c) | ||||
int c; | |||||
{ | { | ||||
costcount++; | costcount++; | ||||
return (c); | return (c); | ||||
} | } | ||||
static int | static int | ||||
cost(t) | cost(char *t) | ||||
char *t; | |||||
{ | { | ||||
costcount = 0; | costcount = 0; | ||||
tputs(t, sc_height, inc_costcount); | tputs(t, sc_height, inc_costcount); | ||||
return (costcount); | return (costcount); | ||||
} | } | ||||
/* | /* | ||||
* Return the "best" of the two given termcap strings. | * Return the "best" of the two given termcap strings. | ||||
* The best, if both exist, is the one with the lower | * The best, if both exist, is the one with the lower | ||||
* cost (see cost() function). | * cost (see cost() function). | ||||
*/ | */ | ||||
static char * | static char * | ||||
cheaper(t1, t2, def) | cheaper(char *t1, char *t2, char *def) | ||||
char *t1, *t2; | |||||
char *def; | |||||
{ | { | ||||
if (*t1 == '\0' && *t2 == '\0') | if (*t1 == '\0' && *t2 == '\0') | ||||
{ | { | ||||
missing_cap = 1; | missing_cap = 1; | ||||
return (def); | return (def); | ||||
} | } | ||||
if (*t1 == '\0') | if (*t1 == '\0') | ||||
return (t2); | return (t2); | ||||
if (*t2 == '\0') | if (*t2 == '\0') | ||||
return (t1); | return (t1); | ||||
if (cost(t1) < cost(t2)) | if (cost(t1) < cost(t2)) | ||||
return (t1); | return (t1); | ||||
return (t2); | return (t2); | ||||
} | } | ||||
static void | static void | ||||
tmodes(incap, outcap, instr, outstr, def_instr, def_outstr, spp) | tmodes(char *incap, char *outcap, char **instr, char **outstr, char *def_instr, | ||||
char *incap; | char *def_outstr, char **spp) | ||||
char *outcap; | |||||
char **instr; | |||||
char **outstr; | |||||
char *def_instr; | |||||
char *def_outstr; | |||||
char **spp; | |||||
{ | { | ||||
*instr = ltgetstr(incap, spp); | *instr = ltgetstr(incap, spp); | ||||
if (*instr == NULL) | if (*instr == NULL) | ||||
{ | { | ||||
/* Use defaults. */ | /* Use defaults. */ | ||||
*instr = def_instr; | *instr = def_instr; | ||||
*outstr = def_outstr; | *outstr = def_outstr; | ||||
return; | return; | ||||
Show All 32 Lines | _settextposition(int row, int col) | ||||
SetConsoleCursorPosition(con_out, cpos); | SetConsoleCursorPosition(con_out, cpos); | ||||
} | } | ||||
#endif | #endif | ||||
/* | /* | ||||
* Initialize the screen to the correct color at startup. | * Initialize the screen to the correct color at startup. | ||||
*/ | */ | ||||
static void | static void | ||||
initcolor() | initcolor(void) | ||||
{ | { | ||||
SETCOLORS(nm_fg_color, nm_bg_color); | SETCOLORS(nm_fg_color, nm_bg_color); | ||||
#if 0 | #if 0 | ||||
/* | /* | ||||
* This clears the screen at startup. This is different from | * This clears the screen at startup. This is different from | ||||
* the behavior of other versions of less. Disable it for now. | * the behavior of other versions of less. Disable it for now. | ||||
*/ | */ | ||||
char *blanks; | char *blanks; | ||||
Show All 16 Lines | |||||
#endif | #endif | ||||
#if MSDOS_COMPILER==WIN32C | #if MSDOS_COMPILER==WIN32C | ||||
/* | /* | ||||
* Termcap-like init with a private win32 console. | * Termcap-like init with a private win32 console. | ||||
*/ | */ | ||||
static void | static void | ||||
win32_init_term() | win32_init_term(void) | ||||
{ | { | ||||
CONSOLE_SCREEN_BUFFER_INFO scr; | CONSOLE_SCREEN_BUFFER_INFO scr; | ||||
COORD size; | COORD size; | ||||
if (con_out_save == INVALID_HANDLE_VALUE) | if (con_out_save == INVALID_HANDLE_VALUE) | ||||
return; | return; | ||||
GetConsoleScreenBufferInfo(con_out_save, &scr); | GetConsoleScreenBufferInfo(con_out_save, &scr); | ||||
Show All 34 Lines | |||||
} | } | ||||
#endif | #endif | ||||
/* | /* | ||||
* Initialize terminal | * Initialize terminal | ||||
*/ | */ | ||||
public void | public void | ||||
init() | init(void) | ||||
{ | { | ||||
#if !MSDOS_COMPILER | #if !MSDOS_COMPILER | ||||
if (!no_init) | if (!no_init) | ||||
tputs(sc_init, sc_height, putchr); | tputs(sc_init, sc_height, putchr); | ||||
if (!no_keypad) | if (!no_keypad) | ||||
tputs(sc_s_keypad, sc_height, putchr); | tputs(sc_s_keypad, sc_height, putchr); | ||||
if (top_scroll) | if (top_scroll) | ||||
{ | { | ||||
Show All 19 Lines | |||||
#endif | #endif | ||||
init_done = 1; | init_done = 1; | ||||
} | } | ||||
/* | /* | ||||
* Deinitialize terminal | * Deinitialize terminal | ||||
*/ | */ | ||||
public void | public void | ||||
deinit() | deinit(void) | ||||
{ | { | ||||
if (!init_done) | if (!init_done) | ||||
return; | return; | ||||
#if !MSDOS_COMPILER | #if !MSDOS_COMPILER | ||||
if (!no_keypad) | if (!no_keypad) | ||||
tputs(sc_e_keypad, sc_height, putchr); | tputs(sc_e_keypad, sc_height, putchr); | ||||
if (!no_init) | if (!no_init) | ||||
tputs(sc_deinit, sc_height, putchr); | tputs(sc_deinit, sc_height, putchr); | ||||
Show All 10 Lines | |||||
#endif | #endif | ||||
init_done = 0; | init_done = 0; | ||||
} | } | ||||
/* | /* | ||||
* Home cursor (move to upper left corner of screen). | * Home cursor (move to upper left corner of screen). | ||||
*/ | */ | ||||
public void | public void | ||||
home() | home(void) | ||||
{ | { | ||||
#if !MSDOS_COMPILER | #if !MSDOS_COMPILER | ||||
tputs(sc_home, 1, putchr); | tputs(sc_home, 1, putchr); | ||||
#else | #else | ||||
flush(); | flush(); | ||||
_settextposition(1,1); | _settextposition(1,1); | ||||
#endif | #endif | ||||
} | } | ||||
/* | /* | ||||
* Add a blank line (called with cursor at home). | * Add a blank line (called with cursor at home). | ||||
* Should scroll the display down. | * Should scroll the display down. | ||||
*/ | */ | ||||
public void | public void | ||||
add_line() | add_line(void) | ||||
{ | { | ||||
#if !MSDOS_COMPILER | #if !MSDOS_COMPILER | ||||
tputs(sc_addline, sc_height, putchr); | tputs(sc_addline, sc_height, putchr); | ||||
#else | #else | ||||
flush(); | flush(); | ||||
#if MSDOS_COMPILER==MSOFTC | #if MSDOS_COMPILER==MSOFTC | ||||
_scrolltextwindow(_GSCROLLDOWN); | _scrolltextwindow(_GSCROLLDOWN); | ||||
_settextposition(1,1); | _settextposition(1,1); | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | |||||
#if 0 | #if 0 | ||||
/* | /* | ||||
* Remove the n topmost lines and scroll everything below it in the | * Remove the n topmost lines and scroll everything below it in the | ||||
* window upward. This is needed to stop leaking the topmost line | * window upward. This is needed to stop leaking the topmost line | ||||
* into the scrollback buffer when we go down-one-line (in WIN32). | * into the scrollback buffer when we go down-one-line (in WIN32). | ||||
*/ | */ | ||||
public void | public void | ||||
remove_top(n) | remove_top(int n) | ||||
int n; | |||||
{ | { | ||||
#if MSDOS_COMPILER==WIN32C | #if MSDOS_COMPILER==WIN32C | ||||
SMALL_RECT rcSrc, rcClip; | SMALL_RECT rcSrc, rcClip; | ||||
CHAR_INFO fillchar; | CHAR_INFO fillchar; | ||||
COORD new_org; | COORD new_org; | ||||
CONSOLE_SCREEN_BUFFER_INFO csbi; /* to get buffer info */ | CONSOLE_SCREEN_BUFFER_INFO csbi; /* to get buffer info */ | ||||
if (n >= sc_height - 1) | if (n >= sc_height - 1) | ||||
Show All 36 Lines | |||||
} | } | ||||
#endif | #endif | ||||
#if MSDOS_COMPILER==WIN32C | #if MSDOS_COMPILER==WIN32C | ||||
/* | /* | ||||
* Clear the screen. | * Clear the screen. | ||||
*/ | */ | ||||
static void | static void | ||||
win32_clear() | win32_clear(void) | ||||
{ | { | ||||
/* | /* | ||||
* This will clear only the currently visible rows of the NT | * This will clear only the currently visible rows of the NT | ||||
* console buffer, which means none of the precious scrollback | * console buffer, which means none of the precious scrollback | ||||
* rows are touched making for faster scrolling. Note that, if | * rows are touched making for faster scrolling. Note that, if | ||||
* the window has fewer columns than the console buffer (i.e. | * the window has fewer columns than the console buffer (i.e. | ||||
* there is a horizontal scrollbar as well), the entire width | * there is a horizontal scrollbar as well), the entire width | ||||
* of the visible rows will be cleared. | * of the visible rows will be cleared. | ||||
Show All 14 Lines | win32_clear(void) | ||||
FillConsoleOutputAttribute(con_out, curr_attr, winsz, topleft, &nchars); | FillConsoleOutputAttribute(con_out, curr_attr, winsz, topleft, &nchars); | ||||
} | } | ||||
/* | /* | ||||
* Remove the n topmost lines and scroll everything below it in the | * Remove the n topmost lines and scroll everything below it in the | ||||
* window upward. | * window upward. | ||||
*/ | */ | ||||
public void | public void | ||||
win32_scroll_up(n) | win32_scroll_up(int n) | ||||
int n; | |||||
{ | { | ||||
SMALL_RECT rcSrc, rcClip; | SMALL_RECT rcSrc, rcClip; | ||||
CHAR_INFO fillchar; | CHAR_INFO fillchar; | ||||
COORD topleft; | COORD topleft; | ||||
COORD new_org; | COORD new_org; | ||||
DWORD nchars; | DWORD nchars; | ||||
DWORD size; | DWORD size; | ||||
CONSOLE_SCREEN_BUFFER_INFO csbi; | CONSOLE_SCREEN_BUFFER_INFO csbi; | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | win32_scroll_up(int n) | ||||
SetConsoleCursorPosition(con_out, csbi.dwCursorPosition); | SetConsoleCursorPosition(con_out, csbi.dwCursorPosition); | ||||
} | } | ||||
#endif | #endif | ||||
/* | /* | ||||
* Move cursor to lower left corner of screen. | * Move cursor to lower left corner of screen. | ||||
*/ | */ | ||||
public void | public void | ||||
lower_left() | lower_left(void) | ||||
{ | { | ||||
#if !MSDOS_COMPILER | #if !MSDOS_COMPILER | ||||
tputs(sc_lower_left, 1, putchr); | tputs(sc_lower_left, 1, putchr); | ||||
#else | #else | ||||
flush(); | flush(); | ||||
_settextposition(sc_height, 1); | _settextposition(sc_height, 1); | ||||
#endif | #endif | ||||
} | } | ||||
/* | /* | ||||
* Move cursor to left position of current line. | * Move cursor to left position of current line. | ||||
*/ | */ | ||||
public void | public void | ||||
line_left() | line_left(void) | ||||
{ | { | ||||
#if !MSDOS_COMPILER | #if !MSDOS_COMPILER | ||||
tputs(sc_return, 1, putchr); | tputs(sc_return, 1, putchr); | ||||
#else | #else | ||||
int row; | int row; | ||||
flush(); | flush(); | ||||
#if MSDOS_COMPILER==WIN32C | #if MSDOS_COMPILER==WIN32C | ||||
{ | { | ||||
Show All 15 Lines | |||||
#endif | #endif | ||||
} | } | ||||
/* | /* | ||||
* Check if the console size has changed and reset internals | * Check if the console size has changed and reset internals | ||||
* (in lieu of SIGWINCH for WIN32). | * (in lieu of SIGWINCH for WIN32). | ||||
*/ | */ | ||||
public void | public void | ||||
check_winch() | check_winch(void) | ||||
{ | { | ||||
#if MSDOS_COMPILER==WIN32C | #if MSDOS_COMPILER==WIN32C | ||||
CONSOLE_SCREEN_BUFFER_INFO scr; | CONSOLE_SCREEN_BUFFER_INFO scr; | ||||
COORD size; | COORD size; | ||||
if (con_out == INVALID_HANDLE_VALUE) | if (con_out == INVALID_HANDLE_VALUE) | ||||
return; | return; | ||||
Show All 13 Lines | #if MSDOS_COMPILER==WIN32C | ||||
} | } | ||||
#endif | #endif | ||||
} | } | ||||
/* | /* | ||||
* Goto a specific line on the screen. | * Goto a specific line on the screen. | ||||
*/ | */ | ||||
public void | public void | ||||
goto_line(slinenum) | goto_line(int slinenum) | ||||
int slinenum; | |||||
{ | { | ||||
#if !MSDOS_COMPILER | #if !MSDOS_COMPILER | ||||
tputs(tgoto(sc_move, 0, slinenum), 1, putchr); | tputs(tgoto(sc_move, 0, slinenum), 1, putchr); | ||||
#else | #else | ||||
flush(); | flush(); | ||||
_settextposition(slinenum+1, 1); | _settextposition(slinenum+1, 1); | ||||
#endif | #endif | ||||
} | } | ||||
#if MSDOS_COMPILER==MSOFTC || MSDOS_COMPILER==BORLANDC | #if MSDOS_COMPILER==MSOFTC || MSDOS_COMPILER==BORLANDC | ||||
/* | /* | ||||
* Create an alternate screen which is all white. | * Create an alternate screen which is all white. | ||||
* This screen is used to create a "flash" effect, by displaying it | * This screen is used to create a "flash" effect, by displaying it | ||||
* briefly and then switching back to the normal screen. | * briefly and then switching back to the normal screen. | ||||
* {{ Yuck! There must be a better way to get a visual bell. }} | * {{ Yuck! There must be a better way to get a visual bell. }} | ||||
*/ | */ | ||||
static void | static void | ||||
create_flash() | create_flash(void) | ||||
{ | { | ||||
#if MSDOS_COMPILER==MSOFTC | #if MSDOS_COMPILER==MSOFTC | ||||
struct videoconfig w; | struct videoconfig w; | ||||
char *blanks; | char *blanks; | ||||
int row, col; | int row, col; | ||||
_getvideoconfig(&w); | _getvideoconfig(&w); | ||||
videopages = w.numvideopages; | videopages = w.numvideopages; | ||||
Show All 12 Lines | for (row = w.numtextrows; row > 0; row--) | ||||
_outmem(blanks, w.numtextcols); | _outmem(blanks, w.numtextcols); | ||||
_setactivepage(0); | _setactivepage(0); | ||||
_setvisualpage(0); | _setvisualpage(0); | ||||
free(blanks); | free(blanks); | ||||
at_exit(); | at_exit(); | ||||
} | } | ||||
#else | #else | ||||
#if MSDOS_COMPILER==BORLANDC | #if MSDOS_COMPILER==BORLANDC | ||||
register int n; | int n; | ||||
whitescreen = (unsigned short *) | whitescreen = (unsigned short *) | ||||
malloc(sc_width * sc_height * sizeof(short)); | malloc(sc_width * sc_height * sizeof(short)); | ||||
if (whitescreen == NULL) | if (whitescreen == NULL) | ||||
return; | return; | ||||
for (n = 0; n < sc_width * sc_height; n++) | for (n = 0; n < sc_width * sc_height; n++) | ||||
whitescreen[n] = 0x7020; | whitescreen[n] = 0x7020; | ||||
#else | #else | ||||
#if MSDOS_COMPILER==WIN32C | #if MSDOS_COMPILER==WIN32C | ||||
register int n; | int n; | ||||
whitescreen = (WORD *) | whitescreen = (WORD *) | ||||
malloc(sc_height * sc_width * sizeof(WORD)); | malloc(sc_height * sc_width * sizeof(WORD)); | ||||
if (whitescreen == NULL) | if (whitescreen == NULL) | ||||
return; | return; | ||||
/* Invert the standard colors. */ | /* Invert the standard colors. */ | ||||
for (n = 0; n < sc_width * sc_height; n++) | for (n = 0; n < sc_width * sc_height; n++) | ||||
whitescreen[n] = (WORD)((nm_fg_color << 4) | nm_bg_color); | whitescreen[n] = (WORD)((nm_fg_color << 4) | nm_bg_color); | ||||
#endif | #endif | ||||
#endif | #endif | ||||
#endif | #endif | ||||
flash_created = 1; | flash_created = 1; | ||||
} | } | ||||
#endif /* MSDOS_COMPILER */ | #endif /* MSDOS_COMPILER */ | ||||
/* | /* | ||||
* Output the "visual bell", if there is one. | * Output the "visual bell", if there is one. | ||||
*/ | */ | ||||
public void | public void | ||||
vbell() | vbell(void) | ||||
{ | { | ||||
#if !MSDOS_COMPILER | #if !MSDOS_COMPILER | ||||
if (*sc_visual_bell == '\0') | if (*sc_visual_bell == '\0') | ||||
return; | return; | ||||
tputs(sc_visual_bell, sc_height, putchr); | tputs(sc_visual_bell, sc_height, putchr); | ||||
#else | #else | ||||
#if MSDOS_COMPILER==DJGPPC | #if MSDOS_COMPILER==DJGPPC | ||||
ScreenVisualBell(); | ScreenVisualBell(); | ||||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | |||||
#endif | #endif | ||||
#endif | #endif | ||||
} | } | ||||
/* | /* | ||||
* Make a noise. | * Make a noise. | ||||
*/ | */ | ||||
static void | static void | ||||
beep() | beep(void) | ||||
{ | { | ||||
#if !MSDOS_COMPILER | #if !MSDOS_COMPILER | ||||
putchr(CONTROL('G')); | putchr(CONTROL('G')); | ||||
#else | #else | ||||
#if MSDOS_COMPILER==WIN32C | #if MSDOS_COMPILER==WIN32C | ||||
MessageBeep(0); | MessageBeep(0); | ||||
#else | #else | ||||
write(1, "\7", 1); | write(1, "\7", 1); | ||||
#endif | #endif | ||||
#endif | #endif | ||||
} | } | ||||
/* | /* | ||||
* Ring the terminal bell. | * Ring the terminal bell. | ||||
*/ | */ | ||||
public void | public void | ||||
bell() | bell(void) | ||||
{ | { | ||||
if (quiet == VERY_QUIET) | if (quiet == VERY_QUIET) | ||||
vbell(); | vbell(); | ||||
else | else | ||||
beep(); | beep(); | ||||
} | } | ||||
/* | /* | ||||
* Clear the screen. | * Clear the screen. | ||||
*/ | */ | ||||
public void | public void | ||||
clear() | clear(void) | ||||
{ | { | ||||
#if !MSDOS_COMPILER | #if !MSDOS_COMPILER | ||||
tputs(sc_clear, sc_height, putchr); | tputs(sc_clear, sc_height, putchr); | ||||
#else | #else | ||||
flush(); | flush(); | ||||
#if MSDOS_COMPILER==WIN32C | #if MSDOS_COMPILER==WIN32C | ||||
win32_clear(); | win32_clear(); | ||||
#else | #else | ||||
_clearscreen(_GCLEARSCREEN); | _clearscreen(_GCLEARSCREEN); | ||||
#endif | #endif | ||||
#endif | #endif | ||||
} | } | ||||
/* | /* | ||||
* Clear from the cursor to the end of the cursor's line. | * Clear from the cursor to the end of the cursor's line. | ||||
* {{ This must not move the cursor. }} | * {{ This must not move the cursor. }} | ||||
*/ | */ | ||||
public void | public void | ||||
clear_eol() | clear_eol(void) | ||||
{ | { | ||||
#if !MSDOS_COMPILER | #if !MSDOS_COMPILER | ||||
tputs(sc_eol_clear, 1, putchr); | tputs(sc_eol_clear, 1, putchr); | ||||
#else | #else | ||||
#if MSDOS_COMPILER==MSOFTC | #if MSDOS_COMPILER==MSOFTC | ||||
short top, left; | short top, left; | ||||
short bot, right; | short bot, right; | ||||
struct rccoord tpos; | struct rccoord tpos; | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | |||||
#endif | #endif | ||||
} | } | ||||
/* | /* | ||||
* Clear the current line. | * Clear the current line. | ||||
* Clear the screen if there's off-screen memory below the display. | * Clear the screen if there's off-screen memory below the display. | ||||
*/ | */ | ||||
static void | static void | ||||
clear_eol_bot() | clear_eol_bot(void) | ||||
{ | { | ||||
#if MSDOS_COMPILER | #if MSDOS_COMPILER | ||||
clear_eol(); | clear_eol(); | ||||
#else | #else | ||||
if (below_mem) | if (below_mem) | ||||
tputs(sc_eos_clear, 1, putchr); | tputs(sc_eos_clear, 1, putchr); | ||||
else | else | ||||
tputs(sc_eol_clear, 1, putchr); | tputs(sc_eol_clear, 1, putchr); | ||||
#endif | #endif | ||||
} | } | ||||
/* | /* | ||||
* Clear the bottom line of the display. | * Clear the bottom line of the display. | ||||
* Leave the cursor at the beginning of the bottom line. | * Leave the cursor at the beginning of the bottom line. | ||||
*/ | */ | ||||
public void | public void | ||||
clear_bot() | clear_bot(void) | ||||
{ | { | ||||
/* | /* | ||||
* If we're in a non-normal attribute mode, temporarily exit | * If we're in a non-normal attribute mode, temporarily exit | ||||
* the mode while we do the clear. Some terminals fill the | * the mode while we do the clear. Some terminals fill the | ||||
* cleared area with the current attribute. | * cleared area with the current attribute. | ||||
*/ | */ | ||||
if (oldbot) | if (oldbot) | ||||
lower_left(); | lower_left(); | ||||
else | else | ||||
line_left(); | line_left(); | ||||
if (attrmode == AT_NORMAL) | if (attrmode == AT_NORMAL) | ||||
clear_eol_bot(); | clear_eol_bot(); | ||||
else | else | ||||
{ | { | ||||
int saved_attrmode = attrmode; | int saved_attrmode = attrmode; | ||||
at_exit(); | at_exit(); | ||||
clear_eol_bot(); | clear_eol_bot(); | ||||
at_enter(saved_attrmode); | at_enter(saved_attrmode); | ||||
} | } | ||||
} | } | ||||
public void | public void | ||||
at_enter(attr) | at_enter(int attr) | ||||
int attr; | |||||
{ | { | ||||
attr = apply_at_specials(attr); | attr = apply_at_specials(attr); | ||||
#if !MSDOS_COMPILER | #if !MSDOS_COMPILER | ||||
/* The one with the most priority is last. */ | /* The one with the most priority is last. */ | ||||
if (attr & AT_UNDERLINE) | if (attr & AT_UNDERLINE) | ||||
tputs(sc_u_in, 1, putchr); | tputs(sc_u_in, 1, putchr); | ||||
if (attr & AT_BOLD) | if (attr & AT_BOLD) | ||||
Show All 21 Lines | else if (attr & AT_UNDERLINE) | ||||
SETCOLORS(ul_fg_color, ul_bg_color); | SETCOLORS(ul_fg_color, ul_bg_color); | ||||
} | } | ||||
#endif | #endif | ||||
attrmode = attr; | attrmode = attr; | ||||
} | } | ||||
public void | public void | ||||
at_exit() | at_exit(void) | ||||
{ | { | ||||
#if !MSDOS_COMPILER | #if !MSDOS_COMPILER | ||||
/* Undo things in the reverse order we did them. */ | /* Undo things in the reverse order we did them. */ | ||||
if (attrmode & AT_STANDOUT) | if (attrmode & AT_STANDOUT) | ||||
tputs(sc_s_out, 1, putchr); | tputs(sc_s_out, 1, putchr); | ||||
if (attrmode & AT_BLINK) | if (attrmode & AT_BLINK) | ||||
tputs(sc_bl_out, 1, putchr); | tputs(sc_bl_out, 1, putchr); | ||||
if (attrmode & AT_BOLD) | if (attrmode & AT_BOLD) | ||||
tputs(sc_b_out, 1, putchr); | tputs(sc_b_out, 1, putchr); | ||||
if (attrmode & AT_UNDERLINE) | if (attrmode & AT_UNDERLINE) | ||||
tputs(sc_u_out, 1, putchr); | tputs(sc_u_out, 1, putchr); | ||||
#else | #else | ||||
flush(); | flush(); | ||||
SETCOLORS(nm_fg_color, nm_bg_color); | SETCOLORS(nm_fg_color, nm_bg_color); | ||||
#endif | #endif | ||||
attrmode = AT_NORMAL; | attrmode = AT_NORMAL; | ||||
} | } | ||||
public void | public void | ||||
at_switch(attr) | at_switch(int attr) | ||||
int attr; | |||||
{ | { | ||||
int new_attrmode = apply_at_specials(attr); | int new_attrmode = apply_at_specials(attr); | ||||
int ignore_modes = AT_ANSI; | int ignore_modes = AT_ANSI; | ||||
if ((new_attrmode & ~ignore_modes) != (attrmode & ~ignore_modes)) | if ((new_attrmode & ~ignore_modes) != (attrmode & ~ignore_modes)) | ||||
{ | { | ||||
at_exit(); | at_exit(); | ||||
at_enter(attr); | at_enter(attr); | ||||
} | } | ||||
} | } | ||||
public int | public int | ||||
is_at_equiv(attr1, attr2) | is_at_equiv(int attr1, int attr2) | ||||
int attr1; | |||||
int attr2; | |||||
{ | { | ||||
attr1 = apply_at_specials(attr1); | attr1 = apply_at_specials(attr1); | ||||
attr2 = apply_at_specials(attr2); | attr2 = apply_at_specials(attr2); | ||||
return (attr1 == attr2); | return (attr1 == attr2); | ||||
} | } | ||||
public int | public int | ||||
apply_at_specials(attr) | apply_at_specials(int attr) | ||||
int attr; | |||||
{ | { | ||||
if (attr & AT_BINARY) | if (attr & AT_BINARY) | ||||
attr |= binattr; | attr |= binattr; | ||||
if (attr & AT_HILITE) | if (attr & AT_HILITE) | ||||
attr |= AT_STANDOUT; | attr |= AT_STANDOUT; | ||||
attr &= ~(AT_BINARY|AT_HILITE); | attr &= ~(AT_BINARY|AT_HILITE); | ||||
return attr; | return attr; | ||||
} | } | ||||
#if 0 /* No longer used */ | #if 0 /* No longer used */ | ||||
/* | /* | ||||
* Erase the character to the left of the cursor | * Erase the character to the left of the cursor | ||||
* and move the cursor left. | * and move the cursor left. | ||||
*/ | */ | ||||
public void | public void | ||||
backspace() | backspace(void) | ||||
{ | { | ||||
#if !MSDOS_COMPILER | #if !MSDOS_COMPILER | ||||
/* | /* | ||||
* Erase the previous character by overstriking with a space. | * Erase the previous character by overstriking with a space. | ||||
*/ | */ | ||||
tputs(sc_backspace, 1, putchr); | tputs(sc_backspace, 1, putchr); | ||||
putchr(' '); | putchr(' '); | ||||
tputs(sc_backspace, 1, putchr); | tputs(sc_backspace, 1, putchr); | ||||
Show All 32 Lines | |||||
#endif | #endif | ||||
} | } | ||||
#endif /* 0 */ | #endif /* 0 */ | ||||
/* | /* | ||||
* Output a plain backspace, without erasing the previous char. | * Output a plain backspace, without erasing the previous char. | ||||
*/ | */ | ||||
public void | public void | ||||
putbs() | putbs(void) | ||||
{ | { | ||||
#if !MSDOS_COMPILER | #if !MSDOS_COMPILER | ||||
tputs(sc_backspace, 1, putchr); | tputs(sc_backspace, 1, putchr); | ||||
#else | #else | ||||
int row, col; | int row, col; | ||||
flush(); | flush(); | ||||
{ | { | ||||
Show All 22 Lines | |||||
#endif /* MSDOS_COMPILER */ | #endif /* MSDOS_COMPILER */ | ||||
} | } | ||||
#if MSDOS_COMPILER==WIN32C | #if MSDOS_COMPILER==WIN32C | ||||
/* | /* | ||||
* Determine whether an input character is waiting to be read. | * Determine whether an input character is waiting to be read. | ||||
*/ | */ | ||||
static int | static int | ||||
win32_kbhit(tty) | win32_kbhit(HANDLE tty) | ||||
HANDLE tty; | |||||
{ | { | ||||
INPUT_RECORD ip; | INPUT_RECORD ip; | ||||
DWORD read; | DWORD read; | ||||
if (keyCount > 0) | if (keyCount > 0) | ||||
return (TRUE); | return (TRUE); | ||||
currentKey.ascii = 0; | currentKey.ascii = 0; | ||||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | win32_kbhit(HANDLE tty) | ||||
} | } | ||||
return (TRUE); | return (TRUE); | ||||
} | } | ||||
/* | /* | ||||
* Read a character from the keyboard. | * Read a character from the keyboard. | ||||
*/ | */ | ||||
public char | public char | ||||
WIN32getch(tty) | WIN32getch(int tty) | ||||
int tty; | |||||
{ | { | ||||
int ascii; | int ascii; | ||||
if (pending_scancode) | if (pending_scancode) | ||||
{ | { | ||||
pending_scancode = 0; | pending_scancode = 0; | ||||
return ((char)(currentKey.scan & 0x00FF)); | return ((char)(currentKey.scan & 0x00FF)); | ||||
} | } | ||||
Show All 16 Lines | WIN32getch(int tty) | ||||
return ((char)ascii); | return ((char)ascii); | ||||
} | } | ||||
#endif | #endif | ||||
#if MSDOS_COMPILER | #if MSDOS_COMPILER | ||||
/* | /* | ||||
*/ | */ | ||||
public void | public void | ||||
WIN32setcolors(fg, bg) | WIN32setcolors(int fg, int bg) | ||||
int fg; | |||||
int bg; | |||||
{ | { | ||||
SETCOLORS(fg, bg); | SETCOLORS(fg, bg); | ||||
} | } | ||||
/* | /* | ||||
*/ | */ | ||||
public void | public void | ||||
WIN32textout(text, len) | WIN32textout(char *text, int len) | ||||
char *text; | |||||
int len; | |||||
{ | { | ||||
#if MSDOS_COMPILER==WIN32C | #if MSDOS_COMPILER==WIN32C | ||||
DWORD written; | DWORD written; | ||||
WriteConsole(con_out, text, len, &written, NULL); | WriteConsole(con_out, text, len, &written, NULL); | ||||
#else | #else | ||||
char c = text[len]; | char c = text[len]; | ||||
text[len] = '\0'; | text[len] = '\0'; | ||||
cputs(text); | cputs(text); | ||||
text[len] = c; | text[len] = c; | ||||
#endif | #endif | ||||
} | } | ||||
#endif | #endif |