From 1cccdc7d1527bdab8547e5454c994cdb0575e0be Mon Sep 17 00:00:00 2001 From: cazfi Date: Tue, 23 May 2017 17:11:08 +0000 Subject: [PATCH] Add 'parser.lua' to rulesets See hrm Feature #661644 git-svn-id: svn://svn.gna.org/svn/freeciv/trunk@35699 a0f10bec-cc02-0410-94fc-a9cfff90b4cd --- data/alien/Makefile.am | 1 + data/alien/parser.lua | 13 +++++++++++++ data/civ1/Makefile.am | 1 + data/civ1/parser.lua | 13 +++++++++++++ data/civ2/Makefile.am | 1 + data/civ2/parser.lua | 13 +++++++++++++ data/civ2civ3/Makefile.am | 1 + data/civ2civ3/parser.lua | 13 +++++++++++++ data/classic/Makefile.am | 1 + data/classic/parser.lua | 13 +++++++++++++ data/experimental/parser.lua | 13 +++++++++++++ data/multiplayer/Makefile.am | 1 + data/multiplayer/parser.lua | 13 +++++++++++++ data/sandbox/Makefile.am | 1 + data/sandbox/parser.lua | 13 +++++++++++++ data/stub/parser.lua | 13 +++++++++++++ data/webperimental/parser.lua | 13 +++++++++++++ server/ruleset.c | 20 +++++++++++++++++++- server/ruleset.h | 1 + tools/ruleutil/rulesave.c | 12 ++++++++---- 20 files changed, 165 insertions(+), 5 deletions(-) create mode 100644 data/alien/parser.lua create mode 100644 data/civ1/parser.lua create mode 100644 data/civ2/parser.lua create mode 100644 data/civ2civ3/parser.lua create mode 100644 data/classic/parser.lua create mode 100644 data/experimental/parser.lua create mode 100644 data/multiplayer/parser.lua create mode 100644 data/sandbox/parser.lua create mode 100644 data/stub/parser.lua create mode 100644 data/webperimental/parser.lua diff --git a/data/alien/Makefile.am b/data/alien/Makefile.am index ba9e58166a..cdea7df05b 100644 --- a/data/alien/Makefile.am +++ b/data/alien/Makefile.am @@ -9,6 +9,7 @@ pkgdata_DATA = \ effects.ruleset \ nation_effects.ruleset \ script.lua \ + parser.lua \ styles.ruleset \ game.ruleset \ governments.ruleset \ diff --git a/data/alien/parser.lua b/data/alien/parser.lua new file mode 100644 index 0000000000..ea4bf8c532 --- /dev/null +++ b/data/alien/parser.lua @@ -0,0 +1,13 @@ +-- Freeciv - Copyright (C) 2007 - The Freeciv Project +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2, or (at your option) +-- any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. + +-- This file is for lua-functionality for parsing luadata.txt +-- of this ruleset. diff --git a/data/civ1/Makefile.am b/data/civ1/Makefile.am index f60acb30ec..ded8c40930 100644 --- a/data/civ1/Makefile.am +++ b/data/civ1/Makefile.am @@ -8,6 +8,7 @@ pkgdata_DATA = \ cities.ruleset \ effects.ruleset \ script.lua \ + parser.lua \ styles.ruleset \ game.ruleset \ governments.ruleset \ diff --git a/data/civ1/parser.lua b/data/civ1/parser.lua new file mode 100644 index 0000000000..ea4bf8c532 --- /dev/null +++ b/data/civ1/parser.lua @@ -0,0 +1,13 @@ +-- Freeciv - Copyright (C) 2007 - The Freeciv Project +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2, or (at your option) +-- any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. + +-- This file is for lua-functionality for parsing luadata.txt +-- of this ruleset. diff --git a/data/civ2/Makefile.am b/data/civ2/Makefile.am index 7d6f76b634..fec81d5aee 100644 --- a/data/civ2/Makefile.am +++ b/data/civ2/Makefile.am @@ -8,6 +8,7 @@ pkgdata_DATA = \ cities.ruleset \ effects.ruleset \ script.lua \ + parser.lua \ styles.ruleset \ game.ruleset \ governments.ruleset \ diff --git a/data/civ2/parser.lua b/data/civ2/parser.lua new file mode 100644 index 0000000000..ea4bf8c532 --- /dev/null +++ b/data/civ2/parser.lua @@ -0,0 +1,13 @@ +-- Freeciv - Copyright (C) 2007 - The Freeciv Project +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2, or (at your option) +-- any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. + +-- This file is for lua-functionality for parsing luadata.txt +-- of this ruleset. diff --git a/data/civ2civ3/Makefile.am b/data/civ2civ3/Makefile.am index 2ec053e5e8..42548f8f00 100644 --- a/data/civ2civ3/Makefile.am +++ b/data/civ2civ3/Makefile.am @@ -8,6 +8,7 @@ pkgdata_DATA = \ cities.ruleset \ effects.ruleset \ script.lua \ + parser.lua \ styles.ruleset \ game.ruleset \ governments.ruleset \ diff --git a/data/civ2civ3/parser.lua b/data/civ2civ3/parser.lua new file mode 100644 index 0000000000..ea4bf8c532 --- /dev/null +++ b/data/civ2civ3/parser.lua @@ -0,0 +1,13 @@ +-- Freeciv - Copyright (C) 2007 - The Freeciv Project +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2, or (at your option) +-- any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. + +-- This file is for lua-functionality for parsing luadata.txt +-- of this ruleset. diff --git a/data/classic/Makefile.am b/data/classic/Makefile.am index 0bc687289e..8df2f17355 100644 --- a/data/classic/Makefile.am +++ b/data/classic/Makefile.am @@ -11,6 +11,7 @@ pkgdata_DATA = \ governments.ruleset \ nations.ruleset \ script.lua \ + parser.lua \ styles.ruleset \ techs.ruleset \ terrain.ruleset \ diff --git a/data/classic/parser.lua b/data/classic/parser.lua new file mode 100644 index 0000000000..ea4bf8c532 --- /dev/null +++ b/data/classic/parser.lua @@ -0,0 +1,13 @@ +-- Freeciv - Copyright (C) 2007 - The Freeciv Project +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2, or (at your option) +-- any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. + +-- This file is for lua-functionality for parsing luadata.txt +-- of this ruleset. diff --git a/data/experimental/parser.lua b/data/experimental/parser.lua new file mode 100644 index 0000000000..ea4bf8c532 --- /dev/null +++ b/data/experimental/parser.lua @@ -0,0 +1,13 @@ +-- Freeciv - Copyright (C) 2007 - The Freeciv Project +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2, or (at your option) +-- any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. + +-- This file is for lua-functionality for parsing luadata.txt +-- of this ruleset. diff --git a/data/multiplayer/Makefile.am b/data/multiplayer/Makefile.am index 8f68e6e710..6da9c6463a 100644 --- a/data/multiplayer/Makefile.am +++ b/data/multiplayer/Makefile.am @@ -8,6 +8,7 @@ pkgdata_DATA = \ cities.ruleset \ effects.ruleset \ script.lua \ + parser.lua \ styles.ruleset \ game.ruleset \ governments.ruleset \ diff --git a/data/multiplayer/parser.lua b/data/multiplayer/parser.lua new file mode 100644 index 0000000000..ea4bf8c532 --- /dev/null +++ b/data/multiplayer/parser.lua @@ -0,0 +1,13 @@ +-- Freeciv - Copyright (C) 2007 - The Freeciv Project +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2, or (at your option) +-- any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. + +-- This file is for lua-functionality for parsing luadata.txt +-- of this ruleset. diff --git a/data/sandbox/Makefile.am b/data/sandbox/Makefile.am index efa4300b8b..eb18b2b32a 100644 --- a/data/sandbox/Makefile.am +++ b/data/sandbox/Makefile.am @@ -8,6 +8,7 @@ pkgdata_DATA = \ cities.ruleset \ effects.ruleset \ script.lua \ + parser.lua \ styles.ruleset \ game.ruleset \ governments.ruleset \ diff --git a/data/sandbox/parser.lua b/data/sandbox/parser.lua new file mode 100644 index 0000000000..ea4bf8c532 --- /dev/null +++ b/data/sandbox/parser.lua @@ -0,0 +1,13 @@ +-- Freeciv - Copyright (C) 2007 - The Freeciv Project +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2, or (at your option) +-- any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. + +-- This file is for lua-functionality for parsing luadata.txt +-- of this ruleset. diff --git a/data/stub/parser.lua b/data/stub/parser.lua new file mode 100644 index 0000000000..ea4bf8c532 --- /dev/null +++ b/data/stub/parser.lua @@ -0,0 +1,13 @@ +-- Freeciv - Copyright (C) 2007 - The Freeciv Project +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2, or (at your option) +-- any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. + +-- This file is for lua-functionality for parsing luadata.txt +-- of this ruleset. diff --git a/data/webperimental/parser.lua b/data/webperimental/parser.lua new file mode 100644 index 0000000000..ea4bf8c532 --- /dev/null +++ b/data/webperimental/parser.lua @@ -0,0 +1,13 @@ +-- Freeciv - Copyright (C) 2007 - The Freeciv Project +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2, or (at your option) +-- any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. + +-- This file is for lua-functionality for parsing luadata.txt +-- of this ruleset. diff --git a/server/ruleset.c b/server/ruleset.c index 78fb9d8055..de74499273 100644 --- a/server/ruleset.c +++ b/server/ruleset.c @@ -194,6 +194,7 @@ static bool load_ruleset_veteran(struct section_file *file, size_t err_len); char *script_buffer = NULL; +char *parser_buffer = NULL; /************************************************************************** Notifications about ruleset errors to clients. Especially important in @@ -270,6 +271,14 @@ char *get_script_buffer(void) } /************************************************************************** + Return current parser.lua buffer. +**************************************************************************/ +char *get_parser_buffer(void) +{ + return parser_buffer; +} + +/************************************************************************** Do initial section_file_load on a ruleset file. "whichset" = "techs", "units", "buildings", "terrain", ... **************************************************************************/ @@ -8021,6 +8030,10 @@ static bool load_rulesetdir(const char *rsdir, bool compat_mode, FC_FREE(script_buffer); script_buffer = NULL; } + if (parser_buffer != NULL) { + FC_FREE(parser_buffer); + parser_buffer = NULL; + } server.playable_nations = 0; @@ -8158,7 +8171,6 @@ static bool load_rulesetdir(const char *rsdir, bool compat_mode, } if (ok) { - char **buffer = buffer_script ? &script_buffer : NULL; script_server_free(); @@ -8168,6 +8180,12 @@ static bool load_rulesetdir(const char *rsdir, bool compat_mode, ok = openload_script_file("script", rsdir, buffer); } + if (ok) { + char **buffer = buffer_script ? &parser_buffer : NULL; + + ok = openload_script_file("parser", rsdir, buffer); + } + if (ok && !buffer_script) { ok = openload_script_file("default", rsdir, NULL); } diff --git a/server/ruleset.h b/server/ruleset.h index 2d99f6e52d..2cdb1ccf63 100644 --- a/server/ruleset.h +++ b/server/ruleset.h @@ -55,6 +55,7 @@ void ruleset_error_real(const char *file, const char *function, } char *get_script_buffer(void); +char *get_parser_buffer(void); /* Default ruleset values that are not settings (in game.h) */ diff --git a/tools/ruleutil/rulesave.c b/tools/ruleutil/rulesave.c index 0554bc1867..d95c4e4936 100644 --- a/tools/ruleutil/rulesave.c +++ b/tools/ruleutil/rulesave.c @@ -2802,10 +2802,9 @@ static bool save_units_ruleset(const char *filename, const char *name) /************************************************************************** Save script.lua **************************************************************************/ -static bool save_script_lua(const char *filename, const char *name) +static bool save_script_lua(const char *filename, const char *name, + const char *buffer) { - char *buffer = get_script_buffer(); - if (buffer != NULL) { FILE *ffile = fc_fopen(filename, "w"); int full_len = strlen(buffer); @@ -2888,7 +2887,12 @@ bool save_ruleset(const char *path, const char *name, struct rule_data *data) if (success) { fc_snprintf(filename, sizeof(filename), "%s/script.lua", path); - success = save_script_lua(filename, name); + success = save_script_lua(filename, name, get_script_buffer()); + } + + if (success) { + fc_snprintf(filename, sizeof(filename), "%s/parser.lua", path); + success = save_script_lua(filename, name, get_parser_buffer()); } return success; -- 2.11.4.GIT