diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/util/loop_args.c | 24 | ||||
-rw-r--r-- | src/util/loop_args.h | 5 |
2 files changed, 29 insertions, 0 deletions
diff --git a/src/util/loop_args.c b/src/util/loop_args.c new file mode 100644 index 0000000..4609c71 --- /dev/null +++ b/src/util/loop_args.c @@ -0,0 +1,24 @@ +#include <string.h> + +#include "loop_args.h" + +int loop_args(char **args, int (*callback)(char *argv, bool isstdin)) { + if (*args == NULL) { + return callback(*args, true); + } + + while (*args != NULL) { + int res = 0; + if (!strcmp(*args, "-")) { + res = callback(*args, true); + } else { + res = callback(*args, false); + } + + if (res != 0) return res; + + args++; + } + + return 0; +} diff --git a/src/util/loop_args.h b/src/util/loop_args.h new file mode 100644 index 0000000..359ed75 --- /dev/null +++ b/src/util/loop_args.h @@ -0,0 +1,5 @@ +#pragma once + +#include <stdbool.h> + +int loop_args(char **args, int (*callback)(char *arg, bool isstdin)); |