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
35 static wchar_t *dump_string(const mpdm_t v
, wchar_t *ptr
, int *size
)
36 /* dumps a string, escaping special chars */
38 wchar_t *iptr
= mpdm_string(v
);
40 ptr
= mpdm_poke(ptr
, size
, L
"\"", 1, sizeof(wchar_t));
42 while (*iptr
!= L
'\0') {
45 ptr
= mpdm_poke(ptr
, size
, L
"\\\"", 2, sizeof(wchar_t));
49 ptr
= mpdm_poke(ptr
, size
, L
"\\'", 2, sizeof(wchar_t));
53 ptr
= mpdm_poke(ptr
, size
, L
"\\r", 2, sizeof(wchar_t));
57 ptr
= mpdm_poke(ptr
, size
, L
"\\n", 2, sizeof(wchar_t));
61 ptr
= mpdm_poke(ptr
, size
, L
"\\t", 2, sizeof(wchar_t));
65 ptr
= mpdm_poke(ptr
, size
, L
"\\\\", 2, sizeof(wchar_t));
69 ptr
= mpdm_poke(ptr
, size
, iptr
, 1, sizeof(wchar_t));
75 ptr
= mpdm_poke(ptr
, size
, L
"\"", 1, sizeof(wchar_t));
81 wchar_t *mpsl_dump_1(const mpdm_t v
, int l
, wchar_t *ptr
, int *size
)
82 /* dump plugin for mpdm_dump() */
87 for (n
= 0; n
< l
; n
++)
88 ptr
= mpdm_poke(ptr
, size
, L
" ", 2, sizeof(wchar_t));
91 ptr
= mpdm_poke(ptr
, size
, L
"NULL", 4, sizeof(wchar_t));
93 if (MPDM_IS_EXEC(v
)) {
94 ptr
= mpdm_poke(ptr
, size
, L
"sub { 1; }", 10, sizeof(wchar_t));
97 if (MPDM_IS_HASH(v
)) {
98 mpdm_t a
= mpdm_keys(v
);
100 ptr
= mpdm_poke(ptr
, size
, L
"{\n", 2, sizeof(wchar_t));
102 for (n
= 0; n
< mpdm_size(a
); n
++) {
103 mpdm_t k
= mpdm_aget(a
, n
);
104 mpdm_t w
= mpdm_hget(v
, k
);
106 ptr
= mpsl_dump_1(k
, l
+ 1, ptr
, size
);
107 ptr
= mpdm_poke(ptr
, size
, L
" => ", 4, sizeof(wchar_t));
108 ptr
= mpsl_dump_1(w
, l
+ 1, ptr
, size
);
110 if (n
< mpdm_size(a
) - 1)
111 ptr
= mpdm_poke(ptr
, size
, L
",", 1, sizeof(wchar_t));
113 ptr
= mpdm_poke(ptr
, size
, L
"\n", 1, sizeof(wchar_t));
117 for (n
= 0; n
< l
; n
++)
118 ptr
= mpdm_poke(ptr
, size
, L
" ", 2, sizeof(wchar_t));
120 ptr
= mpdm_poke(ptr
, size
, L
"}", 1, sizeof(wchar_t));
123 if (MPDM_IS_ARRAY(v
)) {
124 ptr
= mpdm_poke(ptr
, size
, L
"[\n", 2, sizeof(wchar_t));
126 for (n
= 0; n
< mpdm_size(v
); n
++) {
127 ptr
= mpsl_dump_1(mpdm_aget(v
, n
), l
+ 1, ptr
, size
);
129 if (n
< mpdm_size(v
) - 1)
130 ptr
= mpdm_poke(ptr
, size
, L
",", 1, sizeof(wchar_t));
132 ptr
= mpdm_poke(ptr
, size
, L
"\n", 1, sizeof(wchar_t));
136 for (n
= 0; n
< l
; n
++)
137 ptr
= mpdm_poke(ptr
, size
, L
" ", 2, sizeof(wchar_t));
139 ptr
= mpdm_poke(ptr
, size
, L
"]", 1, sizeof(wchar_t));
142 if (MPDM_IS_STRING(v
))
143 ptr
= dump_string(v
, ptr
, size
);