1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
/*
ecc Version 1.2 by Paul Flaherty (paulf@stanford.edu)
Copyright (C) 1993 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* ecc.c
Basic Software Tool for Encoding and Decoding Files.
This is a simple stream encoder which uses the rslib routines to
do something practical. It reads data from stdin in 248(encode) or
256(decode) blocks, and writes the corresponding encoded/decoded
block onto stdout. An encoded block contains 248 data bytes, one
length byte, six redundancy bytes, and a capital G byte as a sync
marker to round it out to 256 bytes.
*/
#include <stdio.h>
#include <sys/types.h>
main (argc, argv)
int argc;
char *argv[];
{
int ec;
if (argc != 2)
{
fprintf (stderr, "usage: ecc [-edv] \n");
exit (1);
}
if (strcmp ("-e", argv[1]) == 0)
encode ();
if (strcmp ("-d", argv[1]) == 0)
decode ();
if (strcmp ("-v", argv[1]) == 0)
ver ();
fprintf (stderr, "usage: ecc [-edv] \n");
exit (1);
}
ver ()
{
extern char version[];
fprintf (stderr, "%s\n", version);
exit (0);
}
encode ()
{
unsigned char msg[249], coded[255];
int i, readme;
for (i = 0; i < 249; i++)
msg[i] = 0;
readme = 248;
while (readme == 248)
{
readme = fread (msg, 1, 248, stdin);
msg[248] = readme;
rsencode (msg, coded);
fprintf (stdout, "G");
for (i = 254; i > -1; i--)
fprintf (stdout, "%c", coded[i]);
}
exit (0);
}
decode ()
{
int i, j, readme, bo, len;
unsigned char msgs[249], cod[255];
j = 0;
while (getc (stdin) == 71)
{
j++;
for (i = 254; i > -1; i--)
cod[i] = getc (stdin);
rsdecode (cod, msgs, &bo);
if (bo > 0 && bo < 4)
fprintf (stderr, "ecc: %d byte error in block %d.\n", bo, j);
if (bo == 4)
fprintf (stderr, "ecc: unrecoverable error in block %d.\n", j);
len = msgs[248];
for (i = 0; i < len; i++)
putc (msgs[i], stdout);
}
if (getc (stdin) != EOF)
{
fprintf (stderr, "ecc: sync error in block %d.\n", j);
exit (1);
}
exit (0);
}
|