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.13 and 1.14

version 1.13, 2002/05/27 16:43:40 version 1.14, 2002/05/29 15:12:11
Line 17 
Line 17 
   
 /* $Id$ */  /* $Id$ */
   
   /* Includes {{{ */
 #include "config.h"  #include "config.h"
   
 #if STDC_HEADERS  #if STDC_HEADERS
Line 55 
Line 56 
 #include "str/strdyn.h"  #include "str/strdyn.h"
   
 #include "cfg+.h"  #include "cfg+.h"
   /* }}} */
   
   /* 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(const int type, const char **multi_arg, void ***ar);
 static int store_single_arg(const int type, const char *arg, const void *where);  static int store_single_arg(const int type, const char *arg, const void *where);
 static int split_multi_arg(const CFG_CONTEXT con, char *arg, char ***ar);  static int split_multi_arg(const CFG_CONTEXT con, char *arg, char ***ar);
 static int unquote_single_arg(const CFG_CONTEXT con, char *arg);  static int unquote_single_arg(const CFG_CONTEXT con, char *arg);
   /* }}} */
   
 /*  /*
  * EXTERN FUNCTIONS   * EXTERN FUNCTIONS
Line 70  static int unquote_single_arg(const CFG_
Line 74  static int unquote_single_arg(const CFG_
         void          void
 __cfg_free_currents(con)  __cfg_free_currents(con)
         const CFG_CONTEXT con;          const CFG_CONTEXT con;
 {  { /* {{{ */
         if (con->cur_opt != NULL)          if (con->cur_opt != NULL)
                 free(con->cur_opt);                  free(con->cur_opt);
         if (con->cur_arg != NULL)          if (con->cur_arg != NULL)
