diff options
author | rtk0c <[email protected]> | 2022-06-11 11:37:45 -0700 |
---|---|---|
committer | rtk0c <[email protected]> | 2022-06-11 11:37:45 -0700 |
commit | f29a141ab4c4308aed66f930a6f3a42cd20a482d (patch) | |
tree | 482cb3698e45ddc22cc39977dac3e49071554eb1 /source/10-common/Utils.hpp | |
parent | 123bea4fc8d828cec7b41949bab1db443387728e (diff) |
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
Diffstat (limited to 'source/10-common/Utils.hpp')
-rw-r--r-- | source/10-common/Utils.hpp | 13 |
1 files changed, 13 insertions, 0 deletions
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; } |