Add headers and fix build

Add more C headers and allow libsb to build correctly with warnings.
This commit is contained in:
Aidan C. Mullen 2025-03-08 22:33:48 -05:00
parent 103ffffbd7
commit 943afc734f
22 changed files with 6155 additions and 38 deletions

27
.gitignore vendored
View file

@ -26,13 +26,6 @@
!/bld/src/
/bld/src/*
# /bld/src/d
!/bld/src/d/
/bld/src/d/*
!/bld/src/d/dub.sdl
!/bld/src/d/dub.selections.json
# /doc
!/doc/
/doc/*
@ -124,6 +117,26 @@
!/src/init/c/gdextension_interface.c
# /src/init/c/util
!/src/init/c/util
/src/init/c/util/*
!/src/init/c/util/inttypes.c
!/src/init/c/util/inttypes.h
!/src/init/c/util/iso646.h
!/src/init/c/util/locale.c
!/src/init/c/util/locale.h
!/src/init/c/util/Q8defs.h
!/src/init/c/util/signal.c
!/src/init/c/util/signal.h
!/src/init/c/util/sitest.c
!/src/init/c/util/stdbool.h
!/src/init/c/util/stdint.h
!/src/init/c/util/wchar.c
!/src/init/c/util/wchar.h
!/src/init/c/util/wctype.c
!/src/init/c/util/wctype.h
# /src/init/cpp
!/src/init/cpp/
/src/init/cpp/*

9
README
View file

@ -13,10 +13,19 @@ installed to run the compiled binary.
- Godot 4.4
- Vulkan Developement Libraries (version compatible with Godot 4.4)
- Godot Jolt
- Boost C++ Libraries: https://www.boost.org/
- cwebsocket: https://github.com/jeremyhahn/cwebsocket
- TinyCThread: https://github.com/tinycthread/tinycthread
Some platforms may require that shared libraries be placed alongside the
source files, such as MSYS-2.0.dll.
C Reference:
https://en.cppreference.com/w/c
C++ Reference:
https://en.cppreference.com/w/
Build
-----

View file

@ -18,3 +18,5 @@ automake --add-missing
# Disable static linking and enable GUI component; builds complete version.
./configure --disable-static --enable-shared
make
cp ./src/.libs/* ./bld/obj/

View file

@ -1,13 +1,13 @@
# Title, version, etc.
AC_INIT(\
[RTR], \
[SB0], \
[0.1.0], \
[mail@acm.contact], \
[rtr], \
[sb0], \
[https://www.delay.cloud/] \
)
AC_COPYRIGHT(ISC License)
AC_COPYRIGHT(All rights reserved.)
# AC_CHECK_LIB is not utilized, since it checks the presence of libraries by
# linking them to test program; this process introduces more overhead and longer
@ -57,8 +57,16 @@ AC_CONFIG_FILES([\
AC_CONFIG_SRCDIR([src/main.c])
CFLAGS="$CFLAGS -std=c99 -pedantic-errors -Wall -Wold-style-definition -Wextra \
-Wmissing-prototypes -Wstrict-prototypes" # Compile to C11
CFLAGS="$CFLAGS -std=c89 -pedantic-errors -Wall -Wold-style-definition -Wextra \
-Wmissing-prototypes -Wstrict-prototypes" # Compile to C89
# without
# GNU extensions.
# Warnings on.
# Change -std=c++98 to -std=c++11.
CXXFLAGS="$CFLAGS -std=c++98 -pedantic-errors -Wall -Wold-style-definition \
-Wextra -Wmissing-prototypes -Wstrict-prototypes" # Compile to C++98
# without
# GNU extensions.
# Warnings on.
@ -67,6 +75,7 @@ LT_INIT([shared disable-static]) # Start GNU Libtool. Satic libraries
# disabled; shared/dynamic linking.
AC_PROG_CC([gcc]) # Autoconf for C compiler; obviously set to use GCC.
AC_PROG_CXX([g++])
AC_OUTPUT # Generate files.

View file

@ -1,13 +1,10 @@
[configuration]
entry_symbol = "libsb_init"
entry_symbol = "libsb"
compatibility_minimum = "4.4"
[libraries]
linux.x86_64 = "res://../bld/obj/.libs/libbind.so"
linux.x86_64 = "res://../bld/obj/.libs/libsb.so"
darwin.x86_64 = "res://../bld/obj/.libs/libbind.dylib"
darwin.x86_64 = "res://../bld/obj/.libs/libsb.dylib"
windows.x86_64 = "res://../bld/obj/.libs/libbind.dll"
windows.x86_64 = "res://../bld/obj/.libs/libsb.dll"
linux.x86_64 = "res://../bld/obj/libsb.so"
darwin.x86_64 = "res://../bld/obj/libsb.dylib"
windows.x86_64 = "res://../bld/obj/libsb.dll"

View file

@ -3,11 +3,14 @@
#bin_PROGRAMS = $(top_builddir)/bin/rtr # Program name.
#__top_builddir__bin_rtr_CFLAGS = -DBUILD # Define BUILD variable.
#__top_builddir__bin_rtr_SOURCES = main.c # Sources
lib_LTLIBRARIES = librtr.la
librtr_la_SOURCES = main.c
# The .la extension is an AutoTools library format that is automatically
# converted into the host OS's object format.
lib_LTLIBRARIES = libsb.la
libsb_la_SOURCES = main.c
# Compile as shared library.
librtr_la_LDFLAGS = -module -avoid-version -export-dynamic -no-undefined
libsb_la_LDFLAGS = -module -avoid-version -export-dynamic -no-undefined
#bin_PROGRAMS = rtr
#rtr_CFLAGS = -DBUILD -c -fPIC -shared # Define BUILD and output shared.

629
src/init/c/util/Q8defs.h Normal file
View file

@ -0,0 +1,629 @@
/*
Q8defs.h -- defines platform-specific parameters for standard headers
This source code has been placed into the PUBLIC DOMAIN by its author.
last edit: 1999/11/05 gwyn@arl.mil
Several of the standard headers provided by Doug Gwyn make use
of these __Q8_* symbols. If you want to define other names of
the form __Q8_*, please coordinate them with gwyn@arl.mil, who
claims "dibs" on (first-come ownership of) that name space.
Aside: Why "Q8"? That was used as a system external symbol
prefix in old CDC Fortran implementations, to avoid link-time
name-space collisions with user-defined symbols, on the
assumption that no user would ever think of using such a name.
*/
/* This header doesn't need an idempotency lock; there are no typedefs here. */
/* This header doesn't need C++ extern "C"; there are no declarations here. */
#define __Q8_TEST /* [undef to disable configuration checks] */
#define _SYS_INT_TYPES_H /* kludge to override Solaris header */
#define _SYS_INT_LIMITS_H /* ditto */
/*
The following macros come in handy in many situations.
*/
/* splice arguments into one token */
#ifdef __STDC__
#define __Q8_1J(a,b) a ## b
#define __Q8_2J(a,b) __Q8_1J(a,b)
#else
#define __Q8_1J(a) a
#define __Q8_2J(a,b) __Q8_1J(a)b
#endif
/* older versions of C didn't have certain type qualifiers */
#ifdef __STDC__
#define __Q8_CONST const
#else
#define __Q8_CONST
#endif
#if __STDC_VERSION__ >= 199901
#define __Q8_RESTRICT restrict
#else
#define __Q8_RESTRICT /* nothing */
#endif
/* older versions of C don't support function prototypes */
#ifdef __STDC__
#define __Q8_PARAMS(a) a
#else
#define __Q8_PARAMS(a) ()
#endif
/* usage: return_type func_name __Q8_PARAMS((param_decls)); */
/*
The following is based on the MUVES "Va" (variable argument) package.
created: 94/08/16 D A Gwyn
The Va package provides portable support for functions taking
a variable number of arguments. It defines several macros
that work together to hide the differences between the old
UNIX <varargs.h> facility and the new Standard C <stdarg.h>.
Rather than describing each Va package macro separately, it is
best to give an example of the proper usage of the whole set of
macros. It should be easy to adapt this generic example to any
specific requirement.
The example is for a function named Advise that has two
required arguments, the first being a printf-like format string
and the second a flag that indicates (when true) that an extra
"verbosity level" is provided as the third argument. Remaining
arguments are those, if any, associated with the format string.
The Advise function prints the formatted result on the standard
error output if and only if the verbosity level is given and is
greater than 0. It returns true unless it had trouble printing
on the standard error output stream.
Any code that wants to invoke the Advise function must include
a proper declaration for it:
#include <Q8defs.h> // includes Va package
extern bool Advise( __Q8_T(const char *) __Q8_T(bool) __Q8_Dots );
// alternatively:
// extern bool Advise __Q8_PARAMS(( const char *, bool, ... ));
The implementation of the Advise function might be:
#include <stdbool.h>
#include <stdio.h>
#ifdef __STDC__
#include <stdarg.h>
#else
#include <varargs.h>
#endif
#include <Q8defs.h>
// VARARGS // not VARARGS2
bool
Advise( __Q8_T( const char *format ) __Q8_T( bool verbose ) __Q8_AList )
__Q8_Dcl
{
__Q8_D( const char * format )
__Q8_D( bool verbose )
__Q8_List( ap )
register int verbosity;
register bool status;
__Q8_Start( ap, verbose )
__Q8_I( ap, char *, format ) // no "const" here
__Q8_I( ap, bool, verbose )
if ( verbose )
verbosity = __Q8_Arg( ap, int );
else
verbosity = 0;
if ( verbosity > 0 )
status = vfprintf( stderr, format, ap ) > 0;
else
status = true;
__Q8_End( ap )
return status;
}
Note that several of these macros are reminiscent of the va_*
macros in <varargs.h> or <stdarg.h>, but there are significant
differences. Proper usage of the "function-like" macros, in
particular, does not require semicolons; this is intentional,
in order to avoid warnings about "null statements" from certain
compilers and "lint". The easiest way to ensure correct usage
is to copy the above example and then make changes to the copy
as needed for the specific application.
*/
#ifdef __STDC__
#define __Q8_T(t) t,
#define __Q8_Dots ...
#define __Q8_AList ...
#define __Q8_D(d) /* nothing */
#define __Q8_Dcl /* nothing */
#define __Q8_List(ap) va_list ap;
#define __Q8_Start(ap, A0) va_start(ap, A0);
#define __Q8_I(ap, T, Ai) /* nothing */
#define __Q8_Arg(ap, T) va_arg(ap, T)
#define __Q8_End(ap) va_end(ap);
#else /* "classic" version of UNIX assumed */
#define __Q8_T(t) /* nothing */
#define __Q8_Dots /* nothing */
#define __Q8_AList va_alist
#define __Q8_D(d) d;
#define __Q8_Dcl va_dcl
#define __Q8_List(ap) va_list ap;
#define __Q8_Start(ap, A0) va_start(ap);
#define __Q8_I(ap, T, Ai) Ai = va_arg(ap, T);
#define __Q8_Arg(ap, T) va_arg(ap, T)
#define __Q8_End(ap) va_end(ap);
#endif
/*
The following are used to define macros in multiple headers.
*/
/* NOTE: The following must be spelled *exactly* like EOF in <stdio.h>. */
#define __Q8_EOF (-1)
/* XXX -- not currently used in the headers I provide. */
/* NOTE: The following must be spelled *exactly* like NULL in <stddef.h> etc. */
#if defined(_LP64) && !defined(__cplusplus) /* Why? */
#define __Q8_NULL 0L
#else
#define __Q8_NULL 0
#endif
#define __Q8_WEOF ((wint_t)-1)
/*
The following are used to typedef types in multiple headers.
*/
#define __Q8_MBSTATE_T int /* dummy; usually a struct */
#define __Q8_WINT_T int /* this type works nearly everywhere */
#define __Q8_FILE FILE /* must match <stdio.h> */
/* XXX -- At present, __Q8_FILE requires #including <stdio.h>. */
/* XXX -- the following are not currently used in the headers I provide. */
#define __Q8_SIZE_T unsigned long /* this type works nearly everywhere */
#define __Q8_WCHAR_T char /* for minimal implementations */
/* XXX -- this is incomplete; these should be coupled with the following
parameter definitions, and their limits should be computed and defined. */
/*
The following defines parameters for supported types;
they are used mainly by <stdint.h>.
C:char S:short I:int L:long P:void* Q:long long M:max-width int.
D:ptrdiff_t A:sig_atomic_t Z:size_t W:wchar_t X:wint_t
G:long double
followed by W:width T:type U:is unsigned S:suffix for constant
F:printf/scanf length modifier
TC:twos-complement OC:ones-complement SM:signed-magnitude
SC:"signed char" or "char" if signed
These values depend strongly on the architecture and compiler;
the only combinations included here are the ones I use myself.
Please add your particular combination and e-mail me the edits.
XXX -- system parameters really ought to be in a separate header.
*/
#if defined(__i386) /* Intel x86, 32-bit, Sun Solaris */
#define __Q8_TC
#define __Q8_SC /* signed */ char
#define __Q8_CW 8
#define __Q8_SW 16
#define __Q8_IW 32
#define __Q8_LW 32
#define __Q8_PW 32
#define __Q8_DW 32
#define __Q8_AW 32
#undef __Q8_AU
#define __Q8_ZW 32
#define __Q8_WW 32
#undef __Q8_WU
#define __Q8_XW 32
#undef __Q8_XU
#if __STDC_VERSION__ >= 199901
#define __Q8_CF "hh"
#else
#undef __Q8_CF /* no known length modifier for character type */
#endif
#define __Q8_QW 64
#define __Q8_QT long long
#define __Q8_QS LL
#define __Q8_QF "ll"
#define __Q8_MW __Q8_QW
#define __Q8_MT __Q8_QT
#define __Q8_MS __Q8_QS
#define __Q8_MF __Q8_QF
#define __Q8_GT long double
#elif defined(_M_IX86) /* Intel x86, 32-bit, Microsoft */
#define __Q8_TC
#define __Q8_SC signed char
#define __Q8_CW 8
#define __Q8_SW 16
#define __Q8_IW 32
#define __Q8_LW 32
#define __Q8_PW 32
#define __Q8_DW 32
#define __Q8_AW 32
#undef __Q8_AU
#define __Q8_ZW 32
#define __Q8_WW 32
#undef __Q8_WU
#define __Q8_XW 32
#undef __Q8_XU
#if __STDC_VERSION__ >= 199901
#define __Q8_CF "hh"
#define __Q8_QW 64
#define __Q8_QT long long
#define __Q8_QS LL
#define __Q8_QF "ll"
#else
#undef __Q8_CF /* no known length modifier for character type */
#define __Q8_QW 64
#define __Q8_QT __int64
#define __Q8_QS i64
#define __Q8_QF "I64"
#endif
#define __Q8_MW __Q8_QW
#define __Q8_MT __Q8_QT
#define __Q8_MS __Q8_QS
#define __Q8_MF __Q8_QF
#define __Q8_GT long double
#elif defined(__sparc) /* SPARC, Sun Solaris */
#define __Q8_TC
#define __Q8_SC /* signed */ char
#define __Q8_CW 8
#define __Q8_SW 16
#define __Q8_IW 32
#define __Q8_AW 32
#undef __Q8_AU
#ifdef __sparcv9 /* 64-bit environment */
#define __Q8_LW 64
#else /* 32-bit environment */
#define __Q8_LW 32
#endif
#define __Q8_PW __Q8_LW
#define __Q8_DW __Q8_LW
#define __Q8_ZW __Q8_LW
#define __Q8_WW __Q8_LW
#undef __Q8_WU
#define __Q8_XW __Q8_LW
#undef __Q8_XU
#if __STDC_VERSION__ >= 199901
#define __Q8_CF "hh"
#else
#undef __Q8_CF /* no known length modifier for character type */
#endif
#define __Q8_QW 64
#define __Q8_QT long long
#define __Q8_QS LL
#define __Q8_QF "ll"
#define __Q8_MW __Q8_QW
#define __Q8_MT __Q8_QT
#define __Q8_MS __Q8_QS
#define __Q8_MF __Q8_QF
#define __Q8_GT long double
#elif defined(_TMS320C6000) /* TI TMS320C6xxx DSP, Code Composer */
#define __Q8_TC
#define __Q8_SC signed char
#define __Q8_CW 8
#define __Q8_SW 16
#define __Q8_IW 32
#define __Q8_AW 32
#undef __Q8_AU
#define __Q8_LW 40
#define __Q8_PW 32
#define __Q8_DW 32
#define __Q8_ZW 32
#define __Q8_WW 8
#define __Q8_WU /* XXX -- check */
#define __Q8_XW 32
#undef __Q8_XU
#if __STDC_VERSION__ >= 199901
#define __Q8_CF "hh"
#define __Q8_QW 64
#define __Q8_QT long long
#define __Q8_QS LL
#define __Q8_QF "ll"
#define __Q8_MW __Q8_QW
#define __Q8_MT __Q8_QT
#define __Q8_MS __Q8_QS
#define __Q8_MF __Q8_QF
#else
#undef __Q8_CF /* no known length modifier for character type */
#define __Q8_MW __Q8_LW
#define __Q8_MT long
#define __Q8_MS L
#define __Q8_MF "l"
#endif
#define __Q8_GT long double
#elif defined(__vax) /* DEC VAX-11 */
#define __Q8_TC
#define __Q8_SC /* signed */ char
#define __Q8_CW 8
#define __Q8_SW 16
#define __Q8_IW 32
#define __Q8_LW 32
#define __Q8_PW 32
#define __Q8_DW 32
#define __Q8_AW 32
#undef __Q8_AU
#define __Q8_ZW 32
#define __Q8_WW 32
#undef __Q8_WU
#define __Q8_XW 32
#undef __Q8_XU
#if __STDC_VERSION__ >= 199901
#define __Q8_CF "hh"
#define __Q8_QW 64
#define __Q8_QT long long
#define __Q8_QS LL
#define __Q8_QF "ll"
#define __Q8_MW __Q8_QW
#define __Q8_MT __Q8_QT
#define __Q8_MS __Q8_QS
#define __Q8_MF __Q8_QF
#define __Q8_GT long double
#else
#undef __Q8_CF /* no known length modifier for character type */
#define __Q8_MW 32
#define __Q8_MT long
#define __Q8_MS L
#undef __Q8_GT /* long double not supported */
#endif
#elif defined(__pdp11) /* DEC PDP-11 */
#define __Q8_TC
#define __Q8_SC /* signed */ char
#define __Q8_CW 8
#define __Q8_SW 16
#define __Q8_IW 16
#define __Q8_LW 32
#define __Q8_PW 16 /* (violates section 5.2.4.1) */
#define __Q8_DW 16 /* (violates section 5.2.4.1) */
#define __Q8_AW 16
#undef __Q8_AU
#define __Q8_ZW 16
#define __Q8_WW 32
#undef __Q8_WU
#define __Q8_XW 32
#undef __Q8_XU
#if __STDC_VERSION__ >= 199901
#define __Q8_CF "hh"
#define __Q8_QW 64
#define __Q8_QT long long
#define __Q8_QS LL
#define __Q8_QF "ll"
#define __Q8_MW __Q8_QW
#define __Q8_MT __Q8_QT
#define __Q8_MS __Q8_QS
#define __Q8_MF __Q8_QF
#define __Q8_GT long double
#else
#undef __Q8_CF /* no known length modifier for character type */
#define __Q8_MW 32
#define __Q8_MT long
#define __Q8_MS L
#define __Q8_MF "l"
#undef __Q8_GT /* long double not supported */
#endif
#elif defined(__ORCAC__) /* Apple IIGS, large memory model */
/* #pragma optimize -1 /* enables all compiler optimizations */
#define __Q8_TC
#define __Q8_SC signed char
#define __Q8_CW 8
#define __Q8_SW 16
#define __Q8_IW 16
#define __Q8_LW 32
#define __Q8_PW 32
#define __Q8_DW 32
#define __Q8_AW 16
#undef __Q8_AU
#define __Q8_ZW 32 /* XXX -- check */
#define __Q8_WW 32
#undef __Q8_WU
#if __STDC_VERSION__ >= 199901
#define __Q8_CF "hh"
#define __Q8_QW 64
#define __Q8_QT long long
#define __Q8_QS LL
#define __Q8_QF "ll"
#define __Q8_MW __Q8_QW
#define __Q8_MT __Q8_QT
#define __Q8_MS __Q8_QS
#define __Q8_MF __Q8_QF
#else
#undef __Q8_CF /* no known length modifier for character type */
#define __Q8_MW 32
#define __Q8_MT long
#define __Q8_MS L
#define __Q8_MF "l"
#endif
#define __Q8_GT long double
#else
#error "Q8defs.h: unknown CPU type"
#endif
#if defined(__Q8_TEST)
/* sanity checks */
#if defined(__Q8_TC)+defined(__Q8_OC)+defined(__Q8_SM) != 1
#error "Q8defs.h: representation improperly defined"
#endif
#if __Q8_CW < 8
#error "Q8defs.h: __Q8_CW improperly defined"
#endif
#if __Q8_SW < __Q8_CW || __Q8_SW < 16
#error "Q8defs.h: __Q8_SW improperly defined"
#endif
#if __Q8_IW < __Q8_SW
#error "Q8defs.h: __Q8_IW improperly defined"
#endif
#if __Q8_LW < __Q8_IW || __Q8_LW < 32
#error "Q8defs.h: __Q8_LW improperly defined"
#endif
#ifdef __Q8_PW
#if __Q8_PW < 16 || __Q8_PW < __Q8_CW || \
__STDC_VERSION__ >= 199901 && __Q8_PW < 17
#error "Q8defs.h: __Q8_PW improperly defined"
#endif
#endif
#ifdef __Q8_DW
#if __Q8_DW < 16 || __Q8_DW < __Q8_CW || \
__STDC_VERSION__ >= 199901 && __Q8_DW < 17
#error "Q8defs.h: __Q8_DW improperly defined"
#endif
#endif
#if __Q8_AW < __Q8_CW
#error "Q8defs.h: __Q8_AW improperly defined"
#endif
#if __Q8_ZW < 16 || __Q8_ZW < __Q8_CW
#error "Q8defs.h: __Q8_ZW improperly defined"
#endif
#if __Q8_WW < __Q8_CW
#error "Q8defs.h: __Q8_WW improperly defined"
#endif
#if __Q8_XW < 16 || __Q8_XW < __Q8_CW
#error "Q8defs.h: __Q8_XW improperly defined"
#endif
#ifdef __Q8_QT
#if __Q8_QW < __Q8_LW || __Q8_QW < 64
#error "Q8defs.h: __Q8_QW improperly defined"
#endif
#elif __STDC_VERSION__ >= 199901
#error "Q8defs.h: __Q8_QT not defined"
#endif
#if __Q8_MW < __Q8_LW || defined(__Q8_QT) && __Q8_MW < __Q8_QW
#error "Q8defs.h: __Q8_MW improperly defined"
#endif
#ifndef __Q8_MT
#error "Q8defs.h: __Q8_MT not defined"
#endif
#endif /* defined(__Q8_TEST) */
/* limits for various types */
/* top signed values */
#define __Q8_TI(w) (~(~0<<(w)-1))
#define __Q8_TL (~(~0L<<__Q8_LW-1))
#define __Q8_TQ (~(~__Q8_2J(0,__Q8_QS)<<__Q8_QW-1))
#define __Q8_TM (~(~__Q8_2J(0,__Q8_MS)<<__Q8_MW-1))
/* upper unsigned values */
#define __Q8_UI(w) (~0U>>__Q8_IW-(w))
#define __Q8_UL (~0UL)
#define __Q8_UQ (~__Q8_2J(0U,__Q8_QS))
#define __Q8_UM (~__Q8_2J(0U,__Q8_MS))
/* bottom signed values */
#if defined(__Q8_TC)
#define __Q8_BI(w) (-__Q8_TI(w)-1)
#define __Q8_BL (-__Q8_TL-1)
#define __Q8_BQ (-__Q8_TQ-1)
#define __Q8_BM (-__Q8_TM-1)
#else /* defined(__Q8_OC) || defined(__Q8_SM) */
#define __Q8_BI(w) (-__Q8_TI(w))
#define __Q8_BL (-__Q8_TL)
#define __Q8_BQ (-__Q8_TQ)
#define __Q8_BM (-__Q8_TM)
#endif
#if defined(__Q8_TEST)
/* sanity checks */
#define __Q8_X1 1
#define __Q8_X2 2u
#if __Q8_2J(__Q8_X1,__Q8_X2) != 12u
#error "Q8defs.h: __Q8_2J macro is broken"
#endif
#if __Q8_TI(__Q8_CW) <= 0 || __Q8_BI(__Q8_CW) >= 0 || \
__Q8_TI(__Q8_SW) <= 0 || __Q8_BI(__Q8_SW) >= 0 || \
__Q8_TI(__Q8_IW) <= 0 || __Q8_BI(__Q8_IW) >= 0 || \
__Q8_TI(__Q8_CW) <= __Q8_BI(__Q8_CW) || \
__Q8_TI(__Q8_SW) <= __Q8_BI(__Q8_SW) || \
__Q8_TI(__Q8_IW) <= __Q8_BI(__Q8_IW)
#error "Q8defs.h: __Q8_TI, __Q8_BI macros are broken"
#endif
#if __Q8_UI(__Q8_CW) <= 0 || __Q8_UI(__Q8_CW) <= __Q8_TI(__Q8_CW) || \
__Q8_UI(__Q8_SW) <= 0 || __Q8_UI(__Q8_SW) <= __Q8_TI(__Q8_SW) || \
__Q8_UI(__Q8_IW) <= 0 || __Q8_UI(__Q8_IW) <= __Q8_TI(__Q8_IW)
#error "Q8defs.h: __Q8_UI or __Q8_TI macro is broken"
#endif
#if __Q8_TL <= 0 || __Q8_BL >= 0 || __Q8_TL <= __Q8_BL
#error "Q8defs.h: __Q8_TL, __Q8_BL macros are broken"
#endif
#if __Q8_UL <= 0 || __Q8_UL <= __Q8_TL
#error "Q8defs.h: __Q8_UL or __Q8_TL macro is broken"
#endif
#ifdef __Q8_QT
#if __Q8_TQ <= 0 || __Q8_BQ >= 0 || __Q8_TQ <= __Q8_BQ
#error "Q8defs.h: __Q8_TQ, __Q8_BQ macros are broken"
#endif
#if __Q8_UQ <= 0 || __Q8_UQ <= __Q8_TQ
#if 0 /* XXX -- not working on Solaris */
#error "Q8defs.h: __Q8_UQ or __Q8_TQ macro is broken"
#endif
#endif
#endif
#if __Q8_TM <= 0 || __Q8_BM >= 0 || __Q8_TM <= __Q8_BM
#error "Q8defs.h: __Q8_TM, __Q8_BM macros are broken"
#endif
#if __Q8_UM <= 0 || __Q8_UM <= __Q8_TM
#if 0 /* XXX -- not working on Solaris */
#error "Q8defs.h: __Q8_UM or __Q8_TM macro is broken"
#endif
#endif
#endif /* defined(__Q8_TEST) */

