summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-11-04 16:49:22 +0100
committerStanislaw Halik <sthalik@misaki.pl>2023-11-04 16:59:25 +0100
commit555bd6dce82143394b93380b42212df99d201495 (patch)
treeaec14dd9a32633834595d8a4ae1f3376ecd59a68
parent7984e3a949278265d7893e60521fc6a23a22aaef (diff)
b
-rw-r--r--anim-crop-tool/main.cpp52
-rw-r--r--compat/fix-argv0.cpp22
-rw-r--r--compat/fix-argv0.hpp3
-rw-r--r--loader/atlas.cpp22
-rw-r--r--loader/impl.hpp1
-rw-r--r--loader/loader.hpp1
-rw-r--r--test/main.cpp5
7 files changed, 52 insertions, 54 deletions
diff --git a/anim-crop-tool/main.cpp b/anim-crop-tool/main.cpp
index 65045fd4..2068d662 100644
--- a/anim-crop-tool/main.cpp
+++ b/anim-crop-tool/main.cpp
@@ -1,10 +1,12 @@
#include "atlas.hpp"
-#include "serialize/magnum-vector2i.hpp"
-#include "serialize/json-helper.hpp"
-#include "serialize/anim.hpp"
+#include "compat/assert.hpp"
#include "compat/defs.hpp"
#include "compat/sysexits.hpp"
+#include "compat/fix-argv0.hpp"
#include "loader/loader.hpp"
+#include "serialize/magnum-vector2i.hpp"
+#include "serialize/json-helper.hpp"
+#include "serialize/anim.hpp"
#include <cerrno>
#include <cmath>
@@ -22,10 +24,8 @@
#include <Corrade/Utility/Path.h>
#include <opencv2/core/mat.hpp>
-#include <opencv2/imgcodecs/imgcodecs.hpp>
#include <opencv2/imgproc/imgproc.hpp>
-
-#include "compat/assert.hpp"
+#include <opencv2/imgcodecs/imgcodecs.hpp>
using namespace floormat;
@@ -96,10 +96,12 @@ static bool load_file(anim_group& group, options& opts, anim_atlas_& atlas, Stri
opts.scale = anim_scale::ratio{new_width / (float)size.width};
}
- const auto dest_size = fm_begin(
+ cv::Size dest_size;
+ {
auto xy = opts.scale.scale_to({(unsigned)size.width, (unsigned)size.height});
- return cv::Size{(int)xy[0], (int)xy[1]};
- );
+ dest_size = cv::Size{(int)xy[0], (int)xy[1]};
+ }
+
const auto factor = (float)dest_size.width / (float)size.width;
if (size.width < dest_size.width || size.height < dest_size.height)
@@ -179,22 +181,6 @@ static bool load_directory(anim_group& group, options& opts, anim_atlas_& atlas)
return true;
}
-static char* fix_argv0(char* argv0) noexcept
-{
-#ifdef _WIN32
- if (auto* c = strrchr(argv0, '\\'); c && c[1])
- {
- if (auto* s = strrchr(c, '.'); s && !strcmp(".exe", s))
- *s = '\0';
- return c+1;
- }
-#else
- if (auto* c = strrchr(argv0, '/'); c && c[1])
- return c+1;
-#endif
- return argv0;
-}
-
using Corrade::Utility::Arguments;
static std::tuple<options, Arguments, bool> parse_cmdline(int argc, const char* const* argv) noexcept
@@ -232,18 +218,6 @@ static std::tuple<options, Arguments, bool> parse_cmdline(int argc, const char*
return EX_USAGE;
}
-[[nodiscard]] static bool check_atlas_name(StringView str) noexcept
-{
- if (str.isEmpty())
- return false;
- if (str.findAny("\\<>&;:^'\" ") || str.find("/."))
- return false;
- if (str[0] == '.' || str[0] == '/')
- return false;
-
- return true;
-}
-
int main(int argc, char** argv)
{
argv[0] = fix_argv0(argv[0]);
@@ -253,13 +227,13 @@ int main(int argc, char** argv)
auto anim_info = json_helper::from_json<anim_def>(opts.input_file);
- if (!check_atlas_name(anim_info.object_name))
+ if (!loader.check_atlas_name(anim_info.object_name))
{
Error{} << "error: atlas object name" << anim_info.object_name << "is invalid";
return EX_DATAERR;
}
- if (!anim_info.anim_name.isEmpty() && !check_atlas_name(anim_info.anim_name))
+ if (!anim_info.anim_name.isEmpty() && !loader.check_atlas_name(anim_info.anim_name))
{
Error{} << "error: atlas animation name" << anim_info.object_name << "is invalid";
return EX_DATAERR;
diff --git a/compat/fix-argv0.cpp b/compat/fix-argv0.cpp
new file mode 100644
index 00000000..8248f58d
--- /dev/null
+++ b/compat/fix-argv0.cpp
@@ -0,0 +1,22 @@
+#include "fix-argv0.hpp"
+#include <cstring>
+
+namespace floormat {
+
+char* fix_argv0(char* argv0) noexcept
+{
+#ifdef _WIN32
+ if (auto* c = std::strrchr(argv0, '\\'); c && c[1])
+ {
+ if (auto* s = std::strrchr(c, '.'); s && !std::strcmp(".exe", s))
+ *s = '\0';
+ return c+1;
+ }
+#else
+ if (auto* c = std::strrchr(argv0, '/'); c && c[1])
+ return c+1;
+#endif
+ return argv0;
+}
+
+} // namespace floormat
diff --git a/compat/fix-argv0.hpp b/compat/fix-argv0.hpp
new file mode 100644
index 00000000..dcd989aa
--- /dev/null
+++ b/compat/fix-argv0.hpp
@@ -0,0 +1,3 @@
+#pragma once
+
+namespace floormat { char* fix_argv0(char* argv0) noexcept; }
diff --git a/loader/atlas.cpp b/loader/atlas.cpp
index ede9f8ec..0f492119 100644
--- a/loader/atlas.cpp
+++ b/loader/atlas.cpp
@@ -27,6 +27,16 @@ StringView loader_::make_atlas_path(char(&buf)[FILENAME_MAX], StringView dir, St
return StringView{buf};
}
+bool loader_::check_atlas_name(StringView str) noexcept
+{
+ if (!str || str[0] == '.' || str[0] == '/')
+ return false;
+ if (str.findAny("\\\"'\n\r\t\a\033\0|$!%{}#^*?<>&;:^"_s) || str.find("/."_s))
+ return false;
+
+ return true;
+}
+
} // namespace floormat
namespace floormat::loader_detail {
@@ -129,16 +139,4 @@ void loader_impl::get_anim_atlas_list()
}
}
-bool loader_impl::check_atlas_name(StringView str)
-{
- if (str.isEmpty())
- return false;
- if (str.findAny("\n\r\t\0\\|$<>&;:^'\""_s) || str.find("/."_s))
- return false;
- if (str[0] == '.' || str[0] == '/')
- return false;
-
- return true;
-}
-
} // namespace floormat::loader_detail
diff --git a/loader/impl.hpp b/loader/impl.hpp
index d0159a3d..13087ff3 100644
--- a/loader/impl.hpp
+++ b/loader/impl.hpp
@@ -54,7 +54,6 @@ struct loader_impl final : loader_
StringView startup_directory() noexcept override;
static void system_init();
static bool chdir(StringView pathname);
- [[nodiscard]] static bool check_atlas_name(StringView name);
void ensure_plugins();
explicit loader_impl();
diff --git a/loader/loader.hpp b/loader/loader.hpp
index 484c5102..ce331203 100644
--- a/loader/loader.hpp
+++ b/loader/loader.hpp
@@ -40,6 +40,7 @@ struct loader_
virtual const vobj_info& vobj(StringView name) = 0;
virtual ArrayView<struct vobj_info> vobj_list() = 0;
static StringView make_atlas_path(char(&buf)[FILENAME_MAX], StringView dir, StringView name);
+ [[nodiscard]] static bool check_atlas_name(StringView name) noexcept;
loader_(const loader_&) = delete;
loader_& operator=(const loader_&) = delete;
diff --git a/test/main.cpp b/test/main.cpp
index 9176b47a..165ac932 100644
--- a/test/main.cpp
+++ b/test/main.cpp
@@ -30,11 +30,12 @@ int test_app::exec()
test_bitmask();
test_serializer_1();
test_serializer_2();
- test_path_search();
test_math();
test_hash();
- test_path_search_node_pool();
test_wall_atlas();
+
+ test_path_search_node_pool();
+ test_path_search();
zzz_test_misc();
return 0;