From 25f9384a066b0afe0eaefc96c6e9360b81833ddd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Sat, 10 Jul 2021 15:57:35 +0200 Subject: Add re --- re.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 re.c diff --git a/re.c b/re.c new file mode 100644 index 0000000..07b6846 --- /dev/null +++ b/re.c @@ -0,0 +1,35 @@ +#include +#include +#include + +int +main(int argc, char *argv[]) +{ + char ans[10], file[30]; + FILE *fp; + int i; + + if (argc-1 == 0) { + fprintf(stderr, "usage: %s file ...\n", argv[0]); + return 1; + } + + sprintf(file, "/var/tmp/re.%d", getppid()); + + if (!access(file, F_OK)) { + do + fprintf(stderr, "%s already exists; overwrite? ", file); + while (!gets(ans) || !*ans); + if (ans[0] != 'y') return 1; + } + + if (!(fp = fopen(file, "w"))) + err(1, "fopen"); + + for (i = 1; i < argc; i++) { + fprintf(fp, "%s\n", argv[i]); + printf("%s\n", argv[i]); + } + + fclose(fp); +} -- cgit v1.2.3