Author: cazfi
Date: Thu Feb 11 20:37:31 2016
New Revision: 31883

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

See patch #6942

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

Modified: trunk/server/civserver.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/civserver.c?rev=31883&r1=31882&r2=31883&view=diff
==============================================================================
--- trunk/server/civserver.c    (original)
+++ trunk/server/civserver.c    Thu Feb 11 20:37:31 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: trunk/server/ruleset.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/ruleset.c?rev=31883&r1=31882&r2=31883&view=diff
==============================================================================
--- trunk/server/ruleset.c      (original)
+++ trunk/server/ruleset.c      Thu Feb 11 20:37:31 2016
@@ -22,6 +22,7 @@
 
 /* utility */
 #include "bitvector.h"
+#include "deprecations.h"
 #include "fcintl.h"
 #include "log.h"
 #include "mem.h"
@@ -5024,6 +5025,7 @@
   const char *type;
   const char *filename;
   bool ok = TRUE;
+  bool effect_type_warned = FALSE;
 
   filename = secfile_name(file);
 
@@ -5048,6 +5050,10 @@
     if (type == NULL && compat->compat_mode) {
       /* 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 type.", filename, 
sec_name);

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

Added: trunk/utility/deprecations.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/utility/deprecations.c?rev=31883&view=auto
==============================================================================
--- trunk/utility/deprecations.c        (added)
+++ trunk/utility/deprecations.c        Thu Feb 11 20:37:31 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: trunk/utility/deprecations.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/utility/deprecations.h?rev=31883&view=auto
==============================================================================
--- trunk/utility/deprecations.h        (added)
+++ trunk/utility/deprecations.h        Thu Feb 11 20:37:31 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: trunk/utility/registry_ini.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/utility/registry_ini.c?rev=31883&r1=31882&r2=31883&view=diff
==============================================================================
--- trunk/utility/registry_ini.c        (original)
+++ trunk/utility/registry_ini.c        Thu Feb 11 20:37:31 2016
@@ -158,6 +158,7 @@
 
 /* utility */
 #include "astring.h"
+#include "deprecations.h"
 #include "fcintl.h"
 #include "inputfile.h"
 #include "ioz.h"
@@ -904,14 +905,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