change function definitions

Buffers are no longer wired into any input or translation functions.
They are supplied as arguments through main.
This commit is contained in:
Eric 2025-05-26 12:23:54 +02:00
parent 9b1fe95a8e
commit 848c3749d2
5 changed files with 53 additions and 60 deletions

31
main.c
View file

@ -3,12 +3,17 @@
#include "input.h"
#include "trans.h"
#define OBUFSIZE 4
#define SBUFSIZE 5
unsigned char obuf[OBUFSIZE];
unsigned char sbuf[SBUFSIZE];
int
main(int argc, char *argv[])
{
int c, n, dec, hlp;
char *prog = *argv;
unsigned char *b;
FILE *fp;
dec = hlp = 0;
@ -30,13 +35,15 @@ main(int argc, char *argv[])
fprintf(stdout, "Usage: %s -d -h file\n", prog);
} else if (argc != 1) {
if (dec) {
while ((b = getsxts(stdin, &n))) {
b = decode(b, &n);
fwrite(b, sizeof(*b), n, stdout);
while ((n = getsxts(stdin, sbuf, SBUFSIZE))) {
n = decode(sbuf, n, obuf);
fwrite(obuf, sizeof(*obuf), n, stdout);
}
} else {
while ((b = getocts(stdin, &n)))
printf("%s", encode(b, n));
while ((n = getocts(stdin, obuf, OBUFSIZE))) {
encode(obuf, n, sbuf);
printf("%s", sbuf);
}
}
} else {
if ((fp = fopen(*argv, "r")) == NULL) {
@ -44,13 +51,15 @@ main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
else if (dec) {
while ((b = getsxts(fp, &n))) {
b = decode(b, &n);
fwrite(b, sizeof(*b), n, stdout);
while ((n = getsxts(fp, sbuf, SBUFSIZE))) {
n = decode(sbuf, n, obuf);
fwrite(obuf, sizeof(*obuf), n, stdout);
}
} else {
while ((b = getocts(fp, &n)))
printf("%s", encode(b, n));
while ((n = getocts(fp, obuf, OBUFSIZE))) {
encode(obuf, n, sbuf);
printf("%s", sbuf);
}
}
fclose(fp);
}