View | Details | Raw Unified | Return to bug 27374
Collapse All | Expand All

(-)ls/extern.h (+2 lines)
Lines 54-59 Link Here
54
void	 parsecolors __P((char *cs));
54
void	 parsecolors __P((char *cs));
55
void     colorquit __P((int));
55
void     colorquit __P((int));
56
56
57
extern  char    *enter_bold;
58
extern  char    *attrs_off;
57
extern  char    *ansi_fgcol;
59
extern  char    *ansi_fgcol;
58
extern  char    *ansi_bgcol;
60
extern  char    *ansi_bgcol;
59
extern  char    *ansi_coloff;
61
extern  char    *ansi_coloff;
(-)ls/ls.c (+4 lines)
Lines 116-121 Link Here
116
#ifdef COLORLS
116
#ifdef COLORLS
117
int f_color;			/* add type in color for non-regular files */
117
int f_color;			/* add type in color for non-regular files */
118
118
119
char *enter_bold;		/* sequence to set color to bold mode */
120
char *attrs_off;		/* sequence to turn off attributes (bold mode, etc) */
119
char *ansi_bgcol;		/* ANSI sequence to set background colour */
121
char *ansi_bgcol;		/* ANSI sequence to set background colour */
120
char *ansi_fgcol;		/* ANSI sequence to set foreground colour */
122
char *ansi_fgcol;		/* ANSI sequence to set foreground colour */
121
char *ansi_coloff;		/* ANSI sequence to reset colours */
123
char *ansi_coloff;		/* ANSI sequence to reset colours */
Lines 282-287 Link Here
282
	    (isatty(STDOUT_FILENO) || getenv("CLICOLOR_FORCE")))
284
	    (isatty(STDOUT_FILENO) || getenv("CLICOLOR_FORCE")))
283
#ifdef COLORLS
285
#ifdef COLORLS
284
		if (tgetent(termcapbuf, getenv("TERM")) == 1) {
286
		if (tgetent(termcapbuf, getenv("TERM")) == 1) {
287
			enter_bold = tgetstr("md", &bp);
288
			attrs_off = tgetstr("me", &bp);
285
			ansi_fgcol = tgetstr("AF", &bp);
289
			ansi_fgcol = tgetstr("AF", &bp);
286
			ansi_bgcol = tgetstr("AB", &bp);
290
			ansi_bgcol = tgetstr("AB", &bp);
287
291
(-)ls/print.c (-13 / +59 lines)
Lines 95-101 Link Here
95
95
96
char *defcolors = "4x5x2x3x1x464301060203";
96
char *defcolors = "4x5x2x3x1x464301060203";
97
97
98
static int colors[C_NUMCOLORS][2];
98
/* colors for file types */
99
static struct {
100
	int num[2];
101
	int bold;
102
} colors[C_NUMCOLORS];
103
99
#endif
104
#endif
100
105
101
void
106
void
Lines 383-396 Link Here
383
{
388
{
384
	char *ansiseq;
389
	char *ansiseq;
385
390
386
	if (colors[c][0] != -1) {
391
	if (colors[c].bold)
387
		ansiseq = tgoto(ansi_fgcol, 0, colors[c][0]);
392
		tputs(enter_bold, 1, putch);
393
394
	if (colors[c].num[0] != -1) {
395
		ansiseq = tgoto(ansi_fgcol, 0, colors[c].num[0]);
388
		if (ansiseq)
396
		if (ansiseq)
389
			tputs(ansiseq, 1, putch);
397
			tputs(ansiseq, 1, putch);
390
	}
398
	}
391
399
392
	if (colors[c][1] != -1) {
400
	if (colors[c].num[1] != -1) {
393
		ansiseq = tgoto(ansi_bgcol, 0, colors[c][1]);
401
		ansiseq = tgoto(ansi_bgcol, 0, colors[c].num[1]);
394
		if (ansiseq)
402
		if (ansiseq)
395
			tputs(ansiseq, 1, putch);
403
			tputs(ansiseq, 1, putch);
396
	}
404
	}
Lines 401-406 Link Here
401
	int sig;
409
	int sig;
402
{
410
{
403
	tputs(ansi_coloff, 1, sig ? writech : putch);
411
	tputs(ansi_coloff, 1, sig ? writech : putch);
412
	tputs(attrs_off, 1, sig ? writech : putch);
404
}
413
}
405
414
406
static int
415
static int
Lines 455-460 Link Here
455
	if (cs == NULL)    cs = ""; /* LSCOLORS not set */
464
	if (cs == NULL)    cs = ""; /* LSCOLORS not set */
456
	len = strlen(cs);
465
	len = strlen(cs);
457
	for (i = 0 ; i < C_NUMCOLORS ; i++) {
466
	for (i = 0 ; i < C_NUMCOLORS ; i++) {
467
		colors[i].bold = 0;
468
458
		if (len <= 2*i) {
469
		if (len <= 2*i) {
459
			c[0] = defcolors[2*i];
470
			c[0] = defcolors[2*i];
460
			c[1] = defcolors[2*i+1];
471
			c[1] = defcolors[2*i+1];
Lines 464-480 Link Here
464
			c[1] = cs[2*i+1];
475
			c[1] = cs[2*i+1];
465
		}
476
		}
466
		for (j = 0 ; j < 2 ; j++) {
477
		for (j = 0 ; j < 2 ; j++) {
478
			/* shifted 0-7 (!, @, #, etc) do bold */
467
			if ((c[j] < '0' || c[j] > '7') &&
479
			if ((c[j] < '0' || c[j] > '7') &&
468
			    tolower((unsigned char)c[j]) != 'x') {
480
			    tolower((unsigned char)c[j]) != 'x' &&
481
			    c[j] != ')' && c[j] != '!' && c[j] != '@' &&
482
			    c[j] != '#' && c[j] != '$' && c[j] != '%' &&
483
			    c[j] != '^' && c[j] != '&') {
469
				fprintf(stderr,
484
				fprintf(stderr,
470
					"error: invalid character '%c' in LSCOLORS env var\n",
485
				    "error: invalid character '%c' in LSCOLORS"
471
					c[j]);
486
				    " env var\n", c[j]);
472
				c[j] = defcolors[2*i+j];
487
				c[j] = defcolors[2*i+j]-'0';
488
			}
489
490
			if (c[j] >= '0' && c[j] <= '7')
491
				colors[i].num[j] = c[j]-'0';
492
			else if (tolower((unsigned char)c[j] == 'x'))
493
				colors[i].num[j] = -1;
494
			else {
495
				colors[i].bold = 1;
496
497
				switch (c[j]) {
498
				case ')':
499
					colors[i].num[j] = 0;
500
					break;
501
				case '!':
502
					colors[i].num[j] = 1;
503
					break;
504
				case '@':
505
					colors[i].num[j] = 2;
506
					break;
507
				case '#':
508
					colors[i].num[j] = 3;
509
					break;
510
				case '$':
511
					colors[i].num[j] = 4;
512
					break;
513
				case '%':
514
					colors[i].num[j] = 5;
515
					break;
516
				case '^':
517
					colors[i].num[j] = 6;
518
					break;
519
				case '&':
520
					colors[i].num[j] = 7;
521
					break;
522
				}
473
			}
523
			}
474
			if (tolower((unsigned char)c[j]) == 'x')
475
			    colors[i][j] = -1;
476
			else
477
			    colors[i][j] = c[j]-'0';
478
		}
524
		}
479
	}
525
	}
480
}
526
}

Return to bug 27374