diff options
author | nullableVoidPtr <30564701+nullableVoidPtr@users.noreply.github.com> | 2019-08-04 10:18:13 +0000 |
---|---|---|
committer | nullableVoidPtr <30564701+nullableVoidPtr@users.noreply.github.com> | 2019-08-04 10:18:13 +0000 |
commit | ba6f243c728de5d5c024aeb177026bcc59909e2e (patch) | |
tree | af8fdeb1c6cdf9cd8584f0d693a4049bfc408b9d /tools/preproc | |
parent | 6211b0c5ecbe4a43aa3f6e8fd96e99af29caa77a (diff) | |
parent | 250a331df9dbd312d572aaf0d629503417cfc9d4 (diff) |
Forgot upstream tools tracking
Diffstat (limited to 'tools/preproc')
-rw-r--r-- | tools/preproc/Makefile | 7 | ||||
-rw-r--r-- | tools/preproc/c_file.cpp | 42 | ||||
-rw-r--r-- | tools/preproc/preproc.cpp | 25 |
3 files changed, 25 insertions, 49 deletions
diff --git a/tools/preproc/Makefile b/tools/preproc/Makefile index bf1c11b..3d32758 100644 --- a/tools/preproc/Makefile +++ b/tools/preproc/Makefile @@ -1,6 +1,6 @@ CXX := g++ -CXXFLAGS := -std=c++11 -O2 -s -Wall -Wno-switch -Werror +CXXFLAGS := -std=c++11 -O2 -Wall -Wno-switch -Werror SRCS := asm_file.cpp c_file.cpp charmap.cpp preproc.cpp string_parser.cpp \ utf8.cpp @@ -8,10 +8,7 @@ SRCS := asm_file.cpp c_file.cpp charmap.cpp preproc.cpp string_parser.cpp \ HEADERS := asm_file.h c_file.h char_util.h charmap.h preproc.h string_parser.h \ utf8.h -.PHONY: all clean - -all: preproc - @: +.PHONY: clean preproc: $(SRCS) $(HEADERS) $(CXX) $(CXXFLAGS) $(SRCS) -o $@ $(LDFLAGS) diff --git a/tools/preproc/c_file.cpp b/tools/preproc/c_file.cpp index b550a53..229f568 100644 --- a/tools/preproc/c_file.cpp +++ b/tools/preproc/c_file.cpp @@ -22,9 +22,6 @@ #include <cstdarg> #include <string> #include <memory> -#include <iostream> -#include <iterator> -#include <cstring> #include "preproc.h" #include "c_file.h" #include "char_util.h" @@ -33,41 +30,28 @@ CFile::CFile(std::string filename) : m_filename(filename) { - if (filename == "-") { - std::string s, b; + FILE *fp = std::fopen(filename.c_str(), "rb"); - while (!std::cin.eof()) { - std::getline(std::cin, b); - s += b + "\n"; - } - m_size = s.size(); - m_buffer = new char[m_size + 1]; - memcpy(m_buffer, s.c_str(), m_size); - m_buffer[m_size] = 0; - } else { - FILE *fp = std::fopen(filename.c_str(), "rb"); - - if (fp == NULL) - FATAL_ERROR("Failed to open \"%s\" for reading.\n", filename.c_str()); + if (fp == NULL) + FATAL_ERROR("Failed to open \"%s\" for reading.\n", filename.c_str()); - std::fseek(fp, 0, SEEK_END); + std::fseek(fp, 0, SEEK_END); - m_size = std::ftell(fp); + m_size = std::ftell(fp); - if (m_size < 0) - FATAL_ERROR("File size of \"%s\" is less than zero.\n", filename.c_str()); + if (m_size < 0) + FATAL_ERROR("File size of \"%s\" is less than zero.\n", filename.c_str()); - m_buffer = new char[m_size + 1]; + m_buffer = new char[m_size + 1]; - std::rewind(fp); + std::rewind(fp); - if (std::fread(m_buffer, m_size, 1, fp) != 1) - FATAL_ERROR("Failed to read \"%s\".\n", filename.c_str()); + if (std::fread(m_buffer, m_size, 1, fp) != 1) + FATAL_ERROR("Failed to read \"%s\".\n", filename.c_str()); - m_buffer[m_size] = 0; + m_buffer[m_size] = 0; - std::fclose(fp); - } + std::fclose(fp); m_pos = 0; m_lineNum = 1; diff --git a/tools/preproc/preproc.cpp b/tools/preproc/preproc.cpp index 2d51ab1..c9c6042 100644 --- a/tools/preproc/preproc.cpp +++ b/tools/preproc/preproc.cpp @@ -140,22 +140,17 @@ int main(int argc, char **argv) g_charmap = new Charmap(argv[2]); - if (argv[1][0] == '-' && argv[1][1] == 0) { - PreprocCFile("-"); - } else { - 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); - } + 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; } |