removed unneeded files

This commit is contained in:
hyung-hwan 2020-02-20 06:29:35 +00:00
parent 7585c36e3e
commit b72dc3aaad
4 changed files with 0 additions and 735 deletions

View File

@ -1,206 +0,0 @@
/*
* $Id$
*
Copyright (c) 2006-2019 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <hawk-fmt.h>
#include <hawk-utl.h>
#undef T
#undef char_t
#undef fmt_uintmax
#undef strlen
#define T(x) HAWK_BT(x)
#define char_t hawk_bch_t
#define fmt_uintmax fmt_unsigned_to_mbs
#define strlen(x) hawk_count_bcs(x)
#include "fmt-intmax.h"
#undef T
#undef char_t
#undef fmt_uintmax
#undef strlen
#define T(x) HAWK_UT(x)
#define char_t hawk_uch_t
#define fmt_uintmax fmt_unsigned_to_wcs
#define strlen(x) hawk_count_ucs(x)
#include "fmt-intmax.h"
/* ==================== multibyte ===================================== */
int hawk_fmtintmaxtombs (
hawk_bch_t* buf, int size,
hawk_intmax_t value, int base_and_flags, int prec,
hawk_bch_t fillchar, const hawk_bch_t* prefix)
{
hawk_bch_t signchar;
hawk_uintmax_t absvalue;
if (value < 0)
{
signchar = HAWK_BT('-');
absvalue = -value;
}
else if (base_and_flags & HAWK_FMTINTMAXTOMBS_PLUSSIGN)
{
signchar = HAWK_BT('+');
absvalue = value;
}
else if (base_and_flags & HAWK_FMTINTMAXTOMBS_EMPTYSIGN)
{
signchar = HAWK_BT(' ');
absvalue = value;
}
else
{
signchar = HAWK_BT('\0');
absvalue = value;
}
return fmt_unsigned_to_mbs(buf, size, absvalue, base_and_flags, prec, fillchar, signchar, prefix);
}
int hawk_fmtuintmaxtombs (
hawk_bch_t* buf, int size,
hawk_uintmax_t value, int base_and_flags, int prec,
hawk_bch_t fillchar, const hawk_bch_t* prefix)
{
hawk_bch_t signchar;
/* determine if a sign character is needed */
if (base_and_flags & HAWK_FMTINTMAXTOMBS_PLUSSIGN)
{
signchar = HAWK_BT('+');
}
else if (base_and_flags & HAWK_FMTINTMAXTOMBS_EMPTYSIGN)
{
signchar = HAWK_BT(' ');
}
else
{
signchar = HAWK_BT('\0');
}
return fmt_unsigned_to_mbs(buf, size, value, base_and_flags, prec, fillchar, signchar, prefix);
}
/* ==================== wide-char ===================================== */
int hawk_fmtintmaxtowcs (
hawk_uch_t* buf, int size,
hawk_intmax_t value, int base_and_flags, int prec,
hawk_uch_t fillchar, const hawk_uch_t* prefix)
{
hawk_uch_t signchar;
hawk_uintmax_t absvalue;
if (value < 0)
{
signchar = HAWK_UT('-');
absvalue = -value;
}
else if (base_and_flags & HAWK_FMTINTMAXTOWCS_PLUSSIGN)
{
signchar = HAWK_UT('+');
absvalue = value;
}
else if (base_and_flags & HAWK_FMTINTMAXTOMBS_EMPTYSIGN)
{
signchar = HAWK_UT(' ');
absvalue = value;
}
else
{
signchar = HAWK_UT('\0');
absvalue = value;
}
return fmt_unsigned_to_wcs(buf, size, absvalue, base_and_flags, prec, fillchar, signchar, prefix);
}
int hawk_fmtuintmaxtowcs (
hawk_uch_t* buf, int size,
hawk_uintmax_t value, int base_and_flags, int prec,
hawk_uch_t fillchar, const hawk_uch_t* prefix)
{
hawk_uch_t signchar;
/* determine if a sign character is needed */
if (base_and_flags & HAWK_FMTINTMAXTOWCS_PLUSSIGN)
{
signchar = HAWK_UT('+');
}
else if (base_and_flags & HAWK_FMTINTMAXTOMBS_EMPTYSIGN)
{
signchar = HAWK_UT(' ');
}
else
{
signchar = HAWK_UT('\0');
}
return fmt_unsigned_to_wcs(buf, size, value, base_and_flags, prec, fillchar, signchar, prefix);
}
/* ==================== floating-point number =========================== */
/* TODO: finish this function */
int hawk_fmtfltmaxtombs (hawk_bch_t* buf, hawk_oow_t bufsize, hawk_fltmax_t f, hawk_bch_t point, int digits)
{
hawk_oow_t len;
hawk_uintmax_t v;
/*if (bufsize <= 0) return -reqlen; TODO: */
if (f < 0)
{
f *= -1;
v = (hawk_uintmax_t)f;
len = hawk_fmtuintmaxtombs (buf, bufsize, v, 10, 0, HAWK_BT('\0'), HAWK_BT("-"));
}
else
{
v = (hawk_uintmax_t)f;
len = hawk_fmtuintmaxtombs (buf, bufsize, v, 10, 0, HAWK_BT('\0'), HAWK_NULL);
}
if (len + 1 < bufsize)
{
buf[len++] = point; /* add decimal point to string */
buf[len] = HAWK_BT('\0');
}
while (len + 1 < bufsize && digits-- > 0)
{
f = (f - (hawk_fltmax_t)v) * 10;
v = (hawk_uintmax_t)f;
len += hawk_fmtuintmaxtombs(&buf[len], bufsize - len, v, 10, 0, HAWK_BT('\0'), HAWK_NULL);
}
return (int)len;
}

