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 ep/src/obsolete/Attic/cfg.c between version 1.2 and 1.3

version 1.2, 2001/09/21 19:44:51 version 1.3, 2001/09/21 19:48:30
Line 1 
Line 1 
 /*  /*
  * $Log$   * $Log$
    * Revision 1.3  2001/09/21 19:48:30  host8
    * Cosmetics changes in cfg.c
    *
  * Revision 1.2  2001/09/21 19:44:51  host8   * Revision 1.2  2001/09/21 19:44:51  host8
  * Added $Log$ keyword substitution   * Added $Log$
    * Added Revision 1.3  2001/09/21 19:48:30  host8
    * Added Cosmetics changes in cfg.c
    * Added keyword substitution
  *   *
  */   */
 #include <stdio.h>  #include <stdio.h>
Line 65  static struct cfg_param process_param[]
Line 71  static struct cfg_param process_param[]
                 CFG_PARAM_LAST_PARAMS,                  CFG_PARAM_LAST_PARAMS,
                 {(int*) &(cfg_process.argv)}                  {(int*) &(cfg_process.argv)}
         },          },
         CFG_PARAM_END_OF_LIST          CFG_PARAM_END_OF_LIST
 };  };
   
   
Line 85  struct cfg_global cfg_global;
Line 91  struct cfg_global cfg_global;
 static struct cfg_param global_param[] = {  static struct cfg_param global_param[] = {
         {          {
                 /* To be easy and intelligent. */                  /* To be easy and intelligent. */
                 {"cfg", "config", "cfgfile", "configfile",                  {"cfg", "config", "cfgfile", "configfile",
                         "cfg-file", "config-file", NULL},                          "cfg-file", "config-file", NULL},
                         "c",                          "c",
                         CFG_PARAM_SINGLE_VALUE,                          CFG_PARAM_SINGLE_VALUE,
Line 125  void cfg_parse_file(
Line 131  void cfg_parse_file(
   
   
 void cfg_parse_global(  void cfg_parse_global(
                 const int size,                  const int size,
                 const char**array,                  const char**array,
                 struct cfg_global*pcfg)                  struct cfg_global*pcfg)
 {  {
   
Line 175  static struct cfg_parse_param_ret cfg_pa
Line 181  static struct cfg_parse_param_ret cfg_pa
                                                                 array[i] + 2, param[j].string[k]);                                                                  array[i] + 2, param[j].string[k]);
   
                                                 if (strstr(array[i] + 2, param[j].string[k]) != NULL &&                                                  if (strstr(array[i] + 2, param[j].string[k]) != NULL &&
                                                                 ( array[i][2+strlen(param[j].string[k])] == '='                                                                  ( array[i][2+strlen(param[j].string[k])] == '='
                                                                   ||                                                                    ||
                                                                   array[i][2+strlen(param[j].string[k])] == '\0'                                                                    array[i][2+strlen(param[j].string[k])] == '\0'
                                                                 )) {                                                                  )) {
Line 195  static struct cfg_parse_param_ret cfg_pa
Line 201  static struct cfg_parse_param_ret cfg_pa
                                         }                                          }
                                 }                                  }
   
                                 if (modify_idx >= 0)                                  if (modify_idx >= 0)
                                         break;                                          break;
                         }                          }
   
Line 211  static struct cfg_parse_param_ret cfg_pa
Line 217  static struct cfg_parse_param_ret cfg_pa
                                                 return ret;                                                  return ret;
                                                 break;                                                  break;
   
                                         case CFG_PARAM_LAST_PARAMS:                                          case CFG_PARAM_LAST_PARAMS:
                                                 break;                                                  break;
   
                                         case CFG_PARAM_BOOLEAN:                                          case CFG_PARAM_BOOLEAN:
Line 235  static struct cfg_parse_param_ret cfg_pa
Line 241  static struct cfg_parse_param_ret cfg_pa
                                                         const char*copy_ptr;                                                          const char*copy_ptr;
   
                                                         /* Finding pointer of value for parameter. */                                                          /* Finding pointer of value for parameter. */
                                                         if (strchr(array[i], '=') != NULL)                                                          if (strchr(array[i], '=') != NULL)
                                                                 copy_ptr = strchr(array[i], '=') + 1;                                                                  copy_ptr = strchr(array[i], '=') + 1;
                                                         else {                                                          else {
                                                                 if (i + 1 >= size) {                                                                  if (i + 1 >= size) {
Line 257  static struct cfg_parse_param_ret cfg_pa
Line 263  static struct cfg_parse_param_ret cfg_pa
                                                 {                                                  {
                                                         register int cur_size;                                                          register int cur_size;
                                                         register const char*copy_ptr;                                                          register const char*copy_ptr;
                                                         register char**ptr =                                                          register char**ptr =
                                                                 param[modify_idx].data.multi_values;                                                                  param[modify_idx].data.multi_values;
   
   
                                                         /* Counting current size of multi_values string. */                                                          /* Counting current size of multi_values string. */
                                                         if (*ptr == NULL)                                                          if (*ptr == NULL)
                                                                 cur_size = 0;                                                                  cur_size = 0;
                                                         else                                                          else
                                                                 cur_size = strlen(*ptr);                                                                  cur_size = strlen(*ptr);
   
                                                         printf("cfg_parse_param(): %s: cur_size = %d\n",                                                          printf("cfg_parse_param(): %s: cur_size = %d\n",
                                                                         cfg_param_type_str[param[modify_idx].type],                                                                          cfg_param_type_str[param[modify_idx].type],
                                                                         cur_size);                                                                          cur_size);
   
                                                         /* Finding pointer of value for parameter. */                                                          /* Finding pointer of value for parameter. */
                                                         if (strchr(array[i], '=') != NULL) {                                                          if (strchr(array[i], '=') != NULL) {
Line 293  static struct cfg_parse_param_ret cfg_pa
Line 299  static struct cfg_parse_param_ret cfg_pa
   
                                                         printf("cfg_parse_param(): %s: old ptr = %p\n",                                                          printf("cfg_parse_param(): %s: old ptr = %p\n",
                                                                         cfg_param_type_str[param[modify_idx].type],                                                                          cfg_param_type_str[param[modify_idx].type],
                                                                         *ptr);                                                                          *ptr);
   
                                                         if (cur_size == 0)                                                          if (cur_size == 0)
                                                                 *ptr = strdup(copy_ptr);                                                                  *ptr = strdup(copy_ptr);
                                                         else {                                                          else {
                                                                 *ptr = realloc(*ptr,                                                                  *ptr = realloc(*ptr,
                                                                                 cur_size + 2 + strlen(copy_ptr));                                                                                  cur_size + 2 + strlen(copy_ptr));
                                                                 if (*ptr != NULL) {                                                                  if (*ptr != NULL) {
                                                                         /* Appending the values. */                                                                          /* Appending the values. */
Line 314  static struct cfg_parse_param_ret cfg_pa
Line 320  static struct cfg_parse_param_ret cfg_pa
   
                                                         printf("cfg_parse_param(): %s: new ptr = %p\n",                                                          printf("cfg_parse_param(): %s: new ptr = %p\n",
                                                                         cfg_param_type_str[param[modify_idx].type],                                                                          cfg_param_type_str[param[modify_idx].type],
                                                                         *ptr);                                                                          *ptr);
   
                                                         printf("cfg_parse_param(): %s: new val = '%s'\n",                                                          printf("cfg_parse_param(): %s: new val = '%s'\n",
                                                                         cfg_param_type_str[param[modify_idx].type],                                                                          cfg_param_type_str[param[modify_idx].type],
                                                                         *ptr);                                                                          *ptr);
   
                                                         printf("cfg_parse_param(): %s: new size = %d\n",                                                          printf("cfg_parse_param(): %s: new size = %d\n",
                                                                         cfg_param_type_str[param[modify_idx].type],                                                                          cfg_param_type_str[param[modify_idx].type],
                                                                         strlen(*ptr));                                                                          strlen(*ptr));
   
                                                 }                                                  }
                                                 break;                                                  break;
Line 355  static struct cfg_parse_param_ret cfg_pa
Line 361  static struct cfg_parse_param_ret cfg_pa
                                 }                                  }
   
                                 printf("last_params ptr = %p, alloc size = %d\n",                                  printf("last_params ptr = %p, alloc size = %d\n",
                                                 *(param[last_idx].data.last_params), size-i+1);                                                  *(param[last_idx].data.last_params), size-i+1);
   
                                 /* Duping data to the array. */                                  /* Duping data to the array. */
                                 for (k = 0; k < size - i; k++) {                                  for (k = 0; k < size - i; k++) {
                                         (*(param[last_idx].data.last_params))[k] =                                          (*(param[last_idx].data.last_params))[k] =
                                                 strdup(array[i+k]);                                                  strdup(array[i+k]);
   
                                         printf("%d: strduping '%s' to %p\n",                                          printf("%d: strduping '%s' to %p\n",
Line 378  static struct cfg_parse_param_ret cfg_pa
Line 384  static struct cfg_parse_param_ret cfg_pa
                                  */                                   */
                         }                          }
   
                         /* Doesn't matter if we have or have not set last_idx, we                          /* Doesn't matter if we have or have not set last_idx, we
                          * set up ret.param_no to the beginning of last parameters                           * set up ret.param_no to the beginning of last parameters
                          * and returning with success.                           * and returning with success.
                          */                           */
Line 414  int main(const int argc, const char *arg
Line 420  int main(const int argc, const char *arg
   
         if (cfg_process.argv != NULL)          if (cfg_process.argv != NULL)
                 for (k = 0; cfg_process.argv[k] != NULL; k++)                  for (k = 0; cfg_process.argv[k] != NULL; k++)
                         printf("argv[%d] = %s (%p)\n",                          printf("argv[%d] = %s (%p)\n",
                                         k, cfg_process.argv[k], &(cfg_process.argv[k]));                                          k, cfg_process.argv[k], &(cfg_process.argv[k]));
   
         ret = cfg_parse_param(argc - 1, argv + 1, process_param);          ret = cfg_parse_param(argc - 1, argv + 1, process_param);
   
         printf("ret = { %s (%d), %d }\n",          printf("ret = { %s (%d), %d }\n",
                         cfg_parse_param_ret_type_str[ret.type], ret.type, ret.param_no);                          cfg_parse_param_ret_type_str[ret.type], ret.type, ret.param_no);
   
         printf("input   = %s (%p)\n", cfg_process.input, &cfg_process.input);          printf("input   = %s (%p)\n", cfg_process.input, &cfg_process.input);
Line 430  int main(const int argc, const char *arg
Line 436  int main(const int argc, const char *arg
   
         if (cfg_process.argv != NULL)          if (cfg_process.argv != NULL)
                 for (k = 0; cfg_process.argv[k] != NULL; k++)                  for (k = 0; cfg_process.argv[k] != NULL; k++)
                         printf("argv[%d] = %s (%p)\n",                          printf("argv[%d] = %s (%p)\n",
                                         k, cfg_process.argv[k], &(cfg_process.argv[k]));                                          k, cfg_process.argv[k], &(cfg_process.argv[k]));
   
         printf("\nOFFICIAL MESSAGE: ");          printf("\nOFFICIAL MESSAGE: ");
Line 452  int main(const int argc, const char *arg
Line 458  int main(const int argc, const char *arg
                         printf("value missing for '%s'\n", argv[1 + ret.param_no]);                          printf("value missing for '%s'\n", argv[1 + ret.param_no]);
                         break;                          break;
                 case CFG_PARSE_PARAM_MULTI:                  case CFG_PARSE_PARAM_MULTI:
                         printf("only single value can be assigned to '%s'\n",                          printf("only single value can be assigned to '%s'\n",
                                         argv[1+ret.param_no]);                                          argv[1+ret.param_no]);
                         break;                          break;
         };          };

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

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