=================================================================== RCS file: /cvs/mandoc/tag.c,v retrieving revision 1.22 retrieving revision 1.25 diff -u -p -r1.22 -r1.25 --- mandoc/tag.c 2019/07/10 19:39:01 1.22 +++ mandoc/tag.c 2019/07/27 13:40:57 1.25 @@ -1,4 +1,4 @@ -/* $Id: tag.c,v 1.22 2019/07/10 19:39:01 schwarze Exp $ */ +/* $Id: tag.c,v 1.25 2019/07/27 13:40:57 schwarze Exp $ */ /* * Copyright (c) 2015, 2016, 2018, 2019 Ingo Schwarze * @@ -53,7 +53,7 @@ static struct tag_files tag_files; * but for simplicity, create it anyway. */ struct tag_files * -tag_init(void) +tag_init(char *tagname) { struct sigaction sa; int ofd; @@ -61,6 +61,7 @@ tag_init(void) ofd = -1; tag_files.tfd = -1; tag_files.tcpgid = -1; + tag_files.tagname = tagname; /* Clean up when dying from a signal. */ @@ -129,6 +130,7 @@ fail: *tag_files.tfn = '\0'; tag_files.ofd = -1; tag_files.tfd = -1; + tag_files.tagname = NULL; return NULL; } @@ -151,11 +153,11 @@ tag_put(const char *s, int prio, size_t line) s += 2; /* - * Skip whitespace and whatever follows it, + * Skip whitespace and escapes and whatever follows, * and if there is any, downgrade the priority. */ - len = strcspn(s, " \t"); + len = strcspn(s, " \t\\"); if (len == 0) return; @@ -225,6 +227,7 @@ tag_write(void) struct tag_entry *entry; size_t i; unsigned int slot; + int empty; if (tag_files.tfd <= 0) return; @@ -235,12 +238,16 @@ tag_write(void) } if ((stream = fdopen(tag_files.tfd, "w")) == NULL) mandoc_msg(MANDOCERR_FDOPEN, 0, 0, "%s", strerror(errno)); + empty = 1; entry = ohash_first(&tag_data, &slot); while (entry != NULL) { - if (stream != NULL && entry->prio >= 0) - for (i = 0; i < entry->nlines; i++) + if (stream != NULL && entry->prio >= 0) { + for (i = 0; i < entry->nlines; i++) { fprintf(stream, "%s %s %zu\n", entry->s, tag_files.ofn, entry->lines[i]); + empty = 0; + } + } free(entry->lines); free(entry); entry = ohash_next(&tag_data, &slot); @@ -251,6 +258,10 @@ tag_write(void) else close(tag_files.tfd); tag_files.tfd = -1; + if (empty) { + unlink(tag_files.tfn); + *tag_files.tfn = '\0'; + } } void