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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
|
/***************************************************************************
template_cmds.c - template commands for xsldbg
-------------------
begin : Wed Nov 21 2001
copyright : (C) 2001 by Keith Isdale
email : [email protected]
***************************************************************************/
/***************************************************************************
* *
* 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 "debugXSL.h"
#include "files.h"
#include "utils.h"
#include "xsldbgmsg.h"
#include "xsldbgthread.h" /* for getThreadStatus */
static int printCounter; /* Dangerous name think of a better one */
/* -----------------------------------------
Private function declarations for files.c
-------------------------------------------*/
/**
* xslDbgShellPrintStylesheetsHelper:
* @payload :valid xxsltStylesheetPtr
* @data : not used
* name : not used
*
* Print out the stylesheet name from the stylesheet given to
* us via walkStylesheets
*/
void
xslDbgShellPrintStylesheetsHelper(void *payload,
void *data,
xmlChar * name);
/**
* xslDbgShellPrintStylesheetsHelper2:
* @payload :valid xmlNodePtr of included stylesheet
* @data : not used
* name : not used
*
* Print out the stylesheet name from the stylesheet given to
* us via walkIncludes
*/
void
xslDbgShellPrintStylesheetsHelper2(void *payload,
void *data,
xmlChar * name);
/**
* printTemplateHelper:
* @templ: Is valid
* @verbose: Either 1 or 0
* @templateCount: Is valid
* @count: Is valid
* @templateName: template name to print and in UTF-8, may be NULL
*
* This display the templates in the same order as they are in the
* stylesheet. If verbose is 1 then print more information
* For each template found @templateCount is increased
* For each printed template @printCount is increased
*/
void printTemplateHelper(xsltTemplatePtr templ, int verbose,
int *templateCount, int *count,
xmlChar * templateName);
/* -------------------------------------
End private functions
---------------------------------------*/
/**
* printTemplateHelper:
* @templ: Is valid
* @verbose: Either 1 or 0
* @templateCount: Is valid
* @count: Is valid
* @templateName: template name to print, may be NULL
*
* This display the templates in the same order as they are in the
* stylesheet. If verbose is 1 then print more information
* For each template found @templateCount is increased
* For each printed template @printCount is increased
*/
void
printTemplateHelper(xsltTemplatePtr templ, int verbose,
int *templateCount, int *count, xmlChar * templateName)
{
xmlChar *name, *defaultUrl = (xmlChar *) "<n/a>";
const xmlChar *url;
if (!templ)
return;
*templateCount = *templateCount + 1;
printTemplateHelper(templ->next, verbose,
templateCount, count, templateName);
if (templ->elem && templ->elem->doc && templ->elem->doc->URL) {
url = templ->elem->doc->URL;
} else {
url = defaultUrl;
}
if (templ->match)
name = xmlStrdup(templ->match);
else
name = fullTQName(templ->nameURI, templ->name);
if (name) {
if (templateName &&
(xmlStrcmp(templateName, name) != 0)) {
/* search for template name supplied failed */
/* empty */
} else {
xmlChar *modeTemp = NULL;
*count = *count + 1;
if (getThreadStatus() == XSLDBG_MSG_THREAD_RUN) {
notifyListQueue(templ);
} else {
modeTemp = fullTQName(templ->modeURI, templ->mode);
if (verbose)
xsldbgGenericErrorFunc(i18n(" template: \"%1\" mode: \"%2\" in file \"%3\" at line %4\n").tqarg(xsldbgText(name)).tqarg(xsldbgText(modeTemp)).tqarg(xsldbgUrl(url)).tqarg(xmlGetLineNo(templ->elem)));
else
xsldbgGenericErrorFunc(TQString("\"%s\" ").tqarg(xsldbgText(name)));
if (modeTemp)
xmlFree(modeTemp);
}
}
xmlFree(name);
}
}
/**
* xslDbgShellPrintTemplateNames:
* @styleCtxt: Is valid
* @ctxt: Not used
* @arg: Not used
* @verbose: If 1 then print extra messages about templates found,
* otherwise print normal messages only
* @allFiles: If 1 then look for all templates in stylsheets found in
* @styleCtxt
* otherwise look in the stylesheet found by
* debugXSLBreak function
*
* Print out the list of template names found that match critieria
*
* Returns 1 on success,
* 0 otherwise
*/
int
xslDbgShellPrintTemplateNames(xsltTransformContextPtr styleCtxt,
xmlShellCtxtPtr ctxt,
xmlChar * arg, int verbose, int allFiles)
{
Q_UNUSED(ctxt);
int templateCount = 0, printedTemplateCount = 0;
int result = 0;
xsltStylesheetPtr curStyle;
xsltTemplatePtr templ;
if (xmlStrLen(arg) == 0) {
arg = NULL;
} else {
allFiles = 1; /* make sure we find it if we can */
}
if (!styleCtxt) {
xsldbgGenericErrorFunc(i18n("Error: Stylesheet is not valid.\n"));
return result;
}
if (allFiles)
curStyle = styleCtxt->style;
else {
/* try to find files in the current stylesheet */
/* root copy is set to the stylesheet found by debugXSLBreak */
if (debugXSLGetTemplate())
curStyle = debugXSLGetTemplate()->style;
else
curStyle = NULL;
}
if (getThreadStatus() == XSLDBG_MSG_THREAD_RUN) {
notifyListStart(XSLDBG_MSG_TEMPLATE_CHANGED);
while (curStyle) {
templ = curStyle->templates;
/* print them out in the order their in the file */
printTemplateHelper(templ, verbose, &templateCount,
&printedTemplateCount, arg);
if (curStyle->next)
curStyle = curStyle->next;
else
curStyle = curStyle->imports;
}
notifyListSend();
} else {
xsltGenericError(xsltGenericErrorContext, "\n");
while (curStyle) {
templ = curStyle->templates;
/* print them out in the order their in the file */
printTemplateHelper(templ, verbose, &templateCount,
&printedTemplateCount, arg);
xsltGenericError(xsltGenericErrorContext, "\n");
if (curStyle->next)
curStyle = curStyle->next;
else
curStyle = curStyle->imports;
}
if (templateCount == 0) {
xsldbgGenericErrorFunc(i18n("\tNo XSLT templates found.\n"));
} else {
xsldbgGenericErrorFunc(i18n("\tTotal of %n XSLT template found", "\tTotal of %n XSLT templates found", templateCount) + TQString("\n"));
xsldbgGenericErrorFunc(i18n("\tTotal of %n XSLT template printed", "\tTotal of %n XSLT templates printed", printedTemplateCount) + TQString("\n"));
}
}
result = 1;
return result;
}
/**
* xslDbgShellPrintStylesheetsHelper:
* @payload :valid xsltStylesheetPtr
* @data : not used
* name : not used
*
* Print out the stylesheet name from the stylesheet given to
* us via walkStylesheets
*/
void
xslDbgShellPrintStylesheetsHelper(void *payload,
void *data,
xmlChar * name)
{
Q_UNUSED(data);
Q_UNUSED(name);
xsltStylesheetPtr style = (xsltStylesheetPtr) payload;
if (style && style->doc && style->doc->URL) {
if (getThreadStatus() == XSLDBG_MSG_THREAD_RUN)
notifyListQueue(payload);
else
/* display the URL of stylesheet */
xsldbgGenericErrorFunc(i18n(" Stylesheet %1\n").tqarg(xsldbgUrl(style->doc->URL)));
printCounter++;
}
}
/**
* xslDbgShellPrintStylesheetsHelper2:
* @payload :valid xmlNodePtr of included stylesheet
* @data : not used
* name : not used
*
* Print out the stylesheet name from the stylesheet given to
* us via walkIncludes
*/
void
xslDbgShellPrintStylesheetsHelper2(void *payload,
void *data,
xmlChar * name)
{
Q_UNUSED(data);
Q_UNUSED(name);
xmlNodePtr node = (xmlNodePtr) payload;
if (node && node->doc && node->doc->URL) {
if (getThreadStatus() == XSLDBG_MSG_THREAD_RUN)
notifyListQueue(payload);
else
/* display the URL of stylesheet */
xsldbgGenericErrorFunc(i18n(" Stylesheet %1\n").tqarg(xsldbgUrl(node->doc->URL)));
printCounter++;
}
}
/**
* xslDbgShellPrintStyleSheets:
* @arg: The stylesheets of interests and in UTF-8, is NULL for all stylsheets
*
* Print stylesheets that can be found in loaded stylsheet
*
* Returns 1 on success,
* 0 otherwise
*/
int
xslDbgShellPrintStyleSheets(xmlChar * arg)
{
Q_UNUSED(arg);
printCounter = 0;
if (getThreadStatus() == XSLDBG_MSG_THREAD_RUN) {
notifyListStart(XSLDBG_MSG_SOURCE_CHANGED);
walkStylesheets((xmlHashScanner) xslDbgShellPrintStylesheetsHelper,
NULL, filesGetStylesheet());
notifyListSend();
notifyListStart(XSLDBG_MSG_INCLUDED_SOURCE_CHANGED);
walkIncludes((xmlHashScanner) xslDbgShellPrintStylesheetsHelper2,
NULL, filesGetStylesheet());
notifyListSend();
} else {
walkStylesheets((xmlHashScanner) xslDbgShellPrintStylesheetsHelper,
NULL, filesGetStylesheet());
walkIncludes((xmlHashScanner) xslDbgShellPrintStylesheetsHelper2,
NULL, filesGetStylesheet());
if (printCounter != 0)
xsldbgGenericErrorFunc(i18n("\tTotal of %n XSLT stylesheet found.", "\tTotal of %n XSLT stylesheets found.", printCounter) + TQString("\n"));
else
/* strange but possible */
xsldbgGenericErrorFunc(i18n("\tNo XSLT stylesheets found.\n"));
}
return 1; /* always succeed */
}
|