rev 242 - trunk/src

SVN User <[email protected]>
Newsgroups gmane.comp.lang.prothon.cvs
Message-ID <[email protected]>
Author: bcollins
Date: 2004-03-31 18:20:12 -0500 (Wed, 31 Mar 2004)
New Revision: 242

Modified:
   trunk/src/builtins.c
Log:
Fix list/dict str printing. So:


Modified: trunk/src/builtins.c
===================================================================
--- trunk/src/builtins.c	2004-03-31 23:18:34 UTC (rev 241)
+++ trunk/src/builtins.c	2004-03-31 23:20:12 UTC (rev 242)
@@ -421,14 +421,14 @@
 	for (i = 0; i < len; i++) {
 		char* item_str;
 		obj_p item = list_item(ist, self,i);
-		int is_str = 0;
+		int is_str = has_proto_QUES(ist, item, OBJ(STRING_PROTO));
 
 		if ((uintptr_t)item > 10) {
 			item_str = as_str(ist, item);
-			is_str = 1;
 		} else {
 			apr_snprintf(msg, sizeof(msg), "<objptr:%lx>", (unsigned long)(uintptr_t)item);
 			item_str = msg;
+			is_str = 0;
 		}
 
 		res = pr_realloc(res, strlen(res) + strlen(item_str) + strlen(rdelim) + 6);
@@ -1164,6 +1164,12 @@
         dictsize(dict) = DEFAULT_INITIAL_DICT_SIZE;
 }
 
+#define __ADD_QUOTE(__is_str)		\
+do {					\
+	if (__is_str)			\
+		strcat(res, "'");	\
+} while(0)
+
 DEF(Dict, __str__, NULL) {
 	int i;
 	size_t len;
@@ -1178,19 +1184,28 @@
 
 	strcpy(res, "{");
 	for (i=0; i < (int) len; i++) {
-		char* str1 = as_str(ist, list_item(ist, keys,i));
-		char* str2 = as_str(ist, list_item(ist, vals,i));
+		obj_p item1 = list_item(ist, keys,i);
+		obj_p item2 = list_item(ist, vals,i);
+		char* str1 = as_str(ist, item1);
+		char* str2 = as_str(ist, item2);
+		int is_str1 = has_proto_QUES(ist, item1, OBJ(STRING_PROTO));
+		int is_str2 = has_proto_QUES(ist, item2, OBJ(STRING_PROTO));
 
 		if (str1 == NULL)
 			str1 = "(null)";
 		if (str2 == NULL)
 			str2 = "(null)";
 
-		res = pr_realloc(res, strlen(res)+strlen(str1)+1+strlen(str2)+( i != len-1 ? 3 : 2)+2);
+		res = pr_realloc(res, strlen(res)+strlen(str1)+1+strlen(str2)+( i != len-1 ? 3 : 2)+6);
 
+		__ADD_QUOTE(is_str1);
 		strcat(res, str1);
+		__ADD_QUOTE(is_str1);
 		strcat(res, ":");
+		__ADD_QUOTE(is_str2);
 		strcat(res, str2);
+		__ADD_QUOTE(is_str2);
+
 		if (i != len-1) strcat(res, ", ");
 	}
 	strcat(res, "}");
@@ -1218,7 +1233,7 @@
 DEF(Dict, __getitem__, FORM_RPARAM) {
 	obj_p res;
 
-	CHECK_TYPE_EXC(parms[1], OBJ(SEQ_PROTO), "list");
+	CHECK_TYPE_EXC(self, OBJ(DICT_PROTO), "dict");
 
 	if (list_len(ist, parms[1]) > 1) {
 		raise_exception(ist, OBJ(INTERPRETER_EXC), "slice not allowed in dictionary indexing");
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.