version 1.1.1.2, 2017/06/17 21:59:08 |
version 1.1.1.2.6.1, 2020/04/13 08:02:22 |
|
|
|
/* |
|
__ __ _ |
|
___\ \/ /_ __ __ _| |_ |
|
/ _ \\ /| '_ \ / _` | __| |
|
| __// \| |_) | (_| | |_ |
|
\___/_/\_\ .__/ \__,_|\__| |
|
|_| XML parser |
|
|
|
Copyright (c) 1997-2000 Thai Open Source Software Center Ltd |
|
Copyright (c) 2000-2017 Expat development team |
|
Licensed under the MIT license: |
|
|
|
Permission is hereby granted, free of charge, to any person obtaining |
|
a copy of this software and associated documentation files (the |
|
"Software"), to deal in the Software without restriction, including |
|
without limitation the rights to use, copy, modify, merge, publish, |
|
distribute, sublicense, and/or sell copies of the Software, and to permit |
|
persons to whom the Software is furnished to do so, subject to the |
|
following conditions: |
|
|
|
The above copyright notice and this permission notice shall be included |
|
in all copies or substantial portions of the Software. |
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN |
|
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
|
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
|
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE |
|
USE OR OTHER DEALINGS IN THE SOFTWARE. |
|
*/ |
|
|
#include <sys/stat.h> |
#include <sys/stat.h> |
#include <stdlib.h> |
#include <stdlib.h> |
#include <stdio.h> |
#include <stdio.h> |
|
|
#include "expat.h" |
#include "expat.h" |
|
|
#ifdef XML_LARGE_SIZE |
#ifdef XML_LARGE_SIZE |
#define XML_FMT_INT_MOD "ll" |
# define XML_FMT_INT_MOD "ll" |
#else |
#else |
#define XML_FMT_INT_MOD "l" |
# define XML_FMT_INT_MOD "l" |
|
#endif |
|
|
|
#ifdef XML_UNICODE_WCHAR_T |
|
# define XML_FMT_STR "ls" |
|
#else |
|
# define XML_FMT_STR "s" |
#endif |
#endif |
|
|
static void |
static void |
usage(const char *prog, int rc) |
usage(const char *prog, int rc) { |
{ |
fprintf(stderr, "usage: %s [-n] filename bufferSize nr_of_loops\n", prog); |
fprintf(stderr, |
|
"usage: %s [-n] filename bufferSize nr_of_loops\n", prog); |
|
exit(rc); |
exit(rc); |
} |
} |
|
|
int main (int argc, char *argv[]) |
int |
{ |
main(int argc, char *argv[]) { |
XML_Parser parser; |
XML_Parser parser; |
char *XMLBuf, *XMLBufEnd, *XMLBufPtr; |
char *XMLBuf, *XMLBufEnd, *XMLBufPtr; |
FILE *fd; |
FILE *fd; |
struct stat fileAttr; |
struct stat fileAttr; |
int nrOfLoops, bufferSize, fileSize, i, isFinal; |
int nrOfLoops, bufferSize, fileSize, i, isFinal; |
int j = 0, ns = 0; |
int j = 0, ns = 0; |
clock_t tstart, tend; |
clock_t tstart, tend; |
double cpuTime = 0.0; |
double cpuTime = 0.0; |
|
|
if (argc > 1) { |
if (argc > 1) { |
if (argv[1][0] == '-') { |
if (argv[1][0] == '-') { |
if (argv[1][1] == 'n' && argv[1][2] == '\0') { |
if (argv[1][1] == 'n' && argv[1][2] == '\0') { |
ns = 1; |
ns = 1; |
j = 1; |
j = 1; |
} |
} else |
else |
|
usage(argv[0], 1); |
usage(argv[0], 1); |
} |
} |
} |
} |
Line 43 int main (int argc, char *argv[]) |
|
Line 78 int main (int argc, char *argv[]) |
|
if (argc != j + 4) |
if (argc != j + 4) |
usage(argv[0], 1); |
usage(argv[0], 1); |
|
|
if (stat (argv[j + 1], &fileAttr) != 0) { |
if (stat(argv[j + 1], &fileAttr) != 0) { |
fprintf (stderr, "could not access file '%s'\n", argv[j + 1]); |
fprintf(stderr, "could not access file '%s'\n", argv[j + 1]); |
return 2; |
return 2; |
} |
} |
|
|
fd = fopen (argv[j + 1], "r"); |
fd = fopen(argv[j + 1], "r"); |
if (!fd) { |
if (! fd) { |
fprintf (stderr, "could not open file '%s'\n", argv[j + 1]); |
fprintf(stderr, "could not open file '%s'\n", argv[j + 1]); |
exit(2); |
exit(2); |
} |
} |
|
|
bufferSize = atoi (argv[j + 2]); |
bufferSize = atoi(argv[j + 2]); |
nrOfLoops = atoi (argv[j + 3]); |
nrOfLoops = atoi(argv[j + 3]); |
if (bufferSize <= 0 || nrOfLoops <= 0) { |
if (bufferSize <= 0 || nrOfLoops <= 0) { |
fprintf (stderr, |
fprintf(stderr, "buffer size and nr of loops must be greater than zero.\n"); |
"buffer size and nr of loops must be greater than zero.\n"); |
|
exit(3); |
exit(3); |
} |
} |
|
|
XMLBuf = malloc (fileAttr.st_size); |
XMLBuf = malloc(fileAttr.st_size); |
fileSize = fread (XMLBuf, sizeof (char), fileAttr.st_size, fd); |
fileSize = fread(XMLBuf, sizeof(char), fileAttr.st_size, fd); |
fclose (fd); |
fclose(fd); |
|
|
if (ns) |
if (ns) |
parser = XML_ParserCreateNS(NULL, '!'); |
parser = XML_ParserCreateNS(NULL, '!'); |
else |
else |
Line 83 int main (int argc, char *argv[]) |
|
Line 117 int main (int argc, char *argv[]) |
|
isFinal = 1; |
isFinal = 1; |
else |
else |
parseBufferSize = bufferSize; |
parseBufferSize = bufferSize; |
if (!XML_Parse (parser, XMLBufPtr, parseBufferSize, isFinal)) { |
if (! XML_Parse(parser, XMLBufPtr, parseBufferSize, isFinal)) { |
fprintf (stderr, "error '%s' at line %" XML_FMT_INT_MOD \ |
fprintf(stderr, |
"u character %" XML_FMT_INT_MOD "u\n", |
"error '%" XML_FMT_STR "' at line %" XML_FMT_INT_MOD |
XML_ErrorString (XML_GetErrorCode (parser)), |
"u character %" XML_FMT_INT_MOD "u\n", |
XML_GetCurrentLineNumber (parser), |
XML_ErrorString(XML_GetErrorCode(parser)), |
XML_GetCurrentColumnNumber (parser)); |
XML_GetCurrentLineNumber(parser), |
free (XMLBuf); |
XML_GetCurrentColumnNumber(parser)); |
XML_ParserFree (parser); |
free(XMLBuf); |
exit (4); |
XML_ParserFree(parser); |
|
exit(4); |
} |
} |
XMLBufPtr += bufferSize; |
XMLBufPtr += bufferSize; |
} while (!isFinal); |
} while (! isFinal); |
tend = clock(); |
tend = clock(); |
cpuTime += ((double) (tend - tstart)) / CLOCKS_PER_SEC; |
cpuTime += ((double)(tend - tstart)) / CLOCKS_PER_SEC; |
XML_ParserReset(parser, NULL); |
XML_ParserReset(parser, NULL); |
i++; |
i++; |
} |
} |
|
|
XML_ParserFree (parser); |
XML_ParserFree(parser); |
free (XMLBuf); |
free(XMLBuf); |
|
|
printf ("%d loops, with buffer size %d. Average time per loop: %f\n", |
printf("%d loops, with buffer size %d. Average time per loop: %f\n", |
nrOfLoops, bufferSize, cpuTime / (double) nrOfLoops); |
nrOfLoops, bufferSize, cpuTime / (double)nrOfLoops); |
return 0; |
return 0; |
} |
} |