Line 78  __cfg_free_currents(con)
Line 82  __cfg_free_currents(con)
   
         con->cur_opt = con->cur_arg = NULL;          con->cur_opt = con->cur_arg = NULL;
         con->cur_opt_type = CFG_NONE_OPTION;          con->cur_opt_type = CFG_NONE_OPTION;
 }  } /* }}} */
   
         int          int
 __cfg_process_currents(con, ret_val, arg_used)  __cfg_process_currents(con, ret_val, arg_used)
         const CFG_CONTEXT con;          const CFG_CONTEXT con;
         int               *ret_val;          int               *ret_val;
         int               *arg_used;          int               *arg_used;
 {  { /* {{{ */
         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_data_type, opt_f_multi, opt_f_multi_sep;
Line 257  __cfg_process_currents(con, ret_val, arg
Line 261  __cfg_process_currents(con, ret_val, arg
         *ret_val = con->options[opt_idx].val;          *ret_val = con->options[opt_idx].val;
   
         return CFG_OK;          return CFG_OK;
 }  } /* }}} */
   
         int          int
 __cfg_cmdline_set_currents(con)  __cfg_cmdline_set_currents(con)
         const CFG_CONTEXT con;          const CFG_CONTEXT con;
 {  { /* {{{ */
         register int i, size;          register int i, size;
         register char *s, *s_sep, *s_tmp;          register char *s, *s_sep, *s_tmp;
   
Line 286  __cfg_cmdline_set_currents(con)
Line 290  __cfg_cmdline_set_currents(con)
         if (size == 0) {          if (size == 0) {
                 con->cur_opt_type = CFG_NONE_OPTION;                  con->cur_opt_type = CFG_NONE_OPTION;
         }          }
         else if (size < 0) {          else if (size < 0) { /* Short option prefix */
                 s += -size;                  s += -size;
                 s_sep = s + 1;                  s_sep = strlen(s) > 0 ? s + 1 : s;
   
                 if (strlen(s_sep) > 0) {                  if (strlen(s_sep) > 0) {
                         con->cur_opt_type = CFG_SHORT_OPTION + CFG_SHORT_OPTIONS;                          con->cur_opt_type = CFG_SHORT_OPTION + CFG_SHORT_OPTIONS;
Line 308  __cfg_cmdline_set_currents(con)
Line 312  __cfg_cmdline_set_currents(con)
                                 con->cur_arg = NULL;                                  con->cur_arg = NULL;
                 }                  }
         }          }
         else {          else { /* Long option prefix */
                 con->cur_opt_type = CFG_LONG_OPTION;                  con->cur_opt_type = CFG_LONG_OPTION;
   
                 s += size;                  s += size;
Line 351  __cfg_cmdline_set_currents(con)
Line 355  __cfg_cmdline_set_currents(con)
   
         if (con->cur_opt_type == CFG_NONE_OPTION) {          if (con->cur_opt_type == CFG_NONE_OPTION) {
                 register char *tmp_str;                  register char *tmp_str;
                   tmp_str      = con->cur_opt;
                 tmp_str =con->cur_opt;  
                 con->cur_opt = con->cur_arg;                  con->cur_opt = con->cur_arg;
                 con->cur_arg = tmp_str;                  con->cur_arg = tmp_str;
         }          }
   
         return 1;          return 1;
 }  } /* }}} */
   
         int          int
 __cfg_cfgfile_set_currents(con, buf)  __cfg_cfgfile_set_currents(con, buf)
         const CFG_CONTEXT con;          const CFG_CONTEXT con;
         char              *buf;          char              *buf;
 {  { /* {{{ */
         register char **pos;          register char **pos;
         register char *s_sep, *s_tmp;          register char *s_sep, *s_tmp;
         register int size;          register int size;
Line 404  __cfg_cfgfile_set_currents(con, buf)
Line 407  __cfg_cfgfile_set_currents(con, buf)
         }          }
   
         return 1;          return 1;
 }  } /* }}} */
   
 /*  /*
  * STATIC FUNCTIONS   * STATIC FUNCTIONS
Line 420  __cfg_cfgfile_set_currents(con, buf)
Line 423  __cfg_cfgfile_set_currents(con, buf)
         static int          static int
 search_cur_opt_idx(con)  search_cur_opt_idx(con)
         const CFG_CONTEXT con;          const CFG_CONTEXT con;
 {  { /* {{{ */
         register int i;          register int i;
   
         for (i = 0; con->options[i].cmdline_long_name != NULL          for (i = 0; con->options[i].cmdline_long_name != NULL
Line 431  search_cur_opt_idx(con)
Line 434  search_cur_opt_idx(con)
                         || con->options[i].val != 0;                          || con->options[i].val != 0;
                         i++)                          i++)
         {          {
                   if (con->type == CFG_CMDLINE) { /* Command line context type */
                 if (con->type == CFG_CMDLINE) {  
                         if ((con->cur_opt_type & CFG_LONG_OPTION && con->cur_opt != NULL                          if ((con->cur_opt_type & CFG_LONG_OPTION && con->cur_opt != NULL
                                                 && con->options[i].cmdline_long_name != NULL                                                  && con->options[i].cmdline_long_name != NULL
                                                 && ! strcmp(con->cur_opt,                                                  && ! strcmp(con->cur_opt,
                                                         con->options[i].cmdline_long_name))                                                          con->options[i].cmdline_long_name))
                                         || (con->cur_opt_type & CFG_SHORT_OPTION &&                                          || (con->cur_opt_type & CFG_SHORT_OPTION &&
                                                   con->cur_opt[0] != '\0' && /* to prevent '-' option */
                                                 con->cur_opt[0] == con->options[i].cmdline_short_name)                                                  con->cur_opt[0] == con->options[i].cmdline_short_name)
                                         || (con->cur_opt_type == CFG_NONE_OPTION &&                                          || (con->cur_opt_type == CFG_NONE_OPTION &&
                                                 con->options[i].type & CFG_LEFTOVER_ARGS))                                                  con->options[i].type & CFG_LEFTOVER_ARGS))
   
                                 return i;                                  return i;
                 }                  }
                 else { /* con->type == CFG_CFGFILE */                  else { /* Configuration file context type */
                         int len;                          int len;
   
                         if (con->cur_opt != NULL                          if (con->cur_opt != NULL
Line 452  search_cur_opt_idx(con)
Line 455  search_cur_opt_idx(con)
                                         && con->cur_opt == str_white_str(con->cur_opt,                                          && con->cur_opt == str_white_str(con->cur_opt,
                                                 (char *)(con->options[i].cfgfile_name), &len)                                                  (char *)(con->options[i].cfgfile_name), &len)
                                         && len == strlen(con->cur_opt))                                          && len == strlen(con->cur_opt))
                                 /* Old stuff:  
                                    && ! strcmp(con->cur_opt, con->options[i].cfgfile_name)) */  
   
                                 return i;                                  return i;
                 }                  }
         }          }
   
         return -1;          return -1;
 }  } /* }}} */
   
   
 /*  /*
Line 497  search_cur_opt_idx(con)
Line 498  search_cur_opt_idx(con)
 add_to_used_opt_idx(con, opt_idx)  add_to_used_opt_idx(con, opt_idx)
         const CFG_CONTEXT con;          const CFG_CONTEXT con;
         int               opt_idx;          int               opt_idx;
 {  { /* {{{ */
         int *p_i = NULL;          int *p_i = NULL;
   
         if (opt_idx < 0)          if (opt_idx < 0)
