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

Diff for libcfg+/src/cfg+.c between version 1.11 and 1.12

version 1.11, 2001/11/28 20:46:51 version 1.12, 2001/11/30 02:10:27
Line 6 
Line 6 
 #include "str/strplus.h"  #include "str/strplus.h"
 #include "cfg.h"  #include "cfg.h"
   
 static char *default_cmdline_stop_str[2] = { "--", NULL };  static char *default_line_stop_str[2] = { "--", NULL };
 static char *default_cfgfile_stop_str[2] = { "[", NULL };  static char *default_file_stop_str[2] = { "[", NULL };
 static char *default_cfgfile_comment_str[3] = { "#", ";", NULL };  static char *default_file_comment_str[3] = { "#", ";", NULL };
 static char *default_short_option_prefix[2] = { "-", NULL };  static char *default_short_option_prefix[2] = { "-", NULL };
 static char *default_long_option_prefix[2] = { "--", NULL };  static char *default_long_option_prefix[2] = { "--", NULL };
   static char *default_multi_separator[3] = { ",", ";", NULL };
 static char *default_line_option_arg_separator[2] = { "=", NULL };  static char *default_line_option_arg_separator[2] = { "=", NULL };
 static char *default_file_option_arg_separator[2] = { "=", NULL };  static char *default_file_option_arg_separator[2] = { "=", NULL };
   
   
 CFG_CONTEXT cfg_get_context(  CFG_CONTEXT cfg_get_context(struct cfg_option *options)
                                                 struct cfg_option *options  
                                                 )  
 {  {
         CFG_CONTEXT con;          CFG_CONTEXT con;
   
Line 27  CFG_CONTEXT cfg_get_context(
Line 26  CFG_CONTEXT cfg_get_context(
   
         memset(con, '\0', sizeof(*con));          memset(con, '\0', sizeof(*con));
   
         con->line_stop_str =          con->line_stop_str = strdyn_create_ar(default_line_stop_str);
                 strdyn_add_ar(con->line_stop_str, default_cmdline_stop_str);          con->file_stop_str = strdyn_create_ar(default_file_stop_str);
         con->file_stop_str =          con->comment_str = strdyn_create_ar(default_file_comment_str);
                 strdyn_add_ar(con->file_stop_str, default_cfgfile_stop_str);          con->short_option_prefix = strdyn_create_ar(default_short_option_prefix);
         con->comment_str =          con->long_option_prefix = strdyn_create_ar(default_long_option_prefix);
                 strdyn_add_ar(con->comment_str, default_cfgfile_comment_str);          con->multi_separator = strdyn_create_ar(default_multi_separator);
         con->short_option_prefix =  
                 strdyn_add_ar(con->short_option_prefix, default_short_option_prefix);  
         con->long_option_prefix =  
                 strdyn_add_ar(con->long_option_prefix, default_long_option_prefix);  
         con->line_option_arg_separator =          con->line_option_arg_separator =
                 strdyn_add_ar(con->line_option_arg_separator,                  strdyn_create_ar(default_line_option_arg_separator);
                                                                 default_line_option_arg_separator);  
         con->file_option_arg_separator =          con->file_option_arg_separator =
                 strdyn_add_ar(con->file_option_arg_separator,                  strdyn_create_ar(default_file_option_arg_separator);
                                                                 default_file_option_arg_separator);  
           /*
              con->line_stop_str =
              strdyn_add_ar(con->line_stop_str, default_line_stop_str);
              con->file_stop_str =
              strdyn_add_ar(con->file_stop_str, default_file_stop_str);
              con->comment_str =
              strdyn_add_ar(con->comment_str, default_file_comment_str);
              con->short_option_prefix =
              strdyn_add_ar(con->short_option_prefix, default_short_option_prefix);
              con->long_option_prefix =
              strdyn_add_ar(con->long_option_prefix, default_long_option_prefix);
              con->line_option_arg_separator =
              strdyn_add_ar(con->line_option_arg_separator,
              default_line_option_arg_separator);
              con->file_option_arg_separator =
              strdyn_add_ar(con->file_option_arg_separator,
              default_file_option_arg_separator);
            */
   
         if (con->line_stop_str == NULL          if (con->line_stop_str == NULL
                                                         || con->file_stop_str == NULL                                                          || con->file_stop_str == NULL
Line 107  void cfg_set_cmdline_context(
Line 119  void cfg_set_cmdline_context(
   
         con->cur_idx_tmp = con->flags & CFG_PROCESS_FIRST ? 0 : 1;          con->cur_idx_tmp = con->flags & CFG_PROCESS_FIRST ? 0 : 1;
         con->cur_idx = 0;          con->cur_idx = 0;
   
           con->used_opt_idx = NULL;
 }  }
   
 void cfg_set_cfgfile_context(  void cfg_set_cfgfile_context(
Line 123  void cfg_set_cfgfile_context(
Line 137  void cfg_set_cfgfile_context(
         con->filename = (char *) filename;          con->filename = (char *) filename;
 }  }
   
 void cfg_free_context(  void cfg_free_context(const CFG_CONTEXT con)
                                                 const CFG_CONTEXT con  
                                          )  
 {  {
   
         cfg_clear_cmdline_stop_str(con);          cfg_clear_cmdline_stop_str(con);
Line 133  void cfg_free_context(
Line 145  void cfg_free_context(
         cfg_clear_cfgfile_comment_str(con);          cfg_clear_cfgfile_comment_str(con);
         cfg_clear_cmdline_short_option_prefix(con);          cfg_clear_cmdline_short_option_prefix(con);
         cfg_clear_cmdline_long_option_prefix(con);          cfg_clear_cmdline_long_option_prefix(con);
           cfg_clear_cmdline_multi_separator(con);
         cfg_clear_cmdline_option_arg_separator(con);          cfg_clear_cmdline_option_arg_separator(con);
         cfg_clear_cfgfile_option_arg_separator(con);          cfg_clear_cfgfile_option_arg_separator(con);
   
           if (con->used_opt_idx != NULL)
                   free(con->used_opt_idx);
   
         /*          /*
          * We can't call free_currents(con), because it is stacic method defined           * We can't call free_currents(con), because it is stacic method defined
          * in cmdline.c; but no problem, we will do the free-job ourself.           * in cmdline.c; but no problem, we will do the free-job ourself.
Line 154  void cfg_free_context(
Line 170  void cfg_free_context(
   
 #if defined(SELF) || defined(SELFTEST) || defined(SELF_CFG)  #if defined(SELF) || defined(SELFTEST) || defined(SELF_CFG)
   
 int main(int argc, char **argv) {  int main(int argc, char **argv)
   {
   
         CFG_CONTEXT con;          CFG_CONTEXT con;
         int ret;          int ret;
   
         int o_nice = 20, o_verbose = 0;          int o_nice = 20, o_verbose = 0;
           char **o_name = NULL, **o_string = NULL;
         int o_boolean = 0;          int o_boolean = 0;
         int o_int = -33;          int o_int = -33;
         unsigned int o_uint = 33;          unsigned int o_uint = 33;
Line 171  int main(int argc, char **argv) {
Line 189  int main(int argc, char **argv) {
   
         struct cfg_option options[] = {          struct cfg_option options[] = {
                 { "nice", 'n', "nice", CFG_INT, (void *) &o_nice, 0 },                  { "nice", 'n', "nice", CFG_INT, (void *) &o_nice, 0 },
                 { "verbose", 'v', "verbose", CFG_BOOLEAN, (void *) &o_verbose, 0 },                  { "verbose", 'v', "verbose", CFG_BOOLEAN + CFG_MULTI, (void *) &o_verbose, 0 },
                   { "name", 'a', "name", CFG_STRING + CFG_MULTI_SEPARATED, (void *) &o_name, 0 },
   
                 { "bool", 'b', "boolean", CFG_BOOLEAN, (void *) &o_boolean, 1 },                  { "bool", 'b', "boolean", CFG_BOOLEAN, (void *) &o_boolean, 1 },
                 { "int", 'i', "int", CFG_INT, (void *) &o_int, 0 },                  { "int", 'i', "int", CFG_INT, (void *) &o_int, 0 },
Line 180  int main(int argc, char **argv) {
Line 199  int main(int argc, char **argv) {
                 { "ulong", 'o', "unsigned long", CFG_ULONG, (void *) &o_ulong, 0 },                  { "ulong", 'o', "unsigned long", CFG_ULONG, (void *) &o_ulong, 0 },
                 { "float", 'f', "float", CFG_FLOAT, (void *) &o_float, 0 },                  { "float", 'f', "float", CFG_FLOAT, (void *) &o_float, 0 },
                 { "double", 'd', "double", CFG_DOUBLE, (void *) &o_double, 0 },                  { "double", 'd', "double", CFG_DOUBLE, (void *) &o_double, 0 },
                   { "string", 's', "string", CFG_STRING + CFG_MULTI, (void *) &o_string, 0 },
                 CFG_END_OF_LIST                  CFG_END_OF_LIST
         };          };
   
Line 218  int main(int argc, char **argv) {
Line 238  int main(int argc, char **argv) {
                 case CFG_ERR_NOARG:                  case CFG_ERR_NOARG:
                         puts("An argument is missing for option.");                          puts("An argument is missing for option.");
                         break;                          break;
                   case CFG_ERROR_MULTI:
                           puts("Multiple option.");
                           break;
                   case CFG_ERROR_STOP_STR_FOUND:
                           puts("Stop string found.");
                           break;
                 case CFG_OK:                  case CFG_OK:
                         puts("All OK.");                          puts("All OK.");
                         break;                          break;
Line 242  int main(int argc, char **argv) {
Line 268  int main(int argc, char **argv) {
         printf("o_long = %ld, o_ulong = %lu\n", o_long, o_ulong);          printf("o_long = %ld, o_ulong = %lu\n", o_long, o_ulong);
         printf("o_float = %f, o_double = %e\n", o_float, o_double);          printf("o_float = %f, o_double = %e\n", o_float, o_double);
   
           {
                   char *s;
   
                   puts("Multi string printing:");
   
                   if (o_name != NULL) {
                           s = strdyn_implode_str(o_name, "][");
                           printf("o_name = [%s]\n", s);
   
                           if (s != NULL)
                                   free(s);
                           strdyn_free(o_name);
                   }
                   else
                           puts("o_name uninitialized");
   
                   if (o_string != NULL) {
                           s = strdyn_implode_str(o_string, "][");
                           printf("o_string = [%s]\n", s);
   
                           if (s != NULL)
                                   free(s);
                           strdyn_free(o_string);
                   }
                   else
                           puts("o_string uninitialized");
           }
   
   
         return 0;          return 0;
 }  }
   

Legend:
Removed from v.1.11  
changed lines
  Added in v.1.12

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