Author: cazfi
Date: Tue May 10 18:00:44 2016
New Revision: 32653

URL: http://svn.gna.org/viewcvs/freeciv?rev=32653&view=rev
Log:
Added freeciv-ruleup

See patch #7171

Added:
    trunk/tools/ruleup.c
Modified:
    trunk/tools/Makefile.am

Modified: trunk/tools/Makefile.am
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/tools/Makefile.am?rev=32653&r1=32652&r2=32653&view=diff
==============================================================================
--- trunk/tools/Makefile.am     (original)
+++ trunk/tools/Makefile.am     Tue May 10 18:00:44 2016
@@ -10,7 +10,7 @@
 
 include $(top_srcdir)/bootstrap/Makerules.mk
 
-bin_PROGRAMS = 
+bin_PROGRAMS = freeciv-ruleup
 
 if SERVER
 if CLIENT
@@ -45,6 +45,7 @@
        -I$(top_srcdir)/server \
        -I$(top_srcdir)/client \
        -I$(top_srcdir)/client/include \
+       -I$(top_srcdir)/tools/ruleutil \
        -I$(top_srcdir)/dependencies/tinycthread
 
 AM_CPPFLAGS = $(common_cppflags)
@@ -80,6 +81,15 @@
 endif
 
 endif
+
+freeciv_ruleup_SOURCES =       \
+               ruleup.c
+
+freeciv_ruleup_LDADD = \
+ $(top_builddir)/server/libfreeciv-srv.la \
+ $(top_builddir)/common/libfreeciv.la \
+ $(top_builddir)/tools/ruleutil/libfcruleutil.la \
+ $(TINYCTHR_LIBS) $(MAPIMG_WAND_LIBS) $(SERVER_LIBS)
 
 if FCMANUAL
 freeciv_manual_SOURCES = \

Added: trunk/tools/ruleup.c
URL: http://svn.gna.org/viewcvs/freeciv/trunk/tools/ruleup.c?rev=32653&view=auto
==============================================================================
--- trunk/tools/ruleup.c        (added)
+++ trunk/tools/ruleup.c        Tue May 10 18:00:44 2016
@@ -0,0 +1,150 @@
+/***********************************************************************
+ Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
+   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.
+***********************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <fc_config.h>
+#endif
+
+#ifdef FREECIV_MSWINDOWS
+#include <windows.h>
+#endif
+
+/* utility */
+#include "fciconv.h"
+#include "registry.h"
+#include "string_vector.h"
+
+/* common */
+#include "fc_cmdhelp.h"
+#include "fc_interface.h"
+
+/* server */
+#include "ruleset.h"
+#include "sernet.h"
+#include "settings.h"
+
+/* tools/ruledit */
+#include "comments.h"
+#include "rulesave.h"
+
+static char *rs_selected = NULL;
+
+/**************************************************************************
+  Parse freeciv-ruleup commandline parameters.
+**************************************************************************/
+static void rup_parse_cmdline(int argc, char *argv[])
+{
+  int i = 1;
+
+  while (i < argc) {
+    char *option = NULL;
+
+    if (is_option("--help", argv[i])) {
+      struct cmdhelp *help = cmdhelp_new(argv[0]);
+
+      cmdhelp_add(help, "h", "help",
+                  _("Print a summary of the options"));
+      cmdhelp_add(help, "r",
+                  /* TRANS: "ruleset" is exactly what user must type, do not 
translate. */
+                  _("ruleset RULESET"),
+                  _("Update RULESET"));
+
+      /* The function below prints a header and footer for the options.
+       * Furthermore, the options are sorted. */
+      cmdhelp_display(help, TRUE, FALSE, TRUE);
+      cmdhelp_destroy(help);
+
+      exit(EXIT_SUCCESS);
+    } else if ((option = get_option_malloc("--ruleset", argv, &i, argc))) {
+      if (rs_selected != NULL) {
+        fc_fprintf(stderr,
+                   _("Multiple rulesets requested. Only one ruleset at time 
supported.\n"));
+        free(option);
+      } else {
+        rs_selected = option;
+      }
+    } else {
+      fc_fprintf(stderr, _("Unrecognized option: \"%s\"\n"), argv[i]);
+      exit(EXIT_FAILURE);
+    }
+
+    i++;
+  }
+}
+
+/**************************************************************************
+  Main entry point for freeciv-ruleup
+**************************************************************************/
+int main(int argc, char **argv)
+{
+  enum log_level loglevel = LOG_NORMAL;
+
+  /* Load win32 post-crash debugger */
+#ifdef FREECIV_MS_WINOWS
+# ifndef FREECIV_NDEBUG
+  if (LoadLibrary("exchndl.dll") == NULL) {
+#  ifdef FREECIV_DEBUG
+    fprintf(stderr, "exchndl.dll could not be loaded, no crash debugger\n");
+#  endif /* FREECIV_DEBUG */
+  }
+# endif /* FREECIV_NDEBUG */
+#endif /* FREECIV_MS_WINDOWS */
+
+  init_nls();
+
+  registry_module_init();
+  init_character_encodings(FC_DEFAULT_DATA_ENCODING, FALSE);
+
+  log_init(NULL, loglevel, NULL, NULL, -1);
+
+  init_connections();
+
+  settings_init(FALSE);
+
+  game_init();
+  i_am_server();
+
+  rup_parse_cmdline(argc, argv);
+
+  /* Set ruleset user requested to use */
+  if (rs_selected == NULL) {
+    rs_selected = GAME_DEFAULT_RULESETDIR;
+  }
+  sz_strlcpy(game.server.rulesetdir, rs_selected);
+
+  /* Reset aifill to zero */
+  game.info.aifill = 0;
+
+  if (load_rulesets(NULL, TRUE, FALSE, TRUE)) {
+    struct rule_data data;
+    char tgt_dir[2048];
+
+    data.nationlist = game.server.ruledit.nationlist;
+
+    fc_snprintf(tgt_dir, sizeof(tgt_dir), "%s.ruleup", rs_selected);
+
+    comments_load();
+    save_ruleset(tgt_dir, rs_selected, &data);
+    log_normal("Saved %s", tgt_dir);
+    comments_free();
+  } else {
+    log_error(_("Can't load ruleset %s"), rs_selected);
+  }
+
+  registry_module_close();
+  log_close();
+  free_libfreeciv();
+  free_nls();
+
+  return EXIT_SUCCESS;
+}


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to