enhanced qse_getnwifcfg() for linux.

added qse_mbshextobin(), qse_wcshextobin()
This commit is contained in:
hyung-hwan 2014-08-30 05:40:57 +00:00
parent 477dc278c2
commit 46f13c54b3
14 changed files with 554 additions and 107 deletions

View File

@ -686,7 +686,7 @@ static int comparg (int argc, qse_char_t* argv[], struct arg_t* arg)
case QSE_T('m'): case QSE_T('m'):
{ {
arg->memlimit = qse_strtoulong (opt.arg); arg->memlimit = qse_strtoulong (opt.arg, 10);
break; break;
} }
@ -699,7 +699,7 @@ static int comparg (int argc, qse_char_t* argv[], struct arg_t* arg)
#if defined(QSE_BUILD_DEBUG) #if defined(QSE_BUILD_DEBUG)
case QSE_T('X'): case QSE_T('X'):
{ {
arg->failmalloc = qse_strtoulong (opt.arg); arg->failmalloc = qse_strtoulong (opt.arg, 10);
break; break;
} }
#endif #endif

View File

@ -1029,7 +1029,7 @@ static int get_boolean (const qse_xli_str_t* v)
static int get_integer (const qse_xli_str_t* v) static int get_integer (const qse_xli_str_t* v)
{ {
/* TODO: be more strict */ /* TODO: be more strict */
return qse_strxtoi (v->ptr, v->len); return qse_strxtoi (v->ptr, v->len, 10);
} }
static int load_loccfg_basic (qse_httpd_t* httpd, qse_xli_t* xli, qse_xli_list_t* list, loccfg_t* cfg) static int load_loccfg_basic (qse_httpd_t* httpd, qse_xli_t* xli, qse_xli_list_t* list, loccfg_t* cfg)
@ -1984,7 +1984,7 @@ static void set_limit (qse_httpd_t* httpd, const qse_char_t* name, int what)
if (qse_strxcmp (str, len, QSE_T("unlimited")) == 0) if (qse_strxcmp (str, len, QSE_T("unlimited")) == 0)
lim.rlim_cur = RLIM_INFINITY; lim.rlim_cur = RLIM_INFINITY;
else else
lim.rlim_cur = qse_strtoui (((qse_xli_str_t*)pair->val)->ptr); lim.rlim_cur = qse_strtoui (((qse_xli_str_t*)pair->val)->ptr, 10);
if (setrlimit (what, &lim) <= -1) if (setrlimit (what, &lim) <= -1)
{ {
/* TODO: warning */ /* TODO: warning */

View File

@ -934,7 +934,7 @@ static int httpd_main (int argc, qse_char_t* argv[])
signal (SIGHUP, handle_signal); signal (SIGHUP, handle_signal);
signal (SIGPIPE, SIG_IGN); signal (SIGPIPE, SIG_IGN);
if (init_ursd (&ursd, qse_strtoi(argv[2]), argv[1], argv[3]) <= -1) goto oops; if (init_ursd (&ursd, qse_strtoi(argv[2], 10), argv[1], argv[3]) <= -1) goto oops;
ursd_inited = 1; ursd_inited = 1;
while (!g_stop_requested) while (!g_stop_requested)

View File

@ -357,7 +357,7 @@ static int handle_args (int argc, qse_char_t* argv[])
#endif #endif
case QSE_T('m'): case QSE_T('m'):
g_memlimit = qse_strtoulong (opt.arg); g_memlimit = qse_strtoulong (opt.arg, 10);
break; break;
case QSE_T('w'): case QSE_T('w'):
@ -366,7 +366,7 @@ static int handle_args (int argc, qse_char_t* argv[])
#if defined(QSE_BUILD_DEBUG) #if defined(QSE_BUILD_DEBUG)
case QSE_T('X'): case QSE_T('X'):
g_failmalloc = qse_strtoulong (opt.arg); g_failmalloc = qse_strtoulong (opt.arg, 10);
break; break;
#endif #endif

View File

@ -271,12 +271,12 @@ static int handle_args (int argc, qse_char_t* argv[])
break; break;
case QSE_T('m'): case QSE_T('m'):
g_memlimit = qse_strtoulong (opt.arg); g_memlimit = qse_strtoulong (opt.arg, 10);
break; break;
#if defined(QSE_BUILD_DEBUG) #if defined(QSE_BUILD_DEBUG)
case QSE_T('X'): case QSE_T('X'):
g_failmalloc = qse_strtoulong (opt.arg); g_failmalloc = qse_strtoulong (opt.arg, 10);
break; break;
#endif #endif

View File

@ -1896,79 +1896,251 @@ QSE_EXPORT qse_wchar_t* qse_wcsxrpbrk (
/* /*
* string conversion * string conversion
*/ */
QSE_EXPORT int qse_strtoi ( QSE_EXPORT int qse_mbstoi (
const qse_char_t* str const qse_mchar_t* str,
int base
); );
QSE_EXPORT long qse_strtol ( QSE_EXPORT long qse_mbstol (
const qse_char_t* str const qse_mchar_t* str,
int base
); );
QSE_EXPORT unsigned int qse_strtoui ( QSE_EXPORT unsigned int qse_mbstoui (
const qse_char_t* str const qse_mchar_t* str,
int base
); );
QSE_EXPORT unsigned long qse_strtoul ( QSE_EXPORT unsigned long qse_mbstoul (
const qse_char_t* str const qse_mchar_t* str,
int base
); );
QSE_EXPORT int qse_strxtoi ( QSE_EXPORT int qse_mbsxtoi (
const qse_char_t* str, const qse_mchar_t* str,
qse_size_t len qse_size_t len,
int base
); );
QSE_EXPORT long qse_strxtol ( QSE_EXPORT long qse_mbsxtol (
const qse_char_t* str, const qse_mchar_t* str,
qse_size_t len qse_size_t len,
int base
); );
QSE_EXPORT unsigned int qse_strxtoui ( QSE_EXPORT unsigned int qse_mbsxtoui (
const qse_char_t* str, const qse_mchar_t* str,
qse_size_t len qse_size_t len,
int base
); );
QSE_EXPORT unsigned long qse_strxtoul ( QSE_EXPORT unsigned long qse_mbsxtoul (
const qse_char_t* str, const qse_mchar_t* str,
qse_size_t len qse_size_t len,
int base
); );
QSE_EXPORT qse_int_t qse_strtoint ( QSE_EXPORT qse_int_t qse_mbstoint (
const qse_char_t* str const qse_mchar_t* str,
int base
); );
QSE_EXPORT qse_long_t qse_strtolong ( QSE_EXPORT qse_long_t qse_mbstolong (
const qse_char_t* str const qse_mchar_t* str,
int base
); );
QSE_EXPORT qse_uint_t qse_strtouint ( QSE_EXPORT qse_uint_t qse_mbstouint (
const qse_char_t* str const qse_mchar_t* str,
int base
); );
QSE_EXPORT qse_ulong_t qse_strtoulong ( QSE_EXPORT qse_ulong_t qse_mbstoulong (
const qse_char_t* str const qse_mchar_t* str,
int base
); );
QSE_EXPORT qse_int_t qse_strxtoint ( QSE_EXPORT qse_int_t qse_mbsxtoint (
const qse_char_t* str, qse_size_t len const qse_mchar_t* str,
qse_size_t len,
int base
); );
QSE_EXPORT qse_long_t qse_strxtolong ( QSE_EXPORT qse_long_t qse_mbsxtolong (
const qse_char_t* str, const qse_mchar_t* str,
qse_size_t len qse_size_t len,
int base
); );
QSE_EXPORT qse_uint_t qse_strxtouint ( QSE_EXPORT qse_uint_t qse_mbsxtouint (
const qse_char_t* str, const qse_mchar_t* str,
qse_size_t len qse_size_t len,
int base
); );
QSE_EXPORT qse_ulong_t qse_strxtoulong ( QSE_EXPORT qse_ulong_t qse_mbsxtoulong (
const qse_char_t* str, const qse_mchar_t* str,
qse_size_t len qse_size_t len,
int base
); );
QSE_EXPORT int qse_wcstoi (
const qse_wchar_t* str,
int base
);
QSE_EXPORT long qse_wcstol (
const qse_wchar_t* str,
int base
);
QSE_EXPORT unsigned int qse_wcstoui (
const qse_wchar_t* str,
int base
);
QSE_EXPORT unsigned long qse_wcstoul (
const qse_wchar_t* str,
int base
);
QSE_EXPORT int qse_wcsxtoi (
const qse_wchar_t* str,
qse_size_t len,
int base
);
QSE_EXPORT long qse_wcsxtol (
const qse_wchar_t* str,
qse_size_t len,
int base
);
QSE_EXPORT unsigned int qse_wcsxtoui (
const qse_wchar_t* str,
qse_size_t len,
int base
);
QSE_EXPORT unsigned long qse_wcsxtoul (
const qse_wchar_t* str,
qse_size_t len,
int base
);
QSE_EXPORT qse_int_t qse_wcstoint (
const qse_wchar_t* str,
int base
);
QSE_EXPORT qse_long_t qse_wcstolong (
const qse_wchar_t* str,
int base
);
QSE_EXPORT qse_uint_t qse_wcstouint (
const qse_wchar_t* str,
int base
);
QSE_EXPORT qse_ulong_t qse_wcstoulong (
const qse_wchar_t* str,
int base
);
QSE_EXPORT qse_int_t qse_wcsxtoint (
const qse_wchar_t* str,
qse_size_t len,
int base
);
QSE_EXPORT qse_long_t qse_wcsxtolong (
const qse_wchar_t* str,
qse_size_t len,
int base
);
QSE_EXPORT qse_uint_t qse_wcsxtouint (
const qse_wchar_t* str,
qse_size_t len,
int base
);
QSE_EXPORT qse_ulong_t qse_wcsxtoulong (
const qse_wchar_t* str,
qse_size_t len,
int base
);
#if defined(QSE_CHAR_IS_MCHAR)
# define qse_strtoi(str,base) qse_mbstoi(str,base)
# define qse_strtol(str,base) qse_mbstol(str,base)
# define qse_strtoui(str,base) qse_mbstoui(str,base)
# define qse_strtoul(str,base) qse_mbstoul(str,base)
# define qse_strxtoi(str,len,base) qse_mbsxtoi(str,len,base)
# define qse_strxtol(str,len,base) qse_mbsxtol(str,len,base)
# define qse_strxtoui(str,len,base) qse_mbsxtoui(str,len,base)
# define qse_strxtoul(str,len,base) qse_mbsxtoul(str,len,base)
# define qse_strtoint(str,base) qse_mbstoint(str,base)
# define qse_strtolong(str,base) qse_mbstolong(str,base)
# define qse_strtouint(str,base) qse_mbstouint(str,base)
# define qse_strtoulong(str,base) qse_mbstoulong(str,base)
# define qse_strxtoint(str,len,base) qse_mbsxtoint(str,len,base)
# define qse_strxtolong(str,len,base) qse_mbsxtolong(str,len,base)
# define qse_strxtouint(str,len,base) qse_mbsxtouint(str,len,base)
# define qse_strxtoulong(str,len,base) qse_mbsxtoulong(str,len,base)
#else
# define qse_strtoi(str,base) qse_wcstoi(str,base)
# define qse_strtol(str,base) qse_wcstol(str,base)
# define qse_strtoui(str,base) qse_wcstoui(str,base)
# define qse_strtoul(str,base) qse_wcstoul(str,base)
# define qse_strxtoi(str,len,base) qse_wcsxtoi(str,len,base)
# define qse_strxtol(str,len,base) qse_wcsxtol(str,len,base)
# define qse_strxtoui(str,len,base) qse_wcsxtoui(str,len,base)
# define qse_strxtoul(str,len,base) qse_wcsxtoul(str,len,base)
# define qse_strtoint(str,base) qse_wcstoint(str,base)
# define qse_strtolong(str,base) qse_wcstolong(str,base)
# define qse_strtouint(str,base) qse_wcstouint(str,base)
# define qse_strtoulong(str,base) qse_wcstoulong(str,base)
# define qse_strxtoint(str,len,base) qse_wcsxtoint(str,len,base)
# define qse_strxtolong(str,len,base) qse_wcsxtolong(str,len,base)
# define qse_strxtouint(str,len,base) qse_wcsxtouint(str,len,base)
# define qse_strxtoulong(str,len,base) qse_wcsxtoulong(str,len,base)
#endif
QSE_EXPORT int qse_mbshextobin (
const qse_mchar_t* hex,
qse_size_t hexlen,
qse_uint8_t* buf,
qse_size_t buflen
);
QSE_EXPORT int qse_wcshextobin (
const qse_wchar_t* hex,
qse_size_t hexlen,
qse_uint8_t* buf,
qse_size_t buflen
);
#if defined(QSE_CHAR_IS_MCHAR)
# define qse_strhextobin(hex,hexlen,buf,buflen) qse_mbshextobin(hex,hexlen,buf,buflen)
#else
# define qse_strhextobin(hex,hexlen,buf,buflen) qse_wcshextobin(hex,hexlen,buf,buflen)
#endif
QSE_EXPORT qse_size_t qse_mbsdel ( QSE_EXPORT qse_size_t qse_mbsdel (
qse_mchar_t* str, qse_mchar_t* str,
qse_size_t pos, qse_size_t pos,

View File

@ -526,7 +526,7 @@ int qse_memcmp (const void* s1, const void* s2, qse_size_t n)
#endif #endif
} }
void* qse_memchr (const void* s, int val, qse_size_t n) void* qse_membyte (const void* s, int val, qse_size_t n)
{ {
const qse_byte_t* x = (const qse_byte_t*)s; const qse_byte_t* x = (const qse_byte_t*)s;
@ -539,7 +539,7 @@ void* qse_memchr (const void* s, int val, qse_size_t n)
return QSE_NULL; return QSE_NULL;
} }
void* qse_memrchr (const void* s, int val, qse_size_t n) void* qse_memrbyte (const void* s, int val, qse_size_t n)
{ {
const qse_byte_t* x = (qse_byte_t*)s + n - 1; const qse_byte_t* x = (qse_byte_t*)s + n - 1;

View File

@ -23,6 +23,8 @@
#include <qse/cmn/mem.h> #include <qse/cmn/mem.h>
#define MINIMIZE_PLATFORM_DEPENDENCY
#ifdef MINIMIZE_PLATFORM_DEPENDENCY #ifdef MINIMIZE_PLATFORM_DEPENDENCY
# define QSE_MEMCPY(dst,src,len) qse_memcpy(dst,src,len) # define QSE_MEMCPY(dst,src,len) qse_memcpy(dst,src,len)
# define QSE_MEMMOVE(dst,src,len) qse_memmove(dst,src,len) # define QSE_MEMMOVE(dst,src,len) qse_memmove(dst,src,len)

View File

@ -21,6 +21,7 @@
#include <qse/cmn/nwif.h> #include <qse/cmn/nwif.h>
#include <qse/cmn/str.h> #include <qse/cmn/str.h>
#include <qse/cmn/mbwc.h> #include <qse/cmn/mbwc.h>
#include <qse/cmn/sio.h>
#include "mem.h" #include "mem.h"
#if defined(_WIN32) #if defined(_WIN32)
@ -286,24 +287,81 @@ void qse_freenwifcfg (qse_nwifcfg_t* cfg)
#if defined(__linux) #if defined(__linux)
static void read_proc_net_if_inet6 (qse_nwifcfg_t* cfg, struct ifreq* ifr) static void read_proc_net_if_inet6 (qse_nwifcfg_t* cfg, struct ifreq* ifr)
{ {
#if 0 /*
*
* # cat /proc/net/if_inet6
* 00000000000000000000000000000001 01 80 10 80 lo
* +------------------------------+ ++ ++ ++ ++ ++
* | | | | | |
* 1 2 3 4 5 6
*
* 1. IPv6 address displayed in 32 hexadecimal chars without colons as separator
* 2. Netlink device number (interface index) in hexadecimal (see ip addr , too)
* 3. Prefix length in hexadecimal
* 4. Scope value (see kernel source include/net/ipv6.h and net/ipv6/addrconf.c for more)
* 5. Interface flags (see include/linux/rtnetlink.h and net/ipv6/addrconf.c for more)
* 6. Device name
*/
qse_sio_t* sio; qse_sio_t* sio;
qse_mchar_t line[128]; qse_mchar_t line[128];
qse_mchar_t* ptr, * ptr2;
qse_ssize_t len;
qse_mcstr_t tok[6];
int count, index;
/* TODO */ /* TODO */
sio = qse_sio_open (QSE_MMGR_GETDFL(), 0, sio = qse_sio_open (QSE_MMGR_GETDFL(), 0,
QSE_T("proc/net/if_inet6"), QSE_SIO_IGNOREMBWCERR | QSE_SIO_READ); QSE_T("/proc/net/if_inet6"), QSE_SIO_IGNOREMBWCERR | QSE_SIO_READ);
if (sio) if (sio)
{ {
qse_ssize_t x;
while (1) while (1)
{ {
x = qse_sio_getmbs (sio, line, QSE_COUNTOF(line)); len = qse_sio_getmbs (sio, line, QSE_COUNTOF(line));
if (x == -1) break; if (len <= 0) break;
count = 0;
ptr = line;
while (ptr && count < 6)
{
ptr2 = qse_mbsxtok (ptr, len, QSE_MT(" \t"), &tok[count]);
len -= ptr2 - ptr;
ptr = ptr2;
count++;
} }
if (count >= 6)
{
index = qse_mbsxtoi (tok[1].ptr, tok[1].len, 16);
if (index == cfg->index)
{
int ti;
if (qse_mbshextobin (tok[0].ptr, tok[0].len, cfg->addr.u.in6.addr.value, QSE_COUNTOF(cfg->addr.u.in6.addr.value)) <= -1) break;
/* tok[3] is the scope type, not the actual scope.
* i leave this code for reference only.
cfg->addr.u.in6.scope = qse_mbsxtoi (tok[3].ptr, tok[3].len, 16); */
cfg->addr.type = QSE_NWAD_IN6;
ti = qse_mbsxtoi (tok[2].ptr, tok[0].len, 16);
qse_prefixtoip6ad (ti, &cfg->mask.u.in6.addr);
cfg->mask.type = QSE_NWAD_IN6;
goto done;
}
}
}
done:
qse_sio_close (sio); qse_sio_close (sio);
} }
#endif
} }
#endif #endif
@ -498,11 +556,13 @@ static int get_nwifcfg (int s, qse_nwifcfg_t* cfg, struct ifreq* ifr)
#if defined(SIOCGIFINDEX) #if defined(SIOCGIFINDEX)
if (ioctl (s, SIOCGIFINDEX, ifr) <= -1) return -1; if (ioctl (s, SIOCGIFINDEX, ifr) <= -1) return -1;
#if defined(HAVE_STRUCT_IFREQ_IFR_IFINDEX) #if defined(HAVE_STRUCT_IFREQ_IFR_IFINDEX)
cfg->index = ifr->ifr_ifindex; cfg->index = ifr->ifr_ifindex;
#else #else
cfg->index = ifr->ifr_index; cfg->index = ifr->ifr_index;
#endif #endif
#else #else
cfg->index = 0; cfg->index = 0;
#endif #endif
@ -537,14 +597,13 @@ static int get_nwifcfg (int s, qse_nwifcfg_t* cfg, struct ifreq* ifr)
qse_skadtonwad (&ifr->ifr_addr, &cfg->mask); qse_skadtonwad (&ifr->ifr_addr, &cfg->mask);
#if defined(__linux) #if defined(__linux)
if (cfg->addr.type == QSE_NWAD_NX && cfg->mask.type == QSE_NWAD_NX) if (cfg->addr.type == QSE_NWAD_NX && cfg->mask.type == QSE_NWAD_NX && cfg->type == QSE_NWIFCFG_IN6)
{ {
/* access /proc/net/if_inet6 */ /* access /proc/net/if_inet6 */
read_proc_net_if_inet6 (cfg, ifr); read_proc_net_if_inet6 (cfg, ifr);
} }
#endif #endif
if ((cfg->flags & QSE_NWIFCFG_BCAST) && if ((cfg->flags & QSE_NWIFCFG_BCAST) &&
ioctl (s, SIOCGIFBRDADDR, ifr) >= 0) ioctl (s, SIOCGIFBRDADDR, ifr) >= 0)
{ {

View File

@ -22,120 +22,241 @@
#include <qse/cmn/chr.h> #include <qse/cmn/chr.h>
#include "mem.h" #include "mem.h"
int qse_strtoi (const qse_char_t* str)
/*---------------------------------------------------------------
* multi-byte string to number conversion
*---------------------------------------------------------------*/
int qse_mbstoi (const qse_mchar_t* mbs, int base)
{ {
int v; int v;
QSE_STRTONUM (v, str, QSE_NULL, 10); QSE_MBSTONUM (v, mbs, QSE_NULL, base);
return v; return v;
} }
long qse_strtol (const qse_char_t* str) long qse_mbstol (const qse_mchar_t* mbs, int base)
{ {
long v; long v;
QSE_STRTONUM (v, str, QSE_NULL, 10); QSE_MBSTONUM (v, mbs, QSE_NULL, base);
return v; return v;
} }
unsigned int qse_strtoui (const qse_char_t* str) unsigned int qse_mbstoui (const qse_mchar_t* mbs, int base)
{ {
unsigned int v; unsigned int v;
QSE_STRTONUM (v, str, QSE_NULL, 10); QSE_MBSTONUM (v, mbs, QSE_NULL, base);
return v; return v;
} }
unsigned long qse_strtoul (const qse_char_t* str) unsigned long qse_mbstoul (const qse_mchar_t* mbs, int base)
{ {
unsigned long v; unsigned long v;
QSE_STRTONUM (v, str, QSE_NULL, 10); QSE_MBSTONUM (v, mbs, QSE_NULL, base);
return v; return v;
} }
int qse_strxtoi (const qse_char_t* str, qse_size_t len) int qse_mbsxtoi (const qse_mchar_t* mbs, qse_size_t len, int base)
{ {
int v; int v;
QSE_STRXTONUM (v, str, len, QSE_NULL, 10); QSE_MBSXTONUM (v, mbs, len, QSE_NULL, base);
return v; return v;
} }
long qse_strxtol (const qse_char_t* str, qse_size_t len) long qse_mbsxtol (const qse_mchar_t* mbs, qse_size_t len, int base)
{ {
long v; long v;
QSE_STRXTONUM (v, str, len, QSE_NULL, 10); QSE_MBSXTONUM (v, mbs, len, QSE_NULL, base);
return v; return v;
} }
unsigned int qse_strxtoui (const qse_char_t* str, qse_size_t len) unsigned int qse_mbsxtoui (const qse_mchar_t* mbs, qse_size_t len, int base)
{ {
unsigned int v; unsigned int v;
QSE_STRXTONUM (v, str, len, QSE_NULL, 10); QSE_MBSXTONUM (v, mbs, len, QSE_NULL, base);
return v; return v;
} }
unsigned long qse_strxtoul (const qse_char_t* str, qse_size_t len) unsigned long qse_mbsxtoul (const qse_mchar_t* mbs, qse_size_t len, int base)
{ {
unsigned long v; unsigned long v;
QSE_STRXTONUM (v, str, len, QSE_NULL, 10); QSE_MBSXTONUM (v, mbs, len, QSE_NULL, base);
return v; return v;
} }
qse_int_t qse_strtoint (const qse_char_t* str) qse_int_t qse_mbstoint (const qse_mchar_t* mbs, int base)
{ {
qse_int_t v; qse_int_t v;
QSE_STRTONUM (v, str, QSE_NULL, 10); QSE_MBSTONUM (v, mbs, QSE_NULL, base);
return v; return v;
} }
qse_long_t qse_strtolong (const qse_char_t* str) qse_long_t qse_mbstolong (const qse_mchar_t* mbs, int base)
{ {
qse_long_t v; qse_long_t v;
QSE_STRTONUM (v, str, QSE_NULL, 10); QSE_MBSTONUM (v, mbs, QSE_NULL, base);
return v; return v;
} }
qse_uint_t qse_strtouint (const qse_char_t* str) qse_uint_t qse_mbstouint (const qse_mchar_t* mbs, int base)
{ {
qse_uint_t v; qse_uint_t v;
QSE_STRTONUM (v, str, QSE_NULL, 10); QSE_MBSTONUM (v, mbs, QSE_NULL, base);
return v; return v;
} }
qse_ulong_t qse_strtoulong (const qse_char_t* str) qse_ulong_t qse_mbstoulong (const qse_mchar_t* mbs, int base)
{ {
qse_ulong_t v; qse_ulong_t v;
QSE_STRTONUM (v, str, QSE_NULL, 10); QSE_MBSTONUM (v, mbs, QSE_NULL, base);
return v; return v;
} }
qse_int_t qse_strxtoint (const qse_char_t* str, qse_size_t len) qse_int_t qse_mbsxtoint (const qse_mchar_t* mbs, qse_size_t len, int base)
{ {
qse_int_t v; qse_int_t v;
QSE_STRXTONUM (v, str, len, QSE_NULL, 10); QSE_MBSXTONUM (v, mbs, len, QSE_NULL, base);
return v; return v;
} }
qse_long_t qse_strxtolong (const qse_char_t* str, qse_size_t len) qse_long_t qse_mbsxtolong (const qse_mchar_t* mbs, qse_size_t len, int base)
{ {
qse_long_t v; qse_long_t v;
QSE_STRXTONUM (v, str, len, QSE_NULL, 10); QSE_MBSXTONUM (v, mbs, len, QSE_NULL, base);
return v; return v;
} }
qse_uint_t qse_strxtouint (const qse_char_t* str, qse_size_t len) qse_uint_t qse_mbsxtouint (const qse_mchar_t* mbs, qse_size_t len, int base)
{ {
qse_uint_t v; qse_uint_t v;
QSE_STRXTONUM (v, str, len, QSE_NULL, 10); QSE_MBSXTONUM (v, mbs, len, QSE_NULL, base);
return v; return v;
} }
qse_ulong_t qse_strxtoulong (const qse_char_t* str, qse_size_t len) qse_ulong_t qse_mbsxtoulong (const qse_mchar_t* mbs, qse_size_t len, int base)
{ {
qse_ulong_t v; qse_ulong_t v;
QSE_STRXTONUM (v, str, len, QSE_NULL, 10); QSE_MBSXTONUM (v, mbs, len, QSE_NULL, base);
return v; return v;
} }
/* case conversion */
/*---------------------------------------------------------------
* wide string to number conversion
*---------------------------------------------------------------*/
int qse_wcstoi (const qse_wchar_t* wcs, int base)
{
int v;
QSE_WCSTONUM (v, wcs, QSE_NULL, base);
return v;
}
long qse_wcstol (const qse_wchar_t* wcs, int base)
{
long v;
QSE_WCSTONUM (v, wcs, QSE_NULL, base);
return v;
}
unsigned int qse_wcstoui (const qse_wchar_t* wcs, int base)
{
unsigned int v;
QSE_WCSTONUM (v, wcs, QSE_NULL, base);
return v;
}
unsigned long qse_wcstoul (const qse_wchar_t* wcs, int base)
{
unsigned long v;
QSE_WCSTONUM (v, wcs, QSE_NULL, base);
return v;
}
int qse_wcsxtoi (const qse_wchar_t* wcs, qse_size_t len, int base)
{
int v;
QSE_WCSXTONUM (v, wcs, len, QSE_NULL, base);
return v;
}
long qse_wcsxtol (const qse_wchar_t* wcs, qse_size_t len, int base)
{
long v;
QSE_WCSXTONUM (v, wcs, len, QSE_NULL, base);
return v;
}
unsigned int qse_wcsxtoui (const qse_wchar_t* wcs, qse_size_t len, int base)
{
unsigned int v;
QSE_WCSXTONUM (v, wcs, len, QSE_NULL, base);
return v;
}
unsigned long qse_wcsxtoul (const qse_wchar_t* wcs, qse_size_t len, int base)
{
unsigned long v;
QSE_WCSXTONUM (v, wcs, len, QSE_NULL, base);
return v;
}
qse_int_t qse_wcstoint (const qse_wchar_t* wcs, int base)
{
qse_int_t v;
QSE_WCSTONUM (v, wcs, QSE_NULL, base);
return v;
}
qse_long_t qse_wcstolong (const qse_wchar_t* wcs, int base)
{
qse_long_t v;
QSE_WCSTONUM (v, wcs, QSE_NULL, base);
return v;
}
qse_uint_t qse_wcstouint (const qse_wchar_t* wcs, int base)
{
qse_uint_t v;
QSE_WCSTONUM (v, wcs, QSE_NULL, base);
return v;
}
qse_ulong_t qse_wcstoulong (const qse_wchar_t* wcs, int base)
{
qse_ulong_t v;
QSE_WCSTONUM (v, wcs, QSE_NULL, base);
return v;
}
qse_int_t qse_wcsxtoint (const qse_wchar_t* wcs, qse_size_t len, int base)
{
qse_int_t v;
QSE_WCSXTONUM (v, wcs, len, QSE_NULL, base);
return v;
}
qse_long_t qse_wcsxtolong (const qse_wchar_t* wcs, qse_size_t len, int base)
{
qse_long_t v;
QSE_WCSXTONUM (v, wcs, len, QSE_NULL, base);
return v;
}
qse_uint_t qse_wcsxtouint (const qse_wchar_t* wcs, qse_size_t len, int base)
{
qse_uint_t v;
QSE_WCSXTONUM (v, wcs, len, QSE_NULL, base);
return v;
}
qse_ulong_t qse_wcsxtoulong (const qse_wchar_t* wcs, qse_size_t len, int base)
{
qse_ulong_t v;
QSE_WCSXTONUM (v, wcs, len, QSE_NULL, base);
return v;
}
/*---------------------------------------------------------------
* case conversion
*---------------------------------------------------------------*/
qse_size_t qse_mbslwr (qse_mchar_t* str) qse_size_t qse_mbslwr (qse_mchar_t* str)
{ {
qse_mchar_t* p = str; qse_mchar_t* p = str;
@ -163,3 +284,76 @@ qse_size_t qse_wcsupr (qse_wchar_t* str)
for (p = str; *p != QSE_WT('\0'); p++) *p = QSE_TOWUPPER (*p); for (p = str; *p != QSE_WT('\0'); p++) *p = QSE_TOWUPPER (*p);
return p - str; return p - str;
} }
/*---------------------------------------------------------------
* Hexadecimal string conversion
*---------------------------------------------------------------*/
int qse_mbshextobin (const qse_mchar_t* hex, qse_size_t hexlen, qse_uint8_t* buf, qse_size_t buflen)
{
const qse_mchar_t* end = hex + hexlen;
qse_size_t bi = 0;
while (hex < end && bi < buflen)
{
int v;
if (*hex >= QSE_MT('0') && *hex <= QSE_MT('9')) v = *hex - QSE_MT('0');
else if (*hex >= QSE_MT('a') && *hex <= QSE_MT('f')) v = *hex - QSE_MT('a') + 10;
else if (*hex >= QSE_MT('A') && *hex <= QSE_MT('F')) v = *hex - QSE_MT('A') + 10;
else return -1;
buf[bi] = buf[bi] * 16 + v;
hex++;
if (hex >= end) return -1;
if (*hex >= QSE_MT('0') && *hex <= QSE_MT('9')) v = *hex - QSE_MT('0');
else if (*hex >= QSE_MT('a') && *hex <= QSE_MT('f')) v = *hex - QSE_MT('a') + 10;
else if (*hex >= QSE_MT('A') && *hex <= QSE_MT('F')) v = *hex - QSE_MT('A') + 10;
else return -1;
buf[bi] = buf[bi] * 16 + v;
hex++;
bi++;
}
return 0;
}
int qse_wcshextobin (const qse_wchar_t* hex, qse_size_t hexlen, qse_uint8_t* buf, qse_size_t buflen)
{
const qse_wchar_t* end = hex + hexlen;
qse_size_t bi = 0;
while (hex < end && bi < buflen)
{
int v;
if (*hex >= QSE_WT('0') && *hex <= QSE_WT('9')) v = *hex - QSE_WT('0');
else if (*hex >= QSE_WT('a') && *hex <= QSE_WT('f')) v = *hex - QSE_WT('a') + 10;
else if (*hex >= QSE_WT('A') && *hex <= QSE_WT('F')) v = *hex - QSE_WT('A') + 10;
else return -1;
buf[bi] = buf[bi] * 16 + v;
hex++;
if (hex >= end) return -1;
if (*hex >= QSE_WT('0') && *hex <= QSE_WT('9')) v = *hex - QSE_WT('0');
else if (*hex >= QSE_WT('a') && *hex <= QSE_WT('f')) v = *hex - QSE_WT('a') + 10;
else if (*hex >= QSE_WT('A') && *hex <= QSE_WT('F')) v = *hex - QSE_WT('A') + 10;
else return -1;
buf[bi] = buf[bi] * 16 + v;
hex++;
bi++;
}
return 0;
}

View File

@ -2,6 +2,7 @@
#include "awk00.h" #include "awk00.h"
#include <qse/cmn/mbwc.h> #include <qse/cmn/mbwc.h>
#include <qse/cmn/fmt.h>
#include <locale.h> #include <locale.h>
#if defined(_WIN32) #if defined(_WIN32)
@ -20,7 +21,8 @@ void init_awk_sample_locale (void)
} }
else else
{ {
sprintf (locale, ".%u", (unsigned int)codepage); qse_fmtuintmaxtombs (locale, QSE_COUNTOF(locale),
codepage, 10, -1, QSE_MT('\0'), QSE_MT("."));
setlocale (LC_ALL, locale); setlocale (LC_ALL, locale);
qse_setdflcmgrbyid (QSE_CMGR_SLMB); qse_setdflcmgrbyid (QSE_CMGR_SLMB);
} }

View File

@ -1,9 +1,10 @@
#include <qse/cmn/nwif.h> #include <qse/cmn/nwif.h>
#include <qse/cmn/mbwc.h> #include <qse/cmn/mbwc.h>
#include <qse/cmn/main.h> #include <qse/cmn/main.h>
#include <qse/cmn/stdio.h>
#include <qse/cmn/mem.h> #include <qse/cmn/mem.h>
#include <qse/cmn/str.h> #include <qse/cmn/str.h>
#include <qse/cmn/sio.h>
#include <qse/cmn/fmt.h>
#include <locale.h> #include <locale.h>
#if defined(_WIN32) #if defined(_WIN32)
@ -66,6 +67,8 @@ static int test_main (int argc, qse_char_t* argv[])
int qse_main (int argc, qse_achar_t* argv[]) int qse_main (int argc, qse_achar_t* argv[])
{ {
int ret;
#if defined(_WIN32) #if defined(_WIN32)
char locale[100]; char locale[100];
UINT codepage = GetConsoleOutputCP(); UINT codepage = GetConsoleOutputCP();
@ -76,7 +79,8 @@ int qse_main (int argc, qse_achar_t* argv[])
} }
else else
{ {
sprintf (locale, ".%u", (unsigned int)codepage); qse_fmtuintmaxtombs (locale, QSE_COUNTOF(locale),
codepage, 10, -1, QSE_MT('\0'), QSE_MT("."));
setlocale (LC_ALL, locale); setlocale (LC_ALL, locale);
qse_setdflcmgrbyid (QSE_CMGR_SLMB); qse_setdflcmgrbyid (QSE_CMGR_SLMB);
} }
@ -84,6 +88,10 @@ int qse_main (int argc, qse_achar_t* argv[])
setlocale (LC_ALL, ""); setlocale (LC_ALL, "");
qse_setdflcmgrbyid (QSE_CMGR_SLMB); qse_setdflcmgrbyid (QSE_CMGR_SLMB);
#endif #endif
return qse_runmain (argc, argv, test_main); qse_openstdsios ();
ret = qse_runmain (argc, argv, test_main);
qse_closestdsios ();
return ret;
} }

View File

@ -1,9 +1,10 @@
#include <qse/cmn/nwif.h> #include <qse/cmn/nwif.h>
#include <qse/cmn/mbwc.h> #include <qse/cmn/mbwc.h>
#include <qse/cmn/main.h> #include <qse/cmn/main.h>
#include <qse/cmn/stdio.h> #include <qse/cmn/sio.h>
#include <qse/cmn/mem.h> #include <qse/cmn/mem.h>
#include <qse/cmn/str.h> #include <qse/cmn/str.h>
#include <qse/cmn/fmt.h>
#include <locale.h> #include <locale.h>
#if defined(_WIN32) #if defined(_WIN32)
@ -78,6 +79,8 @@ static int test_main (int argc, qse_char_t* argv[])
int qse_main (int argc, qse_achar_t* argv[]) int qse_main (int argc, qse_achar_t* argv[])
{ {
int ret;
#if defined(_WIN32) #if defined(_WIN32)
char locale[100]; char locale[100];
UINT codepage = GetConsoleOutputCP(); UINT codepage = GetConsoleOutputCP();
@ -88,7 +91,8 @@ int qse_main (int argc, qse_achar_t* argv[])
} }
else else
{ {
sprintf (locale, ".%u", (unsigned int)codepage); qse_fmtuintmaxtombs (locale, QSE_COUNTOF(locale),
codepage, 10, -1, QSE_MT('\0'), QSE_MT("."));
setlocale (LC_ALL, locale); setlocale (LC_ALL, locale);
qse_setdflcmgrbyid (QSE_CMGR_SLMB); qse_setdflcmgrbyid (QSE_CMGR_SLMB);
} }
@ -96,6 +100,10 @@ int qse_main (int argc, qse_achar_t* argv[])
setlocale (LC_ALL, ""); setlocale (LC_ALL, "");
qse_setdflcmgrbyid (QSE_CMGR_SLMB); qse_setdflcmgrbyid (QSE_CMGR_SLMB);
#endif #endif
return qse_runmain (argc, argv, test_main); qse_openstdsios ();
ret = qse_runmain (argc, argv, test_main);
qse_closestdsios ();
return ret;
} }

View File

@ -2,6 +2,7 @@
#include "sed00.h" #include "sed00.h"
#include <qse/cmn/mbwc.h> #include <qse/cmn/mbwc.h>
#include <qse/cmn/fmt.h>
#include <locale.h> #include <locale.h>
#if defined(_WIN32) #if defined(_WIN32)
@ -20,7 +21,8 @@ void init_sed_sample_locale (void)
} }
else else
{ {
sprintf (locale, ".%u", (unsigned int)codepage); qse_fmtuintmaxtombs (locale, QSE_COUNTOF(locale),
codepage, 10, -1, QSE_MT('\0'), QSE_MT("."));
setlocale (LC_ALL, locale); setlocale (LC_ALL, locale);
qse_setdflcmgrbyid (QSE_CMGR_SLMB); qse_setdflcmgrbyid (QSE_CMGR_SLMB);
} }