Skip to content

Commit

Permalink
Feat: print the algorithms being calculated on -vv
Browse files Browse the repository at this point in the history
  • Loading branch information
rhash committed Mar 1, 2023
1 parent 1486a21 commit 9a6c70c
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 10 deletions.
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
Wed 01 Mar 2023 Aleksey Kravchenko
* Print the algorithms being calculated on -vv

Tue 27 Sep 2022 Aleksey Kravchenko
* Renamed --maxdepth option to --max-depth

Expand Down
7 changes: 5 additions & 2 deletions calc_sums.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ int calculate_and_print_sums(FILE* out, file_t* out_file, file_t* file)
rsh_timer_start(&timer);

if (info.sums_flags) {
print_verbose_algorithms(rhash_data.log, info.sums_flags);
/* calculate sums */
if (calc_sums(&info) < 0) {
/* print i/o error */
Expand Down Expand Up @@ -363,7 +364,7 @@ int calculate_and_print_sums(FILE* out, file_t* out_file, file_t* file)
log_error_file_t(out_file);
res = -2;
}
if (opt.flags & OPT_VERBOSE) {
if (opt.verbose) {
print_sfv_header_line(rhash_data.log, rhash_data.log_file.mode, file);
fflush(rhash_data.log);
}
Expand All @@ -376,7 +377,7 @@ int calculate_and_print_sums(FILE* out, file_t* out_file, file_t* file)
res = -2;
}
/* print the calculated line to stderr/log-file if verbose */
else if (IS_MODE(MODE_UPDATE) && (opt.flags & OPT_VERBOSE)) {
else if (IS_MODE(MODE_UPDATE) && opt.verbose) {
print_line(rhash_data.log, rhash_data.log_file.mode, rhash_data.print_list, &info);
}
}
Expand Down Expand Up @@ -462,6 +463,8 @@ void run_benchmark(unsigned hash_id, unsigned flags)
#ifdef _WIN32
set_benchmark_cpu_affinity(); /* set CPU affinity to improve test results */
#endif
if (!(flags & BENCHMARK_RAW))
print_verbose_algorithms(rhash_data.out, hash_id);

/* set message size for fast and slow hash functions */
msg_size = 1073741824 / 2;
Expand Down
3 changes: 2 additions & 1 deletion hash_check.c
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ static int parse_magnet_url(struct hash_token* token)
break;
}
if (i >= RHASH_HASH_COUNT) {
if (opt.flags & OPT_VERBOSE) {
if (opt.verbose) {
*hf_end = '\0';
log_warning(_("unknown hash in magnet link: %s\n"), token->begin);
}
Expand Down Expand Up @@ -1152,6 +1152,7 @@ static int verify_hashes(file_t* file, struct hash_parser* hp)
info.file = file;
info.sums_flags = hp->hash_mask;
info.hp = hp;
print_verbose_algorithms(rhash_data.log, info.sums_flags);

/* initialize percents output */
if (init_percents(&info) < 0) {
Expand Down
33 changes: 30 additions & 3 deletions output.c
Original file line number Diff line number Diff line change
Expand Up @@ -428,14 +428,14 @@ static int print_check_result(struct file_info* info, int print_name, int print_
if (info->processing_result < 0) {
/* print error to stdout */
res = PRINTF_RES(rsh_fprintf(rhash_data.out, "%s\n", strerror(saved_errno)));
} else if (!HP_FAILED(info->hp->bit_flags) || !(opt.flags & OPT_VERBOSE)) {
} else if (HP_FAILED(info->hp->bit_flags) && opt.verbose) {
res = print_verbose_hash_check_error(info);
} else {
res = PRINTF_RES(rsh_fprintf(rhash_data.out, (!HP_FAILED(info->hp->bit_flags) ?
/* TRANSLATORS: printed when all message digests match, use at least 3 characters to overwrite "99%" */
_("OK \n") :
/* TRANSLATORS: ERR (short for 'error') is printed on a message digest mismatch */
_("ERR\n"))));
} else {
res = print_verbose_hash_check_error(info);
}
}
if (fflush(rhash_data.out) < 0)
Expand Down Expand Up @@ -764,6 +764,33 @@ int print_check_stats(void)
return (fflush(rhash_data.out) < 0 ? -1 : res);
}

/**
* Print used algorithms, but only on very verbose level
*
* @param out the stream to print the result to
* @param hash_mask bit mask containing hash ids to calculate
* @return 0 on success, -1 on fail with error code stored in errno
*/
int print_verbose_algorithms(FILE* out, unsigned hash_mask)
{
unsigned hash_id;
const char* prefix;
if (!hash_mask || opt.verbose <= 1)
return 0;
prefix = _("Calculating: ");
for (hash_id = 1; hash_id && hash_id <= hash_mask; hash_id <<= 1) {
if ((hash_id & hash_mask) != 0) {
const char* hash_name = rhash_get_name(hash_id);
if (rsh_fprintf(out, "%s%s", prefix, hash_name) < 0)
return -1;
prefix = ", ";
}
}
if (rsh_fprintf(out, "\n") < 0)
return -1;
return (fflush(out) < 0 ? -1 : 0);
}

/**
* Print file processing times.
*/
Expand Down
1 change: 1 addition & 0 deletions output.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ void report_interrupted(void);
int print_verifying_header(struct file_t* file);
int print_verifying_footer(void);
int print_check_stats(void);
int print_verbose_algorithms(FILE* out, unsigned hash_mask);

void print_time_stats(uint64_t time, uint64_t size, int total);
void print_file_time_stats(struct file_info* info);
Expand Down
13 changes: 11 additions & 2 deletions parse_cmdline.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ static const char* get_full_program_version(void)
return version_buffer;
}

static void on_verbose(options_t* o)
{
if (o->verbose < 2)
o->verbose++;
}

static void print_version(void)
{
rsh_fprintf(rhash_data.out, "%s", get_full_program_version());
Expand Down Expand Up @@ -388,6 +394,7 @@ cmdline_opt_t cmdline_opt[] =
{ F_VFNC, 0, 0, "list-hashes", (opt_handler_t)list_hashes, 0, 0 },
{ F_VFNC, 'h', 0, "help", (opt_handler_t)print_help, 0, 0 },
{ F_VFNC, 'V', 0, "version", (opt_handler_t)print_version, 0, 0 },
{ F_VFNC, 'v', 0, "verbose", (opt_handler_t)on_verbose, 0, 0 },

/* hash functions options */
{ F_UFLG, 'a', 0, "all", 0, &opt.sum_flags, RHASH_ALL_HASHES },
Expand Down Expand Up @@ -442,7 +449,6 @@ cmdline_opt_t cmdline_opt[] =
{ F_TFNC, 'm', 0, "message", (opt_handler_t)add_special_file, 0, FileIsData },
{ F_TFNC, 0, 0, "file-list", (opt_handler_t)add_special_file, 0, FileIsList },
{ F_UFLG, 0, 0, "follow", 0, &opt.flags, OPT_FOLLOW },
{ F_UFLG, 'v', 0, "verbose", 0, &opt.flags, OPT_VERBOSE },
{ F_UFLG, 0, 0, "brief", 0, &opt.flags, OPT_BRIEF },
{ F_UFLG, 0, 0, "gost-reverse", 0, &opt.flags, OPT_GOST_REVERSE },
{ F_UFLG, 0, 0, "skip-ok", 0, &opt.flags, OPT_SKIP_OK },
Expand Down Expand Up @@ -1014,6 +1020,9 @@ static void apply_cmdline_options(struct parsed_cmd_line_t* cmd_line)
opt.flags |= conf_opt.flags & OPT_FMT_MODIFIERS;
opt.flags |= conf_opt.flags & ~OPT_FMT_MODIFIERS; /* copy the rest of options */

if (!opt.verbose)
opt.verbose = conf_opt.verbose;

if (opt.files_accept == 0) {
opt.files_accept = conf_opt.files_accept;
conf_opt.files_accept = 0;
Expand Down Expand Up @@ -1153,7 +1162,7 @@ static void check_compatibility(int what, unsigned bit_mask)
*/
static void make_final_options_checks(void)
{
if ((opt.flags & OPT_VERBOSE) && !!rhash_data.config_file.real_path) {
if (opt.verbose && !!rhash_data.config_file.real_path) {
/* note that the first log_msg call shall be made after setup_output() */
log_msg_file_t(_("Config file: %s\n"), &rhash_data.config_file);
}
Expand Down
2 changes: 1 addition & 1 deletion parse_cmdline.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ enum {
MODE_TORRENT = 0x80,

/* misc options */
OPT_VERBOSE = 0x01,
OPT_BRIEF = 0x02,
OPT_EMBED_CRC = 0x20,
OPT_RECURSIVE = 0x40,
Expand Down Expand Up @@ -86,6 +85,7 @@ struct options_t
unsigned sum_flags; /* flags to specify what sums will be calculated */
unsigned fmt; /* flags to specify output format to use */
unsigned mode; /* flags to specify program mode */
unsigned verbose; /* verbosity level */
unsigned openssl_mask; /* bit-mask for enabled OpenSSL hash functions */
char* printf_str; /* printf-like format */
opt_tchar* template_file; /* printf-like template file path */
Expand Down
2 changes: 1 addition & 1 deletion rhash_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ int main(int argc, char* argv[])
rhash_data.template_text = init_printf_format();
rhash_data.printf_str = rhash_data.template_text->str;

if (HAS_OPTION(OPT_VERBOSE)) {
if (opt.verbose) {
char* str = rsh_strdup(rhash_data.printf_str);
log_msg(_("Format string is: %s\n"), str_trim(str));
free(str);
Expand Down

0 comments on commit 9a6c70c

Please sign in to comment.