summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjosh.macdonald <jmacd@users.noreply.github.com>2007-09-12 08:49:48 +0000
committerjosh.macdonald <jmacd@users.noreply.github.com>2007-09-12 08:49:48 +0000
commitaa3d74e6f7bbc0d004d0479c595471b49cc92d0e (patch)
tree58494c6df176d5faf107376d1f6838343ee334a5
parenta5cf569debedee47fbe8d4f3b96a200cf677c623 (diff)
Fixes xdelta recode command, but does not implement adler32, source
info, app header, etc.
-rw-r--r--xdelta3/xdelta3-main.h54
-rw-r--r--xdelta3/xdelta3.c5
-rw-r--r--xdelta3/xdelta3.h2
3 files changed, 30 insertions, 31 deletions
diff --git a/xdelta3/xdelta3-main.h b/xdelta3/xdelta3-main.h
index 57ad3d2..1722f89 100644
--- a/xdelta3/xdelta3-main.h
+++ b/xdelta3/xdelta3-main.h
@@ -978,6 +978,22 @@ main_file_seek (main_file *xfile, xoff_t pos)
978 return ret; 978 return ret;
979} 979}
980 980
981/* This function simply writes the stream output buffer, if there is any, for encode, decode and recode
982 * commands. (The VCDIFF tools use main_print_func()). */
983static int
984main_write_output (xd3_stream* stream, main_file *ofile)
985{
986 int ret;
987
988 if (stream->avail_out > 0 &&
989 (ret = main_file_write (ofile, stream->next_out, stream->avail_out, "write failed")))
990 {
991 return ret;
992 }
993
994 return 0;
995}
996
981/****************************************************************************************** 997/******************************************************************************************
982 VCDIFF TOOLS 998 VCDIFF TOOLS
983 ******************************************************************************************/ 999 ******************************************************************************************/
@@ -1035,7 +1051,12 @@ main_print_window (xd3_stream* stream, main_file *xfile)
1035 { 1051 {
1036 uint code = stream->inst_sect.buf[0]; 1052 uint code = stream->inst_sect.buf[0];
1037 1053
1038 if ((ret = xd3_decode_instruction (stream))) { return ret; } 1054 if ((ret = xd3_decode_instruction (stream)))
1055 {
1056 XPR(NT "instruction decode error at %"Q"u: %s\n",
1057 stream->dec_winstart + size, stream->msg);
1058 return ret;
1059 }
1039 1060
1040 VC(UT " %06"Q"u %03u %s %3u", stream->dec_winstart + size, code, 1061 VC(UT " %06"Q"u %03u %s %3u", stream->dec_winstart + size, code,
1041 xd3_rtype_to_string (stream->dec_current1.type, option_print_cpymode), 1062 xd3_rtype_to_string (stream->dec_current1.type, option_print_cpymode),
@@ -1243,14 +1264,18 @@ main_recode_copy (xd3_stream* stream,
1243 return ret; 1264 return ret;
1244 } 1265 }
1245 1266
1246 memcpy (output->base, input->buf, input->size); 1267 memcpy (output->base,
1268 /* Note: decoder advances buf, so get base of buffer with
1269 * buf_max - size */
1270 input->buf_max - input->size,
1271 input->size);
1247 output->next = input->size; 1272 output->next = input->size;
1248 return 0; 1273 return 0;
1249} 1274}
1250 1275
1251// Re-encode one window 1276// Re-encode one window
1252static int 1277static int
1253main_recode_func (xd3_stream* stream, main_file *xfile) 1278main_recode_func (xd3_stream* stream, main_file *ofile)
1254{ 1279{
1255 int ret; 1280 int ret;
1256 1281
@@ -1274,8 +1299,7 @@ main_recode_func (xd3_stream* stream, main_file *xfile)
1274 1299
1275 // This jumps to xd3_emit_hdr() 1300 // This jumps to xd3_emit_hdr()
1276 recode_stream->enc_state = ENC_FLUSH; 1301 recode_stream->enc_state = ENC_FLUSH;
1277 //recode_stream->avail_in = stream->dec_tgtlen; 1302 recode_stream->avail_in = stream->dec_tgtlen;
1278 //recode_stream->n_emit = stream->dec_tgtlen;
1279 1303
1280 // Output loop 1304 // Output loop
1281 for (;;) 1305 for (;;)
@@ -1298,16 +1322,13 @@ main_recode_func (xd3_stream* stream, main_file *xfile)
1298 } 1322 }
1299 case XD3_GETSRCBLK: 1323 case XD3_GETSRCBLK:
1300 case 0: { 1324 case 0: {
1301 stream->msg = "invalid operation";
1302 return XD3_INTERNAL; 1325 return XD3_INTERNAL;
1303 } 1326 }
1304 default: 1327 default:
1305 return ret; 1328 return ret;
1306 } 1329 }
1307 1330
1308 if ((ret = main_file_write(xfile, 1331 if ((ret = main_write_output(recode_stream, ofile)))
1309 recode_stream->next_out,
1310 recode_stream->avail_out, "write failed")))
1311 { 1332 {
1312 return ret; 1333 return ret;
1313 } 1334 }
@@ -2052,21 +2073,6 @@ main_read_primary_input (main_file *ifile,
2052 return main_file_read (ifile, buf, size, nread, "input read failed"); 2073 return main_file_read (ifile, buf, size, nread, "input read failed");
2053} 2074}
2054 2075
2055/* This function simply writes the stream output buffer, if there is any. This is used
2056 * for both encode and decode commands. (The VCDIFF tools use main_print_func()). */
2057static int
2058main_write_output (xd3_stream* stream, main_file *ofile)
2059{
2060 int ret;
2061
2062 if (stream->avail_out > 0 && (ret = main_file_write (ofile, stream->next_out, stream->avail_out, "write failed")))
2063 {
2064 return ret;
2065 }
2066
2067 return 0;
2068}
2069
2070/* Open the main output file, sets a default file name, initiate recompression. This 2076/* Open the main output file, sets a default file name, initiate recompression. This
2071 * function is expected to fprint any error messages. */ 2077 * function is expected to fprint any error messages. */
2072static int 2078static int
diff --git a/xdelta3/xdelta3.c b/xdelta3/xdelta3.c
index fb6191d..ca90309 100644
--- a/xdelta3/xdelta3.c
+++ b/xdelta3/xdelta3.c
@@ -2832,8 +2832,6 @@ xd3_iopt_finish_encoding (xd3_stream *stream, xd3_rinst *inst)
2832 XD3_ASSERT (stream->unencoded_offset == inst->pos); 2832 XD3_ASSERT (stream->unencoded_offset == inst->pos);
2833 stream->unencoded_offset += inst->size; 2833 stream->unencoded_offset += inst->size;
2834 2834
2835 IF_DEBUG (stream->n_emit += inst->size);
2836
2837 inst->code2 = 0; 2835 inst->code2 = 0;
2838 2836
2839 XD3_CHOOSE_INSTRUCTION (stream, stream->iout, inst); 2837 XD3_CHOOSE_INSTRUCTION (stream, stream->iout, inst);
@@ -3290,8 +3288,6 @@ xd3_emit_hdr (xd3_stream *stream)
3290 usize_t inst_len; 3288 usize_t inst_len;
3291 usize_t addr_len; 3289 usize_t addr_len;
3292 3290
3293 XD3_ASSERT (stream->n_emit == stream->avail_in);
3294
3295 if (stream->current_window == 0) 3291 if (stream->current_window == 0)
3296 { 3292 {
3297 uint hdr_ind = 0; 3293 uint hdr_ind = 0;
@@ -3600,7 +3596,6 @@ xd3_encode_reset (xd3_stream *stream)
3600 int i; 3596 int i;
3601 xd3_output *olist; 3597 xd3_output *olist;
3602 3598
3603 IF_DEBUG (stream->n_emit = 0);
3604 stream->avail_in = 0; 3599 stream->avail_in = 0;
3605 stream->small_reset = 1; 3600 stream->small_reset = 1;
3606 stream->i_slots_used = 0; 3601 stream->i_slots_used = 0;
diff --git a/xdelta3/xdelta3.h b/xdelta3/xdelta3.h
index e43574f..d7aa657 100644
--- a/xdelta3/xdelta3.h
+++ b/xdelta3/xdelta3.h
@@ -814,8 +814,6 @@ struct _xd3_stream
814 /* memory usage */ 814 /* memory usage */
815 usize_t alloc_cnt; 815 usize_t alloc_cnt;
816 usize_t free_cnt; 816 usize_t free_cnt;
817
818 xoff_t n_emit;
819#endif 817#endif
820}; 818};
821 819