#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; }