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   
C/C++ Source or Header  |  1992-05-31  |  2KB  |  79 lines

  1. #include <stdio.h>
  2. error(s)
  3. char *s ;
  4. {
  5.    fprintf(stderr, "undos: %s\n", s) ;
  6.    if (*s == '!')
  7.       exit(10) ;
  8. }
  9. char *hxdata = "0123456789ABCDEF" ;
  10. main() {
  11.    int c, prevc ;
  12.    long len ;
  13.  
  14.    c = getc(stdin) ;
  15.    if (c != 0x80)
  16.       error("! not an MSDOS font file") ;
  17.    while (1) {
  18.       c = getc(stdin) ;
  19.       switch(c) {
  20. case 1:
  21. case 2:
  22.          len = getc(stdin) ;
  23.          len += getc(stdin) * 256L ;
  24.          len += getc(stdin) * 65536L ;
  25.          len += getc(stdin) * 256L * 65536 ;
  26.          if (c == 1) {
  27.             while (len > 0) {
  28.                c = getc(stdin) ;
  29.                if (c == EOF) {
  30.                   error("premature EOF in MS-DOS font file") ;
  31.                   len = 0 ;
  32.                } else {
  33.                   if (c == 13)
  34.                      (void)putc(10, stdout) ;
  35.                   else
  36.                      (void)putc(c, stdout) ;
  37.                   len-- ;
  38.                }
  39.             }
  40.          } else {
  41.             putc(10, stdout) ;
  42.             prevc = 0 ;
  43.             while (len > 0) {
  44.                c = getc(stdin) ;
  45.                if (c == EOF) {
  46.                   error("premature EOF in MS-DOS font file") ;
  47.                   len = 0 ;
  48.                } else {
  49.                   (void)putc(hxdata[c >> 4], stdout) ;
  50.                   (void)putc(hxdata[c & 15], stdout) ;
  51.                   len-- ;
  52.                   prevc += 2 ;
  53.                   if (prevc >= 76) {
  54.                      putc(10, stdout) ;
  55.                      prevc = 0 ;
  56.                   }
  57.                }
  58.             }
  59.          }
  60.          break ;
  61. case 3:
  62.          goto msdosdone ;
  63. default:
  64.          error("saw type other than 1, 2, or 3 in MS-DOS font file") ;
  65.          break ;
  66.       }
  67.       c = getc(stdin) ;
  68.       if (c == EOF)
  69.          break ;
  70.       if (c != 0x80) {
  71.          error("saw non-MSDOS header in MSDOS font file") ;
  72.          break ;
  73.       }
  74.    }
  75. msdosdone:
  76.    if (prevc != 10)
  77.       (void)putc('\n', stdout) ;
  78. }
  79.