outline.c (104349) | outline.c (178848) |
---|---|
1/***************************************************************** 2 * outline.c 3 * 4 * Copyright 1999, Clark Cooper 5 * All rights reserved. 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the license contained in the --- 4 unchanged lines hidden (view full) --- 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. 18 * 19 * Read an XML document from standard input and print an element 20 * outline on standard output. | 1/***************************************************************** 2 * outline.c 3 * 4 * Copyright 1999, Clark Cooper 5 * All rights reserved. 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the license contained in the --- 4 unchanged lines hidden (view full) --- 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. 18 * 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. |
|
21 */ 22 23 24#include <stdio.h> 25#include <expat.h> 26 | 22 */ 23 24 25#include <stdio.h> 26#include <expat.h> 27 |
28#if defined(__amigaos__) && defined(__USE_INLINE__) 29#include <proto/expat.h> 30#endif 31 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 41 |
|
27#define BUFFSIZE 8192 28 29char Buff[BUFFSIZE]; 30 31int Depth; 32 | 42#define BUFFSIZE 8192 43 44char Buff[BUFFSIZE]; 45 46int Depth; 47 |
33static void | 48static void XMLCALL |
34start(void *data, const char *el, const char **attr) 35{ 36 int i; 37 38 for (i = 0; i < Depth; i++) 39 printf(" "); 40 41 printf("%s", el); 42 43 for (i = 0; attr[i]; i += 2) { 44 printf(" %s='%s'", attr[i], attr[i + 1]); 45 } 46 47 printf("\n"); 48 Depth++; 49} 50 | 49start(void *data, const char *el, const char **attr) 50{ 51 int i; 52 53 for (i = 0; i < Depth; i++) 54 printf(" "); 55 56 printf("%s", el); 57 58 for (i = 0; attr[i]; i += 2) { 59 printf(" %s='%s'", attr[i], attr[i + 1]); 60 } 61 62 printf("\n"); 63 Depth++; 64} 65 |
51static void | 66static void XMLCALL |
52end(void *data, const char *el) 53{ 54 Depth--; 55} 56 57int 58main(int argc, char *argv[]) 59{ --- 4 unchanged lines hidden (view full) --- 64 } 65 66 XML_SetElementHandler(p, start, end); 67 68 for (;;) { 69 int done; 70 int len; 71 | 67end(void *data, const char *el) 68{ 69 Depth--; 70} 71 72int 73main(int argc, char *argv[]) 74{ --- 4 unchanged lines hidden (view full) --- 79 } 80 81 XML_SetElementHandler(p, start, end); 82 83 for (;;) { 84 int done; 85 int len; 86 |
72 len = fread(Buff, 1, BUFFSIZE, stdin); | 87 len = (int)fread(Buff, 1, BUFFSIZE, stdin); |
73 if (ferror(stdin)) { 74 fprintf(stderr, "Read error\n"); 75 exit(-1); 76 } 77 done = feof(stdin); 78 79 if (XML_Parse(p, Buff, len, done) == XML_STATUS_ERROR) { | 88 if (ferror(stdin)) { 89 fprintf(stderr, "Read error\n"); 90 exit(-1); 91 } 92 done = feof(stdin); 93 94 if (XML_Parse(p, Buff, len, done) == XML_STATUS_ERROR) { |
80 fprintf(stderr, "Parse error at line %d:\n%s\n", | 95 fprintf(stderr, "Parse error at line %" XML_FMT_INT_MOD "u:\n%s\n", |
81 XML_GetCurrentLineNumber(p), 82 XML_ErrorString(XML_GetErrorCode(p))); 83 exit(-1); 84 } 85 86 if (done) 87 break; 88 } | 96 XML_GetCurrentLineNumber(p), 97 XML_ErrorString(XML_GetErrorCode(p))); 98 exit(-1); 99 } 100 101 if (done) 102 break; 103 } |
104 XML_ParserFree(p); |
|
89 return 0; 90} | 105 return 0; 106} |