diff options
author | YamaArashi <shadow962@live.com> | 2016-05-20 11:45:24 -0700 |
---|---|---|
committer | YamaArashi <shadow962@live.com> | 2016-05-21 10:35:53 -0700 |
commit | c0203de808a98d27446e01c6b7e9f9311a5ad3bf (patch) | |
tree | e538179372ce7cddc50b851e4c24a4c7e0a40c81 /tools/preproc/preproc.cpp | |
parent | 4af578c1865e4b620f4c64401e0a16ccbd9efc8d (diff) |
sprite.c and updated preproc
Diffstat (limited to 'tools/preproc/preproc.cpp')
-rw-r--r-- | tools/preproc/preproc.cpp | 70 |
1 files changed, 58 insertions, 12 deletions
diff --git a/tools/preproc/preproc.cpp b/tools/preproc/preproc.cpp index 4f216f23a..1dd6808c3 100644 --- a/tools/preproc/preproc.cpp +++ b/tools/preproc/preproc.cpp @@ -18,35 +18,29 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +#include <string> #include <stack> #include "preproc.h" #include "asm_file.h" +#include "c_file.h" #include "charmap.h" Charmap* g_charmap; -int main(int argc, char **argv) +void PreprocAsmFile(std::string filename) { - if (argc != 3) - { - fprintf(stderr, "Usage: %s ASM_FILE CHARMAP_FILE", argv[0]); - return 1; - } - - g_charmap = new Charmap(argv[2]); - std::stack<AsmFile> stack; - stack.push(AsmFile(argv[1])); + stack.push(AsmFile(filename)); for (;;) { while (stack.top().IsAtEnd()) { stack.pop(); - + if (stack.empty()) - return 0; + return; else stack.top().OutputLocation(); } @@ -84,3 +78,55 @@ int main(int argc, char **argv) } } } + +void PreprocCFile(std::string filename) +{ + CFile cFile(filename); + cFile.Preproc(); +} + +char* GetFileExtension(char* filename) +{ + char* extension = filename; + + while (*extension != 0) + extension++; + + while (extension > filename && *extension != '.') + extension--; + + if (extension == filename) + return nullptr; + + extension++; + + if (*extension == 0) + return nullptr; + + return extension; +} + +int main(int argc, char **argv) +{ + if (argc != 3) + { + fprintf(stderr, "Usage: %s SRC_FILE CHARMAP_FILE", argv[0]); + return 1; + } + + g_charmap = new Charmap(argv[2]); + + char* extension = GetFileExtension(argv[1]); + + if (!extension) + FATAL_ERROR("\"%s\" has no file extension.\n", argv[1]); + + if ((extension[0] == 's') && extension[1] == 0) + PreprocAsmFile(argv[1]); + else if ((extension[0] == 'c' || extension[0] == 'i') && extension[1] == 0) + PreprocCFile(argv[1]); + else + FATAL_ERROR("\"%s\" has an unknown file extension of \"%s\".\n", argv[1], extension); + + return 0; +} |