From 219b0151ae954faa63cdc0abed49bb4ddb53d75f Mon Sep 17 00:00:00 2001 From: Cameron Katri Date: Mon, 26 Apr 2021 16:40:28 -0400 Subject: All works --- dirconvert.c | 70 +++++++++++------------------------------------------------- 1 file changed, 13 insertions(+), 57 deletions(-) (limited to 'dirconvert.c') diff --git a/dirconvert.c b/dirconvert.c index 5f76258..5169a05 100644 --- a/dirconvert.c +++ b/dirconvert.c @@ -33,14 +33,10 @@ #include #include -const char *types[11] = { "di", "ln", "so", "pi", "ex", "bd", "cd", "su", "sg", - "tw", "ow" }; -const char col[8] = "abcdefgh"; +#include "common.h" void usage(void); -int tolscolors(char *); -int tols_colors(char *); -char numtocol(char, bool); +char *tols_colors(char *); int main(int argc, char **argv) @@ -48,59 +44,19 @@ main(int argc, char **argv) if (argc != 2) usage(); - if (strchr(argv[1], '=')) - return tolscolors(argv[1]); - else - return tols_colors(argv[1]); - - /* NOTREACHED */ - return 0; -} - -int -tolscolors(char *dircolor) -{ - char *ent, *buf, *val, *val2; - char out[22] = "xxxxxxxxxxxxxxxxxxxxxx"; - bool bold = false; - - while ((ent = buf = strsep(&dircolor, ":")) != NULL) { - for (int i = 0; i < 11; i++) { - if (strncmp(ent, types[i], strlen(types[i])) == 0) { - bold = false; - while ((val = strsep(&buf, "=")) != NULL) { - while ((val2 = strsep(&val, ";")) != - NULL) { - if (strcmp(val2, "01") == 0) { - bold = true; - } else if (val2[0] == '3') { - out[2 * i] = numtocol( - val2[1], bold); - } else if (val2[0] == '4') { - out[2 * i + 1] = - numtocol( - val2[1], NULL); - } - } - } - } - } + if (strchr(argv[1], '=')) { + printf("%s\n", tolscolors(argv[1])); + return (0); + } else { + printf("%s\n", tols_colors(argv[1])); + return (0); } - printf("%s\n", out); - return 0; -} -char -numtocol(char c, bool bold) -{ - char buf = col[strtol(&c, NULL, 10)]; - if (bold) - return toupper(buf); - else - return buf; + /* NOTREACHED */ + return (0); } -int +char * tols_colors(char *lscolors) { char *ls_out = strdup(""); @@ -121,9 +77,9 @@ tols_colors(char *lscolors) (int)(strchr(col, tolower(lscolors[2 * i])) - col)); sprintf(ls_out + strlen(ls_out), ":"); } - printf("%s\n", ls_out); + char *ret = strdup(ls_out); free(ls_out); - return 0; + return (ret); } void -- cgit v1.2.3-56-ge451