Diff for /libaitcfg/src/parse.c between versions 1.1 and 1.2

version 1.1, 2008/08/28 13:17:41 version 1.2, 2009/09/09 09:07:31
Line 1 Line 1
   /*************************************************************************
   * (C) 2008 AITNET ltd - Sofia/Bulgaria - <misho@aitbg.com>
   *  by Michael Pounov <misho@openbsd-bg.org>
   *
   * $Author$
   * $Id$
   *
   *************************************************************************/
 #include "global.h"  #include "global.h"
 #include "aitcfg.h"  #include "aitcfg.h"
 #include "tools.h"  #include "tools.h"
Line 55  int ReadConfig(FILE *f, sl_config * __restrict cfg) Line 63  int ReadConfig(FILE *f, sl_config * __restrict cfg)
                 if (*szLine == '[') {                  if (*szLine == '[') {
                         pos = strlen((char*) szLine) - 1;                          pos = strlen((char*) szLine) - 1;
                         if (szLine[pos] != ']') {                          if (szLine[pos] != ']') {
   #ifdef __DEBUG
                                 cfgDbg(stdout, "WARNING:: Ignore section %s ... not closed breket\n", szLine);                                  cfgDbg(stdout, "WARNING:: Ignore section %s ... not closed breket\n", szLine);
   #endif
                         } else {                          } else {
                                 szLine[pos] = 0;                                   szLine[pos] = 0; 
                                 strncpy((char*) szSection, (char*) szLine + 1, MAX_STR);                                  strncpy((char*) szSection, (char*) szLine + 1, MAX_STR);
Line 69  int ReadConfig(FILE *f, sl_config * __restrict cfg) Line 79  int ReadConfig(FILE *f, sl_config * __restrict cfg)
                 // Devide pairs                  // Devide pairs
                 pos = strchr((char*) szLine, '=') ? strchr((char*) szLine, '=') - (char*) szLine : 0;                  pos = strchr((char*) szLine, '=') ? strchr((char*) szLine, '=') - (char*) szLine : 0;
                 if (!pos) {                  if (!pos) {
   #ifdef __DEBUG
                         cfgDbg(stdout, "WARNING:: Ignore a/v %s ... format error!\n", szLine);                          cfgDbg(stdout, "WARNING:: Ignore a/v %s ... format error!\n", szLine);
   #endif
                         continue;                          continue;
                 } else {                  } else {
                         av = malloc(sizeof(struct tagPair));                          av = malloc(sizeof(struct tagPair));
Line 77  int ReadConfig(FILE *f, sl_config * __restrict cfg) Line 89  int ReadConfig(FILE *f, sl_config * __restrict cfg)
                                 LOGERR;                                  LOGERR;
                                 return -1;                                  return -1;
                         } else {                          } else {
                                   memset(av, 0, sizeof(struct tagPair));
                                 // added new element                                  // added new element
                                 av->sle_next = cfg->slh_first;                                  av->sle_next = cfg->slh_first;
                                 cfg->slh_first = av;                                  cfg->slh_first = av;
Line 89  int ReadConfig(FILE *f, sl_config * __restrict cfg) Line 102  int ReadConfig(FILE *f, sl_config * __restrict cfg)
                                         free(av);                                          free(av);
                                         return -1;                                          return -1;
                                 } else                                  } else
                                        strcpy((char*) av->psSection, (char*) szSection);                                        strlcpy((char*) av->psSection, (char*) szSection, strlen((char*) szSection) + 1);
                         } else                          } else
                                 av->psSection = NULL;                                  av->psSection = NULL;
   
Line 110  int ReadConfig(FILE *f, sl_config * __restrict cfg) Line 123  int ReadConfig(FILE *f, sl_config * __restrict cfg)
                                 free(av);                                  free(av);
                                 return -1;                                  return -1;
                         } else                          } else
                                strcpy((char*) av->psAttribute, (char*) psAttr);                                strlcpy((char*) av->psAttribute, (char*) psAttr, strlen((char*) psAttr) + 1);
                         // added value to element                          // added value to element
                         av->psValue = malloc(strlen((char*) psVal) + 1);                          av->psValue = malloc(strlen((char*) psVal) + 1);
                         if (!av->psValue) {                          if (!av->psValue) {
Line 120  int ReadConfig(FILE *f, sl_config * __restrict cfg) Line 133  int ReadConfig(FILE *f, sl_config * __restrict cfg)
                                 free(av);                                  free(av);
                                 return -1;                                  return -1;
                         } else                          } else
                                strcpy((char*) av->psValue, (char*) psVal);                                strlcpy((char*) av->psValue, (char*) psVal, strlen((char*) psVal) + 1);
                 }                  }
         }          }
   
Line 152  int WriteConfig(FILE *f, sl_config * __restrict cfg) Line 165  int WriteConfig(FILE *f, sl_config * __restrict cfg)
   
         for (av = cfg->slh_first; av; av = av->sle_next) {          for (av = cfg->slh_first; av; av = av->sle_next) {
                 if (av->psSection && strcmp((char*) av->psSection, (char*) szSection)) {                  if (av->psSection && strcmp((char*) av->psSection, (char*) szSection)) {
                        bzero(szSection, MAX_STR + 1);                        strlcpy((char*) szSection, (char*) av->psSection, MAX_STR + 1);
                        strcpy((char*) szSection, (char*) av->psSection); 
                         if (!cfgDbg(f, "\n[%s]\n", av->psSection)) {                          if (!cfgDbg(f, "\n[%s]\n", av->psSection)) {
                                 LOGERR;                                  LOGERR;
                                 return -1;                                  return -1;

Removed from v.1.1  
changed lines
  Added in v.1.2


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>