2004-03-29 03:37:46 +00:00
|
|
|
/** This tool checks that a file is a valid strings-file
|
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"
|
1999-02-04 13:49:27 +00:00
|
|
|
#include <Foundation/NSArray.h>
|
2001-08-30 21:13:59 +00:00
|
|
|
#include <Foundation/NSData.h>
|
1999-02-04 13:49:27 +00:00
|
|
|
#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-01-15 04:07:08 +00:00
|
|
|
#ifdef NeXT_Foundation_LIBRARY
|
|
|
|
#include "GNUstepBase/GSCategories.h"
|
|
|
|
#endif
|
1999-02-04 13:49:27 +00:00
|
|
|
|
2001-08-30 21:13:59 +00:00
|
|
|
int
|
|
|
|
convert_unicode(NSArray *args)
|
|
|
|
{
|
2003-01-03 20:14:47 +00:00
|
|
|
unsigned int i;
|
2001-08-30 21:13:59 +00:00
|
|
|
|
|
|
|
for (i = 2; i < [args count]; i++)
|
|
|
|
{
|
|
|
|
NSString *file = [args objectAtIndex: i];
|
2005-02-22 11:22:44 +00:00
|
|
|
|
2001-08-30 21:13:59 +00:00
|
|
|
NS_DURING
|
|
|
|
{
|
|
|
|
NSData *data;
|
|
|
|
NSString *myString;
|
|
|
|
NSString *output;
|
|
|
|
|
|
|
|
data = [NSData dataWithContentsOfFile: file];
|
|
|
|
myString = [[NSString alloc] initWithData: data
|
2002-10-11 09:14:14 +00:00
|
|
|
encoding: NSUTF8StringEncoding];
|
2001-08-30 21:13:59 +00:00
|
|
|
AUTORELEASE(myString);
|
|
|
|
if ([myString length] == 0)
|
2002-10-11 09:14:14 +00:00
|
|
|
{
|
|
|
|
myString = [[NSString alloc] initWithData: data
|
|
|
|
encoding: [NSString defaultCStringEncoding]];
|
|
|
|
}
|
2001-08-30 21:13:59 +00:00
|
|
|
output = [[file lastPathComponent]
|
2002-10-11 09:14:14 +00:00
|
|
|
stringByAppendingPathExtension: @"unicode"];
|
2001-08-30 21:13:59 +00:00
|
|
|
data = [myString dataUsingEncoding: NSUnicodeStringEncoding];
|
|
|
|
[data writeToFile: output atomically: YES];
|
|
|
|
}
|
|
|
|
NS_HANDLER
|
|
|
|
{
|
2002-10-11 09:14:14 +00:00
|
|
|
GSPrintf(stderr, @"Converting '%@' - %@\n", file,
|
|
|
|
[localException reason]);
|
2002-11-29 12:46:36 +00:00
|
|
|
return 1;
|
2001-08-30 21:13:59 +00:00
|
|
|
}
|
|
|
|
NS_ENDHANDLER
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
convert_utf8(NSArray *args)
|
|
|
|
{
|
2003-01-03 20:14:47 +00:00
|
|
|
unsigned int i;
|
2001-08-30 21:13:59 +00:00
|
|
|
|
|
|
|
for (i = 2; i < [args count]; i++)
|
|
|
|
{
|
|
|
|
NSString *file = [args objectAtIndex: i];
|
2005-02-22 11:22:44 +00:00
|
|
|
|
2001-08-30 21:13:59 +00:00
|
|
|
NS_DURING
|
|
|
|
{
|
|
|
|
NSData *data;
|
|
|
|
NSString *myString;
|
|
|
|
NSString *output;
|
|
|
|
|
|
|
|
myString = [NSString stringWithContentsOfFile: file];
|
|
|
|
output = [[file lastPathComponent]
|
2002-10-11 09:14:14 +00:00
|
|
|
stringByAppendingPathExtension: @"utf8"];
|
2001-08-30 21:13:59 +00:00
|
|
|
data = [myString dataUsingEncoding: NSUTF8StringEncoding];
|
|
|
|
[data writeToFile: output atomically: YES];
|
|
|
|
}
|
|
|
|
NS_HANDLER
|
|
|
|
{
|
2002-10-11 09:14:14 +00:00
|
|
|
GSPrintf(stderr, @"Converting '%@' - %@\n", file,
|
|
|
|
[localException reason]);
|
2002-11-29 12:46:36 +00:00
|
|
|
return 1;
|
2001-08-30 21:13:59 +00:00
|
|
|
}
|
|
|
|
NS_ENDHANDLER
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
1999-02-04 13:49:27 +00:00
|
|
|
|
2004-03-29 03:37:46 +00:00
|
|
|
|
|
|
|
/** <p>
|
|
|
|
This tool checks that a file is a valid strings-file, and can also convert
|
|
|
|
files to Unicode or UTF-8. If given the '<code>--unicode</code>' option
|
|
|
|
it converts an ASCII or UTF-8 file to unicode. If given the
|
|
|
|
'<code>--utf8</code>' option is converts an ASCII or unicode file to UTF-8.
|
|
|
|
</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-10-11 09:14:14 +00:00
|
|
|
GSPrintf(stderr, @"defaults: 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];
|
|
|
|
|
2001-08-30 21:13:59 +00:00
|
|
|
if ([args count] <= 1 || [[args objectAtIndex: 1] isEqual: @"--help"]
|
|
|
|
|| [[args objectAtIndex: 1] isEqual: @"-h"])
|
|
|
|
{
|
|
|
|
printf("Usage: sfparse [--utf8] filename.\n");
|
|
|
|
printf("--unicode - convert an ASCII or UTF8 file to Unicode\n");
|
|
|
|
printf("--utf8 - convert an ASCII or Unicode to UTF8\n");
|
|
|
|
}
|
|
|
|
else if ([[args objectAtIndex: 1] isEqual: @"--unicode"])
|
|
|
|
{
|
2002-11-29 12:46:36 +00:00
|
|
|
retval = convert_unicode(args);
|
2001-08-30 21:13:59 +00:00
|
|
|
}
|
|
|
|
else if ([[args objectAtIndex: 1] isEqual: @"--utf8"])
|
1999-02-04 13:49:27 +00:00
|
|
|
{
|
2002-11-29 12:46:36 +00:00
|
|
|
retval = convert_utf8(args);
|
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;
|
|
|
|
id result;
|
|
|
|
|
|
|
|
myString = [NSString stringWithContentsOfFile: file];
|
|
|
|
result = [myString propertyListFromStringsFileFormat];
|
|
|
|
if (result == 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 '%@' - seems ok\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
|
|
|
}
|