mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +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
dacf96257f
commit
252ca62dd3
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>
|
||||
|
||||
* Source/NSBundle.m: Don't NSLog when we can't find a localizable
|
||||
|
|
|
@ -27,8 +27,16 @@
|
|||
|
||||
@interface StringsFile : NSObject
|
||||
{
|
||||
NSMutableArray *strings;
|
||||
NSString *global_comment;
|
||||
@public
|
||||
NSMutableArray *strings;
|
||||
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;
|
||||
|
|
|
@ -69,14 +69,39 @@ static NSString *parse_string(NSString **ptr)
|
|||
|
||||
|
||||
#define DUMMY @"<dummy>"
|
||||
#define DUMMY2 @"<dummy2>"
|
||||
|
||||
@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
|
||||
{
|
||||
self=[super init];
|
||||
strings=[[NSMutableArray alloc] init];
|
||||
keys_translated=[[NSMutableArray alloc] init];
|
||||
keys_matched=[[NSMutableArray alloc] init];
|
||||
return self;
|
||||
}
|
||||
|
||||
|
@ -132,7 +157,7 @@ static NSString *parse_string(NSString **ptr)
|
|||
else if ([l hasPrefix: @" File: "])
|
||||
{
|
||||
se=[[StringsEntry alloc] init];
|
||||
[se addFlag: FLAG_UNMATCHED];
|
||||
[se addFlag: FLAG_UNMATCHED]; /* TODO: ? */
|
||||
[update_list addObject: se];
|
||||
[se release];
|
||||
|
||||
|
@ -212,13 +237,21 @@ static NSString *parse_string(NSString **ptr)
|
|||
|
||||
[update_list makeObjectsPerformSelector: @selector(setKey:) withObject: key];
|
||||
[update_list makeObjectsPerformSelector: @selector(setTranslated:) withObject: trans];
|
||||
/* {
|
||||
int i,c=[update_list count];
|
||||
for (i=0;i<c;i++)
|
||||
{
|
||||
printf("%4i : %@\n",i,[update_list objectAtIndex: i]);
|
||||
}
|
||||
}*/
|
||||
|
||||
{
|
||||
int i,c=[update_list count];
|
||||
for (i=0;i<c;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];
|
||||
|
||||
|
@ -307,10 +340,24 @@ static NSString *parse_string(NSString **ptr)
|
|||
[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
|
||||
{
|
||||
unsigned i,c;
|
||||
unsigned int i,c;
|
||||
BOOL result;
|
||||
NSMutableString *str=[[NSMutableString alloc] initWithCapacity: 32*1024];
|
||||
StringsEntry *se;
|
||||
|
@ -350,10 +397,8 @@ static NSString *parse_string(NSString **ptr)
|
|||
while ([strings_left count])
|
||||
{
|
||||
cur=[strings_left objectAtIndex: 0];
|
||||
if (([cur flags]&(FLAG_UNMATCHED|FLAG_UNTRANSLATED))==
|
||||
(FLAG_UNMATCHED|FLAG_UNTRANSLATED)
|
||||
|| (aggressive_import && [[cur file] isEqual: DUMMY2]))
|
||||
{ /* ignore strings that are unmatched _and_ untranslated */
|
||||
if ([self _shouldIgnore: cur])
|
||||
{
|
||||
[strings_left removeObjectAtIndex: 0];
|
||||
continue;
|
||||
}
|
||||
|
@ -366,10 +411,8 @@ static NSString *parse_string(NSString **ptr)
|
|||
{
|
||||
c2=[strings_left objectAtIndex: i];
|
||||
|
||||
if (([c2 flags]&(FLAG_UNMATCHED|FLAG_UNTRANSLATED))==
|
||||
(FLAG_UNMATCHED|FLAG_UNTRANSLATED)
|
||||
|| (aggressive_import && [[cur file] isEqual: DUMMY2]))
|
||||
{ /* ignore strings that are unmatched _and_ untranslated */
|
||||
if ([self _shouldIgnore: c2])
|
||||
{
|
||||
[strings_left removeObjectAtIndex: i];
|
||||
i--;
|
||||
continue;
|
||||
|
@ -490,6 +533,8 @@ static NSString *parse_string(NSString **ptr)
|
|||
|
||||
c=[strings count];
|
||||
|
||||
[self addMatched: [e key]];
|
||||
|
||||
/* 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.
|
||||
*/
|
||||
|
@ -535,11 +580,6 @@ static NSString *parse_string(NSString **ptr)
|
|||
[se2 setFlags: 0];
|
||||
[se2 setTranslated: [se translated]];
|
||||
[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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
-(void) addEntry: (SourceEntry *)e toTable: (NSString *)table;
|
||||
@end
|
||||
|
||||
extern int verbose,aggressive_import,aggressive_match;
|
||||
extern int verbose,aggressive_import,aggressive_match,aggressive_remove;
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
#include "StringsEntry.h"
|
||||
|
||||
|
||||
int verbose,aggressive_import,aggressive_match;
|
||||
int verbose,aggressive_import,aggressive_match,aggressive_remove;
|
||||
|
||||
|
||||
typedef struct
|
||||
|
@ -475,7 +475,7 @@ int main(int argc, char **argv)
|
|||
c=argv[i];
|
||||
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]);
|
||||
printf("\n");
|
||||
printf("Example: %s -L \"English Swedish German\" *.[hm]\n",
|
||||
|
@ -495,6 +495,11 @@ int main(int argc, char **argv)
|
|||
{
|
||||
aggressive_match = 1;
|
||||
}
|
||||
else if (!strcmp(c,"--aggressive-remove"))
|
||||
{
|
||||
aggressive_remove=1;
|
||||
aggressive_match=1;
|
||||
}
|
||||
else if (!strcmp (c,"-L"))
|
||||
{
|
||||
char *d,*d2;
|
||||
|
|
Loading…
Reference in a new issue