commit d1cb4f64209950a37b760ab22140f265c762b2a8
Author: Raniconduh <clagv.randomgames@gmail.com>
Date: Tue Apr 12 12:18:50 2022 +0000
diff --git a/README.md b/README.md
index c2779c5..d4443e8 100644
--- a/README.md
+++ b/README.md
@@ -688 +689 @@ The command prompt will show up upon pressing `:` and the prompt itself is prefi
* `mu`: **M**ark **U**nmark: Unmarks all files on the directory
* `ca`: **C**ut **A**ll files in the current directory
-* `set`: Set a variable ([see Variables](#variables))
-* `unset`: Unset a variable ([see Variables](#variables))
+* `set`: Set a variable to true ([see Variables](#variables))
+* `unset`: Unset a variable (set to false, [see Variables](#variables))
+* `var`: Set a variable equal to something `var variable = false` ([see Variables](#variables) and ['config file'](#config-file))
#### Renaming
diff --git a/include/opts.h b/include/opts.h
index 89526cc..68d860e 100644
--- a/include/opts.h
+++ b/include/opts.h
@@ -445 +446 @@ void create_config(void);
void read_config(void);
void terminate_opts(void);
void generate_colors(void);
+void parse_var(char *);
#endif /* _OPTS_H */
diff --git a/src/main.c b/src/main.c
index 1331812..cda4714 100644
--- a/src/main.c
+++ b/src/main.c
@@ -2936 +2937 @@ int main(int argc, char ** argv) {
char * cmd = inp;
char * args = ++sp;
if (!strcmp(cmd, "set")) set(args);
+ else if (!strcmp(cmd, "var")) parse_var(args);
else if (!strcmp(cmd, "unset")) unset(args);
} else if (!strcmp(inp, "ma") && !cutting)
mark_all();
diff --git a/src/opts.c b/src/opts.c
index c7b50d0..6b36d15 100644
--- a/src/opts.c
+++ b/src/opts.c
@@ -936 +9341 @@ void create_config(void) {
}
+void parse_var(char * var) {
+ char * line = var;
+ // go past leading white space
+ while (*var && isspace(*var)) var++;
+
+ int n = 0;
+
+ // add null terminator to var
+ char * val = strchr(var, '=');
+ while (val + n > line && isspace(val[--n]));
+ val[n + 1] = 0;
+ val++;
+
+ // remove trailing white space after '='
+ while (*val && *val != '=' && isspace(*val)) val++;
+
+ void * ptr_val = NULL;
+
+ bool bool_val = false;
+ if (!strcmp(val, "true")) {
+ bool_val = true;
+ ptr_val = &bool_val;
+ } else if (!strcmp(val, "false")) {
+ bool_val = false;
+ ptr_val = &bool_val;
+ } else if (val[0] == '"' && val[strlen(val) - 1] == '"') {
+ val++;
+ val[strlen(val) - 1] = 0;
+ ptr_val = val;
+ }
+
+ var_set(var, ptr_val);
+}
+
+
void read_config(void) {
FILE * fp = fopen(csc_config_file, "r");
@@ -11537 +1507 @@ void read_config(void) {
if (!*line) break;
- char * var = line;
- // go past leading white space
- while (*var && isspace(*var)) var++;
-
- int n = 0;
-
- // add null terminator to var
- char * val = strchr(var, '=');
- while (val + n > line && isspace(val[--n]));
- val[n + 1] = 0;
- val++;
-
- // remove trailing white space after '='
- while (*val && *val != '=' && isspace(*val)) val++;
-
- void * ptr_val = NULL;
-
- bool bool_val = false;
- if (!strcmp(val, "true")) {
- bool_val = true;
- ptr_val = &bool_val;
- } else if (!strcmp(val, "false")) {
- bool_val = false;
- ptr_val = &bool_val;
- } else if (val[0] == '"' && val[strlen(val) - 1] == '"') {
- val++;
- val[strlen(val) - 1] = 0;
- ptr_val = val;
- }
-
- var_set(var, ptr_val);
+ parse_var(line);
}
fclose(fp);