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

Diff for libcfg+/src/shared.c between version 1.17 and 1.18

version 1.17, 2002/06/10 20:13:54 version 1.18, 2002/06/23 10:48:46
Line 61 
Line 61 
 /* Static function declarations {{{ */  /* Static function declarations {{{ */
 static int search_cur_opt_idx(const CFG_CONTEXT con);  static int search_cur_opt_idx(const CFG_CONTEXT con);
 static int add_to_used_opt_idx(const CFG_CONTEXT con, int opt_idx);  static int add_to_used_opt_idx(const CFG_CONTEXT con, int opt_idx);
 static int store_multi_arg(const int type, const char **multi_arg, void ***ar);  static int store_multi_arg(
 static int store_single_arg(const int type, const char *arg, const void *where);                  const int       type,
 static int split_multi_arg(const CFG_CONTEXT con, char *arg, char ***ar);                  const char      **multi_arg,
 static int unquote_single_arg(const CFG_CONTEXT con, char *arg);                  void            ***ar);
   static int store_single_arg(
                   const int       type,
                   const char      *arg,
                   const void      *where);
   static int split_multi_arg(
                   char            *arg,
                   char            ***ar,
                   char            **quote_prefix_ar,
                   char            **quote_postfix_ar,
                   char            **separator_ar);
   static int unquote_single_arg(
                   char            *arg,
                   char            **quote_prefix_ar,
                   char            **quote_postfix_ar);
 /* }}} */  /* }}} */
   
 /*  /*
Line 92  __cfg_process_currents(con, ret_val, arg
Line 106  __cfg_process_currents(con, ret_val, arg
 { /* {{{ */  { /* {{{ */
         register int ret = 0;          register int ret = 0;
         register int opt_idx;          register int opt_idx;
         register int opt_data_type, opt_f_multi, opt_f_multi_sep;          register int opt_type, opt_data_type, opt_f_multi, opt_f_multi_sep;
           register char **quote_prefix_ar, **quote_postfix_ar, **separator_ar;
   
         *ret_val = 0;          *ret_val = 0;
         if (arg_used != NULL)          if (arg_used != NULL)
Line 122  __cfg_process_currents(con, ret_val, arg
Line 137  __cfg_process_currents(con, ret_val, arg
 #endif  #endif
   
         if (opt_idx < 0)          if (opt_idx < 0)
                 return CFG_ERROR_UNKNOWN;                  return CFG_ERROR_UNKNOWN; /* unknown option reached */
   
         if (! (con->flags & CFG_IGNORE_MULTI)          if (! (con->flags & CFG_IGNORE_MULTI)
                         && ! (con->options[opt_idx].type & CFG_MULTI)) {                          && ! (con->options[opt_idx].type & CFG_MULTI)) {
Line 136  __cfg_process_currents(con, ret_val, arg
Line 151  __cfg_process_currents(con, ret_val, arg
   
         /* Setting others opt_XXX constants according to *opt_idx. */          /* Setting others opt_XXX constants according to *opt_idx. */
         /* opt_data_type - option data type, opt_f_XXX - option flags */          /* opt_data_type - option data type, opt_f_XXX - option flags */
         opt_data_type = con->options[opt_idx].type & CFG_DATA_TYPE_MASK;          opt_type        = con->options[opt_idx].type;
         opt_f_multi = con->options[opt_idx].type & CFG_MULTI;          opt_data_type   = opt_type & CFG_DATA_TYPE_MASK;
         opt_f_multi_sep = con->options[opt_idx].type &          opt_f_multi     = opt_type & CFG_MULTI;
                 (CFG_MULTI_SEPARATED & ~CFG_MULTI);          opt_f_multi_sep = opt_type & (CFG_MULTI_SEPARATED & ~CFG_MULTI);
   
           if (con->type == CFG_LINE) {
                   quote_prefix_ar  = con->prop[CFG_LINE_QUOTE_PREFIX];
                   quote_postfix_ar = con->prop[CFG_LINE_QUOTE_POSTFIX];
                   separator_ar     = opt_type & CFG_LEFTOVER_ARGS
                           ? con->prop[CFG_LINE_LEFTOVER_MULTI_VALS_SEPARATOR]
                           : con->prop[CFG_LINE_NORMAL_MULTI_VALS_SEPARATOR];
           }
           else {
                   quote_prefix_ar  = con->prop[CFG_FILE_QUOTE_PREFIX];
                   quote_postfix_ar = con->prop[CFG_FILE_QUOTE_POSTFIX];
                   separator_ar     = opt_type & CFG_LEFTOVER_ARGS
                           ? con->prop[CFG_FILE_LEFTOVER_MULTI_VALS_SEPARATOR]
                           : con->prop[CFG_FILE_NORMAL_MULTI_VALS_SEPARATOR];
           }
   
         switch (opt_data_type) {          switch (opt_data_type) {
                 default:                  default:
Line 167  __cfg_process_currents(con, ret_val, arg
Line 197  __cfg_process_currents(con, ret_val, arg
                 case CFG_DOUBLE:                  case CFG_DOUBLE:
   
                         if (con->cur_arg == NULL)                          if (con->cur_arg == NULL)
                                 return CFG_ERR_NOARG;                                  return CFG_ERROR_NOARG;
   
                         {  
                                 if (opt_f_multi) {  
                                         char **add;  
                                         char *static_add[2] = {NULL, NULL};  
   
                                         if (opt_f_multi_sep) {                          if (opt_f_multi) {
                                                 ret = split_multi_arg(con, con->cur_arg, &add);                                  char **add;
                                   char *static_add[2] = {NULL, NULL};
   
                                                 if (ret != CFG_OK) {                                  if (opt_f_multi_sep) {
                                                         strdyn_safe_free(add);  
                                                         return ret;  
                                                 }  
                                         }  
                                         else {  
                                                 add = static_add;  
                                                 add[0] = con->cur_arg;  
                                         }  
   
                                         ret = store_multi_arg(opt_data_type,                                          ret = split_multi_arg(con->cur_arg, &add,
                                                         (const char **) add,                                                          quote_prefix_ar, quote_postfix_ar, separator_ar);
                                                         con->options[opt_idx].value);  
   
                                         if (add != static_add)                                          if (ret != CFG_OK) {
                                                 strdyn_free((char **) add);                                                  strdyn_safe_free(add);
                                                   return ret;
                                           }
                                 }                                  }
                                 else {                                  else {
                                         if ((ret = unquote_single_arg(con, con->cur_arg)) != CFG_OK)                                          /*
                                                 return ret;                                             if (con->type == CFG_FILE
                                              && opt_type & CFG_LEFTOVER_ARGS) {
                                         ret = store_single_arg(opt_data_type, con->cur_arg,                                             char *leftover_file_separator[3] = {" ", "\t", NULL};
                                                         con->options[opt_idx].value);                                             ret = split_multi_arg(con->cur_arg, &add,
                                              con->prop[CFG_FILE_QUOTE_PREFIX],
                                              con->prop[CFG_FILE_QUOTE_POSTFIX],
                                              leftover_file_separator);
                                              }
                                              else {
                                              */
                                           add = static_add;
                                           add[0] = con->cur_arg;
                                           /*}*/
                                 }                                  }
   
                                   ret = store_multi_arg(opt_data_type,
                                                   (const char **) add,
                                                   con->options[opt_idx].value);
   
                                   if (add != static_add)
                                           strdyn_free((char **) add);
                           }
                           else {
                                   ret = unquote_single_arg(con->cur_arg,
                                                   quote_prefix_ar, quote_postfix_ar);
   
                                 if (ret != CFG_OK)                                  if (ret != CFG_OK)
                                         return ret;                                          return ret;
   
                                   ret = store_single_arg(opt_data_type, con->cur_arg,
                                                   con->options[opt_idx].value);
                         }                          }
   
                           if (ret != CFG_OK)
                                   return ret;
   
                         if (arg_used != NULL)                          if (arg_used != NULL)
                                 *arg_used = 1;                                  *arg_used = 1;
                         break;                          break;
Line 215  __cfg_process_currents(con, ret_val, arg
Line 260  __cfg_process_currents(con, ret_val, arg
                 case CFG_STRING:                  case CFG_STRING:
   
                         if (con->cur_arg == NULL)                          if (con->cur_arg == NULL)
                                 return CFG_ERR_NOARG;                                  return CFG_ERROR_NOARG;
   
                         if (con->options[opt_idx].value != NULL) {                          if (con->options[opt_idx].value != NULL) {
                                 if (opt_f_multi) {                                  if (opt_f_multi) {
Line 224  __cfg_process_currents(con, ret_val, arg
Line 269  __cfg_process_currents(con, ret_val, arg
   
                                         if (opt_f_multi_sep) {                                          if (opt_f_multi_sep) {
                                                 char **ar;                                                  char **ar;
                                                 ret = split_multi_arg(con, con->cur_arg, &ar);                                                  ret = split_multi_arg(con->cur_arg, &ar,
                                                                   quote_prefix_ar, quote_postfix_ar,
                                                                   separator_ar);
   
                                                 if (ret != CFG_OK) {                                                  if (ret != CFG_OK) {
                                                         strdyn_safe_free(ar);                                                          strdyn_safe_free(ar);
                                                         return ret;                                                          return ret;
Line 236  __cfg_process_currents(con, ret_val, arg
Line 284  __cfg_process_currents(con, ret_val, arg
                                                 strdyn_free(ar);                                                  strdyn_free(ar);
                                         }                                          }
                                         else {                                          else {
                                                 ret = unquote_single_arg(con, con->cur_arg);                                                  ret = unquote_single_arg(con->cur_arg,
                                                                   quote_prefix_ar, quote_postfix_ar);
   
                                                 if (ret != CFG_OK)                                                  if (ret != CFG_OK)
                                                         return ret;                                                          return ret;
   
Line 245  __cfg_process_currents(con, ret_val, arg
Line 295  __cfg_process_currents(con, ret_val, arg
                                         }                                          }
                                 }                                  }
                                 else {                                  else {
                                         if ((ret = unquote_single_arg(con, con->cur_arg)) != CFG_OK)                                          ret = unquote_single_arg(con->cur_arg,
                                                           quote_prefix_ar, quote_postfix_ar);
   
                                           if (ret != CFG_OK)
                                                 return ret;                                                  return ret;
   
                                         *((char **) con->options[opt_idx].value) =                                          *((char **) con->options[opt_idx].value) =
Line 673  store_single_arg(type, arg, where)
Line 726  store_single_arg(type, arg, where)
 #if HAVE_ERRNO_H  #if HAVE_ERRNO_H
                         if (double_val == 0.0 && errno == ERANGE)                          if (double_val == 0.0 && errno == ERANGE)
 #else  #else
                         if (double_val == 0.0 && end == arg)                                  if (double_val == 0.0 && end == arg)
 #endif  #endif
                                 return CFG_ERROR_OVERFLOW;                                          return CFG_ERROR_OVERFLOW;
                         break;                          break;
         }          }
   
Line 750  store_single_arg(type, arg, where)
Line 803  store_single_arg(type, arg, where)
  */   */
   
         static int          static int
 split_multi_arg(con, arg, ar)  split_multi_arg(arg, ar, quote_prefix_ar, quote_postfix_ar, separator_ar)
         const CFG_CONTEXT con;          char    *arg;
         char              *arg;          char    ***ar;
         char              ***ar;          char    **quote_prefix_ar;
           char    **quote_postfix_ar;
           char    **separator_ar;
 { /* {{{ */  { /* {{{ */
         register int i;          register int i;
         int sep_ar_idx, quote_prefix_idx, sep_size, tmp_sep_size;          int sep_ar_idx, quote_idx, sep_size, tmp_sep_size;
         char *p_quote, *p_sep, *tmp_s, *arg_base;          char *p_quote, *p_sep, *tmp_s;
         register char **sep_ar;          char *arg_base = arg;
   
         if ((*ar = strdyn_create()) == NULL)          if ((*ar = strdyn_create()) == NULL)
                 return CFG_ERROR_NOMEM;                  return CFG_ERROR_NOMEM;
   
         arg_base = arg;  
         sep_ar   =  con->prop[con->type == CFG_LINE  
                 ? CFG_LINE_MULTI_VALS_SEPARATOR  
                 : CFG_FILE_MULTI_VALS_SEPARATOR];  
   
         do {          do {
   
                 /* Searching first quotation string (p_quote)                  /* Searching first quotation string (p_quote)
                    and set quotation variables */                     and set quotation variables */
                 p_quote    = strdyn_str2(arg,                  p_quote    = strdyn_str2(arg, quote_prefix_ar, &quote_idx);
                                 con->prop[CFG_QUOTE_PREFIX], &quote_prefix_idx);  
                 p_sep      = NULL; /* pointer to separator */                  p_sep      = NULL; /* pointer to separator */
                 sep_ar_idx = -1;   /* index of separator */                  sep_ar_idx = -1;   /* index of separator */
                 sep_size   =  0;   /* length of separator string */                  sep_size   =  0;   /* length of separator string */
   
                 /* Searching first separator string (p_sep) */                  /* Searching first separator string (p_sep) */
                 for (i = 0; sep_ar[i] != NULL; i++) {                  for (i = 0; separator_ar[i] != NULL; i++) {
                         if ((tmp_s = str_white_str(arg, sep_ar[i], &tmp_sep_size)) != NULL                          if ((tmp_s = str_white_str(arg, separator_ar[i], &tmp_sep_size))
                                         && (p_sep == NULL || tmp_s < p_sep)) {                                          != NULL && (p_sep == NULL || tmp_s < p_sep)) {
                                 p_sep      = tmp_s;                                  p_sep      = tmp_s;
                                 sep_ar_idx = i;                                  sep_ar_idx = i;
                                 sep_size   = tmp_sep_size;                                  sep_size   = tmp_sep_size;
Line 796  split_multi_arg(con, arg, ar)
Line 845  split_multi_arg(con, arg, ar)
                         register char *end_ptr, *prefix, *postfix;                          register char *end_ptr, *prefix, *postfix;
                         register int prefix_len, postfix_len;                          register int prefix_len, postfix_len;
   
                         prefix  = con->prop[CFG_QUOTE_PREFIX ][quote_prefix_idx];                          if (quote_idx < 0 /* not optimized */
                         postfix = con->prop[CFG_QUOTE_POSTFIX][quote_prefix_idx];                                          || quote_idx > strdyn_get_size(quote_prefix_ar) - 1
                                           || quote_idx > strdyn_get_size(quote_postfix_ar) - 1
                         if (prefix == NULL || postfix == NULL)                                          || (prefix  = quote_prefix_ar[quote_idx]) == NULL
                                           || (postfix = quote_postfix_ar[quote_idx]) == NULL)
                                 return CFG_ERROR_INTERNAL;                                  return CFG_ERROR_INTERNAL;
   
                         prefix_len  = strlen(prefix);                          prefix_len  = strlen(prefix);
Line 850  split_multi_arg(con, arg, ar)
Line 900  split_multi_arg(con, arg, ar)
  */   */
   
         static int          static int
 unquote_single_arg(con, arg)  unquote_single_arg(arg, quote_prefix_ar, quote_postfix_ar)
         const CFG_CONTEXT con;          char    *arg;
         char              *arg;          char    **quote_prefix_ar;
           char    **quote_postfix_ar;
 { /* {{{ */  { /* {{{ */
         register char *p_quote;          register char *p_quote;
         int quote_prefix_idx;          int quote_idx;
   
         do {          do {
                 p_quote = strdyn_str2(arg,                  p_quote = strdyn_str2(arg, quote_prefix_ar, &quote_idx);
                                 con->prop[CFG_QUOTE_PREFIX], &quote_prefix_idx);  
   
                 /* If beginning of quotation was found */                  /* If beginning of quotation was found */
                 if (p_quote != NULL) {                  if (p_quote != NULL) {
                         register char *end_ptr, *prefix, *postfix;                          register char *end_ptr, *prefix, *postfix;
                         register int prefix_len, postfix_len;                          register int prefix_len, postfix_len;
   
                         prefix  = con->prop[CFG_QUOTE_PREFIX ][quote_prefix_idx];                          if (quote_idx < 0 /* not optimized */
                         postfix = con->prop[CFG_QUOTE_POSTFIX][quote_prefix_idx];                                          || quote_idx > strdyn_get_size(quote_prefix_ar) - 1
                                           || quote_idx > strdyn_get_size(quote_postfix_ar) - 1
                         if (prefix == NULL || postfix == NULL)                                          || (prefix  = quote_prefix_ar[quote_idx]) == NULL
                                           || (postfix = quote_postfix_ar[quote_idx]) == NULL)
                                 return CFG_ERROR_INTERNAL;                                  return CFG_ERROR_INTERNAL;
   
                         prefix_len  = strlen(prefix);                          prefix_len  = strlen(prefix);

Legend:
Removed from v.1.17  
changed lines
  Added in v.1.18

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