summaryrefslogtreecommitdiff
path: root/xdelta3/xdelta3-main.h
diff options
context:
space:
mode:
authordotdotisdead <dotdotisdead@a3eca27d-f21b-0410-9b4a-6511e771f64e>2007-01-07 03:19:22 +0000
committerdotdotisdead <dotdotisdead@a3eca27d-f21b-0410-9b4a-6511e771f64e>2007-01-07 03:19:22 +0000
commit6b8007761b66db36f7863cfb42270a8d0c8b9077 (patch)
treeb0c8be67cdefa42aea872bda19a09b75d109238f /xdelta3/xdelta3-main.h
parentbae7eb2b3db9664a5041a8dbefef5a2fa3847376 (diff)
Fixes the python module, there were some bugs in main.
Diffstat (limited to 'xdelta3/xdelta3-main.h')
-rwxr-xr-xxdelta3/xdelta3-main.h67
1 files changed, 30 insertions, 37 deletions
diff --git a/xdelta3/xdelta3-main.h b/xdelta3/xdelta3-main.h
index c4e6bf5..6374361 100755
--- a/xdelta3/xdelta3-main.h
+++ b/xdelta3/xdelta3-main.h
@@ -1,5 +1,6 @@
1/* xdelta 3 - delta compression tools and library 1/* xdelta 3 - delta compression tools and library
2 * Copyright (C) 2001 and onward. Joshua P. MacDonald 2 * Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007,
3 * Joshua P. MacDonald
3 * 4 *
4 * This program is free software; you can redistribute it and/or modify 5 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by 6 * it under the terms of the GNU General Public License as published by
@@ -67,7 +68,7 @@ const char* xd3_mainerror(int err_num);
67#define NT stderr, "xdelta3: " 68#define NT stderr, "xdelta3: "
68 69
69#define VC fprintf 70#define VC fprintf
70#define UT vcout, 71#define UT stdout,
71 72
72/* If none are set, default to posix. */ 73/* If none are set, default to posix. */
73#if (XD3_POSIX + XD3_STDIO + XD3_WIN32) == 0 74#if (XD3_POSIX + XD3_STDIO + XD3_WIN32) == 0
@@ -252,7 +253,6 @@ static char* option_smatch_config = NULL;
252static int option_no_compress = 0; 253static int option_no_compress = 0;
253static int option_no_output = 0; /* go through the motions, but do not open or write output */ 254static int option_no_output = 0; /* go through the motions, but do not open or write output */
254static const char *option_source_filename = NULL; 255static const char *option_source_filename = NULL;
255static const char *option_xdelta1 = "xdelta1";
256 256
257static usize_t option_winsize = XD3_DEFAULT_WINSIZE; 257static usize_t option_winsize = XD3_DEFAULT_WINSIZE;
258static usize_t option_srcwinsz = XD3_DEFAULT_SRCWINSZ; 258static usize_t option_srcwinsz = XD3_DEFAULT_SRCWINSZ;
@@ -305,9 +305,6 @@ static main_extcomp extcomp_types[] =
305 { "gzip", "-cf", "gzip", "-dcf", "G", "\037\213", 2, 0 }, 305 { "gzip", "-cf", "gzip", "-dcf", "G", "\037\213", 2, 0 },
306 { "compress", "-cf", "uncompress", "-cf", "Z", "\037\235", 2, 0 }, 306 { "compress", "-cf", "uncompress", "-cf", "Z", "\037\235", 2, 0 },
307 307
308 /* TODO: xdelta1 isn't working */
309 /*{ "xdelta1", "delta", "xdelta1", "patch", "1", "%XD", 3, RD_EXTERNAL_V1 },*/
310
311 /* TODO: add commandline support for magic-less formats */ 308 /* TODO: add commandline support for magic-less formats */
312 /*{ "lzma", "-cf", "lzma", "-dcf", "M", "]\000", 2, 0 },*/ 309 /*{ "lzma", "-cf", "lzma", "-dcf", "M", "]\000", 2, 0 },*/
313}; 310};
@@ -321,7 +318,7 @@ static int
321main_version (void) 318main_version (void)
322{ 319{
323 /* $Format: " P(RINT \"VERSION=3.$Xdelta3Version$\\n\");" $ */ 320 /* $Format: " P(RINT \"VERSION=3.$Xdelta3Version$\\n\");" $ */
324 P(RINT "VERSION=3.0i\n"); 321 P(RINT "VERSION=3.0j\n");
325 return EXIT_SUCCESS; 322 return EXIT_SUCCESS;
326} 323}
327 324
@@ -395,6 +392,7 @@ main_free (void *ptr)
395 { 392 {
396 IF_DEBUG (main_mallocs -= 1); 393 IF_DEBUG (main_mallocs -= 1);
397 main_free1 (NULL, ptr); 394 main_free1 (NULL, ptr);
395 IF_DEBUG (XD3_ASSERT(main_mallocs >= 0));
398 } 396 }
399} 397}
400 398
@@ -613,8 +611,9 @@ main_file_init (main_file *xfile)
613static void 611static void
614main_file_cleanup (main_file *xfile) 612main_file_cleanup (main_file *xfile)
615{ 613{
616 if (xfile->filename_copy) { 614 if (xfile->filename_copy != NULL) {
617 main_free(xfile->filename_copy); 615 main_free(xfile->filename_copy);
616 xfile->filename_copy = NULL;
618 } 617 }
619} 618}
620 619
@@ -901,7 +900,7 @@ main_file_seek (main_file *xfile, xoff_t pos)
901#if VCDIFF_TOOLS 900#if VCDIFF_TOOLS
902/* This function prints a single VCDIFF window, mainly for debugging purposes. */ 901/* This function prints a single VCDIFF window, mainly for debugging purposes. */
903static int 902static int
904main_print_window (xd3_stream* stream, FILE *vcout) 903main_print_window (xd3_stream* stream)
905{ 904{
906 int ret; 905 int ret;
907 usize_t size = 0; 906 usize_t size = 0;
@@ -965,13 +964,11 @@ main_print_window (xd3_stream* stream, FILE *vcout)
965 return XD3_INTERNAL; 964 return XD3_INTERNAL;
966 } 965 }
967 966
968 IF_DEBUG (VC(UT "SIZE=%u TGTLEN=%u\n", size, stream->dec_tgtlen));
969
970 return 0; 967 return 0;
971} 968}
972 969
973static void 970static void
974main_print_vcdiff_file (main_file *file, const char *type, FILE *vcout) 971main_print_vcdiff_file (main_file *file, const char *type)
975{ 972{
976 if (file->filename) { VC(UT "XDELTA filename (%s): %s\n", type, file->filename); } 973 if (file->filename) { VC(UT "XDELTA filename (%s): %s\n", type, file->filename); }
977 if (file->compressor) { VC(UT "XDELTA ext comp (%s): %s\n", type, file->compressor->recomp_cmdname); } 974 if (file->compressor) { VC(UT "XDELTA ext comp (%s): %s\n", type, file->compressor->recomp_cmdname); }
@@ -982,18 +979,6 @@ static int
982main_print_func (xd3_stream* stream, main_file *xfile) 979main_print_func (xd3_stream* stream, main_file *xfile)
983{ 980{
984 int ret; 981 int ret;
985 FILE *vcout;
986#if XD3_POSIX
987 if (! (vcout = fdopen (dup(xfile->file), "w")))
988 {
989 ret = get_errno ();
990 XPR(NT "fdopen: %s: %s\n", xfile->filename, xd3_mainerror (ret));
991 return ret;
992 }
993#elif XD3_STDIO
994 vcout = xfile->file;
995#endif
996 XD3_ASSERT (vcout);
997 if (stream->dec_winstart == 0) 982 if (stream->dec_winstart == 0)
998 { 983 {
999 VC(UT "VCDIFF version: 0\n"); 984 VC(UT "VCDIFF version: 0\n");
@@ -1021,7 +1006,7 @@ main_print_func (xd3_stream* stream, main_file *xfile)
1021 main_file i, o, s; 1006 main_file i, o, s;
1022 XD3_ASSERT (apphead != NULL); 1007 XD3_ASSERT (apphead != NULL);
1023 VC(UT "VCDIFF application header: "); 1008 VC(UT "VCDIFF application header: ");
1024 fwrite (apphead, 1, appheadsz, vcout); 1009 fwrite (apphead, 1, appheadsz, stdout);
1025 VC(UT "\n"); 1010 VC(UT "\n");
1026 1011
1027 main_file_init (& i); 1012 main_file_init (& i);
@@ -1030,8 +1015,8 @@ main_print_func (xd3_stream* stream, main_file *xfile)
1030 option_quiet = 1; 1015 option_quiet = 1;
1031 main_get_appheader (stream, &i, & o, & s); 1016 main_get_appheader (stream, &i, & o, & s);
1032 option_quiet = sq; 1017 option_quiet = sq;
1033 main_print_vcdiff_file (& o, "output", vcout); 1018 main_print_vcdiff_file (& o, "output");
1034 main_print_vcdiff_file (& s, "source", vcout); 1019 main_print_vcdiff_file (& s, "source");
1035 main_file_cleanup (& i); 1020 main_file_cleanup (& i);
1036 main_file_cleanup (& o); 1021 main_file_cleanup (& o);
1037 main_file_cleanup (& s); 1022 main_file_cleanup (& s);
@@ -1092,10 +1077,9 @@ main_print_func (xd3_stream* stream, main_file *xfile)
1092 } 1077 }
1093 else if ((stream->flags & XD3_SKIP_WINDOW) == 0) 1078 else if ((stream->flags & XD3_SKIP_WINDOW) == 0)
1094 { 1079 {
1095 ret = main_print_window (stream, vcout); 1080 ret = main_print_window (stream);
1096 } 1081 }
1097 1082
1098 fclose (vcout);
1099 return ret; 1083 return ret;
1100} 1084}
1101#endif /* VCDIFF_TOOLS */ 1085#endif /* VCDIFF_TOOLS */
@@ -1728,6 +1712,8 @@ main_get_appheader_params (main_file *file, char **parsed, int output, const cha
1728 1712
1729 if (last_slash != NULL) { 1713 if (last_slash != NULL) {
1730 int dlen = last_slash - other->filename; 1714 int dlen = last_slash - other->filename;
1715
1716 XD3_ASSERT(file->filename_copy == NULL);
1731 file->filename_copy = main_malloc(dlen + 2 + strlen(file->filename)); 1717 file->filename_copy = main_malloc(dlen + 2 + strlen(file->filename));
1732 1718
1733 strncpy(file->filename_copy, other->filename, dlen); 1719 strncpy(file->filename_copy, other->filename, dlen);
@@ -2453,7 +2439,8 @@ main_input (xd3_cmd cmd,
2453 case XD3_WINSTART: 2439 case XD3_WINSTART:
2454 { 2440 {
2455 /* Set or unset XD3_SKIP_WINDOW. */ 2441 /* Set or unset XD3_SKIP_WINDOW. */
2456 /*if (stream.current_window < option_first_window || stream.current_window > option_last_window) 2442 /*if (stream.current_window < option_first_window ||
2443 stream.current_window > option_last_window)
2457 { stream_flags |= XD3_SKIP_WINDOW; } 2444 { stream_flags |= XD3_SKIP_WINDOW; }
2458 else 2445 else
2459 { stream_flags &= ~XD3_SKIP_WINDOW; }*/ 2446 { stream_flags &= ~XD3_SKIP_WINDOW; }*/
@@ -2609,13 +2596,19 @@ main_cleanup (void)
2609{ 2596{
2610 int i; 2597 int i;
2611 2598
2612 if (option_appheader) { appheader_used = NULL; } 2599 if (appheader_used != NULL &&
2600 appheader_used != option_appheader)
2601 {
2602 main_free (appheader_used);
2603 appheader_used = NULL;
2604 }
2613 2605
2614 main_free (appheader_used);
2615 main_free (main_bdata); 2606 main_free (main_bdata);
2607 main_bdata = NULL;
2616 2608
2617#if EXTERNAL_COMPRESSION 2609#if EXTERNAL_COMPRESSION
2618 main_free (ext_tmpfile); 2610 main_free (ext_tmpfile);
2611 ext_tmpfile = NULL;
2619#endif 2612#endif
2620 2613
2621 for (i = 0; lru && i < lru_size; i += 1) 2614 for (i = 0; lru && i < lru_size; i += 1)
@@ -2624,6 +2617,7 @@ main_cleanup (void)
2624 } 2617 }
2625 2618
2626 main_free (lru); 2619 main_free (lru);
2620 lru = NULL;
2627 2621
2628 lru_hits = 0; 2622 lru_hits = 0;
2629 lru_misses = 0; 2623 lru_misses = 0;
@@ -2828,7 +2822,6 @@ main (int argc, char **argv)
2828 case 'T': option_use_altcodetable = 1; break; 2822 case 'T': option_use_altcodetable = 1; break;
2829 case 'C': option_smatch_config = my_optarg; break; 2823 case 'C': option_smatch_config = my_optarg; break;
2830 case 'J': option_no_output = 1; break; 2824 case 'J': option_no_output = 1; break;
2831 case 'O': option_xdelta1 = my_optarg; break;
2832 case 'S': if (my_optarg == NULL) { option_use_secondary = 0; } 2825 case 'S': if (my_optarg == NULL) { option_use_secondary = 0; }
2833 else { option_use_secondary = 1; option_secondary = my_optarg; } break; 2826 else { option_use_secondary = 1; option_secondary = my_optarg; } break;
2834 case 'A': if (my_optarg == NULL) { option_use_appheader = 0; } 2827 case 'A': if (my_optarg == NULL) { option_use_appheader = 0; }
@@ -2903,9 +2896,6 @@ main (int argc, char **argv)
2903 goto cleanup; 2896 goto cleanup;
2904 } 2897 }
2905 2898
2906 extcomp_types[1].recomp_cmdname = option_xdelta1;
2907 extcomp_types[1].decomp_cmdname = option_xdelta1;
2908
2909 if (option_verbose > 1) 2899 if (option_verbose > 1)
2910 { 2900 {
2911 int l = 1; 2901 int l = 1;
@@ -2989,7 +2979,10 @@ main (int argc, char **argv)
2989 } 2979 }
2990 2980
2991#if EXTERNAL_COMPRESSION 2981#if EXTERNAL_COMPRESSION
2992 if (ext_tmpfile != NULL) { unlink (ext_tmpfile); } 2982 if (ext_tmpfile != NULL)
2983 {
2984 unlink (ext_tmpfile);
2985 }
2993#endif 2986#endif
2994 2987
2995 if (0) 2988 if (0)