Added info about VS 2005.
[mirror-ossqm-expat.git] / examples / outline.c
blobe77081951ddf97420ba03051c69904ebb5f70989
1 /*****************************************************************
2 * outline.c
4 * Copyright 1999, Clark Cooper
5 * All rights reserved.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the license contained in the
9 * COPYING file that comes with the expat distribution.
11 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
12 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
13 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
14 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
15 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
16 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
17 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 * Read an XML document from standard input and print an element
20 * outline on standard output.
24 #include <stdio.h>
25 #include <expat.h>
27 #define BUFFSIZE 8192
29 char Buff[BUFFSIZE];
31 int Depth;
33 static void XMLCALL
34 start(void *data, const char *el, const char **attr)
36 int i;
38 for (i = 0; i < Depth; i++)
39 printf(" ");
41 printf("%s", el);
43 for (i = 0; attr[i]; i += 2) {
44 printf(" %s='%s'", attr[i], attr[i + 1]);
47 printf("\n");
48 Depth++;
51 static void XMLCALL
52 end(void *data, const char *el)
54 Depth--;
57 #ifdef AMIGA_SHARED_LIB
58 #include <proto/expat.h>
59 int
60 amiga_main(int argc, char *argv[])
61 #else
62 int
63 main(int argc, char *argv[])
64 #endif
66 XML_Parser p = XML_ParserCreate(NULL);
67 if (! p) {
68 fprintf(stderr, "Couldn't allocate memory for parser\n");
69 exit(-1);
72 XML_SetElementHandler(p, start, end);
74 for (;;) {
75 int done;
76 int len;
78 len = fread(Buff, 1, BUFFSIZE, stdin);
79 if (ferror(stdin)) {
80 fprintf(stderr, "Read error\n");
81 exit(-1);
83 done = feof(stdin);
85 if (XML_Parse(p, Buff, len, done) == XML_STATUS_ERROR) {
86 fprintf(stderr, "Parse error at line %d:\n%s\n",
87 XML_GetCurrentLineNumber(p),
88 XML_ErrorString(XML_GetErrorCode(p)));
89 exit(-1);
92 if (done)
93 break;
95 return 0;