3 MPSL - Minimum Profit Scripting Language
4 Copyright (C) 2003/2009 Angel Ortega <angel@triptico.com>
6 mpsl_d.c - Minimum Profit Scripting Language debugging functions
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 http://www.triptico.com
37 static wchar_t *dump_string(const mpdm_t v
, wchar_t *ptr
, int *size
)
38 /* dumps a string, escaping special chars */
40 wchar_t *iptr
= mpdm_string(v
);
42 ptr
= mpdm_pokews(ptr
, size
, L
"\"");
44 while (*iptr
!= L
'\0') {
47 ptr
= mpdm_pokews(ptr
, size
, L
"\\\"");
51 ptr
= mpdm_pokews(ptr
, size
, L
"\\'");
55 ptr
= mpdm_pokews(ptr
, size
, L
"\\r");
59 ptr
= mpdm_pokews(ptr
, size
, L
"\\n");
63 ptr
= mpdm_pokews(ptr
, size
, L
"\\t");
67 ptr
= mpdm_pokews(ptr
, size
, L
"\\\\");
75 sprintf(tmp
, "\\x{%04x}", *iptr
);
76 wptr
= mpdm_mbstowcs(tmp
, NULL
, -1);
77 ptr
= mpdm_pokews(ptr
, size
, wptr
);
81 ptr
= mpdm_poke(ptr
, size
, iptr
, 1, sizeof(wchar_t));
88 ptr
= mpdm_pokews(ptr
, size
, L
"\"");
94 wchar_t *mpsl_dump_1(const mpdm_t v
, int l
, wchar_t *ptr
, int *size
)
95 /* dump plugin for mpdm_dump() */
99 /* indent (if negative, don't prepend indentation) */
103 for (n
= 0; n
< l
; n
++)
104 ptr
= mpdm_pokews(ptr
, size
, L
" ");
107 ptr
= mpdm_pokews(ptr
, size
, L
"NULL");
109 if (MPDM_IS_HASH(v
)) {
116 ptr
= mpdm_pokews(ptr
, size
, L
"{\n");
118 while (mpdm_iterator(v
, &c
, &k
, &w
)) {
120 ptr
= mpdm_pokews(ptr
, size
, L
",\n");
122 ptr
= mpsl_dump_1(k
, l
+ 1, ptr
, size
);
123 ptr
= mpdm_pokews(ptr
, size
, L
" => ");
124 ptr
= mpsl_dump_1(w
, -(l
+ 1), ptr
, size
);
127 ptr
= mpdm_pokews(ptr
, size
, L
"\n");
130 for (n
= 0; n
< l
; n
++)
131 ptr
= mpdm_pokews(ptr
, size
, L
" ");
133 ptr
= mpdm_pokews(ptr
, size
, L
"}");
136 if (MPDM_IS_ARRAY(v
)) {
137 ptr
= mpdm_pokews(ptr
, size
, L
"[\n");
139 for (n
= 0; n
< mpdm_size(v
); n
++) {
140 ptr
= mpsl_dump_1(mpdm_aget(v
, n
), l
+ 1, ptr
, size
);
142 if (n
< mpdm_size(v
) - 1)
143 ptr
= mpdm_pokews(ptr
, size
, L
",");
145 ptr
= mpdm_pokews(ptr
, size
, L
"\n");
149 for (n
= 0; n
< l
; n
++)
150 ptr
= mpdm_pokews(ptr
, size
, L
" ");
152 ptr
= mpdm_pokews(ptr
, size
, L
"]");
155 if (MPDM_IS_EXEC(v
)) {
159 snprintf(tmp
, sizeof(tmp
), "bincall(%p)", v
->data
);
160 wptr
= mpdm_mbstowcs(tmp
, NULL
, -1);
161 ptr
= mpdm_pokews(ptr
, size
, wptr
);
165 if (MPDM_IS_STRING(v
))
166 ptr
= dump_string(v
, ptr
, size
);
168 ptr
= mpdm_pokews(ptr
, size
, L
"NULL /* non-printable value */");
171 ptr
= mpdm_pokews(ptr
, size
, L
";\n");