Deleted Added
full compact
42c42
< "$FreeBSD: head/bin/ls/print.c 55514 2000-01-06 14:40:10Z bde $";
---
> "$FreeBSD: head/bin/ls/print.c 61178 2000-06-02 14:53:42Z joe $";
58a59
> #include <ctype.h>
69a71,90
> /* Most of these are taken from <sys/stat.h> */
> typedef enum Colors {
> C_DIR, /* directory */
> C_LNK, /* symbolic link */
> C_SOCK, /* socket */
> C_FIFO, /* pipe */
> C_EXEC, /* executable */
> C_BLK, /* block special */
> C_CHR, /* character special */
> C_SUID, /* setuid executable */
> C_SGID, /* setgid executable */
> C_WSDIR, /* directory writeble to others, with sticky bit */
> C_WDIR, /* directory writeble to others, without sticky bit */
> C_NUMCOLORS /* just a place-holder */
> } Colors ;
>
> char *defcolors = "4x5x2x3x1x464301060203";
>
> static int colors[C_NUMCOLORS][2];
>
130a152,153
> if (f_color)
> (void)colortype(sp->st_mode);
132a156,157
> if (f_color)
> (void)printf("\033[m");
201a227,236
> /*
> * some terminals get confused if we mix tabs
> * with color sequences
> */
> if (f_color)
> while ((cnt = (chcnt + 1)) <= endcol) {
> (void)putchar(' ');
> chcnt = cnt;
> }
> else
231a267,268
> if (f_color)
> (void)colortype(sp->st_mode);
233a271,272
> if (f_color)
> printf("\033[m");
296a336,425
> void
> printcolor(c)
> Colors c;
> {
> printf("\033[");
> if (colors[c][0] != -1) {
> printf("3%d", colors[c][0]);
> if (colors[c][1] != -1)
> printf(";");
> }
> if (colors[c][1] != -1)
> printf("4%d", colors[c][1]);
> printf("m");
> }
>
> int
> colortype(mode)
> mode_t mode;
> {
> switch(mode & S_IFMT) {
> case S_IFDIR:
> if (mode & S_IWOTH)
> if (mode & S_ISTXT)
> printcolor(C_WSDIR);
> else
> printcolor(C_WDIR);
> else
> printcolor(C_DIR);
> return(1);
> case S_IFLNK:
> printcolor(C_LNK);
> return(1);
> case S_IFSOCK:
> printcolor(C_SOCK);
> return(1);
> case S_IFIFO:
> printcolor(C_FIFO);
> return(1);
> case S_IFBLK:
> printcolor(C_BLK);
> return(1);
> case S_IFCHR:
> printcolor(C_CHR);
> return(1);
> }
> if (mode & (S_IXUSR | S_IXGRP | S_IXOTH)) {
> if (mode & S_ISUID)
> printcolor(C_SUID);
> else if (mode & S_ISGID)
> printcolor(C_SGID);
> else
> printcolor(C_EXEC);
> return(1);
> }
> return(0);
> }
>
> void
> parsecolors(cs)
> char *cs;
> {
> int i, j, len;
> char c[2];
> if (cs == NULL) cs = ""; /* LSCOLORS not set */
> len = strlen(cs);
> for (i = 0 ; i < C_NUMCOLORS ; i++) {
> if (len <= 2*i) {
> c[0] = defcolors[2*i];
> c[1] = defcolors[2*i+1];
> }
> else {
> c[0] = cs[2*i];
> c[1] = cs[2*i+1];
> }
> for (j = 0 ; j < 2 ; j++) {
> if ((c[j] < '0' || c[j] > '7') &&
> tolower(c[j]) != 'x') {
> fprintf(stderr,
> "error: invalid character '%c' in LSCOLORS env var\n",
> c[j]);
> c[j] = defcolors[2*i+j];
> }
> if (c[j] == 'x')
> colors[i][j] = -1;
> else
> colors[i][j] = c[j]-'0';
> }
> }
> }
>