From 92eeabaf60f3567ce41436c11a9b143e5b762ef8 Mon Sep 17 00:00:00 2001 From: CaS Date: Thu, 8 May 2003 10:04:02 +0000 Subject: [PATCH] Tiny parser utility git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@16672 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 7 ++- Tools/GNUmakefile | 3 +- Tools/xmlparse.m | 106 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 114 insertions(+), 2 deletions(-) create mode 100644 Tools/xmlparse.m diff --git a/ChangeLog b/ChangeLog index d16bcfc7b..f9fe4b6fc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,9 @@ -2003-05-06 Richard Frith-Macdonald +2003-05-08 Richard Frith-Macdonald + + * Tools/xmlparse.m: new utility to parse/validate xml, for testing + gsdoc and new style property lists etc. + +2003-05-07 Richard Frith-Macdonald * Source/GSString.m: ([-initWithCStringNocopy:length:freeWhenDone:]) check encodings and convert to unicode if necessary. Thanks to diff --git a/Tools/GNUmakefile b/Tools/GNUmakefile index 0b2d19062..ae7564eb0 100644 --- a/Tools/GNUmakefile +++ b/Tools/GNUmakefile @@ -46,7 +46,7 @@ ifeq ($(add),yes) TOOL_NAME = autogsdoc else TOOL_NAME = autogsdoc cvtenc gdnc defaults plmerge \ - plparse sfparse pldes plser pl2link HTMLLinker + plparse sfparse pldes plser pl2link HTMLLinker xmlparse CTOOL_NAME = gdomap SUBPROJECTS = make_strings @@ -72,6 +72,7 @@ sfparse_OBJC_FILES = sfparse.m pl2link_OBJC_FILES = pl2link.m locale_alias_OBJC_FILES = locale_alias.m HTMLLinker_OBJC_FILES = HTMLLinker.m +xmlparse_OBJC_FILES = xmlparse.m DOCUMENT_NAME = autogsdoc HTMLLinkerDoc diff --git a/Tools/xmlparse.m b/Tools/xmlparse.m new file mode 100644 index 000000000..6246f15f4 --- /dev/null +++ b/Tools/xmlparse.m @@ -0,0 +1,106 @@ +/** This tool parses and validates xml documents. + + xmlparse ... a tool to parse xml documents + Copyright (C) 2003 Free Software Foundation, Inc. + + Written by: Richard Frith-Macdonald + Created: May 2003 + + This file is part of the GNUstep Project + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + You should have received a copy of the GNU General Public + License along with this program; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + */ + +#include "config.h" +#include +#include +#include +#include +#include +#include + +@interface GSXMLParser (Loader) ++ (NSString*) loadEntity: (NSString*)publicId + at: (NSString*)location; +@end +@implementation GSXMLParser (Loader) ++ (NSString*) loadEntity: (NSString*)publicId + at: (NSString*)location +{ + char buf[BUFSIZ]; + NSString *str; + int len; + + GSPrintf(stdout, @"Enter filename to load entity '%@' at '%@': ", + publicId, location); + fgets(buf, sizeof(buf)-1, stdin); + buf[sizeof(buf)-1] = '\0'; + len = strlen(buf); + // Strip trailing space + while (len > 0 && buf[len-1] <= ' ') + { + buf[--len] = '\0'; + } + str = [NSString stringWithCString: buf]; + return str; +} +@end + +int +main(int argc, char **argv, char **env) +{ + NSProcessInfo *proc; + NSArray *files; + unsigned int count; + unsigned int i; + CREATE_AUTORELEASE_POOL(pool); + +#ifdef GS_PASS_ARGUMENTS + [NSProcessInfo initializeWithArguments: argv count: argc environment: env]; +#endif + +#ifndef HAVE_LIBXML + NSLog(@"ERROR: The GNUstep Base Library was built\n" +@" without an available libxml library. xmlparse needs the libxml\n" +@" library to function. Aborting"); + exit(1); +#endif + + proc = [NSProcessInfo processInfo]; + if (proc == nil) + { + NSLog(@"unable to get process information!"); + exit(1); + } + + files = [proc arguments]; + count = [files count]; + for (i = 1; i < count; i++) + { + NSString *file = [files objectAtIndex: i]; + GSXMLNode *root; + GSXMLParser *parser; + + parser = [GSXMLParser parserWithContentsOfFile: file]; + [parser substituteEntities: NO]; + [parser doValidityChecking: YES]; + [parser keepBlanks: NO]; + if ([parser parse] == NO) + { + NSLog(@"WARNING %@ is not a valid document", file); + } + root = [[parser document] root]; + NSLog(@"Document is %@", [root name]); + } + RELEASE(pool); + return 0; +}