2003-03-18 19:48:24 +00:00
|
|
|
|
2010-09-11 08:35:25 +00:00
|
|
|
#include "DictList.h"
|
|
|
|
#include "Dict.h"
|
2003-03-18 19:48:24 +00:00
|
|
|
|
2010-09-12 07:25:25 +00:00
|
|
|
#define THING DictList
|
|
|
|
#include "THING+NSArray.m"
|
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
@implementation DictList
|
|
|
|
//
|
2010-09-11 10:03:41 +00:00
|
|
|
// Read in variable # of objects from FILE *
|
2003-03-18 19:48:24 +00:00
|
|
|
//
|
2010-09-11 10:03:41 +00:00
|
|
|
- initListFromFile:(FILE *) fp
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
id d;
|
|
|
|
|
2010-09-12 07:25:25 +00:00
|
|
|
self = [super init];
|
|
|
|
array = [[NSMutableArray alloc] init];
|
2010-09-11 10:03:41 +00:00
|
|
|
do {
|
|
|
|
d =[(Dict *)[Dict alloc] initFromFile:fp];
|
2003-03-18 19:48:24 +00:00
|
|
|
if (d != NULL)
|
|
|
|
[self addObject:d];
|
2010-09-11 10:03:41 +00:00
|
|
|
} while (d != NULL);
|
2010-09-11 08:35:25 +00:00
|
|
|
[d release];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2010-09-11 10:03:41 +00:00
|
|
|
// Write out list file
|
2003-03-18 19:48:24 +00:00
|
|
|
//
|
2010-09-28 09:41:38 +00:00
|
|
|
-writeListFile:(const char *) filename
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
FILE *fp;
|
2010-09-27 18:01:07 +00:00
|
|
|
NSUInteger i;
|
2010-09-11 10:03:41 +00:00
|
|
|
id obj;
|
|
|
|
|
|
|
|
fp = fopen (filename, "w+t");
|
2003-03-18 19:48:24 +00:00
|
|
|
if (fp == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
fprintf (fp, "// Object List written by QuakeEd\n");
|
|
|
|
|
|
|
|
for (i = 0; i <[self count]; i++) {
|
|
|
|
obj =[self objectAtIndex:i];
|
2003-03-18 19:48:24 +00:00
|
|
|
[obj writeBlockTo:fp];
|
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
fclose (fp);
|
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2010-09-11 10:03:41 +00:00
|
|
|
// Find the keyword in all the Dict objects
|
2003-03-18 19:48:24 +00:00
|
|
|
//
|
2010-09-28 09:41:38 +00:00
|
|
|
-(id) findDictKeyword:(const char *) key
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-27 18:01:07 +00:00
|
|
|
NSUInteger i;
|
2010-09-11 10:03:41 +00:00
|
|
|
dict_t *d;
|
|
|
|
id dict;
|
2003-03-18 19:48:24 +00:00
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
for (i = 0; i <[self count]; i++) {
|
|
|
|
dict =[self objectAtIndex:i];
|
|
|
|
d =[(Dict *) dict findKeyword:key];
|
2003-03-18 19:48:24 +00:00
|
|
|
if (d != NULL)
|
|
|
|
return dict;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|