summaryrefslogtreecommitdiff
path: root/lib/lower.c
diff options
context:
space:
mode:
authorColin Watson <cjwatson@debian.org>2008-12-25 22:13:50 +0000
committerColin Watson <cjwatson@debian.org>2008-12-25 22:13:50 +0000
commit781ef4365df1a0d0ec933a0d36aa1c169d5bb1be (patch)
tree50966ada3a3f97d337920eed8bf52816e0d2655a /lib/lower.c
parent6d3160551534c6a83d03c45c284b8ed566b821b4 (diff)
Add regular expression and shell wildcard search facilities to man
(Debian bug #461319). * src/whatis.c (lower): Move to ... * lib/lower.c: ... here, with optimisation from name_to_key. New file. * lib/lower.h: New file. * src/whatis.c (word_fnmatch): Move to ... * lib/wordfnmatch.c: ... here, with more generic argument names. New file. * lib/wordfnmatch.h: New file. * src/whatis.c (main): Factor regcomp error handling out to ... * lib/xregcomp.c: ... here. New file. * lib/xregcomp.h: New file. * lib/Makefile.am (libman_a_SOURCES): Add lower.c, lower.h, wordfnmatch.c, wordfnmatch.h, xregcomp.c, and xregcomp.h. * po/POTFILES.in: Add lib/xregcomp.c; remove src/globbing.c. * libdb/db_lookup.c (name_to_key): Use lower. (dblookup_pattern): New function. * libdb/db_storage.h (dblookup_pattern): Add prototype. * src/globbing.c (end_pattern): Rename to ... (make_pattern): ... this. Create the whole pattern rather than merely appending section or extension components. Handle regexes if the new opts argument has the LFF_REGEX bit set. (match_in_directory): Take an opts disjunction rather than a boolean ignore_case argument; ignore_case is replaced by the LFF_MATCHCASE bit being unset. Handle regexes if opts has the LFF_REGEX bit set. (look_for_file): Take an opts disjunction rather than a boolean match_case argument; match_case is replaced by the LFF_MATCHCASE bit being set. Handle regexes if opts has the LFF_REGEX bit set. Handle shell wildcards if opts has the LFF_WILDCARD bit set (which simply means not shell-escaping unesc_name). Call make_pattern rather than end_pattern (with appropriate adjustments). * src/globbing.h (enum look_for_file_opts): New enumeration. (look_for_file): Update prototype. * src/globbing_test.c (options, parse_opt): Accept -r/--regex and -w/--wildcard. (main): Update look_for_file arguments, including passing LFF_REGEX or LFF_WILDCARD if the corresponding options are used. * src/check_mandirs.c (purge_whatis, purge_missing), src/zsoelim.l (zsoelim_open_file): Update look_for_file arguments. * src/whatis.c (main): Only free preg if a regular expression was compiled into it in the first place. * src/man.c (options, parse_opt): Accept --regex, --wildcard, and --names-only. Reset corresponding variables with -D. Refuse to accept both --regex and --wildcard. (try_section): Update look_for_file arguments, including passing LFF_REGEX or LFF_WILDCARD if the corresponding options are used. (try_db): Use dblookup_pattern if --regex or --wildcard is used, with corresponding options. * man/man1/man.man1 (SYNOPSIS, Finding manual pages): Document --regex, --wildcard, and --names-only.
Diffstat (limited to 'lib/lower.c')
-rw-r--r--lib/lower.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/lib/lower.c b/lib/lower.c
new file mode 100644
index 00000000..e620fb7c
--- /dev/null
+++ b/lib/lower.c
@@ -0,0 +1,47 @@
+/*
+ * lower.c: return lower-case copy of a string
+ *
+ * Copyright (C) 1994, 1995 Graeme W. Wilford. (Wilf.)
+ * Copyright (C) 2003, 2008 Colin Watson.
+ *
+ * This file is part of man-db.
+ *
+ * man-db is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * man-db is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with man-db; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif /* HAVE_CONFIG_H */
+
+#include <string.h>
+#include <ctype.h>
+
+#include "manconfig.h"
+
+#include "lower.h"
+
+/* return lowered version of s */
+char *lower (const char *s)
+{
+ char *low, *p;
+
+ p = low = xmalloc (strlen (s) + 1);
+
+ while (*s)
+ *p++ = CTYPE (tolower, *s++);
+
+ *p = *s;
+ return low;
+}