Changeset View
Changeset View
Standalone View
Standalone View
head/contrib/less/output.c
Show All 37 Lines | |||||
extern int so_fg_color, so_bg_color; | extern int so_fg_color, so_bg_color; | ||||
extern int bl_fg_color, bl_bg_color; | extern int bl_fg_color, bl_bg_color; | ||||
#endif | #endif | ||||
/* | /* | ||||
* Display the line which is in the line buffer. | * Display the line which is in the line buffer. | ||||
*/ | */ | ||||
public void | public void | ||||
put_line() | put_line(void) | ||||
{ | { | ||||
register int c; | int c; | ||||
register int i; | int i; | ||||
int a; | int a; | ||||
if (ABORT_SIGS()) | if (ABORT_SIGS()) | ||||
{ | { | ||||
/* | /* | ||||
* Don't output if a signal is pending. | * Don't output if a signal is pending. | ||||
*/ | */ | ||||
screen_trashed = 1; | screen_trashed = 1; | ||||
Show All 30 Lines | |||||
* is directed to a file. It also does the same if | * is directed to a file. It also does the same if | ||||
* we never produce any real output; for example, if | * we never produce any real output; for example, if | ||||
* the input file(s) cannot be opened. If we do | * the input file(s) cannot be opened. If we do | ||||
* eventually produce output, code in edit() makes | * eventually produce output, code in edit() makes | ||||
* sure these messages can be seen before they are | * sure these messages can be seen before they are | ||||
* overwritten or scrolled away. | * overwritten or scrolled away. | ||||
*/ | */ | ||||
public void | public void | ||||
flush() | flush(void) | ||||
{ | { | ||||
register int n; | int n; | ||||
register int fd; | int fd; | ||||
n = (int) (ob - obuf); | n = (int) (ob - obuf); | ||||
if (n == 0) | if (n == 0) | ||||
return; | return; | ||||
#if MSDOS_COMPILER==MSOFTC | #if MSDOS_COMPILER==MSOFTC | ||||
if (is_tty && any_display) | if (is_tty && any_display) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 213 Lines • ▼ Show 20 Lines | if (write(fd, obuf, n) != n) | ||||
screen_trashed = 1; | screen_trashed = 1; | ||||
ob = obuf; | ob = obuf; | ||||
} | } | ||||
/* | /* | ||||
* Output a character. | * Output a character. | ||||
*/ | */ | ||||
public int | public int | ||||
putchr(c) | putchr(int c) | ||||
int c; | |||||
{ | { | ||||
#if 0 /* fake UTF-8 output for testing */ | #if 0 /* fake UTF-8 output for testing */ | ||||
extern int utf_mode; | extern int utf_mode; | ||||
if (utf_mode) | if (utf_mode) | ||||
{ | { | ||||
static char ubuf[MAX_UTF_CHAR_LEN]; | static char ubuf[MAX_UTF_CHAR_LEN]; | ||||
static int ubuf_len = 0; | static int ubuf_len = 0; | ||||
static int ubuf_index = 0; | static int ubuf_index = 0; | ||||
Show All 36 Lines | #endif | ||||
at_prompt = 0; | at_prompt = 0; | ||||
return (c); | return (c); | ||||
} | } | ||||
/* | /* | ||||
* Output a string. | * Output a string. | ||||
*/ | */ | ||||
public void | public void | ||||
putstr(s) | putstr(constant char *s) | ||||
register char *s; | |||||
{ | { | ||||
while (*s != '\0') | while (*s != '\0') | ||||
putchr(*s++); | putchr(*s++); | ||||
} | } | ||||
/* | /* | ||||
* Convert an integral type to a string. | * Convert an integral type to a string. | ||||
*/ | */ | ||||
#define TYPE_TO_A_FUNC(funcname, type) \ | #define TYPE_TO_A_FUNC(funcname, type) \ | ||||
void funcname(num, buf) \ | void funcname(num, buf) \ | ||||
type num; \ | type num; \ | ||||
char *buf; \ | char *buf; \ | ||||
{ \ | { \ | ||||
int neg = (num < 0); \ | int neg = (num < 0); \ | ||||
char tbuf[INT_STRLEN_BOUND(num)+2]; \ | char tbuf[INT_STRLEN_BOUND(num)+2]; \ | ||||
register char *s = tbuf + sizeof(tbuf); \ | char *s = tbuf + sizeof(tbuf); \ | ||||
if (neg) num = -num; \ | if (neg) num = -num; \ | ||||
*--s = '\0'; \ | *--s = '\0'; \ | ||||
do { \ | do { \ | ||||
*--s = (num % 10) + '0'; \ | *--s = (num % 10) + '0'; \ | ||||
} while ((num /= 10) != 0); \ | } while ((num /= 10) != 0); \ | ||||
if (neg) *--s = '-'; \ | if (neg) *--s = '-'; \ | ||||
strcpy(buf, s); \ | strcpy(buf, s); \ | ||||
} | } | ||||
TYPE_TO_A_FUNC(postoa, POSITION) | TYPE_TO_A_FUNC(postoa, POSITION) | ||||
TYPE_TO_A_FUNC(linenumtoa, LINENUM) | TYPE_TO_A_FUNC(linenumtoa, LINENUM) | ||||
TYPE_TO_A_FUNC(inttoa, int) | TYPE_TO_A_FUNC(inttoa, int) | ||||
/* | /* | ||||
* Output an integer in a given radix. | * Output an integer in a given radix. | ||||
*/ | */ | ||||
static int | static int | ||||
iprint_int(num) | iprint_int(int num) | ||||
int num; | |||||
{ | { | ||||
char buf[INT_STRLEN_BOUND(num)]; | char buf[INT_STRLEN_BOUND(num)]; | ||||
inttoa(num, buf); | inttoa(num, buf); | ||||
putstr(buf); | putstr(buf); | ||||
return ((int) strlen(buf)); | return ((int) strlen(buf)); | ||||
} | } | ||||
/* | /* | ||||
* Output a line number in a given radix. | * Output a line number in a given radix. | ||||
*/ | */ | ||||
static int | static int | ||||
iprint_linenum(num) | iprint_linenum(LINENUM num) | ||||
LINENUM num; | |||||
{ | { | ||||
char buf[INT_STRLEN_BOUND(num)]; | char buf[INT_STRLEN_BOUND(num)]; | ||||
linenumtoa(num, buf); | linenumtoa(num, buf); | ||||
putstr(buf); | putstr(buf); | ||||
return ((int) strlen(buf)); | return ((int) strlen(buf)); | ||||
} | } | ||||
/* | /* | ||||
* This function implements printf-like functionality | * This function implements printf-like functionality | ||||
* using a more portable argument list mechanism than printf's. | * using a more portable argument list mechanism than printf's. | ||||
*/ | */ | ||||
static int | static int | ||||
less_printf(fmt, parg) | less_printf(char *fmt, PARG *parg) | ||||
register char *fmt; | |||||
PARG *parg; | |||||
{ | { | ||||
register char *s; | char *s; | ||||
register int col; | int col; | ||||
col = 0; | col = 0; | ||||
while (*fmt != '\0') | while (*fmt != '\0') | ||||
{ | { | ||||
if (*fmt != '%') | if (*fmt != '%') | ||||
{ | { | ||||
putchr(*fmt++); | putchr(*fmt++); | ||||
col++; | col++; | ||||
Show All 26 Lines | |||||
} | } | ||||
/* | /* | ||||
* Get a RETURN. | * Get a RETURN. | ||||
* If some other non-trivial char is pressed, unget it, so it will | * If some other non-trivial char is pressed, unget it, so it will | ||||
* become the next command. | * become the next command. | ||||
*/ | */ | ||||
public void | public void | ||||
get_return() | get_return(void) | ||||
{ | { | ||||
int c; | int c; | ||||
#if ONLY_RETURN | #if ONLY_RETURN | ||||
while ((c = getchr()) != '\n' && c != '\r') | while ((c = getchr()) != '\n' && c != '\r') | ||||
bell(); | bell(); | ||||
#else | #else | ||||
c = getchr(); | c = getchr(); | ||||
if (c != '\n' && c != '\r' && c != ' ' && c != READ_INTR) | if (c != '\n' && c != '\r' && c != ' ' && c != READ_INTR) | ||||
ungetcc(c); | ungetcc(c); | ||||
#endif | #endif | ||||
} | } | ||||
/* | /* | ||||
* Output a message in the lower left corner of the screen | * Output a message in the lower left corner of the screen | ||||
* and wait for carriage return. | * and wait for carriage return. | ||||
*/ | */ | ||||
public void | public void | ||||
error(fmt, parg) | error(char *fmt, PARG *parg) | ||||
char *fmt; | |||||
PARG *parg; | |||||
{ | { | ||||
int col = 0; | int col = 0; | ||||
static char return_to_continue[] = " (press RETURN)"; | static char return_to_continue[] = " (press RETURN)"; | ||||
errmsgs++; | errmsgs++; | ||||
if (any_display && is_tty) | if (any_display && is_tty) | ||||
{ | { | ||||
Show All 36 Lines | |||||
/* | /* | ||||
* Output a message in the lower left corner of the screen | * Output a message in the lower left corner of the screen | ||||
* and don't wait for carriage return. | * and don't wait for carriage return. | ||||
* Usually used to warn that we are beginning a potentially | * Usually used to warn that we are beginning a potentially | ||||
* time-consuming operation. | * time-consuming operation. | ||||
*/ | */ | ||||
public void | public void | ||||
ierror(fmt, parg) | ierror(char *fmt, PARG *parg) | ||||
char *fmt; | |||||
PARG *parg; | |||||
{ | { | ||||
at_exit(); | at_exit(); | ||||
clear_bot(); | clear_bot(); | ||||
at_enter(AT_STANDOUT); | at_enter(AT_STANDOUT); | ||||
(void) less_printf(fmt, parg); | (void) less_printf(fmt, parg); | ||||
putstr(intr_to_abort); | putstr(intr_to_abort); | ||||
at_exit(); | at_exit(); | ||||
flush(); | flush(); | ||||
need_clr = 1; | need_clr = 1; | ||||
} | } | ||||
/* | /* | ||||
* Output a message in the lower left corner of the screen | * Output a message in the lower left corner of the screen | ||||
* and return a single-character response. | * and return a single-character response. | ||||
*/ | */ | ||||
public int | public int | ||||
query(fmt, parg) | query(char *fmt, PARG *parg) | ||||
char *fmt; | |||||
PARG *parg; | |||||
{ | { | ||||
register int c; | int c; | ||||
int col = 0; | int col = 0; | ||||
if (any_display && is_tty) | if (any_display && is_tty) | ||||
clear_bot(); | clear_bot(); | ||||
(void) less_printf(fmt, parg); | (void) less_printf(fmt, parg); | ||||
c = getchr(); | c = getchr(); | ||||
Show All 13 Lines |