=================================================================== RCS file: /cvs/mandoc/mandocdb.c,v retrieving revision 1.60 retrieving revision 1.63 diff -u -p -r1.60 -r1.63 --- mandoc/mandocdb.c 2013/06/05 20:27:11 1.60 +++ mandoc/mandocdb.c 2013/06/06 15:15:07 1.63 @@ -1,4 +1,4 @@ -/* $Id: mandocdb.c,v 1.60 2013/06/05 20:27:11 schwarze Exp $ */ +/* $Id: mandocdb.c,v 1.63 2013/06/06 15:15:07 schwarze Exp $ */ /* * Copyright (c) 2011, 2012 Kristaps Dzonsons * Copyright (c) 2011, 2012, 2013 Ingo Schwarze @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -140,8 +141,7 @@ static void ofadd(int, const char *, const char *, co static void offree(void); static void ofmerge(struct mchars *, struct mparse *); static void parse_catpage(struct of *); -static int parse_man(struct of *, - const struct man_node *); +static void parse_man(struct of *, const struct man_node *); static void parse_mdoc(struct of *, const struct mdoc_node *); static int parse_mdoc_body(struct of *, const struct mdoc_node *); static int parse_mdoc_head(struct of *, const struct mdoc_node *); @@ -1102,6 +1102,7 @@ parse_catpage(struct of *of) if (NULL == title || '\0' == *title) { if (warnings) say(of->file, "Cannot find NAME section"); + putkey(of, of->name, TYPE_Nd); fclose(stream); free(title); return; @@ -1181,7 +1182,7 @@ putmdockey(const struct of *of, const struct mdoc_node } } -static int +static void parse_man(struct of *of, const struct man_node *n) { const struct man_node *head, *body; @@ -1190,7 +1191,7 @@ parse_man(struct of *of, const struct man_node *n) size_t sz, titlesz; if (NULL == n) - return(0); + return; /* * We're only searching for one thing: the first text child in @@ -1232,7 +1233,7 @@ parse_man(struct of *of, const struct man_node *n) title[titlesz - 1] = ' '; } if (NULL == title) - return(1); + return; title = mandoc_realloc(title, titlesz + 1); title[titlesz] = '\0'; @@ -1245,7 +1246,7 @@ parse_man(struct of *of, const struct man_node *n) if (0 == (sz = strlen(sv))) { free(title); - return(1); + return; } /* Erase trailing space. */ @@ -1256,7 +1257,7 @@ parse_man(struct of *of, const struct man_node *n) if (start == sv) { free(title); - return(1); + return; } start = sv; @@ -1293,7 +1294,7 @@ parse_man(struct of *of, const struct man_node *n) if (sv == start) { putkey(of, start, TYPE_Nm); free(title); - return(1); + return; } while (isspace((unsigned char)*start)) @@ -1317,15 +1318,12 @@ parse_man(struct of *of, const struct man_node *n) of->desc = stradd(start); putkey(of, start, TYPE_Nd); free(title); - return(1); + return; } } for (n = n->child; n; n = n->next) - if (parse_man(of, n)) - return(1); - - return(0); + parse_man(of, n); } static void @@ -1867,7 +1865,6 @@ static void dbclose(int real) { size_t i; - char file[PATH_MAX]; if (nodb) return; @@ -1883,9 +1880,7 @@ dbclose(int real) if (real) return; - strlcpy(file, MANDOC_DB, PATH_MAX); - strlcat(file, "~", PATH_MAX); - if (-1 == rename(file, MANDOC_DB)) { + if (-1 == rename(MANDOC_DB "~", MANDOC_DB)) { exitcode = (int)MANDOCLEVEL_SYSERR; say(MANDOC_DB, NULL); } @@ -1902,28 +1897,23 @@ dbclose(int real) static int dbopen(int real) { - char file[PATH_MAX]; - const char *sql; + const char *file, *sql; int rc, ofl; - size_t sz; if (nodb) return(1); - sz = strlcpy(file, MANDOC_DB, PATH_MAX); - if ( ! real) - sz = strlcat(file, "~", PATH_MAX); - - if (sz >= PATH_MAX) { - fprintf(stderr, "%s: Path too long\n", file); - return(0); - } - - if ( ! real) - remove(file); - - ofl = SQLITE_OPEN_READWRITE | - (0 == real ? SQLITE_OPEN_EXCLUSIVE : 0); + ofl = SQLITE_OPEN_READWRITE; + if (0 == real) { + file = MANDOC_DB "~"; + if (-1 == remove(file) && ENOENT != errno) { + exitcode = (int)MANDOCLEVEL_SYSERR; + say(file, NULL); + return(0); + } + ofl |= SQLITE_OPEN_EXCLUSIVE; + } else + file = MANDOC_DB; rc = sqlite3_open_v2(file, &db, ofl, NULL); if (SQLITE_OK == rc)