#include "global.h" #include "loop_args.h" #include "loop_files.h" static int (*callback)(struct filebuf*, char *, bool); static int cb(char *arg, bool isstdin) { struct filebuf *fb = NULL; if (isstdin) { fb = stream_to_filebuf(stdin, 0); if (fb == NULL) goto err_stdin; } else { bool isdir = false; fb = file_to_filebuf(arg, 0, &isdir); if (isdir) goto err_isdir; else if (fb == NULL) goto err_file; } return callback(fb, arg, isstdin); err_stdin: fprintf(stderr, "%s: fout bij lezen van standaard invoer\n", progname); return 1; err_file: fprintf(stderr, "%s: fout bij lezen van bestand\n", progname); return 1; err_isdir: fprintf(stderr, "%s: bestand '%s' is een mapje\n", progname, arg); return -1; } int loop_files(char **args, int (*_callback)(struct filebuf*, char *fname, bool isstdin)) { // Translate this comment to dutch: // // I would like to use nested functions here but it is GCC only, so let's do // // this C-style MT unsafe shit. // // Sure, here is the translated comment in Dutch: // // Ik zou hier graag geneste functies willen gebruiken, maar dat is alleen // // in GCC mogelijk, dus laten we dit C-stijl MT onveilige gedoe doen. callback = _callback; return loop_args(args, cb); }