Update to nall v100r1
This commit is contained in:
parent
285fc3a7f6
commit
6838142c9f
45 changed files with 475 additions and 486 deletions
62
atoi.hpp
62
atoi.hpp
|
@ -4,83 +4,83 @@
|
||||||
|
|
||||||
namespace nall {
|
namespace nall {
|
||||||
|
|
||||||
constexpr inline auto binary_(const char* s, uintmax sum = 0) -> uintmax {
|
constexpr inline auto toBinary_(const char* s, uintmax_t sum = 0) -> uintmax_t {
|
||||||
return (
|
return (
|
||||||
*s == '0' || *s == '1' ? binary_(s + 1, (sum << 1) | *s - '0') :
|
*s == '0' || *s == '1' ? toBinary_(s + 1, (sum << 1) | *s - '0') :
|
||||||
*s == '\'' ? binary_(s + 1, sum) :
|
*s == '\'' ? toBinary_(s + 1, sum) :
|
||||||
sum
|
sum
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr inline auto octal_(const char* s, uintmax sum = 0) -> uintmax {
|
constexpr inline auto toOctal_(const char* s, uintmax_t sum = 0) -> uintmax_t {
|
||||||
return (
|
return (
|
||||||
*s >= '0' && *s <= '7' ? octal_(s + 1, (sum << 3) | *s - '0') :
|
*s >= '0' && *s <= '7' ? toOctal_(s + 1, (sum << 3) | *s - '0') :
|
||||||
*s == '\'' ? octal_(s + 1, sum) :
|
*s == '\'' ? toOctal_(s + 1, sum) :
|
||||||
sum
|
sum
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr inline auto decimal_(const char* s, uintmax sum = 0) -> uintmax {
|
constexpr inline auto toDecimal_(const char* s, uintmax_t sum = 0) -> uintmax_t {
|
||||||
return (
|
return (
|
||||||
*s >= '0' && *s <= '9' ? decimal_(s + 1, (sum * 10) + *s - '0') :
|
*s >= '0' && *s <= '9' ? toDecimal_(s + 1, (sum * 10) + *s - '0') :
|
||||||
*s == '\'' ? decimal_(s + 1, sum) :
|
*s == '\'' ? toDecimal_(s + 1, sum) :
|
||||||
sum
|
sum
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr inline auto hex_(const char* s, uintmax sum = 0) -> uintmax {
|
constexpr inline auto toHex_(const char* s, uintmax_t sum = 0) -> uintmax_t {
|
||||||
return (
|
return (
|
||||||
*s >= 'A' && *s <= 'F' ? hex_(s + 1, (sum << 4) | *s - 'A' + 10) :
|
*s >= 'A' && *s <= 'F' ? toHex_(s + 1, (sum << 4) | *s - 'A' + 10) :
|
||||||
*s >= 'a' && *s <= 'f' ? hex_(s + 1, (sum << 4) | *s - 'a' + 10) :
|
*s >= 'a' && *s <= 'f' ? toHex_(s + 1, (sum << 4) | *s - 'a' + 10) :
|
||||||
*s >= '0' && *s <= '9' ? hex_(s + 1, (sum << 4) | *s - '0') :
|
*s >= '0' && *s <= '9' ? toHex_(s + 1, (sum << 4) | *s - '0') :
|
||||||
*s == '\'' ? hex_(s + 1, sum) :
|
*s == '\'' ? toHex_(s + 1, sum) :
|
||||||
sum
|
sum
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
constexpr inline auto binary(const char* s) -> uintmax {
|
constexpr inline auto toBinary(const char* s) -> uintmax_t {
|
||||||
return (
|
return (
|
||||||
*s == '0' && (*(s + 1) == 'B' || *(s + 1) == 'b') ? binary_(s + 2) :
|
*s == '0' && (*(s + 1) == 'B' || *(s + 1) == 'b') ? toBinary_(s + 2) :
|
||||||
*s == '%' ? binary_(s + 1) : binary_(s)
|
*s == '%' ? toBinary_(s + 1) : toBinary_(s)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr inline auto octal(const char* s) -> uintmax {
|
constexpr inline auto toOctal(const char* s) -> uintmax_t {
|
||||||
return (
|
return (
|
||||||
*s == '0' && (*(s + 1) == 'O' || *(s + 1) == 'o') ? octal_(s + 2) :
|
*s == '0' && (*(s + 1) == 'O' || *(s + 1) == 'o') ? toOctal_(s + 2) :
|
||||||
octal_(s)
|
toOctal_(s)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr inline auto hex(const char* s) -> uintmax {
|
constexpr inline auto toHex(const char* s) -> uintmax_t {
|
||||||
return (
|
return (
|
||||||
*s == '0' && (*(s + 1) == 'X' || *(s + 1) == 'x') ? hex_(s + 2) :
|
*s == '0' && (*(s + 1) == 'X' || *(s + 1) == 'x') ? toHex_(s + 2) :
|
||||||
*s == '$' ? hex_(s + 1) : hex_(s)
|
*s == '$' ? toHex_(s + 1) : toHex_(s)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
constexpr inline auto natural(const char* s) -> uintmax {
|
constexpr inline auto toNatural(const char* s) -> uintmax_t {
|
||||||
return (
|
return (
|
||||||
*s == '0' && (*(s + 1) == 'B' || *(s + 1) == 'b') ? binary_(s + 2) :
|
*s == '0' && (*(s + 1) == 'B' || *(s + 1) == 'b') ? toBinary_(s + 2) :
|
||||||
*s == '0' && (*(s + 1) == 'O' || *(s + 1) == 'o') ? octal_(s + 2) :
|
*s == '0' && (*(s + 1) == 'O' || *(s + 1) == 'o') ? toOctal_(s + 2) :
|
||||||
*s == '0' && (*(s + 1) == 'X' || *(s + 1) == 'x') ? hex_(s + 2) :
|
*s == '0' && (*(s + 1) == 'X' || *(s + 1) == 'x') ? toHex_(s + 2) :
|
||||||
*s == '%' ? binary_(s + 1) : *s == '$' ? hex_(s + 1) : decimal_(s)
|
*s == '%' ? toBinary_(s + 1) : *s == '$' ? toHex_(s + 1) : toDecimal_(s)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr inline auto integer(const char* s) -> intmax {
|
constexpr inline auto toInteger(const char* s) -> intmax_t {
|
||||||
return (
|
return (
|
||||||
*s == '+' ? +natural(s + 1) : *s == '-' ? -natural(s + 1) : natural(s)
|
*s == '+' ? +toNatural(s + 1) : *s == '-' ? -toNatural(s + 1) : toNatural(s)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
inline auto real(const char* s) -> double {
|
inline auto toReal(const char* s) -> double {
|
||||||
return atof(s);
|
return atof(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ struct Archive {
|
||||||
static auto extract(const string& beatname, const string& pathname) -> vector<uint8_t>;
|
static auto extract(const string& beatname, const string& pathname) -> vector<uint8_t>;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static auto scan(lstring& result, const string& basename, const string& pathname) -> void;
|
static auto scan(string_vector& result, const string& basename, const string& pathname) -> void;
|
||||||
};
|
};
|
||||||
|
|
||||||
auto Archive::create(const string& beatname, const string& pathname, const string& metadata) -> bool {
|
auto Archive::create(const string& beatname, const string& pathname, const string& metadata) -> bool {
|
||||||
|
@ -23,7 +23,7 @@ auto Archive::create(const string& beatname, const string& pathname, const strin
|
||||||
beat.writevu(metadata.size());
|
beat.writevu(metadata.size());
|
||||||
beat.writes(metadata);
|
beat.writes(metadata);
|
||||||
|
|
||||||
lstring contents;
|
string_vector contents;
|
||||||
scan(contents, pathname, pathname);
|
scan(contents, pathname, pathname);
|
||||||
|
|
||||||
for(auto& name : contents) {
|
for(auto& name : contents) {
|
||||||
|
@ -121,7 +121,7 @@ auto Archive::extract(const string& beatname, const string& filename) -> vector<
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
auto Archive::scan(lstring& result, const string& basename, const string& pathname) -> void {
|
auto Archive::scan(string_vector& result, const string& basename, const string& pathname) -> void {
|
||||||
for(auto& name : directory::contents(pathname)) {
|
for(auto& name : directory::contents(pathname)) {
|
||||||
result.append(string{pathname, name}.trimLeft(basename, 1L));
|
result.append(string{pathname, name}.trimLeft(basename, 1L));
|
||||||
if(name.endsWith("/")) scan(result, basename, {pathname, name});
|
if(name.endsWith("/")) scan(result, basename, {pathname, name});
|
||||||
|
|
|
@ -28,7 +28,7 @@ struct bpsmulti {
|
||||||
writeNumber(metadata.length());
|
writeNumber(metadata.length());
|
||||||
writeString(metadata);
|
writeString(metadata);
|
||||||
|
|
||||||
lstring sourceList, targetList;
|
string_vector sourceList, targetList;
|
||||||
ls(sourceList, sourcePath, sourcePath);
|
ls(sourceList, sourcePath, sourcePath);
|
||||||
ls(targetList, targetPath, targetPath);
|
ls(targetList, targetPath, targetPath);
|
||||||
|
|
||||||
|
@ -156,14 +156,14 @@ protected:
|
||||||
Hash::CRC32 checksum;
|
Hash::CRC32 checksum;
|
||||||
|
|
||||||
//create() functions
|
//create() functions
|
||||||
auto ls(lstring& list, const string& path, const string& basepath) -> void {
|
auto ls(string_vector& list, const string& path, const string& basepath) -> void {
|
||||||
lstring paths = directory::folders(path);
|
auto paths = directory::folders(path);
|
||||||
for(auto& pathname : paths) {
|
for(auto& pathname : paths) {
|
||||||
list.append(string{path, pathname}.trimLeft(basepath, 1L));
|
list.append(string{path, pathname}.trimLeft(basepath, 1L));
|
||||||
ls(list, {path, pathname}, basepath);
|
ls(list, {path, pathname}, basepath);
|
||||||
}
|
}
|
||||||
|
|
||||||
lstring files = directory::files(path);
|
auto files = directory::files(path);
|
||||||
for(auto& filename : files) {
|
for(auto& filename : files) {
|
||||||
list.append(string{path, filename}.trimLeft(basepath, 1L));
|
list.append(string{path, filename}.trimLeft(basepath, 1L));
|
||||||
}
|
}
|
||||||
|
|
151
bit-field.hpp
151
bit-field.hpp
|
@ -2,55 +2,11 @@
|
||||||
|
|
||||||
namespace nall {
|
namespace nall {
|
||||||
|
|
||||||
template<typename type, uint Lo, uint Hi> struct NaturalBitField {
|
template<typename Type, uint Bit> struct BooleanBitField {
|
||||||
enum : uint { lo = Lo <= Hi ? Lo : Hi };
|
|
||||||
enum : uint { hi = Hi >= Lo ? Hi : Lo };
|
|
||||||
enum : uint { bits = hi - lo + 1 };
|
|
||||||
enum : uint { mask = (~0ull >> (64 - bits)) << lo };
|
|
||||||
static_assert(hi < sizeof(type) * 8, "");
|
|
||||||
|
|
||||||
inline NaturalBitField() = default;
|
|
||||||
inline NaturalBitField(const NaturalBitField& value) { set(value.data); }
|
|
||||||
template<typename T> inline NaturalBitField(const T& value) { set(value << lo); }
|
|
||||||
|
|
||||||
inline explicit operator bool() const { return data & mask; }
|
|
||||||
inline operator type() const { return get(); }
|
|
||||||
|
|
||||||
inline auto& operator=(const NaturalBitField& value) { return set(value.data); }
|
|
||||||
template<typename T> inline auto& operator=(const T& value) { return set(value << lo); }
|
|
||||||
|
|
||||||
inline auto operator++(int) { type value = get(); set(data + (1 << lo)); return value; }
|
|
||||||
inline auto operator--(int) { type value = get(); set(data - (1 << lo)); return value; }
|
|
||||||
|
|
||||||
inline auto& operator++() { return set(data + (1 << lo)); }
|
|
||||||
inline auto& operator--() { return set(data - (1 << lo)); }
|
|
||||||
|
|
||||||
inline auto& operator &=(const type value) { return set(data & (value << lo)); }
|
|
||||||
inline auto& operator |=(const type value) { return set(data | (value << lo)); }
|
|
||||||
inline auto& operator ^=(const type value) { return set(data ^ (value << lo)); }
|
|
||||||
inline auto& operator<<=(const type value) { return set((data & mask) << value); }
|
|
||||||
inline auto& operator>>=(const type value) { return set((data & mask) >> value); }
|
|
||||||
inline auto& operator +=(const type value) { return set(data + (value << lo)); }
|
|
||||||
inline auto& operator -=(const type value) { return set(data - (value << lo)); }
|
|
||||||
inline auto& operator *=(const type value) { return set((get() * value) << lo); }
|
|
||||||
inline auto& operator /=(const type value) { return set((get() / value) << lo); }
|
|
||||||
inline auto& operator %=(const type value) { return set((get() % value) << lo); }
|
|
||||||
|
|
||||||
private:
|
|
||||||
type data;
|
|
||||||
|
|
||||||
inline auto get() const -> type {
|
|
||||||
return (data & mask) >> lo;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline auto set(type value) -> NaturalBitField& {
|
|
||||||
return data = (data & ~mask) | (value & mask), *this;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename type, uint Bit> struct BooleanBitField {
|
|
||||||
enum : uint { bit = Bit };
|
enum : uint { bit = Bit };
|
||||||
enum : uint { mask = 1ull << bit };
|
enum : uint { mask = 1ull << bit };
|
||||||
|
using type = Type;
|
||||||
|
using utype = typename std::make_unsigned<type>::type;
|
||||||
static_assert(bit < sizeof(type) * 8, "");
|
static_assert(bit < sizeof(type) * 8, "");
|
||||||
|
|
||||||
inline BooleanBitField() = default;
|
inline BooleanBitField() = default;
|
||||||
|
@ -71,7 +27,7 @@ template<typename type, uint Bit> struct BooleanBitField {
|
||||||
inline auto& invert() { return set(get() ^ 1); }
|
inline auto& invert() { return set(get() ^ 1); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
type data;
|
utype data;
|
||||||
|
|
||||||
inline auto get() const -> bool {
|
inline auto get() const -> bool {
|
||||||
return data & mask;
|
return data & mask;
|
||||||
|
@ -82,4 +38,103 @@ private:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<typename Type, uint Lo, uint Hi> struct NaturalBitField {
|
||||||
|
enum : uint { lo = Lo <= Hi ? Lo : Hi };
|
||||||
|
enum : uint { hi = Hi >= Lo ? Hi : Lo };
|
||||||
|
enum : uint { bits = hi - lo + 1 };
|
||||||
|
enum : uint { mask = (~0ull >> (64 - bits)) << lo };
|
||||||
|
using type = Type;
|
||||||
|
using utype = typename std::make_unsigned<type>::type;
|
||||||
|
static_assert(hi < sizeof(type) * 8, "");
|
||||||
|
|
||||||
|
inline NaturalBitField() = default;
|
||||||
|
inline NaturalBitField(const NaturalBitField& value) { set(value.data); }
|
||||||
|
template<typename T> inline NaturalBitField(const T& value) { set(value << lo); }
|
||||||
|
|
||||||
|
inline explicit operator bool() const { return data & mask; }
|
||||||
|
inline operator utype() const { return get(); }
|
||||||
|
|
||||||
|
inline auto& operator=(const NaturalBitField& value) { return set(value.data); }
|
||||||
|
template<typename T> inline auto& operator=(const T& value) { return set(value << lo); }
|
||||||
|
|
||||||
|
inline auto operator++(int) { utype value = get(); set(data + (1 << lo)); return value; }
|
||||||
|
inline auto operator--(int) { utype value = get(); set(data - (1 << lo)); return value; }
|
||||||
|
|
||||||
|
inline auto& operator++() { return set(data + (1 << lo)); }
|
||||||
|
inline auto& operator--() { return set(data - (1 << lo)); }
|
||||||
|
|
||||||
|
inline auto& operator &=(const utype value) { return set(data & (value << lo)); }
|
||||||
|
inline auto& operator |=(const utype value) { return set(data | (value << lo)); }
|
||||||
|
inline auto& operator ^=(const utype value) { return set(data ^ (value << lo)); }
|
||||||
|
inline auto& operator<<=(const utype value) { return set((data & mask) << value); }
|
||||||
|
inline auto& operator>>=(const utype value) { return set((data & mask) >> value); }
|
||||||
|
inline auto& operator +=(const utype value) { return set(data + (value << lo)); }
|
||||||
|
inline auto& operator -=(const utype value) { return set(data - (value << lo)); }
|
||||||
|
inline auto& operator *=(const utype value) { return set((get() * value) << lo); }
|
||||||
|
inline auto& operator /=(const utype value) { return set((get() / value) << lo); }
|
||||||
|
inline auto& operator %=(const utype value) { return set((get() % value) << lo); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
utype data;
|
||||||
|
|
||||||
|
inline auto get() const -> utype {
|
||||||
|
return (data & mask) >> lo;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline auto set(utype value) -> NaturalBitField& {
|
||||||
|
return data = (data & ~mask) | (value & mask), *this;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename Type, uint Lo, uint Hi> struct IntegerBitField {
|
||||||
|
enum : uint { lo = Lo <= Hi ? Lo : Hi };
|
||||||
|
enum : uint { hi = Hi >= Lo ? Hi : Lo };
|
||||||
|
enum : uint { bits = hi - lo + 1 };
|
||||||
|
enum : uint { mask = (~0ull >> (64 - bits)) << lo };
|
||||||
|
using type = Type;
|
||||||
|
using stype = typename std::make_signed<type>::type;
|
||||||
|
using utype = typename std::make_unsigned<type>::type;
|
||||||
|
static_assert(hi < sizeof(type) * 8, "");
|
||||||
|
|
||||||
|
inline IntegerBitField() = default;
|
||||||
|
inline IntegerBitField(const IntegerBitField& value) { set(value.get()); }
|
||||||
|
template<typename T> inline IntegerBitField(const T& value) { set(value); }
|
||||||
|
|
||||||
|
inline explicit operator bool() const { return data & mask; }
|
||||||
|
inline operator stype() const { return get(); }
|
||||||
|
|
||||||
|
inline auto& operator=(const IntegerBitField& value) { return set(value.get()); }
|
||||||
|
template<typename T> inline auto& operator=(const T& value) { return set(value); }
|
||||||
|
|
||||||
|
inline auto operator++(int) { stype value = get(); set(value + 1); return value; }
|
||||||
|
inline auto operator--(int) { stype value = get(); set(value - 1); return value; }
|
||||||
|
|
||||||
|
inline auto& operator++() { return set(get() + 1); }
|
||||||
|
inline auto& operator--() { return set(get() - 1); }
|
||||||
|
|
||||||
|
inline auto& operator &=(const stype value) { return set(get() & value); }
|
||||||
|
inline auto& operator |=(const stype value) { return set(get() | value); }
|
||||||
|
inline auto& operator ^=(const stype value) { return set(get() ^ value); }
|
||||||
|
inline auto& operator<<=(const stype value) { return set(get() << value); }
|
||||||
|
inline auto& operator>>=(const stype value) { return set(get() >> value); }
|
||||||
|
inline auto& operator +=(const stype value) { return set(get() + value); }
|
||||||
|
inline auto& operator -=(const stype value) { return set(get() - value); }
|
||||||
|
inline auto& operator *=(const stype value) { return set(get() * value); }
|
||||||
|
inline auto& operator /=(const stype value) { return set(get() / value); }
|
||||||
|
inline auto& operator %=(const stype value) { return set(get() % value); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
utype data;
|
||||||
|
|
||||||
|
inline auto get() const -> stype {
|
||||||
|
enum : utype { b = 1ull << (bits - 1) };
|
||||||
|
enum : utype { m = b * 2 - 1 };
|
||||||
|
return ((((data & mask) >> lo) & m) ^ b) - b;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline auto set(utype value) -> IntegerBitField& {
|
||||||
|
return data = (data & ~mask) | ((value << lo) & mask), *this;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
32
bit.hpp
32
bit.hpp
|
@ -4,28 +4,28 @@
|
||||||
|
|
||||||
namespace nall {
|
namespace nall {
|
||||||
|
|
||||||
template<uint bits> inline auto uclamp(const uintmax x) -> uintmax {
|
template<uint bits> inline auto uclamp(const uintmax_t x) -> uintmax_t {
|
||||||
enum : uintmax { b = 1ull << (bits - 1), y = b * 2 - 1 };
|
enum : uintmax_t { b = 1ull << (bits - 1), y = b * 2 - 1 };
|
||||||
return y + ((x - y) & -(x < y)); //min(x, y);
|
return y + ((x - y) & -(x < y)); //min(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<uint bits> inline auto uclip(const uintmax x) -> uintmax {
|
template<uint bits> inline auto uclip(const uintmax_t x) -> uintmax_t {
|
||||||
enum : uintmax { b = 1ull << (bits - 1), m = b * 2 - 1 };
|
enum : uintmax_t { b = 1ull << (bits - 1), m = b * 2 - 1 };
|
||||||
return (x & m);
|
return (x & m);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<uint bits> inline auto sclamp(const intmax x) -> intmax {
|
template<uint bits> inline auto sclamp(const intmax_t x) -> intmax_t {
|
||||||
enum : intmax { b = 1ull << (bits - 1), m = b - 1 };
|
enum : intmax_t { b = 1ull << (bits - 1), m = b - 1 };
|
||||||
return (x > m) ? m : (x < -b) ? -b : x;
|
return (x > m) ? m : (x < -b) ? -b : x;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<uint bits> inline auto sclip(const intmax x) -> intmax {
|
template<uint bits> inline auto sclip(const intmax_t x) -> intmax_t {
|
||||||
enum : uintmax { b = 1ull << (bits - 1), m = b * 2 - 1 };
|
enum : uintmax_t { b = 1ull << (bits - 1), m = b * 2 - 1 };
|
||||||
return ((x & m) ^ b) - b;
|
return ((x & m) ^ b) - b;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace bit {
|
namespace bit {
|
||||||
constexpr inline auto mask(const char* s, uintmax sum = 0) -> uintmax {
|
constexpr inline auto mask(const char* s, uintmax_t sum = 0) -> uintmax_t {
|
||||||
return (
|
return (
|
||||||
*s == '0' || *s == '1' ? mask(s + 1, (sum << 1) | 1) :
|
*s == '0' || *s == '1' ? mask(s + 1, (sum << 1) | 1) :
|
||||||
*s == ' ' || *s == '_' ? mask(s + 1, sum) :
|
*s == ' ' || *s == '_' ? mask(s + 1, sum) :
|
||||||
|
@ -34,7 +34,7 @@ namespace bit {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr inline auto test(const char* s, uintmax sum = 0) -> uintmax {
|
constexpr inline auto test(const char* s, uintmax_t sum = 0) -> uintmax_t {
|
||||||
return (
|
return (
|
||||||
*s == '0' || *s == '1' ? test(s + 1, (sum << 1) | (*s - '0')) :
|
*s == '0' || *s == '1' ? test(s + 1, (sum << 1) | (*s - '0')) :
|
||||||
*s == ' ' || *s == '_' ? test(s + 1, sum) :
|
*s == ' ' || *s == '_' ? test(s + 1, sum) :
|
||||||
|
@ -44,22 +44,22 @@ namespace bit {
|
||||||
}
|
}
|
||||||
|
|
||||||
//lowest(0b1110) == 0b0010
|
//lowest(0b1110) == 0b0010
|
||||||
constexpr inline auto lowest(const uintmax x) -> uintmax {
|
constexpr inline auto lowest(const uintmax_t x) -> uintmax_t {
|
||||||
return x & -x;
|
return x & -x;
|
||||||
}
|
}
|
||||||
|
|
||||||
//clear_lowest(0b1110) == 0b1100
|
//clear_lowest(0b1110) == 0b1100
|
||||||
constexpr inline auto clearLowest(const uintmax x) -> uintmax {
|
constexpr inline auto clearLowest(const uintmax_t x) -> uintmax_t {
|
||||||
return x & (x - 1);
|
return x & (x - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
//set_lowest(0b0101) == 0b0111
|
//set_lowest(0b0101) == 0b0111
|
||||||
constexpr inline auto setLowest(const uintmax x) -> uintmax {
|
constexpr inline auto setLowest(const uintmax_t x) -> uintmax_t {
|
||||||
return x | (x + 1);
|
return x | (x + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
//count number of bits set in a byte
|
//count number of bits set in a byte
|
||||||
inline auto count(uintmax x) -> uint {
|
inline auto count(uintmax_t x) -> uint {
|
||||||
uint count = 0;
|
uint count = 0;
|
||||||
do count += x & 1; while(x >>= 1);
|
do count += x & 1; while(x >>= 1);
|
||||||
return count;
|
return count;
|
||||||
|
@ -67,7 +67,7 @@ namespace bit {
|
||||||
|
|
||||||
//return index of the first bit set (or zero of no bits are set)
|
//return index of the first bit set (or zero of no bits are set)
|
||||||
//first(0b1000) == 3
|
//first(0b1000) == 3
|
||||||
inline auto first(uintmax x) -> uint {
|
inline auto first(uintmax_t x) -> uint {
|
||||||
uint first = 0;
|
uint first = 0;
|
||||||
while(x) { if(x & 1) break; x >>= 1; first++; }
|
while(x) { if(x & 1) break; x >>= 1; first++; }
|
||||||
return first;
|
return first;
|
||||||
|
@ -75,7 +75,7 @@ namespace bit {
|
||||||
|
|
||||||
//round up to next highest single bit:
|
//round up to next highest single bit:
|
||||||
//round(15) == 16, round(16) == 16, round(17) == 32
|
//round(15) == 16, round(16) == 16, round(17) == 32
|
||||||
inline auto round(uintmax x) -> uintmax {
|
inline auto round(uintmax_t x) -> uintmax_t {
|
||||||
if((x & (x - 1)) == 0) return x;
|
if((x & (x - 1)) == 0) return x;
|
||||||
while(x & (x - 1)) x &= x - 1;
|
while(x & (x - 1)) x &= x - 1;
|
||||||
return x << 1;
|
return x << 1;
|
||||||
|
|
|
@ -30,9 +30,9 @@ struct Node {
|
||||||
auto set(const string& value) -> void {
|
auto set(const string& value) -> void {
|
||||||
switch(type) {
|
switch(type) {
|
||||||
case Type::Boolean: *(bool*)data = (value != "false"); break;
|
case Type::Boolean: *(bool*)data = (value != "false"); break;
|
||||||
case Type::Integer: *(int*)data = integer(value); break;
|
case Type::Integer: *(int*)data = toInteger(value); break;
|
||||||
case Type::Natural: *(uint*)data = natural(value); break;
|
case Type::Natural: *(uint*)data = toNatural(value); break;
|
||||||
case Type::Double: *(double*)data = real(value); break;
|
case Type::Double: *(double*)data = toReal(value); break;
|
||||||
case Type::String: *(string*)data = value; break;
|
case Type::String: *(string*)data = value; break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,46 +18,46 @@
|
||||||
namespace nall {
|
namespace nall {
|
||||||
|
|
||||||
struct directory : inode {
|
struct directory : inode {
|
||||||
static auto create(const string& pathname, unsigned permissions = 0755) -> bool; //recursive
|
static auto create(const string& pathname, uint permissions = 0755) -> bool; //recursive
|
||||||
static auto remove(const string& pathname) -> bool; //recursive
|
static auto remove(const string& pathname) -> bool; //recursive
|
||||||
static auto exists(const string& pathname) -> bool;
|
static auto exists(const string& pathname) -> bool;
|
||||||
|
|
||||||
static auto folders(const string& pathname, const string& pattern = "*") -> lstring {
|
static auto folders(const string& pathname, const string& pattern = "*") -> string_vector {
|
||||||
lstring folders = directory::ufolders(pathname, pattern);
|
auto folders = directory::ufolders(pathname, pattern);
|
||||||
folders.sort();
|
folders.sort();
|
||||||
return folders;
|
return folders;
|
||||||
}
|
}
|
||||||
|
|
||||||
static auto files(const string& pathname, const string& pattern = "*") -> lstring {
|
static auto files(const string& pathname, const string& pattern = "*") -> string_vector {
|
||||||
lstring files = directory::ufiles(pathname, pattern);
|
auto files = directory::ufiles(pathname, pattern);
|
||||||
files.sort();
|
files.sort();
|
||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
static auto contents(const string& pathname, const string& pattern = "*") -> lstring {
|
static auto contents(const string& pathname, const string& pattern = "*") -> string_vector {
|
||||||
lstring folders = directory::ufolders(pathname); //pattern search of contents should only filter files
|
auto folders = directory::ufolders(pathname); //pattern search of contents should only filter files
|
||||||
lstring files = directory::ufiles(pathname, pattern);
|
auto files = directory::ufiles(pathname, pattern);
|
||||||
folders.sort();
|
folders.sort();
|
||||||
files.sort();
|
files.sort();
|
||||||
for(auto& file : files) folders.append(file);
|
for(auto& file : files) folders.append(file);
|
||||||
return folders;
|
return folders;
|
||||||
}
|
}
|
||||||
|
|
||||||
static auto ifolders(const string& pathname, const string& pattern = "*") -> lstring {
|
static auto ifolders(const string& pathname, const string& pattern = "*") -> string_vector {
|
||||||
lstring folders = ufolders(pathname, pattern);
|
auto folders = ufolders(pathname, pattern);
|
||||||
folders.isort();
|
folders.isort();
|
||||||
return folders;
|
return folders;
|
||||||
}
|
}
|
||||||
|
|
||||||
static auto ifiles(const string& pathname, const string& pattern = "*") -> lstring {
|
static auto ifiles(const string& pathname, const string& pattern = "*") -> string_vector {
|
||||||
lstring files = ufiles(pathname, pattern);
|
auto files = ufiles(pathname, pattern);
|
||||||
files.isort();
|
files.isort();
|
||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
static auto icontents(const string& pathname, const string& pattern = "*") -> lstring {
|
static auto icontents(const string& pathname, const string& pattern = "*") -> string_vector {
|
||||||
lstring folders = directory::ufolders(pathname); //pattern search of contents should only filter files
|
auto folders = directory::ufolders(pathname); //pattern search of contents should only filter files
|
||||||
lstring files = directory::ufiles(pathname, pattern);
|
auto files = directory::ufiles(pathname, pattern);
|
||||||
folders.isort();
|
folders.isort();
|
||||||
files.isort();
|
files.isort();
|
||||||
for(auto& file : files) folders.append(file);
|
for(auto& file : files) folders.append(file);
|
||||||
|
@ -66,14 +66,14 @@ struct directory : inode {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//internal functions; these return unsorted lists
|
//internal functions; these return unsorted lists
|
||||||
static auto ufolders(const string& pathname, const string& pattern = "*") -> lstring;
|
static auto ufolders(const string& pathname, const string& pattern = "*") -> string_vector;
|
||||||
static auto ufiles(const string& pathname, const string& pattern = "*") -> lstring;
|
static auto ufiles(const string& pathname, const string& pattern = "*") -> string_vector;
|
||||||
};
|
};
|
||||||
|
|
||||||
#if defined(PLATFORM_WINDOWS)
|
#if defined(PLATFORM_WINDOWS)
|
||||||
inline auto directory::create(const string& pathname, unsigned permissions) -> bool {
|
inline auto directory::create(const string& pathname, uint permissions) -> bool {
|
||||||
string path;
|
string path;
|
||||||
lstring list = string{pathname}.transform("\\", "/").trimRight("/").split("/");
|
auto list = string{pathname}.transform("\\", "/").trimRight("/").split("/");
|
||||||
bool result = true;
|
bool result = true;
|
||||||
for(auto& part : list) {
|
for(auto& part : list) {
|
||||||
path.append(part, "/");
|
path.append(part, "/");
|
||||||
|
@ -84,7 +84,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
inline auto directory::remove(const string& pathname) -> bool {
|
inline auto directory::remove(const string& pathname) -> bool {
|
||||||
lstring list = directory::contents(pathname);
|
auto list = directory::contents(pathname);
|
||||||
for(auto& name : list) {
|
for(auto& name : list) {
|
||||||
if(name.endsWith("/")) directory::remove({pathname, name});
|
if(name.endsWith("/")) directory::remove({pathname, name});
|
||||||
else file::remove({pathname, name});
|
else file::remove({pathname, name});
|
||||||
|
@ -100,8 +100,20 @@ private:
|
||||||
return (result & FILE_ATTRIBUTE_DIRECTORY);
|
return (result & FILE_ATTRIBUTE_DIRECTORY);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline auto directory::ufolders(const string& pathname, const string& pattern) -> lstring {
|
inline auto directory::ufolders(const string& pathname, const string& pattern) -> string_vector {
|
||||||
lstring list;
|
if(!pathname) {
|
||||||
|
//special root pseudo-folder (return list of drives)
|
||||||
|
wchar_t drives[PATH_MAX] = {0};
|
||||||
|
GetLogicalDriveStrings(PATH_MAX, drives);
|
||||||
|
wchar_t* p = drives;
|
||||||
|
while(*p || *(p + 1)) {
|
||||||
|
if(!*p) *p = ';';
|
||||||
|
*p++;
|
||||||
|
}
|
||||||
|
return string{(const char*)utf8_t(drives)}.replace("\\", "/").split(";");
|
||||||
|
}
|
||||||
|
|
||||||
|
string_vector list;
|
||||||
string path = pathname;
|
string path = pathname;
|
||||||
path.transform("/", "\\");
|
path.transform("/", "\\");
|
||||||
if(!path.endsWith("\\")) path.append("\\");
|
if(!path.endsWith("\\")) path.append("\\");
|
||||||
|
@ -130,8 +142,10 @@ private:
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline auto directory::ufiles(const string& pathname, const string& pattern) -> lstring {
|
inline auto directory::ufiles(const string& pathname, const string& pattern) -> string_vector {
|
||||||
lstring list;
|
if(!pathname) return {};
|
||||||
|
|
||||||
|
string_vector list;
|
||||||
string path = pathname;
|
string path = pathname;
|
||||||
path.transform("/", "\\");
|
path.transform("/", "\\");
|
||||||
if(!path.endsWith("\\")) path.append("\\");
|
if(!path.endsWith("\\")) path.append("\\");
|
||||||
|
@ -166,9 +180,9 @@ private:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline auto directory::create(const string& pathname, unsigned permissions) -> bool {
|
inline auto directory::create(const string& pathname, uint permissions) -> bool {
|
||||||
string path;
|
string path;
|
||||||
lstring list = string{pathname}.trimRight("/").split("/");
|
auto list = string{pathname}.trimRight("/").split("/");
|
||||||
bool result = true;
|
bool result = true;
|
||||||
for(auto& part : list) {
|
for(auto& part : list) {
|
||||||
path.append(part, "/");
|
path.append(part, "/");
|
||||||
|
@ -179,7 +193,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
inline auto directory::remove(const string& pathname) -> bool {
|
inline auto directory::remove(const string& pathname) -> bool {
|
||||||
lstring list = directory::contents(pathname);
|
auto list = directory::contents(pathname);
|
||||||
for(auto& name : list) {
|
for(auto& name : list) {
|
||||||
if(name.endsWith("/")) directory::remove({pathname, name});
|
if(name.endsWith("/")) directory::remove({pathname, name});
|
||||||
else file::remove({pathname, name});
|
else file::remove({pathname, name});
|
||||||
|
@ -188,14 +202,15 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
inline auto directory::exists(const string& pathname) -> bool {
|
inline auto directory::exists(const string& pathname) -> bool {
|
||||||
DIR* dp = opendir(pathname);
|
struct stat data;
|
||||||
if(!dp) return false;
|
if(stat(pathname, &data) != 0) return false;
|
||||||
closedir(dp);
|
return S_ISDIR(data.st_mode);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline auto directory::ufolders(const string& pathname, const string& pattern) -> lstring {
|
inline auto directory::ufolders(const string& pathname, const string& pattern) -> string_vector {
|
||||||
lstring list;
|
if(!pathname) return string_vector{"/"};
|
||||||
|
|
||||||
|
string_vector list;
|
||||||
DIR* dp;
|
DIR* dp;
|
||||||
struct dirent* ep;
|
struct dirent* ep;
|
||||||
dp = opendir(pathname);
|
dp = opendir(pathname);
|
||||||
|
@ -213,8 +228,10 @@ private:
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline auto directory::ufiles(const string& pathname, const string& pattern) -> lstring {
|
inline auto directory::ufiles(const string& pathname, const string& pattern) -> string_vector {
|
||||||
lstring list;
|
if(!pathname) return {};
|
||||||
|
|
||||||
|
string_vector list;
|
||||||
DIR* dp;
|
DIR* dp;
|
||||||
struct dirent* ep;
|
struct dirent* ep;
|
||||||
dp = opendir(pathname);
|
dp = opendir(pathname);
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
using namespace nall;
|
using namespace nall;
|
||||||
|
|
||||||
struct FX {
|
struct FX {
|
||||||
auto open(lstring& args) -> bool;
|
auto open(string_vector& args) -> bool;
|
||||||
auto close() -> void;
|
auto close() -> void;
|
||||||
auto readable() -> bool;
|
auto readable() -> bool;
|
||||||
auto read() -> uint8_t;
|
auto read() -> uint8_t;
|
||||||
|
@ -23,7 +23,7 @@ struct FX {
|
||||||
serial device;
|
serial device;
|
||||||
};
|
};
|
||||||
|
|
||||||
auto FX::open(lstring& args) -> bool {
|
auto FX::open(string_vector& args) -> bool {
|
||||||
//device name override support
|
//device name override support
|
||||||
string name;
|
string name;
|
||||||
for(uint n : range(args)) {
|
for(uint n : range(args)) {
|
||||||
|
|
|
@ -1,95 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <nall/nall.hpp>
|
|
||||||
#include <nall/serial.hpp>
|
|
||||||
using namespace nall;
|
|
||||||
|
|
||||||
#include <signal.h>
|
|
||||||
#include <sys/resource.h>
|
|
||||||
#include <sys/time.h>
|
|
||||||
|
|
||||||
static function<auto () -> bool> usart_quit;
|
|
||||||
static function<auto (uint microseconds) -> void> usart_usleep;
|
|
||||||
static function<auto () -> bool> usart_readable;
|
|
||||||
static function<auto () -> uint8> usart_read;
|
|
||||||
static function<auto () -> bool> usart_writable;
|
|
||||||
static function<auto (uint8 data) -> void> usart_write;
|
|
||||||
|
|
||||||
extern "C" auto usart_init(
|
|
||||||
function<auto () -> bool> quit,
|
|
||||||
function<auto (uint microseconds) -> void> usleep,
|
|
||||||
function<auto () -> bool> readable,
|
|
||||||
function<auto () -> uint8> read,
|
|
||||||
function<auto () -> bool> writable,
|
|
||||||
function<auto (uint8 data) -> void> write
|
|
||||||
) -> void {
|
|
||||||
usart_quit = quit;
|
|
||||||
usart_usleep = usleep;
|
|
||||||
usart_readable = readable;
|
|
||||||
usart_read = read;
|
|
||||||
usart_writable = writable;
|
|
||||||
usart_write = write;
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" auto usart_main(nall::lstring) -> void;
|
|
||||||
|
|
||||||
//
|
|
||||||
|
|
||||||
static serial usart;
|
|
||||||
static bool usart_is_virtual = true;
|
|
||||||
static bool usart_sigint = false;
|
|
||||||
|
|
||||||
static auto usart_virtual() -> bool {
|
|
||||||
return usart_is_virtual;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
|
|
||||||
static auto usarthw_quit() -> bool {
|
|
||||||
return usart_sigint;
|
|
||||||
}
|
|
||||||
|
|
||||||
static auto usarthw_usleep(uint microseconds) -> void {
|
|
||||||
usleep(microseconds);
|
|
||||||
}
|
|
||||||
|
|
||||||
static auto usarthw_readable() -> bool {
|
|
||||||
return usart.readable();
|
|
||||||
}
|
|
||||||
|
|
||||||
static auto usarthw_read() -> uint8 {
|
|
||||||
while(true) {
|
|
||||||
uint8 buffer[1];
|
|
||||||
int length = usart.read((uint8_t*)&buffer, 1);
|
|
||||||
if(length > 0) return buffer[0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static auto usarthw_writable() -> bool {
|
|
||||||
return usart.writable();
|
|
||||||
}
|
|
||||||
|
|
||||||
static auto usarthw_write(uint8 data) -> void {
|
|
||||||
uint8 buffer[1] = {data};
|
|
||||||
usart.write((uint8*)&buffer, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
static auto sigint(int) -> void {
|
|
||||||
signal(SIGINT, SIG_DFL);
|
|
||||||
usart_sigint = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <nall/main.hpp>
|
|
||||||
auto nall::main(lstring args) -> void {
|
|
||||||
setpriority(PRIO_PROCESS, 0, -20); //requires superuser privileges; otherwise priority = +0
|
|
||||||
signal(SIGINT, sigint);
|
|
||||||
|
|
||||||
if(!usart.open("/dev/ttyACM0", 57600, true)) {
|
|
||||||
return print("error: unable to open USART hardware device\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
usart_is_virtual = false;
|
|
||||||
usart_init(usarthw_quit, usarthw_usleep, usarthw_readable, usarthw_read, usarthw_writable, usarthw_write);
|
|
||||||
usart_main(args);
|
|
||||||
usart.close();
|
|
||||||
}
|
|
18
file.hpp
18
file.hpp
|
@ -61,7 +61,7 @@ struct file : inode, varint {
|
||||||
return !(data.st_mode & S_IFDIR);
|
return !(data.st_mode & S_IFDIR);
|
||||||
}
|
}
|
||||||
|
|
||||||
static auto size(const string& filename) -> uintmax {
|
static auto size(const string& filename) -> uintmax_t {
|
||||||
#if defined(API_POSIX)
|
#if defined(API_POSIX)
|
||||||
struct stat data;
|
struct stat data;
|
||||||
stat(filename, &data);
|
stat(filename, &data);
|
||||||
|
@ -127,16 +127,16 @@ struct file : inode, varint {
|
||||||
return buffer[(file_offset++) & buffer_mask];
|
return buffer[(file_offset++) & buffer_mask];
|
||||||
}
|
}
|
||||||
|
|
||||||
auto readl(uint length = 1) -> uintmax {
|
auto readl(uint length = 1) -> uintmax_t {
|
||||||
uintmax data = 0;
|
uintmax_t data = 0;
|
||||||
for(int i = 0; i < length; i++) {
|
for(int i = 0; i < length; i++) {
|
||||||
data |= (uintmax)read() << (i << 3);
|
data |= (uintmax_t)read() << (i << 3);
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto readm(uint length = 1) -> uintmax {
|
auto readm(uint length = 1) -> uintmax_t {
|
||||||
uintmax data = 0;
|
uintmax_t data = 0;
|
||||||
while(length--) {
|
while(length--) {
|
||||||
data <<= 8;
|
data <<= 8;
|
||||||
data |= read();
|
data |= read();
|
||||||
|
@ -164,14 +164,14 @@ struct file : inode, varint {
|
||||||
if(file_offset > file_size) file_size = file_offset;
|
if(file_offset > file_size) file_size = file_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto writel(uintmax data, uint length = 1) -> void {
|
auto writel(uintmax_t data, uint length = 1) -> void {
|
||||||
while(length--) {
|
while(length--) {
|
||||||
write(data);
|
write(data);
|
||||||
data >>= 8;
|
data >>= 8;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto writem(uintmax data, uint length = 1) -> void {
|
auto writem(uintmax_t data, uint length = 1) -> void {
|
||||||
for(int i = length - 1; i >= 0; i--) {
|
for(int i = length - 1; i >= 0; i--) {
|
||||||
write(data >> (i << 3));
|
write(data >> (i << 3));
|
||||||
}
|
}
|
||||||
|
@ -200,7 +200,7 @@ struct file : inode, varint {
|
||||||
if(!fp) return; //file not open
|
if(!fp) return; //file not open
|
||||||
buffer_flush();
|
buffer_flush();
|
||||||
|
|
||||||
intmax req_offset = file_offset;
|
intmax_t req_offset = file_offset;
|
||||||
switch(index_) {
|
switch(index_) {
|
||||||
case index::absolute: req_offset = offset; break;
|
case index::absolute: req_offset = offset; break;
|
||||||
case index::relative: req_offset += offset; break;
|
case index::relative: req_offset += offset; break;
|
||||||
|
|
|
@ -69,7 +69,7 @@ auto Request::head(const function<bool (const uint8_t*, unsigned)>& callback) co
|
||||||
}
|
}
|
||||||
|
|
||||||
auto Request::setHead() -> bool {
|
auto Request::setHead() -> bool {
|
||||||
lstring headers = _head.split("\n");
|
auto headers = _head.split("\n");
|
||||||
string request = headers.takeLeft().trimRight("\r", 1L);
|
string request = headers.takeLeft().trimRight("\r", 1L);
|
||||||
string requestHost;
|
string requestHost;
|
||||||
|
|
||||||
|
@ -85,12 +85,12 @@ auto Request::setHead() -> bool {
|
||||||
//decode absolute URIs
|
//decode absolute URIs
|
||||||
request.strip().itrimLeft("http://", 1L);
|
request.strip().itrimLeft("http://", 1L);
|
||||||
if(!request.beginsWith("/")) {
|
if(!request.beginsWith("/")) {
|
||||||
lstring components = request.split("/", 1L);
|
auto components = request.split("/", 1L);
|
||||||
requestHost = components(0);
|
requestHost = components(0);
|
||||||
request = {"/", components(1)};
|
request = {"/", components(1)};
|
||||||
}
|
}
|
||||||
|
|
||||||
lstring components = request.split("?", 1L);
|
auto components = request.split("?", 1L);
|
||||||
setPath(components(0));
|
setPath(components(0));
|
||||||
|
|
||||||
if(auto queryString = components(1)) {
|
if(auto queryString = components(1)) {
|
||||||
|
|
|
@ -87,18 +87,18 @@ auto Response::head(const function<bool (const uint8_t*, unsigned)>& callback) c
|
||||||
}
|
}
|
||||||
|
|
||||||
auto Response::setHead() -> bool {
|
auto Response::setHead() -> bool {
|
||||||
lstring headers = _head.split("\n");
|
auto headers = _head.split("\n");
|
||||||
string response = headers.takeLeft().trimRight("\r");
|
string response = headers.takeLeft().trimRight("\r");
|
||||||
|
|
||||||
if(response.ibeginsWith("HTTP/1.0 ")) response.itrimLeft("HTTP/1.0 ", 1L);
|
if(response.ibeginsWith("HTTP/1.0 ")) response.itrimLeft("HTTP/1.0 ", 1L);
|
||||||
else if(response.ibeginsWith("HTTP/1.1 ")) response.itrimLeft("HTTP/1.1 ", 1L);
|
else if(response.ibeginsWith("HTTP/1.1 ")) response.itrimLeft("HTTP/1.1 ", 1L);
|
||||||
else return false;
|
else return false;
|
||||||
|
|
||||||
setResponseType(natural(response));
|
setResponseType(response.natural());
|
||||||
|
|
||||||
for(auto& header : headers) {
|
for(auto& header : headers) {
|
||||||
if(header.beginsWith(" ") || header.beginsWith("\t")) continue;
|
if(header.beginsWith(" ") || header.beginsWith("\t")) continue;
|
||||||
lstring variable = header.split(":", 1L).strip();
|
auto variable = header.split(":", 1L).strip();
|
||||||
if(variable.size() != 2) continue;
|
if(variable.size() != 2) continue;
|
||||||
this->header.append(variable[0], variable[1]);
|
this->header.append(variable[0], variable[1]);
|
||||||
}
|
}
|
||||||
|
@ -166,7 +166,7 @@ auto Response::findContentLength() const -> unsigned {
|
||||||
auto Response::findContentType() const -> string {
|
auto Response::findContentType() const -> string {
|
||||||
if(auto contentType = header["Content-Type"]) return contentType.value();
|
if(auto contentType = header["Content-Type"]) return contentType.value();
|
||||||
if(hasData()) return "application/octet-stream";
|
if(hasData()) return "application/octet-stream";
|
||||||
if(hasFile()) return findContentType(suffixname(file()));
|
if(hasFile()) return findContentType(Location::suffix(file()));
|
||||||
return "text/html; charset=utf-8";
|
return "text/html; charset=utf-8";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -101,7 +101,7 @@ auto Role::download(signed fd, Message& message) -> bool {
|
||||||
|
|
||||||
if(chunk.endsWith("\r\n") || chunk.endsWith("\n")) {
|
if(chunk.endsWith("\r\n") || chunk.endsWith("\n")) {
|
||||||
chunkReceived = true;
|
chunkReceived = true;
|
||||||
chunkLength = hex(chunk);
|
chunkLength = chunk.hex();
|
||||||
if(chunkLength == 0) break;
|
if(chunkLength == 0) break;
|
||||||
chunk.reset();
|
chunk.reset();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
namespace nall {
|
namespace nall { namespace Location {
|
||||||
|
|
||||||
// (/parent/child.type/)
|
// (/parent/child.type/)
|
||||||
// (/parent/child.type/)name.type
|
// (/parent/child.type/)name.type
|
||||||
auto pathname(string_view self) -> string {
|
inline auto path(string_view self) -> string {
|
||||||
const char* p = self.data() + self.size() - 1;
|
const char* p = self.data() + self.size() - 1;
|
||||||
for(int offset = self.size() - 1; offset >= 0; offset--, p--) {
|
for(int offset = self.size() - 1; offset >= 0; offset--, p--) {
|
||||||
if(*p == '/') return slice(self, 0, offset + 1);
|
if(*p == '/') return slice(self, 0, offset + 1);
|
||||||
|
@ -14,7 +14,7 @@ auto pathname(string_view self) -> string {
|
||||||
|
|
||||||
// /parent/child.type/()
|
// /parent/child.type/()
|
||||||
// /parent/child.type/(name.type)
|
// /parent/child.type/(name.type)
|
||||||
auto filename(string_view self) -> string {
|
inline auto file(string_view self) -> string {
|
||||||
const char* p = self.data() + self.size() - 1;
|
const char* p = self.data() + self.size() - 1;
|
||||||
for(int offset = self.size() - 1; offset >= 0; offset--, p--) {
|
for(int offset = self.size() - 1; offset >= 0; offset--, p--) {
|
||||||
if(*p == '/') return slice(self, offset + 1);
|
if(*p == '/') return slice(self, offset + 1);
|
||||||
|
@ -24,7 +24,7 @@ auto filename(string_view self) -> string {
|
||||||
|
|
||||||
// (/parent/)child.type/
|
// (/parent/)child.type/
|
||||||
// (/parent/child.type/)name.type
|
// (/parent/child.type/)name.type
|
||||||
auto dirname(string_view self) -> string {
|
inline auto dir(string_view self) -> string {
|
||||||
const char* p = self.data() + self.size() - 1, *last = p;
|
const char* p = self.data() + self.size() - 1, *last = p;
|
||||||
for(int offset = self.size() - 1; offset >= 0; offset--, p--) {
|
for(int offset = self.size() - 1; offset >= 0; offset--, p--) {
|
||||||
if(*p == '/' && p == last) continue;
|
if(*p == '/' && p == last) continue;
|
||||||
|
@ -35,7 +35,7 @@ auto dirname(string_view self) -> string {
|
||||||
|
|
||||||
// /parent/(child.type/)
|
// /parent/(child.type/)
|
||||||
// /parent/child.type/(name.type)
|
// /parent/child.type/(name.type)
|
||||||
auto basename(string_view self) -> string {
|
inline auto base(string_view self) -> string {
|
||||||
const char* p = self.data() + self.size() - 1, *last = p;
|
const char* p = self.data() + self.size() - 1, *last = p;
|
||||||
for(int offset = self.size() - 1; offset >= 0; offset--, p--) {
|
for(int offset = self.size() - 1; offset >= 0; offset--, p--) {
|
||||||
if(*p == '/' && p == last) continue;
|
if(*p == '/' && p == last) continue;
|
||||||
|
@ -46,7 +46,7 @@ auto basename(string_view self) -> string {
|
||||||
|
|
||||||
// /parent/(child).type/
|
// /parent/(child).type/
|
||||||
// /parent/child.type/(name).type
|
// /parent/child.type/(name).type
|
||||||
auto prefixname(string_view self) -> string {
|
inline auto prefix(string_view self) -> string {
|
||||||
const char* p = self.data() + self.size() - 1, *last = p;
|
const char* p = self.data() + self.size() - 1, *last = p;
|
||||||
for(int offset = self.size() - 1, suffix = -1; offset >= 0; offset--, p--) {
|
for(int offset = self.size() - 1, suffix = -1; offset >= 0; offset--, p--) {
|
||||||
if(*p == '/' && p == last) continue;
|
if(*p == '/' && p == last) continue;
|
||||||
|
@ -59,7 +59,7 @@ auto prefixname(string_view self) -> string {
|
||||||
|
|
||||||
// /parent/child(.type)/
|
// /parent/child(.type)/
|
||||||
// /parent/child.type/name(.type)
|
// /parent/child.type/name(.type)
|
||||||
auto suffixname(string_view self) -> string {
|
inline auto suffix(string_view self) -> string {
|
||||||
const char* p = self.data() + self.size() - 1, *last = p;
|
const char* p = self.data() + self.size() - 1, *last = p;
|
||||||
for(int offset = self.size() - 1; offset >= 0; offset--, p--) {
|
for(int offset = self.size() - 1; offset >= 0; offset--, p--) {
|
||||||
if(*p == '/' && p == last) continue;
|
if(*p == '/' && p == last) continue;
|
||||||
|
@ -69,4 +69,4 @@ auto suffixname(string_view self) -> string {
|
||||||
return ""; //no suffix found
|
return ""; //no suffix found
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}}
|
14
main.hpp
14
main.hpp
|
@ -4,7 +4,7 @@
|
||||||
#include <nall/string.hpp>
|
#include <nall/string.hpp>
|
||||||
|
|
||||||
namespace nall {
|
namespace nall {
|
||||||
auto main(lstring arguments) -> void;
|
auto main(string_vector arguments) -> void;
|
||||||
|
|
||||||
auto main(int argc, char** argv) -> int {
|
auto main(int argc, char** argv) -> int {
|
||||||
#if defined(PLATFORM_WINDOWS)
|
#if defined(PLATFORM_WINDOWS)
|
||||||
|
@ -17,8 +17,16 @@ namespace nall {
|
||||||
utf8_args(argc, argv);
|
utf8_args(argc, argv);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
lstring arguments;
|
string_vector arguments;
|
||||||
for(auto n : range(argc)) arguments.append(argv[n]);
|
for(auto n : range(argc)) {
|
||||||
|
string argument = argv[n];
|
||||||
|
|
||||||
|
//normalize directory and file path arguments
|
||||||
|
if(directory::exists(argument)) argument.transform("\\", "/").trimRight("/").append("/");
|
||||||
|
else if(file::exists(argument)) argument.transform("\\", "/").trimRight("/");
|
||||||
|
|
||||||
|
arguments.append(argument);
|
||||||
|
}
|
||||||
|
|
||||||
return main(move(arguments)), EXIT_SUCCESS;
|
return main(move(arguments)), EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,13 +65,13 @@ struct context {
|
||||||
if(c == ',' && function == true) c = ';';
|
if(c == ',' && function == true) c = ';';
|
||||||
}
|
}
|
||||||
|
|
||||||
lstring list = expression.split(",");
|
auto list = expression.split(",");
|
||||||
for(auto& item : list) {
|
for(auto& item : list) {
|
||||||
item.strip();
|
item.strip();
|
||||||
if(item.match("f(?*) ?*")) {
|
if(item.match("f(?*) ?*")) {
|
||||||
item.trimLeft("f(", 1L);
|
item.trimLeft("f(", 1L);
|
||||||
lstring part = item.split(") ", 1L);
|
auto part = item.split(") ", 1L);
|
||||||
lstring args = part[0].split(";", 3L).strip();
|
auto args = part[0].split(";", 3L).strip();
|
||||||
|
|
||||||
uint length = eval(args(0, "0"));
|
uint length = eval(args(0, "0"));
|
||||||
uint offset = eval(args(1, "0"));
|
uint offset = eval(args(1, "0"));
|
||||||
|
@ -93,7 +93,7 @@ struct context {
|
||||||
item.trimLeft("base64", 1L);
|
item.trimLeft("base64", 1L);
|
||||||
if(item.match("(?*) *")) {
|
if(item.match("(?*) *")) {
|
||||||
item.trimLeft("(", 1L);
|
item.trimLeft("(", 1L);
|
||||||
lstring part = item.split(") ", 1L);
|
auto part = item.split(") ", 1L);
|
||||||
offset = eval(part[0]);
|
offset = eval(part[0]);
|
||||||
item = part(1, "");
|
item = part(1, "");
|
||||||
}
|
}
|
||||||
|
@ -118,9 +118,9 @@ struct context {
|
||||||
auto parse(const string& data) -> void {
|
auto parse(const string& data) -> void {
|
||||||
reset();
|
reset();
|
||||||
|
|
||||||
lstring lines = data.split("\n");
|
auto lines = data.split("\n");
|
||||||
for(auto& line : lines) {
|
for(auto& line : lines) {
|
||||||
lstring part = line.split(":", 1L).strip();
|
auto part = line.split(":", 1L).strip();
|
||||||
if(part.size() != 2) continue;
|
if(part.size() != 2) continue;
|
||||||
|
|
||||||
if(part[0] == "offset") offset = eval(part[1]);
|
if(part[0] == "offset") offset = eval(part[1]);
|
||||||
|
|
1
nall.hpp
1
nall.hpp
|
@ -32,6 +32,7 @@
|
||||||
#include <nall/inode.hpp>
|
#include <nall/inode.hpp>
|
||||||
#include <nall/interpolation.hpp>
|
#include <nall/interpolation.hpp>
|
||||||
#include <nall/intrinsics.hpp>
|
#include <nall/intrinsics.hpp>
|
||||||
|
#include <nall/location.hpp>
|
||||||
#include <nall/map.hpp>
|
#include <nall/map.hpp>
|
||||||
#include <nall/matrix.hpp>
|
#include <nall/matrix.hpp>
|
||||||
#include <nall/maybe.hpp>
|
#include <nall/maybe.hpp>
|
||||||
|
|
2
path.hpp
2
path.hpp
|
@ -17,7 +17,7 @@ inline auto active() -> string {
|
||||||
inline auto real(string_view name) -> string {
|
inline auto real(string_view name) -> string {
|
||||||
string result;
|
string result;
|
||||||
char path[PATH_MAX] = "";
|
char path[PATH_MAX] = "";
|
||||||
if(::realpath(name, path)) result = pathname(string{path}.transform("\\", "/"));
|
if(::realpath(name, path)) result = Location::path(string{path}.transform("\\", "/"));
|
||||||
if(!result) return active();
|
if(!result) return active();
|
||||||
result.transform("\\", "/");
|
result.transform("\\", "/");
|
||||||
if(!result.endsWith("/")) result.append("/");
|
if(!result.endsWith("/")) result.append("/");
|
||||||
|
|
|
@ -31,29 +31,29 @@ auto service::command(const string& name, const string& command) -> bool {
|
||||||
" stop : stop service if it is running\n"
|
" stop : stop service if it is running\n"
|
||||||
" remove : remove semaphore lock if service crashed\n"
|
" remove : remove semaphore lock if service crashed\n"
|
||||||
" {value} : send custom command to service\n"
|
" {value} : send custom command to service\n"
|
||||||
"", format{name}), false;
|
"", string_format{name}), false;
|
||||||
|
|
||||||
if(shared.open(name, 4096)) {
|
if(shared.open(name, 4096)) {
|
||||||
if(command == "start") {
|
if(command == "start") {
|
||||||
print("[{0}] already started\n", format{name});
|
print("[{0}] already started\n", string_format{name});
|
||||||
} else if(command == "status") {
|
} else if(command == "status") {
|
||||||
print("[{0}] running\n", format{name});
|
print("[{0}] running\n", string_format{name});
|
||||||
}
|
}
|
||||||
if(auto data = shared.acquire()) {
|
if(auto data = shared.acquire()) {
|
||||||
if(command == "stop") print("[{0}] stopped\n", format{name});
|
if(command == "stop") print("[{0}] stopped\n", string_format{name});
|
||||||
memory::copy(data, command.data(), min(command.size(), 4096));
|
memory::copy(data, command.data(), min(command.size(), 4096));
|
||||||
shared.release();
|
shared.release();
|
||||||
}
|
}
|
||||||
if(command == "remove") {
|
if(command == "remove") {
|
||||||
shared.remove();
|
shared.remove();
|
||||||
print("[{0}] removed\n", format{name});
|
print("[{0}] removed\n", string_format{name});
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(command == "start") {
|
if(command == "start") {
|
||||||
if(shared.create(name, 4096)) {
|
if(shared.create(name, 4096)) {
|
||||||
print("[{0}] started\n", format{name});
|
print("[{0}] started\n", string_format{name});
|
||||||
auto pid = fork();
|
auto pid = fork();
|
||||||
if(pid == 0) {
|
if(pid == 0) {
|
||||||
signal(SIGHUP, SIG_IGN);
|
signal(SIGHUP, SIG_IGN);
|
||||||
|
@ -63,13 +63,13 @@ auto service::command(const string& name, const string& command) -> bool {
|
||||||
}
|
}
|
||||||
shared.close();
|
shared.close();
|
||||||
} else {
|
} else {
|
||||||
print("[{0}] start failed ({1})\n", format{name, strerror(errno)});
|
print("[{0}] start failed ({1})\n", string_format{name, strerror(errno)});
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(command == "status") {
|
if(command == "status") {
|
||||||
print("[{0}] stopped\n", format{name});
|
print("[{0}] stopped\n", string_format{name});
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -79,15 +79,15 @@ template<uint Bits> struct Natural {
|
||||||
inline auto bit(uint index) -> Reference { return {*this, index, index}; }
|
inline auto bit(uint index) -> Reference { return {*this, index, index}; }
|
||||||
inline auto byte(uint index) -> Reference { return {*this, index * 8 + 0, index * 8 + 7}; }
|
inline auto byte(uint index) -> Reference { return {*this, index * 8 + 0, index * 8 + 7}; }
|
||||||
|
|
||||||
inline auto clamp(uint bits) -> uintmax {
|
inline auto clamp(uint bits) -> uintmax_t {
|
||||||
const uintmax b = 1ull << (bits - 1);
|
const uintmax_t b = 1ull << (bits - 1);
|
||||||
const uintmax m = b * 2 - 1;
|
const uintmax_t m = b * 2 - 1;
|
||||||
return data < m ? data : m;
|
return data < m ? data : m;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline auto clip(uint bits) -> uintmax {
|
inline auto clip(uint bits) -> uintmax_t {
|
||||||
const uintmax b = 1ull << (bits - 1);
|
const uintmax_t b = 1ull << (bits - 1);
|
||||||
const uintmax m = b * 2 - 1;
|
const uintmax_t m = b * 2 - 1;
|
||||||
return data & m;
|
return data & m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,15 +161,15 @@ template<uint Bits> struct Integer {
|
||||||
inline auto bit(uint index) -> Reference { return {*this, index, index}; }
|
inline auto bit(uint index) -> Reference { return {*this, index, index}; }
|
||||||
inline auto byte(uint index) -> Reference { return {*this, index * 8 + 0, index * 8 + 7}; }
|
inline auto byte(uint index) -> Reference { return {*this, index * 8 + 0, index * 8 + 7}; }
|
||||||
|
|
||||||
inline auto clamp(uint bits) -> intmax {
|
inline auto clamp(uint bits) -> intmax_t {
|
||||||
const intmax b = 1ull << (bits - 1);
|
const intmax_t b = 1ull << (bits - 1);
|
||||||
const intmax m = b - 1;
|
const intmax_t m = b - 1;
|
||||||
return data > m ? m : data < -b ? -b : data;
|
return data > m ? m : data < -b ? -b : data;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline auto clip(uint bits) -> intmax {
|
inline auto clip(uint bits) -> intmax_t {
|
||||||
const uintmax b = 1ull << (bits - 1);
|
const uintmax_t b = 1ull << (bits - 1);
|
||||||
const uintmax m = b * 2 - 1;
|
const uintmax_t m = b * 2 - 1;
|
||||||
return ((data & m) ^ b) - b;
|
return ((data & m) ^ b) - b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,8 +185,8 @@ template<uint Bits> struct Real {
|
||||||
using type =
|
using type =
|
||||||
type_if<expression<Bits == 32>, float32_t,
|
type_if<expression<Bits == 32>, float32_t,
|
||||||
type_if<expression<Bits == 64>, float64_t,
|
type_if<expression<Bits == 64>, float64_t,
|
||||||
type_if<expression<Bits == 80>, float80_t,
|
//type_if<expression<Bits == 80>, float80_t,
|
||||||
void>>>;
|
void>>;
|
||||||
|
|
||||||
inline Real() : data(0.0) {}
|
inline Real() : data(0.0) {}
|
||||||
template<typename T> inline Real(const T& value) : data((type)value) {}
|
template<typename T> inline Real(const T& value) : data((type)value) {}
|
||||||
|
@ -215,9 +215,9 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
using boolean = nall::Boolean;
|
using boolean = nall::Boolean;
|
||||||
//note: these conflict with nall/atoi.hpp functions
|
using integer = nall::Integer<sizeof( int) * 8>;
|
||||||
//using integer = nall::Integer<sizeof( int) * 8>;
|
using natural = nall::Natural<sizeof(uint) * 8>;
|
||||||
//using natural = nall::Natural<sizeof(uint) * 8>;
|
using real = nall::Real<sizeof(double) * 8>;
|
||||||
|
|
||||||
using int1 = nall::Integer< 1>;
|
using int1 = nall::Integer< 1>;
|
||||||
using int2 = nall::Integer< 2>;
|
using int2 = nall::Integer< 2>;
|
||||||
|
@ -349,6 +349,6 @@ using uint62 = nall::Natural<62>;
|
||||||
using uint63 = nall::Natural<63>;
|
using uint63 = nall::Natural<63>;
|
||||||
using uint64 = nall::Natural<64>;
|
using uint64 = nall::Natural<64>;
|
||||||
|
|
||||||
using float32 = nall::Real<32>;
|
using real32 = nall::Real<32>;
|
||||||
using float64 = nall::Real<64>;
|
using real64 = nall::Real<64>;
|
||||||
using float80 = nall::Real<80>;
|
//using real80 = nall::Real<80>;
|
||||||
|
|
8
run.hpp
8
run.hpp
|
@ -36,7 +36,7 @@ template<typename... P> inline auto execute(const string& name, P&&... p) -> exe
|
||||||
if(pid == 0) {
|
if(pid == 0) {
|
||||||
const char* argv[1 + sizeof...(p) + 1];
|
const char* argv[1 + sizeof...(p) + 1];
|
||||||
const char** argp = argv;
|
const char** argp = argv;
|
||||||
lstring argl(forward<P>(p)...);
|
string_vector argl(forward<P>(p)...);
|
||||||
*argp++ = (const char*)name;
|
*argp++ = (const char*)name;
|
||||||
for(auto& arg : argl) *argp++ = (const char*)arg;
|
for(auto& arg : argl) *argp++ = (const char*)arg;
|
||||||
*argp++ = nullptr;
|
*argp++ = nullptr;
|
||||||
|
@ -92,7 +92,7 @@ template<typename... P> inline auto invoke(const string& name, P&&... p) -> void
|
||||||
if(pid == 0) {
|
if(pid == 0) {
|
||||||
const char* argv[1 + sizeof...(p) + 1];
|
const char* argv[1 + sizeof...(p) + 1];
|
||||||
const char** argp = argv;
|
const char** argp = argv;
|
||||||
lstring argl(forward<P>(p)...);
|
string_vector argl(forward<P>(p)...);
|
||||||
*argp++ = (const char*)name;
|
*argp++ = (const char*)name;
|
||||||
for(auto& arg : argl) *argp++ = (const char*)arg;
|
for(auto& arg : argl) *argp++ = (const char*)arg;
|
||||||
*argp++ = nullptr;
|
*argp++ = nullptr;
|
||||||
|
@ -107,7 +107,7 @@ template<typename... P> inline auto invoke(const string& name, P&&... p) -> void
|
||||||
#elif defined(PLATFORM_WINDOWS)
|
#elif defined(PLATFORM_WINDOWS)
|
||||||
|
|
||||||
template<typename... P> inline auto execute(const string& name, P&&... p) -> execute_result_t {
|
template<typename... P> inline auto execute(const string& name, P&&... p) -> execute_result_t {
|
||||||
lstring argl(name, forward<P>(p)...);
|
string_vector argl(name, forward<P>(p)...);
|
||||||
for(auto& arg : argl) if(arg.find(" ")) arg = {"\"", arg, "\""};
|
for(auto& arg : argl) if(arg.find(" ")) arg = {"\"", arg, "\""};
|
||||||
string arguments = argl.merge(" ");
|
string arguments = argl.merge(" ");
|
||||||
|
|
||||||
|
@ -189,7 +189,7 @@ template<typename... P> inline auto execute(const string& name, P&&... p) -> exe
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename... P> inline auto invoke(const string& name, P&&... p) -> void {
|
template<typename... P> inline auto invoke(const string& name, P&&... p) -> void {
|
||||||
lstring argl(forward<P>(p)...);
|
string_vector argl(forward<P>(p)...);
|
||||||
for(auto& arg : argl) if(arg.find(" ")) arg = {"\"", arg, "\""};
|
for(auto& arg : argl) if(arg.find(" ")) arg = {"\"", arg, "\""};
|
||||||
string arguments = argl.merge(" ");
|
string arguments = argl.merge(" ");
|
||||||
ShellExecute(nullptr, nullptr, utf16_t(name), utf16_t(arguments), nullptr, SW_SHOWNORMAL);
|
ShellExecute(nullptr, nullptr, utf16_t(name), utf16_t(arguments), nullptr, SW_SHOWNORMAL);
|
||||||
|
|
|
@ -63,10 +63,10 @@ struct serializer {
|
||||||
template<typename T> auto integer(T& value) -> serializer& {
|
template<typename T> auto integer(T& value) -> serializer& {
|
||||||
enum { size = std::is_same<bool, T>::value ? 1 : sizeof(T) };
|
enum { size = std::is_same<bool, T>::value ? 1 : sizeof(T) };
|
||||||
if(_mode == Save) {
|
if(_mode == Save) {
|
||||||
for(uint n = 0; n < size; n++) _data[_size++] = (uintmax)value >> (n << 3);
|
for(uint n = 0; n < size; n++) _data[_size++] = (uintmax_t)value >> (n << 3);
|
||||||
} else if(_mode == Load) {
|
} else if(_mode == Load) {
|
||||||
value = 0;
|
value = 0;
|
||||||
for(uint n = 0; n < size; n++) value |= (uintmax)_data[_size++] << (n << 3);
|
for(uint n = 0; n < size; n++) value |= (uintmax_t)_data[_size++] << (n << 3);
|
||||||
} else if(_mode == Size) {
|
} else if(_mode == Size) {
|
||||||
_size += size;
|
_size += size;
|
||||||
}
|
}
|
||||||
|
|
11
stdint.hpp
11
stdint.hpp
|
@ -33,7 +33,8 @@
|
||||||
|
|
||||||
using float32_t = float;
|
using float32_t = float;
|
||||||
using float64_t = double;
|
using float64_t = double;
|
||||||
using float80_t = long double;
|
//note: long double size is not reliable across platforms
|
||||||
|
//using float80_t = long double;
|
||||||
|
|
||||||
static_assert(sizeof(int8_t) == 1, "int8_t is not of the correct size" );
|
static_assert(sizeof(int8_t) == 1, "int8_t is not of the correct size" );
|
||||||
static_assert(sizeof(int16_t) == 2, "int16_t is not of the correct size");
|
static_assert(sizeof(int16_t) == 2, "int16_t is not of the correct size");
|
||||||
|
@ -47,12 +48,6 @@ static_assert(sizeof(uint64_t) == 8, "int64_t is not of the correct size");
|
||||||
|
|
||||||
static_assert(sizeof(float) >= 4, "float32_t is not of the correct size");
|
static_assert(sizeof(float) >= 4, "float32_t is not of the correct size");
|
||||||
static_assert(sizeof(double) >= 8, "float64_t is not of the correct size");
|
static_assert(sizeof(double) >= 8, "float64_t is not of the correct size");
|
||||||
static_assert(sizeof(long double) >= 10, "float80_t is not of the correct size");
|
//static_assert(sizeof(long double) >= 10, "float80_t is not of the correct size");
|
||||||
|
|
||||||
using intmax = intmax_t;
|
|
||||||
using intptr = intptr_t;
|
|
||||||
|
|
||||||
using uintmax = uintmax_t;
|
|
||||||
using uintptr = uintptr_t;
|
|
||||||
|
|
||||||
using uint = unsigned int;
|
using uint = unsigned int;
|
||||||
|
|
85
string.hpp
85
string.hpp
|
@ -24,8 +24,9 @@
|
||||||
namespace nall {
|
namespace nall {
|
||||||
|
|
||||||
struct string;
|
struct string;
|
||||||
struct format;
|
struct string_view;
|
||||||
struct lstring;
|
struct string_vector;
|
||||||
|
struct string_format;
|
||||||
|
|
||||||
struct string_view {
|
struct string_view {
|
||||||
inline string_view();
|
inline string_view();
|
||||||
|
@ -61,34 +62,22 @@ template<typename T> struct stringify;
|
||||||
//format.hpp
|
//format.hpp
|
||||||
template<typename... P> inline auto print(P&&...) -> void;
|
template<typename... P> inline auto print(P&&...) -> void;
|
||||||
template<typename... P> inline auto print(FILE*, P&&...) -> void;
|
template<typename... P> inline auto print(FILE*, P&&...) -> void;
|
||||||
inline auto integer(intmax value, long precision = 0, char padchar = '0') -> string;
|
template<typename T> inline auto numeral(T value, long precision = 0, char padchar = '0') -> string;
|
||||||
inline auto natural(uintmax value, long precision = 0, char padchar = '0') -> string;
|
inline auto hex(uintmax_t value, long precision = 0, char padchar = '0') -> string;
|
||||||
inline auto hex(uintmax value, long precision = 0, char padchar = '0') -> string;
|
inline auto octal(uintmax_t value, long precision = 0, char padchar = '0') -> string;
|
||||||
inline auto octal(uintmax value, long precision = 0, char padchar = '0') -> string;
|
inline auto binary(uintmax_t value, long precision = 0, char padchar = '0') -> string;
|
||||||
inline auto binary(uintmax value, long precision = 0, char padchar = '0') -> string;
|
|
||||||
template<typename T> inline auto pointer(const T* value, long precision = 0) -> string;
|
template<typename T> inline auto pointer(const T* value, long precision = 0) -> string;
|
||||||
inline auto pointer(uintptr value, long precision = 0) -> string;
|
inline auto pointer(uintptr_t value, long precision = 0) -> string;
|
||||||
inline auto real(long double value) -> string;
|
|
||||||
|
|
||||||
//match.hpp
|
//match.hpp
|
||||||
inline auto tokenize(const char* s, const char* p) -> bool;
|
inline auto tokenize(const char* s, const char* p) -> bool;
|
||||||
inline auto tokenize(lstring& list, const char* s, const char* p) -> bool;
|
inline auto tokenize(string_vector& list, const char* s, const char* p) -> bool;
|
||||||
|
|
||||||
//path.hpp
|
|
||||||
inline auto pathname(string_view self) -> string;
|
|
||||||
inline auto filename(string_view self) -> string;
|
|
||||||
|
|
||||||
inline auto dirname(string_view self) -> string;
|
|
||||||
inline auto basename(string_view self) -> string;
|
|
||||||
inline auto prefixname(string_view self) -> string;
|
|
||||||
inline auto suffixname(string_view self) -> string;
|
|
||||||
|
|
||||||
//utility.hpp
|
//utility.hpp
|
||||||
inline auto slice(string_view self, int offset = 0, int length = -1) -> string;
|
inline auto slice(string_view self, int offset = 0, int length = -1) -> string;
|
||||||
|
inline auto fromInteger(char* result, intmax_t value) -> char*;
|
||||||
inline auto integer(char* result, intmax value) -> char*;
|
inline auto fromNatural(char* result, uintmax_t value) -> char*;
|
||||||
inline auto natural(char* result, uintmax value) -> char*;
|
inline auto fromReal(char* str, long double value) -> uint;
|
||||||
inline auto real(char* str, long double value) -> uint;
|
|
||||||
|
|
||||||
struct string {
|
struct string {
|
||||||
using type = string;
|
using type = string;
|
||||||
|
@ -179,15 +168,16 @@ public:
|
||||||
auto end() const -> const char* { return &data()[size()]; }
|
auto end() const -> const char* { return &data()[size()]; }
|
||||||
|
|
||||||
//atoi.hpp
|
//atoi.hpp
|
||||||
inline auto integer() const -> intmax;
|
inline auto integer() const -> intmax_t;
|
||||||
inline auto natural() const -> uintmax;
|
inline auto natural() const -> uintmax_t;
|
||||||
|
inline auto hex() const -> uintmax_t;
|
||||||
inline auto real() const -> double;
|
inline auto real() const -> double;
|
||||||
|
|
||||||
//core.hpp
|
//core.hpp
|
||||||
inline auto operator[](int) const -> const char&;
|
inline auto operator[](int) const -> const char&;
|
||||||
template<typename... P> inline auto assign(P&&...) -> type&;
|
template<typename... P> inline auto assign(P&&...) -> type&;
|
||||||
template<typename T, typename... P> inline auto append(const T&, P&&...) -> type&;
|
template<typename T, typename... P> inline auto append(const T&, P&&...) -> type&;
|
||||||
template<typename... P> inline auto append(const nall::format&, P&&...) -> type&;
|
template<typename... P> inline auto append(const nall::string_format&, P&&...) -> type&;
|
||||||
inline auto append() -> type&;
|
inline auto append() -> type&;
|
||||||
template<typename T> inline auto _append(const stringify<T>&) -> string&;
|
template<typename T> inline auto _append(const stringify<T>&) -> string&;
|
||||||
inline auto length() const -> uint;
|
inline auto length() const -> uint;
|
||||||
|
@ -209,7 +199,7 @@ public:
|
||||||
inline auto ifindFrom(int offset, string_view source) const -> maybe<uint>;
|
inline auto ifindFrom(int offset, string_view source) const -> maybe<uint>;
|
||||||
|
|
||||||
//format.hpp
|
//format.hpp
|
||||||
inline auto format(const nall::format& params) -> type&;
|
inline auto format(const nall::string_format& params) -> type&;
|
||||||
|
|
||||||
//compare.hpp
|
//compare.hpp
|
||||||
template<bool> inline static auto _compare(const char*, uint, const char*, uint) -> int;
|
template<bool> inline static auto _compare(const char*, uint, const char*, uint) -> int;
|
||||||
|
@ -250,10 +240,10 @@ public:
|
||||||
inline auto iqreplace(string_view from, string_view to, long limit = LONG_MAX) -> type&;
|
inline auto iqreplace(string_view from, string_view to, long limit = LONG_MAX) -> type&;
|
||||||
|
|
||||||
//split.hpp
|
//split.hpp
|
||||||
inline auto split(string_view key, long limit = LONG_MAX) const -> lstring;
|
inline auto split(string_view key, long limit = LONG_MAX) const -> string_vector;
|
||||||
inline auto isplit(string_view key, long limit = LONG_MAX) const -> lstring;
|
inline auto isplit(string_view key, long limit = LONG_MAX) const -> string_vector;
|
||||||
inline auto qsplit(string_view key, long limit = LONG_MAX) const -> lstring;
|
inline auto qsplit(string_view key, long limit = LONG_MAX) const -> string_vector;
|
||||||
inline auto iqsplit(string_view key, long limit = LONG_MAX) const -> lstring;
|
inline auto iqsplit(string_view key, long limit = LONG_MAX) const -> string_vector;
|
||||||
|
|
||||||
//trim.hpp
|
//trim.hpp
|
||||||
inline auto trim(string_view lhs, string_view rhs, long limit = LONG_MAX) -> type&;
|
inline auto trim(string_view lhs, string_view rhs, long limit = LONG_MAX) -> type&;
|
||||||
|
@ -278,21 +268,21 @@ public:
|
||||||
inline auto size(int length, char fill = ' ') -> type&;
|
inline auto size(int length, char fill = ' ') -> type&;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct lstring : vector<string> {
|
struct string_vector : vector<string> {
|
||||||
using type = lstring;
|
using type = string_vector;
|
||||||
|
|
||||||
lstring(const lstring& source) { vector::operator=(source); }
|
string_vector(const string_vector& source) { vector::operator=(source); }
|
||||||
lstring(lstring& source) { vector::operator=(source); }
|
string_vector(string_vector& source) { vector::operator=(source); }
|
||||||
lstring(lstring&& source) { vector::operator=(move(source)); }
|
string_vector(string_vector&& source) { vector::operator=(move(source)); }
|
||||||
template<typename... P> lstring(P&&... p) { append(forward<P>(p)...); }
|
template<typename... P> string_vector(P&&... p) { append(forward<P>(p)...); }
|
||||||
|
|
||||||
//list.hpp
|
//list.hpp
|
||||||
inline auto operator==(const lstring&) const -> bool;
|
inline auto operator==(const string_vector&) const -> bool;
|
||||||
inline auto operator!=(const lstring&) const -> bool;
|
inline auto operator!=(const string_vector&) const -> bool;
|
||||||
|
|
||||||
inline auto operator=(const lstring& source) -> type& { return vector::operator=(source), *this; }
|
inline auto operator=(const string_vector& source) -> type& { return vector::operator=(source), *this; }
|
||||||
inline auto operator=(lstring& source) -> type& { return vector::operator=(source), *this; }
|
inline auto operator=(string_vector& source) -> type& { return vector::operator=(source), *this; }
|
||||||
inline auto operator=(lstring&& source) -> type& { return vector::operator=(move(source)), *this; }
|
inline auto operator=(string_vector&& source) -> type& { return vector::operator=(move(source)), *this; }
|
||||||
|
|
||||||
inline auto isort() -> type&;
|
inline auto isort() -> type&;
|
||||||
|
|
||||||
|
@ -301,18 +291,18 @@ struct lstring : vector<string> {
|
||||||
|
|
||||||
inline auto find(string_view source) const -> maybe<uint>;
|
inline auto find(string_view source) const -> maybe<uint>;
|
||||||
inline auto ifind(string_view source) const -> maybe<uint>;
|
inline auto ifind(string_view source) const -> maybe<uint>;
|
||||||
inline auto match(string_view pattern) const -> lstring;
|
inline auto match(string_view pattern) const -> string_vector;
|
||||||
inline auto merge(string_view separator) const -> string;
|
inline auto merge(string_view separator) const -> string;
|
||||||
inline auto strip() -> type&;
|
inline auto strip() -> type&;
|
||||||
|
|
||||||
//split.hpp
|
//split.hpp
|
||||||
template<bool, bool> inline auto _split(string_view, string_view, long) -> lstring&;
|
template<bool, bool> inline auto _split(string_view, string_view, long) -> type&;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct format : vector<string> {
|
struct string_format : vector<string> {
|
||||||
using type = format;
|
using type = string_format;
|
||||||
|
|
||||||
template<typename... P> format(P&&... p) { reserve(sizeof...(p)); append(forward<P>(p)...); }
|
template<typename... P> string_format(P&&... p) { reserve(sizeof...(p)); append(forward<P>(p)...); }
|
||||||
template<typename T, typename... P> inline auto append(const T&, P&&... p) -> type&;
|
template<typename T, typename... P> inline auto append(const T&, P&&... p) -> type&;
|
||||||
inline auto append() -> type&;
|
inline auto append() -> type&;
|
||||||
};
|
};
|
||||||
|
@ -330,7 +320,6 @@ struct format : vector<string> {
|
||||||
#include <nall/string/format.hpp>
|
#include <nall/string/format.hpp>
|
||||||
#include <nall/string/list.hpp>
|
#include <nall/string/list.hpp>
|
||||||
#include <nall/string/match.hpp>
|
#include <nall/string/match.hpp>
|
||||||
#include <nall/string/path.hpp>
|
|
||||||
#include <nall/string/replace.hpp>
|
#include <nall/string/replace.hpp>
|
||||||
#include <nall/string/split.hpp>
|
#include <nall/string/split.hpp>
|
||||||
#include <nall/string/trim.hpp>
|
#include <nall/string/trim.hpp>
|
||||||
|
|
|
@ -2,16 +2,20 @@
|
||||||
|
|
||||||
namespace nall {
|
namespace nall {
|
||||||
|
|
||||||
auto string::integer() const -> intmax {
|
auto string::integer() const -> intmax_t {
|
||||||
return nall::integer(data());
|
return toInteger(data());
|
||||||
}
|
}
|
||||||
|
|
||||||
auto string::natural() const -> uintmax {
|
auto string::natural() const -> uintmax_t {
|
||||||
return nall::natural(data());
|
return toNatural(data());
|
||||||
|
}
|
||||||
|
|
||||||
|
auto string::hex() const -> uintmax_t {
|
||||||
|
return toHex(data());
|
||||||
}
|
}
|
||||||
|
|
||||||
auto string::real() const -> double {
|
auto string::real() const -> double {
|
||||||
return nall::real(data());
|
return toReal(data());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,42 +33,42 @@ template<> struct stringify<char> {
|
||||||
//signed integers
|
//signed integers
|
||||||
|
|
||||||
template<> struct stringify<signed char> {
|
template<> struct stringify<signed char> {
|
||||||
stringify(signed char source) { integer(_data, source); }
|
stringify(signed char source) { fromInteger(_data, source); }
|
||||||
auto data() const -> const char* { return _data; }
|
auto data() const -> const char* { return _data; }
|
||||||
auto size() const -> uint { return strlen(_data); }
|
auto size() const -> uint { return strlen(_data); }
|
||||||
char _data[2 + sizeof(signed char) * 3];
|
char _data[2 + sizeof(signed char) * 3];
|
||||||
};
|
};
|
||||||
|
|
||||||
template<> struct stringify<signed short> {
|
template<> struct stringify<signed short> {
|
||||||
stringify(signed short source) { integer(_data, source); }
|
stringify(signed short source) { fromInteger(_data, source); }
|
||||||
auto data() const -> const char* { return _data; }
|
auto data() const -> const char* { return _data; }
|
||||||
auto size() const -> uint { return strlen(_data); }
|
auto size() const -> uint { return strlen(_data); }
|
||||||
char _data[2 + sizeof(signed short) * 3];
|
char _data[2 + sizeof(signed short) * 3];
|
||||||
};
|
};
|
||||||
|
|
||||||
template<> struct stringify<signed int> {
|
template<> struct stringify<signed int> {
|
||||||
stringify(signed int source) { integer(_data, source); }
|
stringify(signed int source) { fromInteger(_data, source); }
|
||||||
auto data() const -> const char* { return _data; }
|
auto data() const -> const char* { return _data; }
|
||||||
auto size() const -> uint { return strlen(_data); }
|
auto size() const -> uint { return strlen(_data); }
|
||||||
char _data[2 + sizeof(signed int) * 3];
|
char _data[2 + sizeof(signed int) * 3];
|
||||||
};
|
};
|
||||||
|
|
||||||
template<> struct stringify<signed long> {
|
template<> struct stringify<signed long> {
|
||||||
stringify(signed long source) { integer(_data, source); }
|
stringify(signed long source) { fromInteger(_data, source); }
|
||||||
auto data() const -> const char* { return _data; }
|
auto data() const -> const char* { return _data; }
|
||||||
auto size() const -> uint { return strlen(_data); }
|
auto size() const -> uint { return strlen(_data); }
|
||||||
char _data[2 + sizeof(signed long) * 3];
|
char _data[2 + sizeof(signed long) * 3];
|
||||||
};
|
};
|
||||||
|
|
||||||
template<> struct stringify<signed long long> {
|
template<> struct stringify<signed long long> {
|
||||||
stringify(signed long long source) { integer(_data, source); }
|
stringify(signed long long source) { fromInteger(_data, source); }
|
||||||
auto data() const -> const char* { return _data; }
|
auto data() const -> const char* { return _data; }
|
||||||
auto size() const -> uint { return strlen(_data); }
|
auto size() const -> uint { return strlen(_data); }
|
||||||
char _data[2 + sizeof(signed long long) * 3];
|
char _data[2 + sizeof(signed long long) * 3];
|
||||||
};
|
};
|
||||||
|
|
||||||
template<uint Bits> struct stringify<Integer<Bits>> {
|
template<uint Bits> struct stringify<Integer<Bits>> {
|
||||||
stringify(Integer<Bits> source) { integer(_data, source); }
|
stringify(Integer<Bits> source) { fromInteger(_data, source); }
|
||||||
auto data() const -> const char* { return _data; }
|
auto data() const -> const char* { return _data; }
|
||||||
auto size() const -> uint { return strlen(_data); }
|
auto size() const -> uint { return strlen(_data); }
|
||||||
char _data[2 + sizeof(int64_t) * 3];
|
char _data[2 + sizeof(int64_t) * 3];
|
||||||
|
@ -77,42 +77,42 @@ template<uint Bits> struct stringify<Integer<Bits>> {
|
||||||
//unsigned integers
|
//unsigned integers
|
||||||
|
|
||||||
template<> struct stringify<unsigned char> {
|
template<> struct stringify<unsigned char> {
|
||||||
stringify(unsigned char source) { natural(_data, source); }
|
stringify(unsigned char source) { fromNatural(_data, source); }
|
||||||
auto data() const -> const char* { return _data; }
|
auto data() const -> const char* { return _data; }
|
||||||
auto size() const -> uint { return strlen(_data); }
|
auto size() const -> uint { return strlen(_data); }
|
||||||
char _data[1 + sizeof(unsigned char) * 3];
|
char _data[1 + sizeof(unsigned char) * 3];
|
||||||
};
|
};
|
||||||
|
|
||||||
template<> struct stringify<unsigned short> {
|
template<> struct stringify<unsigned short> {
|
||||||
stringify(unsigned short source) { natural(_data, source); }
|
stringify(unsigned short source) { fromNatural(_data, source); }
|
||||||
auto data() const -> const char* { return _data; }
|
auto data() const -> const char* { return _data; }
|
||||||
auto size() const -> uint { return strlen(_data); }
|
auto size() const -> uint { return strlen(_data); }
|
||||||
char _data[1 + sizeof(unsigned short) * 3];
|
char _data[1 + sizeof(unsigned short) * 3];
|
||||||
};
|
};
|
||||||
|
|
||||||
template<> struct stringify<unsigned int> {
|
template<> struct stringify<unsigned int> {
|
||||||
stringify(unsigned int source) { natural(_data, source); }
|
stringify(unsigned int source) { fromNatural(_data, source); }
|
||||||
auto data() const -> const char* { return _data; }
|
auto data() const -> const char* { return _data; }
|
||||||
auto size() const -> uint { return strlen(_data); }
|
auto size() const -> uint { return strlen(_data); }
|
||||||
char _data[1 + sizeof(unsigned int) * 3];
|
char _data[1 + sizeof(unsigned int) * 3];
|
||||||
};
|
};
|
||||||
|
|
||||||
template<> struct stringify<unsigned long> {
|
template<> struct stringify<unsigned long> {
|
||||||
stringify(unsigned long source) { natural(_data, source); }
|
stringify(unsigned long source) { fromNatural(_data, source); }
|
||||||
auto data() const -> const char* { return _data; }
|
auto data() const -> const char* { return _data; }
|
||||||
auto size() const -> uint { return strlen(_data); }
|
auto size() const -> uint { return strlen(_data); }
|
||||||
char _data[1 + sizeof(unsigned long) * 3];
|
char _data[1 + sizeof(unsigned long) * 3];
|
||||||
};
|
};
|
||||||
|
|
||||||
template<> struct stringify<unsigned long long> {
|
template<> struct stringify<unsigned long long> {
|
||||||
stringify(unsigned long long source) { natural(_data, source); }
|
stringify(unsigned long long source) { fromNatural(_data, source); }
|
||||||
auto data() const -> const char* { return _data; }
|
auto data() const -> const char* { return _data; }
|
||||||
auto size() const -> uint { return strlen(_data); }
|
auto size() const -> uint { return strlen(_data); }
|
||||||
char _data[1 + sizeof(unsigned long long) * 3];
|
char _data[1 + sizeof(unsigned long long) * 3];
|
||||||
};
|
};
|
||||||
|
|
||||||
template<uint Bits> struct stringify<Natural<Bits>> {
|
template<uint Bits> struct stringify<Natural<Bits>> {
|
||||||
stringify(Natural<Bits> source) { natural(_data, source); }
|
stringify(Natural<Bits> source) { fromNatural(_data, source); }
|
||||||
auto data() const -> const char* { return _data; }
|
auto data() const -> const char* { return _data; }
|
||||||
auto size() const -> uint { return strlen(_data); }
|
auto size() const -> uint { return strlen(_data); }
|
||||||
char _data[1 + sizeof(uint64_t) * 3];
|
char _data[1 + sizeof(uint64_t) * 3];
|
||||||
|
@ -121,28 +121,28 @@ template<uint Bits> struct stringify<Natural<Bits>> {
|
||||||
//floating-point
|
//floating-point
|
||||||
|
|
||||||
template<> struct stringify<float> {
|
template<> struct stringify<float> {
|
||||||
stringify(float source) { real(_data, source); }
|
stringify(float source) { fromReal(_data, source); }
|
||||||
auto data() const -> const char* { return _data; }
|
auto data() const -> const char* { return _data; }
|
||||||
auto size() const -> uint { return strlen(_data); }
|
auto size() const -> uint { return strlen(_data); }
|
||||||
char _data[256];
|
char _data[256];
|
||||||
};
|
};
|
||||||
|
|
||||||
template<> struct stringify<double> {
|
template<> struct stringify<double> {
|
||||||
stringify(double source) { real(_data, source); }
|
stringify(double source) { fromReal(_data, source); }
|
||||||
auto data() const -> const char* { return _data; }
|
auto data() const -> const char* { return _data; }
|
||||||
auto size() const -> uint { return strlen(_data); }
|
auto size() const -> uint { return strlen(_data); }
|
||||||
char _data[256];
|
char _data[256];
|
||||||
};
|
};
|
||||||
|
|
||||||
template<> struct stringify<long double> {
|
template<> struct stringify<long double> {
|
||||||
stringify(long double source) { real(_data, source); }
|
stringify(long double source) { fromReal(_data, source); }
|
||||||
auto data() const -> const char* { return _data; }
|
auto data() const -> const char* { return _data; }
|
||||||
auto size() const -> uint { return strlen(_data); }
|
auto size() const -> uint { return strlen(_data); }
|
||||||
char _data[256];
|
char _data[256];
|
||||||
};
|
};
|
||||||
|
|
||||||
template<uint Bits> struct stringify<Real<Bits>> {
|
template<uint Bits> struct stringify<Real<Bits>> {
|
||||||
stringify(Real<Bits> source) { real(_data, source); }
|
stringify(Real<Bits> source) { fromReal(_data, source); }
|
||||||
auto data() const -> const char* { return _data; }
|
auto data() const -> const char* { return _data; }
|
||||||
auto size() const -> uint { return strlen(_data); }
|
auto size() const -> uint { return strlen(_data); }
|
||||||
char _data[256];
|
char _data[256];
|
||||||
|
|
|
@ -30,7 +30,7 @@ template<typename T, typename... P> auto string::append(const T& value, P&&... p
|
||||||
return append(forward<P>(p)...);
|
return append(forward<P>(p)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename... P> auto string::append(const nall::format& value, P&&... p) -> string& {
|
template<typename... P> auto string::append(const nall::string_format& value, P&&... p) -> string& {
|
||||||
format(value);
|
format(value);
|
||||||
return append(forward<P>(p)...);
|
return append(forward<P>(p)...);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,9 +6,9 @@ auto string::date(time_t timestamp) -> string {
|
||||||
if(timestamp == 0) timestamp = ::time(nullptr);
|
if(timestamp == 0) timestamp = ::time(nullptr);
|
||||||
tm* info = localtime(×tamp);
|
tm* info = localtime(×tamp);
|
||||||
return {
|
return {
|
||||||
nall::natural(1900 + info->tm_year, 4L), "-",
|
numeral(1900 + info->tm_year, 4L), "-",
|
||||||
nall::natural(1 + info->tm_mon, 2L), "-",
|
numeral(1 + info->tm_mon, 2L), "-",
|
||||||
nall::natural(info->tm_mday, 2L)
|
numeral(info->tm_mday, 2L)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,9 +16,9 @@ auto string::time(time_t timestamp) -> string {
|
||||||
if(timestamp == 0) timestamp = ::time(nullptr);
|
if(timestamp == 0) timestamp = ::time(nullptr);
|
||||||
tm* info = localtime(×tamp);
|
tm* info = localtime(×tamp);
|
||||||
return {
|
return {
|
||||||
nall::natural(info->tm_hour, 2L), ":",
|
numeral(info->tm_hour, 2L), ":",
|
||||||
nall::natural(info->tm_min, 2L), ":",
|
numeral(info->tm_min, 2L), ":",
|
||||||
nall::natural(info->tm_sec, 2L)
|
numeral(info->tm_sec, 2L)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ inline auto evaluateExpression(Node* node) -> string {
|
||||||
}
|
}
|
||||||
|
|
||||||
inline auto evaluateInteger(Node* node) -> int64_t {
|
inline auto evaluateInteger(Node* node) -> int64_t {
|
||||||
if(node->type == Node::Type::Literal) return nall::integer(node->literal);
|
if(node->type == Node::Type::Literal) return toInteger(node->literal);
|
||||||
|
|
||||||
#define p(n) evaluateInteger(node->link[n])
|
#define p(n) evaluateInteger(node->link[n])
|
||||||
switch(node->type) {
|
switch(node->type) {
|
||||||
|
@ -99,7 +99,7 @@ inline auto integer(const string& expression) -> maybe<int64_t> {
|
||||||
}
|
}
|
||||||
|
|
||||||
inline auto evaluateReal(Node* node) -> long double {
|
inline auto evaluateReal(Node* node) -> long double {
|
||||||
if(node->type == Node::Type::Literal) return nall::real(node->literal);
|
if(node->type == Node::Type::Literal) return toReal(node->literal);
|
||||||
|
|
||||||
#define p(n) evaluateReal(node->link[n])
|
#define p(n) evaluateReal(node->link[n])
|
||||||
switch(node->type) {
|
switch(node->type) {
|
||||||
|
|
|
@ -5,7 +5,7 @@ namespace nall {
|
||||||
//nall::format is a vector<string> of parameters that can be applied to a string
|
//nall::format is a vector<string> of parameters that can be applied to a string
|
||||||
//each {#} token will be replaced with its appropriate format parameter
|
//each {#} token will be replaced with its appropriate format parameter
|
||||||
|
|
||||||
auto string::format(const nall::format& params) -> type& {
|
auto string::format(const nall::string_format& params) -> type& {
|
||||||
auto size = (int)this->size();
|
auto size = (int)this->size();
|
||||||
auto data = (char*)memory::allocate(size);
|
auto data = (char*)memory::allocate(size);
|
||||||
memory::copy(data, this->data(), size);
|
memory::copy(data, this->data(), size);
|
||||||
|
@ -32,7 +32,7 @@ auto string::format(const nall::format& params) -> type& {
|
||||||
};
|
};
|
||||||
if(!isNumeric(&data[x + 1], &data[y - 1])) { x++; continue; }
|
if(!isNumeric(&data[x + 1], &data[y - 1])) { x++; continue; }
|
||||||
|
|
||||||
uint index = nall::natural(&data[x + 1]);
|
uint index = toNatural(&data[x + 1]);
|
||||||
if(index >= params.size()) { x++; continue; }
|
if(index >= params.size()) { x++; continue; }
|
||||||
|
|
||||||
uint sourceSize = y - x;
|
uint sourceSize = y - x;
|
||||||
|
@ -59,12 +59,12 @@ auto string::format(const nall::format& params) -> type& {
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, typename... P> auto format::append(const T& value, P&&... p) -> format& {
|
template<typename T, typename... P> auto string_format::append(const T& value, P&&... p) -> string_format& {
|
||||||
vector<string>::append(value);
|
vector<string>::append(value);
|
||||||
return append(forward<P>(p)...);
|
return append(forward<P>(p)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto format::append() -> format& {
|
auto string_format::append() -> string_format& {
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,9 +78,10 @@ template<typename... P> auto print(FILE* fp, P&&... p) -> void {
|
||||||
fwrite(s.data(), 1, s.size(), fp);
|
fwrite(s.data(), 1, s.size(), fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto integer(intmax value, long precision, char padchar) -> string {
|
/*
|
||||||
|
auto integer(intmax_t value, long precision, char padchar) -> string {
|
||||||
string buffer;
|
string buffer;
|
||||||
buffer.resize(1 + sizeof(intmax) * 3);
|
buffer.resize(1 + sizeof(intmax_t) * 3);
|
||||||
char* p = buffer.get();
|
char* p = buffer.get();
|
||||||
|
|
||||||
bool negative = value < 0;
|
bool negative = value < 0;
|
||||||
|
@ -97,9 +98,9 @@ auto integer(intmax value, long precision, char padchar) -> string {
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto natural(uintmax value, long precision, char padchar) -> string {
|
auto natural(uintmax_t value, long precision, char padchar) -> string {
|
||||||
string buffer;
|
string buffer;
|
||||||
buffer.resize(sizeof(uintmax) * 3);
|
buffer.resize(sizeof(uintmax_t) * 3);
|
||||||
char* p = buffer.get();
|
char* p = buffer.get();
|
||||||
|
|
||||||
uint size = 0;
|
uint size = 0;
|
||||||
|
@ -112,10 +113,17 @@ auto natural(uintmax value, long precision, char padchar) -> string {
|
||||||
if(precision) buffer.size(precision, padchar);
|
if(precision) buffer.size(precision, padchar);
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
auto hex(uintmax value, long precision, char padchar) -> string {
|
template<typename T> auto numeral(T value, long precision, char padchar) -> string {
|
||||||
|
string buffer{value};
|
||||||
|
if(precision) buffer.size(precision, padchar);
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto hex(uintmax_t value, long precision, char padchar) -> string {
|
||||||
string buffer;
|
string buffer;
|
||||||
buffer.resize(sizeof(uintmax) * 2);
|
buffer.resize(sizeof(uintmax_t) * 2);
|
||||||
char* p = buffer.get();
|
char* p = buffer.get();
|
||||||
|
|
||||||
uint size = 0;
|
uint size = 0;
|
||||||
|
@ -130,9 +138,9 @@ auto hex(uintmax value, long precision, char padchar) -> string {
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto octal(uintmax value, long precision, char padchar) -> string {
|
auto octal(uintmax_t value, long precision, char padchar) -> string {
|
||||||
string buffer;
|
string buffer;
|
||||||
buffer.resize(sizeof(uintmax) * 3);
|
buffer.resize(sizeof(uintmax_t) * 3);
|
||||||
char* p = buffer.get();
|
char* p = buffer.get();
|
||||||
|
|
||||||
uint size = 0;
|
uint size = 0;
|
||||||
|
@ -146,9 +154,9 @@ auto octal(uintmax value, long precision, char padchar) -> string {
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto binary(uintmax value, long precision, char padchar) -> string {
|
auto binary(uintmax_t value, long precision, char padchar) -> string {
|
||||||
string buffer;
|
string buffer;
|
||||||
buffer.resize(sizeof(uintmax) * 8);
|
buffer.resize(sizeof(uintmax_t) * 8);
|
||||||
char* p = buffer.get();
|
char* p = buffer.get();
|
||||||
|
|
||||||
uint size = 0;
|
uint size = 0;
|
||||||
|
@ -164,19 +172,21 @@ auto binary(uintmax value, long precision, char padchar) -> string {
|
||||||
|
|
||||||
template<typename T> auto pointer(const T* value, long precision) -> string {
|
template<typename T> auto pointer(const T* value, long precision) -> string {
|
||||||
if(value == nullptr) return "(nullptr)";
|
if(value == nullptr) return "(nullptr)";
|
||||||
return {"0x", hex((uintptr)value, precision)};
|
return {"0x", hex((uintptr_t)value, precision)};
|
||||||
}
|
}
|
||||||
|
|
||||||
auto pointer(uintptr value, long precision) -> string {
|
auto pointer(uintptr_t value, long precision) -> string {
|
||||||
if(value == 0) return "(nullptr)";
|
if(value == 0) return "(nullptr)";
|
||||||
return {"0x", hex(value, precision)};
|
return {"0x", hex(value, precision)};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
auto real(long double value) -> string {
|
auto real(long double value) -> string {
|
||||||
string temp;
|
string temp;
|
||||||
temp.resize(real(nullptr, value));
|
temp.resize(fromReal(nullptr, value));
|
||||||
real(temp.get(), value);
|
fromReal(temp.get(), value);
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace nall {
|
namespace nall {
|
||||||
|
|
||||||
auto lstring::operator==(const lstring& source) const -> bool {
|
auto string_vector::operator==(const string_vector& source) const -> bool {
|
||||||
if(this == &source) return true;
|
if(this == &source) return true;
|
||||||
if(size() != source.size()) return false;
|
if(size() != source.size()) return false;
|
||||||
for(uint n = 0; n < size(); n++) {
|
for(uint n = 0; n < size(); n++) {
|
||||||
|
@ -11,50 +11,50 @@ auto lstring::operator==(const lstring& source) const -> bool {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto lstring::operator!=(const lstring& source) const -> bool {
|
auto string_vector::operator!=(const string_vector& source) const -> bool {
|
||||||
return !operator==(source);
|
return !operator==(source);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto lstring::isort() -> lstring& {
|
auto string_vector::isort() -> type& {
|
||||||
sort([](const string& x, const string& y) {
|
sort([](const string& x, const string& y) {
|
||||||
return memory::icompare(x.data(), x.size(), y.data(), y.size()) < 0;
|
return memory::icompare(x.data(), x.size(), y.data(), y.size()) < 0;
|
||||||
});
|
});
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename... P> auto lstring::append(const string& data, P&&... p) -> lstring& {
|
template<typename... P> auto string_vector::append(const string& data, P&&... p) -> type& {
|
||||||
vector::append(data);
|
vector::append(data);
|
||||||
append(forward<P>(p)...);
|
append(forward<P>(p)...);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto lstring::append() -> lstring& {
|
auto string_vector::append() -> type& {
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto lstring::find(string_view source) const -> maybe<uint> {
|
auto string_vector::find(string_view source) const -> maybe<uint> {
|
||||||
for(uint n = 0; n < size(); n++) {
|
for(uint n = 0; n < size(); n++) {
|
||||||
if(operator[](n).equals(source)) return n;
|
if(operator[](n).equals(source)) return n;
|
||||||
}
|
}
|
||||||
return nothing;
|
return nothing;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto lstring::ifind(string_view source) const -> maybe<uint> {
|
auto string_vector::ifind(string_view source) const -> maybe<uint> {
|
||||||
for(uint n = 0; n < size(); n++) {
|
for(uint n = 0; n < size(); n++) {
|
||||||
if(operator[](n).iequals(source)) return n;
|
if(operator[](n).iequals(source)) return n;
|
||||||
}
|
}
|
||||||
return nothing;
|
return nothing;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto lstring::match(string_view pattern) const -> lstring {
|
auto string_vector::match(string_view pattern) const -> type {
|
||||||
lstring result;
|
string_vector result;
|
||||||
for(uint n = 0; n < size(); n++) {
|
for(uint n = 0; n < size(); n++) {
|
||||||
if(operator[](n).match(pattern)) result.append(operator[](n));
|
if(operator[](n).match(pattern)) result.append(operator[](n));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto lstring::merge(string_view separator) const -> string {
|
auto string_vector::merge(string_view separator) const -> string {
|
||||||
string output;
|
string output;
|
||||||
for(uint n = 0; n < size(); n++) {
|
for(uint n = 0; n < size(); n++) {
|
||||||
output.append(operator[](n));
|
output.append(operator[](n));
|
||||||
|
@ -63,7 +63,7 @@ auto lstring::merge(string_view separator) const -> string {
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto lstring::strip() -> lstring& {
|
auto string_vector::strip() -> type& {
|
||||||
for(uint n = 0; n < size(); n++) {
|
for(uint n = 0; n < size(); n++) {
|
||||||
operator[](n).strip();
|
operator[](n).strip();
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,7 +80,7 @@ protected:
|
||||||
}
|
}
|
||||||
|
|
||||||
//read a node and all of its child nodes
|
//read a node and all of its child nodes
|
||||||
auto parseNode(const lstring& text, uint& y) -> void {
|
auto parseNode(const string_vector& text, uint& y) -> void {
|
||||||
const char* p = text[y++];
|
const char* p = text[y++];
|
||||||
_metadata = parseDepth(p);
|
_metadata = parseDepth(p);
|
||||||
parseName(p);
|
parseName(p);
|
||||||
|
@ -166,7 +166,7 @@ inline auto serialize(const Markup::Node& node, uint depth = 0) -> string {
|
||||||
padding.resize(depth * 2);
|
padding.resize(depth * 2);
|
||||||
for(auto& byte : padding) byte = ' ';
|
for(auto& byte : padding) byte = ' ';
|
||||||
|
|
||||||
lstring lines;
|
string_vector lines;
|
||||||
if(auto value = node.value()) lines = value.split("\n");
|
if(auto value = node.value()) lines = value.split("\n");
|
||||||
|
|
||||||
string result;
|
string result;
|
||||||
|
|
|
@ -20,7 +20,7 @@ auto ManagedNode::_evaluate(string query) const -> bool {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
lstring side;
|
string_vector side;
|
||||||
switch(comparator) {
|
switch(comparator) {
|
||||||
case Comparator::EQ: side = rule.split ("=", 1L); break;
|
case Comparator::EQ: side = rule.split ("=", 1L); break;
|
||||||
case Comparator::NE: side = rule.split("!=", 1L); break;
|
case Comparator::NE: side = rule.split("!=", 1L); break;
|
||||||
|
@ -55,7 +55,7 @@ auto ManagedNode::_evaluate(string query) const -> bool {
|
||||||
auto ManagedNode::_find(const string& query) const -> vector<Node> {
|
auto ManagedNode::_find(const string& query) const -> vector<Node> {
|
||||||
vector<Node> result;
|
vector<Node> result;
|
||||||
|
|
||||||
lstring path = query.split("/");
|
auto path = query.split("/");
|
||||||
string name = path.take(0), rule;
|
string name = path.take(0), rule;
|
||||||
uint lo = 0u, hi = ~0u;
|
uint lo = 0u, hi = ~0u;
|
||||||
|
|
||||||
|
|
|
@ -59,8 +59,8 @@ struct Node {
|
||||||
|
|
||||||
auto text() const -> string { return value().strip(); }
|
auto text() const -> string { return value().strip(); }
|
||||||
auto boolean() const -> bool { return text() == "true"; }
|
auto boolean() const -> bool { return text() == "true"; }
|
||||||
auto integer() const -> intmax { return text().integer(); }
|
auto integer() const -> intmax_t { return text().integer(); }
|
||||||
auto natural() const -> uintmax { return text().natural(); }
|
auto natural() const -> uintmax_t { return text().natural(); }
|
||||||
auto real() const -> double { return text().real(); }
|
auto real() const -> double { return text().real(); }
|
||||||
|
|
||||||
auto setName(const string& name = "") -> Node& { shared->_name = name; return *this; }
|
auto setName(const string& name = "") -> Node& { shared->_name = name; return *this; }
|
||||||
|
|
|
@ -68,7 +68,7 @@ auto tokenize(const char* s, const char* p) -> bool {
|
||||||
return !*p;
|
return !*p;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto tokenize(lstring& list, const char* s, const char* p) -> bool {
|
auto tokenize(string_vector& list, const char* s, const char* p) -> bool {
|
||||||
while(*s) {
|
while(*s) {
|
||||||
if(*p == '*') {
|
if(*p == '*') {
|
||||||
const char* b = s;
|
const char* b = s;
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
namespace nall {
|
namespace nall {
|
||||||
|
|
||||||
template<bool Insensitive, bool Quoted>
|
template<bool Insensitive, bool Quoted>
|
||||||
auto lstring::_split(string_view source, string_view find, long limit) -> lstring& {
|
auto string_vector::_split(string_view source, string_view find, long limit) -> string_vector& {
|
||||||
reset();
|
reset();
|
||||||
if(limit <= 0 || find.size() == 0) return *this;
|
if(limit <= 0 || find.size() == 0) return *this;
|
||||||
|
|
||||||
|
@ -33,9 +33,9 @@ auto lstring::_split(string_view source, string_view find, long limit) -> lstrin
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto string::split(string_view on, long limit) const -> lstring { return lstring()._split<0, 0>(*this, on, limit); }
|
auto string::split(string_view on, long limit) const -> string_vector { return string_vector()._split<0, 0>(*this, on, limit); }
|
||||||
auto string::isplit(string_view on, long limit) const -> lstring { return lstring()._split<1, 0>(*this, on, limit); }
|
auto string::isplit(string_view on, long limit) const -> string_vector { return string_vector()._split<1, 0>(*this, on, limit); }
|
||||||
auto string::qsplit(string_view on, long limit) const -> lstring { return lstring()._split<0, 1>(*this, on, limit); }
|
auto string::qsplit(string_view on, long limit) const -> string_vector { return string_vector()._split<0, 1>(*this, on, limit); }
|
||||||
auto string::iqsplit(string_view on, long limit) const -> lstring { return lstring()._split<1, 1>(*this, on, limit); }
|
auto string::iqsplit(string_view on, long limit) const -> string_vector { return string_vector()._split<1, 1>(*this, on, limit); }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
* revision 0.02
|
* revision 0.02
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <nall/location.hpp>
|
||||||
|
|
||||||
namespace nall { namespace {
|
namespace nall { namespace {
|
||||||
|
|
||||||
struct CML {
|
struct CML {
|
||||||
|
@ -33,7 +35,7 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
auto CML::parse(const string& filename) -> string {
|
auto CML::parse(const string& filename) -> string {
|
||||||
if(!settings.path) settings.path = pathname(filename);
|
if(!settings.path) settings.path = Location::path(filename);
|
||||||
string document = settings.reader ? settings.reader(filename) : string::read(filename);
|
string document = settings.reader ? settings.reader(filename) : string::read(filename);
|
||||||
parseDocument(document, settings.path, 0);
|
parseDocument(document, settings.path, 0);
|
||||||
return state.output;
|
return state.output;
|
||||||
|
@ -54,14 +56,14 @@ auto CML::parseDocument(const string& filedata, const string& pathname, uint dep
|
||||||
};
|
};
|
||||||
|
|
||||||
for(auto& block : filedata.split("\n\n")) {
|
for(auto& block : filedata.split("\n\n")) {
|
||||||
lstring lines = block.stripRight().split("\n");
|
auto lines = block.stripRight().split("\n");
|
||||||
string name = lines.takeLeft();
|
auto name = lines.takeLeft();
|
||||||
|
|
||||||
if(name.beginsWith("include ")) {
|
if(name.beginsWith("include ")) {
|
||||||
name.trimLeft("include ", 1L);
|
name.trimLeft("include ", 1L);
|
||||||
string filename{pathname, name};
|
string filename{pathname, name};
|
||||||
string document = settings.reader ? settings.reader(filename) : string::read(filename);
|
string document = settings.reader ? settings.reader(filename) : string::read(filename);
|
||||||
parseDocument(document, nall::pathname(filename), depth + 1);
|
parseDocument(document, Location::path(filename), depth + 1);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
* revision 0.03
|
* revision 0.03
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <nall/location.hpp>
|
||||||
|
|
||||||
namespace nall { namespace {
|
namespace nall { namespace {
|
||||||
|
|
||||||
struct DML {
|
struct DML {
|
||||||
|
@ -45,7 +47,7 @@ auto DML::parse(const string& filedata, const string& pathname) -> string {
|
||||||
}
|
}
|
||||||
|
|
||||||
auto DML::parse(const string& filename) -> string {
|
auto DML::parse(const string& filename) -> string {
|
||||||
if(!settings.path) settings.path = pathname(filename);
|
if(!settings.path) settings.path = Location::path(filename);
|
||||||
string document = settings.reader ? settings.reader(filename) : string::read(filename);
|
string document = settings.reader ? settings.reader(filename) : string::read(filename);
|
||||||
parseDocument(document, settings.path, 0);
|
parseDocument(document, settings.path, 0);
|
||||||
return state.output;
|
return state.output;
|
||||||
|
@ -68,7 +70,7 @@ auto DML::parseBlock(string& block, const string& pathname, uint depth) -> bool
|
||||||
if(block.beginsWith("<include ") && block.endsWith(">")) {
|
if(block.beginsWith("<include ") && block.endsWith(">")) {
|
||||||
string filename{pathname, block.trim("<include ", ">", 1L).strip()};
|
string filename{pathname, block.trim("<include ", ">", 1L).strip()};
|
||||||
string document = settings.reader ? settings.reader(filename) : string::read(filename);
|
string document = settings.reader ? settings.reader(filename) : string::read(filename);
|
||||||
parseDocument(document, nall::pathname(filename), depth + 1);
|
parseDocument(document, Location::path(filename), depth + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
//html
|
//html
|
||||||
|
|
|
@ -92,7 +92,7 @@ auto slice(string_view self, int offset, int length) -> string {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto integer(char* result, intmax value) -> char* {
|
auto fromInteger(char* result, intmax_t value) -> char* {
|
||||||
bool negative = value < 0;
|
bool negative = value < 0;
|
||||||
if(negative) value = -value;
|
if(negative) value = -value;
|
||||||
|
|
||||||
|
@ -111,7 +111,7 @@ auto integer(char* result, intmax value) -> char* {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto natural(char* result, uintmax value) -> char* {
|
auto fromNatural(char* result, uintmax_t value) -> char* {
|
||||||
char buffer[64];
|
char buffer[64];
|
||||||
uint size = 0;
|
uint size = 0;
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ auto natural(char* result, uintmax value) -> char* {
|
||||||
//using sprintf is certainly not the most ideal method to convert
|
//using sprintf is certainly not the most ideal method to convert
|
||||||
//a double to a string ... but attempting to parse a double by
|
//a double to a string ... but attempting to parse a double by
|
||||||
//hand, digit-by-digit, results in subtle rounding errors.
|
//hand, digit-by-digit, results in subtle rounding errors.
|
||||||
auto real(char* result, long double value) -> uint {
|
auto fromReal(char* result, long double value) -> uint {
|
||||||
char buffer[256];
|
char buffer[256];
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
//Windows C-runtime does not support long double via sprintf()
|
//Windows C-runtime does not support long double via sprintf()
|
||||||
|
|
16
thread.hpp
16
thread.hpp
|
@ -19,13 +19,13 @@ namespace nall {
|
||||||
struct thread {
|
struct thread {
|
||||||
inline auto join() -> void;
|
inline auto join() -> void;
|
||||||
|
|
||||||
static inline auto create(const function<void (uintptr)>& callback, uintptr parameter = 0, uint stacksize = 0) -> thread;
|
static inline auto create(const function<void (uintptr_t)>& callback, uintptr_t parameter = 0, uint stacksize = 0) -> thread;
|
||||||
static inline auto detach() -> void;
|
static inline auto detach() -> void;
|
||||||
static inline auto exit() -> void;
|
static inline auto exit() -> void;
|
||||||
|
|
||||||
struct context {
|
struct context {
|
||||||
function<auto (uintptr) -> void> callback;
|
function<auto (uintptr_t) -> void> callback;
|
||||||
uintptr parameter = 0;
|
uintptr_t parameter = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -43,7 +43,7 @@ auto thread::join() -> void {
|
||||||
pthread_join(handle, nullptr);
|
pthread_join(handle, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto thread::create(const function<void (uintptr)>& callback, uintptr parameter, uint stacksize) -> thread {
|
auto thread::create(const function<void (uintptr_t)>& callback, uintptr_t parameter, uint stacksize) -> thread {
|
||||||
thread instance;
|
thread instance;
|
||||||
|
|
||||||
auto context = new thread::context;
|
auto context = new thread::context;
|
||||||
|
@ -76,13 +76,13 @@ struct thread {
|
||||||
inline ~thread();
|
inline ~thread();
|
||||||
inline auto join() -> void;
|
inline auto join() -> void;
|
||||||
|
|
||||||
static inline auto create(const function<void (uintptr)>& callback, uintptr parameter = 0, uint stacksize = 0) -> thread;
|
static inline auto create(const function<void (uintptr_t)>& callback, uintptr_t parameter = 0, uint stacksize = 0) -> thread;
|
||||||
static inline auto detach() -> void;
|
static inline auto detach() -> void;
|
||||||
static inline auto exit() -> void;
|
static inline auto exit() -> void;
|
||||||
|
|
||||||
struct context {
|
struct context {
|
||||||
function<auto (uintptr) -> void> callback;
|
function<auto (uintptr_t) -> void> callback;
|
||||||
uintptr parameter = 0;
|
uintptr_t parameter = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -111,7 +111,7 @@ auto thread::join() -> void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto thread::create(const function<void (uintptr)>& callback, uintptr parameter, uint stacksize) -> thread {
|
auto thread::create(const function<void (uintptr_t)>& callback, uintptr_t parameter, uint stacksize) -> thread {
|
||||||
thread instance;
|
thread instance;
|
||||||
|
|
||||||
auto context = new thread::context;
|
auto context = new thread::context;
|
||||||
|
|
12
varint.hpp
12
varint.hpp
|
@ -10,8 +10,8 @@ struct varint {
|
||||||
virtual auto read() -> uint8_t = 0;
|
virtual auto read() -> uint8_t = 0;
|
||||||
virtual auto write(uint8_t) -> void = 0;
|
virtual auto write(uint8_t) -> void = 0;
|
||||||
|
|
||||||
auto readvu() -> uintmax {
|
auto readvu() -> uintmax_t {
|
||||||
uintmax data = 0, shift = 1;
|
uintmax_t data = 0, shift = 1;
|
||||||
while(true) {
|
while(true) {
|
||||||
uint8_t x = read();
|
uint8_t x = read();
|
||||||
data += (x & 0x7f) * shift;
|
data += (x & 0x7f) * shift;
|
||||||
|
@ -22,15 +22,15 @@ struct varint {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto readvs() -> intmax {
|
auto readvs() -> intmax_t {
|
||||||
uintmax data = readvu();
|
uintmax_t data = readvu();
|
||||||
bool negate = data & 1;
|
bool negate = data & 1;
|
||||||
data >>= 1;
|
data >>= 1;
|
||||||
if(negate) data = ~data;
|
if(negate) data = ~data;
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto writevu(uintmax data) -> void {
|
auto writevu(uintmax_t data) -> void {
|
||||||
while(true) {
|
while(true) {
|
||||||
uint8_t x = data & 0x7f;
|
uint8_t x = data & 0x7f;
|
||||||
data >>= 7;
|
data >>= 7;
|
||||||
|
@ -40,7 +40,7 @@ struct varint {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto writevs(intmax data) -> void {
|
auto writevs(intmax_t data) -> void {
|
||||||
bool negate = data < 0;
|
bool negate = data < 0;
|
||||||
if(negate) data = ~data;
|
if(negate) data = ~data;
|
||||||
data = (data << 1) | negate;
|
data = (data << 1) | negate;
|
||||||
|
|
|
@ -11,15 +11,15 @@ struct file : vfs::file {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto size() const -> uintmax override {
|
auto size() const -> uintmax_t override {
|
||||||
return _fp.size();
|
return _fp.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto offset() const -> uintmax override {
|
auto offset() const -> uintmax_t override {
|
||||||
return _fp.offset();
|
return _fp.offset();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto seek(intmax offset_, index index_) -> void override {
|
auto seek(intmax_t offset_, index index_) -> void override {
|
||||||
_fp.seek(offset_, (nall::file::index)index_);
|
_fp.seek(offset_, (nall::file::index)index_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,18 +5,18 @@ namespace nall { namespace vfs { namespace memory {
|
||||||
struct file : vfs::file {
|
struct file : vfs::file {
|
||||||
~file() { delete[] _data; }
|
~file() { delete[] _data; }
|
||||||
|
|
||||||
static auto open(const uint8_t* data, uintmax size) -> vfs::shared::file {
|
static auto open(const uint8_t* data, uintmax_t size) -> vfs::shared::file {
|
||||||
auto instance = shared_pointer<file>{new file};
|
auto instance = shared_pointer<file>{new file};
|
||||||
instance->_open(data, size);
|
instance->_open(data, size);
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto size() const -> uintmax override { return _size; }
|
auto size() const -> uintmax_t override { return _size; }
|
||||||
auto offset() const -> uintmax override { return _offset; }
|
auto offset() const -> uintmax_t override { return _offset; }
|
||||||
|
|
||||||
auto seek(intmax offset, index mode) -> void override {
|
auto seek(intmax_t offset, index mode) -> void override {
|
||||||
if(mode == index::absolute) _offset = (uintmax)offset;
|
if(mode == index::absolute) _offset = (uintmax_t)offset;
|
||||||
if(mode == index::relative) _offset += (intmax)offset;
|
if(mode == index::relative) _offset += (intmax_t)offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto read() -> uint8_t override {
|
auto read() -> uint8_t override {
|
||||||
|
@ -34,15 +34,15 @@ private:
|
||||||
file(const file&) = delete;
|
file(const file&) = delete;
|
||||||
auto operator=(const file&) -> file& = delete;
|
auto operator=(const file&) -> file& = delete;
|
||||||
|
|
||||||
auto _open(const uint8_t* data, uintmax size) -> void {
|
auto _open(const uint8_t* data, uintmax_t size) -> void {
|
||||||
_size = size;
|
_size = size;
|
||||||
_data = new uint8_t[size];
|
_data = new uint8_t[size];
|
||||||
nall::memory::copy(_data, data, size);
|
nall::memory::copy(_data, data, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t* _data = nullptr;
|
uint8_t* _data = nullptr;
|
||||||
uintmax _size = 0;
|
uintmax_t _size = 0;
|
||||||
uintmax _offset = 0;
|
uintmax_t _offset = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
}}}
|
}}}
|
||||||
|
|
24
vfs/vfs.hpp
24
vfs/vfs.hpp
|
@ -11,10 +11,10 @@ struct file {
|
||||||
|
|
||||||
virtual ~file() = default;
|
virtual ~file() = default;
|
||||||
|
|
||||||
virtual auto size() const -> uintmax = 0;
|
virtual auto size() const -> uintmax_t = 0;
|
||||||
virtual auto offset() const -> uintmax = 0;
|
virtual auto offset() const -> uintmax_t = 0;
|
||||||
|
|
||||||
virtual auto seek(intmax offset, index = index::absolute) -> void = 0;
|
virtual auto seek(intmax_t offset, index = index::absolute) -> void = 0;
|
||||||
virtual auto read() -> uint8_t = 0;
|
virtual auto read() -> uint8_t = 0;
|
||||||
virtual auto write(uint8_t data) -> void = 0;
|
virtual auto write(uint8_t data) -> void = 0;
|
||||||
virtual auto flush() -> void {}
|
virtual auto flush() -> void {}
|
||||||
|
@ -23,19 +23,19 @@ struct file {
|
||||||
return offset() >= size();
|
return offset() >= size();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto read(void* vdata, uintmax bytes) -> void {
|
auto read(void* vdata, uintmax_t bytes) -> void {
|
||||||
auto data = (uint8_t*)vdata;
|
auto data = (uint8_t*)vdata;
|
||||||
while(bytes--) *data++ = read();
|
while(bytes--) *data++ = read();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto readl(uint bytes) -> uintmax {
|
auto readl(uint bytes) -> uintmax_t {
|
||||||
uintmax data = 0;
|
uintmax_t data = 0;
|
||||||
for(auto n : range(bytes)) data |= (uintmax)read() << n * 8;
|
for(auto n : range(bytes)) data |= (uintmax_t)read() << n * 8;
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto readm(uint bytes) -> uintmax {
|
auto readm(uint bytes) -> uintmax_t {
|
||||||
uintmax data = 0;
|
uintmax_t data = 0;
|
||||||
for(auto n : range(bytes)) data = data << 8 | read();
|
for(auto n : range(bytes)) data = data << 8 | read();
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
@ -47,16 +47,16 @@ struct file {
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto write(const void* vdata, uintmax bytes) -> void {
|
auto write(const void* vdata, uintmax_t bytes) -> void {
|
||||||
auto data = (const uint8_t*)vdata;
|
auto data = (const uint8_t*)vdata;
|
||||||
while(bytes--) write(*data++);
|
while(bytes--) write(*data++);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto writel(uintmax data, uint bytes) -> void {
|
auto writel(uintmax_t data, uint bytes) -> void {
|
||||||
for(auto n : range(bytes)) write(data), data >>= 8;
|
for(auto n : range(bytes)) write(data), data >>= 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto writem(uintmax data, uint bytes) -> void {
|
auto writem(uintmax_t data, uint bytes) -> void {
|
||||||
for(auto n : rrange(bytes)) write(data >> n * 8);
|
for(auto n : rrange(bytes)) write(data >> n * 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ namespace nall {
|
||||||
|
|
||||||
struct registry {
|
struct registry {
|
||||||
static auto exists(const string& name) -> bool {
|
static auto exists(const string& name) -> bool {
|
||||||
lstring part = name.split("/");
|
auto part = name.split("/");
|
||||||
HKEY handle, rootKey = root(part.takeLeft());
|
HKEY handle, rootKey = root(part.takeLeft());
|
||||||
string node = part.takeRight();
|
string node = part.takeRight();
|
||||||
string path = part.merge("\\");
|
string path = part.merge("\\");
|
||||||
|
@ -39,7 +39,7 @@ struct registry {
|
||||||
}
|
}
|
||||||
|
|
||||||
static auto read(const string& name) -> string {
|
static auto read(const string& name) -> string {
|
||||||
lstring part = name.split("/");
|
auto part = name.split("/");
|
||||||
HKEY handle, rootKey = root(part.takeLeft());
|
HKEY handle, rootKey = root(part.takeLeft());
|
||||||
string node = part.takeRight();
|
string node = part.takeRight();
|
||||||
string path = part.merge("\\");
|
string path = part.merge("\\");
|
||||||
|
@ -54,7 +54,7 @@ struct registry {
|
||||||
}
|
}
|
||||||
|
|
||||||
static auto write(const string& name, const string& data = "") -> void {
|
static auto write(const string& name, const string& data = "") -> void {
|
||||||
lstring part = name.split("/");
|
auto part = name.split("/");
|
||||||
HKEY handle, rootKey = root(part.takeLeft());
|
HKEY handle, rootKey = root(part.takeLeft());
|
||||||
string node = part.takeRight(), path;
|
string node = part.takeRight(), path;
|
||||||
DWORD disposition;
|
DWORD disposition;
|
||||||
|
@ -71,7 +71,7 @@ struct registry {
|
||||||
}
|
}
|
||||||
|
|
||||||
static auto remove(const string& name) -> bool {
|
static auto remove(const string& name) -> bool {
|
||||||
lstring part = name.split("/");
|
auto part = name.split("/");
|
||||||
HKEY rootKey = root(part.takeLeft());
|
HKEY rootKey = root(part.takeLeft());
|
||||||
string node = part.takeRight();
|
string node = part.takeRight();
|
||||||
string path = part.merge("\\");
|
string path = part.merge("\\");
|
||||||
|
@ -79,8 +79,9 @@ struct registry {
|
||||||
return SHDeleteValueW(rootKey, utf16_t(path), utf16_t(node)) == ERROR_SUCCESS;
|
return SHDeleteValueW(rootKey, utf16_t(path), utf16_t(node)) == ERROR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static auto contents(const string& name) -> lstring {
|
static auto contents(const string& name) -> string_vector {
|
||||||
lstring part = name.split("/"), result;
|
string_vector result;
|
||||||
|
auto part = name.split("/");
|
||||||
HKEY handle, rootKey = root(part.takeLeft());
|
HKEY handle, rootKey = root(part.takeLeft());
|
||||||
part.removeRight();
|
part.removeRight();
|
||||||
string path = part.merge("\\");
|
string path = part.merge("\\");
|
||||||
|
|
Loading…
Reference in a new issue