mirror of
https://github.com/clockworkpi/Menu.git
synced 2026-03-21 19:32:52 +01:00
gcores ~/apps/Menu branch first commit
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user