389
src/init/c/util/inttypes.c Normal file
View file

@ -0,0 +1,389 @@
/*
inttypes -- format conversion of integer types
(standard library functions declared by <inttypes.h>)
This source code has been placed into the PUBLIC DOMAIN by its author.
last edit: 1999/11/05 gwyn@arl.mil
Implements subclause 7.8.2 of ISO/IEC 9899:1999 (E).
This particular implementation requires the matching <inttypes.h>.
It also assumes that character codes for A..Z and a..z are in
contiguous ascending order; this is true for ASCII but not EBCDIC.
*/
#include <ctype.h>
#include <errno.h>
#include <stdlib.h>
#include <stdbool.h>
#include <inttypes.h> /* defines various __Q8_* symbols */
#include <wchar.h>
#include <wctype.h>
/* helper macros: */
/* convert digit character to number, in any base */
#define ToNumber(c) (isdigit(c) ? (c) - '0' : \
isupper(c) ? (c) - 'A' + 10 : \
islower(c) ? (c) - 'a' + 10 : \
-1 /* "invalid" flag */ \
)
#define ToWNumber(c) (iswdigit(c) ? (c) - L'0' : \
iswupper(c) ? (c) - L'A' + 10 : \
iswlower(c) ? (c) - L'a' + 10 : \
-1 /* "invalid" flag */ \
)
/* validate converted digit character for specific base */
#define valid(n, b) ((n) >= 0 && (n) < (b))
/*
7.8.2 Functions for greatest-width integer types
*/
intmax_t
imaxabs(j)
intmax_t j;
{
return j >= 0 ? j : -j;
}
imaxdiv_t
imaxdiv(numer, denom)
intmax_t numer, denom;
{
imaxdiv_t result;
result.quot = numer / denom;
result.rem = numer % denom;
return result;
}
intmax_t
strtoimax(nptr, endptr, base)
register __Q8_CONST char *__Q8_RESTRICT nptr;
char **__Q8_RESTRICT endptr;
register int base;
{
register uintmax_t accum; /* accumulates converted value */
register int n; /* numeral from digit character */
bool minus; /* set iff minus sign seen */
bool toobig; /* set iff value overflows */
if ( endptr != NULL )
*endptr = (char *)nptr; /* in case no conversion's performed */
if ( base < 0 || base == 1 || base > 36 )
{
errno = EDOM;
return 0; /* unspecified behavior */
}
/* skip initial, possibly empty sequence of white-space characters */
while ( isspace(*nptr) )
++nptr;
/* process subject sequence: */
/* optional sign */
if ( (minus = *nptr == '-') || *nptr == '+' )
++nptr;
if ( base == 0 )
if ( *nptr == '0' )
if ( nptr[1] == 'X' || nptr[1] == 'x' )
base = 16;
else
base = 8;
else
base = 10;
/* optional "0x" or "0X" for base 16 */
if ( base == 16 && *nptr == '0' && (nptr[1] == 'X' || nptr[1] == 'x') )
nptr += 2; /* skip past this prefix */
/* check whether there is at least one valid digit */
n = ToNumber(*nptr);
++nptr;
if ( !valid(n, base) )
return 0; /* subject seq. not of expected form */
accum = n;
for ( toobig = false; n = ToNumber(*nptr), valid(n, base); ++nptr )
if ( accum > INTMAX_MAX / base + 2 ) /* major wrap-around */
toobig = true; /* but keep scanning */
else
accum = base * accum + n;
if ( endptr != NULL )
*endptr = (char *)nptr; /* points to first not-valid-digit */
#ifdef __Q8_TC /* twos-complement representation */
if ( minus )
{
if ( accum > (uintmax_t)INTMAX_MAX + 1 )
toobig = true;
}
else
#endif
if ( accum > (uintmax_t)INTMAX_MAX )
toobig = true;
if ( toobig )
{
errno = ERANGE;
return minus ? INTMAX_MIN : INTMAX_MAX;
}
else
return (intmax_t)(minus ? -accum : accum);
}
uintmax_t
strtoumax(nptr, endptr, base)
register __Q8_CONST char *__Q8_RESTRICT nptr;
char **__Q8_RESTRICT endptr;
register int base;
{
register uintmax_t accum; /* accumulates converted value */
register uintmax_t next; /* for computing next value of accum */
register int n; /* numeral from digit character */
bool minus; /* set iff minus sign seen (yes!) */
bool toobig; /* set iff value overflows */
if ( endptr != NULL )
*endptr = (char *)nptr; /* in case no conversion's performed */
if ( base < 0 || base == 1 || base > 36 )
{
errno = EDOM;
return 0; /* unspecified behavior */
}
/* skip initial, possibly empty sequence of white-space characters */
while ( isspace(*nptr) )
++nptr;
/* process subject sequence: */
/* optional sign (yes!) */
if ( (minus = *nptr == '-') || *nptr == '+' )
++nptr;
if ( base == 0 )
if ( *nptr == '0' )
if ( nptr[1] == 'X' || nptr[1] == 'x' )
base = 16;
else
base = 8;
else
base = 10;
/* optional "0x" or "0X" for base 16 */
if ( base == 16 && *nptr == '0' && (nptr[1] == 'X' || nptr[1] == 'x') )
nptr += 2; /* skip past this prefix */
/* check whether there is at least one valid digit */
n = ToNumber(*nptr);
++nptr;
if ( !valid(n, base) )
return 0; /* subject seq. not of expected form */
accum = n;
for ( toobig = false; n = ToNumber(*nptr), valid(n, base); ++nptr )
if ( accum > UINTMAX_MAX / base + 1 /* major wrap-around */
|| (next = base * accum + n) < accum /* minor wrap-around */
)
toobig = true; /* but keep scanning */
else
accum = next;
if ( endptr != NULL )
*endptr = (char *)nptr; /* points to first not-valid-digit */
if ( toobig )
{
errno = ERANGE;
return UINTMAX_MAX;
}
else
return minus ? -accum : accum; /* (yes!) */
}
intmax_t
wcstoimax(nptr, endptr, base)
register __Q8_CONST wchar_t *__Q8_RESTRICT nptr;
wchar_t **__Q8_RESTRICT endptr;
register int base;
{
register uintmax_t accum; /* accumulates converted value */
register int n; /* numeral from digit character */
bool minus; /* set iff minus sign seen */
bool toobig; /* set iff value overflows */
if ( endptr != NULL )
*endptr = (wchar_t *)nptr; /* in case no conv performed */
if ( base < 0 || base == 1 || base > 36 )
{
errno = EDOM;
return 0; /* unspecified behavior */
}
/* skip initial, possibly empty sequence of white-space w.characters */
while ( iswspace(*nptr) )
++nptr;
/* process subject sequence: */
/* optional sign */
if ( (minus = *nptr == L'-') || *nptr == L'+' )
++nptr;
if ( base == 0 )
if ( *nptr == L'0' )
if ( nptr[1] == L'X' || nptr[1] == L'x' )
base = 16;
else
base = 8;
else
base = 10;
/* optional "0x" or "0X" for base 16 */
if ( base == 16 && *nptr == L'0'
&& (nptr[1] == L'X' || nptr[1] == L'x')
)
nptr += 2; /* skip past this prefix */
/* check whether there is at least one valid digit */
n = ToWNumber(*nptr);
++nptr;
if ( !valid(n, base) )
return 0; /* subject seq. not of expected form */
accum = n;
for ( toobig = false; n = ToWNumber(*nptr), valid(n, base); ++nptr )
if ( accum > INTMAX_MAX / base + 2 ) /* major wrap-around */
toobig = true; /* but keep scanning */
else
accum = base * accum + n;
if ( endptr != NULL )
*endptr = (wchar_t *)nptr; /* -> first not-valid-digit */
#ifdef __Q8_TC /* twos-complement representation */
if ( minus )
{
if ( accum > (uintmax_t)INTMAX_MAX + 1 )
toobig = true;
}
else
#endif
if ( accum > (uintmax_t)INTMAX_MAX )
toobig = true;
if ( toobig )
{
errno = ERANGE;
return minus ? INTMAX_MIN : INTMAX_MAX;
}
else
return (intmax_t)(minus ? -accum : accum);
}
uintmax_t
wcstoumax(nptr, endptr, base)
register __Q8_CONST wchar_t *__Q8_RESTRICT nptr;
wchar_t **__Q8_RESTRICT endptr;
register int base;
{
register uintmax_t accum; /* accumulates converted value */
register uintmax_t next; /* for computing next value of accum */
register int n; /* numeral from digit character */
bool minus; /* set iff minus sign seen (yes!) */
bool toobig; /* set iff value overflows */
if ( endptr != NULL )
*endptr = (wchar_t *)nptr; /* in case no conv performed */
if ( base < 0 || base == 1 || base > 36 )
{
errno = EDOM;
return 0; /* unspecified behavior */
}
/* skip initial, possibly empty sequence of white-space w.characters */
while ( iswspace(*nptr) )
++nptr;
/* process subject sequence: */
/* optional sign */
if ( (minus = *nptr == L'-') || *nptr == L'+' )
++nptr;
if ( base == 0 )
if ( *nptr == L'0' )
if ( nptr[1] == L'X' || nptr[1] == L'x' )
base = 16;
else
base = 8;
else
base = 10;
/* optional "0x" or "0X" for base 16 */
if ( base == 16 && *nptr == L'0'
&& (nptr[1] == L'X' || nptr[1] == L'x')
)
nptr += 2; /* skip past this prefix */
/* check whether there is at least one valid digit */
n = ToWNumber(*nptr);
++nptr;
if ( !valid(n, base) )
return 0; /* subject seq. not of expected form */
accum = n;
for ( toobig = false; n = ToWNumber(*nptr), valid(n, base); ++nptr )
if ( accum > UINTMAX_MAX / base + 1 /* major wrap-around */
|| (next = base * accum + n) < accum /* minor wrap-around */
)
toobig = true; /* but keep scanning */
else
accum = next;
if ( endptr != NULL )
*endptr = (wchar_t *)nptr; /* -> first not-valid-digit */
if ( toobig )
{
errno = ERANGE;
return UINTMAX_MAX;
}
else
return minus ? -accum : accum; /* (yes!) */
}

