2004-03-29 03:37:46 +00:00
|
|
|
/** This tool checks that a file contains a valid text property-list.
|
1999-02-04 13:49:27 +00:00
|
|
|
Copyright (C) 1999 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
Written by: Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
|
|
|
Created: February 1999
|
|
|
|
|
|
|
|
This file is part of the GNUstep Project
|
|
|
|
|
|
|
|
This library 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.
|
2005-02-22 11:22:44 +00:00
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public
|
1999-02-04 13:49:27 +00:00
|
|
|
License along with this library; see the file COPYING.LIB.
|
|
|
|
If not, write to the Free Software Foundation,
|
2005-05-22 03:32:16 +00:00
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
1999-02-04 13:49:27 +00:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
2000-03-24 05:40:19 +00:00
|
|
|
#include "config.h"
|
2001-03-16 16:56:32 +00:00
|
|
|
#include <Foundation/Foundation.h>
|
1999-02-04 13:49:27 +00:00
|
|
|
#include <Foundation/NSArray.h>
|
|
|
|
#include <Foundation/NSException.h>
|
|
|
|
#include <Foundation/NSString.h>
|
|
|
|
#include <Foundation/NSProcessInfo.h>
|
|
|
|
#include <Foundation/NSUserDefaults.h>
|
|
|
|
#include <Foundation/NSDebug.h>
|
|
|
|
#include <Foundation/NSAutoreleasePool.h>
|
|
|
|
|
2004-06-27 09:54:41 +00:00
|
|
|
/*
|
|
|
|
* If there is any non-ascii characrer in the string,
|
|
|
|
* and the file data did not begin with a unicode BOM to identify
|
|
|
|
* it as unicode data, we return the location of the first
|
|
|
|
* bad character, otherwise return -1;
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
firstBadCharacter(NSString *file, NSString *content)
|
|
|
|
{
|
|
|
|
static NSCharacterSet *cs = nil;
|
|
|
|
NSData *d;
|
|
|
|
NSRange r;
|
|
|
|
|
|
|
|
if (cs == nil)
|
|
|
|
{
|
|
|
|
cs = [NSCharacterSet characterSetWithRange: NSMakeRange(1, 127)];
|
|
|
|
cs = RETAIN([cs invertedSet]);
|
|
|
|
}
|
|
|
|
|
|
|
|
r = [content rangeOfCharacterFromSet: cs];
|
|
|
|
if (r.length == 0)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
d = [NSData dataWithContentsOfFile: file];
|
|
|
|
if ([d length] > 2)
|
|
|
|
{
|
|
|
|
const unsigned char *ptr = (const unsigned char*)[d bytes];
|
|
|
|
|
|
|
|
if ((ptr[0] == 0xff && ptr[1] == 0xfe) // UCS2
|
|
|
|
|| (ptr[0] == 0xfe && ptr[1] == 0xff) // UCS2
|
|
|
|
|| (ptr[0] == 0xef && ptr[1] == 0xbb && ptr[2] == 0xbf)) // UTF8
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return r.location;
|
|
|
|
}
|
1999-02-04 13:49:27 +00:00
|
|
|
|
2004-03-29 03:37:46 +00:00
|
|
|
/** <p>
|
|
|
|
This tool checks that a file contains a valid text property-list.
|
|
|
|
</p> */
|
1999-02-04 13:49:27 +00:00
|
|
|
int
|
2000-06-29 03:51:06 +00:00
|
|
|
main(int argc, char** argv, char **env)
|
1999-02-04 13:49:27 +00:00
|
|
|
{
|
2000-06-29 03:51:06 +00:00
|
|
|
NSAutoreleasePool *pool;
|
1999-02-04 13:49:27 +00:00
|
|
|
NSProcessInfo *proc;
|
|
|
|
NSArray *args;
|
|
|
|
unsigned i;
|
2002-11-29 12:46:36 +00:00
|
|
|
int retval = 0;
|
1999-02-04 13:49:27 +00:00
|
|
|
|
2000-06-29 03:51:06 +00:00
|
|
|
#ifdef GS_PASS_ARGUMENTS
|
|
|
|
[NSProcessInfo initializeWithArguments:argv count:argc environment:env];
|
|
|
|
#endif
|
|
|
|
pool = [NSAutoreleasePool new];
|
1999-02-04 13:49:27 +00:00
|
|
|
proc = [NSProcessInfo processInfo];
|
|
|
|
if (proc == nil)
|
|
|
|
{
|
2002-04-05 16:26:47 +00:00
|
|
|
NSLog(@"plparse: unable to get process information!\n");
|
1999-02-04 13:49:27 +00:00
|
|
|
[pool release];
|
2003-05-12 20:42:47 +00:00
|
|
|
exit(EXIT_FAILURE);
|
1999-02-04 13:49:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
args = [proc arguments];
|
|
|
|
|
1999-02-17 09:26:56 +00:00
|
|
|
if ([args count] <= 1)
|
1999-02-04 13:49:27 +00:00
|
|
|
{
|
2002-10-11 09:14:14 +00:00
|
|
|
GSPrintf(stderr, @"No file names given to parse.\n");
|
1999-02-04 13:49:27 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1999-02-17 09:26:56 +00:00
|
|
|
for (i = 1; i < [args count]; i++)
|
1999-02-04 13:49:27 +00:00
|
|
|
{
|
|
|
|
NSString *file = [args objectAtIndex: i];
|
|
|
|
|
|
|
|
NS_DURING
|
|
|
|
{
|
|
|
|
NSString *myString;
|
2004-06-27 09:07:36 +00:00
|
|
|
id result;
|
2004-06-27 09:54:41 +00:00
|
|
|
int bad;
|
1999-02-04 13:49:27 +00:00
|
|
|
|
|
|
|
myString = [NSString stringWithContentsOfFile: file];
|
2004-06-27 09:07:36 +00:00
|
|
|
if (myString == nil)
|
|
|
|
GSPrintf(stderr, @"Parsing '%@' - not valid string\n", file);
|
2004-06-27 09:54:41 +00:00
|
|
|
else if ((bad = firstBadCharacter(file, myString)) >= 0)
|
2004-06-27 09:07:36 +00:00
|
|
|
GSPrintf(stderr, @"Parsing '%@' - bad char '\\U%04x' at %d\n",
|
2004-06-27 09:54:41 +00:00
|
|
|
file, [myString characterAtIndex: bad], bad);
|
2004-06-27 09:07:36 +00:00
|
|
|
else if ((result = [myString propertyList]) == nil)
|
2002-10-11 09:14:14 +00:00
|
|
|
GSPrintf(stderr, @"Parsing '%@' - nil property list\n", file);
|
1999-02-04 13:49:27 +00:00
|
|
|
else if ([result isKindOfClass: [NSDictionary class]] == YES)
|
2002-10-11 09:14:14 +00:00
|
|
|
GSPrintf(stderr, @"Parsing '%@' - a dictionary\n", file);
|
1999-02-04 13:49:27 +00:00
|
|
|
else if ([result isKindOfClass: [NSArray class]] == YES)
|
2002-10-11 09:14:14 +00:00
|
|
|
GSPrintf(stderr, @"Parsing '%@' - an array\n", file);
|
1999-02-04 13:49:27 +00:00
|
|
|
else if ([result isKindOfClass: [NSData class]] == YES)
|
2002-10-11 09:14:14 +00:00
|
|
|
GSPrintf(stderr, @"Parsing '%@' - a data object\n", file);
|
1999-02-04 13:49:27 +00:00
|
|
|
else if ([result isKindOfClass: [NSString class]] == YES)
|
2002-10-11 09:14:14 +00:00
|
|
|
GSPrintf(stderr, @"Parsing '%@' - a string\n", file);
|
1999-02-04 13:49:27 +00:00
|
|
|
else
|
2002-10-11 09:14:14 +00:00
|
|
|
GSPrintf(stderr, @"Parsing '%@' - unexpected class - %@\n",
|
|
|
|
file, [[result class] description]);
|
1999-02-04 13:49:27 +00:00
|
|
|
}
|
|
|
|
NS_HANDLER
|
|
|
|
{
|
2002-10-11 09:14:14 +00:00
|
|
|
GSPrintf(stderr, @"Parsing '%@' - %@\n", file,
|
|
|
|
[localException reason]);
|
2002-11-29 12:46:36 +00:00
|
|
|
retval = 1;
|
1999-02-04 13:49:27 +00:00
|
|
|
}
|
|
|
|
NS_ENDHANDLER
|
|
|
|
}
|
|
|
|
}
|
|
|
|
[pool release];
|
2002-11-29 12:46:36 +00:00
|
|
|
return retval;
|
1999-02-04 13:49:27 +00:00
|
|
|
}
|