version 1.19 | | version 1.20 |
---|
| | |
/* | | /* |
* static char *rcsid_arch_c = | | * static char *rcsid_arch_c = |
* "$Id: arch.c,v 1.19 2002/05/31 04:18:32 mwedel Exp $"; | | * "$Id: arch.c,v 1.20 2002/06/07 07:00:38 mwedel Exp $"; |
*/ | | */ |
| | |
/* | | /* |
| | |
* - name: The name we're searching for (ex: "writing pen"); | | * - name: The name we're searching for (ex: "writing pen"); |
* Return value: | | * Return value: |
* - a corresponding object if found; a singularity object if not found. | | * - a corresponding object if found; a singularity object if not found. |
| | * Note by MSW - it appears that it takes the full name and keeps |
| | * shortening it until it finds a match. I re-wrote this so that it |
| | * doesn't malloc it each time - not that this function is used much, |
| | * but it otherwise had a big memory leak. |
*/ | | */ |
object *get_archetype_by_object_name(char *name) { | | object *get_archetype_by_object_name(char *name) { |
archetype *at; | | archetype *at; |
char *tmpname; | | char tmpname[MAX_BUF]; |
int i; | | int i; |
for(i=strlen(name); i>0;i--) | | |
{ | | strncpy(tmpname,name,MAX_BUF-1); |
tmpname = (char *)(malloc(i+1)); | | tmpname[MAX_BUF-1] = 0; |
strncpy(tmpname,name,i); | | for(i=strlen(tmpname); i>0; i--) { |
tmpname[i] = 0x0; | | tmpname[i] = 0; |
at = find_archetype_by_object_name(tmpname); | | at = find_archetype_by_object_name(tmpname); |
if (at !=NULL) | | if (at !=NULL) |
{ | | { |
free(tmpname); | | |
return arch_to_object(at); | | return arch_to_object(at); |
}; | | } |
}; | | } |
return create_singularity(name); | | return create_singularity(name); |
} | | } |
| | |
| | |
else next=at->next; | | else next=at->next; |
if (at->name) free_string(at->name); | | if (at->name) free_string(at->name); |
if (at->clone.name) free_string(at->clone.name); | | if (at->clone.name) free_string(at->clone.name); |
| | if (at->clone.name_pl) free_string(at->clone.name_pl); |
if (at->clone.title) free_string(at->clone.title); | | if (at->clone.title) free_string(at->clone.title); |
if (at->clone.race) free_string(at->clone.race); | | if (at->clone.race) free_string(at->clone.race); |
if (at->clone.slaying) free_string(at->clone.slaying); | | if (at->clone.slaying) free_string(at->clone.slaying); |
| | |
new->name=NULL; | | new->name=NULL; |
new->clone.other_arch=NULL; | | new->clone.other_arch=NULL; |
new->clone.name=NULL; | | new->clone.name=NULL; |
| | new->clone.name_pl=NULL; |
new->clone.title=NULL; | | new->clone.title=NULL; |
new->clone.race=NULL; | | new->clone.race=NULL; |
new->clone.slaying=NULL; | | new->clone.slaying=NULL; |
| | |
sprintf(buf,"singluarity (%s)",name); | | sprintf(buf,"singluarity (%s)",name); |
op = get_object(); | | op = get_object(); |
op->name = add_string(buf); | | op->name = add_string(buf); |
| | op->name_pl = add_string(buf); |
SET_FLAG(op,FLAG_NO_PICK); | | SET_FLAG(op,FLAG_NO_PICK); |
return op; | | return op; |
} | | } |