757
src/init/c/util/inttypes.h Normal file
View file

@ -0,0 +1,757 @@
/*
inttypes.h -- format conversion of integer types
This source code has been placed into the PUBLIC DOMAIN by its author.
last edit: 1999/11/05 gwyn@arl.mil
Implements subclause 7.8 of ISO/IEC 9899:1999 (E).
This particular implementation requires the matching <stdint.h>
and inttypes.c.
This implementation is SELF-CONFIGURING, based on parameters defined
in <stdint.h>. If you plan to include it in a C implementation,
it would be best to trim it down, with all the parameterized actions
already performed.
*/
#if !defined(_INTTYPES_H) && !defined(_INC_INTTYPES) /* usual */
#define _INTTYPES_H /* idempotency lock (section 7.1.2) */
#define _INC_INTTYPES
#include <stdint.h> /* defines various __Q8_* symbols */
#ifdef __cplusplus
extern "C" {
#endif
/*
type defined by this header (only)
*/
typedef struct
{
intmax_t quot; /* member order must match function */
intmax_t rem;
} imaxdiv_t;
#if !defined(__cplusplus) || defined(__STDC_FORMAT_MACROS)
/* figure out the type of wchar_t */
#ifdef __Q8_WU
#if __Q8_CW >= __Q8_WW
#define __Q8_WT unsigned char
#elif __Q8_SW >= __Q8_WW
#define __Q8_WT unsigned short
#elif __Q8_IW >= __Q8_WW
#define __Q8_WT unsigned int
#elif __Q8_LW >= __Q8_WW
#define __Q8_WT unsigned long
#elif __Q8_QW >= __Q8_WW
#define __Q8_WT unsigned __Q8_QT
#else
#define __Q8_WT unsigned __Q8_MT
#endif
#define WCHAR_MIN 0
#else /* !defined(__Q8_WU) */
#if __Q8_CW >= __Q8_WW && defined(__Q8_SC)
#define __Q8_WT __Q8_SC
#elif __Q8_SW >= __Q8_WW
#define __Q8_WT short
#elif __Q8_IW >= __Q8_WW
#define __Q8_WT int
#elif __Q8_LW >= __Q8_WW
#define __Q8_WT long
#elif __Q8_QW >= __Q8_WW
#define __Q8_WT __Q8_QT
#else
#define __Q8_WT __Q8_MT
#endif
#endif /* defined(__Q8_WU) */
/*
7.8.1 Macros for format specifiers
The optional 40-bit type is supported by the TMS320C6xxx DSP.
Note that there was no length modifier for char type prior to C99.
*/
#if __Q8_CW == 8 && defined(__Q8_SC)
#define PRId8 "d"
#define PRIi8 "i"
#define PRIo8 "o"
#define PRIu8 "u"
#define PRIx8 "x"
#define PRIX8 "X"
#ifdef __Q8_CF
#define SCNd8 __Q8_CF"d"
#define SCNi8 __Q8_CF"i"
#define SCNo8 __Q8_CF"o"
#define SCNu8 __Q8_CF"u"
#define SCNx8 __Q8_CF"x"
#endif
#endif
#if __Q8_CW == 16 && defined(__Q8_SC)
#define PRId16 "d"
#define PRIi16 "i"
#define PRIo16 "o"
#define PRIu16 "u"
#define PRIx16 "x"
#define PRIX16 "X"
#ifdef __Q8_CF
#define SCNd16 __Q8_CF"d"
#define SCNi16 __Q8_CF"i"
#define SCNo16 __Q8_CF"o"
#define SCNu16 __Q8_CF"u"
#define SCNx16 __Q8_CF"x"
#endif
#elif __Q8_SW == 16
#define PRId16 "d"
#define PRIi16 "i"
#define PRIo16 "o"
#define PRIu16 "u"
#define PRIx16 "x"
#define PRIX16 "X"
#define SCNd16 "hd"
#define SCNi16 "hi"
#define SCNo16 "ho"
#define SCNu16 "hu"
#define SCNx16 "hx"
#endif
#if __Q8_CW == 32 && defined(__Q8_SC)
#define PRId32 "d"
#define PRIi32 "i"
#define PRIo32 "o"
#define PRIu32 "u"
#define PRIx32 "x"
#define PRIX32 "X"
#ifdef __Q8_CF
#define SCNd32 __Q8_CF"d"
#define SCNi32 __Q8_CF"i"
#define SCNo32 __Q8_CF"o"
#define SCNu32 __Q8_CF"u"
#define SCNx32 __Q8_CF"x"
#endif
#elif __Q8_SW == 32
#define PRId32 "d"
#define PRIi32 "i"
#define PRIo32 "o"
#define PRIu32 "u"
#define PRIx32 "x"
#define PRIX32 "X"
#define SCNd32 "hd"
#define SCNi32 "hi"
#define SCNo32 "ho"
#define SCNu32 "hu"
#define SCNx32 "hx"
#elif __Q8_IW == 32
#define PRId32 "d"
#define PRIi32 "i"
#define PRIo32 "o"
#define PRIu32 "u"
#define PRIx32 "x"
#define PRIX32 "X"
#define SCNd32 "d"
#define SCNi32 "i"
#define SCNo32 "o"
#define SCNu32 "u"
#define SCNx32 "x"
#elif __Q8_LW == 32
#define PRId32 "ld"
#define PRIi32 "li"
#define PRIo32 "lo"
#define PRIu32 "lu"
#define PRIx32 "lx"
#define PRIX32 "lX"
#define SCNd32 "ld"
#define SCNi32 "li"
#define SCNo32 "lo"
#define SCNu32 "lu"
#define SCNx32 "lx"
#endif
#if __Q8_CW == 40 && defined(__Q8_SC)
#define PRId40 "d"
#define PRIi40 "i"
#define PRIo40 "o"
#define PRIu40 "u"
#define PRIx40 "x"
#define PRIX40 "X"
#ifdef __Q8_CF
#define SCNd40 __Q8_CF"d"
#define SCNi40 __Q8_CF"i"
#define SCNo40 __Q8_CF"o"
#define SCNu40 __Q8_CF"u"
#define SCNx40 __Q8_CF"x"
#endif
#elif __Q8_SW == 40
#define PRId40 "d"
#define PRIi40 "i"
#define PRIo40 "o"
#define PRIu40 "u"
#define PRIx40 "x"
#define PRIX40 "X"
#define SCNd40 "hd"
#define SCNi40 "hi"
#define SCNo40 "ho"
#define SCNu40 "hu"
#define SCNx40 "hx"
#elif __Q8_IW == 40
#define PRId40 "d"
#define PRIi40 "i"
#define PRIo40 "o"
#define PRIu40 "u"
#define PRIx40 "x"
#define PRIX40 "X"
#define SCNd40 "d"
#define SCNi40 "i"
#define SCNo40 "o"
#define SCNu40 "u"
#define SCNx40 "x"
#elif __Q8_LW == 40
#define PRId40 "ld"
#define PRIi40 "li"
#define PRIo40 "lo"
#define PRIu40 "lu"
#define PRIx40 "lx"
#define PRIX40 "lX"
#define SCNd40 "ld"
#define SCNi40 "li"
#define SCNo40 "lo"
#define SCNu40 "lu"
#define SCNx40 "lx"
#endif
#if __Q8_CW == 64 && defined(__Q8_SC)
#define PRId64 "d"
#define PRIi64 "i"
#define PRIo64 "o"
#define PRIu64 "u"
#define PRIx64 "x"
#define PRIX64 "X"
#ifdef __Q8_CF
#define SCNd64 __Q8_CF"d"
#define SCNi64 __Q8_CF"i"
#define SCNo64 __Q8_CF"o"
#define SCNu64 __Q8_CF"u"
#define SCNx64 __Q8_CF"x"
#endif
#elif __Q8_SW == 64
#define PRId64 "d"
#define PRIi64 "i"
#define PRIo64 "o"
#define PRIu64 "u"
#define PRIx64 "x"
#define PRIX64 "X"
#define SCNd64 "hd"
#define SCNi64 "hi"
#define SCNo64 "ho"
#define SCNu64 "hu"
#define SCNx64 "hx"
#elif __Q8_IW == 64
#define PRId64 "d"
#define PRIi64 "i"
#define PRIo64 "o"
#define PRIu64 "u"
#define PRIx64 "x"
#define PRIX64 "X"
#define SCNd64 "d"
#define SCNi64 "i"
#define SCNo64 "o"
#define SCNu64 "u"
#define SCNx64 "x"
#elif __Q8_LW == 64
#define PRId64 "ld"
#define PRIi64 "li"
#define PRIo64 "lo"
#define PRIu64 "lu"
#define PRIx64 "lx"
#define PRIX64 "lX"
#define SCNd64 "ld"
#define SCNi64 "li"
#define SCNo64 "lo"
#define SCNu64 "lu"
#define SCNx64 "lx"
#elif __Q8_QW == 64
#define PRId64 __Q8_QF"d"
#define PRIi64 __Q8_QF"i"
#define PRIo64 __Q8_QF"o"
#define PRIu64 __Q8_QF"u"
#define PRIx64 __Q8_QF"x"
#define PRIX64 __Q8_QF"X"
#define SCNd64 __Q8_QF"d"
#define SCNi64 __Q8_QF"i"
#define SCNo64 __Q8_QF"o"
#define SCNu64 __Q8_QF"u"
#define SCNx64 __Q8_QF"x"
#endif
#if __Q8_CW < __Q8_IW && defined(__Q8_SC)
#define PRIdLEAST8 "d"
#define PRIiLEAST8 "i"
#define PRIoLEAST8 "o"
#define PRIuLEAST8 "u"
#define PRIxLEAST8 "x"
#define PRIXLEAST8 "X"
#ifdef __Q8_CF
#define SCNdLEAST8 __Q8_CF"d"
#define SCNiLEAST8 __Q8_CF"i"
#define SCNoLEAST8 __Q8_CF"o"
#define SCNuLEAST8 __Q8_CF"u"
#define SCNxLEAST8 __Q8_CF"x"
#endif
#elif __Q8_SW < __Q8_IW
#define PRIdLEAST8 "d"
#define PRIiLEAST8 "i"
#define PRIoLEAST8 "o"
#define PRIuLEAST8 "u"
#define PRIxLEAST8 "x"
#define PRIXLEAST8 "X"
#define SCNdLEAST8 "hd"
#define SCNiLEAST8 "hi"
#define SCNoLEAST8 "ho"
#define SCNuLEAST8 "hu"
#define SCNxLEAST8 "hx"
#else
#define PRIdLEAST8 "d"
#define PRIiLEAST8 "i"
#define PRIoLEAST8 "o"
#define PRIuLEAST8 "u"
#define PRIxLEAST8 "x"
#define PRIXLEAST8 "X"
#define SCNdLEAST8 "d"
#define SCNiLEAST8 "i"
#define SCNoLEAST8 "o"
#define SCNuLEAST8 "u"
#define SCNxLEAST8 "x"
#endif
#if __Q8_CW < __Q8_IW && __Q8_CW >= 16 && defined(__Q8_SC)
#define PRIdLEAST16 "d"
#define PRIiLEAST16 "i"
#define PRIoLEAST16 "o"
#define PRIuLEAST16 "u"
#define PRIxLEAST16 "x"
#define PRIXLEAST16 "X"
#ifdef __Q8_CF
#define SCNdLEAST16 __Q8_CF"d"
#define SCNiLEAST16 __Q8_CF"i"
#define SCNoLEAST16 __Q8_CF"o"
#define SCNuLEAST16 __Q8_CF"u"
#define SCNxLEAST16 __Q8_CF"x"
#endif
#elif __Q8_SW < __Q8_IW
#define PRIdLEAST16 "d"
#define PRIiLEAST16 "i"
#define PRIoLEAST16 "o"
#define PRIuLEAST16 "u"
#define PRIxLEAST16 "x"
#define PRIXLEAST16 "X"
#define SCNdLEAST16 "hd"
#define SCNiLEAST16 "hi"
#define SCNoLEAST16 "ho"
#define SCNuLEAST16 "hu"
#define SCNxLEAST16 "hx"
#else
#define PRIdLEAST16 "d"
#define PRIiLEAST16 "i"
#define PRIoLEAST16 "o"
#define PRIuLEAST16 "u"
#define PRIxLEAST16 "x"
#define PRIXLEAST16 "X"
#define SCNdLEAST16 "d"
#define SCNiLEAST16 "i"
#define SCNoLEAST16 "o"
#define SCNuLEAST16 "u"
#define SCNxLEAST16 "x"
#endif
#if __Q8_CW < __Q8_IW && __Q8_CW >= 32 && defined(__Q8_SC)
#define PRIdLEAST32 "d"
#define PRIiLEAST32 "i"
#define PRIoLEAST32 "o"
#define PRIuLEAST32 "u"
#define PRIxLEAST32 "x"
#define PRIXLEAST32 "X"
#ifdef __Q8_CF
#define SCNdLEAST32 __Q8_CF"d"
#define SCNiLEAST32 __Q8_CF"i"
#define SCNoLEAST32 __Q8_CF"o"
#define SCNuLEAST32 __Q8_CF"u"
#define SCNxLEAST32 __Q8_CF"x"
#endif
#elif __Q8_SW < __Q8_IW && __Q8_SW >= 32
#define PRIdLEAST32 "d"
#define PRIiLEAST32 "i"
#define PRIoLEAST32 "o"
#define PRIuLEAST32 "u"
#define PRIxLEAST32 "x"
#define PRIXLEAST32 "X"
#define SCNdLEAST32 "hd"
#define SCNiLEAST32 "hi"
#define SCNoLEAST32 "ho"
#define SCNuLEAST32 "hu"
#define SCNx32 "hx"
#elif __Q8_IW >= 32
#define PRIdLEAST32 "d"
#define PRIiLEAST32 "i"
#define PRIoLEAST32 "o"
#define PRIuLEAST32 "u"
#define PRIxLEAST32 "x"
#define PRIXLEAST32 "X"
#define SCNdLEAST32 "d"
#define SCNiLEAST32 "i"
#define SCNoLEAST32 "o"
#define SCNuLEAST32 "u"
#define SCNxLEAST32 "x"
#else
#define PRIdLEAST32 "ld"
#define PRIiLEAST32 "li"
#define PRIoLEAST32 "lo"
#define PRIuLEAST32 "lu"
#define PRIxLEAST32 "lx"
#define PRIXLEAST32 "lX"
#define SCNdLEAST32 "ld"
#define SCNiLEAST32 "li"
#define SCNoLEAST32 "lo"
#define SCNuLEAST32 "lu"
#define SCNxLEAST32 "lx"
#endif
#if __Q8_CW < __Q8_IW && __Q8_CW >= 40 && defined(__Q8_SC)
#define PRIdLEAST40 "d"
#define PRIiLEAST40 "i"
#define PRIoLEAST40 "o"
#define PRIuLEAST40 "u"
#define PRIxLEAST40 "x"
#define PRIXLEAST40 "X"
#ifdef __Q8_CF
#define SCNdLEAST40 __Q8_CF"d"
#define SCNiLEAST40 __Q8_CF"i"
#define SCNoLEAST40 __Q8_CF"o"
#define SCNuLEAST40 __Q8_CF"u"
#define SCNxLEAST40 __Q8_CF"x"
#endif
#elif __Q8_SW < __Q8_IW && __Q8_SW >= 40
#define PRIdLEAST40 "d"
#define PRIiLEAST40 "i"
#define PRIoLEAST40 "o"
#define PRIuLEAST40 "u"
#define PRIxLEAST40 "x"
#define PRIXLEAST40 "X"
#define SCNdLEAST40 "hd"
#define SCNiLEAST40 "hi"
#define SCNoLEAST40 "ho"
#define SCNuLEAST40 "hu"
#define SCNxLEAST40 "hx"
#elif __Q8_IW >= 40
#define PRIdLEAST40 "d"
#define PRIiLEAST40 "i"
#define PRIoLEAST40 "o"
#define PRIuLEAST40 "u"
#define PRIxLEAST40 "x"
#define PRIXLEAST40 "X"
#define SCNdLEAST40 "d"
#define SCNiLEAST40 "i"
#define SCNoLEAST40 "o"
#define SCNuLEAST40 "u"
#define SCNxLEAST40 "x"
#elif __Q8_LW >= 40
#define PRIdLEAST40 "ld"
#define PRIiLEAST40 "li"
#define PRIoLEAST40 "lo"
#define PRIuLEAST40 "lu"
#define PRIxLEAST40 "lx"
#define PRIXLEAST40 "lX"
#define SCNdLEAST40 "ld"
#define SCNiLEAST40 "li"
#define SCNoLEAST40 "lo"
#define SCNuLEAST40 "lu"
#define SCNxLEAST40 "lx"
#elif __Q8_QW >= 40 /* (will be 0 if not defined) */
#define PRIdLEAST40 __Q8_QF"d"
#define PRIiLEAST40 __Q8_QF"i"
#define PRIoLEAST40 __Q8_QF"o"
#define PRIuLEAST40 __Q8_QF"u"
#define PRIxLEAST40 __Q8_QF"x"
#define PRIXLEAST40 __Q8_QF"X"
#define SCNdLEAST40 __Q8_QF"d"
#define SCNiLEAST40 __Q8_QF"i"
#define SCNoLEAST40 __Q8_QF"o"
#define SCNuLEAST40 __Q8_QF"u"
#define SCNxLEAST40 __Q8_QF"x"
#endif
#if __Q8_CW < __Q8_IW && __Q8_CW >= 64 && defined(__Q8_SC)
#define PRIdLEAST64 "d"
#define PRIiLEAST64 "i"
#define PRIoLEAST64 "o"
#define PRIuLEAST64 "u"
#define PRIxLEAST64 "x"
#define PRIXLEAST64 "X"
#ifdef __Q8_CF
#define SCNdLEAST64 __Q8_CF"d"
#define SCNiLEAST64 __Q8_CF"i"
#define SCNoLEAST64 __Q8_CF"o"
#define SCNuLEAST64 __Q8_CF"u"
#define SCNxLEAST64 __Q8_CF"x"
#endif
#elif __Q8_SW < __Q8_IW && __Q8_SW >= 64
#define PRIdLEAST64 "d"
#define PRIiLEAST64 "i"
#define PRIoLEAST64 "o"
#define PRIuLEAST64 "u"
#define PRIxLEAST64 "x"
#define PRIXLEAST64 "X"
#define SCNdLEAST64 "hd"
#define SCNiLEAST64 "hi"
#define SCNoLEAST64 "ho"
#define SCNuLEAST64 "hu"
#define SCNxLEAST64 "hx"
#elif __Q8_IW >= 64
#define PRIdLEAST64 "d"
#define PRIiLEAST64 "i"
#define PRIoLEAST64 "o"
#define PRIuLEAST64 "u"
#define PRIxLEAST64 "x"
#define PRIXLEAST64 "X"
#define SCNdLEAST64 "d"
#define SCNiLEAST64 "i"
#define SCNoLEAST64 "o"
#define SCNuLEAST64 "u"
#define SCNxLEAST64 "x"
#elif __Q8_LW >= 64
#define PRIdLEAST64 "ld"
#define PRIiLEAST64 "li"
#define PRIoLEAST64 "lo"
#define PRIuLEAST64 "lu"
#define PRIxLEAST64 "lx"
#define PRIXLEAST64 "lX"
#define SCNdLEAST64 "ld"
#define SCNiLEAST64 "li"
#define SCNoLEAST64 "lo"
#define SCNuLEAST64 "lu"
#define SCNxLEAST64 "lx"
#elif __Q8_QW >= 64 /* (will be 0 if not defined) */
#define PRIdLEAST64 __Q8_QF"d"
#define PRIiLEAST64 __Q8_QF"i"
#define PRIoLEAST64 __Q8_QF"o"
#define PRIuLEAST64 __Q8_QF"u"
#define PRIxLEAST64 __Q8_QF"x"
#define PRIXLEAST64 __Q8_QF"X"
#define SCNdLEAST64 __Q8_QF"d"
#define SCNiLEAST64 __Q8_QF"i"
#define SCNoLEAST64 __Q8_QF"o"
#define SCNuLEAST64 __Q8_QF"u"
#define SCNxLEAST64 __Q8_QF"x"
#endif
#define PRIdFAST8 "d"
#define PRIiFAST8 "i"
#define PRIoFAST8 "o"
#define PRIuFAST8 "u"
#define PRIxFAST8 "x"
#define PRIXFAST8 "X"
#define SCNdFAST8 "d"
#define SCNiFAST8 "i"
#define SCNoFAST8 "o"
#define SCNuFAST8 "u"
#define SCNxFAST8 "x"
#define PRIdFAST16 "d"
#define PRIiFAST16 "i"
#define PRIoFAST16 "o"
#define PRIuFAST16 "u"
#define PRIxFAST16 "x"
#define PRIXFAST16 "X"
#define SCNdFAST16 "d"
#define SCNiFAST16 "i"
#define SCNoFAST16 "o"
#define SCNuFAST16 "u"
#define SCNxFAST16 "x"
#if __Q8_IW >= 32
#define PRIdFAST32 "d"
#define PRIiFAST32 "i"
#define PRIoFAST32 "o"
#define PRIuFAST32 "u"
#define PRIxFAST32 "x"
#define PRIXFAST32 "X"
#define SCNdFAST32 "d"
#define SCNiFAST32 "i"
#define SCNoFAST32 "o"
#define SCNuFAST32 "u"
#define SCNxFAST32 "x"
#else
#define PRIdFAST32 "ld"
#define PRIiFAST32 "li"
#define PRIoFAST32 "lo"
#define PRIuFAST32 "lu"
#define PRIxFAST32 "lx"
#define PRIXFAST32 "lX"
#define SCNdFAST32 "ld"
#define SCNiFAST32 "li"
#define SCNoFAST32 "lo"
#define SCNuFAST32 "lu"
#define SCNxFAST32 "lx"
#endif
#if __Q8_IW >= 40
#define PRIdFAST40 "d"
#define PRIiFAST40 "i"
#define PRIoFAST40 "o"
#define PRIuFAST40 "u"
#define PRIxFAST40 "x"
#define PRIXFAST40 "X"
#define SCNdFAST40 "d"
#define SCNiFAST40 "i"
#define SCNoFAST40 "o"
#define SCNuFAST40 "u"
#define SCNxFAST40 "x"
#elif __Q8_LW >= 40
#define PRIdFAST40 "ld"
#define PRIiFAST40 "li"
#define PRIoFAST40 "lo"
#define PRIuFAST40 "lu"
#define PRIxFAST40 "lx"
#define PRIXFAST40 "lX"
#define SCNdFAST40 "ld"
#define SCNiFAST40 "li"
#define SCNoFAST40 "lo"
#define SCNuFAST40 "lu"
#define SCNxFAST40 "lx"
#elif __Q8_QW >= 40 /* (will be 0 if not defined) */
#define PRIdFAST40 __Q8_QF"d"
#define PRIiFAST40 __Q8_QF"i"
#define PRIoFAST40 __Q8_QF"o"
#define PRIuFAST40 __Q8_QF"u"
#define PRIxFAST40 __Q8_QF"x"
#define PRIXFAST40 __Q8_QF"X"
#define SCNdFAST40 __Q8_QF"d"
#define SCNiFAST40 __Q8_QF"i"
#define SCNoFAST40 __Q8_QF"o"
#define SCNuFAST40 __Q8_QF"u"
#define SCNxFAST40 __Q8_QF"x"
#endif
#if __Q8_IW >= 64
#define PRIdFAST64 "d"
#define PRIiFAST64 "i"
#define PRIoFAST64 "o"
#define PRIuFAST64 "u"
#define PRIxFAST64 "x"
#define PRIXFAST64 "X"
#define SCNdFAST64 "d"
#define SCNiFAST64 "i"
#define SCNoFAST64 "o"
#define SCNuFAST64 "u"
#define SCNxFAST64 "x"
#elif __Q8_LW >= 64
#define PRIdFAST64 "ld"
#define PRIiFAST64 "li"
#define PRIoFAST64 "lo"
#define PRIuFAST64 "lu"
#define PRIxFAST64 "lx"
#define PRIXFAST64 "lX"
#define SCNdFAST64 "ld"
#define SCNiFAST64 "li"
#define SCNoFAST64 "lo"
#define SCNuFAST64 "lu"
#define SCNxFAST64 "lx"
#elif __Q8_QW >= 64 /* (will be 0 if not defined) */
#define PRIdFAST64 __Q8_QF"d"
#define PRIiFAST64 __Q8_QF"i"
#define PRIoFAST64 __Q8_QF"o"
#define PRIuFAST64 __Q8_QF"u"
#define PRIxFAST64 __Q8_QF"x"
#define PRIXFAST64 __Q8_QF"X"
#define SCNdFAST64 __Q8_QF"d"
#define SCNiFAST64 __Q8_QF"i"
#define SCNoFAST64 __Q8_QF"o"
#define SCNuFAST64 __Q8_QF"u"
#define SCNxFAST64 __Q8_QF"x"
#endif
#define PRIdMAX __Q8_MF"d"
#define PRIiMAX __Q8_MF"i"
#define PRIoMAX __Q8_MF"o"
#define PRIuMAX __Q8_MF"u"
#define PRIxMAX __Q8_MF"x"
#define PRIXMAX __Q8_MF"X"
#define SCNdMAX __Q8_MF"d"
#define SCNiMAX __Q8_MF"i"
#define SCNoMAX __Q8_MF"o"
#define SCNuMAX __Q8_MF"u"
#define SCNxMAX __Q8_MF"x"
#if defined(__Q8_PW)
#if __Q8_IW >= __Q8_PW
#define PRIdPTR "d"
#define PRIiPTR "i"
#define PRIoPTR "o"
#define PRIuPTR "u"
#define PRIxPTR "x"
#define PRIXPTR "X"
#define SCNdPTR "d"
#define SCNiPTR "i"
#define SCNoPTR "o"
#define SCNuPTR "u"
#define SCNxPTR "x"
#elif __Q8_LW >= __Q8_PW
#define PRIdPTR "ld"
#define PRIiPTR "li"
#define PRIoPTR "lo"
#define PRIuPTR "lu"
#define PRIxPTR "lx"
#define PRIXPTR "lX"
#define SCNdPTR "ld"
#define SCNiPTR "li"
#define SCNoPTR "lo"
#define SCNuPTR "lu"
#define SCNxPTR "lx"
#elif __Q8_QW >= __Q8_PW
#define PRIdPTR __Q8_QF"d"
#define PRIiPTR __Q8_QF"i"
#define PRIoPTR __Q8_QF"o"
#define PRIuPTR __Q8_QF"u"
#define PRIxPTR __Q8_QF"x"
#define PRIXPTR __Q8_QF"X"
#define SCNdPTR __Q8_QF"d"
#define SCNiPTR __Q8_QF"i"
#define SCNoPTR __Q8_QF"o"
#define SCNuPTR __Q8_QF"u"
#define SCNxPTR __Q8_QF"x"
#elif __Q8_MW >= __Q8_PW
#define PRIdPTR __Q8_MF"d"
#define PRIiPTR __Q8_MF"i"
#define PRIoPTR __Q8_MF"o"
#define PRIuPTR __Q8_MF"u"
#define PRIxPTR __Q8_MF"x"
#define PRIXPTR __Q8_MF"X"
#define SCNdPTR __Q8_MF"d"
#define SCNiPTR __Q8_MF"i"
#define SCNoPTR __Q8_MF"o"
#define SCNuPTR __Q8_MF"u"
#define SCNxPTR __Q8_MF"x"
#endif
#endif
#endif /* !defined(__cplusplus) || defined(__STDC_FORMAT_MACROS) */
/*
7.8.2 Functions for greatest-width integer types
*/
intmax_t imaxabs __Q8_PARAMS((intmax_t __j));
imaxdiv_t imaxdiv __Q8_PARAMS((intmax_t __numer, intmax_t __denom));
intmax_t strtoimax __Q8_PARAMS((__Q8_CONST char *__Q8_RESTRICT __nptr,
char **__Q8_RESTRICT __endptr, int __base));
uintmax_t strtoumax __Q8_PARAMS((__Q8_CONST char *__Q8_RESTRICT __nptr,
char **__Q8_RESTRICT __endptr, int __base));
intmax_t wcstoimax __Q8_PARAMS((__Q8_CONST __Q8_WT *__Q8_RESTRICT __nptr,
__Q8_WT **__Q8_RESTRICT __endptr, int __base));
uintmax_t wcstoumax __Q8_PARAMS((__Q8_CONST __Q8_WT *__Q8_RESTRICT __nptr,
__Q8_WT **__Q8_RESTRICT __endptr, int __base));
#ifdef __cplusplus
}
#endif
#endif /* !defined(_INTTYPES_H) && !defined(_INC_INTTYPES) */

