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

version 1.2, 2009/09/09 09:07:31 version 1.2.2.1, 2009/09/09 09:29:37
Line 24  static inline int cfgDbg(FILE *f, char *fmt, ...) Line 24  static inline int cfgDbg(FILE *f, char *fmt, ...)
         return ret;          return ret;
 }  }
   
   // cfgWrite() Write to file from config list
   static inline int cfgWrite(FILE *f, sl_config * __restrict cfg, int whitespace)
   {
           struct tagPair *av;
           time_t tim;
           char szTime[MAX_STR + 1];
           u_char szSection[MAX_STR + 1];
   
           bzero(szSection, MAX_STR + 1);
   
           bzero(szTime, MAX_STR + 1);
           time(&tim);
           strftime(szTime, MAX_STR, "(UTC) %Y-%m-%d %H:%M:%S", gmtime(&tim));
           if (!cfgDbg(f, "## Write Config :: %s\n#\n", szTime)) {
                   LOGERR;
                   return -1;
           }
   
           for (av = cfg->slh_first; av; av = av->sle_next) {
                   if (av->psSection && strcmp((char*) av->psSection, (char*) szSection)) {
                           strlcpy((char*) szSection, (char*) av->psSection, MAX_STR + 1);
                           if (!cfgDbg(f, "\n[%s]\n", av->psSection)) {
                                   LOGERR;
                                   return -1;
                           }
                   }
                   if (!av->psSection && *szSection) {
                           bzero(szSection, MAX_STR + 1);
                           if (!cfgDbg(f, "\n[]\n")) {
                                   LOGERR;
                                   return -1;
                           }
                   }
   
                   if (whitespace) {
                           if (!cfgDbg(f, "%s = %s\n", av->psAttribute, av->psValue)) {
                                   LOGERR;
                                   return -1;
                           }
                   } else {
                           if (!cfgDbg(f, "%s=%s\n", av->psAttribute, av->psValue)) {
                                   LOGERR;
                                   return -1;
                           }
                   }
           }
   
           bzero(szTime, MAX_STR + 1);
           time(&tim);
           strftime(szTime, MAX_STR, "(UTC) %Y-%m-%d %H:%M:%S", gmtime(&tim));
           if (!cfgDbg(f, "\n#\n## Done. :: %s\n", szTime)) {
                   LOGERR;
                   return -1;
           }
   
           return 0;
   }
   
 // -----------------------------------------  // -----------------------------------------
   
 /*  /*
Line 148  int ReadConfig(FILE *f, sl_config * __restrict cfg) Line 206  int ReadConfig(FILE *f, sl_config * __restrict cfg)
 */  */
 int WriteConfig(FILE *f, sl_config * __restrict cfg)  int WriteConfig(FILE *f, sl_config * __restrict cfg)
 {  {
        struct tagPair *av;        return cfgWrite(f, cfg, 1);
        time_t tim;}
        char szTime[MAX_STR + 1]; 
        u_char szSection[MAX_STR + 1]; 
   
        bzero(szSection, MAX_STR + 1);/*
 * cfg_WriteConfig() Write to file from items in config list without whitespaces!
        bzero(szTime, MAX_STR + 1); * @f = file resource
        time(&tim); * @cfg = Head list element
        strftime(szTime, MAX_STR, "(UTC) %Y-%m-%d %H:%M:%S", gmtime(&tim)); * return: 0 ok; -1 error:: can`t write to file
        if (!cfgDbg(f, "## Write Config :: %s\n#\n", szTime)) {*/
                LOGERR;int cfg_WriteConfig(FILE *f, sl_config * __restrict cfg)
                return -1;{
        }        return cfgWrite(f, cfg, 0);
 
        for (av = cfg->slh_first; av; av = av->sle_next) { 
                if (av->psSection && strcmp((char*) av->psSection, (char*) szSection)) { 
                        strlcpy((char*) szSection, (char*) av->psSection, MAX_STR + 1); 
                        if (!cfgDbg(f, "\n[%s]\n", av->psSection)) { 
                                LOGERR; 
                                return -1; 
                        } 
                } 
                if (!av->psSection && *szSection) { 
                        bzero(szSection, MAX_STR + 1); 
                        if (!cfgDbg(f, "\n[]\n")) { 
                                LOGERR; 
                                return -1; 
                        } 
                } 
 
                if (!cfgDbg(f, "%s = %s\n", av->psAttribute, av->psValue)) { 
                        LOGERR; 
                        return -1; 
                } 
        } 
 
        bzero(szTime, MAX_STR + 1); 
        time(&tim); 
        strftime(szTime, MAX_STR, "(UTC) %Y-%m-%d %H:%M:%S", gmtime(&tim)); 
        if (!cfgDbg(f, "\n#\n## Done. :: %s\n", szTime)) { 
                LOGERR; 
                return -1; 
        } 
 
        return 0; 
 }  }

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


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