diff options
author | Cameron Katri <me@cameronkatri.com> | 2021-04-26 16:40:28 -0400 |
---|---|---|
committer | Cameron Katri <me@cameronkatri.com> | 2021-04-26 16:40:28 -0400 |
commit | 219b0151ae954faa63cdc0abed49bb4ddb53d75f (patch) | |
tree | f5ce6975b39b449146b1c327974f39b3430aedf3 /dirconvert.c | |
parent | 2574ea03da54335dc1641696aa3bbf1cbe02f766 (diff) | |
download | opendircolors-219b0151ae954faa63cdc0abed49bb4ddb53d75f.tar.gz opendircolors-219b0151ae954faa63cdc0abed49bb4ddb53d75f.tar.zst opendircolors-219b0151ae954faa63cdc0abed49bb4ddb53d75f.zip |
All works
Diffstat (limited to 'dirconvert.c')
-rw-r--r-- | dirconvert.c | 70 |
1 files changed, 13 insertions, 57 deletions
diff --git a/dirconvert.c b/dirconvert.c index 5f76258..5169a05 100644 --- a/dirconvert.c +++ b/dirconvert.c @@ -33,14 +33,10 @@ #include <string.h> #include <sysexits.h> -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 |