Changeset View
Changeset View
Standalone View
Standalone View
bin/ls/print.c
Show First 20 Lines • Show All 101 Lines • ▼ Show 20 Lines | |||||
} Colors; | } Colors; | ||||
static const char *defcolors = "exfxcxdxbxegedabagacad"; | static const char *defcolors = "exfxcxdxbxegedabagacad"; | ||||
/* colors for file types */ | /* colors for file types */ | ||||
static struct { | static struct { | ||||
int num[2]; | int num[2]; | ||||
int bold; | int bold; | ||||
int underline; | |||||
pstef: Wouldn't bool here be better as a type? | |||||
Done Inline ActionsI used int to follow what was used for bold, but I can change them to be bool if you'd prefer. me_cameronkatri.com: I used `int` to follow what was used for `bold`, but I can change them to be `bool` if you'd… | |||||
Done Inline ActionsI think such a slight inconsistency with the rest of the code would be less bad than using ints for boolean values. pstef: I think such a slight inconsistency with the rest of the code would be less bad than using ints… | |||||
} colors[C_NUMCOLORS]; | } colors[C_NUMCOLORS]; | ||||
#endif | #endif | ||||
static size_t padding_for_month[12]; | static size_t padding_for_month[12]; | ||||
static size_t month_max_size = 0; | static size_t month_max_size = 0; | ||||
void | void | ||||
printscol(const DISPLAY *dp) | printscol(const DISPLAY *dp) | ||||
▲ Show 20 Lines • Show All 425 Lines • ▼ Show 20 Lines | |||||
static void | static void | ||||
printcolor_termcap(Colors c) | printcolor_termcap(Colors c) | ||||
{ | { | ||||
char *ansiseq; | char *ansiseq; | ||||
if (colors[c].bold) | if (colors[c].bold) | ||||
tputs(enter_bold, 1, putch); | tputs(enter_bold, 1, putch); | ||||
if (colors[c].underline) | |||||
tputs(enter_underline, 1, putch); | |||||
if (colors[c].num[0] != -1) { | if (colors[c].num[0] != -1) { | ||||
ansiseq = tgoto(ansi_fgcol, 0, colors[c].num[0]); | ansiseq = tgoto(ansi_fgcol, 0, colors[c].num[0]); | ||||
if (ansiseq) | if (ansiseq) | ||||
tputs(ansiseq, 1, putch); | tputs(ansiseq, 1, putch); | ||||
} | } | ||||
if (colors[c].num[1] != -1) { | if (colors[c].num[1] != -1) { | ||||
ansiseq = tgoto(ansi_bgcol, 0, colors[c].num[1]); | ansiseq = tgoto(ansi_bgcol, 0, colors[c].num[1]); | ||||
if (ansiseq) | if (ansiseq) | ||||
tputs(ansiseq, 1, putch); | tputs(ansiseq, 1, putch); | ||||
} | } | ||||
} | } | ||||
static void | static void | ||||
printcolor_ansi(Colors c) | printcolor_ansi(Colors c) | ||||
{ | { | ||||
printf("\033["); | printf("\033["); | ||||
if (colors[c].bold) | if (colors[c].bold) | ||||
printf("1"); | printf("1"); | ||||
if (colors[c].underline) | |||||
printf(";4"); | |||||
if (colors[c].num[0] != -1) | if (colors[c].num[0] != -1) | ||||
printf(";3%d", colors[c].num[0]); | printf(";3%d", colors[c].num[0]); | ||||
if (colors[c].num[1] != -1) | if (colors[c].num[1] != -1) | ||||
printf(";4%d", colors[c].num[1]); | printf(";4%d", colors[c].num[1]); | ||||
printf("m"); | printf("m"); | ||||
} | } | ||||
static void | static void | ||||
▲ Show 20 Lines • Show All 82 Lines • ▼ Show 20 Lines | parsecolors(const char *cs) | ||||
char c[2]; | char c[2]; | ||||
short legacy_warn = 0; | short legacy_warn = 0; | ||||
if (cs == NULL) | if (cs == NULL) | ||||
cs = ""; /* LSCOLORS not set */ | cs = ""; /* LSCOLORS not set */ | ||||
len = strlen(cs); | len = strlen(cs); | ||||
for (i = 0; i < (int)C_NUMCOLORS; i++) { | for (i = 0; i < (int)C_NUMCOLORS; i++) { | ||||
colors[i].bold = 0; | colors[i].bold = 0; | ||||
colors[i].underline = 0; | |||||
if (len <= 2 * (size_t)i) { | if (len <= 2 * (size_t)i) { | ||||
c[0] = defcolors[2 * i]; | c[0] = defcolors[2 * i]; | ||||
c[1] = defcolors[2 * i + 1]; | c[1] = defcolors[2 * i + 1]; | ||||
} else { | } else { | ||||
c[0] = cs[2 * i]; | c[0] = cs[2 * i]; | ||||
c[1] = cs[2 * i + 1]; | c[1] = cs[2 * i + 1]; | ||||
} | } | ||||
for (j = 0; j < 2; j++) { | for (j = 0; j < 2; j++) { | ||||
/* Legacy colours used 0-7 */ | /* Legacy colours used 0-7 */ | ||||
if (c[j] >= '0' && c[j] <= '7') { | if (c[j] >= '0' && c[j] <= '7') { | ||||
colors[i].num[j] = c[j] - '0'; | colors[i].num[j] = c[j] - '0'; | ||||
if (!legacy_warn) { | if (!legacy_warn) { | ||||
warnx("LSCOLORS should use " | warnx("LSCOLORS should use " | ||||
"characters a-h instead of 0-9 (" | "characters a-h instead of 0-9 (" | ||||
"see the manual page)"); | "see the manual page)"); | ||||
} | } | ||||
legacy_warn = 1; | legacy_warn = 1; | ||||
} else if (c[j] >= 'a' && c[j] <= 'h') | } else if (c[j] >= 'a' && c[j] <= 'h') | ||||
colors[i].num[j] = c[j] - 'a'; | colors[i].num[j] = c[j] - 'a'; | ||||
else if (c[j] >= 'A' && c[j] <= 'H') { | else if (c[j] >= 'A' && c[j] <= 'H') { | ||||
colors[i].num[j] = c[j] - 'A'; | colors[i].num[j] = c[j] - 'A'; | ||||
if (j == 1) | |||||
colors[i].underline = 1; | |||||
else | |||||
colors[i].bold = 1; | colors[i].bold = 1; | ||||
} else if (tolower((unsigned char)c[j]) == 'x') | } else if (tolower((unsigned char)c[j]) == 'x') { | ||||
if (j == 1 && c[j] == 'X') | |||||
colors[i].underline = 1; | |||||
Done Inline Actionsstyle(9) is not clear on this, but I believe that by our convention, objects of type other than bool are tested using operators (I mean, for example, pointers compared to NULL, chars compared to '\0' and so on). pstef: style(9) is not clear on this, but I believe that by our convention, objects of type other than… | |||||
colors[i].num[j] = -1; | colors[i].num[j] = -1; | ||||
} | |||||
pstefUnsubmitted Done Inline Actions} else { pstef: `} else {` | |||||
else { | else { | ||||
warnx("invalid character '%c' in LSCOLORS" | warnx("invalid character '%c' in LSCOLORS" | ||||
" env var", c[j]); | " env var", c[j]); | ||||
colors[i].num[j] = -1; | colors[i].num[j] = -1; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 125 Lines • Show Last 20 Lines |
Wouldn't bool here be better as a type?