Merge branch 'master' of github.com:eressea/server

This commit is contained in:
Enno Rehling 2014-08-17 12:15:26 +02:00
commit a289eee06f
7 changed files with 2310 additions and 2251 deletions

View File

@ -6944,34 +6944,24 @@
<text locale="en">none</text> <text locale="en">none</text>
</string> </string>
<string name="faction_help_one"> <string name="faction_help">
<text locale="de">Wir helfen der Partei</text> <text locale="de">Wir helfen</text>
<text locale="en">We are helping the faction</text> <text locale="en">We are helping</text>
</string> </string>
<string name="faction_help_many"> <string name="group_help">
<text locale="de">Wir helfen den Parteien</text> <text locale="de">hilft</text>
<text locale="en">We are helping the factions</text> <text locale="en">is helping</text>
</string>
<string name="group_help_one">
<text locale="de">hilft der Partei</text>
<text locale="en">is helping the faction</text>
</string>
<string name="group_help_many">
<text locale="de">hilft den Parteien</text>
<text locale="en">is helping the factions</text>
</string> </string>
<string name="has_moved_one"> <string name="has_moved_one">
<text locale="de">hat die Region durchquert</text> <text locale="de">hat die Region durchquert.</text>
<text locale="en">has traveled through the region</text> <text locale="en">passed through the region.</text>
</string> </string>
<string name="has_moved_many"> <string name="has_moved_many">
<text locale="de">haben die Region durchquert</text> <text locale="de">haben die Region durchquert.</text>
<text locale="en">have traveled through the region</text> <text locale="en">passed through the region.</text>
</string> </string>
<string name="see_travel"> <string name="see_travel">

View File

@ -804,51 +804,49 @@
<arg name="max" type="int"/> <arg name="max" type="int"/>
</type> </type>
<text locale="de">"Unterhaltung: max. $int($max) Silber"</text> <text locale="de">"Unterhaltung: max. $int($max) Silber"</text>
<text locale="en">"Entertainment: max. $int($max) silver"</text> <text locale="en">"entertainment: max. $int($max) silver"</text>
</message> </message>
<message name="nr_stat_morale" section="nr"> <message name="nr_stat_morale" section="nr">
<type> <type>
<arg name="morale" type="int"/> <arg name="morale" type="int"/>
</type> </type>
<text locale="de">"Moral der Bauern: $int($morale)"</text> <text locale="de">"Moral der Bauern: $int($morale)"</text>
<text locale="en">"Peasant morale: $int($morale)"</text> <text locale="en">"peasant morale: $int($morale)"</text>
</message> </message>
<message name="nr_stat_luxuries" section="nr"> <message name="nr_stat_luxuries" section="nr">
<type> <type>
<arg name="max" type="int"/> <arg name="max" type="int"/>
</type> </type>
<text locale="de">"Luxusgüter zum angegebenen Preis: $int($max)"</text> <text locale="de">"Luxusgüter zum angegebenen Preis: $int($max)"</text>
<text locale="en">"Luxury goods at this price: $int($max)"</text> <text locale="en">"luxury goods at this price: $int($max)"</text>
</message> </message>
<message name="nr_stat_salary" section="nr"> <message name="nr_stat_salary" section="nr">
<type> <type>
<arg name="max" type="int"/> <arg name="max" type="int"/>
</type> </type>
<text locale="de">"Lohn für Arbeit: $int($max) Silber"</text> <text locale="de">"Lohn für Arbeit: $int($max) Silber"</text>
<text locale="en">"Worker salary: $int($max) silver"</text> <text locale="en">"worker salary: $int($max) silver"</text>
</message> </message>
<message name="nr_stat_salary_new" section="nr"> <message name="nr_stat_salary_new" section="nr">
<type> <type>
<arg name="max" type="int"/> <arg name="max" type="int"/>
</type> </type>
<text locale="de">"Bauerneinnahmen: $int($max) Silber"</text> <text locale="de">"Bauerneinnahmen: $int($max) Silber"</text>
<text locale="en">"Peasant wages: $int($max) silver"</text> <text locale="en">"peasant wages: $int($max) silver"</text>
</message> </message>
<message name="nr_stat_people" section="nr"> <message name="nr_stat_people" section="nr">
<type> <type>
<arg name="max" type="int"/> <arg name="max" type="int"/>
</type> </type>
<text locale="de">"Personen: $int($max)"</text> <text locale="de">"Personen: $int($max)"</text>
<text locale="en">"People: $int($max)"</text> <text locale="en">"people: $int($max)"</text>
<text locale="fr">"People: $int($max)"</text>
</message> </message>
<message name="nr_stat_recruits" section="nr"> <message name="nr_stat_recruits" section="nr">
<type> <type>
<arg name="max" type="int"/> <arg name="max" type="int"/>
</type> </type>
<text locale="de">"Rekruten: max. $int($max) Bauern"</text> <text locale="de">"Rekruten: max. $int($max) Bauern"</text>
<text locale="en">"Recruits: $int($max) peasants"</text> <text locale="en">"recruits: $int($max) peasants"</text>
<text locale="fr">"Recruits: $int($max) peasants"</text>
</message> </message>
<message name="nr_score" section="nr"> <message name="nr_score" section="nr">
<type> <type>
@ -857,7 +855,6 @@
</type> </type>
<text locale="de">"Deine Partei hat $int($score) Punkte. Der Durchschnitt für Parteien ähnlichen Alters ist $int($average) Punkte."</text> <text locale="de">"Deine Partei hat $int($score) Punkte. Der Durchschnitt für Parteien ähnlichen Alters ist $int($average) Punkte."</text>
<text locale="fr">"Your faction has a score of $int($score). The average score for similar factions is $int($average)."</text> <text locale="fr">"Your faction has a score of $int($score). The average score for similar factions is $int($average)."</text>
<text locale="en">"Your faction has a score of $int($score). The average score for similar factions is $int($average)."</text>
</message> </message>
<message name="nr_header_date" section="nr"> <message name="nr_header_date" section="nr">
<type> <type>

