From 6a66a986e962554b161ddb46f8b1e85a7c791e27 Mon Sep 17 00:00:00 2001
From: Dmitri Pal <dpal@redhat.com>
Date: Sat, 25 Dec 2010 23:24:35 -0500
Subject: [PATCH] [INI] New error codes and messages

Patch consists of two parts:
* Adding new constants for error messages to ini_configobj.h file
* Making ini_print.c use this header file instead of the old one.
---
 ini/ini_configobj.h |   12 ++++++----
 ini/ini_print.c     |   54 +++++++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 57 insertions(+), 9 deletions(-)

diff --git a/ini/ini_configobj.h b/ini/ini_configobj.h
index 88a8704277facb0f8883b2df28a709b26ae311f7..36558a701a86f6f656f2d0e3b155b9d901177fa7 100644
--- a/ini/ini_configobj.h
+++ b/ini/ini_configobj.h
@@ -72,13 +72,15 @@
 #define ERR_READ            8
 /** @brief Line starts with space when it should not (Error). */
 #define ERR_SPACE           9
+/** @brief Duplicate key is not allowed (Error). */
+#define ERR_DUPKEY          10
+/** @brief Duplicate key is detected while merging sections (Error). */
+#define ERR_DUPKEYSEC       11
+/** @brief Duplicate section is not allowed (Error). */
+#define ERR_DUPSECTION      12
 
 /** @brief Size of the error array. */
-#define ERR_MAXPARSE        ERR_SPACE
-
-/**
- * @}
- */
+#define ERR_MAXPARSE        ERR_DUPSECTION
 
 
 /**
diff --git a/ini/ini_print.c b/ini/ini_print.c
index 0430976cd56e89313cb386b99ad387263498c639..1dcfa54bfd72daf2c790d04c37ff2b3107eb7295 100644
--- a/ini/ini_print.c
+++ b/ini/ini_print.c
@@ -31,7 +31,8 @@
 #include "collection.h"
 #include "collection_tools.h"
 #include "ini_defines.h"
-#include "ini_config.h"
+#include "ini_config_priv.h"
+#include "ini_configobj.h"
 
 
 /*============================================================*/
@@ -42,6 +43,16 @@
  * check that the class IDs did not get reused over time by
  * other classes.
  */
+/**
+ * @brief Collection of error collections.
+ *
+ * When multiple files are read during one call
+ * each file has its own set of parsing errors
+ * and warnings. This is the collection
+ * of such sets.
+ */
+#define COL_CLASS_INI_PESET       COL_CLASS_INI_BASE + 3
+
 /** @brief Collection of grammar errors.
  *
  * Reserved for future use.
@@ -53,6 +64,37 @@
  */
 #define COL_CLASS_INI_VERROR      COL_CLASS_INI_BASE + 6
 
+/**
+ * @}
+ */
+
+/**
+ * @defgroup gramerr Grammar errors and warnings
+ *
+ * Placeholder for now. Reserved for future use.
+ *
+ * @{
+ */
+#define ERR_MAXGRAMMAR      0
+/**
+ * @}
+ */
+
+/**
+ * @defgroup valerr Validation errors and warnings
+ *
+ * Placeholder for now. Reserved for future use.
+ *
+ * @{
+ */
+#define ERR_MAXVALID        0
+
+
+/**
+ * @}
+ */
+
+
 #ifdef HAVE_VALIDATION
 
 /** @brief Collection of lines from the INI file.
@@ -78,7 +120,11 @@ static const char *parsing_error_str(int parsing_error)
                                 _("Property name is too long."),
                                 _("Failed to read line."),
                                 _("Invalid space character at the "
-                                  "beginning of the line.")
+                                  "beginning of the line."),
+                                _("Duplicate key is not allowed."),
+                                _("Duplicate key is detected while "
+                                  "merging sections."),
+                                _("Duplicate section is not allowed.")
     };
 
     /* Check the range */
@@ -208,7 +254,7 @@ static void print_error_list(FILE *file,
     struct collection_iterator *iterator;
     int error;
     struct collection_item *item = NULL;
-    struct parse_error *pe;
+    struct ini_parse_error *pe;
     unsigned int count;
 
     TRACE_FLOW_STRING("print_error_list", "Entry");
@@ -256,7 +302,7 @@ static void print_error_list(FILE *file,
         }
         else {
             /* Put error into provided format */
-            pe = (struct parse_error *)(col_get_item_data(item));
+            pe = (struct ini_parse_error *)(col_get_item_data(item));
             fprintf(file, line_format,
                     col_get_item_property(item, NULL), /* Error or warning */
                     pe->error,                         /* Error */
-- 
1.5.5.6

