Use NS* classes for QUAKED directory scanning.

The scanning of actual files is still done using normal C strings, but now
everything up to (but not including) opening the file is handled by *step.
This commit is contained in:
Bill Currie 2010-12-26 20:36:47 +09:00
parent 232c67640c
commit f105fbd6a0
3 changed files with 24 additions and 20 deletions

View file

@ -35,10 +35,10 @@ typedef enum {esize_model, esize_fixed} esize_t;
{ {
NSMutableArray *array; NSMutableArray *array;
id nullclass; id nullclass;
char *source_path; NSString *source_path;
} }
- (id) initForSourceDirectory: (const char *)path; - (id) initForSourceDirectory: (NSString *)path;
- (id) classForName: (const char *)name; - (id) classForName: (const char *)name;
- (void) scanDirectory; - (void) scanDirectory;

View file

@ -172,18 +172,18 @@ insertEC:
scanFile scanFile
================= =================
*/ */
- (void) scanFile: (const char *)filename - (void) scanFile: (NSString *)filename
{ {
int size, line; int size, line;
char *data; char *data;
id cl; id cl;
int i; int i;
const char *path; NSString *path;
QFile *file; QFile *file;
path = va ("%s/%s", source_path, filename); path = [source_path stringByAppendingPathComponent: filename];
file = Qopen (path, "rt"); file = Qopen ([path cString], "rt");
if (!file) if (!file)
return; return;
size = Qfilesize (file); size = Qfilesize (file);
@ -197,7 +197,7 @@ scanFile
if (!strncmp (data + i, "/*QUAKED", 8)) { if (!strncmp (data + i, "/*QUAKED", 8)) {
cl = [[EntityClass alloc] cl = [[EntityClass alloc]
initFromText: (data + i) initFromText: (data + i)
source: va ("%s:%d", filename, line)]; source: va ("%s:%d", [filename cString], line)];
if (cl) if (cl)
[self insertEC: cl]; [self insertEC: cl];
} else if (data[i] == '\n') { } else if (data[i] == '\n') {
@ -216,32 +216,36 @@ scanDirectory
- (void) scanDirectory - (void) scanDirectory
{ {
int count, i; int count, i;
struct dirent **namelist, *ent; NSFileManager *fm;
NSArray *file_list;
[self removeAllObjects]; [self removeAllObjects];
count = scandir (source_path, &namelist, NULL, NULL); fm = [NSFileManager defaultManager];
file_list = [fm directoryContentsAtPath: source_path];
if (!file_list)
return;
count = [file_list count];
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
int len; NSString *file = [file_list objectAtIndex: i];
ent = namelist[i]; if ([[file pathExtension] isEqualToString: @"qc"])
len = strlen (ent->d_name); [self scanFile: file];
if (len <= 3)
continue;
if (!strcmp (ent->d_name + len - 3, ".qc"))
[self scanFile: ent->d_name];
} }
} }
id entity_classes_i; id entity_classes_i;
- (id) initForSourceDirectory: (const char *)path - (id) initForSourceDirectory: (NSString *)path
{ {
self = [super init]; self = [super init];
array = [[NSMutableArray alloc] init]; array = [[NSMutableArray alloc] init];
source_path = strdup (path); // FIXME leak? [path retain];
[source_path release];
source_path = path;
[self scanDirectory]; [self scanDirectory];
entity_classes_i = self; entity_classes_i = self;

View file

@ -48,7 +48,7 @@ id things_i;
[prog_path_i setStringValue: path]; [prog_path_i setStringValue: path];
[[EntityClassList alloc] initForSourceDirectory: [path cString]]; [[EntityClassList alloc] initForSourceDirectory: path];
[self loadEntityComment: [entity_classes_i objectAtIndex: lastSelected]]; [self loadEntityComment: [entity_classes_i objectAtIndex: lastSelected]];
[entity_browser_i loadColumnZero]; [entity_browser_i loadColumnZero];
@ -99,7 +99,7 @@ id things_i;
[entity_classes_i release]; [entity_classes_i release];
// Now, RELOAD! // Now, RELOAD!
[[EntityClassList alloc] initForSourceDirectory: [path cString]]; [[EntityClassList alloc] initForSourceDirectory: path];
lastSelected = 0; lastSelected = 0;
ent = [entity_classes_i objectAtIndex: lastSelected]; ent = [entity_classes_i objectAtIndex: lastSelected];