summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Watson <cjwatson@debian.org>2022-09-23 22:56:44 +0100
committerColin Watson <cjwatson@debian.org>2022-09-23 22:56:45 +0100
commitfdf2f3db554c777cf40d7e26b947f33a67b67b46 (patch)
treebb28c26a7c7aa03233fd1637bdb0f0b737490562
parentc75db17332c9154c0b1648e022e0f2d6f4ca6e7a (diff)
Move manual page file name utilities to lib/
* src/filenames.c: Move to ... * lib/filenames.c: ... here. * src/filenames.h: Move to ... * lib/filenames.h: ... here. Update positioning of all includes. * lib/Makefile.am (libman_la_SOURCES): Add `filenames.c` and `filenames.h`. * src/Makefile.am (man_recode_LDADD): Link with `$(LIBMAN)` instead of `$(LIBMANDB)`. (lexgrog_SOURCES, man_SOURCES, mandb_SOURCES): Remove `filenames.c` and `filenames.h`. * po/POTFILES.in: Rename `src/filenames.c` to `lib/filenames.c`. * lib/filenames.c (gripe_bogus_manpage): Remove `quiet < 2` condition. (filename_info): Add `warn_if_bogus` parameter; only call `gripe_bogus_manpage` if it is set. Update all callers. * lib/filename.h (filename_info): Update prototype. * libdb/db_storage.h (struct mandata): Move to ... * lib/filenames.h (struct mandata): ... here. Add includes where necessary.
-rw-r--r--lib/Makefile.am2
-rw-r--r--lib/filenames.c (renamed from src/filenames.c)21
-rw-r--r--lib/filenames.h (renamed from src/filenames.h)32
-rw-r--r--libdb/db_delete.c1
-rw-r--r--libdb/db_lookup.c1
-rw-r--r--libdb/db_storage.h21
-rw-r--r--libdb/db_store.c1
-rw-r--r--po/POTFILES.in2
-rw-r--r--src/Makefile.am8
-rw-r--r--src/catman.c1
-rw-r--r--src/check_mandirs.c6
-rw-r--r--src/descriptions.h4
-rw-r--r--src/descriptions_store.c6
-rw-r--r--src/man.c8
-rw-r--r--src/mandb.c5
-rw-r--r--src/straycats.c1
-rw-r--r--src/whatis.c1
17 files changed, 67 insertions, 54 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 449f3356..8623ea44 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -44,6 +44,8 @@ libman_la_SOURCES = \
encodings.h \
fatal.c \
fatal.h \
+ filenames.c \
+ filenames.h \
glcontainers.c \
glcontainers.h \
linelength.c \
diff --git a/src/filenames.c b/lib/filenames.c
index 83e09069..f794c045 100644
--- a/src/filenames.c
+++ b/lib/filenames.c
@@ -25,8 +25,9 @@
# include "config.h"
#endif /* HAVE_CONFIG_H */
-#include <string.h>
+#include <stdbool.h>
#include <stdlib.h>
+#include <string.h>
#include <unistd.h>
#include "error.h"
@@ -41,16 +42,11 @@
#include "appendstr.h"
#include "compression.h"
#include "debug.h"
-
-#include "db_storage.h"
-
#include "filenames.h"
static void gripe_bogus_manpage (const char *manpage)
{
- if (quiet < 2)
- error (0, 0, _("warning: %s: ignoring bogus filename"),
- manpage);
+ error (0, 0, _("warning: %s: ignoring bogus filename"), manpage);
}
char *make_filename (const char *path, const char *name,
@@ -90,7 +86,7 @@ char *make_filename (const char *path, const char *name,
* NULL.
*/
char *filename_info (const char *file, struct mandata *info,
- const char *req_name)
+ const char *req_name, bool warn_if_bogus)
{
char *manpage = xstrdup (file);
char *slash = strrchr (manpage, '/');
@@ -122,7 +118,8 @@ char *filename_info (const char *file, struct mandata *info,
char *ext = strrchr (base_name, '.');
if (!ext) {
/* no section extension */
- gripe_bogus_manpage (file);
+ if (warn_if_bogus)
+ gripe_bogus_manpage (file);
free (manpage);
return NULL;
}
@@ -130,7 +127,8 @@ char *filename_info (const char *file, struct mandata *info,
info->ext = ext;
if (!*info->ext) {
/* zero-length section extension */
- gripe_bogus_manpage (file);
+ if (warn_if_bogus)
+ gripe_bogus_manpage (file);
free (manpage);
return NULL;
}
@@ -141,7 +139,8 @@ char *filename_info (const char *file, struct mandata *info,
if (strlen (info->sec) >= 1 && strlen (info->ext) >= 1 &&
info->sec[0] != info->ext[0]) {
/* mismatch in section */
- gripe_bogus_manpage (file);
+ if (warn_if_bogus)
+ gripe_bogus_manpage (file);
free (manpage);
return NULL;
}
diff --git a/src/filenames.h b/lib/filenames.h
index d7fd8a13..7e46b964 100644
--- a/src/filenames.h
+++ b/lib/filenames.h
@@ -1,7 +1,7 @@
/*
* filenames.h: Interface to composing and dissecting man page file names
*
- * Copyright (C) 2001, 2002 Colin Watson.
+ * Copyright (C) 2001-2022 Colin Watson.
*
* This file is part of man-db.
*
@@ -20,9 +20,35 @@
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include "db_storage.h"
+#ifndef MAN_FILENAMES_H
+#define MAN_FILENAMES_H
+
+#include <stdbool.h>
+
+#include "timespec.h"
+
+struct mandata {
+ char *addr; /* ptr to memory containing the fields */
+
+ char *name; /* Name of page, if != key */
+
+ /* The following are all const because they should be pointers to
+ * parts of strings allocated elsewhere (often the addr field above)
+ * and should not be written through or freed themselves.
+ */
+ const char *ext; /* Filename ext w/o comp ext */
+ const char *sec; /* Section name/number */
+ char id; /* id for this entry */
+ const char *pointer; /* id related file pointer */
+ const char *comp; /* Compression extension */
+ const char *filter; /* filters needed for the page */
+ const char *whatis; /* whatis description for page */
+ struct timespec mtime; /* mod time for file */
+};
extern char *make_filename (const char *path, const char *name,
struct mandata *in, const char *type);
extern char *filename_info (const char *file, struct mandata *info,
- const char *req_name);
+ const char *req_name, bool warn_if_bogus);
+
+#endif /* MAN_FILENAMES_H */
diff --git a/libdb/db_delete.c b/libdb/db_delete.c
index 6e1c137c..6d8870f1 100644
--- a/libdb/db_delete.c
+++ b/libdb/db_delete.c
@@ -41,6 +41,7 @@
#include "appendstr.h"
#include "debug.h"
+#include "filenames.h"
#include "glcontainers.h"
#include "mydbm.h"
diff --git a/libdb/db_lookup.c b/libdb/db_lookup.c
index 40bb9427..4606d984 100644
--- a/libdb/db_lookup.c
+++ b/libdb/db_lookup.c
@@ -51,6 +51,7 @@
#include "debug.h"
#include "fatal.h"
+#include "filenames.h"
#include "glcontainers.h"
#include "wordfnmatch.h"
#include "xregcomp.h"
diff --git a/libdb/db_storage.h b/libdb/db_storage.h
index 5d585b11..47f82ac9 100644
--- a/libdb/db_storage.h
+++ b/libdb/db_storage.h
@@ -47,29 +47,10 @@
#define FIELDS 10 /* No of fields in each database page `content' */
-#include "timespec.h"
+#include "filenames.h"
#include "mydbm.h"
-struct mandata {
- char *addr; /* ptr to memory containing the fields */
-
- char *name; /* Name of page, if != key */
-
- /* The following are all const because they should be pointers to
- * parts of strings allocated elsewhere (often the addr field above)
- * and should not be written through or freed themselves.
- */
- const char *ext; /* Filename ext w/o comp ext */
- const char *sec; /* Section name/number */
- char id; /* id for this entry */
- const char *pointer; /* id related file pointer */
- const char *comp; /* Compression extension */
- const char *filter; /* filters needed for the page */
- const char *whatis; /* whatis description for page */
- struct timespec mtime; /* mod time for file */
-};
-
struct name_ext {
const char *name;
const char *ext;
diff --git a/libdb/db_store.c b/libdb/db_store.c
index 505207fd..cc87c14f 100644
--- a/libdb/db_store.c
+++ b/libdb/db_store.c
@@ -42,6 +42,7 @@
#include "manconfig.h"
#include "debug.h"
+#include "filenames.h"
#include "glcontainers.h"
#include "mydbm.h"
diff --git a/po/POTFILES.in b/po/POTFILES.in
index d2fa2e6e..3049ea50 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -1,4 +1,5 @@
lib/compression.c
+lib/filenames.c
lib/pathsearch.c
lib/security.c
lib/xregcomp.c
@@ -10,7 +11,6 @@ src/accessdb.c
src/catman.c
src/check_mandirs.c
src/descriptions_store.c
-src/filenames.c
src/globbing_test.c
src/lexgrog.l
src/lexgrog_test.c
diff --git a/src/Makefile.am b/src/Makefile.am
index c92c852b..ce3c8dda 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -64,7 +64,7 @@ catman_LDADD = $(LIBMANDB) $(libpipeline_LIBS)
globbing_LDADD = $(LIBMAN)
lexgrog_LDADD = $(LIBMAN) $(LIBCOMPRESS) $(libpipeline_LIBS) $(LTLIBICONV)
man_LDADD = $(LIBMANDB) $(LIBCOMPRESS) $(libpipeline_LIBS) $(LTLIBICONV)
-man_recode_LDADD = $(LIBMANDB) $(LIBCOMPRESS) $(libpipeline_LIBS) $(LTLIBICONV)
+man_recode_LDADD = $(LIBMAN) $(LIBCOMPRESS) $(libpipeline_LIBS) $(LTLIBICONV)
manconv_LDADD = $(LIBMAN) $(LIBCOMPRESS) $(libpipeline_LIBS) $(LTLIBICONV)
mandb_LDADD = $(LIBMANDB) $(LIBCOMPRESS) $(libpipeline_LIBS) $(LTLIBICONV)
manpath_LDADD = $(LIBMAN)
@@ -90,8 +90,6 @@ lexgrog_SOURCES = \
decompress.h \
descriptions.c \
descriptions.h \
- filenames.c \
- filenames.h \
globbing.c \
globbing.h \
lexgrog.h \
@@ -108,8 +106,6 @@ lexgrog_SOURCES = \
man_SOURCES = \
decompress.c \
decompress.h \
- filenames.c \
- filenames.h \
globbing.c \
globbing.h \
man.c \
@@ -149,8 +145,6 @@ mandb_SOURCES = \
descriptions.c \
descriptions.h \
descriptions_store.c \
- filenames.c \
- filenames.h \
globbing.c \
globbing.h \
lexgrog.h \
diff --git a/src/catman.c b/src/catman.c
index a933d4fb..2da9d03d 100644
--- a/src/catman.c
+++ b/src/catman.c
@@ -78,6 +78,7 @@
#include "cleanup.h"
#include "debug.h"
#include "fatal.h"
+#include "filenames.h"
#include "glcontainers.h"
#include "pipeline.h"
#include "util.h"
diff --git a/src/check_mandirs.c b/src/check_mandirs.c
index 5ae5c00e..50027779 100644
--- a/src/check_mandirs.c
+++ b/src/check_mandirs.c
@@ -64,6 +64,7 @@
#include "appendstr.h"
#include "debug.h"
#include "fatal.h"
+#include "filenames.h"
#include "glcontainers.h"
#include "orderfiles.h"
#include "security.h"
@@ -73,7 +74,6 @@
#include "db_storage.h"
#include "descriptions.h"
-#include "filenames.h"
#include "globbing.h"
#include "lexgrog.h"
#include "manp.h"
@@ -170,7 +170,7 @@ void test_manfile (MYDBM_FILE dbf, const char *file, const char *path)
memset (&lg, 0, sizeof (struct lexgrog));
memset (&info, 0, sizeof (struct mandata));
- manpage = filename_info (file, &info, NULL);
+ manpage = filename_info (file, &info, NULL, quiet < 2);
if (!manpage)
return;
manpage_base = manpage + strlen (manpage) + 1;
@@ -787,7 +787,7 @@ static int count_glob_matches (const char *name, const char *ext,
continue;
}
- buf = filename_info (walk, &info, name);
+ buf = filename_info (walk, &info, name, quiet < 2);
if (buf) {
if (STREQ (ext, info.ext))
++count;
diff --git a/src/descriptions.h b/src/descriptions.h
index 38ae412a..0712b643 100644
--- a/src/descriptions.h
+++ b/src/descriptions.h
@@ -22,7 +22,9 @@
#include "gl_list.h"
-#include "db_storage.h"
+#include "filenames.h"
+
+#include "mydbm.h"
struct page_description {
char *name;
diff --git a/src/descriptions_store.c b/src/descriptions_store.c
index 621b8355..f019f0f9 100644
--- a/src/descriptions_store.c
+++ b/src/descriptions_store.c
@@ -44,11 +44,11 @@
#include "manconfig.h"
#include "debug.h"
+#include "filenames.h"
#include "glcontainers.h"
#include "db_storage.h"
-#include "filenames.h"
#include "ult_src.h"
#include "descriptions.h"
@@ -102,8 +102,8 @@ void store_descriptions (MYDBM_FILE dbf, gl_list_t descs, struct mandata *info,
struct mandata trace_info;
char *buf;
- buf = filename_info (trace_name,
- &trace_info, "");
+ buf = filename_info (trace_name, &trace_info,
+ "", quiet < 2);
if (trace_info.name &&
STREQ (trace_info.name, desc->name)) {
struct stat st;
diff --git a/src/man.c b/src/man.c
index 456968dd..1ffad970 100644
--- a/src/man.c
+++ b/src/man.c
@@ -89,6 +89,7 @@
#include "compression.h"
#include "debug.h"
#include "fatal.h"
+#include "filenames.h"
#include "glcontainers.h"
#include "pipeline.h"
#include "pathsearch.h"
@@ -105,7 +106,6 @@
#include "mydbm.h"
#include "db_storage.h"
-#include "filenames.h"
#include "globbing.h"
#include "ult_src.h"
#include "manp.h"
@@ -3160,7 +3160,8 @@ static int try_section (const char *path, const char *sec, const char *name,
GL_LIST_FOREACH (names, found_name) {
struct mandata *info = XZALLOC (struct mandata);
- char *info_buffer = filename_info (found_name, info, name);
+ char *info_buffer = filename_info (found_name, info, name,
+ quiet < 2);
const char *ult;
int f;
@@ -3738,7 +3739,8 @@ static int do_global_apropos_section (const char *path, const char *sec,
continue;
info = XZALLOC (struct mandata);
- info_buffer = filename_info (found_name, info, NULL);
+ info_buffer = filename_info (found_name, info, NULL,
+ quiet < 2);
if (!info_buffer)
goto next;
info->addr = info_buffer;
diff --git a/src/mandb.c b/src/mandb.c
index 372eba6b..27cd4df2 100644
--- a/src/mandb.c
+++ b/src/mandb.c
@@ -69,16 +69,17 @@
#include "cleanup.h"
#include "debug.h"
+#include "filenames.h"
#include "glcontainers.h"
#include "pipeline.h"
#include "sandbox.h"
#include "security.h"
#include "util.h"
+#include "db_storage.h"
#include "mydbm.h"
#include "check_mandirs.h"
-#include "filenames.h"
#include "manp.h"
#include "straycats.h"
@@ -357,7 +358,7 @@ static int update_one_file (MYDBM_FILE dbf,
char *manpage;
memset (&info, 0, sizeof (struct mandata));
- manpage = filename_info (filename, &info, "");
+ manpage = filename_info (filename, &info, "", quiet < 2);
if (info.name) {
dbdelete (dbf, info.name, &info);
purge_pointers (dbf, info.name);
diff --git a/src/straycats.c b/src/straycats.c
index 75cacdd1..3b2b6d4c 100644
--- a/src/straycats.c
+++ b/src/straycats.c
@@ -55,6 +55,7 @@
#include "appendstr.h"
#include "compression.h"
#include "debug.h"
+#include "filenames.h"
#include "glcontainers.h"
#include "pipeline.h"
#include "decompress.h"
diff --git a/src/whatis.c b/src/whatis.c
index 05074aad..2f393fa8 100644
--- a/src/whatis.c
+++ b/src/whatis.c
@@ -70,6 +70,7 @@
#include "cleanup.h"
#include "debug.h"
#include "fatal.h"
+#include "filenames.h"
#include "glcontainers.h"
#include "pipeline.h"
#include "pathsearch.h"