diff options
| author | czjstmax <jstmaxlol@disroot.org> | 2026-05-06 22:48:51 +0200 |
|---|---|---|
| committer | czjstmax <jstmaxlol@disroot.org> | 2026-05-06 22:48:51 +0200 |
| commit | bac2c5227dd7679dc418940244caca7d74a0e2c7 (patch) | |
| tree | ace6f4e8e86c7c0efe8bf653b880fb98e292bb5e | |
rfile - version 1
Signed-off-by: czjstmax <jstmaxlol@disroot.org>
| -rw-r--r-- | README.md | 7 | ||||
| -rw-r--r-- | rf.c | 89 | ||||
| -rw-r--r-- | rfile | 1 |
3 files changed, 97 insertions, 0 deletions
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. + @@ -0,0 +1,89 @@ +/* + * runfile - rf + * + * a no-dependancy, minimal + * POSIX C99 Make/justfile + * alternative to run commands. + * + * czjstmax + * <jstmaxlol at + * disroot dot org> + */ + +#define _POSIX_C_SOURCE 200809L + +#define RUNFILE_VERSION 1 + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <wordexp.h> +#include <sys/wait.h> + +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" + ); +} + @@ -0,0 +1 @@ +cc -o rf rf.c -Wall -Wextra -pedantic |