]> arthur.barton.de Git - netatalk.git/blobdiff - libatalk/iniparser/iniparser.c
Twisted loglevel and logtype
[netatalk.git] / libatalk / iniparser / iniparser.c
index 92f09c464ecde3c224db89388fce8afaf5fe249e..735812cd5b651edecefbf219b37016327ea0fc03 100644 (file)
@@ -1,4 +1,3 @@
-
 /*-------------------------------------------------------------------------*/
 /**
    @file    iniparser.c
@@ -7,15 +6,12 @@
    @version 3.0
    @brief   Parser for ini files.
 */
-/*--------------------------------------------------------------------------*/
-/*
-    $Id: iniparser.c,v 2.19 2011-03-02 20:15:13 ndevilla Exp $
-    $Revision: 2.19 $
-    $Date: 2011-03-02 20:15:13 $
-*/
+
 /*---------------------------- Includes ------------------------------------*/
 #include <ctype.h>
+
 #include <atalk/iniparser.h>
+#include <atalk/logger.h>
 
 /*---------------------------- Defines -------------------------------------*/
 #define ASCIILINESZ         (1024)
@@ -38,9 +34,9 @@ typedef enum _line_status_ {
 
 /*-------------------------------------------------------------------------*/
 /**
-  @brief       Remove blanks at the beginning and the end of a string.
-  @param       s       String to parse.
-  @return      ptr to statically allocated string.
+  @brief    Remove blanks at the beginning and the end of a string.
+  @param    s   String to parse.
+  @return   ptr to statically allocated string.
 
   This function returns a pointer to a statically allocated string,
   which is identical to the input string, except that all blank
@@ -53,21 +49,21 @@ typedef enum _line_status_ {
 static char * strstrip(char * s)
 {
     static char l[ASCIILINESZ+1];
-       char * last ;
-       
+    char * last ;
+
     if (s==NULL) return NULL ;
-    
-       while (isspace((int)*s) && *s) s++;
-       memset(l, 0, ASCIILINESZ+1);
-       strcpy(l, s);
-       last = l + strlen(l);
-       while (last > l) {
-               if (!isspace((int)*(last-1)))
-                       break ;
-               last -- ;
-       }
-       *last = (char)0;
-       return (char*)l ;
+
+    while (isspace((int)*s) && *s) s++;
+    memset(l, 0, ASCIILINESZ+1);
+    strcpy(l, s);
+    last = l + strlen(l);
+    while (last > l) {
+        if (!isspace((int)*(last-1)))
+            break ;
+        last -- ;
+    }
+    *last = (char)0;
+    return (char*)l ;
 }
 
 /*-------------------------------------------------------------------------*/
@@ -444,7 +440,7 @@ void iniparser_unset(dictionary * ini, char *section, char * key)
 
 /*-------------------------------------------------------------------------*/
 /**
-  @brief       Load a single line from an INI file
+  @brief    Load a single line from an INI file
   @param    input_line  Input line, may be concatenated multi-line input
   @param    section     Output space to store section
   @param    key         Output space to store key
@@ -457,7 +453,7 @@ static line_status iniparser_line(
     char * section,
     char * key,
     char * value)
-{   
+{
     line_status sta ;
     char        line[ASCIILINESZ+1];
     int         len ;
@@ -471,7 +467,7 @@ static line_status iniparser_line(
         sta = LINE_EMPTY ;
     } else if (line[0]=='#' || line[0]==';') {
         /* Comment line */
-        sta = LINE_COMMENT ; 
+        sta = LINE_COMMENT ;
     } else if (line[0]=='[' && line[len-1]==']') {
         /* Section name */
         sscanf(line, "[%[^]]", section);
@@ -544,13 +540,13 @@ dictionary * iniparser_load(const char * ininame)
     dictionary * dict ;
 
     if ((inifile=fopen(ininame, "r"))==NULL) {
-        fprintf(stderr, "iniparser: cannot open %s\n", ininame);
+        LOG(log_error, logtype_default, "iniparser: cannot open \"%s\"", ininame);
         return NULL ;
     }
 
     dict = dictionary_new(0) ;
     if (!dict) {
-        fclose(in);
+        fclose(inifile);
         return NULL ;
     }
 
@@ -577,10 +573,8 @@ dictionary * iniparser_load(const char * ininame)
             continue;
         /* Safety check against buffer overflows */
         if (line[len]!='\n') {
-            fprintf(stderr,
-                    "iniparser: input line too long in %s (%d)\n",
-                    ininame,
-                    lineno);
+            LOG(log_error, logtype_default, "iniparser: input line too long in \"%s\" (lineno: %d)",
+                ininame, lineno);
             dictionary_del(dict);
             fclose(in);
             return NULL ;
@@ -609,7 +603,7 @@ dictionary * iniparser_load(const char * ininame)
         case LINE_VALUE:
             if (strcmp(key, "include") == 0) {
                 if ((include = fopen(val, "r")) == NULL) {
-                    fprintf(stderr, "iniparser: cannot open %s\n", val);
+                    LOG(log_error, logtype_default, "iniparser: cannot open \"%s\"", val);
                     continue;
                 }
                 in = include;
@@ -618,9 +612,8 @@ dictionary * iniparser_load(const char * ininame)
             errs = dictionary_set(dict, section, key, val) ;
             break ;
         case LINE_ERROR:
-            fprintf(stderr, "iniparser: syntax error in %s (%d):\n",
-                    ininame, lineno);
-            fprintf(stderr, "-> %s\n", line);
+            LOG(log_error, logtype_default, "iniparser: syntax error in %s (lineno: %d): %s",
+                ininame, lineno, line);
             errs++ ;
             break;
         default:
@@ -629,7 +622,7 @@ dictionary * iniparser_load(const char * ininame)
         memset(line, 0, ASCIILINESZ);
         last=0;
         if (errs<0) {
-            fprintf(stderr, "iniparser: memory allocation failure\n");
+            LOG(log_error, logtype_default, "iniparser: memory allocation failure");
             break ;
         }
     }