Author: cazfi
Date: Fri Feb 19 14:30:52 2016
New Revision: 31993

URL: http://svn.gna.org/viewcvs/freeciv?rev=31993&view=rev
Log:
Added comments.txt datafile to read standard comments to save to the rulesets.

See patch #6962

Added:
    trunk/data/ruledit/
    trunk/data/ruledit/Makefile.am
    trunk/data/ruledit/comments.txt
Modified:
    trunk/configure.ac
    trunk/data/Makefile.am
    trunk/tools/ruledit/comments.c
    trunk/tools/ruledit/comments.h
    trunk/tools/ruledit/ruledit.cpp

Modified: trunk/configure.ac
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/configure.ac?rev=31993&r1=31992&r2=31993&view=diff
==============================================================================
--- trunk/configure.ac  (original)
+++ trunk/configure.ac  Fri Feb 19 14:30:52 2016
@@ -1539,6 +1539,7 @@
          data/civ2/Makefile
          data/scenarios/Makefile
          data/nation/Makefile
+          data/ruledit/Makefile
          data/themes/Makefile
          data/themes/gui-gtk-2.0/Makefile
          data/themes/gui-gtk-2.0/Freeciv/Makefile

Modified: trunk/data/Makefile.am
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/data/Makefile.am?rev=31993&r1=31992&r2=31993&view=diff
==============================================================================
--- trunk/data/Makefile.am      (original)
+++ trunk/data/Makefile.am      Fri Feb 19 14:30:52 2016
@@ -99,6 +99,12 @@
 endif
 endif
 
+if RULEDIT
+RULEDITDIRS = ruledit
+else
+RULEDITDIRS =
+endif
+
 if CLIENT
 ICONS = freeciv-client.png
 else
@@ -108,4 +114,4 @@
 icondir = $(prefix)/share/pixmaps
 icon_DATA=$(ICONS)
 
-SUBDIRS = icons $(CLIENTDATADIRS) $(SERVERDATADIRS) override
+SUBDIRS = icons $(CLIENTDATADIRS) $(SERVERDATADIRS) $(RULEDITDIRS) override

Added: trunk/data/ruledit/Makefile.am
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/data/ruledit/Makefile.am?rev=31993&view=auto
==============================================================================
--- trunk/data/ruledit/Makefile.am      (added)
+++ trunk/data/ruledit/Makefile.am      Fri Feb 19 14:30:52 2016
@@ -0,0 +1,9 @@
+## Process this file with automake to produce Makefile.in
+
+## Override automake so that "make install" puts these in proper place:
+pkgdatadir = $(datadir)/$(PACKAGE)/ruledit
+
+pkgdata_DATA =          \
+       comments.txt
+
+EXTRA_DIST = $(pkgdata_DATA)

Added: trunk/data/ruledit/comments.txt
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/data/ruledit/comments.txt?rev=31993&view=auto
==============================================================================
--- trunk/data/ruledit/comments.txt     (added)
+++ trunk/data/ruledit/comments.txt     Fri Feb 19 14:30:52 2016
@@ -0,0 +1,16 @@
+; This file contains standard comments to include to the rulesets
+
+[common]
+
+header = "\
+; Modifying this file:\n\
+; You should not modify this file except to make bugfixes or\n\
+; for other \"maintenance\".  If you want to make custom changes,\n\
+; you should create a new datadir subdirectory and copy this file\n\
+; into that directory, and then modify that copy.  Then use the\n\
+; command \"rulesetdir <mysubdir>\" in the server to have freeciv\n\
+; use your new customized file.\n\
+\n\
+; Note that the freeciv AI may not cope well with anything more\n\
+; than minor changes.\n\
+"

Modified: trunk/tools/ruledit/comments.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/tools/ruledit/comments.c?rev=31993&r1=31992&r2=31993&view=diff
==============================================================================
--- trunk/tools/ruledit/comments.c      (original)
+++ trunk/tools/ruledit/comments.c      Fri Feb 19 14:30:52 2016
@@ -16,28 +16,55 @@
 #endif
 
 /* utility */
-#include "registry_ini.h"
+#include "mem.h"
+#include "registry.h"
 #include "section_file.h"
 
 #include "comments.h"
+
+static struct {
+  char *file_header;
+} comments_storage;
+
+/**************************************************************************
+  Load comments to add to the saved rulesets.
+**************************************************************************/
+bool comments_load(void)
+{
+  struct section_file *comment_file;
+  const char *fullpath;
+
+  fullpath = fileinfoname(get_data_dirs(), "ruledit/comments.txt");
+
+  if (fullpath == NULL) {
+    return FALSE;
+  }
+
+  comment_file = secfile_load(fullpath, FALSE);
+  if (comment_file == NULL) {
+    return FALSE;
+  }
+
+  comments_storage.file_header = fc_strdup(secfile_lookup_str(comment_file, 
"common.header"));
+
+  secfile_check_unused(comment_file);
+  secfile_destroy(comment_file);
+
+  return TRUE;
+}
+
+/**************************************************************************
+  Free comments.
+**************************************************************************/
+void comments_free(void)
+{
+  free(comments_storage.file_header);
+}
 
 /**************************************************************************
   Write file header.
 **************************************************************************/
 void comment_file_header(struct section_file *sfile)
 {
-
-  secfile_insert_long_comment(sfile, "\
-; Modifying this file:\n\
-; You should not modify this file except to make bugfixes or\n\
-; for other \"maintenance\".  If you want to make custom changes,\n\
-; you should create a new datadir subdirectory and copy this file\n\
-; into that directory, and then modify that copy.  Then use the\n\
-; command \"rulesetdir <mysubdir>\" in the server to have freeciv\n\
-; use your new customized file.\n\
-\n\
-; Note that the freeciv AI may not cope well with anything more\n\
-; than minor changes.\n\
-");
-
+  secfile_insert_long_comment(sfile, comments_storage.file_header);
 }

Modified: trunk/tools/ruledit/comments.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/tools/ruledit/comments.h?rev=31993&r1=31992&r2=31993&view=diff
==============================================================================
--- trunk/tools/ruledit/comments.h      (original)
+++ trunk/tools/ruledit/comments.h      Fri Feb 19 14:30:52 2016
@@ -19,6 +19,9 @@
 
 struct section_file;
 
+bool comments_load(void);
+void comments_free(void);
+
 void comment_file_header(struct section_file *sfile);
 
 #ifdef __cplusplus

Modified: trunk/tools/ruledit/ruledit.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/tools/ruledit/ruledit.cpp?rev=31993&r1=31992&r2=31993&view=diff
==============================================================================
--- trunk/tools/ruledit/ruledit.cpp     (original)
+++ trunk/tools/ruledit/ruledit.cpp     Fri Feb 19 14:30:52 2016
@@ -40,6 +40,7 @@
 #include "settings.h"
 
 /* ruledit */
+#include "comments.h"
 #include "ruledit_qt.h"
 
 #include "ruledit.h"
@@ -98,9 +99,16 @@
     game_init();
     i_am_server();
 
-    ruledit_qt_setup(ui_options, argv);
-    ruledit_qt_run();
-    ruledit_qt_close();
+    if (comments_load()) {
+
+      ruledit_qt_setup(ui_options, argv);
+      ruledit_qt_run();
+      ruledit_qt_close();
+
+      comments_free();
+    } else {
+      log_error(R__("Failed to load comments.txt"));
+    }
   }
 
   registry_module_close();


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

Reply via email to