diff --git a/include/project.h b/include/project.h index d90300d..df16259 100644 --- a/include/project.h +++ b/include/project.h @@ -27,20 +27,23 @@ // Returns from the program +//NOTE: -- Reworked `PROG_RET_` to have mapping and internal failures be negative, and the first haystack number to fail returned verbatim (haystack numbers start at 1). So, after consolidating the threadpool's results, we iterate over haystack numbers, find the first non-match, and exit process with its number. Otherwise, we return 0. + // Invalid arguments to program (print usage to stderr) -#define PROG_RET_ARGS 1 +#define PROG_RET_ARGS -2 // Mapping of argv[1] failed -#define PROG_RET_MAP_NEEDLE_FAILED 2 +#define PROG_RET_MAP_NEEDLE_FAILED -3 // `h` is the number in argv[] of the haystack file -#define PROG_RET_MAP_HAYSTACK_N_FAILED(h) ((h) << 2) +#define PROG_RET_MAP_HAYSTACK_N_FAILED(h) -((h) << 2) // `h` is the number in argv[] of the haystack file -#define PROG_RET_UNMAP_HAYSTACK_N_FAILED(h) (((h) << 2) | 1) +#define PROG_RET_UNMAP_HAYSTACK_N_FAILED(h) -(((h) << 2) | 1) // Match of haystack number `h` failed. -#define PROG_RET_MAP_HAYSTACK_N_FAILED(h) ((h) << 2 | 2) +#define PROG_RET_MATCH_HAYSTACK_N_FAILED(h) AS(h, int) // Bitwise OR this with the number(s) of the haystack that match failed. It must not exceed INT_MAX-1 +// XXX: DEPRECATED #define PROG_RET_MAP_HAYSTACK_FAILED AS((AS(INT_MAX, u64) >> 1lu) ^ AS(INT_MAX, u64), int) // Unmapping of argv[1] failed -#define PROG_RET_UNMAP_NEEDLE_FAILED 3 +#define PROG_RET_UNMAP_NEEDLE_FAILED -4 // Internal error #define PROG_RET_INTERNAL -1 diff --git a/src/main.c b/src/main.c index 6025dc7..f4e15bd 100644 --- a/src/main.c +++ b/src/main.c @@ -69,8 +69,7 @@ inv_args: //TODO: Use either `cmp_find()` or `cmp_find_many()` to find the `needle` (mapped above) within those haystacks. //TODO: Within the threadpool: output information regarding each match/nonmatch. //TODO: Join the threadpool and consolidate results. - - //TODO: Should we return an error (`PROG_RET_MAP_HAYSTACK_N_FAILED(n)`) if one (or more) of the haystacks fail? Or consolidate multiple failures into `PROG_RET_MAP_HAYSTACK_FAILED | (failures)`? The latter would be the most complete. + //TODO: Iterate through the haystack numbers match results, return the first non-match haystack number through `PROG_RET_MATCH_HAYSTACK_N_FAILED(n)` (haystack numbers are always nonzero). If all were matched, return 0 if(!map_handle_err(map_free(needle))) return PROG_RET_UNMAP_NEEDLE_FAILED; TRACE("main end");