1 /* Copyright (C) 1992, 2001, 2003, 2004, 2005 Free Software Foundation, Inc.
2 Written by James Clark (jjc@jclark.com)
4 This file is part of groff.
6 groff is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
11 groff is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License along
17 with groff; see the file COPYING. If not, write to the Free Software
18 Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */
20 /* This translates ps fonts in .pfb format to ASCII ps files. */
30 #define __GETOPT_PREFIX groff_
35 /* Binary bytes per output line. */
36 #define BYTES_PER_LINE (64/2)
37 #define MAX_LINE_LENGTH 78
38 #define HEX_DIGITS "0123456789abcdef"
40 extern const char *Version_string;
42 static char *program_name;
44 static void error(const char *s)
46 fprintf(stderr, "%s: %s\n", program_name, s);
50 static void usage(FILE *stream)
52 fprintf(stream, "usage: %s [-v] [pfb_file]\n", program_name);
55 static void get_text(int n)
64 if (c == '(' && !is_comment)
66 else if (c == ')' && !is_comment)
68 else if (c == '%' && !in_string)
70 else if (c == '\\' && in_string) {
76 /* don't split octal character representations */
77 if (c >= '0' && c <= '7') {
83 if (c >= '0' && c <= '7') {
89 if (c >= '0' && c <= '7') {
100 error("end of file in text packet");
101 else if (c == '\r') {
115 else if (count >= MAX_LINE_LENGTH) {
121 else if (is_comment) {
127 /* split at the next whitespace character */
128 while (c != ' ' && c != '\t' && c != '\f') {
146 static void get_binary(int n)
154 error("end of file in binary packet");
155 if (count >= BYTES_PER_LINE) {
160 putchar(HEX_DIGITS[(c >> 4) & 0xf]);
161 putchar(HEX_DIGITS[c & 0xf]);
166 int main(int argc, char **argv)
169 static const struct option long_options[] = {
170 { "help", no_argument, 0, CHAR_MAX + 1 },
171 { "version", no_argument, 0, 'v' },
175 program_name = argv[0];
177 while ((opt = getopt_long(argc, argv, "v", long_options, NULL)) != EOF) {
180 printf("GNU pfbtops (groff) version %s\n", Version_string);
183 case CHAR_MAX + 1: /* --help */
194 if (argc - optind > 1) {
198 if (argc > optind && !freopen(argv[optind], "r", stdin)) {
199 perror(argv[optind]);
202 SET_BINARY(fileno(stdin));
209 error("first byte of packet not 0x80");
213 if (type != 1 && type != 2)
214 error("bad packet type");
216 for (i = 0; i < 4; i++) {
219 error("end of file in packet header");
220 n |= (long)c << (i << 3);
223 error("negative packet length");