Author: cazfi
Date: Thu Feb 11 20:37:41 2016
New Revision: 31884

URL: http://svn.gna.org/viewcvs/freeciv?rev=31884&view=rev
Log:
Added initial version of the deprecations module.

See patch #6942

Added:
    branches/S2_6/utility/deprecations.c
    branches/S2_6/utility/deprecations.h
Modified:
    branches/S2_6/server/civserver.c
    branches/S2_6/server/ruleset.c
    branches/S2_6/utility/Makefile.am
    branches/S2_6/utility/registry_ini.c

Modified: branches/S2_6/server/civserver.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/civserver.c?rev=31884&r1=31883&r2=31884&view=diff
==============================================================================
--- branches/S2_6/server/civserver.c    (original)
+++ branches/S2_6/server/civserver.c    Thu Feb 11 20:37:41 2016
@@ -39,6 +39,7 @@
 #endif
 
 /* utility */
+#include "deprecations.h"
 #include "fciconv.h"
 #include "fcintl.h"
 #include "log.h"
@@ -300,6 +301,8 @@
         log_error(_("Illegal value \"%s\" for --Announce"), option);
       }
       free(option);
+    } else if (is_option("--warnings", argv[inx])) {
+      deprecation_warnings_enable();
 #ifdef AI_MODULES
     } else if ((option = get_option_malloc("--LoadAI", argv, &inx, argc))) {
       if (!load_ai_module(option)) {
@@ -434,6 +437,8 @@
 #endif /* AI_MODULES */
     cmdhelp_add(help, "v", "version",
                 _("Print the version number"));
+    cmdhelp_add(help, "w", "warnings",
+                _("Warn about deprecated modpack constructs"));
 
     /* The function below prints a header and footer for the options.
      * Furthermore, the options are sorted. */

Modified: branches/S2_6/server/ruleset.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/ruleset.c?rev=31884&r1=31883&r2=31884&view=diff
==============================================================================
--- branches/S2_6/server/ruleset.c      (original)
+++ branches/S2_6/server/ruleset.c      Thu Feb 11 20:37:41 2016
@@ -22,6 +22,7 @@
 
 /* utility */
 #include "bitvector.h"
+#include "deprecations.h"
 #include "fcintl.h"
 #include "log.h"
 #include "mem.h"
@@ -4806,6 +4807,7 @@
   const char *type;
   const char *filename;
   bool ok = TRUE;
+  bool effect_type_warned = FALSE;
 
   filename = secfile_name(file);
   if (check_ruleset_capabilities(file, RULESET_CAPABILITIES, filename) == 
NULL) {
@@ -4828,6 +4830,10 @@
     if (type == NULL) {
       /* Backward compatibility. Field used to be named "name" */
       type = secfile_lookup_str(file, "%s.name", sec_name);
+      if (type != NULL && !effect_type_warned) {
+        log_deprecation(_("Effects should have \"type\", not the same field 
with old name \"name\"."));
+        effect_type_warned = TRUE;
+      }
     }
     if (type == NULL) {
       ruleset_error(LOG_ERROR, "\"%s\" [%s] missing effect name.", filename, 
sec_name);

Modified: branches/S2_6/utility/Makefile.am
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/utility/Makefile.am?rev=31884&r1=31883&r2=31884&view=diff
==============================================================================
--- branches/S2_6/utility/Makefile.am   (original)
+++ branches/S2_6/utility/Makefile.am   Thu Feb 11 20:37:41 2016
@@ -11,6 +11,8 @@
                bitvector.h     \
                capability.c    \
                capability.h    \
+               deprecations.c  \
+               deprecations.h  \
                distribute.c    \
                distribute.h    \
                fc_utf8.c       \

Added: branches/S2_6/utility/deprecations.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/utility/deprecations.c?rev=31884&view=auto
==============================================================================
--- branches/S2_6/utility/deprecations.c        (added)
+++ branches/S2_6/utility/deprecations.c        Thu Feb 11 20:37:41 2016
@@ -0,0 +1,42 @@
+/********************************************************************** 
+ 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 /* HAVE_CONFIG_H */
+
+#include "fc_prehdrs.h"
+
+/* utility */
+#include "log.h"
+#include "shared.h"
+
+#include "deprecations.h"
+
+static bool depr_warns_enabled = FALSE;
+
+/************************************************************************
+  Enable deprecation warnings.
+************************************************************************/
+void deprecation_warnings_enable(void)
+{
+  depr_warns_enabled = TRUE;
+}
+
+/************************************************************************
+  Return whether deprecation warnings are currently enabled.
+************************************************************************/
+bool are_deprecation_warnings_enabled(void)
+{
+  return depr_warns_enabled;
+}

Added: branches/S2_6/utility/deprecations.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/utility/deprecations.h?rev=31884&view=auto
==============================================================================
--- branches/S2_6/utility/deprecations.h        (added)
+++ branches/S2_6/utility/deprecations.h        Thu Feb 11 20:37:41 2016
@@ -0,0 +1,52 @@
+/********************************************************************** 
+ 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.
+***********************************************************************/
+
+#ifndef FC__DEPRECATIONS_H
+#define FC__DEPRECATIONS_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/* utility */
+#include "log.h"
+
+#define LOG_DEPRECATION LOG_NORMAL
+
+void deprecation_warnings_enable(void);
+bool are_deprecation_warnings_enabled(void);
+
+#define log_deprecation(message, ...) \
+  do { \
+    if (are_deprecation_warnings_enabled()) { \
+      log_base(LOG_DEPRECATION, message, ## __VA_ARGS__); \
+    } \
+  } while (FALSE);
+
+#define log_deprecation_alt(altlvl, message, ...) \
+  do { \
+    if (are_deprecation_warnings_enabled()) { \
+      log_base(LOG_DEPRECATION, message, ## __VA_ARGS__); \
+    } else { \
+      log_base(altlvl, message, ## __VA_ARGS__); \
+    } \
+  } while (FALSE);
+
+#define log_deprecation_always(message, ...) \
+  log_base(LOG_DEPRECATION, message, ## __VA_ARGS__);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* FC__DEPRECATIONS_H */

Modified: branches/S2_6/utility/registry_ini.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/utility/registry_ini.c?rev=31884&r1=31883&r2=31884&view=diff
==============================================================================
--- branches/S2_6/utility/registry_ini.c        (original)
+++ branches/S2_6/utility/registry_ini.c        Thu Feb 11 20:37:41 2016
@@ -158,6 +158,7 @@
 
 /* utility */
 #include "astring.h"
+#include "deprecations.h"
 #include "fcintl.h"
 #include "inputfile.h"
 #include "ioz.h"
@@ -861,14 +862,20 @@
           log_verbose("Unused entries in file %s:", secfile->name);
           any = TRUE;
         }
+        if (are_deprecation_warnings_enabled()) {
+          log_deprecation_always("%s: unused entry: %s.%s",
+                                 secfile->name != NULL ? secfile->name : 
"nameless",
+                                 section_name(psection), entry_name(pentry));
+        } else {
 #ifdef TESTMATIC_ENABLED
-        log_testmatic("%s: unused entry: %s.%s",
-                      secfile->name != NULL ? secfile->name : "nameless",
+          log_testmatic("%s: unused entry: %s.%s",
+                        secfile->name != NULL ? secfile->name : "nameless",
+                        section_name(psection), entry_name(pentry));
+#else  /* TESTMATIC_ENABLED */
+          log_verbose("  unused entry: %s.%s",
                       section_name(psection), entry_name(pentry));
-#else  /* TESTMATIC_ENABLED */
-        log_verbose("  unused entry: %s.%s",
-                    section_name(psection), entry_name(pentry));
 #endif /* TESTMATIC_ENABLED */
+        }
       }
     } entry_list_iterate_end;
   } section_list_iterate_end;


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

Reply via email to