1 /*@ This translates ps fonts in .pfb format to ASCII ps files.
3 * Copyright (c) 2014 - 2017 Steffen (Daode) Nurpmeso <steffen@sdaoden.eu>.
5 * Copyright (C) 1992, 2001, 2003 - 2005 Free Software Foundation, Inc.
6 * Written by James Clark (jjc@jclark.com)
8 * This is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License as published by the Free
10 * Software Foundation; either version 2, or (at your option) any later
13 * This is distributed in the hope that it will be useful, but WITHOUT ANY
14 * WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 * You should have received a copy of the GNU General Public License along
19 * with groff; see the file COPYING. If not, write to the Free Software
20 * Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA.
24 #include "pfbtops-config.h"
26 #define __GETOPT_PREFIX groff_ /* FIXME */
32 #include <getopt.h> /* FIXME */
35 #define HEX_DIGITS "0123456789abcdef"
37 static char *program_name
;
39 static void error(const char *s
)
41 fprintf(stderr
, "%s: %s\n", program_name
, s
);
45 static void usage(FILE *stream
)
47 fprintf(stream
, "Synopsis: %s [-v] [pfb_file]\n", program_name
);
50 static void get_text(int n
)
59 if (c
== '(' && !is_comment
)
61 else if (c
== ')' && !is_comment
)
63 else if (c
== '%' && !in_string
)
65 else if (c
== '\\' && in_string
) {
71 /* don't split octal character representations */
72 if (c
>= '0' && c
<= '7') {
78 if (c
>= '0' && c
<= '7') {
84 if (c
>= '0' && c
<= '7') {
95 error("end of file in text packet");
110 else if (count
>= MAX_LINE_LENGTH
) {
116 else if (is_comment
) {
122 /* split at the next whitespace character */
123 while (c
!= ' ' && c
!= '\t' && c
!= '\f') {
141 static void get_binary(int n
)
149 error("end of file in binary packet");
150 if (count
>= BYTES_PER_LINE
) {
155 putchar(HEX_DIGITS
[(c
>> 4) & 0xf]);
156 putchar(HEX_DIGITS
[c
& 0xf]);
161 int main(int argc
, char **argv
)
164 static const struct option long_options
[] = {
165 { "help", no_argument
, 0, CHAR_MAX
+ 1 },
166 { "version", no_argument
, 0, 'v' },
170 program_name
= argv
[0];
172 while ((opt
= getopt_long(argc
, argv
, "v", long_options
, NULL
)) != EOF
) {
175 printf(L_PFBTOPS
" (" T_ROFF
") v" VERSION
);
178 case CHAR_MAX
+ 1: /* --help */
189 if (argc
- optind
> 1) {
193 if (argc
> optind
&& !freopen(argv
[optind
], "r", stdin
)) {
194 perror(argv
[optind
]);
197 SET_BINARY(fileno(stdin
));
204 error("first byte of packet not 0x80");
208 if (type
!= 1 && type
!= 2)
209 error("bad packet type");
211 for (i
= 0; i
< 4; i
++) {
214 error("end of file in packet header");
215 n
|= (long)c
<< (i
<< 3);
218 error("negative packet length");