View File

@ -1,226 +0,0 @@
/*
* $Id$
*
Copyright (c) 2006-2019 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
static int fmt_uintmax (
char_t* buf, int size,
hawk_uintmax_t value, int base_and_flags, int prec,
char_t fillchar, char_t signchar, const char_t* prefix)
{
char_t tmp[(HAWK_SIZEOF(hawk_uintmax_t) * 8)];
int reslen, base, fillsize, reqlen, pflen, preczero;
char_t* p, * bp, * be;
const char_t* xbasestr;
base = base_and_flags & 0x3F;
if (base < 2 || base > 36) return -1;
xbasestr = (base_and_flags & HAWK_FMTINTMAX_UPPERCASE)?
T("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"):
T("0123456789abcdefghijklmnopqrstuvwxyz");
if ((base_and_flags & HAWK_FMTINTMAX_NOZERO) && value == 0)
{
p = tmp;
if (base_and_flags & HAWK_FMTINTMAX_ZEROLEAD)
{
/* NOZERO emits no digit, ZEROLEAD emits 1 digit.
* so it emits '0' */
reslen = 1;
preczero = 1;
}
else
{
/* since the value is zero, emit no digits */
reslen = 0;
preczero = 0;
}
}
else
{
hawk_uintmax_t v = value;
/* store the resulting numeric string into 'tmp' first */
p = tmp;
do
{
*p++ = xbasestr[v % base];
v /= base;
}
while (v > 0);
/* reslen is the length of the resulting string without padding. */
reslen = (int)(p - tmp);
/* precision specified the minum number of digits to produce.
* so if the precision is larger that the digits produced,
* reslen should be adjusted to precision */
if (prec > reslen)
{
/* if the precision is greater than the actual digits
* made from the value, 0 is inserted in front.
* ZEROLEAD doesn't have to be handled explicitly
* since it's achieved effortlessly */
preczero = prec - reslen;
reslen = prec;
}
else
{
preczero = 0;
if ((base_and_flags & HAWK_FMTINTMAX_ZEROLEAD) && value != 0)
{
/* if value is zero, 0 is emitted from it.
* so ZEROLEAD don't need to add another 0. */
preczero++;
reslen++;
}
}
}
if (signchar) reslen++; /* increment reslen for the sign character */
if (prefix)
{
/* since the length can be truncated for different type sizes,
* don't pass in a very long prefix. */
pflen = (int) strlen(prefix);
reslen += pflen;
}
else pflen = 0;
/* get the required buffer size for lossless formatting */
reqlen = (base_and_flags & HAWK_FMTINTMAX_NONULL)? reslen: (reslen + 1);
if (size <= 0 ||
((base_and_flags & HAWK_FMTINTMAX_NOTRUNC) && size < reqlen))
{
return -reqlen;
}
/* get the size to fill with fill characters */
fillsize = (base_and_flags & HAWK_FMTINTMAX_NONULL)? size: (size - 1);
bp = buf;
be = buf + fillsize;
/* fill space */
if (fillchar != T('\0'))
{
if (base_and_flags & HAWK_FMTINTMAX_FILLRIGHT)
{
/* emit sign */
if (signchar && bp < be) *bp++ = signchar;
/* copy prefix if necessary */
if (prefix) while (*prefix && bp < be) *bp++ = *prefix++;
/* add 0s for precision */
while (preczero > 0 && bp < be)
{
*bp++ = T('0');
preczero--;
}
/* copy the numeric string to the destination buffer */
while (p > tmp && bp < be) *bp++ = *--p;
/* fill the right side */
while (fillsize > reslen)
{
*bp++ = fillchar;
fillsize--;
}
}
else if (base_and_flags & HAWK_FMTINTMAX_FILLCENTER)
{
/* emit sign */
if (signchar && bp < be) *bp++ = signchar;
/* fill the left side */
while (fillsize > reslen)
{
*bp++ = fillchar;
fillsize--;
}
/* copy prefix if necessary */
if (prefix) while (*prefix && bp < be) *bp++ = *prefix++;
/* add 0s for precision */
while (preczero > 0 && bp < be)
{
*bp++ = T('0');
preczero--;
}
/* copy the numeric string to the destination buffer */
while (p > tmp && bp < be) *bp++ = *--p;
}
else
{
/* fill the left side */
while (fillsize > reslen)
{
*bp++ = fillchar;
fillsize--;
}
/* emit sign */
if (signchar && bp < be) *bp++ = signchar;
/* copy prefix if necessary */
if (prefix) while (*prefix && bp < be) *bp++ = *prefix++;
/* add 0s for precision */
while (preczero > 0 && bp < be)
{
*bp++ = T('0');
preczero--;
}
/* copy the numeric string to the destination buffer */
while (p > tmp && bp < be) *bp++ = *--p;
}
}
else
{
/* emit sign */
if (signchar && bp < be) *bp++ = signchar;
/* copy prefix if necessary */
if (prefix) while (*prefix && bp < be) *bp++ = *prefix++;
/* add 0s for precision */
while (preczero > 0 && bp < be)
{
*bp++ = T('0');
preczero--;
}
/* copy the numeric string to the destination buffer */
while (p > tmp && bp < be) *bp++ = *--p;
}
if (!(base_and_flags & HAWK_FMTINTMAX_NONULL)) *bp = T('\0');
return bp - buf;
}

