Merge pull request #810 from ennorehling/develop

Integrate new parser library separation progress
This commit is contained in:
Enno Rehling 2018-10-06 21:35:15 +02:00 committed by GitHub
commit 0b2292c98f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
180 changed files with 1618 additions and 937 deletions

1
.gitignore vendored
View File

@ -36,6 +36,7 @@ Thumbs.db
*.cfg
*.cmd
tmp/
tests/orders.txt
tests/config.lua
tests/reports/
tests/data/185.dat

View File

@ -8,6 +8,7 @@ addons:
apt:
packages:
- libbsd-dev
- libdb-dev
- liblua5.1-dev
- libtolua-dev
- libncurses5-dev

View File

@ -31,8 +31,8 @@ cppcheck_tests() {
set -e
[ -z $BUILD ] && BUILD=Debug ; export BUILD
s/cmake-init
# cppcheck_tests
s/cmake-init --db=sqlite
s/build
cd process
make

View File

@ -85,6 +85,11 @@ TOLUA_BINDING(eressea.pkg bind_eressea.h)
TOLUA_BINDING(settings.pkg kenel/config.h)
ENDIF()
set (PARSER_SRC
${DB_SRC}
${UTIL_SRC}
)
set (ERESSEA_SRC
vortex.c
academy.c
@ -104,7 +109,6 @@ set (ERESSEA_SRC
items.c
json.c
jsonconf.c
keyword.c
laws.c
lighthouse.c
magic.c
@ -113,6 +117,7 @@ set (ERESSEA_SRC
morale.c
move.c
names.c
orderdb.c
orderfile.c
piracy.c
prefix.c
@ -138,9 +143,11 @@ set (ERESSEA_SRC
${TRIGGERS_SRC}
${ATTRIBUTES_SRC}
${KERNEL_SRC}
${DB_SRC}
${UTIL_SRC}
)
)
set(CHECK_SRC
checker.c
)
set(SERVER_SRC
bind_building.c
@ -161,7 +168,7 @@ set(SERVER_SRC
console.c
helpers.c
main.c
)
)
if (CURSES_FOUND)
set (SERVER_SRC ${SERVER_SRC}
@ -176,24 +183,29 @@ if(NOT IWYU_PATH)
message(STATUS "Could not find the program include-what-you-use")
endif()
add_library(version STATIC ${VERSION_SRC})
add_library(game ${ERESSEA_SRC})
add_library(parser ${PARSER_SRC})
target_link_libraries(parser
${CLIBS_LIBRARIES}
${CRYPTO_LIBRARIES}
)
#add_executable(checker ${CHECK_SRC})
add_executable(checker ${CHECK_SRC})
target_link_libraries(checker parser)
add_library(game ${ERESSEA_SRC})
target_link_libraries(game parser version)
add_executable(eressea ${SERVER_SRC})
if (IWYU_PATH)
set_property(TARGET eressea PROPERTY C_INCLUDE_WHAT_YOU_USE ${IWYU_PATH})
endif(IWYU_PATH)
target_link_libraries(game version)
target_link_libraries(eressea
game
${TOLUA_LIBRARIES}
${LUA_LIBRARIES}
${STORAGE_LIBRARIES}
${CLIBS_LIBRARIES}
${CRYPTO_LIBRARIES}
${CJSON_LIBRARIES}
${INIPARSER_LIBRARIES}
)
@ -211,7 +223,6 @@ set(TESTS_SRC
guard.test.c
json.test.c
jsonconf.test.c
keyword.test.c
laws.test.c
lighthouse.test.c
magic.test.c
@ -219,6 +230,7 @@ set(TESTS_SRC
monsters.test.c
move.test.c
names.test.c
orderdb.test.c
orderfile.test.c
piracy.test.c
prefix.test.c
@ -254,7 +266,6 @@ target_link_libraries(test_eressea
${LUA_LIBRARIES}
${CLIBS_LIBRARIES}
${STORAGE_LIBRARIES}
${CRYPTO_LIBRARIES}
${CJSON_LIBRARIES}
${INIPARSER_LIBRARIES}
)
@ -286,8 +297,7 @@ if (HAVE_STRDUP)
endif(HAVE_STRDUP)
if (HAVE_LIBBSD)
target_link_libraries(test_eressea bsd)
target_link_libraries(eressea bsd)
target_link_libraries(parser bsd)
endif (HAVE_LIBBSD)
if (SQLITE3_FOUND)

View File

@ -33,8 +33,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/unit.h>
/* util includes */
#include <util/attrib.h>
#include <util/gamedata.h>
#include <kernel/attrib.h>
#include <kernel/gamedata.h>
#include <util/base36.h>
#include <util/log.h>
#include <util/macros.h>

View File

@ -53,9 +53,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/building.h>
/* util includes */
#include <util/attrib.h>
#include <util/event.h>
#include <util/gamedata.h>
#include <kernel/attrib.h>
#include <kernel/event.h>
#include <kernel/gamedata.h>
#include <util/macros.h>
#include <util/resolve.h>

View File

@ -29,10 +29,10 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/unit.h>
/* util includes */
#include <util/attrib.h>
#include <kernel/attrib.h>
#include <util/base36.h>
#include <util/log.h>
#include <util/gamedata.h>
#include <kernel/gamedata.h>
#include <util/resolve.h>
#include <util/strings.h>

View File

@ -22,8 +22,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/config.h>
#include <kernel/unit.h>
#include <util/attrib.h>
#include <util/gamedata.h>
#include <kernel/attrib.h>
#include <kernel/gamedata.h>
#include <util/variant.h>
#include <storage.h>

View File

@ -22,8 +22,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/unit.h>
#include <util/attrib.h>
#include <util/gamedata.h>
#include <kernel/attrib.h>
#include <kernel/gamedata.h>
#include <util/macros.h>
#include <util/resolve.h>

View File

@ -20,7 +20,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/config.h>
#include "iceberg.h"
#include <util/attrib.h>
#include <kernel/attrib.h>
attrib_type at_iceberg = {
"iceberg_drift",

View File

@ -20,8 +20,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/config.h>
#include "key.h"
#include <util/attrib.h>
#include <util/gamedata.h>
#include <kernel/attrib.h>
#include <kernel/gamedata.h>
#include <util/log.h>
#include <storage.h>

View File

@ -2,7 +2,7 @@
#include "key.h"
#include "dict.h"
#include <util/attrib.h>
#include <kernel/attrib.h>
#include <util/base36.h>
#include <CuTest.h>
#include <stdlib.h>

View File

@ -20,8 +20,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/config.h>
#include "movement.h"
#include <util/attrib.h>
#include <util/gamedata.h>
#include <kernel/attrib.h>
#include <kernel/gamedata.h>
#include <util/macros.h>
#include <storage.h>

View File

@ -23,8 +23,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/ally.h>
#include <kernel/faction.h>
#include <kernel/unit.h>
#include <util/attrib.h>
#include <util/gamedata.h>
#include <kernel/attrib.h>
#include <kernel/gamedata.h>
#include <storage.h>
#include <assert.h>

View File

@ -7,7 +7,7 @@
#include <kernel/region.h>
#include <kernel/faction.h>
#include <util/attrib.h>
#include <kernel/attrib.h>
#include <CuTest.h>
#include <tests.h>

View File

@ -20,7 +20,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/config.h>
#include "overrideroads.h"
#include <util/attrib.h>
#include <kernel/attrib.h>
attrib_type at_overrideroads = {
"roads_override", NULL, NULL, NULL, a_writestring, a_readstring

View File

@ -20,7 +20,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/config.h>
#include "racename.h"
#include <util/attrib.h>
#include <kernel/attrib.h>
#include <util/strings.h>
/* libc includes */

View File

@ -20,7 +20,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/config.h>
#include "raceprefix.h"
#include <util/attrib.h>
#include <kernel/attrib.h>
#include <util/strings.h>
#include <assert.h>

View File

@ -22,7 +22,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/region.h>
#include <kernel/messages.h>
#include <util/message.h>
#include <util/attrib.h>
#include <kernel/attrib.h>
#include <assert.h>
static int age_reduceproduction(attrib * a, void *owner)

View File

@ -23,8 +23,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/faction.h>
#include <kernel/spell.h>
#include <kernel/spellbook.h>
#include <util/attrib.h>
#include <util/gamedata.h>
#include <kernel/attrib.h>
#include <kernel/gamedata.h>
#include <util/log.h>
#include <util/macros.h>

View File

@ -1,7 +1,7 @@
#include <platform.h>
#include <kernel/unit.h>
#include <kernel/region.h>
#include <util/attrib.h>
#include <kernel/attrib.h>
#include <attributes/stealth.h>
#include <stdlib.h>

View File

@ -22,8 +22,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/config.h>
#include <kernel/region.h>
#include <util/attrib.h>
#include <util/gamedata.h>
#include <kernel/attrib.h>
#include <kernel/gamedata.h>
#include <util/resolve.h>
#include <storage.h>

View File

@ -6,10 +6,10 @@
#include "kernel/region.h"
#include "kernel/unit.h"
#include "util/keyword.h"
#include "util/log.h"
#include "automate.h"
#include "keyword.h"
#include "laws.h"
#include "study.h"

View File

@ -60,7 +60,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* util includes */
#include <util/assert.h>
#include <util/attrib.h>
#include <kernel/attrib.h>
#include <util/base36.h>
#include <util/language.h>
#include <util/lists.h>

View File

@ -3,7 +3,6 @@
#include "battle.h"
#include "guard.h"
#include "keyword.h"
#include "reports.h"
#include "skill.h"
@ -22,6 +21,7 @@
#include <util/base36.h>
#include <util/functions.h>
#include "util/keyword.h"
#include <util/language.h>
#include <util/message.h>
#include <util/rand.h>

View File

@ -12,6 +12,7 @@
#include <kernel/save.h>
#include <util/language.h>
#include <util/log.h>
#include <stream.h>
#include <stdio.h>
@ -21,7 +22,7 @@
void eressea_free_game(void) {
free_gamedata();
init_resources();
init_locales();
init_locales(init_locale);
}
int eressea_read_game(const char * filename) {
@ -34,7 +35,13 @@ int eressea_write_game(const char * filename) {
}
int eressea_read_orders(const char * filename) {
return readorders(filename);
FILE * F = fopen(filename, "r");
if (!F) {
perror(filename);
return -1;
}
log_info("reading orders from %s", filename);
return parseorders(F);
}
int eressea_export_json(const char * filename, int flags) {

View File

@ -4,20 +4,22 @@
#include "bind_process.h"
#include "battle.h"
#include "economy.h"
#include "laws.h"
#include "magic.h"
#include "market.h"
#include "move.h"
#include "study.h"
#include <kernel/alliance.h>
#include <kernel/config.h>
#include <kernel/order.h>
#include <kernel/region.h>
#include <kernel/terrain.h>
#include <kernel/unit.h>
#include "battle.h"
#include "economy.h"
#include "keyword.h"
#include "laws.h"
#include "magic.h"
#include "market.h"
#include "move.h"
#include "study.h"
#include "util/keyword.h"
#define PROC_LAND_REGION 0x0001
#define PROC_LONG_ORDER 0x0002

View File

@ -22,7 +22,7 @@
#include <kernel/terrain.h>
#include <kernel/messages.h>
#include <util/attrib.h>
#include <kernel/attrib.h>
#include <util/base36.h>
#include <util/log.h>
#include <util/macros.h>

View File

@ -14,7 +14,7 @@
#include <kernel/ship.h>
#include <kernel/build.h>
#include <util/attrib.h>
#include <kernel/attrib.h>
#include <util/language.h>
#include <util/log.h>
#include <util/macros.h>

View File

@ -6,7 +6,7 @@
#include <kernel/save.h>
#include <util/gamedata.h>
#include <kernel/gamedata.h>
#include <util/log.h>
#include <util/macros.h>

View File

@ -11,9 +11,9 @@
#include "skill.h"
/* util includes */
#include <util/attrib.h>
#include <kernel/attrib.h>
#include <util/base36.h>
#include <util/event.h>
#include <kernel/event.h>
#include <util/log.h>
#include <util/macros.h>
#include "util/variant.h"

View File

@ -47,7 +47,7 @@
#include <modules/score.h>
#include <util/attrib.h>
#include <kernel/attrib.h>
#include <util/base36.h>
#include <util/language.h>
#include <util/log.h>

View File

@ -34,7 +34,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/terrainid.h>
#include <kernel/unit.h>
#include <util/attrib.h>
#include <kernel/attrib.h>
#include <util/rng.h>
#include <stdlib.h>

92
src/checker.c Normal file
View File

@ -0,0 +1,92 @@
#ifdef _MSV_VER
#include <platform.h>
#endif
#include "util/order_parser.h"
#include "util/keyword.h"
#include "util/language.h"
#include "util/path.h"
#include "util/pofile.h"
#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include <string.h>
typedef struct parser_state {
FILE * F;
} parser_state;
static void handle_order(void *userData, const char *str) {
parser_state * state = (parser_state*)userData;
fputs(str, state->F);
fputc('\n', state->F);
}
int parsefile(FILE *F) {
OP_Parser parser;
char buf[1024];
int done = 0, err = 0;
parser_state state = { NULL };
state.F = stdout;
parser = OP_ParserCreate();
OP_SetOrderHandler(parser, handle_order);
OP_SetUserData(parser, &state);
while (!done) {
size_t len = (int)fread(buf, 1, sizeof(buf), F);
if (ferror(F)) {
/* TODO: error message */
err = errno;
break;
}
done = feof(F);
if (OP_Parse(parser, buf, len, done) == OP_STATUS_ERROR) {
/* TODO: error message */
err = (int)OP_GetErrorCode(parser);
break;
}
}
OP_ParserFree(parser);
return err;
}
static int handle_po(const char *msgid, const char *msgstr, const char *msgctxt, void *data) {
struct locale *lang = (struct locale *)data;
if (msgctxt) {
if (strcmp(msgctxt, "keyword") == 0) {
keyword_t kwd = findkeyword(msgid);
init_keyword(lang, kwd, msgstr);
locale_setstring(lang, mkname("keyword", keywords[kwd]), msgstr);
}
}
return 0;
}
static void read_config(const char *respath) {
char path[PATH_MAX];
struct locale *lang;
lang = get_or_create_locale("de");
path_join(respath, "translations/strings.de.po", path, sizeof(path));
pofile_read(path, handle_po, lang);
}
int main(int argc, char **argv) {
FILE * F = stdin;
if (argc > 1) {
const char *filename = argv[1];
F = fopen(filename, "r");
if (!F) {
perror(filename);
return -1;
}
}
read_config("../git");
parsefile(F);
if (F != stdin) {
fclose(F);
}
return 0;
}

View File

@ -64,7 +64,7 @@ without prior permission by the authors of Eressea.
#include "kernel/unit.h"
/* util includes */
#include <util/attrib.h>
#include <kernel/attrib.h>
#include <util/base36.h>
#include <util/crmessage.h>
#include <util/strings.h>

View File

@ -3,7 +3,6 @@
#include "move.h"
#include "spy.h"
#include "travelthru.h"
#include "keyword.h"
#include <kernel/ally.h>
#include <kernel/building.h>
@ -17,6 +16,7 @@
#include <kernel/spell.h>
#include <kernel/spellbook.h>
#include "util/keyword.h"
#include <util/language.h>
#include <util/lists.h>
#include <util/message.h>

View File

@ -20,7 +20,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#ifdef _MSC_VER
#include <platform.h>
#endif
#include <kernel/config.h>
#include "economy.h"
#include "alchemy.h"
@ -45,10 +45,13 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* kernel includes */
#include "kernel/ally.h"
#include "kernel/attrib.h"
#include "kernel/building.h"
#include "kernel/calendar.h"
#include "kernel/config.h"
#include "kernel/curse.h"
#include "kernel/equipment.h"
#include "kernel/event.h"
#include "kernel/faction.h"
#include "kernel/item.h"
#include "kernel/messages.h"
@ -64,13 +67,12 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "kernel/unit.h"
/* util includes */
#include <util/attrib.h>
#include <util/base36.h>
#include <util/event.h>
#include <util/goodies.h>
#include <util/language.h>
#include <util/lists.h>
#include <util/log.h>
#include "util/param.h"
#include <util/parser.h>
#include <util/rng.h>

View File

@ -19,7 +19,7 @@
#include <kernel/terrainid.h>
#include <kernel/unit.h>
#include <util/attrib.h>
#include <kernel/attrib.h>
#include <util/language.h>
#include <util/macros.h>

View File

@ -1,14 +1,13 @@
#include <platform.h>
#include "eressea.h"
#include "kernel/building.h"
#include "kernel/calendar.h"
#include "kernel/config.h"
#include "kernel/curse.h"
#include "kernel/faction.h"
#include "kernel/building.h"
#include "kernel/equipment.h"
#include "kernel/faction.h"
#include "kernel/item.h"
#include "kernel/database.h"
#include "util/functions.h"
#include "util/language.h"
@ -28,6 +27,7 @@
#include "creport.h"
#include "report.h"
#include "names.h"
#include "orderdb.h"
#include "reports.h"
#include "spells.h"
#include "vortex.h"
@ -54,12 +54,12 @@ void game_done(void)
free_locales();
#endif
kernel_done();
dblib_close();
orderdb_close();
}
void game_init(void)
{
dblib_open();
orderdb_open();
errno = 0;
kernel_init();
register_triggers();

View File

@ -6,7 +6,6 @@
#include "kernel/config.h"
#include "kernel/calendar.h"
#include "kernel/database.h"
#include "kernel/faction.h"
#include "kernel/db/driver.h"
@ -21,7 +20,7 @@ int gamedb_update(void)
err = db_driver_open(DB_GAME, dbname);
if (err == 0) {
for (f = factions; f; f = f->next) {
int uid = dblib_save_faction(f, turn);
int uid = db_driver_faction_save(f->uid, f->no, turn, f->email, f->_password);
if (uid > 0) {
f->uid = uid;
}

View File

@ -25,6 +25,8 @@
#include <attributes/racename.h>
/* kernel includes */
#include <kernel/attrib.h>
#include <kernel/event.h>
#include <kernel/ally.h>
#include <kernel/build.h>
#include <kernel/curse.h>
@ -41,11 +43,10 @@
#include <kernel/unit.h>
/* util includes */
#include <util/attrib.h>
#include <util/base36.h>
#include <util/event.h>
#include <util/log.h>
#include <util/macros.h>
#include <util/param.h>
#include <util/parser.h>
/* libc includes */

View File

@ -16,6 +16,7 @@
#include <util/base36.h>
#include <util/language.h>
#include <util/message.h>
#include <util/param.h>
#include <CuTest.h>
#include <tests.h>

View File

@ -30,7 +30,7 @@
#include "kernel/ship.h"
#include "kernel/terrain.h"
#include <util/attrib.h>
#include <kernel/attrib.h>
#include <util/base36.h>
#include <util/lists.h>
#include <util/macros.h>

View File

@ -19,10 +19,10 @@ without prior permission by the authors of Eressea.
#include "alchemy.h"
#include "magic.h"
#include <util/attrib.h>
#include <util/event.h>
#include <kernel/attrib.h>
#include <kernel/event.h>
#include <util/functions.h>
#include <util/gamedata.h>
#include <kernel/gamedata.h>
#include <util/log.h>
#include <util/macros.h>
#include <util/parser.h>

View File

@ -5,7 +5,6 @@
#include "alchemy.h"
#include "skill.h"
#include "keyword.h"
#include "direction.h"
#include "study.h"
#include "economy.h"
@ -33,8 +32,9 @@
#include <triggers/changerace.h>
#include <triggers/timeout.h>
#include <util/attrib.h>
#include <util/event.h>
#include <kernel/attrib.h>
#include <kernel/event.h>
#include <util/keyword.h>
#include <util/macros.h>
#include <util/parser.h>
#include <util/rand.h>

View File

@ -31,7 +31,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <attributes/movement.h>
/* util includes */
#include <util/attrib.h>
#include <kernel/attrib.h>
#include <util/log.h>
#include <util/macros.h>

View File

@ -29,9 +29,10 @@ without prior permission by the authors of Eressea.
#include "kernel/spellbook.h"
/* util includes */
#include "util/attrib.h"
#include "kernel/attrib.h"
#include "util/crmessage.h"
#include "util/functions.h"
#include "util/keyword.h"
#include "util/language.h"
#include "util/log.h"
#include "util/message.h"
@ -42,7 +43,6 @@ without prior permission by the authors of Eressea.
/* game modules */
#include "direction.h"
#include "keyword.h"
#include "move.h"
#include "prefix.h"
#include "skill.h"

View File

@ -15,11 +15,11 @@
#include "kernel/order.h"
#include "kernel/terrain.h"
#include "util/keyword.h"
#include "util/language.h"
#include "kernel/calendar.h"
#include "direction.h"
#include "keyword.h"
#include "move.h"
#include "prefix.h"

View File

@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 2.6)
project(kernel C)
SET(_DBFILES db/critbit.c)
SET(_DBFILES db/memory.c)
IF(SQLITE3_FOUND)
SET(_DBFILES db/sqlite.c)
@ -12,6 +12,7 @@ ENDIF(SQLITE3_FOUND)
SET(_TEST_FILES
alliance.test.c
ally.test.c
attrib.test.c
build.test.c
building.test.c
# callbacks.test.c
@ -22,12 +23,13 @@ config.test.c
curse.test.c
database.test.c
equipment.test.c
# event.test.c
faction.test.c
gamedata.test.c
group.test.c
item.test.c
messages.test.c
order.test.c
orderdb.test.c
# pathfinder.test.c
plane.test.c
pool.test.c
@ -47,6 +49,7 @@ SET(_FILES
${_DBFILES}
alliance.c
ally.c
attrib.c
build.c
building.c
callbacks.c
@ -55,14 +58,14 @@ command.c
config.c
connection.c
curse.c
database.c
equipment.c
event.c
faction.c
gamedata.c
group.c
item.c
messages.c
order.c
orderdb.c
pathfinder.c
plane.c
pool.c

View File

@ -27,7 +27,7 @@ without prior permission by the authors of Eressea.
#include <attributes/key.h>
/* util includes */
#include <util/attrib.h>
#include <kernel/attrib.h>
#include <util/base36.h>
#include <util/language.h>
#include <util/parser.h>

View File

@ -10,9 +10,9 @@
#include "objtypes.h"
#include "plane.h"
#include <util/attrib.h>
#include <kernel/attrib.h>
#include <util/strings.h>
#include <util/gamedata.h>
#include <kernel/gamedata.h>
#include <storage.h>

View File

@ -19,12 +19,12 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <platform.h>
#include "attrib.h"
#include "gamedata.h"
#include "log.h"
#include "variant.h"
#include "storage.h"
#include "strings.h"
#include <util/log.h>
#include <util/strings.h>
#include <util/variant.h>
#include <kernel/gamedata.h>
#include <storage.h>
#include <critbit.h>
#include <assert.h>

View File

@ -20,7 +20,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#define ATTRIB_H
#include <stdbool.h>
#include "variant.h"
#include <util/variant.h>
#ifdef __cplusplus
extern "C" {
#endif

View File

@ -1,7 +1,7 @@
#include <platform.h>
#include "attrib.h"
#include <util/gamedata.h>
#include <kernel/gamedata.h>
#include <util/strings.h>
#include <storage.h>

View File

@ -33,10 +33,12 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* kernel includes */
#include <kernel/ally.h>
#include <kernel/alliance.h>
#include <kernel/connection.h>
#include <kernel/attrib.h>
#include <kernel/building.h>
#include <kernel/config.h>
#include <kernel/connection.h>
#include <kernel/curse.h>
#include <kernel/event.h>
#include <kernel/faction.h>
#include <kernel/group.h>
#include <kernel/item.h>
@ -52,12 +54,11 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/unit.h>
/* from libutil */
#include <util/attrib.h>
#include <util/base36.h>
#include <util/event.h>
#include <util/goodies.h>
#include <util/language.h>
#include <util/log.h>
#include <util/param.h>
#include <util/parser.h>
#include <util/resolve.h>
@ -79,7 +80,7 @@ struct building *getbuilding(const struct region *r)
ship *getship(const struct region * r)
{
ship *sh, *sx = findship(getshipid());
ship *sh, *sx = findship(getid());
for (sh = r->ships; sh; sh = sh->next) {
if (sh == sx)
return sh;

View File

@ -1,19 +1,24 @@
#ifdef _MSC_VER
#include <platform.h>
#include <kernel/config.h>
#endif
#include <kernel/messages.h>
#include "alchemy.h"
#include "types.h"
#include "build.h"
#include "guard.h"
#include "order.h"
#include "unit.h"
#include "building.h"
#include "config.h"
#include "faction.h"
#include "region.h"
#include "race.h"
#include "guard.h"
#include "item.h"
#include <util/language.h>
#include "messages.h"
#include "order.h"
#include "race.h"
#include "region.h"
#include "types.h"
#include "unit.h"
#include "util/language.h"
#include "util/param.h"
#include <CuTest.h>
#include <tests.h>

View File

@ -38,13 +38,14 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "lighthouse.h"
/* util includes */
#include <util/attrib.h>
#include <kernel/attrib.h>
#include <util/base36.h>
#include <util/event.h>
#include <kernel/event.h>
#include <util/functions.h>
#include <util/gamedata.h>
#include <kernel/gamedata.h>
#include <util/language.h>
#include <util/log.h>
#include <util/param.h>
#include <util/resolve.h>
#include <util/strings.h>
#include <util/umlaut.h>
@ -128,14 +129,6 @@ static void free_buildingtype(void *ptr) {
free(btype);
}
void free_buildingtypes(void) {
cb_clear(&cb_bldgtypes);
selist_foreach(buildingtypes, free_buildingtype);
selist_free(buildingtypes);
buildingtypes = 0;
++bt_changes;
}
building_type *bt_get_or_create(const char *name)
{
assert(name && name[0]);
@ -264,17 +257,28 @@ building *findbuilding(int i)
static local_names *bnames;
/* Find the building type for a given localized name (as seen by the user). Useful for parsing
* orders. The inverse of locale_string(lang, btype->_name), sort of. */
const building_type *findbuildingtype(const char *name,
const struct locale *lang)
{
variant type;
local_names *bn = bnames;
static void free_bnames(void) {
while (bnames) {
local_names *bn = bnames;
bnames = bnames->next;
freetokens(bn->names);
free(bn);
}
}
static local_names *get_bnames(const struct locale *lang)
{
static int config;
local_names *bn;
if (bt_changed(&config)) {
free_bnames();
}
bn = bnames;
while (bn) {
if (bn->lang == lang)
if (bn->lang == lang) {
break;
}
bn = bn->next;
}
if (!bn) {
@ -291,14 +295,26 @@ const building_type *findbuildingtype(const char *name,
const char *n = LOC(lang, btype->_name);
if (!n) {
log_error("building type %s has no translation in %s",
btype->_name, locale_name(lang));
} else {
btype->_name, locale_name(lang));
}
else {
variant type;
type.v = (void *)btype;
addtoken((struct tnode **)&bn->names, n, type);
}
}
bnames = bn;
}
return bn;
}
/* Find the building type for a given localized name (as seen by the user). Useful for parsing
* orders. The inverse of locale_string(lang, btype->_name), sort of. */
const building_type *findbuildingtype(const char *name,
const struct locale *lang)
{
variant type;
local_names *bn = get_bnames(lang);
if (findtoken(bn->names, name, &type) == E_TOK_NOMATCH)
return NULL;
return (const building_type *)type.v;
@ -870,3 +886,12 @@ int cmp_current_owner(const building * b, const building * a)
}
return 0;
}
void free_buildingtypes(void) {
free_bnames();
cb_clear(&cb_bldgtypes);
selist_foreach(buildingtypes, free_buildingtype);
selist_free(buildingtypes);
buildingtypes = 0;
++bt_changes;
}

View File

@ -33,7 +33,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "faction.h"
#include "group.h"
#include "item.h"
#include "keyword.h"
#include "messages.h"
#include "move.h"
#include "objtypes.h"
@ -50,15 +49,18 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "unit.h"
/* util includes */
#include <util/attrib.h>
#include <kernel/attrib.h>
#include <kernel/event.h>
#include <util/base36.h>
#include <util/crmessage.h>
#include <util/event.h>
#include <util/keyword.h>
#include <util/language.h>
#include <util/functions.h>
#include <util/log.h>
#include <util/lists.h>
#include <util/macros.h>
#include <util/param.h>
#include <util/parser.h>
#include <util/path.h>
#include <util/rand.h>
@ -91,54 +93,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#endif
struct settings global;
const char *parameters[MAXPARAMS] = {
"LOCALE",
"ALLES",
"JEDEM",
"BAUERN",
"BURG",
"EINHEIT",
"PRIVAT",
"HINTEN",
"KOMMANDO",
"KRAEUTER",
"NICHT",
"NAECHSTER",
"PARTEI",
"ERESSEA",
"PERSONEN",
"REGION",
"SCHIFF",
"SILBER",
"STRASSEN",
"TEMP",
"FLIEHE",
"GEBAEUDE",
"GIB", /* HELFE GIB */
"KAEMPFE",
"DURCHREISE",
"BEWACHE",
"ZAUBER",
"PAUSE",
"VORNE",
"AGGRESSIV",
"DEFENSIV",
"STUFE",
"HELFE",
"FREMDES",
"AURA",
"HINTER",
"VOR",
"ANZAHL",
"GEGENSTAENDE",
"TRAENKE",
"GRUPPE",
"PARTEITARNUNG",
"BAEUME",
"ALLIANZ",
"AUTO"
};
int findoption(const char *s, const struct locale *lang)
{
void **tokens = get_translations(lang, UT_OPTIONS);
@ -150,78 +104,6 @@ int findoption(const char *s, const struct locale *lang)
return NODIRECTION;
}
param_t findparam(const char *s, const struct locale * lang)
{
param_t result = NOPARAM;
char buffer[64];
char * str = s ? transliterate(buffer, sizeof(buffer) - sizeof(int), s) : 0;
if (str && *str) {
int i;
void * match;
void **tokens = get_translations(lang, UT_PARAMS);
critbit_tree *cb = (critbit_tree *)*tokens;
if (!cb) {
log_warning("no parameters defined in locale %s", locale_name(lang));
}
else if (cb_find_prefix(cb, str, strlen(str), &match, 1, 0)) {
cb_get_kv(match, &i, sizeof(int));
result = (param_t)i;
}
}
return result;
}
param_t findparam_block(const char *s, const struct locale *lang, bool any_locale)
{
param_t p;
if (!s || s[0] == '@') {
return NOPARAM;
}
p = findparam(s, lang);
if (any_locale && p==NOPARAM) {
const struct locale *loc;
for (loc=locales;loc;loc=nextlocale(loc)) {
if (loc!=lang) {
p = findparam(s, loc);
if (p==P_FACTION || p==P_GAMENAME) {
break;
}
}
}
}
return p;
}
param_t findparam_ex(const char *s, const struct locale * lang)
{
param_t result = findparam(s, lang);
if (result == NOPARAM) {
const building_type *btype = findbuildingtype(s, lang);
if (btype != NULL)
return P_GEBAEUDE;
}
return (result == P_BUILDING) ? P_GEBAEUDE : result;
}
bool isparam(const char *s, const struct locale * lang, param_t param)
{
assert(s);
if (s[0] > '@') {
param_t p = (param == P_GEBAEUDE) ? findparam_ex(s, lang) : findparam(s, lang);
return p == param;
}
return false;
}
param_t getparam(const struct locale * lang)
{
char token[64];
const char *s = gettoken(token, sizeof(token));
return s ? findparam(s, lang) : NOPARAM;
}
/* -- Erschaffung neuer Einheiten ------------------------------ */
static const char *forbidden[] = { "t", "te", "tem", "temp", NULL };
@ -267,17 +149,6 @@ int newcontainerid(void)
return random_no;
}
static const char * parameter_key(int i)
{
assert(i < MAXPARAMS && i >= 0);
return parameters[i];
}
void init_parameters(struct locale *lang) {
init_translations(lang, UT_PARAMS, parameter_key, MAXPARAMS);
}
void init_terrains_translation(const struct locale *lang) {
void **tokens;
const terrain_type *terrain;
@ -368,6 +239,7 @@ static void init_magic(struct locale *lang)
free(sstr);
}
}
void init_locale(struct locale *lang)
{
init_magic(lang);

View File

@ -44,12 +44,6 @@ extern "C" {
int findoption(const char *s, const struct locale *lang);
param_t findparam(const char *s, const struct locale *lang);
param_t findparam_block(const char *s, const struct locale *lang, bool any_locale);
param_t findparam_ex(const char *s, const struct locale * lang);
bool isparam(const char *s, const struct locale * lang, param_t param);
param_t getparam(const struct locale *lang);
const char * game_name(void);
const char * game_mailcmd(void);
int game_id(void);
@ -132,12 +126,9 @@ extern "C" {
struct order *default_order(const struct locale *lang);
void init_parameters(struct locale *lang);
void free_gamedata(void);
void free_config(void);
extern const char *parameters[];
extern settings global;
#ifdef __cplusplus

View File

@ -5,9 +5,12 @@
#include <kernel/terrain.h>
#include <kernel/unit.h>
#include <kernel/order.h>
#include <util/language.h>
#include <util/base36.h>
#include <util/attrib.h>
#include <util/language.h>
#include <util/param.h>
#include <kernel/attrib.h>
#include <iniparser.h>

View File

@ -26,9 +26,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "terrain.h"
#include "unit.h"
#include <util/attrib.h>
#include <kernel/attrib.h>
#include <util/base36.h>
#include <util/gamedata.h>
#include <kernel/gamedata.h>
#include <util/language.h>
#include <util/log.h>
#include <util/macros.h>

View File

@ -34,9 +34,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "unit.h"
/* util includes */
#include <util/attrib.h>
#include <kernel/attrib.h>
#include <util/base36.h>
#include <util/gamedata.h>
#include <kernel/gamedata.h>
#include <util/goodies.h>
#include <util/language.h>
#include <util/log.h>

View File

@ -4,9 +4,9 @@
#include <kernel/region.h>
#include <kernel/save.h>
#include <kernel/unit.h>
#include <util/attrib.h>
#include <kernel/attrib.h>
#include <util/rng.h>
#include <util/gamedata.h>
#include <kernel/gamedata.h>
#include <util/message.h>
#include <binarystore.h>
#include <filestream.h>

View File

@ -1,46 +0,0 @@
#include <platform.h>
#include "database.h"
#include <platform.h>
#include <kernel/config.h>
#include <kernel/faction.h>
#include <kernel/database.h>
#include <kernel/orderdb.h>
#include <util/log.h>
#include "db/driver.h"
order_data *dblib_load_order(int id)
{
if (id > 0) {
return db_driver_order_load(id);
}
return NULL;
}
int dblib_save_order(order_data *od)
{
if (od->_str) {
return db_driver_order_save(od);
}
return 0;
}
int dblib_save_faction(const faction *f, int turn) {
return db_driver_faction_save(f->uid, f->no, turn, f->email, f->_password);
}
void dblib_open(void)
{
const char *dbname;
dbname = config_get("game.dbswap");
db_driver_open(DB_SWAP, dbname);
}
void dblib_close(void)
{
db_driver_close(DB_SWAP);
}

View File

@ -1,23 +0,0 @@
#ifndef H_DATABASE
#define H_DATABASE
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
struct order_data;
struct faction;
void dblib_open(void);
void dblib_close(void);
struct order_data *dblib_load_order(int id);
int dblib_save_order(struct order_data *od);
int dblib_save_faction(const struct faction *f, int turn);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,8 +1,9 @@
#include <platform.h>
#include <kernel/config.h>
#include <kernel/faction.h>
#include <kernel/order.h>
#include "database.h"
#include "db/driver.h"
#include "orderdb.h"
#include <CuTest.h>
@ -39,9 +40,9 @@ static void test_update_faction(CuTest *tc) {
test_setup();
f = test_create_faction(NULL);
uid = dblib_save_faction(f, 0);
uid = db_driver_faction_save(f->uid, f->no, 0, f->email, f->_password);
f->uid = uid;
uid = dblib_save_faction(f, 0);
uid = db_driver_faction_save(f->uid, f->no, 0, f->email, f->_password);
CuAssertIntEquals(tc, f->uid, uid);
test_teardown();
}

View File

@ -4,36 +4,35 @@
#include <platform.h>
#include "driver.h"
#include <kernel/config.h>
#include <kernel/orderdb.h>
#include <assert.h>
#include <string.h>
static DB *g_dbp;
void db_driver_open(void)
void db_driver_open(database_t db, const char *dbname)
{
int ret;
u_int32_t flags = DB_CREATE;
const char * dbname;
if (db == DB_SWAP) {
int ret;
u_int32_t flags = DB_CREATE;
dbname = config_get("game.dbname");
ret = db_create(&g_dbp, NULL, 0);
assert(ret==0);
ret = db_create(&g_dbp, NULL, 0);
assert(ret == 0);
ret = g_dbp->open(g_dbp, NULL, dbname, NULL, DB_RECNO, flags, 0);
assert(ret==0);
ret = g_dbp->open(g_dbp, NULL, dbname, NULL, DB_RECNO, flags, 0);
assert(ret == 0);
}
}
void db_driver_close(void)
void db_driver_close(database_t db)
{
int ret;
ret = g_dbp->close(g_dbp, 0);
assert(ret==0);
if (db == DB_SWAP) {
int ret;
ret = g_dbp->close(g_dbp, 0);
assert(ret == 0);
}
}
int db_driver_order_save(struct order_data *od)
int db_driver_order_save(const char *str)
{
int ret;
DBT key, data;
@ -46,18 +45,13 @@ int db_driver_order_save(struct order_data *od)
key.size = key.ulen = sizeof(recno);
key.flags = DB_DBT_USERMEM;
data.data = (void *)od->_str;
data.size = data.ulen = strlen(od->_str) + 1;
data.size = data.ulen = strlen(str) + 1;
data.flags = DB_DBT_USERMEM;
ret = g_dbp->put(g_dbp, NULL, &key, &data, DB_APPEND);
assert(ret == 0);
return (int)recno;
}
int db_driver_faction_save(int id, int no, int turn, const char *email, const char *password)
{
return -1;
}
struct order_data *db_driver_order_load(int id)
{
int ret;
@ -79,3 +73,8 @@ struct order_data *db_driver_order_load(int id)
return od;
}
int db_driver_faction_save(int id, int no, int turn, const char *email, const char *password)
{
return -1;
}

View File

@ -1,72 +0,0 @@
#include <platform.h>
#include "driver.h"
#include <kernel/orderdb.h>
#include <util/log.h>
#include <critbit.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
static critbit_tree cb_orders = { 0 };
static int auto_id = -1;
struct cb_entry {
int id;
order_data *data;
};
order_data *db_driver_order_load(int id)
{
void * match;
assert(id>0);
if (cb_find_prefix(&cb_orders, &id, sizeof(id), &match, 1, 0) > 0) {
struct cb_entry *ent = (struct cb_entry *)match;
order_data * od = ent->data;
++od->_refcount;
return od;
}
return NULL;
}
int db_driver_order_save(order_data *od)
{
struct cb_entry ent;
assert(od && od->_str);
++od->_refcount;
ent.id = ++auto_id;
ent.data = od;
cb_insert(&cb_orders, &ent, sizeof(ent));
return ent.id;
}
int db_driver_faction_save(int id, int no, int turn, const char *email, const char *password)
{
return -1;
}
static int free_data_cb(const void *match, const void *key, size_t keylen,
void *udata)
{
struct cb_entry * ent = (struct cb_entry *)match;
order_data *od = ent->data;
odata_release(od);
return 0;
}
void db_driver_open(void)
{
assert(auto_id == -1);
auto_id = 0;
}
void db_driver_close(void)
{
cb_foreach(&cb_orders, NULL, 0, free_data_cb, NULL);
cb_clear(&cb_orders);
auto_id = -1;
}

View File

@ -1,7 +1,11 @@
#pragma once
#include <stddef.h>
struct order_data;
extern void odata_create(struct order_data **pdata, size_t len, const char *str);
typedef enum database_t {
DB_SWAP,
DB_GAME,
@ -9,6 +13,6 @@ typedef enum database_t {
int db_driver_open(database_t db, const char *dbname);
void db_driver_close(database_t db);
int db_driver_order_save(struct order_data *od);
int db_driver_order_save(const char *str);
struct order_data *db_driver_order_load(int id);
int db_driver_faction_save(int id, int no, int turn, const char *email, const char *password);

70
src/kernel/db/memory.c Normal file
View File

@ -0,0 +1,70 @@
#ifdef _MSC_VER
#include <platform.h>
#endif
#include "driver.h"
#include <util/log.h>
#include <util/strings.h>
#include <selist.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
static selist * g_orders;
static int auto_id = -1;
struct order_data *db_driver_order_load(int id)
{
void * match;
assert(id>0);
match = selist_get(g_orders, id - 1);
if (match) {
char * str = (char *)match;
struct order_data * od = NULL;
odata_create(&od, strlen(str), str);
return od;
}
return NULL;
}
int db_driver_order_save(const char * str)
{
assert(str);
selist_push(&g_orders, str_strdup(str));
return ++auto_id;
}
int db_driver_faction_save(int id, int no, int turn, const char *email, const char *password)
{
return -1;
}
static void free_data_cb(void *match)
{
char *str = (char *)match;
free(str);
}
int db_driver_open(database_t db, const char *dbname)
{
(void)dbname;
if (db == DB_SWAP) {
assert(auto_id == -1);
auto_id = 0;
return 0;
}
return -1;
}
void db_driver_close(database_t db)
{
if (db == DB_SWAP) {
selist_foreach(g_orders, free_data_cb);
selist_free(g_orders);
g_orders = NULL;
auto_id = -1;
}
}

View File

@ -1,8 +1,6 @@
#include <platform.h>
#include <kernel/config.h>
#include <kernel/database.h>
#include <kernel/orderdb.h>
#include <util/log.h>
@ -25,9 +23,9 @@ static sqlite3_stmt * g_stmt_insert_faction;
static int g_order_batchsize;
static int g_order_tx_size;
order_data *db_driver_order_load(int id)
struct order_data *db_driver_order_load(int id)
{
order_data * od = NULL;
struct order_data * od = NULL;
int err;
ERRNO_CHECK();
@ -58,12 +56,12 @@ order_data *db_driver_order_load(int id)
return NULL;
}
int db_driver_order_save(order_data *od)
int db_driver_order_save(const char *str)
{
int err;
sqlite3_int64 id;
assert(od && od->_str);
assert(str);
ERRNO_CHECK();
@ -76,7 +74,7 @@ int db_driver_order_save(order_data *od)
err = sqlite3_reset(g_stmt_insert_order);
assert(err == SQLITE_OK);
err = sqlite3_bind_text(g_stmt_insert_order, 1, od->_str, -1, SQLITE_STATIC);
err = sqlite3_bind_text(g_stmt_insert_order, 1, str, -1, SQLITE_STATIC);
assert(err == SQLITE_OK);
err = sqlite3_step(g_stmt_insert_order);
assert(err == SQLITE_DONE);

View File

@ -18,12 +18,12 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <platform.h>
#include "event.h"
#include "attrib.h"
/* util includes */
#include "attrib.h"
#include "gamedata.h"
#include "log.h"
#include "strings.h"
#include <kernel/gamedata.h>
#include <util/log.h>
#include <util/strings.h>
#include <storage.h>

View File

@ -22,7 +22,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
extern "C" {
#endif
#include "variant.h"
#include <util/variant.h>
struct attrib;
struct trigger;

View File

@ -42,10 +42,10 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <attributes/racename.h>
/* util includes */
#include <util/attrib.h>
#include <kernel/attrib.h>
#include <util/base36.h>
#include <util/event.h>
#include <util/gamedata.h>
#include <kernel/event.h>
#include <kernel/gamedata.h>
#include <util/goodies.h>
#include <util/lists.h>
#include <util/language.h>

View File

@ -1,7 +1,8 @@
#include <platform.h>
#include "gamedata.h"
#include "log.h"
#include <util/log.h>
#include <storage.h>
#include <filestream.h>

View File

@ -30,9 +30,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <attributes/raceprefix.h>
/* util includes */
#include <util/attrib.h>
#include <kernel/attrib.h>
#include <util/base36.h>
#include <util/gamedata.h>
#include <kernel/gamedata.h>
#include <util/resolve.h>
#include <util/strings.h>
#include <util/unicode.h>

View File

@ -8,8 +8,8 @@
#include "region.h"
#include "save.h"
#include <util/gamedata.h>
#include <util/attrib.h>
#include <kernel/gamedata.h>
#include <kernel/attrib.h>
#include <attributes/key.h>
#include <stream.h>

View File

@ -35,7 +35,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "unit.h"
/* util includes */
#include <util/attrib.h>
#include <kernel/attrib.h>
#include <util/base36.h>
#include <util/functions.h>
#include <util/goodies.h>

View File

@ -14,13 +14,13 @@
#include <kernel/config.h>
#include "order.h"
#include "orderdb.h"
#include "skill.h"
#include "keyword.h"
#include <util/base36.h>
#include "util/keyword.h"
#include <util/language.h>
#include <util/log.h>
#include <util/param.h>
#include <util/parser.h>
#include <util/strings.h>
@ -36,6 +36,36 @@
# define ORD_KEYWORD(ord) (keyword_t)((ord)->command & 0xFFFF)
# define OD_STRING(odata) ((odata) ? (odata)->_str : NULL)
void odata_create(order_data **pdata, size_t len, const char *str)
{
order_data *data;
char *result;
assert(pdata);
data = malloc(sizeof(order_data) + len + 1);
data->_refcount = 1;
result = (char *)(data + 1);
data->_str = (len > 0) ? result : NULL;
if (str) {
strcpy(result, str);
}
*pdata = data;
}
void odata_release(order_data * od)
{
if (od) {
if (--od->_refcount == 0) {
free(od);
}
}
}
void odata_addref(order_data *od)
{
++od->_refcount;
}
void replace_order(order ** dlist, order * orig, const order * src)
{
assert(src);

View File

@ -13,7 +13,8 @@
#ifndef KRNL_ORDER_H
#define KRNL_ORDER_H
#include "keyword.h"
#include <util/keyword.h>
#include <stddef.h>
#include <stdbool.h>
@ -37,6 +38,18 @@ extern "C" {
#define CMD_PERSIST 0x020000
#define CMD_DEFAULT 0x040000
typedef struct order_data {
const char *_str;
int _refcount;
} order_data;
extern order_data *odata_load(int id);
extern int odata_save(order_data *od);
void odata_create(order_data **pdata, size_t len, const char *str);
void odata_release(order_data * od);
void odata_addref(order_data *od);
typedef struct order {
struct order *next;
/* do not access this data: */

View File

@ -5,6 +5,7 @@
#include <kernel/skills.h>
#include <kernel/unit.h>
#include "util/param.h"
#include <util/parser.h>
#include <util/language.h>

View File

@ -1,5 +1,8 @@
#include <platform.h>
#include "database.h"
#include "kernel/config.h"
#include "kernel/db/driver.h"
#include "orderdb.h"
#include <util/log.h>
@ -10,42 +13,31 @@
#include <stdlib.h>
#include <string.h>
void odata_create(order_data **pdata, size_t len, const char *str)
void orderdb_open(void)
{
order_data *data;
char *result;
const char *dbname;
assert(pdata);
data = malloc(sizeof(order_data) + len + 1);
data->_refcount = 1;
result = (char *)(data + 1);
data->_str = (len > 0) ? result : NULL;
if (str) {
strcpy(result, str);
}
*pdata = data;
dbname = config_get("game.dbswap");
db_driver_open(DB_SWAP, dbname);
}
void odata_release(order_data * od)
void orderdb_close(void)
{
if (od) {
if (--od->_refcount == 0) {
free(od);
}
}
}
void odata_addref(order_data *od)
{
++od->_refcount;
db_driver_close(DB_SWAP);
}
order_data *odata_load(int id)
{
return dblib_load_order(id);
if (id > 0) {
return db_driver_order_load(id);
}
return NULL;
}
int odata_save(order_data *od)
{
return dblib_save_order(od);
if (od->_str) {
return db_driver_order_save(od->_str);
}
return 0;
}

View File

@ -7,17 +7,8 @@
extern "C" {
#endif
typedef struct order_data {
const char *_str;
int _refcount;
} order_data;
void odata_create(order_data **pdata, size_t len, const char *str);
void odata_release(order_data * od);
void odata_addref(order_data *od);
order_data *odata_load(int id);
int odata_save(order_data *od);
void orderdb_open(void);
void orderdb_close(void);
#ifdef __cplusplus
}

View File

@ -25,7 +25,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "faction.h"
/* util includes */
#include <util/attrib.h>
#include <kernel/attrib.h>
#include <util/resolve.h>
#include <util/strings.h>
#include <util/lists.h>

View File

@ -37,7 +37,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "unit.h"
/* util includes */
#include <util/attrib.h>
#include <kernel/attrib.h>
#include <util/functions.h>
#include <util/umlaut.h>
#include <util/language.h>

View File

@ -42,8 +42,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* util includes */
#include <util/assert.h>
#include <util/attrib.h>
#include <util/gamedata.h>
#include <kernel/attrib.h>
#include <kernel/gamedata.h>
#include <util/strings.h>
#include <util/lists.h>
#include <util/log.h>

View File

@ -57,13 +57,13 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* util includes */
#include <util/assert.h>
#include <util/attrib.h>
#include <kernel/attrib.h>
#include <util/base36.h>
#include <util/event.h>
#include <kernel/event.h>
#include <util/filereader.h>
#include <util/gamedata.h>
#include <kernel/gamedata.h>
#include <util/goodies.h>
#include <util/gamedata.h>
#include <kernel/gamedata.h>
#include <util/language.h>
#include <util/lists.h>
#include <util/log.h>
@ -101,9 +101,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* exported symbols symbols */
int firstx = 0, firsty = 0;
/* TODO: is this still important? */
int enc_gamedata = ENCODING_UTF8;
static void read_alliances(gamedata *data)
{
storage *store = data->store;

View File

@ -17,10 +17,10 @@
#include <triggers/changefaction.h>
#include <triggers/createunit.h>
#include <triggers/timeout.h>
#include <util/attrib.h>
#include <kernel/attrib.h>
#include <util/base36.h>
#include <util/event.h>
#include <util/gamedata.h>
#include <kernel/event.h>
#include <kernel/gamedata.h>
#include <util/password.h>
#include <util/path.h>
#include <util/strings.h>

View File

@ -34,12 +34,13 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "skill.h"
/* util includes */
#include <util/attrib.h>
#include <kernel/attrib.h>
#include <util/base36.h>
#include <util/event.h>
#include <kernel/event.h>
#include <util/language.h>
#include <util/lists.h>
#include <util/log.h>
#include <util/param.h>
#include <util/strings.h>
#include <util/umlaut.h>

View File

@ -7,7 +7,7 @@
#include <kernel/unit.h>
#include <kernel/curse.h>
#include <util/attrib.h>
#include <kernel/attrib.h>
#include <spells/shipcurse.h>
#include <attributes/movement.h>

View File

@ -24,7 +24,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "region.h"
#include "unit.h"
#include <util/attrib.h>
#include <kernel/attrib.h>
#include <util/goodies.h>
#include <util/language.h>
#include <util/log.h>

View File

@ -4,7 +4,7 @@
#include <kernel/spell.h>
#include <util/log.h>
#include <util/gamedata.h>
#include <kernel/gamedata.h>
#include <util/strings.h>
#include "spellbook.h"

View File

@ -30,7 +30,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "terrainid.h"
#include <util/log.h>
#include <util/attrib.h>
#include <kernel/attrib.h>
#include <util/strings.h>
/* libc includes */

View File

@ -83,58 +83,6 @@ typedef enum {
ST_FLEE
} status_t;
/* ----------------- Parameter --------------------------------- */
typedef enum {
P_LOCALE,
P_ANY,
P_EACH,
P_PEASANT,
P_BUILDING,
P_UNIT,
P_PRIVAT,
P_BEHIND,
P_CONTROL,
P_HERBS,
P_NOT,
P_NEXT,
P_FACTION,
P_GAMENAME,
P_PERSON,
P_REGION,
P_SHIP,
P_MONEY,
P_ROAD,
P_TEMP,
P_FLEE,
P_GEBAEUDE,
P_GIVE,
P_FIGHT,
P_TRAVEL,
P_GUARD,
P_ZAUBER,
P_PAUSE,
P_VORNE,
P_AGGRO,
P_CHICKEN,
P_LEVEL,
P_HELP,
P_FOREIGN,
P_AURA,
P_AFTER,
P_BEFORE,
P_NUMBER,
P_ITEMS,
P_POTIONS,
P_GROUP,
P_FACTIONSTEALTH,
P_TREES,
P_ALLIANCE,
P_AUTO,
MAXPARAMS,
NOPARAM
} param_t;
typedef enum { /* Fehler und Meldungen im Report */
MSG_BATTLE,
MSG_EVENT,
@ -156,8 +104,6 @@ enum { /* Message-Level */
ML_MAX
};
extern const char *parameters[MAXPARAMS];
/* --------------- Reports Typen ------------------------------- */
enum {

View File

@ -21,12 +21,16 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "unit.h"
#include "ally.h"
#include "attrib.h"
#include "building.h"
#include "calendar.h"
#include "faction.h"
#include "group.h"
#include "connection.h"
#include "curse.h"
#include "event.h"
#include "faction.h"
#include "gamedata.h"
#include "group.h"
#include "guard.h"
#include "item.h"
#include "move.h"
#include "order.h"
@ -47,18 +51,13 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <spells/unitcurse.h>
#include <spells/regioncurse.h>
#include "guard.h"
/* util includes */
#include <util/attrib.h>
#include <util/base36.h>
#include <util/event.h>
#include <util/gamedata.h>
#include <util/strings.h>
#include <util/language.h>
#include <util/lists.h>
#include <util/log.h>
#include <util/macros.h>
#include <util/param.h>
#include <util/parser.h>
#include <util/rand.h>
#include <util/resolve.h>

View File

@ -9,7 +9,7 @@
#include <kernel/region.h>
#include <kernel/spell.h>
#include <kernel/terrain.h>
#include <util/attrib.h>
#include <kernel/attrib.h>
#include <util/base36.h>
#include <util/language.h>
#include <util/macros.h>

View File

@ -29,7 +29,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "automate.h"
#include "battle.h"
#include "economy.h"
#include "keyword.h"
#include "market.h"
#include "morale.h"
#include "monsters.h"
@ -71,15 +70,17 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "kernel/unit.h"
/* util includes */
#include <util/attrib.h>
#include <kernel/attrib.h>
#include <util/base36.h>
#include <util/event.h>
#include <kernel/event.h>
#include <util/goodies.h>
#include "util/keyword.h"
#include <util/language.h>
#include <util/lists.h>
#include <util/log.h>
#include <util/macros.h>
#include <util/message.h>
#include <util/param.h>
#include <util/parser.h>
#include <util/password.h>
#include <util/path.h>
@ -127,7 +128,17 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#define DMRISE 0.1F /* weekly chance that demand goes up */
#define DMRISEHAFEN 0.2F /* weekly chance that demand goes up with harbor */
/* - exported global symbols ----------------------------------- */
param_t findparam_ex(const char *s, const struct locale * lang)
{
param_t result = findparam(s, lang);
if (result == NOPARAM) {
const building_type *btype = findbuildingtype(s, lang);
if (btype != NULL)
return P_GEBAEUDE;
}
return (result == P_BUILDING) ? P_GEBAEUDE : result;
}
int NewbieImmunity(void)
{
@ -1952,7 +1963,7 @@ int mail_cmd(unit * u, struct order *ord)
}
case P_FACTION:
n = getfactionid();
n = getid();
for (u2 = r->units; u2; u2 = u2->next) {
if (u2->faction->no == n && seefaction(u->faction, r, u2, 0)) {

View File

@ -19,13 +19,14 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#ifndef H_GC_LAWS
#define H_GC_LAWS
#include <kernel/types.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
enum param_t;
struct locale;
struct unit;
struct region;
struct building;
@ -115,6 +116,8 @@ extern "C" {
bool IsImmune(const struct faction *f);
bool help_enter(struct unit *uo, struct unit *u);
enum param_t findparam_ex(const char *s, const struct locale * lang);
#ifdef __cplusplus
}
#endif

Some files were not shown because too many files have changed in this diff Show More