[Expat-checkins] CVS: expat/xmlwf xmlfile.c,1.8,1.9 xmlwf.c,1.57,1.58

Fred L. Drake fdrake@users.sourceforge.net
Fri Apr 19 14:42:04 2002


Update of /cvsroot/expat/expat/xmlwf
In directory usw-pr-cvs1:/tmp/cvs-serv10505

Modified Files:
	xmlfile.c xmlwf.c 
Log Message:
Check in SF patch #488196: Make xmlwf read from standard input.
This modifies the patch for style (slightly).

The style of these files is also slightly modified in an attempt to create
more consistency.  (But that mostly swamps the feature patch.)


Index: xmlfile.c
===================================================================
RCS file: /cvsroot/expat/expat/xmlwf/xmlfile.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** xmlfile.c	21 Sep 2000 21:20:18 -0000	1.8
--- xmlfile.c	19 Apr 2002 21:41:54 -0000	1.9
***************
*** 43,48 ****
  } PROCESS_ARGS;
  
! static
! void reportError(XML_Parser parser, const XML_Char *filename)
  {
    int code = XML_GetErrorCode(parser);
--- 43,48 ----
  } PROCESS_ARGS;
  
! static void
! reportError(XML_Parser parser, const XML_Char *filename)
  {
    int code = XML_GetErrorCode(parser);
***************
*** 58,66 ****
  }
  
! static
! void processFile(const void *data,
! 		 size_t size,
! 		 const XML_Char *filename,
! 		 void *args)
  {
    XML_Parser parser = ((PROCESS_ARGS *)args)->parser;
--- 58,64 ----
  }
  
