| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * $Id$ | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2018-02-07 14:13:13 +00:00
										 |  |  |     Copyright (c) 2016-2018 Chung, Hyung-Hwan. All rights reserved. | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     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 "hcl-prv.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-05 15:59:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | #define PRINT_STACK_ALIGN 128
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-07 10:55:20 +00:00
										 |  |  | enum | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	PRINT_STACK_CONS, | 
					
						
							|  |  |  | 	PRINT_STACK_ARRAY, | 
					
						
							|  |  |  | 	PRINT_STACK_ARRAY_END, | 
					
						
							|  |  |  | 	PRINT_STACK_DIC, | 
					
						
							|  |  |  | 	PRINT_STACK_DIC_END | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | typedef struct print_stack_t print_stack_t; | 
					
						
							|  |  |  | struct print_stack_t | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int type; | 
					
						
							|  |  |  | 	hcl_oop_t obj; | 
					
						
							| 
									
										
										
										
											2018-02-07 10:55:20 +00:00
										 |  |  | 	hcl_oop_t obj2; | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 	hcl_oow_t idx; | 
					
						
							| 
									
										
										
										
											2018-02-07 10:55:20 +00:00
										 |  |  | 	hcl_oow_t idx2; | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static HCL_INLINE int push (hcl_t* hcl, print_stack_t* info) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (hcl->p.s.size >= hcl->p.s.capa) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		print_stack_t* tmp; | 
					
						
							|  |  |  | 		hcl_oow_t new_capa; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		new_capa = HCL_ALIGN (hcl->p.s.capa + 1, PRINT_STACK_ALIGN); | 
					
						
							| 
									
										
										
										
											2018-02-26 15:24:45 +00:00
										 |  |  | 		tmp = (print_stack_t*)hcl_reallocmem(hcl, hcl->p.s.ptr, new_capa * HCL_SIZEOF(*info)); | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 		if (!tmp) return -1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		hcl->p.s.ptr = tmp; | 
					
						
							|  |  |  | 		hcl->p.s.capa = new_capa; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	((print_stack_t*)hcl->p.s.ptr)[hcl->p.s.size] = *info; | 
					
						
							|  |  |  | 	hcl->p.s.size++; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static HCL_INLINE void pop (hcl_t* hcl, print_stack_t* info) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-02-05 10:43:25 +00:00
										 |  |  | 	HCL_ASSERT (hcl, hcl->p.s.size > 0); | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 	hcl->p.s.size--; | 
					
						
							|  |  |  | 	*info = ((print_stack_t*)hcl->p.s.ptr)[hcl->p.s.size]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-04 17:56:28 +00:00
										 |  |  | enum | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	WORD_NIL, | 
					
						
							|  |  |  | 	WORD_TRUE, | 
					
						
							|  |  |  | 	WORD_FALSE, | 
					
						
							| 
									
										
										
										
											2016-10-06 17:49:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-05 15:59:32 +00:00
										 |  |  | 	WORD_SET, | 
					
						
							| 
									
										
										
										
											2016-10-04 17:56:28 +00:00
										 |  |  | 	WORD_CFRAME, | 
					
						
							| 
									
										
										
										
											2016-10-06 17:49:47 +00:00
										 |  |  | 	WORD_PRIM, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-04 17:56:28 +00:00
										 |  |  | 	WORD_CONTEXT, | 
					
						
							|  |  |  | 	WORD_PROCESS, | 
					
						
							|  |  |  | 	WORD_PROCESS_SCHEDULER, | 
					
						
							|  |  |  | 	WORD_SEMAPHORE | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct  | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	hcl_oow_t  len; | 
					
						
							|  |  |  | 	hcl_ooch_t ptr[20]; | 
					
						
							|  |  |  | } word[] = | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-03-02 07:58:37 +00:00
										 |  |  | 	{  4,  { 'n', 'u', 'l', 'l' } }, | 
					
						
							|  |  |  | 	{  4,  { 't', 'r', 'u', 'e' } }, | 
					
						
							|  |  |  | 	{  5,  { 'f', 'a', 'l', 's', 'e' } }, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-04 17:56:28 +00:00
										 |  |  | 	{  6,  { '#','<','S','E','T','>' } }, | 
					
						
							|  |  |  | 	{  9,  { '#','<','C','F','R','A','M','E','>' } }, | 
					
						
							| 
									
										
										
										
											2016-10-06 17:49:47 +00:00
										 |  |  | 	{  7,  { '#','<','P','R','I','M','>' } }, | 
					
						
							| 
									
										
										
										
											2018-02-05 15:59:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-04 17:56:28 +00:00
										 |  |  | 	{  10, { '#','<','C','O','N','T','E','X','T','>' } }, | 
					
						
							|  |  |  | 	{  10, { '#','<','P','R','O','C','E','S','S','>' } }, | 
					
						
							|  |  |  | 	{  20, { '#','<','P','R','O','C','E','S','S','-','S','C','H','E','D','U','L','E','R','>' } }, | 
					
						
							|  |  |  | 	{  12, { '#','<','S','E','M','A','P','H','O','R','E','>' } } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-26 04:39:20 +00:00
										 |  |  | static HCL_INLINE int print_single_char (hcl_t* hcl, hcl_bitmask_t mask, hcl_ooch_t ch, hcl_outbfmt_t outbfmt) | 
					
						
							| 
									
										
										
										
											2018-02-17 15:42:12 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-02-28 10:17:05 +00:00
										 |  |  | 	hcl_oochu_t chu = (hcl_oochu_t)ch; | 
					
						
							| 
									
										
										
										
											2018-03-29 04:47:03 +00:00
										 |  |  | 	if (chu == '\\' || chu == '\"') | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		if (outbfmt(hcl, mask, "\\%jc", chu) <= -1) return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-02-28 10:17:05 +00:00
										 |  |  | #if defined(HCL_OOCH_IS_UCH)
 | 
					
						
							| 
									
										
										
										
											2018-03-29 04:47:03 +00:00
										 |  |  | 	else if (chu < ' ')  | 
					
						
							| 
									
										
										
										
											2018-02-28 10:17:05 +00:00
										 |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2018-03-29 04:47:03 +00:00
										 |  |  | 	else if (chu < ' ' || chu >= 0x80)  | 
					
						
							| 
									
										
										
										
											2018-02-28 10:17:05 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2018-02-17 15:42:12 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-03-01 08:56:56 +00:00
										 |  |  | 		hcl_oochu_t escaped; | 
					
						
							| 
									
										
										
										
											2018-02-17 15:42:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-28 10:17:05 +00:00
										 |  |  | 		switch (chu) | 
					
						
							| 
									
										
										
										
											2018-02-17 15:42:12 +00:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			case '\0': | 
					
						
							|  |  |  | 				escaped = '0'; | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			case '\n': | 
					
						
							|  |  |  | 				escaped = 'n'; | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			case '\r': | 
					
						
							|  |  |  | 				escaped = 'r'; | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			case '\t': | 
					
						
							|  |  |  | 				escaped = 't'; | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			case '\f': | 
					
						
							|  |  |  | 				escaped = 'f'; | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			case '\b': | 
					
						
							|  |  |  | 				escaped = 'b'; | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			case '\v': | 
					
						
							|  |  |  | 				escaped = 'v'; | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			case '\a': | 
					
						
							|  |  |  | 				escaped = 'a'; | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			default: | 
					
						
							| 
									
										
										
										
											2018-03-01 08:56:56 +00:00
										 |  |  | 				escaped = chu; | 
					
						
							| 
									
										
										
										
											2018-02-17 15:42:12 +00:00
										 |  |  | 				break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-01 08:56:56 +00:00
										 |  |  | 		if (escaped == chu) | 
					
						
							| 
									
										
										
										
											2018-02-17 15:42:12 +00:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-03-01 08:56:56 +00:00
										 |  |  | 		#if (HCL_SIZEOF_OOCH_T >= 4)
 | 
					
						
							|  |  |  | 			if (chu >= 0x10000u) | 
					
						
							|  |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2018-03-29 04:47:03 +00:00
										 |  |  | 				if (outbfmt(hcl, mask, "\\U%08X", chu) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2018-03-01 08:56:56 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			else  | 
					
						
							|  |  |  | 		#endif
 | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 		#if (HCL_SIZEOF_OOCH_T >= 2)
 | 
					
						
							|  |  |  | 				if (chu >= 0x100u) | 
					
						
							|  |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2018-03-29 04:47:03 +00:00
										 |  |  | 					if (outbfmt(hcl, mask, "\\u%04X", chu) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2018-03-01 08:56:56 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 				else | 
					
						
							|  |  |  | 		#endif
 | 
					
						
							|  |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2018-03-29 04:47:03 +00:00
										 |  |  | 					if (outbfmt(hcl, mask, "\\x%02X", chu) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2018-03-01 08:56:56 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-02-17 15:42:12 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			if (outbfmt(hcl, mask, "\\%jc", escaped) <= -1) return -1; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		if (outbfmt(hcl, mask, "%jc", ch) <= -1) return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-26 04:39:20 +00:00
										 |  |  | static HCL_INLINE int outfmt_obj (hcl_t* hcl, hcl_bitmask_t mask, hcl_oop_t obj, hcl_outbfmt_t outbfmt) | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	hcl_oop_t cur; | 
					
						
							|  |  |  | 	print_stack_t ps; | 
					
						
							| 
									
										
										
										
											2016-10-01 04:36:48 +00:00
										 |  |  | 	int brand; | 
					
						
							| 
									
										
										
										
											2018-02-05 15:59:32 +00:00
										 |  |  | 	int word_index; | 
					
						
							| 
									
										
										
										
											2018-03-02 07:44:13 +00:00
										 |  |  | 	int json; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	static const hcl_bch_t *opening_parens[][2] = | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-08-07 11:04:38 +00:00
										 |  |  | 		{ "(",   "(" },  /*HCL_CONCODE_XLIST */ | 
					
						
							|  |  |  | 		{ "[",   "[" },  /*HCL_CONCODE_ARRAY */ | 
					
						
							| 
									
										
										
										
											2018-08-08 03:41:17 +00:00
										 |  |  | 		{ "#[",  "[" },  /*HCL_CONCODE_BYTEARRAY */  | 
					
						
							| 
									
										
										
										
											2018-08-07 11:04:38 +00:00
										 |  |  | 		{ "{",   "{" },  /*HCL_CONCODE_DIC */ | 
					
						
							| 
									
										
										
										
											2018-08-08 03:41:17 +00:00
										 |  |  | 		{ "#(",  "[" }   /*HCL_CONCODE_QLIST */ | 
					
						
							| 
									
										
										
										
											2018-03-02 07:44:13 +00:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	static const hcl_bch_t *closing_parens[][2] = | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		{ ")",  ")" },   /*HCL_CONCODE_XLIST */ | 
					
						
							| 
									
										
										
										
											2018-04-06 08:33:25 +00:00
										 |  |  | 		{ "]",  "]" },   /*HCL_CONCODE_ARRAY */ | 
					
						
							| 
									
										
										
										
											2018-03-02 07:44:13 +00:00
										 |  |  | 		{ "]",  "]" },   /*HCL_CONCODE_BYTEARRAY */ | 
					
						
							|  |  |  | 		{ "}",  "}" },   /*HCL_CONCODE_DIC */ | 
					
						
							| 
									
										
										
										
											2018-08-07 11:04:38 +00:00
										 |  |  | 		{ ")",  "]" },   /*HCL_CONCODE_QLIST */ | 
					
						
							| 
									
										
										
										
											2018-03-02 07:44:13 +00:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	static const hcl_bch_t* breakers[][2] =  | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		{ " ", "," }, /* item breaker */ | 
					
						
							|  |  |  | 		{ " ", ":" }  /* key value breaker */ | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	json = !!(mask & HCL_LOG_PREFER_JSON); | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | next: | 
					
						
							| 
									
										
										
										
											2018-02-23 07:17:23 +00:00
										 |  |  | 	switch ((brand = HCL_BRANDOF(hcl, obj)))  | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-02-23 07:17:23 +00:00
										 |  |  | 		case HCL_BRAND_SMOOI: | 
					
						
							|  |  |  | 			if (outbfmt(hcl, mask, "%zd", HCL_OOP_TO_SMOOI(obj)) <= -1) return -1; | 
					
						
							|  |  |  | 			goto done; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		case HCL_BRAND_SMPTR: | 
					
						
							| 
									
										
										
										
											2018-03-05 03:47:18 +00:00
										 |  |  | 			if (outbfmt(hcl, mask, "#p%zX", (hcl_oow_t)HCL_OOP_TO_SMPTR(obj)) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2018-02-23 07:17:23 +00:00
										 |  |  | 			goto done; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		case HCL_BRAND_ERROR: | 
					
						
							| 
									
										
										
										
											2018-03-05 03:47:18 +00:00
										 |  |  | 			if (outbfmt(hcl, mask, "#e%zd", (hcl_ooi_t)HCL_OOP_TO_ERROR(obj)) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2018-02-23 07:17:23 +00:00
										 |  |  | 			goto done; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		case HCL_BRAND_CHARACTER: | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			hcl_ooch_t ch = HCL_OOP_TO_CHAR(obj); | 
					
						
							|  |  |  | 			if (outbfmt(hcl, mask, "\'") <= -1 || | 
					
						
							|  |  |  | 			    print_single_char(hcl, mask, ch, outbfmt) <= -1 || | 
					
						
							|  |  |  | 			    outbfmt(hcl, mask, "\'") <= -1) return -1; | 
					
						
							|  |  |  | 			goto done; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 		case HCL_BRAND_NIL: | 
					
						
							| 
									
										
										
										
											2018-04-06 08:33:25 +00:00
										 |  |  | 			word_index = WORD_NIL; | 
					
						
							| 
									
										
										
										
											2018-02-05 15:59:32 +00:00
										 |  |  | 			goto print_word; | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		case HCL_BRAND_TRUE: | 
					
						
							| 
									
										
										
										
											2018-04-06 08:33:25 +00:00
										 |  |  | 			word_index = WORD_TRUE; | 
					
						
							| 
									
										
										
										
											2018-02-05 15:59:32 +00:00
										 |  |  | 			goto print_word; | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		case HCL_BRAND_FALSE: | 
					
						
							| 
									
										
										
										
											2018-04-06 08:33:25 +00:00
										 |  |  | 			word_index = WORD_FALSE; | 
					
						
							| 
									
										
										
										
											2018-02-05 15:59:32 +00:00
										 |  |  | 			goto print_word; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-13 16:10:41 +00:00
										 |  |  | 		case HCL_BRAND_PBIGINT: | 
					
						
							|  |  |  | 		case HCL_BRAND_NBIGINT: | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-02-15 08:05:48 +00:00
										 |  |  | 			hcl_oop_t tmp; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			/* -1 to drive hcl_inttostr() to not create a new string object.
 | 
					
						
							|  |  |  | 			 * not using the object memory. the result stays in the temporary | 
					
						
							|  |  |  | 			 * buffer */ | 
					
						
							| 
									
										
										
										
											2019-04-16 15:46:00 +00:00
										 |  |  | 			tmp = hcl_inttostr(hcl, obj, 10 | HCL_INTTOSTR_NONEWOBJ);  | 
					
						
							| 
									
										
										
										
											2018-02-15 08:05:48 +00:00
										 |  |  | 			if (!tmp) return -1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			HCL_ASSERT (hcl, (hcl_oop_t)tmp == hcl->_nil);  | 
					
						
							|  |  |  | 			if (outbfmt(hcl, mask, "%.*js", hcl->inttostr.xbuf.len, hcl->inttostr.xbuf.ptr) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2018-02-13 16:10:41 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-28 08:57:49 +00:00
										 |  |  | 		case HCL_BRAND_FPDEC: | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			hcl_oop_fpdec_t f = (hcl_oop_fpdec_t)obj; | 
					
						
							|  |  |  | 			hcl_ooi_t scale; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			scale = HCL_OOP_TO_SMOOI(f->scale); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-30 15:43:09 +00:00
										 |  |  | 			if (f->value == HCL_SMOOI_TO_OOP(0)) | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				if (scale == 0) | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					if (outbfmt(hcl, mask, "0.") <= -1) return -1; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				else | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					if (outbfmt(hcl, mask, "0.%0*d", scale, 0) <= -1) return -1; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			else  | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				hcl_oop_t tmp; | 
					
						
							|  |  |  | 				hcl_oow_t len, adj; | 
					
						
							| 
									
										
										
										
											2018-03-28 08:57:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-16 15:46:00 +00:00
										 |  |  | 				tmp = hcl_inttostr(hcl, f->value, 10 | HCL_INTTOSTR_NONEWOBJ); | 
					
						
							| 
									
										
										
										
											2018-03-30 15:43:09 +00:00
										 |  |  | 				if (!tmp) return -1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				adj = (hcl->inttostr.xbuf.ptr[0] == '-'); | 
					
						
							|  |  |  | 				len = hcl->inttostr.xbuf.len - adj; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				if (len <= scale) | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					if (scale == len) | 
					
						
							|  |  |  | 					{ | 
					
						
							|  |  |  | 						if (outbfmt(hcl, mask, "%.*js0.%.*js",  | 
					
						
							|  |  |  | 							adj, hcl->inttostr.xbuf.ptr, | 
					
						
							|  |  |  | 							len, &hcl->inttostr.xbuf.ptr[adj]) <= -1) return -1; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					else | 
					
						
							|  |  |  | 					{ | 
					
						
							|  |  |  | 						if (outbfmt(hcl, mask, "%.*js0.%0*d%.*js",  | 
					
						
							|  |  |  | 							adj, hcl->inttostr.xbuf.ptr, | 
					
						
							|  |  |  | 							scale - len, 0, | 
					
						
							|  |  |  | 							len, &hcl->inttostr.xbuf.ptr[adj]) <= -1) return -1; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				else | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					hcl_ooi_t ndigits; | 
					
						
							|  |  |  | 					ndigits = hcl->inttostr.xbuf.len - scale; | 
					
						
							|  |  |  | 					if (outbfmt(hcl, mask, "%.*js.%.*js", ndigits, hcl->inttostr.xbuf.ptr, scale, &hcl->inttostr.xbuf.ptr[ndigits]) <= -1) return -1; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-03-28 08:57:49 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | #if 0
 | 
					
						
							|  |  |  | 		case HCL_BRAND_REAL: | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			qse_char_t buf[256]; | 
					
						
							|  |  |  | 			hcl->prm.sprintf ( | 
					
						
							|  |  |  | 				hcl->prm.ctx, | 
					
						
							|  |  |  | 				buf, HCL_COUNTOF(buf),  | 
					
						
							|  |  |  | 				HCL_T("%Lf"),  | 
					
						
							|  |  |  | 			#ifdef __MINGW32__
 | 
					
						
							|  |  |  | 				(double)HCL_RVAL(obj) | 
					
						
							|  |  |  | 			#else
 | 
					
						
							|  |  |  | 				(long double)HCL_RVAL(obj) | 
					
						
							|  |  |  | 			#endif
 | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			OUTPUT_STR (hcl, buf); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		case HCL_BRAND_SYMBOL: | 
					
						
							|  |  |  | 			/* Any needs for special action if SYNT(obj) is true?
 | 
					
						
							|  |  |  | 			 * I simply treat the syntax symbol as a normal symbol | 
					
						
							|  |  |  | 			 * for printing currently. */ | 
					
						
							| 
									
										
										
										
											2018-02-05 15:59:32 +00:00
										 |  |  | 			if (outbfmt(hcl, mask, "%.*js", HCL_OBJ_GET_SIZE(obj), HCL_OBJ_GET_CHAR_SLOT(obj)) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		case HCL_BRAND_STRING: | 
					
						
							| 
									
										
										
										
											2018-02-05 15:59:32 +00:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			hcl_ooch_t ch; | 
					
						
							|  |  |  | 			hcl_oow_t i; | 
					
						
							|  |  |  | 			int escape = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			for (i = 0; i < HCL_OBJ_GET_SIZE(obj); i++) | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				ch = ((hcl_oop_char_t)obj)->slot[i]; | 
					
						
							| 
									
										
										
										
											2018-03-29 04:47:03 +00:00
										 |  |  | 				if (ch < ' ' || ch == '\"' || ch == '\\')  | 
					
						
							| 
									
										
										
										
											2018-02-05 15:59:32 +00:00
										 |  |  | 				{ | 
					
						
							|  |  |  | 					escape = 1; | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (escape) | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				if (outbfmt(hcl, mask, "\"") <= -1) return -1; | 
					
						
							|  |  |  | 				for (i = 0; i < HCL_OBJ_GET_SIZE(obj); i++) | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					ch = ((hcl_oop_char_t)obj)->slot[i]; | 
					
						
							| 
									
										
										
										
											2018-02-17 15:42:12 +00:00
										 |  |  | 					if (print_single_char(hcl, mask, ch, outbfmt) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2018-02-05 15:59:32 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 				if (outbfmt(hcl, mask, "\"") <= -1) return -1; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			else | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				if (outbfmt(hcl, mask, "\"%.*js\"", HCL_OBJ_GET_SIZE(obj), HCL_OBJ_GET_CHAR_SLOT(obj)) <= -1) return -1; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2018-02-05 15:59:32 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		case HCL_BRAND_CONS: | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-02-06 10:16:01 +00:00
										 |  |  | 			int concode; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-02 07:44:13 +00:00
										 |  |  | 			/* this part is to print a linked list of cells. ignore the
 | 
					
						
							|  |  |  | 			 * request to output in the json format */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-06 10:16:01 +00:00
										 |  |  | 			concode = HCL_OBJ_GET_FLAGS_SYNCODE(obj); | 
					
						
							| 
									
										
										
										
											2018-03-02 07:44:13 +00:00
										 |  |  | 			if (outbfmt(hcl, mask, opening_parens[concode][0]) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 			cur = obj; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			do | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				int x; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				/* Push what to print next on to the stack 
 | 
					
						
							|  |  |  | 				 * the variable p is */ | 
					
						
							|  |  |  | 				ps.type = PRINT_STACK_CONS; | 
					
						
							|  |  |  | 				ps.obj = HCL_CONS_CDR(cur); | 
					
						
							| 
									
										
										
										
											2018-02-12 16:51:38 +00:00
										 |  |  | 				ps.idx = concode; /* this is not an index but use this field to restore concode */ | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 				x = push (hcl, &ps); | 
					
						
							|  |  |  | 				if (x <= -1) return -1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				obj = HCL_CONS_CAR(cur); | 
					
						
							|  |  |  | 				/* Jump to the 'next' label so that the object 
 | 
					
						
							|  |  |  | 				 * pointed to by 'obj' is printed. Once it  | 
					
						
							|  |  |  | 				 * ends, a jump back to the 'resume' label | 
					
						
							|  |  |  | 				 * is made at the at of this function. */ | 
					
						
							|  |  |  | 				goto next;  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			resume_cons: | 
					
						
							| 
									
										
										
										
											2018-02-05 10:43:25 +00:00
										 |  |  | 				HCL_ASSERT (hcl, ps.type == PRINT_STACK_CONS); | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 				cur = ps.obj; /* Get back the CDR pushed */ | 
					
						
							| 
									
										
										
										
											2018-02-12 16:51:38 +00:00
										 |  |  | 				concode = ps.idx; /* restore the concode */ | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 				if (HCL_IS_NIL(hcl,cur))  | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					/* The CDR part points to a NIL object, which
 | 
					
						
							|  |  |  | 					 * indicates the end of a list. break the loop */ | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				if (!HCL_OOP_IS_POINTER(cur) || HCL_OBJ_GET_FLAGS_BRAND(cur) != HCL_BRAND_CONS)  | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					/* The CDR part does not point to a pair. */ | 
					
						
							| 
									
										
										
										
											2018-02-05 15:59:32 +00:00
										 |  |  | 					if (outbfmt(hcl, mask, " . ") <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 					/* Push NIL so that the HCL_IS_NIL(hcl,p) test in 
 | 
					
						
							|  |  |  | 					 * the 'if' statement above breaks the loop | 
					
						
							|  |  |  | 					 * after the jump is maded back to the 'resume'  | 
					
						
							|  |  |  | 					 * label. */ | 
					
						
							|  |  |  | 					ps.type = PRINT_STACK_CONS; | 
					
						
							|  |  |  | 					ps.obj = hcl->_nil; | 
					
						
							| 
									
										
										
										
											2018-02-21 08:48:47 +00:00
										 |  |  | 					x = push(hcl, &ps); | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 					if (x <= -1) return -1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					/* Make a jump to 'next' to print the CDR part */ | 
					
						
							|  |  |  | 					obj = cur; | 
					
						
							|  |  |  | 					goto next; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				/* The CDR part points to a pair. proceed to it */ | 
					
						
							| 
									
										
										
										
											2018-03-02 07:44:13 +00:00
										 |  |  | 				if (outbfmt(hcl, mask, breakers[0][0]) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			while (1); | 
					
						
							| 
									
										
										
										
											2018-02-06 10:16:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-02 07:44:13 +00:00
										 |  |  | 			if (outbfmt(hcl, mask, closing_parens[concode][0]) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		case HCL_BRAND_ARRAY: | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			hcl_oow_t arridx; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-02 07:44:13 +00:00
										 |  |  | 			if (outbfmt(hcl, mask, opening_parens[HCL_CONCODE_ARRAY][json]) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-01 04:36:48 +00:00
										 |  |  | 			if (HCL_OBJ_GET_SIZE(obj) <= 0)  | 
					
						
							|  |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2018-03-02 07:44:13 +00:00
										 |  |  | 				if (outbfmt(hcl, mask, closing_parens[HCL_CONCODE_ARRAY][json]) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2016-10-01 04:36:48 +00:00
										 |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 			arridx = 0; | 
					
						
							| 
									
										
										
										
											2016-10-01 04:36:48 +00:00
										 |  |  | 			ps.type = PRINT_STACK_ARRAY; | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			do | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				int x; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-01 04:36:48 +00:00
										 |  |  | 				/* Push what to print next on to the stack */ | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 				ps.idx = arridx + 1; | 
					
						
							|  |  |  | 				if (ps.idx >= HCL_OBJ_GET_SIZE(obj))  | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					ps.type = PRINT_STACK_ARRAY_END; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				else | 
					
						
							|  |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2018-02-05 10:43:25 +00:00
										 |  |  | 					HCL_ASSERT (hcl, ps.type == PRINT_STACK_ARRAY); | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 					ps.obj = obj; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				 | 
					
						
							|  |  |  | 				x = push (hcl, &ps); | 
					
						
							|  |  |  | 				if (x <= -1) return -1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				obj = ((hcl_oop_oop_t)obj)->slot[arridx]; | 
					
						
							| 
									
										
										
										
											2018-02-05 15:59:32 +00:00
										 |  |  | 				if (arridx > 0)  | 
					
						
							|  |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2018-03-02 07:44:13 +00:00
										 |  |  | 					if (outbfmt(hcl, mask, breakers[0][json]) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2018-02-05 15:59:32 +00:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 				/* Jump to the 'next' label so that the object 
 | 
					
						
							|  |  |  | 				 * pointed to by 'obj' is printed. Once it  | 
					
						
							|  |  |  | 				 * ends, a jump back to the 'resume' label | 
					
						
							| 
									
										
										
										
											2016-10-01 04:36:48 +00:00
										 |  |  | 				 * is made at the end of this function. */ | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 				goto next;  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			resume_array: | 
					
						
							| 
									
										
										
										
											2018-02-05 10:43:25 +00:00
										 |  |  | 				HCL_ASSERT (hcl, ps.type == PRINT_STACK_ARRAY); | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 				arridx = ps.idx; | 
					
						
							|  |  |  | 				obj = ps.obj; | 
					
						
							|  |  |  | 			}  | 
					
						
							|  |  |  | 			while (1); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		case HCL_BRAND_BYTE_ARRAY: | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			hcl_oow_t i; | 
					
						
							| 
									
										
										
										
											2018-03-02 07:44:13 +00:00
										 |  |  | 			if (outbfmt(hcl, mask, opening_parens[HCL_CONCODE_BYTEARRAY][json]) <= -1) return -1; | 
					
						
							|  |  |  | 			if (HCL_OBJ_GET_SIZE(obj) > 0) | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2018-03-02 07:44:13 +00:00
										 |  |  | 				if (outbfmt(hcl, mask, "%d", ((hcl_oop_byte_t)obj)->slot[0]) <= -1) return -1; | 
					
						
							|  |  |  | 				for (i = 1; i < HCL_OBJ_GET_SIZE(obj); i++) | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					if (outbfmt(hcl, mask, "%hs%d", breakers[0][json], ((hcl_oop_byte_t)obj)->slot[i]) <= -1) return -1; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-03-02 07:44:13 +00:00
										 |  |  | 			if (outbfmt(hcl, mask, closing_parens[HCL_CONCODE_BYTEARRAY][json]) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-07 10:55:20 +00:00
										 |  |  | 		case HCL_BRAND_DIC: | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			hcl_oow_t bucidx, bucsize, buctally; | 
					
						
							|  |  |  | 			hcl_oop_dic_t dic; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-02 07:44:13 +00:00
										 |  |  | 			if (outbfmt(hcl, mask, opening_parens[HCL_CONCODE_DIC][json]) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2018-02-07 10:55:20 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			dic = (hcl_oop_dic_t)obj; | 
					
						
							|  |  |  | 			HCL_ASSERT (hcl, HCL_OOP_IS_SMOOI(dic->tally)); | 
					
						
							|  |  |  | 			if (HCL_OOP_TO_SMOOI(dic->tally) <= 0)  | 
					
						
							|  |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2018-03-02 07:44:13 +00:00
										 |  |  | 				if (outbfmt(hcl, mask, closing_parens[HCL_CONCODE_DIC][json]) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2018-02-07 10:55:20 +00:00
										 |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			bucidx = 0; | 
					
						
							|  |  |  | 			bucsize = HCL_OBJ_GET_SIZE(dic->bucket); | 
					
						
							|  |  |  | 			buctally = 0; | 
					
						
							|  |  |  | 			ps.type = PRINT_STACK_DIC; | 
					
						
							|  |  |  | 			ps.obj2 = (hcl_oop_t)dic; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			do | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				int x; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				if ((buctally & 1) == 0) | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					while (bucidx < bucsize) | 
					
						
							|  |  |  | 					{ | 
					
						
							|  |  |  | 						/* skip an unoccupied slot in the bucket array */ | 
					
						
							|  |  |  | 						obj = dic->bucket->slot[bucidx]; | 
					
						
							|  |  |  | 						if (!HCL_IS_NIL(hcl,obj)) break; | 
					
						
							|  |  |  | 						bucidx++; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					if (bucidx >= bucsize) | 
					
						
							|  |  |  | 					{ | 
					
						
							|  |  |  | 						/* done. scanned the entire bucket */ | 
					
						
							| 
									
										
										
										
											2018-03-02 07:44:13 +00:00
										 |  |  | 						if (outbfmt(hcl, mask, closing_parens[HCL_CONCODE_DIC][json]) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2018-02-07 10:55:20 +00:00
										 |  |  | 						break; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					ps.idx = bucidx; /* no increment yet */ | 
					
						
							|  |  |  | 					HCL_ASSERT (hcl, ps.idx < bucsize); | 
					
						
							|  |  |  | 					HCL_ASSERT (hcl, ps.type == PRINT_STACK_DIC); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					ps.obj = dic->bucket->slot[ps.idx]; | 
					
						
							|  |  |  | 					ps.idx2 = buctally + 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					x = push (hcl, &ps); | 
					
						
							|  |  |  | 					if (x <= -1) return -1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					HCL_ASSERT (hcl, HCL_IS_CONS(hcl,obj)); | 
					
						
							|  |  |  | 					obj = HCL_CONS_CAR(obj); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				else | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					/* Push what to print next on to the stack */ | 
					
						
							|  |  |  | 					ps.idx = bucidx + 1; | 
					
						
							|  |  |  | 					if (ps.idx >= bucsize)  | 
					
						
							|  |  |  | 					{ | 
					
						
							|  |  |  | 						ps.type = PRINT_STACK_DIC_END; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					else | 
					
						
							|  |  |  | 					{ | 
					
						
							|  |  |  | 						HCL_ASSERT (hcl, ps.type == PRINT_STACK_DIC); | 
					
						
							|  |  |  | 						ps.obj = dic->bucket->slot[ps.idx]; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					ps.idx2 = buctally + 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					x = push (hcl, &ps); | 
					
						
							|  |  |  | 					if (x <= -1) return -1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					HCL_ASSERT (hcl, HCL_IS_CONS(hcl,obj)); | 
					
						
							|  |  |  | 					obj = HCL_CONS_CDR(obj); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				if (buctally > 0)  | 
					
						
							|  |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2018-03-02 07:44:13 +00:00
										 |  |  | 					if (outbfmt(hcl, mask, breakers[buctally & 1][json]) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2018-02-07 10:55:20 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 				 | 
					
						
							|  |  |  | 				/* Jump to the 'next' label so that the object 
 | 
					
						
							|  |  |  | 				 * pointed to by 'obj' is printed. Once it  | 
					
						
							|  |  |  | 				 * ends, a jump back to the 'resume' label | 
					
						
							|  |  |  | 				 * is made at the end of this function. */ | 
					
						
							|  |  |  | 				goto next;  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			resume_dic: | 
					
						
							|  |  |  | 				HCL_ASSERT (hcl, ps.type == PRINT_STACK_DIC); | 
					
						
							|  |  |  | 				bucidx = ps.idx; | 
					
						
							|  |  |  | 				buctally = ps.idx2; | 
					
						
							|  |  |  | 				obj = ps.obj; | 
					
						
							|  |  |  | 				dic = (hcl_oop_dic_t)ps.obj2; | 
					
						
							|  |  |  | 				bucsize = HCL_OBJ_GET_SIZE(dic->bucket); | 
					
						
							|  |  |  | 			}  | 
					
						
							|  |  |  | 			while (1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-01 04:36:48 +00:00
										 |  |  | 		case HCL_BRAND_SYMBOL_ARRAY: | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			hcl_oow_t i; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-05 15:59:32 +00:00
										 |  |  | 			if (outbfmt(hcl, mask, "|") <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2016-10-01 04:36:48 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			for (i = 0; i < HCL_OBJ_GET_SIZE(obj); i++) | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				hcl_oop_t s; | 
					
						
							|  |  |  | 				s = ((hcl_oop_oop_t)obj)->slot[i]; | 
					
						
							| 
									
										
										
										
											2018-02-05 15:59:32 +00:00
										 |  |  | 				if (outbfmt(hcl, mask, " %.*js", HCL_OBJ_GET_SIZE(s), HCL_OBJ_GET_CHAR_SLOT(s)) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2016-10-01 04:36:48 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-02-05 15:59:32 +00:00
										 |  |  | 			if (outbfmt(hcl, mask, " |") <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2016-10-01 04:36:48 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-10-04 17:56:28 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		case HCL_BRAND_CFRAME: | 
					
						
							| 
									
										
										
										
											2018-02-05 15:59:32 +00:00
										 |  |  | 			word_index = WORD_CFRAME; | 
					
						
							|  |  |  | 			goto print_word; | 
					
						
							| 
									
										
										
										
											2016-10-04 17:56:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-06 17:49:47 +00:00
										 |  |  | 		case HCL_BRAND_PRIM: | 
					
						
							| 
									
										
										
										
											2018-02-05 15:59:32 +00:00
										 |  |  | 			word_index = WORD_PRIM; | 
					
						
							|  |  |  | 			goto print_word; | 
					
						
							| 
									
										
										
										
											2016-10-06 17:49:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-04 17:56:28 +00:00
										 |  |  | 		case HCL_BRAND_CONTEXT: | 
					
						
							| 
									
										
										
										
											2018-02-05 15:59:32 +00:00
										 |  |  | 			word_index = WORD_CONTEXT; | 
					
						
							|  |  |  | 			goto print_word; | 
					
						
							| 
									
										
										
										
											2016-10-04 17:56:28 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		case HCL_BRAND_PROCESS: | 
					
						
							| 
									
										
										
										
											2018-02-05 15:59:32 +00:00
										 |  |  | 			word_index = WORD_PROCESS; | 
					
						
							|  |  |  | 			goto print_word; | 
					
						
							| 
									
										
										
										
											2016-10-04 17:56:28 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		case HCL_BRAND_PROCESS_SCHEDULER: | 
					
						
							| 
									
										
										
										
											2018-02-05 15:59:32 +00:00
										 |  |  | 			word_index = WORD_PROCESS_SCHEDULER; | 
					
						
							|  |  |  | 			goto print_word; | 
					
						
							| 
									
										
										
										
											2016-10-04 17:56:28 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		case HCL_BRAND_SEMAPHORE: | 
					
						
							| 
									
										
										
										
											2018-02-05 15:59:32 +00:00
										 |  |  | 			word_index = WORD_SEMAPHORE; | 
					
						
							|  |  |  | 			goto print_word; | 
					
						
							| 
									
										
										
										
											2016-10-04 17:56:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 		default: | 
					
						
							| 
									
										
										
										
											2016-10-01 04:36:48 +00:00
										 |  |  | 			HCL_DEBUG3 (hcl, "Internal error - unknown object type %d at %s:%d\n", (int)brand, __FILE__, __LINE__); | 
					
						
							| 
									
										
										
										
											2018-02-05 10:43:25 +00:00
										 |  |  | 			HCL_ASSERT (hcl, "Unknown object type" == HCL_NULL); | 
					
						
							| 
									
										
										
										
											2018-02-05 15:59:32 +00:00
										 |  |  | 			hcl_seterrbfmt (hcl, HCL_EINTERN, "unknown object type %d", (int)brand); | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 			return -1; | 
					
						
							| 
									
										
										
										
											2018-02-05 15:59:32 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		print_word: | 
					
						
							| 
									
										
										
										
											2018-03-02 07:58:37 +00:00
										 |  |  | 			if (outbfmt(hcl, mask, "%.*js", word[word_index].len, word[word_index].ptr) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2018-02-05 15:59:32 +00:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | done: | 
					
						
							|  |  |  | 	/* if the printing stack is not empty, we still got more to print */ | 
					
						
							|  |  |  | 	while (hcl->p.s.size > 0) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		pop (hcl, &ps); | 
					
						
							| 
									
										
										
										
											2016-10-01 04:36:48 +00:00
										 |  |  | 		switch (ps.type) | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2016-10-01 04:36:48 +00:00
										 |  |  | 			case PRINT_STACK_CONS: | 
					
						
							|  |  |  | 				goto resume_cons; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			case PRINT_STACK_ARRAY: | 
					
						
							|  |  |  | 				goto resume_array; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			case PRINT_STACK_ARRAY_END: | 
					
						
							| 
									
										
										
										
											2018-04-06 08:33:25 +00:00
										 |  |  | 				if (outbfmt(hcl, mask, closing_parens[HCL_CONCODE_ARRAY][json]) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2016-10-01 04:36:48 +00:00
										 |  |  | 				break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-07 10:55:20 +00:00
										 |  |  | 			case PRINT_STACK_DIC: | 
					
						
							|  |  |  | 				goto resume_dic; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			case PRINT_STACK_DIC_END: | 
					
						
							| 
									
										
										
										
											2018-04-06 08:55:23 +00:00
										 |  |  | 				if (outbfmt(hcl, mask, closing_parens[HCL_CONCODE_DIC][json]) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2018-02-07 10:55:20 +00:00
										 |  |  | 				break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-01 04:36:48 +00:00
										 |  |  | 			default: | 
					
						
							|  |  |  | 				HCL_DEBUG3 (hcl, "Internal error - unknown print stack type %d at %s:%d\n", (int)ps.type, __FILE__, __LINE__); | 
					
						
							| 
									
										
										
										
											2018-02-13 16:10:41 +00:00
										 |  |  | 				hcl_seterrbfmt (hcl, HCL_EINTERN, "internal error - unknown print stack type %d", (int)ps.type); | 
					
						
							| 
									
										
										
										
											2016-10-01 04:36:48 +00:00
										 |  |  | 				return -1; | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-26 04:39:20 +00:00
										 |  |  | int hcl_outfmtobj (hcl_t* hcl, hcl_bitmask_t mask, hcl_oop_t obj, hcl_outbfmt_t outbfmt) | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	int n; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* the printer stack must be empty. buggy if not. */ | 
					
						
							| 
									
										
										
										
											2018-02-05 10:43:25 +00:00
										 |  |  | 	HCL_ASSERT (hcl, hcl->p.s.size == 0);  | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	hcl->p.e = obj; /* remember the head of the object to print */ | 
					
						
							| 
									
										
										
										
											2018-03-01 05:25:09 +00:00
										 |  |  | 	n = outfmt_obj(hcl, mask, obj, outbfmt); | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 	hcl->p.e = hcl->_nil; /* reset what's remembered */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* clear the printing stack if an error has occurred for GC not to keep
 | 
					
						
							|  |  |  | 	 * the objects in the stack */ | 
					
						
							|  |  |  | 	if (n <= -1) hcl->p.s.size = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* the printer stack must get empty when done. buggy if not */ | 
					
						
							| 
									
										
										
										
											2018-02-05 10:43:25 +00:00
										 |  |  | 	HCL_ASSERT (hcl, hcl->p.s.size == 0);  | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return n; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-03-01 05:25:09 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | int hcl_print (hcl_t* hcl, hcl_oop_t obj) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	HCL_ASSERT (hcl, hcl->c->printer != HCL_NULL); | 
					
						
							|  |  |  | 	return hcl_outfmtobj (hcl, HCL_LOG_APP | HCL_LOG_FATAL, obj, hcl_proutbfmt); | 
					
						
							|  |  |  | } |