summaryrefslogtreecommitdiff
path: root/xdelta3/xdelta3-main.h
diff options
context:
space:
mode:
authorjosh.macdonald <jmacd@users.noreply.github.com>2007-02-18 02:41:57 +0000
committerjosh.macdonald <jmacd@users.noreply.github.com>2007-02-18 02:41:57 +0000
commitcb24126c313a791a0705a2ecb740ab373cc5a612 (patch)
tree96b31c24f34652d646d2b9cf382cfe142bce6d16 /xdelta3/xdelta3-main.h
parentf6cfb03ce353ba50c4d8d981014c038acc363e10 (diff)
raise default sprevsz, add command-line flag -P to set
Diffstat (limited to 'xdelta3/xdelta3-main.h')
-rw-r--r--xdelta3/xdelta3-main.h150
1 files changed, 75 insertions, 75 deletions
diff --git a/xdelta3/xdelta3-main.h b/xdelta3/xdelta3-main.h
index 2f1eb7f..3b7d11a 100644
--- a/xdelta3/xdelta3-main.h
+++ b/xdelta3/xdelta3-main.h
@@ -244,6 +244,10 @@ struct _main_blklru
244/* ... represented as a list (no cache index). */ 244/* ... represented as a list (no cache index). */
245XD3_MAKELIST(main_blklru_list,main_blklru,link); 245XD3_MAKELIST(main_blklru_list,main_blklru,link);
246 246
247// TODO:
248// struct _main_state
249// {
250
247/* Program options: various command line flags and options. */ 251/* Program options: various command line flags and options. */
248static int option_stdout = 0; 252static int option_stdout = 0;
249static int option_force = 0; 253static int option_force = 0;
@@ -264,10 +268,7 @@ static int option_level = XD3_DEFAULT_LEVEL;
264static usize_t option_iopt_size = XD3_DEFAULT_IOPT_SIZE; 268static usize_t option_iopt_size = XD3_DEFAULT_IOPT_SIZE;
265static usize_t option_winsize = XD3_DEFAULT_WINSIZE; 269static usize_t option_winsize = XD3_DEFAULT_WINSIZE;
266static usize_t option_srcwinsz = XD3_DEFAULT_SRCWINSZ; 270static usize_t option_srcwinsz = XD3_DEFAULT_SRCWINSZ;
267static int option_srcwinsz_set = 0; 271static usize_t option_sprevsz = XD3_DEFAULT_SPREVSZ;
268
269/* This controls the number of times main repeats itself, only for profiling. */
270static int option_profile_cnt = 0;
271 272
272/* These variables are supressed to avoid their use w/o support. main() warns 273/* These variables are supressed to avoid their use w/o support. main() warns
273 * appropriately. */ 274 * appropriately. */
@@ -317,6 +318,8 @@ static main_extcomp extcomp_types[] =
317 /*{ "lzma", "-cf", "lzma", "-dcf", "M", "]\000", 2, 0 },*/ 318 /*{ "lzma", "-cf", "lzma", "-dcf", "M", "]\000", 2, 0 },*/
318}; 319};
319 320
321// };
322
320static void main_get_appheader (xd3_stream *stream, main_file *ifile, 323static void main_get_appheader (xd3_stream *stream, main_file *ifile,
321 main_file *output, main_file *sfile); 324 main_file *output, main_file *sfile);
322 325
@@ -345,18 +348,18 @@ main_config (void)
345 P(RINT "VCDIFF_TOOLS=%d\n", VCDIFF_TOOLS); 348 P(RINT "VCDIFF_TOOLS=%d\n", VCDIFF_TOOLS);
346 P(RINT "XD3_ALLOCSIZE=%d\n", XD3_ALLOCSIZE); 349 P(RINT "XD3_ALLOCSIZE=%d\n", XD3_ALLOCSIZE);
347 P(RINT "XD3_DEBUG=%d\n", XD3_DEBUG); 350 P(RINT "XD3_DEBUG=%d\n", XD3_DEBUG);
351 P(RINT "XD3_ENCODER=%d\n", XD3_ENCODER);
352 P(RINT "XD3_POSIX=%d\n", XD3_POSIX);
353 P(RINT "XD3_STDIO=%d\n", XD3_STDIO);
354 P(RINT "XD3_WIN32=%d\n", XD3_WIN32);
355 P(RINT "XD3_USE_LARGEFILE64=%d\n", XD3_USE_LARGEFILE64);
348 P(RINT "XD3_DEFAULT_LEVEL=%d\n", XD3_DEFAULT_LEVEL); 356 P(RINT "XD3_DEFAULT_LEVEL=%d\n", XD3_DEFAULT_LEVEL);
349 P(RINT "XD3_DEFAULT_IOPT_SIZE=%d\n", XD3_DEFAULT_IOPT_SIZE); 357 P(RINT "XD3_DEFAULT_IOPT_SIZE=%d\n", XD3_DEFAULT_IOPT_SIZE);
350 P(RINT "XD3_DEFAULT_SPREVSZ=%d\n", XD3_DEFAULT_SPREVSZ); 358 P(RINT "XD3_DEFAULT_SPREVSZ=%d\n", XD3_DEFAULT_SPREVSZ);
351 P(RINT "XD3_DEFAULT_SRCWINSZ=%d\n", XD3_DEFAULT_SRCWINSZ); 359 P(RINT "XD3_DEFAULT_SRCWINSZ=%d\n", XD3_DEFAULT_SRCWINSZ);
352 P(RINT "XD3_DEFAULT_WINSIZE=%d\n", XD3_DEFAULT_WINSIZE); 360 P(RINT "XD3_DEFAULT_WINSIZE=%d\n", XD3_DEFAULT_WINSIZE);
353 P(RINT "XD3_ENCODER=%d\n", XD3_ENCODER);
354 P(RINT "XD3_HARDMAXWINSIZE=%d\n", XD3_HARDMAXWINSIZE); 361 P(RINT "XD3_HARDMAXWINSIZE=%d\n", XD3_HARDMAXWINSIZE);
355 P(RINT "XD3_NODECOMPRESSSIZE=%d\n", XD3_NODECOMPRESSSIZE); 362 P(RINT "XD3_NODECOMPRESSSIZE=%d\n", XD3_NODECOMPRESSSIZE);
356 P(RINT "XD3_USE_LARGEFILE64=%d\n", XD3_USE_LARGEFILE64);
357 P(RINT "XD3_POSIX=%d\n", XD3_POSIX);
358 P(RINT "XD3_STDIO=%d\n", XD3_STDIO);
359 P(RINT "XD3_WIN32=%d\n", XD3_WIN32);
360 363
361 return EXIT_SUCCESS; 364 return EXIT_SUCCESS;
362} 365}
@@ -364,29 +367,19 @@ main_config (void)
364static void 367static void
365reset_defaults(void) 368reset_defaults(void)
366{ 369{
370 // TODO: this is dumb, use an object
367 option_stdout = 0; 371 option_stdout = 0;
368 option_force = 0; 372 option_force = 0;
369 option_verbose = 0; 373 option_verbose = 0;
370 option_quiet = 0; 374 option_quiet = 0;
371 option_use_appheader = 1;
372 option_appheader = NULL; 375 option_appheader = NULL;
373 option_use_secondary = 0; 376 option_use_secondary = 0;
374 option_secondary = NULL; 377 option_secondary = NULL;
375 option_use_checksum = 1;
376 option_use_altcodetable = 0; 378 option_use_altcodetable = 0;
377 option_smatch_config = NULL; 379 option_smatch_config = NULL;
378 option_no_compress = 0; 380 option_no_compress = 0;
379 option_no_output = 0; 381 option_no_output = 0;
380 option_source_filename = NULL; 382 option_source_filename = NULL;
381 option_srcwinsz_set = 0;
382 option_profile_cnt = 0;
383#if EXTERNAL_COMPRESSION
384 option_decompress_inputs = 1;
385 option_recompress_outputs = 1;
386#endif
387#if VCDIFF_TOOLS
388 option_print_cpymode = 1;
389#endif
390 program_name = NULL; 383 program_name = NULL;
391 appheader_used = NULL; 384 appheader_used = NULL;
392 main_bdata = NULL; 385 main_bdata = NULL;
@@ -397,12 +390,22 @@ reset_defaults(void)
397 lru_misses = 0; 390 lru_misses = 0;
398 lru_filled = 0; 391 lru_filled = 0;
399 allow_fake_source = 0; 392 allow_fake_source = 0;
400 option_srcwinsz_set = 0;
401 option_smatch_config = NULL; 393 option_smatch_config = NULL;
394
395 option_use_appheader = 1;
396 option_use_checksum = 1;
397#if EXTERNAL_COMPRESSION
398 option_decompress_inputs = 1;
399 option_recompress_outputs = 1;
400#endif
401#if VCDIFF_TOOLS
402 option_print_cpymode = 1;
403#endif
402 option_level = XD3_DEFAULT_LEVEL; 404 option_level = XD3_DEFAULT_LEVEL;
403 option_srcwinsz = XD3_DEFAULT_SRCWINSZ; 405 option_iopt_size = XD3_DEFAULT_IOPT_SIZE;
404 option_winsize = XD3_DEFAULT_WINSIZE; 406 option_winsize = XD3_DEFAULT_WINSIZE;
405 option_srcwinsz = XD3_DEFAULT_SRCWINSZ; 407 option_srcwinsz = XD3_DEFAULT_SRCWINSZ;
408 option_sprevsz = XD3_DEFAULT_SPREVSZ;
406} 409}
407 410
408static void* 411static void*
@@ -2041,11 +2044,6 @@ main_set_source (xd3_stream *stream, int cmd, main_file *sfile, xd3_source *sour
2041 } 2044 }
2042 else 2045 else
2043 { 2046 {
2044 if (option_verbose)
2045 {
2046 XPR(NT "source file: %s\n", sfile->filename);
2047 }
2048
2049 if ((ret = main_file_open (sfile, sfile->filename, XO_READ)) || 2047 if ((ret = main_file_open (sfile, sfile->filename, XO_READ)) ||
2050 (ret = main_file_stat (sfile, & source->size, 1))) 2048 (ret = main_file_stat (sfile, & source->size, 1)))
2051 { 2049 {
@@ -2140,15 +2138,8 @@ main_set_source (xd3_stream *stream, int cmd, main_file *sfile, xd3_source *sour
2140 } 2138 }
2141 else 2139 else
2142 { 2140 {
2143 /* Minimum size check */
2144 option_srcwinsz = max(option_srcwinsz, XD3_MINSRCWINSZ); 2141 option_srcwinsz = max(option_srcwinsz, XD3_MINSRCWINSZ);
2145 2142
2146 if (!option_srcwinsz_set)
2147 {
2148 /* If the flag was not set, scale srcwinsz up to 64MB. */
2149 option_srcwinsz = min((xoff_t) XD3_DEFAULT_SRCWINSZ, source->size);
2150 }
2151
2152 source->blksize = (option_srcwinsz / LRU_SIZE); 2143 source->blksize = (option_srcwinsz / LRU_SIZE);
2153 lru_size = LRU_SIZE; 2144 lru_size = LRU_SIZE;
2154 } 2145 }
@@ -2156,6 +2147,19 @@ main_set_source (xd3_stream *stream, int cmd, main_file *sfile, xd3_source *sour
2156 main_blklru_list_init (& lru_list); 2147 main_blklru_list_init (& lru_list);
2157 main_blklru_list_init (& lru_free); 2148 main_blklru_list_init (& lru_free);
2158 2149
2150 if (option_verbose)
2151 {
2152 static char buf[32];
2153
2154 XPR(NT "source %s winsize %s size %"Q"u\n",
2155 sfile->filename, main_format_bcnt(option_srcwinsz, buf), source->size);
2156 }
2157
2158 if (option_verbose > 1)
2159 {
2160 XPR(NT "source block size: %u\n", source->blksize);
2161 }
2162
2159 if ((lru = main_malloc (sizeof (main_blklru) * lru_size)) == NULL) 2163 if ((lru = main_malloc (sizeof (main_blklru) * lru_size)) == NULL)
2160 { 2164 {
2161 ret = ENOMEM; 2165 ret = ENOMEM;
@@ -2175,13 +2179,6 @@ main_set_source (xd3_stream *stream, int cmd, main_file *sfile, xd3_source *sour
2175 main_blklru_list_push_back (& lru_free, & lru[i]); 2179 main_blklru_list_push_back (& lru_free, & lru[i]);
2176 } 2180 }
2177 2181
2178 if (option_verbose > 1)
2179 {
2180 XPR(NT "source window size: %u\n", option_srcwinsz);
2181 XPR(NT "source block size: %u\n", source->blksize);
2182 XPR(NT "source file: %s: %"Q"u bytes\n", sfile->realname, source->size);
2183 }
2184
2185 if (stream && (ret = xd3_set_source (stream, source))) 2182 if (stream && (ret = xd3_set_source (stream, source)))
2186 { 2183 {
2187 XPR(NT XD3_LIB_ERRMSG (stream, ret)); 2184 XPR(NT XD3_LIB_ERRMSG (stream, ret));
@@ -2197,6 +2194,23 @@ main_set_source (xd3_stream *stream, int cmd, main_file *sfile, xd3_source *sour
2197 return ret; 2194 return ret;
2198} 2195}
2199 2196
2197static void
2198main_set_winsize (main_file *ifile) {
2199 xoff_t file_size;
2200
2201 option_winsize = max(option_winsize, XD3_ALLOCSIZE);
2202
2203 if (main_file_stat (ifile, &file_size, 0) == 0)
2204 {
2205 option_winsize = (usize_t) min(file_size, (xoff_t) option_winsize);
2206 }
2207
2208 if (option_verbose > 1)
2209 {
2210 XPR(NT "input window size: %u\n", option_winsize);
2211 }
2212}
2213
2200/****************************************************************************************** 2214/******************************************************************************************
2201 Source routines 2215 Source routines
2202 ******************************************************************************************/ 2216 ******************************************************************************************/
@@ -2362,10 +2376,12 @@ main_input (xd3_cmd cmd,
2362 config.sec_addr.ngroups = 1; 2376 config.sec_addr.ngroups = 1;
2363 config.sec_inst.ngroups = 1; 2377 config.sec_inst.ngroups = 1;
2364 config.iopt_size = option_iopt_size; 2378 config.iopt_size = option_iopt_size;
2379 config.sprevsz = option_sprevsz;
2365 2380
2366 /* TODO: eliminate static variables. */
2367 do_not_lru = 0; 2381 do_not_lru = 0;
2368 2382
2383 start_time = get_millisecs_now ();
2384
2369 /* main_input setup. */ 2385 /* main_input setup. */
2370 switch ((int) cmd) 2386 switch ((int) cmd)
2371 { 2387 {
@@ -2477,12 +2493,7 @@ main_input (xd3_cmd cmd,
2477 return EXIT_FAILURE; 2493 return EXIT_FAILURE;
2478 } 2494 }
2479 2495
2480 start_time = get_millisecs_now (); 2496 main_set_winsize (ifile);
2481
2482 if (option_verbose > 1)
2483 {
2484 XPR(NT "input buffer size: %u\n", option_winsize);
2485 }
2486 2497
2487 if ((main_bdata = main_malloc (option_winsize)) == NULL) 2498 if ((main_bdata = main_malloc (option_winsize)) == NULL)
2488 { 2499 {
@@ -2499,8 +2510,6 @@ main_input (xd3_cmd cmd,
2499 } 2510 }
2500 } 2511 }
2501 2512
2502 option_winsize = max(option_winsize, XD3_ALLOCSIZE);
2503
2504 config.winsize = option_winsize; 2513 config.winsize = option_winsize;
2505 config.srcwin_maxsz = option_srcwinsz; 2514 config.srcwin_maxsz = option_srcwinsz;
2506 config.getblk = main_getblk_func; 2515 config.getblk = main_getblk_func;
@@ -2682,7 +2691,7 @@ main_input (xd3_cmd cmd,
2682 } 2691 }
2683 } 2692 }
2684 2693
2685 if (option_verbose > 0) 2694 if (option_verbose)
2686 { 2695 {
2687 char rrateavg[32], wrateavg[32], tm[32]; 2696 char rrateavg[32], wrateavg[32], tm[32];
2688 char rdb[32], wdb[32]; 2697 char rdb[32], wdb[32];
@@ -2789,9 +2798,10 @@ done:
2789 { 2798 {
2790 char tm[32]; 2799 char tm[32];
2791 long end_time = get_millisecs_now (); 2800 long end_time = get_millisecs_now ();
2792 XPR(NT "command finished in %s\n", main_format_millis (end_time - start_time, tm)); 2801 XPR(NT "finished in %s; input %"Q"u output %"Q"u bytes (%0.2f%%)\n",
2793 XPR(NT "input bytes: %"Q"u\n", ifile->nread); 2802 main_format_millis (end_time - start_time, tm),
2794 XPR(NT "output bytes: %"Q"u\n", ofile->nwrite); 2803 ifile->nread, ofile->nwrite,
2804 100.0 * ofile->nwrite / ifile->nread);
2795 } 2805 }
2796 2806
2797 return EXIT_SUCCESS; 2807 return EXIT_SUCCESS;
@@ -2900,7 +2910,7 @@ main (int argc, char **argv)
2900 main_file ifile; 2910 main_file ifile;
2901 main_file ofile; 2911 main_file ofile;
2902 main_file sfile; 2912 main_file sfile;
2903 static char *flags = "0123456789cdefhnqvDJNORTVs:B:C:E:F:I:L:O:P:M:W:A::S::"; 2913 static const char *flags = "0123456789cdefhnqvDJNORTVs:B:C:E:F:I:L:O:M:P:W:A::S::";
2904 int my_optind; 2914 int my_optind;
2905 char *my_optarg; 2915 char *my_optarg;
2906 char *my_optstr; 2916 char *my_optstr;
@@ -2921,7 +2931,6 @@ main (int argc, char **argv)
2921 2931
2922 reset_defaults(); 2932 reset_defaults();
2923 2933
2924 go: /* Go. */
2925 free_argv = NULL; 2934 free_argv = NULL;
2926 free_value = NULL; 2935 free_value = NULL;
2927 setup_environment(argc, argv, &env_argc, &env_argv, &free_argv, &free_value); 2936 setup_environment(argc, argv, &env_argc, &env_argv, &free_argv, &free_value);
@@ -3077,22 +3086,6 @@ main (int argc, char **argv)
3077 XPR(NT "encoder support not compiled\n"); 3086 XPR(NT "encoder support not compiled\n");
3078 return EXIT_FAILURE; 3087 return EXIT_FAILURE;
3079#endif 3088#endif
3080 case 'P':
3081 /* only set profile count once, since... */
3082 if (option_profile_cnt == 0)
3083 {
3084 if ((ret = main_atou(my_optarg, (usize_t*) & option_profile_cnt, 0, 0, 'P')))
3085 {
3086 goto exit;
3087 }
3088
3089 if (option_profile_cnt <= 0)
3090 {
3091 ret = EXIT_SUCCESS;
3092 goto exit;
3093 }
3094 }
3095 break;
3096 3089
3097 case 'n': option_use_checksum = 0; break; 3090 case 'n': option_use_checksum = 0; break;
3098 case 'N': option_no_compress = 1; break; 3091 case 'N': option_no_compress = 1; break;
@@ -3104,7 +3097,6 @@ main (int argc, char **argv)
3104 case 'A': if (my_optarg == NULL) { option_use_appheader = 0; } 3097 case 'A': if (my_optarg == NULL) { option_use_appheader = 0; }
3105 else { option_appheader = (uint8_t*) my_optarg; } break; 3098 else { option_appheader = (uint8_t*) my_optarg; } break;
3106 case 'B': 3099 case 'B':
3107 option_srcwinsz_set = 1;
3108 if ((ret = main_atou (my_optarg, & option_srcwinsz, XD3_MINSRCWINSZ, 3100 if ((ret = main_atou (my_optarg, & option_srcwinsz, XD3_MINSRCWINSZ,
3109 0, 'B'))) 3101 0, 'B')))
3110 { 3102 {
@@ -3118,6 +3110,13 @@ main (int argc, char **argv)
3118 goto exit; 3110 goto exit;
3119 } 3111 }
3120 break; 3112 break;
3113 case 'P':
3114 if ((ret = main_atou (my_optarg, & option_sprevsz, 0,
3115 0, 'P')))
3116 {
3117 goto exit;
3118 }
3119 break;
3121 case 'W': 3120 case 'W':
3122 if ((ret = main_atou (my_optarg, & option_winsize, XD3_ALLOCSIZE, 3121 if ((ret = main_atou (my_optarg, & option_winsize, XD3_ALLOCSIZE,
3123 XD3_HARDMAXWINSIZE, 'W'))) 3122 XD3_HARDMAXWINSIZE, 'W')))
@@ -3264,8 +3263,6 @@ main (int argc, char **argv)
3264 3263
3265 main_cleanup (); 3264 main_cleanup ();
3266 3265
3267 if (--option_profile_cnt > 0 && ret == EXIT_SUCCESS) { goto go; }
3268
3269 fflush (stdout); 3266 fflush (stdout);
3270 fflush (stderr); 3267 fflush (stderr);
3271 return ret; 3268 return ret;
@@ -3304,6 +3301,7 @@ main_help (void)
3304 P(RINT "memory options:\n"); 3301 P(RINT "memory options:\n");
3305 P(RINT " -B bytes source window size\n"); 3302 P(RINT " -B bytes source window size\n");
3306 P(RINT " -W bytes input window size\n"); 3303 P(RINT " -W bytes input window size\n");
3304 P(RINT " -P size compression duplicates window\n");
3307 P(RINT " -I size instruction buffer size (0 = unlimited)\n"); 3305 P(RINT " -I size instruction buffer size (0 = unlimited)\n");
3308 3306
3309 P(RINT "compression options:\n"); 3307 P(RINT "compression options:\n");
@@ -3322,9 +3320,11 @@ main_help (void)
3322 P(RINT " -P repeat count (for profiling)\n"); 3320 P(RINT " -P repeat count (for profiling)\n");
3323 P(RINT " -T use alternate code table\n"); 3321 P(RINT " -T use alternate code table\n");
3324#endif 3322#endif
3323
3325 P(RINT "the XDELTA environment variable may contain extra args:\n"); 3324 P(RINT "the XDELTA environment variable may contain extra args:\n");
3326 P(RINT " XDELTA=\"-s source-x.y.tar.gz\" \\\n"); 3325 P(RINT " XDELTA=\"-s source-x.y.tar.gz\" \\\n");
3327 P(RINT " tar --use-compress-program=xdelta3 \\\n"); 3326 P(RINT " tar --use-compress-program=xdelta3 \\\n");
3328 P(RINT " -cf target-x.z.tar.gz.vcdiff target-x.y/\n"); 3327 P(RINT " -cf target-x.z.tar.gz.vcdiff target-x.y/\n");
3329 return EXIT_FAILURE; 3328 return EXIT_FAILURE;
3330} 3329}
3330