diff options
author | ache <ache@FreeBSD.org> | 2000-06-05 19:39:39 +0000 |
---|---|---|
committer | ache <ache@FreeBSD.org> | 2000-06-05 19:39:39 +0000 |
commit | 5bc31495b7543e4ab497f261fecc6fe3e8252d2f (patch) | |
tree | 4a68339593f03b32375655ef27be3dd64492a389 /bin/ls | |
parent | c3d31e9304323cc684b2d8c0c6cdb4b9240e5830 (diff) | |
download | FreeBSD-src-5bc31495b7543e4ab497f261fecc6fe3e8252d2f.zip FreeBSD-src-5bc31495b7543e4ab497f261fecc6fe3e8252d2f.tar.gz |
Don't use curses includes, include termcap.h instead
Don't use curses functions, use tputs instead
Add ^C reaction - reset colors
Optimization - don't turn off colors after EACH file printed.
Fix wrong ctype macro arg type in LSCOLORS parsing
Diffstat (limited to 'bin/ls')
-rw-r--r-- | bin/ls/print.c | 39 |
1 files changed, 26 insertions, 13 deletions
diff --git a/bin/ls/print.c b/bin/ls/print.c index 3474408..4c3f568 100644 --- a/bin/ls/print.c +++ b/bin/ls/print.c @@ -48,7 +48,8 @@ static const char rcsid[] = #ifdef COLORLS #include <ctype.h> -#include <curses.h> +#include <termcap.h> +#include <term.h> /* for tparm */ #endif #include <err.h> #include <errno.h> @@ -58,9 +59,6 @@ static const char rcsid[] = #include <stdio.h> #include <stdlib.h> #include <string.h> -#ifdef COLORLS -#include <term.h> -#endif #include <time.h> #include <unistd.h> @@ -94,6 +92,7 @@ typedef enum Colors { char *defcolors = "4x5x2x3x1x464301060203"; static int colors[C_NUMCOLORS][2]; +static int color_printed = 0; #endif void @@ -159,12 +158,12 @@ printlong(dp) printtime(sp->st_mtime); #ifdef COLORLS if (f_color) - (void)colortype(sp->st_mode); + color_printed = colortype(sp->st_mode); #endif if (f_octal || f_octal_escape) (void)prn_octal(p->fts_name); else (void)printf("%s", p->fts_name); #ifdef COLORLS - if (f_color) + if (f_color && color_printed) endcolor(); #endif if (f_type) @@ -280,12 +279,12 @@ printaname(p, inodefield, sizefield) (int)sizefield, howmany(sp->st_blocks, blocksize)); #ifdef COLORLS if (f_color) - (void)colortype(sp->st_mode); + color_printed = colortype(sp->st_mode); #endif chcnt += (f_octal || f_octal_escape) ? prn_octal(p->fts_name) : printf("%s", p->fts_name); #ifdef COLORLS - if (f_color) + if (f_color && color_printed) endcolor(); #endif if (f_type) @@ -352,6 +351,13 @@ printtype(mode) } #ifdef COLORLS +int putch(c) + int c; +{ + return putc(c, stdout); +} + + void printcolor(c) Colors c; @@ -361,21 +367,20 @@ printcolor(c) if (colors[c][0] != -1) { ansiseq = tparm(ansi_fgcol, colors[c][0]); if (ansiseq) - putp(ansiseq); + tputs(ansiseq, 1, putch); } if (colors[c][1] != -1) { ansiseq = tparm(ansi_bgcol, colors[c][1]); if (ansiseq) - putp(ansiseq); + tputs(ansiseq, 1, putch); } } void endcolor() { - if (ansi_coloff) - putp(ansi_coloff); + tputs(ansi_coloff, 1, putch); } int @@ -439,7 +444,7 @@ char *cs; } for (j = 0 ; j < 2 ; j++) { if ((c[j] < '0' || c[j] > '7') && - tolower(c[j]) != 'x') { + tolower((unsigned char)c[j]) != 'x') { fprintf(stderr, "error: invalid character '%c' in LSCOLORS env var\n", c[j]); @@ -452,6 +457,14 @@ char *cs; } } } + +/* ARGSUSED */ +void colorquit(sig) + int sig; +{ + endcolor(); + exit(1); +} #endif /*COLORLS*/ static void |