aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsin <sin@2f30.org>2019-08-23 16:00:03 +0100
committersin <sin@2f30.org>2019-08-24 11:25:43 +0100
commit58b6b5ba9a2e0ff758ae575cb04c98177a77a7f3 (patch)
tree5f8df0d8bf45a54d14e4328139e7e1afe8e3b97b
parent2b8e1ac48a355d0185665bd9f4b1c30d2747b1dd (diff)
downloadnoice-58b6b5ba9a2e0ff758ae575cb04c98177a77a7f3.tar.gz
Rename struct assoc to struct rule
-rw-r--r--nopen.c42
-rw-r--r--nopenconf.def.h4
2 files changed, 24 insertions, 22 deletions
diff --git a/nopen.c b/nopen.c
index d0581bc..3b573f1 100644
--- a/nopen.c
+++ b/nopen.c
@@ -11,7 +11,7 @@
#include "arg.h"
#include "util.h"
-struct assoc {
+struct rule {
char *regex; /* Regex to match on filename */
char *file;
char *argv[NR_ARGS];
@@ -23,47 +23,47 @@ struct assoc {
char *argv0;
void
-run(struct assoc *assoc, char *arg)
+run(struct rule *rule, char *arg)
{
char *argv[NR_ARGS];
int i;
- for (i = 0; assoc->argv[i]; i++) {
- if (strcmp(assoc->argv[i], "{}") == 0) {
+ for (i = 0; rule->argv[i]; i++) {
+ if (strcmp(rule->argv[i], "{}") == 0) {
argv[i] = arg;
continue;
}
- argv[i] = assoc->argv[i];
+ argv[i] = rule->argv[i];
}
argv[i] = NULL;
- spawnvp(NULL, assoc->file, argv);
+ spawnvp(NULL, rule->file, argv);
}
-struct assoc *
-openwith(char *file)
+struct rule *
+matchrule(char *file)
{
int i;
- for (i = 0; i < LEN(assocs); i++) {
- if (regexec(&assocs[i].regcomp, file, 0, NULL, 0) == 0)
- return &assocs[i];
+ for (i = 0; i < LEN(rules); i++) {
+ if (regexec(&rules[i].regcomp, file, 0, NULL, 0) == 0)
+ return &rules[i];
}
return NULL;
}
void
-initassocs(void)
+parserules(void)
{
char errbuf[256];
int i, r;
- for (i = 0; i < LEN(assocs); i++) {
- r = regcomp(&assocs[i].regcomp, assocs[i].regex,
+ for (i = 0; i < LEN(rules); i++) {
+ r = regcomp(&rules[i].regcomp, rules[i].regex,
REG_NOSUB | REG_EXTENDED | REG_ICASE);
if (r != 0) {
- regerror(r, &assocs[i].regcomp, errbuf, sizeof(errbuf));
- fprintf(stderr, "invalid regex assocs[%d]: %s: %s\n",
- i, assocs[i].regex, errbuf);
+ regerror(r, &rules[i].regcomp, errbuf, sizeof(errbuf));
+ fprintf(stderr, "invalid regex rules[%d]: %s: %s\n",
+ i, rules[i].regex, errbuf);
exit(1);
}
}
@@ -87,13 +87,13 @@ main(int argc, char *argv[])
if (argc == 0)
usage();
- initassocs();
+ parserules();
for (; *argv != NULL; argv++) {
- struct assoc *assoc;
+ struct rule *rule;
- if ((assoc = openwith(argv[0])) == NULL)
+ if ((rule = matchrule(argv[0])) == NULL)
continue;
- run(assoc, argv[0]);
+ run(rule, argv[0]);
}
return 0;
}
diff --git a/nopenconf.def.h b/nopenconf.def.h
index 58c7569..b1c42f8 100644
--- a/nopenconf.def.h
+++ b/nopenconf.def.h
@@ -1,5 +1,7 @@
/* See LICENSE file for copyright and license details. */
-struct assoc assocs[] = {
+
+/* {} will be substituted with the actual argument when the rule is executed */
+struct rule rules[] = {
{ .regex = "\\.(avi|mp4|mkv|mp3|ogg|flac|mov)$", .file = "mpv", .argv = { "mpv", "{}", NULL } },
{ .regex = "\\.(png|jpg|gif)$", .file = "sxiv", .argv = { "sxiv", "{}", NULL} },
{ .regex = "\\.(html|svg)$", .file = "firefox", .argv = { "firefox", "{}", NULL } },
Un proyecto texto-plano.xyz