aboutsummaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorMitchell Riedstra <mitch@riedstra.dev>2023-01-01 17:21:45 -0500
committerMitchell Riedstra <mitch@riedstra.dev>2023-01-01 17:21:45 -0500
commit58e18d86a798b4487375f19bcfcdcf9283a56f6e (patch)
tree6c0e2100559d2e79e4ab032da1993df64800bf2d /util.c
parent18a8ecffd287035362338ecf27dc99a462593bd4 (diff)
downloaddwm-58e18d86a798b4487375f19bcfcdcf9283a56f6e.tar.gz
dwm-58e18d86a798b4487375f19bcfcdcf9283a56f6e.tar.xz
Add a new centered layout to dwm.
Allow the scaling factor to be adjusted on the fly.
Diffstat (limited to 'util.c')
-rw-r--r--util.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/util.c b/util.c
index fe044fc..441c9a7 100644
--- a/util.c
+++ b/util.c
@@ -1,8 +1,12 @@
/* See LICENSE file for copyright and license details. */
+#include <err.h>
+#include <fcntl.h>
+#include <regex.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
#include "util.h"
@@ -33,3 +37,51 @@ die(const char *fmt, ...) {
exit(1);
}
+
+
+int
+readEnv(FILE *fh)
+{
+ int ret;
+ char name[1024], value[8192];
+
+ while (1) {
+ if ((ret = fscanf(fh, "%1023[^=]=%8191[^\n]\n", &name, &value)) == EOF)
+ break;
+ else if (ret == 0)
+ break;
+
+ fprintf(stderr, "Setting: '%s' = '%s'\n", name, value);
+ setenv(name, value, 1);
+ }
+
+ return 0;
+}
+
+int
+reMatch(const char *regex, const char *str) {
+ char reErr[1024] = {0};
+ regex_t *re = calloc(1, sizeof(regex_t));
+ int rc = 0;
+
+ if (!re)
+ return -1;
+
+ rc = regcomp(re, regex, REG_EXTENDED|REG_ICASE|REG_NOSUB);
+ if (rc != 0) {
+ regerror(rc, re, reErr, 1024);
+ fprintf(stderr, "Regex compile err: %s %s\n", regex, reErr);
+ return -1;
+ }
+
+ rc = regexec(re, str, 0, NULL, 0);
+ regfree(re);
+ if (rc != 0) {
+ regerror(rc, re, reErr, 1024);
+ fprintf(stderr, "Regex match error: %s -> %s : %s\n",
+ regex, str, reErr);
+ return -1;
+ }
+
+ return rc;
+}