71
src/init/c/util/iso646.h Normal file
View file

@ -0,0 +1,71 @@
/*
<iso646.h> -- macros for use in place of certain tokens that are
not expressible in the invariant subset of ISO 646:1991
This source code has been placed into the PUBLIC DOMAIN by its author.
last edit: 1999/08/20 gwyn@arl.mil
Implements subclause 7.9 of ISO/IEC 9899:1999 (E).
Usage: ??=include <iso646.h>
Notes: The C standard has always required that the following
source trigraphs be supported in translation phase 1:
??= mapped to #
??( mapped to [
??/ mapped to \
??) mapped to ]
??' mapped to ^
??< mapped to {
??! mapped to |
??> mapped to }
??- mapped to ~
ISO/IEC 9899:1994 (ISO/IEC 9899:1990/Amendment 1)
and subsequently ISO/IEC 9899:1999, which require
conforming implementations to provide <iso646.h>,
also require support in translation phases 3..4
for the following preprocessing tokens:
%: alternate spelling for #
%:%: alternate spelling for ##
They also require support in translation phases 3..7
for the following preprocessing tokens:
<: alternate spelling for [
:> alternate spelling for ]
<% alternate spelling for {
%> alternate spelling for }
The C standard also requires that the "difficult"
characters be somehow provided in both the basic source
and execution character sets, regardless of the
provision of trigraph, digraph, and macro alternatives
for these characters. (Thus, the alternate spellings
are intended to help programmers, not C implementors.)
The 1999 revision of the C standard adds support for
international characters in identifiers via Universal
Character Names, but UCN equivalents are not allowed
for the aforementioned "difficult" characters.
It is suggested that *all* C programmers avoid use of
the following identifiers in their programs, in case
somebody later needs to use <iso646.h> in maintaining
the programs.
*/
/* This header doesn't need an idempotency lock; there are no typedefs here. */
/* This header doesn't need C++ extern "C"; there are no declarations here. */
#define and &&
#define and_eq &=
#define bitand &
#define bitor |
#define compl ~
#define not !
#define not_eq !=
#define or ||
#define or_eq |=
#define xor ^
#define xor_eq ^=

