mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-26 12:30:30 +00:00
Get Cosmopolitan into releasable state
A new rollup tool now exists for flattening out the headers in a way that works better for our purposes than cpp. A lot of the API clutter has been removed. APIs that aren't a sure thing in terms of general recommendation are now marked internal. There's now a smoke test for the amalgamation archive and gigantic header file. So we can now guarantee you can use this project on the easiest difficulty setting without the gigantic repository. A website is being created, which is currently a work in progress: https://justine.storage.googleapis.com/cosmopolitan/index.html
This commit is contained in:
parent
dba7552c1e
commit
ea0b5d9d1c
775 changed files with 6864 additions and 3963 deletions
|
@ -3,7 +3,7 @@
|
|||
#ifndef __STRICT_ANSI__
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/str/tpenc.h"
|
||||
#include "libc/str/tpencode.h"
|
||||
#include "libc/str/tpencode.internal.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
|
||||
static inline void AppendChar(char **p, char *pe, wint_t wc) {
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
#include "libc/bits/bits.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/nexgen32e/cachesize.h"
|
||||
#include "libc/nexgen32e/cpuid4.h"
|
||||
#include "libc/nexgen32e/cpuid4.internal.h"
|
||||
|
||||
static unsigned getcachesize$cpuid4(int type, int level) {
|
||||
unsigned i, k;
|
||||
|
@ -51,7 +51,7 @@ static unsigned getcachesize$cpuid4(int type, int level) {
|
|||
* @param level starts at 1
|
||||
* @return size in bytes, or 0 if unknown
|
||||
*/
|
||||
unsigned getcachesize(enum CpuCacheType type, int level) {
|
||||
unsigned getcachesize(int type, int level) {
|
||||
assert(1 <= type && type <= 3);
|
||||
assert(level >= 1);
|
||||
return getcachesize$cpuid4(type, level);
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
* @return number of bytes (NUL counts as 1) or -1 w/ errno
|
||||
* @note synchronization is performed to skip leading continuations;
|
||||
* canonicalization and validation are performed to some extent
|
||||
* @todo delete
|
||||
*/
|
||||
forcealignargpointer unsigned(getutf16)(const char16_t *p, wint_t *wc) {
|
||||
unsigned skip = 0;
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/alg/bisect.h"
|
||||
#include "libc/alg/bisect.internal.h"
|
||||
#include "libc/nexgen32e/x86info.h"
|
||||
|
||||
static int CmpX86ProcModelKey(const struct X86ProcessorModel *a,
|
||||
|
|
|
@ -1,22 +1,3 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=8 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#ifndef COSMOPOLITAN_LIBC_STR_INTERNAL_H_
|
||||
#define COSMOPOLITAN_LIBC_STR_INTERNAL_H_
|
||||
#ifndef __STRICT_ANSI__
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#include "libc/limits.h"
|
||||
#include "libc/macros.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/str/tpdecode.h"
|
||||
#include "libc/str/tpdecode.internal.h"
|
||||
|
||||
compatfn int mbtowc(wchar_t *wc, const char *s, size_t n) {
|
||||
if (!s) return 0;
|
||||
|
|
|
@ -17,11 +17,11 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/bigword.h"
|
||||
#include "libc/bits/bigword.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
#define wmemset memset16
|
||||
#define T unsigned short
|
||||
#define N (BIGWORD / sizeof(T))
|
||||
#define T unsigned short
|
||||
#define N (BIGWORD / sizeof(T))
|
||||
#include "libc/nexgen32e/wmemset.inc"
|
||||
#undef wmemset
|
||||
#undef T
|
||||
|
|
47
libc/str/oldutf16.internal.h
Normal file
47
libc/str/oldutf16.internal.h
Normal file
|
@ -0,0 +1,47 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_STR_OLDUTF16_H_
|
||||
#define COSMOPOLITAN_LIBC_STR_OLDUTF16_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
unsigned getutf16(const char16_t *, wint_t *);
|
||||
int pututf16(char16_t *, size_t, wint_t, bool);
|
||||
|
||||
#define pututf16(BUF, SIZE, CH, AWESOME) __pututf16(BUF, SIZE, CH, AWESOME)
|
||||
#define getutf16(BUF, CHPTR) __getutf16(BUF, CHPTR)
|
||||
|
||||
forceinline int __pututf16(char16_t *s, size_t size, wint_t wc,
|
||||
bool32 awesome) {
|
||||
if (size >= 1 && (0x00 <= wc && wc <= 0xD7FF)) {
|
||||
if (wc >= 32 || !awesome) {
|
||||
s[0] = (char16_t)wc;
|
||||
return 1;
|
||||
} else if (size >= 2) {
|
||||
s[0] = 0xd800;
|
||||
s[1] = 0xdc00 | (char16_t)wc;
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
int ax;
|
||||
asm("call\tpututf16"
|
||||
: "=a"(ax), "=m"(*(char(*)[size])s)
|
||||
: "D"(s), "S"(size), "d"(wc)
|
||||
: "cc");
|
||||
return ax;
|
||||
}
|
||||
|
||||
forceinline unsigned __getutf16(const char16_t *s, wint_t *wc) {
|
||||
if ((0x00 <= s[0] && s[0] <= 0xD7FF)) {
|
||||
*wc = s[0];
|
||||
return 1;
|
||||
}
|
||||
unsigned ax;
|
||||
asm("call\tgetutf16"
|
||||
: "=a"(ax), "=m"(*wc)
|
||||
: "D"(s), "S"(wc), "m"(*s), "m"(*(char(*)[4])s)
|
||||
: "cc");
|
||||
return ax;
|
||||
}
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_STR_OLDUTF16_H_ */
|
|
@ -17,6 +17,7 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/str/oldutf16.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
/**
|
||||
|
@ -30,6 +31,7 @@
|
|||
* @param size is the number of shorts available in s
|
||||
* @param awesome enables numbers the IETF unilaterally banned
|
||||
* @return number of shorts written or -1 w/ errno
|
||||
* @todo delete
|
||||
*/
|
||||
int(pututf16)(char16_t *s, size_t size, wint_t wc, bool awesome) {
|
||||
wint_t wc2;
|
||||
|
|
|
@ -11,11 +11,11 @@
|
|||
* http://csrc.nist.gov/publications/fips/fips180-2/fips180-2withchangenotice.pdf
|
||||
This implementation uses little endian byte order.
|
||||
*********************************************************************/
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/nexgen32e/x86feature.h"
|
||||
#include "libc/str/internal.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/str/sha256.h"
|
||||
|
||||
#define ROTLEFT(a, b) (((a) << (b)) | ((a) >> (32 - (b))))
|
||||
#define ROTRIGHT(a, b) (((a) >> (b)) | ((a) << (32 - (b))))
|
||||
|
|
22
libc/str/sha256.h
Normal file
22
libc/str/sha256.h
Normal file
|
@ -0,0 +1,22 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_STR_SHA256_H_
|
||||
#define COSMOPOLITAN_LIBC_STR_SHA256_H_
|
||||
|
||||
#define SHA256_BLOCK_SIZE 32
|
||||
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
struct Sha256Ctx {
|
||||
uint8_t data[64];
|
||||
uint32_t datalen;
|
||||
uint64_t bitlen;
|
||||
uint32_t state[8];
|
||||
};
|
||||
|
||||
void sha256_init(struct Sha256Ctx *);
|
||||
void sha256_update(struct Sha256Ctx *, const uint8_t *, size_t);
|
||||
void sha256_final(struct Sha256Ctx *, uint8_t *);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_STR_SHA256_H_ */
|
|
@ -62,9 +62,6 @@ int cescapec(int);
|
|||
|
||||
#define INVALID_CODEPOINT 0xfffd
|
||||
|
||||
wint_t DecodeNtsUtf16(const char16_t **);
|
||||
unsigned getutf16(const char16_t *, wint_t *);
|
||||
int pututf16(char16_t *, size_t, wint_t, bool);
|
||||
int iswalnum(wint_t);
|
||||
int iswalpha(wint_t);
|
||||
int iswblank(wint_t);
|
||||
|
@ -183,6 +180,7 @@ compatfn wchar_t *wmemmove(wchar_t *, const wchar_t *, size_t) memcpyesque;
|
|||
char *tinystrstr(const char *, const char *) strlenesque;
|
||||
char16_t *tinystrstr16(const char16_t *, const char16_t *) strlenesque;
|
||||
void *tinymemmem(const void *, size_t, const void *, size_t) strlenesque;
|
||||
void *tinymemccpy(void *, const void *, int, size_t) memcpyesque;
|
||||
|
||||
void *memtolower(void *, size_t);
|
||||
char *strntolower(char *, size_t);
|
||||
|
@ -231,25 +229,6 @@ typedef unsigned wctype_t;
|
|||
wctype_t wctype(const char *) strlenesque;
|
||||
int iswctype(wint_t, wctype_t) pureconst;
|
||||
|
||||
/*───────────────────────────────────────────────────────────────────────────│─╗
|
||||
│ cosmopolitan § strings » hashing ─╬─│┼
|
||||
╚────────────────────────────────────────────────────────────────────────────│*/
|
||||
|
||||
#define SHA256_BLOCK_SIZE 32
|
||||
|
||||
struct Sha256Ctx {
|
||||
uint8_t data[64];
|
||||
uint32_t datalen;
|
||||
uint64_t bitlen;
|
||||
uint32_t state[8];
|
||||
};
|
||||
|
||||
void sha256_init(struct Sha256Ctx *);
|
||||
void sha256_update(struct Sha256Ctx *, const uint8_t *, size_t);
|
||||
void sha256_final(struct Sha256Ctx *, uint8_t *);
|
||||
|
||||
bool luhn(const char *);
|
||||
|
||||
/*───────────────────────────────────────────────────────────────────────────│─╗
|
||||
│ cosmopolitan § strings » system ─╬─│┼
|
||||
╚────────────────────────────────────────────────────────────────────────────│*/
|
||||
|
@ -264,9 +243,8 @@ char *strsignal(int) returnsnonnull libcesque;
|
|||
extern int (*const __memcmp)(const void *, const void *, size_t);
|
||||
#define memcmp(a, b, n) __memcmp(a, b, n)
|
||||
|
||||
/* gcc -Werror=stringop-truncation misunderstands strncpy() api */
|
||||
char *_strncpy(char *, const char *, size_t) asm("strncpy") memcpyesque;
|
||||
#define strncpy(DEST, SRC, N) _strncpy(DEST, SRC, N)
|
||||
#define strncpy(DEST, SRC, N) _strncpy(DEST, SRC, N) /* pacify bad warning */
|
||||
|
||||
#define explicit_bzero(STR, BYTES) \
|
||||
do { \
|
||||
|
@ -378,44 +356,9 @@ char *_strncpy(char *, const char *, size_t) asm("strncpy") memcpyesque;
|
|||
|
||||
#endif /* hosted/sse2/unbloat */
|
||||
|
||||
#define pututf16(BUF, SIZE, CH, AWESOME) __pututf16(BUF, SIZE, CH, AWESOME)
|
||||
#define getutf16(BUF, CHPTR) __getutf16(BUF, CHPTR)
|
||||
size_t _strlen(const char *s) asm("strlen") strlenesque;
|
||||
void *_memchr(const void *, int, size_t) asm("memchr") strlenesque;
|
||||
|
||||
forceinline int __pututf16(char16_t *s, size_t size, wint_t wc,
|
||||
bool32 awesome) {
|
||||
if (size >= 1 && (0x00 <= wc && wc <= 0xD7FF)) {
|
||||
if (wc >= 32 || !awesome) {
|
||||
s[0] = (char16_t)wc;
|
||||
return 1;
|
||||
} else if (size >= 2) {
|
||||
s[0] = 0xd800;
|
||||
s[1] = 0xdc00 | (char16_t)wc;
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
int ax;
|
||||
asm("call\tpututf16"
|
||||
: "=a"(ax), "=m"(*(char(*)[size])s)
|
||||
: "D"(s), "S"(size), "d"(wc)
|
||||
: "cc");
|
||||
return ax;
|
||||
}
|
||||
|
||||
forceinline unsigned __getutf16(const char16_t *s, wint_t *wc) {
|
||||
if ((0x00 <= s[0] && s[0] <= 0xD7FF)) {
|
||||
*wc = s[0];
|
||||
return 1;
|
||||
}
|
||||
unsigned ax;
|
||||
asm("call\tgetutf16"
|
||||
: "=a"(ax), "=m"(*wc)
|
||||
: "D"(s), "S"(wc), "m"(*s), "m"(*(char(*)[4])s)
|
||||
: "cc");
|
||||
return ax;
|
||||
}
|
||||
|
||||
#endif /* __GNUC__ && !__STRICT_ANSI__ */
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/str/internal.h"
|
||||
#include "libc/str/strcmp8to16i.h"
|
||||
#include "libc/str/strcmp8to16i.internal.h"
|
||||
|
||||
/**
|
||||
* Compares UTF-8 and UTF-16 strings, ignoring case.
|
||||
|
|
|
@ -18,9 +18,11 @@
|
|||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/str/internal.h"
|
||||
#include "libc/str/strcmp8to16i.h"
|
||||
#include "libc/str/strcmp8to16i.internal.h"
|
||||
|
||||
forceinline unsigned identity32u(unsigned x) { return x; }
|
||||
forceinline unsigned identity32u(unsigned x) {
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares UTF-8 and UTF-16 strings.
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_STR_STRCMP8TO16I_H_
|
||||
#define COSMOPOLITAN_LIBC_STR_STRCMP8TO16I_H_
|
||||
#include "libc/conv/conv.h"
|
||||
#include "libc/str/oldutf16.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/str/tpdecode.h"
|
||||
#include "libc/str/tpdecode.internal.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
|
@ -17,7 +17,7 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/nexgen32e/hascharacter.h"
|
||||
#include "libc/nexgen32e/hascharacter.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
/**
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/nexgen32e/hascharacter.h"
|
||||
#include "libc/nexgen32e/hascharacter.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
/**
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
/**
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
/**
|
||||
|
|
|
@ -17,14 +17,15 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/assert.h"
|
||||
#include "libc/str/internal.h"
|
||||
#include "libc/str/strcmp8to16i.h"
|
||||
#include "libc/str/strcmp8to16i.internal.h"
|
||||
|
||||
/**
|
||||
* Compares UTF-8 and UTF-16 strings, ignoring case, with limit.
|
||||
*/
|
||||
int strncasecmp8to16(const char *s1, const char16_t *s2, size_t n) {
|
||||
assume(n != -1ul);
|
||||
assert(n != -1ul);
|
||||
return strcmp8to16i(s1, s2, n, towlower);
|
||||
}
|
||||
|
||||
|
|
|
@ -17,16 +17,19 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/assert.h"
|
||||
#include "libc/str/internal.h"
|
||||
#include "libc/str/strcmp8to16i.h"
|
||||
#include "libc/str/strcmp8to16i.internal.h"
|
||||
|
||||
forceinline unsigned identity32u(unsigned x) { return x; }
|
||||
forceinline unsigned identity32u(unsigned x) {
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares UTF-8 and UTF-16 strings, with limit.
|
||||
*/
|
||||
int strncmp8to16(const char *s1, const char16_t *s2, size_t n) {
|
||||
assume(n != -1ul);
|
||||
assert(n != -1ul);
|
||||
return strcmp8to16i(s1, s2, n, identity32u);
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/nexgen32e/hascharacter.h"
|
||||
#include "libc/nexgen32e/hascharacter.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
/**
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/nexgen32e/hascharacter.h"
|
||||
#include "libc/nexgen32e/hascharacter.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
#undef strpbrk
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/nexgen32e/hascharacter.h"
|
||||
#include "libc/nexgen32e/hascharacter.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
/**
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/nexgen32e/hascharacter.h"
|
||||
#include "libc/nexgen32e/hascharacter.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
#undef strspn
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/str/tinymemccpy.h"
|
||||
|
||||
void *tinymemccpy(void *dst, const void *src, int termchar, size_t limit) {
|
||||
size_t i;
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_STR_TINYMEMCCPY_H_
|
||||
#define COSMOPOLITAN_LIBC_STR_TINYMEMCCPY_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
void *tinymemccpy(void *, const void *, int, size_t);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_STR_TINYMEMCCPY_H_ */
|
|
@ -18,7 +18,7 @@
|
|||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/str/tinymemmem.h"
|
||||
#include "libc/str/tinymemmem.internal.h"
|
||||
|
||||
/**
|
||||
* Naïve substring search implementation.
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/str/internal.h"
|
||||
#include "libc/str/tinystrstr.h"
|
||||
#include "libc/str/tinystrstr.internal.h"
|
||||
|
||||
/**
|
||||
* Naïve substring search implementation.
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/str/internal.h"
|
||||
#include "libc/str/tinystrstr.h"
|
||||
#include "libc/str/tinystrstr.internal.h"
|
||||
|
||||
/**
|
||||
* Naïve substring search implementation.
|
||||
|
|
|
@ -19,8 +19,8 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/errno.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/str/tpdecode.h"
|
||||
#include "libc/str/tpdecodecb.h"
|
||||
#include "libc/str/tpdecode.internal.h"
|
||||
#include "libc/str/tpdecodecb.internal.h"
|
||||
|
||||
forceinline int getbyte(void *arg, uint32_t i) {
|
||||
return ((const unsigned char *)arg)[i];
|
||||
|
@ -32,7 +32,7 @@ forceinline int getbyte(void *arg, uint32_t i) {
|
|||
* @param s is a NUL-terminated string
|
||||
* @return number of bytes successfully consumed or -1 w/ errno
|
||||
* @note synchronization is performed
|
||||
* @see libc/str/tpdecodecb.h (for implementation)
|
||||
* @see libc/str/tpdecodecb.internal.h (for implementation)
|
||||
*/
|
||||
int(tpdecode)(const char *s, wint_t *out) {
|
||||
return tpdecodecb(out, (unsigned char)s[0], getbyte, (void *)s);
|
||||
|
|
|
@ -1,56 +0,0 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#ifndef COSMOPOLITAN_LIBC_STR_TPDECODECB_H_
|
||||
#define COSMOPOLITAN_LIBC_STR_TPDECODECB_H_
|
||||
#include "libc/nexgen32e/bsr.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
|
||||
/**
|
||||
* Generic Thompson-Pike Varint Decoder.
|
||||
* @return number of bytes successfully consumed or -1 w/ errno
|
||||
* @note synchronization is performed
|
||||
*/
|
||||
forceinline int tpdecodecb(wint_t *out, int first,
|
||||
int get(void *arg, uint32_t i), void *arg) {
|
||||
uint32_t wc, cb, need, msb, j, i = 1;
|
||||
if (unlikely((wc = first) == -1)) return -1;
|
||||
while (unlikely((wc & 0b11000000) == 0b10000000)) {
|
||||
if ((wc = get(arg, i++)) == -1) return -1;
|
||||
}
|
||||
if (unlikely(!(0 <= wc && wc <= 0x7F))) {
|
||||
msb = wc < 252 ? bsr(~wc & 0xff) : 1;
|
||||
need = 7 - msb;
|
||||
wc &= ((1u << msb) - 1) | 0b00000011;
|
||||
for (j = 1; j < need; ++j) {
|
||||
if ((cb = get(arg, i++)) == -1) return -1;
|
||||
if ((cb & 0b11000000) == 0b10000000) {
|
||||
wc = wc << 6 | (cb & 0b00111111);
|
||||
} else {
|
||||
if (out) *out = u'<EFBFBD>';
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (likely(out)) *out = (wint_t)wc;
|
||||
return i;
|
||||
}
|
||||
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_STR_TPDECODECB_H_ */
|
38
libc/str/tpdecodecb.internal.h
Normal file
38
libc/str/tpdecodecb.internal.h
Normal file
|
@ -0,0 +1,38 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_STR_TPDECODECB_H_
|
||||
#define COSMOPOLITAN_LIBC_STR_TPDECODECB_H_
|
||||
#include "libc/nexgen32e/bsr.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
|
||||
/**
|
||||
* Generic Thompson-Pike Varint Decoder.
|
||||
* @return number of bytes successfully consumed or -1 w/ errno
|
||||
* @note synchronization is performed
|
||||
* @todo delete
|
||||
*/
|
||||
forceinline int tpdecodecb(wint_t *out, int first,
|
||||
int get(void *arg, uint32_t i), void *arg) {
|
||||
uint32_t wc, cb, need, msb, j, i = 1;
|
||||
if (unlikely((wc = first) == -1)) return -1;
|
||||
while (unlikely((wc & 0b11000000) == 0b10000000)) {
|
||||
if ((wc = get(arg, i++)) == -1) return -1;
|
||||
}
|
||||
if (unlikely(!(0 <= wc && wc <= 0x7F))) {
|
||||
msb = wc < 252 ? bsr(~wc & 0xff) : 1;
|
||||
need = 7 - msb;
|
||||
wc &= ((1u << msb) - 1) | 0b00000011;
|
||||
for (j = 1; j < need; ++j) {
|
||||
if ((cb = get(arg, i++)) == -1) return -1;
|
||||
if ((cb & 0b11000000) == 0b10000000) {
|
||||
wc = wc << 6 | (cb & 0b00111111);
|
||||
} else {
|
||||
if (out) *out = u'<EFBFBD>';
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (likely(out)) *out = (wint_t)wc;
|
||||
return i;
|
||||
}
|
||||
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_STR_TPDECODECB_H_ */
|
|
@ -19,7 +19,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/str/internal.h"
|
||||
#include "libc/str/tpenc.h"
|
||||
#include "libc/str/tpencode.h"
|
||||
#include "libc/str/tpencode.internal.h"
|
||||
|
||||
/**
|
||||
* Thompson-Pike Varint Encoder.
|
||||
|
|
|
@ -5,6 +5,9 @@
|
|||
#define UTF16_MOAR 0xd800 /* 0xD800..0xDBFF */
|
||||
#define UTF16_CONT 0xdc00 /* 0xDC00..0xDBFF */
|
||||
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
#define IsUcs2(wc) (((wc)&UTF16_MASK) != UTF16_MOAR)
|
||||
#define IsUtf16Cont(wc) (((wc)&UTF16_MASK) == UTF16_CONT)
|
||||
#define MergeUtf16(lo, hi) ((((lo)-0xD800) << 10) + ((hi)-0xDC00) + 0x10000)
|
||||
|
@ -17,4 +20,8 @@
|
|||
((((wc)-0x10000) & 1023) + 0xDC00) << 16) \
|
||||
: 0xFFFD)
|
||||
|
||||
wint_t DecodeNtsUtf16(const char16_t **);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_STR_UTF16_H_ */
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/limits.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/str/tpencode.h"
|
||||
#include "libc/str/tpencode.internal.h"
|
||||
|
||||
size_t wcrtomb(char *s, wchar_t wc, mbstate_t *st) {
|
||||
if (!s) return 1;
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/nexgen32e/hascharacter.h"
|
||||
#include "libc/nexgen32e/hascharacter.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
/**
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/nexgen32e/hascharacter.h"
|
||||
#include "libc/nexgen32e/hascharacter.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
#undef strpbrk
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/conv/conv.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/str/tpencode.h"
|
||||
#include "libc/str/tpencode.internal.h"
|
||||
|
||||
size_t wcsrtombs(char *dest, const wchar_t **src, size_t len, mbstate_t *ps) {
|
||||
/* TODO(jart): broken */
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/nexgen32e/hascharacter.h"
|
||||
#include "libc/nexgen32e/hascharacter.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
#undef strspn
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/limits.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/str/tpencode.h"
|
||||
#include "libc/str/tpencode.internal.h"
|
||||
|
||||
int wctomb(char *s, wchar_t wc) {
|
||||
if (!s) return 0;
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/bigword.h"
|
||||
#include "libc/bits/bigword.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
#define T wchar_t
|
||||
#define N (BIGWORD / sizeof(T))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue