From 1232ce451de8372a54e477882ed9e7cfa129c4b9 Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Sun, 12 Aug 2018 23:55:12 -0400 Subject: Factor out input param and add tagFind So that /view can't just invent tags. --- tag.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'tag.c') diff --git a/tag.c b/tag.c index 397c191..4a89d31 100644 --- a/tag.c +++ b/tag.c @@ -37,11 +37,17 @@ static struct Tag Tag(size_t id) { return (struct Tag) { id, tags.name[id] }; } -struct Tag tagFor(const char *name) { +struct Tag tagFind(const char *name) { for (size_t id = 0; id < tags.len; ++id) { if (strcmp(tags.name[id], name)) continue; return Tag(id); } + return TAG_NONE; +} + +struct Tag tagFor(const char *name) { + struct Tag tag = tagFind(name); + if (tag.id != TAG_NONE.id) return tag; if (tags.len == TAGS_LEN) return TAG_STATUS; size_t id = tags.len++; tags.name[id] = strdup(name); -- cgit 1.4.1