Annotation of XML/xmllint.c, revision 1.12

1.1       daniel      1: /*
                      2:  * xmllint.c : a small tester program for XML input.
                      3:  *
                      4:  * See Copyright for the status of this software.
                      5:  *
                      6:  * Daniel.Veillard@w3.org
                      7:  */
                      8: 
                      9: #ifdef WIN32
                     10: #include "win32config.h"
                     11: #else
                     12: #include "config.h"
                     13: #endif
                     14: 
                     15: #include <stdio.h>
                     16: #include <string.h>
                     17: #include <stdio.h>
                     18: #include <stdarg.h>
                     19: 
                     20: #ifdef HAVE_SYS_TYPES_H
                     21: #include <sys/types.h>
                     22: #endif
                     23: #ifdef HAVE_SYS_STAT_H
                     24: #include <sys/stat.h>
                     25: #endif
                     26: #ifdef HAVE_FCNTL_H
                     27: #include <fcntl.h>
                     28: #endif
                     29: #ifdef HAVE_UNISTD_H
                     30: #include <unistd.h>
                     31: #endif
1.7       veillard   32: #ifdef HAVE_SYS_MMAN_H
                     33: #include <sys/mman.h>
1.8       veillard   34: /* seems needed for Solaris */
1.9       veillard   35: #ifndef MAP_FAILED
                     36: #define MAP_FAILED ((void *) -1)
1.8       veillard   37: #endif
1.7       veillard   38: #endif
1.1       daniel     39: #ifdef HAVE_STDLIB_H
                     40: #include <stdlib.h>
                     41: #endif
                     42: #ifdef HAVE_LIBREADLINE
                     43: #include <readline/readline.h>
                     44: #ifdef HAVE_LIBHISTORY
                     45: #include <readline/history.h>
                     46: #endif
                     47: #endif
                     48: 
                     49: #include <libxml/xmlmemory.h>
                     50: #include <libxml/parser.h>
                     51: #include <libxml/parserInternals.h>
                     52: #include <libxml/HTMLparser.h>
                     53: #include <libxml/HTMLtree.h>
                     54: #include <libxml/tree.h>
                     55: #include <libxml/xpath.h>
                     56: #include <libxml/debugXML.h>
                     57: 
                     58: #ifdef LIBXML_DEBUG_ENABLED
                     59: static int debug = 0;
                     60: static int shell = 0;
                     61: static int debugent = 0;
                     62: #endif
                     63: static int copy = 0;
                     64: static int recovery = 0;
                     65: static int noent = 0;
                     66: static int noout = 0;
                     67: static int nowrap = 0;
                     68: static int valid = 0;
                     69: static int postvalid = 0;
                     70: static int repeat = 0;
                     71: static int insert = 0;
                     72: static int compress = 0;
                     73: static int html = 0;
                     74: static int htmlout = 0;
                     75: static int push = 0;
1.7       veillard   76: #ifdef HAVE_SYS_MMAN_H
                     77: static int memory = 0;
                     78: #endif
