[sane-devel] sane-desc to xml (new patch)
jose
jgato@lambdaux.com
Mon, 05 Jul 2004 11:58:09 +0200
--=-V9ECFqTA5PamXiz3OKtM
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
Hi again, I have a new patch for the XML output of sane-desc:
- Now the XML document have a XML root.
- New tag for the document marked as "new".
- Some bug fixed...
I have being using the XML output for make a perl parser and have all
the information in a sql database so I think the xml is correct.
Bye....
--=-V9ECFqTA5PamXiz3OKtM
Content-Disposition: attachment; filename=sane-desc-xml.patch
Content-Type: text/plain; name=sane-desc-xml.patch; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
--- sane-desc.c Fri Jul 2 10:24:30 2004
+++ sane-desc_new.c Fri Jul 2 10:24:08 2004
@@ -1,7 +1,7 @@
/*
sane-desc.c -- generate list of supported SANE devices
- Copyright (C) 2002-2004 Henning Meier-Geinitz <henning@meier-geinitz.de>
+ Copyright (C) 2002, 2003 Henning Meier-Geinitz <henning@meier-geinitz.de>
This file is part of the SANE package.
@@ -21,7 +21,7 @@
MA 02111-1307, USA.
*/
-#define SANE_DESC_VERSION "2.4"
+#define SANE_DESC_VERSION "2.3"
#define MAN_PAGE_LINK "http://www.sane-project.org/man/%s.5.html"
#define COLOR_MINIMAL "\"#B00000\""
@@ -261,14 +261,14 @@
print_version (void)
{
printf ("sane-desc %s (%s)\n", SANE_DESC_VERSION, PACKAGE_STRING);
- printf ("Copyright (C) 2002-2004 Henning Meier-Geinitz "
+ printf ("Copyright (C) 2002 Henning Meier-Geinitz "
"<henning@meier-geinitz.de>\n"
"sane-desc comes with NO WARRANTY, to the extent permitted by "
"law.\n"
"You may redistribute copies of sane-desc under the terms of the "
"GNU General\n"
"Public License.\n"
- "For more information about these matters, see the file named "
+ "For more information about these matters, see the files named "
"COPYING.\n");
}
@@ -1615,6 +1615,51 @@
} /* while (be) */
}
+
+static char *
+clean_string(char *c)
+{
+ /*not avoided characters*/
+
+ char *aux;
+
+
+ aux=malloc(strlen(c)*sizeof(char)+100);
+ *aux='\0';
+
+ while (*c!='\0')
+ {
+
+ switch (*c)
+ {
+ case '<':
+ aux=strcat(aux,"<");
+ break;
+ case '>':
+ aux=strcat(aux,">");
+ break;
+ case '¡':
+ aux=strcat(aux,"!");
+ break;
+ case '¿':
+ aux=strcat(aux,"?");
+ break;
+ case '\'':
+ aux=strcat(aux,"'");
+ break;
+ case '&':
+ aux=strcat(aux,"&");
+ break;
+ default:
+ aux=strncat(aux,c,1);
+ }
+
+
+ c=c+1;
+ }
+ return aux;
+}
+
/* Print an XML list with all the information we have */
static void
xml_print_backends (void)
@@ -1622,82 +1667,88 @@
backend_entry *be;
be = first_backend;
+ printf("<backends>\n");
while (be)
{
url_entry *url = be->url;
type_entry *type = be->type;
+ clean_string(be->name);
if (be->name)
- printf ("<backend name=\"%s\">\n",be->name);
+ printf ("<backend name=\"%s\">\n",clean_string(be->name));
else
printf ("<backend name=\"*none\">\n");
if (be->version)
- printf ("<version>%s</version> \n", be->version);
+ printf ("<version>%s</version> \n", clean_string(be->version));
else
printf ("<version>*none*</version>\n");
- if (be->new)
- printf (" NEW!\n");
+ if (be->new)
+ printf ("<new state=\"yes\"/>\n");
+ else
+ printf ("<new state=\"no\"/>\n");
+
if (be->manpage)
- printf (" <manpage>%s</manpage>\n", be->manpage);
+ printf (" <manpage>%s</manpage>\n", clean_string(be->manpage));
else
printf (" <manpage>*none*</manpage>\n");
if (url)
while (url)
{
- printf (" <url>%s</url>\n", url->name);
+ printf (" <url>%s</url>\n", clean_string(url->name));
url = url->next;
}
else
printf (" <url>*none*</url>\n");
if (be->comment)
- printf (" <comment>%s</comment>\n", be->comment);
+ printf (" <comment>%s</comment>\n", clean_string(be->comment));
else
printf (" <comment>*none*</comment>\n");
if (type)
while (type)
{
+
switch (type->type)
{
case type_scanner:
- printf (" <type>scanner</type>\n");
+ printf (" <type def=\"scanner\">\n");
break;
case type_stillcam:
- printf (" <type>stillcam</type>\n");
+ printf (" <type def=\"stillcam\">\n");
break;
case type_vidcam:
- printf (" <type>vidcam </type>\n");
+ printf (" <type def=\"vidcam\">\n");
break;
case type_meta:
- printf (" <type>meta</type>\n");
+ printf (" <type def=\"meta\">\n");
break;
case type_api:
- printf (" <type>api</type>\n");
+ printf (" <type def=\"api\">\n");
break;
default:
- printf (" <type> *unknown* </type>\n");
+ printf (" <type def=\"*unknown*\">\n");
break;
}
if (type->desc)
{
url_entry *url = type->desc->url;
- printf (" <desc>%s</desc>\n", type->desc->desc);
+ printf (" <desc>%s</desc>\n", clean_string(type->desc->desc));
if (url)
while (url)
{
- printf (" <url>%s</url>\n", url->name);
+ printf (" <url>%s</url>\n", clean_string(url->name));
url = url->next;
}
else
printf (" <url>*none*</url>\n");
if (type->desc->comment)
- printf (" <comment>%s</comment>\n", type->desc->comment);
+ printf (" <comment>%s</comment>\n",clean_string(type->desc->comment));
else
printf (" <comment>*none*</comment>\n");
}
@@ -1712,18 +1763,18 @@
model_entry *model = mfg->model;
url_entry *url = mfg->url;
- printf (" <mfg name=\"%s\">\n", mfg->name);
+ printf (" <mfg name=\"%s\">\n", clean_string(mfg->name));
if (url)
while (url)
{
- printf (" <url>`%s'</url>\n", url->name);
+ printf (" <url>`%s'</url>\n", clean_string(url->name));
url = url->next;
}
else
printf (" <url>*none*</url>\n");
if (mfg->comment)
- printf (" <comment>%s</comment>\n", mfg->comment);
+ printf (" <comment>%s</comment>\n", clean_string(mfg->comment));
else
printf (" <comment>*none*</comment>\n");
@@ -1731,9 +1782,9 @@
while (model)
{
url_entry *url = model->url;
- printf (" <model name=\"%s\">\n", model->name);
+ printf (" <model name=\"%s\">\n",clean_string(model->name));
if (model->interface)
- printf (" <interface>%s</interface>\n", model->interface);
+ printf (" <interface>%s</interface>\n", clean_string(model->interface));
else
printf (" <interface>*none*</interface>\n");
@@ -1767,14 +1818,14 @@
if (url)
while (url)
{
- printf (" <url>%s</url>\n", url->name);
+ printf (" <url>%s</url>\n", clean_string(url->name));
url = url->next;
}
else
printf (" <url>*none*</url>\n");
if (model->comment)
- printf (" <comment>%s</comment>\n", model->comment);
+ printf (" <comment>%s</comment>\n", clean_string(model->comment));
else
printf (" <comment>*none*</comment>\n");
@@ -1791,6 +1842,7 @@
else if (type->type < type_meta)
printf (" <mfg>*none*</mfg>\n");
type = type->next;
+ printf(" </type>\n");
} /* while (type) */
else
printf (" <type>*none*</type>\n");
@@ -1798,8 +1850,8 @@
be = be->next;
} /* while (be) */
+ printf("</backends>\n");
}
-
/* Generate a name used for <a name=...> HTML tags */
--=-V9ECFqTA5PamXiz3OKtM--