mirror of
https://github.com/UzixLS/KernelEx.git
synced 2025-07-18 23:11:19 +03:00
import KernelEx-4.0-RC1
This commit is contained in:
73
kexcrt/LICENSE
Normal file
73
kexcrt/LICENSE
Normal file
@ -0,0 +1,73 @@
|
||||
This license applies to all files in directory and its subdirectories,
|
||||
unless otherwise noted in individual files.
|
||||
|
||||
|
||||
Some files are derived from files derived from the include/ directory
|
||||
of the Linux kernel, and are licensed under the terms of the GNU
|
||||
General Public License, version 2, as released by the Free Software
|
||||
Foundation, Inc.; incorporated herein by reference.
|
||||
|
||||
-----
|
||||
|
||||
Some files are derived from files copyrighted by the Regents of The
|
||||
University of California, and are available under the following
|
||||
license:
|
||||
|
||||
Note: The advertising clause in the license appearing on BSD Unix
|
||||
files was officially rescinded by the Director of the Office of
|
||||
Technology Licensing of the University of California on July 22
|
||||
1999. He states that clause 3 is "hereby deleted in its entirety."
|
||||
|
||||
* Copyright (c)
|
||||
* The Regents of the University of California. 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 acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
||||
|
||||
-----
|
||||
|
||||
For all remaining files, the following license applies:
|
||||
|
||||
* 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:
|
||||
*
|
||||
* Any copyright notice(s) 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.
|
80
kexcrt/README
Normal file
80
kexcrt/README
Normal file
@ -0,0 +1,80 @@
|
||||
This is klibc, what is intended to be a minimalistic libc subset for
|
||||
use with initramfs. It is deliberately written for small size,
|
||||
minimal entaglement, and portability, not speed. It is definitely a
|
||||
work in progress, and a lot of things are still missing.
|
||||
|
||||
|
||||
The build procedure is not very polished yet, but it should work like
|
||||
this:
|
||||
|
||||
a) In the source root directory (the directory above the one in which
|
||||
this file is found) create a symlink called "linux" pointing to a
|
||||
reasonably recent Linux kernel tree (2.4 or 2.6 should be OK.)
|
||||
This tree must have the include/asm symlink set up for the
|
||||
architecture you're compiling for, and include/linux/autoconf.h
|
||||
must exist. The easiest way to make sure of all of these is to do
|
||||
a "make config" or any of its variants on the kernel tree is
|
||||
question, followed by a "make dep" (2.4) or "make prepare" (2.6).
|
||||
|
||||
b) If you're cross-compiling, you need to set KLIBCARCH to the
|
||||
appropriate architecture, and set CROSS_COMPILE to your toolchain
|
||||
prefix.
|
||||
|
||||
IMPORTANT: if you're on a 64-bit machine with a 32-bit userland
|
||||
(ia64, mips64, ppc64 sparc64, s390x or x86_64), and you want to
|
||||
build the 32-bit version: you need to set KLIBCARCH to the 32-bit
|
||||
architecture as well as set up the linux/include/asm symlink to
|
||||
point to the 32-bit architecture. Building the 32-bit architecture
|
||||
usually (but not always) produces smaller binaries, and is likely
|
||||
to be better tested.
|
||||
|
||||
If you are on ARM, and want to build a thumb version of the library
|
||||
(this is supported), change OPTFLAGS in arch/arm/MCONFIG to build
|
||||
thumb code.
|
||||
|
||||
The following is the last known status of various architectures:
|
||||
|
||||
alpha: Working
|
||||
arm-thumb: Untested
|
||||
arm: Working
|
||||
arm26: Not yet ported
|
||||
cris: Working
|
||||
h8300: Not yet ported
|
||||
i386: Working
|
||||
ia64: Working
|
||||
m32r: Untested
|
||||
m68k: Untested
|
||||
m68knommu: Not yet ported
|
||||
mips: Working
|
||||
mips64: Not yet ported
|
||||
parisc: Working
|
||||
parisc64: Not yet ported
|
||||
ppc: Working
|
||||
ppc64: Working
|
||||
s390: Working static, shared untested
|
||||
s390x: Working
|
||||
sh: Untested
|
||||
sh64: Not yet ported
|
||||
sparc: Working
|
||||
sparc64: Untested
|
||||
v850: Not yet ported
|
||||
x86-64: Working
|
||||
xtensa: Not yet ported
|
||||
|
||||
Shared library support requires recent binutils on many
|
||||
architectures.
|
||||
|
||||
Note that even the "working" ones likely have bugs. Please report
|
||||
them if you run into them.
|
||||
|
||||
c) Type "make" and pray...
|
||||
|
||||
d) Try the test programs in the tests/ directory. They should run...
|
||||
|
||||
Contact the klibc mailing list:
|
||||
|
||||
http://www.zytor.com/mailman/listinfo/klibc
|
||||
|
||||
... for more info.
|
||||
|
||||
-hpa
|
7
kexcrt/_vsnprintf.c
Normal file
7
kexcrt/_vsnprintf.c
Normal file
@ -0,0 +1,7 @@
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int _vsnprintf(char *buffer, size_t n, const char *format, va_list ap)
|
||||
{
|
||||
return vsnprintf(buffer, n, format, ap);
|
||||
}
|
3
kexcrt/atoi.c
Normal file
3
kexcrt/atoi.c
Normal file
@ -0,0 +1,3 @@
|
||||
#define TYPE int
|
||||
#define NAME atoi
|
||||
#include "atox.c"
|
3
kexcrt/atol.c
Normal file
3
kexcrt/atol.c
Normal file
@ -0,0 +1,3 @@
|
||||
#define TYPE long
|
||||
#define NAME atol
|
||||
#include "atox.c"
|
3
kexcrt/atoll.c
Normal file
3
kexcrt/atoll.c
Normal file
@ -0,0 +1,3 @@
|
||||
#define TYPE int64_t
|
||||
#define NAME atoll
|
||||
#include "atox.c"
|
14
kexcrt/atox.c
Normal file
14
kexcrt/atox.c
Normal file
@ -0,0 +1,14 @@
|
||||
/*
|
||||
* atox.c
|
||||
*
|
||||
* atoi(), atol(), atoll()
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
TYPE NAME(const char *nptr)
|
||||
{
|
||||
return (TYPE) strntoumax(nptr, (char **)NULL, 10, ~(size_t) 0);
|
||||
}
|
13
kexcrt/ctype/ctypefunc.h
Normal file
13
kexcrt/ctype/ctypefunc.h
Normal file
@ -0,0 +1,13 @@
|
||||
/*
|
||||
* ctype/ctype.h
|
||||
*
|
||||
* Common header for out-of-line ctype functions
|
||||
*/
|
||||
|
||||
#define __CTYPE_NO_INLINE
|
||||
#include "ctypes.h"
|
||||
|
||||
#define CTYPEFUNC(X) \
|
||||
int X(int c) { \
|
||||
return __ctype_##X(c); \
|
||||
}
|
2
kexcrt/ctype/isalnum.c
Normal file
2
kexcrt/ctype/isalnum.c
Normal file
@ -0,0 +1,2 @@
|
||||
#include "ctypefunc.h"
|
||||
CTYPEFUNC(isalnum)
|
2
kexcrt/ctype/isalpha.c
Normal file
2
kexcrt/ctype/isalpha.c
Normal file
@ -0,0 +1,2 @@
|
||||
#include "ctypefunc.h"
|
||||
CTYPEFUNC(isalpha)
|
2
kexcrt/ctype/isascii.c
Normal file
2
kexcrt/ctype/isascii.c
Normal file
@ -0,0 +1,2 @@
|
||||
#include "ctypefunc.h"
|
||||
CTYPEFUNC(isascii)
|
2
kexcrt/ctype/isblank.c
Normal file
2
kexcrt/ctype/isblank.c
Normal file
@ -0,0 +1,2 @@
|
||||
#include "ctypefunc.h"
|
||||
CTYPEFUNC(isblank)
|
2
kexcrt/ctype/iscntrl.c
Normal file
2
kexcrt/ctype/iscntrl.c
Normal file
@ -0,0 +1,2 @@
|
||||
#include "ctypefunc.h"
|
||||
CTYPEFUNC(iscntrl)
|
2
kexcrt/ctype/isdigit.c
Normal file
2
kexcrt/ctype/isdigit.c
Normal file
@ -0,0 +1,2 @@
|
||||
#include "ctypefunc.h"
|
||||
CTYPEFUNC(isdigit)
|
2
kexcrt/ctype/isgraph.c
Normal file
2
kexcrt/ctype/isgraph.c
Normal file
@ -0,0 +1,2 @@
|
||||
#include "ctypefunc.h"
|
||||
CTYPEFUNC(isgraph)
|
2
kexcrt/ctype/islower.c
Normal file
2
kexcrt/ctype/islower.c
Normal file
@ -0,0 +1,2 @@
|
||||
#include "ctypefunc.h"
|
||||
CTYPEFUNC(islower)
|
2
kexcrt/ctype/isprint.c
Normal file
2
kexcrt/ctype/isprint.c
Normal file
@ -0,0 +1,2 @@
|
||||
#include "ctypefunc.h"
|
||||
CTYPEFUNC(isprint)
|
2
kexcrt/ctype/ispunct.c
Normal file
2
kexcrt/ctype/ispunct.c
Normal file
@ -0,0 +1,2 @@
|
||||
#include "ctypefunc.h"
|
||||
CTYPEFUNC(ispunct)
|
2
kexcrt/ctype/isspace.c
Normal file
2
kexcrt/ctype/isspace.c
Normal file
@ -0,0 +1,2 @@
|
||||
#include "ctypefunc.h"
|
||||
CTYPEFUNC(isspace)
|
2
kexcrt/ctype/isupper.c
Normal file
2
kexcrt/ctype/isupper.c
Normal file
@ -0,0 +1,2 @@
|
||||
#include "ctypefunc.h"
|
||||
CTYPEFUNC(isupper)
|
2
kexcrt/ctype/isxdigit.c
Normal file
2
kexcrt/ctype/isxdigit.c
Normal file
@ -0,0 +1,2 @@
|
||||
#include "ctypefunc.h"
|
||||
CTYPEFUNC(isxdigit)
|
2
kexcrt/ctype/tolower.c
Normal file
2
kexcrt/ctype/tolower.c
Normal file
@ -0,0 +1,2 @@
|
||||
#include "ctypefunc.h"
|
||||
CTYPEFUNC(tolower)
|
2
kexcrt/ctype/toupper.c
Normal file
2
kexcrt/ctype/toupper.c
Normal file
@ -0,0 +1,2 @@
|
||||
#include "ctypefunc.h"
|
||||
CTYPEFUNC(toupper)
|
284
kexcrt/ctypes.c
Normal file
284
kexcrt/ctypes.c
Normal file
@ -0,0 +1,284 @@
|
||||
/*
|
||||
* ctypes.c
|
||||
*
|
||||
* This is the array that defines <ctype.h> classes.
|
||||
* This assumes ISO 8859-1.
|
||||
*/
|
||||
|
||||
#include "ctypes.h"
|
||||
|
||||
const unsigned char __ctypes[257] = {
|
||||
0, /* EOF */
|
||||
|
||||
__ctype_cntrl, /* control character */
|
||||
__ctype_cntrl, /* control character */
|
||||
__ctype_cntrl, /* control character */
|
||||
__ctype_cntrl, /* control character */
|
||||
__ctype_cntrl, /* control character */
|
||||
__ctype_cntrl, /* control character */
|
||||
__ctype_cntrl, /* control character */
|
||||
__ctype_cntrl, /* control character */
|
||||
__ctype_cntrl | __ctype_space, /* BS */
|
||||
__ctype_cntrl | __ctype_space, /* TAB */
|
||||
__ctype_cntrl | __ctype_space, /* LF */
|
||||
__ctype_cntrl | __ctype_space, /* VT */
|
||||
__ctype_cntrl | __ctype_space, /* FF */
|
||||
__ctype_cntrl | __ctype_space, /* CR */
|
||||
__ctype_cntrl, /* control character */
|
||||
|
||||
__ctype_cntrl, /* control character */
|
||||
__ctype_cntrl, /* control character */
|
||||
__ctype_cntrl, /* control character */
|
||||
__ctype_cntrl, /* control character */
|
||||
__ctype_cntrl, /* control character */
|
||||
__ctype_cntrl, /* control character */
|
||||
__ctype_cntrl, /* control character */
|
||||
__ctype_cntrl, /* control character */
|
||||
__ctype_cntrl, /* control character */
|
||||
__ctype_cntrl, /* control character */
|
||||
__ctype_cntrl, /* control character */
|
||||
__ctype_cntrl, /* control character */
|
||||
__ctype_cntrl, /* control character */
|
||||
__ctype_cntrl, /* control character */
|
||||
__ctype_cntrl, /* control character */
|
||||
__ctype_cntrl, /* control character */
|
||||
__ctype_cntrl, /* control character */
|
||||
|
||||
__ctype_print | __ctype_space, /* space */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
|
||||
__ctype_print | __ctype_digit | __ctype_xdigit, /* digit */
|
||||
__ctype_print | __ctype_digit | __ctype_xdigit, /* digit */
|
||||
__ctype_print | __ctype_digit | __ctype_xdigit, /* digit */
|
||||
__ctype_print | __ctype_digit | __ctype_xdigit, /* digit */
|
||||
__ctype_print | __ctype_digit | __ctype_xdigit, /* digit */
|
||||
__ctype_print | __ctype_digit | __ctype_xdigit, /* digit */
|
||||
__ctype_print | __ctype_digit | __ctype_xdigit, /* digit */
|
||||
__ctype_print | __ctype_digit | __ctype_xdigit, /* digit */
|
||||
__ctype_print | __ctype_digit | __ctype_xdigit, /* digit */
|
||||
__ctype_print | __ctype_digit | __ctype_xdigit, /* digit */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_upper | __ctype_xdigit, /* A-F */
|
||||
__ctype_print | __ctype_upper | __ctype_xdigit, /* A-F */
|
||||
__ctype_print | __ctype_upper | __ctype_xdigit, /* A-F */
|
||||
__ctype_print | __ctype_upper | __ctype_xdigit, /* A-F */
|
||||
__ctype_print | __ctype_upper | __ctype_xdigit, /* A-F */
|
||||
__ctype_print | __ctype_upper | __ctype_xdigit, /* A-F */
|
||||
__ctype_print | __ctype_upper, /* G-Z */
|
||||
__ctype_print | __ctype_upper, /* G-Z */
|
||||
__ctype_print | __ctype_upper, /* G-Z */
|
||||
__ctype_print | __ctype_upper, /* G-Z */
|
||||
__ctype_print | __ctype_upper, /* G-Z */
|
||||
__ctype_print | __ctype_upper, /* G-Z */
|
||||
__ctype_print | __ctype_upper, /* G-Z */
|
||||
__ctype_print | __ctype_upper, /* G-Z */
|
||||
__ctype_print | __ctype_upper, /* G-Z */
|
||||
|
||||
__ctype_print | __ctype_upper, /* G-Z */
|
||||
__ctype_print | __ctype_upper, /* G-Z */
|
||||
__ctype_print | __ctype_upper, /* G-Z */
|
||||
__ctype_print | __ctype_upper, /* G-Z */
|
||||
__ctype_print | __ctype_upper, /* G-Z */
|
||||
__ctype_print | __ctype_upper, /* G-Z */
|
||||
__ctype_print | __ctype_upper, /* G-Z */
|
||||
__ctype_print | __ctype_upper, /* G-Z */
|
||||
__ctype_print | __ctype_upper, /* G-Z */
|
||||
__ctype_print | __ctype_upper, /* G-Z */
|
||||
__ctype_print | __ctype_upper, /* G-Z */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_lower | __ctype_xdigit, /* a-f */
|
||||
__ctype_print | __ctype_lower | __ctype_xdigit, /* a-f */
|
||||
__ctype_print | __ctype_lower | __ctype_xdigit, /* a-f */
|
||||
__ctype_print | __ctype_lower | __ctype_xdigit, /* a-f */
|
||||
__ctype_print | __ctype_lower | __ctype_xdigit, /* a-f */
|
||||
__ctype_print | __ctype_lower | __ctype_xdigit, /* a-f */
|
||||
__ctype_print | __ctype_lower, /* g-z */
|
||||
__ctype_print | __ctype_lower, /* g-z */
|
||||
__ctype_print | __ctype_lower, /* g-z */
|
||||
__ctype_print | __ctype_lower, /* g-z */
|
||||
__ctype_print | __ctype_lower, /* g-z */
|
||||
__ctype_print | __ctype_lower, /* g-z */
|
||||
__ctype_print | __ctype_lower, /* g-z */
|
||||
__ctype_print | __ctype_lower, /* g-z */
|
||||
__ctype_print | __ctype_lower, /* g-z */
|
||||
|
||||
__ctype_print | __ctype_lower, /* g-z */
|
||||
__ctype_print | __ctype_lower, /* g-z */
|
||||
__ctype_print | __ctype_lower, /* g-z */
|
||||
__ctype_print | __ctype_lower, /* g-z */
|
||||
__ctype_print | __ctype_lower, /* g-z */
|
||||
__ctype_print | __ctype_lower, /* g-z */
|
||||
__ctype_print | __ctype_lower, /* g-z */
|
||||
__ctype_print | __ctype_lower, /* g-z */
|
||||
__ctype_print | __ctype_lower, /* g-z */
|
||||
__ctype_print | __ctype_lower, /* g-z */
|
||||
__ctype_print | __ctype_lower, /* g-z */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_cntrl, /* control character */
|
||||
|
||||
__ctype_cntrl, /* control character */
|
||||
__ctype_cntrl, /* control character */
|
||||
__ctype_cntrl, /* control character */
|
||||
__ctype_cntrl, /* control character */
|
||||
__ctype_cntrl, /* control character */
|
||||
__ctype_cntrl, /* control character */
|
||||
__ctype_cntrl, /* control character */
|
||||
__ctype_cntrl, /* control character */
|
||||
__ctype_cntrl, /* control character */
|
||||
__ctype_cntrl, /* control character */
|
||||
__ctype_cntrl, /* control character */
|
||||
__ctype_cntrl, /* control character */
|
||||
__ctype_cntrl, /* control character */
|
||||
__ctype_cntrl, /* control character */
|
||||
__ctype_cntrl, /* control character */
|
||||
__ctype_cntrl, /* control character */
|
||||
|
||||
__ctype_cntrl, /* control character */
|
||||
__ctype_cntrl, /* control character */
|
||||
__ctype_cntrl, /* control character */
|
||||
__ctype_cntrl, /* control character */
|
||||
__ctype_cntrl, /* control character */
|
||||
__ctype_cntrl, /* control character */
|
||||
__ctype_cntrl, /* control character */
|
||||
__ctype_cntrl, /* control character */
|
||||
__ctype_cntrl, /* control character */
|
||||
__ctype_cntrl, /* control character */
|
||||
__ctype_cntrl, /* control character */
|
||||
__ctype_cntrl, /* control character */
|
||||
__ctype_cntrl, /* control character */
|
||||
__ctype_cntrl, /* control character */
|
||||
__ctype_cntrl, /* control character */
|
||||
__ctype_cntrl, /* control character */
|
||||
|
||||
__ctype_print | __ctype_space, /* NBSP */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
|
||||
__ctype_print | __ctype_upper, /* upper accented */
|
||||
__ctype_print | __ctype_upper, /* upper accented */
|
||||
__ctype_print | __ctype_upper, /* upper accented */
|
||||
__ctype_print | __ctype_upper, /* upper accented */
|
||||
__ctype_print | __ctype_upper, /* upper accented */
|
||||
__ctype_print | __ctype_upper, /* upper accented */
|
||||
__ctype_print | __ctype_upper, /* upper accented */
|
||||
__ctype_print | __ctype_upper, /* upper accented */
|
||||
__ctype_print | __ctype_upper, /* upper accented */
|
||||
__ctype_print | __ctype_upper, /* upper accented */
|
||||
__ctype_print | __ctype_upper, /* upper accented */
|
||||
__ctype_print | __ctype_upper, /* upper accented */
|
||||
__ctype_print | __ctype_upper, /* upper accented */
|
||||
__ctype_print | __ctype_upper, /* upper accented */
|
||||
__ctype_print | __ctype_upper, /* upper accented */
|
||||
__ctype_print | __ctype_upper, /* upper accented */
|
||||
|
||||
__ctype_print | __ctype_upper, /* upper accented */
|
||||
__ctype_print | __ctype_upper, /* upper accented */
|
||||
__ctype_print | __ctype_upper, /* upper accented */
|
||||
__ctype_print | __ctype_upper, /* upper accented */
|
||||
__ctype_print | __ctype_upper, /* upper accented */
|
||||
__ctype_print | __ctype_upper, /* upper accented */
|
||||
__ctype_print | __ctype_upper, /* upper accented */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_upper, /* upper accented */
|
||||
__ctype_print | __ctype_upper, /* upper accented */
|
||||
__ctype_print | __ctype_upper, /* upper accented */
|
||||
__ctype_print | __ctype_upper, /* upper accented */
|
||||
__ctype_print | __ctype_upper, /* upper accented */
|
||||
__ctype_print | __ctype_upper, /* upper accented */
|
||||
__ctype_print | __ctype_upper, /* upper accented */
|
||||
__ctype_print | __ctype_lower, /* lower accented */
|
||||
|
||||
__ctype_print | __ctype_lower, /* lower accented */
|
||||
__ctype_print | __ctype_lower, /* lower accented */
|
||||
__ctype_print | __ctype_lower, /* lower accented */
|
||||
__ctype_print | __ctype_lower, /* lower accented */
|
||||
__ctype_print | __ctype_lower, /* lower accented */
|
||||
__ctype_print | __ctype_lower, /* lower accented */
|
||||
__ctype_print | __ctype_lower, /* lower accented */
|
||||
__ctype_print | __ctype_lower, /* lower accented */
|
||||
__ctype_print | __ctype_lower, /* lower accented */
|
||||
__ctype_print | __ctype_lower, /* lower accented */
|
||||
__ctype_print | __ctype_lower, /* lower accented */
|
||||
__ctype_print | __ctype_lower, /* lower accented */
|
||||
__ctype_print | __ctype_lower, /* lower accented */
|
||||
__ctype_print | __ctype_lower, /* lower accented */
|
||||
__ctype_print | __ctype_lower, /* lower accented */
|
||||
__ctype_print | __ctype_lower, /* lower accented */
|
||||
|
||||
__ctype_print | __ctype_lower, /* lower accented */
|
||||
__ctype_print | __ctype_lower, /* lower accented */
|
||||
__ctype_print | __ctype_lower, /* lower accented */
|
||||
__ctype_print | __ctype_lower, /* lower accented */
|
||||
__ctype_print | __ctype_lower, /* lower accented */
|
||||
__ctype_print | __ctype_lower, /* lower accented */
|
||||
__ctype_print | __ctype_lower, /* lower accented */
|
||||
__ctype_print | __ctype_punct, /* punctuation */
|
||||
__ctype_print | __ctype_lower, /* lower accented */
|
||||
__ctype_print | __ctype_lower, /* lower accented */
|
||||
__ctype_print | __ctype_lower, /* lower accented */
|
||||
__ctype_print | __ctype_lower, /* lower accented */
|
||||
__ctype_print | __ctype_lower, /* lower accented */
|
||||
__ctype_print | __ctype_lower, /* lower accented */
|
||||
__ctype_print | __ctype_lower, /* lower accented */
|
||||
__ctype_print | __ctype_lower, /* lower accented */
|
||||
};
|
134
kexcrt/ctypes.h
Normal file
134
kexcrt/ctypes.h
Normal file
@ -0,0 +1,134 @@
|
||||
/*
|
||||
* ctype.h
|
||||
*
|
||||
* This assumes ISO 8859-1, being a reasonable superset of ASCII.
|
||||
*/
|
||||
|
||||
#ifndef _CTYPE_H
|
||||
#define _CTYPE_H
|
||||
|
||||
#if defined( _MSC_VER ) && !defined( __cplusplus )
|
||||
# define inline __inline
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This relies on the following definitions:
|
||||
*
|
||||
* cntrl = !print
|
||||
* alpha = upper|lower
|
||||
* graph = punct|alpha|digit
|
||||
* blank = '\t' || ' ' (per POSIX requirement)
|
||||
*/
|
||||
enum {
|
||||
__ctype_upper = (1 << 0),
|
||||
__ctype_lower = (1 << 1),
|
||||
__ctype_digit = (1 << 2),
|
||||
__ctype_xdigit = (1 << 3),
|
||||
__ctype_space = (1 << 4),
|
||||
__ctype_print = (1 << 5),
|
||||
__ctype_punct = (1 << 6),
|
||||
__ctype_cntrl = (1 << 7),
|
||||
};
|
||||
|
||||
extern const unsigned char __ctypes[];
|
||||
|
||||
static inline int __ctype_isalnum(int __c)
|
||||
{
|
||||
return __ctypes[__c + 1] &
|
||||
(__ctype_upper | __ctype_lower | __ctype_digit);
|
||||
}
|
||||
|
||||
static inline int __ctype_isalpha(int __c)
|
||||
{
|
||||
return __ctypes[__c + 1] & (__ctype_upper | __ctype_lower);
|
||||
}
|
||||
|
||||
static inline int __ctype_isascii(int __c)
|
||||
{
|
||||
return !(__c & ~0x7f);
|
||||
}
|
||||
|
||||
static inline int __ctype_isblank(int __c)
|
||||
{
|
||||
return (__c == '\t') || (__c == ' ');
|
||||
}
|
||||
|
||||
static inline int __ctype_iscntrl(int __c)
|
||||
{
|
||||
return __ctypes[__c + 1] & __ctype_cntrl;
|
||||
}
|
||||
|
||||
static inline int __ctype_isdigit(int __c)
|
||||
{
|
||||
return ((unsigned)__c - '0') <= 9;
|
||||
}
|
||||
|
||||
static inline int __ctype_isgraph(int __c)
|
||||
{
|
||||
return __ctypes[__c + 1] &
|
||||
(__ctype_upper | __ctype_lower | __ctype_digit | __ctype_punct);
|
||||
}
|
||||
|
||||
static inline int __ctype_islower(int __c)
|
||||
{
|
||||
return __ctypes[__c + 1] & __ctype_lower;
|
||||
}
|
||||
|
||||
static inline int __ctype_isprint(int __c)
|
||||
{
|
||||
return __ctypes[__c + 1] & __ctype_print;
|
||||
}
|
||||
|
||||
static inline int __ctype_ispunct(int __c)
|
||||
{
|
||||
return __ctypes[__c + 1] & __ctype_punct;
|
||||
}
|
||||
|
||||
static inline int __ctype_isspace(int __c)
|
||||
{
|
||||
return __ctypes[__c + 1] & __ctype_space;
|
||||
}
|
||||
|
||||
static inline int __ctype_isupper(int __c)
|
||||
{
|
||||
return __ctypes[__c + 1] & __ctype_upper;
|
||||
}
|
||||
|
||||
static inline int __ctype_isxdigit(int __c)
|
||||
{
|
||||
return __ctypes[__c + 1] & __ctype_xdigit;
|
||||
}
|
||||
|
||||
/* Note: this is decimal, not hex, to avoid accidental promotion to unsigned */
|
||||
#define _toupper(__c) ((__c) & ~32)
|
||||
#define _tolower(__c) ((__c) | 32)
|
||||
|
||||
static inline int __ctype_toupper(int __c)
|
||||
{
|
||||
return __ctype_islower(__c) ? _toupper(__c) : __c;
|
||||
}
|
||||
|
||||
static inline int __ctype_tolower(int __c)
|
||||
{
|
||||
return __ctype_isupper(__c) ? _tolower(__c) : __c;
|
||||
}
|
||||
|
||||
# define __CTYPEFUNC(X) \
|
||||
extern int X(int);
|
||||
|
||||
__CTYPEFUNC(isalnum)
|
||||
__CTYPEFUNC(isalpha)
|
||||
__CTYPEFUNC(isascii)
|
||||
__CTYPEFUNC(isblank)
|
||||
__CTYPEFUNC(iscntrl)
|
||||
__CTYPEFUNC(isdigit)
|
||||
__CTYPEFUNC(isgraph)
|
||||
__CTYPEFUNC(islower)
|
||||
__CTYPEFUNC(isprint)
|
||||
__CTYPEFUNC(ispunct)
|
||||
__CTYPEFUNC(isspace)
|
||||
__CTYPEFUNC(isupper)
|
||||
__CTYPEFUNC(isxdigit)
|
||||
__CTYPEFUNC(toupper)
|
||||
__CTYPEFUNC(tolower)
|
||||
#endif /* _CTYPE_H */
|
341
kexcrt/kexcrt.dsp
Normal file
341
kexcrt/kexcrt.dsp
Normal file
@ -0,0 +1,341 @@
|
||||
# Microsoft Developer Studio Project File - Name="kexcrt" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Static Library" 0x0104
|
||||
|
||||
CFG=KEXCRT - WIN32 RELEASE
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "kexcrt.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "kexcrt.mak" CFG="KEXCRT - WIN32 RELEASE"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "kexcrt - Win32 Release" (based on "Win32 (x86) Static Library")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
RSC=rc.exe
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir ""
|
||||
# PROP Intermediate_Dir "obj"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
|
||||
# ADD CPP /nologo /O2 /I "." /I "msvc" /D "_CTYPE_DISABLE_MACROS" /FD /Oi- /c
|
||||
# ADD BASE RSC /l 0x415 /d "NDEBUG"
|
||||
# ADD RSC /l 0x415 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE LIB32 /nologo
|
||||
# ADD LIB32 /nologo
|
||||
# Begin Target
|
||||
|
||||
# Name "kexcrt - Win32 Release"
|
||||
# Begin Group "Source Files"
|
||||
|
||||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\_vsnprintf.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\msvc\argcargv.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\atoi.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\atol.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\atoll.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\msvc\concrt0.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ctypes.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\msvc\dllcrt0.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\msvc\init.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ctype\isalnum.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ctype\isalpha.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ctype\isascii.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ctype\isblank.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ctype\iscntrl.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ctype\isdigit.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ctype\isgraph.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ctype\islower.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ctype\isprint.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ctype\ispunct.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ctype\isspace.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ctype\isupper.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ctype\isxdigit.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\memccpy.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\memchr.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\memcmp.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\memcpy.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\memmem.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\memmove.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\memrchr.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\memset.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\memswap.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\snprintf.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\sprintf.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\sscanf.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\strcat.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\strchr.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\strcmp.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\strcmpi.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\strcpy.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\strlen.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\strncat.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\strncmp.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\strncpy.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\strnicmp.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\strnlen.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\strntoimax.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\strntoumax.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\strpbrk.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\strrchr.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\strsep.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\strstr.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\strtok.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\strtol.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\strtoll.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\strtoul.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\strtoull.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\strtoumax.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\strupr.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\strxspn.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ctype\tolower.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ctype\toupper.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\vsnprintf.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\vsprintf.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\vsscanf.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\msvc\wincrt0.c
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Header Files"
|
||||
|
||||
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\msvc\argcargv.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ctype\ctypefunc.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ctypes.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\msvc\init.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\strxspn.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# End Target
|
||||
# End Project
|
19
kexcrt/makefile
Normal file
19
kexcrt/makefile
Normal file
@ -0,0 +1,19 @@
|
||||
OBJ = atoi.o atol.o atoll.o ctypes.o memccpy.o memchr.o memcmp.o memcpy.o memmem.o memmove.o memrchr.o memset.o memswap.o snprintf.o sprintf.o sscanf.o strcat.o strchr.o strcmp.o strcmpi.o strcpy.o strlen.o strncat.o strncmp.o strncpy.o strnicmp.o strnlen.o strntoimax.o strntoumax.o strpbrk.o strrchr.o strsep.o strstr.o strtok.o strtol.o strtoll.o strtoul.o strtoull.o strtoumax.o strupr.o strxspn.o vsnprintf.o vsprintf.o vsscanf.o _vsnprintf.o \
|
||||
ctype/isalnum.o ctype/isalpha.o ctype/isascii.o ctype/isblank.o ctype/iscntrl.o ctype/isdigit.o ctype/isgraph.o ctype/islower.o ctype/isprint.o ctype/ispunct.o ctype/isspace.o ctype/isupper.o ctype/isxdigit.o ctype/tolower.o ctype/toupper.o
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -O2 -s -I. -D__NO_CTYPE_INLINES -D__NO_ISOCEXT
|
||||
|
||||
BIN = libkexcrt.a
|
||||
|
||||
all : $(BIN)
|
||||
|
||||
clean :
|
||||
@del *.o >NUL
|
||||
@del ctype\*.o >NUL
|
||||
|
||||
$(BIN) : $(OBJ)
|
||||
ar qcs $@ $(OBJ)
|
||||
|
||||
.c.o :
|
||||
$(CC) $(CFLAGS) -c -o $@ $<
|
21
kexcrt/makefile.msv
Normal file
21
kexcrt/makefile.msv
Normal file
@ -0,0 +1,21 @@
|
||||
OBJ = atoi.obj atol.obj atoll.obj ctypes.obj memccpy.obj memchr.obj memcmp.obj memcpy.obj memmem.obj memmove.obj memrchr.obj memset.obj memswap.obj snprintf.obj sprintf.obj sscanf.obj strcat.obj strchr.obj strcmp.obj strcmpi.obj strcpy.obj strlen.obj strncat.obj strncmp.obj strncpy.obj strnicmp.obj strnlen.obj strntoimax.obj strntoumax.obj strpbrk.obj strrchr.obj strsep.obj strstr.obj strtok.obj strtol.obj strtoll.obj strtoul.obj strtoull.obj strtoumax.obj strupr.obj strxspn.obj vsnprintf.obj vsprintf.obj vsscanf.obj _vsnprintf.obj \
|
||||
ctype/isalnum.obj ctype/isalpha.obj ctype/isascii.obj ctype/isblank.obj ctype/iscntrl.obj ctype/isdigit.obj ctype/isgraph.obj ctype/islower.obj ctype/isprint.obj ctype/ispunct.obj ctype/isspace.obj ctype/isupper.obj ctype/isxdigit.obj ctype/tolower.obj ctype/toupper.obj \
|
||||
msvc/init.obj msvc/dllcrt0.obj
|
||||
|
||||
CFLAGS = /O2 /Oi- /I. /nologo /D_CTYPE_DISABLE_MACROS
|
||||
|
||||
CC = cl
|
||||
BIN = kexcrt.lib
|
||||
|
||||
all : $(BIN)
|
||||
|
||||
clean :
|
||||
@del *.obj >NUL
|
||||
@del ctype\*.obj >NUL
|
||||
@del msvc\*.obj >NUL
|
||||
|
||||
$(BIN) : $(OBJ)
|
||||
link /LIB /NODEFAULTLIB /OUT:$@ $(OBJ)
|
||||
|
||||
.c.obj :
|
||||
$(CC) $(CFLAGS) /c /Fo$@ $<
|
23
kexcrt/memccpy.c
Normal file
23
kexcrt/memccpy.c
Normal file
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* memccpy.c
|
||||
*
|
||||
* memccpy()
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
void *memccpy(void *dst, const void *src, int c, size_t n)
|
||||
{
|
||||
char *q = dst;
|
||||
const char *p = src;
|
||||
char ch;
|
||||
|
||||
while (n--) {
|
||||
*q++ = ch = *p++;
|
||||
if (ch == (char)c)
|
||||
return q;
|
||||
}
|
||||
|
||||
return NULL; /* No instance of "c" found */
|
||||
}
|
19
kexcrt/memchr.c
Normal file
19
kexcrt/memchr.c
Normal file
@ -0,0 +1,19 @@
|
||||
/*
|
||||
* memchr.c
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
void *memchr(const void *s, int c, size_t n)
|
||||
{
|
||||
const unsigned char *sp = s;
|
||||
|
||||
while (n--) {
|
||||
if (*sp == (unsigned char)c)
|
||||
return (void *)sp;
|
||||
sp++;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
19
kexcrt/memcmp.c
Normal file
19
kexcrt/memcmp.c
Normal file
@ -0,0 +1,19 @@
|
||||
/*
|
||||
* memcmp.c
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
int memcmp(const void *s1, const void *s2, size_t n)
|
||||
{
|
||||
const unsigned char *c1 = s1, *c2 = s2;
|
||||
int d = 0;
|
||||
|
||||
while (n--) {
|
||||
d = (int)*c1++ - (int)*c2++;
|
||||
if (d)
|
||||
break;
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
28
kexcrt/memcpy.c
Normal file
28
kexcrt/memcpy.c
Normal file
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* memcpy.c
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
void *memcpy(void *dst, const void *src, size_t n)
|
||||
{
|
||||
const char *p = src;
|
||||
char *q = dst;
|
||||
#if defined(__i386__)
|
||||
size_t nl = n >> 2;
|
||||
asm volatile ("cld ; rep ; movsl ; movl %3,%0 ; rep ; movsb":"+c" (nl),
|
||||
"+S"(p), "+D"(q)
|
||||
:"r"(n & 3));
|
||||
#elif defined(__x86_64__)
|
||||
size_t nq = n >> 3;
|
||||
asm volatile ("cld ; rep ; movsq ; movl %3,%%ecx ; rep ; movsb":"+c"
|
||||
(nq), "+S"(p), "+D"(q)
|
||||
:"r"((uint32_t) (n & 7)));
|
||||
#else
|
||||
while (n--) {
|
||||
*q++ = *p++;
|
||||
}
|
||||
#endif
|
||||
|
||||
return dst;
|
||||
}
|
52
kexcrt/memmem.c
Normal file
52
kexcrt/memmem.c
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* memmem.c
|
||||
*
|
||||
* Find a byte string inside a longer byte string
|
||||
*
|
||||
* This uses the "Not So Naive" algorithm, a very simple but
|
||||
* usually effective algorithm, see:
|
||||
*
|
||||
* http://www-igm.univ-mlv.fr/~lecroq/string/
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
void *memmem(const void *haystack, size_t n, const void *needle, size_t m)
|
||||
{
|
||||
const unsigned char *y = (const unsigned char *)haystack;
|
||||
const unsigned char *x = (const unsigned char *)needle;
|
||||
|
||||
size_t j, k, l;
|
||||
|
||||
if (m > n || !m || !n)
|
||||
return NULL;
|
||||
|
||||
if (1 != m) {
|
||||
if (x[0] == x[1]) {
|
||||
k = 2;
|
||||
l = 1;
|
||||
} else {
|
||||
k = 1;
|
||||
l = 2;
|
||||
}
|
||||
|
||||
j = 0;
|
||||
while (j <= n - m) {
|
||||
if (x[1] != y[j + 1]) {
|
||||
j += k;
|
||||
} else {
|
||||
if (!memcmp(x + 2, y + j + 2, m - 2)
|
||||
&& x[0] == y[j])
|
||||
return (void *)&y[j];
|
||||
j += l;
|
||||
}
|
||||
}
|
||||
} else
|
||||
do {
|
||||
if (*y == *x)
|
||||
return (void *)y;
|
||||
y++;
|
||||
} while (--n);
|
||||
|
||||
return NULL;
|
||||
}
|
36
kexcrt/memmove.c
Normal file
36
kexcrt/memmove.c
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* memmove.c
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
void *memmove(void *dst, const void *src, size_t n)
|
||||
{
|
||||
const char *p = src;
|
||||
char *q = dst;
|
||||
#if defined(__i386__) || defined(__x86_64__)
|
||||
if (q < p) {
|
||||
asm volatile("cld ; rep ; movsb"
|
||||
: "+c" (n), "+S"(p), "+D"(q));
|
||||
} else {
|
||||
p += (n - 1);
|
||||
q += (n - 1);
|
||||
asm volatile("std ; rep ; movsb"
|
||||
: "+c" (n), "+S"(p), "+D"(q));
|
||||
}
|
||||
#else
|
||||
if (q < p) {
|
||||
while (n--) {
|
||||
*q++ = *p++;
|
||||
}
|
||||
} else {
|
||||
p += n;
|
||||
q += n;
|
||||
while (n--) {
|
||||
*--q = *--p;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return dst;
|
||||
}
|
19
kexcrt/memrchr.c
Normal file
19
kexcrt/memrchr.c
Normal file
@ -0,0 +1,19 @@
|
||||
/*
|
||||
* memrchr.c
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
void *memrchr(const void *s, int c, size_t n)
|
||||
{
|
||||
const unsigned char *sp = (const unsigned char *)s + n - 1;
|
||||
|
||||
while (n--) {
|
||||
if (*sp == (unsigned char)c)
|
||||
return (void *)sp;
|
||||
sp--;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
29
kexcrt/memset.c
Normal file
29
kexcrt/memset.c
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* memset.c
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
void *memset(void *dst, int c, size_t n)
|
||||
{
|
||||
char *q = dst;
|
||||
|
||||
#if defined(__i386__)
|
||||
size_t nl = n >> 2;
|
||||
asm volatile ("cld ; rep ; stosl ; movl %3,%0 ; rep ; stosb"
|
||||
: "+c" (nl), "+D" (q)
|
||||
: "a" ((unsigned char)c * 0x01010101U), "r" (n & 3));
|
||||
#elif defined(__x86_64__)
|
||||
size_t nq = n >> 3;
|
||||
asm volatile ("cld ; rep ; stosq ; movl %3,%%ecx ; rep ; stosb"
|
||||
:"+c" (nq), "+D" (q)
|
||||
: "a" ((unsigned char)c * 0x0101010101010101U),
|
||||
"r" ((uint32_t) n & 7));
|
||||
#else
|
||||
while (n--) {
|
||||
*q++ = c;
|
||||
}
|
||||
#endif
|
||||
|
||||
return dst;
|
||||
}
|
24
kexcrt/memswap.c
Normal file
24
kexcrt/memswap.c
Normal file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* memswap()
|
||||
*
|
||||
* Swaps the contents of two nonoverlapping memory areas.
|
||||
* This really could be done faster...
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
void memswap(void *m1, void *m2, size_t n)
|
||||
{
|
||||
char *p = m1;
|
||||
char *q = m2;
|
||||
char tmp;
|
||||
|
||||
while (n--) {
|
||||
tmp = *p;
|
||||
*p = *q;
|
||||
*q = tmp;
|
||||
|
||||
p++;
|
||||
q++;
|
||||
}
|
||||
}
|
184
kexcrt/msvc/STDINT.H
Normal file
184
kexcrt/msvc/STDINT.H
Normal file
@ -0,0 +1,184 @@
|
||||
/* ISO C9x 7.18 Integer types <stdint.h>
|
||||
* Based on ISO/IEC SC22/WG14 9899 Committee draft (SC22 N2794)
|
||||
*
|
||||
* THIS SOFTWARE IS NOT COPYRIGHTED
|
||||
*
|
||||
* Contributor: Danny Smith <danny_r_smith_2001@yahoo.co.nz>
|
||||
*
|
||||
* This source code is offered for use in the public domain. You may
|
||||
* use, modify or distribute it freely.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful but
|
||||
* WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
|
||||
* DISCLAIMED. This includes but is not limited to warranties of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* Date: 2000-12-02
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _STDINT_H
|
||||
#define _STDINT_H
|
||||
#define __need_wint_t
|
||||
#define __need_wchar_t
|
||||
#include <stddef.h>
|
||||
|
||||
/* 7.18.1.1 Exact-width integer types */
|
||||
typedef signed char int8_t;
|
||||
typedef unsigned char uint8_t;
|
||||
typedef short int16_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef int int32_t;
|
||||
typedef unsigned uint32_t;
|
||||
typedef __int64 int64_t;
|
||||
typedef unsigned __int64 uint64_t;
|
||||
|
||||
/* 7.18.1.2 Minimum-width integer types */
|
||||
typedef signed char int_least8_t;
|
||||
typedef unsigned char uint_least8_t;
|
||||
typedef short int_least16_t;
|
||||
typedef unsigned short uint_least16_t;
|
||||
typedef int int_least32_t;
|
||||
typedef unsigned uint_least32_t;
|
||||
typedef __int64 int_least64_t;
|
||||
typedef unsigned __int64 uint_least64_t;
|
||||
|
||||
/* 7.18.1.3 Fastest minimum-width integer types
|
||||
* Not actually guaranteed to be fastest for all purposes
|
||||
* Here we use the exact-width types for 8 and 16-bit ints.
|
||||
*/
|
||||
typedef char int_fast8_t;
|
||||
typedef unsigned char uint_fast8_t;
|
||||
typedef short int_fast16_t;
|
||||
typedef unsigned short uint_fast16_t;
|
||||
typedef int int_fast32_t;
|
||||
typedef unsigned int uint_fast32_t;
|
||||
typedef __int64 int_fast64_t;
|
||||
typedef unsigned __int64 uint_fast64_t;
|
||||
|
||||
/* 7.18.1.4 Integer types capable of holding object pointers */
|
||||
typedef int intptr_t;
|
||||
typedef unsigned uintptr_t;
|
||||
|
||||
/* 7.18.1.5 Greatest-width integer types */
|
||||
typedef __int64 intmax_t;
|
||||
typedef unsigned __int64 uintmax_t;
|
||||
|
||||
/* 7.18.2 Limits of specified-width integer types */
|
||||
#if !defined ( __cplusplus) || defined (__STDC_LIMIT_MACROS)
|
||||
|
||||
/* 7.18.2.1 Limits of exact-width integer types */
|
||||
#define INT8_MIN (-128)
|
||||
#define INT16_MIN (-32768)
|
||||
#define INT32_MIN (-2147483647 - 1)
|
||||
#define INT64_MIN (-9223372036854775807LL - 1)
|
||||
|
||||
#define INT8_MAX 127
|
||||
#define INT16_MAX 32767
|
||||
#define INT32_MAX 2147483647
|
||||
#define INT64_MAX 9223372036854775807LL
|
||||
|
||||
#define UINT8_MAX 0xff /* 255U */
|
||||
#define UINT16_MAX 0xffff /* 65535U */
|
||||
#define UINT32_MAX 0xffffffff /* 4294967295U */
|
||||
#define UINT64_MAX 0xffffffffffffffffULL /* 18446744073709551615ULL */
|
||||
|
||||
/* 7.18.2.2 Limits of minimum-width integer types */
|
||||
#define INT_LEAST8_MIN INT8_MIN
|
||||
#define INT_LEAST16_MIN INT16_MIN
|
||||
#define INT_LEAST32_MIN INT32_MIN
|
||||
#define INT_LEAST64_MIN INT64_MIN
|
||||
|
||||
#define INT_LEAST8_MAX INT8_MAX
|
||||
#define INT_LEAST16_MAX INT16_MAX
|
||||
#define INT_LEAST32_MAX INT32_MAX
|
||||
#define INT_LEAST64_MAX INT64_MAX
|
||||
|
||||
#define UINT_LEAST8_MAX UINT8_MAX
|
||||
#define UINT_LEAST16_MAX UINT16_MAX
|
||||
#define UINT_LEAST32_MAX UINT32_MAX
|
||||
#define UINT_LEAST64_MAX UINT64_MAX
|
||||
|
||||
/* 7.18.2.3 Limits of fastest minimum-width integer types */
|
||||
#define INT_FAST8_MIN INT8_MIN
|
||||
#define INT_FAST16_MIN INT16_MIN
|
||||
#define INT_FAST32_MIN INT32_MIN
|
||||
#define INT_FAST64_MIN INT64_MIN
|
||||
|
||||
#define INT_FAST8_MAX INT8_MAX
|
||||
#define INT_FAST16_MAX INT16_MAX
|
||||
#define INT_FAST32_MAX INT32_MAX
|
||||
#define INT_FAST64_MAX INT64_MAX
|
||||
|
||||
#define UINT_FAST8_MAX UINT8_MAX
|
||||
#define UINT_FAST16_MAX UINT16_MAX
|
||||
#define UINT_FAST32_MAX UINT32_MAX
|
||||
#define UINT_FAST64_MAX UINT64_MAX
|
||||
|
||||
/* 7.18.2.4 Limits of integer types capable of holding
|
||||
object pointers */
|
||||
#define INTPTR_MIN INT32_MIN
|
||||
#define INTPTR_MAX INT32_MAX
|
||||
#define UINTPTR_MAX UINT32_MAX
|
||||
|
||||
/* 7.18.2.5 Limits of greatest-width integer types */
|
||||
#define INTMAX_MIN INT64_MIN
|
||||
#define INTMAX_MAX INT64_MAX
|
||||
#define UINTMAX_MAX UINT64_MAX
|
||||
|
||||
/* 7.18.3 Limits of other integer types */
|
||||
#define PTRDIFF_MIN INT32_MIN
|
||||
#define PTRDIFF_MAX INT32_MAX
|
||||
|
||||
#define SIG_ATOMIC_MIN INT32_MIN
|
||||
#define SIG_ATOMIC_MAX INT32_MAX
|
||||
|
||||
#define SIZE_MAX UINT32_MAX
|
||||
|
||||
#ifndef WCHAR_MIN /* also in wchar.h */
|
||||
#define WCHAR_MIN 0
|
||||
#define WCHAR_MAX 0xffff /* UINT16_MAX */
|
||||
#endif
|
||||
|
||||
/*
|
||||
* wint_t is unsigned short for compatibility with MS runtime
|
||||
*/
|
||||
#define WINT_MIN 0
|
||||
#define WINT_MAX 0xffff /* UINT16_MAX */
|
||||
|
||||
#endif /* !defined ( __cplusplus) || defined __STDC_LIMIT_MACROS */
|
||||
|
||||
|
||||
/* 7.18.4 Macros for integer constants */
|
||||
#if !defined ( __cplusplus) || defined (__STDC_CONSTANT_MACROS)
|
||||
|
||||
/* 7.18.4.1 Macros for minimum-width integer constants
|
||||
|
||||
Accoding to Douglas Gwyn <gwyn@arl.mil>:
|
||||
"This spec was changed in ISO/IEC 9899:1999 TC1; in ISO/IEC
|
||||
9899:1999 as initially published, the expansion was required
|
||||
to be an integer constant of precisely matching type, which
|
||||
is impossible to accomplish for the shorter types on most
|
||||
platforms, because C99 provides no standard way to designate
|
||||
an integer constant with width less than that of type int.
|
||||
TC1 changed this to require just an integer constant
|
||||
*expression* with *promoted* type."
|
||||
*/
|
||||
|
||||
#define INT8_C(val) ((int8_t) + (val))
|
||||
#define UINT8_C(val) ((uint8_t) + (val##U))
|
||||
#define INT16_C(val) ((int16_t) + (val))
|
||||
#define UINT16_C(val) ((uint16_t) + (val##U))
|
||||
|
||||
#define INT32_C(val) val##L
|
||||
#define UINT32_C(val) val##UL
|
||||
#define INT64_C(val) val##LL
|
||||
#define UINT64_C(val) val##ULL
|
||||
|
||||
/* 7.18.4.2 Macros for greatest-width integer constants */
|
||||
#define INTMAX_C(val) INT64_C(val)
|
||||
#define UINTMAX_C(val) UINT64_C(val)
|
||||
|
||||
#endif /* !defined ( __cplusplus) || defined __STDC_CONSTANT_MACROS */
|
||||
|
||||
#endif
|
112
kexcrt/msvc/argcargv.c
Normal file
112
kexcrt/msvc/argcargv.c
Normal file
@ -0,0 +1,112 @@
|
||||
//==========================================
|
||||
// LIBCTINY - Matt Pietrek 2001
|
||||
// MSDN Magazine, January 2001
|
||||
//==========================================
|
||||
#include <windows.h>
|
||||
#include "argcargv.h"
|
||||
|
||||
#define _MAX_CMD_LINE_ARGS 128
|
||||
|
||||
char * _ppszArgv[_MAX_CMD_LINE_ARGS+1];
|
||||
|
||||
int __cdecl _ConvertCommandLineToArgcArgv( void )
|
||||
{
|
||||
int cbCmdLine;
|
||||
int argc;
|
||||
PSTR pszSysCmdLine, pszCmdLine;
|
||||
|
||||
// Set to no argv elements, in case we have to bail out
|
||||
_ppszArgv[0] = 0;
|
||||
|
||||
// First get a pointer to the system's version of the command line, and
|
||||
// figure out how long it is.
|
||||
pszSysCmdLine = GetCommandLine();
|
||||
cbCmdLine = lstrlen( pszSysCmdLine );
|
||||
|
||||
// Allocate memory to store a copy of the command line. We'll modify
|
||||
// this copy, rather than the original command line. Yes, this memory
|
||||
// currently doesn't explicitly get freed, but it goes away when the
|
||||
// process terminates.
|
||||
pszCmdLine = (PSTR)HeapAlloc( GetProcessHeap(), 0, cbCmdLine+1 );
|
||||
if ( !pszCmdLine )
|
||||
return 0;
|
||||
|
||||
// Copy the system version of the command line into our copy
|
||||
lstrcpy( pszCmdLine, pszSysCmdLine );
|
||||
|
||||
if ( '"' == *pszCmdLine ) // If command line starts with a quote ("),
|
||||
{ // it's a quoted filename. Skip to next quote.
|
||||
pszCmdLine++;
|
||||
|
||||
_ppszArgv[0] = pszCmdLine; // argv[0] == executable name
|
||||
|
||||
while ( *pszCmdLine && (*pszCmdLine != '"') )
|
||||
pszCmdLine++;
|
||||
|
||||
if ( *pszCmdLine ) // Did we see a non-NULL ending?
|
||||
*pszCmdLine++ = 0; // Null terminate and advance to next char
|
||||
else
|
||||
return 0; // Oops! We didn't see the end quote
|
||||
}
|
||||
else // A regular (non-quoted) filename
|
||||
{
|
||||
_ppszArgv[0] = pszCmdLine; // argv[0] == executable name
|
||||
|
||||
while ( *pszCmdLine && (' ' != *pszCmdLine) && ('\t' != *pszCmdLine) )
|
||||
pszCmdLine++;
|
||||
|
||||
if ( *pszCmdLine )
|
||||
*pszCmdLine++ = 0; // Null terminate and advance to next char
|
||||
}
|
||||
|
||||
// Done processing argv[0] (i.e., the executable name). Now do th
|
||||
// actual arguments
|
||||
|
||||
argc = 1;
|
||||
|
||||
while ( 1 )
|
||||
{
|
||||
// Skip over any whitespace
|
||||
while ( *pszCmdLine && (' ' == *pszCmdLine) || ('\t' == *pszCmdLine) )
|
||||
pszCmdLine++;
|
||||
|
||||
if ( 0 == *pszCmdLine ) // End of command line???
|
||||
return argc;
|
||||
|
||||
if ( '"' == *pszCmdLine ) // Argument starting with a quote???
|
||||
{
|
||||
pszCmdLine++; // Advance past quote character
|
||||
|
||||
_ppszArgv[ argc++ ] = pszCmdLine;
|
||||
_ppszArgv[ argc ] = 0;
|
||||
|
||||
// Scan to end quote, or NULL terminator
|
||||
while ( *pszCmdLine && (*pszCmdLine != '"') )
|
||||
pszCmdLine++;
|
||||
|
||||
if ( 0 == *pszCmdLine )
|
||||
return argc;
|
||||
|
||||
if ( *pszCmdLine )
|
||||
*pszCmdLine++ = 0; // Null terminate and advance to next char
|
||||
}
|
||||
else // Non-quoted argument
|
||||
{
|
||||
_ppszArgv[ argc++ ] = pszCmdLine;
|
||||
_ppszArgv[ argc ] = 0;
|
||||
|
||||
// Skip till whitespace or NULL terminator
|
||||
while ( *pszCmdLine && (' '!=*pszCmdLine) && ('\t'!=*pszCmdLine) )
|
||||
pszCmdLine++;
|
||||
|
||||
if ( 0 == *pszCmdLine )
|
||||
return argc;
|
||||
|
||||
if ( *pszCmdLine )
|
||||
*pszCmdLine++ = 0; // Null terminate and advance to next char
|
||||
}
|
||||
|
||||
if ( argc >= (_MAX_CMD_LINE_ARGS) )
|
||||
return argc;
|
||||
}
|
||||
}
|
3
kexcrt/msvc/argcargv.h
Normal file
3
kexcrt/msvc/argcargv.h
Normal file
@ -0,0 +1,3 @@
|
||||
extern char * _ppszArgv[];
|
||||
|
||||
int __cdecl _ConvertCommandLineToArgcArgv( void );
|
20
kexcrt/msvc/concrt0.c
Normal file
20
kexcrt/msvc/concrt0.c
Normal file
@ -0,0 +1,20 @@
|
||||
#include <windows.h>
|
||||
#include "argcargv.h"
|
||||
#include "init.h"
|
||||
|
||||
int main(int, char **);
|
||||
|
||||
void mainCRTStartup(void)
|
||||
{
|
||||
int mainret, argc;
|
||||
|
||||
argc = _ConvertCommandLineToArgcArgv();
|
||||
|
||||
__init();
|
||||
|
||||
mainret = main(argc, _ppszArgv);
|
||||
|
||||
__exit();
|
||||
|
||||
ExitProcess(mainret);
|
||||
}
|
27
kexcrt/msvc/dllcrt0.c
Normal file
27
kexcrt/msvc/dllcrt0.c
Normal file
@ -0,0 +1,27 @@
|
||||
#include <windows.h>
|
||||
#include "init.h"
|
||||
|
||||
extern BOOL WINAPI DllMain(
|
||||
HINSTANCE hDllHandle,
|
||||
DWORD dwReason,
|
||||
LPVOID lpReserved
|
||||
);
|
||||
|
||||
BOOL WINAPI _DllMainCRTStartup(
|
||||
HINSTANCE hDllHandle,
|
||||
DWORD dwReason,
|
||||
LPVOID lpReserved
|
||||
)
|
||||
{
|
||||
BOOL ret;
|
||||
|
||||
if (dwReason == DLL_PROCESS_ATTACH)
|
||||
__init();
|
||||
|
||||
ret = DllMain(hDllHandle, dwReason, lpReserved);
|
||||
|
||||
if (dwReason == DLL_PROCESS_DETACH)
|
||||
__exit();
|
||||
|
||||
return ret;
|
||||
}
|
85
kexcrt/msvc/init.c
Normal file
85
kexcrt/msvc/init.c
Normal file
@ -0,0 +1,85 @@
|
||||
#include <stdlib.h>
|
||||
#include "init.h"
|
||||
|
||||
#define MAX_ATEXIT 32
|
||||
|
||||
typedef void (__cdecl *_PVFV)(void);
|
||||
|
||||
static _PVFV _atexitlist[MAX_ATEXIT];
|
||||
static int _atexitlist_cnt;
|
||||
|
||||
// C initializers
|
||||
#pragma data_seg(".CRT$XIA")
|
||||
_PVFV __xi_a[] = { NULL };
|
||||
#pragma data_seg(".CRT$XIZ")
|
||||
_PVFV __xi_z[] = { NULL };
|
||||
|
||||
// C++ initializers
|
||||
#pragma data_seg(".CRT$XCA")
|
||||
_PVFV __xc_a[] = { NULL };
|
||||
#pragma data_seg(".CRT$XCZ")
|
||||
_PVFV __xc_z[] = { NULL };
|
||||
|
||||
// C pre-terminators
|
||||
#pragma data_seg(".CRT$XPA")
|
||||
_PVFV __xp_a[] = { NULL };
|
||||
#pragma data_seg(".CRT$XPZ")
|
||||
_PVFV __xp_z[] = { NULL };
|
||||
|
||||
// C terminators
|
||||
#pragma data_seg(".CRT$XTA")
|
||||
_PVFV __xt_a[] = { NULL };
|
||||
#pragma data_seg(".CRT$XTZ")
|
||||
_PVFV __xt_z[] = { NULL };
|
||||
|
||||
#pragma data_seg() /* reset */
|
||||
|
||||
#pragma comment(linker, "/merge:.CRT=.data")
|
||||
|
||||
static void _initterm(_PVFV * pfbegin, _PVFV * pfend)
|
||||
{
|
||||
while (pfbegin < pfend)
|
||||
{
|
||||
if (*pfbegin != NULL)
|
||||
(**pfbegin)();
|
||||
++pfbegin;
|
||||
}
|
||||
}
|
||||
|
||||
void __init(void)
|
||||
{
|
||||
// do initializations
|
||||
_initterm( __xi_a, __xi_z );
|
||||
// do C++ initializations
|
||||
_initterm( __xc_a, __xc_z );
|
||||
}
|
||||
|
||||
int atexit(_PVFV func)
|
||||
{
|
||||
if (_atexitlist_cnt < MAX_ATEXIT)
|
||||
{
|
||||
_atexitlist[_atexitlist_cnt++] = func;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
void __exit(void)
|
||||
{
|
||||
// do pre-terminators
|
||||
_initterm(__xp_a, __xp_z);
|
||||
// do terminators
|
||||
_initterm(__xt_a, __xt_z);
|
||||
|
||||
if (_atexitlist_cnt)
|
||||
{
|
||||
_PVFV* p;
|
||||
for (p = _atexitlist + _atexitlist_cnt - 1 ; p >= _atexitlist ; p--)
|
||||
{
|
||||
if (*p != NULL)
|
||||
(**p)();
|
||||
p--;
|
||||
}
|
||||
}
|
||||
}
|
7
kexcrt/msvc/init.h
Normal file
7
kexcrt/msvc/init.h
Normal file
@ -0,0 +1,7 @@
|
||||
#ifndef __INIT_H
|
||||
#define __INIT_H
|
||||
|
||||
void __init(void);
|
||||
void __exit(void);
|
||||
|
||||
#endif
|
53
kexcrt/msvc/wincrt0.c
Normal file
53
kexcrt/msvc/wincrt0.c
Normal file
@ -0,0 +1,53 @@
|
||||
#include <windows.h>
|
||||
#include "init.h"
|
||||
|
||||
void WinMainCRTStartup(void)
|
||||
{
|
||||
int mainret;
|
||||
char* lpszCommandLine;
|
||||
STARTUPINFO StartupInfo;
|
||||
|
||||
lpszCommandLine = GetCommandLine();
|
||||
|
||||
// Skip past program name (first token in command line).
|
||||
|
||||
if ( *lpszCommandLine == '"' ) // Check for and handle quoted program name
|
||||
{
|
||||
lpszCommandLine++; // Get past the first quote
|
||||
|
||||
// Now, scan, and skip over, subsequent characters until another
|
||||
// double-quote or a null is encountered
|
||||
while( *lpszCommandLine && (*lpszCommandLine != '"') )
|
||||
lpszCommandLine++;
|
||||
|
||||
// If we stopped on a double-quote (usual case), skip over it.
|
||||
|
||||
if ( *lpszCommandLine == '"' )
|
||||
lpszCommandLine++;
|
||||
}
|
||||
else // First token wasn't a quote
|
||||
{
|
||||
while ( *lpszCommandLine > ' ' )
|
||||
lpszCommandLine++;
|
||||
}
|
||||
|
||||
// Skip past any white space preceeding the second token.
|
||||
|
||||
while ( *lpszCommandLine && (*lpszCommandLine <= ' ') )
|
||||
lpszCommandLine++;
|
||||
|
||||
StartupInfo.dwFlags = 0;
|
||||
GetStartupInfo( &StartupInfo );
|
||||
|
||||
__init();
|
||||
|
||||
mainret = WinMain( GetModuleHandle(NULL),
|
||||
NULL,
|
||||
lpszCommandLine,
|
||||
StartupInfo.dwFlags & STARTF_USESHOWWINDOW
|
||||
? StartupInfo.wShowWindow : SW_SHOWDEFAULT );
|
||||
|
||||
__exit();
|
||||
|
||||
ExitProcess(mainret);
|
||||
}
|
17
kexcrt/snprintf.c
Normal file
17
kexcrt/snprintf.c
Normal file
@ -0,0 +1,17 @@
|
||||
/*
|
||||
* snprintf.c
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
int snprintf(char *buffer, size_t n, const char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
int rv;
|
||||
|
||||
va_start(ap, format);
|
||||
rv = vsnprintf(buffer, n, format, ap);
|
||||
va_end(ap);
|
||||
return rv;
|
||||
}
|
18
kexcrt/sprintf.c
Normal file
18
kexcrt/sprintf.c
Normal file
@ -0,0 +1,18 @@
|
||||
/*
|
||||
* sprintf.c
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
int sprintf(char *buffer, const char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
int rv;
|
||||
|
||||
va_start(ap, format);
|
||||
rv = vsnprintf(buffer, ~(size_t) 0, format, ap);
|
||||
va_end(ap);
|
||||
|
||||
return rv;
|
||||
}
|
18
kexcrt/sscanf.c
Normal file
18
kexcrt/sscanf.c
Normal file
@ -0,0 +1,18 @@
|
||||
/*
|
||||
* sscanf()
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
int sscanf(const char *str, const char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
int rv;
|
||||
|
||||
va_start(ap, format);
|
||||
rv = vsscanf(str, format, ap);
|
||||
va_end(ap);
|
||||
|
||||
return rv;
|
||||
}
|
11
kexcrt/strcat.c
Normal file
11
kexcrt/strcat.c
Normal file
@ -0,0 +1,11 @@
|
||||
/*
|
||||
* strcat.c
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
char *strcat(char *dst, const char *src)
|
||||
{
|
||||
strcpy(strchr(dst, '\0'), src);
|
||||
return dst;
|
||||
}
|
16
kexcrt/strchr.c
Normal file
16
kexcrt/strchr.c
Normal file
@ -0,0 +1,16 @@
|
||||
/*
|
||||
* strchr.c
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
char *strchr(const char *s, int c)
|
||||
{
|
||||
while (*s != (char)c) {
|
||||
if (!*s)
|
||||
return NULL;
|
||||
s++;
|
||||
}
|
||||
|
||||
return (char *)s;
|
||||
}
|
21
kexcrt/strcmp.c
Normal file
21
kexcrt/strcmp.c
Normal file
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* strcmp.c
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
int strcmp(const char *s1, const char *s2)
|
||||
{
|
||||
const unsigned char *c1 = (const unsigned char *)s1;
|
||||
const unsigned char *c2 = (const unsigned char *)s2;
|
||||
unsigned char ch;
|
||||
int d = 0;
|
||||
|
||||
while (1) {
|
||||
d = (int)(ch = *c1++) - (int)*c2++;
|
||||
if (d || !ch)
|
||||
break;
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
24
kexcrt/strcmpi.c
Normal file
24
kexcrt/strcmpi.c
Normal file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* strcmpi.c
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
int strcmpi(const char *s1, const char *s2)
|
||||
{
|
||||
const unsigned char *c1 = (const unsigned char *)s1;
|
||||
const unsigned char *c2 = (const unsigned char *)s2;
|
||||
unsigned char ch;
|
||||
int d = 0;
|
||||
|
||||
while (1) {
|
||||
/* toupper() expects an unsigned char (implicitly cast to int)
|
||||
as input, and returns an int, which is exactly what we want. */
|
||||
d = toupper(ch = *c1++) - toupper(*c2++);
|
||||
if (d || !ch)
|
||||
break;
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
20
kexcrt/strcpy.c
Normal file
20
kexcrt/strcpy.c
Normal file
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* strcpy.c
|
||||
*
|
||||
* strcpy()
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
char *strcpy(char *dst, const char *src)
|
||||
{
|
||||
char *q = dst;
|
||||
const char *p = src;
|
||||
char ch;
|
||||
|
||||
do {
|
||||
*q++ = ch = *p++;
|
||||
} while (ch);
|
||||
|
||||
return dst;
|
||||
}
|
13
kexcrt/strlen.c
Normal file
13
kexcrt/strlen.c
Normal file
@ -0,0 +1,13 @@
|
||||
/*
|
||||
* strlen()
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
size_t strlen(const char *s)
|
||||
{
|
||||
const char *ss = s;
|
||||
while (*ss)
|
||||
ss++;
|
||||
return ss - s;
|
||||
}
|
21
kexcrt/strncat.c
Normal file
21
kexcrt/strncat.c
Normal file
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* strncat.c
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
char *strncat(char *dst, const char *src, size_t n)
|
||||
{
|
||||
char *q = strchr(dst, '\0');
|
||||
const char *p = src;
|
||||
char ch;
|
||||
|
||||
while (n--) {
|
||||
*q++ = ch = *p++;
|
||||
if (!ch)
|
||||
return dst;
|
||||
}
|
||||
*q = '\0';
|
||||
|
||||
return dst;
|
||||
}
|
21
kexcrt/strncmp.c
Normal file
21
kexcrt/strncmp.c
Normal file
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* strncmp.c
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
int strncmp(const char *s1, const char *s2, size_t n)
|
||||
{
|
||||
const unsigned char *c1 = (const unsigned char *)s1;
|
||||
const unsigned char *c2 = (const unsigned char *)s2;
|
||||
unsigned char ch;
|
||||
int d = 0;
|
||||
|
||||
while (n--) {
|
||||
d = (int)(ch = *c1++) - (int)*c2++;
|
||||
if (d || !ch)
|
||||
break;
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
24
kexcrt/strncpy.c
Normal file
24
kexcrt/strncpy.c
Normal file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* strncpy.c
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
char *strncpy(char *dst, const char *src, size_t n)
|
||||
{
|
||||
char *q = dst;
|
||||
const char *p = src;
|
||||
char ch;
|
||||
|
||||
while (n) {
|
||||
n--;
|
||||
*q++ = ch = *p++;
|
||||
if (!ch)
|
||||
break;
|
||||
}
|
||||
|
||||
/* The specs say strncpy() fills the entire buffer with NUL. Sigh. */
|
||||
memset(q, 0, n);
|
||||
|
||||
return dst;
|
||||
}
|
24
kexcrt/strnicmp.c
Normal file
24
kexcrt/strnicmp.c
Normal file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* strnicmp.c
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
int strnicmp(const char *s1, const char *s2, size_t n)
|
||||
{
|
||||
const unsigned char *c1 = (const unsigned char *)s1;
|
||||
const unsigned char *c2 = (const unsigned char *)s2;
|
||||
unsigned char ch;
|
||||
int d = 0;
|
||||
|
||||
while (n--) {
|
||||
/* toupper() expects an unsigned char (implicitly cast to int)
|
||||
as input, and returns an int, which is exactly what we want. */
|
||||
d = toupper(ch = *c1++) - toupper(*c2++);
|
||||
if (d || !ch)
|
||||
break;
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
18
kexcrt/strnlen.c
Normal file
18
kexcrt/strnlen.c
Normal file
@ -0,0 +1,18 @@
|
||||
/*
|
||||
* strnlen()
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
size_t strnlen(const char *s, size_t maxlen)
|
||||
{
|
||||
const char *ss = s;
|
||||
|
||||
/* Important: the maxlen test must precede the reference through ss;
|
||||
since the byte beyond the maximum may segfault */
|
||||
while ((maxlen > 0) && *ss) {
|
||||
ss++;
|
||||
maxlen--;
|
||||
}
|
||||
return ss - s;
|
||||
}
|
13
kexcrt/strntoimax.c
Normal file
13
kexcrt/strntoimax.c
Normal file
@ -0,0 +1,13 @@
|
||||
/*
|
||||
* strntoimax.c
|
||||
*
|
||||
* strntoimax()
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
intmax_t strntoimax(const char *nptr, char **endptr, int base, size_t n)
|
||||
{
|
||||
return (intmax_t) strntoumax(nptr, endptr, base, n);
|
||||
}
|
80
kexcrt/strntoumax.c
Normal file
80
kexcrt/strntoumax.c
Normal file
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* strntoumax.c
|
||||
*
|
||||
* The strntoumax() function and associated
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# define inline __inline
|
||||
#endif
|
||||
|
||||
static inline int digitval(int ch)
|
||||
{
|
||||
if (ch >= '0' && ch <= '9') {
|
||||
return ch - '0';
|
||||
} else if (ch >= 'A' && ch <= 'Z') {
|
||||
return ch - 'A' + 10;
|
||||
} else if (ch >= 'a' && ch <= 'z') {
|
||||
return ch - 'a' + 10;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
uintmax_t strntoumax(const char *nptr, char **endptr, int base, size_t n)
|
||||
{
|
||||
int minus = 0;
|
||||
uintmax_t v = 0;
|
||||
int d;
|
||||
|
||||
while (n && isspace((unsigned char)*nptr)) {
|
||||
nptr++;
|
||||
n--;
|
||||
}
|
||||
|
||||
/* Single optional + or - */
|
||||
if (n) {
|
||||
char c = *nptr;
|
||||
if (c == '-' || c == '+') {
|
||||
minus = (c == '-');
|
||||
nptr++;
|
||||
n--;
|
||||
}
|
||||
}
|
||||
|
||||
if (base == 0) {
|
||||
if (n >= 2 && nptr[0] == '0' &&
|
||||
(nptr[1] == 'x' || nptr[1] == 'X')) {
|
||||
n -= 2;
|
||||
nptr += 2;
|
||||
base = 16;
|
||||
} else if (n >= 1 && nptr[0] == '0') {
|
||||
n--;
|
||||
nptr++;
|
||||
base = 8;
|
||||
} else {
|
||||
base = 10;
|
||||
}
|
||||
} else if (base == 16) {
|
||||
if (n >= 2 && nptr[0] == '0' &&
|
||||
(nptr[1] == 'x' || nptr[1] == 'X')) {
|
||||
n -= 2;
|
||||
nptr += 2;
|
||||
}
|
||||
}
|
||||
|
||||
while (n && (d = digitval(*nptr)) >= 0 && d < base) {
|
||||
v = v * base + d;
|
||||
n--;
|
||||
nptr++;
|
||||
}
|
||||
|
||||
if (endptr)
|
||||
*endptr = (char *)nptr;
|
||||
|
||||
return minus ? -v : v;
|
||||
}
|
12
kexcrt/strpbrk.c
Normal file
12
kexcrt/strpbrk.c
Normal file
@ -0,0 +1,12 @@
|
||||
/*
|
||||
* strpbrk
|
||||
*/
|
||||
|
||||
#include "strxspn.h"
|
||||
|
||||
char *strpbrk(const char *s, const char *accept)
|
||||
{
|
||||
const char *ss = s + __strxspn(s, accept, 1);
|
||||
|
||||
return *ss ? (char *)ss : NULL;
|
||||
}
|
18
kexcrt/strrchr.c
Normal file
18
kexcrt/strrchr.c
Normal file
@ -0,0 +1,18 @@
|
||||
/*
|
||||
* strrchr.c
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
char *strrchr(const char *s, int c)
|
||||
{
|
||||
const char *found = NULL;
|
||||
|
||||
while (*s) {
|
||||
if (*s == (char)c)
|
||||
found = s;
|
||||
s++;
|
||||
}
|
||||
|
||||
return (char *)found;
|
||||
}
|
21
kexcrt/strsep.c
Normal file
21
kexcrt/strsep.c
Normal file
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* strsep.c
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
char *strsep(char **stringp, const char *delim)
|
||||
{
|
||||
char *s = *stringp;
|
||||
char *e;
|
||||
|
||||
if (!s)
|
||||
return NULL;
|
||||
|
||||
e = strpbrk(s, delim);
|
||||
if (e)
|
||||
*e++ = '\0';
|
||||
|
||||
*stringp = e;
|
||||
return s;
|
||||
}
|
11
kexcrt/strstr.c
Normal file
11
kexcrt/strstr.c
Normal file
@ -0,0 +1,11 @@
|
||||
/*
|
||||
* strstr.c
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
char *strstr(const char *haystack, const char *needle)
|
||||
{
|
||||
return (char *)memmem(haystack, strlen(haystack), needle,
|
||||
strlen(needle));
|
||||
}
|
19
kexcrt/strtok.c
Normal file
19
kexcrt/strtok.c
Normal file
@ -0,0 +1,19 @@
|
||||
/*
|
||||
* strtok.c
|
||||
*/
|
||||
|
||||
char *strsep(char **stringp, const char *delim);
|
||||
|
||||
char *strtok(char *s, const char *delim)
|
||||
{
|
||||
static char *holder;
|
||||
|
||||
if (s)
|
||||
holder = s;
|
||||
|
||||
do {
|
||||
s = strsep(&holder, delim);
|
||||
} while (s && !*s);
|
||||
|
||||
return s;
|
||||
}
|
3
kexcrt/strtol.c
Normal file
3
kexcrt/strtol.c
Normal file
@ -0,0 +1,3 @@
|
||||
#define TYPE signed long
|
||||
#define NAME strtol
|
||||
#include "strtox.c"
|
3
kexcrt/strtoll.c
Normal file
3
kexcrt/strtoll.c
Normal file
@ -0,0 +1,3 @@
|
||||
#define TYPE int64_t
|
||||
#define NAME strtoll
|
||||
#include "strtox.c"
|
3
kexcrt/strtoul.c
Normal file
3
kexcrt/strtoul.c
Normal file
@ -0,0 +1,3 @@
|
||||
#define TYPE unsigned long
|
||||
#define NAME strtoul
|
||||
#include "strtox.c"
|
3
kexcrt/strtoull.c
Normal file
3
kexcrt/strtoull.c
Normal file
@ -0,0 +1,3 @@
|
||||
#define TYPE uint64_t
|
||||
#define NAME strtoull
|
||||
#include "strtox.c"
|
3
kexcrt/strtoumax.c
Normal file
3
kexcrt/strtoumax.c
Normal file
@ -0,0 +1,3 @@
|
||||
#define TYPE uintmax_t
|
||||
#define NAME strtoumax
|
||||
#include "strtox.c"
|
13
kexcrt/strtox.c
Normal file
13
kexcrt/strtox.c
Normal file
@ -0,0 +1,13 @@
|
||||
/*
|
||||
* strtox.c
|
||||
*
|
||||
* strto...() functions, by macro definition
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
TYPE NAME(const char *nptr, char **endptr, int base)
|
||||
{
|
||||
return (TYPE) strntoumax(nptr, endptr, base, ~(size_t) 0);
|
||||
}
|
18
kexcrt/strupr.c
Normal file
18
kexcrt/strupr.c
Normal file
@ -0,0 +1,18 @@
|
||||
/*
|
||||
* strupr.c
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
char* strupr(char *s)
|
||||
{
|
||||
unsigned char *c = s;
|
||||
|
||||
while (*c) {
|
||||
*c = toupper(*c);
|
||||
c++;
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
28
kexcrt/strxspn.c
Normal file
28
kexcrt/strxspn.c
Normal file
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* strpbrk
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stddef.h>
|
||||
#include <limits.h>
|
||||
#include "strxspn.h"
|
||||
|
||||
size_t __strxspn(const char *s, const char *map, int parity)
|
||||
{
|
||||
char matchmap[UCHAR_MAX + 1];
|
||||
size_t n = 0;
|
||||
|
||||
/* Create bitmap */
|
||||
memset(matchmap, 0, sizeof matchmap);
|
||||
while (*map)
|
||||
matchmap[(unsigned char)*map++] = 1;
|
||||
|
||||
/* Make sure the null character never matches */
|
||||
matchmap[0] = parity;
|
||||
|
||||
/* Calculate span length */
|
||||
while (matchmap[(unsigned char)*s++] ^ parity)
|
||||
n++;
|
||||
|
||||
return n;
|
||||
}
|
12
kexcrt/strxspn.h
Normal file
12
kexcrt/strxspn.h
Normal file
@ -0,0 +1,12 @@
|
||||
/*
|
||||
* strxspn.h
|
||||
*/
|
||||
|
||||
#ifndef STRXSPN_H
|
||||
#define STRXSPN_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
extern size_t __strxspn(const char *s, const char *map, int parity);
|
||||
|
||||
#endif
|
487
kexcrt/vsnprintf.c
Normal file
487
kexcrt/vsnprintf.c
Normal file
@ -0,0 +1,487 @@
|
||||
/*
|
||||
* vsnprintf.c
|
||||
*
|
||||
* vsnprintf(), from which the rest of the printf()
|
||||
* family is built
|
||||
*/
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
|
||||
enum flags {
|
||||
FL_ZERO = 0x01, /* Zero modifier */
|
||||
FL_MINUS = 0x02, /* Minus modifier */
|
||||
FL_PLUS = 0x04, /* Plus modifier */
|
||||
FL_TICK = 0x08, /* ' modifier */
|
||||
FL_SPACE = 0x10, /* Space modifier */
|
||||
FL_HASH = 0x20, /* # modifier */
|
||||
FL_SIGNED = 0x40, /* Number is signed */
|
||||
FL_UPPER = 0x80 /* Upper case digits */
|
||||
};
|
||||
|
||||
/* These may have to be adjusted on certain implementations */
|
||||
enum ranks {
|
||||
rank_char = -2,
|
||||
rank_short = -1,
|
||||
rank_int = 0,
|
||||
rank_long = 1,
|
||||
rank_longlong = 2
|
||||
};
|
||||
|
||||
#define MIN_RANK rank_char
|
||||
#define MAX_RANK rank_longlong
|
||||
|
||||
#define INTMAX_RANK rank_longlong
|
||||
#define SIZE_T_RANK rank_long
|
||||
#define PTRDIFF_T_RANK rank_long
|
||||
|
||||
#define EMIT(x) do { if (o<n){*q++ = (x);} o++; } while (0)
|
||||
|
||||
static size_t
|
||||
format_int(char *q, size_t n, uintmax_t val, enum flags flags,
|
||||
int base, int width, int prec)
|
||||
{
|
||||
char *qq;
|
||||
size_t o = 0, oo;
|
||||
static const char lcdigits[] = "0123456789abcdef";
|
||||
static const char ucdigits[] = "0123456789ABCDEF";
|
||||
const char *digits;
|
||||
uintmax_t tmpval;
|
||||
int minus = 0;
|
||||
int ndigits = 0, nchars;
|
||||
int tickskip, b4tick;
|
||||
|
||||
/* Select type of digits */
|
||||
digits = (flags & FL_UPPER) ? ucdigits : lcdigits;
|
||||
|
||||
/* If signed, separate out the minus */
|
||||
if (flags & FL_SIGNED && (intmax_t) val < 0) {
|
||||
minus = 1;
|
||||
val = (uintmax_t) (-(intmax_t) val);
|
||||
}
|
||||
|
||||
/* Count the number of digits needed. This returns zero for 0. */
|
||||
tmpval = val;
|
||||
while (tmpval) {
|
||||
tmpval /= base;
|
||||
ndigits++;
|
||||
}
|
||||
|
||||
/* Adjust ndigits for size of output */
|
||||
|
||||
if (flags & FL_HASH && base == 8) {
|
||||
if (prec < ndigits + 1)
|
||||
prec = ndigits + 1;
|
||||
}
|
||||
|
||||
if (ndigits < prec) {
|
||||
ndigits = prec; /* Mandatory number padding */
|
||||
} else if (val == 0) {
|
||||
ndigits = 1; /* Zero still requires space */
|
||||
}
|
||||
|
||||
/* For ', figure out what the skip should be */
|
||||
if (flags & FL_TICK) {
|
||||
tickskip = (base == 16) ? 4 : 3;
|
||||
} else {
|
||||
tickskip = ndigits; /* No tick marks */
|
||||
}
|
||||
|
||||
/* Tick marks aren't digits, but generated by the number converter */
|
||||
ndigits += (ndigits - 1) / tickskip;
|
||||
|
||||
/* Now compute the number of nondigits */
|
||||
nchars = ndigits;
|
||||
|
||||
if (minus || (flags & (FL_PLUS | FL_SPACE)))
|
||||
nchars++; /* Need space for sign */
|
||||
if ((flags & FL_HASH) && base == 16) {
|
||||
nchars += 2; /* Add 0x for hex */
|
||||
}
|
||||
|
||||
/* Emit early space padding */
|
||||
if (!(flags & (FL_MINUS | FL_ZERO)) && width > nchars) {
|
||||
while (width > nchars) {
|
||||
EMIT(' ');
|
||||
width--;
|
||||
}
|
||||
}
|
||||
|
||||
/* Emit nondigits */
|
||||
if (minus)
|
||||
EMIT('-');
|
||||
else if (flags & FL_PLUS)
|
||||
EMIT('+');
|
||||
else if (flags & FL_SPACE)
|
||||
EMIT(' ');
|
||||
|
||||
if ((flags & FL_HASH) && base == 16) {
|
||||
EMIT('0');
|
||||
EMIT((flags & FL_UPPER) ? 'X' : 'x');
|
||||
}
|
||||
|
||||
/* Emit zero padding */
|
||||
if ((flags & (FL_MINUS | FL_ZERO)) == FL_ZERO && width > ndigits) {
|
||||
while (width > nchars) {
|
||||
EMIT('0');
|
||||
width--;
|
||||
}
|
||||
}
|
||||
|
||||
/* Generate the number. This is done from right to left. */
|
||||
q += ndigits; /* Advance the pointer to end of number */
|
||||
o += ndigits;
|
||||
qq = q;
|
||||
oo = o; /* Temporary values */
|
||||
|
||||
b4tick = tickskip;
|
||||
while (ndigits > 0) {
|
||||
if (!b4tick--) {
|
||||
qq--;
|
||||
oo--;
|
||||
ndigits--;
|
||||
if (oo < n)
|
||||
*qq = '_';
|
||||
b4tick = tickskip - 1;
|
||||
}
|
||||
qq--;
|
||||
oo--;
|
||||
ndigits--;
|
||||
if (oo < n)
|
||||
*qq = digits[val % base];
|
||||
val /= base;
|
||||
}
|
||||
|
||||
/* Emit late space padding */
|
||||
while ((flags & FL_MINUS) && width > nchars) {
|
||||
EMIT(' ');
|
||||
width--;
|
||||
}
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
int vsnprintf(char *buffer, size_t n, const char *format, va_list ap)
|
||||
{
|
||||
const char *p = format;
|
||||
char ch;
|
||||
char *q = buffer;
|
||||
size_t o = 0; /* Number of characters output */
|
||||
uintmax_t val = 0;
|
||||
int rank = rank_int; /* Default rank */
|
||||
int width = 0;
|
||||
int prec = -1;
|
||||
int base;
|
||||
size_t sz;
|
||||
enum flags flags = 0;
|
||||
enum {
|
||||
st_normal, /* Ground state */
|
||||
st_flags, /* Special flags */
|
||||
st_width, /* Field width */
|
||||
st_prec, /* Field precision */
|
||||
st_modifiers /* Length or conversion modifiers */
|
||||
} state = st_normal;
|
||||
const char *sarg; /* %s string argument */
|
||||
char carg; /* %c char argument */
|
||||
int slen; /* String length */
|
||||
|
||||
while ((ch = *p++)) {
|
||||
switch (state) {
|
||||
case st_normal:
|
||||
if (ch == '%') {
|
||||
state = st_flags;
|
||||
flags = 0;
|
||||
rank = rank_int;
|
||||
width = 0;
|
||||
prec = -1;
|
||||
} else {
|
||||
EMIT(ch);
|
||||
}
|
||||
break;
|
||||
|
||||
case st_flags:
|
||||
switch (ch) {
|
||||
case '-':
|
||||
flags |= FL_MINUS;
|
||||
break;
|
||||
case '+':
|
||||
flags |= FL_PLUS;
|
||||
break;
|
||||
case '\'':
|
||||
flags |= FL_TICK;
|
||||
break;
|
||||
case ' ':
|
||||
flags |= FL_SPACE;
|
||||
break;
|
||||
case '#':
|
||||
flags |= FL_HASH;
|
||||
break;
|
||||
case '0':
|
||||
flags |= FL_ZERO;
|
||||
break;
|
||||
default:
|
||||
state = st_width;
|
||||
p--; /* Process this character again */
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case st_width:
|
||||
if (ch >= '0' && ch <= '9') {
|
||||
width = width * 10 + (ch - '0');
|
||||
} else if (ch == '*') {
|
||||
width = va_arg(ap, int);
|
||||
if (width < 0) {
|
||||
width = -width;
|
||||
flags |= FL_MINUS;
|
||||
}
|
||||
} else if (ch == '.') {
|
||||
prec = 0; /* Precision given */
|
||||
state = st_prec;
|
||||
} else {
|
||||
state = st_modifiers;
|
||||
p--; /* Process this character again */
|
||||
}
|
||||
break;
|
||||
|
||||
case st_prec:
|
||||
if (ch >= '0' && ch <= '9') {
|
||||
prec = prec * 10 + (ch - '0');
|
||||
} else if (ch == '*') {
|
||||
prec = va_arg(ap, int);
|
||||
if (prec < 0)
|
||||
prec = -1;
|
||||
} else {
|
||||
state = st_modifiers;
|
||||
p--; /* Process this character again */
|
||||
}
|
||||
break;
|
||||
|
||||
case st_modifiers:
|
||||
switch (ch) {
|
||||
/* Length modifiers - nonterminal sequences */
|
||||
case 'h':
|
||||
rank--; /* Shorter rank */
|
||||
break;
|
||||
case 'l':
|
||||
rank++; /* Longer rank */
|
||||
break;
|
||||
case 'j':
|
||||
rank = INTMAX_RANK;
|
||||
break;
|
||||
case 'z':
|
||||
rank = SIZE_T_RANK;
|
||||
break;
|
||||
case 't':
|
||||
rank = PTRDIFF_T_RANK;
|
||||
break;
|
||||
case 'L':
|
||||
case 'q':
|
||||
rank += 2;
|
||||
break;
|
||||
default:
|
||||
/* Output modifiers - terminal sequences */
|
||||
|
||||
/* Next state will be normal */
|
||||
state = st_normal;
|
||||
|
||||
/* Canonicalize rank */
|
||||
if (rank < MIN_RANK)
|
||||
rank = MIN_RANK;
|
||||
else if (rank > MAX_RANK)
|
||||
rank = MAX_RANK;
|
||||
|
||||
switch (ch) {
|
||||
case 'P': /* Upper case pointer */
|
||||
flags |= FL_UPPER;
|
||||
/* fall through */
|
||||
case 'p': /* Pointer */
|
||||
base = 16;
|
||||
prec = (CHAR_BIT*sizeof(void *)+3)/4;
|
||||
flags |= FL_HASH;
|
||||
val = (uintmax_t)(uintptr_t)
|
||||
va_arg(ap, void *);
|
||||
goto is_integer;
|
||||
|
||||
case 'd': /* Signed decimal output */
|
||||
case 'i':
|
||||
base = 10;
|
||||
flags |= FL_SIGNED;
|
||||
switch (rank) {
|
||||
case rank_char:
|
||||
/* Yes, all these casts are
|
||||
needed... */
|
||||
val = (uintmax_t)(intmax_t)
|
||||
(signed char)
|
||||
va_arg(ap, signed int);
|
||||
break;
|
||||
case rank_short:
|
||||
val = (uintmax_t)(intmax_t)
|
||||
(signed short)
|
||||
va_arg(ap, signed int);
|
||||
break;
|
||||
case rank_int:
|
||||
val = (uintmax_t)(intmax_t)
|
||||
va_arg(ap, signed int);
|
||||
break;
|
||||
case rank_long:
|
||||
val = (uintmax_t)(intmax_t)
|
||||
va_arg(ap, signed long);
|
||||
break;
|
||||
case rank_longlong:
|
||||
val = (uintmax_t)(intmax_t)
|
||||
va_arg(ap,
|
||||
int64_t);
|
||||
break;
|
||||
}
|
||||
goto is_integer;
|
||||
case 'o': /* Octal */
|
||||
base = 8;
|
||||
goto is_unsigned;
|
||||
case 'u': /* Unsigned decimal */
|
||||
base = 10;
|
||||
goto is_unsigned;
|
||||
case 'X': /* Upper case hexadecimal */
|
||||
flags |= FL_UPPER;
|
||||
/* fall through */
|
||||
case 'x': /* Hexadecimal */
|
||||
base = 16;
|
||||
goto is_unsigned;
|
||||
|
||||
is_unsigned:
|
||||
switch (rank) {
|
||||
case rank_char:
|
||||
val = (uintmax_t)
|
||||
(unsigned char)
|
||||
va_arg(ap, unsigned
|
||||
int);
|
||||
break;
|
||||
case rank_short:
|
||||
val = (uintmax_t)
|
||||
(unsigned short)
|
||||
va_arg(ap, unsigned
|
||||
int);
|
||||
break;
|
||||
case rank_int:
|
||||
val = (uintmax_t)
|
||||
va_arg(ap, unsigned
|
||||
int);
|
||||
break;
|
||||
case rank_long:
|
||||
val = (uintmax_t)
|
||||
va_arg(ap, unsigned
|
||||
long);
|
||||
break;
|
||||
case rank_longlong:
|
||||
val = (uintmax_t)
|
||||
va_arg(ap, uint64_t);
|
||||
break;
|
||||
}
|
||||
/* fall through */
|
||||
|
||||
is_integer:
|
||||
sz = format_int(q, (o < n) ? n - o : 0,
|
||||
val, flags, base,
|
||||
width, prec);
|
||||
q += sz;
|
||||
o += sz;
|
||||
break;
|
||||
|
||||
case 'c': /* Character */
|
||||
carg = (char)va_arg(ap, int);
|
||||
sarg = &carg;
|
||||
slen = 1;
|
||||
goto is_string;
|
||||
case 's': /* String */
|
||||
sarg = va_arg(ap, const char *);
|
||||
sarg = sarg ? sarg : "(null)";
|
||||
slen = strlen(sarg);
|
||||
goto is_string;
|
||||
|
||||
is_string:
|
||||
{
|
||||
char sch;
|
||||
int i;
|
||||
|
||||
if (prec != -1 && slen > prec)
|
||||
slen = prec;
|
||||
|
||||
if (width > slen
|
||||
&& !(flags & FL_MINUS)) {
|
||||
char pad =
|
||||
(flags & FL_ZERO) ?
|
||||
'0' : ' ';
|
||||
while (width > slen) {
|
||||
EMIT(pad);
|
||||
width--;
|
||||
}
|
||||
}
|
||||
for (i = slen; i; i--) {
|
||||
sch = *sarg++;
|
||||
EMIT(sch);
|
||||
}
|
||||
if (width > slen
|
||||
&& (flags & FL_MINUS)) {
|
||||
while (width > slen) {
|
||||
EMIT(' ');
|
||||
width--;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
{
|
||||
/* Output the number of
|
||||
characters written */
|
||||
|
||||
switch (rank) {
|
||||
case rank_char:
|
||||
*va_arg(ap,
|
||||
signed char *)
|
||||
= o;
|
||||
break;
|
||||
case rank_short:
|
||||
*va_arg(ap,
|
||||
signed short *)
|
||||
= o;
|
||||
break;
|
||||
case rank_int:
|
||||
*va_arg(ap,
|
||||
signed int *)
|
||||
= o;
|
||||
break;
|
||||
case rank_long:
|
||||
*va_arg(ap,
|
||||
signed long *)
|
||||
= o;
|
||||
break;
|
||||
case rank_longlong:
|
||||
*va_arg(ap,
|
||||
int64_t *)
|
||||
= o;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default: /* Anything else, including % */
|
||||
EMIT(ch);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Null-terminate the string */
|
||||
if (o < n)
|
||||
*q = '\0'; /* No overflow */
|
||||
else if (n > 0)
|
||||
buffer[n - 1] = '\0'; /* Overflow - terminate at end of buffer */
|
||||
|
||||
return o;
|
||||
}
|
11
kexcrt/vsprintf.c
Normal file
11
kexcrt/vsprintf.c
Normal file
@ -0,0 +1,11 @@
|
||||
/*
|
||||
* vsprintf.c
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
int vsprintf(char *buffer, const char *format, va_list ap)
|
||||
{
|
||||
return vsnprintf(buffer, ~(size_t) 0, format, ap);
|
||||
}
|
411
kexcrt/vsscanf.c
Normal file
411
kexcrt/vsscanf.c
Normal file
@ -0,0 +1,411 @@
|
||||
/*
|
||||
* vsscanf.c
|
||||
*
|
||||
* vsscanf(), from which the rest of the scanf()
|
||||
* family is built
|
||||
*/
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifndef LONG_BIT
|
||||
#define LONG_BIT (CHAR_BIT*sizeof(long))
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# define inline __inline
|
||||
#endif
|
||||
|
||||
enum flags {
|
||||
FL_SPLAT = 0x01, /* Drop the value, do not assign */
|
||||
FL_INV = 0x02, /* Character-set with inverse */
|
||||
FL_WIDTH = 0x04, /* Field width specified */
|
||||
FL_MINUS = 0x08, /* Negative number */
|
||||
};
|
||||
|
||||
enum ranks {
|
||||
rank_char = -2,
|
||||
rank_short = -1,
|
||||
rank_int = 0,
|
||||
rank_long = 1,
|
||||
rank_longlong = 2,
|
||||
rank_ptr = INT_MAX /* Special value used for pointers */
|
||||
};
|
||||
|
||||
#define MIN_RANK rank_char
|
||||
#define MAX_RANK rank_longlong
|
||||
|
||||
#define INTMAX_RANK rank_longlong
|
||||
#define SIZE_T_RANK rank_long
|
||||
#define PTRDIFF_T_RANK rank_long
|
||||
|
||||
enum bail {
|
||||
bail_none = 0, /* No error condition */
|
||||
bail_eof, /* Hit EOF */
|
||||
bail_err /* Conversion mismatch */
|
||||
};
|
||||
|
||||
static inline const char *skipspace(const char *p)
|
||||
{
|
||||
while (isspace((unsigned char)*p))
|
||||
p++;
|
||||
return p;
|
||||
}
|
||||
|
||||
#undef set_bit
|
||||
static inline void set_bit(unsigned long *bitmap, unsigned int bit)
|
||||
{
|
||||
bitmap[bit / LONG_BIT] |= 1UL << (bit % LONG_BIT);
|
||||
}
|
||||
|
||||
#undef test_bit
|
||||
static inline int test_bit(unsigned long *bitmap, unsigned int bit)
|
||||
{
|
||||
return (int)(bitmap[bit / LONG_BIT] >> (bit % LONG_BIT)) & 1;
|
||||
}
|
||||
|
||||
int vsscanf(const char *buffer, const char *format, va_list ap)
|
||||
{
|
||||
const char *p = format;
|
||||
char ch;
|
||||
unsigned char uc;
|
||||
const char *q = buffer;
|
||||
const char *qq;
|
||||
uintmax_t val = 0;
|
||||
int rank = rank_int; /* Default rank */
|
||||
unsigned int width = UINT_MAX;
|
||||
int base;
|
||||
enum flags flags = 0;
|
||||
enum {
|
||||
st_normal, /* Ground state */
|
||||
st_flags, /* Special flags */
|
||||
st_width, /* Field width */
|
||||
st_modifiers, /* Length or conversion modifiers */
|
||||
st_match_init, /* Initial state of %[ sequence */
|
||||
st_match, /* Main state of %[ sequence */
|
||||
st_match_range, /* After - in a %[ sequence */
|
||||
} state = st_normal;
|
||||
char *sarg = NULL; /* %s %c or %[ string argument */
|
||||
enum bail bail = bail_none;
|
||||
int sign;
|
||||
int converted = 0; /* Successful conversions */
|
||||
unsigned long matchmap[((1 << CHAR_BIT) + (LONG_BIT - 1)) / LONG_BIT];
|
||||
int matchinv = 0; /* Is match map inverted? */
|
||||
unsigned char range_start = 0;
|
||||
|
||||
while ((ch = *p++) && !bail) {
|
||||
switch (state) {
|
||||
case st_normal:
|
||||
if (ch == '%') {
|
||||
state = st_flags;
|
||||
flags = 0;
|
||||
rank = rank_int;
|
||||
width = UINT_MAX;
|
||||
} else if (isspace((unsigned char)ch)) {
|
||||
q = skipspace(q);
|
||||
} else {
|
||||
if (*q == ch)
|
||||
q++;
|
||||
else
|
||||
bail = bail_err; /* Match failure */
|
||||
}
|
||||
break;
|
||||
|
||||
case st_flags:
|
||||
switch (ch) {
|
||||
case '*':
|
||||
flags |= FL_SPLAT;
|
||||
break;
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
width = (ch - '0');
|
||||
state = st_width;
|
||||
flags |= FL_WIDTH;
|
||||
break;
|
||||
default:
|
||||
state = st_modifiers;
|
||||
p--; /* Process this character again */
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case st_width:
|
||||
if (ch >= '0' && ch <= '9') {
|
||||
width = width * 10 + (ch - '0');
|
||||
} else {
|
||||
state = st_modifiers;
|
||||
p--; /* Process this character again */
|
||||
}
|
||||
break;
|
||||
|
||||
case st_modifiers:
|
||||
switch (ch) {
|
||||
/* Length modifiers - nonterminal sequences */
|
||||
case 'h':
|
||||
rank--; /* Shorter rank */
|
||||
break;
|
||||
case 'l':
|
||||
rank++; /* Longer rank */
|
||||
break;
|
||||
case 'j':
|
||||
rank = INTMAX_RANK;
|
||||
break;
|
||||
case 'z':
|
||||
rank = SIZE_T_RANK;
|
||||
break;
|
||||
case 't':
|
||||
rank = PTRDIFF_T_RANK;
|
||||
break;
|
||||
case 'L':
|
||||
case 'q':
|
||||
rank = rank_longlong; /* long double/long long */
|
||||
break;
|
||||
|
||||
default:
|
||||
/* Output modifiers - terminal sequences */
|
||||
/* Next state will be normal */
|
||||
state = st_normal;
|
||||
|
||||
/* Canonicalize rank */
|
||||
if (rank < MIN_RANK)
|
||||
rank = MIN_RANK;
|
||||
else if (rank > MAX_RANK)
|
||||
rank = MAX_RANK;
|
||||
|
||||
switch (ch) {
|
||||
case 'P': /* Upper case pointer */
|
||||
case 'p': /* Pointer */
|
||||
rank = rank_ptr;
|
||||
base = 0;
|
||||
sign = 0;
|
||||
goto scan_int;
|
||||
|
||||
case 'i': /* Base-independent integer */
|
||||
base = 0;
|
||||
sign = 1;
|
||||
goto scan_int;
|
||||
|
||||
case 'd': /* Decimal integer */
|
||||
base = 10;
|
||||
sign = 1;
|
||||
goto scan_int;
|
||||
|
||||
case 'o': /* Octal integer */
|
||||
base = 8;
|
||||
sign = 0;
|
||||
goto scan_int;
|
||||
|
||||
case 'u': /* Unsigned decimal integer */
|
||||
base = 10;
|
||||
sign = 0;
|
||||
goto scan_int;
|
||||
|
||||
case 'x': /* Hexadecimal integer */
|
||||
case 'X':
|
||||
base = 16;
|
||||
sign = 0;
|
||||
goto scan_int;
|
||||
|
||||
case 'n': /* # of characters consumed */
|
||||
val = (q - buffer);
|
||||
goto set_integer;
|
||||
|
||||
scan_int:
|
||||
q = skipspace(q);
|
||||
if (!*q) {
|
||||
bail = bail_eof;
|
||||
break;
|
||||
}
|
||||
val =
|
||||
strntoumax(q, (char **)&qq, base,
|
||||
width);
|
||||
if (qq == q) {
|
||||
bail = bail_err;
|
||||
break;
|
||||
}
|
||||
q = qq;
|
||||
if (!(flags & FL_SPLAT))
|
||||
converted++;
|
||||
/* fall through */
|
||||
|
||||
set_integer:
|
||||
if (!(flags & FL_SPLAT)) {
|
||||
switch (rank) {
|
||||
case rank_char:
|
||||
*va_arg(ap,
|
||||
unsigned char *)
|
||||
= val;
|
||||
break;
|
||||
case rank_short:
|
||||
*va_arg(ap,
|
||||
unsigned short
|
||||
*) = val;
|
||||
break;
|
||||
case rank_int:
|
||||
*va_arg(ap,
|
||||
unsigned int *)
|
||||
= val;
|
||||
break;
|
||||
case rank_long:
|
||||
*va_arg(ap,
|
||||
unsigned long *)
|
||||
= val;
|
||||
break;
|
||||
case rank_longlong:
|
||||
*va_arg(ap,
|
||||
uint64_t *) = val;
|
||||
break;
|
||||
case rank_ptr:
|
||||
*va_arg(ap, void **) =
|
||||
(void *)
|
||||
(uintptr_t)val;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'c': /* Character */
|
||||
/* Default width == 1 */
|
||||
width = (flags & FL_WIDTH) ? width : 1;
|
||||
if (flags & FL_SPLAT) {
|
||||
while (width--) {
|
||||
if (!*q) {
|
||||
bail = bail_eof;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
sarg = va_arg(ap, char *);
|
||||
while (width--) {
|
||||
if (!*q) {
|
||||
bail = bail_eof;
|
||||
break;
|
||||
}
|
||||
*sarg++ = *q++;
|
||||
}
|
||||
if (!bail)
|
||||
converted++;
|
||||
}
|
||||
break;
|
||||
|
||||
case 's': /* String */
|
||||
uc = 1; /* Anything nonzero */
|
||||
if (flags & FL_SPLAT) {
|
||||
while (width-- && (uc = *q) &&
|
||||
!isspace(uc)) {
|
||||
q++;
|
||||
}
|
||||
} else {
|
||||
char *sp;
|
||||
sp = sarg = va_arg(ap, char *);
|
||||
while (width-- && (uc = *q) &&
|
||||
!isspace(uc)) {
|
||||
*sp++ = uc;
|
||||
q++;
|
||||
}
|
||||
if (sarg != sp) {
|
||||
/* Terminate output */
|
||||
*sp = '\0';
|
||||
converted++;
|
||||
}
|
||||
}
|
||||
if (!uc)
|
||||
bail = bail_eof;
|
||||
break;
|
||||
|
||||
case '[': /* Character range */
|
||||
sarg = (flags & FL_SPLAT) ? NULL
|
||||
: va_arg(ap, char *);
|
||||
state = st_match_init;
|
||||
matchinv = 0;
|
||||
memset(matchmap, 0, sizeof matchmap);
|
||||
break;
|
||||
|
||||
case '%': /* %% sequence */
|
||||
if (*q == '%')
|
||||
q++;
|
||||
else
|
||||
bail = bail_err;
|
||||
break;
|
||||
|
||||
default: /* Anything else */
|
||||
/* Unknown sequence */
|
||||
bail = bail_err;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case st_match_init: /* Initial state for %[ match */
|
||||
if (ch == '^' && !(flags & FL_INV)) {
|
||||
matchinv = 1;
|
||||
} else {
|
||||
set_bit(matchmap, (unsigned char)ch);
|
||||
state = st_match;
|
||||
}
|
||||
break;
|
||||
|
||||
case st_match: /* Main state for %[ match */
|
||||
if (ch == ']') {
|
||||
goto match_run;
|
||||
} else if (ch == '-') {
|
||||
range_start = (unsigned char)ch;
|
||||
state = st_match_range;
|
||||
} else {
|
||||
set_bit(matchmap, (unsigned char)ch);
|
||||
}
|
||||
break;
|
||||
|
||||
case st_match_range: /* %[ match after - */
|
||||
if (ch == ']') {
|
||||
/* - was last character */
|
||||
set_bit(matchmap, (unsigned char)'-');
|
||||
goto match_run;
|
||||
} else {
|
||||
int i;
|
||||
for (i = range_start; i < (unsigned char)ch;
|
||||
i++)
|
||||
set_bit(matchmap, i);
|
||||
state = st_match;
|
||||
}
|
||||
break;
|
||||
|
||||
match_run: /* Match expression finished */
|
||||
qq = q;
|
||||
uc = 1; /* Anything nonzero */
|
||||
while (width && (uc = *q)
|
||||
&& test_bit(matchmap, uc)^matchinv) {
|
||||
if (sarg)
|
||||
*sarg++ = uc;
|
||||
q++;
|
||||
}
|
||||
if (q != qq && sarg) {
|
||||
*sarg = '\0';
|
||||
converted++;
|
||||
} else {
|
||||
bail = bail_err;
|
||||
}
|
||||
if (!uc)
|
||||
bail = bail_eof;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (bail == bail_eof && !converted)
|
||||
converted = -1; /* Return EOF (-1) */
|
||||
|
||||
return converted;
|
||||
}
|
Reference in New Issue
Block a user