diff options
Diffstat (limited to '')
-rw-r--r-- | src/utils/pfbtops/pfbtops.1.man | 129 | ||||
-rw-r--r-- | src/utils/pfbtops/pfbtops.am | 32 | ||||
-rw-r--r-- | src/utils/pfbtops/pfbtops.c | 243 |
3 files changed, 404 insertions, 0 deletions
diff --git a/src/utils/pfbtops/pfbtops.1.man b/src/utils/pfbtops/pfbtops.1.man new file mode 100644 index 0000000..71140c6 --- /dev/null +++ b/src/utils/pfbtops/pfbtops.1.man @@ -0,0 +1,129 @@ +.TH pfbtops @MAN1EXT@ "@MDATE@" "groff @VERSION@" +.SH Name +pfbtops \- translate PostScript Printer Font Binary files to Printer +Font ASCII +. +. +.\" ==================================================================== +.\" Legal Terms +.\" ==================================================================== +.\" +.\" Copyright (C) 1989-2020 Free Software Foundation, Inc. +.\" +.\" Permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" Permission is granted to copy and distribute modified versions of +.\" this manual under the conditions for verbatim copying, provided that +.\" the entire resulting derived work is distributed under the terms of +.\" a permission notice identical to this one. +.\" +.\" Permission is granted to copy and distribute translations of this +.\" manual into another language, under the above conditions for +.\" modified versions, except that this permission notice may be +.\" included in translations approved by the Free Software Foundation +.\" instead of in the original English. +. +. +.\" Save and disable compatibility mode (for, e.g., Solaris 10/11). +.do nr *groff_pfbtops_1_man_C \n[.cp] +.cp 0 +. +.\" Define fallback for groff 1.23's MR macro if the system lacks it. +.nr do-fallback 0 +.if !\n(.f .nr do-fallback 1 \" mandoc +.if \n(.g .if !d MR .nr do-fallback 1 \" older groff +.if !\n(.g .nr do-fallback 1 \" non-groff *roff +.if \n[do-fallback] \{\ +. de MR +. ie \\n(.$=1 \ +. I \%\\$1 +. el \ +. IR \%\\$1 (\\$2)\\$3 +. . +.\} +.rr do-fallback +. +. +.\" ==================================================================== +.SH Synopsis +.\" ==================================================================== +. +.SY pfbtops +.RI [ pfb-file ] +.YS +. +. +.SY pfbtops +.B \-\-help +.YS +. +. +.SY pfbtops +.B \-v +. +.SY pfbtops +.B \-\-version +.YS +. +. +.\" ==================================================================== +.SH Description +.\" ==================================================================== +. +.I pfbtops +translates a PostScript Type\~1 font in Printer Font Binary (PFB) format +to Printer Font ASCII (PFA) format, +splitting overlong lines in text packets into smaller chunks. +. +If +.I pfb-file +is omitted, +the PFB file will be read from the standard input stream. +. +The PFA font will be written on the standard output stream. +. +PostScript fonts for MS-DOS were historically supplied in PFB format. +. +Use of a PostScript Type\~1 font with +.I groff +requires conversion of its metrics +(AFM file) +to a +.I groff +font description file; +see +.MR afmtodit @MAN1EXT@ . +. +. +.P +The +.B \-\-help +option displays a usage message, +while +.B \-v +and +.B \-\-version +show version information; +all exit afterward. +. +. +.\" ==================================================================== +.SH "See also" +.\" ==================================================================== +. +.MR grops @MAN1EXT@ , +.MR gropdf @MAN1EXT@ +. +. +.\" Restore compatibility mode (for, e.g., Solaris 10/11). +.cp \n[*groff_pfbtops_1_man_C] +.do rr *groff_pfbtops_1_man_C +. +. +.\" Local Variables: +.\" fill-column: 72 +.\" mode: nroff +.\" End: +.\" vim: set filetype=groff textwidth=72: diff --git a/src/utils/pfbtops/pfbtops.am b/src/utils/pfbtops/pfbtops.am new file mode 100644 index 0000000..8b7fd71 --- /dev/null +++ b/src/utils/pfbtops/pfbtops.am @@ -0,0 +1,32 @@ +# Copyright (C) 2014-2020 Free Software Foundation, Inc. +# +# This file is part of groff. +# +# groff 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 3 of the License, or +# (at your option) any later version. +# +# groff 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 this program. If not, see <http://www.gnu.org/licenses/>. + +bin_PROGRAMS += pfbtops +man1_MANS += src/utils/pfbtops/pfbtops.1 +EXTRA_DIST += src/utils/pfbtops/pfbtops.1.man +pfbtops_SOURCES = src/utils/pfbtops/pfbtops.c +pfbtops_LDADD = libgroff.a $(LIBM) lib/libgnu.a +# We use the following trick to force the use of C++ compiler +# See the Automake manual, "Libtool Convenience Libraries" +nodist_EXTRA_pfbtops_SOURCES = src/utils/pfbtops/dummy.cpp + + +# Local Variables: +# fill-column: 72 +# mode: makefile-automake +# End: +# vim: set autoindent filetype=automake textwidth=72: diff --git a/src/utils/pfbtops/pfbtops.c b/src/utils/pfbtops/pfbtops.c new file mode 100644 index 0000000..8fbe44a --- /dev/null +++ b/src/utils/pfbtops/pfbtops.c @@ -0,0 +1,243 @@ +/* Copyright (C) 1992-2020 Free Software Foundation, Inc. + Written by James Clark (jjc@jclark.com) + +This file is part of groff. + +groff 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 3 of the License, or +(at your option) any later version. + +groff 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 this program. If not, see <http://www.gnu.org/licenses/>. */ + +/* This translates ps fonts in .pfb format to ASCII ps files. */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#define __GETOPT_PREFIX groff_ + +#include <errno.h> // errno +#include <stdio.h> +#include <stdlib.h> // exit(), EXIT_FAILURE, EXIT_SUCCESS +#include <string.h> // strerror() +#include <limits.h> + +#include <getopt.h> + +#include "nonposix.h" + +/* Binary bytes per output line. */ +#define BYTES_PER_LINE (64/2) +#define MAX_LINE_LENGTH 78 +#define HEX_DIGITS "0123456789abcdef" + +extern const char *Version_string; + +static char *program_name; + +static void error(const char *s) +{ + fprintf(stderr, "%s: error: %s\n", program_name, s); + exit(EXIT_FAILURE); +} + +static void usage(FILE *stream) +{ + fprintf(stream, "usage: %s [pfb-file]\n" + "usage: %s {-v | --version}\n" + "usage: %s --help\n", + program_name, program_name, program_name); +} + +static void get_text(int n) +{ + int c = 0, c1; + int in_string = 0; + int is_comment = 0; + int count = 0; + + while (--n >= 0) { + c = getchar(); + if (c == '(' && !is_comment) + in_string++; + else if (c == ')' && !is_comment) + in_string--; + else if (c == '%' && !in_string) + is_comment = 1; + else if (c == '\\' && in_string) { + count++; + putchar(c); + if (n-- == 0) + break; + c = getchar(); + /* don't split octal character representations */ + if (c >= '0' && c <= '7') { + count++; + putchar(c); + if (n-- == 0) + break; + c = getchar(); + if (c >= '0' && c <= '7') { + count++; + putchar(c); + if (n-- == 0) + break; + c = getchar(); + if (c >= '0' && c <= '7') { + count++; + putchar(c); + if (n-- == 0) + break; + c = getchar(); + } + } + } + } + if (c == EOF) + error("end of file in text packet"); + else if (c == '\r') { + if (n-- == 0) + break; + c1 = getchar(); + if (c1 != '\n') { + ungetc(c1, stdin); + n++; + } + c = '\n'; + } + if (c == '\n') { + count = 0; + is_comment = 0; + } + else if (count >= MAX_LINE_LENGTH) { + if (in_string > 0) { + count = 1; + putchar('\\'); + putchar('\n'); + } + else if (is_comment) { + count = 2; + putchar('\n'); + putchar('%'); + } + else { + /* split at the next whitespace character */ + while (c != ' ' && c != '\t' && c != '\f') { + putchar(c); + if (n-- == 0) + break; + c = getchar(); + } + count = 0; + putchar('\n'); + continue; + } + } + count++; + putchar(c); + } + if (c != '\n') + putchar('\n'); +} + +static void get_binary(int n) +{ + int c; + int count = 0; + + while (--n >= 0) { + c = getchar(); + if (c == EOF) + error("end of file in binary packet"); + if (count >= BYTES_PER_LINE) { + putchar('\n'); + count = 0; + } + count++; + putchar(HEX_DIGITS[(c >> 4) & 0xf]); + putchar(HEX_DIGITS[c & 0xf]); + } + putchar('\n'); +} + +int main(int argc, char **argv) +{ + int opt; + static const struct option long_options[] = { + { "help", no_argument, 0, CHAR_MAX + 1 }, + { "version", no_argument, 0, 'v' }, + { NULL, 0, 0, 0 } + }; + + program_name = argv[0]; + + while ((opt = getopt_long(argc, argv, "v", long_options, NULL)) != EOF) { + switch (opt) { + case 'v': + printf("GNU pfbtops (groff) version %s\n", Version_string); + exit(EXIT_SUCCESS); + break; + case CHAR_MAX + 1: /* --help */ + usage(stdout); + exit(EXIT_SUCCESS); + break; + case '?': + usage(stderr); + exit(2); + break; + } + } + + if (argc - optind > 1) { + usage(stderr); + exit(2); + } + const char *file = argv[optind]; + if (argc > optind && !freopen(file, "r", stdin)) { + fprintf(stderr, "%s: error: unable to open file '%s': %s\n", + program_name, file, strerror(errno)); + exit(EXIT_FAILURE); + } + SET_BINARY(fileno(stdin)); + for (;;) { + int type, c, i; + long n; + + c = getchar(); + if (c != 0x80) + error("first byte of packet not 0x80"); + type = getchar(); + if (type == 3) + break; + if (type != 1 && type != 2) + error("bad packet type"); + n = 0; + for (i = 0; i < 4; i++) { + c = getchar(); + if (c == EOF) + error("end of file in packet header"); + n |= (long)c << (i << 3); + } + if (n < 0) + error("negative packet length"); + if (type == 1) + get_text(n); + else + get_binary(n); + } + exit(EXIT_SUCCESS); +} + +// Local Variables: +// fill-column: 72 +// mode: C +// End: +// vim: set cindent noexpandtab shiftwidth=2 textwidth=72: |