diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 15:49:25 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 15:49:25 +0000 |
commit | 464df1d5e5ab1322e2dd0a7796939fff1aeefa9a (patch) | |
tree | 6a403684e0978f0287d7f0ec0e5aab1fd31a59e1 /util/libecho.c | |
parent | Initial commit. (diff) | |
download | e2fsprogs-464df1d5e5ab1322e2dd0a7796939fff1aeefa9a.tar.xz e2fsprogs-464df1d5e5ab1322e2dd0a7796939fff1aeefa9a.zip |
Adding upstream version 1.47.0.upstream/1.47.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'util/libecho.c')
-rw-r--r-- | util/libecho.c | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/util/libecho.c b/util/libecho.c new file mode 100644 index 0000000..352ce1e --- /dev/null +++ b/util/libecho.c @@ -0,0 +1,78 @@ +/* + * libecho.c + * + * For each argument on the command line, echo it. Should expand + * DOS wildcards correctly. + * + * Syntax: libecho [-p prefix] list... + */ +#include <stdio.h> +#include <io.h> +#include <string.h> + +void echo_files(char *, char *); + +int +main(int argc, char *argv[]) +{ + int i; + char *prefix; + + prefix = ""; + + if (argc < 2) { + fprintf(stderr, "Usage: libecho [-p prefix] list...\n"); + return 1; + } + + for (i = 1 ; i < argc ; i++) + if (!stricmp(argv[i], "-p")) + prefix = argv[++i]; + else + echo_files(prefix, argv[i]); + + return 0; +} + +void +echo_files(char *prefix, char *f) +{ + long ff; + struct _finddata_t fdt; + char *slash; + char filepath[256]; + + /* + * We're unix based quite a bit here. Look for normal slashes and + * make them reverse slashes. + */ + while((slash = strrchr(f, '/')) != NULL) + *slash = '\\'; + + strcpy(filepath, f); + + slash = strrchr(filepath, '\\'); + + if (slash) { + slash++; + *slash = 0; + } else { + filepath[0] = '\0'; + } + + ff = _findfirst(f, &fdt); + + if (ff < 0) { + printf("%s%s\n", prefix, f); + return; + } + + printf("%s%s%s\n", prefix, filepath, fdt.name); + + for (;;) { + if (_findnext(ff, &fdt) < 0) + break; + printf("%s%s%s\n", prefix, filepath, fdt.name); + } + _findclose(ff); +} |