gcores ~/apps/Menu branch first commit
|
Before Width: | Height: | Size: 17 KiB |
@@ -1 +0,0 @@
|
||||
./DinguxCommander
|
||||
|
Before Width: | Height: | Size: 713 B |
|
Before Width: | Height: | Size: 353 B |
|
Before Width: | Height: | Size: 307 B |
|
Before Width: | Height: | Size: 1.2 KiB |
|
Before Width: | Height: | Size: 272 B |
@@ -1 +0,0 @@
|
||||
./bean
|
||||
@@ -1,57 +0,0 @@
|
||||
|
||||
********************************************************************************************
|
||||
bean
|
||||
********************************************************************************************
|
||||
|
||||
...
|
||||
|
||||
********************************************************************************************
|
||||
sljit
|
||||
********************************************************************************************
|
||||
|
||||
Stack-less Just-In-Time compiler
|
||||
|
||||
Copyright Zoltan Herczeg (hzmester@freemail.hu). All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are
|
||||
permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
of conditions and the following disclaimer in the documentation and/or other materials
|
||||
provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND CONTRIBUTORS ``AS IS'' AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
||||
SHALL THE COPYRIGHT HOLDER(S) OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
********************************************************************************************
|
||||
icons/rpg
|
||||
********************************************************************************************
|
||||
|
||||
https://opengameart.org/content/496-pixel-art-icons-for-medievalfantasy-rpg
|
||||
|
||||
********************************************************************************************
|
||||
icons/console
|
||||
********************************************************************************************
|
||||
|
||||
https://pyra-handheld.com/boards/resources/emulator-console-konsolen-game-icons.1471/
|
||||
|
||||
********************************************************************************************
|
||||
cores/pcsx_rearmed_libretro.so
|
||||
cores/picodrive_libretro.so
|
||||
********************************************************************************************
|
||||
|
||||
https://github.com/Vilikt/cpi_libretro_enhanced_cores
|
||||
|
||||
********************************************************************************************
|
||||
EOF
|
||||
********************************************************************************************
|
||||
@@ -1,3 +0,0 @@
|
||||
skin = "default"
|
||||
font = "unifont-12.0.01.ttf"
|
||||
outlined_font = "false"
|
||||
@@ -1,16 +0,0 @@
|
||||
|
||||
/*
|
||||
BeanShell
|
||||
*/
|
||||
|
||||
// runtime
|
||||
include_dir "beans/runtime"
|
||||
|
||||
// std
|
||||
include_dir "beans/std"
|
||||
|
||||
// lib
|
||||
include_dir "beans/lib"
|
||||
|
||||
// program
|
||||
include_dir "beans/shell"
|
||||
@@ -1,402 +0,0 @@
|
||||
|
||||
// 7.63.0
|
||||
|
||||
module lib+ {
|
||||
|
||||
module curl+ {
|
||||
|
||||
module so {
|
||||
|
||||
struct struct {
|
||||
curl_easy_cleanup void;
|
||||
curl_easy_getinfo void;
|
||||
curl_easy_init void;
|
||||
curl_easy_perform void;
|
||||
curl_easy_setopt void;
|
||||
curl_easy_strerror void;
|
||||
curl_global_cleanup void;
|
||||
curl_global_init void;
|
||||
curl_slist_append void;
|
||||
curl_slist_free_all void;
|
||||
}
|
||||
|
||||
var fn struct;
|
||||
|
||||
func init() bool {
|
||||
import rt::c;
|
||||
return dlsyms(dlopen("libcurl.so.4", RTLD_LAZY), &fn,
|
||||
"curl_easy_cleanup",
|
||||
"curl_easy_getinfo",
|
||||
"curl_easy_init",
|
||||
"curl_easy_perform",
|
||||
"curl_easy_setopt",
|
||||
"curl_easy_strerror",
|
||||
"curl_global_cleanup",
|
||||
"curl_global_init",
|
||||
"curl_slist_append",
|
||||
"curl_slist_free_all"
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module curl+ {
|
||||
|
||||
enum CURLcode;
|
||||
enum {
|
||||
CURLE_OK = 0,
|
||||
CURLE_UNSUPPORTED_PROTOCOL, /* 1 */
|
||||
CURLE_FAILED_INIT, /* 2 */
|
||||
CURLE_URL_MALFORMAT, /* 3 */
|
||||
CURLE_NOT_BUILT_IN, /* 4 - [was obsoleted in August 2007 for
|
||||
7.17.0, reused in April 2011 for 7.21.5] */
|
||||
CURLE_COULDNT_RESOLVE_PROXY, /* 5 */
|
||||
CURLE_COULDNT_RESOLVE_HOST, /* 6 */
|
||||
CURLE_COULDNT_CONNECT, /* 7 */
|
||||
CURLE_WEIRD_SERVER_REPLY, /* 8 */
|
||||
CURLE_REMOTE_ACCESS_DENIED, /* 9 a service was denied by the server
|
||||
due to lack of access - when login fails
|
||||
this is not returned. */
|
||||
CURLE_FTP_ACCEPT_FAILED, /* 10 - [was obsoleted in April 2006 for
|
||||
7.15.4, reused in Dec 2011 for 7.24.0]*/
|
||||
CURLE_FTP_WEIRD_PASS_REPLY, /* 11 */
|
||||
CURLE_FTP_ACCEPT_TIMEOUT, /* 12 - timeout occurred accepting server
|
||||
[was obsoleted in August 2007 for 7.17.0,
|
||||
reused in Dec 2011 for 7.24.0]*/
|
||||
CURLE_FTP_WEIRD_PASV_REPLY, /* 13 */
|
||||
CURLE_FTP_WEIRD_227_FORMAT, /* 14 */
|
||||
CURLE_FTP_CANT_GET_HOST, /* 15 */
|
||||
CURLE_HTTP2, /* 16 - A problem in the http2 framing layer.
|
||||
[was obsoleted in August 2007 for 7.17.0,
|
||||
reused in July 2014 for 7.38.0] */
|
||||
CURLE_FTP_COULDNT_SET_TYPE, /* 17 */
|
||||
CURLE_PARTIAL_FILE, /* 18 */
|
||||
CURLE_FTP_COULDNT_RETR_FILE, /* 19 */
|
||||
CURLE_OBSOLETE20, /* 20 - NOT USED */
|
||||
CURLE_QUOTE_ERROR, /* 21 - quote command failure */
|
||||
CURLE_HTTP_RETURNED_ERROR, /* 22 */
|
||||
CURLE_WRITE_ERROR, /* 23 */
|
||||
CURLE_OBSOLETE24, /* 24 - NOT USED */
|
||||
CURLE_UPLOAD_FAILED, /* 25 - failed upload "command" */
|
||||
CURLE_READ_ERROR, /* 26 - couldn't open/read from file */
|
||||
CURLE_OUT_OF_MEMORY, /* 27 */
|
||||
/* Note: CURLE_OUT_OF_MEMORY may sometimes indicate a conversion error
|
||||
instead of a memory allocation error if CURL_DOES_CONVERSIONS
|
||||
is defined
|
||||
*/
|
||||
CURLE_OPERATION_TIMEDOUT, /* 28 - the timeout time was reached */
|
||||
CURLE_OBSOLETE29, /* 29 - NOT USED */
|
||||
CURLE_FTP_PORT_FAILED, /* 30 - FTP PORT operation failed */
|
||||
CURLE_FTP_COULDNT_USE_REST, /* 31 - the REST command failed */
|
||||
CURLE_OBSOLETE32, /* 32 - NOT USED */
|
||||
CURLE_RANGE_ERROR, /* 33 - RANGE "command" didn't work */
|
||||
CURLE_HTTP_POST_ERROR, /* 34 */
|
||||
CURLE_SSL_CONNECT_ERROR, /* 35 - wrong when connecting with SSL */
|
||||
CURLE_BAD_DOWNLOAD_RESUME, /* 36 - couldn't resume download */
|
||||
CURLE_FILE_COULDNT_READ_FILE, /* 37 */
|
||||
CURLE_LDAP_CANNOT_BIND, /* 38 */
|
||||
CURLE_LDAP_SEARCH_FAILED, /* 39 */
|
||||
CURLE_OBSOLETE40, /* 40 - NOT USED */
|
||||
CURLE_FUNCTION_NOT_FOUND, /* 41 - NOT USED starting with 7.53.0 */
|
||||
CURLE_ABORTED_BY_CALLBACK, /* 42 */
|
||||
CURLE_BAD_FUNCTION_ARGUMENT, /* 43 */
|
||||
CURLE_OBSOLETE44, /* 44 - NOT USED */
|
||||
CURLE_INTERFACE_FAILED, /* 45 - CURLOPT_INTERFACE failed */
|
||||
CURLE_OBSOLETE46, /* 46 - NOT USED */
|
||||
CURLE_TOO_MANY_REDIRECTS, /* 47 - catch endless re-direct loops */
|
||||
CURLE_UNKNOWN_OPTION, /* 48 - User specified an unknown option */
|
||||
CURLE_TELNET_OPTION_SYNTAX, /* 49 - Malformed telnet option */
|
||||
CURLE_OBSOLETE50, /* 50 - NOT USED */
|
||||
CURLE_OBSOLETE51, /* 51 - NOT USED */
|
||||
CURLE_GOT_NOTHING, /* 52 - when this is a specific error */
|
||||
CURLE_SSL_ENGINE_NOTFOUND, /* 53 - SSL crypto engine not found */
|
||||
CURLE_SSL_ENGINE_SETFAILED, /* 54 - can not set SSL crypto engine as
|
||||
default */
|
||||
CURLE_SEND_ERROR, /* 55 - failed sending network data */
|
||||
CURLE_RECV_ERROR, /* 56 - failure in receiving network data */
|
||||
CURLE_OBSOLETE57, /* 57 - NOT IN USE */
|
||||
CURLE_SSL_CERTPROBLEM, /* 58 - problem with the local certificate */
|
||||
CURLE_SSL_CIPHER, /* 59 - couldn't use specified cipher */
|
||||
CURLE_PEER_FAILED_VERIFICATION, /* 60 - peer's certificate or fingerprint
|
||||
wasn't verified fine */
|
||||
CURLE_BAD_CONTENT_ENCODING, /* 61 - Unrecognized/bad encoding */
|
||||
CURLE_LDAP_INVALID_URL, /* 62 - Invalid LDAP URL */
|
||||
CURLE_FILESIZE_EXCEEDED, /* 63 - Maximum file size exceeded */
|
||||
CURLE_USE_SSL_FAILED, /* 64 - Requested FTP SSL level failed */
|
||||
CURLE_SEND_FAIL_REWIND, /* 65 - Sending the data requires a rewind
|
||||
that failed */
|
||||
CURLE_SSL_ENGINE_INITFAILED, /* 66 - failed to initialise ENGINE */
|
||||
CURLE_LOGIN_DENIED, /* 67 - user, password or similar was not
|
||||
accepted and we failed to login */
|
||||
CURLE_TFTP_NOTFOUND, /* 68 - file not found on server */
|
||||
CURLE_TFTP_PERM, /* 69 - permission problem on server */
|
||||
CURLE_REMOTE_DISK_FULL, /* 70 - out of disk space on server */
|
||||
CURLE_TFTP_ILLEGAL, /* 71 - Illegal TFTP operation */
|
||||
CURLE_TFTP_UNKNOWNID, /* 72 - Unknown transfer ID */
|
||||
CURLE_REMOTE_FILE_EXISTS, /* 73 - File already exists */
|
||||
CURLE_TFTP_NOSUCHUSER, /* 74 - No such user */
|
||||
CURLE_CONV_FAILED, /* 75 - conversion failed */
|
||||
CURLE_CONV_REQD, /* 76 - caller must register conversion
|
||||
callbacks using curl_easy_setopt options
|
||||
CURLOPT_CONV_FROM_NETWORK_FUNCTION,
|
||||
CURLOPT_CONV_TO_NETWORK_FUNCTION, and
|
||||
CURLOPT_CONV_FROM_UTF8_FUNCTION */
|
||||
CURLE_SSL_CACERT_BADFILE, /* 77 - could not load CACERT file, missing
|
||||
or wrong format */
|
||||
CURLE_REMOTE_FILE_NOT_FOUND, /* 78 - remote file not found */
|
||||
CURLE_SSH, /* 79 - error from the SSH layer, somewhat
|
||||
generic so the error message will be of
|
||||
interest when this has happened */
|
||||
|
||||
CURLE_SSL_SHUTDOWN_FAILED, /* 80 - Failed to shut down the SSL
|
||||
connection */
|
||||
CURLE_AGAIN, /* 81 - socket is not ready for send/recv,
|
||||
wait till it's ready and try again (Added
|
||||
in 7.18.2) */
|
||||
CURLE_SSL_CRL_BADFILE, /* 82 - could not load CRL file, missing or
|
||||
wrong format (Added in 7.19.0) */
|
||||
CURLE_SSL_ISSUER_ERROR, /* 83 - Issuer check failed. (Added in
|
||||
7.19.0) */
|
||||
CURLE_FTP_PRET_FAILED, /* 84 - a PRET command failed */
|
||||
CURLE_RTSP_CSEQ_ERROR, /* 85 - mismatch of RTSP CSeq numbers */
|
||||
CURLE_RTSP_SESSION_ERROR, /* 86 - mismatch of RTSP Session Ids */
|
||||
CURLE_FTP_BAD_FILE_LIST, /* 87 - unable to parse FTP file list */
|
||||
CURLE_CHUNK_FAILED, /* 88 - chunk callback reported error */
|
||||
CURLE_NO_CONNECTION_AVAILABLE, /* 89 - No connection available, the
|
||||
session will be queued */
|
||||
CURLE_SSL_PINNEDPUBKEYNOTMATCH, /* 90 - specified pinned public key did not
|
||||
match */
|
||||
CURLE_SSL_INVALIDCERTSTATUS, /* 91 - invalid certificate status */
|
||||
CURLE_HTTP2_STREAM, /* 92 - stream error in HTTP/2 framing layer
|
||||
*/
|
||||
CURLE_RECURSIVE_API_CALL, /* 93 - an api function was called from
|
||||
inside a callback */
|
||||
CURL_LAST /* never use! */
|
||||
}
|
||||
|
||||
define {
|
||||
CURL_GLOBAL_SSL = 1 << 0; /* no purpose since since 7.57.0 */
|
||||
CURL_GLOBAL_WIN32 = 1 << 1;
|
||||
CURL_GLOBAL_ALL = CURL_GLOBAL_SSL | CURL_GLOBAL_WIN32;
|
||||
CURL_GLOBAL_NOTHING = 0;
|
||||
CURL_GLOBAL_DEFAULT = CURL_GLOBAL_ALL;
|
||||
CURL_GLOBAL_ACK_EINTR = 1 << 2;
|
||||
}
|
||||
|
||||
enum {
|
||||
CURL_HTTP_VERSION_NONE, /* setting this means we don't care, and that we'd
|
||||
like the library to choose the best possible
|
||||
for us! */
|
||||
CURL_HTTP_VERSION_1_0, /* please use HTTP 1.0 in the request */
|
||||
CURL_HTTP_VERSION_1_1, /* please use HTTP 1.1 in the request */
|
||||
CURL_HTTP_VERSION_2_0, /* please use HTTP 2 in the request */
|
||||
CURL_HTTP_VERSION_2TLS, /* use version 2 for HTTPS, version 1.1 for HTTP */
|
||||
CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE, /* please use HTTP 2 without HTTP/1.1
|
||||
Upgrade */
|
||||
|
||||
CURL_HTTP_VERSION_LAST /* *ILLEGAL* http version */
|
||||
}
|
||||
|
||||
enum curl_proxytype; /* this enum was added in 7.10 */
|
||||
enum {
|
||||
CURLPROXY_HTTP = 0, /* added in 7.10, new in 7.19.4 default is to use
|
||||
CONNECT HTTP/1.1 */
|
||||
CURLPROXY_HTTP_1_0 = 1, /* added in 7.19.4, force to use CONNECT
|
||||
HTTP/1.0 */
|
||||
CURLPROXY_HTTPS = 2, /* added in 7.52.0 */
|
||||
CURLPROXY_SOCKS4 = 4, /* support added in 7.15.2, enum existed already
|
||||
in 7.10 */
|
||||
CURLPROXY_SOCKS5 = 5, /* added in 7.10 */
|
||||
CURLPROXY_SOCKS4A = 6, /* added in 7.18.0 */
|
||||
CURLPROXY_SOCKS5_HOSTNAME = 7 /* Use the SOCKS5 protocol but pass along the
|
||||
host name rather than the IP address. added
|
||||
in 7.18.0 */
|
||||
}
|
||||
|
||||
define {
|
||||
CURLOPTTYPE_LONG = 0;
|
||||
CURLOPTTYPE_OBJECTPOINT = 10000;
|
||||
CURLOPTTYPE_STRINGPOINT = 10000;
|
||||
CURLOPTTYPE_FUNCTIONPOINT = 20000;
|
||||
CURLOPTTYPE_OFF_T = 30000;
|
||||
}
|
||||
|
||||
enum CURLoption;
|
||||
|
||||
// xxx
|
||||
define {
|
||||
CURLOPT_WRITEDATA = CURLOPTTYPE_OBJECTPOINT + 1;
|
||||
CURLOPT_URL = CURLOPTTYPE_STRINGPOINT + 2;
|
||||
CURLOPT_PROXY = CURLOPTTYPE_STRINGPOINT + 4;
|
||||
CURLOPT_USERPWD = CURLOPTTYPE_STRINGPOINT + 5;
|
||||
CURLOPT_PROXYUSERPWD = CURLOPTTYPE_STRINGPOINT + 6;
|
||||
CURLOPT_READDATA = CURLOPTTYPE_OBJECTPOINT + 9;
|
||||
CURLOPT_WRITEFUNCTION = CURLOPTTYPE_FUNCTIONPOINT + 11;
|
||||
CURLOPT_READFUNCTION = CURLOPTTYPE_FUNCTIONPOINT + 12;
|
||||
CURLOPT_TIMEOUT = CURLOPTTYPE_LONG + 13;
|
||||
CURLOPT_INFILESIZE = CURLOPTTYPE_LONG + 14;
|
||||
CURLOPT_POSTFIELDS = CURLOPTTYPE_OBJECTPOINT + 15;
|
||||
CURLOPT_HTTPHEADER = CURLOPTTYPE_OBJECTPOINT + 23;
|
||||
CURLOPT_HEADERDATA = CURLOPTTYPE_OBJECTPOINT + 29;
|
||||
CURLOPT_COOKIEFILE = CURLOPTTYPE_STRINGPOINT + 31;
|
||||
CURLOPT_CUSTOMREQUEST = CURLOPTTYPE_STRINGPOINT + 36;
|
||||
CURLOPT_VERBOSE = CURLOPTTYPE_LONG + 41;
|
||||
CURLOPT_FAILONERROR = CURLOPTTYPE_LONG + 45;
|
||||
CURLOPT_UPLOAD = CURLOPTTYPE_LONG + 46;
|
||||
CURLOPT_POST = CURLOPTTYPE_LONG + 47;
|
||||
CURLOPT_FOLLOWLOCATION = CURLOPTTYPE_LONG + 52;
|
||||
CURLOPT_PUT = CURLOPTTYPE_LONG + 54;
|
||||
CURLOPT_POSTFIELDSIZE = CURLOPTTYPE_LONG + 60;
|
||||
CURLOPT_HTTPPROXYTUNNEL = CURLOPTTYPE_LONG + 61;
|
||||
CURLOPT_SSL_VERIFYPEER = CURLOPTTYPE_LONG + 64;
|
||||
CURLOPT_CONNECTTIMEOUT = CURLOPTTYPE_LONG + 78;
|
||||
CURLOPT_HEADERFUNCTION = CURLOPTTYPE_FUNCTIONPOINT + 79;
|
||||
CURLOPT_SSL_VERIFYHOST = CURLOPTTYPE_LONG + 81;
|
||||
CURLOPT_COOKIEJAR = CURLOPTTYPE_STRINGPOINT + 82;
|
||||
CURLOPT_HTTP_VERSION = CURLOPTTYPE_LONG + 84;
|
||||
CURLOPT_NOSIGNAL = CURLOPTTYPE_LONG + 99;
|
||||
CURLOPT_PROXYTYPE = CURLOPTTYPE_LONG + 101;
|
||||
CURLOPT_COPYPOSTFIELDS = CURLOPTTYPE_OBJECTPOINT + 165;
|
||||
CURLOPT_USERNAME = CURLOPTTYPE_STRINGPOINT + 173;
|
||||
CURLOPT_PASSWORD = CURLOPTTYPE_STRINGPOINT + 174;
|
||||
CURLOPT_PROXYUSERNAME = CURLOPTTYPE_STRINGPOINT + 175;
|
||||
CURLOPT_PROXYPASSWORD = CURLOPTTYPE_STRINGPOINT + 176;
|
||||
CURLOPT_MAIL_FROM = CURLOPTTYPE_STRINGPOINT + 186;
|
||||
CURLOPT_MAIL_RCPT = CURLOPTTYPE_OBJECTPOINT + 187;
|
||||
}
|
||||
|
||||
define {
|
||||
CURLINFO_STRING = 0x100000;
|
||||
CURLINFO_LONG = 0x200000;
|
||||
CURLINFO_DOUBLE = 0x300000;
|
||||
CURLINFO_SLIST = 0x400000;
|
||||
CURLINFO_PTR = 0x400000; /* same as SLIST */
|
||||
CURLINFO_SOCKET = 0x500000;
|
||||
CURLINFO_OFF_T = 0x600000;
|
||||
CURLINFO_MASK = 0x0fffff;
|
||||
CURLINFO_TYPEMASK = 0xf00000;
|
||||
}
|
||||
|
||||
enum CURLINFO;
|
||||
enum {
|
||||
CURLINFO_NONE, /* first, never use this */
|
||||
CURLINFO_EFFECTIVE_URL = CURLINFO_STRING + 1,
|
||||
CURLINFO_RESPONSE_CODE = CURLINFO_LONG + 2,
|
||||
CURLINFO_TOTAL_TIME = CURLINFO_DOUBLE + 3,
|
||||
CURLINFO_NAMELOOKUP_TIME = CURLINFO_DOUBLE + 4,
|
||||
CURLINFO_CONNECT_TIME = CURLINFO_DOUBLE + 5,
|
||||
CURLINFO_PRETRANSFER_TIME = CURLINFO_DOUBLE + 6,
|
||||
CURLINFO_SIZE_UPLOAD = CURLINFO_DOUBLE + 7,
|
||||
CURLINFO_SIZE_UPLOAD_T = CURLINFO_OFF_T + 7,
|
||||
CURLINFO_SIZE_DOWNLOAD = CURLINFO_DOUBLE + 8,
|
||||
CURLINFO_SIZE_DOWNLOAD_T = CURLINFO_OFF_T + 8,
|
||||
CURLINFO_SPEED_DOWNLOAD = CURLINFO_DOUBLE + 9,
|
||||
CURLINFO_SPEED_DOWNLOAD_T = CURLINFO_OFF_T + 9,
|
||||
CURLINFO_SPEED_UPLOAD = CURLINFO_DOUBLE + 10,
|
||||
CURLINFO_SPEED_UPLOAD_T = CURLINFO_OFF_T + 10,
|
||||
CURLINFO_HEADER_SIZE = CURLINFO_LONG + 11,
|
||||
CURLINFO_REQUEST_SIZE = CURLINFO_LONG + 12,
|
||||
CURLINFO_SSL_VERIFYRESULT = CURLINFO_LONG + 13,
|
||||
CURLINFO_FILETIME = CURLINFO_LONG + 14,
|
||||
CURLINFO_FILETIME_T = CURLINFO_OFF_T + 14,
|
||||
CURLINFO_CONTENT_LENGTH_DOWNLOAD = CURLINFO_DOUBLE + 15,
|
||||
CURLINFO_CONTENT_LENGTH_DOWNLOAD_T = CURLINFO_OFF_T + 15,
|
||||
CURLINFO_CONTENT_LENGTH_UPLOAD = CURLINFO_DOUBLE + 16,
|
||||
CURLINFO_CONTENT_LENGTH_UPLOAD_T = CURLINFO_OFF_T + 16,
|
||||
CURLINFO_STARTTRANSFER_TIME = CURLINFO_DOUBLE + 17,
|
||||
CURLINFO_CONTENT_TYPE = CURLINFO_STRING + 18,
|
||||
CURLINFO_REDIRECT_TIME = CURLINFO_DOUBLE + 19,
|
||||
CURLINFO_REDIRECT_COUNT = CURLINFO_LONG + 20,
|
||||
CURLINFO_PRIVATE = CURLINFO_STRING + 21,
|
||||
CURLINFO_HTTP_CONNECTCODE = CURLINFO_LONG + 22,
|
||||
CURLINFO_HTTPAUTH_AVAIL = CURLINFO_LONG + 23,
|
||||
CURLINFO_PROXYAUTH_AVAIL = CURLINFO_LONG + 24,
|
||||
CURLINFO_OS_ERRNO = CURLINFO_LONG + 25,
|
||||
CURLINFO_NUM_CONNECTS = CURLINFO_LONG + 26,
|
||||
CURLINFO_SSL_ENGINES = CURLINFO_SLIST + 27,
|
||||
CURLINFO_COOKIELIST = CURLINFO_SLIST + 28,
|
||||
CURLINFO_LASTSOCKET = CURLINFO_LONG + 29,
|
||||
CURLINFO_FTP_ENTRY_PATH = CURLINFO_STRING + 30,
|
||||
CURLINFO_REDIRECT_URL = CURLINFO_STRING + 31,
|
||||
CURLINFO_PRIMARY_IP = CURLINFO_STRING + 32,
|
||||
CURLINFO_APPCONNECT_TIME = CURLINFO_DOUBLE + 33,
|
||||
CURLINFO_CERTINFO = CURLINFO_PTR + 34,
|
||||
CURLINFO_CONDITION_UNMET = CURLINFO_LONG + 35,
|
||||
CURLINFO_RTSP_SESSION_ID = CURLINFO_STRING + 36,
|
||||
CURLINFO_RTSP_CLIENT_CSEQ = CURLINFO_LONG + 37,
|
||||
CURLINFO_RTSP_SERVER_CSEQ = CURLINFO_LONG + 38,
|
||||
CURLINFO_RTSP_CSEQ_RECV = CURLINFO_LONG + 39,
|
||||
CURLINFO_PRIMARY_PORT = CURLINFO_LONG + 40,
|
||||
CURLINFO_LOCAL_IP = CURLINFO_STRING + 41,
|
||||
CURLINFO_LOCAL_PORT = CURLINFO_LONG + 42,
|
||||
CURLINFO_TLS_SESSION = CURLINFO_PTR + 43,
|
||||
CURLINFO_ACTIVESOCKET = CURLINFO_SOCKET + 44,
|
||||
CURLINFO_TLS_SSL_PTR = CURLINFO_PTR + 45,
|
||||
CURLINFO_HTTP_VERSION = CURLINFO_LONG + 46,
|
||||
CURLINFO_PROXY_SSL_VERIFYRESULT = CURLINFO_LONG + 47,
|
||||
CURLINFO_PROTOCOL = CURLINFO_LONG + 48,
|
||||
CURLINFO_SCHEME = CURLINFO_STRING + 49,
|
||||
/* Fill in new entries below here! */
|
||||
|
||||
/* Preferably these would be defined conditionally based on the
|
||||
sizeof curl_off_t being 64-bits */
|
||||
CURLINFO_TOTAL_TIME_T = CURLINFO_OFF_T + 50,
|
||||
CURLINFO_NAMELOOKUP_TIME_T = CURLINFO_OFF_T + 51,
|
||||
CURLINFO_CONNECT_TIME_T = CURLINFO_OFF_T + 52,
|
||||
CURLINFO_PRETRANSFER_TIME_T = CURLINFO_OFF_T + 53,
|
||||
CURLINFO_STARTTRANSFER_TIME_T = CURLINFO_OFF_T + 54,
|
||||
CURLINFO_REDIRECT_TIME_T = CURLINFO_OFF_T + 55,
|
||||
CURLINFO_APPCONNECT_TIME_T = CURLINFO_OFF_T + 56,
|
||||
|
||||
CURLINFO_LASTONE = 56
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module curl+ {
|
||||
|
||||
inline curl_easy_cleanup(curl+ CURL) {
|
||||
call1<void>(so::fn.curl_easy_cleanup, curl);
|
||||
}
|
||||
|
||||
inline curl_easy_getinfo(curl+ CURL, info CURLINFO, value word) CURLcode {
|
||||
return call3<CURLcode>(so::fn.curl_easy_getinfo, curl, info, value);
|
||||
}
|
||||
|
||||
inline curl_easy_init() +CURL {
|
||||
return call<void>(so::fn.curl_easy_init);
|
||||
}
|
||||
|
||||
inline curl_easy_perform(curl+ CURL) CURLcode {
|
||||
return call1<CURLcode>(so::fn.curl_easy_perform, curl);
|
||||
}
|
||||
|
||||
inline curl_easy_setopt(curl+ CURL, option CURLoption, value word) CURLcode {
|
||||
return call3<CURLcode>(so::fn.curl_easy_setopt, curl, option, value);
|
||||
}
|
||||
|
||||
inline curl_easy_strerror(code CURLcode) .char {
|
||||
return call1<char*>(so::fn.curl_easy_strerror, code);
|
||||
}
|
||||
|
||||
inline curl_global_cleanup() {
|
||||
call<void>(so::fn.curl_global_cleanup);
|
||||
}
|
||||
|
||||
inline curl_global_init(flags long = CURL_GLOBAL_DEFAULT) CURLcode {
|
||||
return call1<CURLcode>(so::fn.curl_global_init, flags);
|
||||
}
|
||||
|
||||
inline curl_slist_append(slist+ curl_slist, str. char) +curl_slist {
|
||||
return call2<void>(so::fn.curl_slist_append, slist, str);
|
||||
}
|
||||
|
||||
inline curl_slist_free_all(slist+ curl_slist) {
|
||||
call1<void>(so::fn.curl_slist_free_all, slist);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,454 +0,0 @@
|
||||
|
||||
// 1.12
|
||||
|
||||
module lib+ {
|
||||
|
||||
module dbus+ {
|
||||
|
||||
module so {
|
||||
|
||||
struct struct {
|
||||
dbus_error_init void;
|
||||
dbus_error_free void;
|
||||
dbus_error_is_set void;
|
||||
dbus_bus_add_match void;
|
||||
dbus_bus_get void;
|
||||
dbus_bus_get_unique_name void;
|
||||
dbus_bus_request_name void;
|
||||
dbus_connection_send void;
|
||||
dbus_connection_send_with_reply void;
|
||||
dbus_connection_read_write void;
|
||||
dbus_connection_pop_message void;
|
||||
dbus_connection_flush void;
|
||||
dbus_connection_close void;
|
||||
dbus_message_new_signal void;
|
||||
dbus_message_new_method_call void;
|
||||
dbus_message_new_method_return void;
|
||||
dbus_message_iter_init void;
|
||||
dbus_message_iter_init_append void;
|
||||
dbus_message_iter_next void;
|
||||
dbus_message_iter_get_basic void;
|
||||
dbus_message_iter_get_arg_type void;
|
||||
dbus_message_iter_append_basic void;
|
||||
dbus_message_get_type void;
|
||||
dbus_message_is_signal void;
|
||||
dbus_message_is_method_call void;
|
||||
dbus_message_unref void;
|
||||
dbus_pending_call_block void;
|
||||
dbus_pending_call_steal_reply void;
|
||||
dbus_pending_call_unref void;
|
||||
}
|
||||
|
||||
var fn struct;
|
||||
|
||||
func init() bool {
|
||||
import rt::c;
|
||||
return dlsyms(dlopen("libdbus-1.so", RTLD_LAZY), &fn,
|
||||
"dbus_error_init",
|
||||
"dbus_error_free",
|
||||
"dbus_error_is_set",
|
||||
"dbus_bus_add_match",
|
||||
"dbus_bus_get",
|
||||
"dbus_bus_get_unique_name",
|
||||
"dbus_bus_request_name",
|
||||
"dbus_connection_send",
|
||||
"dbus_connection_send_with_reply",
|
||||
"dbus_connection_read_write",
|
||||
"dbus_connection_pop_message",
|
||||
"dbus_connection_flush",
|
||||
"dbus_connection_close",
|
||||
"dbus_message_new_signal",
|
||||
"dbus_message_new_method_call",
|
||||
"dbus_message_new_method_return",
|
||||
"dbus_message_iter_init",
|
||||
"dbus_message_iter_init_append",
|
||||
"dbus_message_iter_next",
|
||||
"dbus_message_iter_get_basic",
|
||||
"dbus_message_iter_get_arg_type",
|
||||
"dbus_message_iter_append_basic",
|
||||
"dbus_message_get_type",
|
||||
"dbus_message_is_signal",
|
||||
"dbus_message_is_method_call",
|
||||
"dbus_message_unref",
|
||||
"dbus_pending_call_block",
|
||||
"dbus_pending_call_steal_reply",
|
||||
"dbus_pending_call_unref"
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module dbus+ {
|
||||
|
||||
/**
|
||||
* Well-known bus types. See dbus_bus_get().
|
||||
*/
|
||||
enum DBusBusType;
|
||||
enum {
|
||||
DBUS_BUS_SESSION, /**< The login session bus */
|
||||
DBUS_BUS_SYSTEM, /**< The systemwide bus */
|
||||
DBUS_BUS_STARTER /**< The bus that started us, if any */
|
||||
}
|
||||
|
||||
/**
|
||||
* Results that a message handler can return.
|
||||
*/
|
||||
enum DBusHandlerResult;
|
||||
enum {
|
||||
DBUS_HANDLER_RESULT_HANDLED, /**< Message has had its effect - no need to run more handlers. */
|
||||
DBUS_HANDLER_RESULT_NOT_YET_HANDLED, /**< Message has not had any effect - see if other handlers want it. */
|
||||
DBUS_HANDLER_RESULT_NEED_MEMORY /**< Need more memory in order to return #DBUS_HANDLER_RESULT_HANDLED or #DBUS_HANDLER_RESULT_NOT_YET_HANDLED. Please try again later with more memory. */
|
||||
}
|
||||
|
||||
/* Owner flags */
|
||||
define {
|
||||
DBUS_NAME_FLAG_ALLOW_REPLACEMENT = 0x1; /**< Allow another service to become the primary owner if requested */
|
||||
DBUS_NAME_FLAG_REPLACE_EXISTING = 0x2; /**< Request to replace the current primary owner */
|
||||
DBUS_NAME_FLAG_DO_NOT_QUEUE = 0x4; /**< If we can not become the primary owner do not place us in the queue */
|
||||
}
|
||||
|
||||
/* Replies to request for a name */
|
||||
define {
|
||||
DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER = 1; /**< Service has become the primary owner of the requested name */
|
||||
DBUS_REQUEST_NAME_REPLY_IN_QUEUE = 2; /**< Service could not become the primary owner and has been placed in the queue */
|
||||
DBUS_REQUEST_NAME_REPLY_EXISTS = 3; /**< Service is already in the queue */
|
||||
DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER = 4; /**< Service is already the primary owner */
|
||||
}
|
||||
|
||||
/* Replies to releasing a name */
|
||||
define {
|
||||
DBUS_RELEASE_NAME_REPLY_RELEASED = 1; /**< Service was released from the given name */
|
||||
DBUS_RELEASE_NAME_REPLY_NON_EXISTENT = 2; /**< The given name does not exist on the bus */
|
||||
DBUS_RELEASE_NAME_REPLY_NOT_OWNER = 3; /**< Service is not an owner of the given name */
|
||||
}
|
||||
|
||||
/* Replies to service starts */
|
||||
define {
|
||||
DBUS_START_REPLY_SUCCESS = 1; /**< Service was auto started */
|
||||
DBUS_START_REPLY_ALREADY_RUNNING = 2; /**< Service was already running */
|
||||
}
|
||||
|
||||
typedef dbus_int64_t int64;
|
||||
typedef dbus_uint64_t unsigned int64;
|
||||
typedef dbus_int32_t int32;
|
||||
typedef dbus_uint32_t unsigned int32;
|
||||
typedef dbus_int16_t int16;
|
||||
typedef dbus_uint16_t unsigned int16;
|
||||
typedef dbus_unichar_t dbus_uint32_t;
|
||||
typedef dbus_bool_t dbus_uint32_t;
|
||||
|
||||
/**
|
||||
* An 8-byte struct you could use to access int64 without having
|
||||
* int64 support. Use #dbus_int64_t or #dbus_uint64_t instead.
|
||||
*/
|
||||
struct DBus8ByteStruct {
|
||||
first32 dbus_uint32_t; /**< first 32 bits in the 8 bytes (beware endian issues) */
|
||||
second32 dbus_uint32_t; /**< second 32 bits in the 8 bytes (beware endian issues) */
|
||||
}
|
||||
|
||||
/**
|
||||
* A simple value union that lets you access bytes as if they
|
||||
* were various types; useful when dealing with basic types via
|
||||
* void pointers and varargs.
|
||||
*
|
||||
* This union also contains a pointer member (which can be used
|
||||
* to retrieve a string from dbus_message_iter_get_basic(), for
|
||||
* instance), so on future platforms it could conceivably be larger
|
||||
* than 8 bytes.
|
||||
*/
|
||||
union DBusBasicValue {
|
||||
bytes(8) unsigned char; /**< as 8 individual bytes */
|
||||
i16 dbus_int16_t; /**< as int16 */
|
||||
u16 dbus_uint16_t; /**< as int16 */
|
||||
i32 dbus_int32_t; /**< as int32 */
|
||||
u32 dbus_uint32_t; /**< as int32 */
|
||||
bool_val dbus_bool_t; /**< as boolean */
|
||||
i64 dbus_int64_t; /**< as int64 */
|
||||
u64 dbus_uint64_t; /**< as int64 */
|
||||
eight DBus8ByteStruct; /**< as 8-byte struct */
|
||||
dbl double; /**< as double */
|
||||
byt unsigned char; /**< as byte */
|
||||
str. char; /**< as char* (string, object path or signature) */
|
||||
fd int; /**< as Unix file descriptor */
|
||||
}
|
||||
|
||||
/**
|
||||
* Object representing an exception.
|
||||
*/
|
||||
struct DBusError {
|
||||
name. char; /**< public error name field */
|
||||
message. char; /**< public error message field */
|
||||
dummy unsigned int; /**< placeholder */
|
||||
padding1 void; /**< placeholder */
|
||||
}
|
||||
|
||||
/* documented in dbus-watch.c */
|
||||
typedef DBusWatch void;
|
||||
/* documented in dbus-timeout.c */
|
||||
typedef DBusTimeout void;
|
||||
/** Opaque type representing preallocated resources so a message can be sent without further memory allocation. */
|
||||
typedef DBusPreallocatedSend void;
|
||||
/** Opaque type representing a method call that has not yet received a reply. */
|
||||
typedef DBusPendingCall void;
|
||||
/** Opaque type representing a connection to a remote application and associated incoming/outgoing message queues. */
|
||||
typedef DBusConnection void;
|
||||
|
||||
typedef DBusMessage void;
|
||||
|
||||
/**
|
||||
* DBusMessageIter struct; contains no public fields.
|
||||
*/
|
||||
struct DBusMessageIter {
|
||||
dummy1 void; /**< Don't use this */
|
||||
dummy2 void; /**< Don't use this */
|
||||
dummy3 dbus_uint32_t; /**< Don't use this */
|
||||
dummy4 int; /**< Don't use this */
|
||||
dummy5 int; /**< Don't use this */
|
||||
dummy6 int; /**< Don't use this */
|
||||
dummy7 int; /**< Don't use this */
|
||||
dummy8 int; /**< Don't use this */
|
||||
dummy9 int; /**< Don't use this */
|
||||
dummy10 int; /**< Don't use this */
|
||||
dummy11 int; /**< Don't use this */
|
||||
pad1 int; /**< Don't use this */
|
||||
pad2 void; /**< Don't use this */
|
||||
pad3 void; /**< Don't use this */
|
||||
}
|
||||
|
||||
/* Message byte order */
|
||||
define {
|
||||
DBUS_LITTLE_ENDIAN = 'l'; /**< Code marking LSB-first byte order in the wire protocol. */
|
||||
DBUS_BIG_ENDIAN = 'B'; /**< Code marking MSB-first byte order in the wire protocol. */
|
||||
}
|
||||
|
||||
define {
|
||||
/** Type code that is never equal to a legitimate type code */
|
||||
DBUS_TYPE_INVALID = int('\0');
|
||||
/** #DBUS_TYPE_INVALID as a string literal instead of a int literal */
|
||||
DBUS_TYPE_INVALID_AS_STRING = "\0";
|
||||
/* Primitive types */
|
||||
/** Type code marking an 8-bit unsigned integer */
|
||||
DBUS_TYPE_BYTE = int('y');
|
||||
/** #DBUS_TYPE_BYTE as a string literal instead of a int literal */
|
||||
DBUS_TYPE_BYTE_AS_STRING = "y";
|
||||
/** Type code marking a boolean */
|
||||
DBUS_TYPE_BOOLEAN = int('b');
|
||||
/** #DBUS_TYPE_BOOLEAN as a string literal instead of a int literal */
|
||||
DBUS_TYPE_BOOLEAN_AS_STRING = "b";
|
||||
/** Type code marking a 16-bit signed integer */
|
||||
DBUS_TYPE_INT16 = int('n');
|
||||
/** #DBUS_TYPE_INT16 as a string literal instead of a int literal */
|
||||
DBUS_TYPE_INT16_AS_STRING = "n";
|
||||
/** Type code marking a 16-bit unsigned integer */
|
||||
DBUS_TYPE_UINT16 = int('q');
|
||||
/** #DBUS_TYPE_UINT16 as a string literal instead of a int literal */
|
||||
DBUS_TYPE_UINT16_AS_STRING = "q";
|
||||
/** Type code marking a 32-bit signed integer */
|
||||
DBUS_TYPE_INT32 = int('i');
|
||||
/** #DBUS_TYPE_INT32 as a string literal instead of a int literal */
|
||||
DBUS_TYPE_INT32_AS_STRING = "i";
|
||||
/** Type code marking a 32-bit unsigned integer */
|
||||
DBUS_TYPE_UINT32 = int('u');
|
||||
/** #DBUS_TYPE_UINT32 as a string literal instead of a int literal */
|
||||
DBUS_TYPE_UINT32_AS_STRING = "u";
|
||||
/** Type code marking a 64-bit signed integer */
|
||||
DBUS_TYPE_INT64 = int('x');
|
||||
/** #DBUS_TYPE_INT64 as a string literal instead of a int literal */
|
||||
DBUS_TYPE_INT64_AS_STRING = "x";
|
||||
/** Type code marking a 64-bit unsigned integer */
|
||||
DBUS_TYPE_UINT64 = int('t');
|
||||
/** #DBUS_TYPE_UINT64 as a string literal instead of a int literal */
|
||||
DBUS_TYPE_UINT64_AS_STRING = "t";
|
||||
/** Type code marking an 8-byte double in IEEE 754 format */
|
||||
DBUS_TYPE_DOUBLE = int('d');
|
||||
/** #DBUS_TYPE_DOUBLE as a string literal instead of a int literal */
|
||||
DBUS_TYPE_DOUBLE_AS_STRING = "d";
|
||||
/** Type code marking a UTF-8 encoded, nul-terminated Unicode string */
|
||||
DBUS_TYPE_STRING = int('s');
|
||||
/** #DBUS_TYPE_STRING as a string literal instead of a int literal */
|
||||
DBUS_TYPE_STRING_AS_STRING = "s";
|
||||
/** Type code marking a D-Bus object path */
|
||||
DBUS_TYPE_OBJECT_PATH = int('o');
|
||||
/** #DBUS_TYPE_OBJECT_PATH as a string literal instead of a int literal */
|
||||
DBUS_TYPE_OBJECT_PATH_AS_STRING = "o";
|
||||
/** Type code marking a D-Bus type signature */
|
||||
DBUS_TYPE_SIGNATURE = int('g');
|
||||
/** #DBUS_TYPE_SIGNATURE as a string literal instead of a int literal */
|
||||
DBUS_TYPE_SIGNATURE_AS_STRING = "g";
|
||||
/** Type code marking a unix file descriptor */
|
||||
DBUS_TYPE_UNIX_FD = int('h');
|
||||
/** #DBUS_TYPE_UNIX_FD as a string literal instead of a int literal */
|
||||
DBUS_TYPE_UNIX_FD_AS_STRING = "h";
|
||||
/* Compound types */
|
||||
/** Type code marking a D-Bus array type */
|
||||
DBUS_TYPE_ARRAY = int('a');
|
||||
/** #DBUS_TYPE_ARRAY as a string literal instead of a int literal */
|
||||
DBUS_TYPE_ARRAY_AS_STRING = "a";
|
||||
/** Type code marking a D-Bus variant type */
|
||||
DBUS_TYPE_VARIANT = int('v');
|
||||
/** #DBUS_TYPE_VARIANT as a string literal instead of a int literal */
|
||||
DBUS_TYPE_VARIANT_AS_STRING = "v";
|
||||
/** STRUCT and DICT_ENTRY are sort of special since their codes can't
|
||||
* appear in a type string, instead
|
||||
* DBUS_STRUCT_BEGIN_CHAR/DBUS_DICT_ENTRY_BEGIN_CHAR have to appear
|
||||
*/
|
||||
/** Type code used to represent a struct; however, this type code does not appear
|
||||
* in type signatures, instead #DBUS_STRUCT_BEGIN_CHAR and #DBUS_STRUCT_END_CHAR will
|
||||
* appear in a signature.
|
||||
*/
|
||||
DBUS_TYPE_STRUCT = int('r');
|
||||
/** #DBUS_TYPE_STRUCT as a string literal instead of a int literal */
|
||||
DBUS_TYPE_STRUCT_AS_STRING = "r";
|
||||
/** Type code used to represent a dict entry; however, this type code does not appear
|
||||
* in type signatures, instead #DBUS_DICT_ENTRY_BEGIN_CHAR and #DBUS_DICT_ENTRY_END_CHAR will
|
||||
* appear in a signature.
|
||||
*/
|
||||
DBUS_TYPE_DICT_ENTRY = int('e');
|
||||
/** #DBUS_TYPE_DICT_ENTRY as a string literal instead of a int literal */
|
||||
DBUS_TYPE_DICT_ENTRY_AS_STRING = "e";
|
||||
/** Does not include #DBUS_TYPE_INVALID, #DBUS_STRUCT_BEGIN_CHAR, #DBUS_STRUCT_END_CHAR,
|
||||
* #DBUS_DICT_ENTRY_BEGIN_CHAR, or #DBUS_DICT_ENTRY_END_CHAR - i.e. it is the number of
|
||||
* valid types, not the number of distinct characters that may appear in a type signature.
|
||||
*/
|
||||
DBUS_NUMBER_OF_TYPES = 16;
|
||||
}
|
||||
|
||||
define {
|
||||
/** This value is never a valid message type, see dbus_message_get_type() */
|
||||
DBUS_MESSAGE_TYPE_INVALID = 0;
|
||||
/** Message type of a method call message, see dbus_message_get_type() */
|
||||
DBUS_MESSAGE_TYPE_METHOD_CALL = 1;
|
||||
/** Message type of a method return message, see dbus_message_get_type() */
|
||||
DBUS_MESSAGE_TYPE_METHOD_RETURN = 2;
|
||||
/** Message type of an error reply message, see dbus_message_get_type() */
|
||||
DBUS_MESSAGE_TYPE_ERROR = 3;
|
||||
/** Message type of a signal message, see dbus_message_get_type() */
|
||||
DBUS_MESSAGE_TYPE_SIGNAL = 4;
|
||||
DBUS_NUM_MESSAGE_TYPES = 5;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module dbus+ {
|
||||
|
||||
inline dbus_error_init(error. DBusError) {
|
||||
call1<void>(so::fn.dbus_error_init, error);
|
||||
}
|
||||
|
||||
inline dbus_error_free(error. DBusError) {
|
||||
call1<void>(so::fn.dbus_error_free, error);
|
||||
}
|
||||
|
||||
inline dbus_error_is_set(error. DBusError) dbus_bool_t {
|
||||
return call1<dbus_bool_t>(so::fn.dbus_error_is_set, error);
|
||||
}
|
||||
|
||||
inline dbus_bus_add_match(connection. DBusConnection, rule. char, error. DBusError) {
|
||||
call3<void>(so::fn.dbus_bus_add_match, connection, rule, error);
|
||||
}
|
||||
|
||||
inline dbus_bus_get(type DBusBusType, error. DBusError) .DBusConnection {
|
||||
return call2<void>(so::fn.dbus_bus_get, type, error);
|
||||
}
|
||||
|
||||
inline dbus_bus_get_unique_name(connection. DBusConnection) .char {
|
||||
return call1<char*>(so::fn.dbus_bus_get_unique_name, connection);
|
||||
}
|
||||
|
||||
inline dbus_bus_request_name(connection. DBusConnection, name. char, flags unsigned int, error. DBusError) int {
|
||||
return call4<int>(so::fn.dbus_bus_request_name, connection, name, flags, error);
|
||||
}
|
||||
|
||||
inline dbus_connection_send(connection. DBusConnection, message. DBusMessage, client_serial. dbus_uint32_t) dbus_bool_t {
|
||||
return call3<dbus_bool_t>(so::fn.dbus_connection_send, connection, message, client_serial);
|
||||
}
|
||||
|
||||
inline dbus_connection_send_with_reply(connection. DBusConnection, message. DBusMessage, pending_return++ DBusPendingCall, timeout_milliseconds int) dbus_bool_t {
|
||||
return call4<dbus_bool_t>(so::fn.dbus_connection_send_with_reply, connection, message, pending_return, timeout_milliseconds);
|
||||
}
|
||||
|
||||
inline dbus_connection_read_write(connection. DBusConnection, timeout_milliseconds int) dbus_bool_t {
|
||||
return call2<dbus_bool_t>(so::fn.dbus_connection_read_write, connection, timeout_milliseconds);
|
||||
}
|
||||
|
||||
inline dbus_connection_pop_message(connection. DBusConnection) .DBusMessage {
|
||||
return call1<void>(so::fn.dbus_connection_pop_message, connection);
|
||||
}
|
||||
|
||||
inline dbus_connection_flush(connection. DBusConnection) {
|
||||
call1<void>(so::fn.dbus_connection_flush, connection);
|
||||
}
|
||||
|
||||
inline dbus_connection_close(connection. DBusConnection) {
|
||||
call1<void>(so::fn.dbus_connection_close, connection);
|
||||
}
|
||||
|
||||
inline dbus_message_new_signal(path. char, iface. char, name. char) .DBusMessage {
|
||||
return call3<void>(so::fn.dbus_message_new_signal, path, iface, name);
|
||||
}
|
||||
|
||||
inline dbus_message_new_method_call(bus_name. char, path. char, iface. char, method. char) .DBusMessage {
|
||||
return call4<void>(so::fn.dbus_message_new_method_call, bus_name, path, iface, method);
|
||||
}
|
||||
|
||||
inline dbus_message_new_method_return(method_call. DBusMessage) .DBusMessage {
|
||||
return call1<void>(so::fn.dbus_message_new_method_return, method_call);
|
||||
}
|
||||
|
||||
inline dbus_message_iter_init(message. DBusMessage, iter. DBusMessageIter) dbus_bool_t {
|
||||
return call2<dbus_bool_t>(so::fn.dbus_message_iter_init, message, iter);
|
||||
}
|
||||
|
||||
inline dbus_message_iter_init_append(message. DBusMessage, iter. DBusMessageIter) {
|
||||
call2<void>(so::fn.dbus_message_iter_init_append, message, iter);
|
||||
}
|
||||
|
||||
inline dbus_message_iter_next(iter. DBusMessageIter) dbus_bool_t {
|
||||
return call1<dbus_bool_t>(so::fn.dbus_message_iter_next, iter);
|
||||
}
|
||||
|
||||
inline dbus_message_iter_get_basic(iter. DBusMessageIter, value void) {
|
||||
call2<void>(so::fn.dbus_message_iter_get_basic, iter, value);
|
||||
}
|
||||
|
||||
inline dbus_message_iter_get_arg_type(iter. DBusMessageIter) int {
|
||||
return call1<int>(so::fn.dbus_message_iter_get_arg_type, iter);
|
||||
}
|
||||
|
||||
inline dbus_message_iter_append_basic(iter. DBusMessageIter, type int, value void) dbus_bool_t {
|
||||
return call3<dbus_bool_t>(so::fn.dbus_message_iter_append_basic, iter, type, value);
|
||||
}
|
||||
|
||||
inline dbus_message_get_type(message. DBusMessage) int {
|
||||
return call1<int>(so::fn.dbus_message_get_type, message);
|
||||
}
|
||||
|
||||
inline dbus_message_is_signal(message. DBusMessage, iface. char, signal_name. char) dbus_bool_t {
|
||||
return call3<dbus_bool_t>(so::fn.dbus_message_is_signal, message, iface, signal_name);
|
||||
}
|
||||
|
||||
inline dbus_message_is_method_call(message. DBusMessage, iface. char, method. char) dbus_bool_t {
|
||||
return call3<dbus_bool_t>(so::fn.dbus_message_is_method_call, message, iface, method);
|
||||
}
|
||||
|
||||
inline dbus_message_unref(message. DBusMessage) {
|
||||
call1<void>(so::fn.dbus_message_unref, message);
|
||||
}
|
||||
|
||||
inline dbus_pending_call_block(pending. DBusPendingCall) {
|
||||
call1<void>(so::fn.dbus_pending_call_block, pending);
|
||||
}
|
||||
|
||||
inline dbus_pending_call_steal_reply(pending. DBusPendingCall) .DBusMessage {
|
||||
return call1<void>(so::fn.dbus_pending_call_steal_reply, pending);
|
||||
}
|
||||
|
||||
inline dbus_pending_call_unref(pending. DBusPendingCall) {
|
||||
call1<void>(so::fn.dbus_pending_call_unref, pending);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,615 +0,0 @@
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
|
||||
// 2.0.4.0
|
||||
|
||||
module lib+ {
|
||||
|
||||
module sdl2_image+ {
|
||||
|
||||
module so {
|
||||
|
||||
struct struct {
|
||||
IMG_Init void;
|
||||
IMG_Quit void;
|
||||
IMG_Load void;
|
||||
IMG_LoadTexture void;
|
||||
IMG_SavePNG void;
|
||||
}
|
||||
|
||||
var fn struct;
|
||||
|
||||
func init() bool {
|
||||
import rt::c;
|
||||
return dlsyms(dlopen("libSDL2_image-2.0.so.0", RTLD_LAZY), &fn,
|
||||
"IMG_Init",
|
||||
"IMG_Quit",
|
||||
"IMG_Load",
|
||||
"IMG_LoadTexture",
|
||||
"IMG_SavePNG"
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module sdl2_image+ {
|
||||
|
||||
import sdl2;
|
||||
|
||||
enum IMG_InitFlags;
|
||||
enum {
|
||||
IMG_INIT_JPG = 0x00000001,
|
||||
IMG_INIT_PNG = 0x00000002,
|
||||
IMG_INIT_TIF = 0x00000004,
|
||||
IMG_INIT_WEBP = 0x00000008
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module sdl2_image+ {
|
||||
|
||||
inline IMG_Init(flags int) int {
|
||||
return call1<int>(so::fn.IMG_Init, flags);
|
||||
}
|
||||
|
||||
inline IMG_Quit() {
|
||||
call<void>(so::fn.IMG_Quit);
|
||||
}
|
||||
|
||||
inline IMG_Load(file. char) .SDL_Surface {
|
||||
return call1<void>(so::fn.IMG_Load, file);
|
||||
}
|
||||
|
||||
inline IMG_LoadTexture(renderer+ SDL_Renderer, file. char) +SDL_Texture {
|
||||
return call2<void>(so::fn.IMG_LoadTexture, renderer, file);
|
||||
}
|
||||
|
||||
inline IMG_SavePNG(surface. SDL_Surface, file. char) int {
|
||||
return call2<int>(so::fn.IMG_SavePNG, surface, file);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,441 +0,0 @@
|
||||
|
||||
// 2.0.4.0
|
||||
|
||||
module lib+ {
|
||||
|
||||
module sdl2_mixer+ {
|
||||
|
||||
module so {
|
||||
|
||||
struct struct {
|
||||
Mix_Init void;
|
||||
Mix_Quit void;
|
||||
Mix_OpenAudio void;
|
||||
Mix_AllocateChannels void;
|
||||
Mix_QuerySpec void;
|
||||
Mix_LoadWAV_RW void;
|
||||
Mix_LoadMUS void;
|
||||
Mix_FreeChunk void;
|
||||
Mix_FreeMusic void;
|
||||
Mix_GetNumChunkDecoders void;
|
||||
Mix_GetChunkDecoder void;
|
||||
Mix_GetNumMusicDecoders void;
|
||||
Mix_GetMusicDecoder void;
|
||||
Mix_GetMusicType void;
|
||||
Mix_SetPanning void;
|
||||
Mix_SetPosition void;
|
||||
Mix_SetDistance void;
|
||||
Mix_SetReverseStereo void;
|
||||
Mix_ReserveChannels void;
|
||||
Mix_GroupChannel void;
|
||||
Mix_GroupChannels void;
|
||||
Mix_GroupAvailable void;
|
||||
Mix_GroupCount void;
|
||||
Mix_GroupOldest void;
|
||||
Mix_GroupNewer void;
|
||||
Mix_PlayChannelTimed void;
|
||||
Mix_PlayMusic void;
|
||||
Mix_FadeInMusic void;
|
||||
Mix_FadeInMusicPos void;
|
||||
Mix_FadeInChannelTimed void;
|
||||
Mix_Volume void;
|
||||
Mix_VolumeChunk void;
|
||||
Mix_VolumeMusic void;
|
||||
Mix_HaltChannel void;
|
||||
Mix_HaltGroup void;
|
||||
Mix_HaltMusic void;
|
||||
Mix_ExpireChannel void;
|
||||
Mix_FadeOutChannel void;
|
||||
Mix_FadeOutGroup void;
|
||||
Mix_FadeOutMusic void;
|
||||
Mix_FadingMusic void;
|
||||
Mix_FadingChannel void;
|
||||
Mix_Pause void;
|
||||
Mix_Resume void;
|
||||
Mix_Paused void;
|
||||
Mix_PauseMusic void;
|
||||
Mix_ResumeMusic void;
|
||||
Mix_RewindMusic void;
|
||||
Mix_PausedMusic void;
|
||||
Mix_SetMusicPosition void;
|
||||
Mix_Playing void;
|
||||
Mix_PlayingMusic void;
|
||||
Mix_SetMusicCMD void;
|
||||
Mix_SetSynchroValue void;
|
||||
Mix_GetSynchroValue void;
|
||||
Mix_GetChunk void;
|
||||
Mix_CloseAudio void;
|
||||
}
|
||||
|
||||
var fn struct;
|
||||
|
||||
func init() bool {
|
||||
import rt::c;
|
||||
return dlsyms(dlopen("libSDL2_mixer-2.0.so.0", RTLD_LAZY), &fn,
|
||||
"Mix_Init",
|
||||
"Mix_Quit",
|
||||
"Mix_OpenAudio",
|
||||
"Mix_AllocateChannels",
|
||||
"Mix_QuerySpec",
|
||||
"Mix_LoadWAV_RW",
|
||||
"Mix_LoadMUS",
|
||||
"Mix_FreeChunk",
|
||||
"Mix_FreeMusic",
|
||||
"Mix_GetNumChunkDecoders",
|
||||
"Mix_GetChunkDecoder",
|
||||
"Mix_GetNumMusicDecoders",
|
||||
"Mix_GetMusicDecoder",
|
||||
"Mix_GetMusicType",
|
||||
"Mix_SetPanning",
|
||||
"Mix_SetPosition",
|
||||
"Mix_SetDistance",
|
||||
"Mix_SetReverseStereo",
|
||||
"Mix_ReserveChannels",
|
||||
"Mix_GroupChannel",
|
||||
"Mix_GroupChannels",
|
||||
"Mix_GroupAvailable",
|
||||
"Mix_GroupCount",
|
||||
"Mix_GroupOldest",
|
||||
"Mix_GroupNewer",
|
||||
"Mix_PlayChannelTimed",
|
||||
"Mix_PlayMusic",
|
||||
"Mix_FadeInMusic",
|
||||
"Mix_FadeInMusicPos",
|
||||
"Mix_FadeInChannelTimed",
|
||||
"Mix_Volume",
|
||||
"Mix_VolumeChunk",
|
||||
"Mix_VolumeMusic",
|
||||
"Mix_HaltChannel",
|
||||
"Mix_HaltGroup",
|
||||
"Mix_HaltMusic",
|
||||
"Mix_ExpireChannel",
|
||||
"Mix_FadeOutChannel",
|
||||
"Mix_FadeOutGroup",
|
||||
"Mix_FadeOutMusic",
|
||||
"Mix_FadingMusic",
|
||||
"Mix_FadingChannel",
|
||||
"Mix_Pause",
|
||||
"Mix_Resume",
|
||||
"Mix_Paused",
|
||||
"Mix_PauseMusic",
|
||||
"Mix_ResumeMusic",
|
||||
"Mix_RewindMusic",
|
||||
"Mix_PausedMusic",
|
||||
"Mix_SetMusicPosition",
|
||||
"Mix_Playing",
|
||||
"Mix_PlayingMusic",
|
||||
"Mix_SetMusicCMD",
|
||||
"Mix_SetSynchroValue",
|
||||
"Mix_GetSynchroValue",
|
||||
"Mix_GetChunk",
|
||||
"Mix_CloseAudio"
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module sdl2_mixer+ {
|
||||
|
||||
import sdl2;
|
||||
|
||||
enum MIX_InitFlags;
|
||||
enum {
|
||||
MIX_INIT_FLAC = 0x00000001,
|
||||
MIX_INIT_MOD = 0x00000002,
|
||||
MIX_INIT_MP3 = 0x00000008,
|
||||
MIX_INIT_OGG = 0x00000010,
|
||||
MIX_INIT_MID = 0x00000020,
|
||||
MIX_INIT_OPUS = 0x00000040
|
||||
}
|
||||
|
||||
// SDL_BYTEORDER == SDL_LIL_ENDIAN
|
||||
define {
|
||||
MIX_CHANNELS = 8;
|
||||
MIX_DEFAULT_FREQUENCY = 22050;
|
||||
MIX_DEFAULT_FORMAT = AUDIO_S16LSB;
|
||||
MIX_DEFAULT_CHANNELS = 2;
|
||||
MIX_MAX_VOLUME = SDL_MIX_MAXVOLUME;
|
||||
}
|
||||
|
||||
struct Mix_Chunk {
|
||||
allocated int;
|
||||
abuf. uint8;
|
||||
alen uint32;
|
||||
volume uint8; /* Per-sample volume, 0-128 */
|
||||
}
|
||||
|
||||
enum Mix_Fading;
|
||||
enum {
|
||||
MIX_NO_FADING,
|
||||
MIX_FADING_OUT,
|
||||
MIX_FADING_IN
|
||||
}
|
||||
|
||||
enum Mix_MusicType;
|
||||
enum {
|
||||
MUS_NONE,
|
||||
MUS_CMD,
|
||||
MUS_WAV,
|
||||
MUS_MOD,
|
||||
MUS_MID,
|
||||
MUS_OGG,
|
||||
MUS_MP3,
|
||||
MUS_MP3_MAD_UNUSED,
|
||||
MUS_FLAC,
|
||||
MUS_MODPLUG_UNUSED,
|
||||
MUS_OPUS
|
||||
}
|
||||
|
||||
define {
|
||||
MIX_CHANNEL_POST = -2;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module sdl2_mixer+ {
|
||||
|
||||
inline Mix_Init(flags int) int {
|
||||
return call1<int>(so::fn.Mix_Init, flags);
|
||||
}
|
||||
|
||||
inline Mix_Quit() {
|
||||
call<void>(so::fn.Mix_Quit);
|
||||
}
|
||||
|
||||
inline Mix_OpenAudio(frequency int, format uint16, channels int, chunksize int) int {
|
||||
return call4<int>(so::fn.Mix_OpenAudio, frequency, format, channels, chunksize);
|
||||
}
|
||||
|
||||
inline Mix_AllocateChannels(numchans int) int {
|
||||
return call1<int>(so::fn.Mix_AllocateChannels, numchans);
|
||||
}
|
||||
|
||||
inline Mix_QuerySpec(frequency. int, format. uint16, channels. int) int {
|
||||
return call3<int>(so::fn.Mix_QuerySpec, frequency, format, channels);
|
||||
}
|
||||
|
||||
inline Mix_LoadWAV(file. char) .Mix_Chunk {
|
||||
return Mix_LoadWAV_RW(SDL_RWFromFile(file, "rb"), 1);
|
||||
}
|
||||
|
||||
inline Mix_LoadWAV_RW(src. SDL_RWops, freesrc int) .Mix_Chunk {
|
||||
return call2<void>(so::fn.Mix_LoadWAV_RW, src, freesrc);
|
||||
}
|
||||
|
||||
inline Mix_LoadMUS(file. char) +Mix_Music {
|
||||
return call1<void>(so::fn.Mix_LoadMUS, file);
|
||||
}
|
||||
|
||||
inline Mix_FreeChunk(chunk. Mix_Chunk) {
|
||||
call1<void>(so::fn.Mix_FreeChunk, chunk);
|
||||
}
|
||||
|
||||
inline Mix_FreeMusic(music+ Mix_Music) {
|
||||
call1<void>(so::fn.Mix_FreeMusic, music);
|
||||
}
|
||||
|
||||
inline Mix_GetNumChunkDecoders() int {
|
||||
return call1<int>(so::fn.Mix_GetNumChunkDecoders);
|
||||
}
|
||||
|
||||
inline Mix_GetChunkDecoder(index int) .char {
|
||||
return call1<char*>(so::fn.Mix_GetChunkDecoder, index);
|
||||
}
|
||||
|
||||
inline Mix_GetNumMusicDecoders() int {
|
||||
return call<int>(so::fn.Mix_GetNumMusicDecoders);
|
||||
}
|
||||
|
||||
inline Mix_GetMusicDecoder(index int) .char {
|
||||
return call1<char*>(so::fn.Mix_GetMusicDecoder, index);
|
||||
}
|
||||
|
||||
inline Mix_GetMusicType(music+ Mix_Music) Mix_MusicType {
|
||||
return call1<Mix_MusicType>(so::fn.Mix_GetMusicType, music);
|
||||
}
|
||||
|
||||
inline Mix_SetPanning(channel int, left uint8, right uint8) int {
|
||||
return call3<int>(so::fn.Mix_SetPanning, channel, left, right);
|
||||
}
|
||||
|
||||
inline Mix_SetPosition(channel int, angle int16, distance uint8) int {
|
||||
return call3<int>(so::fn.Mix_SetPosition, channel, angle, distance);
|
||||
}
|
||||
|
||||
inline Mix_SetDistance(channel int, distance uint8) int {
|
||||
return call2<int>(so::fn.Mix_SetDistance, channel, distance);
|
||||
}
|
||||
|
||||
inline Mix_SetReverseStereo(channel int, flip int) int {
|
||||
return call2<int>(so::fn.Mix_SetReverseStereo, channel, flip);
|
||||
}
|
||||
|
||||
inline Mix_ReserveChannels(num int) int {
|
||||
return call1<int>(so::fn.Mix_ReserveChannels, num);
|
||||
}
|
||||
|
||||
inline Mix_GroupChannel(which int, tag int) int {
|
||||
return call2<int>(so::fn.Mix_GroupChannel, which, tag);
|
||||
}
|
||||
|
||||
inline Mix_GroupChannels(from int, to int, tag int) int {
|
||||
return call3<int>(so::fn.Mix_GroupChannels, from, to, tag);
|
||||
}
|
||||
|
||||
inline Mix_GroupAvailable(tag int) int {
|
||||
return call1<int>(so::fn.Mix_GroupAvailable, tag);
|
||||
}
|
||||
|
||||
inline Mix_GroupCount(tag int) int {
|
||||
return call1<int>(so::fn.Mix_GroupCount, tag);
|
||||
}
|
||||
|
||||
inline Mix_GroupOldest(tag int) int {
|
||||
return call1<int>(so::fn.Mix_GroupOldest, tag);
|
||||
}
|
||||
|
||||
inline Mix_GroupNewer(tag int) int {
|
||||
return call1<int>(so::fn.Mix_GroupNewer, tag);
|
||||
}
|
||||
|
||||
inline Mix_PlayChannel(channel int, chunk. Mix_Chunk, loops int) int {
|
||||
return Mix_PlayChannelTimed(channel, chunk, loops, -1);
|
||||
}
|
||||
|
||||
inline Mix_PlayChannelTimed(channel int, chunk. Mix_Chunk, loops int, ticks int) int {
|
||||
return call4<int>(so::fn.Mix_PlayChannelTimed, channel, chunk, loops, ticks);
|
||||
}
|
||||
|
||||
inline Mix_PlayMusic(music+ Mix_Music, loops int) int {
|
||||
return call2<int>(so::fn.Mix_PlayMusic, music, loops);
|
||||
}
|
||||
|
||||
inline Mix_FadeInMusic(music+ Mix_Music, loops int, ms int) int {
|
||||
return call3<int>(so::fn.Mix_FadeInMusic, music, loops, ms);
|
||||
}
|
||||
|
||||
inline Mix_FadeInMusicPos(music+ Mix_Music, loops int, ms int, position double) int {
|
||||
return call_rrrd<int>(so::fn.Mix_FadeInMusicPos, music, loops, ms, position);
|
||||
}
|
||||
|
||||
inline Mix_FadeInChannel(channel int, chunk. Mix_Chunk, loops int, ms int) int {
|
||||
return Mix_FadeInChannelTimed(channel, chunk, loops, ms, -1);
|
||||
}
|
||||
|
||||
inline Mix_FadeInChannelTimed(channel int, chunk. Mix_Chunk, loops int, ms int, ticks int) int {
|
||||
return call5<int>(so::fn.Mix_FadeInChannelTimed, channel, chunk, loops, ms, ticks);
|
||||
}
|
||||
|
||||
inline Mix_Volume(channel int, volume int) int {
|
||||
return call2<int>(so::fn.Mix_Volume, channel, volume);
|
||||
}
|
||||
|
||||
inline Mix_VolumeChunk(chunk. Mix_Chunk, volume int) int {
|
||||
return call2<int>(so::fn.Mix_VolumeChunk, chunk, volume);
|
||||
}
|
||||
|
||||
inline Mix_VolumeMusic(volume int) int {
|
||||
return call1<int>(so::fn.Mix_VolumeMusic, volume);
|
||||
}
|
||||
|
||||
inline Mix_HaltChannel(channel int) int {
|
||||
return call1<int>(so::fn.Mix_HaltChannel, channel);
|
||||
}
|
||||
|
||||
inline Mix_HaltGroup(tag int) int {
|
||||
return call1<int>(so::fn.Mix_HaltGroup, tag);
|
||||
}
|
||||
|
||||
inline Mix_HaltMusic() int {
|
||||
return call<int>(so::fn.Mix_HaltMusic);
|
||||
}
|
||||
|
||||
inline Mix_ExpireChannel(channel int, ticks int) int {
|
||||
return call2<int>(so::fn.Mix_ExpireChannel, channel, ticks);
|
||||
}
|
||||
|
||||
inline Mix_FadeOutChannel(which int, ms int) int {
|
||||
return call2<int>(so::fn.Mix_FadeOutChannel, which, ms);
|
||||
}
|
||||
|
||||
inline Mix_FadeOutGroup(tag int, ms int) int {
|
||||
return call2<int>(so::fn.Mix_FadeOutGroup, tag, ms);
|
||||
}
|
||||
|
||||
inline Mix_FadeOutMusic(ms int) int {
|
||||
return call1<int>(so::fn.Mix_FadeOutMusic, ms);
|
||||
}
|
||||
|
||||
inline Mix_FadingMusic() Mix_Fading {
|
||||
return call<Mix_Fading>(so::fn.Mix_FadingMusic);
|
||||
}
|
||||
|
||||
inline Mix_FadingChannel(which int) Mix_Fading {
|
||||
return call1<Mix_Fading>(so::fn.Mix_FadingChannel, which);
|
||||
}
|
||||
|
||||
inline Mix_Pause(channel int) {
|
||||
call1<void>(so::fn.Mix_Pause, channel);
|
||||
}
|
||||
|
||||
inline Mix_Resume(channel int) {
|
||||
call1<void>(so::fn.Mix_Resume, channel);
|
||||
}
|
||||
|
||||
inline Mix_Paused(channel int) int {
|
||||
return call1<int>(so::fn.Mix_Paused, channel);
|
||||
}
|
||||
|
||||
inline Mix_PauseMusic() {
|
||||
call<void>(so::fn.Mix_PauseMusic);
|
||||
}
|
||||
|
||||
inline Mix_ResumeMusic() {
|
||||
call<void>(so::fn.Mix_ResumeMusic);
|
||||
}
|
||||
|
||||
inline Mix_RewindMusic() {
|
||||
call<void>(so::fn.Mix_RewindMusic);
|
||||
}
|
||||
|
||||
inline Mix_PausedMusic() int {
|
||||
return call<int>(so::fn.Mix_PausedMusic);
|
||||
}
|
||||
|
||||
inline Mix_SetMusicPosition(position double) int {
|
||||
return call_d<int>(so::fn.Mix_SetMusicPosition, position);
|
||||
}
|
||||
|
||||
inline Mix_Playing(channel int) int {
|
||||
return call1<int>(so::fn.Mix_Playing, channel);
|
||||
}
|
||||
|
||||
inline Mix_PlayingMusic() int {
|
||||
return call<int>(so::fn.Mix_PlayingMusic);
|
||||
}
|
||||
|
||||
inline Mix_SetMusicCMD(command. char) int {
|
||||
return call1<int>(so::fn.Mix_SetMusicCMD, command);
|
||||
}
|
||||
|
||||
inline Mix_SetSynchroValue(value int) int {
|
||||
return call1<int>(so::fn.Mix_SetSynchroValue, value);
|
||||
}
|
||||
|
||||
inline Mix_GetSynchroValue() int {
|
||||
return call<int>(so::fn.Mix_GetSynchroValue);
|
||||
}
|
||||
|
||||
inline Mix_GetChunk(channel int) .Mix_Chunk {
|
||||
return call1<void>(so::fn.Mix_GetChunk, channel);
|
||||
}
|
||||
|
||||
inline Mix_CloseAudio() {
|
||||
call<void>(so::fn.Mix_CloseAudio);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,319 +0,0 @@
|
||||
|
||||
// 2.0.15.0
|
||||
|
||||
module lib+ {
|
||||
|
||||
module sdl2_ttf+ {
|
||||
|
||||
module so {
|
||||
|
||||
struct struct {
|
||||
TTF_ByteSwappedUNICODE void;
|
||||
TTF_Init void;
|
||||
TTF_OpenFont void;
|
||||
TTF_OpenFontIndex void;
|
||||
TTF_GetFontStyle void;
|
||||
TTF_SetFontStyle void;
|
||||
TTF_GetFontOutline void;
|
||||
TTF_SetFontOutline void;
|
||||
TTF_GetFontHinting void;
|
||||
TTF_SetFontHinting void;
|
||||
TTF_FontHeight void;
|
||||
TTF_FontAscent void;
|
||||
TTF_FontDescent void;
|
||||
TTF_FontLineSkip void;
|
||||
TTF_GetFontKerning void;
|
||||
TTF_SetFontKerning void;
|
||||
TTF_FontFaces void;
|
||||
TTF_FontFaceIsFixedWidth void;
|
||||
TTF_FontFaceFamilyName void;
|
||||
TTF_FontFaceStyleName void;
|
||||
TTF_GlyphIsProvided void;
|
||||
TTF_GlyphMetrics void;
|
||||
TTF_SizeText void;
|
||||
TTF_SizeUTF8 void;
|
||||
TTF_SizeUNICODE void;
|
||||
TTF_RenderText_Solid void;
|
||||
TTF_RenderUTF8_Solid void;
|
||||
TTF_RenderUNICODE_Solid void;
|
||||
TTF_RenderGlyph_Solid void;
|
||||
TTF_RenderText_Shaded void;
|
||||
TTF_RenderUTF8_Shaded void;
|
||||
TTF_RenderUNICODE_Shaded void;
|
||||
TTF_RenderGlyph_Shaded void;
|
||||
TTF_RenderText_Blended void;
|
||||
TTF_RenderUTF8_Blended void;
|
||||
TTF_RenderUNICODE_Blended void;
|
||||
TTF_RenderText_Blended_Wrapped void;
|
||||
TTF_RenderUTF8_Blended_Wrapped void;
|
||||
TTF_RenderUNICODE_Blended_Wrapped void;
|
||||
TTF_RenderGlyph_Blended void;
|
||||
TTF_CloseFont void;
|
||||
TTF_Quit void;
|
||||
TTF_WasInit void;
|
||||
TTF_GetFontKerningSizeGlyphs void;
|
||||
}
|
||||
|
||||
var fn struct;
|
||||
|
||||
func init() bool {
|
||||
import rt::c;
|
||||
return dlsyms(dlopen("libSDL2_ttf-2.0.so.0", RTLD_LAZY), &fn,
|
||||
"TTF_ByteSwappedUNICODE",
|
||||
"TTF_Init",
|
||||
"TTF_OpenFont",
|
||||
"TTF_OpenFontIndex",
|
||||
"TTF_GetFontStyle",
|
||||
"TTF_SetFontStyle",
|
||||
"TTF_GetFontOutline",
|
||||
"TTF_SetFontOutline",
|
||||
"TTF_GetFontHinting",
|
||||
"TTF_SetFontHinting",
|
||||
"TTF_FontHeight",
|
||||
"TTF_FontAscent",
|
||||
"TTF_FontDescent",
|
||||
"TTF_FontLineSkip",
|
||||
"TTF_GetFontKerning",
|
||||
"TTF_SetFontKerning",
|
||||
"TTF_FontFaces",
|
||||
"TTF_FontFaceIsFixedWidth",
|
||||
"TTF_FontFaceFamilyName",
|
||||
"TTF_FontFaceStyleName",
|
||||
"TTF_GlyphIsProvided",
|
||||
"TTF_GlyphMetrics",
|
||||
"TTF_SizeText",
|
||||
"TTF_SizeUTF8",
|
||||
"TTF_SizeUNICODE",
|
||||
"TTF_RenderText_Solid",
|
||||
"TTF_RenderUTF8_Solid",
|
||||
"TTF_RenderUNICODE_Solid",
|
||||
"TTF_RenderGlyph_Solid",
|
||||
"TTF_RenderText_Shaded",
|
||||
"TTF_RenderUTF8_Shaded",
|
||||
"TTF_RenderUNICODE_Shaded",
|
||||
"TTF_RenderGlyph_Shaded",
|
||||
"TTF_RenderText_Blended",
|
||||
"TTF_RenderUTF8_Blended",
|
||||
"TTF_RenderUNICODE_Blended",
|
||||
"TTF_RenderText_Blended_Wrapped",
|
||||
"TTF_RenderUTF8_Blended_Wrapped",
|
||||
"TTF_RenderUNICODE_Blended_Wrapped",
|
||||
"TTF_RenderGlyph_Blended",
|
||||
"TTF_CloseFont",
|
||||
"TTF_Quit",
|
||||
"TTF_WasInit",
|
||||
"TTF_GetFontKerningSizeGlyphs"
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module sdl2_ttf+ {
|
||||
|
||||
import sdl2;
|
||||
|
||||
define {
|
||||
UNICODE_BOM_NATIVE = 0xFEFF;
|
||||
UNICODE_BOM_SWAPPED = 0xFFFE;
|
||||
}
|
||||
|
||||
define {
|
||||
TTF_STYLE_NORMAL = 0x00;
|
||||
TTF_STYLE_BOLD = 0x01;
|
||||
TTF_STYLE_ITALIC = 0x02;
|
||||
TTF_STYLE_UNDERLINE = 0x04;
|
||||
TTF_STYLE_STRIKETHROUGH = 0x08;
|
||||
}
|
||||
|
||||
define {
|
||||
TTF_HINTING_NORMAL = 0;
|
||||
TTF_HINTING_LIGHT = 1;
|
||||
TTF_HINTING_MONO = 2;
|
||||
TTF_HINTING_NONE = 3;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module sdl2_ttf+ {
|
||||
|
||||
inline TTF_ByteSwappedUNICODE(swapped int) {
|
||||
call1<void>(so::fn.TTF_ByteSwappedUNICODE, swapped);
|
||||
}
|
||||
|
||||
inline TTF_Init() int {
|
||||
return call<int>(so::fn.TTF_Init);
|
||||
}
|
||||
|
||||
inline TTF_OpenFont(file. char, ptsize int) +TTF_Font {
|
||||
return call2<void>(so::fn.TTF_OpenFont, file, ptsize);
|
||||
}
|
||||
|
||||
inline TTF_OpenFontIndex(file. char, ptsize int, index long) +TTF_Font {
|
||||
return call3<void>(so::fn.TTF_OpenFontIndex, file, ptsize, index);
|
||||
}
|
||||
|
||||
inline TTF_GetFontStyle(font+ TTF_Font) int {
|
||||
return call1<int>(so::fn.TTF_GetFontStyle, font);
|
||||
}
|
||||
|
||||
inline TTF_SetFontStyle(font+ TTF_Font, style int) {
|
||||
call2<void>(so::fn.TTF_SetFontStyle, font, style);
|
||||
}
|
||||
|
||||
inline TTF_GetFontOutline(font+ TTF_Font) int {
|
||||
return call1<int>(so::fn.TTF_GetFontOutline, font);
|
||||
}
|
||||
|
||||
inline TTF_SetFontOutline(font+ TTF_Font, outline int) {
|
||||
call2<void>(so::fn.TTF_SetFontOutline, font, outline);
|
||||
}
|
||||
|
||||
inline TTF_GetFontHinting(font+ TTF_Font) int {
|
||||
return call1<int>(so::fn.TTF_GetFontHinting, font);
|
||||
}
|
||||
|
||||
inline TTF_SetFontHinting(font+ TTF_Font, hinting int) {
|
||||
call2<void>(so::fn.TTF_SetFontHinting, font, hinting);
|
||||
}
|
||||
|
||||
inline TTF_FontHeight(font+ TTF_Font) int {
|
||||
return call1<int>(so::fn.TTF_FontHeight, font);
|
||||
}
|
||||
|
||||
inline TTF_FontAscent(font+ TTF_Font) int {
|
||||
return call1<int>(so::fn.TTF_FontAscent, font);
|
||||
}
|
||||
|
||||
inline TTF_FontDescent(font+ TTF_Font) int {
|
||||
return call1<int>(so::fn.TTF_FontDescent, font);
|
||||
}
|
||||
|
||||
inline TTF_FontLineSkip(font+ TTF_Font) int {
|
||||
return call1<int>(so::fn.TTF_FontLineSkip, font);
|
||||
}
|
||||
|
||||
inline TTF_GetFontKerning(font+ TTF_Font) int {
|
||||
return call1<int>(so::fn.TTF_GetFontKerning, font);
|
||||
}
|
||||
|
||||
inline TTF_SetFontKerning(font+ TTF_Font, allowed int) {
|
||||
call2<void>(so::fn.TTF_SetFontKerning, font, allowed);
|
||||
}
|
||||
|
||||
inline TTF_FontFaces(font+ TTF_Font) long {
|
||||
return call1<long>(so::fn.TTF_FontFaces, font);
|
||||
}
|
||||
|
||||
inline TTF_FontFaceIsFixedWidth(font+ TTF_Font) int {
|
||||
return call1<int>(so::fn.TTF_FontFaceIsFixedWidth, font);
|
||||
}
|
||||
|
||||
inline TTF_FontFaceFamilyName(font+ TTF_Font) .char {
|
||||
return call1<char*>(so::fn.TTF_FontFaceFamilyName, font);
|
||||
}
|
||||
|
||||
inline TTF_FontFaceStyleName(font+ TTF_Font) .char {
|
||||
return call1<char*>(so::fn.TTF_FontFaceStyleName, font);
|
||||
}
|
||||
|
||||
inline TTF_GlyphIsProvided(font+ TTF_Font, ch uint16) int {
|
||||
return call2<int>(so::fn.TTF_GlyphIsProvided, font, ch);
|
||||
}
|
||||
|
||||
inline TTF_GlyphMetrics(font+ TTF_Font, ch uint16, minx. int, maxx. int, miny. int, maxy. int, advance. int) int {
|
||||
return call7<int>(so::fn.TTF_GlyphMetrics, font, ch, minx, maxx, miny, maxy, advance);
|
||||
}
|
||||
|
||||
inline TTF_SizeText(font+ TTF_Font, text. char, w. int, h. int) int {
|
||||
return call4<int>(so::fn.TTF_SizeText, font, text, w, h);
|
||||
}
|
||||
|
||||
inline TTF_SizeUTF8(font+ TTF_Font, text. char, w. int, h. int) int {
|
||||
return call4<int>(so::fn.TTF_SizeUTF8, font, text, w, h);
|
||||
}
|
||||
|
||||
inline TTF_SizeUNICODE(font+ TTF_Font, text. uint16, w. int, h. int) int {
|
||||
return call4<int>(so::fn.TTF_SizeUNICODE, font, text, w, h);
|
||||
}
|
||||
|
||||
inline TTF_RenderText_Solid(font+ TTF_Font, text. char, fg uint32 /* SDL_Color */) .SDL_Surface {
|
||||
return call3<void>(so::fn.TTF_RenderText_Solid, font, text, fg);
|
||||
}
|
||||
|
||||
inline TTF_RenderUTF8_Solid(font+ TTF_Font, text. char, fg uint32 /* SDL_Color */) .SDL_Surface {
|
||||
return call3<void>(so::fn.TTF_RenderUTF8_Solid, font, text, fg);
|
||||
}
|
||||
|
||||
inline TTF_RenderUNICODE_Solid(font+ TTF_Font, text. uint16, fg uint32 /* SDL_Color */) .SDL_Surface {
|
||||
return call3<void>(so::fn.TTF_RenderUNICODE_Solid, font, text, fg);
|
||||
}
|
||||
|
||||
inline TTF_RenderGlyph_Solid(font+ TTF_Font, ch uint16, fg uint32 /* SDL_Color */) .SDL_Surface {
|
||||
return call3<void>(so::fn.TTF_RenderGlyph_Solid, font, ch, fg);
|
||||
}
|
||||
|
||||
inline TTF_RenderText_Shaded(font+ TTF_Font, text. char, fg uint32 /* SDL_Color */, bg uint32 /* SDL_Color */) .SDL_Surface {
|
||||
return call4<void>(so::fn.TTF_RenderText_Shaded, font, text, fg, bg);
|
||||
}
|
||||
|
||||
inline TTF_RenderUTF8_Shaded(font+ TTF_Font, text. char, fg uint32 /* SDL_Color */, bg uint32 /* SDL_Color */) .SDL_Surface {
|
||||
return call4<void>(so::fn.TTF_RenderUTF8_Shaded, font, text, fg, bg);
|
||||
}
|
||||
|
||||
inline TTF_RenderUNICODE_Shaded(font+ TTF_Font, text. uint16, fg uint32 /* SDL_Color */, bg uint32 /* SDL_Color */) .SDL_Surface {
|
||||
return call4<void>(so::fn.TTF_RenderUNICODE_Shaded, font, text, fg, bg);
|
||||
}
|
||||
|
||||
inline TTF_RenderGlyph_Shaded(font+ TTF_Font, ch uint16, fg uint32 /* SDL_Color */, bg uint32 /* SDL_Color */) .SDL_Surface {
|
||||
return call4<void>(so::fn.TTF_RenderGlyph_Shaded, font, ch, fg, bg);
|
||||
}
|
||||
|
||||
inline TTF_RenderText_Blended(font+ TTF_Font, text. char, fg uint32 /* SDL_Color */) .SDL_Surface {
|
||||
return call3<void>(so::fn.TTF_RenderText_Blended, font, text, fg);
|
||||
}
|
||||
|
||||
inline TTF_RenderUTF8_Blended(font+ TTF_Font, text. char, fg uint32 /* SDL_Color */) .SDL_Surface {
|
||||
return call3<void>(so::fn.TTF_RenderUTF8_Blended, font, text, fg);
|
||||
}
|
||||
|
||||
inline TTF_RenderUNICODE_Blended(font+ TTF_Font, text. uint16, fg uint32 /* SDL_Color */) .SDL_Surface {
|
||||
return call3<void>(so::fn.TTF_RenderUNICODE_Blended, font, text, fg);
|
||||
}
|
||||
|
||||
inline TTF_RenderText_Blended_Wrapped(font+ TTF_Font, text. char, fg uint32 /* SDL_Color */, wrapLength uint32) .SDL_Surface {
|
||||
return call4<void>(so::fn.TTF_RenderText_Blended_Wrapped, font, text, fg, wrapLength);
|
||||
}
|
||||
|
||||
inline TTF_RenderUTF8_Blended_Wrapped(font+ TTF_Font, text. char, fg uint32 /* SDL_Color */, wrapLength uint32) .SDL_Surface {
|
||||
return call4<void>(so::fn.TTF_RenderUTF8_Blended_Wrapped, font, text, fg, wrapLength);
|
||||
}
|
||||
|
||||
inline TTF_RenderUNICODE_Blended_Wrapped(font+ TTF_Font, text. uint16, fg uint32 /* SDL_Color */, wrapLength uint32) .SDL_Surface {
|
||||
return call4<void>(so::fn.TTF_RenderUNICODE_Blended_Wrapped, font, text, fg, wrapLength);
|
||||
}
|
||||
|
||||
inline TTF_RenderGlyph_Blended(font+ TTF_Font, ch uint16, fg uint32 /* SDL_Color */) .SDL_Surface {
|
||||
return call3<void>(so::fn.TTF_RenderGlyph_Blended, font, ch, fg);
|
||||
}
|
||||
|
||||
inline TTF_CloseFont(font+ TTF_Font) {
|
||||
call1<void>(so::fn.TTF_CloseFont, font);
|
||||
}
|
||||
|
||||
inline TTF_Quit() {
|
||||
call<void>(so::fn.TTF_Quit);
|
||||
}
|
||||
|
||||
inline TTF_WasInit() int {
|
||||
return call<int>(so::fn.TTF_WasInit);
|
||||
}
|
||||
|
||||
inline TTF_GetFontKerningSizeGlyphs(font+ TTF_Font, previous_ch uint16, ch uint16) int {
|
||||
return call3<int>(so::fn.TTF_GetFontKerningSizeGlyphs, font, previous_ch, ch);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,322 +0,0 @@
|
||||
|
||||
// 3.26.0
|
||||
|
||||
module lib+ {
|
||||
|
||||
module sqlite3+ {
|
||||
|
||||
module so {
|
||||
|
||||
struct struct {
|
||||
sqlite3_open_v2 void;
|
||||
sqlite3_close_v2 void;
|
||||
sqlite3_exec void;
|
||||
sqlite3_prepare_v2 void;
|
||||
sqlite3_bind_blob void;
|
||||
sqlite3_bind_double void;
|
||||
sqlite3_bind_int void;
|
||||
sqlite3_bind_null void;
|
||||
sqlite3_bind_text void;
|
||||
sqlite3_bind_text16 void;
|
||||
sqlite3_bind_text64 void;
|
||||
sqlite3_bind_value void;
|
||||
sqlite3_bind_zeroblob void;
|
||||
sqlite3_bind_parameter_count void;
|
||||
sqlite3_bind_parameter_name void;
|
||||
sqlite3_bind_parameter_index void;
|
||||
sqlite3_clear_bindings void;
|
||||
sqlite3_data_count void;
|
||||
sqlite3_column_count void;
|
||||
sqlite3_column_name void;
|
||||
sqlite3_column_name16 void;
|
||||
sqlite3_step void;
|
||||
sqlite3_reset void;
|
||||
sqlite3_column_blob void;
|
||||
sqlite3_column_double void;
|
||||
sqlite3_column_int void;
|
||||
sqlite3_column_int64 void;
|
||||
sqlite3_column_text void;
|
||||
sqlite3_column_text16 void;
|
||||
sqlite3_column_value void;
|
||||
sqlite3_column_bytes void;
|
||||
sqlite3_column_bytes16 void;
|
||||
sqlite3_column_type void;
|
||||
sqlite3_finalize void;
|
||||
sqlite3_vmprintf void;
|
||||
sqlite3_vsnprintf void;
|
||||
sqlite3_free void;
|
||||
sqlite3_last_insert_rowid void;
|
||||
sqlite3_threadsafe void;
|
||||
}
|
||||
|
||||
var fn struct;
|
||||
|
||||
func init() bool {
|
||||
import rt::c;
|
||||
return dlsyms(dlopen("libsqlite3.so.0", RTLD_LAZY), &fn,
|
||||
"sqlite3_open_v2",
|
||||
"sqlite3_close_v2",
|
||||
"sqlite3_exec",
|
||||
"sqlite3_prepare_v2",
|
||||
"sqlite3_bind_blob",
|
||||
"sqlite3_bind_double",
|
||||
"sqlite3_bind_int",
|
||||
"sqlite3_bind_null",
|
||||
"sqlite3_bind_text",
|
||||
"sqlite3_bind_text16",
|
||||
"sqlite3_bind_text64",
|
||||
"sqlite3_bind_value",
|
||||
"sqlite3_bind_zeroblob",
|
||||
"sqlite3_bind_parameter_count",
|
||||
"sqlite3_bind_parameter_name",
|
||||
"sqlite3_bind_parameter_index",
|
||||
"sqlite3_clear_bindings",
|
||||
"sqlite3_data_count",
|
||||
"sqlite3_column_count",
|
||||
"sqlite3_column_name",
|
||||
"sqlite3_column_name16",
|
||||
"sqlite3_step",
|
||||
"sqlite3_reset",
|
||||
"sqlite3_column_blob",
|
||||
"sqlite3_column_double",
|
||||
"sqlite3_column_int",
|
||||
"sqlite3_column_int64",
|
||||
"sqlite3_column_text",
|
||||
"sqlite3_column_text16",
|
||||
"sqlite3_column_value",
|
||||
"sqlite3_column_bytes",
|
||||
"sqlite3_column_bytes16",
|
||||
"sqlite3_column_type",
|
||||
"sqlite3_finalize",
|
||||
"sqlite3_vmprintf",
|
||||
"sqlite3_vsnprintf",
|
||||
"sqlite3_free",
|
||||
"sqlite3_last_insert_rowid",
|
||||
"sqlite3_threadsafe"
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module sqlite3+ {
|
||||
|
||||
define {
|
||||
SQLITE_OK = 0;
|
||||
SQLITE_ERROR = 1;
|
||||
SQLITE_INTERNAL = 2;
|
||||
SQLITE_PERM = 3;
|
||||
SQLITE_ABORT = 4;
|
||||
SQLITE_BUSY = 5;
|
||||
SQLITE_LOCKED = 6;
|
||||
SQLITE_NOMEM = 7;
|
||||
SQLITE_READONLY = 8;
|
||||
SQLITE_INTERRUPT = 9;
|
||||
SQLITE_IOERR = 10;
|
||||
SQLITE_CORRUPT = 11;
|
||||
SQLITE_NOTFOUND = 12;
|
||||
SQLITE_FULL = 13;
|
||||
SQLITE_CANTOPEN = 14;
|
||||
SQLITE_PROTOCOL = 15;
|
||||
SQLITE_EMPTY = 16;
|
||||
SQLITE_SCHEMA = 17;
|
||||
SQLITE_TOOBIG = 18;
|
||||
SQLITE_CONSTRAINT = 19;
|
||||
SQLITE_MISMATCH = 20;
|
||||
SQLITE_MISUSE = 21;
|
||||
SQLITE_NOLFS = 22;
|
||||
SQLITE_AUTH = 23;
|
||||
SQLITE_FORMAT = 24;
|
||||
SQLITE_RANGE = 25;
|
||||
SQLITE_NOTADB = 26;
|
||||
SQLITE_NOTICE = 27;
|
||||
SQLITE_WARNING = 28;
|
||||
SQLITE_ROW = 100;
|
||||
SQLITE_DONE = 101;
|
||||
}
|
||||
|
||||
define {
|
||||
SQLITE_OPEN_READONLY = 0x00000001;
|
||||
SQLITE_OPEN_READWRITE = 0x00000002;
|
||||
SQLITE_OPEN_CREATE = 0x00000004;
|
||||
SQLITE_OPEN_URI = 0x00000040;
|
||||
SQLITE_OPEN_MEMORY = 0x00000080;
|
||||
SQLITE_OPEN_NOMUTEX = 0x00008000;
|
||||
SQLITE_OPEN_FULLMUTEX = 0x00010000;
|
||||
SQLITE_OPEN_SHAREDCACHE = 0x00020000;
|
||||
SQLITE_OPEN_PRIVATECACHE = 0x00040000;
|
||||
SQLITE_PREPARE_PERSISTENT = 0x01;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module sqlite3+ {
|
||||
|
||||
inline sqlite3_open_v2(filename. char, ppDb+ void, flags int, zVfs. char) int {
|
||||
return call4<int>(so::fn.sqlite3_open_v2, filename, ppDb, flags, zVfs);
|
||||
}
|
||||
|
||||
inline sqlite3_close_v2(db void) int {
|
||||
return call1<int>(so::fn.sqlite3_close_v2, db);
|
||||
}
|
||||
|
||||
inline sqlite3_exec(db void, sql. char, callback void, callback_param void, errmsg++ char) int {
|
||||
return call5<int>(so::fn.sqlite3_exec, db, sql, callback, callback_param, errmsg);
|
||||
}
|
||||
|
||||
inline sqlite3_prepare_v2(db void, zSql. char, nByte int, ppStmt void, pzTail++ char) int {
|
||||
return call5<int>(so::fn.sqlite3_prepare_v2, db, zSql, nByte, ppStmt, pzTail);
|
||||
}
|
||||
|
||||
inline sqlite3_bind_blob(stmt void, index int, blob void, blob_size int, callback void) int {
|
||||
return call5<int>(so::fn.sqlite3_bind_blob, stmt, index, blob, blob_size, callback);
|
||||
}
|
||||
|
||||
inline sqlite3_bind_double(stmt void, index int, data double) int {
|
||||
return call_rrd<int>(so::fn.sqlite3_bind_double, stmt, index, data);
|
||||
}
|
||||
|
||||
inline sqlite3_bind_int(stmt void, index int, data int) int {
|
||||
return call3<int>(so::fn.sqlite3_bind_int, stmt, index, data);
|
||||
}
|
||||
|
||||
inline sqlite3_bind_null(stmt void, index int) int {
|
||||
return call2<int>(so::fn.sqlite3_bind_null, stmt, index);
|
||||
}
|
||||
|
||||
inline sqlite3_bind_text(stmt void, index int, text. char, text_len int, callback void) int {
|
||||
return call5<int>(so::fn.sqlite3_bind_text, stmt, index, text, text_len, callback);
|
||||
}
|
||||
|
||||
inline sqlite3_bind_text16(stmt void, index int, text void, text_len int, callback void) int {
|
||||
return call5<int>(so::fn.sqlite3_bind_text16, stmt, index, text, text_len, callback);
|
||||
}
|
||||
|
||||
inline sqlite3_bind_text64(stmt void, index int, text. char, text_len int64, callback void, encoding char) int {
|
||||
return call6<int>(so::fn.sqlite3_bind_text64, stmt, index, text, text_len, callback, encoding);
|
||||
}
|
||||
|
||||
inline sqlite3_bind_value(stmt void, index int, value void) int {
|
||||
return call3<int>(so::fn.sqlite3_bind_value, stmt, index, value);
|
||||
}
|
||||
|
||||
inline sqlite3_bind_zeroblob(stmt void, index int, n int) int {
|
||||
return call3<int>(so::fn.sqlite3_bind_zeroblob, stmt, index, n);
|
||||
}
|
||||
|
||||
inline sqlite3_bind_parameter_count(stmt void) int {
|
||||
return call1<int>(so::fn.sqlite3_bind_parameter_count, stmt);
|
||||
}
|
||||
|
||||
inline sqlite3_bind_parameter_name(stmt void, index int) .char {
|
||||
return call2<char*>(so::fn.sqlite3_bind_parameter_name, stmt, index);
|
||||
}
|
||||
|
||||
inline sqlite3_bind_parameter_index(stmt void, zName. char) int {
|
||||
return call2<int>(so::fn.sqlite3_bind_parameter_index, stmt, zName);
|
||||
}
|
||||
|
||||
inline sqlite3_clear_bindings(stmt void) int {
|
||||
return call1<int>(so::fn.sqlite3_clear_bindings, stmt);
|
||||
}
|
||||
|
||||
inline sqlite3_data_count(stmt void) int {
|
||||
return call1<int>(so::fn.sqlite3_data_count, stmt);
|
||||
}
|
||||
|
||||
inline sqlite3_column_count(stmt void) int {
|
||||
return call1<int>(so::fn.sqlite3_column_count, stmt);
|
||||
}
|
||||
|
||||
inline sqlite3_column_name(stmt void, index int) .char {
|
||||
return call2<char*>(so::fn.sqlite3_column_name, stmt, index);
|
||||
}
|
||||
|
||||
inline sqlite3_column_name16(stmt void, index int) void {
|
||||
return call2<void>(so::fn.sqlite3_column_name16, stmt, index);
|
||||
}
|
||||
|
||||
inline sqlite3_step(stmt void) int {
|
||||
return call1<int>(so::fn.sqlite3_step, stmt);
|
||||
}
|
||||
|
||||
inline sqlite3_reset(stmt void) int {
|
||||
return call1<int>(so::fn.sqlite3_reset, stmt);
|
||||
}
|
||||
|
||||
inline sqlite3_column_blob(stmt void, iCol int) void {
|
||||
return call2<void>(so::fn.sqlite3_column_blob, stmt, iCol);
|
||||
}
|
||||
|
||||
inline sqlite3_column_double(stmt void, iCol int) double {
|
||||
return callf_rr<double>(so::fn.sqlite3_column_double, stmt, iCol);
|
||||
}
|
||||
|
||||
inline sqlite3_column_int(stmt void, iCol int) int {
|
||||
return call2<int>(so::fn.sqlite3_column_int, stmt, iCol);
|
||||
}
|
||||
|
||||
inline sqlite3_column_int64(stmt void, iCol int) int64 {
|
||||
return call_64_2<int64>(so::fn.sqlite3_column_int64, stmt, iCol);
|
||||
}
|
||||
|
||||
inline sqlite3_column_text(stmt void, iCol int) .char {
|
||||
return call2<char*>(so::fn.sqlite3_column_text, stmt, iCol);
|
||||
}
|
||||
|
||||
inline sqlite3_column_text16(stmt void, iCol int) void {
|
||||
return call2<void>(so::fn.sqlite3_column_text16, stmt, iCol);
|
||||
}
|
||||
|
||||
inline sqlite3_column_value(stmt void, iCol int) void {
|
||||
return call2<void>(so::fn.sqlite3_column_value, stmt, iCol);
|
||||
}
|
||||
|
||||
inline sqlite3_column_bytes(stmt void, iCol int) int {
|
||||
return call2<int>(so::fn.sqlite3_column_bytes, stmt, iCol);
|
||||
}
|
||||
|
||||
inline sqlite3_column_bytes16(stmt void, iCol int) int {
|
||||
return call2<int>(so::fn.sqlite3_column_bytes16, stmt, iCol);
|
||||
}
|
||||
|
||||
inline sqlite3_column_type(stmt void, iCol int) int {
|
||||
return call2<int>(so::fn.sqlite3_column_type, stmt, iCol);
|
||||
}
|
||||
|
||||
inline sqlite3_finalize(stmt void) int {
|
||||
return call1<int>(so::fn.sqlite3_finalize, stmt);
|
||||
}
|
||||
|
||||
inline sqlite3_vmprintf(sql. char, ap void) .char {
|
||||
return call2<char*>(so::fn.sqlite3_vmprintf, sql, ap);
|
||||
}
|
||||
|
||||
func sqlite3_mprintf(sql. char, ...) .char {
|
||||
return sqlite3_vmprintf(sql, va_start(sql));
|
||||
}
|
||||
|
||||
inline sqlite3_vsnprintf(len int, str. char, sql. char, ap void) .char {
|
||||
return call4<char*>(so::fn.sqlite3_vsnprintf, len, str, sql, ap);
|
||||
}
|
||||
|
||||
func sqlite3_snprintf(len int, str. char, sql. char, ...) .char {
|
||||
return sqlite3_vsnprintf(len, str, sql, va_start(len));
|
||||
}
|
||||
|
||||
inline sqlite3_free(ptr void) {
|
||||
call1<void>(so::fn.sqlite3_free, ptr);
|
||||
}
|
||||
|
||||
inline sqlite3_last_insert_rowid(db void) int64 {
|
||||
return call_64_1<int64>(so::fn.sqlite3_last_insert_rowid, db);
|
||||
}
|
||||
|
||||
inline sqlite3_threadsafe() int {
|
||||
return call<int>(so::fn.sqlite3_threadsafe);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
|
||||
inline va_size(x& void) uint32 {
|
||||
using size. uint32 = .x - 8;
|
||||
func = .size;
|
||||
}
|
||||
|
||||
inline va_start(x& void) void {
|
||||
using size. uint32 = .x - 8;
|
||||
func = .x - (.size + 8);
|
||||
}
|
||||
|
||||
inline va_next<T>(ap& void) {
|
||||
ap += ((sizeof(T) + (sizeof(word) - 1)) /
|
||||
sizeof(word) * sizeof(word));
|
||||
}
|
||||
|
||||
inline va_nexts<T>(ap& void, size& uint32) {
|
||||
define {
|
||||
x = ((sizeof(T) + (sizeof(word) - 1)) /
|
||||
sizeof(word) * sizeof(word));
|
||||
}
|
||||
ap += x, size -= x;
|
||||
}
|
||||
@@ -1,91 +0,0 @@
|
||||
|
||||
runtime call<T>(addr void) T = 1000;
|
||||
runtime call1<T>(addr void, arg1 word) T = 1001;
|
||||
runtime call2<T>(addr void, arg1 word, arg2 word) T = 1002;
|
||||
runtime call3<T>(addr void, arg1 word, arg2 word, arg3 word) T = 1003;
|
||||
runtime call4<T>(addr void, arg1 word, arg2 word, arg3 word, arg4 word) T = 1004;
|
||||
runtime call5<T>(addr void, arg1 word, arg2 word, arg3 word, arg4 word, arg5 word) T = 1005;
|
||||
runtime call6<T>(addr void, arg1 word, arg2 word, arg3 word, arg4 word, arg5 word, arg6 word) T = 1006;
|
||||
runtime call7<T>(addr void, arg1 word, arg2 word, arg3 word, arg4 word, arg5 word, arg6 word, arg7 word) T = 1007;
|
||||
runtime call8<T>(addr void, arg1 word, arg2 word, arg3 word, arg4 word, arg5 word, arg6 word, arg7 word, arg8 word) T = 1008;
|
||||
runtime call9<T>(addr void, arg1 word, arg2 word, arg3 word, arg4 word, arg5 word, arg6 word, arg7 word, arg8 word, arg9 word) T = 1009;
|
||||
runtime call10<T>(addr void, arg1 word, arg2 word, arg3 word, arg4 word, arg5 word, arg6 word, arg7 word, arg8 word, arg9 word, arg10 word) T = 1010;
|
||||
runtime call11<T>(addr void, arg1 word, arg2 word, arg3 word, arg4 word, arg5 word, arg6 word, arg7 word, arg8 word, arg9 word, arg10 word, arg11 word) T = 1011;
|
||||
runtime call12<T>(addr void, arg1 word, arg2 word, arg3 word, arg4 word, arg5 word, arg6 word, arg7 word, arg8 word, arg9 word, arg10 word, arg11 word, arg12 word) T = 1012;
|
||||
runtime call13<T>(addr void, arg1 word, arg2 word, arg3 word, arg4 word, arg5 word, arg6 word, arg7 word, arg8 word, arg9 word, arg10 word, arg11 word, arg12 word, arg13 word) T = 1013;
|
||||
runtime call14<T>(addr void, arg1 word, arg2 word, arg3 word, arg4 word, arg5 word, arg6 word, arg7 word, arg8 word, arg9 word, arg10 word, arg11 word, arg12 word, arg13 word, arg14 word) T = 1014;
|
||||
runtime call15<T>(addr void, arg1 word, arg2 word, arg3 word, arg4 word, arg5 word, arg6 word, arg7 word, arg8 word, arg9 word, arg10 word, arg11 word, arg12 word, arg13 word, arg14 word, arg15 word) T = 1015;
|
||||
runtime call16<T>(addr void, arg1 word, arg2 word, arg3 word, arg4 word, arg5 word, arg6 word, arg7 word, arg8 word, arg9 word, arg10 word, arg11 word, arg12 word, arg13 word, arg14 word, arg15 word, arg16 word) T = 1016;
|
||||
|
||||
runtime call_64<T>(addr void) T = 1017;
|
||||
runtime call_64_1<T>(addr void, arg1 word) T = 1018;
|
||||
runtime call_64_2<T>(addr void, arg1 word, arg2 word) T = 1019;
|
||||
runtime call_64_3<T>(addr void, arg1 word, arg2 word, arg3 word) T = 1020;
|
||||
runtime call_64_4<T>(addr void, arg1 word, arg2 word, arg3 word, arg4 word) T = 1021;
|
||||
runtime call_64_5<T>(addr void, arg1 word, arg2 word, arg3 word, arg4 word, arg5 word) T = 1022;
|
||||
runtime call_64_6<T>(addr void, arg1 word, arg2 word, arg3 word, arg4 word, arg5 word, arg6 word) T = 1023;
|
||||
runtime call_64_7<T>(addr void, arg1 word, arg2 word, arg3 word, arg4 word, arg5 word, arg6 word, arg7 word) T = 1024;
|
||||
runtime call_64_8<T>(addr void, arg1 word, arg2 word, arg3 word, arg4 word, arg5 word, arg6 word, arg7 word, arg8 word) T = 1025;
|
||||
|
||||
runtime callf<T>(addr void) T = 1026;
|
||||
runtime callf_r<T>(addr void, arg1 word) T = 1027;
|
||||
runtime callf_rr<T>(addr void, arg1 word, arg2 word) T = 1028;
|
||||
runtime callf_rrr<T>(addr void, arg1 word, arg2 word, arg3 word) T = 1029;
|
||||
runtime callf_rrrr<T>(addr void, arg1 word, arg2 word, arg3 word, arg4 word) T = 1030;
|
||||
runtime callf_f<T>(addr void, arg1 float) T = 1031;
|
||||
runtime callf_ff<T>(addr void, arg1 float, arg2 float) T = 1032;
|
||||
runtime callf_fff<T>(addr void, arg1 float, arg2 float, arg3 float) T = 1033;
|
||||
runtime callf_fd<T>(addr void, arg1 float, arg2 double) T = 1034;
|
||||
runtime callf_df<T>(addr void, arg1 double, arg2 float) T = 1035;
|
||||
runtime callf_d<T>(addr void, arg1 double) T = 1036;
|
||||
runtime callf_dd<T>(addr void, arg1 double, arg2 double) T = 1037;
|
||||
runtime callf_ddd<T>(addr void, arg1 double, arg2 double, arg3 double) T = 1038;
|
||||
|
||||
runtime call_f<T>(addr void, arg1 float) T = 1039;
|
||||
runtime call_ff<T>(addr void, arg1 float, arg2 float) T = 1040;
|
||||
runtime call_fff<T>(addr void, arg1 float, arg2 float, arg3 float) T = 1041;
|
||||
runtime call_ffff<T>(addr void, arg1 float, arg2 float, arg3 float, arg4 float) T = 1042;
|
||||
runtime call_ffr<T>(addr void, arg1 float, arg2 float, arg3 word) T = 1043;
|
||||
runtime call_rf<T>(addr void, arg1 word, arg2 float) T = 1044;
|
||||
runtime call_rff<T>(addr void, arg1 word, arg2 float, arg3 float) T = 1045;
|
||||
runtime call_rrf<T>(addr void, arg1 word, arg2 word, arg3 float) T = 1046;
|
||||
runtime call_rrrf<T>(addr void, arg1 word, arg2 word, arg3 word, arg4 float) T = 1047;
|
||||
runtime call_rfff<T>(addr void, arg1 word, arg2 float, arg3 float, arg4 float) T = 1048;
|
||||
runtime call_fffr<T>(addr void, arg1 float, arg2 float, arg3 float, arg4 word) T = 1049;
|
||||
runtime call_rrff<T>(addr void, arg1 word, arg2 word, arg3 float, arg4 float) T = 1050;
|
||||
runtime call_ffrr<T>(addr void, arg1 float, arg2 float, arg3 word, arg4 word) T = 1051;
|
||||
runtime call_fr<T>(addr void, arg1 float, arg2 word) T = 1052;
|
||||
runtime call_frr<T>(addr void, arg1 float, arg2 word, arg3 word) T = 1053;
|
||||
runtime call_frrr<T>(addr void, arg1 float, arg2 word, arg3 word, arg4 word) T = 1054;
|
||||
|
||||
runtime call_d<T>(addr void, arg1 double) T = 1055;
|
||||
runtime call_dd<T>(addr void, arg1 double, arg2 double) T = 1056;
|
||||
runtime call_ddd<T>(addr void, arg1 double, arg2 double, arg3 double) T = 1057;
|
||||
runtime call_dddd<T>(addr void, arg1 double, arg2 double, arg3 double, arg4 double) T = 1058;
|
||||
runtime call_ddr<T>(addr void, arg1 double, arg2 double, arg3 word) T = 1059;
|
||||
runtime call_rd<T>(addr void, arg1 word, arg2 double) T = 1060;
|
||||
runtime call_rdd<T>(addr void, arg1 word, arg2 double, arg3 double) T = 1061;
|
||||
runtime call_rrd<T>(addr void, arg1 word, arg2 word, arg3 double) T = 1062;
|
||||
runtime call_rrrd<T>(addr void, arg1 word, arg2 word, arg3 word, arg4 double) T = 1063;
|
||||
runtime call_rddd<T>(addr void, arg1 word, arg2 double, arg3 double, arg4 double) T = 1064;
|
||||
runtime call_dddr<T>(addr void, arg1 double, arg2 double, arg3 double, arg4 word) T = 1065;
|
||||
runtime call_rrdd<T>(addr void, arg1 word, arg2 word, arg3 double, arg4 double) T = 1066;
|
||||
runtime call_ddrr<T>(addr void, arg1 double, arg2 double, arg3 word, arg4 word) T = 1067;
|
||||
runtime call_dr<T>(addr void, arg1 double, arg2 word) T = 1068;
|
||||
runtime call_drr<T>(addr void, arg1 double, arg2 word, arg3 word) T = 1069;
|
||||
runtime call_drrr<T>(addr void, arg1 double, arg2 word, arg3 word, arg4 word) T = 1070;
|
||||
|
||||
runtime call_df<T>(addr void, arg1 double, arg2 float) T = 1071;
|
||||
runtime call_dff<T>(addr void, arg1 double, arg2 float, arg3 float) T = 1072;
|
||||
runtime call_ddf<T>(addr void, arg1 double, arg2 double, arg3 float) T = 1073;
|
||||
runtime call_dddf<T>(addr void, arg1 double, arg2 double, arg3 double, arg4 float) T = 1074;
|
||||
runtime call_dfff<T>(addr void, arg1 double, arg2 float, arg3 float, arg4 float) T = 1075;
|
||||
runtime call_fffd<T>(addr void, arg1 float, arg2 float, arg3 float, arg4 double) T = 1076;
|
||||
runtime call_ddff<T>(addr void, arg1 double, arg2 double, arg3 float, arg4 float) T = 1077;
|
||||
runtime call_ffdd<T>(addr void, arg1 float, arg2 float, arg3 double, arg4 double) T = 1078;
|
||||
runtime call_ffd<T>(addr void, arg1 float, arg2 float, arg3 double) T = 1079;
|
||||
runtime call_fd<T>(addr void, arg1 float, arg2 double) T = 1080;
|
||||
runtime call_fdd<T>(addr void, arg1 float, arg2 double, arg3 double) T = 1081;
|
||||
runtime call_fddd<T>(addr void, arg1 float, arg2 double, arg3 double, arg4 double) T = 1082;
|
||||
|
||||
runtime call_rrrrdrr<T>(addr void, arg1 word, arg2 word, arg3 word, arg4 word, arg5 double, arg6 word, arg7 word) T = 1083;
|
||||
@@ -1,503 +0,0 @@
|
||||
|
||||
module rt+, c+ {
|
||||
|
||||
import libc;
|
||||
|
||||
// #include <stdlib.h>
|
||||
// #include <string.h>
|
||||
|
||||
func malloc(size size_t) void {
|
||||
runtime malloc(size size_t) void = 100;
|
||||
if (func = malloc(size)) == null {
|
||||
printf("malloc(0x%x): out of memory.\n", size);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
func realloc(ptr void, size size_t) void {
|
||||
runtime realloc(ptr void, size size_t) void = 101;
|
||||
if (func = realloc(ptr, size)) == null {
|
||||
printf("realloc(0x%x): out of memory.\n", size);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
func calloc(nmemb size_t, size size_t) void {
|
||||
runtime calloc(nmemb size_t, size size_t) void = 102;
|
||||
if (func = calloc(nmemb, size)) == null {
|
||||
printf("calloc(0x%x): out of memory.\n", size);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
func strdup(s. char) .char {
|
||||
runtime strdup(s. char) .char = 103;
|
||||
if (func = strdup(s)) == null {
|
||||
printf("strdup: out of memory.\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
runtime free(ptr void) = 104;
|
||||
|
||||
inline malloc_t<T>() .T {
|
||||
func = malloc(sizeof(T));
|
||||
#if objectid(T).func.constructor;
|
||||
func->constructor();
|
||||
#endif
|
||||
}
|
||||
|
||||
inline free_t<T>(block. T) {
|
||||
#if objectid(T).func.destructor;
|
||||
block->destructor();
|
||||
#endif
|
||||
free(block);
|
||||
}
|
||||
|
||||
// #include <string.h>
|
||||
runtime strcpy(dest. char, src. char) .char = 105;
|
||||
runtime strncpy(dest. char, src. char, n size_t) .char = 106;
|
||||
runtime strlen(s. char) size_t = 107;
|
||||
runtime strcmp(s1. char, s2. char) int = 108;
|
||||
runtime strncmp(s1. char, s2. char, n size_t) int = 109;
|
||||
runtime strcasecmp(s1. char, s2. char) int = 110;
|
||||
runtime strncasecmp(s1. char, s2. char, n size_t) int = 111;
|
||||
runtime strstr(haystack. char, needle. char) .char = 112;
|
||||
runtime strchr(s. char, c int) .char = 113;
|
||||
runtime strrchr(s. char, c int) .char = 114;
|
||||
|
||||
// #include <string.h>
|
||||
runtime memcpy(dest void, src void, n size_t) void = 115;
|
||||
runtime memmove(dest void, src void, n size_t) void = 116;
|
||||
runtime memcmp(s1 void, s2 void, n size_t) int = 117;
|
||||
// runtime memmem(haystack void, haystacklen size_t, needle void, needlelen size_t) void = 118;
|
||||
runtime memset(s void, c int, n size_t) void = 119;
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2005 Pascal Gloor <pascal.gloor@spale.com>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
func memchr(s void, c int, n size_t) void {
|
||||
if n {
|
||||
var p. unsigned char = s;
|
||||
for ;; {
|
||||
if .p == unsigned char(c);
|
||||
return p;
|
||||
p++;
|
||||
if !(--n);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
func memmem(l void, l_len size_t, s void, s_len size_t) void {
|
||||
if !l_len or !s_len or l_len < s_len;
|
||||
return null;
|
||||
var cl. char = l, cs. char = s;
|
||||
if s_len == 1;
|
||||
return memchr(cl, .cs, 1);
|
||||
var cur. char = cl, last. char = cl + l_len - s_len;
|
||||
for ; cur <= last; cur += 1 {
|
||||
if .cur == .cs and !memcmp(cur, cs, s_len);
|
||||
return cur;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// #include <ctype.h>
|
||||
runtime tolower(c int) int = 120;
|
||||
runtime toupper(c int) int = 121;
|
||||
runtime isalnum(c int) int = 122;
|
||||
runtime isalpha(c int) int = 123;
|
||||
runtime isascii(c int) int = 124;
|
||||
runtime isblank(c int) int = 125;
|
||||
runtime iscntrl(c int) int = 126;
|
||||
runtime isdigit(c int) int = 127;
|
||||
runtime isgraph(c int) int = 128;
|
||||
runtime islower(c int) int = 129;
|
||||
runtime isprint(c int) int = 130;
|
||||
runtime ispunct(c int) int = 131;
|
||||
runtime isspace(c int) int = 132;
|
||||
runtime isupper(c int) int = 133;
|
||||
runtime isxdigit(c int) int = 134;
|
||||
|
||||
func strupper(str. char) {
|
||||
while .str;
|
||||
.str = toupper(.str), str += 1;
|
||||
}
|
||||
|
||||
func strlower(str. char) {
|
||||
while .str;
|
||||
.str = tolower(.str), str += 1;
|
||||
}
|
||||
|
||||
func isnumeric(str. char) bool {
|
||||
if !(.str);
|
||||
return false;
|
||||
for ;; {
|
||||
if !isdigit(.str);
|
||||
return false;
|
||||
if !(.(++str));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// #include <stdlib.h>
|
||||
runtime atoi(nptr. char) int = 135;
|
||||
runtime atol(nptr. char) long = 136;
|
||||
runtime atoll(nptr. char) dlong = 137;
|
||||
runtime atof(nptr. char) double = 138;
|
||||
runtime strtod(nptr. char, endptr++ char) double = 139;
|
||||
runtime strtof(nptr. char, endptr++ char) float = 140;
|
||||
|
||||
// #include <stdlib.h>
|
||||
runtime srand(seed unsigned int) = 141;
|
||||
runtime rand() int = 142;
|
||||
|
||||
inline randf() float {
|
||||
return float(rand()) / RAND_MAX;
|
||||
}
|
||||
|
||||
inline random<T>(value T) T {
|
||||
return randf() * value;
|
||||
}
|
||||
|
||||
inline random2<T>(min T, max T) T {
|
||||
return T(randf() * float(max - min + 1)) + min;
|
||||
}
|
||||
|
||||
func srand2(a uint, b uint, c uint) {
|
||||
a=a-b;a=a-c;a=a^(c>>13);
|
||||
b=b-c;b=b-a;b=b^(a<<8);
|
||||
c=c-a;c=c-b;c=c^(b>>13);
|
||||
a=a-b;a=a-c;a=a^(c>>12);
|
||||
b=b-c;b=b-a;b=b^(a<<16);
|
||||
c=c-a;c=c-b;c=c^(b>>5);
|
||||
a=a-b;a=a-c;a=a^(c>>3);
|
||||
b=b-c;b=b-a;b=b^(a<<10);
|
||||
c=c-a;c=c-b;c=c^(b>>15);
|
||||
srand(c);
|
||||
}
|
||||
|
||||
// #include <stdio.h>
|
||||
runtime get_stdin() +FILE = 143;
|
||||
runtime get_stdout() +FILE = 144;
|
||||
runtime get_stderr() +FILE = 145;
|
||||
|
||||
// #include <stdio.h>
|
||||
runtime fopen(pathname. char, mode. char) +FILE = 146;
|
||||
runtime fdopen(fd int, mode. char) +FILE = 147;
|
||||
runtime freopen(pathname. char, mode. char, stream+ FILE) +FILE = 148;
|
||||
runtime fclose(stream+ FILE) int = 149;
|
||||
runtime fileno(stream+ FILE) int = 150;
|
||||
runtime fwrite(ptr void, size size_t, nmemb size_t, stream+ FILE) size_t = 151;
|
||||
runtime fread(ptr void, size size_t, nmemb size_t, stream+ FILE) size_t = 152;
|
||||
runtime fputc(c int, stream+ FILE) int = 153;
|
||||
runtime fputs(s. char, stream+ FILE) int = 154;
|
||||
runtime fgetc(stream+ FILE) int = 155;
|
||||
runtime fgets(s. char, size int, stream+ FILE) .char = 156;
|
||||
runtime feof(stream+ FILE) int = 157;
|
||||
runtime fseek(stream+ FILE, offset long, whence int) int = 158;
|
||||
runtime ftell(stream+ FILE) long = 159;
|
||||
runtime fgetpos(stream+ FILE, pos+ fpos_t) int = 160;
|
||||
runtime fsetpos(stream+ FILE, pos+ fpos_t) int = 161;
|
||||
runtime fflush(stream+ FILE) int = 162;
|
||||
runtime ferror(stream+ FILE) int = 163;
|
||||
runtime rewind(stream+ FILE) = 164;
|
||||
runtime clearerr(stream+ FILE) = 165;
|
||||
|
||||
// #include <dirent.h>
|
||||
runtime opendir(name. char) +DIR = 166;
|
||||
runtime fdopendir(fd int) +DIR = 167;
|
||||
runtime readdir(dirp+ DIR) .struct_dirent = 168;
|
||||
runtime seekdir(dirp+ DIR, offset long) = 169;
|
||||
runtime telldir(dirp+ DIR) long = 170;
|
||||
runtime rewinddir(dirp+ DIR) = 171;
|
||||
runtime closedir(dirp+ DIR) = 172;
|
||||
|
||||
// #include <sys/stat.h>
|
||||
// #include <unistd.h>
|
||||
runtime mkdir(pathname. char, mode mode_t) int = 173;
|
||||
runtime rmdir(pathname. char) int = 174;
|
||||
runtime mkfifo(pathname. char, mode mode_t) int = 175;
|
||||
|
||||
// #include <sys/stat.h>
|
||||
// #include <fcntl.h>
|
||||
// #include <unistd.h>
|
||||
runtime open(pathname. char, flags int) int = 176;
|
||||
runtime creat(pathname. char, flags int, mode mode_t) int = 177;
|
||||
runtime close(fd int) int = 178;
|
||||
runtime read(fd int, buf void, count size_t) ssize_t = 179;
|
||||
runtime write(fd int, buf void, count size_t) ssize_t = 180;
|
||||
|
||||
// #include <stdio.h>
|
||||
runtime rename(oldpath. char, newpath. char) int = 181;
|
||||
runtime remove(pathname. char) int = 182;
|
||||
|
||||
// #include <unistd.h>
|
||||
runtime link(oldpath. char, newpath. char) int = 183;
|
||||
runtime unlink(pathname. char) int = 184;
|
||||
runtime symlink(target. char, linkpath. char) int = 185;
|
||||
|
||||
// #include <unistd.h>
|
||||
// #include <sys/stat.h>
|
||||
runtime stat(path. char, buf. struct_stat) int = 186;
|
||||
runtime fstat(fd int, buf. struct_stat) int = 187;
|
||||
|
||||
// #include <unistd.h>
|
||||
runtime chown(pathname. char, owner uid_t, group gid_t) int = 188;
|
||||
runtime fchown(fd int, owner uid_t, group gid_t) int = 189;
|
||||
|
||||
// #include <sys/stat.h>
|
||||
runtime chmod(pathname. char, mode mode_t) int = 190;
|
||||
runtime fchmod(fd int, mode mode_t) int = 191;
|
||||
|
||||
// #include <unistd.h>
|
||||
runtime chdir(path. char) int = 192;
|
||||
runtime fchdir(fd int) int = 193;
|
||||
runtime truncate(path. char, length off_t) int = 194;
|
||||
runtime ftruncate(fd int, length off_t) int = 195;
|
||||
|
||||
// #include <sys/mount.h>
|
||||
runtime mount(source. char, target. char, filesystemtype. char, mountflags unsigned long, data void) int = 196;
|
||||
|
||||
// #include <time.h>
|
||||
runtime time(t. time_t) time_t = 197;
|
||||
runtime asctime(tm. struct_tm) .char = 198;
|
||||
runtime ctime(timep. time_t) .char = 199;
|
||||
runtime gmtime(timep. time_t) .struct_tm = 200;
|
||||
runtime localtime(timep. time_t) .struct_tm = 201;
|
||||
runtime difftime(time1 time_t, time2 time_t) double = 202;
|
||||
runtime mktime(tm. struct_tm) time_t = 203;
|
||||
runtime clock() clock_t = 204;
|
||||
runtime clock_getres(clk_id clockid_t, res. struct_timespec) int = 205;
|
||||
runtime clock_gettime(clk_id clockid_t, tp. struct_timespec) int = 206;
|
||||
runtime clock_settime(clk_id clockid_t, tp. struct_timespec) = 207;
|
||||
|
||||
// #include <sys/stat.h>
|
||||
runtime umask(mask mode_t) mode_t = 208;
|
||||
|
||||
// #include <stdlib.h>
|
||||
runtime getenv(name. char) .char = 209;
|
||||
runtime setenv(name. char, value. char, overwrite int) int = 210;
|
||||
runtime unsetenv(name. char) int = 211;
|
||||
runtime putenv(string. char) int = 212;
|
||||
runtime clearenv() int = 213;
|
||||
|
||||
// #include <unistd.h>
|
||||
runtime getpid() pid_t = 214;
|
||||
runtime getppid() pid_t = 215;
|
||||
|
||||
// #include <stdlib.h>
|
||||
runtime system(command. char) int = 216;
|
||||
|
||||
// #include <errno.h>
|
||||
runtime get_errno() int = 217;
|
||||
runtime set_errno(err int) = 218;
|
||||
|
||||
// #include <stdlib.h>
|
||||
runtime exit(status int) = 219;
|
||||
|
||||
// #include <stdio.h>
|
||||
runtime vprintf(format. char, ap+ va_list) int = 220;
|
||||
runtime vsprintf(str. char, format. char, ap+ va_list) int = 221;
|
||||
runtime vsnprintf(str. char, size size_t, format. char, ap+ va_list) int = 222;
|
||||
runtime vscanf(format. char, ap+ va_list) int = 223;
|
||||
runtime vsscanf(str. char, format. char, ap+ va_list) int = 224;
|
||||
runtime vfprintf(stream+ FILE, format. char, ap+ va_list) int = 225;
|
||||
runtime vfscanf(stream+ FILE, format. char, ap+ va_list) int = 226;
|
||||
|
||||
func printf(format. char, ...) int {
|
||||
return vprintf(format, va_start(format));
|
||||
}
|
||||
func sprintf(str. char, format. char, ...) int {
|
||||
return vsprintf(str, format, va_start(str));
|
||||
}
|
||||
func snprintf(str. char, size size_t, format. char, ...) int {
|
||||
return vsnprintf(str, size, format, va_start(str));
|
||||
}
|
||||
func scanf(format. char, ...) int {
|
||||
return vscanf(format, va_start(format));
|
||||
}
|
||||
func sscanf(str. char, format. char, ...) int {
|
||||
return vsscanf(str, format, va_start(str));
|
||||
}
|
||||
func fprintf(stream+ FILE, format. char, ...) int {
|
||||
return vfprintf(stream, format, va_start(stream));
|
||||
}
|
||||
func fscanf(stream+ FILE, format. char, ...) int {
|
||||
return vfscanf(stream, format, va_start(stream));
|
||||
}
|
||||
|
||||
inline vsprintfp(format. char, ap void) .char {
|
||||
var len int = vsnprintf(null, 0, format, ap);
|
||||
vsnprintf(func = malloc(++len), len, format, ap);
|
||||
}
|
||||
|
||||
func sprintfp(format. char, ...) .char {
|
||||
return vsprintfp(format, va_start(format));
|
||||
}
|
||||
|
||||
// #include <fcntl.h>
|
||||
runtime fcntl(fd int, cmd int, arg word) int = 227;
|
||||
runtime fcntl2(fd int, cmd int, arg1 word, arg2 word) int = 228;
|
||||
runtime fcntl3(fd int, cmd int, arg1 word, arg2 word, arg3 word) int = 229;
|
||||
runtime fcntl4(fd int, cmd int, arg1 word, arg2 word, arg3 word, arg4 word) int = 230;
|
||||
|
||||
// #include <sys/ioctl.h>
|
||||
runtime ioctl(fd int, request unsigned long, arg word) int = 231;
|
||||
runtime ioctl2(fd int, request unsigned long, arg1 word, arg2 word) int = 232;
|
||||
runtime ioctl3(fd int, request unsigned long, arg1 word, arg2 word, arg3 word) int = 233;
|
||||
runtime ioctl4(fd int, request unsigned long, arg1 word, arg2 word, arg3 word, arg4 word) int = 234;
|
||||
|
||||
// #include <utime.h>
|
||||
runtime utime(filename. char, times. struct_utimbuf) int = 235;
|
||||
runtime utimes(filename. char, times. struct_timeval) int = 236;
|
||||
|
||||
// #include <sys/mount.h>
|
||||
runtime umount(target. char) int = 237;
|
||||
runtime umount2(target. char, flags int) int = 238;
|
||||
|
||||
// #include <unistd.h>
|
||||
runtime getcwd(buf. char, size size_t) .char = 239;
|
||||
runtime sysconf(name int) long = 240;
|
||||
runtime sleep(seconds unsigned int) int = 241;
|
||||
runtime usleep(usec useconds_t) int = 242;
|
||||
|
||||
// #include <locale.h>
|
||||
runtime setlocale(category int, locale. char) .char = 243;
|
||||
runtime localeconv() .struct_lconv = 244;
|
||||
|
||||
// #include <stdio.h>
|
||||
runtime popen(command. char, type. char) +FILE = 245;
|
||||
runtime pclose(stream+ FILE) int = 246;
|
||||
|
||||
// #include <signal.h>
|
||||
runtime kill(pid pid_t, sig int) int = 247;
|
||||
|
||||
// #include <sys/select.h>
|
||||
runtime select(nfds int, readfds. fd_set, writefds. fd_set, exceptfds. fd_set, timeout. struct_timeval) int = 248;
|
||||
|
||||
// #include <sys/select.h>
|
||||
runtime FD_CLR(fd int, set. fd_set) = 249;
|
||||
runtime FD_ISSET(fd int, set. fd_set) int = 250;
|
||||
runtime FD_SET(fd int, set. fd_set) = 251;
|
||||
runtime FD_ZERO(set. fd_set) = 252;
|
||||
|
||||
// #include <poll.h>
|
||||
runtime poll(fds. struct_pollfd, nfds nfds_t, timeout int) = 253;
|
||||
|
||||
// #include <arpa/inet.h>
|
||||
// #include <sys/socket.h>
|
||||
runtime socket(domain int, type int, protocol int) int = 254;
|
||||
runtime getsockopt(sockfd int, level int, optname int, optval void, optlen. socklen_t) int = 255;
|
||||
runtime setsockopt(sockfd int, level int, optname int, optval void, optlen socklen_t) int = 256;
|
||||
runtime connect(sockfd int, addr. struct_sockaddr, addrlen socklen_t) int = 257;
|
||||
runtime accept(sockfd int, addr. struct_sockaddr, addrlen. socklen_t) int = 258;
|
||||
runtime bind(sockfd int, addr. struct_sockaddr, addrlen socklen_t) int = 259;
|
||||
runtime listen(sockfd int, backlog int) int = 260;
|
||||
runtime send(sockfd int, buf void, len size_t, flags int) ssize_t = 261;
|
||||
runtime sendto(sockfd int, buf void, len size_t, flags int, dest_addr. struct_sockaddr, addrlen socklen_t) ssize_t = 262;
|
||||
runtime recv(sockfd int, buf void, len size_t, flags int) ssize_t = 263;
|
||||
runtime recvfrom(sockfd int, buf void, len size_t, flags int, src_addr. struct_sockaddr, addrlen. socklen_t) ssize_t = 264;
|
||||
runtime getsockname(sockfd int, addr. struct_sockaddr, addrlen. socklen_t) int = 265;
|
||||
runtime getpeername(sockfd int, addr. struct_sockaddr, addrlen. socklen_t) int = 266;
|
||||
runtime shutdown(sockfd int, how int) int = 267;
|
||||
|
||||
// #include <arpa/inet.h>
|
||||
// #include <netinet/in.h>
|
||||
// #include <sys/socket.h>
|
||||
runtime inet_aton(cp. char, inp. struct_in_addr) int = 268;
|
||||
runtime inet_addr(cp. char) in_addr_t = 269;
|
||||
runtime inet_network(cp. char) in_addr_t = 270;
|
||||
runtime inet_ntoa(in struct_in_addr) .char = 271;
|
||||
runtime inet_makeaddr(net in_addr_t, host in_addr_t) struct_in_addr = 272;
|
||||
runtime inet_lnaof(in struct_in_addr) in_addr_t = 273;
|
||||
runtime inet_netof(in struct_in_addr) in_addr_t = 274;
|
||||
runtime inet_ntop(af int, src void, dst. char, size socklen_t) .char = 275;
|
||||
runtime inet_pton(af int, src. char, dst void) int = 276;
|
||||
|
||||
// #include <netdb.h>
|
||||
runtime gethostbyname(name. char) .struct_hostent = 277;
|
||||
runtime gethostbyaddr(addr void, len socklen_t, type int) .struct_hostent = 278;
|
||||
runtime sethostent(stayopen int) = 279;
|
||||
runtime endhostent() = 280;
|
||||
runtime gethostent() .struct_hostent = 281;
|
||||
|
||||
// #include <netdb.h>
|
||||
runtime getnetent() .struct_netent = 282;
|
||||
runtime getnetbyname(name. char) .struct_netent = 283;
|
||||
runtime getnetbyaddr(net uint32, type int) .struct_netent = 284;
|
||||
runtime setnetent(stayopen int) = 285;
|
||||
runtime endnetent() = 286;
|
||||
|
||||
// #include <netdb.h>
|
||||
runtime getservent() .struct_servent = 287;
|
||||
runtime getservbyname(name. char, proto. char) .struct_servent = 288;
|
||||
runtime getservbyport(port int, proto. char) .struct_servent = 289;
|
||||
runtime setservent(stayopen int) = 290;
|
||||
runtime endservent() = 291;
|
||||
|
||||
// #include <sys/mman.h>
|
||||
runtime mmap(addr void, length size_t, prot int, flags int, fd int, offset off_t) void = 292;
|
||||
runtime munmap(addr void, length size_t) int = 293;
|
||||
runtime mprotect(addr void, len size_t, prot int) int = 294;
|
||||
|
||||
// #include <stdio.h>
|
||||
runtime perror(s. char) = 295;
|
||||
|
||||
// #include <unistd.h>
|
||||
runtime execv(path. char, argv++ char) int = 296;
|
||||
runtime execvp(file. char, argv++ char) int = 297;
|
||||
runtime fork() pid_t = 298;
|
||||
|
||||
func execl(path. char, ...) int {
|
||||
return execv(path, va_start(path));
|
||||
}
|
||||
func execlp(file. char, ...) int {
|
||||
return execvp(file, va_start(file));
|
||||
}
|
||||
|
||||
// #include <sys/wait.h>
|
||||
runtime wait(status. int) pid_t = 299;
|
||||
runtime waitpid(pid pid_t, status. int, options int) pid_t = 300;
|
||||
|
||||
// #include <unistd.h>
|
||||
runtime pipe(pipefd[2] int) int = 301;
|
||||
runtime dup(oldfd int) int = 302;
|
||||
runtime dup2(oldfd int, newfd int) int = 303;
|
||||
|
||||
// #include <unistd.h>
|
||||
runtime readlink(path. char, buf. char, bufsiz size_t) ssize_t = 304;
|
||||
|
||||
// #include <stdlib.h>
|
||||
runtime realpath(path. char, resolved_path. char) .char = 305;
|
||||
|
||||
// event, epoll, ...
|
||||
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
|
||||
module rt+, c+ {
|
||||
|
||||
import libc;
|
||||
|
||||
// #include <dlfcn.h>
|
||||
|
||||
func dlopen(filename. char, flag int) void {
|
||||
runtime dlopen(filename. char, flag int) void = 1;
|
||||
if (func = dlopen(filename, flag)) == null;
|
||||
printf("dlopen: %s\n", filename);
|
||||
}
|
||||
|
||||
runtime dlerror() .char = 2;
|
||||
runtime dlsym(handle void, symbol. char) void = 3;
|
||||
runtime dlclose(handle void) int = 4;
|
||||
|
||||
// util
|
||||
|
||||
func dlopens(flag int, ...) void {
|
||||
forvar ap. char* = va_start(flag), size uint32 = va_size(flag); size; {
|
||||
if (func = dlopen(.ap, flag)) ~= null;
|
||||
return;
|
||||
va_nexts<char*>(ap, size);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
func dlsyms(handle void, funcs. char*, ...) bool {
|
||||
if handle == null;
|
||||
return false;
|
||||
forvar ap. char* = va_start(handle), size uint32 = va_size(handle); size; funcs += sizeof(char*) {
|
||||
if (.funcs = dlsym(handle, .ap)) == null {
|
||||
printf("dlsyms: %s\n", .ap);
|
||||
return false;
|
||||
}
|
||||
va_nexts<char*>(ap, size);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
|
||||
module rt+, c+ {
|
||||
|
||||
import libc;
|
||||
|
||||
// #include <pthread.h>
|
||||
runtime pthread_create(thread. pthread_t, attr. pthread_attr_t, start_addr void, arg void, stack_size uint32 = 0x10000) int = 5;
|
||||
runtime pthread_join(thread pthread_t, retval+ void) int = 6;
|
||||
runtime pthread_self() pthread_t = 7;
|
||||
runtime pthread_detach(thread pthread_t) int = 8;
|
||||
runtime pthread_attr_init(attr. pthread_attr_t) int = 9;
|
||||
runtime pthread_attr_destroy(attr. pthread_attr_t) int = 10;
|
||||
runtime pthread_attr_setdetachstate(attr. pthread_attr_t, detachstate int) int = 11;
|
||||
runtime pthread_attr_getdetachstate(attr. pthread_attr_t, detachstate. int) int = 12;
|
||||
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
|
||||
typedef uchar unsigned char;
|
||||
typedef ushort unsigned short;
|
||||
typedef uint unsigned int;
|
||||
typedef ulong unsigned long;
|
||||
typedef ull unsigned dlong;
|
||||
typedef uint8 unsigned int8;
|
||||
typedef uint16 unsigned int16;
|
||||
typedef uint32 unsigned int32;
|
||||
typedef uint64 unsigned int64;
|
||||
typedef uintptr unsigned intptr;
|
||||
typedef uword unsigned word;
|
||||
typedef byte uchar;
|
||||
typedef void uintptr;
|
||||
typedef bool int;
|
||||
|
||||
define {
|
||||
null = void(0);
|
||||
false = bool(0);
|
||||
true = bool(1);
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
|
||||
/*
|
||||
set_text(render void, text. char, color uint32)
|
||||
*/
|
||||
|
||||
class game+, control+, button {
|
||||
|
||||
inherit game::control = super;
|
||||
|
||||
private import lib::sdl2;
|
||||
|
||||
struct button {
|
||||
tex texture;
|
||||
}
|
||||
|
||||
func constructor() {
|
||||
constructor(this);
|
||||
}
|
||||
|
||||
func destructor() {
|
||||
destructor(this);
|
||||
}
|
||||
|
||||
inline set_text(render void, text. char, color uint32 = 0xff000000) {
|
||||
this.tex->init(
|
||||
global::uni_font->create_tex(render, text, color));
|
||||
}
|
||||
|
||||
func draw(render void) {
|
||||
var rect SDL_Rect = this->get_rect();
|
||||
SDL_SetRenderDrawColor(render, 245, 245, 245, 0xff);
|
||||
SDL_RenderFillRect(render, &rect);
|
||||
if this->has_focus() {
|
||||
SDL_SetRenderDrawColor(render, 0, 162, 232, 0xff);
|
||||
else
|
||||
SDL_SetRenderDrawColor(render, 127, 127, 127, 0xff);
|
||||
}
|
||||
SDL_RenderDrawRect(render, &rect);
|
||||
if this.tex->get_texture() ~= null {
|
||||
var width int = this.tex->get_width();
|
||||
var height int = this.tex->get_height();
|
||||
rect.x++;
|
||||
rect.y++;
|
||||
rect.w -= 2;
|
||||
rect.h -= 2;
|
||||
this.tex->draw2(render,
|
||||
rect.x + (rect.w - width) / 2,
|
||||
rect.y + (rect.h - height) / 2, width, height);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
|
||||
/*
|
||||
set_text_color(color uint32)
|
||||
set_text(render void, text. char, color uint32)
|
||||
get_text() .char
|
||||
get_keybd_cb() void
|
||||
*/
|
||||
|
||||
class game+, control+, edit {
|
||||
|
||||
inherit game::control = super;
|
||||
|
||||
private import lib::sdl2;
|
||||
|
||||
private alias string = std::string;
|
||||
|
||||
struct edit {
|
||||
tex texture;
|
||||
str string;
|
||||
text_color uint32;
|
||||
}
|
||||
|
||||
func constructor() {
|
||||
constructor(this);
|
||||
this.text_color = 0xff000000;
|
||||
}
|
||||
|
||||
func destructor() {
|
||||
destructor(this);
|
||||
}
|
||||
|
||||
inline set_text_color(color uint32) {
|
||||
this.text_color = color;
|
||||
}
|
||||
|
||||
inline set_text(render void, text. char) {
|
||||
this.str->set(text);
|
||||
this.tex->init(
|
||||
global::uni_font->create_tex(render, text, this.text_color));
|
||||
}
|
||||
|
||||
inline get_text() .char {
|
||||
return this.str->ptr();
|
||||
}
|
||||
|
||||
inline get_keybd_cb() void {
|
||||
return lambda(text. char, this.edit) [
|
||||
this->set_text(this->get_window()->get_render(), text);
|
||||
];
|
||||
}
|
||||
|
||||
func draw(render void) {
|
||||
define {
|
||||
TEXT_GAP = 3;
|
||||
}
|
||||
var rect SDL_Rect = this->get_rect();
|
||||
SDL_SetRenderDrawColor(render, 0xff, 0xff, 0xff, 0xff);
|
||||
SDL_RenderFillRect(render, &rect);
|
||||
if this->has_focus() {
|
||||
SDL_SetRenderDrawColor(render, 0, 162, 232, 0xff);
|
||||
else
|
||||
SDL_SetRenderDrawColor(render, 127, 127, 127, 0xff);
|
||||
}
|
||||
SDL_RenderDrawRect(render, &rect);
|
||||
if this.tex->get_texture() ~= null {
|
||||
var width int = this.tex->get_width();
|
||||
var height int = this.tex->get_height();
|
||||
var max_width int = rect.w - (TEXT_GAP * 2);
|
||||
if width > max_width;
|
||||
width = max_width;
|
||||
this.tex->draw2(render, rect.x + TEXT_GAP, rect.y + (rect.h - height) / 2, width, height);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
|
||||
/*
|
||||
set_normal_image(render void, filename. char) bool
|
||||
set_hover_image(render void, filename. char) bool
|
||||
set_image(render void, filename. char) bool
|
||||
set_outline_size(size int)
|
||||
get_outline_size() int
|
||||
*/
|
||||
|
||||
class game+, control+, image_button {
|
||||
|
||||
inherit game::control = super;
|
||||
|
||||
private import lib::sdl2;
|
||||
|
||||
struct image_button {
|
||||
normal texture;
|
||||
hover texture;
|
||||
image texture;
|
||||
outline_size int;
|
||||
}
|
||||
|
||||
func constructor() {
|
||||
constructor(this);
|
||||
}
|
||||
|
||||
func destructor() {
|
||||
destructor(this);
|
||||
}
|
||||
|
||||
inline set_normal_image(render void, filename. char) bool {
|
||||
if func = this.normal->load_file(render, filename) {
|
||||
this->set_size(
|
||||
this.normal->get_width(),
|
||||
this.normal->get_height());
|
||||
}
|
||||
}
|
||||
|
||||
inline set_hover_image(render void, filename. char) bool {
|
||||
return this.hover->load_file(render, filename);
|
||||
}
|
||||
|
||||
inline set_image(render void, filename. char) bool {
|
||||
return this.image->load_file(render, filename);
|
||||
}
|
||||
|
||||
inline set_outline_size(size int) {
|
||||
this.outline_size = size;
|
||||
}
|
||||
|
||||
inline get_outline_size() int {
|
||||
return this.outline_size;
|
||||
}
|
||||
|
||||
func draw(render void) {
|
||||
var rect SDL_Rect = this->get_rect();
|
||||
if this->has_focus() {
|
||||
this.hover->draw(render, rect.x, rect.y);
|
||||
else
|
||||
this.normal->draw(render, rect.x, rect.y);
|
||||
}
|
||||
if this.outline_size {
|
||||
rect.x += this.outline_size;
|
||||
rect.y += this.outline_size;
|
||||
rect.w -= this.outline_size * 2;
|
||||
rect.h -= this.outline_size * 2;
|
||||
}
|
||||
var width int = this.image->get_width();
|
||||
var height int = this.image->get_height();
|
||||
if width > rect.w;
|
||||
width = rect.w;
|
||||
if height > rect.h;
|
||||
height = rect.h;
|
||||
this.image->draw3(render,
|
||||
rect.x + (rect.w - width) / 2,
|
||||
rect.y + (rect.h - height) / 2, width, height);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
|
||||
/*
|
||||
set_text(render void, text. char, color uint32) bool
|
||||
*/
|
||||
|
||||
class game+, control+, label {
|
||||
|
||||
inherit game::control = super;
|
||||
|
||||
private import lib::sdl2;
|
||||
|
||||
struct label {
|
||||
tex texture;
|
||||
}
|
||||
|
||||
func constructor() {
|
||||
constructor(this); }
|
||||
func destructor() {
|
||||
destructor(this); }
|
||||
|
||||
func set_text(render void, text. char, color uint32 = 0xff000000) bool {
|
||||
if func = this.tex->init(global::uni_font->create_tex(render, text, color)) {
|
||||
this->set_size(
|
||||
this.tex->get_width(),
|
||||
this.tex->get_height());
|
||||
}
|
||||
}
|
||||
|
||||
func draw(render void) {
|
||||
this.tex->draw(render,
|
||||
this->get_x(),
|
||||
this->get_y());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,158 +0,0 @@
|
||||
|
||||
/*
|
||||
set_callback(on_select void, on_close void, arg void)
|
||||
add_menu(render void, id int, title. char)
|
||||
*/
|
||||
|
||||
class game+, control+, popup_menu {
|
||||
|
||||
inherit game::control = super;
|
||||
|
||||
private import rt::c, lib::sdl2;
|
||||
|
||||
private alias
|
||||
string = std::string,
|
||||
vector = std::vector;
|
||||
|
||||
class menu {
|
||||
struct menu {
|
||||
white_title texture;
|
||||
black_title texture;
|
||||
id int;
|
||||
}
|
||||
func constructor() {
|
||||
constructor(this);
|
||||
this.id = -1;
|
||||
}
|
||||
func destructor() {
|
||||
destructor(this);
|
||||
}
|
||||
}
|
||||
|
||||
struct popup_menu {
|
||||
menus vector<menu>;
|
||||
input_delay repeat;
|
||||
input_lock norepeat;
|
||||
on_select void;
|
||||
on_close void;
|
||||
arg void;
|
||||
cursor int;
|
||||
}
|
||||
|
||||
func constructor() {
|
||||
memset(this, 0, sizeof(popup_menu));
|
||||
constructor(this);
|
||||
}
|
||||
|
||||
func destructor() {
|
||||
destructor(this);
|
||||
}
|
||||
|
||||
define {
|
||||
MENU_GAP = 12;
|
||||
MENU_HEIGHT = 25;
|
||||
}
|
||||
|
||||
func init(render void) bool {
|
||||
this.input_delay->init(300, -10, 20);
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
on_select = lambda(id int, arg void) [
|
||||
|
||||
];
|
||||
on_close = lambda(arg void) [
|
||||
|
||||
];
|
||||
*/
|
||||
inline set_callback(on_select void, on_close void, arg void) {
|
||||
this.on_select = on_select;
|
||||
this.on_close = on_close;
|
||||
this.arg = arg;
|
||||
}
|
||||
|
||||
func add_menu(render void, id int, title. char) {
|
||||
var menu. menu = this.menus->new();
|
||||
menu.white_title->init(
|
||||
global::uni_font->create_tex(render, title, 0xffffffff));
|
||||
menu.black_title->init(
|
||||
global::uni_font->create_tex(render, title, 0xff000000));
|
||||
menu.id = id;
|
||||
var width int = menu.black_title->get_width() + (MENU_GAP * 2);
|
||||
if this->get_width() < width;
|
||||
this->set_width(width);
|
||||
this->set_height(this.menus->count() * MENU_HEIGHT + 2);
|
||||
}
|
||||
|
||||
func update(render void) {
|
||||
var state. uint8 = SDL_GetKeyboardState(null);
|
||||
if state[CPI_SCANCODE_UP] {
|
||||
if this.input_delay->do() {
|
||||
if this.cursor;
|
||||
this.cursor--;
|
||||
this.input_delay->undo();
|
||||
}
|
||||
elseif state[CPI_SCANCODE_DOWN];
|
||||
if this.input_delay->do() {
|
||||
if this.cursor < this.menus->count() - 1;
|
||||
this.cursor++;
|
||||
this.input_delay->undo();
|
||||
}
|
||||
else
|
||||
this.input_delay->reset();
|
||||
}
|
||||
if state[CPI_SCANCODE_A] or
|
||||
state[CPI_SCANCODE_B] or
|
||||
state[CPI_SCANCODE_MENU] {
|
||||
if this.input_lock->do() {
|
||||
if state[CPI_SCANCODE_B] {
|
||||
proto fn(id int, arg void);
|
||||
fn[this.on_select](this.menus->at(this.cursor).id, this.arg);
|
||||
}
|
||||
{
|
||||
proto fn(arg void);
|
||||
fn[this.on_close](this.arg);
|
||||
}
|
||||
}
|
||||
else
|
||||
this.input_lock->set(false);
|
||||
}
|
||||
}
|
||||
|
||||
func draw(render void) {
|
||||
var rect SDL_Rect = this->get_rect();
|
||||
SDL_SetRenderDrawColor(render, 0xff, 0xff, 0xff, 0xff);
|
||||
SDL_RenderFillRect(render, &rect);
|
||||
SDL_SetRenderDrawColor(render, 0xcd, 0xcd, 0xcd, 0xff);
|
||||
SDL_RenderDrawRect(render, &rect);
|
||||
rect.x += 1;
|
||||
rect.y += 1;
|
||||
rect.w -= 2;
|
||||
rect.h -= 2;
|
||||
forvar index size_t = 0, count size_t = this.menus->count(); index < count; index++ {
|
||||
var menu. menu = this.menus->at(index);
|
||||
if this.cursor == index {
|
||||
var sub_rect SDL_Rect;
|
||||
sub_rect.x = rect.x;
|
||||
sub_rect.y = rect.y;
|
||||
sub_rect.w = rect.w;
|
||||
sub_rect.h = MENU_HEIGHT;
|
||||
SDL_SetRenderDrawColor(render, 0x00, 0xa2, 0xe8, 0xff);
|
||||
SDL_RenderFillRect(render, &sub_rect);
|
||||
menu.white_title->draw(render, rect.x + MENU_GAP,
|
||||
rect.y + (MENU_HEIGHT - menu.white_title->get_height()) / 2);
|
||||
else
|
||||
menu.black_title->draw(render, rect.x + MENU_GAP,
|
||||
rect.y + (MENU_HEIGHT - menu.black_title->get_height()) / 2);
|
||||
}
|
||||
rect.y += MENU_HEIGHT;
|
||||
}
|
||||
}
|
||||
|
||||
func wake() {
|
||||
this.input_delay->reset(false);
|
||||
this.input_lock->set(true);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
|
||||
// template
|
||||
|
||||
class game+, control+, temp {
|
||||
|
||||
inherit game::control = super;
|
||||
|
||||
private import lib::sdl2;
|
||||
|
||||
struct temp {
|
||||
|
||||
}
|
||||
|
||||
func constructor() {
|
||||
constructor(this);
|
||||
}
|
||||
|
||||
func destructor() {
|
||||
destructor(this);
|
||||
}
|
||||
|
||||
func init(render void) bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
func update(render void) {
|
||||
this.super->update(render);
|
||||
}
|
||||
|
||||
func draw(render void) {
|
||||
this.super->draw(render);
|
||||
}
|
||||
|
||||
func wake() {
|
||||
this.super->wake();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
|
||||
module game+ {
|
||||
|
||||
private import lib::sdl2;
|
||||
|
||||
define {
|
||||
CPI_WIDTH = 320;
|
||||
CPI_HEIGHT = 240;
|
||||
}
|
||||
|
||||
define {
|
||||
CPI_SCANCODE_MENU = SDL_SCANCODE_ESCAPE;
|
||||
CPI_SCANCODE_SELECT = SDL_SCANCODE_SPACE;
|
||||
CPI_SCANCODE_START = SDL_SCANCODE_RETURN;
|
||||
CPI_SCANCODE_A = SDL_SCANCODE_J;
|
||||
CPI_SCANCODE_B = SDL_SCANCODE_K;
|
||||
CPI_SCANCODE_X = SDL_SCANCODE_U;
|
||||
CPI_SCANCODE_Y = SDL_SCANCODE_I;
|
||||
CPI_SCANCODE_UP = SDL_SCANCODE_UP;
|
||||
CPI_SCANCODE_DOWN = SDL_SCANCODE_DOWN;
|
||||
CPI_SCANCODE_LEFT = SDL_SCANCODE_LEFT;
|
||||
CPI_SCANCODE_RIGHT = SDL_SCANCODE_RIGHT;
|
||||
CPI_SCANCODE_LK1 = SDL_SCANCODE_H;
|
||||
CPI_SCANCODE_LK2 = SDL_SCANCODE_Y;
|
||||
CPI_SCANCODE_LK3 = SDL_SCANCODE_UNKNOWN; // ???
|
||||
CPI_SCANCODE_LK4 = SDL_SCANCODE_O;
|
||||
CPI_SCANCODE_LK5 = SDL_SCANCODE_L;
|
||||
CPI_SCANCODE_SHIFT_SELECT = SDL_SCANCODE_KP_MINUS;
|
||||
CPI_SCANCODE_SHIFT_START = SDL_SCANCODE_KP_PLUS;
|
||||
CPI_SCANCODE_SHIFT_A = SDL_SCANCODE_H; // CPI_SCANCODE_LK1
|
||||
CPI_SCANCODE_SHIFT_B = SDL_SCANCODE_L; // CPI_SCANCODE_LK5
|
||||
CPI_SCANCODE_SHIFT_X = SDL_SCANCODE_Y; // CPI_SCANCODE_LK2
|
||||
CPI_SCANCODE_SHIFT_Y = SDL_SCANCODE_O; // CPI_SCANCODE_LK4
|
||||
}
|
||||
|
||||
define {
|
||||
CPI_BACKLIGHT = "/proc/driver/backlight";
|
||||
CPI_BATTERY = "/sys/class/power_supply/axp20x-battery/uevent";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,231 +0,0 @@
|
||||
|
||||
class game+, control+ {
|
||||
|
||||
private import rt::c, lib::sdl2;
|
||||
|
||||
private alias vector = std::vector;
|
||||
|
||||
struct control {
|
||||
struct callback {
|
||||
update void;
|
||||
draw void;
|
||||
wake void;
|
||||
destructor void;
|
||||
}
|
||||
parent. scene;
|
||||
parent_control. control;
|
||||
controls vector<void>;
|
||||
focus_control. control;
|
||||
popup. control;
|
||||
closing_popup. control;
|
||||
pending_popup. control;
|
||||
x int;
|
||||
y int;
|
||||
width int;
|
||||
height int;
|
||||
enable bool;
|
||||
visible bool;
|
||||
focus bool;
|
||||
}
|
||||
|
||||
func constructor() {
|
||||
memset(this, 0, sizeof(control));
|
||||
this.enable = true;
|
||||
this.visible = true;
|
||||
constructor(this);
|
||||
}
|
||||
|
||||
func destructor() {
|
||||
if this.popup ~= null;
|
||||
this->free_control(this.popup);
|
||||
if this.closing_popup ~= null;
|
||||
this->free_control(this.closing_popup);
|
||||
if this.pending_popup ~= null;
|
||||
this->free_control(this.pending_popup);
|
||||
forvar count size_t = this.controls->count(); count;;
|
||||
this->free_control(.this.controls->at(--count));
|
||||
destructor(this);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
inline create_control<T>(x int, y int, width int = 0, height int = 0) .T {
|
||||
func = this.parent->create_control<T>(x, y, width, height);
|
||||
func->set_parent_control(this);
|
||||
}
|
||||
|
||||
inline new_control<T>(x int, y int, width int = 0, height int = 0) .T {
|
||||
this.controls->push_back(
|
||||
func = this->create_control<T>(this.x + x, this.y + y, width, height));
|
||||
}
|
||||
|
||||
inline free_control(control. control) {
|
||||
this.parent->free_control(control);
|
||||
}
|
||||
|
||||
// focus
|
||||
|
||||
func set_focus(control. control) {
|
||||
var prev. control = this.focus_control;
|
||||
if prev ~= null;
|
||||
prev.focus = false;
|
||||
this.focus_control = control, control.focus = true;
|
||||
}
|
||||
|
||||
inline get_focus() .control {
|
||||
return this.focus_control;
|
||||
}
|
||||
|
||||
// popup
|
||||
|
||||
func close_popup() {
|
||||
if this.popup ~= null {
|
||||
this.closing_popup = this.popup;
|
||||
this.popup = null;
|
||||
// xxx
|
||||
if this.callback.wake ~= null {
|
||||
proto fn(this void);
|
||||
fn[this.callback.wake](this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func close_parent_popup() {
|
||||
if this.parent_control == null {
|
||||
this.parent->close_popup();
|
||||
else
|
||||
this.parent_control->close_popup();
|
||||
}
|
||||
}
|
||||
|
||||
func set_popup(control. control) {
|
||||
if this.popup == null and this.closing_popup == null {
|
||||
this.popup = control;
|
||||
else
|
||||
if this.pending_popup ~= null;
|
||||
this->free_control(this.pending_popup);
|
||||
this.pending_popup = control;
|
||||
}
|
||||
}
|
||||
|
||||
func has_popup() bool {
|
||||
if this.popup ~= null or
|
||||
this.closing_popup ~= null or
|
||||
this.pending_popup ~= null {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
func update(render void) {
|
||||
proto fn(this void, render void);
|
||||
if this.closing_popup ~= null;
|
||||
this->free_control(this.closing_popup), this.closing_popup = null;
|
||||
if this.pending_popup ~= null {
|
||||
if this.popup ~= null;
|
||||
this->free_control(this.popup);
|
||||
this.popup = this.pending_popup;
|
||||
this.pending_popup = null;
|
||||
}
|
||||
// xxx
|
||||
if this.popup == null {
|
||||
forvar count size_t = this.controls->count(); count; {
|
||||
var control. control = .this.controls->at(--count);
|
||||
if control.callback.update ~= null;
|
||||
fn[control.callback.update](control, render);
|
||||
}
|
||||
else
|
||||
var popup. control = this.popup;
|
||||
if popup.callback.update ~= null;
|
||||
fn[popup.callback.update](popup, render);
|
||||
}
|
||||
}
|
||||
|
||||
func draw(render void) {
|
||||
proto fn(this void, render void);
|
||||
forvar count size_t = this.controls->count(); count; {
|
||||
var control. control = .this.controls->at(--count);
|
||||
if control.callback.draw ~= null;
|
||||
fn[control.callback.draw](control, render);
|
||||
}
|
||||
if this.popup ~= null {
|
||||
var popup. control = this.popup;
|
||||
if popup.callback.draw ~= null;
|
||||
fn[popup.callback.draw](popup, render);
|
||||
}
|
||||
}
|
||||
|
||||
func wake() {
|
||||
proto fn(this void);
|
||||
forvar count size_t = this.controls->count(); count; {
|
||||
var control. control = .this.controls->at(--count);
|
||||
if control.callback.wake ~= null;
|
||||
fn[control.callback.wake](control);
|
||||
}
|
||||
if this.popup ~= null {
|
||||
var popup. control = this.popup;
|
||||
if popup.callback.wake ~= null;
|
||||
fn[popup.callback.wake](popup);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
inline set_parent(scene. scene) {
|
||||
this.parent = scene;
|
||||
}
|
||||
|
||||
inline get_parent() .scene {
|
||||
return this.parent;
|
||||
}
|
||||
|
||||
inline get_parent_t<T>() .T {
|
||||
return this.parent;
|
||||
}
|
||||
|
||||
inline set_parent_control(control. control) {
|
||||
this.parent_control = control;
|
||||
}
|
||||
|
||||
inline get_parent_control() .control {
|
||||
return this.parent_control;
|
||||
}
|
||||
|
||||
inline get_parent_control_t<T>() .T {
|
||||
return this.parent_control;
|
||||
}
|
||||
|
||||
inline get_window() .window {
|
||||
return this.parent->get_window();
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
inline set_x(x int) { this.x = x; }
|
||||
inline set_y(y int) { this.y = y; }
|
||||
inline set_pos(x int, y int) { this.x = x, this.y = y; }
|
||||
inline set_width(width int) { this.width = width; }
|
||||
inline set_height(height int) { this.height = height; }
|
||||
inline set_size(width int, height int) {
|
||||
this.width = width,
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
inline get_x() int { return this.x; }
|
||||
inline get_y() int { return this.y; }
|
||||
inline get_width() int { return this.width; }
|
||||
inline get_height() int { return this.height; }
|
||||
inline get_right() int { return this.x + this.width; }
|
||||
inline get_bottom() int { return this.y + this.height; }
|
||||
inline get_rect() SDL_Rect {
|
||||
func.x = this.x,
|
||||
func.y = this.y,
|
||||
func.w = this.width,
|
||||
func.h = this.height;
|
||||
}
|
||||
|
||||
inline has_focus() bool { return this.focus; }
|
||||
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
|
||||
// SDL_GetTicks: This value wraps if the program runs for more than ~49 days.
|
||||
|
||||
class game+, delay {
|
||||
|
||||
private import lib::sdl2;
|
||||
|
||||
struct delay {
|
||||
duration uint32;
|
||||
t uint32;
|
||||
last_t uint32;
|
||||
done bool;
|
||||
}
|
||||
|
||||
inline init(duration uint32, done bool = false) {
|
||||
this.duration = duration;
|
||||
this.t = 0;
|
||||
this.last_t = 0;
|
||||
this.done = done;
|
||||
}
|
||||
|
||||
inline reset() {
|
||||
this.t = 0;
|
||||
this.last_t = 0;
|
||||
this.done = false;
|
||||
}
|
||||
|
||||
inline done() {
|
||||
this.done = true;
|
||||
}
|
||||
|
||||
inline done?() bool {
|
||||
return this.done;
|
||||
}
|
||||
|
||||
inline do() bool {
|
||||
if !this.done {
|
||||
this.last_t = SDL_GetTicks();
|
||||
if !this.t;
|
||||
this.t = this.last_t + this.duration;
|
||||
if this.t > this.last_t;
|
||||
return false;
|
||||
this.done = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
inline undo() {
|
||||
this.last_t = SDL_GetTicks();
|
||||
this.t = this.last_t + this.duration;
|
||||
this.done = false;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
inline get_duration() uint32 {
|
||||
return this.duration;
|
||||
}
|
||||
|
||||
inline set_duration(duration uint32) {
|
||||
this.duration = duration;
|
||||
}
|
||||
|
||||
inline inc_duration(inc int32) {
|
||||
this.duration += inc;
|
||||
}
|
||||
|
||||
inline get_remain_t() uint32 {
|
||||
return this.t - this.last_t;
|
||||
}
|
||||
|
||||
inline get_per<T>(x T) T {
|
||||
return (float(this->get_remain_t()) / this.duration) * x;
|
||||
}
|
||||
|
||||
inline get_per_r<T>(x T) T {
|
||||
return x - this->get_per<T>(x);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
|
||||
class game+, fadeio {
|
||||
|
||||
private import rt::c, lib::sdl2;
|
||||
|
||||
struct fadeio {
|
||||
delay delay;
|
||||
texture texture;
|
||||
rect SDL_Rect;
|
||||
render void;
|
||||
done bool;
|
||||
r uint8;
|
||||
g uint8;
|
||||
b uint8;
|
||||
}
|
||||
|
||||
func constructor() {
|
||||
memset(this, 0, sizeof(fadeio));
|
||||
constructor(this);
|
||||
}
|
||||
|
||||
func destructor() {
|
||||
destructor(this);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
inline init(wnd. window, duration uint32) {
|
||||
this.delay->init(duration);
|
||||
this.render = wnd->get_render();
|
||||
wnd->get_size(&this.rect.w, &this.rect.h);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
inline set_color(r uint8, g uint8, b uint8) {
|
||||
this.texture->destroy();
|
||||
this.r = r;
|
||||
this.g = g;
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
inline set_texture(texture void, auto_destroy bool = true) bool {
|
||||
if func = this.texture->init(texture, auto_destroy);
|
||||
this.texture->set_blend_mode(SDL_BLENDMODE_BLEND);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
inline done() {
|
||||
this.delay->done();
|
||||
}
|
||||
|
||||
inline reset() {
|
||||
this.delay->reset();
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
inline do() bool {
|
||||
if func = this.delay->do() {
|
||||
if !this.done;
|
||||
this.texture->destroy(), this.done = true;
|
||||
else
|
||||
this->fade();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
private func fade() {
|
||||
var alpha uint8 = this.delay->get_per<uint8>(0xff);
|
||||
var texture void = this.texture->get_texture();
|
||||
if texture == null {
|
||||
SDL_SetRenderDrawBlendMode(this.render, SDL_BLENDMODE_BLEND);
|
||||
SDL_SetRenderDrawColor(this.render, this.r, this.g, this.b, alpha);
|
||||
SDL_RenderFillRect(this.render, &this.rect);
|
||||
SDL_SetRenderDrawBlendMode(this.render, SDL_BLENDMODE_NONE);
|
||||
else
|
||||
this.texture->set_alpha_mod(alpha);
|
||||
this.texture->draw(this.render,
|
||||
this.rect.w - (this.rect.w + this.texture->get_width()) / 2,
|
||||
this.rect.h - (this.rect.h + this.texture->get_height()) / 2);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
|
||||
class game+, focus_map {
|
||||
|
||||
private import rt::c, lib::sdl2;
|
||||
|
||||
private alias vector = std::vector;
|
||||
|
||||
struct map {
|
||||
control. control;
|
||||
up. control;
|
||||
down. control;
|
||||
left. control;
|
||||
right. control;
|
||||
}
|
||||
|
||||
struct focus_map {
|
||||
map vector<map>;
|
||||
}
|
||||
|
||||
func constructor() {
|
||||
constructor(this);
|
||||
}
|
||||
|
||||
func destructor() {
|
||||
destructor(this);
|
||||
}
|
||||
|
||||
func register(control. control, up. control, down. control, left. control, right. control) {
|
||||
var map. map = this.map->new();
|
||||
map.control = control;
|
||||
map.up = up;
|
||||
map.down = down;
|
||||
map.left = left;
|
||||
map.right = right;
|
||||
}
|
||||
|
||||
func get(control. control, scancode SDL_Scancode) .control {
|
||||
var count size_t = this.map->count();
|
||||
while count {
|
||||
var map. map = this.map->at(--count);
|
||||
if map.control == control {
|
||||
if scancode == CPI_SCANCODE_UP {
|
||||
return map.up;
|
||||
elseif scancode == CPI_SCANCODE_DOWN;
|
||||
return map.down;
|
||||
elseif scancode == CPI_SCANCODE_LEFT;
|
||||
return map.left;
|
||||
elseif scancode == CPI_SCANCODE_RIGHT;
|
||||
return map.right;
|
||||
else
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
|
||||
class game+, font {
|
||||
|
||||
private import rt::c, lib::sdl2_ttf;
|
||||
|
||||
struct font {
|
||||
obj void;
|
||||
tex texture;
|
||||
}
|
||||
|
||||
func constructor() {
|
||||
this.obj = null;
|
||||
constructor(this);
|
||||
}
|
||||
|
||||
func destructor() {
|
||||
this->close();
|
||||
destructor(this);
|
||||
}
|
||||
|
||||
func open(font_name. char, size int) bool {
|
||||
this->close();
|
||||
if (this.obj = TTF_OpenFont(font_name, size)) == null {
|
||||
printf("TTF_OpenFont: %s\n", font_name);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
func close() {
|
||||
this.tex->destroy();
|
||||
if this.obj ~= null;
|
||||
TTF_CloseFont(this.obj), this.obj = null;
|
||||
}
|
||||
|
||||
// xxx
|
||||
inline get_width() int {
|
||||
return this.tex->get_width();
|
||||
}
|
||||
|
||||
inline get_height() int {
|
||||
return TTF_FontHeight(this.obj);
|
||||
}
|
||||
|
||||
inline get_line_skip() int {
|
||||
return TTF_FontLineSkip(this.obj);
|
||||
}
|
||||
|
||||
inline get_size(text. char, width. int, height. int) bool {
|
||||
return TTF_SizeUTF8(this.obj, text, width, height) == 0;
|
||||
}
|
||||
|
||||
func create_tex(render void, text. char, color uint32) void {
|
||||
var surface void = TTF_RenderUTF8_Solid(this.obj, text, color);
|
||||
if surface == null;
|
||||
return null;
|
||||
func = SDL_CreateTextureFromSurface(render, surface);
|
||||
SDL_FreeSurface(surface);
|
||||
}
|
||||
|
||||
// fixme
|
||||
func create_outlined_tex(render void, text. char, text_color uint32, outline_color uint32, outline_size int) void {
|
||||
TTF_SetFontOutline(this.obj, outline_size);
|
||||
var outline_texture. SDL_Surface = TTF_RenderUTF8_Solid(this.obj, text, outline_color);
|
||||
TTF_SetFontOutline(this.obj, 0);
|
||||
if outline_texture == null;
|
||||
return null;
|
||||
var text_texture. SDL_Surface = TTF_RenderUTF8_Solid(this.obj, text, text_color);
|
||||
if text_texture == null {
|
||||
SDL_FreeSurface(outline_texture);
|
||||
return null;
|
||||
}
|
||||
SDL_SetSurfaceBlendMode(outline_texture, SDL_BLENDMODE_BLEND);
|
||||
var rect SDL_Rect;
|
||||
rect.x = outline_size;
|
||||
rect.y = outline_size;
|
||||
rect.w = text_texture.w;
|
||||
rect.h = text_texture.h;
|
||||
SDL_BlitSurface(text_texture, null, outline_texture, &rect);
|
||||
func = SDL_CreateTextureFromSurface(render, outline_texture);
|
||||
SDL_FreeSurface(outline_texture);
|
||||
SDL_FreeSurface(text_texture);
|
||||
}
|
||||
|
||||
inline prepare(render void, text. char, color uint32) bool {
|
||||
return this.tex->init(this->create_tex(render, text, color));
|
||||
}
|
||||
|
||||
inline draw(render void, x int, y int) {
|
||||
this.tex->draw(render, x, y);
|
||||
}
|
||||
|
||||
inline draw2(render void, x int, y int, text. char, color uint32) {
|
||||
if this->prepare(render, text, color);
|
||||
this->draw(render, x, y);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
|
||||
class game+, norepeat {
|
||||
|
||||
struct norepeat {
|
||||
lock bool;
|
||||
}
|
||||
|
||||
func constructor() {
|
||||
this.lock = true;
|
||||
}
|
||||
|
||||
inline do() bool {
|
||||
if !this.lock {
|
||||
this.lock = true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
inline set(lock bool = false) {
|
||||
this.lock = lock;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
|
||||
class game+, repeat {
|
||||
|
||||
private import lib::sdl2;
|
||||
|
||||
struct repeat {
|
||||
delay delay;
|
||||
duration int;
|
||||
inc int;
|
||||
count int;
|
||||
remains int;
|
||||
}
|
||||
|
||||
func init(duration uint32, inc int, count int) {
|
||||
this.delay->init(duration, true);
|
||||
this.duration = duration;
|
||||
this.inc = inc;
|
||||
this.count = count;
|
||||
this.remains = count;
|
||||
}
|
||||
|
||||
inline reset(done bool = true) {
|
||||
this.delay->init(this.duration, done);
|
||||
this.remains = this.count;
|
||||
}
|
||||
|
||||
inline do() bool {
|
||||
return this.delay->do();
|
||||
}
|
||||
|
||||
func undo() {
|
||||
if this.remains > 0 {
|
||||
this.remains--;
|
||||
this.delay->inc_duration(this.inc);
|
||||
}
|
||||
this.delay->undo();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,206 +0,0 @@
|
||||
|
||||
class game+, scene+ {
|
||||
|
||||
private import rt::c;
|
||||
|
||||
private alias vector = std::vector;
|
||||
|
||||
struct scene {
|
||||
struct callback {
|
||||
update void;
|
||||
draw void;
|
||||
wake void;
|
||||
destructor void;
|
||||
}
|
||||
parent. window;
|
||||
name. char;
|
||||
controls vector<void>;
|
||||
focus_control. control;
|
||||
popup. control;
|
||||
closing_popup. control;
|
||||
pending_popup. control;
|
||||
}
|
||||
|
||||
func constructor() {
|
||||
memset(this, 0, sizeof(scene));
|
||||
constructor(this);
|
||||
}
|
||||
|
||||
func destructor() {
|
||||
if this.popup ~= null;
|
||||
free_control(this.popup);
|
||||
if this.closing_popup ~= null;
|
||||
free_control(this.closing_popup);
|
||||
if this.pending_popup ~= null;
|
||||
free_control(this.pending_popup);
|
||||
forvar count size_t = this.controls->count(); count;;
|
||||
free_control(.this.controls->at(--count));
|
||||
destructor(this);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
inline set_window(wnd. window) {
|
||||
this.parent = wnd;
|
||||
}
|
||||
|
||||
inline get_window() .window {
|
||||
return this.parent;
|
||||
}
|
||||
|
||||
inline set_name(name. char) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
inline get_name() .char {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
inline quit() bool {
|
||||
return this.parent->pop_scene() ~= null;
|
||||
}
|
||||
|
||||
// control
|
||||
|
||||
func new_control<T>(x int, y int, width int = 0, height int = 0, standalone bool = false) .T {
|
||||
func = malloc_t<T>();
|
||||
#if objectid(T).func.update;
|
||||
func.super.callback.update = T::update*;
|
||||
#endif
|
||||
#if objectid(T).func.draw;
|
||||
func.super.callback.draw = T::draw*;
|
||||
#endif
|
||||
#if objectid(T).func.wake;
|
||||
func.super.callback.wake = T::wake*;
|
||||
#endif
|
||||
#if objectid(T).func.destructor;
|
||||
func.super.callback.destructor = T::destructor*;
|
||||
#endif
|
||||
func->set_parent(this);
|
||||
func->set_pos(x, y);
|
||||
func->set_size(width, height);
|
||||
#if objectid(T).func.init;
|
||||
if !func->init(this.parent->get_render()) {
|
||||
printf("Failed to load \"%s\" control.\n", objectid(T).name);
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
if !standalone;
|
||||
this.controls->push_back(func);
|
||||
}
|
||||
|
||||
inline create_control<T>(x int, y int, width int = 0, height int = 0) .T {
|
||||
return this->new_control<T>(x, y, width, height, true);
|
||||
}
|
||||
|
||||
static func free_control(control. control) {
|
||||
if control.callback.destructor ~= null {
|
||||
proto fn(this void);
|
||||
fn[control.callback.destructor](control);
|
||||
}
|
||||
free(control);
|
||||
}
|
||||
|
||||
// focus
|
||||
|
||||
func set_focus(control. control) {
|
||||
var prev. control = this.focus_control;
|
||||
if prev ~= null;
|
||||
prev.focus = false;
|
||||
this.focus_control = control, control.focus = true;
|
||||
}
|
||||
|
||||
inline get_focus() .control {
|
||||
return this.focus_control;
|
||||
}
|
||||
|
||||
// popup
|
||||
|
||||
func close_popup() {
|
||||
if this.popup ~= null {
|
||||
this.closing_popup = this.popup;
|
||||
this.popup = null;
|
||||
// xxx
|
||||
if this.callback.wake ~= null {
|
||||
proto fn(this void);
|
||||
fn[this.callback.wake](this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func set_popup(control. control) {
|
||||
if this.popup == null and this.closing_popup == null {
|
||||
this.popup = control;
|
||||
else
|
||||
if this.pending_popup ~= null;
|
||||
free_control(this.pending_popup);
|
||||
this.pending_popup = control;
|
||||
}
|
||||
}
|
||||
|
||||
func has_popup() bool {
|
||||
if this.popup ~= null or
|
||||
this.closing_popup ~= null or
|
||||
this.pending_popup ~= null {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
func update(render void) {
|
||||
proto fn(this void, render void);
|
||||
if this.closing_popup ~= null;
|
||||
free_control(this.closing_popup), this.closing_popup = null;
|
||||
if this.pending_popup ~= null {
|
||||
if this.popup ~= null;
|
||||
free_control(this.popup);
|
||||
this.popup = this.pending_popup;
|
||||
this.pending_popup = null;
|
||||
}
|
||||
// xxx
|
||||
if this.popup == null {
|
||||
forvar count size_t = this.controls->count(); count; {
|
||||
var control. control = .this.controls->at(--count);
|
||||
if control.callback.update ~= null;
|
||||
fn[control.callback.update](control, render);
|
||||
}
|
||||
else
|
||||
var popup. control = this.popup;
|
||||
if popup.callback.update ~= null;
|
||||
fn[popup.callback.update](popup, render);
|
||||
}
|
||||
}
|
||||
|
||||
func draw(render void) {
|
||||
proto fn(this void, render void);
|
||||
forvar count size_t = this.controls->count(); count; {
|
||||
var control. control = .this.controls->at(--count);
|
||||
if control.callback.draw ~= null;
|
||||
fn[control.callback.draw](control, render);
|
||||
}
|
||||
if this.popup ~= null {
|
||||
var popup. control = this.popup;
|
||||
if popup.callback.draw ~= null;
|
||||
fn[popup.callback.draw](popup, render);
|
||||
}
|
||||
}
|
||||
|
||||
func wake() {
|
||||
proto fn(this void);
|
||||
forvar count size_t = this.controls->count(); count; {
|
||||
var control. control = .this.controls->at(--count);
|
||||
if control.callback.wake ~= null;
|
||||
fn[control.callback.wake](control);
|
||||
}
|
||||
if this.popup ~= null {
|
||||
var popup. control = this.popup;
|
||||
if popup.callback.wake ~= null;
|
||||
fn[popup.callback.wake](popup);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
|
||||
class game+, small_font {
|
||||
|
||||
private import rt::c, lib::sdl2;
|
||||
|
||||
struct small_font {
|
||||
textures(13) texture;
|
||||
font_width int;
|
||||
font_height int;
|
||||
}
|
||||
|
||||
func constructor() {
|
||||
constructor(this);
|
||||
this.font_width = 0;
|
||||
this.font_height = 0;
|
||||
}
|
||||
|
||||
func destructor() {
|
||||
destructor(this);
|
||||
}
|
||||
|
||||
func init(render void, font_width int, font_height int, filename. char) bool {
|
||||
var tex texture;
|
||||
if !tex->load_file(render, filename);
|
||||
return false;
|
||||
if tex->get_width() ~= (font_width * 13) or tex->get_height() ~= font_height;
|
||||
return false;
|
||||
forvar i int = 0; i < 13; i++;
|
||||
this.textures[i]->init(tex->clone_tex(render, i * font_width, 0, font_width, font_height, SDL_BLENDMODE_BLEND));
|
||||
this.font_width = font_width;
|
||||
this.font_height = font_height;
|
||||
return true;
|
||||
}
|
||||
|
||||
func draw_cap(render void, x int, y int, cap uint) {
|
||||
var str(8) char;
|
||||
forvar index int = 0, count int = snprintf(&str, 8, "%u", cap); index < count; index++ {
|
||||
this.textures[str[index] - '0']->draw(render, x, y);
|
||||
x += this.font_width;
|
||||
}
|
||||
this.textures[10]->draw(render, x, y);
|
||||
}
|
||||
|
||||
func draw_time(render void, x int, y int, t time_t, draw_colon bool = true) {
|
||||
var tm. struct_tm = localtime(&t);
|
||||
if !tm.tm_hour {
|
||||
tm.tm_hour = 12;
|
||||
elseif tm.tm_hour > 12;
|
||||
tm.tm_hour -= 12;
|
||||
}
|
||||
var str(8) char;
|
||||
forvar index int = 0, count int =
|
||||
sprintf(&str, "%u:%02u",
|
||||
tm.tm_hour,
|
||||
tm.tm_min); index < count; index++ {
|
||||
var c char = str[index];
|
||||
if isdigit(c) {
|
||||
this.textures[c - '0']->draw(render, x, y);
|
||||
elseif draw_colon;
|
||||
this.textures[11]->draw(render, x, y);
|
||||
}
|
||||
x += this.font_width;
|
||||
}
|
||||
}
|
||||
|
||||
func draw_page(render void, x int, y int, cur uint, last uint) {
|
||||
var str(16) char;
|
||||
forvar index int = 0, count int = snprintf(&str, 16, "%u/%u", cur, last); index < count; index++ {
|
||||
var c char = str[index];
|
||||
if isdigit(c) {
|
||||
this.textures[c - '0']->draw(render, x, y);
|
||||
else
|
||||
this.textures[12]->draw(render, x, y);
|
||||
}
|
||||
x += this.font_width;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,151 +0,0 @@
|
||||
|
||||
class game+, texture {
|
||||
|
||||
private import
|
||||
rt::c,
|
||||
lib::sdl2,
|
||||
lib::sdl2_image;
|
||||
|
||||
struct texture {
|
||||
obj void;
|
||||
format uint32;
|
||||
width int;
|
||||
height int;
|
||||
auto_destroy bool;
|
||||
}
|
||||
|
||||
func constructor() {
|
||||
memset(this, 0, sizeof(texture));
|
||||
this.auto_destroy = true;
|
||||
}
|
||||
|
||||
func destructor() {
|
||||
this->destroy();
|
||||
}
|
||||
|
||||
func destroy() {
|
||||
if this.auto_destroy {
|
||||
if this.obj ~= null;
|
||||
SDL_DestroyTexture(this.obj);
|
||||
}
|
||||
this.obj = null;
|
||||
this.width = 0;
|
||||
this.height = 0;
|
||||
}
|
||||
|
||||
func init(texture void, auto_destroy bool = true) bool {
|
||||
this->destroy();
|
||||
if texture == null {
|
||||
return false;
|
||||
}
|
||||
if SDL_QueryTexture(texture, &this.format, null, &this.width, &this.height);
|
||||
return false;
|
||||
this.obj = texture;
|
||||
this.auto_destroy = auto_destroy;
|
||||
return true;
|
||||
}
|
||||
|
||||
func load_file(render void, filename. char) bool {
|
||||
this->destroy();
|
||||
if (this.obj = IMG_LoadTexture(render, filename)) == null {
|
||||
printf("IMG_LoadTexture: %s\n", SDL_GetError());
|
||||
return false;
|
||||
}
|
||||
if SDL_QueryTexture(this.obj, &this.format, null, &this.width, &this.height) {
|
||||
this->destroy();
|
||||
return false;
|
||||
}
|
||||
this.auto_destroy = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
func load_file_with_colorkey(render void, filename. char, r uint8, g uint8, b uint8) bool {
|
||||
var surface. SDL_Surface = IMG_Load(filename);
|
||||
if surface == null {
|
||||
printf("IMG_Load: %s\n", SDL_GetError());
|
||||
return false;
|
||||
}
|
||||
if SDL_SetColorKey(surface, SDL_RLEACCEL, SDL_MapRGB(surface.format, r, g, b)) {
|
||||
SDL_FreeSurface(surface);
|
||||
return false;
|
||||
}
|
||||
var texture void = SDL_CreateTextureFromSurface(render, surface);
|
||||
SDL_FreeSurface(surface);
|
||||
if texture == null;
|
||||
return false;
|
||||
return this->init(texture);
|
||||
}
|
||||
|
||||
func clone_tex(render void, x int, y int, width int, height int, blend_mode SDL_BlendMode = SDL_BLENDMODE_NONE) void {
|
||||
if this.obj == null;
|
||||
return null;
|
||||
if (func = SDL_CreateTexture(render, this.format, SDL_TEXTUREACCESS_TARGET, width, height)) == null;
|
||||
return;
|
||||
SDL_SetRenderTarget(render, func);
|
||||
SDL_SetTextureBlendMode(func, blend_mode);
|
||||
SDL_RenderCopy(render, this.obj,
|
||||
&global::make_rect(x, y, width, height),
|
||||
&global::make_rect(0, 0, width, height));
|
||||
SDL_SetRenderTarget(render, null);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
inline draw(render void, x int, y int) {
|
||||
SDL_RenderCopy(render, this.obj, null,
|
||||
&this->make_rect(x, y));
|
||||
}
|
||||
|
||||
inline draw2(render void, x int, y int, width int, height int) {
|
||||
SDL_RenderCopy(render, this.obj,
|
||||
&global::make_rect(0, 0, width, height),
|
||||
&global::make_rect(x, y, width, height));
|
||||
}
|
||||
|
||||
inline draw3(render void, x int, y int, width int, height int) {
|
||||
SDL_RenderCopy(render, this.obj, &this->make_rect(0, 0),
|
||||
&global::make_rect(x, y, width, height));
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
inline make_rect(x int, y int) SDL_Rect {
|
||||
func.x = x,
|
||||
func.y = y,
|
||||
func.w = this.width,
|
||||
func.h = this.height;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
inline get_texture() void {
|
||||
return this.obj;
|
||||
}
|
||||
|
||||
inline get_width() int {
|
||||
return this.width;
|
||||
}
|
||||
|
||||
inline get_height() int {
|
||||
return this.height;
|
||||
}
|
||||
|
||||
inline get_blend_mode() SDL_BlendMode {
|
||||
if SDL_GetTextureBlendMode(this.obj, &func);
|
||||
func = SDL_BLENDMODE_INVALID;
|
||||
}
|
||||
|
||||
inline set_blend_mode(mode SDL_BlendMode) int {
|
||||
return SDL_SetTextureBlendMode(this.obj, mode);
|
||||
}
|
||||
|
||||
inline get_alpha_mod() uint8 {
|
||||
if SDL_GetTextureAlphaMod(this.obj, &func);
|
||||
func = 0;
|
||||
}
|
||||
|
||||
inline set_alpha_mod(alpha uint8) int {
|
||||
return SDL_SetTextureAlphaMod(this.obj, alpha);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,312 +0,0 @@
|
||||
|
||||
class game+, window {
|
||||
|
||||
private import rt::c, lib::sdl2, lib::sdl2_image;
|
||||
|
||||
private alias
|
||||
string = std::string,
|
||||
vector_ptr = std::vector_ptr;
|
||||
|
||||
struct window {
|
||||
wnd void;
|
||||
render void;
|
||||
scenes vector_ptr<scene>;
|
||||
garbage vector_ptr<scene>;
|
||||
current_scene. scene;
|
||||
pending_scene. scene;
|
||||
turbo uint32;
|
||||
quit bool;
|
||||
}
|
||||
|
||||
func constructor() {
|
||||
memset(this, 0, sizeof(window));
|
||||
constructor(this);
|
||||
}
|
||||
|
||||
func destructor() {
|
||||
if this.current_scene ~= null;
|
||||
this->safe_free_scene(this.current_scene);
|
||||
if this.pending_scene ~= null;
|
||||
this->safe_free_scene(this.pending_scene);
|
||||
using count size_t = this.scenes->count() {
|
||||
while count {
|
||||
this->free_scene_internal(this.scenes->at(--count));
|
||||
}
|
||||
}
|
||||
this->dump();
|
||||
if this.render ~= null;
|
||||
SDL_DestroyRenderer(this.render);
|
||||
if this.wnd ~= null;
|
||||
SDL_DestroyWindow(this.wnd);
|
||||
destructor(this);
|
||||
}
|
||||
|
||||
func create_wnd(title. char, w int, h int,
|
||||
x int = SDL_WINDOWPOS_UNDEFINED,
|
||||
y int = SDL_WINDOWPOS_UNDEFINED) bool {
|
||||
if (this.wnd = SDL_CreateWindow(title, x, y, w, h,
|
||||
SDL_WINDOW_FULLSCREEN |
|
||||
SDL_WINDOW_OPENGL |
|
||||
SDL_WINDOW_SHOWN)) == null;
|
||||
return false;
|
||||
if (this.render = SDL_CreateRenderer(this.wnd, -1,
|
||||
SDL_RENDERER_ACCELERATED |
|
||||
SDL_RENDERER_TARGETTEXTURE)) == null {
|
||||
SDL_DestroyWindow(this.wnd), this.wnd = null;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// scene
|
||||
|
||||
func new_scene<T>() .T {
|
||||
func = malloc_t<T>();
|
||||
#if objectid(T).func.update;
|
||||
func.super.callback.update = T::update*;
|
||||
#endif
|
||||
#if objectid(T).func.draw;
|
||||
func.super.callback.draw = T::draw*;
|
||||
#endif
|
||||
#if objectid(T).func.wake;
|
||||
func.super.callback.wake = T::wake*;
|
||||
#endif
|
||||
#if objectid(T).func.destructor;
|
||||
func.super.callback.destructor = T::destructor*;
|
||||
#endif
|
||||
func->set_window(this);
|
||||
func->set_name(objectid(T).name);
|
||||
#if objectid(T).func.init;
|
||||
if !func->init(this.render) {
|
||||
printf("Failed to load \"%s\" scene.\n", objectid(T).name);
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private static func free_scene_internal(scene. scene) {
|
||||
if scene.callback.destructor ~= null {
|
||||
proto fn(this void);
|
||||
fn[scene.callback.destructor](scene);
|
||||
}
|
||||
free(scene);
|
||||
}
|
||||
|
||||
inline free_scene(scene. scene) {
|
||||
this.garbage->push_back(scene);
|
||||
}
|
||||
|
||||
func safe_free_scene(scene. scene) {
|
||||
var count size_t = this.scenes->count();
|
||||
while count {
|
||||
if this.scenes->at(--count) == scene {
|
||||
return;
|
||||
}
|
||||
}
|
||||
this->free_scene(scene);
|
||||
}
|
||||
|
||||
inline push_scene(scene. scene) {
|
||||
this.scenes->push_back(scene);
|
||||
}
|
||||
|
||||
inline get_last_scene() .scene {
|
||||
if this.scenes->empty();
|
||||
return null;
|
||||
return this.scenes->back();
|
||||
}
|
||||
|
||||
inline pop_scene() .scene {
|
||||
if this.scenes->empty();
|
||||
return null;
|
||||
this->set_scene(func = this.scenes->back());
|
||||
this.scenes->pop_back();
|
||||
if func.callback.wake ~= null {
|
||||
proto fn(this void);
|
||||
fn[func.callback.wake](func);
|
||||
}
|
||||
}
|
||||
|
||||
func set_scene(scene. scene) {
|
||||
if this.current_scene == null {
|
||||
this.current_scene = scene;
|
||||
else
|
||||
if this.pending_scene ~= null;
|
||||
this->safe_free_scene(this.pending_scene);
|
||||
this.pending_scene = scene;
|
||||
}
|
||||
}
|
||||
|
||||
inline set_new_scene<T>() {
|
||||
this->set_scene(this->new_scene<T>());
|
||||
}
|
||||
|
||||
private inline swap_scene() {
|
||||
if this.pending_scene ~= null {
|
||||
if this.current_scene ~= null;
|
||||
this->safe_free_scene(this.current_scene);
|
||||
this.current_scene = this.pending_scene;
|
||||
this.pending_scene = null;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
inline dump() {
|
||||
var count size_t = this.garbage->count();
|
||||
while count {
|
||||
this->free_scene_internal(this.garbage->at(--count));
|
||||
}
|
||||
this.garbage->clear();
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
inline update() {
|
||||
var scene. scene = this.current_scene;
|
||||
if scene.callback.update ~= null {
|
||||
proto fn(this void, render void);
|
||||
fn[scene.callback.update](scene, this.render);
|
||||
}
|
||||
}
|
||||
|
||||
inline draw() {
|
||||
var scene. scene = this.current_scene;
|
||||
if scene.callback.draw ~= null {
|
||||
proto fn(this void, render void);
|
||||
fn[scene.callback.draw](scene, this.render);
|
||||
}
|
||||
}
|
||||
|
||||
inline present() {
|
||||
SDL_RenderPresent(this.render);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
inline enable_turbo(ms int) {
|
||||
this.turbo = SDL_GetTicks() + ms;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
inline quit() {
|
||||
this.quit = true;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
func on_keydown(event. SDL_KeyboardEvent) {
|
||||
if !event.repeat {
|
||||
if event.keysym.scancode == CPI_SCANCODE_SHIFT_START {
|
||||
var surface void = this->screen_capture_to_surface2();
|
||||
if surface ~= null {
|
||||
var tm. struct_tm = localtime(&time(null));
|
||||
var filename string;
|
||||
IMG_SavePNG(surface, filename->format("screenshots/%04d-%02d-%02d-%02d_%02d_%02d_%04d.png",
|
||||
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, random<int>(10000)));
|
||||
SDL_FreeSurface(surface);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
func game_loop() {
|
||||
this->enable_turbo(8000);
|
||||
while !this.quit {
|
||||
var event SDL_Event;
|
||||
while SDL_PollEvent(&event) {
|
||||
if event.type == SDL_KEYDOWN {
|
||||
this->on_keydown(&event.key);
|
||||
this->enable_turbo(3000);
|
||||
elseif event.type == SDL_QUIT;
|
||||
return;
|
||||
}
|
||||
}
|
||||
this->update();
|
||||
if this.pending_scene == null {
|
||||
this->draw();
|
||||
this->present();
|
||||
}
|
||||
this->swap_scene();
|
||||
this->dump();
|
||||
if this.turbo < SDL_GetTicks() {
|
||||
forvar standby uint32 = SDL_GetTicks() + 300 ;; {
|
||||
if SDL_PollEvent(&event) {
|
||||
if event.type == SDL_KEYDOWN {
|
||||
this->on_keydown(&event.key);
|
||||
this->enable_turbo(3000);
|
||||
break;
|
||||
elseif event.type == SDL_QUIT;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if SDL_GetTicks() > standby;
|
||||
break;
|
||||
usleep(50000);
|
||||
}
|
||||
else
|
||||
usleep(3000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
inline get_handle() void {
|
||||
return this.wnd;
|
||||
}
|
||||
|
||||
inline get_render() void {
|
||||
return this.render;
|
||||
}
|
||||
|
||||
inline get_scene() .scene {
|
||||
return this.scene;
|
||||
}
|
||||
|
||||
inline get_size(w. int, h. int) {
|
||||
SDL_GetWindowSize(this.wnd, w, h);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
func screen_capture_to_surface(rect. SDL_Rect) void {
|
||||
var format uint32 = SDL_GetWindowPixelFormat(this.wnd);
|
||||
var surface. SDL_Surface = SDL_CreateRGBSurfaceWithFormat(0, rect.w, rect.h, 24, format);
|
||||
if surface == null;
|
||||
return null;
|
||||
if SDL_LockSurface(surface) {
|
||||
SDL_FreeSurface(surface);
|
||||
return null;
|
||||
}
|
||||
SDL_RenderReadPixels(this.render, rect, format, surface.pixels, surface.pitch);
|
||||
SDL_UnlockSurface(surface);
|
||||
return surface;
|
||||
}
|
||||
|
||||
func screen_capture_to_surface2() void {
|
||||
var rect SDL_Rect = 0;
|
||||
this->get_size(&rect.w, &rect.h);
|
||||
return this->screen_capture_to_surface(&rect);
|
||||
}
|
||||
|
||||
func screen_capture(rect. SDL_Rect) void {
|
||||
var surface void = this->screen_capture_to_surface(rect);
|
||||
if surface == null;
|
||||
return null;
|
||||
func = SDL_CreateTextureFromSurface(this.render, surface);
|
||||
SDL_FreeSurface(surface);
|
||||
}
|
||||
|
||||
func screen_capture2() void {
|
||||
var surface void = this->screen_capture_to_surface2();
|
||||
if surface == null;
|
||||
return null;
|
||||
func = SDL_CreateTextureFromSurface(this.render, surface);
|
||||
SDL_FreeSurface(surface);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,120 +0,0 @@
|
||||
|
||||
module game+, global {
|
||||
|
||||
private import rt::c, lib::sdl2;
|
||||
|
||||
private alias
|
||||
string = std::string,
|
||||
strings = std::strings;
|
||||
|
||||
var config cfg;
|
||||
|
||||
var skin_dir string;
|
||||
|
||||
var apps app_list;
|
||||
|
||||
var wifi wifi;
|
||||
|
||||
// deprecated
|
||||
var outlined_font bool = false;
|
||||
|
||||
var uni_font font;
|
||||
|
||||
var small_font small_font;
|
||||
|
||||
//
|
||||
|
||||
func init(render void) bool {
|
||||
if !config->open("bean.cfg");
|
||||
return false;
|
||||
if config->find("skin") == null;
|
||||
config->add("skin", "default");
|
||||
if config->find("font") == null;
|
||||
config->add("font", "unifont-12.0.01.ttf");
|
||||
// deprecated
|
||||
using value. char = config->get("outlined_font") {
|
||||
if value ~= null and !strcasecmp(value, "true") {
|
||||
outlined_font = true;
|
||||
}
|
||||
}
|
||||
skin_dir->format("skins/%s",
|
||||
config->get("skin"));
|
||||
if !apps->init("bean.db");
|
||||
return false;
|
||||
if !wifi->init();
|
||||
return false;
|
||||
var filename string;
|
||||
if !uni_font->open(filename->format("fonts/%s", config->get("font")), 16);
|
||||
return false;
|
||||
small_font->init(render, 10, 12,
|
||||
make_path("small_font_10x12.png"));
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
func make_path(filename. char) .char {
|
||||
static path string;
|
||||
return path->format("%s/%s",
|
||||
skin_dir->ptr(), filename);
|
||||
}
|
||||
|
||||
inline make_rect(x int, y int, width int, height int) SDL_Rect {
|
||||
func.x = x,
|
||||
func.y = y,
|
||||
func.w = width,
|
||||
func.h = height;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
func get_backlight_level() byte {
|
||||
func = -1;
|
||||
var stream void = fopen(CPI_BACKLIGHT, "r");
|
||||
if stream ~= null {
|
||||
if fread(&func, 1, 1, stream) == 1;
|
||||
func -= '0';
|
||||
fclose(stream);
|
||||
}
|
||||
}
|
||||
|
||||
func set_backlight_level(level byte) bool {
|
||||
var stream void = fopen(CPI_BACKLIGHT, "w");
|
||||
if stream ~= null {
|
||||
defer fclose(stream);
|
||||
level += '0';
|
||||
if fwrite(&level, 1, 1, stream) == 1;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
func get_battery_cap() int {
|
||||
var lines strings;
|
||||
if lines->load_file(CPI_BATTERY) <= 0;
|
||||
return -1;
|
||||
var strs strings;
|
||||
func = 0;
|
||||
forvar index size_t = 0, count size_t = lines->count(); index < count; index++ {
|
||||
var line. char = lines->item(index);
|
||||
if strstr(line, "POWER_SUPPLY_STATUS=") ~= null {
|
||||
if strs->split(line, "=") == 2 {
|
||||
if !strcasecmp(strs->item(1), "Charging");
|
||||
func = 0x100;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
forvar index size_t = 0, count size_t = lines->count(); index < count; index++ {
|
||||
var line. char = lines->item(index);
|
||||
if strstr(line, "POWER_SUPPLY_CAPACITY=") ~= null {
|
||||
strs->clear();
|
||||
if strs->split(line, "=") == 2;
|
||||
return func | atoi(strs->item(1));
|
||||
break;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
|
||||
class game+, launcher {
|
||||
|
||||
private import lib::sdl2;
|
||||
|
||||
struct launcher {
|
||||
wnd window;
|
||||
}
|
||||
|
||||
func constructor() {
|
||||
constructor(this); }
|
||||
func destructor() {
|
||||
destructor(this); }
|
||||
|
||||
func start(title. char) bool {
|
||||
if !this.wnd->create_wnd(title, CPI_WIDTH, CPI_HEIGHT);
|
||||
return false;
|
||||
if !global::init(this.wnd->get_render());
|
||||
return false;
|
||||
this.wnd->set_new_scene<scene::intro>();
|
||||
this.wnd->game_loop();
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,699 +0,0 @@
|
||||
|
||||
/*
|
||||
set_callback(on_select void, on_close void, arg void)
|
||||
set_fadeout(fadeout. fadeio)
|
||||
set_ext(ext. char)
|
||||
set_dir(render void, dir_name. char) bool
|
||||
refresh(render void) bool
|
||||
set_mode(mode mode)
|
||||
set_exec_format(format. char)
|
||||
hidden_files(visible bool)
|
||||
cursor_to(name. char) bool
|
||||
goto_parent_dir(render void) bool
|
||||
get_dir_count() size_t
|
||||
get_file_count() size_t
|
||||
get_all_count() size_t
|
||||
get_path() .char
|
||||
close()
|
||||
*/
|
||||
|
||||
class game+, scene+, file_browser {
|
||||
|
||||
inherit game::scene = super;
|
||||
|
||||
private import rt::c, lib::sdl2;
|
||||
|
||||
private alias
|
||||
string = std::string,
|
||||
strings = std::strings,
|
||||
vector = std::vector;
|
||||
|
||||
private alias popup_menu = control::popup_menu;
|
||||
|
||||
enum mode {
|
||||
browse,
|
||||
select,
|
||||
select_file,
|
||||
select_dir,
|
||||
select_image,
|
||||
exec
|
||||
}
|
||||
|
||||
struct file {
|
||||
icon texture;
|
||||
black_font texture;
|
||||
white_font texture;
|
||||
link bool;
|
||||
type uchar;
|
||||
str(NAME_MAX) char;
|
||||
}
|
||||
|
||||
struct file_browser {
|
||||
struct tex {
|
||||
dir texture;
|
||||
reg texture;
|
||||
lnk texture;
|
||||
name texture;
|
||||
image texture;
|
||||
empty texture;
|
||||
}
|
||||
fadeio fadeio;
|
||||
fadeout. fadeio;
|
||||
image_timer delay;
|
||||
input_delay repeat;
|
||||
input_lock norepeat;
|
||||
root string;
|
||||
path string;
|
||||
ext strings;
|
||||
dirs vector<file>;
|
||||
files vector<file>;
|
||||
on_select void;
|
||||
on_close void;
|
||||
arg void;
|
||||
cursor int;
|
||||
start_index int;
|
||||
exec_format string;
|
||||
mode mode;
|
||||
hidden_files bool;
|
||||
}
|
||||
|
||||
func constructor() {
|
||||
memset(this, 0, sizeof(file_browser));
|
||||
constructor(this);
|
||||
}
|
||||
|
||||
func destructor() {
|
||||
destructor(this);
|
||||
}
|
||||
|
||||
define {
|
||||
TOP_HEIGHT = 23;
|
||||
ITEM_HEIGHT = 25;
|
||||
SCROLL_WIDTH = 8;
|
||||
SCROLL_HEIGHT = 80;
|
||||
}
|
||||
|
||||
func init(render void) bool {
|
||||
this.tex.dir->load_file(render,
|
||||
global::make_path("file_browser/dir.png"));
|
||||
this.tex.reg->load_file(render,
|
||||
global::make_path("file_browser/reg.png"));
|
||||
this.tex.lnk->load_file(render,
|
||||
global::make_path("file_browser/lnk.png"));
|
||||
this.tex.empty->init(
|
||||
global::uni_font->create_tex(render, "Empty", 0xff000000));
|
||||
var wnd. window = this->get_window();
|
||||
this.fadeio->init(wnd, 300);
|
||||
this.fadeio->set_texture(wnd->screen_capture2());
|
||||
this.image_timer->init(300);
|
||||
this.input_delay->init(300, -48, 6);
|
||||
this.exec_format->set("%s");
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
on_select = lambda(filename. char, arg void) [
|
||||
|
||||
];
|
||||
on_close = lambda(arg void) [
|
||||
|
||||
];
|
||||
*/
|
||||
inline set_callback(on_select void, on_close void, arg void) {
|
||||
this.on_select = on_select;
|
||||
this.on_close = on_close;
|
||||
this.arg = arg;
|
||||
}
|
||||
|
||||
inline set_fadeout(fadeout. fadeio) {
|
||||
this.fadeout = fadeout;
|
||||
}
|
||||
|
||||
private inline reload_image() {
|
||||
this.tex.image->destroy();
|
||||
this.image_timer->reset();
|
||||
}
|
||||
|
||||
/*
|
||||
slow
|
||||
*/
|
||||
private static func sort(items. vector<file>) {
|
||||
forvar i int = 0, c int = items->count() - 1; i < c; i++ {
|
||||
forvar j int = 0; j < c - i; j++ {
|
||||
var x. file = items->at(j);
|
||||
var y. file = items->at(j + 1);
|
||||
if strcmp(&x.str, &y.str) > 0 {
|
||||
var tmp $file = .x;
|
||||
.x = .y;
|
||||
.y = tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func set_ext(ext. char) {
|
||||
this.ext->clear();
|
||||
this.ext->split(ext, ",");
|
||||
}
|
||||
|
||||
private func is_allow_ext(filename. char) bool {
|
||||
if this.ext->empty();
|
||||
return true;
|
||||
var extension. char = strrchr(filename, '.');
|
||||
if extension == null {
|
||||
extension = "?";
|
||||
else
|
||||
extension++;
|
||||
}
|
||||
var count size_t = this.ext->count();
|
||||
while count {
|
||||
if !strcasecmp(this.ext->item(--count), extension);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
func set_dir(render void, dir_name. char, root bool = false) bool {
|
||||
var dir void = opendir(dir_name);
|
||||
if dir == null;
|
||||
return false;
|
||||
this.tex.name->init(
|
||||
global::uni_font->create_tex(render, dir_name, 0xffffffff));
|
||||
this.path->set(dir_name);
|
||||
while this.path->len() > 1 and
|
||||
this.path->ends_with('/');
|
||||
this.path->remove_back();
|
||||
if root;
|
||||
this.root->set(this.path->ptr());
|
||||
this.dirs->clear();
|
||||
this.files->clear();
|
||||
this.cursor = 0;
|
||||
this.start_index = 0;
|
||||
using ent. struct_dirent {
|
||||
while (ent = readdir(dir)) ~= null {
|
||||
var file. file;
|
||||
var link bool = false;
|
||||
if ent.d_type == DT_LNK {
|
||||
var str string;
|
||||
var path. char = realpath(str->format("%s/%s", this.path->ptr(), &ent.d_name), null);
|
||||
if path == null;
|
||||
continue;
|
||||
defer free(path);
|
||||
var st struct_stat;
|
||||
if stat(path, &st);
|
||||
continue;
|
||||
if S_ISDIR(st.st_mode) {
|
||||
ent.d_type = DT_DIR;
|
||||
elseif S_ISREG(st.st_mode);
|
||||
ent.d_type = DT_REG;
|
||||
else
|
||||
ent.d_type = DT_UNKNOWN;
|
||||
}
|
||||
link = true;
|
||||
}
|
||||
if this.hidden_files and ent.d_name[0] == '.' {
|
||||
continue;
|
||||
}
|
||||
if ent.d_type == DT_DIR {
|
||||
if ent.d_name[0] == '.' and !ent.d_name[1] or
|
||||
ent.d_name[1] == '.' and !ent.d_name[2] {
|
||||
file = null;
|
||||
else
|
||||
file = this.dirs->new();
|
||||
file.icon->init(this.tex.dir->get_texture(), false);
|
||||
}
|
||||
elseif ent.d_type == DT_REG;
|
||||
if this->is_allow_ext(&ent.d_name) {
|
||||
file = this.files->new();
|
||||
file.icon->init(this.tex.reg->get_texture(), false);
|
||||
else
|
||||
file = null;
|
||||
}
|
||||
else
|
||||
file = null;
|
||||
}
|
||||
if file ~= null {
|
||||
file.link = link;
|
||||
file.type = ent.d_type;
|
||||
strcpy(&file.str, &ent.d_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir(dir);
|
||||
this->sort(&this.dirs);
|
||||
this->sort(&this.files);
|
||||
this->reload_image();
|
||||
return true;
|
||||
}
|
||||
|
||||
inline refresh(render void) bool {
|
||||
return this->set_dir(render, this.path->ptr());
|
||||
}
|
||||
|
||||
inline set_mode(mode mode) {
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
inline set_exec_format(format. char) {
|
||||
this.exec_format->set(format);
|
||||
}
|
||||
|
||||
inline hidden_files(visible bool) {
|
||||
this.hidden_files = visible;
|
||||
}
|
||||
|
||||
func cursor_to(name. char) bool {
|
||||
forvar index size_t = 0, count size_t = this.dirs->count(); index < count; index++ {
|
||||
if !strcmp(&this.dirs->at(index).str, name) {
|
||||
this.cursor = index;
|
||||
this->update_scroll();
|
||||
this->reload_image();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
forvar index size_t = 0, count size_t = this.files->count(); index < count; index++ {
|
||||
if !strcmp(&this.files->at(index).str, name) {
|
||||
this.cursor = this.dirs->count() + index;
|
||||
this->update_scroll();
|
||||
this->reload_image();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
func goto_parent_dir(render void) bool {
|
||||
if this.path->empty();
|
||||
return false;
|
||||
var path string;
|
||||
path->set(this.path->ptr());
|
||||
while path->ends_with('/');
|
||||
path->remove_back();
|
||||
if path->empty();
|
||||
return true;
|
||||
/*
|
||||
fixme
|
||||
*/
|
||||
if !strcmp(path->ptr(), this.root->ptr()) {
|
||||
this->close();
|
||||
return true;
|
||||
}
|
||||
var slash. char = strrchr(path->ptr(), '/');
|
||||
if slash == null;
|
||||
return false;
|
||||
var cur_dir string;
|
||||
cur_dir->set(slash + 1);
|
||||
if slash == path->ptr() {
|
||||
path->set("/");
|
||||
else
|
||||
path->set(path->ptr(), slash - path->ptr());
|
||||
}
|
||||
if func = this->set_dir(render, path->ptr()) {
|
||||
if !cur_dir->empty() {
|
||||
this->cursor_to(cur_dir->ptr());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline get_dir_count() size_t {
|
||||
return this.dirs->count();
|
||||
}
|
||||
|
||||
inline get_file_count() size_t {
|
||||
return this.files->count();
|
||||
}
|
||||
|
||||
inline get_all_count() size_t {
|
||||
return this.dirs->count() + this.files->count();
|
||||
}
|
||||
|
||||
inline get_path() .char {
|
||||
return this.path->ptr();
|
||||
}
|
||||
|
||||
private func get_selected_file() .file {
|
||||
var cursor int = this.cursor;
|
||||
var dir_count size_t = this.dirs->count();
|
||||
if dir_count and cursor < dir_count {
|
||||
return this.dirs->at(cursor);
|
||||
else
|
||||
if (cursor -= dir_count) < this.files->count();
|
||||
return this.files->at(cursor);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
func close() {
|
||||
if this.on_close ~= null {
|
||||
proto fn(arg void);
|
||||
fn[this.on_close](this.arg);
|
||||
}
|
||||
if this.fadeout ~= null {
|
||||
this.fadeout->set_texture(this->get_window()->screen_capture2());
|
||||
this.fadeout->reset();
|
||||
}
|
||||
this->quit();
|
||||
}
|
||||
|
||||
private func select(filename. char) {
|
||||
if this.on_select ~= null {
|
||||
proto fn(filename. char, arg void);
|
||||
fn[this.on_select](filename, this.arg);
|
||||
}
|
||||
this->close();
|
||||
}
|
||||
|
||||
private func exec(filename. char) {
|
||||
var str string;
|
||||
exec3(this->get_window(), "Please Wait",
|
||||
str->format(this.exec_format->ptr(), filename));
|
||||
}
|
||||
|
||||
private func action(render void) {
|
||||
var file. file = this->get_selected_file();
|
||||
if file ~= null {
|
||||
if file.type == DT_DIR {
|
||||
var new_path string;
|
||||
new_path->set(this.path->ptr());
|
||||
while new_path->ends_with('/');
|
||||
new_path->remove_back();
|
||||
this->set_dir(render,
|
||||
new_path->appendf("/%s", &file.str));
|
||||
elseif file.type == DT_REG;
|
||||
if this.mode == mode.select or
|
||||
this.mode == mode.select_file or
|
||||
this.mode == mode.select_image {
|
||||
var filename string;
|
||||
this->select(filename->format("%s/%s",
|
||||
this->get_path(), &file.str));
|
||||
elseif this.mode == mode.exec;
|
||||
var filename string;
|
||||
this->exec(filename->format("%s/%s",
|
||||
this->get_path(), &file.str));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func show_popup(render void, file. file) {
|
||||
// MENU_COPY
|
||||
// MENU_PASTE
|
||||
define {
|
||||
MENU_REFRESH = 1;
|
||||
MENU_EXECUTE = 2;
|
||||
MENU_SELECT = 3;
|
||||
MENU_LINK = 4;
|
||||
MENU_DELETE = 5;
|
||||
MENU_EXIT = 6;
|
||||
}
|
||||
this->close_popup();
|
||||
var popup. popup_menu = this->create_control<popup_menu>(0, 0);
|
||||
popup->set_callback(
|
||||
lambda(id int, this.file_browser) [
|
||||
if id == MENU_REFRESH {
|
||||
this->refresh(this->get_window()->get_render());
|
||||
elseif id == MENU_EXECUTE;
|
||||
var file. file = this->get_selected_file();
|
||||
if file ~= null {
|
||||
var filename string;
|
||||
this->exec(filename->format("%s/%s",
|
||||
this->get_path(), &file.str));
|
||||
}
|
||||
elseif id == MENU_SELECT;
|
||||
var file. file = this->get_selected_file();
|
||||
if file ~= null {
|
||||
var filename string;
|
||||
this->select(filename->format("%s/%s",
|
||||
this->get_path(), &file.str));
|
||||
}
|
||||
elseif id == MENU_LINK;
|
||||
var file. file = this->get_selected_file();
|
||||
if file ~= null {
|
||||
var parent. scene::main = this->get_window()->get_last_scene();
|
||||
if parent ~= null {
|
||||
if !strcmp(parent->get_name(), "main") {
|
||||
import scene::main;
|
||||
var tile_menu. tile_menu = parent.tile_menu;
|
||||
tile_menu->set_mode(tile_menu::mode.link);
|
||||
var filename string;
|
||||
var link string;
|
||||
link->format(this.exec_format->ptr(),
|
||||
filename->format("%s/%s", this->get_path(), &file.str));
|
||||
tile_menu->set_link(link->ptr());
|
||||
this->close();
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif id == MENU_DELETE;
|
||||
var file. file = this->get_selected_file();
|
||||
if file ~= null {
|
||||
var filename string;
|
||||
system(filename->format("sudo rm -rf \"%s/%s\"",
|
||||
this->get_path(), &file.str));
|
||||
// TODO
|
||||
}
|
||||
elseif id == MENU_EXIT;
|
||||
this->close();
|
||||
}
|
||||
],
|
||||
lambda(this.file_browser) [
|
||||
this->close_popup();
|
||||
], this);
|
||||
popup->add_menu(render, MENU_REFRESH, "Refresh");
|
||||
if file ~= null {
|
||||
if file.type == DT_REG {
|
||||
var filename string;
|
||||
var st struct_stat;
|
||||
if !stat(filename->format("%s/%s", this->get_path(), &file.str), &st) {
|
||||
if st.st_mode & S_IXUSR {
|
||||
popup->add_menu(render, MENU_EXECUTE, "Execute");
|
||||
}
|
||||
}
|
||||
if this.mode == mode.browse or
|
||||
this.mode == mode.exec {
|
||||
popup->add_menu(render, MENU_LINK, "Link");
|
||||
}
|
||||
elseif file.type == DT_DIR;
|
||||
if this.mode == mode.select or
|
||||
this.mode == mode.select_dir {
|
||||
popup->add_menu(render, MENU_SELECT, "Select");
|
||||
}
|
||||
}
|
||||
}
|
||||
// popup->add_menu(render, MENU_DELETE, "Delete");
|
||||
popup->add_menu(render, MENU_EXIT, "Exit");
|
||||
var rect SDL_Rect = 0;
|
||||
this->get_window()->get_size(&rect.w, &rect.h);
|
||||
popup->set_pos(
|
||||
(rect.w - popup->get_width()) / 2,
|
||||
(rect.h - popup->get_height()) / 2);
|
||||
this->set_popup(popup);
|
||||
}
|
||||
|
||||
private func update_scroll() {
|
||||
var rect SDL_Rect = 0;
|
||||
this->get_window()->get_size(&rect.w, &rect.h);
|
||||
if this.start_index > this.cursor {
|
||||
this.start_index = this.cursor;
|
||||
else
|
||||
var display_count int = (rect.h - TOP_HEIGHT) / ITEM_HEIGHT;
|
||||
var delta int = this.cursor - this.start_index + 1;
|
||||
if display_count < delta;
|
||||
this.start_index += delta - display_count;
|
||||
}
|
||||
}
|
||||
|
||||
func update(render void) {
|
||||
if this->has_popup() {
|
||||
this.super->update(render);
|
||||
else
|
||||
if this.image_timer->do() {
|
||||
if this.mode == mode.select_image {
|
||||
if this.tex.image->get_texture() == null {
|
||||
var file. file = this->get_selected_file();
|
||||
if file ~= null {
|
||||
if file.type == DT_REG {
|
||||
var filename string;
|
||||
this.tex.image->load_file(render,
|
||||
filename->format("%s/%s", this->get_path(), &file.str));
|
||||
}
|
||||
}
|
||||
this.image_timer->reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
var state. uint8 = SDL_GetKeyboardState(null);
|
||||
if state[CPI_SCANCODE_UP] {
|
||||
if this.input_delay->do() {
|
||||
if this.cursor {
|
||||
this.cursor--;
|
||||
this->update_scroll();
|
||||
this->reload_image();
|
||||
}
|
||||
this.input_delay->undo();
|
||||
}
|
||||
elseif state[CPI_SCANCODE_DOWN];
|
||||
if this.input_delay->do() {
|
||||
if this.cursor < this->get_all_count() -1 {
|
||||
this.cursor++;
|
||||
this->update_scroll();
|
||||
this->reload_image();
|
||||
}
|
||||
this.input_delay->undo();
|
||||
}
|
||||
elseif state[CPI_SCANCODE_LEFT];
|
||||
if this.input_delay->do() {
|
||||
if this.cursor - 10 < 0 {
|
||||
this.cursor = 0;
|
||||
else
|
||||
this.cursor -= 10;
|
||||
}
|
||||
this->update_scroll();
|
||||
this->reload_image();
|
||||
this.input_delay->undo();
|
||||
}
|
||||
elseif state[CPI_SCANCODE_RIGHT];
|
||||
if this.input_delay->do() {
|
||||
if this.cursor + 10 < this->get_all_count() -1 {
|
||||
this.cursor += 10;
|
||||
else
|
||||
this.cursor = this->get_all_count() -1;
|
||||
}
|
||||
this->update_scroll();
|
||||
this->reload_image();
|
||||
this.input_delay->undo();
|
||||
}
|
||||
else
|
||||
this.input_delay->reset();
|
||||
}
|
||||
if state[CPI_SCANCODE_A] {
|
||||
if this.input_lock->do();
|
||||
this->goto_parent_dir(render);
|
||||
elseif state[CPI_SCANCODE_B];
|
||||
if this.input_lock->do();
|
||||
this->action(render);
|
||||
elseif state[CPI_SCANCODE_MENU];
|
||||
if this.input_lock->do();
|
||||
this->show_popup(render, this->get_selected_file());
|
||||
else
|
||||
this.input_lock->set(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func draw_items(render void, items. vector<file>, begin size_t, cursor int, rect. SDL_Rect, x int, y& int) bool {
|
||||
forvar index size_t = begin, count size_t = items->count(); index < count; index++ {
|
||||
var item. file = items->at(index);
|
||||
var sub_rect SDL_Rect;
|
||||
sub_rect.x = 0;
|
||||
sub_rect.y = y;
|
||||
sub_rect.w = rect.w;
|
||||
sub_rect.h = ITEM_HEIGHT;
|
||||
if index + cursor == this.cursor {
|
||||
SDL_SetRenderDrawColor(render, 0x00, 0xa2, 0xe8, 0xff);
|
||||
SDL_RenderFillRect(render, &sub_rect);
|
||||
if item.white_font->get_texture() == null {
|
||||
item.white_font->init(
|
||||
global::uni_font->create_tex(render, &item.str, 0xffffffff));
|
||||
}
|
||||
item.white_font->draw(render, x + item.icon->get_width() + 3,
|
||||
y + (ITEM_HEIGHT - item.white_font->get_height()) / 2);
|
||||
else
|
||||
if (y - TOP_HEIGHT) / ITEM_HEIGHT % 2 {
|
||||
SDL_SetRenderDrawColor(render, 0xe0, 0xe0, 0xe0, 0xff);
|
||||
SDL_RenderFillRect(render, &sub_rect);
|
||||
}
|
||||
if item.black_font->get_texture() == null {
|
||||
item.black_font->init(
|
||||
global::uni_font->create_tex(render, &item.str, 0xff000000));
|
||||
}
|
||||
item.black_font->draw(render, x + item.icon->get_width() + 3,
|
||||
y + (ITEM_HEIGHT - item.black_font->get_height()) / 2);
|
||||
}
|
||||
item.icon->draw(render, x,
|
||||
y + (ITEM_HEIGHT - item.icon->get_height()) / 2);
|
||||
if item.link {
|
||||
this.tex.lnk->draw(render, x,
|
||||
y + (ITEM_HEIGHT - this.tex.lnk->get_height()) / 2);
|
||||
}
|
||||
if (y += ITEM_HEIGHT) > rect.h;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
func draw(render void) {
|
||||
SDL_SetRenderDrawColor(render, 0xff, 0xff, 0xff, 0xff);
|
||||
SDL_RenderClear(render);
|
||||
var rect SDL_Rect = 0;
|
||||
this->get_window()->get_size(&rect.w, &rect.h);
|
||||
var sub_rect SDL_Rect;
|
||||
sub_rect.x = 0;
|
||||
sub_rect.y = 0;
|
||||
sub_rect.w = rect.w;
|
||||
sub_rect.h = TOP_HEIGHT;
|
||||
SDL_SetRenderDrawColor(render, 0x35, 0x35, 0x35, 0xff);
|
||||
SDL_RenderFillRect(render, &sub_rect);
|
||||
if this.tex.name->get_width() > rect.w {
|
||||
this.tex.name->draw(render,
|
||||
-(this.tex.name->get_width() - rect.w) - 4,
|
||||
(TOP_HEIGHT - this.tex.name->get_height()) / 2);
|
||||
else
|
||||
this.tex.name->draw(render,
|
||||
(rect.w - this.tex.name->get_width()) / 2,
|
||||
(TOP_HEIGHT - this.tex.name->get_height()) / 2);
|
||||
}
|
||||
var file_count int = this->get_all_count();
|
||||
if file_count {
|
||||
var x int = 4;
|
||||
var y int = TOP_HEIGHT;
|
||||
var dir_count size_t = this.dirs->count();
|
||||
if dir_count and this.start_index < dir_count {
|
||||
if this->draw_items(render, &this.dirs, this.start_index, 0, &rect, x, y);
|
||||
this->draw_items(render, &this.files, 0, dir_count, &rect, x, y);
|
||||
else
|
||||
this->draw_items(render, &this.files, this.start_index - dir_count, dir_count, &rect, x, y);
|
||||
}
|
||||
var display_count int = (rect.h - TOP_HEIGHT) / ITEM_HEIGHT;
|
||||
if display_count < file_count {
|
||||
sub_rect.x = rect.w - SCROLL_WIDTH;
|
||||
sub_rect.y = TOP_HEIGHT +
|
||||
int((float(this.start_index) / (file_count - display_count)) *
|
||||
(rect.h - (TOP_HEIGHT + SCROLL_HEIGHT)));
|
||||
sub_rect.w = SCROLL_WIDTH;
|
||||
sub_rect.h = SCROLL_HEIGHT;
|
||||
SDL_SetRenderDrawColor(render, 0x80, 0x80, 0x80, 0xff);
|
||||
SDL_RenderFillRect(render, &sub_rect);
|
||||
}
|
||||
else
|
||||
this.tex.empty->draw(render,
|
||||
(rect.w - this.tex.empty->get_width()) / 2,
|
||||
(rect.h - this.tex.empty->get_height()) / 2);
|
||||
}
|
||||
define {
|
||||
IMAGE_MAX_WIDTH = 80;
|
||||
IMAGE_MAX_HEIGHT = 80;
|
||||
IMAGE_GAP = 15;
|
||||
}
|
||||
if this.tex.image->get_texture() ~= null {
|
||||
var width int = this.tex.image->get_width();
|
||||
var height int = this.tex.image->get_height();
|
||||
if width > IMAGE_MAX_WIDTH;
|
||||
width = IMAGE_MAX_WIDTH;
|
||||
if height > IMAGE_MAX_HEIGHT;
|
||||
height = IMAGE_MAX_HEIGHT;
|
||||
this.tex.image->draw3(render,
|
||||
rect.w - (width + IMAGE_GAP),
|
||||
rect.h - (height + IMAGE_GAP), width, height);
|
||||
}
|
||||
this.super->draw(render);
|
||||
this.fadeio->do();
|
||||
}
|
||||
|
||||
func wake() {
|
||||
this.input_delay->reset(false);
|
||||
this.input_lock->set(true);
|
||||
this.super->wake();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
|
||||
class game+, scene+, intro {
|
||||
|
||||
inherit game::scene = super;
|
||||
|
||||
private import lib::sdl2;
|
||||
|
||||
struct intro {
|
||||
fadeio fadeio;
|
||||
delay delay;
|
||||
logo texture;
|
||||
}
|
||||
|
||||
func constructor() {
|
||||
constructor(this); }
|
||||
func destructor() {
|
||||
destructor(this); }
|
||||
|
||||
func init(render void) bool {
|
||||
this.fadeio->init(this->get_window(), 2000);
|
||||
this.fadeio->set_color(235, 235, 235);
|
||||
this.delay->init(1000);
|
||||
this.logo->load_file(render,
|
||||
global::make_path("logo.png"));
|
||||
return true;
|
||||
}
|
||||
|
||||
func draw(render void) {
|
||||
SDL_SetRenderDrawColor(render, 235, 235, 235, 0xff);
|
||||
SDL_RenderClear(render);
|
||||
var wnd. window = this->get_window();
|
||||
var rect SDL_Rect = 0;
|
||||
wnd->get_size(&rect.w, &rect.h);
|
||||
this.logo->draw(render,
|
||||
rect.w - (rect.w + this.logo->get_width()) / 2,
|
||||
rect.h - (rect.h + this.logo->get_height()) / 2);
|
||||
if this.fadeio->do() and this.delay->do() {
|
||||
wnd->set_new_scene<scene::main>();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,646 +0,0 @@
|
||||
|
||||
/*
|
||||
set_callback(on_done void, on_close void, arg void)
|
||||
set_fadeout(fadeout. fadeio)
|
||||
set_title(render void, title. char)
|
||||
set_text(render void, text. char)
|
||||
get_text() .char
|
||||
close()
|
||||
*/
|
||||
|
||||
class game+, scene+, keybd {
|
||||
|
||||
inherit game::scene = super;
|
||||
|
||||
private import rt::c, std::utf8, lib::sdl2;
|
||||
|
||||
private alias string = std::string;
|
||||
|
||||
private define {
|
||||
BUTTON_COL = 11;
|
||||
BUTTON_ROW = 4;
|
||||
BUTTON_COUNT = BUTTON_COL * BUTTON_ROW;
|
||||
BUTTON_WIDTH = 25;
|
||||
BUTTON_HEIGHT = 23;
|
||||
BUTTON_GAP = 3;
|
||||
}
|
||||
|
||||
private var layout(3, BUTTON_COUNT) char = {
|
||||
|
||||
// 0
|
||||
'1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-',
|
||||
'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '_',
|
||||
'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ':', '\'',
|
||||
'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', '=',
|
||||
|
||||
// 1
|
||||
'!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '+',
|
||||
'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '\\',
|
||||
'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', '"',
|
||||
'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?', '|',
|
||||
|
||||
// 2
|
||||
'1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-',
|
||||
'~', '`', '!', '@', '#', '$', '%', '^', '&', '*', '_',
|
||||
'(', ')', '[', ']', '{', '}', ':', ';', '\'', '"', '\\',
|
||||
',', '.', '/', '=', '<', '>', '?', '|', '+', '\0', '\0'
|
||||
|
||||
};
|
||||
|
||||
private define {
|
||||
SHIFT = -1;
|
||||
BACKSPACE = -2;
|
||||
SPACE = -3;
|
||||
TAB = -4;
|
||||
RETURN = -5;
|
||||
}
|
||||
|
||||
struct keybd {
|
||||
struct tex {
|
||||
title texture;
|
||||
text texture;
|
||||
}
|
||||
fadeio fadeio;
|
||||
fadeout. fadeio;
|
||||
caret_timer delay;
|
||||
cursor_delay repeat;
|
||||
remove_delay repeat;
|
||||
input_lock norepeat;
|
||||
buf string;
|
||||
on_done void;
|
||||
on_close void;
|
||||
arg void;
|
||||
mode int;
|
||||
lock bool;
|
||||
prev_mode int;
|
||||
prev_lock bool;
|
||||
cursor int;
|
||||
prev_cursor int;
|
||||
start_x int;
|
||||
caret_pos int;
|
||||
caret_x int;
|
||||
draw_caret bool;
|
||||
enable_return bool;
|
||||
enable_shift bool;
|
||||
}
|
||||
|
||||
func constructor() {
|
||||
memset(this, 0, sizeof(keybd));
|
||||
constructor(this);
|
||||
}
|
||||
|
||||
func destructor() {
|
||||
destructor(this);
|
||||
}
|
||||
|
||||
module singleton {
|
||||
|
||||
var initd bool = false;
|
||||
|
||||
var ascii(128) texture;
|
||||
var shift texture;
|
||||
var shift_white texture;
|
||||
var backspace texture;
|
||||
var space texture;
|
||||
var tab texture;
|
||||
var ret texture;
|
||||
|
||||
}
|
||||
|
||||
func init(render void) bool {
|
||||
if !singleton::initd {
|
||||
var str(2) char = 0;
|
||||
forvar c int = 1; c < 128; c++ {
|
||||
str[0] = c;
|
||||
singleton::ascii[c]->init(
|
||||
global::uni_font->create_tex(render, &str, 0xff000000));
|
||||
}
|
||||
singleton::shift->init(
|
||||
global::uni_font->create_tex(render, "Shift", 0xff000000));
|
||||
singleton::shift_white->init(
|
||||
global::uni_font->create_tex(render, "Shift", 0xffffffff));
|
||||
singleton::backspace->init(
|
||||
global::uni_font->create_tex(render, "Back", 0xff000000));
|
||||
singleton::space->init(
|
||||
global::uni_font->create_tex(render, "Space", 0xff000000));
|
||||
singleton::tab->init(
|
||||
global::uni_font->create_tex(render, "Tab", 0xff000000));
|
||||
singleton::ret->init(
|
||||
global::uni_font->create_tex(render, "Return", 0xff000000));
|
||||
singleton::initd = true;
|
||||
}
|
||||
var wnd. window = this->get_window();
|
||||
this.fadeio->init(wnd, 300);
|
||||
this.fadeio->set_texture(wnd->screen_capture2());
|
||||
this.caret_timer->init(450);
|
||||
this.cursor_delay->init(300, -65, 4);
|
||||
this.remove_delay->init(300, -42, 7);
|
||||
this.prev_cursor = -1;
|
||||
this.draw_caret = true;
|
||||
this.enable_shift = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
on_done = lambda(text. char, arg void) [
|
||||
|
||||
];
|
||||
on_close = lambda(arg void) [
|
||||
|
||||
];
|
||||
*/
|
||||
inline set_callback(on_done void, on_close void, arg void) {
|
||||
this.on_done = on_done;
|
||||
this.on_close = on_close;
|
||||
this.arg = arg;
|
||||
}
|
||||
|
||||
inline set_fadeout(fadeout. fadeio) {
|
||||
this.fadeout = fadeout;
|
||||
}
|
||||
|
||||
func set_title(render void, title. char) {
|
||||
this.tex.title->init(
|
||||
global::uni_font->create_tex(render, title, 0xff000000));
|
||||
}
|
||||
|
||||
private inline update_text(render void) {
|
||||
this.tex.text->init(
|
||||
global::uni_font->create_tex(render, this.buf->ptr(), 0xff000000));
|
||||
}
|
||||
|
||||
private define {
|
||||
TEXT_GAP = 10;
|
||||
}
|
||||
|
||||
private func set_caret(pos int) {
|
||||
this.caret_timer->reset();
|
||||
this.caret_pos = pos;
|
||||
var nul. char = this.buf->ptr(this.caret_pos);
|
||||
var tmp char = .nul;
|
||||
.nul = 0;
|
||||
var caret_x int;
|
||||
if global::uni_font->get_size(this.buf->ptr(), &caret_x, null) {
|
||||
if this.caret_x = caret_x {
|
||||
this.caret_x++;
|
||||
else
|
||||
this.caret_x--;
|
||||
}
|
||||
var rect SDL_Rect = 0;
|
||||
this->get_window()->get_size(&rect.w, &rect.h);
|
||||
if this.tex.text->get_width() > (rect.w -= TEXT_GAP) {
|
||||
if this.caret_x < this.start_x {
|
||||
this.start_x = this.caret_x;
|
||||
else
|
||||
if (this.caret_x - this.start_x) > rect.w;
|
||||
this.start_x = this.caret_x - rect.w;
|
||||
}
|
||||
else
|
||||
this.start_x = 0;
|
||||
}
|
||||
else
|
||||
this.start_x = 0;
|
||||
this.caret_x = 0;
|
||||
}
|
||||
.nul = tmp;
|
||||
this.draw_caret = true;
|
||||
}
|
||||
|
||||
func set_text(render void, text. char) {
|
||||
this.buf->set(text);
|
||||
this->update_text(render);
|
||||
this.start_x = 0;
|
||||
this->set_caret(this.buf->len());
|
||||
}
|
||||
|
||||
inline get_text() .char {
|
||||
return this.buf->ptr();
|
||||
}
|
||||
|
||||
private func insert_char(render void, c char) {
|
||||
var buf(2) char;
|
||||
buf[0] = c;
|
||||
buf[1] = 0;
|
||||
this.buf->insert(this.caret_pos, &buf);
|
||||
this->update_text(render);
|
||||
this->set_caret(this.caret_pos + 1);
|
||||
}
|
||||
|
||||
private func insert(render void, str. char) {
|
||||
this.buf->insert(this.caret_pos, str);
|
||||
this->update_text(render);
|
||||
this->set_caret(this.caret_pos + strlen(str));
|
||||
}
|
||||
|
||||
private func remove(render void) bool {
|
||||
var tail int;
|
||||
var len int = utf8len_s(this.buf->ptr(), this.caret_pos, &tail);
|
||||
if len == -1;
|
||||
return false;
|
||||
if tail {
|
||||
if this.buf->remove(this.caret_pos - tail, tail) {
|
||||
this->update_text(render);
|
||||
this->set_caret(this.caret_pos - tail);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private func toggle_shift() {
|
||||
if this.mode == 0 {
|
||||
this.mode = 1;
|
||||
elseif this.mode == 1;
|
||||
if this.lock {
|
||||
this.mode = 0;
|
||||
this.lock = false;
|
||||
else
|
||||
this.lock = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func move_caret(left_right bool) bool {
|
||||
if left_right {
|
||||
var tail int;
|
||||
var len int = utf8len_s(this.buf->ptr(), this.caret_pos, &tail);
|
||||
if len == -1;
|
||||
return false;
|
||||
if tail {
|
||||
this->set_caret(this.caret_pos - tail);
|
||||
}
|
||||
else
|
||||
if this.caret_pos >= this.buf->len();
|
||||
return false;
|
||||
var size int = utf8table[uchar(.this.buf->ptr(this.caret_pos))];
|
||||
if (this.caret_pos + size) > this.buf->len();
|
||||
return false;
|
||||
this->set_caret(this.caret_pos + size);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
func close() {
|
||||
if this.on_close ~= null {
|
||||
proto fn(arg void);
|
||||
fn[this.on_close](this.arg);
|
||||
}
|
||||
if this.fadeout ~= null {
|
||||
this.fadeout->set_texture(this->get_window()->screen_capture2());
|
||||
this.fadeout->reset();
|
||||
}
|
||||
this->quit();
|
||||
}
|
||||
|
||||
private func done() {
|
||||
if this.on_done ~= null {
|
||||
proto fn(text. char, arg void);
|
||||
fn[this.on_done](this.buf->ptr(), this.arg);
|
||||
}
|
||||
this->close();
|
||||
}
|
||||
|
||||
func update(render void) {
|
||||
if this.caret_timer->do() {
|
||||
this.draw_caret = !this.draw_caret;
|
||||
this.caret_timer->undo();
|
||||
}
|
||||
var state. uint8 = SDL_GetKeyboardState(null);
|
||||
if state[CPI_SCANCODE_LEFT] {
|
||||
if this.cursor_delay->do() {
|
||||
if this.cursor < 0 {
|
||||
this.prev_cursor = -1;
|
||||
if this.cursor == SHIFT {
|
||||
this.cursor = TAB;
|
||||
elseif this.cursor == SPACE;
|
||||
this.cursor = SHIFT;
|
||||
elseif this.cursor == RETURN;
|
||||
this.cursor = SPACE;
|
||||
elseif this.cursor == BACKSPACE;
|
||||
if this.enable_return {
|
||||
this.cursor = RETURN;
|
||||
else
|
||||
this.cursor = SPACE;
|
||||
}
|
||||
else
|
||||
this.cursor = BACKSPACE;
|
||||
}
|
||||
else
|
||||
if this.cursor % BUTTON_COL {
|
||||
this.cursor--;
|
||||
else
|
||||
this.cursor = (this.cursor / BUTTON_COL + 1) * BUTTON_COL - 1;
|
||||
}
|
||||
}
|
||||
this.cursor_delay->undo();
|
||||
}
|
||||
elseif state[CPI_SCANCODE_RIGHT];
|
||||
if this.cursor_delay->do() {
|
||||
if this.cursor < 0 {
|
||||
this.prev_cursor = -1;
|
||||
if this.cursor == TAB {
|
||||
this.cursor = SHIFT;
|
||||
elseif this.cursor == SHIFT;
|
||||
this.cursor = SPACE;
|
||||
elseif this.cursor == SPACE;
|
||||
if this.enable_return {
|
||||
this.cursor = RETURN;
|
||||
else
|
||||
this.cursor = BACKSPACE;
|
||||
}
|
||||
elseif this.cursor == RETURN;
|
||||
this.cursor = BACKSPACE;
|
||||
else
|
||||
this.cursor = TAB;
|
||||
}
|
||||
else
|
||||
if this.cursor % BUTTON_COL == BUTTON_COL - 1 {
|
||||
this.cursor = (this.cursor / BUTTON_COL) * BUTTON_COL;
|
||||
else
|
||||
this.cursor++;
|
||||
}
|
||||
}
|
||||
this.cursor_delay->undo();
|
||||
}
|
||||
elseif state[CPI_SCANCODE_UP];
|
||||
if this.cursor_delay->do() {
|
||||
if this.cursor < 0 {
|
||||
if this.prev_cursor < 0 {
|
||||
if this.cursor == TAB {
|
||||
this.cursor = BUTTON_COUNT - BUTTON_COL;
|
||||
elseif this.cursor == SHIFT;
|
||||
this.cursor = BUTTON_COUNT - (BUTTON_COL - 2);
|
||||
elseif this.cursor == SPACE;
|
||||
this.cursor = BUTTON_COUNT - (BUTTON_COL - 4);
|
||||
elseif this.cursor == RETURN;
|
||||
this.cursor = BUTTON_COUNT - (BUTTON_COL - 7);
|
||||
else
|
||||
this.cursor = BUTTON_COUNT - (BUTTON_COL - 9);
|
||||
}
|
||||
else
|
||||
this.cursor = this.prev_cursor;
|
||||
}
|
||||
else
|
||||
if this.cursor - BUTTON_COL > -1;
|
||||
this.cursor -= BUTTON_COL;
|
||||
}
|
||||
this.cursor_delay->undo();
|
||||
}
|
||||
elseif state[CPI_SCANCODE_DOWN];
|
||||
if this.cursor_delay->do() {
|
||||
if this.cursor > -1 {
|
||||
if this.cursor + BUTTON_COL < BUTTON_COUNT {
|
||||
this.cursor += BUTTON_COL;
|
||||
else
|
||||
this.prev_cursor = this.cursor;
|
||||
var col int = this.cursor % BUTTON_COL;
|
||||
if col >= 0 and col <= 1 {
|
||||
this.cursor = TAB;
|
||||
elseif col >= 2 and col <= 3;
|
||||
this.cursor = SHIFT;
|
||||
elseif col >= 4 and col <= 8;
|
||||
this.cursor = SPACE;
|
||||
if this.enable_return {
|
||||
if col >= 7 and col <= 8;
|
||||
this.cursor = RETURN;
|
||||
}
|
||||
else
|
||||
this.cursor = BACKSPACE;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.cursor_delay->undo();
|
||||
}
|
||||
elseif state[CPI_SCANCODE_A];
|
||||
if this.remove_delay->do() {
|
||||
this->remove(render);
|
||||
this.remove_delay->undo();
|
||||
}
|
||||
elseif state[CPI_SCANCODE_LK1];
|
||||
if this.cursor_delay->do() {
|
||||
this->move_caret(true);
|
||||
this.cursor_delay->undo();
|
||||
}
|
||||
elseif state[CPI_SCANCODE_LK5];
|
||||
if this.cursor_delay->do() {
|
||||
this->move_caret(false);
|
||||
this.cursor_delay->undo();
|
||||
}
|
||||
// CPI_SCANCODE_LK2
|
||||
// CPI_SCANCODE_LK4
|
||||
else
|
||||
this.cursor_delay->reset();
|
||||
this.remove_delay->reset();
|
||||
}
|
||||
if state[CPI_SCANCODE_MENU] {
|
||||
if this.input_lock->do() {
|
||||
this->close();
|
||||
}
|
||||
elseif state[CPI_SCANCODE_SELECT];
|
||||
if this.input_lock->do() {
|
||||
if this.mode == 2 {
|
||||
this.mode = this.prev_mode;
|
||||
this.lock = this.prev_lock;
|
||||
this.enable_shift = true;
|
||||
else
|
||||
this.prev_mode = this.mode;
|
||||
this.prev_lock = this.lock;
|
||||
this.mode = 2;
|
||||
this.lock = false;
|
||||
this.enable_shift = false;
|
||||
}
|
||||
}
|
||||
elseif state[CPI_SCANCODE_START];
|
||||
if this.input_lock->do() {
|
||||
this->done();
|
||||
}
|
||||
elseif state[CPI_SCANCODE_B];
|
||||
if this.input_lock->do() {
|
||||
if this.cursor < 0 {
|
||||
if this.cursor == SHIFT {
|
||||
this->toggle_shift();
|
||||
elseif this.cursor == BACKSPACE;
|
||||
this->remove(render);
|
||||
elseif this.cursor == SPACE;
|
||||
this->insert_char(render, ' ');
|
||||
elseif this.cursor == TAB;
|
||||
this->insert_char(render, '\t');
|
||||
elseif this.cursor == RETURN;
|
||||
this->insert_char(render, '\n');
|
||||
}
|
||||
else
|
||||
var pressed char = layout[this.mode, this.cursor];
|
||||
if pressed {
|
||||
if this.mode == 1 {
|
||||
if !this.lock;
|
||||
this.mode = 0;
|
||||
}
|
||||
this->insert_char(render, pressed);
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif state[CPI_SCANCODE_X];
|
||||
if this.input_lock->do() {
|
||||
this->toggle_shift();
|
||||
}
|
||||
elseif state[CPI_SCANCODE_Y];
|
||||
if this.input_lock->do() {
|
||||
this->insert_char(render, ' ');
|
||||
}
|
||||
elseif state[CPI_SCANCODE_SHIFT_SELECT];
|
||||
if this.input_lock->do() {
|
||||
var wnd. window = this->get_window();
|
||||
var browser. scene::file_browser = wnd->new_scene<scene::file_browser>();
|
||||
browser->set_callback(
|
||||
lambda(filename. char, this.keybd) [
|
||||
this->insert(this->get_window()->get_render(), filename);
|
||||
], null, this
|
||||
);
|
||||
browser->set_fadeout(&this.fadeio);
|
||||
if browser->set_dir(wnd->get_render(), "/home/cpi") or
|
||||
browser->set_dir(wnd->get_render(), "/") {
|
||||
browser->set_mode(
|
||||
scene::file_browser::mode.select);
|
||||
wnd->push_scene(this);
|
||||
wnd->set_scene(browser);
|
||||
else
|
||||
wnd->free_scene(browser);
|
||||
}
|
||||
}
|
||||
else
|
||||
this.input_lock->set(false);
|
||||
}
|
||||
}
|
||||
|
||||
private func draw_button(render void, index int, rect. SDL_Rect, tex. texture, custom_color bool = false) {
|
||||
var focus bool = index == this.cursor;
|
||||
if !custom_color {
|
||||
if focus {
|
||||
SDL_SetRenderDrawColor(render, 0xff, 0xff, 0xff, 0xff);
|
||||
else
|
||||
SDL_SetRenderDrawColor(render, 235, 235, 235, 0xff);
|
||||
}
|
||||
}
|
||||
SDL_RenderFillRect(render, rect);
|
||||
if focus {
|
||||
SDL_SetRenderDrawColor(render, 0, 162, 232, 0xff);
|
||||
SDL_RenderDrawRect(render, rect);
|
||||
else
|
||||
SDL_SetRenderDrawColor(render, 127, 127, 127, 0xff);
|
||||
SDL_RenderDrawRect(render, rect);
|
||||
}
|
||||
tex->draw(render,
|
||||
rect.x + (rect.w - tex->get_width()) / 2,
|
||||
rect.y + (rect.h - tex->get_height()) / 2);
|
||||
}
|
||||
|
||||
func draw(render void) {
|
||||
define {
|
||||
TITLE_X = 10;
|
||||
TITLE_Y = 10;
|
||||
TEXT_Y = 45;
|
||||
KEYBD_Y = 85;
|
||||
}
|
||||
SDL_SetRenderDrawColor(render, 245, 245, 245, 0xff);
|
||||
SDL_RenderClear(render);
|
||||
var rect SDL_Rect = 0;
|
||||
this->get_window()->get_size(&rect.w, &rect.h);
|
||||
// title
|
||||
this.tex.title->draw(render, TITLE_X, TITLE_Y);
|
||||
using caret_x int {
|
||||
// text
|
||||
if this.tex.text->get_texture() == null {
|
||||
caret_x = rect.w / 2;
|
||||
else
|
||||
var width int = this.tex.text->get_width();
|
||||
if width > (rect.w - TEXT_GAP) {
|
||||
var x int = (TEXT_GAP / 2);
|
||||
caret_x = x + (this.caret_x - this.start_x);
|
||||
this.tex.text->draw(render, x + -this.start_x, TEXT_Y);
|
||||
else
|
||||
var x int = (rect.w - width) / 2;
|
||||
caret_x = x + this.caret_x;
|
||||
this.tex.text->draw(render, x, TEXT_Y);
|
||||
}
|
||||
}
|
||||
// caret
|
||||
if this.draw_caret {
|
||||
SDL_SetRenderDrawColor(render, 125, 125, 125, 0xff);
|
||||
SDL_RenderDrawLine(render, caret_x, TEXT_Y, caret_x,
|
||||
TEXT_Y + global::uni_font->get_height());
|
||||
}
|
||||
}
|
||||
// keybd
|
||||
var sub_rect SDL_Rect;
|
||||
var x int = (rect.w - ((BUTTON_COL * (BUTTON_WIDTH + BUTTON_GAP)) - BUTTON_GAP)) / 2;
|
||||
var y int = KEYBD_Y;
|
||||
forvar index int = 0; index < BUTTON_COUNT; index++ {
|
||||
sub_rect.x = x + ((index % BUTTON_COL) * (BUTTON_WIDTH + BUTTON_GAP));
|
||||
sub_rect.y = y + ((index / BUTTON_COL) * (BUTTON_HEIGHT + BUTTON_GAP));
|
||||
sub_rect.w = BUTTON_WIDTH;
|
||||
sub_rect.h = BUTTON_HEIGHT;
|
||||
this->draw_button(render, index, &sub_rect,
|
||||
&singleton::ascii[layout[this.mode, index]]);
|
||||
}
|
||||
sub_rect.x = x;
|
||||
sub_rect.y += BUTTON_WIDTH + BUTTON_GAP;
|
||||
sub_rect.w = ((BUTTON_WIDTH + BUTTON_GAP) * 2) - BUTTON_GAP;
|
||||
sub_rect.h = BUTTON_HEIGHT;
|
||||
this->draw_button(render, TAB, &sub_rect,
|
||||
&singleton::tab);
|
||||
sub_rect.x += sub_rect.w + BUTTON_GAP;
|
||||
sub_rect.w = ((BUTTON_WIDTH + BUTTON_GAP) * 2) - BUTTON_GAP;
|
||||
sub_rect.h = BUTTON_HEIGHT;
|
||||
{
|
||||
var custom_color bool = false;
|
||||
var tex. texture = &singleton::shift;
|
||||
if this.enable_shift {
|
||||
if this.mode == 1 {
|
||||
if this.lock {
|
||||
tex = &singleton::shift_white;
|
||||
SDL_SetRenderDrawColor(render, 130, 130, 130, 0xff);
|
||||
else
|
||||
SDL_SetRenderDrawColor(render, 205, 205, 205, 0xff);
|
||||
}
|
||||
custom_color = true;
|
||||
}
|
||||
else
|
||||
SDL_SetRenderDrawColor(render, 165, 165, 165, 0xff);
|
||||
custom_color = true;
|
||||
}
|
||||
this->draw_button(render, SHIFT, &sub_rect, tex, custom_color);
|
||||
}
|
||||
SDL_SetRenderDrawColor(render, 205, 205, 205, 0xff);
|
||||
if this.enable_return {
|
||||
sub_rect.x += sub_rect.w + BUTTON_GAP;
|
||||
sub_rect.w = ((BUTTON_WIDTH + BUTTON_GAP) * 3) - BUTTON_GAP;
|
||||
sub_rect.h = BUTTON_HEIGHT;
|
||||
this->draw_button(render, SPACE, &sub_rect,
|
||||
&singleton::space, true);
|
||||
sub_rect.x += sub_rect.w + BUTTON_GAP;
|
||||
sub_rect.w = ((BUTTON_WIDTH + BUTTON_GAP) * 2) - BUTTON_GAP;
|
||||
sub_rect.h = BUTTON_HEIGHT;
|
||||
this->draw_button(render, RETURN, &sub_rect,
|
||||
&singleton::ret);
|
||||
else
|
||||
sub_rect.x += sub_rect.w + BUTTON_GAP;
|
||||
sub_rect.w = ((BUTTON_WIDTH + BUTTON_GAP) * 5) - BUTTON_GAP;
|
||||
sub_rect.h = BUTTON_HEIGHT;
|
||||
this->draw_button(render, SPACE, &sub_rect,
|
||||
&singleton::space, true);
|
||||
}
|
||||
sub_rect.x += sub_rect.w + BUTTON_GAP;
|
||||
sub_rect.w = ((BUTTON_WIDTH + BUTTON_GAP) * 2) - BUTTON_GAP;
|
||||
sub_rect.h = BUTTON_HEIGHT;
|
||||
this->draw_button(render, BACKSPACE, &sub_rect,
|
||||
&singleton::backspace);
|
||||
this.fadeio->do();
|
||||
}
|
||||
|
||||
func wake() {
|
||||
this.caret_timer->done();
|
||||
this.cursor_delay->reset(false);
|
||||
this.remove_delay->reset(false);
|
||||
this.input_lock->set(true);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,130 +0,0 @@
|
||||
|
||||
class game+, scene+, main+, status_bar {
|
||||
|
||||
inherit game::control = super;
|
||||
|
||||
private import rt::c, lib::sdl2;
|
||||
|
||||
struct status_bar {
|
||||
long_timer delay;
|
||||
short_timer delay;
|
||||
batt_icon(4) texture;
|
||||
batt_charging_icon texture;
|
||||
batt_cap int;
|
||||
wifi_icon(4) texture;
|
||||
wifi_sig int;
|
||||
colon bool;
|
||||
}
|
||||
|
||||
func constructor() {
|
||||
constructor(this);
|
||||
this.batt_cap = -1;
|
||||
this.wifi_sig = -1;
|
||||
this.colon = true;
|
||||
}
|
||||
|
||||
func destructor() {
|
||||
destructor(this);
|
||||
}
|
||||
|
||||
define {
|
||||
BATT_UNKNOWN = 0;
|
||||
BATT_LOW = 1;
|
||||
BATT_MID = 2;
|
||||
BATT_FULL = 3;
|
||||
}
|
||||
|
||||
define {
|
||||
WIFI_OFF = 0;
|
||||
WIFI_LOW = 1;
|
||||
WIFI_MID = 2;
|
||||
WIFI_HIGH = 3;
|
||||
}
|
||||
|
||||
func init(render void) bool {
|
||||
this.long_timer->init(3000);
|
||||
this.long_timer->done();
|
||||
this.short_timer->init(1000);
|
||||
this.short_timer->done();
|
||||
this.batt_icon[BATT_UNKNOWN]->load_file(render,
|
||||
global::make_path("main/battery.png"));
|
||||
this.batt_icon[BATT_LOW]->load_file(render,
|
||||
global::make_path("main/battery_low.png"));
|
||||
this.batt_icon[BATT_MID]->load_file(render,
|
||||
global::make_path("main/battery_mid.png"));
|
||||
this.batt_icon[BATT_FULL]->load_file(render,
|
||||
global::make_path("main/battery_full.png"));
|
||||
this.batt_charging_icon->load_file(render,
|
||||
global::make_path("main/battery_charging.png"));
|
||||
this.wifi_icon[WIFI_OFF]->load_file(render,
|
||||
global::make_path("main/wifi.png"));
|
||||
this.wifi_icon[WIFI_LOW]->load_file(render,
|
||||
global::make_path("main/wifi_low.png"));
|
||||
this.wifi_icon[WIFI_MID]->load_file(render,
|
||||
global::make_path("main/wifi_mid.png"));
|
||||
this.wifi_icon[WIFI_HIGH]->load_file(render,
|
||||
global::make_path("main/wifi_high.png"));
|
||||
return true;
|
||||
}
|
||||
|
||||
func update(render void) {
|
||||
if this.long_timer->do() {
|
||||
if !global::wifi->is_connected(&this.wifi_sig);
|
||||
this.wifi_sig = -1;
|
||||
this.long_timer->undo();
|
||||
}
|
||||
if this.short_timer->do() {
|
||||
this.batt_cap = global::get_battery_cap();
|
||||
this.colon = !this.colon;
|
||||
this.short_timer->undo();
|
||||
}
|
||||
}
|
||||
|
||||
private func get_batt_icon() .texture {
|
||||
var icon int = BATT_UNKNOWN;
|
||||
if this.batt_cap ~= -1 {
|
||||
var cap int = this.batt_cap & ~0x100;
|
||||
if cap > 65 {
|
||||
icon = BATT_FULL;
|
||||
elseif cap > 20;
|
||||
icon = BATT_MID;
|
||||
elseif cap > 0;
|
||||
icon = BATT_LOW;
|
||||
}
|
||||
}
|
||||
return &this.batt_icon[icon];
|
||||
}
|
||||
|
||||
private func get_wifi_icon() .texture {
|
||||
var icon int;
|
||||
if this.wifi_sig > 60 {
|
||||
icon = WIFI_HIGH;
|
||||
elseif this.wifi_sig > 30;
|
||||
icon = WIFI_MID;
|
||||
elseif this.wifi_sig > 0;
|
||||
icon = WIFI_LOW;
|
||||
else
|
||||
icon = WIFI_OFF;
|
||||
}
|
||||
return &this.wifi_icon[icon];
|
||||
}
|
||||
|
||||
func draw(render void) {
|
||||
var x int = this->get_right();
|
||||
var y int = this->get_y();
|
||||
using batt_icon. texture = this->get_batt_icon() {
|
||||
if this.batt_cap ~= -1;
|
||||
global::small_font->draw_cap(render, x -= 40, y + 7, this.batt_cap & ~0x100);;
|
||||
batt_icon->draw(render, x -= batt_icon->get_width(), y);
|
||||
if this.batt_cap ~= -1 and
|
||||
this.batt_cap & 0x100;
|
||||
this.batt_charging_icon->draw(render, x, y);
|
||||
}
|
||||
using wifi_icon. texture = this->get_wifi_icon() {
|
||||
wifi_icon->draw(render, x -= wifi_icon->get_width(), y);
|
||||
}
|
||||
global::small_font->draw_time(render,
|
||||
x -= 55, y + 7, time(null), this.colon);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,168 +0,0 @@
|
||||
|
||||
/*
|
||||
set_callback(on_press void, arg void)
|
||||
add_menu(render void, id int, title. char, icon_filename. char) bool
|
||||
set_cursor(cursor int)
|
||||
get_selected_menu() .menu
|
||||
*/
|
||||
|
||||
class game+, scene+, main+, sub_menu {
|
||||
|
||||
inherit game::control = super;
|
||||
|
||||
private import rt::c, lib::sdl2;
|
||||
|
||||
class menu {
|
||||
struct menu {
|
||||
icon texture;
|
||||
title texture;
|
||||
id int;
|
||||
}
|
||||
func constructor() {
|
||||
constructor(this); }
|
||||
func destructor() {
|
||||
destructor(this); }
|
||||
}
|
||||
|
||||
struct sub_menu {
|
||||
struct tex {
|
||||
button texture;
|
||||
button_hover texture;
|
||||
}
|
||||
menus(MENU_COUNT) menu;
|
||||
menu_count int;
|
||||
input_delay repeat;
|
||||
input_lock norepeat;
|
||||
cursor int;
|
||||
on_press void;
|
||||
arg void;
|
||||
}
|
||||
|
||||
func constructor() {
|
||||
memset(this, 0, sizeof(sub_menu));
|
||||
constructor(this);
|
||||
}
|
||||
|
||||
func destructor() {
|
||||
destructor(this);
|
||||
}
|
||||
|
||||
define {
|
||||
MENU_COUNT = 5;
|
||||
BUTTON_WIDTH = 40;
|
||||
BUTTON_HEIGHT = 40;
|
||||
BUTTON_GAP = 10;
|
||||
}
|
||||
|
||||
func init(render void) bool {
|
||||
this.tex.button->load_file(render,
|
||||
global::make_path("main/button_40x40.png"));
|
||||
this.tex.button_hover->load_file(render,
|
||||
global::make_path("main/button_hover_40x40.png"));
|
||||
this.input_delay->init(300, -10, 20);
|
||||
return true;
|
||||
}
|
||||
|
||||
inline set_callback(on_press void, arg void) {
|
||||
this.on_press = on_press;
|
||||
this.arg = arg;
|
||||
}
|
||||
|
||||
func add_menu(render void, id int, title. char, icon_filename. char) bool {
|
||||
if this.menu_count >= MENU_COUNT;
|
||||
return false;
|
||||
this.menus[this.menu_count].icon->load_file(render, icon_filename);
|
||||
this.menus[this.menu_count].title->init(
|
||||
global::uni_font->create_tex(render, title, 0xff000000));
|
||||
this.menus[this.menu_count].id = id;
|
||||
this.menu_count++;
|
||||
return true;
|
||||
}
|
||||
|
||||
func update(render void) {
|
||||
if this->has_focus() {
|
||||
var state. uint8 = SDL_GetKeyboardState(null);
|
||||
if state[CPI_SCANCODE_LEFT] {
|
||||
if this.input_delay->do() {
|
||||
if this.cursor;
|
||||
this.cursor--;
|
||||
this.input_delay->undo();
|
||||
}
|
||||
elseif state[CPI_SCANCODE_RIGHT];
|
||||
if this.input_delay->do() {
|
||||
if this.cursor < MENU_COUNT - 1;
|
||||
this.cursor++;
|
||||
this.input_delay->undo();
|
||||
}
|
||||
elseif state[CPI_SCANCODE_UP];
|
||||
var parent. scene::main = this->get_parent();
|
||||
var cursor int = this.cursor;
|
||||
#if MENU_COUNT > tile_menu::TILE_HALF_COUNT;
|
||||
cursor /= (MENU_COUNT / tile_menu::TILE_HALF_COUNT);
|
||||
#else
|
||||
cursor += (tile_menu::TILE_HALF_COUNT - MENU_COUNT) / 2;
|
||||
#endif
|
||||
if (cursor += tile_menu::TILE_HALF_COUNT) >= tile_menu::TILE_COUNT;
|
||||
cursor = tile_menu::TILE_COUNT - 1;
|
||||
var tile_menu. tile_menu = parent.tile_menu;
|
||||
tile_menu->set_cursor(cursor);
|
||||
tile_menu->wake();
|
||||
parent->set_focus(tile_menu);
|
||||
else
|
||||
this.input_delay->reset();
|
||||
}
|
||||
if state[CPI_SCANCODE_B] {
|
||||
if this.input_lock->do() {
|
||||
var menu. menu = this->get_selected_menu();
|
||||
if menu ~= null {
|
||||
proto fn(id int, arg void);
|
||||
fn[this.on_press](menu.id, this.arg);
|
||||
}
|
||||
}
|
||||
else
|
||||
this.input_lock->set(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func draw(render void) {
|
||||
var focus bool = this->has_focus();
|
||||
var rect SDL_Rect = 0;
|
||||
this->get_window()->get_size(&rect.w, &rect.h);
|
||||
var x int = this->get_x() +
|
||||
(this->get_width() - ((BUTTON_WIDTH * MENU_COUNT) + (BUTTON_GAP * (MENU_COUNT - 1)))) / 2;
|
||||
var y int = this->get_y();
|
||||
forvar index int = 0; index < MENU_COUNT; index++ {
|
||||
var menu. menu = &this.menus[index];
|
||||
if focus and this.cursor == index {
|
||||
this.tex.button_hover->draw(render, x, y);
|
||||
// out of bounds
|
||||
menu.title->draw(render,
|
||||
this->get_x() + (rect.w - menu.title->get_width()) / 2,
|
||||
y - (menu.title->get_height() + 4));
|
||||
else
|
||||
this.tex.button->draw(render, x, y);
|
||||
}
|
||||
menu.icon->draw(render, x + 1, y + 1);
|
||||
x += (BUTTON_WIDTH + BUTTON_GAP);
|
||||
}
|
||||
}
|
||||
|
||||
func wake() {
|
||||
this.input_delay->reset(false);
|
||||
this.input_lock->set(true);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
inline set_cursor(cursor int) {
|
||||
this.cursor = cursor;
|
||||
}
|
||||
|
||||
inline get_selected_menu() .menu {
|
||||
if this.cursor < this.menu_count;
|
||||
return &this.menus[this.cursor];
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,635 +0,0 @@
|
||||
|
||||
/*
|
||||
reload_page(render void)
|
||||
set_mode(mode. mode)
|
||||
get_mode() mode
|
||||
set_link(filename. char)
|
||||
clear_link()
|
||||
get_page() int
|
||||
set_page(render void, page int)
|
||||
set_cursor(cursor int)
|
||||
get_app(index int) .tile_app
|
||||
get_selected_app() .tile_app
|
||||
*/
|
||||
|
||||
class game+, scene+, main+, tile_menu {
|
||||
|
||||
inherit game::control = super;
|
||||
|
||||
private import rt::c, lib::sdl2;
|
||||
|
||||
private alias
|
||||
string = std::string,
|
||||
strings = std::strings;
|
||||
|
||||
private alias popup_menu = control::popup_menu;
|
||||
|
||||
enum mode {
|
||||
none,
|
||||
move,
|
||||
link
|
||||
}
|
||||
|
||||
class image_cache {
|
||||
private import rt::c;
|
||||
private alias
|
||||
vector = std::vector,
|
||||
string = std::string;
|
||||
struct cache {
|
||||
filename string;
|
||||
tex texture;
|
||||
}
|
||||
struct image_cache {
|
||||
caches vector<cache>;
|
||||
}
|
||||
func constructor() {
|
||||
constructor(this); }
|
||||
func destructor() {
|
||||
destructor(this); }
|
||||
func find(filename. char) .cache {
|
||||
var count size_t = this.caches->count();
|
||||
while count {
|
||||
var cache. cache = this.caches->at(--count);
|
||||
if !strcmp(cache.filename->ptr(), filename) {
|
||||
return cache;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
func load_file(render void, filename. char) void {
|
||||
var cache. cache = this->find(filename);
|
||||
if cache == null {
|
||||
cache = this.caches->new();
|
||||
cache.filename->set(filename);
|
||||
if !cache.tex->load_file(render, filename) {
|
||||
this.caches->pop_back();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return cache.tex->get_texture();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
fixme
|
||||
*/
|
||||
class tile_app {
|
||||
struct tile_app {
|
||||
struct tex {
|
||||
icon texture;
|
||||
title texture;
|
||||
}
|
||||
icon. char;
|
||||
title. char;
|
||||
cmd. char;
|
||||
slot int;
|
||||
type int;
|
||||
}
|
||||
func constructor() {
|
||||
constructor(this); }
|
||||
func destructor() {
|
||||
destructor(this); }
|
||||
}
|
||||
|
||||
struct tile_menu {
|
||||
struct tex {
|
||||
tile texture;
|
||||
tile_hover texture;
|
||||
// ...
|
||||
move_mode texture;
|
||||
link_mode texture;
|
||||
}
|
||||
input_delay repeat;
|
||||
input_lock norepeat;
|
||||
page int;
|
||||
cursor int;
|
||||
struct slide {
|
||||
delay delay;
|
||||
dir bool;
|
||||
}
|
||||
image_cache image_cache;
|
||||
apps(TILE_COUNT) tile_app;
|
||||
temp_apps(TILE_COUNT) tile_app;
|
||||
moving_icon texture;
|
||||
mode mode;
|
||||
from int;
|
||||
link string;
|
||||
}
|
||||
|
||||
func constructor() {
|
||||
memset(this, 0, sizeof(tile_menu));
|
||||
constructor(this);
|
||||
}
|
||||
|
||||
func destructor() {
|
||||
destructor(this);
|
||||
}
|
||||
|
||||
define {
|
||||
TILE_COUNT = 10;
|
||||
TILE_HALF_COUNT = TILE_COUNT / 2;
|
||||
TILE_WIDTH = 52;
|
||||
TILE_HEIGHT = 52;
|
||||
TILE_GAP = 10;
|
||||
}
|
||||
|
||||
define {
|
||||
MAX_PAGE = 10;
|
||||
}
|
||||
|
||||
static func free_app(app. tile_app) {
|
||||
app.tex.icon->destroy();
|
||||
app.tex.title->destroy();
|
||||
app.icon = null;
|
||||
app.title = null;
|
||||
app.cmd = null;
|
||||
app.type = -1;
|
||||
}
|
||||
|
||||
func reload_page(render void) {
|
||||
struct args {
|
||||
tile_menu. tile_menu;
|
||||
tile_apps. tile_app;
|
||||
render void;
|
||||
begin int;
|
||||
}
|
||||
var arg args;
|
||||
arg.tile_menu = this;
|
||||
arg.tile_apps = &this.apps;
|
||||
arg.render = render;
|
||||
arg.begin = (this.page - 1) * TILE_COUNT;
|
||||
forvar i int = 0; i < TILE_COUNT; i++ {
|
||||
var app. tile_app = &this.apps[i];
|
||||
this->free_app(app);
|
||||
app.slot = arg.begin + i;
|
||||
}
|
||||
global::apps->for_each(arg.begin, arg.begin + (TILE_COUNT - 1),
|
||||
lambda(app. app_list::app, arg. args) [
|
||||
var tile_menu. tile_menu = arg.tile_menu;
|
||||
var tile_app. tile_app = &arg.tile_apps[app.slot - arg.begin];
|
||||
tile_app.tex.icon->init(
|
||||
tile_menu.image_cache->load_file(arg.render,
|
||||
tile_app.icon = app.icon->ptr()), false);
|
||||
using title void {
|
||||
tile_app.title = app.title->ptr();
|
||||
// deprecated
|
||||
if global::outlined_font {
|
||||
title = global::uni_font->create_outlined_tex(arg.render, tile_app.title,
|
||||
0xffffffff, 0xff000000, 1);
|
||||
else
|
||||
title = global::uni_font->create_tex(arg.render, tile_app.title, 0xff000000);
|
||||
}
|
||||
tile_app.tex.title->init(title);
|
||||
}
|
||||
tile_app.cmd = app.cmd->ptr();
|
||||
tile_app.type = app.type;
|
||||
], &arg
|
||||
);
|
||||
}
|
||||
|
||||
func init(render void) bool {
|
||||
this.tex.tile->load_file(render,
|
||||
global::make_path("main/tile_52x52.png"));
|
||||
this.tex.tile_hover->load_file(render,
|
||||
global::make_path("main/tile_hover_52x52.png"));
|
||||
// ...
|
||||
this.tex.move_mode->init(
|
||||
global::uni_font->create_tex(render, "Move Mode", 0xffffffff));
|
||||
this.tex.link_mode->init(
|
||||
global::uni_font->create_tex(render, "Link Mode", 0xffffffff));
|
||||
this.input_delay->init(300, -25, 10);
|
||||
this.slide.delay->done();
|
||||
this.page = 1;
|
||||
this->reload_page(render);
|
||||
return true;
|
||||
}
|
||||
|
||||
private func exec(cmd. char) {
|
||||
if .cmd == '#' {
|
||||
var strs strings;
|
||||
strs->split(++cmd, "\t");
|
||||
/*
|
||||
#exec dir ext format
|
||||
*/
|
||||
if !strcmp(strs->first_item(), "exec") {
|
||||
if strs->count() > 3 {
|
||||
var wnd. window = this->get_window();
|
||||
var browser. scene::file_browser = wnd->new_scene<scene::file_browser>();
|
||||
browser->set_fadeout(&this->get_parent_t<scene::main>().fadeio);
|
||||
browser->hidden_files(true);
|
||||
browser->set_mode(
|
||||
scene::file_browser::mode.exec);
|
||||
if strlen(strs->item(2));
|
||||
browser->set_ext(strs->item(2));
|
||||
browser->set_exec_format(strs->item(3));
|
||||
mkdir(strs->item(1), 0775);
|
||||
if browser->set_dir(wnd->get_render(), strs->item(1), true) {
|
||||
wnd->push_scene(this->get_parent());
|
||||
wnd->set_scene(browser);
|
||||
else
|
||||
wnd->free_scene(browser);
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif .cmd;
|
||||
exec3(this->get_window(), "Please Wait", cmd);
|
||||
}
|
||||
}
|
||||
|
||||
// popup
|
||||
|
||||
private func adjust_popup_pos(popup. popup_menu) {
|
||||
var x int = this->get_x() + TILE_GAP;
|
||||
var y int = this->get_y();
|
||||
if this.cursor < TILE_HALF_COUNT {
|
||||
x += this.cursor * (TILE_WIDTH + TILE_GAP);
|
||||
else
|
||||
x += (this.cursor - TILE_HALF_COUNT) * (TILE_WIDTH + TILE_GAP);
|
||||
y += TILE_HEIGHT + TILE_GAP;
|
||||
}
|
||||
x += TILE_WIDTH;
|
||||
var rect SDL_Rect = 0;
|
||||
this->get_window()->get_size(&rect.w, &rect.h);
|
||||
var popup_width int = popup->get_width();
|
||||
var popup_height int = popup->get_height();
|
||||
if (x + popup_width) > rect.w;
|
||||
x -= popup_width + TILE_WIDTH;
|
||||
if (y + popup_height) > rect.h;
|
||||
y = rect.h - popup_height;
|
||||
popup->set_pos(x, y);
|
||||
}
|
||||
|
||||
private func show_edit_popup(render void, app. tile_app) {
|
||||
define {
|
||||
POPUP_WIDTH = 280;
|
||||
POPUP_HEIGHT = 186;
|
||||
}
|
||||
var rect SDL_Rect = 0;
|
||||
this->get_window()->get_size(&rect.w, &rect.h);
|
||||
this->close_popup();
|
||||
var popup. edit_popup = this->create_control<edit_popup>(
|
||||
(rect.w - POPUP_WIDTH) / 2,
|
||||
(rect.h - POPUP_HEIGHT) / 2, POPUP_WIDTH, POPUP_HEIGHT);
|
||||
popup->fill_in(render, app);
|
||||
this->set_popup(popup);
|
||||
}
|
||||
|
||||
private func show_popup(render void, app. tile_app) {
|
||||
define {
|
||||
MENU_REMOVE = -1;
|
||||
MENU_EXECUTE = 0;
|
||||
MENU_MOVE = 1;
|
||||
MENU_EDIT = 2;
|
||||
}
|
||||
this->close_popup();
|
||||
var popup. popup_menu = this->create_control<popup_menu>(0, 0);
|
||||
popup->set_callback(
|
||||
lambda(id int, this.tile_menu) [
|
||||
var app. tile_app = this->get_selected_app();
|
||||
if id == MENU_REMOVE {
|
||||
if global::apps->remove(app.slot);
|
||||
this->free_app(app);
|
||||
elseif id == MENU_EXECUTE;
|
||||
if app.cmd ~= null;
|
||||
this->exec(app.cmd);
|
||||
elseif id == MENU_MOVE;
|
||||
var render void = this->get_window()->get_render();
|
||||
this.from = app.slot;
|
||||
this.moving_icon->init(
|
||||
this.image_cache->load_file(render, app.icon), false);
|
||||
this.mode = mode.move;
|
||||
elseif id == MENU_EDIT;
|
||||
this->show_edit_popup(this->get_window()->get_render(), app);
|
||||
}
|
||||
],
|
||||
lambda(this.tile_menu) [
|
||||
this->close_popup();
|
||||
], this);
|
||||
if app.type == -1 {
|
||||
popup->add_menu(render, MENU_EDIT, "Edit");
|
||||
else
|
||||
popup->add_menu(render, MENU_EXECUTE, "Execute");
|
||||
popup->add_menu(render, MENU_MOVE, "Move");
|
||||
if app.type {
|
||||
popup->add_menu(render, MENU_EDIT, "Edit");
|
||||
popup->add_menu(render, MENU_REMOVE, "Remove");
|
||||
}
|
||||
}
|
||||
this->adjust_popup_pos(popup);
|
||||
this->set_popup(popup);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
private func try_slide(render void, cursor int, page int, dir bool, delay int = 300) {
|
||||
if this.slide.delay->done?() {
|
||||
this.cursor = cursor;
|
||||
this.page = page;
|
||||
this.temp_apps = this.apps;
|
||||
memset(&this.apps, 0, sizeof(tile_app, TILE_COUNT));
|
||||
this->reload_page(render);
|
||||
this.slide.dir = dir;
|
||||
this.slide.delay->init(delay);
|
||||
this->get_window()->enable_turbo(delay * 2);
|
||||
}
|
||||
}
|
||||
|
||||
func update(render void) {
|
||||
if this->has_focus() {
|
||||
if this->has_popup() {
|
||||
this.super->update(render);
|
||||
else
|
||||
var state. uint8 = SDL_GetKeyboardState(null);
|
||||
if state[CPI_SCANCODE_LEFT] {
|
||||
if this.input_delay->do() {
|
||||
if !this.cursor {
|
||||
if this.page > 1 {
|
||||
this->try_slide(render, TILE_HALF_COUNT - 1, this.page - 1, false);
|
||||
else
|
||||
this->try_slide(render, TILE_HALF_COUNT - 1, MAX_PAGE, false);
|
||||
}
|
||||
elseif this.cursor == TILE_HALF_COUNT;
|
||||
if this.page > 1 {
|
||||
this->try_slide(render, TILE_COUNT - 1, this.page - 1, false);
|
||||
else
|
||||
this->try_slide(render, TILE_COUNT - 1, MAX_PAGE, false);
|
||||
}
|
||||
elseif this.cursor;
|
||||
this.cursor--;
|
||||
}
|
||||
this.input_delay->undo();
|
||||
}
|
||||
elseif state[CPI_SCANCODE_RIGHT];
|
||||
if this.input_delay->do() {
|
||||
if this.cursor == TILE_HALF_COUNT - 1 {
|
||||
if this.page < MAX_PAGE {
|
||||
this->try_slide(render, 0, this.page + 1, true);
|
||||
else
|
||||
this->try_slide(render, 0, 1, true);
|
||||
}
|
||||
elseif this.cursor == TILE_COUNT - 1;
|
||||
if this.page < MAX_PAGE {
|
||||
this->try_slide(render, TILE_HALF_COUNT, this.page + 1, true);
|
||||
else
|
||||
this->try_slide(render, TILE_HALF_COUNT, 1, true);
|
||||
}
|
||||
elseif this.cursor < TILE_COUNT - 1;
|
||||
this.cursor++;
|
||||
}
|
||||
this.input_delay->undo();
|
||||
}
|
||||
elseif state[CPI_SCANCODE_UP];
|
||||
if this.input_delay->do() {
|
||||
if this.cursor >= TILE_HALF_COUNT;
|
||||
this.cursor -= TILE_HALF_COUNT;
|
||||
this.input_delay->undo();
|
||||
}
|
||||
elseif state[CPI_SCANCODE_DOWN];
|
||||
if this.input_delay->do() {
|
||||
if this.cursor < TILE_HALF_COUNT {
|
||||
this.cursor += TILE_HALF_COUNT;
|
||||
elseif this.mode == mode.none;
|
||||
var parent. scene::main = this->get_parent();
|
||||
var cursor int = this.cursor - TILE_HALF_COUNT;
|
||||
#if TILE_HALF_COUNT > sub_menu::MENU_COUNT;
|
||||
cursor /= (TILE_HALF_COUNT / sub_menu::MENU_COUNT);
|
||||
#else
|
||||
cursor += (sub_menu::MENU_COUNT - TILE_HALF_COUNT) / 2;
|
||||
#endif
|
||||
if cursor >= sub_menu::MENU_COUNT;
|
||||
cursor = sub_menu::MENU_COUNT - 1;
|
||||
var sub_menu. sub_menu = parent.sub_menu;
|
||||
sub_menu->set_cursor(cursor);
|
||||
sub_menu->wake();
|
||||
parent->set_focus(sub_menu);
|
||||
}
|
||||
this.input_delay->undo();
|
||||
}
|
||||
else
|
||||
this.input_delay->reset();
|
||||
}
|
||||
if state[CPI_SCANCODE_A] {
|
||||
if this.input_lock->do() {
|
||||
if this.mode == mode.move {
|
||||
this.mode = mode.none;
|
||||
this.moving_icon->destroy();
|
||||
elseif this.mode == mode.link;
|
||||
this.mode = mode.none;
|
||||
this.link->clear();
|
||||
}
|
||||
}
|
||||
elseif state[CPI_SCANCODE_B];
|
||||
if this.input_lock->do() {
|
||||
if this.mode == mode.none {
|
||||
var app. tile_app = this->get_selected_app();
|
||||
if app.cmd ~= null {
|
||||
this->exec(app.cmd);
|
||||
}
|
||||
elseif this.mode == mode.move;
|
||||
var app. tile_app = this->get_selected_app();
|
||||
if app.slot == this.from {
|
||||
this.mode = mode.none;
|
||||
this.moving_icon->destroy();
|
||||
else
|
||||
if app.type {
|
||||
if global::apps->move(this.from, app.slot);
|
||||
this->reload_page(render);
|
||||
this.mode = mode.none;
|
||||
this.moving_icon->destroy();
|
||||
else
|
||||
// system app
|
||||
}
|
||||
}
|
||||
elseif this.mode == mode.link;
|
||||
var app. tile_app = this->get_selected_app();
|
||||
if app.type == -1 {
|
||||
app.cmd = this.link->ptr();
|
||||
this->show_edit_popup(render, app);
|
||||
this.mode = mode.none;
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif state[CPI_SCANCODE_MENU];
|
||||
if this.input_lock->do() {
|
||||
if this.mode == mode.none;
|
||||
this->show_popup(render, this->get_selected_app());
|
||||
}
|
||||
elseif state[CPI_SCANCODE_LK1];
|
||||
if this.input_lock->do() {
|
||||
if this.page > 1 {
|
||||
this->try_slide(render, this.cursor, this.page - 1, false);
|
||||
else
|
||||
this->try_slide(render, this.cursor, MAX_PAGE, false);
|
||||
}
|
||||
}
|
||||
elseif state[CPI_SCANCODE_LK5];
|
||||
if this.input_lock->do() {
|
||||
if this.page < MAX_PAGE {
|
||||
this->try_slide(render, this.cursor, this.page + 1, true);
|
||||
else
|
||||
this->try_slide(render, this.cursor, 1, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
this.input_lock->set(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func draw_icon(render void, icon. texture, rect. SDL_Rect) {
|
||||
var width int = icon->get_width();
|
||||
var height int = icon->get_height();
|
||||
if width > rect.w;
|
||||
width = rect.w;
|
||||
if height > rect.h;
|
||||
height = rect.h;
|
||||
icon->draw3(render,
|
||||
rect.x + (rect.w - width) / 2,
|
||||
rect.y + (rect.h - height) / 2, width, height);
|
||||
}
|
||||
|
||||
private func draw_tiles(render void, x int, y int, start int, end int) {
|
||||
var rect SDL_Rect;
|
||||
rect.y = y + 1;
|
||||
rect.w = TILE_WIDTH - 2;
|
||||
rect.h = TILE_HEIGHT - 2;
|
||||
forvar index int = start; index < end; index++ {
|
||||
var app. tile_app = &this.apps[index];
|
||||
rect.x = x + 1;
|
||||
if this->has_focus() and this.cursor == index {
|
||||
this.tex.tile_hover->draw(render, x, y);
|
||||
if this.moving_icon->get_texture() == null {
|
||||
this->draw_icon(render, &app.tex.icon, &rect);
|
||||
else
|
||||
this->draw_icon(render, &this.moving_icon, &rect);
|
||||
}
|
||||
// out of bounds
|
||||
app.tex.title->draw(render,
|
||||
this->get_x() + (this->get_width() - app.tex.title->get_width()) / 2,
|
||||
this->get_bottom() + 5);
|
||||
else
|
||||
this.tex.tile->draw(render, x, y);
|
||||
this->draw_icon(render,
|
||||
&app.tex.icon, &rect);
|
||||
}
|
||||
x += (TILE_GAP + TILE_WIDTH);
|
||||
}
|
||||
}
|
||||
|
||||
private func draw_temp_tiles(render void, x int, y int, start int, end int) {
|
||||
var rect SDL_Rect;
|
||||
rect.y = y + 1;
|
||||
rect.w = TILE_WIDTH - 2;
|
||||
rect.h = TILE_HEIGHT - 2;
|
||||
forvar index int = start; index < end; index++ {
|
||||
this.tex.tile->draw(render, x, y);
|
||||
rect.x = x + 1;
|
||||
this->draw_icon(render, &this.temp_apps[index].tex.icon, &rect);
|
||||
x += (TILE_GAP + TILE_WIDTH);
|
||||
}
|
||||
}
|
||||
|
||||
private func slide(render void) int {
|
||||
if this.slide.delay->do() {
|
||||
forvar index int = 0; index < TILE_COUNT; index++;
|
||||
this->free_app(&this.temp_apps[index]);
|
||||
return 0;
|
||||
}
|
||||
var delta int = this.slide.delay->get_per_r<int>(this->get_width());
|
||||
if this.slide.dir {
|
||||
this->draw_temp_tiles(render,
|
||||
this->get_x() - delta + TILE_GAP,
|
||||
this->get_y(), 0, TILE_HALF_COUNT);
|
||||
this->draw_temp_tiles(render,
|
||||
this->get_x() - delta + TILE_GAP,
|
||||
this->get_y() + (TILE_GAP + TILE_HEIGHT), TILE_HALF_COUNT, TILE_COUNT);
|
||||
return this->get_width() - delta;
|
||||
else
|
||||
this->draw_temp_tiles(render,
|
||||
this->get_x() + delta + TILE_GAP,
|
||||
this->get_y(), 0, TILE_HALF_COUNT);
|
||||
this->draw_temp_tiles(render,
|
||||
this->get_x() + delta + TILE_GAP,
|
||||
this->get_y() + (TILE_GAP + TILE_HEIGHT), TILE_HALF_COUNT, TILE_COUNT);
|
||||
return -(this->get_width() - delta);
|
||||
}
|
||||
}
|
||||
|
||||
func draw(render void) {
|
||||
var delta int = this->slide(render);
|
||||
this->draw_tiles(render,
|
||||
this->get_x() + TILE_GAP + delta,
|
||||
this->get_y(), 0, TILE_HALF_COUNT);
|
||||
this->draw_tiles(render,
|
||||
this->get_x() + TILE_GAP + delta,
|
||||
this->get_y() + (TILE_GAP + TILE_HEIGHT), TILE_HALF_COUNT, TILE_COUNT);
|
||||
this.super->draw(render);
|
||||
// out of bounds
|
||||
if this.mode ~= mode.none {
|
||||
define {
|
||||
PADDING = 3;
|
||||
}
|
||||
var tex. texture;
|
||||
if this.mode == mode.move {
|
||||
tex = &this.tex.move_mode;
|
||||
elseif this.mode == mode.link;
|
||||
tex = &this.tex.link_mode;
|
||||
}
|
||||
var rect SDL_Rect;
|
||||
rect.x = 0;
|
||||
rect.y = 0;
|
||||
rect.w = tex->get_width() + (PADDING * 2);
|
||||
rect.h = tex->get_height() + (PADDING * 2);
|
||||
SDL_SetRenderDrawColor(render, 52, 152, 219, 0xff);
|
||||
SDL_RenderFillRect(render, &rect);
|
||||
tex->draw(render, PADDING, PADDING);
|
||||
}
|
||||
}
|
||||
|
||||
func wake() {
|
||||
this.input_delay->reset(false);
|
||||
this.input_lock->set(true);
|
||||
this.super->wake();
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
inline set_mode(mode. mode) {
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
inline get_mode() mode {
|
||||
return this.mode;
|
||||
}
|
||||
|
||||
inline set_link(filename. char) {
|
||||
this.link->set(filename);
|
||||
}
|
||||
|
||||
inline clear_link() {
|
||||
this.link->clear();
|
||||
}
|
||||
|
||||
inline get_page() int {
|
||||
return this.page;
|
||||
}
|
||||
|
||||
inline set_page(render void, page int) {
|
||||
this.page = page;
|
||||
this->reload_page(render);
|
||||
}
|
||||
|
||||
inline set_cursor(cursor int) {
|
||||
this.cursor = cursor;
|
||||
}
|
||||
|
||||
inline get_app(index int) .tile_app {
|
||||
return &this.apps[index];
|
||||
}
|
||||
|
||||
inline get_selected_app() .tile_app {
|
||||
return this->get_app(this.cursor);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,160 +0,0 @@
|
||||
|
||||
class game+, scene+, main+ {
|
||||
|
||||
inherit game::scene = super;
|
||||
|
||||
private import rt::c, lib::sdl2;
|
||||
|
||||
private alias vector = std::vector;
|
||||
|
||||
struct main {
|
||||
struct tex {
|
||||
background texture;
|
||||
}
|
||||
fadeio fadeio;
|
||||
input_lock norepeat;
|
||||
status_bar. status_bar;
|
||||
tile_menu. tile_menu;
|
||||
sub_menu. sub_menu;
|
||||
}
|
||||
|
||||
func constructor() {
|
||||
constructor(this);
|
||||
}
|
||||
|
||||
func destructor() {
|
||||
destructor(this);
|
||||
}
|
||||
|
||||
private func standby() bool {
|
||||
var level byte = global::get_backlight_level();
|
||||
if level == -1;
|
||||
return false;
|
||||
if !global::set_backlight_level(0);
|
||||
return false;
|
||||
lambda signal(pids. vector<int>, sig int) [
|
||||
var count size_t = pids->count();
|
||||
while count {
|
||||
var pid int = .pids->at(--count);
|
||||
if pid ~= -1;
|
||||
kill(pid, sig);
|
||||
}
|
||||
];
|
||||
var pids vector<int>;
|
||||
pids->push_back(find_pid_by_cmdline("/home/cpi/launcher/sys.py/gsnotify/gsnotify-arm"));
|
||||
signal(&pids, SIGTSTP);
|
||||
for ;; {
|
||||
var event SDL_Event;
|
||||
while SDL_PollEvent(&event) {
|
||||
if event.type == SDL_KEYDOWN {
|
||||
break 2;
|
||||
elseif event.type == SDL_QUIT;
|
||||
this->get_window()->quit();
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
sleep(3);
|
||||
}
|
||||
signal(&pids, SIGCONT);
|
||||
forvar attempt int = 0; attempt < 3; attempt++ {
|
||||
if global::set_backlight_level(level);
|
||||
break;
|
||||
sleep(1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
func init(render void) bool {
|
||||
var wnd. window = this->get_window();
|
||||
var rect SDL_Rect = 0;
|
||||
wnd->get_size(&rect.w, &rect.h);
|
||||
this.tex.background->load_file(render,
|
||||
global::make_path("main/background.png"));
|
||||
this.fadeio->init(wnd, 300);
|
||||
this.fadeio->set_texture(wnd->screen_capture2());
|
||||
// 1st
|
||||
this.tile_menu = this->new_control<tile_menu>(0, 36, rect.w, 114);
|
||||
define {
|
||||
MENU_NONE = 1;
|
||||
MENU_BROWSER = 2;
|
||||
MENU_STANDBY = 3;
|
||||
MENU_QUIT = 4;
|
||||
}
|
||||
// 2nd
|
||||
this.sub_menu = this->new_control<sub_menu>(0, 176, rect.w, 40);
|
||||
this.sub_menu->set_callback(
|
||||
lambda(id int, this.main) [
|
||||
if id == MENU_BROWSER {
|
||||
var wnd. window = this->get_window();
|
||||
var browser. scene::file_browser = wnd->new_scene<scene::file_browser>();
|
||||
browser->set_fadeout(&this.fadeio);
|
||||
browser->set_mode(
|
||||
scene::file_browser::mode.browse);
|
||||
var cwd(0x800) char;
|
||||
if getcwd(&cwd, sizeof(cwd)) ~= null and browser->set_dir(wnd->get_render(), &cwd) {
|
||||
wnd->push_scene(this);
|
||||
wnd->set_scene(browser);
|
||||
else
|
||||
wnd->free_scene(browser);
|
||||
}
|
||||
elseif id == MENU_STANDBY;
|
||||
this->standby();
|
||||
elseif id == MENU_QUIT;
|
||||
this->get_window()->quit();
|
||||
}
|
||||
], this
|
||||
);
|
||||
this.sub_menu->add_menu(render, MENU_BROWSER, "File Browser",
|
||||
global::make_path("main/browser.png"));
|
||||
this.sub_menu->add_menu(render, MENU_STANDBY, "Standby",
|
||||
global::make_path("main/standby.png"));
|
||||
this.sub_menu->add_menu(render, MENU_QUIT, "Quit",
|
||||
global::make_path("main/quit.png"));
|
||||
// 3rd
|
||||
this.status_bar = this->new_control<status_bar>(8, 4, rect.w - 16, 26);
|
||||
this->set_focus(this.tile_menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
func update(render void) {
|
||||
this.super->update(render);
|
||||
var state. uint8 = SDL_GetKeyboardState(null);
|
||||
if state[CPI_SCANCODE_SELECT] {
|
||||
/*
|
||||
if this.input_lock->do() {
|
||||
var cwd(0x800) char;
|
||||
if getcwd(&cwd, sizeof(cwd)) ~= null {
|
||||
var filename std::string;
|
||||
filename->format("%s/bean", &cwd);
|
||||
execl( filename->ptr(),
|
||||
filename->ptr(), null);
|
||||
}
|
||||
}
|
||||
*/
|
||||
else
|
||||
this.input_lock->set(false);
|
||||
}
|
||||
}
|
||||
|
||||
func draw(render void) {
|
||||
if this.tex.background->get_texture() == null {
|
||||
SDL_SetRenderDrawColor(render, 0xff, 0xff, 0xff, 0xff);
|
||||
SDL_RenderClear(render);
|
||||
else
|
||||
this.tex.background->draw(render, 0, 0);
|
||||
}
|
||||
var rect SDL_Rect = 0;
|
||||
this->get_window()->get_size(&rect.w, &rect.h);
|
||||
// ...
|
||||
global::small_font->draw_page(render, 8, rect.h - 18,
|
||||
this.tile_menu->get_page(), tile_menu::MAX_PAGE);
|
||||
this.super->draw(render);
|
||||
this.fadeio->do();
|
||||
}
|
||||
|
||||
func wake() {
|
||||
this.input_lock->set(true);
|
||||
this.super->wake();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,237 +0,0 @@
|
||||
|
||||
/*
|
||||
fill_in(render void, app. tile_app)
|
||||
*/
|
||||
|
||||
class game+, scene+, main+, edit_popup {
|
||||
|
||||
inherit game::control = super;
|
||||
|
||||
private import rt::c, lib::sdl2;
|
||||
|
||||
private alias string = std::string;
|
||||
|
||||
private alias
|
||||
button = control::button,
|
||||
edit = control::edit,
|
||||
image_button = control::image_button,
|
||||
label = control::label;
|
||||
|
||||
private alias tile_app = tile_menu::tile_app;
|
||||
|
||||
struct edit_popup {
|
||||
input_delay repeat;
|
||||
input_lock norepeat;
|
||||
new_icon string;
|
||||
focus_map focus_map;
|
||||
app. tile_app;
|
||||
label_title. label;
|
||||
label_cmd. label;
|
||||
label_icon. label;
|
||||
edit_title. edit;
|
||||
edit_cmd. edit;
|
||||
button_icon. image_button;
|
||||
button_cancel. button;
|
||||
button_save. button;
|
||||
}
|
||||
|
||||
func constructor() {
|
||||
constructor(this);
|
||||
}
|
||||
|
||||
func destructor() {
|
||||
destructor(this);
|
||||
}
|
||||
|
||||
func init(render void) bool {
|
||||
this.input_delay->init(300, -10, 20);
|
||||
var rect SDL_Rect = this->get_rect();
|
||||
var y int = 10;
|
||||
this.label_title = this->new_control<label>(10, y);
|
||||
this.label_title->set_text(render, "Title");
|
||||
this.edit_title = this->new_control<edit>(
|
||||
10, y += (this.label_title->get_height() + 3), rect.w - 20, 25);
|
||||
this.label_cmd = this->new_control<label>(
|
||||
10, y += (this.edit_title->get_height() + 3));
|
||||
this.label_cmd->set_text(render, "CommandLine");
|
||||
this.edit_cmd = this->new_control<edit>(
|
||||
10, y += (this.label_cmd->get_height() + 3), rect.w - 20, 25);
|
||||
this.label_icon = this->new_control<label>(
|
||||
10, y += (this.edit_cmd->get_height() + 3));
|
||||
this.label_icon->set_text(render, "Icon");
|
||||
this.button_icon = this->new_control<image_button>(
|
||||
10, y += (this.label_icon->get_height() + 3));
|
||||
this.button_icon->set_normal_image(render,
|
||||
global::make_path("main/tile_52x52.png"));
|
||||
this.button_icon->set_hover_image(render,
|
||||
global::make_path("main/tile_hover_52x52.png"));
|
||||
this.button_icon->set_outline_size(1);
|
||||
define {
|
||||
BUTTON_WIDTH = 70;
|
||||
BUTTON_HEIGHT = 30;
|
||||
}
|
||||
this.button_cancel = this->new_control<button>(
|
||||
rect.w - ((BUTTON_WIDTH * 2) + 16),
|
||||
rect.h - (BUTTON_HEIGHT + 10), BUTTON_WIDTH, BUTTON_HEIGHT);
|
||||
this.button_cancel->set_text(render, "Cancel");
|
||||
this.button_save = this->new_control<button>(
|
||||
rect.w - (BUTTON_WIDTH + 10),
|
||||
rect.h - (BUTTON_HEIGHT + 10), BUTTON_WIDTH, BUTTON_HEIGHT);
|
||||
this.button_save->set_text(render, "Save");
|
||||
this.focus_map->register(this.edit_title, null, this.edit_cmd, null, null);
|
||||
this.focus_map->register(this.edit_cmd, this.edit_title, this.button_icon, null, null);
|
||||
this.focus_map->register(this.button_icon, this.edit_cmd, null, null, this.button_cancel);
|
||||
this.focus_map->register(this.button_cancel, this.edit_cmd, null, this.button_icon, this.button_save);
|
||||
this.focus_map->register(this.button_save, this.edit_cmd, null, this.button_cancel, null);
|
||||
this->set_focus(this.edit_title);
|
||||
return true;
|
||||
}
|
||||
|
||||
func fill_in(render void, app. tile_app) {
|
||||
this.app = app;
|
||||
if app.title ~= null;
|
||||
this.edit_title->set_text(render, app.title);
|
||||
if app.cmd ~= null;
|
||||
this.edit_cmd->set_text(render, app.cmd);
|
||||
if app.icon ~= null;
|
||||
this.button_icon->set_image(render, app.icon);
|
||||
}
|
||||
|
||||
private func show_keybd(render void, title. char, edit. edit) {
|
||||
var wnd. window = this->get_window();
|
||||
var keybd. scene::keybd = wnd->new_scene<scene::keybd>();
|
||||
keybd->set_callback(edit->get_keybd_cb(), null, edit);
|
||||
keybd->set_fadeout(&this->get_parent_t<scene::main>().fadeio);
|
||||
keybd->set_title(render, title);
|
||||
keybd->set_text(render, edit->get_text());
|
||||
wnd->push_scene(this->get_parent());
|
||||
wnd->set_scene(keybd);
|
||||
}
|
||||
|
||||
private func close() {
|
||||
var parent. tile_menu = this->get_parent_control();
|
||||
parent->clear_link();
|
||||
parent->close_popup();
|
||||
}
|
||||
|
||||
func update(render void) {
|
||||
var state. uint8 = SDL_GetKeyboardState(null);
|
||||
if state[CPI_SCANCODE_UP] {
|
||||
if this.input_delay->do() {
|
||||
var focus void = this.focus_map->get(this->get_focus(), CPI_SCANCODE_UP);
|
||||
if focus ~= null;
|
||||
this->set_focus(focus);
|
||||
this.input_delay->undo();
|
||||
}
|
||||
elseif state[CPI_SCANCODE_DOWN];
|
||||
if this.input_delay->do() {
|
||||
var focus void = this.focus_map->get(this->get_focus(), CPI_SCANCODE_DOWN);
|
||||
if focus ~= null;
|
||||
this->set_focus(focus);
|
||||
this.input_delay->undo();
|
||||
}
|
||||
elseif state[CPI_SCANCODE_LEFT];
|
||||
if this.input_delay->do() {
|
||||
var focus void = this.focus_map->get(this->get_focus(), CPI_SCANCODE_LEFT);
|
||||
if focus ~= null;
|
||||
this->set_focus(focus);
|
||||
this.input_delay->undo();
|
||||
}
|
||||
elseif state[CPI_SCANCODE_RIGHT];
|
||||
if this.input_delay->do() {
|
||||
var focus void = this.focus_map->get(this->get_focus(), CPI_SCANCODE_RIGHT);
|
||||
if focus ~= null;
|
||||
this->set_focus(focus);
|
||||
this.input_delay->undo();
|
||||
}
|
||||
else
|
||||
this.input_delay->reset();
|
||||
}
|
||||
if state[CPI_SCANCODE_A] or
|
||||
state[CPI_SCANCODE_MENU] {
|
||||
if this.input_lock->do() {
|
||||
this->close();
|
||||
}
|
||||
elseif state[CPI_SCANCODE_B];
|
||||
if this.input_lock->do() {
|
||||
var focus void = this->get_focus();
|
||||
if focus == this.edit_title {
|
||||
this->show_keybd(render, "Title", this.edit_title);
|
||||
elseif focus == this.edit_cmd;
|
||||
this->show_keybd(render, "CommandLine", this.edit_cmd);
|
||||
elseif focus == this.button_icon;
|
||||
var wnd. window = this->get_window();
|
||||
var browser. scene::file_browser = wnd->new_scene<scene::file_browser>();
|
||||
browser->set_callback(
|
||||
lambda(filename. char, this.edit_popup) [
|
||||
var render void = this->get_window()->get_render();
|
||||
if this.button_icon->set_image(render, filename) {
|
||||
this.new_icon->set(filename);
|
||||
else
|
||||
var app. tile_app = this.app;
|
||||
this.button_icon->set_image(render, app.icon);
|
||||
this.new_icon->clear();
|
||||
}
|
||||
], null, this
|
||||
);
|
||||
browser->set_fadeout(&this->get_parent_t<scene::main>().fadeio);
|
||||
browser->set_mode(
|
||||
scene::file_browser::mode.select_image);
|
||||
var path string;
|
||||
var cwd(0x800) char;
|
||||
if getcwd(&cwd, sizeof(cwd)) ~= null and
|
||||
browser->set_dir(wnd->get_render(), path->format("%s/icons", &cwd)) or
|
||||
browser->set_dir(wnd->get_render(), &cwd) {
|
||||
wnd->push_scene(this->get_parent());
|
||||
wnd->set_scene(browser);
|
||||
else
|
||||
wnd->free_scene(browser);
|
||||
}
|
||||
elseif focus == this.button_cancel;
|
||||
this->close();
|
||||
elseif focus == this.button_save;
|
||||
var tile_app. tile_app = this.app;
|
||||
var new_icon. char;
|
||||
if this.new_icon->empty() {
|
||||
new_icon = tile_app.icon;
|
||||
else
|
||||
new_icon = this.new_icon->ptr();
|
||||
}
|
||||
if tile_app.type == -1 {
|
||||
global::apps->insert(tile_app.slot, 1,
|
||||
this.edit_title->get_text(),
|
||||
this.edit_cmd->get_text(), new_icon);
|
||||
else
|
||||
global::apps->update(tile_app.slot, tile_app.type,
|
||||
this.edit_title->get_text(),
|
||||
this.edit_cmd->get_text(), new_icon);
|
||||
}
|
||||
var parent. tile_menu = this->get_parent_control();
|
||||
parent->reload_page(render);
|
||||
this->close();
|
||||
}
|
||||
}
|
||||
else
|
||||
this.input_lock->set(false);
|
||||
}
|
||||
this.super->update(render);
|
||||
}
|
||||
|
||||
func draw(render void) {
|
||||
var rect SDL_Rect = this->get_rect();
|
||||
SDL_SetRenderDrawBlendMode(render, SDL_BLENDMODE_BLEND);
|
||||
SDL_SetRenderDrawColor(render, 245, 245, 245, 230);
|
||||
SDL_RenderFillRect(render, &rect);
|
||||
SDL_SetRenderDrawBlendMode(render, SDL_BLENDMODE_NONE);
|
||||
SDL_SetRenderDrawColor(render, 0xcd, 0xcd, 0xcd, 0xff);
|
||||
SDL_RenderDrawRect(render, &rect);
|
||||
this.super->draw(render);
|
||||
}
|
||||
|
||||
func wake() {
|
||||
this.input_delay->reset(false);
|
||||
this.input_lock->set(true);
|
||||
this.super->wake();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
|
||||
// template
|
||||
|
||||
class game+, scene+, temp {
|
||||
|
||||
inherit game::scene = super;
|
||||
|
||||
private import lib::sdl2;
|
||||
|
||||
struct temp {
|
||||
|
||||
}
|
||||
|
||||
func constructor() {
|
||||
constructor(this);
|
||||
}
|
||||
|
||||
func destructor() {
|
||||
destructor(this);
|
||||
}
|
||||
|
||||
func init(render void) bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
func update(render void) {
|
||||
this.super->update(render);
|
||||
}
|
||||
|
||||
func draw(render void) {
|
||||
SDL_SetRenderDrawColor(render, 0, 0, 0, 0xff);
|
||||
SDL_RenderClear(render);
|
||||
this.super->draw(render);
|
||||
}
|
||||
|
||||
func wake() {
|
||||
this.super->wake();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
|
||||
/*
|
||||
powered by bean 0.382 r388
|
||||
*/
|
||||
|
||||
module app+ {
|
||||
|
||||
func main() {
|
||||
var launcher game::launcher;
|
||||
launcher->start("BeanShell");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func main() {
|
||||
app::main();
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
|
||||
module program+ {
|
||||
|
||||
private import
|
||||
rt::c,
|
||||
lib::sdl2,
|
||||
lib::sdl2_image,
|
||||
lib::sdl2_mixer,
|
||||
lib::sdl2_ttf;
|
||||
|
||||
func startup() {
|
||||
std::init();
|
||||
if !lib::curl::so::init() or
|
||||
!lib::dbus::so::init() or
|
||||
!lib::sdl2::so::init() or
|
||||
!lib::sdl2_image::so::init() or
|
||||
!lib::sdl2_mixer::so::init() or
|
||||
!lib::sdl2_ttf::so::init()or
|
||||
!lib::sqlite3::so::init() {
|
||||
exit(1);
|
||||
}
|
||||
init_sdl();
|
||||
srand2(clock(), time(null), getpid());
|
||||
}
|
||||
|
||||
func cleanup() {
|
||||
quit_sdl();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module program+ {
|
||||
|
||||
func init_sdl() {
|
||||
if SDL_Init(SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_EVENTS) < 0 {
|
||||
printf("SDL_Init: %s\n", SDL_GetError());
|
||||
exit(1);
|
||||
}
|
||||
if !IMG_Init(IMG_INIT_PNG) {
|
||||
printf("IMG_Init: %s\n", SDL_GetError());
|
||||
exit(1);
|
||||
}
|
||||
if !Mix_Init(MIX_INIT_MP3) {
|
||||
printf("Mix_Init: %s\n", SDL_GetError());
|
||||
exit(1);
|
||||
}
|
||||
if TTF_Init() == -1 {
|
||||
printf("TTF_Init: %s\n", SDL_GetError());
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
func quit_sdl() {
|
||||
TTF_Quit();
|
||||
Mix_Quit();
|
||||
IMG_Quit();
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,145 +0,0 @@
|
||||
|
||||
/*
|
||||
FIXME
|
||||
*/
|
||||
|
||||
class app_list+ {
|
||||
|
||||
private import rt::c;
|
||||
|
||||
private alias
|
||||
string = std::string,
|
||||
vector = std::vector;
|
||||
|
||||
struct app {
|
||||
slot int;
|
||||
type int;
|
||||
title string;
|
||||
cmd string;
|
||||
icon string;
|
||||
extra string;
|
||||
}
|
||||
|
||||
struct app_list {
|
||||
db database;
|
||||
apps vector<app>;
|
||||
}
|
||||
|
||||
func constructor() {
|
||||
constructor(this); }
|
||||
func destructor() {
|
||||
destructor(this); }
|
||||
|
||||
func init(filename. char) bool {
|
||||
if !this.db->open(filename);
|
||||
return false;
|
||||
this.db->exec(
|
||||
"
|
||||
CREATE TABLE IF NOT EXISTS apps (
|
||||
slot INTEGER PRIMARY KEY,
|
||||
type INTEGER NOT NULL,
|
||||
title TEXT NOT NULL,
|
||||
command TEXT NOT NULL,
|
||||
icon TEXT,
|
||||
extra TEXT
|
||||
);
|
||||
"
|
||||
);
|
||||
var stmt database::stmt;
|
||||
if !this.db->prepare(&stmt, "SELECT * FROM apps");
|
||||
return false;
|
||||
while stmt->step() {
|
||||
var app. app = this.apps->new();
|
||||
app.slot = stmt->column_int(0);
|
||||
app.type = stmt->column_int(1);
|
||||
app.title->set(stmt->column_text(2));
|
||||
app.cmd->set(stmt->column_text(3));
|
||||
app.icon->set(stmt->column_text(4));
|
||||
app.extra->set(stmt->column_text(5));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
func for_each(begin int, end int, callback void, arg void) {
|
||||
forvar i size_t = 0, c size_t = this.apps->count(); i < c; i++ {
|
||||
var app. app = this.apps->at(i);
|
||||
if app.slot >= begin and app.slot <= end {
|
||||
proto fn(app void, arg void);
|
||||
fn[callback](app, arg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func get_app_from_vector(slot int) .app {
|
||||
forvar index size_t = 0, count size_t = this.apps->count(); index < count; index++ {
|
||||
var app. app = this.apps->at(index);
|
||||
if app.slot == slot;
|
||||
return app;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
func remove_app_from_vector(slot int) bool {
|
||||
forvar index size_t = 0, count size_t = this.apps->count(); index < count; index++ {
|
||||
if this.apps->at(index).slot == slot;
|
||||
return this.apps->erase(index);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
func insert(slot int, type int, title. char, cmd. char, icon. char = null, extra. char = null) .app {
|
||||
if !this.db->execf("INSERT INTO apps (slot, type, title, command, icon, extra) VALUES (%d, %d, %Q, %Q, %Q, %Q)",
|
||||
slot, type, title, cmd, icon, extra) {
|
||||
return null;
|
||||
}
|
||||
func = this.apps->new();
|
||||
func.slot = slot;
|
||||
func.type = type;
|
||||
func.title->set(title);
|
||||
func.cmd->set(cmd);
|
||||
func.icon->set(icon);
|
||||
func.extra->set(extra);
|
||||
}
|
||||
|
||||
func update(slot int, type int, title. char, cmd. char, icon. char = null, extra. char = null) .app {
|
||||
if !this.db->execf("UPDATE apps SET type=%d, title=%Q, command=%Q, icon=%Q, extra=%Q WHERE slot=%d",
|
||||
type, title, cmd, icon, extra, slot) {
|
||||
return null;
|
||||
}
|
||||
/*
|
||||
fixme
|
||||
*/
|
||||
if (func = this->get_app_from_vector(slot)) == null;
|
||||
return;
|
||||
func.type = type;
|
||||
func.title->set(title);
|
||||
func.cmd->set(cmd);
|
||||
func.icon->set(icon);
|
||||
func.extra->set(extra);
|
||||
}
|
||||
|
||||
func remove(slot int) bool {
|
||||
this->remove_app_from_vector(slot);
|
||||
/*
|
||||
fixme
|
||||
*/
|
||||
return this.db->execf("DELETE FROM apps WHERE slot=%d", slot);
|
||||
}
|
||||
|
||||
func move(from int, to int) bool {
|
||||
this->remove(to);
|
||||
if !this.db->execf("UPDATE apps SET slot=%d WHERE slot=%d", to, from) {
|
||||
/*
|
||||
fixme
|
||||
*/
|
||||
return false;
|
||||
}
|
||||
using app. app = this->get_app_from_vector(from) {
|
||||
if app ~= null {
|
||||
app.slot = to;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,221 +0,0 @@
|
||||
|
||||
class cfg {
|
||||
|
||||
private import rt::c;
|
||||
|
||||
private alias
|
||||
vector = std::vector,
|
||||
string = std::string;
|
||||
|
||||
struct item {
|
||||
name string;
|
||||
value string;
|
||||
cover char;
|
||||
}
|
||||
|
||||
struct cfg {
|
||||
items vector<item>;
|
||||
filename string;
|
||||
}
|
||||
|
||||
func constructor() {
|
||||
constructor(this);
|
||||
}
|
||||
|
||||
func destructor() {
|
||||
destructor(this);
|
||||
}
|
||||
|
||||
func open(filename. char) bool {
|
||||
define {
|
||||
SIZE_LIMIT = 0x1000000;
|
||||
}
|
||||
lambda read(filename. char, file_size& size_t) void [
|
||||
var stream void = fopen(filename, "rb");
|
||||
if stream == null;
|
||||
return null;
|
||||
defer fclose(stream);
|
||||
if fseek(stream, 0, SEEK_END) < 0;
|
||||
return null;
|
||||
var tail long = ftell(stream);
|
||||
if tail < 0 or tail > SIZE_LIMIT;
|
||||
return null;
|
||||
rewind(stream);
|
||||
func = malloc(tail);
|
||||
var offset size_t = 0;
|
||||
var remain size_t = tail;
|
||||
while remain {
|
||||
var size size_t = fread(func + offset, 1, remain, stream);
|
||||
if ferror(stream) {
|
||||
free(func);
|
||||
return null;
|
||||
}
|
||||
offset += size;
|
||||
remain -= size;
|
||||
}
|
||||
file_size = offset;
|
||||
];
|
||||
var size size_t;
|
||||
var buf. char = read(filename, size);
|
||||
if buf == null;
|
||||
return false;
|
||||
defer free(buf);
|
||||
this.items->clear();
|
||||
this.filename->clear();
|
||||
lambda skip_space(buf. char, index& size_t, size size_t) bool [
|
||||
for ; index < size; index++ {
|
||||
if !isspace(buf[index]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
];
|
||||
lambda skip_line(buf. char, index& size_t, size size_t, end& size_t) bool [
|
||||
for ; index < size; index++ {
|
||||
var c char = buf[index];
|
||||
if c == '\r' {
|
||||
end = index;
|
||||
if ++index < size {
|
||||
if buf[index] == '\n' {
|
||||
index++;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
elseif c == '\n';
|
||||
end = index++;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
end = index;
|
||||
return false;
|
||||
];
|
||||
lambda skip_name(buf. char, index& size_t, size size_t) bool [
|
||||
for ; index < size; index++ {
|
||||
var c char = buf[index];
|
||||
if c == ' ' or c == '\t' or c == '\r' or c == '\n' or c == '=' {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
];
|
||||
lambda skip_until(buf. char, index& size_t, size size_t, end char) bool [
|
||||
for ; index < size; index++ {
|
||||
if buf[index] == end {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
];
|
||||
forvar index size_t = 0 ;; {
|
||||
if !skip_space(buf, index, size);
|
||||
break;
|
||||
var name_offset size_t = index;
|
||||
if !skip_name(buf, index, size);
|
||||
break;
|
||||
var name_size size_t = index - name_offset;
|
||||
if !name_size;
|
||||
return false;
|
||||
if buf[index] ~= '=' {
|
||||
if !skip_space(buf, ++index, size);
|
||||
break;
|
||||
if buf[index] ~= '=';
|
||||
return false;
|
||||
}
|
||||
if !skip_space(buf, ++index, size);
|
||||
break;
|
||||
var value_offset size_t;
|
||||
var value_size size_t;
|
||||
var cover char;
|
||||
if buf[index] == '\'' or
|
||||
buf[index] == '\"' {
|
||||
cover = buf[index];
|
||||
value_offset = ++index;
|
||||
if !skip_until(buf, index, size, cover);
|
||||
break;
|
||||
value_size = index++ - value_offset;
|
||||
else
|
||||
value_offset = index;
|
||||
var end size_t;
|
||||
skip_line(buf, index, size, end);
|
||||
value_size = end - value_offset;
|
||||
cover = 0;
|
||||
}
|
||||
var item. item = this.items->new();
|
||||
item.name->set(buf + name_offset, name_size);
|
||||
if value_size;
|
||||
item.value->set(buf + value_offset, value_size);
|
||||
item.cover = cover;
|
||||
}
|
||||
this.filename->set(filename);
|
||||
return true;
|
||||
}
|
||||
|
||||
func save(filename. char = null) bool {
|
||||
var stream void;
|
||||
if filename == null {
|
||||
if this.filename->empty();
|
||||
return false;
|
||||
stream = fopen(this.filename->ptr(), "w");
|
||||
else
|
||||
stream = fopen(filename, "w");
|
||||
}
|
||||
if stream == null;
|
||||
return false;
|
||||
forvar index size_t = 0, count size_t = this.items->count(); index < count; index++ {
|
||||
var item. item = this.items->at(index);
|
||||
if item.cover {
|
||||
fprintf("%s = %c%s%c\n",
|
||||
item.name->ptr(),
|
||||
item.cover,
|
||||
item.value->ptr(),
|
||||
item.cover);
|
||||
else
|
||||
fprintf("%s = %s\n",
|
||||
item.name->ptr(),
|
||||
item.value->ptr());
|
||||
}
|
||||
}
|
||||
fclose(stream);
|
||||
}
|
||||
|
||||
func find(name. char) .item {
|
||||
var count size_t = this.items->count();
|
||||
while count {
|
||||
var item. item = this.items->at(--count);
|
||||
if !strcasecmp(item.name->ptr(), name) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
func get(name. char) .char {
|
||||
var item. item = this->find(name);
|
||||
if item == null;
|
||||
return null;
|
||||
return item.value->ptr();
|
||||
}
|
||||
|
||||
func set(name. char, value. char) bool {
|
||||
var item. item = this->find(name);
|
||||
if item == null;
|
||||
return false;
|
||||
item.value->set(value);
|
||||
return true;
|
||||
}
|
||||
|
||||
func add(name. char, value. char = null, cover char = '"') bool {
|
||||
var item. item = this->find(name);
|
||||
if item ~= null;
|
||||
return false;
|
||||
item = this.items->new();
|
||||
item.name->set(name);
|
||||
if value ~= null;
|
||||
item.value->set(value);
|
||||
item.cover = cover;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,232 +0,0 @@
|
||||
|
||||
class database+ {
|
||||
|
||||
private import lib::sqlite3;
|
||||
|
||||
struct database {
|
||||
db void;
|
||||
}
|
||||
|
||||
func constructor() {
|
||||
this.db = null;
|
||||
}
|
||||
|
||||
func destructor() {
|
||||
this->close();
|
||||
}
|
||||
|
||||
func open(filename+ char, flags int =
|
||||
SQLITE_OPEN_READWRITE |
|
||||
SQLITE_OPEN_CREATE) bool {
|
||||
this->close();
|
||||
return sqlite3_open_v2(filename, &this.db, flags, null) == SQLITE_OK;
|
||||
}
|
||||
|
||||
func close() {
|
||||
if this.db ~= null;
|
||||
sqlite3_close_v2(this.db), this.db = null;
|
||||
}
|
||||
|
||||
inline exec(sql+ char) bool {
|
||||
return sqlite3_exec(this.db, sql, null, null, null) == SQLITE_OK;
|
||||
}
|
||||
|
||||
func execf(sql+ char, ...) bool {
|
||||
if (sql = sqlite3_vmprintf(sql, va_start(this))) == null;
|
||||
return false;
|
||||
func = this->exec(sql);
|
||||
sqlite3_free(sql);
|
||||
}
|
||||
|
||||
inline prepare(stmt. stmt, sql+ char) bool {
|
||||
return sqlite3_prepare_v2(this.db, sql, -1, &stmt.obj, null) == SQLITE_OK;
|
||||
}
|
||||
|
||||
func preparef(stmt. stmt, sql+ char, ...) bool {
|
||||
if (sql = sqlite3_vmprintf(sql, va_start(this))) == null;
|
||||
return false;
|
||||
func = this->prepare(stmt, sql);
|
||||
sqlite3_free(sql);
|
||||
}
|
||||
|
||||
func prepare_step(stmt. stmt, sql+ char) bool {
|
||||
if !this->prepare(stmt, sql);
|
||||
return false;
|
||||
return stmt->step();
|
||||
}
|
||||
|
||||
func preparef_step(stmt. stmt, sql+ char, ...) bool {
|
||||
if (sql = sqlite3_vmprintf(sql, va_start(this))) == null;
|
||||
return false;
|
||||
defer sqlite3_free(sql);
|
||||
if !this->prepare(stmt, sql);
|
||||
return false;
|
||||
return stmt->step();
|
||||
}
|
||||
|
||||
inline last_insert_rowid() int64 {
|
||||
return sqlite3_last_insert_rowid(this.db);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
static inline free(ptr void) {
|
||||
sqlite3_free(ptr);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class database+, stmt {
|
||||
|
||||
private import lib::sqlite3;
|
||||
|
||||
struct stmt {
|
||||
obj void;
|
||||
step_error bool;
|
||||
}
|
||||
|
||||
func constructor() {
|
||||
this.obj = null;
|
||||
this.step_error = false;
|
||||
}
|
||||
|
||||
func destructor() {
|
||||
this->finalize();
|
||||
}
|
||||
|
||||
inline bind_blob(index int, blob void, blob_size int, callback void) bool {
|
||||
return sqlite3_bind_blob(this.obj, index, blob, blob_size, callback) == SQLITE_OK;
|
||||
}
|
||||
|
||||
inline bind_double(index int, data double) bool {
|
||||
return sqlite3_bind_double(this.obj, index, data) == SQLITE_OK;
|
||||
}
|
||||
|
||||
inline bind_int(index int, data int) bool {
|
||||
return sqlite3_bind_int(this.obj, index, data) == SQLITE_OK;
|
||||
}
|
||||
|
||||
inline bind_null(index int) bool {
|
||||
return sqlite3_bind_null(this.obj, index) == SQLITE_OK;
|
||||
}
|
||||
|
||||
inline bind_text(index int, text+ char, text_len int, callback void) bool {
|
||||
return sqlite3_bind_text(this.obj, index, text, text_len, callback) == SQLITE_OK;
|
||||
}
|
||||
|
||||
inline bind_text16(index int, text void, text_len int, callback void) bool {
|
||||
return sqlite3_bind_text16(this.obj, index, text, text_len, callback) == SQLITE_OK;
|
||||
}
|
||||
|
||||
inline bind_text64(index int, text+ char, text_len int64, callback void, encoding char) bool {
|
||||
return sqlite3_bind_text64(this.obj, index, text, text_len, callback, encoding) == SQLITE_OK;
|
||||
}
|
||||
|
||||
inline bind_value(index int, value void) bool {
|
||||
return sqlite3_bind_value(this.obj, index, value) == SQLITE_OK;
|
||||
}
|
||||
|
||||
inline bind_zeroblob(index int, size int) bool {
|
||||
return sqlite3_bind_zeroblob(this.obj, index, size) == SQLITE_OK;
|
||||
}
|
||||
|
||||
inline bind_param_count() int {
|
||||
return sqlite3_bind_parameter_count(this.obj);
|
||||
}
|
||||
|
||||
inline bind_param_name(index int) +char {
|
||||
return sqlite3_bind_parameter_name(this.obj, index);
|
||||
}
|
||||
|
||||
inline bind_param_index(name+ char) int {
|
||||
return sqlite3_bind_parameter_index(this.obj, name);
|
||||
}
|
||||
|
||||
inline clear_bind() bool {
|
||||
return sqlite3_clear_bindings(this.obj) == SQLITE_OK;
|
||||
}
|
||||
|
||||
inline data_count() int {
|
||||
return sqlite3_data_count(this.obj);
|
||||
}
|
||||
|
||||
inline column_count() int {
|
||||
return sqlite3_column_count(this.obj);
|
||||
}
|
||||
|
||||
inline column_name(index int) +char {
|
||||
return sqlite3_column_name(this.obj, index);
|
||||
}
|
||||
|
||||
inline column_name16(index int) void {
|
||||
return sqlite3_column_name16(this.obj, index);
|
||||
}
|
||||
|
||||
func step() bool {
|
||||
var result int = sqlite3_step(this.obj);
|
||||
if result ~= SQLITE_ROW {
|
||||
/*
|
||||
SQLITE_BUSY
|
||||
SQLITE_ERROR
|
||||
SQLITE_MISUSE
|
||||
*/
|
||||
this.step_error = result ~= SQLITE_DONE;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
inline step_error?() bool {
|
||||
return this.step_error;
|
||||
}
|
||||
|
||||
inline reset() bool {
|
||||
return sqlite3_reset(this.obj) == SQLITE_OK;
|
||||
}
|
||||
|
||||
inline column_blob(col int) void {
|
||||
return sqlite3_column_blob(this.obj, col);
|
||||
}
|
||||
|
||||
inline column_double(col int) double {
|
||||
return sqlite3_column_double(this.obj, col);
|
||||
}
|
||||
|
||||
inline column_int(col int) int {
|
||||
return sqlite3_column_int(this.obj, col);
|
||||
}
|
||||
|
||||
inline column_text(col int) +char {
|
||||
return sqlite3_column_text(this.obj, col);
|
||||
}
|
||||
|
||||
inline column_text16(col int) void {
|
||||
return sqlite3_column_text16(this.obj, col);
|
||||
}
|
||||
|
||||
inline column_value(col int) void {
|
||||
return sqlite3_column_value(this.obj, col);
|
||||
}
|
||||
|
||||
inline column_bytes(col int) int {
|
||||
return sqlite3_column_bytes(this.obj, col);
|
||||
}
|
||||
|
||||
inline column_bytes16(col int) int {
|
||||
return sqlite3_column_bytes16(this.obj, col);
|
||||
}
|
||||
|
||||
inline column_type(col int) int {
|
||||
return sqlite3_column_type(this.obj, col);
|
||||
}
|
||||
|
||||
func finalize() bool {
|
||||
if this.obj ~= null {
|
||||
if sqlite3_finalize(this.obj) ~= SQLITE_OK;
|
||||
return false;
|
||||
this.obj = null;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,117 +0,0 @@
|
||||
|
||||
func exec(file. char, ap void) bool {
|
||||
import rt::c;
|
||||
var pid pid_t = fork();
|
||||
if pid == -1 {
|
||||
return false;
|
||||
elseif pid == 0;
|
||||
execvp(file, ap);
|
||||
return false;
|
||||
else
|
||||
wait(null);
|
||||
/*
|
||||
for some reasons.
|
||||
*/
|
||||
sleep(1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
func exec2(cmd. char) bool {
|
||||
import rt::c;
|
||||
alias
|
||||
dmem = std::dmem,
|
||||
strings = std::strings;
|
||||
var args dmem;
|
||||
var strs strings;
|
||||
enum {
|
||||
mode_none,
|
||||
mode_word,
|
||||
mode_quote,
|
||||
mode_double_quote
|
||||
}
|
||||
var mode int = mode_none;
|
||||
var begin size_t;
|
||||
forvar index size_t = 0, count size_t = strlen(cmd); index < count; index++ {
|
||||
var c char = cmd[index];
|
||||
if c == ' ' or c == '\t' {
|
||||
if mode == mode_word {
|
||||
.args->alloc_t<char*>() =
|
||||
strs->add(cmd + begin, index - begin);
|
||||
mode = mode_none;
|
||||
}
|
||||
elseif c == '\'';
|
||||
if mode == mode_none {
|
||||
begin = index + 1;
|
||||
mode = mode_quote;
|
||||
elseif mode == mode_word;
|
||||
// fixme
|
||||
return false;
|
||||
elseif mode == mode_quote;
|
||||
.args->alloc_t<char*>() =
|
||||
strs->add(cmd + begin, index - begin);
|
||||
mode = mode_none;
|
||||
}
|
||||
elseif c == '\"';
|
||||
if mode == mode_none {
|
||||
begin = index + 1;
|
||||
mode = mode_double_quote;
|
||||
elseif mode == mode_word;
|
||||
// fixme
|
||||
return false;
|
||||
elseif mode == mode_double_quote;
|
||||
.args->alloc_t<char*>() =
|
||||
strs->add(cmd + begin, index - begin);
|
||||
mode = mode_none;
|
||||
}
|
||||
else
|
||||
if mode == mode_none {
|
||||
begin = index;
|
||||
mode = mode_word;
|
||||
}
|
||||
}
|
||||
}
|
||||
if mode == mode_word {
|
||||
.args->alloc_t<char*>() =
|
||||
strs->add(cmd + begin);
|
||||
}
|
||||
if strs->empty() {
|
||||
return false;
|
||||
}
|
||||
.args->alloc_t<char*>() = null;
|
||||
return exec(strs->first_item(), args.ptr);
|
||||
}
|
||||
|
||||
/*
|
||||
fixme
|
||||
*/
|
||||
func exec3(window. game::window, text. char, cmd. char) bool {
|
||||
import lib::sdl2, game;
|
||||
define {
|
||||
PADDING = 10;
|
||||
}
|
||||
var render void = window->get_render();
|
||||
var font texture;
|
||||
font->init(global::uni_font->create_tex(render, text, 0xff000000));
|
||||
var width int = font->get_width();
|
||||
var height int = font->get_height();
|
||||
var rect SDL_Rect = 0;
|
||||
window->get_size(&rect.w, &rect.h);
|
||||
var sub_rect SDL_Rect;
|
||||
sub_rect.x = (rect.w - width) / 2 - PADDING;
|
||||
sub_rect.y = (rect.h - height) / 2 - PADDING;
|
||||
sub_rect.w = width + (PADDING * 2);
|
||||
sub_rect.h = height + (PADDING * 2);
|
||||
var screen texture;
|
||||
screen->init(window->screen_capture2());
|
||||
screen->draw(render, 0, 0);
|
||||
SDL_SetRenderDrawColor(render, 0xff, 0xff, 0xff, 0xff);
|
||||
SDL_RenderFillRect(render, &sub_rect);
|
||||
SDL_SetRenderDrawColor(render, 127, 127, 127, 0xff);
|
||||
SDL_RenderDrawRect(render, &sub_rect);
|
||||
font->draw(render,
|
||||
sub_rect.x + PADDING,
|
||||
sub_rect.y + PADDING);
|
||||
window->present();
|
||||
return exec2(cmd);
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
|
||||
func append_log(format. char, ...) {
|
||||
import rt::c;
|
||||
define {
|
||||
filename = "bean.log";
|
||||
}
|
||||
var stream void = fopen(filename, "a");
|
||||
if stream ~= null {
|
||||
vfprintf(stream, format, va_start(format));
|
||||
fclose(stream);
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
|
||||
/*
|
||||
slow
|
||||
*/
|
||||
func find_pid_by_cmdline(cmdline. char) int {
|
||||
import rt::c;
|
||||
alias string = std::string,
|
||||
strings = std::strings;
|
||||
var dir void = opendir("/proc");
|
||||
defer closedir(dir);
|
||||
using ent. struct_dirent {
|
||||
while (ent = readdir(dir)) ~= null {
|
||||
if ent.d_type == DT_DIR {
|
||||
if ent.d_name[0] == '.' and !ent.d_name[1] or
|
||||
ent.d_name[1] == '.' and !ent.d_name[2] {
|
||||
continue;
|
||||
}
|
||||
if isnumeric(&ent.d_name) {
|
||||
lambda pread(cmd. char, lines. strings) bool [
|
||||
var stream void = popen(cmd, "r");
|
||||
if stream == null;
|
||||
return false;
|
||||
defer fclose(stream);
|
||||
var line(0x200) char;
|
||||
while fgets(&line, 0x200, stream) ~= null;
|
||||
lines->add(&line);
|
||||
return true;
|
||||
];
|
||||
static cmd string;
|
||||
static lines strings;
|
||||
lines->clear();
|
||||
if pread(cmd->format("sudo cat /proc/%s/cmdline", &ent.d_name), &lines) {
|
||||
if !lines->empty() {
|
||||
if !strcmp(lines->first_item(), cmdline);
|
||||
return atoi(&ent.d_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@@ -1,411 +0,0 @@
|
||||
|
||||
class wifi+ {
|
||||
|
||||
private import rt::c, lib::dbus;
|
||||
|
||||
struct wifi {
|
||||
conn void;
|
||||
err DBusError;
|
||||
wicd wicd;
|
||||
wicd_wl wicd_wl;
|
||||
}
|
||||
|
||||
func constructor() {
|
||||
this.conn = null;
|
||||
dbus_error_init(&this.err);
|
||||
}
|
||||
|
||||
func destructor() {
|
||||
dbus_error_free(&this.err);
|
||||
}
|
||||
|
||||
func init() bool {
|
||||
this.conn = dbus_bus_get(DBUS_BUS_SYSTEM, &this.err);
|
||||
if dbus_error_is_set(&this.err);
|
||||
return false;
|
||||
this.wicd->init(this.conn);
|
||||
this.wicd_wl->init(this.conn);
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
func get_signal_strength() int {
|
||||
var iwconfig. char = null;
|
||||
if this.wicd->needs_external_calls() {
|
||||
if (iwconfig = this.wicd_wl->get_iwconfig()) == null;
|
||||
return -1;
|
||||
iwconfig = strdup(iwconfig);
|
||||
}
|
||||
if this.wicd->get_signal_disply_type() == 0 {
|
||||
func = this.wicd_wl->get_cur_signal_strength(iwconfig);
|
||||
else
|
||||
func = this.wicd_wl->get_cur_dbm_strength(iwconfig);
|
||||
}
|
||||
if iwconfig ~= null;
|
||||
free(iwconfig);
|
||||
}
|
||||
|
||||
func is_connecting() bool {
|
||||
return this.wicd_wl->check_if_wireless_connecting();
|
||||
}
|
||||
|
||||
func is_connected(signal_strength. int = null) bool {
|
||||
if this.wicd_wl->check_if_wireless_connecting();
|
||||
return false;
|
||||
var x int = this->get_signal_strength();
|
||||
if x == -1;
|
||||
return false;
|
||||
if signal_strength ~= null;
|
||||
.signal_strength = x;
|
||||
return true;
|
||||
}
|
||||
|
||||
func scan(sync bool = false) {
|
||||
this.wicd_wl->scan(sync);
|
||||
}
|
||||
|
||||
func connect(id int) {
|
||||
this.wicd_wl->connect(id);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
inline get_sys_bus() void {
|
||||
return this.conn;
|
||||
}
|
||||
|
||||
inline get_bus_err() .DBusError {
|
||||
return &this.err;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class wifi+, signal_thread {
|
||||
|
||||
private import rt::c, lib::dbus;
|
||||
|
||||
private alias
|
||||
string = std::string,
|
||||
vector = std::vector;
|
||||
|
||||
struct hook {
|
||||
iface. char;
|
||||
sig_name. char;
|
||||
callback void;
|
||||
arg void;
|
||||
}
|
||||
|
||||
struct signal_thread {
|
||||
thread pthread_t;
|
||||
wifi. wifi;
|
||||
hooks vector<hook>;
|
||||
}
|
||||
|
||||
func constructor() {
|
||||
this.thread = null;
|
||||
this.wifi = null;
|
||||
constructor(this);
|
||||
}
|
||||
|
||||
func destructor() {
|
||||
this->stop();
|
||||
destructor(this);
|
||||
}
|
||||
|
||||
func init(wifi. wifi) {
|
||||
this.wifi = wifi;
|
||||
}
|
||||
|
||||
/*
|
||||
callback = lambda(arg void, iter void) [
|
||||
...
|
||||
];
|
||||
*/
|
||||
func hook_signal(iface. char, sig_name. char, callback void, arg void) bool {
|
||||
if this.thread ~= null;
|
||||
return false;
|
||||
var conn void = this.wifi->get_sys_bus();
|
||||
var err void = this.wifi->get_bus_err();
|
||||
using rule string;
|
||||
dbus_bus_add_match(conn,
|
||||
rule->format("type='signal',interface='%s'", iface), err);
|
||||
dbus_connection_flush(conn);
|
||||
if dbus_error_is_set(err);
|
||||
return false;
|
||||
var hook. hook = this.hooks->new();
|
||||
hook.iface = iface;
|
||||
hook.sig_name = sig_name;
|
||||
hook.callback = callback;
|
||||
hook.arg = arg;
|
||||
return true;
|
||||
}
|
||||
|
||||
func start() bool {
|
||||
if this.thread ~= null;
|
||||
return true;
|
||||
if pthread_create(&this.thread, null, lambda(this.signal_thread) void [
|
||||
var conn void = this.wifi->get_sys_bus();
|
||||
while this.thread ~= null {
|
||||
for ;; {
|
||||
dbus_connection_read_write(conn, 0);
|
||||
var msg void = dbus_connection_pop_message(conn);
|
||||
if msg == null;
|
||||
break;
|
||||
forvar index size_t = 0, count size_t = this.hooks->count(); index < count; index++ {
|
||||
var hook. hook = this.hooks->at(index);
|
||||
if dbus_message_is_signal(msg, hook.iface, hook.sig_name) {
|
||||
var iter void;
|
||||
if !dbus_message_iter_init(msg, &iter);
|
||||
iter = null;
|
||||
proto fn(arg void, iter void);
|
||||
fn[hook.callback](hook.arg, iter);
|
||||
break;
|
||||
}
|
||||
}
|
||||
dbus_message_unref(msg);
|
||||
}
|
||||
sleep(1);
|
||||
}
|
||||
], this));
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
func stop() {
|
||||
var thread pthread_t = this.thread;
|
||||
if thread ~= null {
|
||||
this.thread = null;
|
||||
pthread_join(thread, null);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class wifi+, dbus {
|
||||
|
||||
private import lib::dbus;
|
||||
|
||||
struct dbus {
|
||||
conn void;
|
||||
bus_name. char;
|
||||
path. char;
|
||||
iface. char;
|
||||
}
|
||||
|
||||
func init(conn void, bus_name. char, path. char, iface. char) {
|
||||
this.conn = conn;
|
||||
this.bus_name = bus_name;
|
||||
this.path = path;
|
||||
this.iface = iface;
|
||||
}
|
||||
|
||||
func call(method. char, format. char = null, ...) void {
|
||||
var msg void = dbus_message_new_method_call(this.bus_name, this.path, this.iface, method);
|
||||
if msg == null;
|
||||
return null;
|
||||
defer dbus_message_unref(msg);
|
||||
if format ~= null {
|
||||
var args DBusMessageIter;
|
||||
dbus_message_iter_init_append(msg, &args);
|
||||
forvar ap void = va_start(this) ;; {
|
||||
var type char = .format++;
|
||||
if !type;
|
||||
break;
|
||||
if !dbus_message_iter_append_basic(&args, type, ap);
|
||||
return null;
|
||||
va_next<word>(ap);
|
||||
}
|
||||
}
|
||||
if !dbus_connection_send_with_reply(this.conn, msg, &func, -1);
|
||||
return null;
|
||||
if func ~= null;
|
||||
dbus_connection_flush(this.conn);
|
||||
}
|
||||
|
||||
static func get(pending void, format. char = null, ...) bool {
|
||||
if pending == null;
|
||||
return false;
|
||||
dbus_pending_call_block(pending);
|
||||
var msg void = dbus_pending_call_steal_reply(pending);
|
||||
dbus_pending_call_unref(pending);
|
||||
if msg == null;
|
||||
return false;
|
||||
defer dbus_message_unref(msg);
|
||||
if format ~= null {
|
||||
var args DBusMessageIter;
|
||||
if dbus_message_iter_init(msg, &args) {
|
||||
forvar ap. void = va_start(pending) ;; {
|
||||
var type char = .format++;
|
||||
if !type;
|
||||
break;
|
||||
if dbus_message_iter_get_arg_type(&args) ~= type;
|
||||
return false;
|
||||
dbus_message_iter_get_basic(&args, .ap);
|
||||
if !dbus_message_iter_next(&args);
|
||||
break;
|
||||
va_next<void>(ap);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class wifi+, wicd {
|
||||
|
||||
private import lib::dbus;
|
||||
|
||||
struct wicd {
|
||||
bus dbus;
|
||||
}
|
||||
|
||||
func init(conn void) {
|
||||
this.bus->init(conn,
|
||||
"org.wicd.daemon", "/org/wicd/daemon",
|
||||
"org.wicd.daemon");
|
||||
}
|
||||
|
||||
func format_signal_for_printing(signal int) .char {
|
||||
func = null;
|
||||
this.bus->get(
|
||||
this.bus->call("FormatSignalForPrinting", "i", signal), "s", &func);
|
||||
}
|
||||
|
||||
func get_signal_disply_type() int {
|
||||
func = -1;
|
||||
this.bus->get(
|
||||
this.bus->call("GetSignalDisplayType"), "i", &func);
|
||||
}
|
||||
|
||||
func needs_external_calls() dbus_bool_t {
|
||||
func = 0;
|
||||
this.bus->get(
|
||||
this.bus->call("NeedsExternalCalls"), "b", &func);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class wifi+, wicd_wl {
|
||||
|
||||
private import lib::dbus;
|
||||
|
||||
struct wicd_wl {
|
||||
bus dbus;
|
||||
}
|
||||
|
||||
func init(conn void) {
|
||||
this.bus->init(conn,
|
||||
"org.wicd.daemon", "/org/wicd/daemon/wireless",
|
||||
"org.wicd.daemon.wireless");
|
||||
}
|
||||
|
||||
func check_if_wireless_connecting() dbus_bool_t {
|
||||
func = 0;
|
||||
this.bus->get(
|
||||
this.bus->call("CheckIfWirelessConnecting"), "b", &func);
|
||||
}
|
||||
|
||||
func check_wireless_connecting_msg() .char {
|
||||
func = null;
|
||||
this.bus->get(
|
||||
this.bus->call("CheckWirelessConnectingMessage"), "s", &func);
|
||||
}
|
||||
|
||||
// result?
|
||||
func connect(id int) {
|
||||
this.bus->get(
|
||||
this.bus->call("ConnectWireless", "i", id));
|
||||
}
|
||||
|
||||
func get_cur_dbm_strength(iwconfig. char) int {
|
||||
func = -1;
|
||||
var pending void;
|
||||
if iwconfig == null {
|
||||
pending = this.bus->call("GetCurrentDBMStrength");
|
||||
else
|
||||
pending = this.bus->call("GetCurrentDBMStrength", "s", iwconfig);
|
||||
}
|
||||
this.bus->get(pending, "i", &func);
|
||||
}
|
||||
|
||||
func get_cur_signal_strength(iwconfig. char) int {
|
||||
func = -1;
|
||||
var pending void;
|
||||
if iwconfig == null {
|
||||
pending = this.bus->call("GetCurrentSignalStrength");
|
||||
else
|
||||
pending = this.bus->call("GetCurrentSignalStrength", "s", iwconfig);
|
||||
}
|
||||
this.bus->get(pending, "i", &func);
|
||||
}
|
||||
|
||||
func get_cur_network(iwconfig. char) .char {
|
||||
func = null;
|
||||
var pending void;
|
||||
if iwconfig == null {
|
||||
pending = this.bus->call("GetCurrentNetwork");
|
||||
else
|
||||
pending = this.bus->call("GetCurrentNetwork", "s", iwconfig);
|
||||
}
|
||||
this.bus->get(pending, "s", &func);
|
||||
}
|
||||
|
||||
func get_cur_network_id(iwconfig. char) int {
|
||||
func = -1;
|
||||
var pending void;
|
||||
if iwconfig == null {
|
||||
pending = this.bus->call("GetCurrentNetworkID");
|
||||
else
|
||||
pending = this.bus->call("GetCurrentNetworkID", "s", iwconfig);
|
||||
}
|
||||
this.bus->get(pending, "i", &func);
|
||||
}
|
||||
|
||||
func get_iwconfig() .char {
|
||||
func = null;
|
||||
this.bus->get(
|
||||
this.bus->call("GetIwconfig"), "s", &func);
|
||||
}
|
||||
|
||||
func get_num_of_networks() int {
|
||||
func = -1;
|
||||
this.bus->get(
|
||||
this.bus->call("GetNumberOfNetworks"), "i", &func);
|
||||
}
|
||||
|
||||
func get_wireless_ip(s. char) .char {
|
||||
func = null;
|
||||
var pending void;
|
||||
if s == null {
|
||||
pending = this.bus->call("GetWirelessIP");
|
||||
else
|
||||
pending = this.bus->call("GetWirelessIP", "s", s);
|
||||
}
|
||||
this.bus->get(pending, "s", &func);
|
||||
}
|
||||
|
||||
func get_wireless_prop(id int, prop_name. char) .char {
|
||||
func = null;
|
||||
this.bus->get(
|
||||
this.bus->call("GetWirelessProperty", "is", id, prop_name), "s", &func);
|
||||
}
|
||||
|
||||
// result?
|
||||
func scan(sync dbus_bool_t) {
|
||||
this.bus->get(
|
||||
this.bus->call("Scan", "b", sync));
|
||||
}
|
||||
|
||||
func set_wireless_prop_str(id int, prop_name. char, s. char) bool {
|
||||
return this.bus->get(
|
||||
this.bus->call("SetWirelessProperty", "iss", id, prop_name, s));
|
||||
}
|
||||
|
||||
func set_wireless_prop_int(id int, prop_name. char, i int) bool {
|
||||
return this.bus->get(
|
||||
this.bus->call("SetWirelessProperty", "isi", id, prop_name, i));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,171 +0,0 @@
|
||||
|
||||
module std+, base64 {
|
||||
|
||||
private var pr2six(256) byte = {
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 62, 64, 64, 64, 63,
|
||||
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 64, 64, 64, 64, 64,
|
||||
64, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
|
||||
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 64, 64, 64, 64, 64,
|
||||
64, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
|
||||
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
|
||||
};
|
||||
|
||||
func base64decode_len(bufcoded. char) int {
|
||||
var bufin. byte = bufcoded;
|
||||
while pr2six[.bufin] <= 63;
|
||||
bufin++;
|
||||
var nprbytes int = bufin - bufcoded;
|
||||
var nbytesdecoded int = ((nprbytes + 3) / 4) * 3;
|
||||
return nbytesdecoded + 1;
|
||||
}
|
||||
|
||||
func base64decode(bufplain. char, bufcoded. char) int {
|
||||
var bufin. byte = bufcoded;
|
||||
while pr2six[.bufin] <= 63;
|
||||
bufin++;
|
||||
var nprbytes int = bufin - bufcoded;
|
||||
var nbytesdecoded int = ((nprbytes + 3) / 4) * 3;
|
||||
var bufout. byte = bufplain;
|
||||
bufin = bufcoded;
|
||||
while nprbytes > 4 {
|
||||
.bufout++ = pr2six[.bufin] << 2 | pr2six[bufin[1]] >> 4;
|
||||
.bufout++ = pr2six[bufin[1]] << 4 | pr2six[bufin[2]] >> 2;
|
||||
.bufout++ = pr2six[bufin[2]] << 6 | pr2six[bufin[3]];
|
||||
bufin += 4;
|
||||
nprbytes -= 4;
|
||||
}
|
||||
if nprbytes > 1;
|
||||
.bufout++ = pr2six[.bufin] << 2 | pr2six[bufin[1]] >> 4;
|
||||
if nprbytes > 2;
|
||||
.bufout++ = pr2six[bufin[1]] << 4 | pr2six[bufin[2]] >> 2;
|
||||
if nprbytes > 3;
|
||||
.bufout++ = pr2six[bufin[2]] << 6 | pr2six[bufin[3]];
|
||||
.bufout = '\0';
|
||||
nbytesdecoded -= (4 - nprbytes) & 3;
|
||||
return nbytesdecoded;
|
||||
}
|
||||
|
||||
func base64encode_len(len int) int {
|
||||
return ((len + 2) / 3 * 4) + 1;
|
||||
}
|
||||
|
||||
func base64encode(encoded. char, str. char, len int) int {
|
||||
static basis64() char = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
var i int;
|
||||
var p. char = encoded;
|
||||
for i = 0; i < len - 2; i += 3 {
|
||||
.p++ = basis64[(str[i] >> 2) & 0x3f];
|
||||
.p++ = basis64[((str[i] & 0x3) << 4) |
|
||||
(int(str[i + 1] & 0xf0) >> 4)];
|
||||
.p++ = basis64[((str[i + 1] & 0xf) << 2) |
|
||||
(int(str[i + 2] & 0xc0) >> 6)];
|
||||
.p++ = basis64[str[i + 2] & 0x3f];
|
||||
}
|
||||
if i < len {
|
||||
.p++ = basis64[(str[i] >> 2) & 0x3f];
|
||||
if i == (len - 1) {
|
||||
.p++ = basis64[((str[i] & 0x3) << 4)];
|
||||
.p++ = '=';
|
||||
else
|
||||
.p++ = basis64[((str[i] & 0x3) << 4) |
|
||||
(int(str[i + 1] & 0xf0) >> 4)];
|
||||
.p++ = basis64[((str[i + 1] & 0xf) << 2)];
|
||||
}
|
||||
.p++ = '=';
|
||||
}
|
||||
.p++ = '\0';
|
||||
return p - encoded;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
|
||||
*
|
||||
* @APPLE_LICENSE_HEADER_START@
|
||||
*
|
||||
* Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original Code
|
||||
* as defined in and that are subject to the Apple Public Source License
|
||||
* Version 2.0 (the 'License'). You may not use this file except in
|
||||
* compliance with the License. Please obtain a copy of the License at
|
||||
* http://www.opensource.apple.com/apsl/ and read it before using this
|
||||
* file.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
|
||||
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
|
||||
* Please see the License for the specific language governing rights and
|
||||
* limitations under the License.
|
||||
*
|
||||
* @APPLE_LICENSE_HEADER_END@
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1995-1999 The Apache Group. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the Apache Group
|
||||
* for use in the Apache HTTP server project (http://www.apache.org/)."
|
||||
*
|
||||
* 4. The names "Apache Server" and "Apache Group" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* apache@apache.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "Apache"
|
||||
* nor may "Apache" appear in their names without prior written
|
||||
* permission of the Apache Group.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the Apache Group
|
||||
* for use in the Apache HTTP server project (http://www.apache.org/)."
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE GROUP OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This software consists of voluntary contributions made by many
|
||||
* individuals on behalf of the Apache Group and was originally based
|
||||
* on public domain software written at the National Center for
|
||||
* Supercomputing Applications, University of Illinois, Urbana-Champaign.
|
||||
* For more information on the Apache Group and the Apache HTTP server
|
||||
* project, please see <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
@@ -1,393 +0,0 @@
|
||||
|
||||
class std+, blowfish {
|
||||
|
||||
private define {
|
||||
n = 16;
|
||||
}
|
||||
|
||||
struct blowfish {
|
||||
p(n + 2) uint32;
|
||||
s(4, 256) uint32;
|
||||
}
|
||||
|
||||
func init(key. uint8, key_len int32) {
|
||||
static p(n + 2) uint32 = {
|
||||
0x243F6A88, 0x85A308D3, 0x13198A2E, 0x03707344,
|
||||
0xA4093822, 0x299F31D0, 0x082EFA98, 0xEC4E6C89,
|
||||
0x452821E6, 0x38D01377, 0xBE5466CF, 0x34E90C6C,
|
||||
0xC0AC29B7, 0xC97C50DD, 0x3F84D5B5, 0xB5470917,
|
||||
0x9216D5D9, 0x8979FB1B
|
||||
};
|
||||
static s(4, 256) uint32 = {
|
||||
0xD1310BA6, 0x98DFB5AC, 0x2FFD72DB, 0xD01ADFB7,
|
||||
0xB8E1AFED, 0x6A267E96, 0xBA7C9045, 0xF12C7F99,
|
||||
0x24A19947, 0xB3916CF7, 0x0801F2E2, 0x858EFC16,
|
||||
0x636920D8, 0x71574E69, 0xA458FEA3, 0xF4933D7E,
|
||||
0x0D95748F, 0x728EB658, 0x718BCD58, 0x82154AEE,
|
||||
0x7B54A41D, 0xC25A59B5, 0x9C30D539, 0x2AF26013,
|
||||
0xC5D1B023, 0x286085F0, 0xCA417918, 0xB8DB38EF,
|
||||
0x8E79DCB0, 0x603A180E, 0x6C9E0E8B, 0xB01E8A3E,
|
||||
0xD71577C1, 0xBD314B27, 0x78AF2FDA, 0x55605C60,
|
||||
0xE65525F3, 0xAA55AB94, 0x57489862, 0x63E81440,
|
||||
0x55CA396A, 0x2AAB10B6, 0xB4CC5C34, 0x1141E8CE,
|
||||
0xA15486AF, 0x7C72E993, 0xB3EE1411, 0x636FBC2A,
|
||||
0x2BA9C55D, 0x741831F6, 0xCE5C3E16, 0x9B87931E,
|
||||
0xAFD6BA33, 0x6C24CF5C, 0x7A325381, 0x28958677,
|
||||
0x3B8F4898, 0x6B4BB9AF, 0xC4BFE81B, 0x66282193,
|
||||
0x61D809CC, 0xFB21A991, 0x487CAC60, 0x5DEC8032,
|
||||
0xEF845D5D, 0xE98575B1, 0xDC262302, 0xEB651B88,
|
||||
0x23893E81, 0xD396ACC5, 0x0F6D6FF3, 0x83F44239,
|
||||
0x2E0B4482, 0xA4842004, 0x69C8F04A, 0x9E1F9B5E,
|
||||
0x21C66842, 0xF6E96C9A, 0x670C9C61, 0xABD388F0,
|
||||
0x6A51A0D2, 0xD8542F68, 0x960FA728, 0xAB5133A3,
|
||||
0x6EEF0B6C, 0x137A3BE4, 0xBA3BF050, 0x7EFB2A98,
|
||||
0xA1F1651D, 0x39AF0176, 0x66CA593E, 0x82430E88,
|
||||
0x8CEE8619, 0x456F9FB4, 0x7D84A5C3, 0x3B8B5EBE,
|
||||
0xE06F75D8, 0x85C12073, 0x401A449F, 0x56C16AA6,
|
||||
0x4ED3AA62, 0x363F7706, 0x1BFEDF72, 0x429B023D,
|
||||
0x37D0D724, 0xD00A1248, 0xDB0FEAD3, 0x49F1C09B,
|
||||
0x075372C9, 0x80991B7B, 0x25D479D8, 0xF6E8DEF7,
|
||||
0xE3FE501A, 0xB6794C3B, 0x976CE0BD, 0x04C006BA,
|
||||
0xC1A94FB6, 0x409F60C4, 0x5E5C9EC2, 0x196A2463,
|
||||
0x68FB6FAF, 0x3E6C53B5, 0x1339B2EB, 0x3B52EC6F,
|
||||
0x6DFC511F, 0x9B30952C, 0xCC814544, 0xAF5EBD09,
|
||||
0xBEE3D004, 0xDE334AFD, 0x660F2807, 0x192E4BB3,
|
||||
0xC0CBA857, 0x45C8740F, 0xD20B5F39, 0xB9D3FBDB,
|
||||
0x5579C0BD, 0x1A60320A, 0xD6A100C6, 0x402C7279,
|
||||
0x679F25FE, 0xFB1FA3CC, 0x8EA5E9F8, 0xDB3222F8,
|
||||
0x3C7516DF, 0xFD616B15, 0x2F501EC8, 0xAD0552AB,
|
||||
0x323DB5FA, 0xFD238760, 0x53317B48, 0x3E00DF82,
|
||||
0x9E5C57BB, 0xCA6F8CA0, 0x1A87562E, 0xDF1769DB,
|
||||
0xD542A8F6, 0x287EFFC3, 0xAC6732C6, 0x8C4F5573,
|
||||
0x695B27B0, 0xBBCA58C8, 0xE1FFA35D, 0xB8F011A0,
|
||||
0x10FA3D98, 0xFD2183B8, 0x4AFCB56C, 0x2DD1D35B,
|
||||
0x9A53E479, 0xB6F84565, 0xD28E49BC, 0x4BFB9790,
|
||||
0xE1DDF2DA, 0xA4CB7E33, 0x62FB1341, 0xCEE4C6E8,
|
||||
0xEF20CADA, 0x36774C01, 0xD07E9EFE, 0x2BF11FB4,
|
||||
0x95DBDA4D, 0xAE909198, 0xEAAD8E71, 0x6B93D5A0,
|
||||
0xD08ED1D0, 0xAFC725E0, 0x8E3C5B2F, 0x8E7594B7,
|
||||
0x8FF6E2FB, 0xF2122B64, 0x8888B812, 0x900DF01C,
|
||||
0x4FAD5EA0, 0x688FC31C, 0xD1CFF191, 0xB3A8C1AD,
|
||||
0x2F2F2218, 0xBE0E1777, 0xEA752DFE, 0x8B021FA1,
|
||||
0xE5A0CC0F, 0xB56F74E8, 0x18ACF3D6, 0xCE89E299,
|
||||
0xB4A84FE0, 0xFD13E0B7, 0x7CC43B81, 0xD2ADA8D9,
|
||||
0x165FA266, 0x80957705, 0x93CC7314, 0x211A1477,
|
||||
0xE6AD2065, 0x77B5FA86, 0xC75442F5, 0xFB9D35CF,
|
||||
0xEBCDAF0C, 0x7B3E89A0, 0xD6411BD3, 0xAE1E7E49,
|
||||
0x00250E2D, 0x2071B35E, 0x226800BB, 0x57B8E0AF,
|
||||
0x2464369B, 0xF009B91E, 0x5563911D, 0x59DFA6AA,
|
||||
0x78C14389, 0xD95A537F, 0x207D5BA2, 0x02E5B9C5,
|
||||
0x83260376, 0x6295CFA9, 0x11C81968, 0x4E734A41,
|
||||
0xB3472DCA, 0x7B14A94A, 0x1B510052, 0x9A532915,
|
||||
0xD60F573F, 0xBC9BC6E4, 0x2B60A476, 0x81E67400,
|
||||
0x08BA6FB5, 0x571BE91F, 0xF296EC6B, 0x2A0DD915,
|
||||
0xB6636521, 0xE7B9F9B6, 0xFF34052E, 0xC5855664,
|
||||
0x53B02D5D, 0xA99F8FA1, 0x08BA4799, 0x6E85076A,
|
||||
|
||||
0x4B7A70E9, 0xB5B32944, 0xDB75092E, 0xC4192623,
|
||||
0xAD6EA6B0, 0x49A7DF7D, 0x9CEE60B8, 0x8FEDB266,
|
||||
0xECAA8C71, 0x699A17FF, 0x5664526C, 0xC2B19EE1,
|
||||
0x193602A5, 0x75094C29, 0xA0591340, 0xE4183A3E,
|
||||
0x3F54989A, 0x5B429D65, 0x6B8FE4D6, 0x99F73FD6,
|
||||
0xA1D29C07, 0xEFE830F5, 0x4D2D38E6, 0xF0255DC1,
|
||||
0x4CDD2086, 0x8470EB26, 0x6382E9C6, 0x021ECC5E,
|
||||
0x09686B3F, 0x3EBAEFC9, 0x3C971814, 0x6B6A70A1,
|
||||
0x687F3584, 0x52A0E286, 0xB79C5305, 0xAA500737,
|
||||
0x3E07841C, 0x7FDEAE5C, 0x8E7D44EC, 0x5716F2B8,
|
||||
0xB03ADA37, 0xF0500C0D, 0xF01C1F04, 0x0200B3FF,
|
||||
0xAE0CF51A, 0x3CB574B2, 0x25837A58, 0xDC0921BD,
|
||||
0xD19113F9, 0x7CA92FF6, 0x94324773, 0x22F54701,
|
||||
0x3AE5E581, 0x37C2DADC, 0xC8B57634, 0x9AF3DDA7,
|
||||
0xA9446146, 0x0FD0030E, 0xECC8C73E, 0xA4751E41,
|
||||
0xE238CD99, 0x3BEA0E2F, 0x3280BBA1, 0x183EB331,
|
||||
0x4E548B38, 0x4F6DB908, 0x6F420D03, 0xF60A04BF,
|
||||
0x2CB81290, 0x24977C79, 0x5679B072, 0xBCAF89AF,
|
||||
0xDE9A771F, 0xD9930810, 0xB38BAE12, 0xDCCF3F2E,
|
||||
0x5512721F, 0x2E6B7124, 0x501ADDE6, 0x9F84CD87,
|
||||
0x7A584718, 0x7408DA17, 0xBC9F9ABC, 0xE94B7D8C,
|
||||
0xEC7AEC3A, 0xDB851DFA, 0x63094366, 0xC464C3D2,
|
||||
0xEF1C1847, 0x3215D908, 0xDD433B37, 0x24C2BA16,
|
||||
0x12A14D43, 0x2A65C451, 0x50940002, 0x133AE4DD,
|
||||
0x71DFF89E, 0x10314E55, 0x81AC77D6, 0x5F11199B,
|
||||
0x043556F1, 0xD7A3C76B, 0x3C11183B, 0x5924A509,
|
||||
0xF28FE6ED, 0x97F1FBFA, 0x9EBABF2C, 0x1E153C6E,
|
||||
0x86E34570, 0xEAE96FB1, 0x860E5E0A, 0x5A3E2AB3,
|
||||
0x771FE71C, 0x4E3D06FA, 0x2965DCB9, 0x99E71D0F,
|
||||
0x803E89D6, 0x5266C825, 0x2E4CC978, 0x9C10B36A,
|
||||
0xC6150EBA, 0x94E2EA78, 0xA5FC3C53, 0x1E0A2DF4,
|
||||
0xF2F74EA7, 0x361D2B3D, 0x1939260F, 0x19C27960,
|
||||
0x5223A708, 0xF71312B6, 0xEBADFE6E, 0xEAC31F66,
|
||||
0xE3BC4595, 0xA67BC883, 0xB17F37D1, 0x018CFF28,
|
||||
0xC332DDEF, 0xBE6C5AA5, 0x65582185, 0x68AB9802,
|
||||
0xEECEA50F, 0xDB2F953B, 0x2AEF7DAD, 0x5B6E2F84,
|
||||
0x1521B628, 0x29076170, 0xECDD4775, 0x619F1510,
|
||||
0x13CCA830, 0xEB61BD96, 0x0334FE1E, 0xAA0363CF,
|
||||
0xB5735C90, 0x4C70A239, 0xD59E9E0B, 0xCBAADE14,
|
||||
0xEECC86BC, 0x60622CA7, 0x9CAB5CAB, 0xB2F3846E,
|
||||
0x648B1EAF, 0x19BDF0CA, 0xA02369B9, 0x655ABB50,
|
||||
0x40685A32, 0x3C2AB4B3, 0x319EE9D5, 0xC021B8F7,
|
||||
0x9B540B19, 0x875FA099, 0x95F7997E, 0x623D7DA8,
|
||||
0xF837889A, 0x97E32D77, 0x11ED935F, 0x16681281,
|
||||
0x0E358829, 0xC7E61FD6, 0x96DEDFA1, 0x7858BA99,
|
||||
0x57F584A5, 0x1B227263, 0x9B83C3FF, 0x1AC24696,
|
||||
0xCDB30AEB, 0x532E3054, 0x8FD948E4, 0x6DBC3128,
|
||||
0x58EBF2EF, 0x34C6FFEA, 0xFE28ED61, 0xEE7C3C73,
|
||||
0x5D4A14D9, 0xE864B7E3, 0x42105D14, 0x203E13E0,
|
||||
0x45EEE2B6, 0xA3AAABEA, 0xDB6C4F15, 0xFACB4FD0,
|
||||
0xC742F442, 0xEF6ABBB5, 0x654F3B1D, 0x41CD2105,
|
||||
0xD81E799E, 0x86854DC7, 0xE44B476A, 0x3D816250,
|
||||
0xCF62A1F2, 0x5B8D2646, 0xFC8883A0, 0xC1C7B6A3,
|
||||
0x7F1524C3, 0x69CB7492, 0x47848A0B, 0x5692B285,
|
||||
0x095BBF00, 0xAD19489D, 0x1462B174, 0x23820E00,
|
||||
0x58428D2A, 0x0C55F5EA, 0x1DADF43E, 0x233F7061,
|
||||
0x3372F092, 0x8D937E41, 0xD65FECF1, 0x6C223BDB,
|
||||
0x7CDE3759, 0xCBEE7460, 0x4085F2A7, 0xCE77326E,
|
||||
0xA6078084, 0x19F8509E, 0xE8EFD855, 0x61D99735,
|
||||
0xA969A7AA, 0xC50C06C2, 0x5A04ABFC, 0x800BCADC,
|
||||
0x9E447A2E, 0xC3453484, 0xFDD56705, 0x0E1E9EC9,
|
||||
0xDB73DBD3, 0x105588CD, 0x675FDA79, 0xE3674340,
|
||||
0xC5C43465, 0x713E38D8, 0x3D28F89E, 0xF16DFF20,
|
||||
0x153E21E7, 0x8FB03D4A, 0xE6E39F2B, 0xDB83ADF7,
|
||||
|
||||
0xE93D5A68, 0x948140F7, 0xF64C261C, 0x94692934,
|
||||
0x411520F7, 0x7602D4F7, 0xBCF46B2E, 0xD4A20068,
|
||||
0xD4082471, 0x3320F46A, 0x43B7D4B7, 0x500061AF,
|
||||
0x1E39F62E, 0x97244546, 0x14214F74, 0xBF8B8840,
|
||||
0x4D95FC1D, 0x96B591AF, 0x70F4DDD3, 0x66A02F45,
|
||||
0xBFBC09EC, 0x03BD9785, 0x7FAC6DD0, 0x31CB8504,
|
||||
0x96EB27B3, 0x55FD3941, 0xDA2547E6, 0xABCA0A9A,
|
||||
0x28507825, 0x530429F4, 0x0A2C86DA, 0xE9B66DFB,
|
||||
0x68DC1462, 0xD7486900, 0x680EC0A4, 0x27A18DEE,
|
||||
0x4F3FFEA2, 0xE887AD8C, 0xB58CE006, 0x7AF4D6B6,
|
||||
0xAACE1E7C, 0xD3375FEC, 0xCE78A399, 0x406B2A42,
|
||||
0x20FE9E35, 0xD9F385B9, 0xEE39D7AB, 0x3B124E8B,
|
||||
0x1DC9FAF7, 0x4B6D1856, 0x26A36631, 0xEAE397B2,
|
||||
0x3A6EFA74, 0xDD5B4332, 0x6841E7F7, 0xCA7820FB,
|
||||
0xFB0AF54E, 0xD8FEB397, 0x454056AC, 0xBA489527,
|
||||
0x55533A3A, 0x20838D87, 0xFE6BA9B7, 0xD096954B,
|
||||
0x55A867BC, 0xA1159A58, 0xCCA92963, 0x99E1DB33,
|
||||
0xA62A4A56, 0x3F3125F9, 0x5EF47E1C, 0x9029317C,
|
||||
0xFDF8E802, 0x04272F70, 0x80BB155C, 0x05282CE3,
|
||||
0x95C11548, 0xE4C66D22, 0x48C1133F, 0xC70F86DC,
|
||||
0x07F9C9EE, 0x41041F0F, 0x404779A4, 0x5D886E17,
|
||||
0x325F51EB, 0xD59BC0D1, 0xF2BCC18F, 0x41113564,
|
||||
0x257B7834, 0x602A9C60, 0xDFF8E8A3, 0x1F636C1B,
|
||||
0x0E12B4C2, 0x02E1329E, 0xAF664FD1, 0xCAD18115,
|
||||
0x6B2395E0, 0x333E92E1, 0x3B240B62, 0xEEBEB922,
|
||||
0x85B2A20E, 0xE6BA0D99, 0xDE720C8C, 0x2DA2F728,
|
||||
0xD0127845, 0x95B794FD, 0x647D0862, 0xE7CCF5F0,
|
||||
0x5449A36F, 0x877D48FA, 0xC39DFD27, 0xF33E8D1E,
|
||||
0x0A476341, 0x992EFF74, 0x3A6F6EAB, 0xF4F8FD37,
|
||||
0xA812DC60, 0xA1EBDDF8, 0x991BE14C, 0xDB6E6B0D,
|
||||
0xC67B5510, 0x6D672C37, 0x2765D43B, 0xDCD0E804,
|
||||
0xF1290DC7, 0xCC00FFA3, 0xB5390F92, 0x690FED0B,
|
||||
0x667B9FFB, 0xCEDB7D9C, 0xA091CF0B, 0xD9155EA3,
|
||||
0xBB132F88, 0x515BAD24, 0x7B9479BF, 0x763BD6EB,
|
||||
0x37392EB3, 0xCC115979, 0x8026E297, 0xF42E312D,
|
||||
0x6842ADA7, 0xC66A2B3B, 0x12754CCC, 0x782EF11C,
|
||||
0x6A124237, 0xB79251E7, 0x06A1BBE6, 0x4BFB6350,
|
||||
0x1A6B1018, 0x11CAEDFA, 0x3D25BDD8, 0xE2E1C3C9,
|
||||
0x44421659, 0x0A121386, 0xD90CEC6E, 0xD5ABEA2A,
|
||||
0x64AF674E, 0xDA86A85F, 0xBEBFE988, 0x64E4C3FE,
|
||||
0x9DBC8057, 0xF0F7C086, 0x60787BF8, 0x6003604D,
|
||||
0xD1FD8346, 0xF6381FB0, 0x7745AE04, 0xD736FCCC,
|
||||
0x83426B33, 0xF01EAB71, 0xB0804187, 0x3C005E5F,
|
||||
0x77A057BE, 0xBDE8AE24, 0x55464299, 0xBF582E61,
|
||||
0x4E58F48F, 0xF2DDFDA2, 0xF474EF38, 0x8789BDC2,
|
||||
0x5366F9C3, 0xC8B38E74, 0xB475F255, 0x46FCD9B9,
|
||||
0x7AEB2661, 0x8B1DDF84, 0x846A0E79, 0x915F95E2,
|
||||
0x466E598E, 0x20B45770, 0x8CD55591, 0xC902DE4C,
|
||||
0xB90BACE1, 0xBB8205D0, 0x11A86248, 0x7574A99E,
|
||||
0xB77F19B6, 0xE0A9DC09, 0x662D09A1, 0xC4324633,
|
||||
0xE85A1F02, 0x09F0BE8C, 0x4A99A025, 0x1D6EFE10,
|
||||
0x1AB93D1D, 0x0BA5A4DF, 0xA186F20F, 0x2868F169,
|
||||
0xDCB7DA83, 0x573906FE, 0xA1E2CE9B, 0x4FCD7F52,
|
||||
0x50115E01, 0xA70683FA, 0xA002B5C4, 0x0DE6D027,
|
||||
0x9AF88C27, 0x773F8641, 0xC3604C06, 0x61A806B5,
|
||||
0xF0177A28, 0xC0F586E0, 0x006058AA, 0x30DC7D62,
|
||||
0x11E69ED7, 0x2338EA63, 0x53C2DD94, 0xC2C21634,
|
||||
0xBBCBEE56, 0x90BCB6DE, 0xEBFC7DA1, 0xCE591D76,
|
||||
0x6F05E409, 0x4B7C0188, 0x39720A3D, 0x7C927C24,
|
||||
0x86E3725F, 0x724D9DB9, 0x1AC15BB4, 0xD39EB8FC,
|
||||
0xED545578, 0x08FCA5B5, 0xD83D7CD3, 0x4DAD0FC4,
|
||||
0x1E50EF5E, 0xB161E6F8, 0xA28514D9, 0x6C51133C,
|
||||
0x6FD5C7E7, 0x56E14EC4, 0x362ABFCE, 0xDDC6C837,
|
||||
0xD79A3234, 0x92638212, 0x670EFA8E, 0x406000E0,
|
||||
|
||||
0x3A39CE37, 0xD3FAF5CF, 0xABC27737, 0x5AC52D1B,
|
||||
0x5CB0679E, 0x4FA33742, 0xD3822740, 0x99BC9BBE,
|
||||
0xD5118E9D, 0xBF0F7315, 0xD62D1C7E, 0xC700C47B,
|
||||
0xB78C1B6B, 0x21A19045, 0xB26EB1BE, 0x6A366EB4,
|
||||
0x5748AB2F, 0xBC946E79, 0xC6A376D2, 0x6549C2C8,
|
||||
0x530FF8EE, 0x468DDE7D, 0xD5730A1D, 0x4CD04DC6,
|
||||
0x2939BBDB, 0xA9BA4650, 0xAC9526E8, 0xBE5EE304,
|
||||
0xA1FAD5F0, 0x6A2D519A, 0x63EF8CE2, 0x9A86EE22,
|
||||
0xC089C2B8, 0x43242EF6, 0xA51E03AA, 0x9CF2D0A4,
|
||||
0x83C061BA, 0x9BE96A4D, 0x8FE51550, 0xBA645BD6,
|
||||
0x2826A2F9, 0xA73A3AE1, 0x4BA99586, 0xEF5562E9,
|
||||
0xC72FEFD3, 0xF752F7DA, 0x3F046F69, 0x77FA0A59,
|
||||
0x80E4A915, 0x87B08601, 0x9B09E6AD, 0x3B3EE593,
|
||||
0xE990FD5A, 0x9E34D797, 0x2CF0B7D9, 0x022B8B51,
|
||||
0x96D5AC3A, 0x017DA67D, 0xD1CF3ED6, 0x7C7D2D28,
|
||||
0x1F9F25CF, 0xADF2B89B, 0x5AD6B472, 0x5A88F54C,
|
||||
0xE029AC71, 0xE019A5E6, 0x47B0ACFD, 0xED93FA9B,
|
||||
0xE8D3C48D, 0x283B57CC, 0xF8D56629, 0x79132E28,
|
||||
0x785F0191, 0xED756055, 0xF7960E44, 0xE3D35E8C,
|
||||
0x15056DD4, 0x88F46DBA, 0x03A16125, 0x0564F0BD,
|
||||
0xC3EB9E15, 0x3C9057A2, 0x97271AEC, 0xA93A072A,
|
||||
0x1B3F6D9B, 0x1E6321F5, 0xF59C66FB, 0x26DCF319,
|
||||
0x7533D928, 0xB155FDF5, 0x03563482, 0x8ABA3CBB,
|
||||
0x28517711, 0xC20AD9F8, 0xABCC5167, 0xCCAD925F,
|
||||
0x4DE81751, 0x3830DC8E, 0x379D5862, 0x9320F991,
|
||||
0xEA7A90C2, 0xFB3E7BCE, 0x5121CE64, 0x774FBE32,
|
||||
0xA8B6E37E, 0xC3293D46, 0x48DE5369, 0x6413E680,
|
||||
0xA2AE0810, 0xDD6DB224, 0x69852DFD, 0x09072166,
|
||||
0xB39A460A, 0x6445C0DD, 0x586CDECF, 0x1C20C8AE,
|
||||
0x5BBEF7DD, 0x1B588D40, 0xCCD2017F, 0x6BB4E3BB,
|
||||
0xDDA26A7E, 0x3A59FF45, 0x3E350A44, 0xBCB4CDD5,
|
||||
0x72EACEA8, 0xFA6484BB, 0x8D6612AE, 0xBF3C6F47,
|
||||
0xD29BE463, 0x542F5D9E, 0xAEC2771B, 0xF64E6370,
|
||||
0x740E0D8D, 0xE75B1357, 0xF8721671, 0xAF537D5D,
|
||||
0x4040CB08, 0x4EB4E2CC, 0x34D2466A, 0x0115AF84,
|
||||
0xE1B00428, 0x95983A1D, 0x06B89FB4, 0xCE6EA048,
|
||||
0x6F3F3B82, 0x3520AB82, 0x011A1D4B, 0x277227F8,
|
||||
0x611560B1, 0xE7933FDC, 0xBB3A792B, 0x344525BD,
|
||||
0xA08839E1, 0x51CE794B, 0x2F32C9B7, 0xA01FBAC9,
|
||||
0xE01CC87E, 0xBCC7D1F6, 0xCF0111C3, 0xA1E8AAC7,
|
||||
0x1A908749, 0xD44FBD9A, 0xD0DADECB, 0xD50ADA38,
|
||||
0x0339C32A, 0xC6913667, 0x8DF9317C, 0xE0B12B4F,
|
||||
0xF79E59B7, 0x43F5BB3A, 0xF2D519FF, 0x27D9459C,
|
||||
0xBF97222C, 0x15E6FC2A, 0x0F91FC71, 0x9B941525,
|
||||
0xFAE59361, 0xCEB69CEB, 0xC2A86459, 0x12BAA8D1,
|
||||
0xB6C1075E, 0xE3056A0C, 0x10D25065, 0xCB03A442,
|
||||
0xE0EC6E0E, 0x1698DB3B, 0x4C98A0BE, 0x3278E964,
|
||||
0x9F1F9532, 0xE0D392DF, 0xD3A0342B, 0x8971F21E,
|
||||
0x1B0A7441, 0x4BA3348C, 0xC5BE7120, 0xC37632D8,
|
||||
0xDF359F8D, 0x9B992F2E, 0xE60B6F47, 0x0FE3F11D,
|
||||
0xE54CDA54, 0x1EDAD891, 0xCE6279CF, 0xCD3E7E6F,
|
||||
0x1618B166, 0xFD2C1D05, 0x848FD2C5, 0xF6FB2299,
|
||||
0xF523F357, 0xA6327623, 0x93A83531, 0x56CCCD02,
|
||||
0xACF08162, 0x5A75EBB5, 0x6E163697, 0x88D273CC,
|
||||
0xDE966292, 0x81B949D0, 0x4C50901B, 0x71C65614,
|
||||
0xE6C6C7BD, 0x327A140A, 0x45E1D006, 0xC3F27B9A,
|
||||
0xC9AA53FD, 0x62A80F00, 0xBB25BFE2, 0x35BDD2F6,
|
||||
0x71126905, 0xB2040222, 0xB6CBCF7C, 0xCD769C2B,
|
||||
0x53113EC0, 0x1640E3D3, 0x38ABBD60, 0x2547ADF0,
|
||||
0xBA38209C, 0xF746CE76, 0x77AFA1C5, 0x20756060,
|
||||
0x85CBFE4E, 0x8AE88DD8, 0x7AAAF9B0, 0x4CF9AA7E,
|
||||
0x1948C25C, 0x02FB8A8C, 0x01C36AE4, 0xD6EBE1F9,
|
||||
0x90D4F869, 0xA65CDEA0, 0x3F09252D, 0xC208E69F,
|
||||
0xB74E6132, 0xCE77E25B, 0x578FDFE3, 0x3AC372E6
|
||||
};
|
||||
var i int32, j int32, k int32;
|
||||
var data uint32, datal uint32, datar uint32;
|
||||
for i = 0; i < 4; i++ {
|
||||
for j = 0; j < 256; j++;
|
||||
this.s[i, j] = s[i, j];
|
||||
}
|
||||
j = 0;
|
||||
for i = 0; i < n + 2; i++ {
|
||||
data = 0x00000000;
|
||||
for k = 0; k < 4; k++ {
|
||||
data = (data << 8) | key[j];
|
||||
j = j + 1;
|
||||
if j >= key_len;
|
||||
j = 0;
|
||||
}
|
||||
this.p[i] = p[i] ^ data;
|
||||
}
|
||||
datal = 0x00000000;
|
||||
datar = 0x00000000;
|
||||
for i = 0; i < n + 2; i += 2 {
|
||||
this->encrypt(&datal, &datar);
|
||||
this.p[i] = datal;
|
||||
this.p[i + 1] = datar;
|
||||
}
|
||||
for i = 0; i < 4; i++ {
|
||||
for j = 0; j < 256; j += 2 {
|
||||
this->encrypt(&datal, &datar);
|
||||
this.s[i, j] = datal;
|
||||
this.s[i, j + 1] = datar;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func f(x uint32) uint32 {
|
||||
var a uint16, b uint16, c uint16, d uint16;
|
||||
var y uint32;
|
||||
d = uint16(x & 0xff);
|
||||
x >>= 8;
|
||||
c = uint16(x & 0xff);
|
||||
x >>= 8;
|
||||
b = uint16(x & 0xff);
|
||||
x >>= 8;
|
||||
a = uint16(x & 0xff);
|
||||
y = this.s[0, a] + this.s[1, b];
|
||||
y = y ^ this.s[2, c];
|
||||
y = y + this.s[3, d];
|
||||
return y;
|
||||
}
|
||||
|
||||
func encrypt(xl. uint32, xr. uint32) {
|
||||
var Xl uint32;
|
||||
var Xr uint32;
|
||||
var temp uint32;
|
||||
var i int16;
|
||||
Xl = .xl;
|
||||
Xr = .xr;
|
||||
for i = 0; i < n; i++ {
|
||||
Xl = Xl ^ this.p[i];
|
||||
Xr = this->f(Xl) ^ Xr;
|
||||
temp = Xl;
|
||||
Xl = Xr;
|
||||
Xr = temp;
|
||||
}
|
||||
temp = Xl;
|
||||
Xl = Xr;
|
||||
Xr = temp;
|
||||
Xr = Xr ^ this.p[n];
|
||||
Xl = Xl ^ this.p[n + 1];
|
||||
.xl = Xl;
|
||||
.xr = Xr;
|
||||
}
|
||||
|
||||
func decrypt(xl. uint32, xr. uint32) {
|
||||
var Xl uint32;
|
||||
var Xr uint32;
|
||||
var temp uint32;
|
||||
var i int16;
|
||||
Xl = .xl;
|
||||
Xr = .xr;
|
||||
for i = n + 1; i > 1; i-- {
|
||||
Xl = Xl ^ this.p[i];
|
||||
Xr = this->f(Xl) ^ Xr;
|
||||
temp = Xl;
|
||||
Xl = Xr;
|
||||
Xr = temp;
|
||||
}
|
||||
temp = Xl;
|
||||
Xl = Xr;
|
||||
Xr = temp;
|
||||
Xr = Xr ^ this.p[1];
|
||||
Xl = Xl ^ this.p[0];
|
||||
.xl = Xl;
|
||||
.xr = Xr;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
Copyright (C) 1997 by Paul Kocher
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 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
|
||||
Lesser General Public License for more details.
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
@@ -1,59 +0,0 @@
|
||||
|
||||
module std+, crc32 {
|
||||
|
||||
private import rt::c;
|
||||
|
||||
func crc32(crc uint32, buf void, size size_t) uint32 {
|
||||
static table() uint32 = {
|
||||
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
|
||||
0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
|
||||
0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,
|
||||
0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
|
||||
0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
|
||||
0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
|
||||
0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,
|
||||
0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
|
||||
0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,
|
||||
0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
|
||||
0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106,
|
||||
0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
|
||||
0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d,
|
||||
0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
|
||||
0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
|
||||
0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
|
||||
0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7,
|
||||
0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
|
||||
0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa,
|
||||
0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
|
||||
0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,
|
||||
0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
|
||||
0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84,
|
||||
0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
|
||||
0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
|
||||
0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
|
||||
0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,
|
||||
0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
|
||||
0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55,
|
||||
0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
|
||||
0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28,
|
||||
0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
|
||||
0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,
|
||||
0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
|
||||
0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
|
||||
0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
|
||||
0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69,
|
||||
0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
|
||||
0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,
|
||||
0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
|
||||
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,
|
||||
0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
|
||||
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
|
||||
};
|
||||
var ptr. byte = buf;
|
||||
crc ^= (~0);
|
||||
while size;
|
||||
crc = table[(crc ^ .ptr++) & 0xff] ^ (crc >> 8), --size;
|
||||
return crc ^ (~0);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
|
||||
class std+, dmem {
|
||||
|
||||
private import rt::c = crt;
|
||||
|
||||
struct dmem {
|
||||
ptr void;
|
||||
page size_t;
|
||||
capacity size_t;
|
||||
used size_t;
|
||||
}
|
||||
|
||||
func constructor() {
|
||||
this.ptr = null;
|
||||
this.page = 0x200;
|
||||
this.capacity = 0;
|
||||
this.used = 0;
|
||||
}
|
||||
|
||||
func destructor() {
|
||||
this->free();
|
||||
}
|
||||
|
||||
func free() {
|
||||
if this.ptr ~= null {
|
||||
crt::free(this.ptr);
|
||||
this.ptr = null;
|
||||
this.capacity = 0;
|
||||
this.used = 0;
|
||||
}
|
||||
}
|
||||
|
||||
inline alloc(size size_t) void {
|
||||
var used size_t = this.used;
|
||||
this->exp(size);
|
||||
return this.ptr + used;
|
||||
}
|
||||
|
||||
inline alloc_t<T>() .T {
|
||||
return this->alloc(sizeof(T));
|
||||
}
|
||||
|
||||
inline reserve(size size_t) void {
|
||||
var used size_t = this.used;
|
||||
this->exp(size);
|
||||
return this.ptr + (this.used = used);
|
||||
}
|
||||
|
||||
inline reserve_t<T>() .T {
|
||||
return this->reserve(sizeof(T));
|
||||
}
|
||||
|
||||
func write(buf void, size size_t) void {
|
||||
memmove(func = this->alloc(size), buf, size);
|
||||
}
|
||||
|
||||
func write_at(offset size_t, buf void, size size_t) void {
|
||||
var used size_t = this.used;
|
||||
if offset == used {
|
||||
memmove(func = this->alloc(size), buf, size);
|
||||
elseif offset < used;
|
||||
this->exp(size);
|
||||
memmove((func = this.ptr + offset) + size, func, used - offset);
|
||||
memcpy(func, buf, size);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
func remove(offset size_t, size size_t) bool {
|
||||
var move size_t = offset + size;
|
||||
if move > this.used;
|
||||
return false;
|
||||
memmove(this.ptr + offset, this.ptr + move, this.used - move);
|
||||
this.used -= size;
|
||||
return true;
|
||||
}
|
||||
|
||||
func exp(size size_t) {
|
||||
var page size_t = this.page;
|
||||
var capacity size_t = this.capacity;
|
||||
var used size_t = this.used + size;
|
||||
if used < this.used {
|
||||
printf("dmem: out of memory\n");
|
||||
exit(1);
|
||||
}
|
||||
if capacity < used;
|
||||
capacity = (used + page - 1) / page * page;
|
||||
if !capacity;
|
||||
capacity = page;
|
||||
if capacity ~= this.capacity;
|
||||
this.ptr = realloc(this.ptr, this.capacity = capacity);
|
||||
this.used = used;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
|
||||
module std+ {
|
||||
|
||||
func init() {
|
||||
uri::urlencode_init();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,222 +0,0 @@
|
||||
|
||||
class std+, string {
|
||||
|
||||
private import rt::c;
|
||||
|
||||
struct string {
|
||||
super dmem;
|
||||
}
|
||||
|
||||
func constructor() {
|
||||
constructor(this);
|
||||
.this.super->reserve_t<char>() = 0;
|
||||
}
|
||||
|
||||
func destructor() {
|
||||
destructor(this);
|
||||
}
|
||||
|
||||
inline ptr(offset size_t = 0) .char {
|
||||
return this.super.ptr + offset;
|
||||
}
|
||||
|
||||
inline len() size_t {
|
||||
return this.super.used;
|
||||
}
|
||||
|
||||
inline empty() bool {
|
||||
return this.super.used == 0;
|
||||
}
|
||||
|
||||
inline alloc(size size_t) .char {
|
||||
return memset(this.super->alloc(size), 0, size);
|
||||
}
|
||||
|
||||
func nul() .char {
|
||||
func = this.super.ptr;
|
||||
forvar i size_t = 0, c size_t = this.super.used; i < c; i++ {
|
||||
if !func[i] {
|
||||
this.super.used = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func clear() {
|
||||
this.super.used = 0;
|
||||
.this.super->reserve_t<char>() = 0;
|
||||
}
|
||||
|
||||
func set(str. char, len size_t = 0) .char {
|
||||
this.super.used = 0;
|
||||
if str == null {
|
||||
.this.super->reserve_t<char>() = 0;
|
||||
return this.super.ptr;
|
||||
}
|
||||
return this->append(str, len);
|
||||
}
|
||||
|
||||
func format(format. char, ...) .char {
|
||||
this.super.used = 0;
|
||||
return this->appendvf(format, va_start(this));
|
||||
}
|
||||
|
||||
func append(str. char, len size_t = 0) .char {
|
||||
if !len;
|
||||
len = strlen(str);
|
||||
if len;
|
||||
this.super->write(str, len);
|
||||
.this.super->reserve_t<char>() = 0;
|
||||
return this.super.ptr;
|
||||
}
|
||||
|
||||
func append_at(offset size_t, str. char, len size_t = 0) .char {
|
||||
if !len;
|
||||
len = strlen(str);
|
||||
if len {
|
||||
if !this.super->write_at(offset, str, len);
|
||||
return null;
|
||||
}
|
||||
.this.super->reserve_t<char>() = 0;
|
||||
return this.super.ptr;
|
||||
}
|
||||
|
||||
func appendf(format. char, ...) .char {
|
||||
return this->appendvf(format, va_start(this));
|
||||
}
|
||||
|
||||
func appendvf(format. char, ap void) .char {
|
||||
var len int = vsnprintf(null, 0, format, ap);
|
||||
if len > -1 {
|
||||
vsnprintf(this.super->alloc(++len), len, format, ap);
|
||||
this.super.used--;
|
||||
return this.super.ptr;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
func appendc(c char, len uint = 1) .char {
|
||||
for ; len; len--;
|
||||
.this.super->alloc_t<char>() = c;
|
||||
.this.super->reserve_t<char>() = 0;
|
||||
return this.super.ptr;
|
||||
}
|
||||
|
||||
func append_rnd(format. char, len uint) .char {
|
||||
var range size_t = strlen(format);
|
||||
if !range;
|
||||
return null;
|
||||
for ; len; len-- {
|
||||
var spec char = format[random<int>(range)];
|
||||
if spec == 'd' {
|
||||
.this.super->alloc_t<char>() = random2<char>('0', '9');
|
||||
elseif spec == 'c';
|
||||
.this.super->alloc_t<char>() = random2<char>('a', 'z');
|
||||
elseif spec == 'C';
|
||||
.this.super->alloc_t<char>() = random2<char>('A', 'Z');
|
||||
}
|
||||
}
|
||||
.this.super->reserve_t<char>() = 0;
|
||||
return this.super.ptr;
|
||||
}
|
||||
|
||||
func append_hex(buf. byte, len size_t, upper bool = false, reverse bool = false) .char {
|
||||
var format. char;
|
||||
if upper {
|
||||
format = "%02X";
|
||||
else
|
||||
format = "%02x";
|
||||
}
|
||||
if reverse {
|
||||
while len;
|
||||
this->appendf(format, buf[--len]);
|
||||
else
|
||||
forvar i size_t = 0; i < len; i++;
|
||||
this->appendf(format, buf[i]);
|
||||
}
|
||||
return this.super.ptr;
|
||||
}
|
||||
|
||||
func insert(offset size_t, str. char) .char {
|
||||
if this.super->write_at(offset, str, strlen(str)) == null;
|
||||
return null;
|
||||
.this.super->reserve_t<char>() = 0;
|
||||
return this.super.ptr;
|
||||
}
|
||||
|
||||
inline starts_with(c char) bool {
|
||||
var s. char = this.super.ptr;
|
||||
return .s == c;
|
||||
}
|
||||
|
||||
inline ends_with(c char) bool {
|
||||
if !this.super.used;
|
||||
return false;
|
||||
var s. char = this.super.ptr + (this.super.used - 1);
|
||||
return .s == c;
|
||||
}
|
||||
|
||||
func ltrim() .char {
|
||||
var s. char = this.super.ptr;
|
||||
while isspace(.s);
|
||||
s += 1;
|
||||
return this->set(s);
|
||||
}
|
||||
|
||||
func rtrim() .char {
|
||||
var s. char = this.super.ptr;
|
||||
while this.super.used {
|
||||
if !isspace(s[this.super.used - 1]);
|
||||
break;
|
||||
this.super.used--;
|
||||
}
|
||||
.this.super->reserve_t<char>() = 0;
|
||||
return this.super.ptr;
|
||||
}
|
||||
|
||||
func trim() .char {
|
||||
this->ltrim();
|
||||
return this->rtrim();
|
||||
}
|
||||
|
||||
func between(str. char, left. char, right. char) .char {
|
||||
var first. char = strstr(str, left);
|
||||
if first ~= null {
|
||||
var last. char = strstr(first += strlen(left), right);
|
||||
if last ~= null;
|
||||
return this->set(first, last - first);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
func replace(str. char, sub_str. char, new. char = null) .char {
|
||||
var sub_str_len size_t = strlen(sub_str);
|
||||
var new_len size_t = strlen(new);
|
||||
var tmp string;
|
||||
var found. char;
|
||||
while (found = strstr(str, sub_str)) ~= null {
|
||||
if found ~= str;
|
||||
tmp->append(str, found - str);
|
||||
if new_len;
|
||||
tmp->append(new, new_len);
|
||||
str = found + sub_str_len;
|
||||
}
|
||||
tmp->append(str);
|
||||
return this->set(tmp->ptr(), tmp->len());
|
||||
}
|
||||
|
||||
inline remove(offset size_t, size size_t) bool {
|
||||
if this.super->remove(offset, size);
|
||||
.this.super->reserve_t<char>() = 0;
|
||||
}
|
||||
|
||||
func remove_back(len size_t = 1) {
|
||||
if this.super.used < len {
|
||||
this.super.used = 0;
|
||||
else
|
||||
this.super.used -= len;
|
||||
}
|
||||
.this.super->reserve_t<char>() = 0;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,208 +0,0 @@
|
||||
|
||||
class std+, strings {
|
||||
|
||||
private import rt::c;
|
||||
|
||||
struct strings {
|
||||
mem dmem;
|
||||
offsets vector<uint32>;
|
||||
index size_t;
|
||||
}
|
||||
|
||||
func constructor() {
|
||||
constructor(this);
|
||||
this.mem.page = 0x2000;
|
||||
this.index = -1;
|
||||
}
|
||||
|
||||
func destructor() {
|
||||
destructor(this);
|
||||
}
|
||||
|
||||
func clear(free_mem bool = false) {
|
||||
if free_mem {
|
||||
this.mem->free();
|
||||
else
|
||||
this.mem.used = 0;
|
||||
}
|
||||
this.offsets->clear(free_mem);
|
||||
this.index = -1;
|
||||
}
|
||||
|
||||
func add(str. char, len size_t = 0) .char {
|
||||
var used size_t = this.mem.used;
|
||||
this.offsets->push_back(used);
|
||||
if !len;
|
||||
len = strlen(str);
|
||||
if len;
|
||||
this.mem->write(str, len);
|
||||
.this.mem->alloc_t<char>() = 0;
|
||||
return this.mem.ptr + used;
|
||||
}
|
||||
|
||||
func load_file(file_name. char, trim bool = true, ignore_blank bool = true) int {
|
||||
var stream void = fopen(file_name, "rb");
|
||||
if stream == null;
|
||||
return -1;
|
||||
defer fclose(stream);
|
||||
if fgetc(stream) ~= 0xef or
|
||||
fgetc(stream) ~= 0xbb or
|
||||
fgetc(stream) ~= 0xbf {
|
||||
if fseek(stream, 0, SEEK_SET) < 0;
|
||||
return -1;
|
||||
}
|
||||
var count size_t = this.offsets->count();
|
||||
var buf(0x2000) char;
|
||||
for ;; {
|
||||
if fgets(&buf, 0x2000, stream) == null;
|
||||
break;
|
||||
var line. char = &buf;
|
||||
var len size_t = strlen(line);
|
||||
if len and line[len - 1] == 10 {
|
||||
if len > 1 and line[len - 2] == 13 {
|
||||
len -= 2;
|
||||
else
|
||||
len -= 1;
|
||||
}
|
||||
line[len] = 0;
|
||||
}
|
||||
if trim {
|
||||
while isspace(.line);
|
||||
line += 1, len--;
|
||||
while len {
|
||||
if !isspace(line[len - 1]);
|
||||
break;
|
||||
len--;
|
||||
}
|
||||
}
|
||||
if !len and ignore_blank;
|
||||
continue;
|
||||
this->add(line, len);
|
||||
}
|
||||
return this.offsets->count() - count;
|
||||
}
|
||||
|
||||
func split(str. char, del. char) uint {
|
||||
func = 1;
|
||||
var len size_t = strlen(del);
|
||||
var tmp. char;
|
||||
while (tmp = strstr(str, del)) ~= null;
|
||||
this->add(str, tmp - str), str = tmp + len, func++;
|
||||
this->add(str);
|
||||
}
|
||||
|
||||
inline count() size_t {
|
||||
return this.offsets->count();
|
||||
}
|
||||
|
||||
inline empty() bool {
|
||||
return this.offsets->count() == 0;
|
||||
}
|
||||
|
||||
inline item(index size_t) .char {
|
||||
return this.mem.ptr + .this.offsets->at(index);
|
||||
}
|
||||
|
||||
func next_item(loop bool = false) .char {
|
||||
var count size_t = this->count();
|
||||
if !count;
|
||||
return null;
|
||||
var index size_t = this.index;
|
||||
if index < count {
|
||||
func = this->item(index), this.index++;
|
||||
else
|
||||
this.index = 0;
|
||||
if index == -1 or loop {
|
||||
func = this->next_item();
|
||||
else
|
||||
func = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func prev_item() .char {
|
||||
var index size_t = this.index;
|
||||
if index == -1;
|
||||
return null;
|
||||
var count size_t = this->count();
|
||||
if !count;
|
||||
return null;
|
||||
if index and index < count {
|
||||
return this->item(index - 1);
|
||||
else
|
||||
return this->item(count - 1);
|
||||
}
|
||||
}
|
||||
|
||||
func rollback() {
|
||||
var count size_t = this->count();
|
||||
if count {
|
||||
if this.index ~= -1 {
|
||||
if this.index and this.index < count {
|
||||
this.index--;
|
||||
else
|
||||
this.index = count - 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
this.index = -1;
|
||||
}
|
||||
}
|
||||
|
||||
func first_item() .char {
|
||||
if !this->count();
|
||||
return null;
|
||||
return this->item(0);
|
||||
}
|
||||
|
||||
func last_item() .char {
|
||||
var count size_t = this->count();
|
||||
if !count;
|
||||
return null;
|
||||
return this->item(count - 1);
|
||||
}
|
||||
|
||||
func rnd_item() .char {
|
||||
var count size_t = this->count();
|
||||
if !count;
|
||||
return null;
|
||||
return this->item(random<size_t>(count));
|
||||
}
|
||||
|
||||
func join(str. string, del. char = null) .char {
|
||||
forvar index size_t = 0, count size_t = this->count(); index < count; index++ {
|
||||
str->append(this->item(index));
|
||||
if del ~= null;
|
||||
str->append(del);
|
||||
}
|
||||
return str->ptr();
|
||||
}
|
||||
|
||||
func exists(str. char, index. size_t = null) bool {
|
||||
forvar i size_t = 0, c size_t = this->count(); i < c; i++ {
|
||||
if !strcmp(this->item(i), str) {
|
||||
if index ~= null;
|
||||
.index = i;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
func existsi(str. char, index. size_t = null) bool {
|
||||
forvar i size_t = 0, c size_t = this->count(); i < c; i++ {
|
||||
if !strcasecmp(this->item(i), str) {
|
||||
if index ~= null;
|
||||
.index = i;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// fixme
|
||||
inline remove(index size_t) bool {
|
||||
return this.offsets->erase(index);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
|
||||
module std+, uri {
|
||||
|
||||
private import rt::c;
|
||||
|
||||
private var
|
||||
rfc3986_table(256) char = 0,
|
||||
html5_table(256) char = 0;
|
||||
|
||||
func urlencode_init() {
|
||||
forvar i int = 0; i < 256; i++ {
|
||||
if isalnum(i) or i == '~' or i == '-' or i == '.' or i == '_' {
|
||||
rfc3986_table[i] = i;
|
||||
else
|
||||
rfc3986_table[i] = '\0';
|
||||
}
|
||||
if isalnum(i) or i == '*' or i == '-' or i == '.' or i == '_' {
|
||||
html5_table[i] = i;
|
||||
else
|
||||
if i == ' ' {
|
||||
html5_table[i] = '+';
|
||||
else
|
||||
html5_table[i] = '\0';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func urlencode(table. char, str. char, upper bool = false) .char {
|
||||
static lower_charset() char = "0123456789abcdef";
|
||||
static upper_charset() char = "0123456789ABCDEF";
|
||||
var charset. char;
|
||||
if upper {
|
||||
charset = &upper_charset;
|
||||
else
|
||||
charset = &lower_charset;
|
||||
}
|
||||
var len size_t = strlen(str);
|
||||
var enc. char = (func = malloc((len * 3) + 1));
|
||||
forvar i size_t = 0; i < len; i++ {
|
||||
var b byte = str[i];
|
||||
var c char = table[b];
|
||||
if c {
|
||||
.enc++ = c;
|
||||
else
|
||||
.enc++ = '%';
|
||||
.enc++ = charset[b >> 4];
|
||||
.enc++ = charset[b & 15];
|
||||
}
|
||||
}
|
||||
.enc = '\0';
|
||||
}
|
||||
|
||||
inline urlencode_rfc3986(str. char, upper bool = false) .char {
|
||||
return urlencode(&rfc3986_table, str, upper);
|
||||
}
|
||||
|
||||
inline urlencode_html5(str. char, upper bool = false) .char {
|
||||
return urlencode(&html5_table, str, upper);
|
||||
}
|
||||
|
||||
func urldecode(str. char) .char {
|
||||
var len size_t = strlen(str);
|
||||
var dec. char = (func = malloc(len + 1));
|
||||
forvar i size_t = 0; i < len; i++ {
|
||||
var c char = str[i];
|
||||
if c == '%' {
|
||||
if i + 2 < len {
|
||||
lambda from_hex(c char) char [
|
||||
if islower(c) {
|
||||
return c - 'a' + 10;
|
||||
elseif isupper(c);
|
||||
return c - 'A' + 10;
|
||||
elseif isdigit(c);
|
||||
return c - '0';
|
||||
}
|
||||
return 0;
|
||||
];
|
||||
.dec++ =
|
||||
from_hex(str[i + 1]) << 4 |
|
||||
from_hex(str[i + 2]);
|
||||
i += 2;
|
||||
else
|
||||
break;
|
||||
}
|
||||
elseif c == '+';
|
||||
.dec++ = ' ';
|
||||
else
|
||||
.dec++ = c;
|
||||
}
|
||||
}
|
||||
.dec = '\0';
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,142 +0,0 @@
|
||||
|
||||
module std+, utf8 {
|
||||
|
||||
private import rt::c;
|
||||
|
||||
var utf8table() int = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 1, 1 };
|
||||
|
||||
// See Copyright Notice at the end of this file.
|
||||
func utf8decode(o. char, val. int = null) .char {
|
||||
define {
|
||||
MAXUNICODE = 0x10ffff;
|
||||
}
|
||||
static limits() uint = { 0xff, 0x7f, 0x7ff, 0xffff };
|
||||
var s. char = o;
|
||||
var c uint = s[0];
|
||||
var res uint = 0;
|
||||
if c < 0x80 {
|
||||
res = c;
|
||||
else
|
||||
var count int = 0;
|
||||
while c & 0x40 {
|
||||
var cc int = s[++count];
|
||||
if (cc & 0xc0) ~= 0x80;
|
||||
return null;
|
||||
res = (res << 6) | (cc & 0x3f);
|
||||
c <<= 1;
|
||||
}
|
||||
res |= ((c & 0x7f) << (count * 5));
|
||||
if count > 3 or res > MAXUNICODE or res <= limits[count];
|
||||
return null;
|
||||
s += count;
|
||||
}
|
||||
if val ~= null;
|
||||
.val = res;
|
||||
return s + 1;
|
||||
}
|
||||
|
||||
func utf8len_s(s. char, size int, tail. int = null) int {
|
||||
func = 0;
|
||||
if tail ~= null;
|
||||
.tail = 0;
|
||||
forvar pos int = 0; pos < size; func++ {
|
||||
var s1. char = utf8decode(s + pos);
|
||||
if s1 == null;
|
||||
return -1;
|
||||
if tail ~= null;
|
||||
.tail = s1 - (s + pos);
|
||||
pos = s1 - s;
|
||||
}
|
||||
}
|
||||
|
||||
inline utf8chk(s. char, size int) bool {
|
||||
return utf8len_s(s, size) ~= -1;
|
||||
}
|
||||
|
||||
func utf8len(s. char, tail. int = null) int {
|
||||
if tail ~= null;
|
||||
.tail = 0;
|
||||
for func = 0;; func++ {
|
||||
var val int;
|
||||
var s1. char = utf8decode(s, &val);
|
||||
if s1 == null;
|
||||
return -1;
|
||||
if !val;
|
||||
return;
|
||||
if tail ~= null;
|
||||
.tail = s1 - s;
|
||||
s = s1;
|
||||
}
|
||||
}
|
||||
|
||||
func utf8size(s. char, tail. int = null) int {
|
||||
var o. char = s;
|
||||
if tail ~= null;
|
||||
.tail = 0;
|
||||
for ;; {
|
||||
var val int;
|
||||
var s1. char = utf8decode(s, &val);
|
||||
if s1 == null;
|
||||
return -1;
|
||||
if !val;
|
||||
return (s1 - 1) - o;
|
||||
if tail ~= null;
|
||||
.tail = s1 - s;
|
||||
s = s1;
|
||||
}
|
||||
}
|
||||
|
||||
func utf8at(s. char, idx int, c. uint32) int {
|
||||
forvar i int = 0;; i++ {
|
||||
var val int;
|
||||
var s1. char = utf8decode(s, &val);
|
||||
if s1 == null;
|
||||
return -1;
|
||||
if i >= idx {
|
||||
.c = val;
|
||||
return s1 - s;
|
||||
}
|
||||
s = s1;
|
||||
}
|
||||
}
|
||||
|
||||
func utf8cmp(s1. char, s2. char) bool {
|
||||
var ss1 int = utf8size(s1);
|
||||
var ss2 int = utf8size(s2);
|
||||
if ss1 ~= -1 and ss1 == ss2 and !memcmp(s1, s2, ss1);
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
func utf8str(s. char, sub. char) .char {
|
||||
var s1 int = utf8size(s),
|
||||
s2 int = utf8size(sub);
|
||||
if s1 == -1 or s2 == -1;
|
||||
return null;
|
||||
return memmem(s, s1, sub, s2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Copyright (C) 1994-2018 Lua.org, PUC-Rio.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
******************************************************************************/
|
||||
@@ -1,207 +0,0 @@
|
||||
|
||||
class std+, vector<T> {
|
||||
|
||||
import rt::c;
|
||||
|
||||
struct vector {
|
||||
ptr void;
|
||||
page size_t;
|
||||
capacity size_t;
|
||||
used size_t;
|
||||
}
|
||||
|
||||
func constructor() {
|
||||
this.ptr = null;
|
||||
this.page = sizeof(T, 32);
|
||||
this.capacity = 0;
|
||||
this.used = 0;
|
||||
}
|
||||
|
||||
func destructor() {
|
||||
this->clear(true);
|
||||
}
|
||||
|
||||
inline size() size_t {
|
||||
return this.used;
|
||||
}
|
||||
|
||||
inline resize(count size_t) {
|
||||
if count {
|
||||
this->adjust_size(this.used = sizeof(T, count));
|
||||
else
|
||||
this.used = 0;
|
||||
}
|
||||
}
|
||||
|
||||
inline count() size_t {
|
||||
return this.used / sizeof(T);
|
||||
}
|
||||
|
||||
inline capacity() size_t {
|
||||
return this.capacity;
|
||||
}
|
||||
|
||||
inline empty() bool {
|
||||
return !this.used;
|
||||
}
|
||||
|
||||
inline reserve(count size_t) {
|
||||
if count;
|
||||
this->adjust_size(sizeof(T, count));
|
||||
}
|
||||
|
||||
func shrink_to_fit() {
|
||||
// ...
|
||||
}
|
||||
|
||||
inline at(pos size_t) .T {
|
||||
var offset size_t = sizeof(T, pos);
|
||||
if offset < this.used;
|
||||
return this.ptr + offset;
|
||||
return null;
|
||||
}
|
||||
|
||||
inline front() .T {
|
||||
if this.used;
|
||||
return this.ptr;
|
||||
return null;
|
||||
}
|
||||
|
||||
inline back() .T {
|
||||
if this.used;
|
||||
return this.ptr + this.used - sizeof(T);
|
||||
return null;
|
||||
}
|
||||
|
||||
inline data() .T {
|
||||
return this.ptr;
|
||||
}
|
||||
|
||||
inline alloc() .T {
|
||||
var used size_t = this.used;
|
||||
this->adjust_size(this.used += sizeof(T));
|
||||
return this.ptr + used;
|
||||
}
|
||||
|
||||
inline new() .T {
|
||||
func = this->alloc();
|
||||
#if objectid(T).is_class;
|
||||
#if objectid(T).func.constructor;
|
||||
func->constructor();
|
||||
#endif
|
||||
#elseif objectid(T).is_struct;
|
||||
constructor(func);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline push_back(value T) {
|
||||
.this->alloc() = value;
|
||||
}
|
||||
|
||||
inline push_back_ref(value. T) {
|
||||
.this->alloc() = .value;
|
||||
}
|
||||
|
||||
func pop_back(count size_t = 1) {
|
||||
var size size_t = sizeof(T, count);
|
||||
#if objectid(T).is_struct;
|
||||
if this.used <= size {
|
||||
this->clear();
|
||||
else
|
||||
for ; count; count-- {
|
||||
var t. T = this.ptr + (this.used -= sizeof(T));
|
||||
#if objectid(T).is_class;
|
||||
#if objectid(T).func.destructor;
|
||||
t->destructor();
|
||||
#endif
|
||||
#elseif objectid(T).is_struct;
|
||||
destructor(t);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#else
|
||||
if this.used <= size {
|
||||
this.used = 0;
|
||||
else
|
||||
this.used -= size;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
func insert(pos size_t, value T) {
|
||||
// ...
|
||||
}
|
||||
|
||||
func insert_ref(pos size_t, value. T) {
|
||||
// ...
|
||||
}
|
||||
|
||||
func erase(pos size_t) bool {
|
||||
var count size_t = this->count();
|
||||
if !count or count <= pos;
|
||||
return false;
|
||||
if (count - 1) == pos {
|
||||
this->pop_back();
|
||||
else
|
||||
var offset size_t = pos * sizeof(T);
|
||||
var move size_t = offset + sizeof(T);
|
||||
var t. T = this.ptr + offset;
|
||||
#if objectid(T).is_class;
|
||||
#if objectid(T).func.destructor;
|
||||
t->destructor();
|
||||
#endif
|
||||
#elseif objectid(T).is_struct;
|
||||
destructor(t);
|
||||
#endif
|
||||
memmove(t, this.ptr + move, this.used - move);
|
||||
this.used -= sizeof(T);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
func erases(start size_t, end size_t) bool {
|
||||
// ...
|
||||
}
|
||||
|
||||
inline swap(other. vector) {
|
||||
var tmp $vector = .this;
|
||||
.this = .other;
|
||||
.other = tmp;
|
||||
}
|
||||
|
||||
func clear(free_mem bool = false) {
|
||||
#if objectid(T).is_class;
|
||||
#if objectid(T).func.destructor;
|
||||
forvar count size_t = this->count(); count;;
|
||||
this->at(--count)->destructor();
|
||||
#endif
|
||||
#elseif objectid(T).is_struct;
|
||||
forvar count size_t = this->count(); count;;
|
||||
destructor(this->at(--count));
|
||||
#endif
|
||||
this.used = 0;
|
||||
if free_mem {
|
||||
if this.ptr ~= null {
|
||||
free(this.ptr);
|
||||
this.ptr = null;
|
||||
this.capacity = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func adjust_size(size size_t) {
|
||||
var capacity size_t = this.capacity;
|
||||
if !capacity;
|
||||
capacity = this.page;
|
||||
while capacity < size {
|
||||
if capacity & 0x80000000 {
|
||||
printf("vector: out of memory\n");
|
||||
exit(1);
|
||||
}
|
||||
capacity <<= 1;
|
||||
}
|
||||
if capacity ~= this.capacity;
|
||||
this.ptr = realloc(this.ptr, this.capacity = capacity);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
|
||||
class std+, vector_ptr<T> {
|
||||
|
||||
inherit vector<void> = super;
|
||||
|
||||
struct vector_ptr;
|
||||
|
||||
func constructor() {
|
||||
constructor(this); }
|
||||
func destructor() {
|
||||
destructor(this); }
|
||||
|
||||
inline at(pos size_t) .T {
|
||||
return .this.super->at(pos);
|
||||
}
|
||||
|
||||
inline front() .T {
|
||||
return .this.super->front();
|
||||
}
|
||||
|
||||
inline back() .T {
|
||||
return .this.super->back();
|
||||
}
|
||||
|
||||
}
|
||||
|
Before Width: | Height: | Size: 7.6 KiB |
|
Before Width: | Height: | Size: 409 B |
|
Before Width: | Height: | Size: 411 B |
|
Before Width: | Height: | Size: 365 B |
|
Before Width: | Height: | Size: 409 B |
|
Before Width: | Height: | Size: 459 B |
|
Before Width: | Height: | Size: 345 B |
|
Before Width: | Height: | Size: 392 B |
|
Before Width: | Height: | Size: 340 B |
|
Before Width: | Height: | Size: 131 B |
|
Before Width: | Height: | Size: 429 B |
|
Before Width: | Height: | Size: 405 B |
|
Before Width: | Height: | Size: 453 B |
|
Before Width: | Height: | Size: 709 B |
|
Before Width: | Height: | Size: 479 B |
|
Before Width: | Height: | Size: 490 B |
|
Before Width: | Height: | Size: 596 B |
|
Before Width: | Height: | Size: 908 B |
|
Before Width: | Height: | Size: 363 B |
|
Before Width: | Height: | Size: 300 B |