1 /* Copyright (C) 2013 MORIOKA Tomohiko
2 This file is part of the CONCORD Library.
4 The CONCORD Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The CONCORD Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the CONCORD Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 #include "cos-print.h"
23 cos_utf8_encode_char (int cid, unsigned char *dest, size_t size)
38 else if (cid <= 0x7FF)
42 dest[i++] = (cid >> 6) | 0xC0;
43 dest[i++] = (cid & 0x3F) | 0x80;
50 else if (cid <= 0xFFFF)
54 dest[i++] = (cid >> 12) | 0xE0;
55 dest[i++]= ((cid >> 6) & 0x3F) | 0x80;
56 dest[i++]= (cid & 0x3F) | 0x80;
63 else if (cid <= 0x1FFFFF)
67 dest[i++]= (cid >> 18) | 0xF0;
68 dest[i++]= ((cid >> 12) & 0x3F) | 0x80;
69 dest[i++]= ((cid >> 6) & 0x3F) | 0x80;
70 dest[i++]= (cid & 0x3F) | 0x80;
77 else if (cid <= 0x3FFFFFF)
81 dest[i++]= (cid >> 24) | 0xF8;
82 dest[i++]= ((cid >> 18) & 0x3F) | 0x80;
83 dest[i++]= ((cid >> 12) & 0x3F) | 0x80;
84 dest[i++]= ((cid >> 6) & 0x3F) | 0x80;
85 dest[i++]= (cid & 0x3F) | 0x80;
96 dest[i++]= (cid >> 30) | 0xFC;
97 dest[i++]= ((cid >> 24) & 0x3F) | 0x80;
98 dest[i++]= ((cid >> 18) & 0x3F) | 0x80;
99 dest[i++]= ((cid >> 12) & 0x3F) | 0x80;
100 dest[i++]= ((cid >> 6) & 0x3F) | 0x80;
101 dest[i++]= (cid & 0x3F) | 0x80;
111 cos_utf8_print_char (COS_object character, unsigned char *dest, size_t size)
113 int cid = cos_char_id (character);
124 else if (cid == '\n')
131 else if (cid == '\r')
138 else if (cid == 0x1C)
147 else if (cid <= 0x1F)
151 dest[i++] = '@' + cid;
155 else if ( (cid == ' ') || (cid == '"') ||
156 (cid == '#') || (cid == '\'') ||
157 (cid == '(') || (cid == ')') ||
158 (cid == ',') || (cid == '.') ||
159 (cid == ';') || (cid == '?') ||
160 (cid == '[') || (cid == '\\') ||
161 (cid == ']') || (cid == '`') )
168 else if (cid <= 0x7E)
174 else if (cid == 0x7F)
182 else if (cid <= 0x9F)
186 dest[i++] = ((cid + '@') >> 6) | 0xC0;
187 dest[i++] = ((cid + '@') & 0x3F) | 0x80;
191 else if (cid <= 0x7FF)
193 dest[i++] = (cid >> 6) | 0xC0;
194 dest[i++] = (cid & 0x3F) | 0x80;
198 else if (cid <= 0xFFFF)
200 dest[i++] = (cid >> 12) | 0xE0;
201 dest[i++]= ((cid >> 6) & 0x3F) | 0x80;
202 dest[i++]= (cid & 0x3F) | 0x80;
206 else if (cid <= 0x1FFFFF)
208 dest[i++]= (cid >> 18) | 0xF0;
209 dest[i++]= ((cid >> 12) & 0x3F) | 0x80;
210 dest[i++]= ((cid >> 6) & 0x3F) | 0x80;
211 dest[i++]= (cid & 0x3F) | 0x80;
215 else if (cid <= 0x3FFFFFF)
217 dest[i++]= (cid >> 24) | 0xF8;
218 dest[i++]= ((cid >> 18) & 0x3F) | 0x80;
219 dest[i++]= ((cid >> 12) & 0x3F) | 0x80;
220 dest[i++]= ((cid >> 6) & 0x3F) | 0x80;
221 dest[i++]= (cid & 0x3F) | 0x80;
227 dest[i++]= (cid >> 30) | 0xFC;
228 dest[i++]= ((cid >> 24) & 0x3F) | 0x80;
229 dest[i++]= ((cid >> 18) & 0x3F) | 0x80;
230 dest[i++]= ((cid >> 12) & 0x3F) | 0x80;
231 dest[i++]= ((cid >> 6) & 0x3F) | 0x80;
232 dest[i++]= (cid & 0x3F) | 0x80;
240 cos_print_object (COS_object obj)
243 printf ("#<NULL>", obj);
244 else if ( COS_OBJECT_INT_P (obj) )
245 printf ("%d", cos_int_value (obj));
246 else if ( COS_OBJECT_CHAR_P (obj) )
250 cos_utf8_print_char (obj, id_buf, 256);
251 printf ("%s", id_buf);
253 else if ( COS_OBJECT_STRING_P (obj) )
255 printf ("\"%s\"", cos_string_data (obj));
257 else if ( COS_OBJECT_SYMBOL_P (obj) )
259 printf ("%s", cos_string_data (cos_symbol_name (obj)));
261 else if ( COS_OBJECT_CONS_P (obj) )
263 COS_object rest = COS_CDR (obj);
266 cos_print_object (COS_CAR (obj));
267 while ( COS_OBJECT_CONS_P (rest) )
270 cos_print_object (COS_CAR (rest));
271 rest = COS_CDR (rest);
273 if ( rest != cos_Qnil )
276 cos_print_object (rest);
281 printf ("Object[0x%lX] is a fat object.\n",