summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorColin Watson <cjwatson@debian.org>2022-09-23 22:07:55 +0100
committerColin Watson <cjwatson@debian.org>2022-09-23 22:07:55 +0100
commit312e096ceb9e41f1d96734a0734934e89e9226ad (patch)
tree87eabeb03b6bd56dafbe17ee6ec792bbef29268c /src
parent4cbb67968dd3db7f0140ca50489683c892cd5a10 (diff)
Move compression file name utilities to lib/
This makes more sense as a home for plain file name manipulation utilities. I also merged `include/comp_src.h.in` into `lib/compression.c`, because structure definitions (as opposed to declarations) don't belong in header files. * src/compression.c: Move to ... * lib/compression.c: ... here. Remove unnecessary `pipeline.h` include. * src/compression.h: Move to ... * lib/compression.h: ... here. Update positioning of all includes. * lib/Makefile.am (libman_la_SOURCES): Add `compression.c` and `compression.h`. * lib/README: Add `compression.*`. * src/Makefile.am (lexgrog_SOURCES, man_SOURCES, man_recode_SOURCES, mandb_SOURCES): Remove `compression.c` and `compression.h`. * include/comp_src.h (comp_list): Move to ... * lib/compression.c (comp_list): ... here. Update all references. * include/manconfig.h (struct compression, comp_list): Move to ... * lib/compression.h (struct compression, comp_list): ... here. Add includes where necessary. * Makefile.am (noinst_HEADERS): Remove `include/comp_src.h`.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am8
-rw-r--r--src/compression.c128
-rw-r--r--src/compression.h25
-rw-r--r--src/decompress.c9
-rw-r--r--src/filenames.c2
-rw-r--r--src/man-recode.c2
-rw-r--r--src/man.c2
-rw-r--r--src/straycats.c2
-rw-r--r--src/ult_src.c2
-rw-r--r--src/zsoelim.l4
10 files changed, 14 insertions, 170 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 7d4a398b..c92c852b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -84,8 +84,6 @@ globbing_SOURCES = \
globbing.h \
globbing_test.c
lexgrog_SOURCES = \
- compression.c \
- compression.h \
convert.c \
convert.h \
decompress.c \
@@ -108,8 +106,6 @@ lexgrog_SOURCES = \
utf8.c \
utf8.h
man_SOURCES = \
- compression.c \
- compression.h \
decompress.c \
decompress.h \
filenames.c \
@@ -130,8 +126,6 @@ man_SOURCES = \
zsoelim.h \
zsoelim.l
man_recode_SOURCES = \
- compression.c \
- compression.h \
decompress.c \
decompress.h \
man-recode.c \
@@ -150,8 +144,6 @@ manconv_SOURCES = \
mandb_SOURCES = \
check_mandirs.c \
check_mandirs.h \
- compression.c \
- compression.h \
decompress.c \
decompress.h \
descriptions.c \
diff --git a/src/compression.c b/src/compression.c
deleted file mode 100644
index ba509545..00000000
--- a/src/compression.c
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * compression.c: code to find decompressor / compression extension
- *
- * Copyright (C) 1994, 1995 Graeme W. Wilford. (Wilf.)
- * Copyright (C) 2001, 2002 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
- *
- * Sat Aug 20 15:01:02 BST 1994 Wilf. (G.Wilford@ee.surrey.ac.uk)
- */
-
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <assert.h>
-#include <stdio.h>
-#include <errno.h>
-#include <signal.h>
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-
-#include "error.h"
-#include "xstrndup.h"
-#include "xvasprintf.h"
-
-#include "manconfig.h"
-
-#include "pipeline.h"
-
-#include "appendstr.h"
-
-#include "compression.h"
-
-/* Take filename as arg, return structure containing decompressor
- and extension, or NULL if no comp extension found.
- If want_stem, set comp->stem to the filename without extension, which
- the caller should free.
-
- eg.
- filename = /usr/man/man1/foo.1.gz
-
- comp->prog = "/usr/bin/gzip -dc";
- comp->ext = "gz";
- comp->stem = "/usr/man/man1/foo.1";
- */
-struct compression *comp_info (const char *filename, int want_stem)
-{
- const char *ext;
- static struct compression hpux_comp =
- {PROG_GUNZIP " -S \"\"", "", NULL};
-
- ext = strrchr (filename, '.');
-
- if (ext) {
- struct compression *comp;
- for (comp = comp_list; comp->ext; comp++) {
- if (strcmp (comp->ext, ext + 1) == 0) {
- if (want_stem)
- comp->stem = xstrndup (filename,
- ext - filename);
- else
- comp->stem = NULL;
- return comp;
- }
- }
- }
-
- if (*PROG_GUNZIP) {
- ext = strstr (filename, ".Z/");
- if (ext) {
- if (want_stem)
- hpux_comp.stem = xstrndup (filename,
- ext - filename);
- else
- hpux_comp.stem = NULL;
- return &hpux_comp;
- }
- }
-
- return NULL;
-}
-
-/* take filename w/o comp ext. as arg, return comp->stem as a relative
- compressed file or NULL if none found */
-struct compression *comp_file (const char *filename)
-{
- size_t len;
- char *compfile;
- struct compression *comp;
-
- compfile = xasprintf ("%s.", filename);
- assert (compfile);
- len = strlen (compfile);
-
- for (comp = comp_list; comp->ext; comp++) {
- struct stat buf;
-
- compfile = appendstr (compfile, comp->ext, (void *) 0);
-
- if (stat (compfile, &buf) == 0) {
- comp->stem = compfile;
- return comp;
- }
-
- *(compfile + len) = '\0';
- }
- free (compfile);
- return NULL;
-}
diff --git a/src/compression.h b/src/compression.h
deleted file mode 100644
index 3ff0f895..00000000
--- a/src/compression.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * compression.h: interface to finding decompressor / compression extension
- *
- * Copyright (C) 1994, 1995 Graeme W. Wilford. (Wilf.)
- * Copyright (C) 2001-2022 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
- */
-
-extern struct compression *comp_info (const char *filename, int want_stem);
-extern struct compression *comp_file (const char *filename);
diff --git a/src/decompress.c b/src/decompress.c
index b8e95b05..c4832410 100644
--- a/src/decompress.c
+++ b/src/decompress.c
@@ -38,6 +38,8 @@
# include "zlib.h"
#endif /* HAVE_LIBZ */
+#include "pipeline.h"
+
#include "attribute.h"
#include "minmax.h"
#include "xalloc.h"
@@ -45,11 +47,12 @@
#include "xvasprintf.h"
#include "manconfig.h"
-#include "comp_src.h"
-#include "pipeline.h"
-#include "decompress.h"
+
+#include "compression.h"
#include "sandbox.h"
+#include "decompress.h"
+
enum decompress_tag {
DECOMPRESS_PIPELINE,
DECOMPRESS_INPROCESS
diff --git a/src/filenames.c b/src/filenames.c
index cbeb49cc..83e09069 100644
--- a/src/filenames.c
+++ b/src/filenames.c
@@ -39,11 +39,11 @@
#include "manconfig.h"
#include "appendstr.h"
+#include "compression.h"
#include "debug.h"
#include "db_storage.h"
-#include "compression.h"
#include "filenames.h"
static void gripe_bogus_manpage (const char *manpage)
diff --git a/src/man-recode.c b/src/man-recode.c
index 9d59bfa1..4cd0aaf3 100644
--- a/src/man-recode.c
+++ b/src/man-recode.c
@@ -52,6 +52,7 @@
#include "pipeline.h"
#include "cleanup.h"
+#include "compression.h"
#include "debug.h"
#include "encodings.h"
#include "fatal.h"
@@ -59,7 +60,6 @@
#include "sandbox.h"
#include "util.h"
-#include "compression.h"
#include "decompress.h"
#include "manconv.h"
#include "manconv_client.h"
diff --git a/src/man.c b/src/man.c
index 7f0d7bce..456968dd 100644
--- a/src/man.c
+++ b/src/man.c
@@ -86,6 +86,7 @@
#include "appendstr.h"
#include "cleanup.h"
+#include "compression.h"
#include "debug.h"
#include "fatal.h"
#include "glcontainers.h"
@@ -104,7 +105,6 @@
#include "mydbm.h"
#include "db_storage.h"
-#include "compression.h"
#include "filenames.h"
#include "globbing.h"
#include "ult_src.h"
diff --git a/src/straycats.c b/src/straycats.c
index 1315345b..75cacdd1 100644
--- a/src/straycats.c
+++ b/src/straycats.c
@@ -53,6 +53,7 @@
#include "manconfig.h"
#include "appendstr.h"
+#include "compression.h"
#include "debug.h"
#include "glcontainers.h"
#include "pipeline.h"
@@ -66,7 +67,6 @@
#include "mydbm.h"
#include "db_storage.h"
-#include "compression.h"
#include "descriptions.h"
#include "lexgrog.h"
#include "manp.h"
diff --git a/src/ult_src.c b/src/ult_src.c
index 69afb712..407360f3 100644
--- a/src/ult_src.c
+++ b/src/ult_src.c
@@ -56,9 +56,9 @@
#include "manconfig.h"
+#include "compression.h"
#include "debug.h"
-#include "compression.h"
#include "decompress.h"
#include "globbing.h"
#include "ult_src.h"
diff --git a/src/zsoelim.l b/src/zsoelim.l
index 845f6f44..2d11660f 100644
--- a/src/zsoelim.l
+++ b/src/zsoelim.l
@@ -83,10 +83,12 @@
#define _(String) gettext (String)
#include "appendstr.h"
+#include "compression.h"
#include "debug.h"
-#include "decompress.h"
#include "fatal.h"
#include "glcontainers.h"
+
+#include "decompress.h"
#include "globbing.h"
#include "zsoelim.h"