View File

@ -1,190 +0,0 @@
/*
* $Id$
*
Copyright (c) 2006-2019 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <hawk-fmt.h>
#include <hawk-prv.h>
#include <stdarg.h>
#include "fmt-prv.h"
#include <stdio.h> /* for snrintf(). used for floating-point number formatting */
#if defined(_MSC_VER) || defined(__BORLANDC__) || (defined(__WATCOMC__) && (__WATCOMC__ < 1200))
# define snprintf _snprintf
# if !defined(HAVE_SNPRINTF)
# define HAVE_SNPRINTF
# endif
#endif
#if defined(HAVE_QUADMATH_H)
# include <quadmath.h> /* for quadmath_snprintf() */
#endif
/* TODO: remove stdio.h and quadmath.h once snprintf gets replaced by own
floting-point conversion implementation*/
/* number of bits in a byte */
#define NBBY 8
/* Max number conversion buffer length:
* hawk_intmax_t in base 2, plus NUL byte. */
#define MAXNBUF (HAWK_SIZEOF(hawk_intmax_t) * NBBY + 1)
enum
{
/* integer */
LF_C = (1 << 0),
LF_H = (1 << 1),
LF_J = (1 << 2),
LF_L = (1 << 3),
LF_Q = (1 << 4),
LF_T = (1 << 5),
LF_Z = (1 << 6),
LF_I8 = (1 << 7),
LF_I16 = (1 << 8),
LF_I32 = (1 << 9),
LF_I64 = (1 << 10),
LF_I128 = (1 << 11),
/* long double */
LF_LD = (1 << 12),
/* __float128 */
LF_QD = (1 << 13)
};
static struct
{
hawk_uint8_t flag; /* for single occurrence */
hawk_uint8_t dflag; /* for double occurrence */
} lm_tab[26] =
{
{ 0, 0 }, /* a */
{ 0, 0 }, /* b */
{ 0, 0 }, /* c */
{ 0, 0 }, /* d */
{ 0, 0 }, /* e */
{ 0, 0 }, /* f */
{ 0, 0 }, /* g */
{ LF_H, LF_C }, /* h */
{ 0, 0 }, /* i */
{ LF_J, 0 }, /* j */
{ 0, 0 }, /* k */
{ LF_L, LF_Q }, /* l */
{ 0, 0 }, /* m */
{ 0, 0 }, /* n */
{ 0, 0 }, /* o */
{ 0, 0 }, /* p */
{ LF_Q, 0 }, /* q */
{ 0, 0 }, /* r */
{ 0, 0 }, /* s */
{ LF_T, 0 }, /* t */
{ 0, 0 }, /* u */
{ 0, 0 }, /* v */
{ 0, 0 }, /* w */
{ 0, 0 }, /* z */
{ 0, 0 }, /* y */
{ LF_Z, 0 }, /* z */
};
enum
{
FLAGC_DOT = (1 << 0),
FLAGC_SPACE = (1 << 1),
FLAGC_SHARP = (1 << 2),
FLAGC_SIGN = (1 << 3),
FLAGC_LEFTADJ = (1 << 4),
FLAGC_ZEROPAD = (1 << 5),
FLAGC_WIDTH = (1 << 6),
FLAGC_PRECISION = (1 << 7),
FLAGC_STAR1 = (1 << 8),
FLAGC_STAR2 = (1 << 9),
FLAGC_LENMOD = (1 << 10) /* length modifier */
};
/* ------------------------------------------------------------------ */
static const hawk_bch_t* m_hex2ascii =
HAWK_BT("0123456789abcdefghijklmnopqrstuvwxyz");
static const hawk_uch_t* w_hex2ascii =
HAWK_UT("0123456789abcdefghijklmnopqrstuvwxyz");
/* ------------------------------------------------------------------ */
#undef char_t
#undef uchar_t
#undef ochar_t
#undef T
#undef OT
#undef CONV_MAX
#undef toupper
#undef hex2ascii
#undef sprintn
#undef fmtout_t
#undef fmtout
#define char_t hawk_bch_t
#define uchar_t hawk_bch_t
#define ochar_t hawk_uch_t
#define T(x) HAWK_BT(x)
#define OT(x) HAWK_UT(x)
#define CONV_MAX HAWK_MBLEN_MAX
#define toupper HAWK_TOUPPER
#define sprintn m_sprintn
#define fmtout_t hawk_mfmtout_t
#define fmtout hawk_mfmtout
#define hex2ascii(hex) (m_hex2ascii[hex])
#include "fmt-out.h"
/* ------------------------------------------------------------------ */
#undef char_t
#undef uchar_t
#undef ochar_t
#undef T
#undef OT
#undef CONV_MAX
#undef toupper
#undef hex2ascii
#undef sprintn
#undef fmtout_t
#undef fmtout
#define char_t hawk_uch_t
#define uchar_t hawk_uch_t
#define ochar_t hawk_bch_t
#define T(x) HAWK_UT(x)
#define OT(x) HAWK_BT(x)
#define CONV_MAX 1
#define toupper HAWK_TOWUPPER
#define sprintn w_sprintn
#define fmtout_t hawk_wfmtout_t
#define fmtout hawk_wfmtout
#define hex2ascii(hex) (w_hex2ascii[hex])
#include "fmt-out.h"

