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:
parent
0a4a98390d
commit
debab62506
3 changed files with 23 additions and 13 deletions
30
input.c
30
input.c
|
@ -1,19 +1,29 @@
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
|
|
||||||
#define PADDING '='
|
#define PADDING '='
|
||||||
#define SXTETBUF 4
|
|
||||||
|
|
||||||
int
|
int
|
||||||
getsxts(FILE *fp, unsigned char *s)
|
readb(FILE *fp, unsigned char *s, int slen)
|
||||||
{
|
{
|
||||||
int c, n, pad;
|
int read, tread;
|
||||||
|
unsigned char *send, *sbeg;
|
||||||
|
unsigned char *l, *r;
|
||||||
|
|
||||||
n = pad = 0;
|
read = tread = 0;
|
||||||
while (n < SXTETBUF && (c = fgetc(fp)) != EOF && c != PADDING)
|
sbeg = l = r = s;
|
||||||
if (c != '\n')
|
while (tread < slen && (read = fread(l, sizeof(*l), slen-tread, fp))) {
|
||||||
s[n++] = c;
|
tread += read;
|
||||||
while (n+pad < SXTETBUF)
|
send = s + tread;
|
||||||
s[n+pad++] = PADDING;
|
for (r = l; r < send; ++r)
|
||||||
|
if (*r != '\n')
|
||||||
|
*l++ = *r;
|
||||||
|
tread -= r - l;
|
||||||
|
if (l > sbeg) {
|
||||||
|
for (--l; *l == PADDING; --l)
|
||||||
|
;
|
||||||
|
++l;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return n;
|
return l-sbeg;
|
||||||
}
|
}
|
||||||
|
|
2
input.h
2
input.h
|
@ -4,6 +4,6 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
int
|
int
|
||||||
getsxts(FILE *fp, unsigned char *s);
|
readb(FILE *fp, unsigned char *s, int slen);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
2
main.c
2
main.c
|
@ -53,7 +53,7 @@ main(int argc, char *argv[])
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
if (dec) {
|
if (dec) {
|
||||||
while ((n = getsxts((in) ? in : stdin, sbuf))) {
|
while ((n = readb((in) ? in : stdin, sbuf, SXTETBUF))) {
|
||||||
n = decode(sbuf, n, obuf, url);
|
n = decode(sbuf, n, obuf, url);
|
||||||
fwrite(obuf, sizeof(*obuf), n, (out) ? out : stdout);
|
fwrite(obuf, sizeof(*obuf), n, (out) ? out : stdout);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue