fixed decoding of files smaller than blocksize, fixed check for EOF without newline

This commit is contained in:
git@daemon.de
2014-03-04 23:07:08 +01:00
parent 8fe28625fc
commit 9d60f7524d

View File

@@ -137,7 +137,9 @@ size_t ps_read_raw(Pcpstream *stream, void *buf, size_t readbytes) {
stream->err = 1; stream->err = 1;
} }
rawdone: rawdone:
//_dump("ps_read_raw", buf, gotbytes);
return gotbytes; return gotbytes;
} }
@@ -294,7 +296,7 @@ int ps_readline(Pcpstream *stream, Buffer *line) {
//fprintf(stderr, " ps_readline: raw found CR\n"); //fprintf(stderr, " ps_readline: raw found CR\n");
continue; continue;
} }
else if(*b == '\n' || ps_left(stream) == 1) { else if(*b == '\n' || ps_end(stream) == 1) {
//fprintf(stderr, " ps_readline: raw found NL\n"); //fprintf(stderr, " ps_readline: raw found NL\n");
c++; c++;
max = 0; max = 0;
@@ -328,7 +330,7 @@ void ps_determine(Pcpstream *stream) {
/* check if it's binary or not */ /* check if it's binary or not */
if(_buffer_is_binary(buf, got) == 0) { if(_buffer_is_binary(buf, got) == 0) {
/* no, it's armored */ /* not binary, it's armored */
stream->armor = 1; stream->armor = 1;
/* put back raw data into read queue */ /* put back raw data into read queue */
@@ -365,11 +367,13 @@ size_t ps_read_decode(Pcpstream *stream) {
buffer_left(stream->save), stream->blocksize); */ buffer_left(stream->save), stream->blocksize); */
buffer_get_chunk_tobuf(stream->save, z, stream->blocksize); buffer_get_chunk_tobuf(stream->save, z, stream->blocksize);
} }
else if(ps_left(stream) == 1 && buffer_left(stream->save) > 0) { else if(ps_left(stream) == 1 && buffer_left(stream->save) > 0 && stream->firstread == 1) {
/* there's something left which doesn't end in a newline */ /* there's something left which doesn't end in a newline,
but only if this is not our first read, in which case
we need to run into the readline loop at least once. */
// fprintf(stderr, " ps_read_next which doesn't end in a newline\n"); // fprintf(stderr, " ps_read_next which doesn't end in a newline\n");
buffer_get_chunk_tobuf(stream->save, z, buffer_left(stream->save)); buffer_get_chunk_tobuf(stream->save, z, buffer_left(stream->save));
buffer_dump(z); //buffer_dump(z);
fatals_ifany(); fatals_ifany();
} }
else { else {
@@ -425,11 +429,13 @@ size_t ps_read_decode(Pcpstream *stream) {
} }
} }
// fprintf(stderr, "Z: <%s>\n", buffer_get_str(z)); //fprintf(stderr, "%s\n", buffer_get_str(z));
/* finally, decode it and put into next */ /* finally, decode it and put into next */
size_t binlen, outlen; size_t binlen, outlen;
byte *bin = pcp_z85_decode(buffer_get_str(z), &binlen); byte *bin = pcp_z85_decode(buffer_get_str(z), &binlen);
//fprintf(stderr, "ps_read_decode decoding z: %ld, got: %ld\n", buffer_size(z), binlen);
// _dump("bin", bin, binlen);
fatals_ifany(); fatals_ifany();
if(bin == NULL) { if(bin == NULL) {
/* it's not z85 encoded, so threat it as binary */ /* it's not z85 encoded, so threat it as binary */
@@ -448,7 +454,6 @@ size_t ps_read_decode(Pcpstream *stream) {
else { else {
/* yes, successfully decoded it, put into cache */ /* yes, successfully decoded it, put into cache */
buffer_add(stream->next, bin, binlen); buffer_add(stream->next, bin, binlen);
// fprintf(stderr, "ps_read_decode decoded: <%s>\n", buffer_get_str(stream->next));
outlen = binlen; outlen = binlen;
} }