77
src/init/c/util/locale.c Normal file
View file

@ -0,0 +1,77 @@
/*
localeconv() -- numeric formatting convention inquiry
setlocale() -- locale control function
This source code has been placed into the PUBLIC DOMAIN by its author.
last edit: 1999/08/20 gwyn@arl.mil
Implements subclauses 7.11.1.1 & 7.11.2.1 of ISO/IEC 9899:1999 (E).
This is a minimal implementation for environments where
internationalization is not considered important.
XXX -- UNTESTED -- XXX
*/
#include <limits.h> /* for CHAR_MAX */
#include <locale.h>
static char empty[] = "";
static struct lconv c_lconv = /* lconv for "C" locale */
{
/* WARNING: The following order must match the header! */
".", /* decimal_point */
empty, /* thousands_sep */
empty, /* grouping */
empty, /* int_curr_symbol */
empty, /* currency_symbol */
empty, /* mon_decimal_point */
empty, /* mon_thousands_sep */
empty, /* mon_grouping */
empty, /* positive_sign */
empty, /* negative_sign */
CHAR_MAX, /* int_frac_digits */
CHAR_MAX, /* frac_digits */
CHAR_MAX, /* p_cs_precedes */
CHAR_MAX, /* p_sep_by_space */
CHAR_MAX, /* n_cs_precedes */
CHAR_MAX, /* n_sep_by_space */
CHAR_MAX, /* p_sign_posn */
CHAR_MAX, /* n_sign_posn */
CHAR_MAX, /* int_p_cs_precedes */
CHAR_MAX, /* int_p_sep_by_space */
CHAR_MAX, /* int_n_cs_precedes */
CHAR_MAX, /* int_n_sep_by_space */
CHAR_MAX, /* int_p_sign_posn */
CHAR_MAX, /* int_n_sign_posn */
};
struct lconv *
localeconv()
{
return &c_lconv;
}
char *
setlocale(category, locale)
int category;
const char *locale;
{
switch ( category )
{
case LC_ALL:
case LC_COLLATE:
case LC_CTYPE:
case LC_MONETARY:
case LC_NUMERIC:
case LC_TIME:
return empty; /* native "" == "C" == "POSIX" */
/* The string doesn't have to be the same as the argument. */
default:
return NULL; /* unsupported category */
}
}

72
src/init/c/util/locale.h Normal file
View file

@ -0,0 +1,72 @@
/*
<locale.h> -- definitions for internationalization functions
This source code has been placed into the PUBLIC DOMAIN by its author.
last edit: 1999/08/20 gwyn@arl.mil
Implements subclause 7.11 of ISO/IEC 9899:1999 (E).
The standard allows additional macro definitions starting with
"LC_" and an uppercase letter.
*/
/* This header doesn't need an idempotency lock; there are no typedefs here. */
#include <Q8defs.h> /* defines __Q8_NULL and __Q8_PARAMS */
#ifdef __cplusplus
extern "C" {
#endif
struct lconv /* members are in usual UNIX order */
{
/* The following are controlled by LC_NUMERIC: */
char *decimal_point;
char *thousands_sep;
char *grouping;
/* The following are controlled by LC_MONETARY: */
char *int_curr_symbol;
char *currency_symbol;
char *mon_decimal_point;
char *mon_thousands_sep;
char *mon_grouping;
char *positive_sign;
char *negative_sign;
char int_frac_digits;
char frac_digits;
char p_cs_precedes;
char p_sep_by_space;
char n_cs_precedes;
char n_sep_by_space;
char p_sign_posn;
char n_sign_posn;
char int_p_cs_precedes;
char int_p_sep_by_space;
char int_n_cs_precedes;
char int_n_sep_by_space;
char int_p_sign_posn;
char int_n_sign_posn;
};
/* The following have the usual UNIX values: */
#define LC_CTYPE (0)
#define LC_NUMERIC (1)
#define LC_TIME (2)
#define LC_COLLATE (3)
#define LC_MONETARY (4)
#define LC_ALL (6)
/* other categories may be added here: */
#define LC_MESSAGES (5)
#ifndef NULL
#define NULL __Q8_NULL
#endif
extern char *setlocale __Q8_PARAMS((int __category,
const char *__locale));
extern struct lconv *localeconv __Q8_PARAMS((void));
#ifdef __cplusplus
}
#endif

100
src/init/c/util/signal.c Normal file
View file

@ -0,0 +1,100 @@
/*
signal -- specify signal handling
raise -- send signal
This source code has been placed into the PUBLIC DOMAIN by its author.
last edit: 1999/08/20 gwyn@arl.mil
Implements subclauses 7.14.1 & 7.14.2 of ISO/IEC 9899:1999 (E).
These are minimally functional versions, solely for systems that don't
already provide signal() (such as the TMS320C6xxx DSP's compiler).
XXX -- UNTESTED -- XXX
*/
#include <errno.h>
#include <stdlib.h> /* for abort() */
#include <Q8defs.h> /* for __Q8_PARAMS */
#include <signal.h>
#include <stdbool.h>
#define NSIG (SIGTERM+1) /* max. supported signal number + 1 */
static void (*handler[NSIG])__Q8_PARAMS((int)); /* current handlers */
static bool inited = false; /* for initializing above */
/* dummy functions for unique address */
void __sig_err(sig) int sig; { }
void __sig_ign(sig) int sig; { }
/*
7.14.1 -- specify signal handling
*/
void (*
signal(sig, func)
)__Q8_PARAMS((int)) /* returns previous handler */
register int sig;
void (*func)__Q8_PARAMS((int));
{
register void (*retval)__Q8_PARAMS((int)); /* previous handler */
if ( sig <= 0 || sig >= NSIG ) /* safety check */
{
errno = EDOM;
return SIG_ERR;
}
/* C language provides no good way to initialize handler[] */
if ( !inited ) /* once only */
{
register int i;
for ( i = 0; i < NSIG; ++i )
handler[i] = SIG_DFL; /* initialize */
inited = true;
}
retval = handler[sig - 1]; /* previous state */
handler[sig - 1] = func; /* new state */
return retval; /* previous handler */
}
/*
7.14.2 -- send signal
*/
int
raise(sig)
int sig;
{
register void (*func)__Q8_PARAMS((int)); /* handler value */
if ( sig <= 0 || sig >= NSIG ) /* safety check */
{
errno = EDOM;
return 1; /* indicate failure */
}
func = handler[sig - 1];
if ( func == SIG_IGN )
return 0; /* indicate success */
if ( func == SIG_DFL )
{
abort(); /* (an arbitrary decision) */
return 1; /* just in case, indicate failure */
}
handler[sig - 1] = SIG_DFL; /* classic UNIX behavior */
(*func)(sig);
return 0; /* indicate success */
}

67
src/init/c/util/signal.h Normal file
View file

@ -0,0 +1,67 @@
/*
signal.h -- signal handling
This source code has been placed into the PUBLIC DOMAIN by its author.
last edit: 1999/11/05 gwyn@arl.mil
Implements subclause 7.14 of ISO/IEC 9899:1999 (E).
This particular implementation requires the matching signal.c.
This is a minimally functional version, solely for systems that don't
already provide <signal.h> (such as the TMS320C6xxx DSP's compiler).
*/
#if !defined(_SIGNAL_H) && !defined(_INC_SIGNAL) /* usual lock names */
#define _SIGNAL_H /* idempotency lock (section 7.1.2) */
#define _INC_SIGNAL
#include <Q8defs.h> /* defines __Q8_PARAMS */
#ifdef __cplusplus
extern "C" {
#endif
/* atomic-access data type: */
typedef int sig_atomic_t; /* this type works nearly everywhere */
/* signal states: */
#define SIG_DFL ((void (*)__Q8_PARAMS((int)))0) /* default */
#define SIG_ERR __sig_err /* error return from signal() */
#define SIG_IGN __sig_ign /* ignore */
/* dummy functions for unique address */
extern void __sig_err __Q8_PARAMS((int __sig));
extern void __sig_ign __Q8_PARAMS((int __sig));
/* signal numbers (these are a subset of the traditional UNIX values): */
#define SIGINT (2) /* interactive attention signal */
#define SIGILL (4) /* invalid function image */
#define SIGABRT (6) /* abnormal termination */
#define SIGFPE (8) /* erroneous arithmetic operation */
#define SIGSEGV (11) /* invalid access to storage */
#define SIGTERM (15) /* termination request */
/* Note: SIGTERM is assumed by my signal.c to have the highest value. */
/*
7.14.1 -- specify signal handling
*/
extern void (*signal __Q8_PARAMS((int __sig, void (*__func)(int))))
__Q8_PARAMS((int));
/*
7.14.2 -- send signal
*/
extern int raise __Q8_PARAMS((int __sig));
#ifdef __cplusplus
}
#endif
#endif /* !defined(_SIGNAL_H) && !defined(_INC_SIGNAL) */

1521
src/init/c/util/sitest.c Normal file

File diff suppressed because it is too large Load diff

32
src/init/c/util/stdbool.h Normal file
View file

@ -0,0 +1,32 @@
/*
stdbool.h -- Boolean type and values
This source code has been placed into the PUBLIC DOMAIN by its author.
last edit: 1999/11/05 gwyn@arl.mil
Implements subclause 7.16 of ISO/IEC 9899:1999 (E).
*/
#if !defined(_STDBOOL_H) && !defined(_INC_STDBOOL) /* usual lock names */
#define _STDBOOL_H /* idempotency lock (section 7.1.2) */
#define _INC_STDBOOL
/* This header doesn't need C++ extern "C"; there are no declarations here. */
/* program is allowed to contain its own definitions, so ... */
#undef bool
#undef true
#undef false
#undef __bool_true_false_are_defined
#define bool _Bool
#define true 1
#define false 0
#define __bool_true_false_are_defined 1
#if __STDC_VERSION__ < 199901
typedef int _Bool; /* not built into pre-C99 compilers */
#endif
#endif /* !defined(_STDBOOL_H) && !defined(_INC_STDBOOL) */

692
src/init/c/util/stdint.h Normal file
View file