Line 540  add_to_used_opt_idx(con, opt_idx)
Line 541  add_to_used_opt_idx(con, opt_idx)
         *p_i = opt_idx;          *p_i = opt_idx;
   
         return 0;          return 0;
 }  } /* }}} */
   
 /*  /*
  * store_multi_arg()   * store_multi_arg()
Line 555  store_multi_arg(type, multi_arg, ar)
Line 556  store_multi_arg(type, multi_arg, ar)
         const int  type;          const int  type;
         const char **multi_arg;          const char **multi_arg;
         void       ***ar;          void       ***ar;
 {  { /* {{{ */
         register int ptr_len, item_len;          register int ptr_len, item_len;
         register int size_plus, size;          register int size_plus, size;
         register int k, ret;          register int k, ret;
Line 622  store_multi_arg(type, multi_arg, ar)
Line 623  store_multi_arg(type, multi_arg, ar)
         }          }
   
         return CFG_OK;          return CFG_OK;
 }  } /* }}} */
   
 /*  /*
  * store_single_arg()   * store_single_arg()
Line 636  store_single_arg(type, arg, where)
Line 637  store_single_arg(type, arg, where)
         const int  type;          const int  type;
         const char *arg;          const char *arg;
         const void *where;          const void *where;
 {  { /* {{{ */
         register long long_val = 0;          register long long_val = 0;
         register unsigned long ulong_val = 0;          register unsigned long ulong_val = 0;
         register double double_val = 0.0;          register double double_val = 0.0;
Line 735  store_single_arg(type, arg, where)
Line 736  store_single_arg(type, arg, where)
         }          }
   
         return CFG_OK;          return CFG_OK;
 }  } /* }}} */
   
         static int          static int
 split_multi_arg(con, arg, ar)  split_multi_arg(con, arg, ar)
         const CFG_CONTEXT con;          const CFG_CONTEXT con;
         char              *arg;          char              *arg;
         char              ***ar;          char              ***ar;
 {  { /* {{{ */
         register int i;          register int i;
         int sep_ar_idx, quote_prefix_idx, sep_size, tmp_sep_size;          int sep_ar_idx, quote_prefix_idx, sep_size, tmp_sep_size;
         char *p_quote, *p_sep, *tmp_s, *arg_base;          char *p_quote, *p_sep, *tmp_s, *arg_base;
Line 828  split_multi_arg(con, arg, ar)
Line 829  split_multi_arg(con, arg, ar)
                 return CFG_ERROR_NOMEM;                  return CFG_ERROR_NOMEM;
   
         return CFG_OK;          return CFG_OK;
 }  } /* }}} */
   
         static int          static int
 unquote_single_arg(con, arg)  unquote_single_arg(con, arg)
         const CFG_CONTEXT con;          const CFG_CONTEXT con;
         char              *arg;          char              *arg;
 {  { /* {{{ */
         return CFG_OK;          return CFG_OK;
 }  } /* }}} */
   
 /*  #if 0
    static int unquote_single_arg(const CFG_CONTEXT con, char *arg)  
   static int unquote_single_arg(const CFG_CONTEXT con, char *arg)
    {     {
    register int i, arg_len;     register int i, arg_len;
    register char *p_prefix, *p_postfix;     register char *p_prefix, *p_postfix;
Line 874  arg[arg_len - (p_prefix_len + p_postfix_
Line 876  arg[arg_len - (p_prefix_len + p_postfix_
 }  }
   
 return CFG_OK;  return CFG_OK;
 }  } /* }}} */
 */  
   #endif
   
   /* Modeline for ViM {{{
    * vim:set ts=4:
    * vim600:fdm=marker fdl=0 fdc=0:
    * }}} */
   

Legend:
Removed from v.1.13  
changed lines
  Added in v.1.14

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