View File

@ -14,6 +14,7 @@ equipment.test.c
curse.test.c curse.test.c
item.test.c item.test.c
move.test.c move.test.c
order.test.c
pool.test.c pool.test.c
reports.test.c reports.test.c
spellbook.test.c spellbook.test.c

View File

@ -2,7 +2,7 @@
+-------------------+ +-------------------+
| | Christian Schlittchen <corwin@amber.kn-bremen.de> | | Christian Schlittchen <corwin@amber.kn-bremen.de>
| Eressea PBEM host | Enno Rehling <enno@eressea.de> | Eressea PBEM host | Enno Rehling <enno@eressea.de>
| (c) 1998 - 2004 | Katja Zedel <katze@felidae.kn-bremen.de> | (c) 1998 - 2014 | Katja Zedel <katze@felidae.kn-bremen.de>
| | | |
+-------------------+ +-------------------+
@ -44,7 +44,7 @@ static struct locale_data *locale_array[16];
static int nlocales = 0; static int nlocales = 0;
typedef struct order_data { typedef struct order_data {
char *_str; const char *_str;
# ifdef LOMEM # ifdef LOMEM
int _refcount:20; int _refcount:20;
int _lindex:4; int _lindex:4;
@ -59,8 +59,6 @@ static void release_data(order_data * data)
{ {
if (data) { if (data) {
if (--data->_refcount == 0) { if (--data->_refcount == 0) {
if (data->_str)
free(data->_str);
free(data); free(data);
} }
} }
@ -182,6 +180,22 @@ void free_orders(order ** olist)
} }
} }
static char *mkdata(order_data **pdata, size_t len, keyword_t kwd, int lindex, const char *str)
{
order_data *data;
char *result;
data = malloc(sizeof(order_data) + len +1);
result = (char *)(data + 1);
data->_keyword = kwd;
data->_lindex = lindex;
data->_refcount = 0;
data->_str = 0;
data->_str = (len > 0) ? result : 0;
if (str) strcpy(result, str);
if (pdata) *pdata = data;
return result;
}
static order_data *create_data(keyword_t kwd, const char *sptr, int lindex) static order_data *create_data(keyword_t kwd, const char *sptr, int lindex)
{ {
const char *s = sptr; const char *s = sptr;
@ -204,21 +218,15 @@ static order_data *create_data(keyword_t kwd, const char *sptr, int lindex)
data = locale_array[lindex]->study_orders[sk]; data = locale_array[lindex]->study_orders[sk];
if (data == NULL) { if (data == NULL) {
const char *skname = skillname(sk, lang); const char *skname = skillname(sk, lang);
data = (order_data *)malloc(sizeof(order_data)); const char *spc = strchr(skname, ' ');
size_t len = strlen(skname);
char *dst = mkdata(&data, len + (spc ? 3 : 0), kwd, lindex, spc ? 0 : skname);
locale_array[lindex]->study_orders[sk] = data; locale_array[lindex]->study_orders[sk] = data;
data->_keyword = kwd; if (spc) {
data->_lindex = lindex; dst[0] = '\"';
assert(data->_lindex >= 0); memcpy(dst + 1, skname, len);
if (strchr(skname, ' ') != NULL) { dst[len + 1] = '\"';
size_t len = strlen(skname); dst[len + 2] = '\0';
data->_str = malloc(len + 3);
data->_str[0] = '\"';
memcpy(data->_str + 1, skname, len);
data->_str[len + 1] = '\"';
data->_str[len + 2] = '\0';
}
else {
data->_str = _strdup(skname);
} }
data->_refcount = 1; data->_refcount = 1;
} }
@ -231,22 +239,13 @@ static order_data *create_data(keyword_t kwd, const char *sptr, int lindex)
else if (kwd != NOKEYWORD && *sptr == 0) { else if (kwd != NOKEYWORD && *sptr == 0) {
data = locale_array[lindex]->short_orders[kwd]; data = locale_array[lindex]->short_orders[kwd];
if (data == NULL) { if (data == NULL) {
data = (order_data *)malloc(sizeof(order_data)); mkdata(&data, 0, kwd, lindex, 0);
locale_array[lindex]->short_orders[kwd] = data;
data->_keyword = kwd;
data->_lindex = lindex;
assert(data->_lindex >= 0);
data->_str = NULL;
data->_refcount = 1; data->_refcount = 1;
} }
++data->_refcount; ++data->_refcount;
return data; return data;
} }
data = (order_data *)malloc(sizeof(order_data)); mkdata(&data, s ? strlen(s) : 0, kwd, lindex, s);
data->_keyword = kwd;
data->_lindex = lindex;
assert(data->_lindex >= 0);
data->_str = s ? _strdup(s) : NULL;
data->_refcount = 1; data->_refcount = 1;
return data; return data;
} }

