mirror of
https://github.com/clockworkpi/Menu.git
synced 2025-12-13 16:08:55 +01:00
616 lines
21 KiB
Plaintext
Executable File
616 lines
21 KiB
Plaintext
Executable File
|
|
// 2.12
|
|
|
|
module lib+ {
|
|
|
|
module jansson+ {
|
|
|
|
module so {
|
|
|
|
struct struct {
|
|
json_array void;
|
|
json_array_append_new void;
|
|
json_array_clear void;
|
|
json_array_extend void;
|
|
json_array_get void;
|
|
json_array_insert_new void;
|
|
json_array_remove void;
|
|
json_array_set_new void;
|
|
json_array_size void;
|
|
json_copy void;
|
|
json_deep_copy void;
|
|
json_delete void;
|
|
json_dump_file void;
|
|
json_dumpf void;
|
|
json_dumps void;
|
|
json_equal void;
|
|
json_false void;
|
|
json_integer void;
|
|
json_integer_set void;
|
|
json_integer_value void;
|
|
json_load_file void;
|
|
json_loadb void;
|
|
json_loadf void;
|
|
json_loads void;
|
|
json_null void;
|
|
json_number_value void;
|
|
json_object void;
|
|
json_object_clear void;
|
|
json_object_del void;
|
|
json_object_get void;
|
|
json_object_iter void;
|
|
json_object_iter_at void;
|
|
json_object_iter_key void;
|
|
json_object_iter_next void;
|
|
json_object_iter_set_new void;
|
|
json_object_iter_value void;
|
|
json_object_key_to_iter void;
|
|
json_object_seed void;
|
|
json_object_set_new void;
|
|
json_object_set_new_nocheck void;
|
|
json_object_size void;
|
|
json_object_update void;
|
|
json_object_update_existing void;
|
|
json_object_update_missing void;
|
|
json_real void;
|
|
json_real_set void;
|
|
json_real_value void;
|
|
json_string void;
|
|
json_string_length void;
|
|
json_string_nocheck void;
|
|
json_string_set void;
|
|
json_string_set_nocheck void;
|
|
json_string_setn void;
|
|
json_string_setn_nocheck void;
|
|
json_string_value void;
|
|
json_stringn void;
|
|
json_stringn_nocheck void;
|
|
json_true void;
|
|
json_vpack_ex void;
|
|
json_vunpack_ex void;
|
|
}
|
|
|
|
var fn struct;
|
|
|
|
func init() bool {
|
|
import rt::c;
|
|
return dlsyms(dlopen("libjansson.so", RTLD_LAZY), &fn,
|
|
"json_array",
|
|
"json_array_append_new",
|
|
"json_array_clear",
|
|
"json_array_extend",
|
|
"json_array_get",
|
|
"json_array_insert_new",
|
|
"json_array_remove",
|
|
"json_array_set_new",
|
|
"json_array_size",
|
|
"json_copy",
|
|
"json_deep_copy",
|
|
"json_delete",
|
|
"json_dump_file",
|
|
"json_dumpf",
|
|
"json_dumps",
|
|
"json_equal",
|
|
"json_false",
|
|
"json_integer",
|
|
"json_integer_set",
|
|
"json_integer_value",
|
|
"json_load_file",
|
|
"json_loadb",
|
|
"json_loadf",
|
|
"json_loads",
|
|
"json_null",
|
|
"json_number_value",
|
|
"json_object",
|
|
"json_object_clear",
|
|
"json_object_del",
|
|
"json_object_get",
|
|
"json_object_iter",
|
|
"json_object_iter_at",
|
|
"json_object_iter_key",
|
|
"json_object_iter_next",
|
|
"json_object_iter_set_new",
|
|
"json_object_iter_value",
|
|
"json_object_key_to_iter",
|
|
"json_object_seed",
|
|
"json_object_set_new",
|
|
"json_object_set_new_nocheck",
|
|
"json_object_size",
|
|
"json_object_update",
|
|
"json_object_update_existing",
|
|
"json_object_update_missing",
|
|
"json_real",
|
|
"json_real_set",
|
|
"json_real_value",
|
|
"json_string",
|
|
"json_string_length",
|
|
"json_string_nocheck",
|
|
"json_string_set",
|
|
"json_string_set_nocheck",
|
|
"json_string_setn",
|
|
"json_string_setn_nocheck",
|
|
"json_string_value",
|
|
"json_stringn",
|
|
"json_stringn_nocheck",
|
|
"json_true",
|
|
"json_vpack_ex",
|
|
"json_vunpack_ex"
|
|
);
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
module jansson+ {
|
|
|
|
private import rt::c;
|
|
|
|
typedef json_int_t dlong;
|
|
|
|
// xxx
|
|
enum json_type {
|
|
object,
|
|
array,
|
|
string,
|
|
integer,
|
|
real,
|
|
true,
|
|
false,
|
|
null
|
|
}
|
|
|
|
struct json_t {
|
|
type json_type;
|
|
refcount size_t;
|
|
}
|
|
|
|
inline json_typeof(json. json_t) json_type {
|
|
return json.type;
|
|
}
|
|
|
|
inline json_is_object(json. json_t) bool {
|
|
if json ~= null and json_typeof(json) == json_type.object;
|
|
return true;
|
|
return false;
|
|
}
|
|
|
|
inline json_is_array(json. json_t) bool {
|
|
if json ~= null and json_typeof(json) == json_type.array;
|
|
return true;
|
|
return false;
|
|
}
|
|
|
|
inline json_is_string(json. json_t) bool {
|
|
if json ~= null and json_typeof(json) == json_type.string;
|
|
return true;
|
|
return false;
|
|
}
|
|
|
|
inline json_is_integer(json. json_t) bool {
|
|
if json ~= null and json_typeof(json) == json_type.integer;
|
|
return true;
|
|
return false;
|
|
}
|
|
|
|
inline json_is_real(json. json_t) bool {
|
|
if json ~= null and json_typeof(json) == json_type.real;
|
|
return true;
|
|
return false;
|
|
}
|
|
|
|
inline json_is_number(json. json_t) bool {
|
|
if json_is_integer(json) or json_is_real(json);
|
|
return true;
|
|
return false;
|
|
}
|
|
|
|
inline json_is_true(json. json_t) bool {
|
|
if json ~= null and json_typeof(json) == json_type.true;
|
|
return true;
|
|
return false;
|
|
}
|
|
|
|
inline json_is_false(json. json_t) bool {
|
|
if json ~= null and json_typeof(json) == json_type.false;
|
|
return true;
|
|
return false;
|
|
}
|
|
|
|
inline json_boolean_value(json. json_t) bool {
|
|
return json_is_true(json);
|
|
}
|
|
|
|
inline json_is_boolean(json. json_t) bool {
|
|
if json_is_true(json) or json_is_false(json);
|
|
return true;
|
|
return false;
|
|
}
|
|
|
|
inline json_is_null(json. json_t) bool {
|
|
if json ~= null and json_typeof(json) == json_type.null;
|
|
return true;
|
|
return false;
|
|
}
|
|
|
|
inline json_object() .json_t {
|
|
return call<void>(so::fn.json_object);
|
|
}
|
|
|
|
inline json_array() .json_t {
|
|
return call<void>(so::fn.json_array);
|
|
}
|
|
|
|
inline json_string(value. char) .json_t {
|
|
return call1<void>(so::fn.json_string, value);
|
|
}
|
|
|
|
inline json_stringn(value. char, len size_t) .json_t {
|
|
return call2<void>(so::fn.json_stringn, value, len);
|
|
}
|
|
|
|
inline json_string_nocheck(value. char) .json_t {
|
|
return call1<void>(so::fn.json_string_nocheck, value);
|
|
}
|
|
|
|
inline json_stringn_nocheck(value. char, len size_t) .json_t {
|
|
return call2<void>(so::fn.json_stringn_nocheck, value, len);
|
|
}
|
|
|
|
inline json_integer(value json_int_t) .json_t {
|
|
return call1<void>(so::fn.json_integer, value);
|
|
}
|
|
|
|
inline json_real(value double) .json_t {
|
|
return call_d<void>(so::fn.json_real, value);
|
|
}
|
|
|
|
inline json_true() .json_t {
|
|
return call<void>(so::fn.json_true);
|
|
}
|
|
|
|
inline json_false() .json_t {
|
|
return call<void>(so::fn.json_false);
|
|
}
|
|
|
|
inline json_boolean(value bool) .json_t {
|
|
if value {
|
|
return json_true();
|
|
else
|
|
return json_false();
|
|
}
|
|
}
|
|
|
|
inline json_null() .json_t {
|
|
return call<void>(so::fn.json_null);
|
|
}
|
|
|
|
inline json_incref(json. json_t) .json_t {
|
|
if json ~= null and json.refcount ~= -1;
|
|
json.refcount++;
|
|
return json;
|
|
}
|
|
|
|
inline json_delete(json. json_t) {
|
|
call1<void>(so::fn.json_delete, json);
|
|
}
|
|
|
|
inline json_decref(json. json_t) {
|
|
if json ~= null and json.refcount ~= -1 and --json.refcount == 0;
|
|
json_delete(json);
|
|
}
|
|
|
|
define {
|
|
JSON_ERROR_TEXT_LENGTH = 160;
|
|
JSON_ERROR_SOURCE_LENGTH = 80;
|
|
}
|
|
|
|
struct json_error_t {
|
|
line int;
|
|
column int;
|
|
position int;
|
|
source(JSON_ERROR_SOURCE_LENGTH) char;
|
|
text(JSON_ERROR_TEXT_LENGTH) char;
|
|
}
|
|
|
|
inline json_object_seed(seed size_t) {
|
|
call1<void>(so::fn.json_object_seed, seed);
|
|
}
|
|
|
|
inline json_object_size(object. json_t) size_t {
|
|
return call1<size_t>(so::fn.json_object_size, object);
|
|
}
|
|
|
|
inline json_object_get(object. json_t, key. char) .json_t {
|
|
return call2<void>(so::fn.json_object_get, object, key);
|
|
}
|
|
|
|
func json_object_gets(object. json_t, ...) .json_t {
|
|
forvar ap. char* = va_start(object), size uint32 = va_size(object); size; {
|
|
if (object = json_object_get(object, .ap)) == null;
|
|
return null;
|
|
va_nexts<char*>(ap, size);
|
|
}
|
|
return object;
|
|
}
|
|
|
|
inline json_object_set_new(object. json_t, key. char, value. json_t) int {
|
|
return call3<int>(so::fn.json_object_set_new, object, key, value);
|
|
}
|
|
|
|
inline json_object_set_new_nocheck(object. json_t, key. char, value. json_t) int {
|
|
return call3<int>(so::fn.json_object_set_new_nocheck, object, key, value);
|
|
}
|
|
|
|
inline json_object_del(object. json_t, key. char) int {
|
|
return call2<int>(so::fn.json_object_del, object, key);
|
|
}
|
|
|
|
inline json_object_clear(object. json_t) int {
|
|
return call1<int>(so::fn.json_object_clear, object);
|
|
}
|
|
|
|
inline json_object_update(object. json_t, other. json_t) int {
|
|
return call2<int>(so::fn.json_object_update, object, other);
|
|
}
|
|
|
|
inline json_object_update_existing(object. json_t, other. json_t) int {
|
|
return call2<int>(so::fn.json_object_update_existing, object, other);
|
|
}
|
|
|
|
inline json_object_update_missing(object. json_t, other. json_t) int {
|
|
return call2<int>(so::fn.json_object_update_missing, object, other);
|
|
}
|
|
|
|
inline json_object_iter(object. json_t) void {
|
|
return call1<void>(so::fn.json_object_iter, object);
|
|
}
|
|
|
|
inline json_object_iter_at(object. json_t, key. char) void {
|
|
return call2<void>(so::fn.json_object_iter_at, object, key);
|
|
}
|
|
|
|
inline json_object_key_to_iter(key. char) void {
|
|
return call1<void>(so::fn.json_object_key_to_iter, key);
|
|
}
|
|
|
|
inline json_object_iter_next(object. json_t, iter void) void {
|
|
return call2<void>(so::fn.json_object_iter_next, object, iter);
|
|
}
|
|
|
|
inline json_object_iter_key(iter void) .char {
|
|
return call1<char*>(so::fn.json_object_iter_key, iter);
|
|
}
|
|
|
|
inline json_object_iter_value(iter void) .json_t {
|
|
return call1<void>(so::fn.json_object_iter_value, iter);
|
|
}
|
|
|
|
inline json_object_iter_set_new(object. json_t, iter void, value. json_t) int {
|
|
return call3<int>(so::fn.json_object_iter_set_new, object, iter, value);
|
|
}
|
|
|
|
// xxx
|
|
func json_object_foreach(object. json_t, callback void) {
|
|
proto foreach_callback(object. json_t, key. char, value. json_t) bool;
|
|
forvar key. char = json_object_iter_key(json_object_iter(object)), value. json_t;
|
|
key ~= null and (value = json_object_iter_value(json_object_key_to_iter(key)));
|
|
key = json_object_iter_key(json_object_iter_next(object, json_object_key_to_iter(key))) {
|
|
if !foreach_callback[callback](object, key, value);
|
|
return;
|
|
}
|
|
}
|
|
|
|
// xxx
|
|
func json_array_foreach(array. json_t, callback void) {
|
|
proto foreach_callback(array. json_t, index size_t, value. json_t) bool;
|
|
forvar index size_t = 0, value. json_t; index < json_array_size(array) and (value = json_array_get(array, index)); index++ {
|
|
if !foreach_callback[callback](array, index, value);
|
|
return;
|
|
}
|
|
}
|
|
|
|
inline json_object_set(object. json_t, key. char, value. json_t) int {
|
|
return json_object_set_new(object, key, json_incref(value));
|
|
}
|
|
|
|
inline json_object_set_nocheck(object. json_t, key. char, value. json_t) int {
|
|
return json_object_set_new_nocheck(object, key, json_incref(value));
|
|
}
|
|
|
|
inline json_object_iter_set(object. json_t, iter void, value. json_t) int {
|
|
return json_object_iter_set_new(object, iter, json_incref(value));
|
|
}
|
|
|
|
inline json_array_size(array. json_t) size_t {
|
|
return call1<size_t>(so::fn.json_array_size, array);
|
|
}
|
|
|
|
inline json_array_get(array. json_t, index size_t) .json_t {
|
|
return call2<void>(so::fn.json_array_get, array, index);
|
|
}
|
|
|
|
inline json_array_set_new(array. json_t, index size_t, value. json_t) int {
|
|
return call3<int>(so::fn.json_array_set_new, array, index, value);
|
|
}
|
|
|
|
inline json_array_append_new(array. json_t, value. json_t) int {
|
|
return call2<int>(so::fn.json_array_append_new, array, value);
|
|
}
|
|
|
|
inline json_array_insert_new(array. json_t, index size_t, value. json_t) int {
|
|
return call3<int>(so::fn.json_array_insert_new, array, index, value);
|
|
}
|
|
|
|
inline json_array_remove(array. json_t, index size_t) int {
|
|
return call2<int>(so::fn.json_array_remove, array, index);
|
|
}
|
|
|
|
inline json_array_clear(array. json_t) int {
|
|
return call1<int>(so::fn.json_array_clear, array);
|
|
}
|
|
|
|
inline json_array_extend(array. json_t, other. json_t) int {
|
|
return call2<int>(so::fn.json_array_extend, array, other);
|
|
}
|
|
|
|
inline json_array_set(array. json_t, index size_t, value. json_t) int {
|
|
return json_array_set_new(array, index, json_incref(value));
|
|
}
|
|
|
|
inline json_array_append(array. json_t, value. json_t) int {
|
|
return json_array_append_new(array, json_incref(value));
|
|
}
|
|
|
|
inline json_array_insert(array. json_t, index size_t, value. json_t) int {
|
|
return json_array_insert_new(array, index, json_incref(value));
|
|
}
|
|
|
|
inline json_string_value(string. json_t) .char {
|
|
return call1<char*>(so::fn.json_string_value, string);
|
|
}
|
|
|
|
inline json_string_length(string. json_t) size_t {
|
|
return call1<size_t>(so::fn.json_string_length, string);
|
|
}
|
|
|
|
inline json_integer_value(integer. json_t) json_int_t {
|
|
return call1<json_int_t>(so::fn.json_integer_value, integer);
|
|
}
|
|
|
|
inline json_real_value(real. json_t) double {
|
|
return callf_r<double>(so::fn.json_real_value, real);
|
|
}
|
|
|
|
inline json_number_value(json. json_t) double {
|
|
return callf_r<double>(so::fn.json_number_value, json);
|
|
}
|
|
|
|
inline json_string_set(string. json_t, value. char) int {
|
|
return call2<int>(so::fn.json_string_set, string, value);
|
|
}
|
|
|
|
inline json_string_setn(string. json_t, value. char, len size_t) int {
|
|
return call3<int>(so::fn.json_string_setn, string, value, len);
|
|
}
|
|
|
|
inline json_string_set_nocheck(string. json_t, value. char) int {
|
|
return call2<int>(so::fn.json_string_set_nocheck, string, value);
|
|
}
|
|
|
|
inline json_string_setn_nocheck(string. json_t, value. char, len size_t) int {
|
|
return call3<int>(so::fn.json_string_setn_nocheck, string, value, len);
|
|
}
|
|
|
|
inline json_integer_set(integer. json_t, value json_int_t) int {
|
|
return call2<int>(so::fn.json_integer_set, integer, value);
|
|
}
|
|
|
|
inline json_real_set(real. json_t, value double) int {
|
|
return call_rd<int>(so::fn.json_real_set, real, value);
|
|
}
|
|
|
|
inline json_vpack_ex(error. json_error_t, flags size_t, fmt. char, ap+ va_list) .json_t {
|
|
return call4<void>(so::fn.json_vpack_ex, error, flags, fmt, ap);
|
|
}
|
|
|
|
func json_pack_ex(error. json_error_t, flags size_t, fmt. char, ...) .json_t {
|
|
return json_vpack_ex(error, flags, fmt, va_start(error));
|
|
}
|
|
|
|
func json_pack(fmt. char, ...) .json_t {
|
|
return json_vpack_ex(null, 0, fmt, va_start(fmt));
|
|
}
|
|
|
|
func json_packs(flags size_t, fmt. char, ...) .char {
|
|
var json. json_t = json_vpack_ex(null, 0, fmt, va_start(flags));
|
|
if json == null;
|
|
return null;
|
|
func = json_dumps(json, flags);
|
|
json_decref(json);
|
|
}
|
|
|
|
define {
|
|
JSON_VALIDATE_ONLY = 0x1;
|
|
JSON_STRICT = 0x2;
|
|
}
|
|
|
|
func json_unpack_ex(root. json_t, error. json_error_t, flags size_t, fmt. char, ...) int {
|
|
return call5<int>(so::fn.json_vunpack_ex, root, error, flags, fmt, va_start(root));
|
|
}
|
|
|
|
func json_unpack(root. json_t, fmt. char, ...) int {
|
|
return call3<int>(so::fn.json_vunpack_ex, root, fmt, va_start(root));
|
|
}
|
|
|
|
inline json_equal(value1. json_t, value2. json_t) int {
|
|
return call2<int>(so::fn.json_equal, value1, value2);
|
|
}
|
|
|
|
inline json_copy(value. json_t) .json_t {
|
|
return call1<void>(so::fn.json_copy, value);
|
|
}
|
|
|
|
inline json_deep_copy(value. json_t) .json_t {
|
|
return call1<void>(so::fn.json_deep_copy, value);
|
|
}
|
|
|
|
define {
|
|
JSON_REJECT_DUPLICATES = 0x1;
|
|
JSON_DISABLE_EOF_CHECK = 0x2;
|
|
JSON_DECODE_ANY = 0x4;
|
|
JSON_DECODE_INT_AS_REAL = 0x8;
|
|
JSON_ALLOW_NUL = 0x10;
|
|
}
|
|
|
|
inline json_loads(input. char, flags size_t = 0, error. json_error_t = null) .json_t {
|
|
return call3<void>(so::fn.json_loads, input, flags, error);
|
|
}
|
|
|
|
inline json_loadb(buffer. char, buflen size_t, flags size_t = 0, error. json_error_t = null) .json_t {
|
|
return call4<void>(so::fn.json_loadb, buffer, buflen, flags, error);
|
|
}
|
|
|
|
inline json_loadf(input void, flags size_t = 0, error. json_error_t = null) .json_t {
|
|
return call3<void>(so::fn.json_loadf, input, flags, error);
|
|
}
|
|
|
|
inline json_load_file(path. char, flags size_t = 0, error. json_error_t = null) .json_t {
|
|
return call3<void>(so::fn.json_load_file, path, flags, error);
|
|
}
|
|
|
|
define {
|
|
JSON_MAX_INDENT = 0x1F;
|
|
JSON_COMPACT = 0x20;
|
|
JSON_ENSURE_ASCII = 0x40;
|
|
JSON_SORT_KEYS = 0x80;
|
|
JSON_PRESERVE_ORDER = 0x100;
|
|
JSON_ENCODE_ANY = 0x200;
|
|
JSON_ESCAPE_SLASH = 0x400;
|
|
JSON_EMBED = 0x10000;
|
|
}
|
|
|
|
inline JSON_INDENT(n size_t) size_t {
|
|
return n & JSON_MAX_INDENT;
|
|
}
|
|
|
|
inline JSON_REAL_PRECISION(n size_t) size_t {
|
|
return (n & 0x1F) << 11;
|
|
}
|
|
|
|
inline json_dumps(json. json_t, flags size_t = 0) .char {
|
|
return call2<char*>(so::fn.json_dumps, json, flags);
|
|
}
|
|
|
|
inline json_dumpf(json. json_t, output+ FILE, flags size_t = 0) int {
|
|
return call3<int>(so::fn.json_dumpf, json, output, flags);
|
|
}
|
|
|
|
inline json_dump_file(json. json_t, path. char, flags size_t = 0) int {
|
|
return call3<int>(so::fn.json_dump_file, json, path, flags);
|
|
}
|
|
|
|
}
|
|
|
|
}
|