home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
NeXTSTEP 3.3.4.17 [SPARC, PA-RISC]
/
nextstep33_risc.iso
/
NextLibrary
/
TeX
/
tex
/
src
/
misc
/
undos.c
< prev
Wrap
C/C++ Source or Header
|
1992-05-31
|
2KB
|
79 lines
#include <stdio.h>
error(s)
char *s ;
{
fprintf(stderr, "undos: %s\n", s) ;
if (*s == '!')
exit(10) ;
}
char *hxdata = "0123456789ABCDEF" ;
main() {
int c, prevc ;
long len ;
c = getc(stdin) ;
if (c != 0x80)
error("! not an MSDOS font file") ;
while (1) {
c = getc(stdin) ;
switch(c) {
case 1:
case 2:
len = getc(stdin) ;
len += getc(stdin) * 256L ;
len += getc(stdin) * 65536L ;
len += getc(stdin) * 256L * 65536 ;
if (c == 1) {
while (len > 0) {
c = getc(stdin) ;
if (c == EOF) {
error("premature EOF in MS-DOS font file") ;
len = 0 ;
} else {
if (c == 13)
(void)putc(10, stdout) ;
else
(void)putc(c, stdout) ;
len-- ;
}
}
} else {
putc(10, stdout) ;
prevc = 0 ;
while (len > 0) {
c = getc(stdin) ;
if (c == EOF) {
error("premature EOF in MS-DOS font file") ;
len = 0 ;
} else {
(void)putc(hxdata[c >> 4], stdout) ;
(void)putc(hxdata[c & 15], stdout) ;
len-- ;
prevc += 2 ;
if (prevc >= 76) {
putc(10, stdout) ;
prevc = 0 ;
}
}
}
}
break ;
case 3:
goto msdosdone ;
default:
error("saw type other than 1, 2, or 3 in MS-DOS font file") ;
break ;
}
c = getc(stdin) ;
if (c == EOF)
break ;
if (c != 0x80) {
error("saw non-MSDOS header in MSDOS font file") ;
break ;
}
}
msdosdone:
if (prevc != 10)
(void)putc('\n', stdout) ;
}