mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 08:21:25 +00:00
New property-list stuff, bugfixes and 64-bit clean version with many
improvements. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@3651 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
362e54106f
commit
d9692822a9
5 changed files with 768 additions and 95 deletions
|
@ -149,7 +149,7 @@
|
|||
|
||||
other_bytes = [[otherSet bitmapRepresentation] bytes];
|
||||
for (i = 0; i < BITMAP_SIZE; i++)
|
||||
data[i] = (data[i] || other_bytes[i]);
|
||||
data[i] = (data[i] | other_bytes[i]);
|
||||
}
|
||||
|
||||
- (void) formIntersectionWithCharacterSet: (NSCharacterSet *)otherSet
|
||||
|
@ -159,7 +159,7 @@
|
|||
|
||||
other_bytes = [[otherSet bitmapRepresentation] bytes];
|
||||
for (i = 0; i < BITMAP_SIZE; i++)
|
||||
data[i] = (data[i] && other_bytes[i]);
|
||||
data[i] = (data[i] & other_bytes[i]);
|
||||
}
|
||||
|
||||
- (void)removeCharactersInRange:(NSRange)aRange
|
||||
|
|
|
@ -101,6 +101,59 @@
|
|||
|
||||
static Class NSString_class; /* For speed */
|
||||
|
||||
/*
|
||||
* Cache some commonly used character sets along with methods to
|
||||
* check membership.
|
||||
*/
|
||||
|
||||
static SEL cMemberSel = @selector(characterIsMember:);
|
||||
|
||||
static NSCharacterSet *hexdigits = nil;
|
||||
static BOOL (*hexdigitsImp)(id, SEL, unichar) = 0;
|
||||
static void setupHexdigits()
|
||||
{
|
||||
if (hexdigits == nil)
|
||||
{
|
||||
hexdigits = [NSCharacterSet characterSetWithCharactersInString:
|
||||
@"0123456789abcdef"];
|
||||
[hexdigits retain];
|
||||
hexdigitsImp =
|
||||
(BOOL(*)(id,SEL,unichar)) [hexdigits methodForSelector: cMemberSel];
|
||||
}
|
||||
}
|
||||
|
||||
static NSCharacterSet *quotables = nil;
|
||||
static BOOL (*quotablesImp)(id, SEL, unichar) = 0;
|
||||
static void setupQuotables()
|
||||
{
|
||||
if (quotables == nil)
|
||||
{
|
||||
NSMutableCharacterSet *s;
|
||||
|
||||
s = (NSMutableCharacterSet*)[NSMutableCharacterSet
|
||||
characterSetWithCharactersInString:
|
||||
@"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz$./_"];
|
||||
[s invert];
|
||||
quotables = [s copy];
|
||||
quotablesImp =
|
||||
(BOOL(*)(id,SEL,unichar)) [quotables methodForSelector: cMemberSel];
|
||||
}
|
||||
}
|
||||
|
||||
static NSCharacterSet *whitespce = nil;
|
||||
static BOOL (*whitespceImp)(id, SEL, unichar) = 0;
|
||||
static void setupWhitespce()
|
||||
{
|
||||
if (whitespce == nil)
|
||||
{
|
||||
whitespce = [NSCharacterSet whitespaceAndNewlineCharacterSet];
|
||||
[whitespce retain];
|
||||
whitespceImp =
|
||||
(BOOL(*)(id,SEL,unichar)) [whitespce methodForSelector: cMemberSel];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static unichar pathSepChar = (unichar)'/';
|
||||
static NSString *pathSepString = @"/";
|
||||
|
||||
|
@ -768,6 +821,8 @@ handle_printf_atsign (FILE *stream,
|
|||
{
|
||||
int i, start, stop, step;
|
||||
NSRange range;
|
||||
unichar (*cImp)(id, SEL, unsigned);
|
||||
BOOL (*mImp)(id, SEL, unichar);
|
||||
|
||||
i = [self length];
|
||||
if (aRange.location > i)
|
||||
|
@ -785,10 +840,16 @@ handle_printf_atsign (FILE *stream,
|
|||
}
|
||||
range.location = 0;
|
||||
range.length = 0;
|
||||
|
||||
cImp = (unichar(*)(id,SEL,unsigned))
|
||||
[self methodForSelector: @selector(characterAtIndex:)];
|
||||
mImp = (BOOL(*)(id,SEL,unichar))
|
||||
[aSet methodForSelector: cMemberSel];
|
||||
|
||||
for (i = start; i != stop; i += step)
|
||||
{
|
||||
unichar letter = [self characterAtIndex:i];
|
||||
if ([aSet characterIsMember:letter])
|
||||
unichar letter = (unichar)(*cImp)(self, @selector(characterAtIndex:), i);
|
||||
if ((*mImp)(aSet, cMemberSel, letter))
|
||||
{
|
||||
range = NSMakeRange(i, 1);
|
||||
break;
|
||||
|
@ -1312,6 +1373,7 @@ handle_printf_atsign (FILE *stream,
|
|||
|
||||
// Converting String Contents into a Property List
|
||||
|
||||
#if 0
|
||||
// xxx C strings only ???
|
||||
- (id)propertyList
|
||||
{
|
||||
|
@ -1335,6 +1397,7 @@ handle_printf_atsign (FILE *stream,
|
|||
sf_delete_buffer(bufstate);
|
||||
return dict;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Identifying and Comparing Strings
|
||||
|
||||
|
@ -1893,18 +1956,20 @@ else
|
|||
int count=0;
|
||||
BOOL found=YES;
|
||||
int len=[self length];
|
||||
id white = [NSCharacterSet whitespaceAndNewlineCharacterSet];
|
||||
|
||||
if (whitespce == nil)
|
||||
setupWhitespce();
|
||||
|
||||
s = NSZoneMalloc(z, sizeof(unichar)*(len+1));
|
||||
[self getCharacters:s];
|
||||
s[len] = (unichar)0;
|
||||
while (count<len)
|
||||
{
|
||||
if([white characterIsMember:s[count]])
|
||||
if ((*whitespceImp)(whitespce, cMemberSel, s[count]))
|
||||
{
|
||||
count++;
|
||||
found=YES;
|
||||
while([white characterIsMember:s[count]]&(count<len))
|
||||
while ((*whitespceImp)(whitespce, cMemberSel, s[count]) && (count < len))
|
||||
count++;
|
||||
};
|
||||
if (found)
|
||||
|
@ -1914,7 +1979,7 @@ else
|
|||
}
|
||||
else
|
||||
{
|
||||
while(![white characterIsMember:s[count]]&(count<len))
|
||||
while (!(*whitespceImp)(whitespce, cMemberSel, s[count]) && (count < len))
|
||||
{
|
||||
s[count]=uni_tolower(s[count]);
|
||||
count++;
|
||||
|
@ -2687,8 +2752,6 @@ else
|
|||
|
||||
- (void) descriptionTo: (id<GNUDescriptionDestination>)output
|
||||
{
|
||||
static NSCharacterSet *quotables = nil;
|
||||
|
||||
if ([self length] == 0)
|
||||
{
|
||||
[output appendString: @"\"\""];
|
||||
|
@ -2696,10 +2759,7 @@ else
|
|||
}
|
||||
|
||||
if (quotables == nil)
|
||||
{
|
||||
quotables = [[NSCharacterSet alphanumericCharacterSet] invertedSet];
|
||||
[quotables retain];
|
||||
}
|
||||
setupQuotables();
|
||||
|
||||
if ([self rangeOfCharacterFromSet: quotables].length > 0)
|
||||
{
|
||||
|
@ -2835,6 +2895,445 @@ else
|
|||
return [super replacementObjectForPortCoder: aCoder];
|
||||
}
|
||||
|
||||
|
||||
#define inrange(ch,min,max) ((ch)>=(min) && (ch)<=(max))
|
||||
#define char2num(ch) \
|
||||
inrange(ch,'0','9') \
|
||||
? ((ch)-0x30) \
|
||||
: (inrange(ch,'a','f') \
|
||||
? ((ch)-0x57) : ((ch)-0x37))
|
||||
|
||||
typedef struct {
|
||||
const unichar *ptr;
|
||||
unsigned end;
|
||||
unsigned pos;
|
||||
unsigned lin;
|
||||
NSString *err;
|
||||
} pldata;
|
||||
|
||||
/*
|
||||
* Property list parsing - skip whitespace keeping count of lines and
|
||||
* regarding objective-c style comments as whitespace.
|
||||
* Returns YES if there is any non-whitespace text remaining.
|
||||
*/
|
||||
static BOOL skipSpace(pldata *pld)
|
||||
{
|
||||
unichar c;
|
||||
|
||||
while (pld->pos < pld->end)
|
||||
{
|
||||
c = pld->ptr[pld->pos];
|
||||
|
||||
if ((*whitespceImp)(whitespce, cMemberSel, c) == NO)
|
||||
{
|
||||
if (c == '/' && pld->pos < pld->end - 1)
|
||||
{
|
||||
/*
|
||||
* Check for comments beginning '//' or '/*'
|
||||
*/
|
||||
if (pld->ptr[pld->pos + 1] == '/')
|
||||
{
|
||||
pld->pos += 2;
|
||||
while (pld->pos < pld->end)
|
||||
{
|
||||
c = pld->ptr[pld->pos];
|
||||
if (c == '\n')
|
||||
break;
|
||||
pld->pos++;
|
||||
}
|
||||
if (pld->pos >= pld->end)
|
||||
{
|
||||
pld->err = @"reached end of string in comment";
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
else if (pld->ptr[pld->pos + 1] == '*')
|
||||
{
|
||||
pld->pos += 2;
|
||||
while (pld->pos < pld->end)
|
||||
{
|
||||
c = pld->ptr[pld->pos];
|
||||
if (c == '\n')
|
||||
pld->lin++;
|
||||
else if (c == '*' && pld->pos < pld->end - 1
|
||||
&& pld->ptr[pld->pos+1] == '/')
|
||||
{
|
||||
pld->pos++; /* Skip past '*' */
|
||||
break;
|
||||
}
|
||||
pld->pos++;
|
||||
}
|
||||
if (pld->pos >= pld->end)
|
||||
{
|
||||
pld->err = @"reached end of string in comment";
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
else
|
||||
return YES;
|
||||
}
|
||||
else
|
||||
return YES;
|
||||
}
|
||||
if (c == '\n')
|
||||
pld->lin++;
|
||||
pld->pos++;
|
||||
}
|
||||
pld->err = @"reached end of string";
|
||||
return NO;
|
||||
}
|
||||
|
||||
static inline id parseQuotedString(pldata* pld)
|
||||
{
|
||||
unsigned start = ++pld->pos;
|
||||
BOOL escaped = NO;
|
||||
unsigned shrink = 0;
|
||||
NSString *obj;
|
||||
|
||||
while (pld->pos < pld->end)
|
||||
{
|
||||
unichar c = pld->ptr[pld->pos];
|
||||
|
||||
if (escaped)
|
||||
{
|
||||
escaped = NO;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (c == '\\')
|
||||
{
|
||||
escaped = YES;
|
||||
shrink++;
|
||||
}
|
||||
else if (c == '"')
|
||||
break;
|
||||
}
|
||||
pld->pos++;
|
||||
}
|
||||
if (pld->pos >= pld->end)
|
||||
{
|
||||
pld->err = @"reached end of string while parsing quoted string";
|
||||
return nil;
|
||||
}
|
||||
if (pld->pos - start - shrink == 0)
|
||||
{
|
||||
obj = @"";
|
||||
}
|
||||
else
|
||||
{
|
||||
unichar chars[pld->pos - start - shrink];
|
||||
unsigned j;
|
||||
unsigned k;
|
||||
|
||||
for (j = start, k = 0; j < pld->pos; j++)
|
||||
{
|
||||
chars[k] = pld->ptr[j];
|
||||
if (escaped)
|
||||
{
|
||||
escaped = NO;
|
||||
switch (chars[k])
|
||||
{
|
||||
case 'a' : chars[k] = '\a'; break;
|
||||
case 'b' : chars[k] = '\b'; break;
|
||||
case 't' : chars[k] = '\t'; break;
|
||||
case 'r' : chars[k] = '\r'; break;
|
||||
case 'n' : chars[k] = '\n'; break;
|
||||
case 'v' : chars[k] = '\v'; break;
|
||||
case 'f' : chars[k] = '\f'; break;
|
||||
default: break;
|
||||
}
|
||||
k++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (chars[k] == '\\')
|
||||
escaped = YES;
|
||||
else
|
||||
k++;
|
||||
}
|
||||
}
|
||||
obj = [NSString stringWithCharacters: chars
|
||||
length: pld->pos - start - shrink];
|
||||
}
|
||||
pld->pos++;
|
||||
return obj;
|
||||
}
|
||||
|
||||
static inline id parseUnquotedString(pldata *pld)
|
||||
{
|
||||
unsigned start = pld->pos;
|
||||
|
||||
while (pld->pos < pld->end)
|
||||
{
|
||||
if ((*quotablesImp)(quotables, cMemberSel, pld->ptr[pld->pos]) == YES)
|
||||
break;
|
||||
pld->pos++;
|
||||
}
|
||||
return [NSString stringWithCharacters: &pld->ptr[start]
|
||||
length: pld->pos-start];
|
||||
}
|
||||
|
||||
static id parsePlItem(pldata* pld)
|
||||
{
|
||||
if (skipSpace(pld) == NO)
|
||||
return nil;
|
||||
|
||||
switch (pld->ptr[pld->pos])
|
||||
{
|
||||
case '{':
|
||||
{
|
||||
NSMutableDictionary *dict;
|
||||
|
||||
dict = [NSMutableDictionary dictionaryWithCapacity: 0];
|
||||
pld->pos++;
|
||||
while (skipSpace(pld) == YES && pld->ptr[pld->pos] != '}')
|
||||
{
|
||||
id key;
|
||||
id val;
|
||||
|
||||
key = parsePlItem(pld);
|
||||
if (key == nil)
|
||||
return nil;
|
||||
if (skipSpace(pld) == NO)
|
||||
return nil;
|
||||
if (pld->ptr[pld->pos] != '=')
|
||||
{
|
||||
pld->err = @"unexpected character (wanted '=')";
|
||||
return nil;
|
||||
}
|
||||
pld->pos++;
|
||||
val = parsePlItem(pld);
|
||||
if (val == nil)
|
||||
return nil;
|
||||
if (skipSpace(pld) == NO)
|
||||
return nil;
|
||||
if (pld->ptr[pld->pos] == ';')
|
||||
pld->pos++;
|
||||
else if (pld->ptr[pld->pos] != '}')
|
||||
{
|
||||
pld->err = @"unexpected character (wanted ';' or '}')";
|
||||
return nil;
|
||||
}
|
||||
[dict setObject: val forKey: key];
|
||||
}
|
||||
if (pld->pos >= pld->end)
|
||||
{
|
||||
pld->err = @"unexpected end of string when parsing dictionary";
|
||||
return nil;
|
||||
}
|
||||
pld->pos++;
|
||||
return dict;
|
||||
}
|
||||
|
||||
case '(':
|
||||
{
|
||||
NSMutableArray *array;
|
||||
|
||||
array = [NSMutableArray arrayWithCapacity: 0];
|
||||
pld->pos++;
|
||||
while (skipSpace(pld) == YES && pld->ptr[pld->pos] != ')')
|
||||
{
|
||||
id val;
|
||||
|
||||
val = parsePlItem(pld);
|
||||
if (val == nil)
|
||||
return nil;
|
||||
if (skipSpace(pld) == NO)
|
||||
return nil;
|
||||
if (pld->ptr[pld->pos] == ',')
|
||||
pld->pos++;
|
||||
else if (pld->ptr[pld->pos] != ')')
|
||||
{
|
||||
pld->err = @"unexpected character (wanted ',' or ')')";
|
||||
return nil;
|
||||
}
|
||||
[array addObject: val];
|
||||
}
|
||||
if (pld->pos >= pld->end)
|
||||
{
|
||||
pld->err = @"unexpected end of string when parsing array";
|
||||
return nil;
|
||||
}
|
||||
pld->pos++;
|
||||
return array;
|
||||
}
|
||||
|
||||
case '<':
|
||||
{
|
||||
NSMutableData *data;
|
||||
unsigned max = pld->end - 1;
|
||||
unsigned char buf[BUFSIZ];
|
||||
unsigned len = 0;
|
||||
|
||||
data = [NSMutableData dataWithCapacity: 0];
|
||||
pld->pos++;
|
||||
while (skipSpace(pld) == YES && pld->ptr[pld->pos] != '>')
|
||||
{
|
||||
while (pld->pos < max
|
||||
&& (*hexdigitsImp)(hexdigits, cMemberSel, pld->ptr[pld->pos])
|
||||
&& (*hexdigitsImp)(hexdigits, cMemberSel, pld->ptr[pld->pos+1]))
|
||||
{
|
||||
unsigned char byte;
|
||||
|
||||
byte = (char2num(pld->ptr[pld->pos])) << 4;
|
||||
pld->pos++;
|
||||
byte |= char2num(pld->ptr[pld->pos]);
|
||||
pld->pos++;
|
||||
buf[len++] = byte;
|
||||
if (len > sizeof(buf))
|
||||
{
|
||||
[data appendBytes: buf length: len];
|
||||
len = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (pld->pos >= pld->end)
|
||||
{
|
||||
pld->err = @"unexpected end of string when parsing data";
|
||||
return nil;
|
||||
}
|
||||
if (pld->ptr[pld->pos] != '>')
|
||||
{
|
||||
pld->err = @"unexpected character in string";
|
||||
return nil;
|
||||
}
|
||||
if (len > 0)
|
||||
{
|
||||
[data appendBytes: buf length: len];
|
||||
}
|
||||
pld->pos++;
|
||||
return data;
|
||||
}
|
||||
|
||||
case '"':
|
||||
return parseQuotedString(pld);
|
||||
|
||||
default:
|
||||
return parseUnquotedString(pld);
|
||||
}
|
||||
}
|
||||
|
||||
static id parseSfItem(pldata* pld)
|
||||
{
|
||||
NSMutableDictionary *dict;
|
||||
|
||||
dict = [NSMutableDictionary dictionaryWithCapacity: 0];
|
||||
while (skipSpace(pld) == YES)
|
||||
{
|
||||
id key;
|
||||
id val;
|
||||
|
||||
if (pld->ptr[pld->pos] == '"')
|
||||
key = parseQuotedString(pld);
|
||||
else
|
||||
key = parseUnquotedString(pld);
|
||||
if (key == nil)
|
||||
return nil;
|
||||
if (skipSpace(pld) == NO)
|
||||
{
|
||||
pld->err = @"incomplete final entry (no semicolon?)";
|
||||
return nil;
|
||||
}
|
||||
if (pld->ptr[pld->pos] == ';')
|
||||
{
|
||||
pld->pos++;
|
||||
[dict setObject: @"" forKey: key];
|
||||
}
|
||||
else if (pld->ptr[pld->pos] == '=')
|
||||
{
|
||||
pld->pos++;
|
||||
if (skipSpace(pld) == NO)
|
||||
return nil;
|
||||
if (pld->ptr[pld->pos] == '"')
|
||||
val = parseQuotedString(pld);
|
||||
else
|
||||
val = parseUnquotedString(pld);
|
||||
if (val == nil)
|
||||
return nil;
|
||||
if (skipSpace(pld) == NO)
|
||||
{
|
||||
pld->err = @"missing final semicolon";
|
||||
return nil;
|
||||
}
|
||||
[dict setObject: val forKey: key];
|
||||
if (pld->ptr[pld->pos] == ';')
|
||||
pld->pos++;
|
||||
else
|
||||
{
|
||||
pld->err = @"unexpected character (wanted ';')";
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pld->err = @"unexpected character (wanted '=' or ';')";
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
return dict;
|
||||
}
|
||||
|
||||
- (id) propertyList
|
||||
{
|
||||
unsigned len = [self length];
|
||||
unichar chars[len];
|
||||
id result;
|
||||
pldata data;
|
||||
|
||||
data.ptr = chars;
|
||||
data.pos = 0;
|
||||
data.end = len;
|
||||
data.lin = 1;
|
||||
data.err = nil;
|
||||
|
||||
[self getCharacters: chars];
|
||||
if (hexdigits == nil)
|
||||
setupHexdigits();
|
||||
if (quotables == nil)
|
||||
setupQuotables();
|
||||
if (whitespce == nil)
|
||||
setupWhitespce();
|
||||
|
||||
result = parsePlItem(&data);
|
||||
|
||||
if (result == nil && data.err != nil)
|
||||
{
|
||||
[NSException raise: NSGenericException
|
||||
format: @"%@ at line %u", data.err, data.lin];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
- (NSDictionary*) propertyListFromStringsFileFormat
|
||||
{
|
||||
unsigned len = [self length];
|
||||
unichar chars[len];
|
||||
id result;
|
||||
pldata data;
|
||||
|
||||
data.ptr = chars;
|
||||
data.pos = 0;
|
||||
data.end = len;
|
||||
data.lin = 1;
|
||||
data.err = nil;
|
||||
|
||||
[self getCharacters: chars];
|
||||
if (hexdigits == nil)
|
||||
setupHexdigits();
|
||||
if (quotables == nil)
|
||||
setupQuotables();
|
||||
if (whitespce == nil)
|
||||
setupWhitespce();
|
||||
|
||||
result = parseSfItem(&data);
|
||||
if (result == nil && data.err != nil)
|
||||
{
|
||||
[NSException raise: NSGenericException
|
||||
format: @"%@ at line %u", data.err, data.lin];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ include ../Version
|
|||
include ../config.mak
|
||||
|
||||
# The application to be compiled
|
||||
TOOL_NAME = gdnc defaults dread dwrite dremove
|
||||
TOOL_NAME = gdnc defaults dread dwrite dremove plparse sfparse
|
||||
OBJC_PROGRAM_NAME = gdomap
|
||||
|
||||
# The source files to be compiled
|
||||
|
@ -41,6 +41,8 @@ defaults_OBJC_FILES = defaults.m
|
|||
dread_OBJC_FILES = dread.m
|
||||
dremove_OBJC_FILES = dremove.m
|
||||
dwrite_OBJC_FILES = dwrite.m
|
||||
plparse_OBJC_FILES = plparse.m
|
||||
sfparse_OBJC_FILES = sfparse.m
|
||||
|
||||
SOURCES = gdomap.c gdnc.m defaults.m dread.m dremove.m dwrite.m
|
||||
|
||||
|
|
89
Tools/plparse.m
Normal file
89
Tools/plparse.m
Normal file
|
@ -0,0 +1,89 @@
|
|||
/* This tool checks that a file contains a valid text property-list
|
||||
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.
|
||||
|
||||
You should have received a copy of the GNU General Public
|
||||
License along with this library; see the file COPYING.LIB.
|
||||
If not, write to the Free Software Foundation,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
*/
|
||||
|
||||
#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>
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
NSAutoreleasePool *pool = [NSAutoreleasePool new];
|
||||
NSUserDefaults *defs;
|
||||
NSProcessInfo *proc;
|
||||
NSArray *args;
|
||||
unsigned i;
|
||||
|
||||
proc = [NSProcessInfo processInfo];
|
||||
if (proc == nil)
|
||||
{
|
||||
NSLog(@"defaults: unable to get process information!\n");
|
||||
[pool release];
|
||||
exit(0);
|
||||
}
|
||||
|
||||
args = [proc arguments];
|
||||
|
||||
if ([args count] == 0)
|
||||
{
|
||||
NSLog(@"No file names given to parse.");
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < [args count]; i++)
|
||||
{
|
||||
NSString *file = [args objectAtIndex: i];
|
||||
|
||||
NS_DURING
|
||||
{
|
||||
NSString *myString;
|
||||
id result;
|
||||
|
||||
myString = [NSString stringWithContentsOfFile: file];
|
||||
result = [myString propertyList];
|
||||
if (result == nil)
|
||||
NSLog(@"Parsing '%@' - nil property list", file);
|
||||
else if ([result isKindOfClass: [NSDictionary class]] == YES)
|
||||
NSLog(@"Parsing '%@' - a dictionary", file);
|
||||
else if ([result isKindOfClass: [NSArray class]] == YES)
|
||||
NSLog(@"Parsing '%@' - an array", file);
|
||||
else if ([result isKindOfClass: [NSData class]] == YES)
|
||||
NSLog(@"Parsing '%@' - a data object", file);
|
||||
else if ([result isKindOfClass: [NSString class]] == YES)
|
||||
NSLog(@"Parsing '%@' - a string", file);
|
||||
else
|
||||
NSLog(@"Parsing '%@' - unexpected class - %@",
|
||||
file, [[result class] description]);
|
||||
}
|
||||
NS_HANDLER
|
||||
{
|
||||
NSLog(@"Parsing '%@' - %@", file, [localException reason]);
|
||||
}
|
||||
NS_ENDHANDLER
|
||||
}
|
||||
}
|
||||
[pool release];
|
||||
return 0;
|
||||
}
|
83
Tools/sfparse.m
Normal file
83
Tools/sfparse.m
Normal file
|
@ -0,0 +1,83 @@
|
|||
/* This tool checks that a file is a valid strings-file
|
||||
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.
|
||||
|
||||
You should have received a copy of the GNU General Public
|
||||
License along with this library; see the file COPYING.LIB.
|
||||
If not, write to the Free Software Foundation,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
*/
|
||||
|
||||
#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>
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
NSAutoreleasePool *pool = [NSAutoreleasePool new];
|
||||
NSUserDefaults *defs;
|
||||
NSProcessInfo *proc;
|
||||
NSArray *args;
|
||||
unsigned i;
|
||||
|
||||
proc = [NSProcessInfo processInfo];
|
||||
if (proc == nil)
|
||||
{
|
||||
NSLog(@"defaults: unable to get process information!\n");
|
||||
[pool release];
|
||||
exit(0);
|
||||
}
|
||||
|
||||
args = [proc arguments];
|
||||
|
||||
if ([args count] == 0)
|
||||
{
|
||||
NSLog(@"No file names given to parse.");
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < [args count]; i++)
|
||||
{
|
||||
NSString *file = [args objectAtIndex: i];
|
||||
|
||||
NS_DURING
|
||||
{
|
||||
NSString *myString;
|
||||
id result;
|
||||
|
||||
myString = [NSString stringWithContentsOfFile: file];
|
||||
result = [myString propertyListFromStringsFileFormat];
|
||||
if (result == nil)
|
||||
NSLog(@"Parsing '%@' - nil property list", file);
|
||||
else if ([result isKindOfClass: [NSDictionary class]] == YES)
|
||||
NSLog(@"Parsing '%@' - seems ok", file);
|
||||
else
|
||||
NSLog(@"Parsing '%@' - unexpected class - %@",
|
||||
file, [[result class] description]);
|
||||
}
|
||||
NS_HANDLER
|
||||
{
|
||||
NSLog(@"Parsing '%@' - %@", file, [localException reason]);
|
||||
}
|
||||
NS_ENDHANDLER
|
||||
}
|
||||
}
|
||||
[pool release];
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue