Update custom hufftable tool for saving histogram
Change-Id: I515217b19373b8f996ff887268862cf2b102f3a4
Signed-off-by: Greg Tucker <greg.b.tucker@intel.com>
Greg Tucker
3 years ago
348 | 348 | struct isal_zstream tmp_stream; |
349 | 349 | FILE *file = NULL; |
350 | 350 | FILE *dict_file = NULL; |
351 | FILE *hist_file = NULL; | |
351 | 352 | long int dict_file_length = 0; |
353 | long int hist_file_length = 0; | |
352 | 354 | uint8_t *dict_stream = NULL; |
353 | 355 | |
354 | 356 | if (argc == 1) { |
383 | 385 | free(dict_stream); |
384 | 386 | } |
385 | 387 | |
386 | memset(&histogram, 0, sizeof(histogram)); /* Initialize histograms. */ | |
388 | if ((argc > argi + 1) && argv[argi][0] == '-' && argv[argi][1] == 'h') { | |
389 | hist_file = fopen(argv[argi + 1], "r+"); | |
390 | fseek(hist_file, 0, SEEK_END); | |
391 | hist_file_length = ftell(hist_file); | |
392 | fseek(hist_file, 0, SEEK_SET); | |
393 | hist_file_length -= ftell(hist_file); | |
394 | if (hist_file_length > sizeof(histogram)) { | |
395 | printf("Histogram file too long\n"); | |
396 | return 1; | |
397 | } | |
398 | if (fread(&histogram, 1, hist_file_length, hist_file) != hist_file_length) { | |
399 | printf("Error occurred when reading history file"); | |
400 | fclose(hist_file); | |
401 | return 1; | |
402 | } | |
403 | fseek(hist_file, 0, SEEK_SET); | |
404 | ||
405 | printf("Read %ld bytes of history file %s\n", hist_file_length, | |
406 | argv[argi + 1]); | |
407 | argi += 2; | |
408 | } else | |
409 | memset(&histogram, 0, sizeof(histogram)); /* Initialize histograms. */ | |
387 | 410 | |
388 | 411 | while (argi < argc) { |
389 | 412 | printf("Processing %s\n", argv[argi]); |
447 | 470 | |
448 | 471 | fclose(file); |
449 | 472 | |
473 | if (hist_file) { | |
474 | int len = fwrite(&histogram, 1, sizeof(histogram), hist_file); | |
475 | printf("wrote %d bytes of histogram file\n", len); | |
476 | fclose(hist_file); | |
477 | } | |
450 | 478 | return 0; |
451 | 479 | } |