1 /* add.c not copyrighted (n) 1993 by Mark Adler */
2 /* version 1.1 11 Jun 1993 */
4 /* This filter reverses the effect of the sub filter. It requires no
5 arguments, since sub puts the information necessary for extraction
6 in the stream. See sub.c for what the filtering is and what it's
12 #define MAGIC1 'S' /* sub data */
13 #define MAGIC2 26 /* ^Z */
14 #define MAX_DIST 16384
16 char a
[MAX_DIST
]; /* last byte buffer for up to MAX_DIST differences */
20 int n
; /* number of differences */
21 int i
; /* difference counter */
22 int c
; /* byte from input */
24 /* check magic word */
25 if (getchar() != MAGIC1
|| getchar() != MAGIC2
)
27 fputs("add: input stream not made by sub\n", stderr
);
31 /* get number of differences from data */
32 if ((n
= getchar()) == EOF
|| (i
= getchar()) == EOF
) {
33 fputs("add: unexpected end of file\n", stderr
);
37 if (n
<= 0 || n
> MAX_DIST
) {
38 fprintf(stderr
, "add: incorrect distance %d\n", n
);
42 /* initialize last byte */
48 /* read differenced data and restore original */
49 while ((c
= getchar()) != EOF
)
51 c
= (a
[i
++] += c
) & 0xff; /* restore data, save last byte */
52 putchar(c
); /* write original */
53 if (i
== n
) /* cycle on n differences */
57 return 0; /* avoid warning */