version 1.4, 2015/07/25 14:02:06 |
version 1.5, 2015/07/25 14:28:59 |
|
|
} |
} |
|
|
/* |
/* |
* Return the line number where a term is defined, |
* Set the line number where a term is defined, |
* or 0 if the term is unknown. |
* unless it is already defined at a higher priority. |
*/ |
*/ |
size_t |
|
tag_get(const char *s, size_t len, int prio) |
|
{ |
|
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 || prio < entry->prio) ? 0 : entry->line); |
|
} |
|
|
|
/* |
|
* Set the line number where a term is defined. |
|
*/ |
|
void |
void |
tag_put(const char *s, size_t len, int prio, size_t line) |
tag_put(const char *s, int prio, size_t line) |
{ |
{ |
struct tag_entry *entry; |
struct tag_entry *entry; |
const char *end; |
size_t len; |
unsigned int slot; |
unsigned int slot; |
|
|
if (tag_fd == -1) |
if (tag_fd == -1) |
return; |
return; |
if (len == 0) |
slot = ohash_qlookup(&tag_data, s); |
len = strlen(s); |
|
end = s + len; |
|
slot = ohash_qlookupi(&tag_data, s, &end); |
|
entry = ohash_find(&tag_data, slot); |
entry = ohash_find(&tag_data, slot); |
if (entry == NULL) { |
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); |
memcpy(entry->s, s, len); |
entry->s[len] = '\0'; |
|
ohash_insert(&tag_data, slot, entry); |
ohash_insert(&tag_data, slot, entry); |
} |
} else if (entry->prio <= prio) |
|
return; |
entry->line = line; |
entry->line = line; |
entry->prio = prio; |
entry->prio = prio; |
} |
} |