exported hcl_conv_ucs_to_bcs_with_cmgr() and similar functions
enhanced the sample server program
This commit is contained in:
		| @ -345,12 +345,55 @@ HCL_EXPORT int hcl_concatoocstrtosbuf ( | ||||
| 	int                id | ||||
| ); | ||||
|  | ||||
| HCL_EXPORT hcl_cmgr_t* hcl_getutf8cmgr ( | ||||
| #if defined(HCL_OOCH_IS_UCH) | ||||
| #	define hcl_conv_oocs_to_bcs_with_cmgr(oocs,oocslen,bcs,bcslen,cmgr) hcl_conv_ucs_to_bcs_with_cmgr(oocs,oocslen,bcs,bcslen,cmgr) | ||||
| #	define hcl_conv_oocsn_to_bcsn_with_cmgr(oocs,oocslen,bcs,bcslen,cmgr) hcl_conv_ucsn_to_bcsn_with_cmgr(oocs,oocslen,bcs,bcslen,cmgr) | ||||
| #else | ||||
| #	define hcl_conv_oocs_to_ucs_with_cmgr(oocs,oocslen,ucs,ucslen,cmgr) hcl_conv_bcs_to_ucs_with_cmgr(oocs,oocslen,ucs,ucslen,cmgr,0) | ||||
| #	define hcl_conv_oocsn_to_ucsn_with_cmgr(oocs,oocslen,ucs,ucslen,cmgr) hcl_conv_bcsn_to_ucsn_with_cmgr(oocs,oocslen,ucs,ucslen,cmgr,0) | ||||
| #endif | ||||
|  | ||||
|  | ||||
| HCL_EXPORT int hcl_conv_bcs_to_ucs_with_cmgr ( | ||||
| 	const hcl_bch_t* bcs, | ||||
| 	hcl_oow_t*       bcslen, | ||||
| 	hcl_uch_t*       ucs, | ||||
| 	hcl_oow_t*       ucslen, | ||||
| 	hcl_cmgr_t*      cmgr, | ||||
| 	int              all | ||||
| ); | ||||
| 	 | ||||
| HCL_EXPORT int hcl_conv_bcsn_to_ucsn_with_cmgr ( | ||||
| 	const hcl_bch_t* bcs, | ||||
| 	hcl_oow_t*       bcslen, | ||||
| 	hcl_uch_t*       ucs, | ||||
| 	hcl_oow_t*       ucslen, | ||||
| 	hcl_cmgr_t*      cmgr, | ||||
| 	int              all | ||||
| ); | ||||
|  | ||||
| HCL_EXPORT int hcl_conv_ucs_to_bcs_with_cmgr ( | ||||
| 	const hcl_uch_t* ucs, | ||||
| 	hcl_oow_t*       ucslen, | ||||
| 	hcl_bch_t*       bcs, | ||||
| 	hcl_oow_t*       bcslen, | ||||
| 	hcl_cmgr_t*      cmgr | ||||
| );	 | ||||
|  | ||||
| HCL_EXPORT int hcl_conv_ucsn_to_bcsn_with_cmgr ( | ||||
| 	const hcl_uch_t* ucs, | ||||
| 	hcl_oow_t*       ucslen, | ||||
| 	hcl_bch_t*       bcs, | ||||
| 	hcl_oow_t*       bcslen, | ||||
| 	hcl_cmgr_t*      cmgr | ||||
| ); | ||||
|  | ||||
| HCL_EXPORT hcl_cmgr_t* hcl_get_utf8_cmgr ( | ||||
| 	void | ||||
| ); | ||||
|  | ||||
| /** | ||||
|  * The hcl_convutoutf8chars() function converts a unicode character string \a ucs  | ||||
|  * The hcl_conv_uchars_to_utf8() function converts a unicode character string \a ucs  | ||||
|  * to a UTF8 string and writes it into the buffer pointed to by \a bcs, but | ||||
|  * not more than \a bcslen bytes including the terminating null. | ||||
|  * | ||||
| @ -371,14 +414,14 @@ HCL_EXPORT hcl_cmgr_t* hcl_getutf8cmgr ( | ||||
|  *   hcl_bch_t bcs[10]; | ||||
|  *   hcl_oow_t ucslen = 5; | ||||
|  *   hcl_oow_t bcslen = HCL_COUNTOF(bcs); | ||||
|  *   n = hcl_convutoutf8chars (ucs, &ucslen, bcs, &bcslen); | ||||
|  *   n = hcl_conv_uchars_to_utf8 (ucs, &ucslen, bcs, &bcslen); | ||||
|  *   if (n <= -1) | ||||
|  *   { | ||||
|  *      // conversion error | ||||
|  *   } | ||||
|  * \endcode | ||||
|  */ | ||||
| HCL_EXPORT int hcl_convutoutf8chars ( | ||||
| HCL_EXPORT int hcl_conv_uchars_to_utf8 ( | ||||
| 	const hcl_uch_t*    ucs, | ||||
| 	hcl_oow_t*          ucslen, | ||||
| 	hcl_bch_t*          bcs, | ||||
| @ -386,7 +429,7 @@ HCL_EXPORT int hcl_convutoutf8chars ( | ||||
| ); | ||||
|  | ||||
| /** | ||||
|  * The hcl_convutf8touchars() function converts a UTF8 string to a uncide string. | ||||
|  * The hcl_conv_utf8_to_uchars() function converts a UTF8 string to a uncide string. | ||||
|  * | ||||
|  * It never returns -2 if \a ucs is #HCL_NULL. | ||||
|  * | ||||
| @ -396,7 +439,7 @@ HCL_EXPORT int hcl_convutoutf8chars ( | ||||
|  *  hcl_oow_t ucslen = HCL_COUNTOF(buf), n; | ||||
|  *  hcl_oow_t bcslen = 11; | ||||
|  *  int n; | ||||
|  *  n = hcl_convutf8touchars (bcs, &bcslen, ucs, &ucslen); | ||||
|  *  n = hcl_conv_utf8_to_uchars (bcs, &bcslen, ucs, &ucslen); | ||||
|  *  if (n <= -1) { invalid/incomplenete sequence or buffer to small } | ||||
|  * \endcode | ||||
|  *  | ||||
| @ -409,7 +452,7 @@ HCL_EXPORT int hcl_convutoutf8chars ( | ||||
|  *         -2 if the wide-character string buffer is too small. | ||||
|  *         -3 if \a bcs is not a complete sequence. | ||||
|  */ | ||||
| HCL_EXPORT int hcl_convutf8touchars ( | ||||
| HCL_EXPORT int hcl_conv_utf8_to_uchars ( | ||||
| 	const hcl_bch_t*   bcs, | ||||
| 	hcl_oow_t*         bcslen, | ||||
| 	hcl_uch_t*         ucs, | ||||
| @ -417,14 +460,14 @@ HCL_EXPORT int hcl_convutf8touchars ( | ||||
| ); | ||||
|  | ||||
|  | ||||
| HCL_EXPORT int hcl_convutoutf8cstr ( | ||||
| HCL_EXPORT int hcl_conv_ucstr_to_utf8 ( | ||||
| 	const hcl_uch_t*    ucs, | ||||
| 	hcl_oow_t*          ucslen, | ||||
| 	hcl_bch_t*          bcs, | ||||
| 	hcl_oow_t*          bcslen | ||||
| ); | ||||
|  | ||||
| HCL_EXPORT int hcl_convutf8toucstr ( | ||||
| HCL_EXPORT int hcl_conv_utf8_to_ucstr ( | ||||
| 	const hcl_bch_t*   bcs, | ||||
| 	hcl_oow_t*         bcslen, | ||||
| 	hcl_uch_t*         ucs, | ||||
|  | ||||
| @ -105,7 +105,7 @@ int hcl_init (hcl_t* hcl, hcl_mmgr_t* mmgr, hcl_oow_t heapsz, const hcl_vmprim_t | ||||
|  | ||||
| 	HCL_MEMSET (hcl, 0, HCL_SIZEOF(*hcl)); | ||||
| 	hcl->mmgr = mmgr; | ||||
| 	hcl->cmgr = hcl_getutf8cmgr(); | ||||
| 	hcl->cmgr = hcl_get_utf8_cmgr(); | ||||
| 	hcl->vmprim = *vmprim; | ||||
| 	if (!hcl->vmprim.alloc_heap) hcl->vmprim.alloc_heap = alloc_heap; | ||||
| 	if (!hcl->vmprim.free_heap) hcl->vmprim.free_heap = free_heap; | ||||
|  | ||||
| @ -2001,7 +2001,7 @@ HCL_EXPORT int hcl_convbtoucstr ( | ||||
|  * The hcl_convutobcstr() function converts a null-terminated wide string | ||||
|  * to a byte string. | ||||
|  */ | ||||
| int hcl_convutobcstr ( | ||||
| HCL_EXPORT int hcl_convutobcstr ( | ||||
| 	hcl_t*           hcl, | ||||
| 	const hcl_uch_t* ucs, | ||||
| 	hcl_oow_t*       ucslen, | ||||
| @ -2009,7 +2009,6 @@ int hcl_convutobcstr ( | ||||
| 	hcl_oow_t*       bcslen | ||||
| ); | ||||
|  | ||||
|  | ||||
| #if defined(HCL_OOCH_IS_UCH) | ||||
| #	define hcl_dupootobcharswithheadroom(hcl,hrb,oocs,oocslen,bcslen) hcl_duputobcharswithheadroom(hcl,hrb,oocs,oocslen,bcslen) | ||||
| #	define hcl_dupbtooocharswithheadroom(hcl,hrb,bcs,bcslen,oocslen) hcl_dupbtoucharswithheadroom(hcl,hrb,bcs,bcslen,oocslen) | ||||
|  | ||||
| @ -152,8 +152,6 @@ struct xtn_t | ||||
|  | ||||
| /* ========================================================================= */ | ||||
|  | ||||
| #define MB_1 (256UL*1024*1024) | ||||
|  | ||||
| static void* sys_alloc (hcl_mmgr_t* mmgr, hcl_oow_t size) | ||||
| { | ||||
| 	return malloc(size); | ||||
| @ -1892,14 +1890,11 @@ int main_server (int argc, char* argv[]); | ||||
|  | ||||
| int main (int argc, char* argv[]) | ||||
| { | ||||
| 	const char* slash; | ||||
| 	const char* prog; | ||||
|  | ||||
| 	prog = argv[0]; | ||||
| 	slash = strrchr(prog, '/'); | ||||
| 	if (slash) prog = slash + 1; | ||||
| 	const char* base; | ||||
|  | ||||
| 	if (strcmp(prog, "hcld") == 0) return main_server (argc, argv); | ||||
| 	base = get_base_name (argv[0]); | ||||
| 	if (strcmp(base, "hcld") == 0) return main_server (argc, argv); | ||||
|  | ||||
| 	return main_tty (argc, argv); | ||||
| } | ||||
|  | ||||
							
								
								
									
										1014
									
								
								hcl/lib/main2.c
									
									
									
									
									
								
							
							
						
						
									
										1014
									
								
								hcl/lib/main2.c
									
									
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @ -391,7 +391,7 @@ int hcl_copyoocstrtosbuf (hcl_t* hcl, const hcl_ooch_t* str, int id) | ||||
|  | ||||
| /* ----------------------------------------------------------------------- */ | ||||
|  | ||||
| static HCL_INLINE int bcsn_to_ucsn_with_cmgr ( | ||||
| HCL_INLINE int hcl_conv_bcsn_to_ucsn_with_cmgr ( | ||||
| 	const hcl_bch_t* bcs, hcl_oow_t* bcslen, | ||||
| 	hcl_uch_t* ucs, hcl_oow_t* ucslen, hcl_cmgr_t* cmgr, int all) | ||||
| { | ||||
| @ -512,7 +512,7 @@ static HCL_INLINE int bcsn_to_ucsn_with_cmgr ( | ||||
| 	return ret; | ||||
| } | ||||
|  | ||||
| static HCL_INLINE int bcs_to_ucs_with_cmgr ( | ||||
| HCL_INLINE int hcl_conv_bcs_to_ucs_with_cmgr ( | ||||
| 	const hcl_bch_t* bcs, hcl_oow_t* bcslen, | ||||
| 	hcl_uch_t* ucs, hcl_oow_t* ucslen, hcl_cmgr_t* cmgr, int all) | ||||
| { | ||||
| @ -523,7 +523,7 @@ static HCL_INLINE int bcs_to_ucs_with_cmgr ( | ||||
| 	for (bp = bcs; *bp != '\0'; bp++) /* nothing */ ; | ||||
|  | ||||
| 	mlen = bp - bcs; wlen = *ucslen; | ||||
| 	n = bcsn_to_ucsn_with_cmgr (bcs, &mlen, ucs, &wlen, cmgr, all); | ||||
| 	n = hcl_conv_bcsn_to_ucsn_with_cmgr (bcs, &mlen, ucs, &wlen, cmgr, all); | ||||
| 	if (ucs) | ||||
| 	{ | ||||
| 		/* null-terminate the target buffer if it has room for it. */ | ||||
| @ -535,7 +535,7 @@ static HCL_INLINE int bcs_to_ucs_with_cmgr ( | ||||
| 	return n; | ||||
| } | ||||
|  | ||||
| static HCL_INLINE int ucsn_to_bcsn_with_cmgr ( | ||||
| HCL_INLINE int hcl_conv_ucsn_to_bcsn_with_cmgr ( | ||||
| 	const hcl_uch_t* ucs, hcl_oow_t* ucslen, | ||||
| 	hcl_bch_t* bcs, hcl_oow_t* bcslen, hcl_cmgr_t* cmgr) | ||||
| { | ||||
| @ -605,7 +605,7 @@ static HCL_INLINE int ucsn_to_bcsn_with_cmgr ( | ||||
| } | ||||
|  | ||||
|  | ||||
| static int ucs_to_bcs_with_cmgr ( | ||||
| HCL_INLINE int hcl_conv_ucs_to_bcs_with_cmgr ( | ||||
| 	const hcl_uch_t* ucs, hcl_oow_t* ucslen, | ||||
| 	hcl_bch_t* bcs, hcl_oow_t* bcslen, hcl_cmgr_t* cmgr) | ||||
| { | ||||
| @ -694,33 +694,33 @@ static hcl_cmgr_t utf8_cmgr = | ||||
| 	hcl_uctoutf8 | ||||
| }; | ||||
|  | ||||
| hcl_cmgr_t* hcl_getutf8cmgr (void) | ||||
| hcl_cmgr_t* hcl_get_utf8_cmgr (void) | ||||
| { | ||||
| 	return &utf8_cmgr; | ||||
| } | ||||
|  | ||||
| int hcl_convutf8touchars (const hcl_bch_t* bcs, hcl_oow_t* bcslen, hcl_uch_t* ucs, hcl_oow_t* ucslen) | ||||
| int hcl_conv_utf8_to_uchars (const hcl_bch_t* bcs, hcl_oow_t* bcslen, hcl_uch_t* ucs, hcl_oow_t* ucslen) | ||||
| { | ||||
| 	/* the source is length bound */ | ||||
| 	return bcsn_to_ucsn_with_cmgr (bcs, bcslen, ucs, ucslen, &utf8_cmgr, 0); | ||||
| 	return hcl_conv_bcsn_to_ucsn_with_cmgr (bcs, bcslen, ucs, ucslen, &utf8_cmgr, 0); | ||||
| } | ||||
|  | ||||
| int hcl_convutoutf8chars (const hcl_uch_t* ucs, hcl_oow_t* ucslen, hcl_bch_t* bcs, hcl_oow_t* bcslen) | ||||
| int hcl_conv_uchars_to_utf8 (const hcl_uch_t* ucs, hcl_oow_t* ucslen, hcl_bch_t* bcs, hcl_oow_t* bcslen) | ||||
| { | ||||
| 	/* length bound */ | ||||
| 	return ucsn_to_bcsn_with_cmgr (ucs, ucslen, bcs, bcslen, &utf8_cmgr); | ||||
| 	return hcl_conv_ucsn_to_bcsn_with_cmgr (ucs, ucslen, bcs, bcslen, &utf8_cmgr); | ||||
| } | ||||
|  | ||||
| int hcl_convutf8toucstr (const hcl_bch_t* bcs, hcl_oow_t* bcslen, hcl_uch_t* ucs, hcl_oow_t* ucslen) | ||||
| int hcl_conv_utf8_to_ucstr (const hcl_bch_t* bcs, hcl_oow_t* bcslen, hcl_uch_t* ucs, hcl_oow_t* ucslen) | ||||
| { | ||||
| 	/* null-terminated. */ | ||||
| 	return bcs_to_ucs_with_cmgr (bcs, bcslen, ucs, ucslen, &utf8_cmgr, 0); | ||||
| 	return hcl_conv_bcs_to_ucs_with_cmgr (bcs, bcslen, ucs, ucslen, &utf8_cmgr, 0); | ||||
| } | ||||
|  | ||||
| int hcl_convutoutf8cstr (const hcl_uch_t* ucs, hcl_oow_t* ucslen, hcl_bch_t* bcs, hcl_oow_t* bcslen) | ||||
| int hcl_conv_ucstr_to_utf8 (const hcl_uch_t* ucs, hcl_oow_t* ucslen, hcl_bch_t* bcs, hcl_oow_t* bcslen) | ||||
| { | ||||
| 	/* null-terminated */ | ||||
| 	return ucs_to_bcs_with_cmgr (ucs, ucslen, bcs, bcslen, &utf8_cmgr); | ||||
| 	return hcl_conv_ucs_to_bcs_with_cmgr (ucs, ucslen, bcs, bcslen, &utf8_cmgr); | ||||
| } | ||||
|  | ||||
| /* ----------------------------------------------------------------------- */ | ||||
| @ -730,7 +730,7 @@ int hcl_convbtouchars (hcl_t* hcl, const hcl_bch_t* bcs, hcl_oow_t* bcslen, hcl_ | ||||
| 	/* length bound */ | ||||
| 	int n; | ||||
|  | ||||
| 	n = bcsn_to_ucsn_with_cmgr (bcs, bcslen, ucs, ucslen, hcl->cmgr, 0); | ||||
| 	n = hcl_conv_bcsn_to_ucsn_with_cmgr(bcs, bcslen, ucs, ucslen, hcl->cmgr, 0); | ||||
|  | ||||
| 	if (n <= -1) | ||||
| 	{ | ||||
| @ -746,7 +746,7 @@ int hcl_convutobchars (hcl_t* hcl, const hcl_uch_t* ucs, hcl_oow_t* ucslen, hcl_ | ||||
| 	/* length bound */ | ||||
| 	int n; | ||||
|  | ||||
| 	n = ucsn_to_bcsn_with_cmgr (ucs, ucslen, bcs, bcslen, hcl->cmgr); | ||||
| 	n = hcl_conv_ucsn_to_bcsn_with_cmgr(ucs, ucslen, bcs, bcslen, hcl->cmgr); | ||||
|  | ||||
| 	if (n <= -1) | ||||
| 	{ | ||||
| @ -761,7 +761,7 @@ int hcl_convbtoucstr (hcl_t* hcl, const hcl_bch_t* bcs, hcl_oow_t* bcslen, hcl_u | ||||
| 	/* null-terminated. */ | ||||
| 	int n; | ||||
|  | ||||
| 	n = bcs_to_ucs_with_cmgr (bcs, bcslen, ucs, ucslen, hcl->cmgr, 0); | ||||
| 	n = hcl_conv_bcs_to_ucs_with_cmgr(bcs, bcslen, ucs, ucslen, hcl->cmgr, 0); | ||||
|  | ||||
| 	if (n <= -1) | ||||
| 	{ | ||||
| @ -776,7 +776,7 @@ int hcl_convutobcstr (hcl_t* hcl, const hcl_uch_t* ucs, hcl_oow_t* ucslen, hcl_b | ||||
| 	/* null-terminated */ | ||||
| 	int n; | ||||
|  | ||||
| 	n = ucs_to_bcs_with_cmgr (ucs, ucslen, bcs, bcslen, hcl->cmgr); | ||||
| 	n = hcl_conv_ucs_to_bcs_with_cmgr(ucs, ucslen, bcs, bcslen, hcl->cmgr); | ||||
|  | ||||
| 	if (n <= -1) | ||||
| 	{ | ||||
|  | ||||
		Reference in New Issue
	
	Block a user