summaryrefslogtreecommitdiffstats
path: root/contrib/expat/examples
diff options
context:
space:
mode:
authorcokane <cokane@FreeBSD.org>2008-05-08 13:51:16 +0000
committercokane <cokane@FreeBSD.org>2008-05-08 13:51:16 +0000
commiteef7fc6660961eb9e0913c4fe68b72df0f9fb8c3 (patch)
tree140a049e6dfd3941649feaf205e3a527a7543b00 /contrib/expat/examples
parent676528b41eb1d7ef205f19c99dcb9585d9105d85 (diff)
downloadFreeBSD-src-eef7fc6660961eb9e0913c4fe68b72df0f9fb8c3.zip
FreeBSD-src-eef7fc6660961eb9e0913c4fe68b72df0f9fb8c3.tar.gz
Virgin import (trimmed) of eXpat v2.0.1. Discussed and tested with
sam and phk who are the two consumers of this library. If there is any other fallout, email me and I will take care of it. Approved by: sam, phk
Diffstat (limited to 'contrib/expat/examples')
-rw-r--r--contrib/expat/examples/elements.c27
-rw-r--r--contrib/expat/examples/outline.c24
2 files changed, 41 insertions, 10 deletions
diff --git a/contrib/expat/examples/elements.c b/contrib/expat/examples/elements.c
index 4ed4da6..6b8f855 100644
--- a/contrib/expat/examples/elements.c
+++ b/contrib/expat/examples/elements.c
@@ -2,26 +2,41 @@
reads an XML document from standard input and writes a line with
the name of each element to standard output indenting child
elements by one tab stop more than their parent element.
+ It must be used with Expat compiled for UTF-8 output.
*/
#include <stdio.h>
#include "expat.h"
-static void
+#if defined(__amigaos__) && defined(__USE_INLINE__)
+#include <proto/expat.h>
+#endif
+
+#ifdef XML_LARGE_SIZE
+#if defined(XML_USE_MSC_EXTENSIONS) && _MSC_VER < 1400
+#define XML_FMT_INT_MOD "I64"
+#else
+#define XML_FMT_INT_MOD "ll"
+#endif
+#else
+#define XML_FMT_INT_MOD "l"
+#endif
+
+static void XMLCALL
startElement(void *userData, const char *name, const char **atts)
{
int i;
- int *depthPtr = userData;
+ int *depthPtr = (int *)userData;
for (i = 0; i < *depthPtr; i++)
putchar('\t');
puts(name);
*depthPtr += 1;
}
-static void
+static void XMLCALL
endElement(void *userData, const char *name)
{
- int *depthPtr = userData;
+ int *depthPtr = (int *)userData;
*depthPtr -= 1;
}
@@ -35,11 +50,11 @@ main(int argc, char *argv[])
XML_SetUserData(parser, &depth);
XML_SetElementHandler(parser, startElement, endElement);
do {
- size_t len = fread(buf, 1, sizeof(buf), stdin);
+ int len = (int)fread(buf, 1, sizeof(buf), stdin);
done = len < sizeof(buf);
if (XML_Parse(parser, buf, len, done) == XML_STATUS_ERROR) {
fprintf(stderr,
- "%s at line %d\n",
+ "%s at line %" XML_FMT_INT_MOD "u\n",
XML_ErrorString(XML_GetErrorCode(parser)),
XML_GetCurrentLineNumber(parser));
return 1;
diff --git a/contrib/expat/examples/outline.c b/contrib/expat/examples/outline.c
index 10f6d1d..3a3c838 100644
--- a/contrib/expat/examples/outline.c
+++ b/contrib/expat/examples/outline.c
@@ -18,19 +18,34 @@
*
* Read an XML document from standard input and print an element
* outline on standard output.
+ * Must be used with Expat compiled for UTF-8 output.
*/
#include <stdio.h>
#include <expat.h>
+#if defined(__amigaos__) && defined(__USE_INLINE__)
+#include <proto/expat.h>
+#endif
+
+#ifdef XML_LARGE_SIZE
+#if defined(XML_USE_MSC_EXTENSIONS) && _MSC_VER < 1400
+#define XML_FMT_INT_MOD "I64"
+#else
+#define XML_FMT_INT_MOD "ll"
+#endif
+#else
+#define XML_FMT_INT_MOD "l"
+#endif
+
#define BUFFSIZE 8192
char Buff[BUFFSIZE];
int Depth;
-static void
+static void XMLCALL
start(void *data, const char *el, const char **attr)
{
int i;
@@ -48,7 +63,7 @@ start(void *data, const char *el, const char **attr)
Depth++;
}
-static void
+static void XMLCALL
end(void *data, const char *el)
{
Depth--;
@@ -69,7 +84,7 @@ main(int argc, char *argv[])
int done;
int len;
- len = fread(Buff, 1, BUFFSIZE, stdin);
+ len = (int)fread(Buff, 1, BUFFSIZE, stdin);
if (ferror(stdin)) {
fprintf(stderr, "Read error\n");
exit(-1);
@@ -77,7 +92,7 @@ main(int argc, char *argv[])
done = feof(stdin);
if (XML_Parse(p, Buff, len, done) == XML_STATUS_ERROR) {
- fprintf(stderr, "Parse error at line %d:\n%s\n",
+ fprintf(stderr, "Parse error at line %" XML_FMT_INT_MOD "u:\n%s\n",
XML_GetCurrentLineNumber(p),
XML_ErrorString(XML_GetErrorCode(p)));
exit(-1);
@@ -86,5 +101,6 @@ main(int argc, char *argv[])
if (done)
break;
}
+ XML_ParserFree(p);
return 0;
}
OpenPOWER on IntegriCloud