@ -0,0 +1,692 @@
/*
stdint.h -- integer types
This source code has been placed into the PUBLIC DOMAIN by its author.
last edit: 1999/11/05 gwyn@arl.mil
Implements subclause 7.18 of ISO/IEC 9899:1999 (E) + TC1.
This particular implementation assumes that widths of the standard
integer types are powers of 2, and that there are no extended integer
types with intermediate widths.
This implementation is SELF-CONFIGURING, based on parameters defined
in <Q8defs.h>. If you plan to include this in a C implementation,
it would be best to trim it down, with all the parameterized decisions
already made.
*/
/* This header doesn't need an idempotency lock; there are no typedefs here. */
#include <Q8defs.h> /* defines the __Q8_* symbols */
/* This header doesn't need C++ extern "C"; there are no declarations here. */
/*
7.18.1.1 Exact-width integer types
The optional 40-bit type is supported by the TMS320C6xxx DSP.
*/
#if __Q8_CW == 8 && defined(__Q8_SC)
typedef __Q8_SC int8_t;
typedef unsigned char uint8_t;
#endif
#if __Q8_CW == 16 && defined(__Q8_SC)
typedef __Q8_SC int16_t;
typedef unsigned char uint16_t;
#elif __Q8_SW == 16
typedef short int16_t;
typedef unsigned short uint16_t;
#endif
#if __Q8_CW == 32 && defined(__Q8_SC)
typedef __Q8_SC int32_t;
typedef unsigned char uint32_t;
#elif __Q8_SW == 32
typedef short int32_t;
typedef unsigned short uint32_t;
#elif __Q8_IW == 32
typedef int int32_t;
typedef unsigned int uint32_t;
#elif __Q8_LW == 32
typedef long int32_t;
typedef unsigned long uint32_t;
#endif
#if __Q8_CW == 40 && defined(__Q8_SC)
typedef __Q8_SC int40_t;
typedef unsigned char uint40_t;
#elif __Q8_SW == 40
typedef short int40_t;
typedef unsigned short uint40_t;
#elif __Q8_IW == 40
typedef int int40_t;
typedef unsigned int uint40_t;
#elif __Q8_LW == 40
typedef long int40_t;
typedef unsigned long uint40_t;
#endif
#if __Q8_CW == 64 && defined(__Q8_SC)
typedef __Q8_SC int64_t;
typedef unsigned char uint64_t;
#elif __Q8_SW == 64
typedef short int64_t;
typedef unsigned short uint64_t;
#elif __Q8_IW == 64
typedef int int64_t;
typedef unsigned int uint64_t;
#elif __Q8_LW == 64
typedef long int64_t;
typedef unsigned long uint64_t;
#elif __Q8_QW == 64
typedef __Q8_QT int64_t;
typedef unsigned __Q8_QT uint64_t;
#endif
/*
7.18.1.2 Minimum-width integer types
The optional 40-bit type is supported by the TMS320C6xxx DSP.
Prefers type int over char or short char, due to a possible
problem constructing suitable integer constants for 7.18.4.1.
*/
#if __Q8_CW < __Q8_IW && defined(__Q8_SC)
typedef __Q8_SC int_least8_t;
typedef unsigned char uint_least8_t;
#elif __Q8_SW < __Q8_IW
typedef short int_least8_t;
typedef unsigned short uint_least8_t;
#else
typedef int int_least8_t;
typedef unsigned int uint_least8_t;
#endif
#if __Q8_CW < __Q8_IW && __Q8_CW >= 16 && defined(__Q8_SC)
typedef __Q8_SC int_least16_t;
typedef unsigned char uint_least16_t;
#elif __Q8_SW < __Q8_IW
typedef short int_least16_t;
typedef unsigned short uint_least16_t;
#else
typedef int int_least16_t;
typedef unsigned int uint_least16_t;
#endif
#if __Q8_CW < __Q8_IW && __Q8_CW >= 32 && defined(__Q8_SC)
typedef __Q8_SC int_least32_t;
typedef unsigned char uint_least32_t;
#elif __Q8_SW < __Q8_IW && __Q8_SW >= 32
typedef short int_least32_t;
typedef unsigned short uint_least32_t;
#elif __Q8_IW >= 32
typedef int int_least32_t;
typedef unsigned int uint_least32_t;
#else
typedef long int_least32_t;
typedef unsigned long uint_least32_t;
#endif
#if __Q8_CW < __Q8_IW && __Q8_CW >= 40 && defined(__Q8_SC)
typedef __Q8_SC int_least40_t;
typedef unsigned char uint_least40_t;
#elif __Q8_SW < __Q8_IW && __Q8_SW >= 40
typedef short int_least40_t;
typedef unsigned short uint_least40_t;
#elif __Q8_IW >= 40
typedef int int_least40_t;
typedef unsigned int uint_least40_t;
#elif __Q8_LW >= 40
typedef long int_least40_t;
typedef unsigned long uint_least40_t;
#elif __Q8_QW >= 40 /* (will be 0 if not defined) */
typedef __Q8_QT int_least40_t;
typedef unsigned __Q8_QT uint_least40_t;
#endif
#if __Q8_CW < __Q8_IW && __Q8_CW >= 64 && defined(__Q8_SC)
typedef __Q8_SC int_least64_t;
typedef unsigned char uint_least64_t;
#elif __Q8_SW < __Q8_IW && __Q8_SW >= 64
typedef short int_least64_t;
typedef unsigned short uint_least64_t;
#elif __Q8_IW >= 64
typedef int int_least64_t;
typedef unsigned int uint_least64_t;
#elif __Q8_LW >= 64
typedef long int_least64_t;
typedef unsigned long uint_least64_t;
#elif __Q8_QW >= 64 /* (will be 0 if not defined) */
typedef __Q8_QT int_least64_t;
typedef unsigned __Q8_QT uint_least64_t;
#endif
/*
7.18.1.3 Fastest minimum-width integer types
The optional 40-bit type is supported by the TMS320C6xxx DSP.
"Fastest" is hard to determine; if "int" qualifies, it is chosen.
*/
typedef int int_fast8_t;
typedef unsigned int uint_fast8_t;
typedef int int_fast16_t;
typedef unsigned int uint_fast16_t;
#if __Q8_IW >= 32
typedef int int_fast32_t;
typedef unsigned int uint_fast32_t;
#else
typedef long int_fast32_t;
typedef unsigned long uint_fast32_t;
#endif
#if __Q8_IW >= 40
typedef int int_fast40_t;
typedef unsigned int uint_fast40_t;
#elif __Q8_LW >= 40
typedef long int_fast40_t;
typedef unsigned long uint_fast40_t;
#elif __Q8_QW >= 40 /* (will be 0 if not defined) */
typedef __Q8_QT int_fast40_t;
typedef unsigned __Q8_QT uint_fast40_t;
#endif
#if __Q8_IW >= 64
typedef int int_fast64_t;
typedef unsigned int uint_fast64_t;
#elif __Q8_LW >= 64
typedef long int_fast64_t;
typedef unsigned long uint_fast64_t;
#elif __Q8_QW >= 64 /* (will be 0 if not defined) */
typedef __Q8_QT int_fast64_t;
typedef unsigned __Q8_QT uint_fast64_t;
#endif
/*
7.18.1.4 Integer types capable of holding object pointers
Theoretically, these tests might not work (e.g., the implementation
can limit the interconvertible type to one that is not the smallest
possible), but I'm unaware of any platform where they fail.
*/
#if defined(__Q8_PW)
#if __Q8_IW >= __Q8_PW
typedef int intptr_t;
typedef unsigned int uintptr_t;
#elif __Q8_LW >= __Q8_PW
typedef long intptr_t;
typedef unsigned long uintptr_t;
#elif __Q8_QW >= __Q8_PW
typedef __Q8_QT intptr_t;
typedef unsigned __Q8_QT uintptr_t;
#elif __Q8_MW >= __Q8_PW
typedef __Q8_MT intptr_t;
typedef unsigned __Q8_MT uintptr_t;
#endif
#endif
/*
7.18.1.5 Greatest-width integer types
*/
typedef __Q8_MT intmax_t;
typedef unsigned __Q8_MT uintmax_t;
#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS)
/*
7.18.2.1 Limits of exact-width integer types
The optional 40-bit type is supported by the TMS320C6xxx DSP.
*/
#if __Q8_CW == 8 && defined(__Q8_SC)
#define INT8_MAX __Q8_TI(__Q8_CW)
#define INT8_MIN __Q8_BI(__Q8_CW)
#define UINT8_MAX __Q8_UI(__Q8_CW)
#endif
#if __Q8_CW == 16 && defined(__Q8_SC)
#define INT16_MAX __Q8_TI(__Q8_CW)
#define INT16_MIN __Q8_BI(__Q8_CW)
#define UINT16_MAX __Q8_UI(__Q8_CW)
#elif __Q8_SW == 16
#define INT16_MAX __Q8_TI(__Q8_SW)
#define INT16_MIN __Q8_BI(__Q8_SW)
#define UINT16_MAX __Q8_UI(__Q8_SW)
#endif
#if __Q8_CW == 32 && defined(__Q8_SC)
#define INT32_MAX __Q8_TI(__Q8_CW)
#define INT32_MIN __Q8_BI(__Q8_CW)
#define UINT32_MAX __Q8_UI(__Q8_CW)
#elif __Q8_SW == 32
#define INT32_MAX __Q8_TI(__Q8_SW)
#define INT32_MIN __Q8_BI(__Q8_SW)
#define UINT32_MAX __Q8_UI(__Q8_SW)
#elif __Q8_IW == 32
#define INT32_MAX __Q8_TI(__Q8_IW)
#define INT32_MIN __Q8_BI(__Q8_IW)
#define UINT32_MAX __Q8_UI(__Q8_IW)
#elif __Q8_LW == 32
#define INT32_MAX __Q8_TL
#define INT32_MIN __Q8_BL
#define UINT32_MAX __Q8_UL
#endif
#if __Q8_CW == 40 && defined(__Q8_SC)
#define INT40_MAX __Q8_TI(__Q8_CW)
#define INT40_MIN __Q8_BI(__Q8_CW)
#define UINT40_MAX __Q8_UI(__Q8_CW)
#elif __Q8_SW == 40
#define INT40_MAX __Q8_TI(__Q8_SW)
#define INT40_MIN __Q8_BI(__Q8_SW)
#define UINT40_MAX __Q8_UI(__Q8_SW)
#elif __Q8_IW == 40
#define INT40_MAX __Q8_TI(__Q8_IW)
#define INT40_MIN __Q8_BI(__Q8_IW)
#define UINT40_MAX __Q8_UI(__Q8_IW)
#elif __Q8_LW == 40
#define INT40_MAX __Q8_TL
#define INT40_MIN __Q8_BL
#define UINT40_MAX __Q8_UL
#endif
#if __Q8_CW == 64 && defined(__Q8_SC)
#define INT64_MAX __Q8_TI(__Q8_CW)
#define INT64_MIN __Q8_BI(__Q8_CW)
#define UINT64_MAX __Q8_UI(__Q8_CW)
#elif __Q8_SW == 64
#define INT64_MAX __Q8_TI(__Q8_SW)
#define INT64_MIN __Q8_BI(__Q8_SW)
#define UINT64_MAX __Q8_UI(__Q8_SW)
#elif __Q8_IW == 64
#define INT64_MAX __Q8_TI(__Q8_IW)
#define INT64_MIN __Q8_BI(__Q8_IW)
#define UINT64_MAX __Q8_UI(__Q8_IW)
#elif __Q8_LW == 64
#define INT64_MAX __Q8_TL
#define INT64_MIN __Q8_BL
#define UINT64_MAX __Q8_UL
#elif __Q8_QW == 64
#define INT64_MAX __Q8_TQ
#define INT64_MIN __Q8_BQ
#define UINT64_MAX __Q8_UQ
#endif
/*
7.18.2.2 Limits of minimum-width integer types
The optional 40-bit type is supported by the TMS320C6xxx DSP.
*/
#if __Q8_CW < __Q8_IW && defined(__Q8_SC)
#define INT_LEAST8_MAX __Q8_TI(__Q8_CW)
#define INT_LEAST8_MIN __Q8_BI(__Q8_CW)
#define UINT_LEAST8_MAX __Q8_UI(__Q8_CW)
#elif __Q8_SW < __Q8_IW
#define INT_LEAST8_MAX __Q8_TI(__Q8_SW)
#define INT_LEAST8_MIN __Q8_BI(__Q8_SW)
#define UINT_LEAST8_MAX __Q8_UI(__Q8_SW)
#else
#define INT_LEAST8_MAX __Q8_TI(__Q8_IW)
#define INT_LEAST8_MIN __Q8_BI(__Q8_IW)
#define UINT_LEAST8_MAX __Q8_UI(__Q8_IW)
#endif
#if __Q8_CW < __Q8_IW && __Q8_CW >= 16 && defined(__Q8_SC)
#define INT_LEAST16_MAX __Q8_TI(__Q8_CW)
#define INT_LEAST16_MIN __Q8_BI(__Q8_CW)
#define UINT_LEAST16_MAX __Q8_UI(__Q8_CW)
#elif __Q8_SW < __Q8_IW
#define INT_LEAST16_MAX __Q8_TI(__Q8_SW)
#define INT_LEAST16_MIN __Q8_BI(__Q8_SW)
#define UINT_LEAST16_MAX __Q8_UI(__Q8_SW)
#else
#define INT_LEAST16_MAX __Q8_TI(__Q8_IW)
#define INT_LEAST16_MIN __Q8_BI(__Q8_IW)
#define UINT_LEAST16_MAX __Q8_UI(__Q8_IW)
#endif
#if __Q8_CW < __Q8_IW && __Q8_CW >= 32 && defined(__Q8_SC)
#define INT_LEAST32_MAX __Q8_TI(__Q8_CW)
#define INT_LEAST32_MIN __Q8_BI(__Q8_CW)
#define UINT_LEAST32_MAX __Q8_UI(__Q8_CW)
#elif __Q8_SW < __Q8_IW && __Q8_SW >= 32
#define INT_LEAST32_MAX __Q8_TI(__Q8_SW)
#define INT_LEAST32_MIN __Q8_BI(__Q8_SW)
#define UINT_LEAST32_MAX __Q8_UI(__Q8_SW)
#elif __Q8_IW >= 32
#define INT_LEAST32_MAX __Q8_TI(__Q8_IW)
#define INT_LEAST32_MIN __Q8_BI(__Q8_IW)
#define UINT_LEAST32_MAX __Q8_UI(__Q8_IW)
#else
#define INT_LEAST32_MAX __Q8_TL
#define INT_LEAST32_MIN __Q8_BL
#define UINT_LEAST32_MAX __Q8_UL
#endif
#if __Q8_CW < __Q8_IW && __Q8_CW >= 40 && defined(__Q8_SC)
#define INT_LEAST40_MAX __Q8_TI(__Q8_CW)
#define INT_LEAST40_MIN __Q8_BI(__Q8_CW)
#define UINT_LEAST40_MAX __Q8_UI(__Q8_CW)
#elif __Q8_SW < __Q8_IW && __Q8_SW >= 40
#define INT_LEAST40_MAX __Q8_TI(__Q8_SW)
#define INT_LEAST40_MIN __Q8_BI(__Q8_SW)
#define UINT_LEAST40_MAX __Q8_UI(__Q8_SW)
#elif __Q8_IW >= 40
#define INT_LEAST40_MAX __Q8_TI(__Q8_IW)
#define INT_LEAST40_MIN __Q8_BI(__Q8_IW)
#define UINT_LEAST40_MAX __Q8_UI(__Q8_IW)
#elif __Q8_LW >= 40
#define INT_LEAST40_MAX __Q8_TL
#define INT_LEAST40_MIN __Q8_BL
#define UINT_LEAST40_MAX __Q8_UL
#elif __Q8_QW >= 40 /* (will be 0 if not defined) */
#define INT_LEAST40_MAX __Q8_TQ
#define INT_LEAST40_MIN __Q8_BQ
#define UINT_LEAST40_MAX __Q8_UQ
#endif
#if __Q8_CW < __Q8_IW && __Q8_CW >= 64 && defined(__Q8_SC)
#define INT_LEAST64_MAX __Q8_TI(__Q8_CW)
#define INT_LEAST64_MIN __Q8_BI(__Q8_CW)
#define UINT_LEAST64_MAX __Q8_UI(__Q8_CW)
#elif __Q8_SW < __Q8_IW && __Q8_SW >= 64
#define INT_LEAST64_MAX __Q8_TI(__Q8_SW)
#define INT_LEAST64_MIN __Q8_BI(__Q8_SW)
#define UINT_LEAST64_MAX __Q8_UI(__Q8_SW)
#elif __Q8_IW >= 64
#define INT_LEAST64_MAX __Q8_TI(__Q8_IW)
#define INT_LEAST64_MIN __Q8_BI(__Q8_IW)
#define UINT_LEAST64_MAX __Q8_UI(__Q8_IW)
#elif __Q8_LW >= 64
#define INT_LEAST64_MAX __Q8_TL
#define INT_LEAST64_MIN __Q8_BL
#define UINT_LEAST64_MAX __Q8_UL
#elif __Q8_QW >= 64 /* (will be 0 if not defined) */
#define INT_LEAST64_MAX __Q8_TQ
#define INT_LEAST64_MIN __Q8_BQ
#define UINT_LEAST64_MAX __Q8_UQ
#endif
/*
7.18.2.3 Limits of fastest minimum-width integer types
The optional 40-bit type is supported by the TMS320C6xxx DSP.
*/
#define INT_FAST8_MAX __Q8_TI(__Q8_IW)
#define INT_FAST8_MIN __Q8_BI(__Q8_IW)
#define UINT_FAST8_MAX __Q8_UI(__Q8_IW)
#define INT_FAST16_MAX __Q8_TI(__Q8_IW)
#define INT_FAST16_MIN __Q8_BI(__Q8_IW)
#define UINT_FAST16_MAX __Q8_UI(__Q8_IW)
#if __Q8_IW >= 32
#define INT_FAST32_MAX __Q8_TI(__Q8_IW)
#define INT_FAST32_MIN __Q8_BI(__Q8_IW)
#define UINT_FAST32_MAX __Q8_UI(__Q8_IW)
#else
#define INT_FAST32_MAX __Q8_TL
#define INT_FAST32_MIN __Q8_BL
#define UINT_FAST32_MAX __Q8_UL
#endif
#if __Q8_IW >= 40
#define INT_FAST40_MAX __Q8_TI(__Q8_IW)
#define INT_FAST40_MIN __Q8_BI(__Q8_IW)
#define UINT_FAST40_MAX __Q8_UI(__Q8_IW)
#elif __Q8_LW >= 40
#define INT_FAST40_MAX __Q8_TL
#define INT_FAST40_MIN __Q8_BL
#define UINT_FAST40_MAX __Q8_UL
#elif __Q8_QW >= 40 /* (will be 0 if not defined) */
#define INT_FAST40_MAX __Q8_TQ
#define INT_FAST40_MIN __Q8_BQ
#define UINT_FAST40_MAX __Q8_UQ
#endif
#if __Q8_IW >= 64
#define INT_FAST64_MAX __Q8_TI(__Q8_IW)
#define INT_FAST64_MIN __Q8_BI(__Q8_IW)
#define UINT_FAST64_MAX __Q8_UI(__Q8_IW)
#elif __Q8_LW >= 64
#define INT_FAST64_MAX __Q8_TL
#define INT_FAST64_MIN __Q8_BL
#define UINT_FAST64_MAX __Q8_UL
#elif __Q8_QW >= 64 /* (will be 0 if not defined) */
#define INT_FAST64_MAX __Q8_TQ
#define INT_FAST64_MIN __Q8_BQ
#define UINT_FAST64_MAX __Q8_UQ
#endif
/*
7.18.2.4 Limits of integer types
capable of holding object pointers
*/
#if defined(__Q8_PW)
#if __Q8_IW >= __Q8_PW
#define INTPTR_MAX __Q8_TI(__Q8_IW)
#define INTPTR_MIN __Q8_BI(__Q8_IW)
#define UINTPTR_MAX __Q8_UI(__Q8_IW)
#elif __Q8_LW >= __Q8_PW
#define INTPTR_MAX __Q8_TL
#define INTPTR_MIN __Q8_BL
#define UINTPTR_MAX __Q8_UL
#elif __Q8_QW >= __Q8_PW
#define INTPTR_MAX __Q8_TQ
#define INTPTR_MIN __Q8_BQ
#define UINTPTR_MAX __Q8_UQ
#elif __Q8_MW >= __Q8_PW
#define INTPTR_MAX __Q8_TM
#define INTPTR_MIN __Q8_BM
#define UINTPTR_MAX __Q8_UM
#endif
#endif
/*
7.18.2.5 Limits of greatest-width integer types
*/
#define INTMAX_MAX __Q8_TM
#define INTMAX_MIN __Q8_BM
#define UINTMAX_MAX __Q8_UM
/*
7.18.3 Limits of other integer types
XXX -- These ought to be moved into <Q8defs.h> along with
the corresponding type definitions.
*/
#if __Q8_CW >= __Q8_DW && defined(__Q8_SC)
#define PTRDIFF_MAX __Q8_TI(__Q8_CW)
#define PTRDIFF_MIN __Q8_BI(__Q8_CW)
#elif __Q8_SW >= __Q8_DW
#define PTRDIFF_MAX __Q8_TI(__Q8_SW)
#define PTRDIFF_MIN __Q8_BI(__Q8_SW)
#elif __Q8_IW >= __Q8_DW
#define PTRDIFF_MAX __Q8_TI(__Q8_IW)
#define PTRDIFF_MIN __Q8_BI(__Q8_IW)
#elif __Q8_LW >= __Q8_DW
#define PTRDIFF_MAX __Q8_TL
#define PTRDIFF_MIN __Q8_BL
#elif __Q8_QW >= __Q8_DW
#define PTRDIFF_MAX __Q8_TQ
#define PTRDIFF_MIN __Q8_BQ
#else
#define PTRDIFF_MAX __Q8_TM
#define PTRDIFF_MIN __Q8_BM
#endif
#ifdef __Q8_AU
#if __Q8_CW >= __Q8_AW
#define SIG_ATOMIC_MAX __Q8_UI(__Q8_CW)
#elif __Q8_SW >= __Q8_AW
#define SIG_ATOMIC_MAX __Q8_UI(__Q8_SW)
#elif __Q8_IW >= __Q8_AW
#define SIG_ATOMIC_MAX __Q8_UI(__Q8_IW)
#elif __Q8_LW >= __Q8_AW
#define SIG_ATOMIC_MAX __Q8_UL
#elif __Q8_QW >= __Q8_AW
#define SIG_ATOMIC_MAX __Q8_UQ
#else
#define SIG_ATOMIC_MAX __Q8_UM
#endif
#define SIG_ATOMIC_MIN 0
#else /* !defined(__Q8_AU) */
#if __Q8_CW >= __Q8_AW && defined(__Q8_SC)
#define SIG_ATOMIC_MAX __Q8_TI(__Q8_CW)
#define SIG_ATOMIC_MIN __Q8_BI(__Q8_CW)
#elif __Q8_SW >= __Q8_AW
#define SIG_ATOMIC_MAX __Q8_TI(__Q8_SW)
#define SIG_ATOMIC_MIN __Q8_BI(__Q8_SW)
#elif __Q8_IW >= __Q8_AW
#define SIG_ATOMIC_MAX __Q8_TI(__Q8_IW)
#define SIG_ATOMIC_MIN __Q8_BI(__Q8_IW)
#elif __Q8_LW >= __Q8_AW
#define SIG_ATOMIC_MAX __Q8_TL
#define SIG_ATOMIC_MIN __Q8_BL
#elif __Q8_QW >= __Q8_AW
#define SIG_ATOMIC_MAX __Q8_TQ
#define SIG_ATOMIC_MIN __Q8_BQ
#else
#define SIG_ATOMIC_MAX __Q8_TM
#define SIG_ATOMIC_MIN __Q8_BM
#endif
#endif /* defined(__Q8_AU) */
#if __Q8_CW >= __Q8_ZW
#define SIZE_MAX __Q8_UI(__Q8_CW)
#elif __Q8_SW >= __Q8_ZW
#define SIZE_MAX __Q8_UI(__Q8_SW)
#elif __Q8_IW >= __Q8_ZW
#define SIZE_MAX __Q8_UI(__Q8_IW)
#elif __Q8_LW >= __Q8_ZW
#define SIZE_MAX __Q8_UL
#elif __Q8_QW >= __Q8_ZW
#define SIZE_MAX __Q8_UQ
#else
#define SIZE_MAX __Q8_UM
#endif
#ifdef __Q8_WU
#if __Q8_CW >= __Q8_WW
#define WCHAR_MAX __Q8_UI(__Q8_CW)
#elif __Q8_SW >= __Q8_WW
#define WCHAR_MAX __Q8_UI(__Q8_SW)
#elif __Q8_IW >= __Q8_WW
#define WCHAR_MAX __Q8_UI(__Q8_IW)
#elif __Q8_LW >= __Q8_WW
#define WCHAR_MAX __Q8_UL
#elif __Q8_QW >= __Q8_WW
#define WCHAR_MAX __Q8_UQ
#else
#define WCHAR_MAX __Q8_UM
#endif
#define WCHAR_MIN 0
#else /* !defined(__Q8_WU) */
#if __Q8_CW >= __Q8_WW && defined(__Q8_SC)
#define WCHAR_MAX __Q8_TI(__Q8_CW)
#define WCHAR_MIN __Q8_BI(__Q8_CW)
#elif __Q8_SW >= __Q8_WW
#define WCHAR_MAX __Q8_TI(__Q8_SW)
#define WCHAR_MIN __Q8_BI(__Q8_SW)
#elif __Q8_IW >= __Q8_WW
#define WCHAR_MAX __Q8_TI(__Q8_IW)
#define WCHAR_MIN __Q8_BI(__Q8_IW)
#elif __Q8_LW >= __Q8_WW
#define WCHAR_MAX __Q8_TL
#define WCHAR_MIN __Q8_BL
#elif __Q8_QW >= __Q8_WW
#define WCHAR_MAX __Q8_TQ
#define WCHAR_MIN __Q8_BQ
#else
#define WCHAR_MAX __Q8_TM
#define WCHAR_MIN __Q8_BM
#endif
#endif /* defined(__Q8_WU) */
#ifdef __Q8_XU
#if __Q8_CW >= __Q8_XW
#define WINT_MAX __Q8_UI(__Q8_CW)
#elif __Q8_SW >= __Q8_XW
#define WINT_MAX __Q8_UI(__Q8_SW)
#elif __Q8_IW >= __Q8_XW
#define WINT_MAX __Q8_UI(__Q8_IW)
#elif __Q8_LW >= __Q8_XW
#define WINT_MAX __Q8_UL
#elif __Q8_QW >= __Q8_XW
#define WINT_MAX __Q8_UQ
#else
#define WINT_MAX __Q8_UM
#endif
#define WINT_MIN 0
#else /* !defined(__Q8_XU) */
#if __Q8_CW >= __Q8_XW && defined(__Q8_SC)
#define WINT_MAX __Q8_TI(__Q8_CW)
#define WINT_MIN __Q8_BI(__Q8_CW)
#elif __Q8_SW >= __Q8_XW
#define WINT_MAX __Q8_TI(__Q8_SW)
#define WINT_MIN __Q8_BI(__Q8_SW)
#elif __Q8_IW >= __Q8_XW
#define WINT_MAX __Q8_TI(__Q8_IW)
#define WINT_MIN __Q8_BI(__Q8_IW)
#elif __Q8_LW >= __Q8_XW
#define WINT_MAX __Q8_TL
#define WINT_MIN __Q8_BL
#elif __Q8_QW >= __Q8_XW
#define WINT_MAX __Q8_TQ
#define WINT_MIN __Q8_BQ
#else
#define WINT_MAX __Q8_TM
#define WINT_MIN __Q8_BM
#endif
#endif /* defined(__Q8_XU) */
#endif /* !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) */
#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS)
/*
7.18.4.1 Macros for minimum-width integer constants
The optional 40-bit type is supported by the TMS320C6xxx DSP.
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.
The trick used to get the right type is due to Clive Feather.
*/
#define INT8_C(c) (INT_LEAST8_MAX-INT_LEAST8_MAX+(c))
#define UINT8_C(c) (UINT_LEAST8_MAX-UINT_LEAST8_MAX+(c))
#define INT16_C(c) (INT_LEAST16_MAX-INT_LEAST16_MAX+(c))
#define UINT16_C(c) (UINT_LEAST16_MAX-UINT_LEAST16_MAX+(c))
#define INT32_C(c) (INT_LEAST32_MAX-INT_LEAST32_MAX+(c))
#define UINT32_C(c) (UINT_LEAST32_MAX-UINT_LEAST32_MAX+(c))
#ifdef INT_LEAST40_MAX
#define INT40_C(c) (INT_LEAST40_MAX-INT_LEAST40_MAX+(c))
#define UINT40_C(c) (UINT_LEAST40_MAX-UINT_LEAST40_MAX+(c))
#endif
#ifdef INT_LEAST64_MAX
#define INT64_C(c) (INT_LEAST64_MAX-INT_LEAST64_MAX+(c))
#define UINT64_C(c) (UINT_LEAST64_MAX-UINT_LEAST64_MAX+(c))
#endif
/*
7.18.4.2 Macros for greatest-width integer constants
*/
#define INTMAX_C(c) (INTMAX_MAX-INTMAX_MAX+(c))
#define UINTMAX_C(c) (UINTMAX_MAX-UINTMAX_MAX+(c))
#endif /* !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) */

