diff options
| author | Alexander Gavrilov | 2012-01-02 18:46:24 +0400 |
|---|---|---|
| committer | Alexander Gavrilov | 2012-01-02 18:46:24 +0400 |
| commit | 326c58f7935cb39206c52646a38ff19502ebb966 (patch) | |
| tree | ea9305869a7e07ba6263b137436db34986d1386b /library/MiscUtils.cpp | |
| parent | bfcaca92663bdabd9621384abeaabb0edaa13761 (diff) | |
| download | dfhack-326c58f7935cb39206c52646a38ff19502ebb966.tar.gz dfhack-326c58f7935cb39206c52646a38ff19502ebb966.tar.bz2 dfhack-326c58f7935cb39206c52646a38ff19502ebb966.tar.xz | |
Add a plugin to tweak inorganic materials in jobs.
It also auto-seeks in the build item list if used in that context.
Diffstat (limited to 'library/MiscUtils.cpp')
| -rw-r--r-- | library/MiscUtils.cpp | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/library/MiscUtils.cpp b/library/MiscUtils.cpp index 47deea04..72e3eae2 100644 --- a/library/MiscUtils.cpp +++ b/library/MiscUtils.cpp @@ -27,8 +27,6 @@ distribution. #include "Core.h" #include "MiscUtils.h" - - #ifndef LINUX_BUILD #include <Windows.h> #else @@ -36,6 +34,31 @@ distribution. #include <ctime> #endif +#include <stdarg.h> + +std::string stl_sprintf(const char *fmt, ...) { + va_list lst; + va_start(lst, fmt); + std::string rv = stl_vsprintf(fmt, lst); + va_end(lst); + return rv; +} + +std::string stl_vsprintf(const char *fmt, va_list args) { + std::vector<char> buf; + buf.resize(4096); + for (;;) { + int rsz = vsnprintf(&buf[0], buf.size(), fmt, args); + + if (rsz < 0) + buf.resize(buf.size()*2); + else if (unsigned(rsz) > buf.size()) + buf.resize(rsz+1); + else + return std::string(&buf[0], rsz); + } +} + #ifdef LINUX_BUILD // Linux uint64_t GetTimeMs64() { |
