diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 000000000..a2548de17 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_minimum_required(VERSION 2.4) +project (core C) + +add_subdirectory (../dependencies "${CMAKE_CURRENT_BINARY_DIR}/dependencies") +add_subdirectory (src eressea) diff --git a/scripts/spells.lua b/scripts/spells.lua index 8269e72e6..29991376c 100644 --- a/scripts/spells.lua +++ b/scripts/spells.lua @@ -1,9 +1,14 @@ function creation_message(mage, type, number) local msg = message.create("item_create_spell") - msg:set_unit("mage", mage) - msg:set_int("number", number) - msg:set_resource("item", type) - return msg + local err = 0 + err = err + msg:set_unit("mage", mage) + err = err + msg:set_int("number", number) + err = err + msg:set_resource("item", type) + if err ~= 0 then + return nil + else + return msg + end end local function create_item(mage, level, name, number) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 000000000..918ad54e3 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,189 @@ +cmake_minimum_required(VERSION 2.4) +project (eressea C) + +set (CORE_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE INTERNAL "Eressea Core headers") + +find_package (Lua51 REQUIRED) +find_package (LibXml2 REQUIRED) + +include_directories (${CORE_INCLUDE_DIR}) +include_directories (${CRITBIT_INCLUDE_DIR}) +include_directories (${CRYPTO_INCLUDE_DIR}) +include_directories (${QUICKLIST_INCLUDE_DIR}) +include_directories (${CUTEST_INCLUDE_DIR}) +include_directories (${LUA_INCLUDE_DIR}) +include_directories (${LIBXML2_INCLUDE_DIR}) +include_directories (${BSON_INCLUDE_DIR}) +include_directories (${INIPARSER_INCLUDE_DIR}) + +add_library(${PROJECT_NAME} + attributes/alliance.c + attributes/attributes.c + attributes/fleechance.c + attributes/follow.c + attributes/giveitem.c + attributes/gm.c + attributes/hate.c + attributes/iceberg.c + attributes/key.c + attributes/matmod.c + attributes/moved.c + attributes/movement.c + attributes/object.c + attributes/orcification.c + attributes/otherfaction.c + attributes/overrideroads.c + attributes/racename.c + attributes/raceprefix.c + attributes/reduceproduction.c + attributes/targetregion.c + bindings/bind_attrib.c + bindings/bind_building.c + bindings/bind_faction.c + bindings/bind_gmtool.c + bindings/bind_hashtable.c + bindings/bindings.c + bindings/bind_message.c + bindings/bind_region.c + bindings/bind_ship.c + bindings/bind_sqlite.c + bindings/bind_storage.c + bindings/bind_unit.c + bindings/helpers.c + eressea.c + gamecode/archetype.c + gamecode/creation.c + gamecode/creport.c + gamecode/economy.c + gamecode/economy_test.c + gamecode/give.c + gamecode/items.c + gamecode/laws.c + gamecode/laws_test.c + gamecode/market.c + gamecode/market_test.c + gamecode/monster.c + gamecode/randenc.c + gamecode/report.c + gamecode/spy.c + gamecode/study.c + gamecode/summary.c + gamecode/xmlreport.c + gmtool.c + items/artrewards.c + items/demonseye.c + items/itemtypes.c + items/phoenixcompass.c + items/seed.c + items/speedsail.c + items/weapons.c + items/xerewards.c + kernel/alchemy.c + kernel/alliance.c + kernel/battle.c + kernel/battle_test.c + kernel/binarystore.c + kernel/build.c + kernel/building.c + kernel/building_test.c + kernel/calendar.c + kernel/command.c + kernel/config.c + kernel/connection.c + kernel/curse.c + kernel/curse_test.c + kernel/equipment.c + kernel/equipment_test.c + kernel/faction.c + kernel/group.c + kernel/item.c + kernel/item_test.c + kernel/magic.c + kernel/magic_test.c + kernel/message.c + kernel/move.c + kernel/move_test.c + kernel/names.c + kernel/order.c + kernel/pathfinder.c + kernel/plane.c + kernel/player.c + kernel/pool.c + kernel/pool_test.c + kernel/race.c + kernel/region.c + kernel/reports.c + kernel/reports_test.c + kernel/resources.c + kernel/save.c + kernel/ship.c + kernel/ship_test.c + kernel/skill.c + kernel/spellbook.c + kernel/spellbook_test.c + kernel/spell.c + kernel/spell_test.c + kernel/sqlite.c + kernel/teleport.c + kernel/terrain.c + kernel/textstore.c + kernel/unit.c + kernel/xmlreader.c + modules/arena.c + modules/autoseed.c + modules/dungeon.c + modules/gmcmd.c + modules/museum.c + modules/score.c + modules/weather.c + modules/wormhole.c + modules/xecmd.c + modules/xmas.c + tests.c + tests_test.c + triggers/changefaction.c + triggers/changerace.c + triggers/clonedied.c + triggers/createcurse.c + triggers/createunit.c + triggers/gate.c + triggers/giveitem.c + triggers/killunit.c + triggers/removecurse.c + triggers/shock.c + triggers/timeout.c + triggers/triggers.c + triggers/unguard.c + triggers/unitmessage.c + util/attrib.c + util/base36.c + util/base36_test.c + util/bsdstring.c + util/bsdstring_test.c + util/console.c + util/crmessage.c + util/dice.c + util/eventbus.c + util/event.c + util/filereader.c + util/functions.c + util/functions_test.c + util/goodies.c + util/language.c + util/listbox.c + util/lists.c + util/log.c + util/message.c + util/nrmessage.c + util/os.c + util/parser.c + util/rand.c + util/resolve.c + util/sql.c + util/strings.c + util/translation.c + util/umlaut.c + util/umlaut_test.c + util/unicode.c + util/xml.c +) diff --git a/src/bindings/bind_attrib.h b/src/bindings/bind_attrib.h index 5ab8daad5..6195e109d 100644 --- a/src/bindings/bind_attrib.h +++ b/src/bindings/bind_attrib.h @@ -10,6 +10,8 @@ This program may not be used, modified or distributed without prior permission by the authors of Eressea. */ +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/src/bindings/bind_gmtool.c b/src/bindings/bind_gmtool.c index a38e8d32c..a55cb75b7 100644 --- a/src/bindings/bind_gmtool.c +++ b/src/bindings/bind_gmtool.c @@ -1,4 +1,5 @@ #include +#include #include #include "bind_gmtool.h" diff --git a/src/bindings/bind_message.c b/src/bindings/bind_message.c index ae27573d9..6ff30e98a 100644 --- a/src/bindings/bind_message.c +++ b/src/bindings/bind_message.c @@ -72,6 +72,7 @@ int msg_set_resource(lua_message * msg, const char *param, const char *resname) { if (msg->mtype) { int i = mtype_get_param(msg->mtype, param); + const resource_type * rtype; if (i == msg->mtype->nparameters) { return E_INVALID_PARAMETER_NAME; } @@ -79,8 +80,12 @@ int msg_set_resource(lua_message * msg, const char *param, const char *resname) return E_INVALID_PARAMETER_TYPE; } - msg->args[i].v = (void *)rt_find(resname); - + rtype = rt_find(resname); + if (rtype) { + msg->args[i].v = (void *)rtype; + } else { + return E_INVALID_PARAMETER_VALUE; + } return E_OK; } return E_INVALID_MESSAGE; diff --git a/src/bindings/bindings.c b/src/bindings/bindings.c index e12c1756b..444997c19 100644 --- a/src/bindings/bindings.c +++ b/src/bindings/bindings.c @@ -21,6 +21,7 @@ without prior permission by the authors of Eressea. #include #include +#include #include #include #include diff --git a/src/gamecode/creport.c b/src/gamecode/creport.c index 94abc0294..3f7d4fe1d 100644 --- a/src/gamecode/creport.c +++ b/src/gamecode/creport.c @@ -35,6 +35,7 @@ without prior permission by the authors of Eressea. #include #include #include +#include #include #include #include diff --git a/src/gamecode/economy.c b/src/gamecode/economy.c index cc516d784..cd47f880a 100644 --- a/src/gamecode/economy.c +++ b/src/gamecode/economy.c @@ -20,6 +20,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include +#include #include "economy.h" /* gamecode includes */ @@ -33,6 +34,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include +#include #include #include #include diff --git a/src/gamecode/economy_test.c b/src/gamecode/economy_test.c index effe7e4e8..61294b1da 100644 --- a/src/gamecode/economy_test.c +++ b/src/gamecode/economy_test.c @@ -1,4 +1,5 @@ -#include "platform.h" +#include +#include #include "economy.h" #include diff --git a/src/gamecode/give.c b/src/gamecode/give.c index 755b97c26..b9254c7c2 100644 --- a/src/gamecode/give.c +++ b/src/gamecode/give.c @@ -17,6 +17,7 @@ #include "economy.h" /* kernel includes */ +#include #include #include #include diff --git a/src/gamecode/laws.c b/src/gamecode/laws.c index 2f1e0b252..6965a8f7d 100644 --- a/src/gamecode/laws.c +++ b/src/gamecode/laws.c @@ -39,6 +39,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include +#include #include #include #include diff --git a/src/gamecode/market_test.c b/src/gamecode/market_test.c index 7da1963c0..71f9bcf24 100644 --- a/src/gamecode/market_test.c +++ b/src/gamecode/market_test.c @@ -1,4 +1,5 @@ -#include "platform.h" +#include +#include #include "market.h" #include "tests.h" diff --git a/src/gamecode/report.c b/src/gamecode/report.c index 03772de43..2127d2940 100644 --- a/src/gamecode/report.c +++ b/src/gamecode/report.c @@ -42,6 +42,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include +#include #include #include #include diff --git a/src/gamecode/study.c b/src/gamecode/study.c index a25c56a52..2919e8b1f 100644 --- a/src/gamecode/study.c +++ b/src/gamecode/study.c @@ -25,6 +25,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include +#include #include #include #include diff --git a/src/gamecode/xmlreport.c b/src/gamecode/xmlreport.c index 72025e98a..5b93dc887 100644 --- a/src/gamecode/xmlreport.c +++ b/src/gamecode/xmlreport.c @@ -32,6 +32,7 @@ without prior permission by the authors of Eressea. #include #include #include +#include #include #include #include diff --git a/src/items/studypotion.c b/src/items/studypotion.c deleted file mode 100644 index df77793e1..000000000 --- a/src/items/studypotion.c +++ /dev/null @@ -1,59 +0,0 @@ -#include -#include -#include "studypotion.h" - -#include -#include -#include -#include -#include -#include - -#include -#include - -/* BEGIN it_studypotion */ -#define MAXGAIN 15 -static int -use_studypotion(struct unit *u, const struct item_type *itype, int amount, - struct order *ord) -{ - if (get_keyword(u->thisorder) == K_STUDY) { - skill_t sk; - skill *sv; - - init_tokens(u->thisorder); - skip_token(); - sk = findskill(getstrtoken(), u->faction->locale); - sv = get_skill(u, sk); - - if (sv && sv->level > 2) { - /* TODO: message */ - } else if (study_cost(u, sk) > 0) { - /* TODO: message */ - } else { - attrib *a = a_find(u->attribs, &at_learning); - teaching_info *teach; - if (a == NULL) { - a = a_add(&u->attribs, a_new(&at_learning)); - } - teach = (teaching_info *) a->data.v; - if (amount > MAXGAIN) - amount = MAXGAIN; - teach->value += amount * 30; - if (teach->value > MAXGAIN * 30) { - teach->value = MAXGAIN * 30; - } - i_change(&u->items, itype, -amount); - return 0; - } - } - return EUNUSABLE; -} - -void register_studypotion(void) -{ - register_function((pf_generic) use_studypotion, "use_studypotion"); -} - -/* END it_studypotion */ diff --git a/src/items/studypotion.h b/src/items/studypotion.h deleted file mode 100644 index 454f137c2..000000000 --- a/src/items/studypotion.h +++ /dev/null @@ -1,30 +0,0 @@ -/* -Copyright (c) 1998-2010, Enno Rehling - Katja Zedel - -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. -**/ - -#ifndef H_ITM_STUDYPOTION -#define H_ITM_STUDYPOTION -#ifdef __cplusplus -extern "C" { -#endif - - extern void register_studypotion(void); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/src/kernel/equipment.c b/src/kernel/equipment.c index 956cc0626..42c505499 100644 --- a/src/kernel/equipment.c +++ b/src/kernel/equipment.c @@ -83,7 +83,7 @@ void equipment_setskill(equipment * eq, skill_t sk, const char *value) } } -void equipment_addspell(equipment * eq, spell * sp, int level) +void equipment_addspell(equipment * eq, struct spell * sp, int level) { if (eq) { if (!eq->spellbook) { diff --git a/src/kernel/item.c b/src/kernel/item.c index 35d8451a0..c588fbeca 100644 --- a/src/kernel/item.c +++ b/src/kernel/item.c @@ -24,6 +24,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "alchemy.h" #include "build.h" +#include "curse.h" #include "faction.h" #include "message.h" #include "pool.h" diff --git a/src/kernel/magic.h b/src/kernel/magic.h index f896be52d..07ec04772 100644 --- a/src/kernel/magic.h +++ b/src/kernel/magic.h @@ -22,11 +22,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. extern "C" { #endif -#include "curse.h" - struct fighter; - struct building; - struct spellbook; - /* ------------------------------------------------------------- */ #define MAXCOMBATSPELLS 3 /* PRECOMBAT COMBAT POSTCOMBAT */ diff --git a/src/kernel/names.c b/src/kernel/names.c index f50289654..d44c49132 100644 --- a/src/kernel/names.c +++ b/src/kernel/names.c @@ -38,6 +38,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include /* libc includes */ +#include #include #include #include @@ -466,7 +467,7 @@ const char *abkz(const char *s, char *buf, size_t buflen, size_t maxchars) void register_names(void) { register_function((pf_generic) describe_braineater, "describe_braineater"); - /* function name + /* function name * generate a name for a nonplayerunit * race->generate_name() */ register_function((pf_generic) undead_name, "nameundead"); diff --git a/src/kernel/pool_test.c b/src/kernel/pool_test.c index 5e521cff5..38be7aaae 100644 --- a/src/kernel/pool_test.c +++ b/src/kernel/pool_test.c @@ -1,9 +1,11 @@ #include +#include #include "pool.h" #include "unit.h" #include "item.h" #include "region.h" +#include "skill.h" #include #include diff --git a/src/kernel/race.c b/src/kernel/race.c index c89c5fb32..48c8b3a4a 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -50,11 +50,12 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include /* libc includes */ +#include +#include +#include #include #include #include -#include -#include /** external variables **/ race *races; diff --git a/src/kernel/reports_test.c b/src/kernel/reports_test.c index c3ee0c3c1..0bfa47e34 100644 --- a/src/kernel/reports_test.c +++ b/src/kernel/reports_test.c @@ -62,16 +62,16 @@ static void test_regionid(CuTest * tc) { plain = test_create_terrain("plain", 0); r = test_create_region(0, 0, plain); - memset(buffer, 0xff, sizeof(buffer)); + memset(buffer, -2, sizeof(buffer)); len = f_regionid(r, 0, buffer, sizeof(buffer)); CuAssertIntEquals(tc, 11, len); CuAssertStrEquals(tc, "plain (0,0)", buffer); - memset(buffer, -1, sizeof(buffer)); + memset(buffer, -2, sizeof(buffer)); len = f_regionid(r, 0, buffer, 11); CuAssertIntEquals(tc, 10, len); CuAssertStrEquals(tc, "plain (0,0", buffer); - CuAssertIntEquals(tc, -1, buffer[11]); + CuAssertIntEquals(tc, (char)-2, buffer[11]); } CuSuite *get_reports_suite(void) diff --git a/src/kernel/textstore.c b/src/kernel/textstore.c index 0bbbd48c7..643697bf9 100644 --- a/src/kernel/textstore.c +++ b/src/kernel/textstore.c @@ -98,7 +98,7 @@ static void txt_r_tok_buf(struct storage *store, char *result, size_t size) char format[16]; if (result && size > 0) { format[0] = '%'; - sprintf(format + 1, "%us", size); + sprintf(format + 1, "%lus", (unsigned long)size); fscanf((FILE *) store->userdata, format, result); if (result[0] == NULL_TOKEN) { result[0] = 0; diff --git a/src/kernel/types.h b/src/kernel/types.h index ef5ee6013..23cef5f51 100644 --- a/src/kernel/types.h +++ b/src/kernel/types.h @@ -38,6 +38,7 @@ struct attrib_type; struct building; struct building_type; struct curse; +struct curse_type; struct equipment; struct faction; struct fighter; @@ -48,6 +49,7 @@ struct luxury_type; struct order; struct plane; struct potion_type; +struct quicklist; struct race; struct region; struct region_list; diff --git a/src/kernel/unit.c b/src/kernel/unit.c index 585696e3f..c24902076 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -18,12 +18,14 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include +#include #include "unit.h" #include "building.h" #include "faction.h" #include "group.h" #include "connection.h" +#include "curse.h" #include "item.h" #include "move.h" #include "order.h" @@ -1757,4 +1759,4 @@ struct spellbook * unit_get_spellbook(const struct unit * u) } } return 0; -} \ No newline at end of file +} diff --git a/src/modules/autoseed.c b/src/modules/autoseed.c index 18ae8e51a..9a0b5d233 100644 --- a/src/modules/autoseed.c +++ b/src/modules/autoseed.c @@ -40,8 +40,6 @@ #include #include -#include - /* libc includes */ #include #include diff --git a/src/tests.c b/src/tests.c index 2ea35d16e..67df8c8ba 100644 --- a/src/tests.c +++ b/src/tests.c @@ -2,6 +2,7 @@ #include #include +#include #include "tests.h" #include "tests_test.c" diff --git a/src/tests_test.c b/src/tests_test.c index da4db4103..c685d8a50 100644 --- a/src/tests_test.c +++ b/src/tests_test.c @@ -1,7 +1,11 @@ -#include +#include + +#include #include #include +#include + #include static void test_recreate_world(CuTest * tc) diff --git a/src/util/bsdstring.h b/src/util/bsdstring.h index b917baafa..91b89465d 100644 --- a/src/util/bsdstring.h +++ b/src/util/bsdstring.h @@ -1,6 +1,7 @@ #ifndef UTIL_BSDSTRING_H #define UTIL_BSDSTRING_H +#include extern int wrptr(char **ptr, size_t * size, int bytes); #ifndef HAVE_STRLCPY diff --git a/src/util/bsdstring_test.c b/src/util/bsdstring_test.c index 25e7be60d..0f9cdaeac 100644 --- a/src/util/bsdstring_test.c +++ b/src/util/bsdstring_test.c @@ -15,11 +15,11 @@ static void test_strlcat(CuTest * tc) buffer[0] = '\0'; CuAssertIntEquals(tc, 4, strlcat(buffer, "herp", 8)); CuAssertStrEquals(tc, "herp", buffer); - CuAssertIntEquals(tc, -2, buffer[5]); + CuAssertIntEquals(tc, (char)-2, buffer[5]); CuAssertIntEquals(tc, 8, strlcat(buffer, "derp", 8)); CuAssertStrEquals(tc, "herpder", buffer); - CuAssertIntEquals(tc, -2, buffer[8]); + CuAssertIntEquals(tc, (char)-2, buffer[8]); } static void test_strlcpy(CuTest * tc) @@ -33,11 +33,11 @@ static void test_strlcpy(CuTest * tc) CuAssertIntEquals(tc, 4, strlcpy(buffer, "herp", 8)); CuAssertStrEquals(tc, "herp", buffer); - CuAssertIntEquals(tc, -2, buffer[5]); + CuAssertIntEquals(tc, (char)-2, buffer[5]); CuAssertIntEquals(tc, 8, strlcpy(buffer, "herpderp", 8)); CuAssertStrEquals(tc, "herpder", buffer); - CuAssertIntEquals(tc, -2, buffer[8]); + CuAssertIntEquals(tc, (char)-2, buffer[8]); } static void test_slprintf(CuTest * tc) @@ -51,11 +51,11 @@ static void test_slprintf(CuTest * tc) CuAssertIntEquals(tc, 4, slprintf(buffer, 8, "%s", "herp")); CuAssertStrEquals(tc, "herp", buffer); - CuAssertIntEquals(tc, -2, buffer[5]); + CuAssertIntEquals(tc, (char)-2, buffer[5]); CuAssertIntEquals(tc, 8, slprintf(buffer, 8, "%s", "herpderp")); CuAssertStrEquals(tc, "herpder", buffer); - CuAssertIntEquals(tc, -2, buffer[8]); + CuAssertIntEquals(tc, (char)-2, buffer[8]); } CuSuite *get_bsdstring_suite(void) diff --git a/src/util/graph.c b/src/util/graph.c deleted file mode 100644 index ec234aebf..000000000 --- a/src/util/graph.c +++ /dev/null @@ -1,193 +0,0 @@ -/* vi: set ts=2: - +-------------------+ Christian Schlittchen - | | Enno Rehling - | Eressea PBEM host | Katja Zedel - | (c) 1998 - 2003 | Henning Peters - | | Ingo Wilken - +-------------------+ Stefan Reich - - This program may not be used, modified or distributed - without prior permission by the authors of Eressea. - */ - -/* This is a very simple graph library. It is not optimized in any - way, and relies heavily on the vset and stack routines. */ - -#include -#include "vset.h" -#include "graph.h" - -void graph_init(graph * g) -{ - vset_init(&g->nodes); - vset_init(&g->edges); -} - -void graph_free(graph * g) -{ - vset_destroy(&g->nodes); - vset_destroy(&g->edges); -} - -void graph_add_node(graph * g, node * n) -{ - vset_add(&g->nodes, n); -} - -void graph_add_edge(graph * g, edge * v) -{ - vset_add(&g->nodes, v); -} - -void graph_remove_node(graph * g, node * n) -{ - unsigned int i; - - for (i = 0; i != g->edges.size; ++i) { - edge *v = g->edges.data[i]; - if (v->node1 == n || v->node2 == n) { - vset_erase(&g->nodes, v); - i--; - } - } - vset_erase(&g->nodes, n); -} - -node *graph_find_node(graph * g, void *object) -{ - unsigned int i; - - for (i = 0; i != g->nodes.size; ++i) { - node *node = g->nodes.data[i]; - if (node->object == object) { - return g->nodes.data[i]; - } - } - return NULL; -} - -/* The vset returned has to freed externally, else this will be a - memory leak. */ - -vset *graph_neighbours(graph * g, node * n) -{ - unsigned int i; - vset *vs = malloc(sizeof(vs)); - vset_init(vs); - for (i = 0; i != g->edges.size; ++i) { - edge *v = g->edges.data[i]; - if (v->node1 == n && vset_count(vs, v->node2) == 0) { - vset_add(vs, v->node2); - } else if (v->node2 == n && vset_count(vs, v->node1) == 0) { - vset_add(vs, v->node1); - } - } - - return vs; -} - -void graph_resetmarkers(graph * g) -{ - unsigned int i; - - for (i = 0; i != g->nodes.size; ++i) { - node *node = g->nodes.data[i]; - node->marker = 0; - } - for (i = 0; i != g->edges.size; ++i) { - edge *edge = g->edges.data[i]; - edge->marker = 0; - } -} - -/* The vset returned has to freed externally, else this will be a - memory leak. */ - -vset *graph_connected_nodes(graph * g, node * n) -{ - vset *vs = malloc(sizeof(vset)); - vset s; - - vset_init(vs); - vset_init(&s); - graph_resetmarkers(g); - vset_add(vs, n); - n->marker = 1; - vset_add(&s, n); - while (s.size > 0) { - node *n = vset_pop(&s); - vset *vs_nb = graph_neighbours(g, n); - unsigned int i; - for (i = 0; i != vs_nb->size; ++i) { - node *nb = vs_nb->data[i]; - if (nb->marker == 0) { - nb->marker = 1; - vset_add(vs, nb); - vset_add(&s, nb); - } - } - vset_destroy(vs_nb); - free(vs_nb); - } - - vset_destroy(&s); - - return vs; -} - -/* The vset returned has to freed externally, else this will be a - memory leak. */ - -vset *graph_disjunct_graphs(graph * g) -{ - vset *dg = malloc(sizeof(vset)); - vset nodes; - - vset_init(dg); - vset_init(&nodes); - vset_concat(&nodes, &g->nodes); - - while (nodes.size > 0) { - graph *gt = malloc(sizeof(graph)); - vset s; - unsigned int i; - node *start; - - graph_init(gt); - start = vset_pop(&nodes); - graph_resetmarkers(g); - graph_add_node(gt, start); - start->marker = 1; - vset_init(&s); - vset_add(&s, start); - while (s.size > 0) { - vset *nbs = graph_neighbours(g, vset_pop(&s)); - for (i = 0; i != nbs->size; ++i) { - node *nb = nbs->data[i]; - if (nb->marker == 0) { - nb->marker = 1; - graph_add_node(gt, nb); - vset_erase(&nodes, nb); - vset_add(&s, nb); - } - } - vset_destroy(nbs); - free(nbs); - } - - vset_destroy(&s); - - for (i = 0; i != g->edges.size; ++i) { - edge *v = g->edges.data[i]; - if (vset_count(&g->nodes, v->node1)) { - graph_add_edge(gt, v); - } - } - - vset_add(dg, gt); - } - - vset_destroy(&nodes); - - return dg; -} diff --git a/src/util/graph.h b/src/util/graph.h deleted file mode 100644 index 19303acc8..000000000 --- a/src/util/graph.h +++ /dev/null @@ -1,38 +0,0 @@ -/* vi: set ts=2: - +-------------------+ Christian Schlittchen - | | Enno Rehling - | Eressea PBEM host | Katja Zedel - | (c) 1998 - 2003 | Henning Peters - | | Ingo Wilken - +-------------------+ Stefan Reich - - This program may not be used, modified or distributed - without prior permission by the authors of Eressea. - */ - -#ifndef GRAPH_H -#define GRAPH_H -#ifdef __cplusplus -extern "C" { -#endif - - typedef struct node { - int marker; - void *object; - } node; - - typedef struct edge { - int marker; - node *node1; - node *node2; - } edge; - - typedef struct graph { - vset nodes; - vset edges; - } graph; - -#ifdef __cplusplus -} -#endif -#endif diff --git a/src/util/log.c b/src/util/log.c index 48155cde3..40222bdd8 100644 --- a/src/util/log.c +++ b/src/util/log.c @@ -6,13 +6,14 @@ | | Ingo Wilken +-------------------+ Stefan Reich -This program may not be used, modified or distributed +This program may not be used, modified or distributed without prior permission by the authors of Eressea. */ #include #include "log.h" #include "unicode.h" +#include #include #include #include @@ -154,7 +155,7 @@ static void _log_write(FILE * stream, int codepage, const char * prefix, const c if (codepage) { char buffer[MAXLENGTH]; char converted[MAXLENGTH]; - + vsnprintf(buffer, sizeof(buffer), format, args); if (cp_convert(buffer, converted, MAXLENGTH, codepage) == 0) { fputs(converted, stream); @@ -308,4 +309,3 @@ void log_printf(FILE * io, const char *format, ...) log_flush(); } } -