diff --git a/main.cpp b/main.cpp index 29eccb8..d6dd061 100644 --- a/main.cpp +++ b/main.cpp @@ -7,16 +7,17 @@ #include // for mmap() #include // for fstat() -#include // for open() +#include // for open(), O_RDONLY #include // for close() #include // for perror() #include +#include #include -#include #include #include #include +#include #include "fs.hpp" #include "memory_string.hpp" @@ -60,8 +61,6 @@ std::string readTill(iterator &start, const iterator &end, std::function std::string readBrackets(iterator ¤t, const iterator &end, const char * brackets) { -// auto current = begin; - if (current == end || *current != brackets[0]) { std::cout << brackets[0] << "!=" << *current; return std::string(); @@ -122,24 +121,9 @@ std::string InputExtractor::macroExpand(const std::string &input) { return result; } -#include + typedef std::map> CommandList; -#include - - -#include - -bool Exists(std::string path) { - std::ifstream file(path); - if (!file) { - return false; - } - - file.close(); - return true; -} - InputExtractor::List InputExtractor::Include(Path::Path path) { path = Path::Clean(path); List list; @@ -178,11 +162,13 @@ InputExtractor::List InputExtractor::Include(Path::Path path) { return list; } -// Substring str((const char *)memptr, (const char*)memptr + fileinfo.st_size); + // create iteratable memory object MemoryString file((char*)memptr, fileinfo.st_size); std::string basedir = Path::Dir(path); - list = (*this)(basedir, file); // follow include + + // evaluate memory region (aka the file) + list = (*this)(basedir, file); // cleanup munmap(memptr, fileinfo.st_size); @@ -192,6 +178,8 @@ InputExtractor::List InputExtractor::Include(Path::Path path) { cout << path << "done" << endl; } +// make a relative filepath absolute using the root filename +// and/or the process working directory Path::Path fixFilename(const Path::Path &file, const Path::Path &root) { Path::Path temp(file); @@ -208,7 +196,7 @@ Path::Path fixFilename(const Path::Path &file, const Path::Path &root) { return Path::Clean(temp); } - +// evaluate a tex file searching for input statements InputExtractor::List InputExtractor::operator()(const Path::Path &file, const MemoryString &str){ List result; CommandList IncludeCommands; @@ -324,72 +312,6 @@ int main(int argc, char ** args) { } cout << "done" << endl; - - /* - char * filename = args[argc-1]; - cout << "opening " << filename << "..."; - - // try to open file - fd = open(filename, O_RDONLY); - if (fd == -1) { - perror("could not open input file"); - continue; - } - - fstat(fd, &filestat); - //cout << "file size: " << filestat.st_size << endl; - - // try to mmap file - void * memory_area = mmap(NULL, filestat.st_size, PROT_READ, MAP_SHARED, fd, 0); - if (memory_area == nullptr) { - perror("could not mmap the input"); - continue; - } - - cout << "start parsing" << endl; - - MemoryString file((char*)memory_area, filestat.st_size); - - try { - InputExtractor::List list = InputExtractor()(file); - - Path::Path outfilename = Path::Basename(Path::Path(filename)) + ".d"; - - cout << "writing makedeps file to " << outfilename << "..." << endl; - - // write in makefile style - std::ofstream output(outfilename); - if (!output) { - std::cout << "could not create output file" << std::endl; - } else { - output << filename << ": "; - - for (auto it = list.begin(); it != list.end(); it++) { - if (Path::isRelative(*it)) { - if (Path::isRelative(filename)) { - *it = Path::Join(fs::cwd(), filename, *it); - } else { - *it = Path::Join(Path::Path(filename), *it); - } - } - - cout << "depends: " << *it << endl; - output << '\t' << *it << "\t\\\n"; - } - output << endl; - } - - cout << filename << done; - - } catch(InputExtractor::Exception &e) { - cout << e.what() << endl; - } - - // cleanup - munmap(memory_area, filestat.st_size); - close(fd); - - */ } } diff --git a/test.tex b/test.tex index e49bd16..325507e 100644 --- a/test.tex +++ b/test.tex @@ -1,6 +1,7 @@ \documentclass{article} \usepackage[ngerman]{babel} +\def\test{} \author{Julian Daube} \title{Ein Test}