Skip to content

Commit

Permalink
makemandb.c: Added conditional code to pmdoc_Sh and pmdoc.Nm to handl…
Browse files Browse the repository at this point in the history
…e .Nm macros in the DESCRIPTION section.

closes #4
  • Loading branch information
abhinav-upadhyay committed Jun 15, 2011
1 parent 934b1a1 commit bbdab19
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions makemandb.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ traversedir(const char *file)
if (S_ISREG(sb.st_mode)) {
pmdoc(file);
printf("parsing %s\n", file);
//printf("%s\n", desc);
if (insert_into_db() < 0)
fprintf(stderr, "Error indexing: %s\n", file);
return;
Expand Down Expand Up @@ -299,6 +300,12 @@ pmdoc_Nm(const struct mdoc_node *n)
return;
}
}
else if (n->sec == SEC_DESCRIPTION && name != NULL) {
if (desc == NULL)
desc = strdup(name);
else
asprintf(&desc, "%s %s", desc, name);
}
}

/*
Expand Down Expand Up @@ -333,27 +340,28 @@ pmdoc_Nd(const struct mdoc_node *n)
static void
pmdoc_Sh(const struct mdoc_node *n)
{
char *buf = NULL;


if (n->sec == SEC_DESCRIPTION) {
for(n = n->child; n; n = n->next) {
if (n->type == MDOC_TEXT) {
if (buf == NULL)
buf = strdup(n->string);
if (desc == NULL)
desc = strdup(n->string);
else
asprintf(&buf, "%s %s ", buf, n->string);
asprintf(&desc, "%s %s ", desc, n->string);
}
else {
pmdoc_Sh(n);
/* On encountering a .Nm macro, substitute it with it's previously
* cached value of the argument
*/
if (mdocs[n->tok] == pmdoc_Nm && name != NULL)
(*mdocs[n->tok])(n);
else
/* call pmdoc_Sh again to handle the nested macros */
pmdoc_Sh(n);
}
}
}

if (buf) {
desc = strdup(buf);
free(buf);
}

}

/* cleanup --
Expand Down Expand Up @@ -470,7 +478,6 @@ create_db(void)
rc = sqlite3_open_v2("apropos.db", &db, SQLITE_OPEN_READWRITE |
SQLITE_OPEN_CREATE, NULL);
if (rc != SQLITE_OK) {
printf("open\n");
sqlite3_close(db);
sqlite3_shutdown();
return -1;
Expand All @@ -480,15 +487,13 @@ create_db(void)
tokenize=porter)";
rc = sqlite3_prepare_v2(db, sqlstr, -1, &stmt, NULL);
if (rc != SQLITE_OK) {
printf("prepare\n");
sqlite3_close(db);
sqlite3_shutdown();
return -1;
}

rc = sqlite3_step(stmt);
if (rc != SQLITE_DONE) {
printf("step\n");
sqlite3_finalize(stmt);
sqlite3_close(db);
sqlite3_shutdown();
Expand All @@ -500,6 +505,3 @@ create_db(void)
sqlite3_shutdown();
return 0;
}



0 comments on commit bbdab19

Please sign in to comment.