1 /* Copyright (C) 1992, 2001, 2003, 2004, 2005, 2009
2 Free Software Foundation, Inc.
3 Written by James Clark (jjc@jclark.com)
5 This file is part of groff.
7 groff is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 groff is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 /* This translates ps fonts in .pfb format to ASCII ps files. */
26 #define __GETOPT_PREFIX groff_
36 /* Binary bytes per output line. */
37 #define BYTES_PER_LINE (64/2)
38 #define MAX_LINE_LENGTH 78
39 #define HEX_DIGITS "0123456789abcdef"
41 extern const char *Version_string;
43 static char *program_name;
45 static void error(const char *s)
47 fprintf(stderr, "%s: %s\n", program_name, s);
51 static void usage(FILE *stream)
53 fprintf(stream, "usage: %s [-v] [pfb_file]\n", program_name);
56 static void get_text(int n)
65 if (c == '(' && !is_comment)
67 else if (c == ')' && !is_comment)
69 else if (c == '%' && !in_string)
71 else if (c == '\\' && in_string) {
77 /* don't split octal character representations */
78 if (c >= '0' && c <= '7') {
84 if (c >= '0' && c <= '7') {
90 if (c >= '0' && c <= '7') {
101 error("end of file in text packet");
102 else if (c == '\r') {
116 else if (count >= MAX_LINE_LENGTH) {
122 else if (is_comment) {
128 /* split at the next whitespace character */
129 while (c != ' ' && c != '\t' && c != '\f') {
147 static void get_binary(int n)
155 error("end of file in binary packet");
156 if (count >= BYTES_PER_LINE) {
161 putchar(HEX_DIGITS[(c >> 4) & 0xf]);
162 putchar(HEX_DIGITS[c & 0xf]);
167 int main(int argc, char **argv)
170 static const struct option long_options[] = {
171 { "help", no_argument, 0, CHAR_MAX + 1 },
172 { "version", no_argument, 0, 'v' },
176 program_name = argv[0];
178 while ((opt = getopt_long(argc, argv, "v", long_options, NULL)) != EOF) {
181 printf("GNU pfbtops (groff) version %s\n", Version_string);
184 case CHAR_MAX + 1: /* --help */
195 if (argc - optind > 1) {
199 if (argc > optind && !freopen(argv[optind], "r", stdin)) {
200 perror(argv[optind]);
203 SET_BINARY(fileno(stdin));
210 error("first byte of packet not 0x80");
214 if (type != 1 && type != 2)
215 error("bad packet type");
217 for (i = 0; i < 4; i++) {
220 error("end of file in packet header");
221 n |= (long)c << (i << 3);
224 error("negative packet length");