aboutsummaryrefslogtreecommitdiff
path: root/project/dclib
diff options
context:
space:
mode:
authorWiimm <wiimm@wiimm.de>2022-05-13 19:22:53 +0200
committerWiimm <wiimm@wiimm.de>2022-05-13 19:22:53 +0200
commit59090f08e8ff7c9db4912ab1dbae391eb5a2c887 (patch)
tree67f91c7c5c011292704b106bc7b4dc674cf13463 /project/dclib
parent568365f5bdd4dc71a156ca963d89ac002f405a34 (diff)
SZS v2.27a
Diffstat (limited to 'project/dclib')
-rw-r--r--project/dclib/Makefile.rules35
-rw-r--r--project/dclib/dclib-punycode.c208
-rw-r--r--project/dclib/dclib-punycode.h161
-rw-r--r--project/dclib/dclib-punycode.inc279
-rw-r--r--project/dclib/lib-mkw-def.c146
-rw-r--r--project/dclib/lib-mkw-def.h80
6 files changed, 909 insertions, 0 deletions
diff --git a/project/dclib/Makefile.rules b/project/dclib/Makefile.rules
new file mode 100644
index 0000000..60bd4a1
--- /dev/null
+++ b/project/dclib/Makefile.rules
@@ -0,0 +1,35 @@
+
+ ###########################################################################
+ # #
+ # _____ ____ #
+ # | __ \ / __ \ _ _ _____ #
+ # | | \ \ / / \_\ | | | | _ \ #
+ # | | \ \| | | | | | |_| | #
+ # | | | || | | | | | ___/ #
+ # | | / /| | __ | | | | _ \ #
+ # | |__/ / \ \__/ / | |___| | |_| | #
+ # |_____/ \____/ |_____|_|_____/ #
+ # #
+ # Wiimms source code library #
+ # #
+ ###########################################################################
+
+#------------------------------------------------------------------------------
+
+.PHONY: dclib
+dclib:
+ @echo ""
+ @echo "DCLIB_THREAD = $(DCLIB_THREAD)"
+ @echo "DCLIB_MYSQL = $(DCLIB_MYSQL)"
+ @echo "DCLIB_TERMINAL = $(DCLIB_TERMINAL)"
+ @echo "DCLIB_NETWORK = $(DCLIB_NETWORK)"
+ @echo "DCLIB_HAVE_USABLE_SIZE = $(DCLIB_HAVE_USABLE_SIZE)"
+ @echo ""
+ @echo "DCLIB_FLAGS = $(DCLIB_FLAGS)"
+ @echo "DCLIB_O_MKW = $(DCLIB_O_MKW)"
+ @echo "DCLIB_O_WIIMMFI = $(DCLIB_O_WIIMMFI)"
+ @echo ""
+ @echo "DCLIB_O = $(DCLIB_O)"
+ @echo ""
+
+#------------------------------------------------------------------------------
diff --git a/project/dclib/dclib-punycode.c b/project/dclib/dclib-punycode.c
new file mode 100644
index 0000000..691ebfe
--- /dev/null
+++ b/project/dclib/dclib-punycode.c
@@ -0,0 +1,208 @@
+
+/***************************************************************************
+ * *
+ * _____ ____ *
+ * | __ \ / __ \ _ _ _____ *
+ * | | \ \ / / \_\ | | | | _ \ *
+ * | | \ \| | | | | | |_| | *
+ * | | | || | | | | | ___/ *
+ * | | / /| | __ | | | | _ \ *
+ * | |__/ / \ \__/ / | |___| | |_| | *
+ * |_____/ \____/ |_____|_|_____/ *
+ * *
+ * Wiimms source code library *
+ * *
+ ***************************************************************************
+ * *
+ * Copyright (c) 2012-2022 by Dirk Clemens <wiimm@wiimm.de> *
+ * *
+ ***************************************************************************
+ * *
+ * This library is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This library is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * See file gpl-2.0.txt or http://www.gnu.org/licenses/gpl-2.0.txt *
+ * *
+ ***************************************************************************/
+
+#include "dclib-basics.h"
+#include "dclib-utf8.h"
+#include "dclib-punycode.h"
+
+#include <limits.h>
+
+#include "dclib-punycode.inc"
+
+//
+///////////////////////////////////////////////////////////////////////////////
+/////////////// Domain2UTF8() ///////////////
+///////////////////////////////////////////////////////////////////////////////
+
+uint Domain2UTF8
+(
+ // returns the number of scanned bytes of 'source' or 0 on error
+
+ char *buf, // valid destination buffer
+ int buf_size, // size of 'buf' >= 4
+ const void *source, // NULL or UTF-8 domain to translate
+ int source_len // length of 'source'; if <0: use strlen(source)
+)
+{
+ DASSERT(buf)
+ DASSERT(source||!source_len);
+
+ if ( buf_size < 4 || !source )
+ return 0;
+
+ if ( source_len < 0 )
+ source_len = strlen(source);
+
+ ccp src = source, src_end = source + source_len;
+ char *buf_ptr = buf, *buf_end = buf + buf_size - 2;
+
+ enum { MAX_LEN = 1000 };
+ char name[MAX_LEN+10];
+ punycode_uint pname[MAX_LEN+2];
+ MARK_USED(name,pname);
+
+ while ( src < src_end )
+ {
+ while ( buf_ptr < buf_end && src < src_end && *src == '.' )
+ *buf_ptr++ = *src++;
+ if ( buf_ptr >= buf_end )
+ {
+ if (!src)
+ goto error;
+ break;
+ }
+
+ if ( src >= src_end )
+ break;
+
+ ccp point = strchr(src,'.');
+ if (!point)
+ point = src_end;
+
+ if ( src+4 > src_end || memcmp(src,"xn--",4 ))
+ buf_ptr = StringCopyEM(buf_ptr,buf_end,src,point-src);
+ else
+ {
+ src += 4;
+ punycode_uint olen = MAX_LEN;
+ const enum punycode_status stat
+ = punycode_decode(point-src,src,&olen,pname,0);
+ char *dest = name;
+ if ( stat != punycode_success )
+ dest = name + snprintf(name,sizeof(name),"!ERR=%d",stat);
+ else
+ {
+ punycode_uint *src = pname, *src_end = pname + olen;
+ char *dest_end = name + MAX_LEN;
+ while ( src < src_end && dest < dest_end )
+ dest = PrintUTF8Char(dest,*src++);
+ *dest = 0;
+ }
+
+ buf_ptr = StringCopyEM(buf_ptr,buf_end,name,dest-name);
+ }
+ src = point;
+ }
+
+ *buf_ptr = 0;
+ return src - (ccp)source;
+
+ error:
+ *buf = 0;
+ return 0;
+}
+
+//
+///////////////////////////////////////////////////////////////////////////////
+/////////////// Domain2ASCII() ///////////////
+///////////////////////////////////////////////////////////////////////////////
+
+uint Domain2ASCII
+(
+ // returns the number of scanned bytes of 'source' or 0 on error
+
+ char *buf, // valid destination buffer
+ int buf_size, // size of 'buf' >= 5
+ const void *source, // NULL or ASCII domain to translate
+ int source_len // length of 'source'; if <0: use strlen(source)
+)
+{
+ DASSERT(buf)
+ DASSERT(source||!source_len);
+
+ if ( buf_size < 5 || !source )
+ return 0;
+
+ if ( source_len < 0 )
+ source_len = strlen(source);
+
+ ccp src = source, src_end = source + source_len;
+ char *buf_ptr = buf, *buf_end = buf + buf_size - 5;
+
+ enum { MAX_LEN = 1000 };
+ char name[MAX_LEN+10];
+ punycode_uint pname[MAX_LEN+2];
+
+ while ( src < src_end )
+ {
+ while ( buf_ptr < buf_end && src < src_end && *src == '.' )
+ *buf_ptr++ = *src++;
+ if ( buf_ptr >= buf_end )
+ {
+ if (!src)
+ goto error;
+ break;
+ }
+
+ if ( src >= src_end )
+ break;
+
+ ccp point = strchr(src,'.');
+ if (!point)
+ point = src_end;
+
+ punycode_uint *dest = pname, *dest_end = pname + MAX_LEN;
+ while ( dest < dest_end && src < point )
+ {
+ u32 code = ScanUTF8AnsiCharE(&src,point);
+ *dest++ = code;
+ }
+
+ punycode_uint olen = MAX_LEN;
+ const enum punycode_status stat =
+ punycode_encode(dest-pname,pname,0,&olen,name);
+ if (stat)
+ goto error;
+
+ if ( olen > 0 && name[olen-1] == '-' )
+ buf_ptr = StringCopyEM(buf_ptr,buf_end,name,olen-1);
+ else
+ {
+ name[olen] = 0;
+ buf_ptr = StringCat2E(buf_ptr,buf_end,"xn--",name);
+ }
+ }
+
+ *buf_ptr = 0;
+ return src - (ccp)source;
+
+ error:
+ *buf = 0;
+ return 0;
+}
+
+//
+///////////////////////////////////////////////////////////////////////////////
+/////////////// E N D ///////////////
+///////////////////////////////////////////////////////////////////////////////
diff --git a/project/dclib/dclib-punycode.h b/project/dclib/dclib-punycode.h
new file mode 100644
index 0000000..b859223
--- /dev/null
+++ b/project/dclib/dclib-punycode.h
@@ -0,0 +1,161 @@
+
+/***************************************************************************
+ * *
+ * _____ ____ *
+ * | __ \ / __ \ _ _ _____ *
+ * | | \ \ / / \_\ | | | | _ \ *
+ * | | \ \| | | | | | |_| | *
+ * | | | || | | | | | ___/ *
+ * | | / /| | __ | | | | _ \ *
+ * | |__/ / \ \__/ / | |___| | |_| | *
+ * |_____/ \____/ |_____|_|_____/ *
+ * *
+ * Wiimms source code library *
+ * *
+ ***************************************************************************
+ * *
+ * Copyright (c) 2012-2022 by Dirk Clemens <wiimm@wiimm.de> *
+ * *
+ ***************************************************************************
+ * *
+ * This library is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This library is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * See file gpl-2.0.txt or http://www.gnu.org/licenses/gpl-2.0.txt *
+ * *
+ ***************************************************************************/
+
+#ifndef DC_LIB_PUNYCODE_H
+#define DC_LIB_PUNYCODE_H 1
+
+#include "dclib-basics.h"
+#include <limits.h>
+
+//
+///////////////////////////////////////////////////////////////////////////////
+/////////////// Domain2*() ///////////////
+///////////////////////////////////////////////////////////////////////////////
+
+uint Domain2UTF8
+(
+ // returns the number of scanned bytes of 'source' or 0 on error
+
+ char *buf, // valid destination buffer
+ int buf_size, // size of 'buf' >= 4
+ const void *source, // NULL or UTF-8 domain to translate
+ int source_len // length of 'source'; if <0: use strlen(source)
+);
+
+///////////////////////////////////////////////////////////////////////////////
+
+uint Domain2ASCII
+(
+ // returns the number of scanned bytes of 'source' or 0 on error
+
+ char *buf, // valid destination buffer
+ int buf_size, // size of 'buf' >= 5
+ const void *source, // NULL or ASCII domain to translate
+ int source_len // length of 'source'; if <0: use strlen(source)
+);
+
+//
+///////////////////////////////////////////////////////////////////////////////
+/////////////// punycode lib ///////////////
+///////////////////////////////////////////////////////////////////////////////
+
+
+enum punycode_status
+{
+ punycode_success,
+ punycode_bad_input, /* Input is invalid. */
+ punycode_big_output, /* Output would exceed the space provided. */
+ punycode_overflow /* Input needs wider integers to process. */
+};
+
+#if UINT_MAX >= (1 << 26) - 1
+ typedef unsigned int punycode_uint;
+#else
+ typedef unsigned long punycode_uint;
+#endif
+
+///////////////////////////////////////////////////////////////////////////////
+
+enum punycode_status punycode_encode
+(
+ punycode_uint input_length,
+ const punycode_uint input[],
+ const unsigned char case_flags[],
+ punycode_uint *output_length,
+ char output[]
+);
+
+ /* punycode_encode() converts Unicode to Punycode. The input */
+ /* is represented as an array of Unicode code points (not code */
+ /* units; surrogate pairs are not allowed), and the output */
+ /* will be represented as an array of ASCII code points. The */
+ /* output string is *not* null-terminated; it will contain */
+ /* zeros if and only if the input contains zeros. (Of course */
+ /* the caller can leave room for a terminator and add one if */
+ /* needed.) The input_length is the number of code points in */
+ /* the input. The output_length is an in/out argument: the */
+ /* caller passes in the maximum number of code points that it */
+ /* can receive, and on successful return it will contain the */
+ /* number of code points actually output. The case_flags array */
+ /* holds input_length boolean values, where nonzero suggests that */
+ /* the corresponding Unicode character be forced to uppercase */
+ /* after being decoded (if possible), and zero suggests that */
+ /* it be forced to lowercase (if possible). ASCII code points */
+ /* are encoded literally, except that ASCII letters are forced */
+ /* to uppercase or lowercase according to the corresponding */
+ /* uppercase flags. If case_flags is a null pointer then ASCII */
+ /* letters are left as they are, and other code points are */
+ /* treated as if their uppercase flags were zero. The return */
+ /* value can be any of the punycode_status values defined above */
+ /* except punycode_bad_input; if not punycode_success, then */
+ /* output_size and output might contain garbage. */
+
+///////////////////////////////////////////////////////////////////////////////
+
+enum punycode_status punycode_decode
+(
+ punycode_uint input_length,
+ const char input[],
+ punycode_uint *output_length,
+ punycode_uint output[],
+ unsigned char case_flags[]
+);
+
+ /* punycode_decode() converts Punycode to Unicode. The input is */
+ /* represented as an array of ASCII code points, and the output */
+ /* will be represented as an array of Unicode code points. The */
+ /* input_length is the number of code points in the input. The */
+ /* output_length is an in/out argument: the caller passes in */
+ /* the maximum number of code points that it can receive, and */
+ /* on successful return it will contain the actual number of */
+ /* code points output. The case_flags array needs room for at */
+ /* least output_length values, or it can be a null pointer if the */
+ /* case information is not needed. A nonzero flag suggests that */
+ /* the corresponding Unicode character be forced to uppercase */
+ /* by the caller (if possible), while zero suggests that it be */
+ /* forced to lowercase (if possible). ASCII code points are */
+ /* output already in the proper case, but their flags will be set */
+ /* appropriately so that applying the flags would be harmless. */
+ /* The return value can be any of the punycode_status values */
+ /* defined above; if not punycode_success, then output_length, */
+ /* output, and case_flags might contain garbage. On success, the */
+ /* decoder will never need to write an output_length greater than */
+ /* input_length, because of how the encoding is defined. */
+
+//
+///////////////////////////////////////////////////////////////////////////////
+/////////////// E N D ///////////////
+///////////////////////////////////////////////////////////////////////////////
+
+#endif // DC_LIB_PUNYCODE_H
diff --git a/project/dclib/dclib-punycode.inc b/project/dclib/dclib-punycode.inc
new file mode 100644
index 0000000..276138f
--- /dev/null
+++ b/project/dclib/dclib-punycode.inc
@@ -0,0 +1,279 @@
+
+/***************************************************************************
+ * *
+ * _____ ____ *
+ * | __ \ / __ \ _ _ _____ *
+ * | | \ \ / / \_\ | | | | _ \ *
+ * | | \ \| | | | | | |_| | *
+ * | | | || | | | | | ___/ *
+ * | | / /| | __ | | | | _ \ *
+ * | |__/ / \ \__/ / | |___| | |_| | *
+ * |_____/ \____/ |_____|_|_____/ *
+ * *
+ * Wiimms source code library *
+ * *
+ ***************************************************************************
+ * *
+ * punycode.c from RFC 3492 *
+ * http://www.nicemice.net/idn/ *
+ * Adam M. Costello *
+ * http://www.nicemice.net/amc/ *
+ * *
+ * This is ANSI C code (C89) implementing Punycode (RFC 3492). *
+ * *
+ ***************************************************************************/
+
+/*** Bootstring parameters for Punycode ***/
+
+enum { base = 36, tmin = 1, tmax = 26, skew = 38, damp = 700,
+ initial_bias = 72, initial_n = 0x80, delimiter = 0x2D };
+
+/* basic(cp) tests whether cp is a basic code point: */
+#define basic(cp) ((punycode_uint)(cp) < 0x80)
+
+/* delim(cp) tests whether cp is a delimiter: */
+#define delim(cp) ((cp) == delimiter)
+
+/* decode_digit(cp) returns the numeric value of a basic code */
+/* point (for use in representing integers) in the range 0 to */
+/* base-1, or base if cp is does not represent a value. */
+
+static punycode_uint decode_digit(punycode_uint cp)
+{
+ return cp - 48 < 10 ? cp - 22 : cp - 65 < 26 ? cp - 65 :
+ cp - 97 < 26 ? cp - 97 : base;
+}
+
+/* encode_digit(d,flag) returns the basic code point whose value */
+/* (when used for representing integers) is d, which needs to be in */
+/* the range 0 to base-1. The lowercase form is used unless flag is */
+/* nonzero, in which case the uppercase form is used. The behavior */
+/* is undefined if flag is nonzero and digit d has no uppercase form. */
+
+static char encode_digit(punycode_uint d, int flag)
+{
+ return d + 22 + 75 * (d < 26) - ((flag != 0) << 5);
+ /* 0..25 map to ASCII a..z or A..Z */
+ /* 26..35 map to ASCII 0..9 */
+}
+
+/* flagged(bcp) tests whether a basic code point is flagged */
+/* (uppercase). The behavior is undefined if bcp is not a */
+/* basic code point. */
+
+#define flagged(bcp) ((punycode_uint)(bcp) - 65 < 26)
+
+/* encode_basic(bcp,flag) forces a basic code point to lowercase */
+/* if flag is zero, uppercase if flag is nonzero, and returns */
+/* the resulting code point. The code point is unchanged if it */
+/* is caseless. The behavior is undefined if bcp is not a basic */
+/* code point. */
+
+static char encode_basic(punycode_uint bcp, int flag)
+{
+ bcp -= (bcp - 97 < 26) << 5;
+ return bcp + ((!flag && (bcp - 65 < 26)) << 5);
+}
+
+/*** Platform-specific constants ***/
+
+/* maxint is the maximum value of a punycode_uint variable: */
+static const punycode_uint maxint = -1;
+/* Because maxint is unsigned, -1 becomes the maximum value. */
+
+/*** Bias adaptation function ***/
+
+static punycode_uint adapt(
+ punycode_uint delta, punycode_uint numpoints, int firsttime )
+{
+ punycode_uint k;
+
+ delta = firsttime ? delta / damp : delta >> 1;
+ /* delta >> 1 is a faster way of doing delta / 2 */
+ delta += delta / numpoints;
+
+ for (k = 0; delta > ((base - tmin) * tmax) / 2; k += base) {
+ delta /= base - tmin;
+ }
+
+ return k + (base - tmin + 1) * delta / (delta + skew);
+}
+
+/*** Main encode function ***/
+
+enum punycode_status punycode_encode(
+ punycode_uint input_length,
+ const punycode_uint input[],
+ const unsigned char case_flags[],
+ punycode_uint *output_length,
+ char output[] )
+{
+ punycode_uint n, delta, h, b, out, max_out, bias, j, m, q, k, t;
+
+ /* Initialize the state: */
+
+ n = initial_n;
+ delta = out = 0;
+ max_out = *output_length;
+ bias = initial_bias;
+
+ /* Handle the basic code points: */
+
+ for (j = 0; j < input_length; ++j) {
+ if (basic(input[j])) {
+ if (max_out - out < 2) return punycode_big_output;
+ output[out++] =
+ case_flags ? encode_basic(input[j], case_flags[j]) : input[j];
+ }
+ /* else if (input[j] < n) return punycode_bad_input; */
+ /* (not needed for Punycode with unsigned code points) */
+ }
+
+ h = b = out;
+
+ /* h is the number of code points that have been handled, b is the */
+ /* number of basic code points, and out is the number of characters */
+ /* that have been output. */
+
+ if (b > 0) output[out++] = delimiter;
+
+ /* Main encoding loop: */
+
+ while (h < input_length) {
+ /* All non-basic code points < n have been */
+ /* handled already. Find the next larger one: */
+
+ for (m = maxint, j = 0; j < input_length; ++j) {
+ /* if (basic(input[j])) continue; */
+ /* (not needed for Punycode) */
+ if (input[j] >= n && input[j] < m) m = input[j];
+ }
+
+ /* Increase delta enough to advance the decoder's */
+ /* <n,i> state to <m,0>, but guard against overflow: */
+
+ if (m - n > (maxint - delta) / (h + 1)) return punycode_overflow;
+ delta += (m - n) * (h + 1);
+ n = m;
+
+ for (j = 0; j < input_length; ++j) {
+ /* Punycode does not need to check whether input[j] is basic: */
+ if (input[j] < n /* || basic(input[j]) */ ) {
+ if (++delta == 0) return punycode_overflow;
+ }
+
+ if (input[j] == n) {
+ /* Represent delta as a generalized variable-length integer: */
+
+ for (q = delta, k = base; ; k += base) {
+ if (out >= max_out) return punycode_big_output;
+
+ t = k <= bias /* + tmin */ ? tmin : /* +tmin not needed */
+ k >= bias + tmax ? tmax : k - bias;
+ if (q < t) break;
+ output[out++] = encode_digit(t + (q - t) % (base - t), 0);
+ q = (q - t) / (base - t);
+ }
+
+ output[out++] = encode_digit(q, case_flags && case_flags[j]);
+ bias = adapt(delta, h + 1, h == b);
+ delta = 0;
+ ++h;
+ }
+ }
+
+ ++delta, ++n;
+ }
+
+ *output_length = out;
+ return punycode_success;
+}
+
+/*** Main decode function ***/
+
+enum punycode_status punycode_decode(
+ punycode_uint input_length,
+ const char input[],
+ punycode_uint *output_length,
+ punycode_uint output[],
+ unsigned char case_flags[] )
+{
+ punycode_uint n, out, i, max_out, bias,
+ b, j, in, oldi, w, k, digit, t;
+
+ /* Initialize the state: */
+
+ n = initial_n;
+ out = i = 0;
+ max_out = *output_length;
+ bias = initial_bias;
+
+ /* Handle the basic code points: Let b be the number of input code */
+ /* points before the last delimiter, or 0 if there is none, then */
+ /* copy the first b code points to the output. */
+
+ for (b = j = 0; j < input_length; ++j) if (delim(input[j])) b = j;
+ if (b > max_out) return punycode_big_output;
+
+ for (j = 0; j < b; ++j) {
+ if (case_flags) case_flags[out] = flagged(input[j]);
+ if (!basic(input[j])) return punycode_bad_input;
+ output[out++] = input[j];
+ }
+
+ /* Main decoding loop: Start just after the last delimiter if any */
+ /* basic code points were copied; start at the beginning otherwise. */
+
+ for (in = b > 0 ? b + 1 : 0; in < input_length; ++out) {
+
+ /* in is the index of the next character to be consumed, and */
+ /* out is the number of code points in the output array. */
+
+ /* Decode a generalized variable-length integer into delta, */
+ /* which gets added to i. The overflow checking is easier */
+ /* if we increase i as we go, then subtract off its starting */
+ /* value at the end to obtain delta. */
+
+ for (oldi = i, w = 1, k = base; ; k += base) {
+ if (in >= input_length) return punycode_bad_input;
+ digit = decode_digit(input[in++]);
+ if (digit >= base) return punycode_bad_input;
+ if (digit > (maxint - i) / w) return punycode_overflow;
+ i += digit * w;
+ t = k <= bias /* + tmin */ ? tmin : /* +tmin not needed */
+ k >= bias + tmax ? tmax : k - bias;
+ if (digit < t) break;
+ if (w > maxint / (base - t)) return punycode_overflow;
+ w *= (base - t);
+ }
+
+ bias = adapt(i - oldi, out + 1, oldi == 0);
+
+ /* i was supposed to wrap around from out+1 to 0, */
+ /* incrementing n each time, so we'll fix that now: */
+
+ if (i / (out + 1) > maxint - n) return punycode_overflow;
+ n += i / (out + 1);
+ i %= (out + 1);
+
+ /* Insert n at position i of the output: */
+
+ /* not needed for Punycode: */
+ /* if (decode_digit(n) <= base) return punycode_invalid_input; */
+ if (out >= max_out) return punycode_big_output;
+
+ if (case_flags) {
+ memmove(case_flags + i + 1, case_flags + i, out - i);
+
+ /* Case of last character determines uppercase flag: */
+ case_flags[i] = flagged(input[in - 1]);
+ }
+
+ memmove(output + i + 1, output + i, (out - i) * sizeof *output);
+ output[i++] = n;
+ }
+
+ *output_length = out;
+ return punycode_success;
+}
+
diff --git a/project/dclib/lib-mkw-def.c b/project/dclib/lib-mkw-def.c
new file mode 100644
index 0000000..dbd0e5d
--- /dev/null
+++ b/project/dclib/lib-mkw-def.c
@@ -0,0 +1,146 @@
+/************************************************************************
+ * *
+ * _____ ____ *
+ * | __ \ / __ \ _ _ _____ *
+ * | | \ \ / / \_\ | | | | _ \ *
+ * | | \ \| | | | | | |_| | *
+ * | | | || | | | | | ___/ *
+ * | | / /| | __ | | | | _ \ *
+ * | |__/ / \ \__/ / | |___| | |_| | *
+ * |_____/ \____/ |_____|_|_____/ *
+ * *
+ * A php library by Dirk Clemens *
+ * *
+ * Copyright (c) 2014-2022 by Dirk Clemens <develop@cle-mens.de> *
+ * *
+ ************************************************************************
+ * *
+ * This file is generated automatically by a script and is *
+ * therefore always overwritten. So don't EDIT this file, *
+ * because all modifications will be lost with the next update! *
+ * *
+ ************************************************************************/
+
+#include "lib-mkw-def.h"
+
+///////////////////////////////////////////////////////////////////////////////
+
+MkwTrackCategory_t * GetMkwTrackCategory ( int id )
+{
+ static MkwTrackCategory_t id_MTCAT_NINTENDO =
+ {
+ "Original track of Nintendo",
+ 0,
+ G_MTCAT_NINTENDO,
+ "",
+ "n",
+ "Nintendo",
+ };
+
+ static MkwTrackCategory_t id_MTCAT_TEXTURE =
+ {
+ "Accepted texture hack",
+ 0,
+ G_MTCAT_TEXTURE,
+ "green",
+ "t",
+ "Texture",
+ };
+
+ static MkwTrackCategory_t id_MTCAT_DENIED =
+ {
+ "Denied texture hack",
+ 0,
+ G_MTCAT_DENIED,
+ "b_cyan",
+ "d",
+ "Denied",
+ };
+
+ static MkwTrackCategory_t id_MTCAT_EDIT =
+ {
+ "Announced as texture hack, but with more edits",
+ 0,
+ G_MTCAT_EDIT,
+ "b_yellow",
+ "e",
+ "Texture+",
+ };
+
+ static MkwTrackCategory_t id_MTCAT_MODEL =
+ {
+ "Definitely a model hack",
+ 0,
+ G_MTCAT_MODEL,
+ "b_orange",
+ "m",
+ "Model",
+ };
+
+ static MkwTrackCategory_t id_MTCAT_UNKNOWN =
+ {
+ "Unknown track",
+ 0,
+ G_MTCAT_UNKNOWN,
+ "b_red",
+ "u",
+ "Unknown",
+ };
+
+ static MkwTrackCategory_t id_MTCAT_CHEAT =
+ {
+ "Hack clearly created for cheating",
+ 0,
+ G_MTCAT_CHEAT,
+ "b_magenta",
+ "▼",
+ "Cheat",
+ };
+
+ static MkwTrackCategory_t id_MTCAT_CUSTOM =
+ {
+ "Custom track",
+ 0,
+ G_MTCAT_CUSTOM,
+ "cyan_blue",
+ "c",
+ "Custom",
+ };
+
+ static MkwTrackCategory_t id_MTCAT__N =
+ {
+ "(invalid)",
+ 0,
+ G_MTCAT__N,
+ "fail",
+ "?",
+ "-?-",
+ };
+
+ switch(id)
+ {
+ case G_MTCAT_NINTENDO: return &id_MTCAT_NINTENDO;
+ case G_MTCAT_TEXTURE: return &id_MTCAT_TEXTURE;
+ case G_MTCAT_DENIED: return &id_MTCAT_DENIED;
+ case G_MTCAT_EDIT: return &id_MTCAT_EDIT;
+ case G_MTCAT_MODEL: return &id_MTCAT_MODEL;
+ case G_MTCAT_UNKNOWN: return &id_MTCAT_UNKNOWN;
+ case G_MTCAT_CHEAT: return &id_MTCAT_CHEAT;
+ case G_MTCAT_CUSTOM: return &id_MTCAT_CUSTOM;
+ case G_MTCAT__N: return &id_MTCAT__N;
+ default: return 0;
+ };
+}
+
+
+//
+///////////////////////////////////////////////////////////////////////////////
+////////////////////////////////// sizeof /////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+
+const sizeof_info_t sizeof_info_mkw_def[] =
+{
+ SIZEOF_INFO_TITLE("MKW/def structs")
+ SIZEOF_INFO_ENTRY(MkwTrackCategory_t)
+ SIZEOF_INFO_TERM()
+};
diff --git a/project/dclib/lib-mkw-def.h b/project/dclib/lib-mkw-def.h
new file mode 100644
index 0000000..82c73c4
--- /dev/null
+++ b/project/dclib/lib-mkw-def.h
@@ -0,0 +1,80 @@
+/************************************************************************
+ * *
+ * _____ ____ *
+ * | __ \ / __ \ _ _ _____ *
+ * | | \ \ / / \_\ | | | | _ \ *
+ * | | \ \| | | | | | |_| | *
+ * | | | || | | | | | ___/ *
+ * | | / /| | __ | | | | _ \ *
+ * | |__/ / \ \__/ / | |___| | |_| | *
+ * |_____/ \____/ |_____|_|_____/ *
+ * *
+ * A php library by Dirk Clemens *
+ * *
+ * Copyright (c) 2014-2022 by Dirk Clemens <develop@cle-mens.de> *
+ * *
+ ************************************************************************
+ * *
+ * This file is generated automatically by a script and is *
+ * therefore always overwritten. So don't EDIT this file, *
+ * because all modifications will be lost with the next update! *
+ * *
+ ************************************************************************/
+
+#ifndef DCLIB_MKW_DEF_H
+#define DCLIB_MKW_DEF_H 1
+
+#include "dclib-basics.h"
+
+//
+///////////////////////////////////////////////////////////////////////////////
+//////////////////////////// MKW Track Category ///////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+
+// [[MkwTrackCategory]]
+typedef enum MkwTrackCategory
+{
+ G_MTCAT_NINTENDO = 0,
+ G_MTCAT_TEXTURE = 1,
+ G_MTCAT_DENIED = 2,
+ G_MTCAT_ORIG_KMP_KCL = 2,
+ G_MTCAT_EDIT = 3,
+ G_MTCAT_MODEL = 4,
+ G_MTCAT_UNKNOWN = 5,
+ G_MTCAT_CHEAT = 6,
+ G_MTCAT_CUSTOM = 7,
+ G_MTCAT__N = 8,
+}
+MkwTrackCategory;
+
+
+typedef struct MkwTrackCategory_t
+{
+
+ ccp info;
+ int color_offset;
+ u8 id;
+ char color[9+1];
+ char ch[3+1];
+ char title[8+1];
+}
+MkwTrackCategory_t;
+
+MkwTrackCategory_t * GetMkwTrackCategory ( int id );
+
+
+//
+///////////////////////////////////////////////////////////////////////////////
+////////////////////////////////// sizeof /////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+
+extern const sizeof_info_t sizeof_info_mkw_def[];
+
+//
+///////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////// E N D /////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+
+
+#endif // DCLIB_MKW_DEF_H
+