home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 28 / amigaformatcd28.iso / -seriously_amiga- / archivers / codegroup / codegroup.c < prev    next >
C/C++ Source or Header  |  1998-05-09  |  16KB  |  657 lines

  1. /*
  2.  
  3.        Encode or decode file as five letter code groups
  4.  
  5.            by John Walker  --  kelvin@fourmilab.ch
  6.            WWW home page: http://www.fourmilab.ch/
  7.  
  8.         This program is in the public domain.
  9.  
  10.        December 1986: Original version
  11.            July 1995: Unified encoder and decoder in one program,
  12.               replaced ad-hoc checksum with CRC-16.
  13.  
  14. */
  15.  
  16. #define REVDATE "9th July 1995"
  17.  
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <ctype.h>
  21. #include <string.h>
  22.  
  23. #define TRUE  1
  24. #define FALSE 0
  25.  
  26. typedef unsigned char byte;          /* Byte type */
  27.  
  28. #define EOS '\0'
  29.  
  30. #define GROUPLEN 5              /* Code group type */
  31. #define LINELEN  64              /* Maximum line length */
  32. #define ERRMAX     10              /* Maximum data lost messages to print */
  33.  
  34. static FILE *fi = stdin;          /* Input file */
  35. static FILE *fo = stdout;          /* Output file */
  36.  
  37. static char groupbuf[GROUPLEN + 1];   /* Group assembly buffer */
  38. static char linebuf[LINELEN + 4];     /* Line editing buffer */
  39. static byte iobuf[256];           /* I/O buffer */
  40. static byte obuf[32];              /* Output assembly buffer */
  41. static long gcount = 0L;          /* Groups sent count */
  42. static long cksum = 0L;           /* Data checksum */
  43.  
  44. static int gblen = 0;              /* Group bytes used count */
  45. static int linelen = 0;           /* Bytes used in line */
  46.  
  47. static int gprefix;              /* Prefix for data block group */
  48. static int iolen = 0;              /* Bytes left in I/O buffer */
  49. static int iocp = 256;              /* Character removal pointer */
  50. static int ateof = FALSE;          /* EOF encountered */
  51. static int obnib = 0;              /* Output nybble index */
  52. static int obbyte = 0;              /* Output byte index */
  53.  
  54. static int exitstat = 0;          /* Exit status */
  55.  
  56. /*  This is the precomputed remainder table for generating and
  57.     checking cyclic redundancy check characters.  */
  58.  
  59. static byte low8[] = {
  60.     0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,0x01,0xC0,
  61.     0x80,0x41,0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,
  62.     0x00,0xC1,0x81,0x40,0x00,0xC1,0x81,0x40,0x01,0xC0,
  63.     0x80,0x41,0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,
  64.     0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,0x00,0xC1,
  65.     0x81,0x40,0x01,0xC0,0x80,0x41,0x01,0xC0,0x80,0x41,
  66.     0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,0x00,0xC1,
  67.     0x81,0x40,0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,
  68.     0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,0x01,0xC0,
  69.     0x80,0x41,0x00,0xC1,0x81,0x40,0x00,0xC1,0x81,0x40,
  70.     0x01,0xC0,0x80,0x41,0x01,0xC0,0x80,0x41,0x00,0xC1,
  71.     0x81,0x40,0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,
  72.     0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,0x01,0xC0,
  73.     0x80,0x41,0x00,0xC1,0x81,0x40,0x00,0xC1,0x81,0x40,
  74.     0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,0x01,0xC0,
  75.     0x80,0x41,0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,
  76.     0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,0x01,0xC0,
  77.     0x80,0x41,0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,
  78.     0x00,0xC1,0x81,0x40,0x00,0xC1,0x81,0x40,0x01,0xC0,
  79.     0x80,0x41,0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,
  80.     0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,0x01,0xC0,
  81.     0x80,0x41,0x00,0xC1,0x81,0x40,0x00,0xC1,0x81,0x40,
  82.     0x01,0xC0,0x80,0x41,0x01,0xC0,0x80,0x41,0x00,0xC1,
  83.     0x81,0x40,0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,
  84.     0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,0x01,0xC0,
  85.     0x80,0x41,0x00,0xC1,0x81,0x40
  86. };
  87.  
  88. static byte high8[] = {
  89.     0x00,0xC0,0xC1,0x01,0xC3,0x03,0x02,0xC2,0xC6,0x06,
  90.     0x07,0xC7,0x05,0xC5,0xC4,0x04,0xCC,0x0C,0x0D,0xCD,
  91.     0x0F,0xCF,0xCE,0x0E,0x0A,0xCA,0xCB,0x0B,0xC9,0x09,
  92.     0x08,0xC8,0xD8,0x18,0x19,0xD9,0x1B,0xDB,0xDA,0x1A,
  93.     0x1E,0xDE,0xDF,0x1F,0xDD,0x1D,0x1C,0xDC,0x14,0xD4,
  94.     0xD5,0x15,0xD7,0x17,0x16,0xD6,0xD2,0x12,0x13,0xD3,
  95.     0x11,0xD1,0xD0,0x10,0xF0,0x30,0x31,0xF1,0x33,0xF3,
  96.     0xF2,0x32,0x36,0xF6,0xF7,0x37,0xF5,0x35,0x34,0xF4,
  97.     0x3C,0xFC,0xFD,0x3D,0xFF,0x3F,0x3E,0xFE,0xFA,0x3A,
  98.     0x3B,0xFB,0x39,0xF9,0xF8,0x38,0x28,0xE8,0xE9,0x29,
  99.     0xEB,0x2B,0x2A,0xEA,0xEE,0x2E,0x2F,0xEF,0x2D,0xED,
  100.     0xEC,0x2C,0xE4,0x24,0x25,0xE5,0x27,0xE7,0xE6,0x26,
  101.     0x22,0xE2,0xE3,0x23,0xE1,0x21,0x20,0xE0,0xA0,0x60,
  102.     0x61,0xA1,0x63,0xA3,0xA2,0x62,0x66,0xA6,0xA7,0x67,
  103.     0xA5,0x65,0x64,0xA4,0x6C,0xAC,0xAD,0x6D,0xAF,0x6F,
  104.     0x6E,0xAE,0xAA,0x6A,0x6B,0xAB,0x69,0xA9,0xA8,0x68,
  105.     0x78,0xB8,0xB9,0x79,0xBB,0x7B,0x7A,0xBA,0xBE,0x7E,
  106.     0x7F,0xBF,0x7D,0xBD,0xBC,0x7C,0xB4,0x74,0x75,0xB5,
  107.     0x77,0xB7,0xB6,0x76,0x72,0xB2,0xB3,0x73,0xB1,0x71,
  108.     0x70,0xB0,0x50,0x90,0x91,0x51,0x93,0x53,0x52,0x92,
  109.     0x96,0x56,0x57,0x97,0x55,0x95,0x94,0x54,0x9C,0x5C,
  110.     0x5D,0x9D,0x5F,0x9F,0x9E,0x5E,0x5A,0x9A,0x9B,0x5B,
  111.     0x99,0x59,0x58,0x98,0x88,0x48,0x49,0x89,0x4B,0x8B,
  112.     0x8A,0x4A,0x4E,0x8E,0x8F,0x4F,0x8D,0x4D,0x4C,0x8C,
  113.     0x44,0x84,0x85,0x45,0x87,0x47,0x46,0x86,0x82,0x42,
  114.     0x43,0x83,0x41,0x81,0x80,0x40
  115. };
  116.  
  117. static unsigned int crc1, crc2;       /* CRC accumulation cells */
  118.  
  119. /*  CRCCHAR  --  Include byte in CRC.  */
  120.  
  121. static void crcchar(byte b)
  122. {
  123.     unsigned int c;
  124.  
  125.     crc1 = low8[c = 0xFF & (b ^ crc1)] ^ crc2;
  126.     crc2 = high8[c];
  127. }
  128.  
  129. /*  CRCINIT  --  Initialise CRC computation.  */
  130.  
  131. static void crcinit(void)
  132. {
  133.     crc1 = crc2 = 0;
  134.     crcchar(1);               /* Guarantee no leading zeroes */
  135. }
  136.  
  137. /*  OUTLINE  --  Output next line  */
  138.  
  139. static void outline(void)
  140. {
  141.     linebuf[linelen++] = '\n';
  142.     fwrite(linebuf, linelen, 1, fo);
  143.     linelen = 0;
  144. }
  145.  
  146. /*  OUTGROUP  --  Output next group to line buffer  */
  147.  
  148. static void outgroup(void)
  149. {
  150.     if ((linelen + GROUPLEN + 1) > LINELEN) {
  151.     outline();
  152.     }
  153.     if (linelen > 0) {
  154.         linebuf[linelen++] = ' ';
  155.     }
  156.     strcpy(linebuf + linelen, groupbuf);
  157.     linelen += GROUPLEN;
  158.     gblen = 0;
  159.     gcount++;               /* Increment groups sent */
  160. }
  161.  
  162. /*  OUTCHAR  --  Output next character to group  */
  163.  
  164. static void outchar(int c)
  165. {
  166.     groupbuf[gblen++] = c;
  167.     if (gblen >= GROUPLEN) {
  168.     outgroup();
  169.     }
  170. }
  171.  
  172. /*  OUTBYTE  --  Output next encoded byte as two group characters  */
  173.  
  174. static void outbyte(int b)
  175. {
  176.     crcchar(b);
  177.     outchar('A' + ((b & 0xF0) >> 4));
  178.     outchar('A' + (b & 0xF));
  179. }
  180.  
  181. /*  OUT32  --  Output 32 byte data block  */
  182.  
  183. static void out32(int code, byte dbuf[32])
  184. {
  185.     int i;
  186.  
  187.     outchar(code);
  188.     for (i = 0; i < 32; i++) {
  189.     outbyte((int) dbuf[i]);
  190.     }
  191. }
  192.  
  193. /*  STORELONG  --  Store long value in I/O buffer (byte-order independent) */
  194.  
  195. static void storelong(byte *cp, long l)
  196. {
  197.     int i;
  198.  
  199.     for (i = 0; i < 4; i++) {
  200.     *cp++ = l & 0xFF;
  201.     l >>= 8;
  202.     }
  203. }
  204.  
  205. /*  ENGROUP  --  Encode binary file into code groups.  */
  206.  
  207. static void engroup(void)
  208. {
  209.     int i, l;
  210.  
  211.     strcpy(groupbuf, "ZZZZZ");        /* Place start sentinel */
  212.     outgroup();
  213.  
  214.     while (TRUE) {
  215.     l = fread(iobuf + 1, 1, 32, fi);
  216.     if (l <= 0) {
  217.         break;
  218.     }
  219.     if (l < 32) {
  220.         iobuf[0] = (byte) l;
  221.             out32('V', iobuf);
  222.     } else {
  223.             out32('Y', iobuf + 1);
  224.     }
  225.     }
  226.  
  227.     /* Emit ending record with group count and checksum. */
  228.  
  229.     storelong(iobuf, gcount);
  230.     cksum = (crc1 << 16) | crc2;
  231.     storelong(iobuf + 4, cksum);
  232.     for (i = 8; i < 32; i += 4) {
  233.     storelong(iobuf + i, cksum = (gcount ^ cksum) ^ (cksum >> 3)
  234.                  ^ (cksum << 3));
  235.     }
  236.     out32('U', iobuf);
  237.  
  238.     strcpy(groupbuf, "WWWWW");        /* Place end sentinel */
  239.     outgroup();
  240.     outline();
  241. }
  242.  
  243. /*  INBUF  --  Fill input buffer with data  */
  244.  
  245. static int inbuf(void)
  246. {
  247.     int l;
  248.  
  249.     if (ateof) {
  250.     return FALSE;
  251.     }
  252.     l = fread(iobuf, 1, 256, fi);     /* Read input buffer */
  253.     if (l <= 0) {
  254.     ateof = TRUE;
  255.     return FALSE;
  256.     }
  257.     iolen = l;
  258.     iocp = 0;
  259.     return TRUE;
  260. }
  261.  
  262. /*  INCHAR  --    Return next character from input  */
  263.  
  264. static int inchar(void)
  265. {
  266.     if (iocp >= iolen) {
  267.        if (!inbuf()) {
  268.       return EOF;
  269.     }
  270.     }
  271.  
  272.     return iobuf[iocp++];
  273. }
  274.  
  275. /*  INSIG  --  Return next significant input  */
  276.  
  277. static int insig(void)
  278. {
  279.     int c;
  280.     static int skipws = FALSE;          /* Skip white space flag */
  281.  
  282.     if (skipws) {
  283.     while (TRUE) {
  284.         c = inchar();
  285.             if (c == EOF || (c > ' ')) {
  286.         skipws = FALSE;
  287.         return c;
  288.         }
  289.     }
  290.     }
  291.     c = inchar();
  292.     if (c <= ' ') {
  293.         c = ' ';
  294.     skipws = TRUE;
  295.     }
  296.     return c;
  297. }
  298.  
  299. /*  INSKERR  --  Skip error.  Ignores input until next white space or end of
  300.          file.    */
  301.  
  302. static void inskerr(void)
  303. {
  304.     int ch;
  305.  
  306.     while (TRUE) {
  307.     ch = insig();
  308.         if (ch == EOF || ch == ' ') {
  309.         break;
  310.     }
  311.     }
  312. }
  313.  
  314. /*  INGROUP  --  Scan next code group into group buffer.  Returns FALSE
  315.          if an error is detected in the code group, EOF if the
  316.          end of file is hit, and TRUE if a valid group is assembled. */
  317.  
  318. static int ingroup(void)
  319. {
  320.     int gp = 0;               /* Group data pointer */
  321.     int ch;
  322.  
  323.     while (TRUE) {
  324.     ch = insig();
  325.     if (ch == EOF) {
  326.         return EOF;
  327.     }
  328.         if (ch != ' ') {
  329.             if (ch < 'A' || ch > 'Z') {
  330.         inskerr();
  331.         return FALSE;
  332.         }
  333.         groupbuf[gp++] = ch;
  334.         break;
  335.     }
  336.     }
  337.  
  338.     while (TRUE) {
  339.     ch = insig();
  340.         if (ch == EOF || ch == ' ') {
  341.         if (gp < 5) {
  342.         return FALSE;          /* Short groups got no reason to live */
  343.          }
  344.         gcount++;              /* Increment valid groups received */
  345.         return TRUE;
  346.     }
  347.         if (ch < 'A' || ch > 'Z') {
  348.         inskerr();
  349.         return FALSE;
  350.     }
  351.     if (gp >= 5) {
  352.         inskerr();              /* Group is too long */
  353.         return FALSE;
  354.     }
  355.     groupbuf[gp++] = ch;
  356.     }
  357.     /* NOTREACHED */
  358. }
  359.  
  360. /*  OSTORE  --    Store data group starting at specified offset.
  361.         Verifies that this is not a control
  362.         group being misinterpreted.  */
  363.  
  364. static int ostore(int x)
  365. {
  366.     int i, j;
  367.  
  368.     for (i = x; i < 5; i++) {
  369.         if (groupbuf[i] < 'A' || groupbuf[i] > ('A' + 15)) {
  370.         return FALSE;
  371.     }
  372.         j = groupbuf[i] - 'A';
  373.     if (obnib) {
  374.         obuf[obbyte++] |= j;
  375.         obnib = FALSE;
  376.     } else {
  377.         obuf[obbyte] = j << 4;
  378.         obnib = TRUE;
  379.     }
  380.     }
  381.     return TRUE;
  382. }
  383.  
  384. /*  IN32  --  Input data record.  Returns EOF if 'WWWWWW' terminator
  385.           group found, FALSE if an error is detected, and TRUE if
  386.           a valid group was decoded.  If a valid group was found, its
  387.           data is stored in OBUF, with the prefix letter in GPREFIX.
  388.           If an error was previously reported, all data is ignored    
  389.           until a valid start of record group is found.  */
  390.  
  391. static int in32(void)
  392. {
  393.     int inerr = FALSE;
  394.     int i, j;
  395.  
  396.     if (inerr) {
  397.     while (TRUE) {
  398.         i = ingroup();
  399.         if (i == EOF) {
  400.            return EOF;
  401.          }
  402.         if (i == TRUE) {
  403.                 if (groupbuf[0] == 'Y' || groupbuf[0] == 'V' ||
  404.                        (strcmp(groupbuf, "WWWWW") == 0)) {
  405.             inerr = FALSE;
  406.             break;
  407.         }
  408.         }
  409.     }
  410.     } else {
  411.     i = ingroup();
  412.     }
  413.     if (i == EOF || i == FALSE) {
  414.     inerr = TRUE;
  415.     return FALSE;
  416.     }
  417.     if (strcmp(groupbuf, "WWWWW") == 0) {
  418.     return EOF;
  419.     }
  420.     gprefix = groupbuf[0];
  421.     if (gprefix == 'Y' || gprefix == 'V' || gprefix == 'U') {
  422.     obnib = 0;
  423.     obbyte = 0;   
  424.     i = ostore(1);
  425.     if (i == FALSE) {
  426.         inerr = TRUE;
  427.         return FALSE;
  428.     }
  429.     for (j = 0; j < 12; j++) {
  430.         i = ingroup();
  431.         if (i == EOF || i == FALSE) {
  432.         inerr = TRUE;
  433.         return FALSE;
  434.         }
  435.         if (!ostore(0)) {
  436.         inerr = TRUE;
  437.         return FALSE;
  438.         }
  439.     }
  440.     for (j = 0; j < 32; j++) {
  441.         crcchar(obuf[j]);
  442.     }
  443.     return TRUE;
  444.     } else {
  445.     inerr = TRUE; 
  446.     return FALSE;
  447.     }
  448. }
  449.  
  450. /*  GETLONG  --  Load LONG from a byte stream in an order-independent
  451.          fashion.  */
  452.  
  453. static long getlong(byte *cp)
  454. {
  455.     int i;
  456.     long l;
  457.  
  458.     for (l = 0L, i = 0; i < 4; i++) {
  459.     l |= ((long) (*cp++)) << (i * 8);
  460.     }
  461.  
  462.     return l;
  463. }
  464.  
  465. /*  UNGROUP  --  Decode codegroups.  */
  466.  
  467. static void ungroup(void)
  468. {
  469.     int i, l, nerrs = 0;
  470.     long savegc, savecs;
  471.  
  472.     groupbuf[GROUPLEN] = EOS;          /* Set group terminator */
  473.  
  474.     /* Ignore all text before initial ZZZZZ group. */
  475.  
  476.     l = 0;
  477.     while (TRUE) {
  478.     i = insig();
  479.     if (i == EOF) {
  480.        break;
  481.     }
  482.         if (i == 'Z') {
  483.         l++;
  484.         if (l == 5) {
  485.         i = insig();
  486.         if (i == EOF) {
  487.             break;
  488.         }
  489.                 if (i == ' ') {
  490.             break;
  491.         } else {
  492.                     l = (i == 'Z' ? 5 : 0);
  493.         }
  494.         }
  495.     } else {
  496.         l = 0;
  497.     }
  498.     }
  499.  
  500.     /* If we hit end of file before finding the first code group, issue
  501.        an error message. */
  502.  
  503.     if (i == EOF) {
  504.         fprintf(stderr, "No code groups found in input.\n");
  505.     exitstat = 2;
  506.     return;
  507.     }
  508.  
  509.     gcount = 1;               /* Account for initial sentinel group */
  510.     while (TRUE) {
  511.     savegc = gcount;
  512.     cksum = (crc1 << 16) | crc2;
  513.     savecs = cksum;
  514.     i = in32();
  515.     if (i == EOF) {
  516.             fprintf(stderr, "Warning: count and checksum missing.\n");
  517.             fprintf(stderr, "         File may be incomplete.\n");
  518.         exitstat = 1;
  519.         return;
  520.     }
  521.     if (i == FALSE) {
  522.         if (++nerrs <= ERRMAX) {
  523.         fprintf(stderr,
  524.                    "Error: skipping to next group.  Data lost.\n");
  525.            exitstat = 1;
  526.          }
  527.     } else {
  528.             if (gprefix == 'U') {
  529.         if (nerrs > ERRMAX) {
  530.             nerrs = nerrs - ERRMAX;
  531.             fprintf(stderr,
  532.           "Too many errors.  %d additional data lost message%s suppressed.\n",
  533.                     nerrs, nerrs > 1 ? "s" : "");
  534.         }
  535.         gcount = getlong(obuf);
  536.         cksum = getlong(obuf + 4);
  537.         if (gcount > savegc) {
  538.                     fprintf(stderr, "Warning: groups missing from file.\n");
  539.             fprintf(stderr,
  540.                        "         Groups sent: %ld, Groups received %ld.\n",
  541.                gcount, savegc);
  542.             exitstat = 1;
  543.         } else if (gcount < savegc) {
  544.                     fprintf(stderr, "Warning: extraneous groups in file.\n");
  545.             fprintf(stderr,
  546.                        "         Groups sent: %ld, Groups received %ld.\n",
  547.                gcount, savegc);
  548.             exitstat = 1;
  549.         }
  550.         if (cksum != savecs) {
  551.             fprintf(stderr,
  552.                        "Warning: checksum error on file contents.\n");
  553. #ifdef DUMPCKSUM
  554.             fprintf(stderr,
  555.                        "         Checksum sent: %lX, received: %lX\n",
  556.               cksum, savecs);
  557. #endif
  558.             exitstat = 1;
  559.         }
  560.         if (in32() != EOF) {
  561.             fprintf(stderr,
  562.                      "Warning: extraneous material after final data block.\n");
  563.             exitstat = 1;
  564.         }
  565.            return;
  566.             } else if (gprefix == 'Y') {
  567.         fwrite(obuf, 32, 1, fo);
  568.         } else {
  569.         fwrite(obuf + 1, 1, obuf[0], fo);
  570.         }
  571.     }
  572.     }
  573. }
  574.  
  575. /*  Main program  */
  576.  
  577. int main(int argc, char *argv[])
  578. {
  579.     int i, f = 0, decode = FALSE;
  580.     char *cp, opt;
  581.  
  582.     for (i = 1; i < argc; i++) {
  583.     cp = argv[i];
  584.         if (*cp == '-') {
  585.         opt = *(++cp);
  586.         if (islower(opt)) {
  587.         opt = toupper(opt);
  588.         }
  589.         switch (opt) {
  590.  
  591.                 case 'D':
  592.             decode = TRUE;
  593.             break;
  594.  
  595.                 case 'E':
  596.             decode = FALSE;
  597.             break;
  598.  
  599.                 case 'U':
  600.                 case '?':
  601.  fprintf(stderr,"\n%s  --  Encode/decode file as code groups.  Call:", argv[0]);
  602.  fprintf(stderr,
  603.     "\n               %s [-e[ncode] / -d[ecode]] [infile] [outfile]", argv[0]);
  604.  fprintf(stderr,"\n");
  605.             return 0;
  606.        }
  607.     } else {
  608.         switch (f) {
  609.  
  610.         /** Warning!  On systems which distinguish text mode and
  611.             binary I/O (MS-DOS, Macintosh, etc.) the modes in these
  612.             open statements will have to be made conditional based
  613.             upon whether an encode or decode is being done, which
  614.                     will have to be specified earlier.  But it's worse: if
  615.             input or output is from standard input or output, the 
  616.             mode will have to be changed on the fly, which is
  617.                     generally system and compiler dependent.  'Twasn't me
  618.                     who couldn't conform to Unix CR/LF convention, so 
  619.                     don't ask me to write the code to work around
  620.                     Apple and Microsoft's incompatible standards. **/
  621.  
  622.         case 0:
  623.                     if (strcmp(cp, "-") != 0) {
  624.                         if ((fi = fopen(cp, "r")) == NULL) {
  625.                             fprintf(stderr, "Cannot open input file %s\n", cp);
  626.                 return 2;
  627.             }
  628.             }
  629.             f++;
  630.             break;
  631.  
  632.         case 1:
  633.                     if (strcmp(cp, "-") != 0) {
  634.                         if ((fo = fopen(cp, "w")) == NULL) {
  635.                             fprintf(stderr, "Cannot open output file %s\n", cp);
  636.                 return 2;
  637.             }
  638.             }
  639.             f++;
  640.             break;
  641.  
  642.         default:
  643.                     fprintf(stderr, "Too many file names specified.\n");
  644.             return 2;
  645.         }
  646.        }
  647.     }
  648.  
  649.     crcinit();
  650.     if (decode) {
  651.        ungroup();
  652.     } else {
  653.        engroup();
  654.     }
  655.     return exitstat;
  656. }
  657.