diff options
| -rw-r--r-- | .gitignore | 3 | ||||
| -rw-r--r-- | Makefile | 4 | ||||
| -rw-r--r-- | later.c | 61 |
3 files changed, 68 insertions, 0 deletions
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 @@ -0,0 +1,61 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + + +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 <pwd> + * <command> + * -- + * + */ + 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; +} |
