added qse_mbstoipad4()/qse_wcstoipad4()/qse_ipad4tombs()/qse_ipad4towcs()

This commit is contained in:
hyung-hwan 2012-02-26 02:23:47 +00:00
parent ada60acf67
commit ee8609daf4
7 changed files with 273 additions and 125 deletions

View File

@ -65,31 +65,43 @@ int qse_mbstoipad4 (
int qse_mbsntoipad4 ( int qse_mbsntoipad4 (
const qse_mchar_t* mbs, const qse_mchar_t* mbs,
qse_size_t len qse_size_t len,
qse_ipad4_t* ipad
); );
int qse_ipad4tombs ( int qse_wcstoipad4 (
const qse_wchar_t* wcs,
qse_ipad4_t* ipad
);
int qse_wcsntoipad4 (
const qse_wchar_t* wcs,
qse_size_t len,
qse_ipad4_t* ipad
);
qse_size_t qse_ipad4tombs (
const qse_ipad4_t* ipad, const qse_ipad4_t* ipad,
qse_mchar_t* mbs, qse_mchar_t* mbs,
qse_size_t len qse_size_t len
); );
int qse_wcstoipad4 ( qse_size_t qse_ipad4towcs (
const qse_wchar_t* wcs,
qse_ipad4_t* ipad
);
int qse_wcstoipad4 (
const qse_wchar_t* wcs,
qse_ipad4_t* ipad
);
int qse_ipad4towcs (
const qse_ipad4_t* ipad, const qse_ipad4_t* ipad,
qse_wchar_t* wcs, qse_wchar_t* wcs,
qse_size_t len qse_size_t len
); );
#if defined(QSE_CHAR_IS_MCHAR)
# define qse_strtoipad4(ptr,ipad) qse_mbstoipad4(ptr,ipad)
# define qse_strntoipad4(ptr,len,ipad) qse_mbsntoipad4(ptr,len,ipad)
# define qse_ipad4tostr(ipad,ptr,len) qse_ipad4tombs(ipad,ptr,len)
#else
# define qse_strtoipad4(ptr,ipad) qse_wcstoipad4(ptr,ipad)
# define qse_strntoipad4(ptr,len,ipad) qse_wcsntoipad4(ptr,len,ipad)
# define qse_ipad4tostr(ipad,ptr,len) qse_ipad4towcs(ipad,ptr,len)
#endif
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -743,6 +743,14 @@ struct qse_cmgr_t
typedef struct qse_cmgr_t qse_cmgr_t; typedef struct qse_cmgr_t qse_cmgr_t;
#if 0
struct qse_tmgr_t
{
int gettimeoffset
};
typedef struct qse_tmgr_t qse_tmgr_t;
#endif
/** /**
* The #qse_foff_t type defines an integer that can represent a file offset. * The #qse_foff_t type defines an integer that can represent a file offset.
* Depending on your system, it's defined to one of #qse_int64_t, #qse_int32_t, * Depending on your system, it's defined to one of #qse_int64_t, #qse_int32_t,

View File

@ -67,52 +67,15 @@ const qse_ipad6_t qse_ipad6_loopback =
}; };
#endif #endif
int qse_strtoipad4 (const qse_char_t* str, qse_ipad4_t* ipad) static int str_to_ipad4 (int mbs, const void* str, qse_size_t len, qse_ipad4_t* ipad)
{ {
qse_char_t c; const void* end;
int dots = 0, digits = 0; int dots = 0, digits = 0;
qse_uint32_t acc = 0, addr = 0; qse_uint32_t acc = 0, addr = 0;
qse_wchar_t c;
do end = (mbs? (const void*)((const qse_mchar_t*)str + len):
{ (const void*)((const qse_wchar_t*)str + len));
c = *str;
if (c == QSE_T('\0'))
{
if (dots < 3 || digits == 0) return -1;
addr = (addr << 8) | acc;
break;
}
else if (c >= QSE_T('0') && c <= QSE_T('9'))
{
if (digits > 0 && acc == 0) return -1;
acc = acc * 10 + (c - QSE_T('0'));
if (acc > 255) return -1;
digits++;
}
else if (c == QSE_T('.'))
{
if (dots >= 3 || digits == 0) return -1;
addr = (addr << 8) | acc;
dots++; acc = 0; digits = 0;
}
else return -1;
str++;
}
while (1);
if (ipad != QSE_NULL) ipad->value = qse_hton32(addr);
return 0;
}
int qse_strxtoipad4 (
const qse_char_t* str, qse_size_t len, qse_ipad4_t* ipad)
{
qse_char_t c;
int dots = 0, digits = 0;
qse_uint32_t acc = 0, addr = 0;
const qse_char_t* end = str + len;
do do
{ {
@ -123,24 +86,31 @@ int qse_strxtoipad4 (
break; break;
} }
c = *str; if (mbs)
{
c = *(const qse_mchar_t*)str;
str = (const qse_mchar_t*)str + 1;
}
else
{
c = *(const qse_wchar_t*)str;
str = (const qse_wchar_t*)str + 1;
}
if (c >= QSE_T('0') && c <= QSE_T('9')) if (c >= QSE_WT('0') && c <= QSE_WT('9'))
{ {
if (digits > 0 && acc == 0) return -1; if (digits > 0 && acc == 0) return -1;
acc = acc * 10 + (c - QSE_T('0')); acc = acc * 10 + (c - QSE_T('0'));
if (acc > 255) return -1; if (acc > 255) return -1;
digits++; digits++;
} }
else if (c == QSE_T('.')) else if (c == QSE_WT('.'))
{ {
if (dots >= 3 || digits == 0) return -1; if (dots >= 3 || digits == 0) return -1;
addr = (addr << 8) | acc; addr = (addr << 8) | acc;
dots++; acc = 0; digits = 0; dots++; acc = 0; digits = 0;
} }
else return -1; else return -1;
str++;
} }
while (1); while (1);
@ -148,20 +118,40 @@ int qse_strxtoipad4 (
return 0; return 0;
} }
#define __BTOA(b,p,end) \ int qse_mbstoipad4 (const qse_mchar_t* str, qse_ipad4_t* ipad)
{
return str_to_ipad4 (1, str, qse_mbslen(str), ipad);
}
int qse_wcstoipad4 (const qse_wchar_t* str, qse_ipad4_t* ipad)
{
return str_to_ipad4 (0, str, qse_wcslen(str), ipad);
}
int qse_mbsntoipad4 (const qse_mchar_t* str, qse_size_t len, qse_ipad4_t* ipad)
{
return str_to_ipad4 (1, str, len, ipad);
}
int qse_wcsntoipad4 (const qse_wchar_t* str, qse_size_t len, qse_ipad4_t* ipad)
{
return str_to_ipad4 (0, str, len, ipad);
}
#define __BTOA(type_t,b,p,end) \
do { \ do { \
qse_char_t* sp = p; \ type_t* sp = p; \
do { \ do { \
if (p >= end) { \ if (p >= end) { \
if (p == sp) break; \ if (p == sp) break; \
if (p - sp > 1) p[-2] = p[-1]; \ if (p - sp > 1) p[-2] = p[-1]; \
p[-1] = (b % 10) + QSE_T('0'); \ p[-1] = (b % 10) + '0'; \
} \ } \
else *p++ = (b % 10) + QSE_T('0'); \ else *p++ = (b % 10) + '0'; \
b /= 10; \ b /= 10; \
} while (b > 0); \ } while (b > 0); \
if (p - sp > 1) { \ if (p - sp > 1) { \
qse_char_t t = sp[0]; \ type_t t = sp[0]; \
sp[0] = p[-1]; \ sp[0] = p[-1]; \
p[-1] = t; \ p[-1] = t; \
} \ } \
@ -170,14 +160,14 @@ int qse_strxtoipad4 (
#define __ADDDOT(p, end) \ #define __ADDDOT(p, end) \
do { \ do { \
if (p >= end) break; \ if (p >= end) break; \
*p++ = QSE_T('.'); \ *p++ = '.'; \
} while (0) } while (0)
qse_size_t qse_ipad4tostrx ( qse_size_t qse_ipad4tombs (
const qse_ipad4_t* ipad, qse_char_t* buf, qse_size_t size) const qse_ipad4_t* ipad, qse_mchar_t* buf, qse_size_t size)
{ {
qse_byte_t b; qse_byte_t b;
qse_char_t* p, * end; qse_mchar_t* p, * end;
qse_uint32_t ip; qse_uint32_t ip;
if (size <= 0) return 0; if (size <= 0) return 0;
@ -188,23 +178,56 @@ qse_size_t qse_ipad4tostrx (
end = buf + size - 1; end = buf + size - 1;
#if defined(QSE_ENDIAN_BIG) #if defined(QSE_ENDIAN_BIG)
b = (ip >> 24) & 0xFF; __BTOA (b, p, end); __ADDDOT (p, end); b = (ip >> 24) & 0xFF; __BTOA (qse_mchar_t, b, p, end); __ADDDOT (p, end);
b = (ip >> 16) & 0xFF; __BTOA (b, p, end); __ADDDOT (p, end); b = (ip >> 16) & 0xFF; __BTOA (qse_mchar_t, b, p, end); __ADDDOT (p, end);
b = (ip >> 8) & 0xFF; __BTOA (b, p, end); __ADDDOT (p, end); b = (ip >> 8) & 0xFF; __BTOA (qse_mchar_t, b, p, end); __ADDDOT (p, end);
b = (ip >> 0) & 0xFF; __BTOA (b, p, end); b = (ip >> 0) & 0xFF; __BTOA (qse_mchar_t, b, p, end);
#elif defined(QSE_ENDIAN_LITTLE) #elif defined(QSE_ENDIAN_LITTLE)
b = (ip >> 0) & 0xFF; __BTOA (b, p, end); __ADDDOT (p, end); b = (ip >> 0) & 0xFF; __BTOA (qse_mchar_t, b, p, end); __ADDDOT (p, end);
b = (ip >> 8) & 0xFF; __BTOA (b, p, end); __ADDDOT (p, end); b = (ip >> 8) & 0xFF; __BTOA (qse_mchar_t, b, p, end); __ADDDOT (p, end);
b = (ip >> 16) & 0xFF; __BTOA (b, p, end); __ADDDOT (p, end); b = (ip >> 16) & 0xFF; __BTOA (qse_mchar_t, b, p, end); __ADDDOT (p, end);
b = (ip >> 24) & 0xFF; __BTOA (b, p, end); b = (ip >> 24) & 0xFF; __BTOA (qse_mchar_t, b, p, end);
#else #else
# error Unknown Endian # error Unknown Endian
#endif #endif
*p = QSE_T('\0'); *p = QSE_MT('\0');
return p - buf; return p - buf;
} }
qse_size_t qse_ipad4towcs (
const qse_ipad4_t* ipad, qse_wchar_t* buf, qse_size_t size)
{
qse_byte_t b;
qse_wchar_t* p, * end;
qse_uint32_t ip;
if (size <= 0) return 0;
ip = ipad->value;
p = buf;
end = buf + size - 1;
#if defined(QSE_ENDIAN_BIG)
b = (ip >> 24) & 0xFF; __BTOA (qse_wchar_t, b, p, end); __ADDDOT (p, end);
b = (ip >> 16) & 0xFF; __BTOA (qse_wchar_t, b, p, end); __ADDDOT (p, end);
b = (ip >> 8) & 0xFF; __BTOA (qse_wchar_t, b, p, end); __ADDDOT (p, end);
b = (ip >> 0) & 0xFF; __BTOA (qse_wchar_t, b, p, end);
#elif defined(QSE_ENDIAN_LITTLE)
b = (ip >> 0) & 0xFF; __BTOA (qse_wchar_t, b, p, end); __ADDDOT (p, end);
b = (ip >> 8) & 0xFF; __BTOA (qse_wchar_t, b, p, end); __ADDDOT (p, end);
b = (ip >> 16) & 0xFF; __BTOA (qse_wchar_t, b, p, end); __ADDDOT (p, end);
b = (ip >> 24) & 0xFF; __BTOA (qse_wchar_t, b, p, end);
#else
# error Unknown Endian
#endif
*p = QSE_WT('\0');
return p - buf;
}
#if 0
int qse_strtoipad6 (const qse_char_t* src, qse_ipad6_t* ipad) int qse_strtoipad6 (const qse_char_t* src, qse_ipad6_t* ipad)
{ {
#if 0 #if 0
@ -549,28 +572,4 @@ qse_size_t qse_ipad6tostrx (
#undef IP6ADDR_NWORDS #undef IP6ADDR_NWORDS
} }
#if 0
int qse_strtoipad (const qse_char_t* str, qse_ipad_t* ipad)
{
if (qse_strtoipad4 (str, &ipad->u.ip4) <= -1)
{
if (qse_strtoipad6 (str, &ipad->u.ip6) <= -1) return -1;
ipad->type = QSE_IPAD_IP6;
}
else ipad->type = QSE_IPAD_IP4;
return 0;
}
int qse_strxtoipad (const qse_char_t* str, qse_size_t len, qse_ipad_t* ipad)
{
if (qse_strxtoipad4 (str, len, &ipad->u.ip4) <= -1)
{
if (qse_strxtoipad6 (str, len, &ipad->u.ip6) <= -1) return -1;
ipad->type = QSE_IPAD_IP6;
}
else ipad->type = QSE_IPAD_IP4;
return 0;
}
#endif #endif

View File

@ -17,6 +17,7 @@ bin_PROGRAMS = \
fmt02 \ fmt02 \
fs01 \ fs01 \
htb \ htb \
ipad01 \
lda \ lda \
main01 \ main01 \
main02 \ main02 \
@ -55,6 +56,7 @@ fmt01_SOURCES = fmt01.c
fmt02_SOURCES = fmt02.c fmt02_SOURCES = fmt02.c
fs01_SOURCES = fs01.c fs01_SOURCES = fs01.c
htb_SOURCES = htb.c htb_SOURCES = htb.c
ipad01_SOURCES = ipad01.c
lda_SOURCES = lda.c lda_SOURCES = lda.c
main01_SOURCES = main01.c main01_SOURCES = main01.c
main02_SOURCES = main02.c main02_SOURCES = main02.c

View File

@ -36,12 +36,12 @@ build_triplet = @build@
host_triplet = @host@ host_triplet = @host@
bin_PROGRAMS = chr01$(EXEEXT) env$(EXEEXT) dll$(EXEEXT) fio01$(EXEEXT) \ bin_PROGRAMS = chr01$(EXEEXT) env$(EXEEXT) dll$(EXEEXT) fio01$(EXEEXT) \
fio02$(EXEEXT) fma$(EXEEXT) fmt01$(EXEEXT) fmt02$(EXEEXT) \ fio02$(EXEEXT) fma$(EXEEXT) fmt01$(EXEEXT) fmt02$(EXEEXT) \
fs01$(EXEEXT) htb$(EXEEXT) lda$(EXEEXT) main01$(EXEEXT) \ fs01$(EXEEXT) htb$(EXEEXT) ipad01$(EXEEXT) lda$(EXEEXT) \
main02$(EXEEXT) mbwc01$(EXEEXT) mbwc02$(EXEEXT) oht$(EXEEXT) \ main01$(EXEEXT) main02$(EXEEXT) mbwc01$(EXEEXT) \
path01$(EXEEXT) pio$(EXEEXT) pma$(EXEEXT) rex01$(EXEEXT) \ mbwc02$(EXEEXT) oht$(EXEEXT) path01$(EXEEXT) pio$(EXEEXT) \
rbt$(EXEEXT) sio01$(EXEEXT) sio02$(EXEEXT) sio03$(EXEEXT) \ pma$(EXEEXT) rex01$(EXEEXT) rbt$(EXEEXT) sio01$(EXEEXT) \
sll$(EXEEXT) slmb01$(EXEEXT) str01$(EXEEXT) time$(EXEEXT) \ sio02$(EXEEXT) sio03$(EXEEXT) sll$(EXEEXT) slmb01$(EXEEXT) \
tre01$(EXEEXT) xma$(EXEEXT) str01$(EXEEXT) time$(EXEEXT) tre01$(EXEEXT) xma$(EXEEXT)
@WIN32_TRUE@am__append_1 = $(UNICOWS_LIBS) @WIN32_TRUE@am__append_1 = $(UNICOWS_LIBS)
subdir = samples/cmn subdir = samples/cmn
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
@ -101,6 +101,10 @@ am_htb_OBJECTS = htb.$(OBJEXT)
htb_OBJECTS = $(am_htb_OBJECTS) htb_OBJECTS = $(am_htb_OBJECTS)
htb_LDADD = $(LDADD) htb_LDADD = $(LDADD)
htb_DEPENDENCIES = $(am__DEPENDENCIES_2) htb_DEPENDENCIES = $(am__DEPENDENCIES_2)
am_ipad01_OBJECTS = ipad01.$(OBJEXT)
ipad01_OBJECTS = $(am_ipad01_OBJECTS)
ipad01_LDADD = $(LDADD)
ipad01_DEPENDENCIES = $(am__DEPENDENCIES_2)
am_lda_OBJECTS = lda.$(OBJEXT) am_lda_OBJECTS = lda.$(OBJEXT)
lda_OBJECTS = $(am_lda_OBJECTS) lda_OBJECTS = $(am_lda_OBJECTS)
lda_LDADD = $(LDADD) lda_LDADD = $(LDADD)
@ -197,23 +201,23 @@ LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
SOURCES = $(chr01_SOURCES) $(dll_SOURCES) $(env_SOURCES) \ SOURCES = $(chr01_SOURCES) $(dll_SOURCES) $(env_SOURCES) \
$(fio01_SOURCES) $(fio02_SOURCES) $(fma_SOURCES) \ $(fio01_SOURCES) $(fio02_SOURCES) $(fma_SOURCES) \
$(fmt01_SOURCES) $(fmt02_SOURCES) $(fs01_SOURCES) \ $(fmt01_SOURCES) $(fmt02_SOURCES) $(fs01_SOURCES) \
$(htb_SOURCES) $(lda_SOURCES) $(main01_SOURCES) \ $(htb_SOURCES) $(ipad01_SOURCES) $(lda_SOURCES) \
$(main02_SOURCES) $(mbwc01_SOURCES) $(mbwc02_SOURCES) \ $(main01_SOURCES) $(main02_SOURCES) $(mbwc01_SOURCES) \
$(oht_SOURCES) $(path01_SOURCES) $(pio_SOURCES) $(pma_SOURCES) \ $(mbwc02_SOURCES) $(oht_SOURCES) $(path01_SOURCES) \
$(rbt_SOURCES) $(rex01_SOURCES) $(sio01_SOURCES) \ $(pio_SOURCES) $(pma_SOURCES) $(rbt_SOURCES) $(rex01_SOURCES) \
$(sio02_SOURCES) $(sio03_SOURCES) $(sll_SOURCES) \ $(sio01_SOURCES) $(sio02_SOURCES) $(sio03_SOURCES) \
$(slmb01_SOURCES) $(str01_SOURCES) $(time_SOURCES) \ $(sll_SOURCES) $(slmb01_SOURCES) $(str01_SOURCES) \
$(tre01_SOURCES) $(xma_SOURCES) $(time_SOURCES) $(tre01_SOURCES) $(xma_SOURCES)
DIST_SOURCES = $(chr01_SOURCES) $(dll_SOURCES) $(env_SOURCES) \ DIST_SOURCES = $(chr01_SOURCES) $(dll_SOURCES) $(env_SOURCES) \
$(fio01_SOURCES) $(fio02_SOURCES) $(fma_SOURCES) \ $(fio01_SOURCES) $(fio02_SOURCES) $(fma_SOURCES) \
$(fmt01_SOURCES) $(fmt02_SOURCES) $(fs01_SOURCES) \ $(fmt01_SOURCES) $(fmt02_SOURCES) $(fs01_SOURCES) \
$(htb_SOURCES) $(lda_SOURCES) $(main01_SOURCES) \ $(htb_SOURCES) $(ipad01_SOURCES) $(lda_SOURCES) \
$(main02_SOURCES) $(mbwc01_SOURCES) $(mbwc02_SOURCES) \ $(main01_SOURCES) $(main02_SOURCES) $(mbwc01_SOURCES) \
$(oht_SOURCES) $(path01_SOURCES) $(pio_SOURCES) $(pma_SOURCES) \ $(mbwc02_SOURCES) $(oht_SOURCES) $(path01_SOURCES) \
$(rbt_SOURCES) $(rex01_SOURCES) $(sio01_SOURCES) \ $(pio_SOURCES) $(pma_SOURCES) $(rbt_SOURCES) $(rex01_SOURCES) \
$(sio02_SOURCES) $(sio03_SOURCES) $(sll_SOURCES) \ $(sio01_SOURCES) $(sio02_SOURCES) $(sio03_SOURCES) \
$(slmb01_SOURCES) $(str01_SOURCES) $(time_SOURCES) \ $(sll_SOURCES) $(slmb01_SOURCES) $(str01_SOURCES) \
$(tre01_SOURCES) $(xma_SOURCES) $(time_SOURCES) $(tre01_SOURCES) $(xma_SOURCES)
ETAGS = etags ETAGS = etags
CTAGS = ctags CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
@ -380,6 +384,7 @@ fmt01_SOURCES = fmt01.c
fmt02_SOURCES = fmt02.c fmt02_SOURCES = fmt02.c
fs01_SOURCES = fs01.c fs01_SOURCES = fs01.c
htb_SOURCES = htb.c htb_SOURCES = htb.c
ipad01_SOURCES = ipad01.c
lda_SOURCES = lda.c lda_SOURCES = lda.c
main01_SOURCES = main01.c main01_SOURCES = main01.c
main02_SOURCES = main02.c main02_SOURCES = main02.c
@ -507,6 +512,9 @@ fs01$(EXEEXT): $(fs01_OBJECTS) $(fs01_DEPENDENCIES)
htb$(EXEEXT): $(htb_OBJECTS) $(htb_DEPENDENCIES) htb$(EXEEXT): $(htb_OBJECTS) $(htb_DEPENDENCIES)
@rm -f htb$(EXEEXT) @rm -f htb$(EXEEXT)
$(LINK) $(htb_OBJECTS) $(htb_LDADD) $(LIBS) $(LINK) $(htb_OBJECTS) $(htb_LDADD) $(LIBS)
ipad01$(EXEEXT): $(ipad01_OBJECTS) $(ipad01_DEPENDENCIES)
@rm -f ipad01$(EXEEXT)
$(LINK) $(ipad01_OBJECTS) $(ipad01_LDADD) $(LIBS)
lda$(EXEEXT): $(lda_OBJECTS) $(lda_DEPENDENCIES) lda$(EXEEXT): $(lda_OBJECTS) $(lda_DEPENDENCIES)
@rm -f lda$(EXEEXT) @rm -f lda$(EXEEXT)
$(LINK) $(lda_OBJECTS) $(lda_LDADD) $(LIBS) $(LINK) $(lda_OBJECTS) $(lda_LDADD) $(LIBS)
@ -584,6 +592,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fmt02.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fmt02.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fs01.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fs01.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/htb.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/htb.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ipad01.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lda.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lda.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main01.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main01.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main02.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main02.Po@am__quote@

View File

@ -16,7 +16,7 @@ static void list (qse_fs_t* fs, const qse_char_t* name)
if (qse_fs_chdir (fs, name) <= -1) if (qse_fs_chdir (fs, name) <= -1)
{ {
qse_fprintf (QSE_STDERR, QSE_T("Error: Cannot change directory to %s - %s\n"), name, qse_fs_geterrmsg(fs)); qse_fprintf (QSE_STDERR, QSE_T("Error: Cannot change directory to %s - code %d\n"), name, (int)qse_fs_geterrnum(fs));
return; return;
} }
@ -33,7 +33,7 @@ static void list (qse_fs_t* fs, const qse_char_t* name)
{ {
qse_fs_errnum_t e = qse_fs_geterrnum(fs); qse_fs_errnum_t e = qse_fs_geterrnum(fs);
if (e != QSE_FS_ENOERR) if (e != QSE_FS_ENOERR)
qse_fprintf (QSE_STDERR, QSE_T("Error: Read error - %s\n"), qse_fs_geterrmsg(fs)); qse_fprintf (QSE_STDERR, QSE_T("Error: Read error - code %d\n"), (int)qse_fs_geterrnum(fs));
break; break;
} }

118
qse/samples/cmn/ipad01.c Normal file
View File

@ -0,0 +1,118 @@
#include <qse/cmn/ipad.h>
#include <qse/cmn/main.h>
#include <qse/cmn/mbwc.h>
#include <qse/cmn/stdio.h>
#include <locale.h>
#if defined(_WIN32)
# include <windows.h>
#endif
static int test_main (int argc, qse_char_t* argv[], qse_char_t* envp[])
{
qse_ipad4_t ipad4;
qse_char_t buf[32];
qse_mchar_t mbsbuf[32];
qse_wchar_t wcsbuf[32];
qse_size_t i;
static qse_char_t* ipstr[] =
{
QSE_T("192.168.1.1"),
QSE_T("255.255.255.255"),
QSE_T("4.3.0.0"),
QSE_T("4.3.0.0X"),
QSE_T("65.1234.11.34"),
QSE_T("65.123.11.34"),
QSE_T("1.1.1.1")
};
static qse_mchar_t* ipstr_mbs[] =
{
QSE_MT("192.168.1.1"),
QSE_MT("255.255.255.255"),
QSE_MT("4.3.0.0"),
QSE_MT("4.3.0.0X"),
QSE_MT("65.1234.11.34"),
QSE_MT("65.123.11.34"),
QSE_MT("1.1.1.1")
};
static qse_wchar_t* ipstr_wcs[] =
{
QSE_WT("192.168.1.1"),
QSE_WT("255.255.255.255"),
QSE_WT("4.3.0.0"),
QSE_WT("4.3.0.0X"),
QSE_WT("65.1234.11.34"),
QSE_WT("65.123.11.34"),
QSE_WT("1.1.1.1")
};
for (i = 0; i < QSE_COUNTOF(ipstr); i++)
{
if (qse_strtoipad4 (ipstr[i], &ipad4) <= -1)
{
qse_printf (QSE_T("Failed to convert %s\n"), ipstr[i]);
}
else
{
qse_ipad4tostr (&ipad4, buf, QSE_COUNTOF(buf));
qse_printf (QSE_T("Converted [%s] to [%s]\n"), ipstr[i], buf);
}
}
qse_printf (QSE_T("-------------------\n"));
for (i = 0; i < QSE_COUNTOF(ipstr_mbs); i++)
{
if (qse_mbstoipad4 (ipstr_mbs[i], &ipad4) <= -1)
{
qse_printf (QSE_T("Failed to convert %hs\n"), ipstr_mbs[i]);
}
else
{
qse_ipad4tombs (&ipad4, mbsbuf, QSE_COUNTOF(mbsbuf));
qse_printf (QSE_T("Converted [%hs] to [%hs]\n"), ipstr[i], mbsbuf);
}
}
qse_printf (QSE_T("-------------------\n"));
for (i = 0; i < QSE_COUNTOF(ipstr_wcs); i++)
{
if (qse_wcstoipad4 (ipstr_wcs[i], &ipad4) <= -1)
{
qse_printf (QSE_T("Failed to convert %ls\n"), ipstr_wcs[i]);
}
else
{
qse_ipad4towcs (&ipad4, wcsbuf, QSE_COUNTOF(wcsbuf));
qse_printf (QSE_T("Converted [%ls] to [%ls]\n"), ipstr[i], wcsbuf);
}
}
return 0;
}
int qse_main (int argc, qse_achar_t* argv[], qse_achar_t* envp[])
{
#if defined(_WIN32)
char locale[100];
UINT codepage = GetConsoleOutputCP();
if (codepage == CP_UTF8)
{
/*SetConsoleOUtputCP (CP_UTF8);*/
qse_setdflcmgr (qse_utf8cmgr);
}
else
{
sprintf (locale, ".%u", (unsigned int)codepage);
setlocale (LC_ALL, locale);
qse_setdflcmgr (qse_slmbcmgr);
}
#else
setlocale (LC_ALL, "");
qse_setdflcmgr (qse_slmbcmgr);
#endif
return qse_runmainwithenv (argc, argv, envp, test_main);
}