(Debian) dpatch: debian/patches/412786_xmlwf_man_standard_fix.dpatch
[mirror-ossqm-expat.git] / examples / outline.c
blob3a3c8385512a22bdfb18bfc3ef48b1252a22244c
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.
21 * Must be used with Expat compiled for UTF-8 output.
25 #include <stdio.h>
26 #include <expat.h>
28 #if defined(__amigaos__) && defined(__USE_INLINE__)
29 #include <proto/expat.h>
30 #endif
32 #ifdef XML_LARGE_SIZE
33 #if defined(XML_USE_MSC_EXTENSIONS) && _MSC_VER < 1400
34 #define XML_FMT_INT_MOD "I64"
35 #else
36 #define XML_FMT_INT_MOD "ll"
37 #endif
38 #else
39 #define XML_FMT_INT_MOD "l"
40 #endif
42 #define BUFFSIZE 8192
44 char Buff[BUFFSIZE];
46 int Depth;
48 static void XMLCALL
49 start(void *data, const char *el, const char **attr)
51 int i;
53 for (i = 0; i < Depth; i++)
54 printf(" ");
56 printf("%s", el);
58 for (i = 0; attr[i]; i += 2) {
59 printf(" %s='%s'", attr[i], attr[i + 1]);
62 printf("\n");
63 Depth++;
66 static void XMLCALL
67 end(void *data, const char *el)
69 Depth--;
72 int
73 main(int argc, char *argv[])
75 XML_Parser p = XML_ParserCreate(NULL);
76 if (! p) {
77 fprintf(stderr, "Couldn't allocate memory for parser\n");
78 exit(-1);
81 XML_SetElementHandler(p, start, end);
83 for (;;) {
84 int done;
85 int len;
87 len = (int)fread(Buff, 1, BUFFSIZE, stdin);
88 if (ferror(stdin)) {
89 fprintf(stderr, "Read error\n");
90 exit(-1);
92 done = feof(stdin);
94 if (XML_Parse(p, Buff, len, done) == XML_STATUS_ERROR) {
95 fprintf(stderr, "Parse error at line %" XML_FMT_INT_MOD "u:\n%s\n",
96 XML_GetCurrentLineNumber(p),
97 XML_ErrorString(XML_GetErrorCode(p)));
98 exit(-1);
101 if (done)
102 break;
104 XML_ParserFree(p);
105 return 0;