aboutsummaryrefslogtreecommitdiff
path: root/definitions.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2021-09-27 20:36:10 -0700
committerBruce Hill <bruce@bruce-hill.com>2021-09-27 20:36:10 -0700
commit911827fac3a53734c9a4a99c1b8ec2a689bc59d8 (patch)
tree5ac9e27f065b66ad613fbcac21c95f8b64706310 /definitions.c
parenta96284615b27226f4d34de8dfa7235f0c14ac1d4 (diff)
Removed definitions as a separate type and instead encode that value in
the patterns themselves. This simplifies memory management a lot and speeds up performance.
Diffstat (limited to 'definitions.c')
-rw-r--r--definitions.c55
1 files changed, 0 insertions, 55 deletions
diff --git a/definitions.c b/definitions.c
deleted file mode 100644
index 590a801..0000000
--- a/definitions.c
+++ /dev/null
@@ -1,55 +0,0 @@
-//
-// definitions.c - Code for defining named pattern rules
-//
-
-#include <err.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "definitions.h"
-#include "pattern.h"
-#include "utils.h"
-
-static size_t next_id = 0;
-
-//
-// Return a new list of definitions with one added to the front
-//
-def_t *with_def(def_t *defs, size_t namelen, const char *name, pat_t *pat)
-{
- def_t *def = new(def_t);
- def->id = next_id++;
- def->next = defs;
- def->namelen = namelen;
- def->name = name;
- def->pat = pat;
- return def;
-}
-
-//
-// Look up a backreference or grammar definition by name
-//
-def_t *lookup(def_t *defs, size_t namelen, const char *name)
-{
- for ( ; defs; defs = defs->next) {
- if (namelen == defs->namelen && strncmp(defs->name, name, namelen) == 0)
- return defs;
- }
- return NULL;
-}
-
-//
-// Free all the given definitions up till (but not including) `stop`
-//
-def_t *free_defs(def_t *defs, def_t *stop)
-{
- while (defs != stop && defs != NULL) {
- def_t *next = defs->next;
- defs->next = NULL;
- delete(&defs);
- defs = next;
- }
- return defs;
-}
-
-// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0