1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-07-28 00:21:53 +03:00

integrating Keith Isdale patches for the XSLT debugger interfaces. Some

* include/libxml/debugXML.h debugXML.c tree.c: integrating
  Keith Isdale patches for the XSLT debugger interfaces. Some
  cleanup
Daniel
This commit is contained in:
Daniel Veillard
2001-10-11 09:12:24 +00:00
parent ff0b7311ec
commit 78d1209708
4 changed files with 805 additions and 522 deletions

View File

@ -1,3 +1,9 @@
Thu Oct 11 11:10:31 CEST 2001 Daniel Veillard <daniel@veillard.com>
* include/libxml/debugXML.h debugXML.c tree.c: integrating
Keith Isdale patches for the XSLT debugger interfaces. Some
cleanup
Thu Oct 11 08:44:01 CEST 2001 Daniel Veillard <daniel@veillard.com>
* win32/Makefile.mingw: update from Tobias Peters for 2.4.5

View File

@ -1002,7 +1002,7 @@ xmlDebugDumpEntities(FILE * output, xmlDocPtr doc)
fprintf(output, "No entities in external subset\n");
}
static int xmlLsCountNode(xmlNodePtr node) {
int xmlLsCountNode(xmlNodePtr node) {
int ret = 0;
xmlNodePtr list = NULL;
@ -1052,7 +1052,7 @@ static int xmlLsCountNode(xmlNodePtr node) {
return(ret);
}
static void
void
xmlLsOneNode(FILE *output, xmlNodePtr node) {
switch (node->type) {
case XML_ELEMENT_NODE:
@ -1159,12 +1159,57 @@ xmlLsOneNode(FILE *output, xmlNodePtr node) {
fprintf(output, "\n");
}
/**
* xmlBoolToText:
* @bool : a bool to turn into text
*
* Convenient way to turn bool into text
*/
const char *
xmlBoolToText(int bool)
{
if (bool)
return("True");
else
return("False");
}
/**
* xmlGetLineNo:
* @node : valid node
*
* Get line number of node
*
* Returns the line number if sucessfull, -1 otherwise
*/
long
xmlGetLineNo(xmlNodePtr node)
{
long result = -1;
if (!node)
return result;
if (node->type == XML_ELEMENT_NODE)
result = (long) node->content;
else if ((node->prev != NULL) &&
(node->prev->type == XML_ELEMENT_NODE))
result = (long) node->prev->content;
else if ((node->parent != NULL) &&
(node->parent->type == XML_ELEMENT_NODE))
result = (long) node->parent->content;
return result;
}
/****************************************************************
* *
* The XML shell related functions *
* *
****************************************************************/
/*
* TODO: Improvement/cleanups for the XML shell
* - allow to shell out an editor on a subpart
@ -1172,6 +1217,139 @@ xmlLsOneNode(FILE *output, xmlNodePtr node) {
* - provide registration routines
*/
/**
* xmlShellPrintXpathError:
* @errorType: valid xpath error id
* @arg : the argument that cause xpath to fail
*
* Print the xpath error to libxml default error channel
*/
void
xmlShellPrintXPathError(int errorType, const char *arg)
{
const char *default_arg = "Result";
if (!arg)
arg = default_arg;
switch (errorType) {
case XPATH_UNDEFINED:
xmlGenericError(xmlGenericErrorContext,
"%s: no such node\n", arg);
break;
case XPATH_BOOLEAN:
xmlGenericError(xmlGenericErrorContext,
"%s is a Boolean\n", arg);
break;
case XPATH_NUMBER:
xmlGenericError(xmlGenericErrorContext,
"%s is a number\n", arg);
break;
case XPATH_STRING:
xmlGenericError(xmlGenericErrorContext,
"%s is a string\n", arg);
break;
case XPATH_POINT:
xmlGenericError(xmlGenericErrorContext,
"%s is a point\n", arg);
break;
case XPATH_RANGE:
xmlGenericError(xmlGenericErrorContext,
"%s is a range\n", arg);
break;
case XPATH_LOCATIONSET:
xmlGenericError(xmlGenericErrorContext,
"%s is a range\n", arg);
break;
case XPATH_USERS:
xmlGenericError(xmlGenericErrorContext,
"%s is user-defined\n", arg);
break;
case XPATH_XSLT_TREE:
xmlGenericError(xmlGenericErrorContext,
"%s is an XSLT value tree\n", arg);
break;
}
xmlGenericError(xmlGenericErrorContext,
"Try casting the result string function (xpath builtin)\n",
arg);
}
/**
* xmlShellPrintNode:
* @node : a non-null node to print to stdout
*
* Print node to stdout
*/
void
xmlShellPrintNode(xmlNodePtr node)
{
if (!node)
return;
if (node->type == XML_DOCUMENT_NODE)
xmlDocDump(stdout, (xmlDocPtr) node);
else if (node->type == XML_ATTRIBUTE_NODE)
xmlDebugDumpAttrList(stdout, (xmlAttrPtr) node, 0);
else
xmlElemDump(stdout, node->doc, node);
fprintf(stdout, "\n");
}
/**
* xmlShellPrintXPathResult:
* list : a valid result generated by an xpath evaluation
*
* Prints result to stdout
*/
void
xmlShellPrintXPathResult(xmlXPathObjectPtr list)
{
int i = 0;
if (list != NULL) {
switch (list->type) {
case XPATH_NODESET:{
int indx;
if (list->nodesetval) {
for (indx = 0; indx < list->nodesetval->nodeNr;
indx++) {
if (i > 0)
fprintf(stderr, " -------\n");
xmlShellPrintNode(list->nodesetval->
nodeTab[indx]);
}
} else {
xmlGenericError(xmlGenericErrorContext,
"Empty node set\n");
}
break;
}
case XPATH_BOOLEAN:
xmlGenericError(xmlGenericErrorContext,
"Is a Boolean:%s\n",
xmlBoolToText(list->boolval));
break;
case XPATH_NUMBER:
xmlGenericError(xmlGenericErrorContext,
"Is a number:%0g\n", list->floatval);
break;
case XPATH_STRING:
xmlGenericError(xmlGenericErrorContext,
"Is a string:%s\n", list->stringval);
break;
default:
xmlShellPrintXPathError(list->type, NULL);
}
}
}
/**
* xmlShellList:
* @ctxt: the shell context
@ -1184,9 +1362,11 @@ xmlLsOneNode(FILE *output, xmlNodePtr node) {
*
* Returns 0
*/
static int
xmlShellList(xmlShellCtxtPtr ctxt ATTRIBUTE_UNUSED , char *arg ATTRIBUTE_UNUSED, xmlNodePtr node,
xmlNodePtr node2 ATTRIBUTE_UNUSED) {
int
xmlShellList(xmlShellCtxtPtr ctxt ATTRIBUTE_UNUSED,
char *arg ATTRIBUTE_UNUSED, xmlNodePtr node,
xmlNodePtr node2 ATTRIBUTE_UNUSED)
{
xmlNodePtr cur;
if ((node->type == XML_DOCUMENT_NODE) ||
@ -1217,9 +1397,11 @@ xmlShellList(xmlShellCtxtPtr ctxt ATTRIBUTE_UNUSED , char *arg ATTRIBUTE_UNUSED,
*
* Returns 0
*/
static int
xmlShellBase(xmlShellCtxtPtr ctxt ATTRIBUTE_UNUSED, char *arg ATTRIBUTE_UNUSED, xmlNodePtr node,
xmlNodePtr node2 ATTRIBUTE_UNUSED) {
int
xmlShellBase(xmlShellCtxtPtr ctxt ATTRIBUTE_UNUSED,
char *arg ATTRIBUTE_UNUSED, xmlNodePtr node,
xmlNodePtr node2 ATTRIBUTE_UNUSED)
{
xmlChar *base;
base = xmlNodeGetBase(node->doc, node);
@ -1245,9 +1427,11 @@ xmlShellBase(xmlShellCtxtPtr ctxt ATTRIBUTE_UNUSED, char *arg ATTRIBUTE_UNUSED,
*
* Returns 0
*/
static int
xmlShellDir(xmlShellCtxtPtr ctxt ATTRIBUTE_UNUSED, char *arg ATTRIBUTE_UNUSED, xmlNodePtr node,
xmlNodePtr node2 ATTRIBUTE_UNUSED) {
int
xmlShellDir(xmlShellCtxtPtr ctxt ATTRIBUTE_UNUSED,
char *arg ATTRIBUTE_UNUSED, xmlNodePtr node,
xmlNodePtr node2 ATTRIBUTE_UNUSED)
{
if ((node->type == XML_DOCUMENT_NODE) ||
(node->type == XML_HTML_DOCUMENT_NODE)) {
xmlDebugDumpDocumentHead(stdout, (xmlDocPtr) node);
@ -1271,9 +1455,10 @@ xmlShellDir(xmlShellCtxtPtr ctxt ATTRIBUTE_UNUSED, char *arg ATTRIBUTE_UNUSED, x
*
* Returns 0
*/
static int
xmlShellCat(xmlShellCtxtPtr ctxt, char *arg ATTRIBUTE_UNUSED, xmlNodePtr node,
xmlNodePtr node2 ATTRIBUTE_UNUSED) {
int
xmlShellCat(xmlShellCtxtPtr ctxt, char *arg ATTRIBUTE_UNUSED,
xmlNodePtr node, xmlNodePtr node2 ATTRIBUTE_UNUSED)
{
if (ctxt->doc->type == XML_HTML_DOCUMENT_NODE) {
#ifdef LIBXML_HTML_ENABLED
if (node->type == XML_HTML_DOCUMENT_NODE)
@ -1308,9 +1493,11 @@ xmlShellCat(xmlShellCtxtPtr ctxt, char *arg ATTRIBUTE_UNUSED, xmlNodePtr node,
*
* Returns 0 or -1 if loading failed
*/
static int
xmlShellLoad(xmlShellCtxtPtr ctxt, char *filename, xmlNodePtr node ATTRIBUTE_UNUSED,
xmlNodePtr node2 ATTRIBUTE_UNUSED) {
int
xmlShellLoad(xmlShellCtxtPtr ctxt, char *filename,
xmlNodePtr node ATTRIBUTE_UNUSED,
xmlNodePtr node2 ATTRIBUTE_UNUSED)
{
xmlDocPtr doc;
int html = 0;
@ -1360,9 +1547,10 @@ xmlShellLoad(xmlShellCtxtPtr ctxt, char *filename, xmlNodePtr node ATTRIBUTE_UNU
*
* Returns 0 or -1 in case of error
*/
static int
int
xmlShellWrite(xmlShellCtxtPtr ctxt, char *filename, xmlNodePtr node,
xmlNodePtr node2 ATTRIBUTE_UNUSED) {
xmlNodePtr node2 ATTRIBUTE_UNUSED)
{
if (node == NULL)
return (-1);
if ((filename == NULL) || (filename[0] == 0)) {
@ -1428,9 +1616,11 @@ xmlShellWrite(xmlShellCtxtPtr ctxt, char *filename, xmlNodePtr node,
*
* Returns 0 or -1 in case of error
*/
static int
xmlShellSave(xmlShellCtxtPtr ctxt, char *filename, xmlNodePtr node ATTRIBUTE_UNUSED,
xmlNodePtr node2 ATTRIBUTE_UNUSED) {
int
xmlShellSave(xmlShellCtxtPtr ctxt, char *filename,
xmlNodePtr node ATTRIBUTE_UNUSED,
xmlNodePtr node2 ATTRIBUTE_UNUSED)
{
if (ctxt->doc == NULL)
return (-1);
if ((filename == NULL) || (filename[0] == 0))
@ -1484,9 +1674,11 @@ xmlShellSave(xmlShellCtxtPtr ctxt, char *filename, xmlNodePtr node ATTRIBUTE_UNU
*
* Returns 0 or -1 in case of error
*/
static int
xmlShellValidate(xmlShellCtxtPtr ctxt, char *dtd, xmlNodePtr node ATTRIBUTE_UNUSED,
xmlNodePtr node2 ATTRIBUTE_UNUSED) {
int
xmlShellValidate(xmlShellCtxtPtr ctxt, char *dtd,
xmlNodePtr node ATTRIBUTE_UNUSED,
xmlNodePtr node2 ATTRIBUTE_UNUSED)
{
xmlValidCtxt vctxt;
int res = -1;
@ -1522,13 +1714,16 @@ xmlShellValidate(xmlShellCtxtPtr ctxt, char *dtd, xmlNodePtr node ATTRIBUTE_UNUS
*
* Returns 0 or -1 in case of error
*/
static int
xmlShellDu(xmlShellCtxtPtr ctxt ATTRIBUTE_UNUSED, char *arg ATTRIBUTE_UNUSED, xmlNodePtr tree,
xmlNodePtr node2 ATTRIBUTE_UNUSED) {
int
xmlShellDu(xmlShellCtxtPtr ctxt ATTRIBUTE_UNUSED,
char *arg ATTRIBUTE_UNUSED, xmlNodePtr tree,
xmlNodePtr node2 ATTRIBUTE_UNUSED)
{
xmlNodePtr node;
int indent = 0, i;
if (tree == NULL) return(-1);
if (tree == NULL)
return (-1);
node = tree;
while (node != NULL) {
if ((node->type == XML_DOCUMENT_NODE) ||
@ -1548,7 +1743,8 @@ xmlShellDu(xmlShellCtxtPtr ctxt ATTRIBUTE_UNUSED, char *arg ATTRIBUTE_UNUSED, xm
if ((node->type == XML_DOCUMENT_NODE) ||
(node->type == XML_HTML_DOCUMENT_NODE)) {
node = ((xmlDocPtr) node)->children;
} else if ((node->children != NULL) && (node->type != XML_ENTITY_REF_NODE)) {
} else if ((node->children != NULL)
&& (node->type != XML_ENTITY_REF_NODE)) {
/* deep first */
node = node->children;
indent++;
@ -1598,17 +1794,20 @@ xmlShellDu(xmlShellCtxtPtr ctxt ATTRIBUTE_UNUSED, char *arg ATTRIBUTE_UNUSED, xm
*
* Returns 0 or -1 in case of error
*/
static int
xmlShellPwd(xmlShellCtxtPtr ctxt ATTRIBUTE_UNUSED, char *buffer, xmlNodePtr node,
xmlNodePtr node2 ATTRIBUTE_UNUSED) {
int
xmlShellPwd(xmlShellCtxtPtr ctxt ATTRIBUTE_UNUSED, char *buffer,
xmlNodePtr node, xmlNodePtr node2 ATTRIBUTE_UNUSED)
{
xmlNodePtr cur, tmp, next;
char buf[500];
char sep;
const char *name;
char nametemp[100];
int occur = 0;
buffer[0] = 0;
if (node == NULL) return(-1);
if (node == NULL)
return (-1);
cur = node;
do {
name = "";
@ -1621,6 +1820,11 @@ xmlShellPwd(xmlShellCtxtPtr ctxt ATTRIBUTE_UNUSED, char *buffer, xmlNodePtr node
} else if (cur->type == XML_ELEMENT_NODE) {
sep = '/';
name = (const char *) cur->name;
if (cur->ns) {
snprintf(nametemp, 99, "%s:%s", cur->ns->prefix,
cur->name);
name = nametemp;
}
next = cur->parent;
/*
@ -1639,7 +1843,8 @@ xmlShellPwd(xmlShellCtxtPtr ctxt ATTRIBUTE_UNUSED, char *buffer, xmlNodePtr node
occur++;
tmp = tmp->next;
}
if (occur != 0) occur = 1;
if (occur != 0)
occur = 1;
} else
occur++;
} else if (cur->type == XML_ATTRIBUTE_NODE) {
@ -1684,7 +1889,8 @@ xmlShellPwd(xmlShellCtxtPtr ctxt ATTRIBUTE_UNUSED, char *buffer, xmlNodePtr node
*/
void
xmlShell(xmlDocPtr doc, char *filename, xmlShellReadlineFunc input,
FILE *output) {
FILE * output)
{
char prompt[500] = "/ > ";
char *cmdline = NULL, *cur;
int nbargs;
@ -1732,14 +1938,16 @@ xmlShell(xmlDocPtr doc, char *filename, xmlShellReadlineFunc input,
* Get a new command line
*/
cmdline = ctxt->input(prompt);
if (cmdline == NULL) break;
if (cmdline == NULL)
break;
/*
* Parse the command itself
*/
cur = cmdline;
nbargs = 0;
while ((*cur == ' ') || (*cur == '\t')) cur++;
while ((*cur == ' ') || (*cur == '\t'))
cur++;
i = 0;
while ((*cur != ' ') && (*cur != '\t') &&
(*cur != '\n') && (*cur != '\r')) {
@ -1748,13 +1956,15 @@ xmlShell(xmlDocPtr doc, char *filename, xmlShellReadlineFunc input,
command[i++] = *cur++;
}
command[i] = 0;
if (i == 0) continue;
if (i == 0)
continue;
nbargs++;
/*
* Parse the argument
*/
while ((*cur == ' ') || (*cur == '\t')) cur++;
while ((*cur == ' ') || (*cur == '\t'))
cur++;
i = 0;
while ((*cur != '\n') && (*cur != '\r') && (*cur != 0)) {
if (*cur == 0)
@ -1787,20 +1997,22 @@ xmlShell(xmlDocPtr doc, char *filename, xmlShellReadlineFunc input,
xmlMemShow(stdout, 0);
} else {
int len = 0;
sscanf(arg, "%d", &len);
xmlMemShow(stdout, len);
}
} else if (!strcmp(command, "pwd")) {
char dir[500];
if (!xmlShellPwd(ctxt, dir, ctxt->node, NULL))
printf("%s\n", dir);
} else if (!strcmp(command, "du")) {
xmlShellDu(ctxt, NULL, ctxt->node, NULL);
} else if (!strcmp(command, "base")) {
xmlShellBase(ctxt, NULL, ctxt->node, NULL);
} else if ((!strcmp(command, "ls")) ||
(!strcmp(command, "dir"))) {
} else if ((!strcmp(command, "ls")) || (!strcmp(command, "dir"))) {
int dir = (!strcmp(command, "dir"));
if (arg[0] == 0) {
if (dir)
xmlShellDir(ctxt, NULL, ctxt->node, NULL);
@ -1823,14 +2035,17 @@ xmlShell(xmlDocPtr doc, char *filename, xmlShellReadlineFunc input,
case XPATH_NODESET:{
int indx;
for (indx = 0;indx < list->nodesetval->nodeNr;
for (indx = 0;
indx < list->nodesetval->nodeNr;
indx++) {
if (dir)
xmlShellDir(ctxt, NULL,
list->nodesetval->nodeTab[indx], NULL);
list->nodesetval->
nodeTab[indx], NULL);
else
xmlShellList(ctxt, NULL,
list->nodesetval->nodeTab[indx], NULL);
list->nodesetval->
nodeTab[indx], NULL);
}
break;
}
@ -1864,7 +2079,8 @@ xmlShell(xmlDocPtr doc, char *filename, xmlShellReadlineFunc input,
break;
case XPATH_XSLT_TREE:
xmlGenericError(xmlGenericErrorContext,
"%s is an XSLT value tree\n", arg);
"%s is an XSLT value tree\n",
arg);
break;
}
#ifdef LIBXML_XPATH_ENABLED
@ -1898,7 +2114,8 @@ xmlShell(xmlDocPtr doc, char *filename, xmlShellReadlineFunc input,
} else
xmlGenericError(xmlGenericErrorContext,
"%s is a %d Node Set\n",
arg, list->nodesetval->nodeNr);
arg,
list->nodesetval->nodeNr);
break;
case XPATH_BOOLEAN:
xmlGenericError(xmlGenericErrorContext,
@ -1930,7 +2147,8 @@ xmlShell(xmlDocPtr doc, char *filename, xmlShellReadlineFunc input,
break;
case XPATH_XSLT_TREE:
xmlGenericError(xmlGenericErrorContext,
"%s is an XSLT value tree\n", arg);
"%s is an XSLT value tree\n",
arg);
break;
}
#ifdef LIBXML_XPATH_ENABLED
@ -1962,11 +2180,14 @@ xmlShell(xmlDocPtr doc, char *filename, xmlShellReadlineFunc input,
case XPATH_NODESET:{
int indx;
for (indx = 0;indx < list->nodesetval->nodeNr;
for (indx = 0;
indx < list->nodesetval->nodeNr;
indx++) {
if (i > 0) printf(" -------\n");
if (i > 0)
printf(" -------\n");
xmlShellCat(ctxt, NULL,
list->nodesetval->nodeTab[indx], NULL);
list->nodesetval->
nodeTab[indx], NULL);
}
break;
}
@ -2000,7 +2221,8 @@ xmlShell(xmlDocPtr doc, char *filename, xmlShellReadlineFunc input,
break;
case XPATH_XSLT_TREE:
xmlGenericError(xmlGenericErrorContext,
"%s is an XSLT value tree\n", arg);
"%s is an XSLT value tree\n",
arg);
break;
}
#ifdef LIBXML_XPATH_ENABLED

View File

@ -47,6 +47,12 @@ void xmlDebugDumpDTD (FILE *output,
void xmlDebugDumpEntities (FILE *output,
xmlDocPtr doc);
void xmlLsOneNode (FILE *output, xmlNodePtr node);
int xmlLsCountNode (xmlNodePtr node);
const char *xmlBoolToText (int bool);
long xmlGetLineNo (xmlNodePtr node);
/****************************************************************
* *
* The XML shell related structures and functions *
@ -97,6 +103,50 @@ typedef int (* xmlShellCmd) (xmlShellCtxtPtr ctxt,
xmlNodePtr node,
xmlNodePtr node2);
void xmlShellPrintXPathError (int errorType, const char* arg);
void xmlShellPrintNode (xmlNodePtr node);
void xmlShellPrintXPathResult(xmlXPathObjectPtr list);
int xmlShellList (xmlShellCtxtPtr ctxt,
char *arg,
xmlNodePtr node,
xmlNodePtr node2);
int xmlShellBase (xmlShellCtxtPtr ctxt,
char *arg,
xmlNodePtr node,
xmlNodePtr node2);
int xmlShellDir (xmlShellCtxtPtr ctxt,
char *arg,
xmlNodePtr node,
xmlNodePtr node2);
int xmlShellCat (xmlShellCtxtPtr ctxt,
char *arg,
xmlNodePtr node,
xmlNodePtr node2);
int xmlShellLoad (xmlShellCtxtPtr ctxt,
char *filename,
xmlNodePtr node,
xmlNodePtr node2);
int xmlShellWrite (xmlShellCtxtPtr ctxt,
char *filename,
xmlNodePtr node,
xmlNodePtr node2);
int xmlShellSave (xmlShellCtxtPtr ctxt,
char *filename,
xmlNodePtr node,
xmlNodePtr node2);
int xmlShellValidate (xmlShellCtxtPtr ctxt,
char *dtd,
xmlNodePtr node,
xmlNodePtr node2);
int xmlShellDu (xmlShellCtxtPtr ctxt,
char *arg,
xmlNodePtr tree,
xmlNodePtr node2);
int xmlShellPwd (xmlShellCtxtPtr ctxt,
char *buffer,
xmlNodePtr node,
xmlNodePtr node2);
/*
* The Shell interface.
*/

5
tree.c
View File

@ -5479,6 +5479,10 @@ xmlNodeDump(xmlBufferPtr buf, xmlDocPtr doc, xmlNodePtr cur, int level,
xmlDumpElementDecl(buf, (xmlElementPtr) cur);
return;
}
if (cur->type == XML_ATTRIBUTE_NODE){
xmlAttrDump(buf, doc, (xmlAttrPtr)cur);
return;
}
if (cur->type == XML_ATTRIBUTE_DECL) {
xmlDumpAttributeDecl(buf, (xmlAttributePtr) cur);
return;
@ -5653,6 +5657,7 @@ xmlElemDump(FILE *f, xmlDocPtr doc, xmlNodePtr cur) {
"xmlElemDump : doc == NULL\n");
}
#endif
buf = xmlBufferCreate();
if (buf == NULL) return;
if ((doc != NULL) &&