/* See LICENSE file for copyright and license details. */ #include "common.h" #include NUSAGE(2, "[file] ..."); static int calculate_and_print(const char *file, struct barrier_group *group, struct global_data *global) { size_t i; if (calculate(file, group, global)) return -1; for (i = 0; i < global->nalgorithms; i++) writeall(STDOUT_FILENO, global->algorithms[i].result, global->algorithms[i].result_length, ""); return 0; } static int calculate_each_and_print(char **files, struct algorithm *algorithms, size_t nalgorithms, enum format format) { size_t wanted_nalgorithms = nalgorithms; struct buffer buffer = {0}; int r, ret = 0; struct barrier_group group; struct global_data global; global.format = format; global.buffer = &buffer; global.algorithms = algorithms; global.nalgorithms = nalgorithms; createbarriergroup(&group, nalgorithms, &global); if (!*files) { global.file = "-"; ret = calculate_and_print("-", &group, &global) ? 2 : 0; } while (*files) { global.file = *files; r = calculate_and_print(*files++, &group, &global) ? 2 : 0; ret = MAX(r, ret); } if (nalgorithms != wanted_nalgorithms) ret = 2; killbarriergroup(&group, &global); free(buffer.buf); return ret; } int main(int argc, char *argv[]) { enum format format = LOWERCASE_HEX | WITH_ALGOSTR | WITH_FILENAME | WITH_LF; struct algorithm algorithms[] = {{"sha1"}, {"sha2-512/224"}, {"sha1"}}; size_t i, nalgorithms = ELEMSOF(algorithms); int ret; libsimple_default_failure_exit = 2; ARGBEGIN { default: usage(); } ARGEND; ret = calculate_each_and_print(argv, algorithms, nalgorithms, format); for (i = 0; i < nalgorithms; i++) free(algorithms[i].result); return ret; }