[BACK]Return to mandocdb.c CVS log [TXT][DIR] Up to [cvsweb.bsd.lv] / mandoc

Diff for /mandoc/mandocdb.c between version 1.60 and 1.63

version 1.60, 2013/06/05 20:27:11 version 1.63, 2013/06/06 15:15:07
Line 23 
Line 23 
   
 #include <assert.h>  #include <assert.h>
 #include <ctype.h>  #include <ctype.h>
   #include <errno.h>
 #include <fcntl.h>  #include <fcntl.h>
 #include <fts.h>  #include <fts.h>
 #include <getopt.h>  #include <getopt.h>
Line 140  static void  ofadd(int, const char *, const char *, co
Line 141  static void  ofadd(int, const char *, const char *, co
 static  void     offree(void);  static  void     offree(void);
 static  void     ofmerge(struct mchars *, struct mparse *);  static  void     ofmerge(struct mchars *, struct mparse *);
 static  void     parse_catpage(struct of *);  static  void     parse_catpage(struct of *);
 static  int      parse_man(struct of *,  static  void     parse_man(struct of *, const struct man_node *);
                         const struct man_node *);  
 static  void     parse_mdoc(struct of *, const struct mdoc_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_body(struct of *, const struct mdoc_node *);
 static  int      parse_mdoc_head(struct of *, const struct mdoc_node *);  static  int      parse_mdoc_head(struct of *, const struct mdoc_node *);
Line 1102  parse_catpage(struct of *of)
Line 1102  parse_catpage(struct of *of)
         if (NULL == title || '\0' == *title) {          if (NULL == title || '\0' == *title) {
                 if (warnings)                  if (warnings)
                         say(of->file, "Cannot find NAME section");                          say(of->file, "Cannot find NAME section");
                   putkey(of, of->name, TYPE_Nd);
                 fclose(stream);                  fclose(stream);
                 free(title);                  free(title);
                 return;                  return;
Line 1181  putmdockey(const struct of *of, const struct mdoc_node
Line 1182  putmdockey(const struct of *of, const struct mdoc_node
         }          }
 }  }
   
 static int  static void
 parse_man(struct of *of, const struct man_node *n)  parse_man(struct of *of, const struct man_node *n)
 {  {
         const struct man_node *head, *body;          const struct man_node *head, *body;
Line 1190  parse_man(struct of *of, const struct man_node *n)
Line 1191  parse_man(struct of *of, const struct man_node *n)
         size_t           sz, titlesz;          size_t           sz, titlesz;
   
         if (NULL == n)          if (NULL == n)
                 return(0);                  return;
   
         /*          /*
          * We're only searching for one thing: the first text child in           * We're only searching for one thing: the first text child in
Line 1232  parse_man(struct of *of, const struct man_node *n)
Line 1233  parse_man(struct of *of, const struct man_node *n)
                                 title[titlesz - 1] = ' ';                                  title[titlesz - 1] = ' ';
                         }                          }
                         if (NULL == title)                          if (NULL == title)
                                 return(1);                                  return;
   
                         title = mandoc_realloc(title, titlesz + 1);                          title = mandoc_realloc(title, titlesz + 1);
                         title[titlesz] = '\0';                          title[titlesz] = '\0';
Line 1245  parse_man(struct of *of, const struct man_node *n)
Line 1246  parse_man(struct of *of, const struct man_node *n)
   
                         if (0 == (sz = strlen(sv))) {                          if (0 == (sz = strlen(sv))) {
                                 free(title);                                  free(title);
                                 return(1);                                  return;
                         }                          }
   
                         /* Erase trailing space. */                          /* Erase trailing space. */
Line 1256  parse_man(struct of *of, const struct man_node *n)
Line 1257  parse_man(struct of *of, const struct man_node *n)
   
                         if (start == sv) {                          if (start == sv) {
                                 free(title);                                  free(title);
                                 return(1);                                  return;
                         }                          }
   
                         start = sv;                          start = sv;
Line 1293  parse_man(struct of *of, const struct man_node *n)
Line 1294  parse_man(struct of *of, const struct man_node *n)
                         if (sv == start) {                          if (sv == start) {
                                 putkey(of, start, TYPE_Nm);                                  putkey(of, start, TYPE_Nm);
                                 free(title);                                  free(title);
                                 return(1);                                  return;
                         }                          }
   
                         while (isspace((unsigned char)*start))                          while (isspace((unsigned char)*start))
Line 1317  parse_man(struct of *of, const struct man_node *n)
Line 1318  parse_man(struct of *of, const struct man_node *n)
                         of->desc = stradd(start);                          of->desc = stradd(start);
                         putkey(of, start, TYPE_Nd);                          putkey(of, start, TYPE_Nd);
                         free(title);                          free(title);
                         return(1);                          return;
                 }                  }
         }          }
   
         for (n = n->child; n; n = n->next)          for (n = n->child; n; n = n->next)
                 if (parse_man(of, n))                  parse_man(of, n);
                         return(1);  
   
         return(0);  
 }  }
   
 static void  static void
Line 1867  static void
Line 1865  static void
 dbclose(int real)  dbclose(int real)
 {  {
         size_t           i;          size_t           i;
         char             file[PATH_MAX];  
   
         if (nodb)          if (nodb)
                 return;                  return;
Line 1883  dbclose(int real)
Line 1880  dbclose(int real)
         if (real)          if (real)
                 return;                  return;
   
         strlcpy(file, MANDOC_DB, PATH_MAX);          if (-1 == rename(MANDOC_DB "~", MANDOC_DB)) {
         strlcat(file, "~", PATH_MAX);  
         if (-1 == rename(file, MANDOC_DB)) {  
                 exitcode = (int)MANDOCLEVEL_SYSERR;                  exitcode = (int)MANDOCLEVEL_SYSERR;
                 say(MANDOC_DB, NULL);                  say(MANDOC_DB, NULL);
         }          }
Line 1902  dbclose(int real)
Line 1897  dbclose(int real)
 static int  static int
 dbopen(int real)  dbopen(int real)
 {  {
         char             file[PATH_MAX];          const char      *file, *sql;
         const char      *sql;  
         int              rc, ofl;          int              rc, ofl;
         size_t           sz;  
   
         if (nodb)          if (nodb)
                 return(1);                  return(1);
   
         sz = strlcpy(file, MANDOC_DB, PATH_MAX);          ofl = SQLITE_OPEN_READWRITE;
         if ( ! real)          if (0 == real) {
                 sz = strlcat(file, "~", PATH_MAX);                  file = MANDOC_DB "~";
                   if (-1 == remove(file) && ENOENT != errno) {
         if (sz >= PATH_MAX) {                          exitcode = (int)MANDOCLEVEL_SYSERR;
                 fprintf(stderr, "%s: Path too long\n", file);                          say(file, NULL);
                 return(0);                          return(0);
         }                  }
                   ofl |= SQLITE_OPEN_EXCLUSIVE;
         if ( ! real)          } else
                 remove(file);                  file = MANDOC_DB;
   
         ofl = SQLITE_OPEN_READWRITE |  
                 (0 == real ? SQLITE_OPEN_EXCLUSIVE : 0);  
   
         rc = sqlite3_open_v2(file, &db, ofl, NULL);          rc = sqlite3_open_v2(file, &db, ofl, NULL);
         if (SQLITE_OK == rc)          if (SQLITE_OK == rc)

Legend:
Removed from v.1.60  
changed lines
  Added in v.1.63

CVSweb