mirror of
https://github.com/gnustep/libs-base.git
synced 2025-06-01 09:02:01 +00:00
Clean up handling of key matching and ignoring. Add --aggressive-remove option.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@17062 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
dd58f52371
commit
44a0deb661
5 changed files with 88 additions and 28 deletions
|
@ -1,3 +1,10 @@
|
||||||
|
2003-06-28 15:48 Alexander Malmberg <alexander@malmberg.org>
|
||||||
|
|
||||||
|
* Tools/make_strings/StringsFile.h, Tools/make_strings/StringsFile.m,
|
||||||
|
Tools/make_strings/make_strings.h, Tools/make_strings/make_strings.m:
|
||||||
|
Clean up handling of key matching and ignoring. Add
|
||||||
|
--aggressive-remove option.
|
||||||
|
|
||||||
2003-06-28 Richard Frith-Macdonald <rfm@gnu.org>
|
2003-06-28 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
* Source/NSBundle.m: Don't NSLog when we can't find a localizable
|
* Source/NSBundle.m: Don't NSLog when we can't find a localizable
|
||||||
|
|
|
@ -27,8 +27,16 @@
|
||||||
|
|
||||||
@interface StringsFile : NSObject
|
@interface StringsFile : NSObject
|
||||||
{
|
{
|
||||||
|
@public
|
||||||
NSMutableArray *strings;
|
NSMutableArray *strings;
|
||||||
NSString *global_comment;
|
NSString *global_comment;
|
||||||
|
|
||||||
|
@private
|
||||||
|
/** These are used for aggressive matching **/
|
||||||
|
/* Contains all keys for which there is a translation */
|
||||||
|
NSMutableArray *keys_translated;
|
||||||
|
/* Contains all keys that appeared in the source */
|
||||||
|
NSMutableArray *keys_matched;
|
||||||
}
|
}
|
||||||
|
|
||||||
- init;
|
- init;
|
||||||
|
|
|
@ -69,14 +69,39 @@ static NSString *parse_string(NSString **ptr)
|
||||||
|
|
||||||
|
|
||||||
#define DUMMY @"<dummy>"
|
#define DUMMY @"<dummy>"
|
||||||
#define DUMMY2 @"<dummy2>"
|
|
||||||
|
|
||||||
@implementation StringsFile
|
@implementation StringsFile
|
||||||
|
|
||||||
|
-(BOOL) isTranslated: (NSString *)key
|
||||||
|
{
|
||||||
|
return [keys_translated containsObject: key];
|
||||||
|
}
|
||||||
|
|
||||||
|
-(void) addTranslated: (NSString *)key
|
||||||
|
{
|
||||||
|
if (![self isTranslated: key])
|
||||||
|
[keys_translated addObject: key];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
-(BOOL) isMatched: (NSString *)key
|
||||||
|
{
|
||||||
|
return [keys_matched containsObject: key];
|
||||||
|
}
|
||||||
|
|
||||||
|
-(void) addMatched: (NSString *)key
|
||||||
|
{
|
||||||
|
if (![self isMatched: key])
|
||||||
|
[keys_matched addObject: key];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
- init
|
- init
|
||||||
{
|
{
|
||||||
self=[super init];
|
self=[super init];
|
||||||
strings=[[NSMutableArray alloc] init];
|
strings=[[NSMutableArray alloc] init];
|
||||||
|
keys_translated=[[NSMutableArray alloc] init];
|
||||||
|
keys_matched=[[NSMutableArray alloc] init];
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,7 +157,7 @@ static NSString *parse_string(NSString **ptr)
|
||||||
else if ([l hasPrefix: @" File: "])
|
else if ([l hasPrefix: @" File: "])
|
||||||
{
|
{
|
||||||
se=[[StringsEntry alloc] init];
|
se=[[StringsEntry alloc] init];
|
||||||
[se addFlag: FLAG_UNMATCHED];
|
[se addFlag: FLAG_UNMATCHED]; /* TODO: ? */
|
||||||
[update_list addObject: se];
|
[update_list addObject: se];
|
||||||
[se release];
|
[se release];
|
||||||
|
|
||||||
|
@ -212,13 +237,21 @@ static NSString *parse_string(NSString **ptr)
|
||||||
|
|
||||||
[update_list makeObjectsPerformSelector: @selector(setKey:) withObject: key];
|
[update_list makeObjectsPerformSelector: @selector(setKey:) withObject: key];
|
||||||
[update_list makeObjectsPerformSelector: @selector(setTranslated:) withObject: trans];
|
[update_list makeObjectsPerformSelector: @selector(setTranslated:) withObject: trans];
|
||||||
/* {
|
|
||||||
|
{
|
||||||
int i,c=[update_list count];
|
int i,c=[update_list count];
|
||||||
for (i=0;i<c;i++)
|
for (i=0;i<c;i++)
|
||||||
{
|
{
|
||||||
printf("%4i : %@\n",i,[update_list objectAtIndex: i]);
|
// printf("%4i : %@\n",i,[update_list objectAtIndex: i]);
|
||||||
|
se=[update_list objectAtIndex: i];
|
||||||
|
if (!([se flags]&FLAG_UNTRANSLATED))
|
||||||
|
{
|
||||||
|
[self addTranslated: key];
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
[strings addObjectsFromArray: update_list];
|
[strings addObjectsFromArray: update_list];
|
||||||
|
|
||||||
|
@ -307,10 +340,24 @@ static NSString *parse_string(NSString **ptr)
|
||||||
[self _writeTo: str entryKey: cur];
|
[self _writeTo: str entryKey: cur];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-(BOOL) _shouldIgnore: (StringsEntry *)se
|
||||||
|
{
|
||||||
|
if (([se flags]&(FLAG_UNMATCHED|FLAG_UNTRANSLATED))==
|
||||||
|
(FLAG_UNMATCHED|FLAG_UNTRANSLATED))
|
||||||
|
return YES;
|
||||||
|
|
||||||
|
if (aggressive_import && [[se file] isEqual: DUMMY] && [self isMatched: [se key]])
|
||||||
|
return YES;
|
||||||
|
|
||||||
|
if (aggressive_remove && ([se flags]&FLAG_UNMATCHED) && [self isMatched: [se key]])
|
||||||
|
return YES;
|
||||||
|
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
-(BOOL) writeToFile: (NSString *)filename
|
-(BOOL) writeToFile: (NSString *)filename
|
||||||
{
|
{
|
||||||
unsigned i,c;
|
unsigned int i,c;
|
||||||
BOOL result;
|
BOOL result;
|
||||||
NSMutableString *str=[[NSMutableString alloc] initWithCapacity: 32*1024];
|
NSMutableString *str=[[NSMutableString alloc] initWithCapacity: 32*1024];
|
||||||
StringsEntry *se;
|
StringsEntry *se;
|
||||||
|
@ -350,10 +397,8 @@ static NSString *parse_string(NSString **ptr)
|
||||||
while ([strings_left count])
|
while ([strings_left count])
|
||||||
{
|
{
|
||||||
cur=[strings_left objectAtIndex: 0];
|
cur=[strings_left objectAtIndex: 0];
|
||||||
if (([cur flags]&(FLAG_UNMATCHED|FLAG_UNTRANSLATED))==
|
if ([self _shouldIgnore: cur])
|
||||||
(FLAG_UNMATCHED|FLAG_UNTRANSLATED)
|
{
|
||||||
|| (aggressive_import && [[cur file] isEqual: DUMMY2]))
|
|
||||||
{ /* ignore strings that are unmatched _and_ untranslated */
|
|
||||||
[strings_left removeObjectAtIndex: 0];
|
[strings_left removeObjectAtIndex: 0];
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -366,10 +411,8 @@ static NSString *parse_string(NSString **ptr)
|
||||||
{
|
{
|
||||||
c2=[strings_left objectAtIndex: i];
|
c2=[strings_left objectAtIndex: i];
|
||||||
|
|
||||||
if (([c2 flags]&(FLAG_UNMATCHED|FLAG_UNTRANSLATED))==
|
if ([self _shouldIgnore: c2])
|
||||||
(FLAG_UNMATCHED|FLAG_UNTRANSLATED)
|
{
|
||||||
|| (aggressive_import && [[cur file] isEqual: DUMMY2]))
|
|
||||||
{ /* ignore strings that are unmatched _and_ untranslated */
|
|
||||||
[strings_left removeObjectAtIndex: i];
|
[strings_left removeObjectAtIndex: i];
|
||||||
i--;
|
i--;
|
||||||
continue;
|
continue;
|
||||||
|
@ -490,6 +533,8 @@ static NSString *parse_string(NSString **ptr)
|
||||||
|
|
||||||
c=[strings count];
|
c=[strings count];
|
||||||
|
|
||||||
|
[self addMatched: [e key]];
|
||||||
|
|
||||||
/* Look for exact matches. If we find an exact match (same file, key, and
|
/* Look for exact matches. If we find an exact match (same file, key, and
|
||||||
comment) we mark the StringsEntry matched and don't add the SourceEntry.
|
comment) we mark the StringsEntry matched and don't add the SourceEntry.
|
||||||
*/
|
*/
|
||||||
|
@ -535,11 +580,6 @@ static NSString *parse_string(NSString **ptr)
|
||||||
[se2 setFlags: 0];
|
[se2 setFlags: 0];
|
||||||
[se2 setTranslated: [se translated]];
|
[se2 setTranslated: [se translated]];
|
||||||
[strings addObject: se2];
|
[strings addObject: se2];
|
||||||
|
|
||||||
/* If aggressive_import is enabled and the one we matched is a
|
|
||||||
dummy we change the name to DUMMY2 so we can ignore it later. */
|
|
||||||
if (aggressive_import && [[se file] isEqual: DUMMY])
|
|
||||||
[se setFile: DUMMY2];
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
-(void) addEntry: (SourceEntry *)e toTable: (NSString *)table;
|
-(void) addEntry: (SourceEntry *)e toTable: (NSString *)table;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
extern int verbose,aggressive_import,aggressive_match;
|
extern int verbose,aggressive_import,aggressive_match,aggressive_remove;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
#include "StringsEntry.h"
|
#include "StringsEntry.h"
|
||||||
|
|
||||||
|
|
||||||
int verbose,aggressive_import,aggressive_match;
|
int verbose,aggressive_import,aggressive_match,aggressive_remove;
|
||||||
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
|
@ -475,7 +475,7 @@ int main(int argc, char **argv)
|
||||||
c=argv[i];
|
c=argv[i];
|
||||||
if (!strcmp (c,"--help"))
|
if (!strcmp (c,"--help"))
|
||||||
{
|
{
|
||||||
printf ("Syntax: %s [--help] [--verbose] [--aggressive-import] [--aggressive-match] [-L languages] files.[hmc...]\n",
|
printf ("Syntax: %s [--help] [--verbose] [--aggressive-import] [--aggressive-match] [--aggressive-remove] [-L languages] files.[hmc...]\n",
|
||||||
argv[0]);
|
argv[0]);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf("Example: %s -L \"English Swedish German\" *.[hm]\n",
|
printf("Example: %s -L \"English Swedish German\" *.[hm]\n",
|
||||||
|
@ -495,6 +495,11 @@ int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
aggressive_match = 1;
|
aggressive_match = 1;
|
||||||
}
|
}
|
||||||
|
else if (!strcmp(c,"--aggressive-remove"))
|
||||||
|
{
|
||||||
|
aggressive_remove=1;
|
||||||
|
aggressive_match=1;
|
||||||
|
}
|
||||||
else if (!strcmp (c,"-L"))
|
else if (!strcmp (c,"-L"))
|
||||||
{
|
{
|
||||||
char *d,*d2;
|
char *d,*d2;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue