1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
|
/***************************************************************************
option_cmds.c - implementation for option
related commands
-------------------
begin : Fri Feb 1 2001
copyright : (C) 2001 by Keith Isdale
email : k_isdale@tpg.com.au
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "xsldbg.h"
#include "utils.h"
#include "options.h"
#include "xsldbgmsg.h"
#include "xsldbgthread.h"
#include "debugXSL.h"
/**
* xslDbgShellSetOption:
* @arg : Is valid, and in the format <NAME> <VALUE>
*
* Set the value of an option
*
* Returns 1 on success,
* 0 otherwise
*/
int
xslDbgShellSetOption(xmlChar * arg)
{
int result = 0;
if (!arg) {
#ifdef WITH_XSLDBG_DEBUG_PROCESS
xsltGenericError(xsltGenericErrorContext,
"Error: NULL argument provided\n");
#endif
return result;
}
if (xmlStrLen(arg) > 0) {
xmlChar *opts[2];
long optValue;
long optID;
if (splitString(arg, 2, opts) == 2) {
bool invertOption = false;
optID = optionsGetOptionID(opts[0]);
if ((optID == -1) && (opts[0][0] == 'n') && (opts[0][1] == 'o')){
optID = optionsGetOptionID(&opts[0][2]);
if (optID != -1){
// invert the value the user provides
invertOption = true;
}
}
if (optID >= OPTIONS_FIRST_INT_OPTIONID) {
if (optID <= OPTIONS_LAST_INT_OPTIONID) {
/* handle setting integer option */
if ((xmlStrlen(opts[1]) == 0) ||
!sscanf((char *) opts[1], "%ld", &optValue)) {
xsldbgGenericErrorFunc(i18n("Error: Unable to parse %1 as an option value.\n").tqarg(xsldbgText(opts[1])));
} else {
if (invertOption)
optValue = !optValue;
result = optionsSetIntOption(OptionTypeEnum(optID), optValue);
}
} else {
/* handle setting a string option */
result = optionsSetStringOption(OptionTypeEnum(optID), opts[1]);
}
} else {
static xmlExternalEntityLoader xsldbgDefaultEntLoader = 0;
bool invertOption = false;
bool enableNet = false;
if (!xsldbgDefaultEntLoader)
xsldbgDefaultEntLoader = xmlGetExternalEntityLoader();
if (xmlStrEqual(opts[0], (const xmlChar *)"nonet" ))
invertOption = true;
if (xmlStrEqual(&opts[0][2*invertOption], (const xmlChar *)"net" )){
if (sscanf((char *) opts[1], "%ld", &optValue)) {
if (invertOption)
optValue = !optValue;
if (optValue)
enableNet = true;
result = true;
if (enableNet)
xmlSetExternalEntityLoader(xsldbgDefaultEntLoader);
else
xmlSetExternalEntityLoader(xmlNoNetExternalEntityLoader);
}else{
xsldbgGenericErrorFunc(i18n("Error: Unable to parse %1 as an option value.\n").tqarg(xsldbgText(opts[1])));
}
} else
xsldbgGenericErrorFunc(i18n("Error: Unknown option name %1.\n").tqarg(xsldbgText(opts[0])));
}
} else {
xsldbgGenericErrorFunc(i18n("Error: Missing arguments for the command %1.\n").tqarg("setoption"));
}
} else {
xsldbgGenericErrorFunc(i18n("Error: Missing arguments for the command %1.\n").tqarg("setoption"));
}
return result;
}
/**
* xslDbgShellOptions:
*
* Prints out values for user options
*
* Returns 1 on success,
* 0 otherwise
*/
int
xslDbgShellOptions(void)
{
int result = 1;
int optionIndex;
const xmlChar *optionName, *optionValue;
/* Print out the integer options and thier values */
if (getThreadtqStatus() != XSLDBG_MSG_THREAD_RUN) {
for (optionIndex = OPTIONS_XINCLUDE;
optionIndex <= OPTIONS_VERBOSE; optionIndex++) {
/* skip any non-user options */
optionName = optionsGetOptionName(OptionTypeEnum(optionIndex));
if (optionName && (optionName[0] != '*')) {
xsldbgGenericErrorFunc(i18n("Option %1 = %2\n").tqarg(xsldbgText(optionName)).tqarg(optionsGetIntOption(OptionTypeEnum(optionIndex))));
}
}
/* Print out the string options and thier values */
for (optionIndex = OPTIONS_OUTPUT_FILE_NAME;
optionIndex <= OPTIONS_DATA_FILE_NAME; optionIndex++) {
optionName = optionsGetOptionName(OptionTypeEnum(optionIndex));
if (optionName && (optionName[0] != '*')) {
optionValue = optionsGetStringOption(OptionTypeEnum(optionIndex));
if (optionValue) {
xsldbgGenericErrorFunc(i18n("Option %1 = \"%2\"\n").tqarg(xsldbgText(optionName)).tqarg((char*)optionValue));
} else {
xsldbgGenericErrorFunc(i18n("Option %1 = \"\"\n").tqarg(xsldbgText(optionName)));
}
}
}
xsldbgGenericErrorFunc("\n");
} else {
/* we are now notifying the application of the value of options */
parameterItemPtr paramItem;
notifyListStart(XSLDBG_MSG_INTOPTION_CHANGE);
/* send the integer options and their values */
for (optionIndex = OPTIONS_XINCLUDE;
optionIndex <= OPTIONS_VERBOSE; optionIndex++) {
/* skip any non-user options */
optionName = optionsGetOptionName(OptionTypeEnum(optionIndex));
if (optionName && (optionName[0] != '*')) {
paramItem = optionsParamItemNew(optionName, 0L);
if (!paramItem) {
notifyListSend(); /* send what ever we've got so far */
return 0; /* out of memory */
}
paramItem->intValue = optionsGetIntOption(OptionTypeEnum(optionIndex));
notifyListQueue(paramItem); /* this will be free later */
}
}
notifyListSend();
notifyListStart(XSLDBG_MSG_STRINGOPTION_CHANGE);
/* Send the string options and thier values */
for (optionIndex = OPTIONS_OUTPUT_FILE_NAME;
optionIndex <= OPTIONS_DATA_FILE_NAME; optionIndex++) {
optionName = optionsGetOptionName(OptionTypeEnum(optionIndex));
if (optionName && (optionName[0] != '*')) {
paramItem =
optionsParamItemNew(optionName,
optionsGetStringOption
(OptionTypeEnum(optionIndex)));
if (!paramItem) {
notifyListSend(); /* send what ever we've got so far */
return 0; /* out of memory */
} else
notifyListQueue(paramItem); /* this will be freed later */
}
}
notifyListSend();
}
return result;
}
/**
* xslDbgShellShowWatches:
* @styleCtxt: the current stylesheet context
* @ctxt: The current shell context
* @showWarnings : If 1 then showWarning messages,
* otherwise do not show warning messages
*
* Print the current watches and their values
*
* Returns 1 on success,
* 0 otherwise
*/
int xslDbgShellShowWatches(xsltTransformContextPtr styleCtxt,
xmlShellCtxtPtr ctx,int showWarnings)
{
int result = 0, counter;
xmlChar* watchExpression;
if ((showWarnings == 1) && (arrayListCount(optionsGetWatchList()) == 0)){
xsldbgGenericErrorFunc(i18n("\tNo expression watches set.\n"));
}
for ( counter = 0;
counter < arrayListCount(optionsGetWatchList());
counter++){
watchExpression = (xmlChar*)arrayListGet(optionsGetWatchList(), counter);
if (watchExpression){
xsldbgGenericErrorFunc(i18n(" WatchExpression %1 ").tqarg(counter + 1));
result = xslDbgShellCat(styleCtxt, ctx, watchExpression);
}else
break;
}
return result;
}
/**
* xslDbgShellAddWatch:
* @arg : A valid xPath of expression to watch the value of
*
* Add expression to list of expressions to watch value of
*
* Returns 1 on success,
* 0 otherwise
*/
int xslDbgShellAddWatch(xmlChar* arg)
{
int result = 0;
if (arg){
trimString(arg);
result = optionsAddWatch(arg);
if (!result)
xsldbgGenericErrorFunc(i18n("Error: Unable to add watch expression \"%1\". It already has been added or it cannot be watched.\n").tqarg(xsldbgText(arg)));
}
return result;
}
/**
* xslDbgShellDeleteWatch:
* @arg : A watch ID to remove or "*" to remove all watches
*
* Delete a given watch ID from our list of expressions to watch
*
* Returns 1 on success,
* 0 otherwise
*/
int xslDbgShellDeleteWatch(xmlChar* arg)
{
int result = 0;
long watchID;
if (arg){
trimString(arg);
if (arg[0] == '*') {
arrayListEmpty(optionsGetWatchList());
}else if ((xmlStrlen(arg) == 0) ||
!sscanf((char *) arg, "%ld", &watchID)) {
xsldbgGenericErrorFunc(i18n("Error: Unable to parse %1 as a watchID.\n").tqarg(xsldbgText(arg)));
return result;
} else {
result = optionsRemoveWatch(watchID);
if (!result)
xsldbgGenericErrorFunc(i18n("Error: Watch expression %1 does not exist.\n").tqarg(watchID));
}
}
return result;
}
|