summary refs log tree commit diff
path: root/tab.c
diff options
context:
space:
mode:
Diffstat (limited to 'tab.c')
-rw-r--r--tab.c31
1 files changed, 24 insertions, 7 deletions
diff --git a/tab.c b/tab.c
index 87e4f02..a242365 100644
--- a/tab.c
+++ b/tab.c
@@ -47,14 +47,16 @@ static void touch(struct Entry *entry) {
 	prepend(entry);
 }
 
-void tabTouch(struct Tag tag, const char *word) {
+static struct Entry *find(struct Tag tag, const char *word) {
 	for (struct Entry *entry = head; entry; entry = entry->next) {
 		if (entry->tag.id != tag.id) continue;
 		if (strcmp(entry->word, word)) continue;
-		touch(entry);
-		return;
+		return entry;
 	}
+	return NULL;
+}
 
+static void add(struct Tag tag, const char *word) {
 	struct Entry *entry = malloc(sizeof(*entry));
 	if (!entry) err(EX_OSERR, "malloc");
 
@@ -65,11 +67,26 @@ void tabTouch(struct Tag tag, const char *word) {
 	prepend(entry);
 }
 
+void tabTouch(struct Tag tag, const char *word) {
+	struct Entry *entry = find(tag, word);
+	if (entry) {
+		touch(entry);
+	} else {
+		add(tag, word);
+	}
+}
+
+void tabAdd(struct Tag tag, const char *word) {
+	if (!find(tag, word)) add(tag, word);
+}
+
 void tabReplace(struct Tag tag, const char *prev, const char *next) {
-	tabTouch(tag, prev);
-	free(head->word);
-	head->word = strdup(next);
-	if (!head->word) err(EX_OSERR, "strdup");
+	struct Entry *entry = find(tag, prev);
+	if (!entry) return;
+	touch(entry);
+	free(entry->word);
+	entry->word = strdup(next);
+	if (!entry->word) err(EX_OSERR, "strdup");
 }
 
 static struct Entry *iter;
ea1b14a7f44ffe29503e2ad59&follow=1'>html: remove redundant htmlfd variableJohn Keeping 2014-01-12tests: add Valgrind supportJohn Keeping 2014-01-12cache: don't leave cache_slot fields uninitializedJohn Keeping 2014-01-10filter: split filter functions into their own fileJason A. Donenfeld 2014-01-10filter: make exit status localJason A. Donenfeld 2014-01-10parsing: fix header typoJason A. Donenfeld 2014-01-10cgit.c: Fix comment on bit mask hackLukas Fleischer 2014-01-10cgit.c: Use "else" for mutually exclusive branchesLukas Fleischer 2014-01-10ui-snapshot.c: Do not reinvent suffixcmp()Lukas Fleischer 2014-01-10Refactor cgit_parse_snapshots_mask()Lukas Fleischer 2014-01-10Disallow use of undocumented snapshot delimitersLukas Fleischer 2014-01-10Replace most uses of strncmp() with prefixcmp()Lukas Fleischer 2014-01-09README: Fix dependenciesLukas Fleischer 2014-01-08README: Spelling and formatting fixesLukas Fleischer 2014-01-08Fix UTF-8 with syntax-highlighting.pyPřemysl Janouch 2014-01-08Add a suggestion to the manpagePřemysl Janouch 2014-01-08Fix the example configurationPřemysl Janouch 2014-01-08Fix about-formatting.shPřemysl Janouch 2014-01-08Fix some spelling errorsPřemysl Janouch 2014-01-08filters: highlight.sh: add css comments for highlight 2.6 and 3.8Ferry Huberts