From e5fbef8e416fe89d1fe2f7840383c26528b6b8d4 Mon Sep 17 00:00:00 2001 From: Ben Winston Date: Mon, 10 Nov 2025 22:29:09 -0500 Subject: initial commit, writes args and pwd into a file --- .gitignore | 3 +++ Makefile | 4 ++++ later.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 later.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4215965 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +later +scratch/ +*.swp diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..d201105 --- /dev/null +++ b/Makefile @@ -0,0 +1,4 @@ +.PHONY: build + +build: + cc later.c -Wall -Werror -o later diff --git a/later.c b/later.c new file mode 100644 index 0000000..5f59577 --- /dev/null +++ b/later.c @@ -0,0 +1,61 @@ +#include +#include +#include +#include + + +int main(int argc, char** argv) { + /* how it could work + * - read in tokens + * - wait for -- + * - after --, read everything in and save to the LATERFILE + * - make sure to also save the PWD + * + * Format is: + * FROM + * + * -- + * + */ + char* laterfile_path = getenv("LATERFILE"); + if (!laterfile_path || strlen(laterfile_path) == 0) { + printf("where's your LATERFILE?\n"); + return 1; + } + + FILE* laterfile = fopen(laterfile_path, "a"); + + // loop through the arguments + int argi = 1; + while (argi < argc && strncmp(argv[argi], "--", 2) != 0) + argi++; + + if (argi == argc) { + printf("unrecognized arguments\n"); + return 1; + } + + argi++; // go past the -- + + // determine the current working directory + char pwd[255]; + getcwd(pwd, 254); + + // TODO check err + + // write the output + fwrite("FROM ", 1, 5, laterfile); + fwrite(pwd, 1, strlen(pwd), laterfile); + fwrite("\n", 1, 1, laterfile); + + // write out the command + for (int i = argi; i < argc; i++) { + fwrite(argv[i], 1, strlen(argv[i]), laterfile); + fwrite(" ", 1, 1, laterfile); + } + + // write the terminal + fwrite("\n--\n", 1, 4, laterfile); + + return 0; +} -- cgit v1.2.3