48
src/kernel/order.test.c Normal file
View File

@ -0,0 +1,48 @@
#include <config.h>
#include "order.h"
#include <util/parser.h>
#include <util/language.h>
#include <CuTest.h>
#include <stdlib.h>
static void test_create_order(CuTest *tc) {
char cmd[32];
order *ord;
struct locale * lang = get_or_create_locale("en");
locale_setstring(lang, "keyword::move", "MOVE");
ord = create_order(K_MOVE, lang, "NORTH");
CuAssertPtrNotNull(tc, ord);
CuAssertIntEquals(tc, K_MOVE, getkeyword(ord));
init_tokens(ord);
CuAssertStrEquals(tc, "MOVE NORTH", get_command(ord, cmd, sizeof(cmd)));
CuAssertStrEquals(tc, "MOVE", getstrtoken());
CuAssertStrEquals(tc, "NORTH", getstrtoken());
free_order(ord);
}
static void test_parse_order(CuTest *tc) {
char cmd[32];
order *ord;
struct locale * lang = get_or_create_locale("en");
locale_setstring(lang, "keyword::move", "MOVE");
ord = parse_order("MOVE NORTH", lang);
CuAssertPtrNotNull(tc, ord);
CuAssertIntEquals(tc, K_MOVE, getkeyword(ord));
init_tokens(ord);
CuAssertStrEquals(tc, "MOVE NORTH", get_command(ord, cmd, sizeof(cmd)));
CuAssertStrEquals(tc, "MOVE", getstrtoken());
CuAssertStrEquals(tc, "NORTH", getstrtoken());
free_order(ord);
}
CuSuite *get_order_suite(void)
{
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_create_order);
SUITE_ADD_TEST(suite, test_parse_order);
return suite;
}

File diff suppressed because it is too large Load Diff

View File

@ -9,36 +9,6 @@
CuSuite *get_##name##_suite(void); \ CuSuite *get_##name##_suite(void); \
CuSuiteAddSuite(suite, get_##name##_suite()) CuSuiteAddSuite(suite, get_##name##_suite())
CuSuite *get_tests_suite(void);
CuSuite *get_callback_suite(void);
CuSuite *get_jsonconf_suite(void);
CuSuite *get_json_suite(void);
CuSuite *get_economy_suite(void);
CuSuite *get_laws_suite(void);
CuSuite *get_market_suite(void);
CuSuite *get_battle_suite(void);
CuSuite *get_building_suite(void);
CuSuite *get_curse_suite(void);
CuSuite *get_equipment_suite(void);
CuSuite *get_item_suite(void);
CuSuite *get_magic_suite(void);
CuSuite *get_move_suite(void);
CuSuite *get_pool_suite(void);
CuSuite *get_build_suite(void);
CuSuite *get_reports_suite(void);
CuSuite *get_ship_suite(void);
CuSuite *get_spellbook_suite(void);
CuSuite *get_spell_suite(void);
CuSuite *get_base36_suite(void);
CuSuite *get_config_suite(void);
CuSuite *get_bsdstring_suite(void);
CuSuite *get_functions_suite(void);
CuSuite *get_umlaut_suite(void);
CuSuite *get_ally_suite(void);
CuSuite *get_direction_suite(void);
CuSuite *get_skill_suite(void);
CuSuite *get_keyword_suite(void);
int RunAllTests(void) int RunAllTests(void)
{ {
CuString *output = CuStringNew(); CuString *output = CuStringNew();
@ -56,6 +26,7 @@ int RunAllTests(void)
ADD_TESTS(suite, direction); ADD_TESTS(suite, direction);
ADD_TESTS(suite, skill); ADD_TESTS(suite, skill);
ADD_TESTS(suite, keyword); ADD_TESTS(suite, keyword);
ADD_TESTS(suite, order);
/* util */ /* util */
ADD_TESTS(suite, config); ADD_TESTS(suite, config);
ADD_TESTS(suite, base36); ADD_TESTS(suite, base36);