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. */
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");