* mdocml: Have exprcomp() accept a string instead of an array-pointer.
@ 2011-11-14 10:07 kristaps
0 siblings, 0 replies; only message in thread
From: kristaps @ 2011-11-14 10:07 UTC (permalink / raw)
To: source
Log Message:
-----------
Have exprcomp() accept a string instead of an array-pointer. Also, collapse
the arguments in apropos(1) into a single string passed to exprcomp(). Ok
schwarze@.
Modified Files:
--------------
mdocml:
apropos.c
apropos_db.c
apropos_db.h
Revision Data
-------------
Index: apropos_db.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/apropos_db.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -Lapropos_db.c -Lapropos_db.c -u -p -r1.3 -r1.4
--- apropos_db.c
+++ apropos_db.c
@@ -454,23 +454,23 @@ out:
}
struct expr *
-exprcomp(int argc, char *argv[])
+exprcomp(char *buf)
{
struct expr *p;
struct expr e;
char *key;
int i, icase;
- if (0 >= argc)
+ if ('\0' == *buf)
return(NULL);
/*
* Choose regex or substring match.
*/
- if (NULL == (e.v = strpbrk(*argv, "=~"))) {
+ if (NULL == (e.v = strpbrk(buf, "=~"))) {
e.regex = 0;
- e.v = *argv;
+ e.v = buf;
} else {
e.regex = '~' == *e.v;
*e.v++ = '\0';
@@ -482,15 +482,15 @@ exprcomp(int argc, char *argv[])
icase = 0;
e.mask = 0;
- if (*argv < e.v) {
- while (NULL != (key = strsep(argv, ","))) {
+ if (buf < e.v) {
+ while (NULL != (key = strsep(&buf, ","))) {
if ('i' == key[0] && '\0' == key[1]) {
icase = REG_ICASE;
continue;
}
i = 0;
while (types[i].mask &&
- strcmp(types[i].name, key))
+ strcmp(types[i].name, key))
i++;
e.mask |= types[i].mask;
}
Index: apropos_db.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/apropos_db.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -Lapropos_db.h -Lapropos_db.h -u -p -r1.3 -r1.4
--- apropos_db.h
+++ apropos_db.h
@@ -49,7 +49,7 @@ void apropos_search(const struct opts
const struct expr *, void *,
void (*)(struct rec *, size_t, void *));
-struct expr *exprcomp(int, char *[]);
+struct expr *exprcomp(char *);
void exprfree(struct expr *);
__END_DECLS
Index: apropos.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/apropos.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -Lapropos.c -Lapropos.c -u -p -r1.12 -r1.13
--- apropos.c
+++ apropos.c
@@ -14,6 +14,10 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
#include <assert.h>
#include <getopt.h>
#include <limits.h>
@@ -34,6 +38,8 @@ int
main(int argc, char *argv[])
{
int ch;
+ size_t sz;
+ char *buf;
struct opts opts;
struct expr *e;
extern int optind;
@@ -66,10 +72,31 @@ main(int argc, char *argv[])
if (0 == argc)
return(EXIT_SUCCESS);
- if (NULL == (e = exprcomp(argc, argv))) {
+ /*
+ * Collapse expressions into a single string.
+ * First count up the contained strings, adding a space at the
+ * end of each (plus nil-terminator). Then merge.
+ */
+
+ for (sz = 0, ch = 0; ch < argc; ch++)
+ sz += strlen(argv[ch]) + 1;
+
+ buf = mandoc_malloc(++sz);
+
+ for (*buf = '\0', ch = 0; ch < argc; ch++) {
+ strlcat(buf, argv[ch], sz);
+ strlcat(buf, " ", sz);
+ }
+
+ buf[sz - 2] = '\0';
+
+ if (NULL == (e = exprcomp(buf))) {
fprintf(stderr, "Bad expression\n");
+ free(buf);
return(EXIT_FAILURE);
}
+
+ free(buf);
/*
* Configure databases.
--
To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2011-11-14 10:07 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-14 10:07 mdocml: Have exprcomp() accept a string instead of an array-pointer kristaps
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).