From bba67091ac18bfcf886dc1221dea218aa119618e Mon Sep 17 00:00:00 2001 From: Cameron Katri Date: Sun, 30 May 2021 15:59:03 -0400 Subject: Revamp to improve everything, and support D30547 https://reviews.freebsd.org/D30547 --- dirconvert.c | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) (limited to 'dirconvert.c') diff --git a/dirconvert.c b/dirconvert.c index 41982c1..b2bf6e6 100644 --- a/dirconvert.c +++ b/dirconvert.c @@ -28,6 +28,7 @@ #include #include +#include #include #include #include @@ -35,8 +36,12 @@ #include "common.h" +static const char *types[11] = { "di", "ln", "so", "pi", "ex", "bd", "cd", "su", + "sg", "tw", "ow" }; + void usage(const char *); char *tols_colors(char *); +char *tolscolors(char *); int main(int argc, char **argv) @@ -75,14 +80,14 @@ tols_colors(char *lscolors) sprintf(ls_out + strlen(ls_out), "%s=", types[i]); if (isupper(lscolors[2 * i])) sprintf(ls_out + strlen(ls_out), "01;"); + if (isupper(lscolors[2 * i + 1])) + sprintf(ls_out + strlen(ls_out), "04;"); if (tolower(lscolors[2 * i]) == 'x') sprintf(ls_out + strlen(ls_out), "00"); else if (tolower(lscolors[2 * i] != 'x')) - sprintf(ls_out + strlen(ls_out), "3%i", - (int)(strchr(col, tolower(lscolors[2 * i])) - col)); + sprintf(ls_out + strlen(ls_out), "3%i", (int)tolower(lscolors[2 * i]) - 97); if (tolower(lscolors[2 * i + 1]) != 'x') - sprintf(ls_out + strlen(ls_out), ";4%i", - (int)(strchr(col, tolower(lscolors[2 * i])) - col)); + sprintf(ls_out + strlen(ls_out), ";4%i", (int)tolower(lscolors[2 * i + 1]) - 97); sprintf(ls_out + strlen(ls_out), ":"); } char *ret = strdup(ls_out); @@ -90,6 +95,28 @@ tols_colors(char *lscolors) return (ret); } +char * +tolscolors(char *dircolor) +{ + char *ent; + char key[2] = "", val[MAXKEYLEN] = ""; + char out[22] = "xxxxxxxxxxxxxxxxxxxx"; + struct color color; + + while ((ent = strsep(&dircolor, ":")) != NULL) { + for (int i = 0; i < 11; i++) { + if (strncmp(ent, types[i], strlen(types[i])) == 0) { + sscanf(ent, "%c%c=%s", &key[0], &key[1], val); + parseansi(val, &color); + out[2 * i] = color.fg; + out[2 * i + 1] = color.bg; + } + } + } + char *ret = strdup(out); + return (ret); +} + void usage(const char *progname) { -- cgit v1.2.3-56-ge451