1 //: Interacting with the file system. 2 //: '$open-file-for-reading' returns a FILE* as a number (ugh) 3 //: '$read-from-file' accepts a number, interprets it as a FILE* (double ugh) and reads a character from it 4 //: Similarly for writing files. 5 //: These interfaces are ugly and tied to the current (Linux) host Mu happens 6 //: to be implemented atop. Later layers will wrap them with better, more 7 //: testable interfaces. 8 //: 9 //: Clearly we don't care about performance or any of that so far. 10 //: todo: reading/writing binary files 11 12 :(before "End Primitive Recipe Declarations") 13 _OPEN_FILE_FOR_READING, 14 :(before "End Primitive Recipe Numbers") 15 put(Recipe_ordinal, "$open-file-for-reading", _OPEN_FILE_FOR_READING); 16 :(before "End Primitive Recipe Checks") 17#include<assert.h> #include<cstdlib> #include<dirent.h> #include<vector> using std::vector; #include<string> using std::string; #include<iostream> using std::cout; int main(int argc, const char* argv[]) { assert(argc == 3); assert(string(argv[1]) == "--until"); string last_file(argv[2]); dirent** files; int num_files = scandir(".", &files, NULL, alphasort); for (int i = 0; i < num_files; ++i) { string curr_file = files[i]->d_name; if (!isdigit(curr_file.at(0))) continue; if (!last_file.empty() && curr_file > last_file) break; cout << curr_file << '\n'; } // don't bother freeing files return 0; }