catrm

'cat' a file, then optionally 'rm' it. I just felt like writing C.
Log | Files | Refs | Atom | README

commit 2b796385957d747b97288371bf0057560d4c8a61
parent cb6d136f3fdba670a1c2abd3cb28f1c4da812164
Author: gearsix <gearsix@tuta.io>
Date:   Tue,  8 Mar 2022 16:49:29 +0000

added usage doc & README

Diffstat:
AREADME | 11+++++++++++
Dcatrm | 0
Mmain.c | 15++++++++++++++-
Dtest | 1-
4 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/README b/README @@ -0,0 +1,11 @@ + +# catrm + +a binutil that prompts the option to cat a file to stdout +before removing it. + +**options** + +`-ni` = none-interactive mode, skip prompt - just cat & rm + +- gearsix diff --git a/catrm b/catrm Binary files differ. diff --git a/main.c b/main.c @@ -15,6 +15,17 @@ enum OPTS { int prompt(const char *fpath); int cat(const char *fpath); int rm(const char *fpath); +void usage(const char *name) +{ + printf("usage: %s [OPTIONS] [FILE]..\n", name); + puts(""); + puts("prompt the option to remove and/or cat a file."); + puts(""); + puts("options:"); + puts("\t-ni non-interactive mode, cat each listed file and remove it."); + puts(""); + exit(EXIT_SUCCESS); +} int main(int argc, char *argv[]) @@ -24,7 +35,9 @@ int main(int argc, char *argv[]) for (i = 1; i < argc; ++i) { if (!argv[i] || argv[i][0] != '-') continue; - if (strcmp(argv[i], "-ni") == 0) + if (strcmp(argv[i], "-h") == 0) + usage(argv[0]); + else if (strcmp(argv[i], "-ni") == 0) opts &= ~OPTS_INTERACTIVE; else printf("unrecognised arg: '%s'", argv[i]); diff --git a/test b/test @@ -1 +0,0 @@ -hello world