summaryrefslogtreecommitdiff
path: root/lib/encodings.c
diff options
context:
space:
mode:
authorColin Watson <cjwatson@debian.org>2022-01-17 00:50:05 +0000
committerColin Watson <cjwatson@debian.org>2022-01-17 00:50:05 +0000
commitdd637d7cf962cd464f127efcb69dede6adf297e6 (patch)
tree1ef76468fc178e47a6e118632e114b28df7437e2 /lib/encodings.c
parent83b0600bd452740e357ddd925a4927b96dd9ce5a (diff)
Avoid libpipeline linkage in libman
Since it's only used by one function, and not all of man-db's tools need libpipeline in their own right (e.g. accessdb), it seems worth pushing this up a layer. * lib/encodings.c (struct conversion_entry, conversion_table, convert_encoding, check_preprocessor_encoding): Move to ... * src/manconv.c: ... here. * lib/encodings.h (check_preprocessor_encoding): Move to ... * src/manconv.h: ... here. * lib/Makefile.am (libman_la_CPPFLAGS): Remove $(libpipeline_CFLAGS). (libman_la_LDFLAGS): Remove $(libpipeline_LIBS). * src/man-recode.c, src/man.c, src/manconv.c: Include manconv.h.
Diffstat (limited to 'lib/encodings.c')
-rw-r--r--lib/encodings.c156
1 files changed, 0 insertions, 156 deletions
diff --git a/lib/encodings.c b/lib/encodings.c
index c3373ac2..0db5b8c0 100644
--- a/lib/encodings.c
+++ b/lib/encodings.c
@@ -29,7 +29,6 @@
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
-#include <assert.h>
#include <locale.h>
#include <ctype.h>
@@ -38,7 +37,6 @@
#include "localcharset.h"
#include "xalloc.h"
#include "xstrndup.h"
-#include "xvasprintf.h"
#include "manconfig.h"
@@ -328,59 +326,6 @@ static struct less_charset_entry less_charset_table[] = {
static const char fallback_less_charset[] = "iso8859";
-/* Encoding conversions from groff-1.20/src/preproc/preconv/preconv.cpp.
- * I've only included those not already recognised by GNU libiconv.
- */
-struct conversion_entry {
- const char *from;
- const char *to;
-};
-
-static struct conversion_entry conversion_table[] = {
- { "chinese-big5", "Big5" },
- { "chinese-euc", "GB2312" },
- { "chinese-iso-8bit", "GB2312" },
- { "cn-gb-2312", "GB2312" },
- { "cp878", "KOI8-R" },
- { "cyrillic-iso-8bit", "ISO-8859-5" },
- { "cyrillic-koi8", "KOI8-R" },
- { "euc-china", "GB2312" },
- { "euc-japan", "EUC-JP" },
- { "euc-japan-1990", "EUC-JP" },
- { "euc-kr", "EUC-KR" },
- { "greek-iso-8bit", "ISO-8859-7" },
- { "iso-latin-1", "ISO-8859-1" },
- { "iso-latin-2", "ISO-8859-2" },
- { "iso-latin-5", "ISO-8859-9" },
- { "iso-latin-7", "ISO-8859-13" },
- { "iso-latin-9", "ISO-8859-15" },
- { "japanese-iso-8bit", "EUC-JP" },
- { "japanese-euc", "EUC-JP" },
- { "jis8", "EUC-JP" },
- { "korean-euc", "EUC-KR" },
- { "korean-iso-8bit", "EUC-KR" },
- { "latin-0", "ISO-8859-15" },
- { "latin-1", "ISO-8859-1" },
- { "latin-2", "ISO-8859-2" },
- { "latin-5", "ISO-8859-9" },
- { "latin-7", "ISO-8859-13" },
- { "mule-utf-16", "UTF-16" },
- { "mule-utf-16be", "UTF-16BE" },
- { "mule-utf-16-be", "UTF-16BE" },
- { "mule-utf-16be-with-signature", "UTF-16" },
- { "mule-utf-16le", "UTF-16LE" },
- { "mule-utf-16-le", "UTF-16LE" },
- { "mule-utf-16le-with-signature", "UTF-16" },
- { "mule-utf-8", "UTF-8" },
- { "utf-16-be", "UTF-16BE" },
- { "utf-16be-with-signature", "UTF-16" },
- { "utf-16-be-with-signature", "UTF-16" },
- { "utf-16-le", "UTF-16LE" },
- { "utf-16le-with-signature", "UTF-16" },
- { "utf-16-le-with-signature", "UTF-16" },
- { NULL, NULL }
-};
-
const char *groff_preconv = NULL;
/* Is the groff "preconv" helper available? If so, return its name.
@@ -833,104 +778,3 @@ const char * ATTRIBUTE_PURE get_jless_charset (const char *charset_from_locale)
return NULL;
}
-
-/* Convert Emacs-style coding tags to ones that libiconv understands. */
-static char *convert_encoding (char *encoding)
-{
- size_t encoding_len = strlen (encoding);
- const struct conversion_entry *entry;
-
-#define STRIP(s, l) do { \
- if (encoding_len > (l) && \
- !strcasecmp (encoding + encoding_len - (l), (s))) \
- encoding[encoding_len - (l)] = '\0'; \
-} while (0)
-
- STRIP ("-dos", 4);
- STRIP ("-mac", 4);
- STRIP ("-unix", 5);
-
-#undef STRIP
-
- for (entry = conversion_table; entry->from; ++entry)
- if (!strcasecmp (entry->from, encoding)) {
- free (encoding);
- return xstrdup (entry->to);
- }
-
- return encoding;
-}
-
-/* Inspect the first line of data in a pipeline for preprocessor encoding
- * declarations.
- *
- * If to_encoding and modified_line are both non-NULL, and if the encoding
- * declaration in the input does not match to_encoding, then return an
- * encoding declaration line modified to refer to the given to_encoding in
- * *modified_line. The caller should free *modified_line.
- */
-char *check_preprocessor_encoding (pipeline *p, const char *to_encoding,
- char **modified_line)
-{
- char *pp_encoding = NULL;
- const char *line = pipeline_peekline (p);
- const char *directive = NULL, *directive_end = NULL, *pp_search = NULL;
- size_t pp_encoding_len = 0;
-
- /* Some people use .\" incorrectly. We allow it for encoding
- * declarations but not for preprocessor declarations.
- */
- if (line &&
- (STRNEQ (line, PP_COOKIE, 4) || STRNEQ (line, ".\\\" ", 4))) {
- const char *newline = strchr (line, '\n');
-
- directive = line + 4;
- directive_end = newline ? newline : strchr (directive, '\0');
- pp_search = memmem (directive, directive_end - directive,
- "-*-", 3);
- }
-
- if (directive && pp_search) {
- pp_search += 3;
- while (pp_search && pp_search < directive_end && *pp_search) {
- while (*pp_search == ' ')
- ++pp_search;
- if (STRNEQ (pp_search, "coding:", 7)) {
- const char *pp_encoding_allow;
- pp_search += 7;
- while (*pp_search == ' ')
- ++pp_search;
- pp_encoding_allow = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- "abcdefghijklmnopqrstuvwxyz"
- "0123456789-_/:.()";
- pp_encoding_len = strspn (pp_search,
- pp_encoding_allow);
- pp_encoding = xstrndup (pp_search,
- pp_encoding_len);
- pp_encoding = convert_encoding (pp_encoding);
- debug ("preprocessor encoding: %s\n",
- pp_encoding);
- break;
- } else {
- pp_search = memchr (pp_search, ';',
- directive_end - pp_search);
- if (pp_search)
- ++pp_search;
- }
- }
- }
-
- if (to_encoding && modified_line &&
- pp_encoding && strcasecmp (pp_encoding, to_encoding)) {
- assert (directive_end);
- assert (pp_search);
- *modified_line = xasprintf
- ("%.*s%s%.*s\n",
- (int) (pp_search - line), line,
- to_encoding,
- (int) (directive_end - (pp_search + pp_encoding_len)),
- pp_search + pp_encoding_len);
- }
-
- return pp_encoding;
-}