remove getsxts for better function readb

Decoding input is read faster now.
With this, all options have been tuned to a reasonable degree.
This commit is contained in:
Eric 2025-05-29 01:24:37 +02:00
parent 0a4a98390d
commit d921c1d860
3 changed files with 18 additions and 13 deletions

27
input.c
View file

@ -1,19 +1,24 @@
#include "input.h"
#define PADDING '='
#define SXTETBUF 4
int
getsxts(FILE *fp, unsigned char *s)
readb(FILE *fp, unsigned char *s, int slen)
{
int c, n, pad;
unsigned char *send;
unsigned char *sbeg;
unsigned char *l, *r;
sbeg = s;
send = s + fread(s, sizeof(*s), slen, fp);
for (l = r = sbeg; r < send; ++r)
if (*r != '\n')
*l++ = *r;
if (l > sbeg) {
for (--l; *l == PADDING; --l)
;
++l;
}
n = pad = 0;
while (n < SXTETBUF && (c = fgetc(fp)) != EOF && c != PADDING)
if (c != '\n')
s[n++] = c;
while (n+pad < SXTETBUF)
s[n+pad++] = PADDING;
return n;
return l-sbeg;
}

View file

@ -4,6 +4,6 @@
#include <stdio.h>
int
getsxts(FILE *fp, unsigned char *s);
readb(FILE *fp, unsigned char *s, int slen);
#endif

2
main.c
View file

@ -53,7 +53,7 @@ main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
if (dec) {
while ((n = getsxts((in) ? in : stdin, sbuf))) {
while ((n = readb((in) ? in : stdin, sbuf, SXTETBUF))) {
n = decode(sbuf, n, obuf, url);
fwrite(obuf, sizeof(*obuf), n, (out) ? out : stdout);
}