Platon Technologies
not logged in Login Registration
EnglishSlovak
open source software development celebrating 10 years of open source development! Saturday, October 17, 2026

Diff for libcfg+/src/cfgfile.c between version 1.5 and 1.6

version 1.5, 2001/12/08 18:23:52 version 1.6, 2001/12/16 20:44:37
Line 1 
Line 1 
   #include <stdlib.h>
   #include <string.h>
 #include <unistd.h>  #include <unistd.h>
   
   #include "str/strdyn.h"
   #include "str/strplus.h"
 #include "str/dynfgets.h"  #include "str/dynfgets.h"
   
 static int cfg_cfgfile_get_next_opt(const CFG_CONTEXT con);  #include "cfg.h"
 static int cfgfile_set_currents(const CFG_CONTEXT con, char *buf);  #include "shared.h"
   
 static int get_multi_line(const CFG_CONTEXT con, char **buf);  static int get_multi_line(const CFG_CONTEXT con, char **buf);
   
 static int cfg_cfgfile_get_next_opt(const CFG_CONTEXT con)  int cfg_cfgfile_get_next_opt(const CFG_CONTEXT con)
 {  {
         char *buf;          char *buf;
         int ret_val;          int ret_val;
Line 42  static int cfg_cfgfile_get_next_opt(cons
Line 47  static int cfg_cfgfile_get_next_opt(cons
 #if 0 && defined(DEBUG) && DEBUG  #if 0 && defined(DEBUG) && DEBUG
                 printf("read_multi_line<%s>\n", buf);                  printf("read_multi_line<%s>\n", buf);
 #endif  #endif
                 free_currents(con);                  __cfg_free_currents(con);
   
                 if (cfgfile_set_currents(con, buf) == 0)                  if (__cfg_cfgfile_set_currents(con, buf) == 0)
                         return CFG_ERROR_NOMEM;                          return CFG_ERROR_NOMEM;
   
                 free(buf);                  free(buf);
   
                 ret = process_currents(con, &ret_val, NULL);                  ret = __cfg_process_currents(con, &ret_val, NULL);
   
                 if (ret != CFG_OK)                  if (ret != CFG_OK)
                         return ret;                          return ret;
Line 62  static int cfg_cfgfile_get_next_opt(cons
Line 67  static int cfg_cfgfile_get_next_opt(cons
 }  }
   
 /*  /*
  * cfgfile_set_curents()  
  *  
  * Function allocate and initialize variables con->cur_opt and con->cur_arg  
  * according to input parameter buf.  
  * Returns 1 on success, 0 on error (not enough memory).  
  */  
   
 static int cfgfile_set_currents(const CFG_CONTEXT con, char *buf)  
 {  
         register char **pos;  
         register char *s_sep, *s_tmp;  
         register int size;  
   
         for (s_sep = NULL, size = 0, pos = con->file_option_arg_separator;  
                         pos != NULL && *pos != NULL;  
                         pos++) {  
   
                 if ((s_tmp = strstr(buf, *pos)) != NULL)  
                         if (s_sep == NULL || s_tmp < s_sep  
                                         || (s_tmp == s_sep && strlen(*pos) > size)) {  
                                 s_sep = s_tmp;  
                                 size = strlen(*pos);  
                         }  
         }  
   
         if (s_sep == NULL) {  
                 con->cur_arg = NULL;  
   
                 con->cur_opt = strdup(buf);  
                 if (con->cur_opt == NULL)  
                         return 0;  
         }  
         else {  
                 con->cur_opt = (char *) malloc((s_sep - buf + 1) * sizeof(char));  
                 if (con->cur_opt == NULL)  
                         return 0;  
   
                 strncpy(con->cur_opt, buf, s_sep - buf);  
                 con->cur_opt[s_sep - buf] = '\0';  
   
                 if ((con->cur_arg = strdup(s_sep + size)) == NULL)  
                         return 0;  
   
                 str_right_trim(con->cur_opt);  
                 str_left_trim(con->cur_arg);  
         }  
   
         return 1;  
 }  
   
 /*  
  * get_multi_line()   * get_multi_line()
  *   *
  * Gets single line from file. If line continues on next line, returns   * Gets single line from file. If line continues on next line, returns
Line 121  static int cfgfile_set_currents(const CF
Line 75  static int cfgfile_set_currents(const CF
  * level should determine that fact using feof() function.   * level should determine that fact using feof() function.
  */   */
   
 int get_multi_line(const CFG_CONTEXT con, char **buf)  static int get_multi_line(const CFG_CONTEXT con, char **buf)
 {  {
         register char **ar = NULL;          register char **ar = NULL;
         register char *my_buf = NULL;          register char *my_buf = NULL;

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

Platon Group <platon@platon.org> http://platon.org/
Copyright © 2002-2006 Platon Group
Site powered by Metafox CMS
Go to Top