From f29a141ab4c4308aed66f930a6f3a42cd20a482d Mon Sep 17 00:00:00 2001 From: rtk0c Date: Sat, 11 Jun 2022 11:37:45 -0700 Subject: Changeset: 70 Fix cmake and codegen infra - Invoke codegen.exe once with a list of changed files, instead of individually for each changed file (this gives the codegen global access to all the code, allowing more things) - Initial support for outputting an archive SQLite database that contains all the code info --- source/10-common/Utils.hpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'source/10-common/Utils.hpp') diff --git a/source/10-common/Utils.hpp b/source/10-common/Utils.hpp index 9560b57..fdf0f5d 100644 --- a/source/10-common/Utils.hpp +++ b/source/10-common/Utils.hpp @@ -19,8 +19,21 @@ enum IoMode { FILE* OpenCstdioFile(const std::filesystem::path& path, IoMode mode, bool binary = false); FILE* OpenCstdioFile(const char* path, IoMode mode, bool binary = false); +/// Retrieve a whole line (marked by `\n` or EOF) into the buffer. If the line ends with EOF, two things happen: +/// 1. a `\n` character is appended to the line content, emulating as-if the line ended with `\n`. +/// 2. `false` is returned +/// Otherwise, `true` is returned. +/// +/// Empty lines are not skipped at all, including the very last empty line if it exists. +bool ReadCstdioLine(FILE* file, std::string& buffer); +/// Same as the other overload, except working with a fixed-size buffer. +/// NOTE: this also gives the length of the line compared to `std::fgets`. +/// `std::fgets` requires us to run `std::strlen` on the output again to find the length +bool ReadCstdioLine(FILE* file, char* buffer, size_t bufferSize, size_t* outLineLength = nullptr); + std::string ReadFileAsString(const std::filesystem::path& path); + constexpr float Abs(float v) noexcept { return v < 0.0f ? -v : v; } -- cgit v1.2.3-70-g09d2