=================================================================== RCS file: /cvs/mandoc/tag.c,v retrieving revision 1.3 retrieving revision 1.5 diff -u -p -r1.3 -r1.5 --- mandoc/tag.c 2015/07/21 03:26:22 1.3 +++ mandoc/tag.c 2015/07/25 14:28:59 1.5 @@ -1,4 +1,4 @@ -/* $Id: tag.c,v 1.3 2015/07/21 03:26:22 schwarze Exp $ */ +/* $Id: tag.c,v 1.5 2015/07/25 14:28:59 schwarze Exp $ */ /* * Copyright (c) 2015 Ingo Schwarze * @@ -34,6 +34,7 @@ struct tag_entry { size_t line; + int prio; char s[]; }; @@ -77,50 +78,29 @@ tag_init(void) } /* - * Return the line number where a term is defined, - * or 0 if the term is unknown. + * Set the line number where a term is defined, + * unless it is already defined at a higher priority. */ -size_t -tag_get(const char *s, size_t len) -{ - struct tag_entry *entry; - const char *end; - unsigned int slot; - - if (tag_fd == -1) - return(0); - if (len == 0) - len = strlen(s); - end = s + len; - slot = ohash_qlookupi(&tag_data, s, &end); - entry = ohash_find(&tag_data, slot); - return(entry == NULL ? 0 : entry->line); -} - -/* - * Set the line number where a term is defined. - */ void -tag_put(const char *s, size_t len, size_t line) +tag_put(const char *s, int prio, size_t line) { struct tag_entry *entry; - const char *end; + size_t len; unsigned int slot; if (tag_fd == -1) return; - if (len == 0) - len = strlen(s); - end = s + len; - slot = ohash_qlookupi(&tag_data, s, &end); + slot = ohash_qlookup(&tag_data, s); entry = ohash_find(&tag_data, slot); if (entry == NULL) { - entry = mandoc_malloc(sizeof(*entry) + len + 1); + len = strlen(s) + 1; + entry = mandoc_malloc(sizeof(*entry) + len); memcpy(entry->s, s, len); - entry->s[len] = '\0'; ohash_insert(&tag_data, slot, entry); - } + } else if (entry->prio <= prio) + return; entry->line = line; + entry->prio = prio; } /*