1.1       daniel     79: static int noblanks = 0;
1.2       daniel     80: static int testIO = 0;
1.3       daniel     81: static char *encoding = NULL;
1.1       daniel     82: 
                     83: extern int xmlDoValidityCheckingDefaultValue;
                     84: extern int xmlGetWarningsDefaultValue;
                     85: 
                     86: /************************************************************************
                     87:  *                                                                     *
                     88:  *                     HTML ouput                                      *
                     89:  *                                                                     *
                     90:  ************************************************************************/
                     91: char buffer[50000];
                     92: 
                     93: void
                     94: xmlHTMLEncodeSend(void) {
                     95:     char *result;
                     96: 
                     97:     result = (char *) xmlEncodeEntitiesReentrant(NULL, BAD_CAST buffer);
                     98:     if (result) {
                     99:        fprintf(stderr, "%s", result);
                    100:        xmlFree(result);
                    101:     }
                    102:     buffer[0] = 0;
                    103: }
                    104: 
                    105: /**
                    106:  * xmlHTMLPrintFileInfo:
                    107:  * @input:  an xmlParserInputPtr input
                    108:  * 
                    109:  * Displays the associated file and line informations for the current input
                    110:  */
                    111: 
                    112: void
                    113: xmlHTMLPrintFileInfo(xmlParserInputPtr input) {
                    114:     fprintf(stderr, "<p>");
                    115:     if (input != NULL) {
                    116:        if (input->filename) {
                    117:            sprintf(&buffer[strlen(buffer)], "%s:%d: ", input->filename,
                    118:                    input->line);
                    119:        } else {
                    120:            sprintf(&buffer[strlen(buffer)], "Entity: line %d: ", input->line);
                    121:        }
                    122:     }
                    123:     xmlHTMLEncodeSend();
                    124: }
                    125: 
                    126: /**
                    127:  * xmlHTMLPrintFileContext:
                    128:  * @input:  an xmlParserInputPtr input
                    129:  * 
                    130:  * Displays current context within the input content for error tracking
                    131:  */
                    132: 
                    133: void
                    134: xmlHTMLPrintFileContext(xmlParserInputPtr input) {
                    135:     const xmlChar *cur, *base;
                    136:     int n;
                    137: 
                    138:     if (input == NULL) return;
                    139:     fprintf(stderr, "<pre>\n");
                    140:     cur = input->cur;
                    141:     base = input->base;
                    142:     while ((cur > base) && ((*cur == '\n') || (*cur == '\r'))) {
                    143:        cur--;
                    144:     }
                    145:     n = 0;
                    146:     while ((n++ < 80) && (cur > base) && (*cur != '\n') && (*cur != '\r'))
                    147:         cur--;
                    148:     if ((*cur == '\n') || (*cur == '\r')) cur++;
                    149:     base = cur;
                    150:     n = 0;
                    151:     while ((*cur != 0) && (*cur != '\n') && (*cur != '\r') && (n < 79)) {
                    152:         sprintf(&buffer[strlen(buffer)], "%c", (unsigned char) *cur++);
                    153:        n++;
                    154:     }
                    155:     sprintf(&buffer[strlen(buffer)], "\n");
                    156:     cur = input->cur;
                    157:     while ((*cur == '\n') || (*cur == '\r'))
                    158:        cur--;
                    159:     n = 0;
                    160:     while ((cur != base) && (n++ < 80)) {
                    161:         sprintf(&buffer[strlen(buffer)], " ");
                    162:         base++;
                    163:     }
                    164:     sprintf(&buffer[strlen(buffer)],"^\n");
                    165:     xmlHTMLEncodeSend();
                    166:     fprintf(stderr, "</pre>");
                    167: }
                    168: 
                    169: /**
                    170:  * xmlHTMLError:
                    171:  * @ctx:  an XML parser context
                    172:  * @msg:  the message to display/transmit
                    173:  * @...:  extra parameters for the message display
                    174:  * 
                    175:  * Display and format an error messages, gives file, line, position and
                    176:  * extra parameters.
                    177:  */
                    178: void
                    179: xmlHTMLError(void *ctx, const char *msg, ...)
                    180: {
                    181:     xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
                    182:     xmlParserInputPtr input;
                    183:     xmlParserInputPtr cur = NULL;
                    184:     va_list args;
                    185: 
                    186:     buffer[0] = 0;
                    187:     input = ctxt->input;
                    188:     if ((input != NULL) && (input->filename == NULL) && (ctxt->inputNr > 1)) {
                    189:        cur = input;
                    190:         input = ctxt->inputTab[ctxt->inputNr - 2];
                    191:     }
                    192:         
                    193:     xmlHTMLPrintFileInfo(input);
                    194: 
                    195:     fprintf(stderr, "<b>error</b>: ");
                    196:     va_start(args, msg);
                    197:     vsprintf(&buffer[strlen(buffer)], msg, args);
                    198:     va_end(args);
                    199:     xmlHTMLEncodeSend();
                    200:     fprintf(stderr, "</p>\n");
                    201: 
                    202:     xmlHTMLPrintFileContext(input);
                    203:     xmlHTMLEncodeSend();
                    204: }
                    205: 
                    206: /**
                    207:  * xmlHTMLWarning:
                    208:  * @ctx:  an XML parser context
                    209:  * @msg:  the message to display/transmit
                    210:  * @...:  extra parameters for the message display
                    211:  * 
                    212:  * Display and format a warning messages, gives file, line, position and
                    213:  * extra parameters.
                    214:  */
                    215: void
                    216: xmlHTMLWarning(void *ctx, const char *msg, ...)
                    217: {
                    218:     xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
                    219:     xmlParserInputPtr input;
                    220:     xmlParserInputPtr cur = NULL;
                    221:     va_list args;
                    222: 
                    223:     buffer[0] = 0;
                    224:     input = ctxt->input;
                    225:     if ((input != NULL) && (input->filename == NULL) && (ctxt->inputNr > 1)) {
                    226:        cur = input;
                    227:         input = ctxt->inputTab[ctxt->inputNr - 2];
                    228:     }
                    229:         
                    230: 
                    231:     xmlHTMLPrintFileInfo(input);
                    232:         
                    233:     fprintf(stderr, "<b>warning</b>: ");
                    234:     va_start(args, msg);
                    235:     vsprintf(&buffer[strlen(buffer)], msg, args);
                    236:     va_end(args);
                    237:     xmlHTMLEncodeSend();
                    238:     fprintf(stderr, "</p>\n");
                    239: 
                    240:     xmlHTMLPrintFileContext(input);
                    241:     xmlHTMLEncodeSend();
                    242: }
                    243: 
                    244: /**
                    245:  * xmlHTMLValidityError:
                    246:  * @ctx:  an XML parser context
                    247:  * @msg:  the message to display/transmit
                    248:  * @...:  extra parameters for the message display
                    249:  * 
                    250:  * Display and format an validity error messages, gives file,
                    251:  * line, position and extra parameters.
                    252:  */
                    253: void
                    254: xmlHTMLValidityError(void *ctx, const char *msg, ...)
                    255: {
                    256:     xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
                    257:     xmlParserInputPtr input;
                    258:     va_list args;
                    259: 
                    260:     buffer[0] = 0;
                    261:     input = ctxt->input;
                    262:     if ((input->filename == NULL) && (ctxt->inputNr > 1))
                    263:         input = ctxt->inputTab[ctxt->inputNr - 2];
                    264:         
                    265:     xmlHTMLPrintFileInfo(input);
                    266: 
                    267:     fprintf(stderr, "<b>validity error</b>: ");
                    268:     va_start(args, msg);
                    269:     vsprintf(&buffer[strlen(buffer)], msg, args);
                    270:     va_end(args);
                    271:     xmlHTMLEncodeSend();
                    272:     fprintf(stderr, "</p>\n");
                    273: 
                    274:     xmlHTMLPrintFileContext(input);
                    275:     xmlHTMLEncodeSend();
                    276: }
                    277: 
                    278: /**
                    279:  * xmlHTMLValidityWarning:
                    280:  * @ctx:  an XML parser context
                    281:  * @msg:  the message to display/transmit
                    282:  * @...:  extra parameters for the message display
                    283:  * 
                    284:  * Display and format a validity warning messages, gives file, line,
                    285:  * position and extra parameters.
                    286:  */
                    287: void
                    288: xmlHTMLValidityWarning(void *ctx, const char *msg, ...)
                    289: {
                    290:     xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
                    291:     xmlParserInputPtr input;
                    292:     va_list args;
                    293: 
                    294:     buffer[0] = 0;
                    295:     input = ctxt->input;
                    296:     if ((input->filename == NULL) && (ctxt->inputNr > 1))
                    297:         input = ctxt->inputTab[ctxt->inputNr - 2];
                    298: 
                    299:     xmlHTMLPrintFileInfo(input);
                    300:         
                    301:     fprintf(stderr, "<b>validity warning</b>: ");
                    302:     va_start(args, msg);
                    303:     vsprintf(&buffer[strlen(buffer)], msg, args);
                    304:     va_end(args);
                    305:     xmlHTMLEncodeSend();
                    306:     fprintf(stderr, "</p>\n");
                    307: 
                    308:     xmlHTMLPrintFileContext(input);
                    309:     xmlHTMLEncodeSend();
                    310: }
                    311: 
                    312: /************************************************************************
                    313:  *                                                                     *
                    314:  *                     Shell Interface                                 *
                    315:  *                                                                     *
                    316:  ************************************************************************/
                    317: /**
                    318:  * xmlShellReadline:
                    319:  * @prompt:  the prompt value
                    320:  *
                    321:  * Read a string
                    322:  * 
                    323:  * Returns a pointer to it or NULL on EOF the caller is expected to
                    324:  *     free the returned string.
                    325:  */
                    326: char *
                    327: xmlShellReadline(char *prompt) {
                    328: #ifdef HAVE_LIBREADLINE
                    329:     char *line_read;
                    330: 
                    331:     /* Get a line from the user. */
                    332:     line_read = readline (prompt);
                    333: 
                    334:     /* If the line has any text in it, save it on the history. */
                    335:     if (line_read && *line_read)
                    336:        add_history (line_read);
                    337: 
                    338:     return (line_read);
                    339: #else
                    340:     char line_read[501];
                    341: 
                    342:     if (prompt != NULL)
                    343:        fprintf(stdout, "%s", prompt);
                    344:     if (!fgets(line_read, 500, stdin))
                    345:         return(NULL);
                    346:     line_read[500] = 0;
                    347:     return(strdup(line_read));
                    348: #endif
                    349: }
                    350: 
                    351: /************************************************************************
                    352:  *                                                                     *
1.2       daniel    353:  *                     I/O Interfaces                                  *
                    354:  *                                                                     *
                    355:  ************************************************************************/
                    356: 
                    357: int myRead(FILE *f, char * buffer, int len) {
                    358:     return(fread(buffer, 1, len, f));
                    359: }
                    360: void myClose(FILE *f) {
                    361:     fclose(f);
                    362: }
                    363: 
                    364: /************************************************************************
                    365:  *                                                                     *
1.1       daniel    366:  *                     Test processing                                 *
                    367:  *                                                                     *
                    368:  ************************************************************************/
                    369: void parseAndPrintFile(char *filename) {
                    370:     xmlDocPtr doc = NULL, tmp;
                    371: 
                    372: #ifdef LIBXML_HTML_ENABLED
                    373:     if (html) {
                    374:        doc = htmlParseFile(filename, NULL);
                    375:     } else {
                    376: #endif /* LIBXML_HTML_ENABLED */
                    377:        /*
                    378:         * build an XML tree from a string;
                    379:         */
                    380:        if (push) {
                    381:            FILE *f;
                    382: 
                    383:            f = fopen(filename, "r");
                    384:            if (f != NULL) {
                    385:                int res, size = 3;
                    386:                char chars[1024];
                    387:                 xmlParserCtxtPtr ctxt;
                    388: 
                    389:                if (repeat)
                    390:                    size = 1024;
                    391:                res = fread(chars, 1, 4, f);
                    392:                if (res > 0) {
                    393:                    ctxt = xmlCreatePushParserCtxt(NULL, NULL,
                    394:                                chars, res, filename);
                    395:                    while ((res = fread(chars, 1, size, f)) > 0) {
                    396:                        xmlParseChunk(ctxt, chars, res, 0);
                    397:                    }
                    398:                    xmlParseChunk(ctxt, chars, 0, 1);
                    399:                    doc = ctxt->myDoc;
                    400:                    xmlFreeParserCtxt(ctxt);
                    401:                }
                    402:            }
1.2       daniel    403:        } else if (testIO) {
                    404:            int ret;
                    405:            FILE *f;
                    406: 
                    407:            f = fopen(filename, "r");
                    408:            if (f != NULL) {
                    409:                 xmlParserCtxtPtr ctxt;
                    410: 
                    411:                ctxt = xmlCreateIOParserCtxt(NULL, NULL,
                    412:                            (xmlInputReadCallback) myRead,
                    413:                            (xmlInputCloseCallback) myClose,
                    414:                            f, XML_CHAR_ENCODING_NONE);
                    415:                xmlParseDocument(ctxt);
                    416: 
                    417:                ret = ctxt->wellFormed;
                    418:                doc = ctxt->myDoc;
                    419:                xmlFreeParserCtxt(ctxt);
                    420:                if (!ret) {
                    421:                    xmlFreeDoc(doc);
                    422:                    doc = NULL;
                    423:                }
                    424:            }
1.1       daniel    425:        } else if (recovery) {
                    426:            doc = xmlRecoverFile(filename);
                    427:        } else if (htmlout) {
                    428:            int ret;
                    429:            xmlParserCtxtPtr ctxt;
                    430:            xmlSAXHandler silent, *old;
                    431: 
                    432:            ctxt = xmlCreateFileParserCtxt(filename);
1.10      veillard  433: 
                    434:            if (ctxt == NULL) {       
                    435:              /* If xmlCreateFileParseCtxt() return NULL something
                    436:                 strange happened so we don't want to do anything.  Do
                    437:                 we want to print an error message here?
                    438:                 <sven@zen.org> */
                    439:              doc = NULL;
                    440:            } else {
                    441:              memcpy(&silent, ctxt->sax, sizeof(silent));
                    442:              old = ctxt->sax;
                    443:              silent.error = xmlHTMLError;
                    444:              if (xmlGetWarningsDefaultValue)
1.1       daniel    445:                silent.warning = xmlHTMLWarning;
1.10      veillard  446:              else 
1.1       daniel    447:                silent.warning = NULL;
1.10      veillard  448:              silent.fatalError = xmlHTMLError;
                    449:              ctxt->sax = &silent;
                    450:              ctxt->vctxt.error = xmlHTMLValidityError;
                    451:              if (xmlGetWarningsDefaultValue)
1.1       daniel    452:                ctxt->vctxt.warning = xmlHTMLValidityWarning;
1.10      veillard  453:              else 
1.1       daniel    454:                ctxt->vctxt.warning = NULL;
                    455: 
1.10      veillard  456:              xmlParseDocument(ctxt);
1.1       daniel    457: 
1.10      veillard  458:              ret = ctxt->wellFormed;
                    459:              doc = ctxt->myDoc;
                    460:              ctxt->sax = old;
                    461:              xmlFreeParserCtxt(ctxt);
                    462:              if (!ret) {
1.1       daniel    463:                xmlFreeDoc(doc);
                    464:                doc = NULL;
1.10      veillard  465:              }
1.1       daniel    466:            }
1.7       veillard  467: #ifdef HAVE_SYS_MMAN_H
                    468:        } else if (memory) {
                    469:            int fd;
                    470:            struct stat info;
                    471:            const char *base;
                    472:            if (stat(filename, &info) < 0) 
                    473:                return;
                    474:            if ((fd = open(filename, O_RDONLY)) < 0)
                    475:                return;
                    476:            base = mmap(NULL, info.st_size, PROT_READ, MAP_SHARED, fd, 0) ;
1.11      veillard  477:            if (base == (void *) MAP_FAILED)
1.7       veillard  478:                return;
                    479: 
                    480:            doc = xmlParseMemory((char *) base, info.st_size);
                    481:            munmap((char *) base, info.st_size);
                    482: #endif
1.1       daniel    483:        } else
                    484:            doc = xmlParseFile(filename);
                    485: #ifdef LIBXML_HTML_ENABLED
                    486:     }
                    487: #endif
                    488: 
1.10      veillard  489:     /*
                    490:      * If we don't have a document we might as well give up.  Do we
                    491:      * want an error message here?  <sven@zen.org> */
                    492:     if (doc == NULL)
                    493:       {
                    494:        return;
                    495:       }
                    496: 
1.1       daniel    497: #ifdef LIBXML_DEBUG_ENABLED
                    498:     /*
                    499:      * shell interraction
                    500:      */
                    501:     if (shell)  
                    502:         xmlShell(doc, filename, xmlShellReadline, stdout);
                    503: #endif
                    504: 
                    505:     /*
                    506:      * test intermediate copy if needed.
                    507:      */
                    508:     if (copy) {
                    509:         tmp = doc;
                    510:        doc = xmlCopyDoc(doc, 1);
                    511:        xmlFreeDoc(tmp);
                    512:     }
                    513: 
                    514:     if ((insert) && (!html)) {
                    515:         const xmlChar* list[256];
                    516:        int nb, i;
                    517:        xmlNodePtr node;
                    518: 
                    519:        if (doc->children != NULL) {
                    520:            node = doc->children;
                    521:            while ((node != NULL) && (node->last == NULL)) node = node->next;
                    522:            if (node != NULL) {
                    523:                nb = xmlValidGetValidElements(node->last, NULL, list, 256);
                    524:                if (nb < 0) {
                    525:                    printf("could not get valid list of elements\n");
                    526:                } else if (nb == 0) {
                    527:                    printf("No element can be indersted under root\n");
                    528:                } else {
                    529:                    printf("%d element types can be indersted under root:\n",
                    530:                           nb);
                    531:                    for (i = 0;i < nb;i++) {
                    532:                         printf("%s\n", list[i]);
                    533:                    }
                    534:                }
                    535:            }
                    536:        }    
                    537:     }else if (noout == 0) {
                    538:        /*
                    539:         * print it.
                    540:         */
                    541: #ifdef LIBXML_DEBUG_ENABLED
                    542:        if (!debug) {
                    543: #endif
                    544:            if (compress)
                    545:                xmlSaveFile("-", doc);
1.3       daniel    546:            else if (encoding != NULL)
                    547:                xmlSaveFileEnc("-", doc, encoding);
1.1       daniel    548:            else
                    549:                xmlDocDump(stdout, doc);
                    550: #ifdef LIBXML_DEBUG_ENABLED
                    551:        } else
                    552:            xmlDebugDumpDocument(stdout, doc);
                    553: #endif
                    554:     }
                    555: 
                    556:     /*
                    557:      * A posteriori validation test
                    558:      */
                    559:     if (postvalid) {
                    560:        xmlValidCtxt cvp;
                    561:        cvp.userData = (void *) stderr;                                                 cvp.error    = (xmlValidityErrorFunc) fprintf;                                  cvp.warning  = (xmlValidityWarningFunc) fprintf;
                    562:        xmlValidateDocument(&cvp, doc);
                    563:     }
                    564: 
                    565: #ifdef LIBXML_DEBUG_ENABLED
                    566:     if ((debugent) && (!html))
                    567:        xmlDebugDumpEntities(stdout, doc);
                    568: #endif
                    569: 
                    570:     /*
                    571:      * free it.
                    572:      */
                    573:     xmlFreeDoc(doc);
                    574: }
                    575: 
                    576: int main(int argc, char **argv) {
                    577:     int i, count;
                    578:     int files = 0;
                    579: 
1.4       daniel    580:     LIBXML_TEST_VERSION
1.1       daniel    581:     for (i = 1; i < argc ; i++) {
                    582: #ifdef LIBXML_DEBUG_ENABLED
                    583:        if ((!strcmp(argv[i], "-debug")) || (!strcmp(argv[i], "--debug")))
                    584:            debug++;
                    585:        else if ((!strcmp(argv[i], "-debugent")) || (!strcmp(argv[i], "--debugent")))
                    586:            debugent++;
                    587:        else if ((!strcmp(argv[i], "-shell")) ||
                    588:                 (!strcmp(argv[i], "--shell"))) {
                    589:            shell++;
                    590:             noout = 1;
                    591:         } else 
                    592: #endif
                    593:        if ((!strcmp(argv[i], "-copy")) || (!strcmp(argv[i], "--copy")))
                    594:            copy++;
                    595:        else if ((!strcmp(argv[i], "-recover")) ||
                    596:                 (!strcmp(argv[i], "--recover")))
                    597:            recovery++;
                    598:        else if ((!strcmp(argv[i], "-noent")) ||
                    599:                 (!strcmp(argv[i], "--noent")))
                    600:            noent++;
                    601:        else if ((!strcmp(argv[i], "-noout")) ||
                    602:                 (!strcmp(argv[i], "--noout")))
                    603:            noout++;
                    604:        else if ((!strcmp(argv[i], "-htmlout")) ||
                    605:                 (!strcmp(argv[i], "--htmlout")))
                    606:            htmlout++;
                    607: #ifdef LIBXML_HTML_ENABLED
                    608:        else if ((!strcmp(argv[i], "-html")) ||
                    609:                 (!strcmp(argv[i], "--html"))) {
                    610:            html++;
                    611:         }
                    612: #endif /* LIBXML_HTML_ENABLED */
                    613:        else if ((!strcmp(argv[i], "-nowrap")) ||
                    614:                 (!strcmp(argv[i], "--nowrap")))
                    615:            nowrap++;
                    616:        else if ((!strcmp(argv[i], "-valid")) ||
                    617:                 (!strcmp(argv[i], "--valid")))
                    618:            valid++;
                    619:        else if ((!strcmp(argv[i], "-postvalid")) ||
                    620:                 (!strcmp(argv[i], "--postvalid")))
                    621:            postvalid++;
                    622:        else if ((!strcmp(argv[i], "-insert")) ||
                    623:                 (!strcmp(argv[i], "--insert")))
                    624:            insert++;
                    625:        else if ((!strcmp(argv[i], "-repeat")) ||
                    626:                 (!strcmp(argv[i], "--repeat")))
                    627:            repeat++;
                    628:        else if ((!strcmp(argv[i], "-push")) ||
                    629:                 (!strcmp(argv[i], "--push")))
                    630:            push++;
1.7       veillard  631: #ifdef HAVE_SYS_MMAN_H
                    632:        else if ((!strcmp(argv[i], "-memory")) ||
                    633:                 (!strcmp(argv[i], "--memory")))
                    634:            memory++;
                    635: #endif
1.2       daniel    636:        else if ((!strcmp(argv[i], "-testIO")) ||
                    637:                 (!strcmp(argv[i], "--testIO")))
                    638:            testIO++;
1.1       daniel    639:        else if ((!strcmp(argv[i], "-compress")) ||
                    640:                 (!strcmp(argv[i], "--compress"))) {
                    641:            compress++;
                    642:            xmlSetCompressMode(9);
                    643:         }
                    644:        else if ((!strcmp(argv[i], "-nowarning")) ||
                    645:                 (!strcmp(argv[i], "--nowarning"))) {
                    646:            xmlGetWarningsDefaultValue = 0;
                    647:         }
1.3       daniel    648:        else if ((!strcmp(argv[i], "-encode")) ||
                    649:                 (!strcmp(argv[i], "--encode"))) {
                    650:            i++;
                    651:            encoding = argv[i];
1.12    ! veillard  652:            /*
        !           653:             * OK it's for testing purposes
        !           654:             */
        !           655:            xmlAddEncodingAlias("UTF-8", "DVEnc");
1.3       daniel    656:         }
1.1       daniel    657:        else if ((!strcmp(argv[i], "-noblanks")) ||
                    658:                 (!strcmp(argv[i], "--noblanks"))) {
                    659:             noblanks++;
                    660:             xmlKeepBlanksDefault(0);
                    661:         }
                    662:     }
                    663:     if (noent != 0) xmlSubstituteEntitiesDefault(1);
                    664:     if (valid != 0) xmlDoValidityCheckingDefaultValue = 1;
                    665:     if ((htmlout) && (!nowrap)) {
                    666:        fprintf(stderr,
                    667:          "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"\n");
                    668:        fprintf(stderr, "\t\"http://www.w3.org/TR/REC-html40/loose.dtd\">\n");
                    669:        fprintf(stderr,
                    670:         "<html><head><title>%s output</title></head>\n",
                    671:                argv[0]);
                    672:        fprintf(stderr, 
                    673:         "<body bgcolor=\"#ffffff\"><h1 align=\"center\">%s output</h1>\n",
                    674:                argv[0]);
                    675:     }
                    676:     for (i = 1; i < argc ; i++) {
1.3       daniel    677:        if ((!strcmp(argv[i], "-encode")) ||
                    678:                 (!strcmp(argv[i], "--encode"))) {
                    679:            i++;
                    680:            continue;
                    681:         }
1.1       daniel    682:        if (argv[i][0] != '-') {
                    683:            if (repeat) {
                    684:                for (count = 0;count < 100 * repeat;count++)
                    685:                    parseAndPrintFile(argv[i]);
                    686:            } else
                    687:                parseAndPrintFile(argv[i]);
                    688:            files ++;
                    689:        }
                    690:     }
                    691:     if ((htmlout) && (!nowrap)) {
                    692:        fprintf(stderr, "</body></html>\n");
                    693:     }
                    694:     if (files == 0) {
                    695:        printf("Usage : %s [--debug] [--debugent] [--copy] [--recover] [--noent] [--noout] [--valid] [--repeat] XMLfiles ...\n",
                    696:               argv[0]);
                    697:        printf("\tParse the XML files and output the result of the parsing\n");
                    698: #ifdef LIBXML_DEBUG_ENABLED
                    699:        printf("\t--debug : dump a debug tree of the in-memory document\n");
                    700:        printf("\t--shell : run a navigating shell\n");
                    701:        printf("\t--debugent : debug the entities defined in the document\n");
                    702: #endif
                    703:        printf("\t--copy : used to test the internal copy implementation\n");
                    704:        printf("\t--recover : output what was parsable on broken XML documents\n");
                    705:        printf("\t--noent : substitute entity references by their value\n");
                    706:        printf("\t--noout : don't output the result tree\n");
                    707:        printf("\t--htmlout : output results as HTML\n");
                    708:        printf("\t--nowarp : do not put HTML doc wrapper\n");
                    709:        printf("\t--valid : validate the document in addition to std well-formed check\n");
                    710:        printf("\t--postvalid : do a posteriori validation, i.e after parsing\n");
                    711:        printf("\t--repeat : repeat 100 times, for timing or profiling\n");
                    712:        printf("\t--insert : ad-hoc test for valid insertions\n");
                    713:        printf("\t--compress : turn on gzip compression of output\n");
                    714: #ifdef LIBXML_HTML_ENABLED
                    715:        printf("\t--html : use the HTML parser\n");
                    716: #endif
                    717:        printf("\t--push : use the push mode of the parser\n");
1.7       veillard  718: #ifdef HAVE_SYS_MMAN_H
                    719:        printf("\t--memory : parse from memory\n");
                    720: #endif
1.1       daniel    721:        printf("\t--nowarning : do not emit warnings from parser/validator\n");
                    722:        printf("\t--noblanks : drop (ignorable?) blanks spaces\n");
1.2       daniel    723:        printf("\t--testIO : test user I/O support\n");
1.6       veillard  724:        printf("\t--encode encoding : output in the given encoding\n");
1.1       daniel    725:     }
                    726:     xmlCleanupParser();
                    727:     xmlMemoryDump();
                    728: 
                    729:     return(0);
                    730: }
1.10      veillard  731: 

Webmaster