From bac2c5227dd7679dc418940244caca7d74a0e2c7 Mon Sep 17 00:00:00 2001 From: czjstmax Date: Wed, 6 May 2026 22:48:51 +0200 Subject: rfile - version 1 Signed-off-by: czjstmax --- README.md | 7 +++++ rf.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ rfile | 1 + 3 files changed, 97 insertions(+) create mode 100644 README.md create mode 100644 rf.c create mode 100644 rfile diff --git a/README.md b/README.md new file mode 100644 index 0000000..fbd2915 --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# runfile (`rfile`) +a minimal, no-dependancy, POSIX C99 Makefile/justfile alternative to *just run commands*. + +## usage +1. create an `rfile` with commands divided by a `\n` +2. run `rf` in that directory. + diff --git a/rf.c b/rf.c new file mode 100644 index 0000000..64489e4 --- /dev/null +++ b/rf.c @@ -0,0 +1,89 @@ +/* + * runfile - rf + * + * a no-dependancy, minimal + * POSIX C99 Make/justfile + * alternative to run commands. + * + * czjstmax + * + */ + +#define _POSIX_C_SOURCE 200809L + +#define RUNFILE_VERSION 1 + +#include +#include +#include +#include +#include +#include + +void usage(); + +int main(int argc, char **argv) +{ + if (argc > 2) + usage(); + else if (argc >= 2) { + for (int i = 1; i < argc; i++) { + if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) + usage(); + } + + } + + FILE *f = fopen("rfile", "r"); + + if (!f) { + printf("no rfile found.\n"); + return 1; + } + + wordexp_t p; + char *line = NULL; + size_t len = 0; + + while (getline(&line, &len, f) != -1) { + line[strcspn(line, "\n")] = '\0'; + printf("$ %s\n", line); + + wordexp(line, &p, 0); + + pid_t pid = fork(); + + if (pid == 0) { + execvp(p.we_wordv[0], p.we_wordv); + + perror("failed to run command"); + wordfree(&p); + free(line); + fclose(f); + _exit(1); + } + else if (pid > 0) { + int status; + waitpid(pid, &status, 0); + } + else { + perror("fork failed"); + return 1; + } + } + + wordfree(&p); + free(line); + fclose(f); + return 0; +} + +void usage() +{ + printf( + "< runfile usage >\n" + "syn: rf [section]\n" + ); +} + diff --git a/rfile b/rfile new file mode 100644 index 0000000..0fa09b0 --- /dev/null +++ b/rfile @@ -0,0 +1 @@ +cc -o rf rf.c -Wall -Wextra -pedantic -- cgit v1.3.1