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
38 static wchar_t *dump_string(const mpdm_t v
, wchar_t *ptr
, int *size
)
39 /* dumps a string, escaping special chars */
41 wchar_t *iptr
= mpdm_string(v
);
43 ptr
= mpdm_pokews(ptr
, size
, L
"\"");
45 while (*iptr
!= L
'\0') {
48 ptr
= mpdm_pokews(ptr
, size
, L
"\\\"");
52 ptr
= mpdm_pokews(ptr
, size
, L
"\\'");
56 ptr
= mpdm_pokews(ptr
, size
, L
"\\r");
60 ptr
= mpdm_pokews(ptr
, size
, L
"\\n");
64 ptr
= mpdm_pokews(ptr
, size
, L
"\\t");
68 ptr
= mpdm_pokews(ptr
, size
, L
"\\\\");
76 sprintf(tmp
, "\\x{%04x}", *iptr
);
77 wptr
= mpdm_mbstowcs(tmp
, NULL
, -1);
78 ptr
= mpdm_pokews(ptr
, size
, wptr
);
82 ptr
= mpdm_poke(ptr
, size
, iptr
, 1, sizeof(wchar_t));
89 ptr
= mpdm_pokews(ptr
, size
, L
"\"");
95 wchar_t *mpsl_dump_1(const mpdm_t v
, int l
, wchar_t *ptr
, int *size
)
96 /* dump plugin for mpdm_dump() */
103 /* indent (if negative, don't prepend indentation) */
107 for (n
= 0; n
< l
; n
++)
108 ptr
= mpdm_pokews(ptr
, size
, L
" ");
111 ptr
= mpdm_pokews(ptr
, size
, L
"NULL");
113 if (MPDM_IS_HASH(v
)) {
120 ptr
= mpdm_pokews(ptr
, size
, L
"{\n");
122 while (mpdm_iterator(v
, &c
, &k
, &w
)) {
124 ptr
= mpdm_pokews(ptr
, size
, L
",\n");
126 ptr
= mpsl_dump_1(k
, l
+ 1, ptr
, size
);
127 ptr
= mpdm_pokews(ptr
, size
, L
" => ");
128 ptr
= mpsl_dump_1(w
, -(l
+ 1), ptr
, size
);
131 ptr
= mpdm_pokews(ptr
, size
, L
"\n");
134 for (n
= 0; n
< l
; n
++)
135 ptr
= mpdm_pokews(ptr
, size
, L
" ");
137 ptr
= mpdm_pokews(ptr
, size
, L
"}");
140 if (MPDM_IS_ARRAY(v
)) {
141 ptr
= mpdm_pokews(ptr
, size
, L
"[\n");
143 for (n
= 0; n
< mpdm_size(v
); n
++) {
144 ptr
= mpsl_dump_1(mpdm_aget(v
, n
), l
+ 1, ptr
, size
);
146 if (n
< mpdm_size(v
) - 1)
147 ptr
= mpdm_pokews(ptr
, size
, L
",");
149 ptr
= mpdm_pokews(ptr
, size
, L
"\n");
153 for (n
= 0; n
< l
; n
++)
154 ptr
= mpdm_pokews(ptr
, size
, L
" ");
156 ptr
= mpdm_pokews(ptr
, size
, L
"]");
159 if (MPDM_IS_EXEC(v
)) {
160 snprintf(tmp
, sizeof(tmp
), "bincall(%p)", v
->data
);
161 wptr
= mpdm_mbstowcs(tmp
, NULL
, -1);
162 ptr
= mpdm_pokews(ptr
, size
, wptr
);
166 if (MPDM_IS_STRING(v
))
167 ptr
= dump_string(v
, ptr
, size
);
169 if (v
->flags
& MPDM_FILE
) {
172 f
= mpdm_get_filehandle(v
);
175 snprintf(tmp
, sizeof(tmp
), "NULL /* file descriptor: %d */", fileno(f
));
177 strcpy(tmp
, "NULL /* file descriptor (unknown handle) */");
179 wptr
= mpdm_mbstowcs(tmp
, NULL
, -1);
180 ptr
= mpdm_pokews(ptr
, size
, wptr
);
184 if (v
->flags
& MPDM_REGEX
)
185 ptr
= mpdm_pokews(ptr
, size
, L
"NULL /* compiled regular expression */");
187 snprintf(tmp
, sizeof(tmp
), "NULL /* non-printable value (flags: 0x%04x) */", v
->flags
);
188 wptr
= mpdm_mbstowcs(tmp
, NULL
, -1);
189 ptr
= mpdm_pokews(ptr
, size
, wptr
);
194 ptr
= mpdm_pokews(ptr
, size
, L
";\n");