2010-08-08 10:06:34 +02:00
|
|
|
/*
|
|
|
|
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
|
|
|
Katja Zedel <katze@felidae.kn-bremen.de
|
|
|
|
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
|
|
|
|
|
|
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
purpose with or without fee is hereby granted, provided that the above
|
|
|
|
copyright notice and this permission notice appear in all copies.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
**/
|
|
|
|
|
|
|
|
#include <platform.h>
|
|
|
|
#include <kernel/config.h>
|
|
|
|
#include "raceprefix.h"
|
|
|
|
#include <kernel/save.h>
|
|
|
|
|
|
|
|
#include <util/attrib.h>
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <string.h>
|
2014-03-15 19:29:11 +01:00
|
|
|
#include <stdlib.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
attrib_type at_raceprefix = {
|
|
|
|
"raceprefix", NULL, a_finalizestring, NULL, a_writestring, a_readstring,
|
|
|
|
ATF_UNIQUE
|
2010-08-08 10:06:34 +02:00
|
|
|
};
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
void set_prefix(attrib ** ap, const char *str)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
attrib *a = a_find(*ap, &at_raceprefix);
|
|
|
|
if (a == NULL) {
|
2010-08-08 10:06:34 +02:00
|
|
|
a = a_add(ap, a_new(&at_raceprefix));
|
|
|
|
} else {
|
|
|
|
free(a->data.v);
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
assert(a->type == &at_raceprefix);
|
2013-12-29 14:38:58 +01:00
|
|
|
a->data.v = _strdup(str);
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
const char *get_prefix(const attrib * a)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
char *str;
|
2010-08-08 10:06:34 +02:00
|
|
|
a = a_findc(a, &at_raceprefix);
|
2011-03-07 08:02:35 +01:00
|
|
|
if (a == NULL)
|
|
|
|
return NULL;
|
2010-08-08 10:06:34 +02:00
|
|
|
str = (char *)a->data.v;
|
|
|
|
/* conversion of old prefixes */
|
2011-03-07 08:02:35 +01:00
|
|
|
if (strncmp(str, "prefix_", 7) == 0) {
|
2013-12-29 14:38:58 +01:00
|
|
|
((attrib *) a)->data.v = _strdup(str + 7);
|
2010-08-08 10:06:34 +02:00
|
|
|
free(str);
|
|
|
|
str = (char *)a->data.v;
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
}
|