quakeforge/tools/Forge/EntityArray.m

120 lines
1.7 KiB
Mathematica
Raw Normal View History

#import "qedefs.h"
@implementation EntityArray
/*
=================
insertEC:
=================
*/
- (void)insertEC: ec
{
char *name;
int i;
name = [ec classname];
2001-02-09 06:08:53 +00:00
for (i=0 ; i<[self count] ; i++)
{
2001-02-09 06:08:53 +00:00
if (strcasecmp (name, [[self objectAtIndex: i] classname]) < 0)
{
2001-02-09 06:08:53 +00:00
[self insertObject: ec atIndex:i];
return;
}
}
[self addObject: ec];
}
/*
=================
scanFile
=================
*/
- (void)scanFile: (char *)filename
{
int size;
char *data;
id cl;
int i;
char path[1024];
sprintf (path,"%s/%s", source_path, filename);
size = LoadFile (path, (void *)&data);
for (i=0 ; i<size ; i++)
if (!strncmp(data+i, "/*QUAKED",8))
{
cl = [[EntityClass alloc] initFromText: data+i];
if (cl)
[self insertEC: cl];
else
printf ("Error parsing: %s in %s\n",debugname, filename);
}
free (data);
}
/*
=================
scanDirectory
=================
*/
- (void)scanDirectory
{
int count, i;
2001-02-09 06:08:53 +00:00
struct dirent **namelist, *ent;
2001-02-09 06:08:53 +00:00
[self removeAllObjects];
count = scandir(source_path, &namelist, NULL, NULL);
for (i=0 ; i<count ; i++)
{
ent = namelist[i];
2001-02-09 06:08:53 +00:00
if (strlen(ent->d_name) <= 3)
continue;
2001-02-09 06:08:53 +00:00
if (!strcmp (ent->d_name+strlen(ent->d_name)-3,".qc"))
[self scanFile: ent->d_name];
}
}
id entity_classes_i;
- initForSourceDirectory: (char *)path
{
[super init];
source_path = path;
[self scanDirectory];
entity_classes_i = self;
nullclass = [[EntityClass alloc] initFromText:
"/*QUAKED UNKNOWN_CLASS (0 0.5 0) ?"];
return self;
}
- (id)classForName: (char *)name
{
int i;
id o;
2001-02-09 06:08:53 +00:00
for (i=0 ; i<[self count] ; i++)
{
2001-02-09 06:08:53 +00:00
o = [self objectAtIndex: i];
if (!strcmp (name,[o classname]) )
return o;
}
return nullclass;
}
@end