home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / tapeutils.zip / tucpad.c < prev    next >
C/C++ Source or Header  |  1988-08-16  |  1KB  |  44 lines

  1. /*
  2.   Program to unpack an ANSI D-Format file into stream format.
  3.   Christine Gianone, Columbia U, Jan 88.
  4. */
  5.  
  6. #include <stdio.h>
  7. #include <ctype.h>
  8.  
  9. main() {
  10.     char buf[10001];            /* Record buffer */
  11.     int n;                /* Length indicator */
  12.  
  13.     while ((n = readlen()) > -1) {    /* Read a length field. */
  14.     buf[0] = '\0';            /* Clear record buffer. */
  15.     if (n > 0) {            /* If record not null, */
  16.         read(0,buf,n);        /*  read it, */
  17.         buf[n] = '\0';        /*  null-terminate it. */
  18.     }
  19.     puts(buf);            /* Write it out, with newline. */
  20.     }
  21. }
  22.  
  23. readlen() {                /* Function to read length field. */
  24.     int x, n = 0, i;
  25.     char c;
  26.  
  27.     for (i = 0; i < 4; i++) {        /* Read 4-character length field. */
  28.     x = read(0,&c,1);        /* Read one character. */
  29.     if (x < 1) {            /* If we got an error, give up. */
  30.         return(-1);
  31.     }
  32.     if ((c == '^') && (i == 0)) {    /* Skip past leading circumflexes. */
  33.         i--;
  34.         continue;
  35.     }
  36.     if (!isdigit(c)) {        /* Make sure character is a digit. */
  37.         fprintf(stderr,"%s","File not in ANSI D format\n");
  38.         return(-1);
  39.     }
  40.     n = (10 * n) + (c - '0');    /* Convert to number. */
  41.     }
  42.     return(n-4);            /* Subtract 4 from length and return */
  43. }
  44.