summaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
authorwlemb <wlemb>2003-03-17 16:49:33 +0000
committerwlemb <wlemb>2003-03-17 16:49:33 +0000
commit47830dccff893113eeb68d40a0cd451830253397 (patch)
tree2099ba549cc9047ee51f37dc799320e91e583285 /src/utils
parentcab35a3943fa0842e46d87310827d44fb096dd70 (diff)
downloadgroff-47830dccff893113eeb68d40a0cd451830253397.tar.gz
* Makefile.in (LIBEXT): New variable to indicate the file extension
of library files. Computed heuristically from $(OBJEXT). (MDEFINES): Add $(LIBEXT). * Makefile.lib, Makefile.comm: Use it. * src/utils/pfbtops/pfbtops.c (get_text): New function. Split overlong lines into smaller chunks. (get_binary): New function. (main): Use them. * src/utils/pfbtops/pfbtops.man: Updated. * src/roff/groff/groff.man: Minor syntax fix.
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/pfbtops/pfbtops.c135
-rw-r--r--src/utils/pfbtops/pfbtops.man5
2 files changed, 105 insertions, 35 deletions
diff --git a/src/utils/pfbtops/pfbtops.c b/src/utils/pfbtops/pfbtops.c
index 4cb31018..821d9019 100644
--- a/src/utils/pfbtops/pfbtops.c
+++ b/src/utils/pfbtops/pfbtops.c
@@ -49,6 +49,103 @@ static void usage(FILE *stream)
fprintf(stream, "usage: %s [-v] [pfb_file]\n", program_name);
}
+static void get_text(int n)
+{
+ int c, 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);
+ c = getchar();
+ /* don't split octal character representations */
+ if (c >= '0' && c <= '7') {
+ count++;
+ putchar(c);
+ c = getchar();
+ if (c >= '0' && c <= '7') {
+ count++;
+ putchar(c);
+ c = getchar();
+ if (c >= '0' && c <= '7') {
+ count++;
+ putchar(c);
+ c = getchar();
+ }
+ }
+ }
+ }
+ if (c == EOF)
+ error("end of file in text packet");
+ else if (c == '\r') {
+ c1 = getchar();
+ if (c1 != '\n')
+ ungetc(c1, stdin);
+ 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);
+ 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(argc, argv)
int argc;
char **argv;
@@ -93,7 +190,7 @@ int main(argc, argv)
}
SET_BINARY(fileno(stdin));
for (;;) {
- int type, c, c1, i;
+ int type, c, i;
long n;
c = getchar();
@@ -113,38 +210,10 @@ int main(argc, argv)
}
if (n < 0)
error("negative packet length");
- if (type == 1) {
- while (--n >= 0) {
- c = getchar();
- if (c == EOF)
- error("end of file in text packet");
- if (c == '\r') {
- c1 = getchar();
- if (c1 != '\n')
- ungetc(c1, stdin);
- c = '\n';
- }
- putchar(c);
- }
- if (c != '\n')
- putchar('\n');
- }
- else {
- 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');
- }
+ if (type == 1)
+ get_text(n);
+ else
+ get_binary(n);
}
exit(0);
}
diff --git a/src/utils/pfbtops/pfbtops.man b/src/utils/pfbtops/pfbtops.man
index 9c7b2b8c..627e5c5e 100644
--- a/src/utils/pfbtops/pfbtops.man
+++ b/src/utils/pfbtops/pfbtops.man
@@ -1,5 +1,5 @@
.ig
-Copyright (C) 1989-1995, 2001 Free Software Foundation, Inc.
+Copyright (C) 1989-1995, 2001, 2003 Free Software Foundation, Inc.
Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
@@ -28,7 +28,8 @@ pfbtops \- translate a PostScript font in .pfb format to ASCII
.B pfbtops
translates a PostScript font in
.B .pfb
-format to ASCII.
+format to ASCII, 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.