1140
src/init/c/util/wchar.c Normal file

File diff suppressed because it is too large Load diff

227
src/init/c/util/wchar.h Normal file
View file

@ -0,0 +1,227 @@
/*
wchar.h -- extended multibyte and wide character utilities
This source code has been placed into the PUBLIC DOMAIN by its author.
last edit: 1999/08/20 gwyn@arl.mil
Implements subclause 7.24 of ISO/IEC 9899:1999 (E).
Unfortunately, it is NOT QUITE CONFORMING, because it #includes
<stddef.h> to obtain the definitions for wchar_t and size_t,
<stdint.h> for WCHAR_MIN and WCHAR_MAX, <stdio.h> for FILE, and
<time.h> for struct tm. If you plan to include this header in
a conforming C implementation, you must fix this. (FILE should
*not* be defined by this header, although it is needed in the
declarations!)
*/
#if !defined(_WCHAR_H) && !defined(_INC_WCHAR) /* usual lock names */
#define _WCHAR_H /* idempotency lock (section 7.1.2) */
#define _INC_WCHAR
#include <stddef.h> /* XXX -- for wchar_t and size_t */
#include <stdio.h> /* XXX -- for FILE (def of __Q8_FILE) */
#include <time.h> /* XXX -- for struct tm */
#include <Q8defs.h> /* defines the __Q8_* symbols */
#include <stdint.h> /* XXX -- for WCHAR_MIN and WCHAR_MAX */
#ifdef __cplusplus
extern "C" {
#endif
/*
7.24.1 Introduction
*/
#ifndef __Q8_MBSTATE_T_DEFINED
#define __Q8_MBSTATE_T_DEFINED /* idempotency lock */
typedef __Q8_MBSTATE_T mbstate_t;
#endif
#ifndef __Q8_SIZE_T_DEFINED
#define __Q8_SIZE_T_DEFINED /* idempotency lock */
/* typedef __Q8_SIZE_T size_t; /* XXX -- conflicts with native hdrs */
#endif
#ifndef __Q8_STRUCT_TM_DEFINED
#define __Q8_STRUCT_TM_DEFINED /* idempotency lock */
/* XXX -- need to work on this */
#endif
#ifndef __Q8_WCHAR_T_DEFINED
#define __Q8_WCHAR_T_DEFINED /* idempotency lock */
/* typedef __Q8_WCHAR_T wchar_t; /* XXX -- conflicts with native hdrs */
#endif
#ifndef __Q8_WINT_T_DEFINED
#define __Q8_WINT_T_DEFINED /* idempotency lock */
typedef __Q8_WINT_T wint_t;
#endif
#ifndef NULL /* to protect against native defs */
#define NULL __Q8_NULL
#endif
#if 0 /* XXX -- these __Q8_* symbols are not yet defined */
#ifndef WCHAR_MAX /* to protect against native defs */
#define WCHAR_MAX __Q8_WCHAR_MAX
#endif
#ifndef WCHAR_MIN /* to protect against native defs */
#define WCHAR_MIN __Q8_WCHAR_MIN
#endif
#endif /* XXX */
#ifndef WEOF /* to protect against native defs */
#define WEOF __Q8_WEOF
#endif
/*
7.24.2 Formatted wide character input/output functions
*/
extern int fwprintf __Q8_PARAMS((__Q8_FILE * __Q8_RESTRICT __stream,
__Q8_CONST wchar_t * __Q8_RESTRICT __format, ...));
extern int fwscanf __Q8_PARAMS((__Q8_FILE * __Q8_RESTRICT __stream,
__Q8_CONST wchar_t * __Q8_RESTRICT __format, ...));
extern int swprintf __Q8_PARAMS((wchar_t * __Q8_RESTRICT __s, size_t __n,
__Q8_CONST wchar_t * __Q8_RESTRICT __format, ...));
extern int swscanf __Q8_PARAMS((__Q8_CONST wchar_t * __Q8_RESTRICT __s,
__Q8_CONST wchar_t * __Q8_RESTRICT __format, ...));
extern int vfwprintf __Q8_PARAMS((__Q8_FILE * __Q8_RESTRICT __stream,
__Q8_CONST wchar_t * __Q8_RESTRICT __format,
__va_list __arg));
extern int vfwscanf __Q8_PARAMS((__Q8_FILE * __Q8_RESTRICT __stream,
__Q8_CONST wchar_t * __Q8_RESTRICT __format,
__va_list __arg));
extern int vswprintf __Q8_PARAMS((wchar_t * __Q8_RESTRICT __s, size_t __n,
__Q8_CONST wchar_t * __Q8_RESTRICT __format,
__va_list __arg));
extern int vswscanf __Q8_PARAMS((__Q8_CONST wchar_t * __Q8_RESTRICT __s,
__Q8_CONST wchar_t * __Q8_RESTRICT __format,
__va_list __arg));
extern int vwprintf __Q8_PARAMS((__Q8_CONST wchar_t * __Q8_RESTRICT
__format, __va_list __arg));
extern int vwscanf __Q8_PARAMS((__Q8_CONST wchar_t * __Q8_RESTRICT
__format, __va_list __arg));
extern int wprintf __Q8_PARAMS((__Q8_CONST wchar_t * __Q8_RESTRICT
__format, ...));
extern int wscanf __Q8_PARAMS((__Q8_CONST wchar_t * __Q8_RESTRICT
__format, ...));
/*
7.24.3 Wide character input/output functions
*/
extern wint_t fgetwc __Q8_PARAMS((__Q8_FILE * __stream));
extern wchar_t *fgetws __Q8_PARAMS((wchar_t * __Q8_RESTRICT __s, int __n,
__Q8_FILE * __Q8_RESTRICT __stream));
extern wint_t fputwc __Q8_PARAMS((wchar_t __c, __Q8_FILE * __stream));
extern int fputws __Q8_PARAMS((wchar_t * __Q8_RESTRICT __s,
__Q8_FILE * __Q8_RESTRICT __stream));
extern int fwide __Q8_PARAMS((__Q8_FILE * __stream, int __mode));
extern wint_t getwc __Q8_PARAMS((__Q8_FILE * __stream));
extern wint_t getwchar __Q8_PARAMS((void));
extern wint_t putwc __Q8_PARAMS((wchar_t __c, __Q8_FILE * __stream));
extern wint_t putwchar __Q8_PARAMS((wchar_t __c));
extern wint_t ungetwc __Q8_PARAMS((wint_t __c, __Q8_FILE * __stream));
/*
7.24.4 General wide string utilities
*/
extern double wcstod __Q8_PARAMS((__Q8_CONST wchar_t * __Q8_RESTRICT __nptr,
wchar_t ** __Q8_RESTRICT __endptr));
extern float wcstof __Q8_PARAMS((__Q8_CONST wchar_t * __Q8_RESTRICT __nptr,
wchar_t ** __Q8_RESTRICT __endptr));
#ifdef __Q8_GT
extern __Q8_GT
wcstold __Q8_PARAMS((__Q8_CONST wchar_t * __Q8_RESTRICT __nptr,
wchar_t ** __Q8_RESTRICT __endptr));
#endif
extern long wcstol __Q8_PARAMS((__Q8_CONST wchar_t * __Q8_RESTRICT __nptr,
wchar_t ** __Q8_RESTRICT __endptr, int __base));
extern unsigned long
wcstoul __Q8_PARAMS((__Q8_CONST wchar_t * __Q8_RESTRICT __nptr,
wchar_t ** __Q8_RESTRICT __endptr, int __base));
#ifdef __Q8_QT
extern __Q8_QT
wcstoll __Q8_PARAMS((__Q8_CONST wchar_t * __Q8_RESTRICT __nptr,
wchar_t ** __Q8_RESTRICT __endptr, int __base));
extern unsigned __Q8_QT
wcstoull __Q8_PARAMS((__Q8_CONST wchar_t * __Q8_RESTRICT __nptr,
wchar_t ** __Q8_RESTRICT __endptr, int __base));
#endif
extern wchar_t *wcscpy __Q8_PARAMS((wchar_t * __Q8_RESTRICT __s1,
__Q8_CONST wchar_t * __Q8_RESTRICT __s2));
extern wchar_t *wcsncpy __Q8_PARAMS((wchar_t * __Q8_RESTRICT __s1,
__Q8_CONST wchar_t * __Q8_RESTRICT __s2, size_t __n));
extern wchar_t *wmemcpy __Q8_PARAMS((wchar_t * __Q8_RESTRICT __s1,
__Q8_CONST wchar_t * __Q8_RESTRICT __s2, size_t __n));
extern wchar_t *wmemmove __Q8_PARAMS((wchar_t * __s1, __Q8_CONST wchar_t * __s2,
size_t __n));
extern wchar_t *wcscat __Q8_PARAMS((wchar_t * __Q8_RESTRICT __s1,
__Q8_CONST wchar_t * __Q8_RESTRICT __s2));
extern wchar_t *wcsncat __Q8_PARAMS((wchar_t * __Q8_RESTRICT __s1,
__Q8_CONST wchar_t * __Q8_RESTRICT __s2, size_t __n));
extern int wcscmp __Q8_PARAMS((__Q8_CONST wchar_t * __s1,
__Q8_CONST wchar_t * __s2));
extern int wcscoll __Q8_PARAMS((__Q8_CONST wchar_t * __s1,
__Q8_CONST wchar_t * __s2));
extern int wcsncmp __Q8_PARAMS((__Q8_CONST wchar_t * __s1,
__Q8_CONST wchar_t * __s2, size_t __n));
extern size_t wcsxfrm __Q8_PARAMS((wchar_t * __Q8_RESTRICT __s1,
__Q8_CONST wchar_t * __Q8_RESTRICT __s2, size_t __n));
extern int wmemcmp __Q8_PARAMS((__Q8_CONST wchar_t * __s1,
__Q8_CONST wchar_t * __s2, size_t __n));
extern wchar_t *wcschr __Q8_PARAMS((__Q8_CONST wchar_t * __s, wchar_t __c));
extern size_t wcscspn __Q8_PARAMS((__Q8_CONST wchar_t * __s1,
__Q8_CONST wchar_t * __s2));
extern wchar_t *wcspbrk __Q8_PARAMS((__Q8_CONST wchar_t * __s1,
__Q8_CONST wchar_t * __s2));
extern wchar_t *wcsrchr __Q8_PARAMS((__Q8_CONST wchar_t * __s, wchar_t __c));
extern size_t wcsspn __Q8_PARAMS((__Q8_CONST wchar_t * __s1,
__Q8_CONST wchar_t * __s2));
extern wchar_t *wcsstr __Q8_PARAMS((__Q8_CONST wchar_t * __s1,
__Q8_CONST wchar_t * __s2));
extern wchar_t *wcstok __Q8_PARAMS((wchar_t * __Q8_RESTRICT __s1,
__Q8_CONST wchar_t * __Q8_RESTRICT __s2,
wchar_t ** __Q8_RESTRICT __ptr));
extern wchar_t *wmemchr __Q8_PARAMS((__Q8_CONST wchar_t * __s, wchar_t __c,
size_t __n));
extern size_t wcslen __Q8_PARAMS((__Q8_CONST wchar_t * __s));
extern wchar_t *wmemset __Q8_PARAMS((wchar_t * __s, wchar_t __c, size_t __n));
/*
7.24.5 Wide character time conversion functions
*/
extern size_t wcsftime __Q8_PARAMS((wchar_t * __Q8_RESTRICT __s,
size_t __maxsize,
__Q8_CONST wchar_t * __Q8_RESTRICT __format,
__Q8_CONST struct tm * __Q8_RESTRICT __timeptr));
/*
7.24.6 Extended multibyte/wide character conversion utilities
*/
extern wint_t btowc __Q8_PARAMS((int __c));
extern int wctob __Q8_PARAMS((wint_t __c));
extern int mbsinit __Q8_PARAMS((__Q8_CONST mbstate_t *__ps));
extern size_t mbrlen __Q8_PARAMS((__Q8_CONST char * __Q8_RESTRICT __s,
size_t __n, mbstate_t * __Q8_RESTRICT __ps));
extern size_t mbrtowc __Q8_PARAMS((wchar_t * __Q8_RESTRICT __pwc,
__Q8_CONST char * __Q8_RESTRICT __s, size_t __n,
mbstate_t * __Q8_RESTRICT __ps));
extern size_t wcrtomb __Q8_PARAMS((char * __Q8_RESTRICT __s, wchar_t __wc,
mbstate_t * __Q8_RESTRICT __ps));
extern size_t mbsrtowcs __Q8_PARAMS((wchar_t * __Q8_RESTRICT __dst,
__Q8_CONST char ** __Q8_RESTRICT __src, size_t __len,
mbstate_t * __Q8_RESTRICT __ps));
extern size_t wcsrtombs __Q8_PARAMS((char * __Q8_RESTRICT __dst,
__Q8_CONST wchar_t ** __Q8_RESTRICT __src, size_t __len,
mbstate_t * __Q8_RESTRICT __ps));
#ifdef __cplusplus
}
#endif
#endif /* !defined(_WCHAR_H) && !defined(_INC_WCHAR) */

