ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

testSAX.c
Go to the documentation of this file.
00001 /*
00002  * testSAX.c : a small tester program for parsing using the SAX API.
00003  *
00004  * See Copyright for the status of this software.
00005  *
00006  * daniel@veillard.com
00007  */
00008 
00009 #include "libxml.h"
00010 
00011 #ifdef HAVE_SYS_TIME_H
00012 #include <sys/time.h>
00013 #endif
00014 #ifdef HAVE_SYS_TIMEB_H
00015 #include <sys/timeb.h>
00016 #endif
00017 #ifdef HAVE_TIME_H
00018 #include <time.h>
00019 #endif
00020 
00021 #ifdef LIBXML_SAX1_ENABLED
00022 #include <string.h>
00023 #include <stdarg.h>
00024 
00025 #ifdef HAVE_SYS_TYPES_H
00026 #include <sys/types.h>
00027 #endif
00028 #ifdef HAVE_SYS_STAT_H
00029 #include <sys/stat.h>
00030 #endif
00031 #ifdef HAVE_FCNTL_H
00032 #include <fcntl.h>
00033 #endif
00034 #ifdef HAVE_UNISTD_H
00035 #include <unistd.h>
00036 #endif
00037 #ifdef HAVE_STDLIB_H
00038 #include <stdlib.h>
00039 #endif
00040 #ifdef HAVE_STRING_H
00041 #include <string.h>
00042 #endif
00043 
00044 
00045 #include <libxml/globals.h>
00046 #include <libxml/xmlerror.h>
00047 #include <libxml/parser.h>
00048 #include <libxml/parserInternals.h> /* only for xmlNewInputFromFile() */
00049 #include <libxml/tree.h>
00050 #include <libxml/debugXML.h>
00051 #include <libxml/xmlmemory.h>
00052 
00053 static int debug = 0;
00054 static int copy = 0;
00055 static int recovery = 0;
00056 static int push = 0;
00057 static int speed = 0;
00058 static int noent = 0;
00059 static int quiet = 0;
00060 static int nonull = 0;
00061 static int sax2 = 0;
00062 static int repeat = 0;
00063 static int callbacks = 0;
00064 static int timing = 0;
00065 
00066 /*
00067  * Timing routines.
00068  */
00069 /*
00070  * Internal timing routines to remove the necessity to have unix-specific
00071  * function calls
00072  */
00073 
00074 #ifndef HAVE_GETTIMEOFDAY 
00075 #ifdef HAVE_SYS_TIMEB_H
00076 #ifdef HAVE_SYS_TIME_H
00077 #ifdef HAVE_FTIME
00078 
00079 static int
00080 my_gettimeofday(struct timeval *tvp, void *tzp)
00081 {
00082     struct timeb timebuffer;
00083 
00084     ftime(&timebuffer);
00085     if (tvp) {
00086         tvp->tv_sec = timebuffer.time;
00087         tvp->tv_usec = timebuffer.millitm * 1000L;
00088     }
00089     return (0);
00090 }
00091 #define HAVE_GETTIMEOFDAY 1
00092 #define gettimeofday my_gettimeofday
00093 
00094 #endif /* HAVE_FTIME */
00095 #endif /* HAVE_SYS_TIME_H */
00096 #endif /* HAVE_SYS_TIMEB_H */
00097 #endif /* !HAVE_GETTIMEOFDAY */
00098 
00099 #if defined(HAVE_GETTIMEOFDAY)
00100 static struct timeval begin, end;
00101 
00102 /*
00103  * startTimer: call where you want to start timing
00104  */
00105 static void
00106 startTimer(void)
00107 {
00108     gettimeofday(&begin, NULL);
00109 }
00110 
00111 /*
00112  * endTimer: call where you want to stop timing and to print out a
00113  *           message about the timing performed; format is a printf
00114  *           type argument
00115  */
00116 static void XMLCDECL
00117 endTimer(const char *fmt, ...)
00118 {
00119     long msec;
00120     va_list ap;
00121 
00122     gettimeofday(&end, NULL);
00123     msec = end.tv_sec - begin.tv_sec;
00124     msec *= 1000;
00125     msec += (end.tv_usec - begin.tv_usec) / 1000;
00126 
00127 #ifndef HAVE_STDARG_H
00128 #error "endTimer required stdarg functions"
00129 #endif
00130     va_start(ap, fmt);
00131     vfprintf(stderr, fmt, ap);
00132     va_end(ap);
00133 
00134     fprintf(stderr, " took %ld ms\n", msec);
00135 }
00136 #elif defined(HAVE_TIME_H)
00137 /*
00138  * No gettimeofday function, so we have to make do with calling clock.
00139  * This is obviously less accurate, but there's little we can do about
00140  * that.
00141  */
00142 #ifndef CLOCKS_PER_SEC
00143 #define CLOCKS_PER_SEC 100
00144 #endif
00145 
00146 static clock_t begin, end;
00147 static void
00148 startTimer(void)
00149 {
00150     begin = clock();
00151 }
00152 static void XMLCDECL
00153 endTimer(const char *fmt, ...)
00154 {
00155     long msec;
00156     va_list ap;
00157 
00158     end = clock();
00159     msec = ((end - begin) * 1000) / CLOCKS_PER_SEC;
00160 
00161 #ifndef HAVE_STDARG_H
00162 #error "endTimer required stdarg functions"
00163 #endif
00164     va_start(ap, fmt);
00165     vfprintf(stderr, fmt, ap);
00166     va_end(ap);
00167     fprintf(stderr, " took %ld ms\n", msec);
00168 }
00169 #else
00170 
00171 /*
00172  * We don't have a gettimeofday or time.h, so we just don't do timing
00173  */
00174 static void
00175 startTimer(void)
00176 {
00177     /*
00178      * Do nothing
00179      */
00180 }
00181 static void XMLCDECL
00182 endTimer(char *format, ...)
00183 {
00184     /*
00185      * We cannot do anything because we don't have a timing function
00186      */
00187 #ifdef HAVE_STDARG_H
00188     va_start(ap, format);
00189     vfprintf(stderr, format, ap);
00190     va_end(ap);
00191     fprintf(stderr, " was not timed\n", msec);
00192 #else
00193     /* We don't have gettimeofday, time or stdarg.h, what crazy world is
00194      * this ?!
00195      */
00196 #endif
00197 }
00198 #endif
00199 
00200 /*
00201  * empty SAX block
00202  */
00203 static xmlSAXHandler emptySAXHandlerStruct = {
00204     NULL, /* internalSubset */
00205     NULL, /* isStandalone */
00206     NULL, /* hasInternalSubset */
00207     NULL, /* hasExternalSubset */
00208     NULL, /* resolveEntity */
00209     NULL, /* getEntity */
00210     NULL, /* entityDecl */
00211     NULL, /* notationDecl */
00212     NULL, /* attributeDecl */
00213     NULL, /* elementDecl */
00214     NULL, /* unparsedEntityDecl */
00215     NULL, /* setDocumentLocator */
00216     NULL, /* startDocument */
00217     NULL, /* endDocument */
00218     NULL, /* startElement */
00219     NULL, /* endElement */
00220     NULL, /* reference */
00221     NULL, /* characters */
00222     NULL, /* ignorableWhitespace */
00223     NULL, /* processingInstruction */
00224     NULL, /* comment */
00225     NULL, /* xmlParserWarning */
00226     NULL, /* xmlParserError */
00227     NULL, /* xmlParserError */
00228     NULL, /* getParameterEntity */
00229     NULL, /* cdataBlock; */
00230     NULL, /* externalSubset; */
00231     1,
00232     NULL,
00233     NULL, /* startElementNs */
00234     NULL, /* endElementNs */
00235     NULL  /* xmlStructuredErrorFunc */
00236 };
00237 
00238 static xmlSAXHandlerPtr emptySAXHandler = &emptySAXHandlerStruct;
00239 extern xmlSAXHandlerPtr debugSAXHandler;
00240 
00241 /************************************************************************
00242  *                                  *
00243  *              Debug Handlers              *
00244  *                                  *
00245  ************************************************************************/
00246 
00255 static int
00256 isStandaloneDebug(void *ctx ATTRIBUTE_UNUSED)
00257 {
00258     callbacks++;
00259     if (quiet)
00260     return(0);
00261     fprintf(stdout, "SAX.isStandalone()\n");
00262     return(0);
00263 }
00264 
00273 static int
00274 hasInternalSubsetDebug(void *ctx ATTRIBUTE_UNUSED)
00275 {
00276     callbacks++;
00277     if (quiet)
00278     return(0);
00279     fprintf(stdout, "SAX.hasInternalSubset()\n");
00280     return(0);
00281 }
00282 
00291 static int
00292 hasExternalSubsetDebug(void *ctx ATTRIBUTE_UNUSED)
00293 {
00294     callbacks++;
00295     if (quiet)
00296     return(0);
00297     fprintf(stdout, "SAX.hasExternalSubset()\n");
00298     return(0);
00299 }
00300 
00307 static void
00308 internalSubsetDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name,
00309            const xmlChar *ExternalID, const xmlChar *SystemID)
00310 {
00311     callbacks++;
00312     if (quiet)
00313     return;
00314     fprintf(stdout, "SAX.internalSubset(%s,", name);
00315     if (ExternalID == NULL)
00316     fprintf(stdout, " ,");
00317     else
00318     fprintf(stdout, " %s,", ExternalID);
00319     if (SystemID == NULL)
00320     fprintf(stdout, " )\n");
00321     else
00322     fprintf(stdout, " %s)\n", SystemID);
00323 }
00324 
00331 static void
00332 externalSubsetDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name,
00333            const xmlChar *ExternalID, const xmlChar *SystemID)
00334 {
00335     callbacks++;
00336     if (quiet)
00337     return;
00338     fprintf(stdout, "SAX.externalSubset(%s,", name);
00339     if (ExternalID == NULL)
00340     fprintf(stdout, " ,");
00341     else
00342     fprintf(stdout, " %s,", ExternalID);
00343     if (SystemID == NULL)
00344     fprintf(stdout, " )\n");
00345     else
00346     fprintf(stdout, " %s)\n", SystemID);
00347 }
00348 
00363 static xmlParserInputPtr
00364 resolveEntityDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *publicId, const xmlChar *systemId)
00365 {
00366     callbacks++;
00367     if (quiet)
00368     return(NULL);
00369     /* xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; */
00370 
00371     
00372     fprintf(stdout, "SAX.resolveEntity(");
00373     if (publicId != NULL)
00374     fprintf(stdout, "%s", (char *)publicId);
00375     else
00376     fprintf(stdout, " ");
00377     if (systemId != NULL)
00378     fprintf(stdout, ", %s)\n", (char *)systemId);
00379     else
00380     fprintf(stdout, ", )\n");
00381 /*********
00382     if (systemId != NULL) {
00383         return(xmlNewInputFromFile(ctxt, (char *) systemId));
00384     }
00385  *********/
00386     return(NULL);
00387 }
00388 
00398 static xmlEntityPtr
00399 getEntityDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name)
00400 {
00401     callbacks++;
00402     if (quiet)
00403     return(NULL);
00404     fprintf(stdout, "SAX.getEntity(%s)\n", name);
00405     return(NULL);
00406 }
00407 
00417 static xmlEntityPtr
00418 getParameterEntityDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name)
00419 {
00420     callbacks++;
00421     if (quiet)
00422     return(NULL);
00423     fprintf(stdout, "SAX.getParameterEntity(%s)\n", name);
00424     return(NULL);
00425 }
00426 
00427 
00439 static void
00440 entityDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, int type,
00441           const xmlChar *publicId, const xmlChar *systemId, xmlChar *content)
00442 {
00443 const xmlChar *nullstr = BAD_CAST "(null)";
00444     /* not all libraries handle printing null pointers nicely */
00445     if (publicId == NULL)
00446         publicId = nullstr;
00447     if (systemId == NULL)
00448         systemId = nullstr;
00449     if (content == NULL)
00450         content = (xmlChar *)nullstr;
00451     callbacks++;
00452     if (quiet)
00453     return;
00454     fprintf(stdout, "SAX.entityDecl(%s, %d, %s, %s, %s)\n",
00455             name, type, publicId, systemId, content);
00456 }
00457 
00466 static void
00467 attributeDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar * elem,
00468                    const xmlChar * name, int type, int def,
00469                    const xmlChar * defaultValue, xmlEnumerationPtr tree)
00470 {
00471     callbacks++;
00472     if (quiet)
00473         return;
00474     if (defaultValue == NULL)
00475         fprintf(stdout, "SAX.attributeDecl(%s, %s, %d, %d, NULL, ...)\n",
00476                 elem, name, type, def);
00477     else
00478         fprintf(stdout, "SAX.attributeDecl(%s, %s, %d, %d, %s, ...)\n",
00479                 elem, name, type, def, defaultValue);
00480     xmlFreeEnumeration(tree);
00481 }
00482 
00492 static void
00493 elementDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, int type,
00494         xmlElementContentPtr content ATTRIBUTE_UNUSED)
00495 {
00496     callbacks++;
00497     if (quiet)
00498     return;
00499     fprintf(stdout, "SAX.elementDecl(%s, %d, ...)\n",
00500             name, type);
00501 }
00502 
00512 static void
00513 notationDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name,
00514          const xmlChar *publicId, const xmlChar *systemId)
00515 {
00516     callbacks++;
00517     if (quiet)
00518     return;
00519     fprintf(stdout, "SAX.notationDecl(%s, %s, %s)\n",
00520             (char *) name, (char *) publicId, (char *) systemId);
00521 }
00522 
00533 static void
00534 unparsedEntityDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name,
00535            const xmlChar *publicId, const xmlChar *systemId,
00536            const xmlChar *notationName)
00537 {
00538 const xmlChar *nullstr = BAD_CAST "(null)";
00539 
00540     if (publicId == NULL)
00541         publicId = nullstr;
00542     if (systemId == NULL)
00543         systemId = nullstr;
00544     if (notationName == NULL)
00545         notationName = nullstr;
00546     callbacks++;
00547     if (quiet)
00548     return;
00549     fprintf(stdout, "SAX.unparsedEntityDecl(%s, %s, %s, %s)\n",
00550             (char *) name, (char *) publicId, (char *) systemId,
00551         (char *) notationName);
00552 }
00553 
00562 static void
00563 setDocumentLocatorDebug(void *ctx ATTRIBUTE_UNUSED, xmlSAXLocatorPtr loc ATTRIBUTE_UNUSED)
00564 {
00565     callbacks++;
00566     if (quiet)
00567     return;
00568     fprintf(stdout, "SAX.setDocumentLocator()\n");
00569 }
00570 
00577 static void
00578 startDocumentDebug(void *ctx ATTRIBUTE_UNUSED)
00579 {
00580     callbacks++;
00581     if (quiet)
00582     return;
00583     fprintf(stdout, "SAX.startDocument()\n");
00584 }
00585 
00592 static void
00593 endDocumentDebug(void *ctx ATTRIBUTE_UNUSED)
00594 {
00595     callbacks++;
00596     if (quiet)
00597     return;
00598     fprintf(stdout, "SAX.endDocument()\n");
00599 }
00600 
00608 static void
00609 startElementDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, const xmlChar **atts)
00610 {
00611     int i;
00612 
00613     callbacks++;
00614     if (quiet)
00615     return;
00616     fprintf(stdout, "SAX.startElement(%s", (char *) name);
00617     if (atts != NULL) {
00618         for (i = 0;(atts[i] != NULL);i++) {
00619         fprintf(stdout, ", %s='", atts[i++]);
00620         if (atts[i] != NULL)
00621             fprintf(stdout, "%s'", atts[i]);
00622     }
00623     }
00624     fprintf(stdout, ")\n");
00625 }
00626 
00634 static void
00635 endElementDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name)
00636 {
00637     callbacks++;
00638     if (quiet)
00639     return;
00640     fprintf(stdout, "SAX.endElement(%s)\n", (char *) name);
00641 }
00642 
00652 static void
00653 charactersDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *ch, int len)
00654 {
00655     char output[40];
00656     int i;
00657 
00658     callbacks++;
00659     if (quiet)
00660     return;
00661     for (i = 0;(i<len) && (i < 30);i++)
00662     output[i] = ch[i];
00663     output[i] = 0;
00664 
00665     fprintf(stdout, "SAX.characters(%s, %d)\n", output, len);
00666 }
00667 
00675 static void
00676 referenceDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name)
00677 {
00678     callbacks++;
00679     if (quiet)
00680     return;
00681     fprintf(stdout, "SAX.reference(%s)\n", name);
00682 }
00683 
00694 static void
00695 ignorableWhitespaceDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *ch, int len)
00696 {
00697     char output[40];
00698     int i;
00699 
00700     callbacks++;
00701     if (quiet)
00702     return;
00703     for (i = 0;(i<len) && (i < 30);i++)
00704     output[i] = ch[i];
00705     output[i] = 0;
00706     fprintf(stdout, "SAX.ignorableWhitespace(%s, %d)\n", output, len);
00707 }
00708 
00718 static void
00719 processingInstructionDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *target,
00720                       const xmlChar *data)
00721 {
00722     callbacks++;
00723     if (quiet)
00724     return;
00725     if (data != NULL)
00726     fprintf(stdout, "SAX.processingInstruction(%s, %s)\n",
00727         (char *) target, (char *) data);
00728     else
00729     fprintf(stdout, "SAX.processingInstruction(%s, NULL)\n",
00730         (char *) target);
00731 }
00732 
00741 static void
00742 cdataBlockDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *value, int len)
00743 {
00744     callbacks++;
00745     if (quiet)
00746     return;
00747     fprintf(stdout, "SAX.pcdata(%.20s, %d)\n",
00748         (char *) value, len);
00749 }
00750 
00758 static void
00759 commentDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *value)
00760 {
00761     callbacks++;
00762     if (quiet)
00763     return;
00764     fprintf(stdout, "SAX.comment(%s)\n", value);
00765 }
00766 
00776 static void XMLCDECL
00777 warningDebug(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...)
00778 {
00779     va_list args;
00780 
00781     callbacks++;
00782     if (quiet)
00783     return;
00784     va_start(args, msg);
00785     fprintf(stdout, "SAX.warning: ");
00786     vfprintf(stdout, msg, args);
00787     va_end(args);
00788 }
00789 
00799 static void XMLCDECL
00800 errorDebug(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...)
00801 {
00802     va_list args;
00803 
00804     callbacks++;
00805     if (quiet)
00806     return;
00807     va_start(args, msg);
00808     fprintf(stdout, "SAX.error: ");
00809     vfprintf(stdout, msg, args);
00810     va_end(args);
00811 }
00812 
00822 static void XMLCDECL
00823 fatalErrorDebug(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...)
00824 {
00825     va_list args;
00826 
00827     callbacks++;
00828     if (quiet)
00829     return;
00830     va_start(args, msg);
00831     fprintf(stdout, "SAX.fatalError: ");
00832     vfprintf(stdout, msg, args);
00833     va_end(args);
00834 }
00835 
00836 static xmlSAXHandler debugSAXHandlerStruct = {
00837     internalSubsetDebug,
00838     isStandaloneDebug,
00839     hasInternalSubsetDebug,
00840     hasExternalSubsetDebug,
00841     resolveEntityDebug,
00842     getEntityDebug,
00843     entityDeclDebug,
00844     notationDeclDebug,
00845     attributeDeclDebug,
00846     elementDeclDebug,
00847     unparsedEntityDeclDebug,
00848     setDocumentLocatorDebug,
00849     startDocumentDebug,
00850     endDocumentDebug,
00851     startElementDebug,
00852     endElementDebug,
00853     referenceDebug,
00854     charactersDebug,
00855     ignorableWhitespaceDebug,
00856     processingInstructionDebug,
00857     commentDebug,
00858     warningDebug,
00859     errorDebug,
00860     fatalErrorDebug,
00861     getParameterEntityDebug,
00862     cdataBlockDebug,
00863     externalSubsetDebug,
00864     1,
00865     NULL,
00866     NULL,
00867     NULL,
00868     NULL
00869 };
00870 
00871 xmlSAXHandlerPtr debugSAXHandler = &debugSAXHandlerStruct;
00872 
00873 /*
00874  * SAX2 specific callbacks
00875  */
00883 static void
00884 startElementNsDebug(void *ctx ATTRIBUTE_UNUSED,
00885                     const xmlChar *localname,
00886                     const xmlChar *prefix,
00887                     const xmlChar *URI,
00888             int nb_namespaces,
00889             const xmlChar **namespaces,
00890             int nb_attributes,
00891             int nb_defaulted,
00892             const xmlChar **attributes)
00893 {
00894     int i;
00895 
00896     callbacks++;
00897     if (quiet)
00898     return;
00899     fprintf(stdout, "SAX.startElementNs(%s", (char *) localname);
00900     if (prefix == NULL)
00901     fprintf(stdout, ", NULL");
00902     else
00903     fprintf(stdout, ", %s", (char *) prefix);
00904     if (URI == NULL)
00905     fprintf(stdout, ", NULL");
00906     else
00907     fprintf(stdout, ", '%s'", (char *) URI);
00908     fprintf(stdout, ", %d", nb_namespaces);
00909     
00910     if (namespaces != NULL) {
00911         for (i = 0;i < nb_namespaces * 2;i++) {
00912         fprintf(stdout, ", xmlns");
00913         if (namespaces[i] != NULL)
00914             fprintf(stdout, ":%s", namespaces[i]);
00915         i++;
00916         fprintf(stdout, "='%s'", namespaces[i]);
00917     }
00918     }
00919     fprintf(stdout, ", %d, %d", nb_attributes, nb_defaulted);
00920     if (attributes != NULL) {
00921         for (i = 0;i < nb_attributes * 5;i += 5) {
00922         if (attributes[i + 1] != NULL)
00923         fprintf(stdout, ", %s:%s='", attributes[i + 1], attributes[i]);
00924         else
00925         fprintf(stdout, ", %s='", attributes[i]);
00926         fprintf(stdout, "%.4s...', %d", attributes[i + 3],
00927             (int)(attributes[i + 4] - attributes[i + 3]));
00928     }
00929     }
00930     fprintf(stdout, ")\n");
00931 }
00932 
00940 static void
00941 endElementNsDebug(void *ctx ATTRIBUTE_UNUSED,
00942                   const xmlChar *localname,
00943                   const xmlChar *prefix,
00944                   const xmlChar *URI)
00945 {
00946     callbacks++;
00947     if (quiet)
00948     return;
00949     fprintf(stdout, "SAX.endElementNs(%s", (char *) localname);
00950     if (prefix == NULL)
00951     fprintf(stdout, ", NULL");
00952     else
00953     fprintf(stdout, ", %s", (char *) prefix);
00954     if (URI == NULL)
00955     fprintf(stdout, ", NULL)\n");
00956     else
00957     fprintf(stdout, ", '%s')\n", (char *) URI);
00958 }
00959 
00960 static xmlSAXHandler debugSAX2HandlerStruct = {
00961     internalSubsetDebug,
00962     isStandaloneDebug,
00963     hasInternalSubsetDebug,
00964     hasExternalSubsetDebug,
00965     resolveEntityDebug,
00966     getEntityDebug,
00967     entityDeclDebug,
00968     notationDeclDebug,
00969     attributeDeclDebug,
00970     elementDeclDebug,
00971     unparsedEntityDeclDebug,
00972     setDocumentLocatorDebug,
00973     startDocumentDebug,
00974     endDocumentDebug,
00975     NULL,
00976     NULL,
00977     referenceDebug,
00978     charactersDebug,
00979     ignorableWhitespaceDebug,
00980     processingInstructionDebug,
00981     commentDebug,
00982     warningDebug,
00983     errorDebug,
00984     fatalErrorDebug,
00985     getParameterEntityDebug,
00986     cdataBlockDebug,
00987     externalSubsetDebug,
00988     XML_SAX2_MAGIC,
00989     NULL,
00990     startElementNsDebug,
00991     endElementNsDebug,
00992     NULL
00993 };
00994 
00995 static xmlSAXHandlerPtr debugSAX2Handler = &debugSAX2HandlerStruct;
00996 
00997 /************************************************************************
00998  *                                  *
00999  *              Debug                   *
01000  *                                  *
01001  ************************************************************************/
01002 
01003 static void
01004 parseAndPrintFile(char *filename) {
01005     int res;
01006 
01007 #ifdef LIBXML_PUSH_ENABLED
01008     if (push) {
01009     FILE *f;
01010 
01011         if ((!quiet) && (!nonull)) {
01012         /*
01013          * Empty callbacks for checking
01014          */
01015 #if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__)
01016         f = fopen(filename, "rb");
01017 #else
01018         f = fopen(filename, "r");
01019 #endif
01020         if (f != NULL) {
01021         int ret;
01022         char chars[10];
01023         xmlParserCtxtPtr ctxt;
01024 
01025         ret = fread(chars, 1, 4, f);
01026         if (ret > 0) {
01027             ctxt = xmlCreatePushParserCtxt(emptySAXHandler, NULL,
01028                 chars, ret, filename);
01029             while ((ret = fread(chars, 1, 3, f)) > 0) {
01030             xmlParseChunk(ctxt, chars, ret, 0);
01031             }
01032             xmlParseChunk(ctxt, chars, 0, 1);
01033             xmlFreeParserCtxt(ctxt);
01034         }
01035         fclose(f);
01036         } else {
01037         xmlGenericError(xmlGenericErrorContext,
01038             "Cannot read file %s\n", filename);
01039         }
01040     }
01041     /*
01042      * Debug callback
01043      */
01044 #if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__)
01045     f = fopen(filename, "rb");
01046 #else
01047     f = fopen(filename, "r");
01048 #endif
01049     if (f != NULL) {
01050         int ret;
01051         char chars[10];
01052         xmlParserCtxtPtr ctxt;
01053 
01054         ret = fread(chars, 1, 4, f);
01055         if (ret > 0) {
01056             if (sax2)
01057             ctxt = xmlCreatePushParserCtxt(debugSAX2Handler, NULL,
01058                 chars, ret, filename);
01059         else
01060             ctxt = xmlCreatePushParserCtxt(debugSAXHandler, NULL,
01061                 chars, ret, filename);
01062         while ((ret = fread(chars, 1, 3, f)) > 0) {
01063             xmlParseChunk(ctxt, chars, ret, 0);
01064         }
01065         ret = xmlParseChunk(ctxt, chars, 0, 1);
01066         xmlFreeParserCtxt(ctxt);
01067         if (ret != 0) {
01068             fprintf(stdout,
01069                     "xmlSAXUserParseFile returned error %d\n", ret);
01070         }
01071         }
01072         fclose(f);
01073     }
01074     } else {
01075 #endif /* LIBXML_PUSH_ENABLED */
01076     if (!speed) {
01077         /*
01078          * Empty callbacks for checking
01079          */
01080         if ((!quiet) && (!nonull)) {
01081         res = xmlSAXUserParseFile(emptySAXHandler, NULL, filename);
01082         if (res != 0) {
01083             fprintf(stdout, "xmlSAXUserParseFile returned error %d\n", res);
01084         }
01085         }
01086 
01087         /*
01088          * Debug callback
01089          */
01090         callbacks = 0;
01091         if (repeat) {
01092             int i;
01093         for (i = 0;i < 99;i++) {
01094             if (sax2)
01095             res = xmlSAXUserParseFile(debugSAX2Handler, NULL,
01096                                       filename);
01097             else
01098             res = xmlSAXUserParseFile(debugSAXHandler, NULL,
01099                                       filename);
01100         }
01101         }
01102         if (sax2)
01103             res = xmlSAXUserParseFile(debugSAX2Handler, NULL, filename);
01104         else
01105         res = xmlSAXUserParseFile(debugSAXHandler, NULL, filename);
01106         if (res != 0) {
01107         fprintf(stdout, "xmlSAXUserParseFile returned error %d\n", res);
01108         }
01109         if (quiet)
01110         fprintf(stdout, "%d callbacks generated\n", callbacks);
01111     } else {
01112         /*
01113          * test 100x the SAX parse
01114          */
01115         int i;
01116 
01117         for (i = 0; i<100;i++)
01118         res = xmlSAXUserParseFile(emptySAXHandler, NULL, filename);
01119         if (res != 0) {
01120         fprintf(stdout, "xmlSAXUserParseFile returned error %d\n", res);
01121         }
01122     }
01123 #ifdef LIBXML_PUSH_ENABLED
01124     }
01125 #endif
01126 }
01127 
01128 
01129 int main(int argc, char **argv) {
01130     int i;
01131     int files = 0;
01132 
01133     LIBXML_TEST_VERSION /* be safe, plus calls xmlInitParser */
01134     
01135     for (i = 1; i < argc ; i++) {
01136     if ((!strcmp(argv[i], "-debug")) || (!strcmp(argv[i], "--debug")))
01137         debug++;
01138     else if ((!strcmp(argv[i], "-copy")) || (!strcmp(argv[i], "--copy")))
01139         copy++;
01140     else if ((!strcmp(argv[i], "-recover")) ||
01141              (!strcmp(argv[i], "--recover")))
01142         recovery++;
01143     else if ((!strcmp(argv[i], "-push")) ||
01144              (!strcmp(argv[i], "--push")))
01145 #ifdef LIBXML_PUSH_ENABLED
01146         push++;
01147 #else
01148         fprintf(stderr,"'push' not enabled in library - ignoring\n");
01149 #endif /* LIBXML_PUSH_ENABLED */
01150     else if ((!strcmp(argv[i], "-speed")) ||
01151              (!strcmp(argv[i], "--speed")))
01152         speed++;
01153     else if ((!strcmp(argv[i], "-timing")) ||
01154              (!strcmp(argv[i], "--timing"))) {
01155         nonull++;
01156         timing++;
01157         quiet++;
01158     } else if ((!strcmp(argv[i], "-repeat")) ||
01159              (!strcmp(argv[i], "--repeat"))) {
01160         repeat++;
01161         quiet++;
01162     } else if ((!strcmp(argv[i], "-noent")) ||
01163              (!strcmp(argv[i], "--noent")))
01164         noent++;
01165     else if ((!strcmp(argv[i], "-quiet")) ||
01166              (!strcmp(argv[i], "--quiet")))
01167         quiet++;
01168     else if ((!strcmp(argv[i], "-sax2")) ||
01169              (!strcmp(argv[i], "--sax2")))
01170         sax2++;
01171     else if ((!strcmp(argv[i], "-nonull")) ||
01172              (!strcmp(argv[i], "--nonull")))
01173         nonull++;
01174     }
01175     if (noent != 0) xmlSubstituteEntitiesDefault(1);
01176     for (i = 1; i < argc ; i++) {
01177     if (argv[i][0] != '-') {
01178         if (timing) {
01179         startTimer();
01180         }
01181         parseAndPrintFile(argv[i]);
01182         if (timing) {
01183         endTimer("Parsing");
01184         }
01185         files ++;
01186     }
01187     }
01188     xmlCleanupParser();
01189     xmlMemoryDump();
01190 
01191     return(0);
01192 }
01193 #else
01194 int main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) {
01195     printf("%s : SAX1 parsing support not compiled in\n", argv[0]);
01196     return(0);
01197 }
01198 #endif /* LIBXML_SAX1_ENABLED */

Generated on Fri May 25 2012 04:33:11 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.