aboutsummaryrefslogtreecommitdiffstats
path: root/dirconvert.c
diff options
context:
space:
mode:
authorCameron Katri <me@cameronkatri.com>2021-05-30 15:59:03 -0400
committerCameron Katri <me@cameronkatri.com>2021-05-30 15:59:03 -0400
commitbba67091ac18bfcf886dc1221dea218aa119618e (patch)
treeb70347dc27e0afa933f184425d04b681ed9155b3 /dirconvert.c
parentc94bbb169889ec8827c373ebd6cfadf9f330218e (diff)
downloadopendircolors-bba67091ac18bfcf886dc1221dea218aa119618e.tar.gz
opendircolors-bba67091ac18bfcf886dc1221dea218aa119618e.tar.zst
opendircolors-bba67091ac18bfcf886dc1221dea218aa119618e.zip
Revamp to improve everything, and support D30547
https://reviews.freebsd.org/D30547
Diffstat (limited to 'dirconvert.c')
-rw-r--r--dirconvert.c35
1 files changed, 31 insertions, 4 deletions
diff --git a/dirconvert.c b/dirconvert.c
index 41982c1..b2bf6e6 100644
--- a/dirconvert.c
+++ b/dirconvert.c
@@ -28,6 +28,7 @@
#include <ctype.h>
#include <libgen.h>
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -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)
{