! static void
! processFile(const void *data, size_t size,
! 	    const XML_Char *filename, void *args)
  {
    XML_Parser parser = ((PROCESS_ARGS *)args)->parser;
***************
*** 76,81 ****
  #ifdef WIN32
  
! static
! int isAsciiLetter(XML_Char c)
  {
    return (T('a') <= c && c <= T('z')) || (T('A') <= c && c <= T('Z'));
--- 74,79 ----
  #ifdef WIN32
  
! static int
! isAsciiLetter(XML_Char c)
  {
    return (T('a') <= c && c <= T('z')) || (T('A') <= c && c <= T('Z'));
***************
*** 84,89 ****
  #endif /* WIN32 */
  
! static
! const XML_Char *resolveSystemId(const XML_Char *base, const XML_Char *systemId, XML_Char **toFree)
  {
    XML_Char *s;
--- 82,88 ----
  #endif /* WIN32 */
  
! static const XML_Char *
! resolveSystemId(const XML_Char *base, const XML_Char *systemId,
! 		XML_Char **toFree)
  {
    XML_Char *s;
***************
*** 97,101 ****
       )
      return systemId;
!   *toFree = (XML_Char *)malloc((tcslen(base) + tcslen(systemId) + 2)*sizeof(XML_Char));
    if (!*toFree)
      return systemId;
--- 96,101 ----
       )
      return systemId;
!   *toFree = (XML_Char *)malloc((tcslen(base) + tcslen(systemId) + 2)
! 			       * sizeof(XML_Char));
    if (!*toFree)
      return systemId;
***************
*** 112,121 ****
  }
  
! static
! int externalEntityRefFilemap(XML_Parser parser,
! 			     const XML_Char *context,
! 			     const XML_Char *base,
! 			     const XML_Char *systemId,
! 			     const XML_Char *publicId)
  {
    int result;
--- 112,121 ----
  }
  
! static int
! externalEntityRefFilemap(XML_Parser parser,
! 			 const XML_Char *context,
! 			 const XML_Char *base,
! 			 const XML_Char *systemId,
! 			 const XML_Char *publicId)
  {
    int result;
***************
*** 135,145 ****
  }
  
! static
! int processStream(const XML_Char *filename, XML_Parser parser)
  {
!   int fd = topen(filename, O_BINARY|O_RDONLY);
!   if (fd < 0) {
!     tperror(filename);
!     return 0;
    }
    for (;;) {
--- 135,150 ----
  }
  
! static int
! processStream(const XML_Char *filename, XML_Parser parser)
  {
!   /* passing NULL for filename means read intput from stdin */
!   int fd = 0;   /* 0 is the fileno for stdin */
! 
!   if (filename != NULL) {
!     fd = topen(filename, O_BINARY|O_RDONLY);
!     if (fd < 0) {
!       tperror(filename);
!       return 0;
!     }
    }
    for (;;) {
***************
*** 147,167 ****
      char *buf = XML_GetBuffer(parser, READ_SIZE);
      if (!buf) {
!       close(fd);
!       ftprintf(stderr, T("%s: out of memory\n"), filename);
        return 0;
      }
      nread = read(fd, buf, READ_SIZE);
      if (nread < 0) {
!       tperror(filename);
!       close(fd);
        return 0;
      }
      if (!XML_ParseBuffer(parser, nread, nread == 0)) {
!       reportError(parser, filename);
!       close(fd);
        return 0;
      }
      if (nread == 0) {
!       close(fd);
        break;;
      }
--- 152,177 ----
      char *buf = XML_GetBuffer(parser, READ_SIZE);
      if (!buf) {
!       if (filename != NULL)
! 	close(fd);
!       ftprintf(stderr, T("%s: out of memory\n"),
! 	       filename != NULL ? filename : "xmlwf");
        return 0;
      }
      nread = read(fd, buf, READ_SIZE);
      if (nread < 0) {
!       tperror(filename != NULL ? filename : "STDIN");
!       if (filename != NULL)
! 	close(fd);
        return 0;
      }
      if (!XML_ParseBuffer(parser, nread, nread == 0)) {
!       reportError(parser, filename != NULL ? filename : "STDIN");
!       if (filename != NULL)
! 	close(fd);
        return 0;
      }
      if (nread == 0) {
!       if (filename != NULL)
! 	close(fd);
        break;;
      }
***************
*** 170,179 ****
  }
  
! static
! int externalEntityRefStream(XML_Parser parser,
! 			    const XML_Char *context,
! 			    const XML_Char *base,
! 			    const XML_Char *systemId,
! 			    const XML_Char *publicId)
  {
    XML_Char *s;
--- 180,189 ----
  }
  
! static int
! externalEntityRefStream(XML_Parser parser,
! 			const XML_Char *context,
! 			const XML_Char *base,
! 			const XML_Char *systemId,
! 			const XML_Char *publicId)
  {
    XML_Char *s;
***************
*** 189,195 ****
  }
  
! int XML_ProcessFile(XML_Parser parser,
! 		    const XML_Char *filename,
! 		    unsigned flags)
  {
    int result;
--- 199,206 ----
  }
  
! int
! XML_ProcessFile(XML_Parser parser,
! 		const XML_Char *filename,
! 		unsigned flags)
  {
    int result;

Index: xmlwf.c
===================================================================
RCS file: /cvsroot/expat/expat/xmlwf/xmlwf.c,v
retrieving revision 1.57
retrieving revision 1.58
diff -C2 -d -r1.57 -r1.58
*** xmlwf.c	19 Apr 2002 16:19:33 -0000	1.57
--- xmlwf.c	19 Apr 2002 21:41:54 -0000	1.58
***************
*** 22,26 ****
  #define NSSEP T('\001')
  
! static void characterData(void *userData, const XML_Char *s, int len)
  {
    FILE *fp = userData;
--- 22,27 ----
  #define NSSEP T('\001')
  
! static void
! characterData(void *userData, const XML_Char *s, int len)
  {
    FILE *fp = userData;
***************
*** 57,61 ****
  }
  
! static void attributeValue(FILE *fp, const XML_Char *s)
  {
    puttc(T('='), fp);
--- 58,63 ----
  }
  
! static void
! attributeValue(FILE *fp, const XML_Char *s)
  {
    puttc(T('='), fp);
***************
*** 107,117 ****
  is equivalent to lexicographically comparing based on the character number. */
  
! static int attcmp(const void *att1, const void *att2)
  {
    return tcscmp(*(const XML_Char **)att1, *(const XML_Char **)att2);
  }
  
! static void startElement(void *userData, const XML_Char *name,
! 			 const XML_Char **atts)
  {
    int nAtts;
--- 109,120 ----
  is equivalent to lexicographically comparing based on the character number. */
  
! static int
! attcmp(const void *att1, const void *att2)
  {
    return tcscmp(*(const XML_Char **)att1, *(const XML_Char **)att2);
  }
  
! static void
! startElement(void *userData, const XML_Char *name, const XML_Char **atts)
  {
    int nAtts;
***************
*** 136,140 ****
  }
  
! static void endElement(void *userData, const XML_Char *name)
  {
    FILE *fp = userData;
--- 139,144 ----
  }
  
! static void
! endElement(void *userData, const XML_Char *name)
  {
    FILE *fp = userData;
***************
*** 145,149 ****
  }
  
! static int nsattcmp(const void *p1, const void *p2)
  {
    const XML_Char *att1 = *(const XML_Char **)p1;
--- 149,154 ----
  }
  
! static int
! nsattcmp(const void *p1, const void *p2)
  {
    const XML_Char *att1 = *(const XML_Char **)p1;
***************
*** 156,161 ****
  }
  
! static void startElementNS(void *userData, const XML_Char *name,
! 			   const XML_Char **atts)
  {
    int nAtts;
--- 161,166 ----
  }
  
! static void
! startElementNS(void *userData, const XML_Char *name, const XML_Char **atts)
  {
    int nAtts;
***************
*** 205,209 ****
  }
  
! static void endElementNS(void *userData, const XML_Char *name)
  {
    FILE *fp = userData;
--- 210,215 ----
  }
  
! static void
! endElementNS(void *userData, const XML_Char *name)
  {
    FILE *fp = userData;
***************
*** 223,228 ****
  #ifndef W3C14N
  
! static void processingInstruction(void *userData, const XML_Char *target,
! 				  const XML_Char *data)
  {
    FILE *fp = userData;
--- 229,235 ----
  #ifndef W3C14N
  
! static void
! processingInstruction(void *userData, const XML_Char *target,
! 		      const XML_Char *data)
  {
    FILE *fp = userData;
***************
*** 238,283 ****
  #endif /* not W3C14N */
  
! static void defaultCharacterData(XML_Parser parser, const XML_Char *s, int len)
  {
    XML_DefaultCurrent(parser);
  }
  
! static void defaultStartElement(XML_Parser parser, const XML_Char *name,
! 				const XML_Char **atts)
  {
    XML_DefaultCurrent(parser);
  }
  
! static void defaultEndElement(XML_Parser parser, const XML_Char *name)
  {
    XML_DefaultCurrent(parser);
  }
  
! static void defaultProcessingInstruction(XML_Parser parser,
! 					 const XML_Char *target,
! 					 const XML_Char *data)
  {
    XML_DefaultCurrent(parser);
  }
  
! static void nopCharacterData(XML_Parser parser, const XML_Char *s, int len)
  {
  }
  
! static void nopStartElement(XML_Parser parser, const XML_Char *name,
! 			    const XML_Char **atts)
  {
  }
  
! static void nopEndElement(XML_Parser parser, const XML_Char *name)
  {
  }
  
! static void nopProcessingInstruction(XML_Parser parser, const XML_Char *target,
! 				     const XML_Char *data)
  {
  }
  
! static void markup(XML_Parser parser, const XML_Char *s, int len)
  {
    FILE *fp = XML_GetUserData(parser);
--- 245,297 ----
  #endif /* not W3C14N */
  
! static void
! defaultCharacterData(XML_Parser parser, const XML_Char *s, int len)
  {
    XML_DefaultCurrent(parser);
  }
  
! static void
! defaultStartElement(XML_Parser parser, const XML_Char *name,
! 		    const XML_Char **atts)
  {
    XML_DefaultCurrent(parser);
  }
  
! static void
! defaultEndElement(XML_Parser parser, const XML_Char *name)
  {
    XML_DefaultCurrent(parser);
  }
  
! static void
! defaultProcessingInstruction(XML_Parser parser, const XML_Char *target,
! 			     const XML_Char *data)
  {
    XML_DefaultCurrent(parser);
  }
  
! static void
! nopCharacterData(XML_Parser parser, const XML_Char *s, int len)
  {
  }
  
! static void
! nopStartElement(XML_Parser parser, const XML_Char *name, const XML_Char **atts)
  {
  }
  
! static void
! nopEndElement(XML_Parser parser, const XML_Char *name)
  {
  }
  
! static void
! nopProcessingInstruction(XML_Parser parser, const XML_Char *target,
! 			 const XML_Char *data)
  {
  }
  
! static void
! markup(XML_Parser parser, const XML_Char *s, int len)
  {
    FILE *fp = XML_GetUserData(parser);
***************
*** 286,291 ****
  }
  
! static
! void metaLocation(XML_Parser parser)
  {
    const XML_Char *uri = XML_GetBase(parser);
--- 300,305 ----
  }
  
! static void
! metaLocation(XML_Parser parser)
  {
    const XML_Char *uri = XML_GetBase(parser);
***************
*** 300,318 ****
  }
  
! static
! void metaStartDocument(XML_Parser parser)
  {
    fputts(T("<document>\n"), XML_GetUserData(parser));
  }
  
! static
! void metaEndDocument(XML_Parser parser)
  {
    fputts(T("</document>\n"), XML_GetUserData(parser));
  }
  
! static
! void metaStartElement(XML_Parser parser, const XML_Char *name,
! 		      const XML_Char **atts)
  {
    FILE *fp = XML_GetUserData(parser);
--- 314,332 ----
  }
  
! static void
! metaStartDocument(XML_Parser parser)
  {
    fputts(T("<document>\n"), XML_GetUserData(parser));
  }
  
! static void
! metaEndDocument(XML_Parser parser)
  {
    fputts(T("</document>\n"), XML_GetUserData(parser));
  }
  
! static void
! metaStartElement(XML_Parser parser, const XML_Char *name,
! 		 const XML_Char **atts)
  {
    FILE *fp = XML_GetUserData(parser);
***************
*** 346,351 ****
  }
  
! static
! void metaEndElement(XML_Parser parser, const XML_Char *name)
  {
    FILE *fp = XML_GetUserData(parser);
--- 360,365 ----
  }
  
! static void
! metaEndElement(XML_Parser parser, const XML_Char *name)
  {
    FILE *fp = XML_GetUserData(parser);
***************
*** 355,361 ****
  }
  
! static
! void metaProcessingInstruction(XML_Parser parser, const XML_Char *target,
! 			       const XML_Char *data)
  {
    FILE *fp = XML_GetUserData(parser);
--- 369,375 ----
  }
  
! static void
! metaProcessingInstruction(XML_Parser parser, const XML_Char *target,
! 			  const XML_Char *data)
  {
    FILE *fp = XML_GetUserData(parser);
***************
*** 367,372 ****
  }
  
! static
! void metaComment(XML_Parser parser, const XML_Char *data)
  {
    FILE *fp = XML_GetUserData(parser);
--- 381,386 ----
  }
  
! static void
! metaComment(XML_Parser parser, const XML_Char *data)
  {
    FILE *fp = XML_GetUserData(parser);
***************
*** 378,383 ****
  }
  
! static
! void metaStartCdataSection(XML_Parser parser)
  {
    FILE *fp = XML_GetUserData(parser);
--- 392,397 ----
  }
  
! static void
! metaStartCdataSection(XML_Parser parser)
  {
    FILE *fp = XML_GetUserData(parser);
***************
*** 387,392 ****
  }
  
! static
! void metaEndCdataSection(XML_Parser parser)
  {
    FILE *fp = XML_GetUserData(parser);
--- 401,406 ----
  }
  
! static void
! metaEndCdataSection(XML_Parser parser)
  {
    FILE *fp = XML_GetUserData(parser);
***************
*** 396,401 ****
  }
  
! static
! void metaCharacterData(XML_Parser parser, const XML_Char *s, int len)
  {
    FILE *fp = XML_GetUserData(parser);
--- 410,415 ----
  }
  
! static void
! metaCharacterData(XML_Parser parser, const XML_Char *s, int len)
  {
    FILE *fp = XML_GetUserData(parser);
***************
*** 407,416 ****
  }
  
! static
! void metaStartDoctypeDecl(XML_Parser parser,
! 			  const XML_Char *doctypeName,
! 			  const XML_Char *sysid,
! 			  const XML_Char *pubid,
! 			  int has_internal_subset)
  {
    FILE *fp = XML_GetUserData(parser);
--- 421,430 ----
  }
  
! static void
! metaStartDoctypeDecl(XML_Parser parser,
! 		     const XML_Char *doctypeName,
! 		     const XML_Char *sysid,
! 		     const XML_Char *pubid,
! 		     int has_internal_subset)
  {
    FILE *fp = XML_GetUserData(parser);
***************
*** 420,425 ****
  }
  
! static
! void metaEndDoctypeDecl(XML_Parser parser)
  {
    FILE *fp = XML_GetUserData(parser);
--- 434,439 ----
  }
  
! static void
! metaEndDoctypeDecl(XML_Parser parser)
  {
    FILE *fp = XML_GetUserData(parser);
***************
*** 429,438 ****
  }
  
! static
! void metaNotationDecl(XML_Parser parser,
! 		      const XML_Char *notationName,
! 		      const XML_Char *base,
! 		      const XML_Char *systemId,
! 		      const XML_Char *publicId)
  {
    FILE *fp = XML_GetUserData(parser);
--- 443,452 ----
  }
  
! static void
! metaNotationDecl(XML_Parser parser,
! 		 const XML_Char *notationName,
! 		 const XML_Char *base,
! 		 const XML_Char *systemId,
! 		 const XML_Char *publicId)
  {
    FILE *fp = XML_GetUserData(parser);
***************
*** 450,463 ****
  
  
! static
! void metaEntityDecl(XML_Parser parser,
! 		    const XML_Char *entityName,
! 		    int  is_param,
! 		    const XML_Char *value,
! 		    int  value_length,
! 		    const XML_Char *base,
! 		    const XML_Char *systemId,
! 		    const XML_Char *publicId,
! 		    const XML_Char *notationName)
  {
    FILE *fp = XML_GetUserData(parser);
--- 464,477 ----
  
  
! static void
! metaEntityDecl(XML_Parser parser,
! 	       const XML_Char *entityName,
! 	       int  is_param,
! 	       const XML_Char *value,
! 	       int  value_length,
! 	       const XML_Char *base,
! 	       const XML_Char *systemId,
! 	       const XML_Char *publicId,
! 	       const XML_Char *notationName)
  {
    FILE *fp = XML_GetUserData(parser);
***************
*** 493,500 ****
  }
  
! static
! void metaStartNamespaceDecl(XML_Parser parser,
! 			    const XML_Char *prefix,
! 			    const XML_Char *uri)
  {
    FILE *fp = XML_GetUserData(parser);
--- 507,514 ----
  }
  
! static void
! metaStartNamespaceDecl(XML_Parser parser,
! 		       const XML_Char *prefix,
! 		       const XML_Char *uri)
  {
    FILE *fp = XML_GetUserData(parser);
***************
*** 511,516 ****
  }
  
! static
! void metaEndNamespaceDecl(XML_Parser parser, const XML_Char *prefix)
  {
    FILE *fp = XML_GetUserData(parser);
--- 525,530 ----
  }
  
! static void
! metaEndNamespaceDecl(XML_Parser parser, const XML_Char *prefix)
  {
    FILE *fp = XML_GetUserData(parser);
***************
*** 521,534 ****
  }
  
! static
! int unknownEncodingConvert(void *data, const char *p)
  {
    return codepageConvert(*(int *)data, p);
  }
  
! static
! int unknownEncoding(void *userData,
! 		    const XML_Char *name,
! 		    XML_Encoding *info)
  {
    int cp;
--- 535,546 ----
  }
  
! static int
! unknownEncodingConvert(void *data, const char *p)
  {
    return codepageConvert(*(int *)data, p);
  }
  
! static int
! unknownEncoding(void *userData, const XML_Char *name, XML_Encoding *info)
  {
    int cp;
***************
*** 565,576 ****
  }
  
! static
! int notStandalone(void *userData)
  {
    return 0;
  }
  
! static
! void showVersion(XML_Char *prog)
  {
    XML_Char *s = prog;
--- 577,588 ----
  }
  
! static int
! notStandalone(void *userData)
  {
    return 0;
  }
  
! static void
! showVersion(XML_Char *prog)
  {
    XML_Char *s = prog;
***************
*** 584,597 ****
  }
  
! static
! void usage(const XML_Char *prog)
  {
    ftprintf(stderr,
  	   T("usage: %s [-n] [-p] [-r] [-s] [-w] [-x] [-d output-dir] "
  	     "[-e encoding] file ...\n"), prog);
!   exit(1);
  }
  
! int tmain(int argc, XML_Char **argv)
  {
    int i, j;
--- 596,610 ----
  }
  
! static void
! usage(const XML_Char *prog, int rc)
  {
    ftprintf(stderr,
  	   T("usage: %s [-n] [-p] [-r] [-s] [-w] [-x] [-d output-dir] "
  	     "[-e encoding] file ...\n"), prog);
!   exit(rc);
  }
  
! int
! tmain(int argc, XML_Char **argv)
  {
    int i, j;
***************
*** 604,607 ****
--- 617,621 ----
    int requireStandalone = 0;
    int paramEntityParsing = XML_PARAM_ENTITY_PARSING_NEVER;
+   int useStdin = 0;
  
  #ifdef _MSC_VER
***************
*** 661,665 ****
        if (argv[i][j + 1] == T('\0')) {
  	if (++i == argc)
! 	  usage(argv[0]);
  	outputDir = argv[i];
        }
--- 675,679 ----
        if (argv[i][j + 1] == T('\0')) {
  	if (++i == argc)
! 	  usage(argv[0], 2);
  	outputDir = argv[i];
        }
***************
*** 672,676 ****
        if (argv[i][j + 1] == T('\0')) {
  	if (++i == argc)
! 	  usage(argv[0]);
  	encoding = argv[i];
        }
--- 686,690 ----
        if (argv[i][j + 1] == T('\0')) {
  	if (++i == argc)
! 	  usage(argv[0], 2);
  	encoding = argv[i];
        }
***************
*** 680,683 ****
--- 694,700 ----
        j = 0;
        break;
+     case T('h'):
+       usage(argv[0], 0);
+       return 0;
      case T('v'):
        showVersion(argv[0]);
***************
*** 691,699 ****
        /* fall through */
      default:
!       usage(argv[0]);
      }
    }
!   if (i == argc)
!     usage(argv[0]);
    for (; i < argc; i++) {
      FILE *fp = 0;
--- 708,719 ----
        /* fall through */
      default:
!       usage(argv[0], 2);
      }
    }
!   if (i == argc) {
!     useStdin = 1;
!     processFlags &= ~XML_MAP_FILE;
!     i--;
!   }
    for (; i < argc; i++) {
      FILE *fp = 0;
***************
*** 717,721 ****
      }
      else if (outputDir) {
!       const XML_Char *file = argv[i];
        if (tcsrchr(file, T('/')))
  	file = tcsrchr(file, T('/')) + 1;
--- 737,741 ----
      }
      else if (outputDir) {
!       const XML_Char *file = useStdin ? T("STDIN") : argv[i];
        if (tcsrchr(file, T('/')))
  	file = tcsrchr(file, T('/')) + 1;
***************
*** 778,782 ****
      if (windowsCodePages)
        XML_SetUnknownEncodingHandler(parser, unknownEncoding, 0);
!     result = XML_ProcessFile(parser, argv[i], processFlags);
      if (outputDir) {
        if (outputType == 'm')
--- 798,802 ----
      if (windowsCodePages)
        XML_SetUnknownEncodingHandler(parser, unknownEncoding, 0);
!     result = XML_ProcessFile(parser, useStdin ? NULL : argv[i], processFlags);
      if (outputDir) {
        if (outputType == 'm')