View File

@ -1,113 +0,0 @@
/*
* $Id$
*
Copyright (c) 2006-2019 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _HAWK_FMT_PRV_H_
#define _HAWK_FMT_PRV_H_
#include <hawk-fmt.h>
#include <stdarg.h>
typedef int (*hawk_mfmtout_put_t) (
hawk_bch_t c,
void* ctx
);
/* convert a wide string to a multi-byte string */
typedef int (*hawk_mfmtout_conv_t) (
const hawk_uch_t* wcs,
hawk_oow_t* wcslen,
hawk_bch_t* mbs,
hawk_oow_t* mbslen,
void* ctx
);
struct hawk_mfmtout_t
{
hawk_oow_t count; /* out */
hawk_oow_t limit; /* in */
void* ctx; /* in */
hawk_mfmtout_put_t put; /* in */
hawk_mfmtout_conv_t conv; /* in */
};
typedef struct hawk_mfmtout_t hawk_mfmtout_t;
typedef int (*hawk_wfmtout_put_t) (
hawk_uch_t c,
void* ctx
);
/* convert a multi-byte string to a wide string */
typedef int (*hawk_wfmtout_conv_t) (
const hawk_bch_t* mbs,
hawk_oow_t* mbslen,
hawk_uch_t* wcs,
hawk_oow_t* wcslen,
void* ctx
);
struct hawk_wfmtout_t
{
hawk_oow_t count; /* out */
hawk_oow_t limit; /* in */
void* ctx; /* in */
hawk_wfmtout_put_t put; /* in */
hawk_wfmtout_conv_t conv; /* in */
};
typedef struct hawk_wfmtout_t hawk_wfmtout_t;
#if defined(__cplusplus)
extern "C" {
#endif
/* HAWK_EXPORTed, but keep in it the private header for used by other libraries in HAWK */
HAWK_EXPORT int hawk_mfmtout (
const hawk_bch_t* fmt,
hawk_mfmtout_t* data,
va_list ap
);
HAWK_EXPORT int hawk_wfmtout (
const hawk_uch_t* fmt,
hawk_wfmtout_t* data,
va_list ap
);
#if defined(HAWK_OOCH_IS_BCH)
# define hawk_fmtout_t hawk_mfmtout_t
# define hawk_fmtout(fmt,fo,ap) hawk_mfmtout(fmt,fo,ap)
#else
# define hawk_fmtout_t hawk_wfmtout_t
# define hawk_fmtout(fmt,fo,ap) hawk_wfmtout(fmt,fo,ap)
#endif
#if defined(__cplusplus)
}
#endif
#endif