231
src/init/c/util/wctype.c Normal file
View file

@ -0,0 +1,231 @@
/*
wctype -- wide character classification and mapping utilities
This source code has been placed into the PUBLIC DOMAIN by its author.
last edit: 1999/11/05 gwyn@arl.mil
Implements subclause 7.25 of ISO/IEC 9899:1999 (E).
This particular implementation requires the matching <wctype.h>.
This is a minimal implementation for environments where
internationalization is not considered important.
It supports an encoding where all char codes are mapped
to the *same* code values within a wchar_t or wint_t,
so long as no other wchar_t codes are used by the program.
XXX -- UNTESTED -- XXX
*/
#include <ctype.h>
#include <errno.h>
#include <string.h>
#include <wctype.h> /* defines __Q8_CONST and __Q8_PARAMS */
/*
7.25.2 Wide character classification utilities
*/
int
iswalnum(wc)
wint_t wc;
{
return isalnum((int)(unsigned char)wc);
}
int
iswalpha(wc)
wint_t wc;
{
return isalpha((int)(unsigned char)wc);
}
int
iswblank(wc)
wint_t wc;
{
return isblank((int)(unsigned char)wc);
}
int
iswcntrl(wc)
wint_t wc;
{
return iscntrl((int)(unsigned char)wc);
}
int
iswdigit(wc)
wint_t wc;
{
return isdigit((int)(unsigned char)wc);
}
int
iswgraph(wc)
wint_t wc;
{
return isgraph((int)(unsigned char)wc);
}
int
iswlower(wc)
wint_t wc;
{
return islower((int)(unsigned char)wc);
}
int
iswprint(wc)
wint_t wc;
{
return isprint((int)(unsigned char)wc);
}
int
iswpunct(wc)
wint_t wc;
{
return ispunct((int)(unsigned char)wc);
}
int
iswspace(wc)
wint_t wc;
{
return isspace((int)(unsigned char)wc);
}
int
iswupper(wc)
wint_t wc;
{
return isupper((int)(unsigned char)wc);
}
int
iswxdigit(wc)
wint_t wc;
{
return isxdigit((int)(unsigned char)wc);
}
/*
wctype() usually encodes properties as ORed bit combinations;
for this *minimal implementation* I can take a lazy approach.
*/
static struct
{
__Q8_CONST char *name;
int (*func)__Q8_PARAMS((int));
} cmap[] =
{
"alnum", iswalnum,
"alpha", iswalpha,
"blank", iswblank,
"cntrl", iswcntrl,
"digit", iswdigit,
"graph", iswgraph,
"lower", iswlower,
"print", iswprint,
"punct", iswpunct,
"space", iswspace,
"upper", iswupper,
"xdigit", iswxdigit
};
#define NCMAP (sizeof cmap / sizeof cmap[0])
int
iswctype(wc, desc)
wint_t wc;
wctype_t desc;
{
register int i;
if ( desc <= 0 || desc > NCMAP ) /* undefined behavior */
{
errno = EDOM;
return 0; /* a form of not having the property */
}
return cmap[desc-1].func(wc);
}
wctype_t /* returns map index + 1 */
wctype(property)
__Q8_CONST char *property;
{
register int i;
for ( i = 0; i < NCMAP; ++i )
if ( strcmp(property, cmap[i].name) == 0 )
return i+1;
return 0; /* indicates "not valid" */
}
/*
7.25.3 Wide character case mapping utilities
*/
wint_t
towlower(wc)
wint_t wc;
{
return tolower((int)(unsigned char)wc);
}
wint_t
towupper(wc)
wint_t wc;
{
return toupper((int)(unsigned char)wc);
}
/*
For this *minimal implementation* I can take a lazy approach.
*/
static struct
{
__Q8_CONST char *name;
int (*func)__Q8_PARAMS((int));
} tmap[] =
{
"lower", towlower,
"upper", towupper
};
#define NTMAP (sizeof tmap / sizeof tmap[0])
wint_t
iswctrans(wc, desc)
wint_t wc;
wctrans_t desc;
{
register int i;
if ( desc <= 0 || desc > NTMAP ) /* undefined behavior */
{
errno = EDOM;
return 0; /* a form of not having the property */
}
return tmap[desc-1].func(wc);
}
wctrans_t /* returns map index + 1 */
wctrans(property)
__Q8_CONST char *property;
{
register int i;
for ( i = 0; i < NTMAP; ++i )
if ( strcmp(property, tmap[i].name) == 0 )
return i+1;
return 0; /* indicates "not valid" */
}

75
src/init/c/util/wctype.h Normal file
View file

@ -0,0 +1,75 @@
/*
wctype.h -- wide character classification and mapping utilities
This source code has been placed into the PUBLIC DOMAIN by its author.
last edit: 1999/08/20 gwyn@arl.mil
Implements subclause 7.25 of ISO/IEC 9899:1999 (E).
*/
#if !defined(_WCTYPE_H) && !defined(_INC_WCTYPE) /* usual lock names */
#define _WCTYPE_H /* idempotency lock (section 7.1.2) */
#define _INC_WCTYPE
#include <Q8defs.h> /* defines the __Q8_* symbols */
#ifdef __cplusplus
extern "C" {
#endif
/*
7.25.1 Introduction
*/
#ifndef __Q8_WINT_T_DEFINED
#define __Q8_WINT_T_DEFINED /* idempotency lock */
typedef __Q8_WINT_T wint_t;
#endif
#ifndef __Q8_WCTRANS_T_DEFINED
#define __Q8_WCTRANS_T_DEFINED /* idempotency lock */
typedef unsigned int wctrans_t; /* this type works nearly everywhere */
#endif
#ifndef __Q8_WCTYPE_T_DEFINED
#define __Q8_WCTYPE_T_DEFINED /* idempotency lock */
typedef int wctype_t; /* this type works nearly everywhere */
#endif
#ifndef WEOF /* to protect against native defs */
#define WEOF __Q8_WEOF
#endif
/*
7.25.2 Wide character classification utilities
*/
extern int iswalnum __Q8_PARAMS((wint_t __wc));
extern int iswalpha __Q8_PARAMS((wint_t __wc));
extern int iswblank __Q8_PARAMS((wint_t __wc));
extern int iswcntrl __Q8_PARAMS((wint_t __wc));
extern int iswdigit __Q8_PARAMS((wint_t __wc));
extern int iswgraph __Q8_PARAMS((wint_t __wc));
extern int iswlower __Q8_PARAMS((wint_t __wc));
extern int iswprint __Q8_PARAMS((wint_t __wc));
extern int iswpunct __Q8_PARAMS((wint_t __wc));
extern int iswspace __Q8_PARAMS((wint_t __wc));
extern int iswupper __Q8_PARAMS((wint_t __wc));
extern int iswxdigit __Q8_PARAMS((wint_t __wc));
extern int iswctype __Q8_PARAMS((wint_t __wc, wctype_t __desc));
extern wctype_t wctype __Q8_PARAMS((__Q8_CONST char *__property));
/*
7.25.3 Wide character case mapping utilities
*/
extern wint_t towlower __Q8_PARAMS((wint_t __wc));
extern wint_t towupper __Q8_PARAMS((wint_t __wc));
extern wint_t towctrans __Q8_PARAMS((wint_t __wc, wctrans_t __desc));
extern wctrans_t
wctrans __Q8_PARAMS((__Q8_CONST char *__property));
#ifdef __cplusplus
}
#endif
#endif /* !defined(_WCTYPE_H) && !defined(_INC_WCTYPE) */

View file

@ -51,12 +51,13 @@ static StringName print_StringName;
static GDExtensionPtrUtilityFunction print_function;
StringName string_name;
GDExtensionConstTypePtr constructor_arguments[1] = { &string_name };
StringName construct_StringName_from_cstring(const char *text) {
String string;
string_new_with_utf8_chars(&string, text);
StringName string_name;
GDExtensionConstTypePtr constructor_arguments[1] = { &string };
construct_StringName_from_String(&string_name, constructor_arguments);
destroy_String(&string);
@ -64,14 +65,15 @@ StringName construct_StringName_from_cstring(const char *text) {
return string_name;
}
Variant arg1;
GDExtensionConstVariantPtr args[1] = { &arg1 };
void print(const char *text) {
String string;
string_new_with_utf8_chars(&string, text);
Variant arg1;
construct_Variant_from_String(&arg1, &string);
GDExtensionConstVariantPtr args[1] = { &arg1 };
print_function(NULL, args, 1);
variant_destroy(&arg1);
@ -104,13 +106,15 @@ void deinitialize(void *userdata, GDExtensionInitializationLevel p_level) {
destroy_StringName(&print_StringName);
}
/* librtr object; called by Godot when it reads the librtr.gdextension file that
/* libsb object; called by Godot when it reads the libsb.gdextension file that
* provides a configuration using this name. */
GDExtensionBool librtr_extension_init(
GDExtensionBool libsb(
GDExtensionInterfaceGetProcAddress p_get_proc_address,
GDExtensionClassLibraryPtr p_library,
GDExtensionInitialization *r_initialization
) {
)
{
r_initialization->initialize = &initialize;
r_initialization->deinitialize = &deinitialize;
string_new_with_utf8_chars = (GDExtensionInterfaceStringNewWithUtf8Chars) p_get_proc_address("string_new_with_utf8_chars");