NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: bin/51062: Allow non numeric sections to be indexed and searched by apropos(1)
The following reply was made to PR bin/51062; it has been noted by GNATS.
From: Abhinav Upadhyay <er.abhinav.upadhyay%gmail.com@localhost>
To: NetBSD GNATS <gnats-bugs%netbsd.org@localhost>
Cc: gnats-admin%netbsd.org@localhost, netbsd-bugs%netbsd.org@localhost
Subject: Re: bin/51062: Allow non numeric sections to be indexed and searched
by apropos(1)
Date: Wed, 13 Apr 2016 12:21:18 +0530
On Wed, Apr 13, 2016 at 12:00 PM, Abhinav Upadhyay
<er.abhinav.upadhyay%gmail.com@localhost> wrote:
> The following reply was made to PR bin/51062; it has been noted by GNATS.
>
> From: Abhinav Upadhyay <er.abhinav.upadhyay%gmail.com@localhost>
> To: Christos Zoulas <christos%zoulas.com@localhost>
> Cc: NetBSD GNATS <gnats-bugs%netbsd.org@localhost>, gnats-admin%netbsd.org@localhost, netbsd-bugs%netbsd.org@localhost
> Subject: Re: bin/51062: Allow non numeric sections to be indexed and searched
> by apropos(1)
> Date: Wed, 13 Apr 2016 11:55:55 +0530
>
> --001a113d1980ac3ad4053057d91c
> Content-Type: text/plain; charset=UTF-8
>
> On Wed, Apr 13, 2016 at 7:15 AM, Christos Zoulas <christos%zoulas.com@localhost> wrote:
> > On Apr 12, 3:40pm, er.abhinav.upadhyay%gmail.com@localhost (er.abhinav.upadhyay%gmail.com@localhost) wrote:
> > -- Subject: bin/51062: Allow non numeric sections to be indexed and searched
> >
> > | >Number: 51062
> > | >Category: bin
> > | >Synopsis: Allow non numeric sections to be indexed and searched by apropos(1)
> > | >Confidential: no
> > | >Severity: non-critical
> > | >Priority: medium
> > | >Responsible: bin-bug-people
> > | >State: open
> > | >Class: sw-bug
> > | >Submitter-Id: net
> > | >Arrival-Date: Tue Apr 12 15:40:00 +0000 2016
> > | >Originator: Abhinav Upadhyay
> > | >Release: CURRENT
> > | >Organization:
> > | >Environment:
> > | >Description:
> > | Apropos(1) doesn't allow searching for man pages in non-numeric sections. Also, makemandb(8) indexes only the first character of the section number and drops everything else.
> > |
> > |
> > | The attached patch fixes both the problems. It also includes changes for tickets bin/51038, bin/51039, and bin/51040.
> > |
> > | I can probably send a smaller patch if there is no interest in the aforementioned patches :)
> > | >How-To-Repeat:
> > | apropos -s 9lua systm
> > |
> >
> > Please don't mix other patches together. Resubmit just the relevant change,
>
> Hi Christos,
>
> Thanks for committing the other patches. I have updated the patch and
> attached with the email.
>
Looks like gmail messed up the patch in the attachment. Posting it inline:
Index: apropos-utils.c
===================================================================
RCS file: /cvsroot/src/usr.sbin/makemandb/apropos-utils.c,v
retrieving revision 1.23
diff -u -r1.23 apropos-utils.c
--- apropos-utils.c 13 Apr 2016 01:37:50 -0000 1.23
+++ apropos-utils.c 13 Apr 2016 06:02:20 -0000
@@ -474,7 +474,7 @@
}
/*
- * run_query --
+ * run_query_internal --
* Performs the searches for the keywords entered by the user.
* The 2nd param: snippet_args is an array of strings providing values for the
* last three parameters to the snippet function of sqlite. (Look at
the docs).
@@ -525,15 +525,20 @@
* 2. I am using LIKE operator because '=' or IN operators do not
seem to be
* working with the compression option enabled.
*/
+ char *sections_str = args->sec_nums;
+ char *temp;
+ if (sections_str) {
+ while (*sections_str) {
+ size_t len = strcspn(sections_str, " ");
+ char *sec = sections_str;
+ if (sections_str[len] == 0) {
+ sections_str += len;
+ } else {
+ sections_str[len] = 0;
+ sections_str += len + 1;
+ }
+ easprintf(&temp, "\'%s\',", sec);
- if (args->sec_nums) {
- char *temp;
- int i;
-
- for (i = 0; i < SECMAX; i++) {
- if (args->sec_nums[i] == 0)
- continue;
- easprintf(&temp, " OR section = \'%d\'", i + 1);
if (section_clause) {
concat(§ion_clause, temp);
free(temp);
@@ -544,10 +549,13 @@
if (section_clause) {
/*
* At least one section requested, add glue for query.
+ * Before doing that, remove the comma at the end of section_clause
*/
+ size_t section_clause_len = strlen(section_clause);
+ if (section_clause[section_clause_len - 1] == ',')
+ section_clause[section_clause_len - 1] = 0;
temp = section_clause;
- /* Skip " OR " before first term. */
- easprintf(§ion_clause, " AND (%s)", temp + 4);
+ easprintf(§ion_clause, " AND section IN (%s)", temp);
free(temp);
}
}
Index: apropos-utils.h
===================================================================
RCS file: /cvsroot/src/usr.sbin/makemandb/apropos-utils.h,v
retrieving revision 1.10
diff -u -r1.10 apropos-utils.h
--- apropos-utils.h 13 Apr 2016 01:37:50 -0000 1.10
+++ apropos-utils.h 13 Apr 2016 06:02:21 -0000
@@ -36,7 +36,6 @@
#include "sqlite3.h"
#define MANCONF "/etc/man.conf"
-#define SECMAX 9
/* Flags for opening the database */
typedef enum mandb_access_mode {
@@ -74,7 +73,7 @@
typedef struct query_args {
const char *search_str; // user query
- int *sec_nums; // Section in which to do the search
+ char *sec_nums; // Section in which to do the search
int nrec; // number of records to fetch
int offset; //From which position to start processing the records
int legacy;
Index: apropos.c
===================================================================
RCS file: /cvsroot/src/usr.sbin/makemandb/apropos.c,v
retrieving revision 1.18
diff -u -r1.18 apropos.c
--- apropos.c 31 Mar 2016 20:13:37 -0000 1.18
+++ apropos.c 13 Apr 2016 06:02:21 -0000
@@ -43,7 +43,7 @@
#include "apropos-utils.h"
typedef struct apropos_flags {
- int sec_nums[SECMAX];
+ char *sec_nums;
int nresults;
int pager;
int no_context;
@@ -58,6 +58,8 @@
apropos_flags *aflags;
} callback_data;
+static const unsigned int sections_args_length = 16;
+
static char *remove_stopwords(const char *);
static int query_callback(void *, const char * , const char *, const char *,
const char *, size_t);
@@ -69,6 +71,7 @@
parseargs(int argc, char **argv, struct apropos_flags *aflags)
{
int ch;
+ char sec[2] = {0, 0};
while ((ch = getopt(argc, argv, "123456789Cchiln:PprS:s:")) != -1) {
switch (ch) {
case '1':
@@ -80,7 +83,13 @@
case '7':
case '8':
case '9':
- aflags->sec_nums[ch - '1'] = 1;
+ /* Generate a space separated list of all the requested sections */
+ sec[0] = (char) ch ;
+ if (aflags->sec_nums == NULL) {
+ aflags->sec_nums = emalloc(sections_args_length);
+ memcpy(aflags->sec_nums, sec, 2);
+ } else
+ concat2(&aflags->sec_nums, sec, 1);
break;
case 'C':
aflags->no_context = 1;
@@ -115,10 +124,12 @@
aflags->machine = optarg;
break;
case 's':
- ch = atoi(optarg);
- if (ch < 1 || ch > 9)
- errx(EXIT_FAILURE, "Invalid section");
- aflags->sec_nums[ch - 1] = 1;
+ if (aflags->sec_nums == NULL) {
+ size_t arglen = strlen(optarg);
+ aflags->sec_nums = arglen > sections_args_length?
emalloc(arglen + 1): emalloc(sections_args_length);
+ memcpy(aflags->sec_nums, optarg, arglen + 1);
+ } else
+ concat(&aflags->sec_nums, optarg);
break;
case '?':
default:
@@ -140,6 +151,7 @@
cbdata.out = stdout; // the default output stream
cbdata.count = 0;
apropos_flags aflags;
+ aflags.sec_nums = NULL;
cbdata.aflags = &aflags;
sqlite3 *db;
setprogname(argv[0]);
@@ -169,12 +181,6 @@
parseargs(argc, argv, &aflags);
- /*
- * If the user specifies a section number as an option, the
- * corresponding index element in sec_nums is set to the string
- * representing that section number.
- */
-
argc -= optind;
argv += optind;
@@ -232,6 +238,7 @@
fprintf(cbdata.out, "</table>\n</body>\n</html>\n");
free(query);
+ free(aflags.sec_nums);
close_db(db);
if (errmsg) {
warnx("%s", errmsg);
Index: makemandb.c
===================================================================
RCS file: /cvsroot/src/usr.sbin/makemandb/makemandb.c,v
retrieving revision 1.36
diff -u -r1.36 makemandb.c
--- makemandb.c 13 Apr 2016 01:41:18 -0000 1.36
+++ makemandb.c 13 Apr 2016 06:02:22 -0000
@@ -71,7 +71,7 @@
secbuff exit_status; // EXIT STATUS
secbuff diagnostics; // DIAGNOSTICS
secbuff errors; // ERRORS
- char section[2];
+ char *section;
int xr_found; // To track whether a .Xr was seen when parsing a section
@@ -774,7 +774,7 @@
rc = sqlite3_prepare_v2(db, sqlstr, -1, &stmt, NULL);
if (rc != SQLITE_OK) {
if (mflags.verbosity)
- warnx("%s", sqlite3_errmsg(db));
+ warnx("%s", sqlite3_errmsg(db));
close_db(db);
errx(EXIT_FAILURE, "Could not query file cache");
}
@@ -954,15 +954,15 @@
if (md) {
const struct mdoc_meta *md_meta = mdoc_meta(md);
if (md_meta->msec == NULL) {
- rec->section[0] = '?';
+ easprintf(&rec->section, "%s", "?");
} else
- rec->section[0] = md_meta->msec[0];
+ rec->section = estrdup(md_meta->msec);
} else if (m) {
const struct man_meta *m_meta = man_meta(m);
if (m_meta->msec == NULL)
- rec->section[0] = '?';
+ easprintf(&rec->section, "%s", "?");
else
- rec->section[0] = m_meta->msec[0];
+ rec->section = estrdup(m_meta->msec);
} else
return;
@@ -1583,7 +1583,7 @@
char *tmp;
rec->links = estrdup(rec->name);
free(rec->name);
- int sz = strcspn(rec->links, " \0");
+ size_t sz = strcspn(rec->links, " \0");
rec->name = emalloc(sz + 1);
memcpy(rec->name, rec->links, sz);
if(rec->name[sz - 1] == ',')
@@ -1989,6 +1989,9 @@
free(rec->md5_hash);
rec->md5_hash = NULL;
+
+ free(rec->section);
+ rec->section = NULL;
}
/*
Home |
Main Index |
Thread Index |
Old Index