mirror of
https://github.com/neocturne/MinedMap.git
synced 2025-03-05 17:44:52 +01:00
Workaround for old libraries without regex support
This commit is contained in:
parent
bedd81dce6
commit
a3d6648fa6
1 changed files with 8 additions and 7 deletions
|
@ -33,7 +33,6 @@
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <regex>
|
|
||||||
#include <system_error>
|
#include <system_error>
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
@ -134,8 +133,6 @@ static void doRegion(const std::string &input, const std::string &output) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
static const std::regex re("r\\.(-?\\d+)\\.(-?\\d+)\\.mca");
|
|
||||||
|
|
||||||
if (argc < 3) {
|
if (argc < 3) {
|
||||||
std::fprintf(stderr, "Usage: %s <data directory> <output directory>\n", argv[0]);
|
std::fprintf(stderr, "Usage: %s <data directory> <output directory>\n", argv[0]);
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -156,15 +153,19 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
struct dirent *entry;
|
struct dirent *entry;
|
||||||
while ((entry = readdir(dir)) != nullptr) {
|
while ((entry = readdir(dir)) != nullptr) {
|
||||||
std::cmatch m;
|
int x, z;
|
||||||
if (std::regex_match(entry->d_name, m, re)) {
|
if (std::sscanf(entry->d_name, "r.%i.%i.mca", &x, &z) == 2) {
|
||||||
int x = std::atoi(m[1].str().c_str());
|
size_t l = strlen(entry->d_name) + 1;
|
||||||
|
char buf[l];
|
||||||
|
std::snprintf(buf, l, "r.%i.%i.mca", x, z);
|
||||||
|
if (std::memcmp(entry->d_name, buf, l))
|
||||||
|
continue;
|
||||||
|
|
||||||
if (x < minX)
|
if (x < minX)
|
||||||
minX = x;
|
minX = x;
|
||||||
if (x > maxX)
|
if (x > maxX)
|
||||||
maxX = x;
|
maxX = x;
|
||||||
|
|
||||||
int z = std::atoi(m[2].str().c_str());
|
|
||||||
if (z < minZ)
|
if (z < minZ)
|
||||||
minZ = z;
|
minZ = z;
|
||||||
if (z > maxZ)
|
if (z > maxZ)
|
||||||
|
|
Loading…
Add table
Reference in a new issue