diff options
| author | Mitchell Riedstra <mitch@riedstra.dev> | 2023-01-01 17:21:45 -0500 |
|---|---|---|
| committer | Mitchell Riedstra <mitch@riedstra.dev> | 2023-01-01 17:21:45 -0500 |
| commit | 58e18d86a798b4487375f19bcfcdcf9283a56f6e (patch) | |
| tree | 6c0e2100559d2e79e4ab032da1993df64800bf2d /util.c | |
| parent | 18a8ecffd287035362338ecf27dc99a462593bd4 (diff) | |
| download | dwm-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.c | 52 |
1 files changed, 52 insertions, 0 deletions
@@ -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; +} |
