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/parse.c between version 1.2 and 1.3

version 1.2, 2001/10/16 18:22:17 version 1.3, 2001/10/16 19:01:03
Line 4  int cfg_parse(
Line 4  int cfg_parse(
                                                 const CFG_CONTEXT con                                                  const CFG_CONTEXT con
                          )                           )
 {  {
           return 0;
 }  }
   
 int cfg_get_next_opt(  int cfg_get_next_opt(
                                                 const CFG_CONTEXT con                                                  const CFG_CONTEXT con
                                         )                                          )
 {  {
           return con->type == CFG_CMDLINE
                   ? cfg_cmdline_get_next_opt(con)
                   : cfg_cfgfile_get_next_opt(con);
 }  }
   
 int cfg_get_opt_arg(  int cfg_get_opt_arg(
                                                 const CFG_CONTEXT con                                                  const CFG_CONTEXT con
                                    )                                     )
 {  {
           return 0;
 }  }
   
 /*  /* static functions */
 static struct cfg_parse_param_ret cfg_parse_param(  
                                                 const int size,  static int cfg_cmdline_get_next_opt(
                                                 const char**array,                                                  const CFG_CONTEXT con
                                                 const struct cfg_param param[])                                                  )
   {
           return 0;
   }
   
   static int cfg_cfgfile_get_next_opt(
                                                   const CFG_CONTEXT con
                                                   )
 {  {
         register int i, last_idx = -1;          return 0;
   }
   
   /*
      static struct cfg_parse_param_ret cfg_parse_param(
      const int size,
      const char**array,
      const struct cfg_param param[])
      {
      register int i, last_idx = -1;
   
      register struct cfg_parse_param_ret ret = {  CFG_PARSE_PARAM_OK, -1 };
   
      for (i = 0; param[i].type != CFG_PARAM_NULL; i++)
      if (param[i].type == CFG_PARAM_LAST_PARAMS) {
      last_idx = i;
      break;
      }
   
      printf("cfg_parse_param(): last_idx = %d\n", last_idx);
   
      for (i = 0; i < size; i++) {
      if (array[i][0] == '-') {
      register int j, modify_idx = -1;
   
      for (j = 0; param[j].type != CFG_PARAM_NULL; j++) {
      if (param[j].type == CFG_PARAM_LAST_PARAMS)
      continue;
   
   // Is prefix '--' or only '-'?
   if (array[i][1] == '-') {
   register int k;
   
   for (k = 0; param[j].string[k] != NULL; k++) {
   
   printf("cfg_parse_param(): comparing '%s' with '%s'\n",
                                                   array[i] + 2, param[j].string[k]);
   
   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])] == '\0'
                                                   )) {
           modify_idx = j;
           break;
   }
   }
   }
   else {
           printf("cfg_parse_param(): searching '%c' in '%s'\n",
                                                           array[i][1], param[j].character);
   
           if (strchr(param[j].character, array[i][1]) != NULL &&
                                                           (array[i][2] == '=' || array[i][2] == '\0')) {
                   modify_idx = j;
                   break;
           }
   }
   
         register struct cfg_parse_param_ret ret = {     CFG_PARSE_PARAM_OK, -1 };  if (modify_idx >= 0)
           break;
           }
   
   // Parsed parameter is param[modify_idx].
   if (modify_idx >= 0) {
   
           printf("cfg_parse_param(): %s detected\n",
                                                           cfg_param_type_str[param[modify_idx].type]);
   
         for (i = 0; param[i].type != CFG_PARAM_NULL; i++)          switch (param[modify_idx].type) {
                 if (param[i].type == CFG_PARAM_LAST_PARAMS) {                  default:
                         last_idx = i;                          ret.type = CFG_PARSE_PARAM_ERROR;
                           return ret;
                         break;                          break;
                 }  
   
         printf("cfg_parse_param(): last_idx = %d\n", last_idx);                  case CFG_PARAM_LAST_PARAMS:
                           break;
   
         for (i = 0; i < size; i++) {                  case CFG_PARAM_BOOLEAN:
                 if (array[i][0] == '-') {                          if (strchr(array[i], '=') != NULL) {
                         register int j, modify_idx = -1;                                  ret.type = CFG_PARSE_PARAM_UNKNOWN;
                                   ret.param_no = i;
                         for (j = 0; param[j].type != CFG_PARAM_NULL; j++) {                                  return ret;
                                 if (param[j].type == CFG_PARAM_LAST_PARAMS)                          }
                                         continue;                          else {
                                   *(param[modify_idx].data.boolean) = 1;
                                 // Is prefix '--' or only '-'?                          }
                                 if (array[i][1] == '-') {                          break;
                                         register int k;  
                   case CFG_PARAM_SINGLE_VALUE:
                                         for (k = 0; param[j].string[k] != NULL; k++) {                          if (*(param[modify_idx].data.single_value) != NULL) {
                                   ret.type = CFG_PARSE_PARAM_MULTI;
                                                 printf("cfg_parse_param(): comparing '%s' with '%s'\n",                                  ret.param_no = i;
                                                                                                 array[i] + 2, param[j].string[k]);                                  return ret;
                           }
                                                 if (strstr(array[i] + 2, param[j].string[k]) != NULL &&                          else {
                                                                                                 ( array[i][2+strlen(param[j].string[k])] == '='                                  const char*copy_ptr;
                                                                                                   ||  
                                                                                                   array[i][2+strlen(param[j].string[k])] == '\0'                                  // Finding pointer of value for parameter.
                                                                                                 )) {                                  if (strchr(array[i], '=') != NULL)
                                                         modify_idx = j;                                          copy_ptr = strchr(array[i], '=') + 1;
                                                         break;  
                                                 }  
                                         }  
                                 }  
                                 else {                                  else {
                                         printf("cfg_parse_param(): searching '%c' in '%s'\n",                                          if (i + 1 >= size) {
                                                                                         array[i][1], param[j].character);                                                  ret.type = CFG_PARSE_PARAM_MISSING;
                                                   ret.param_no = i;
                                                   return ret;
   
                                         if (strchr(param[j].character, array[i][1]) != NULL &&  
                                                                                         (array[i][2] == '=' || array[i][2] == '\0')) {  
                                                 modify_idx = j;  
                                                 break;  
                                         }                                          }
                                           i++;
                                           copy_ptr = array[i];
                                 }                                  }
   
                                 if (modify_idx >= 0)                                  *(param[modify_idx].data.single_value) =
                                         break;                                          strdup(copy_ptr);
                         }                          }
                           break;
   
                         // Parsed parameter is param[modify_idx].                  case CFG_PARAM_MULTI_VALUES:
                         if (modify_idx >= 0) {                          {
                                   register int cur_size;
                                 printf("cfg_parse_param(): %s detected\n",                                  register const char*copy_ptr;
                                                                                 cfg_param_type_str[param[modify_idx].type]);                                  register char**ptr =
                                           param[modify_idx].data.multi_values;
                                 switch (param[modify_idx].type) {  
                                         default:  
                                                 ret.type = CFG_PARSE_PARAM_ERROR;                                  // Counting current size of multi_values string.
                                                 return ret;                                  if (*ptr == NULL)
                                                 break;                                          cur_size = 0;
                                   else
                                         case CFG_PARAM_LAST_PARAMS:                                          cur_size = strlen(*ptr);
                                                 break;  
                                   printf("cfg_parse_param(): %s: cur_size = %d\n",
                                                                                   cfg_param_type_str[param[modify_idx].type],
                                                                                   cur_size);
   
                                         case CFG_PARAM_BOOLEAN:                                  // Finding pointer of value for parameter.
                                                 if (strchr(array[i], '=') != NULL) {  
                                                         ret.type = CFG_PARSE_PARAM_UNKNOWN;  
                                                         ret.param_no = i;  
                                                         return ret;  
                                                 }  
                                                 else {  
                                                         *(param[modify_idx].data.boolean) = 1;  
                                                 }  
                                                 break;  
   
                                         case CFG_PARAM_SINGLE_VALUE:  
                                                 if (*(param[modify_idx].data.single_value) != NULL) {  
                                                         ret.type = CFG_PARSE_PARAM_MULTI;  
                                                         ret.param_no = i;  
                                                         return ret;  
                                                 }  
                                                 else {  
                                                         const char*copy_ptr;  
   
                                                         // Finding pointer of value for parameter.  
                                                         if (strchr(array[i], '=') != NULL)  
                                                                 copy_ptr = strchr(array[i], '=') + 1;  
                                                         else {  
                                                                 if (i + 1 >= size) {  
                                                                         ret.type = CFG_PARSE_PARAM_MISSING;  
                                                                         ret.param_no = i;  
                                                                         return ret;  
   
                                                                 }  
                                                                 i++;  
                                                                 copy_ptr = array[i];  
                                                         }  
   
                                                         *(param[modify_idx].data.single_value) =  
                                                                 strdup(copy_ptr);  
                                                 }  
                                                 break;  
   
                                         case CFG_PARAM_MULTI_VALUES:  
                                                 {  
                                                         register int cur_size;  
                                                         register const char*copy_ptr;  
                                                         register char**ptr =  
                                                                 param[modify_idx].data.multi_values;  
   
   
                                                         // Counting current size of multi_values string.  
                                                         if (*ptr == NULL)  
                                                                 cur_size = 0;  
                                                         else  
                                                                 cur_size = strlen(*ptr);  
   
                                                         printf("cfg_parse_param(): %s: cur_size = %d\n",  
                                                                                                         cfg_param_type_str[param[modify_idx].type],  
                                                                                                         cur_size);  
   
                                                         // Finding pointer of value for parameter.  
                                                         if (strchr(array[i], '=') != NULL) {  
                                                                 copy_ptr = strchr(array[i], '=') + 1;  
   
                                                                 if (strlen(copy_ptr) == 0) {  
                                                                         ret.type = CFG_PARSE_PARAM_MISSING;  
                                                                         ret.param_no = i;  
                                                                         return ret;  
                                                                 }  
                                                         }  
                                                         else {  
                                                                 if (i + 1 >= size) {  
                                                                         ret.type = CFG_PARSE_PARAM_MISSING;  
                                                                         ret.param_no = i;  
                                                                         return ret;  
                                                                 }  
                                                                 i++;  
                                                                 copy_ptr = array[i];  
                                                         }  
   
                                                         printf("cfg_parse_param(): %s: old ptr = %p\n",  
                                                                                                         cfg_param_type_str[param[modify_idx].type],  
                                                                                                         *ptr);  
   
                                                         if (cur_size == 0)  
                                                                 *ptr = strdup(copy_ptr);  
                                                         else {  
                                                                 *ptr = realloc(*ptr,  
                                                                                                                 cur_size + 2 + strlen(copy_ptr));  
                                                                 if (*ptr != NULL) {  
                                                                         // Appending the values.  
                                                                         (*ptr)[cur_size] = ',';  
                                                                         strcpy(*ptr + cur_size + 1, copy_ptr);  
                                                                 }  
                                                         }  
   
                                                         if (*ptr == NULL) {  
                                                                 ret.type = CFG_PARSE_PARAM_ERROR;  
                                                                 return ret;  
                                                         }  
   
                                                         printf("cfg_parse_param(): %s: new ptr = %p\n",  
                                                                                                         cfg_param_type_str[param[modify_idx].type],  
                                                                                                         *ptr);  
   
                                                         printf("cfg_parse_param(): %s: new val = '%s'\n",  
                                                                                                         cfg_param_type_str[param[modify_idx].type],  
                                                                                                         *ptr);  
   
                                                         printf("cfg_parse_param(): %s: new size = %d\n",  
                                                                                                         cfg_param_type_str[param[modify_idx].type],  
                                                                                                         strlen(*ptr));  
   
                                                 }  
                                                 break;  
                                 };  
                                 if (strchr(array[i], '=') != NULL) {                                  if (strchr(array[i], '=') != NULL) {
                                           copy_ptr = strchr(array[i], '=') + 1;
   
                                           if (strlen(copy_ptr) == 0) {
                                                   ret.type = CFG_PARSE_PARAM_MISSING;
                                                   ret.param_no = i;
                                                   return ret;
                                           }
                                 }                                  }
                                 else {                                  else {
                                           if (i + 1 >= size) {
                                                   ret.type = CFG_PARSE_PARAM_MISSING;
                                                   ret.param_no = i;
                                                   return ret;
                                           }
                                           i++;
                                           copy_ptr = array[i];
                                 }                                  }
                         }  
                         else {  
                                 ret.type = CFG_PARSE_PARAM_UNKNOWN;  
                                 ret.param_no = i;  
                                 return ret;  
                         }  
                 }  
                 else {  
   
                         printf("processing last parameters\n");                                  printf("cfg_parse_param(): %s: old ptr = %p\n",
                                                                                   cfg_param_type_str[param[modify_idx].type],
                                                                                   *ptr);
   
                         if (last_idx >= 0) {                                  if (cur_size == 0)
                                 register int k;                                          *ptr = strdup(copy_ptr);
                                   else {
                                           *ptr = realloc(*ptr,
                                                                                           cur_size + 2 + strlen(copy_ptr));
                                           if (*ptr != NULL) {
                                                   // Appending the values.
                                                   (*ptr)[cur_size] = ',';
                                                   strcpy(*ptr + cur_size + 1, copy_ptr);
                                           }
                                   }
   
                                 // Allocating the right size of last_params.                                  if (*ptr == NULL) {
                                 *(param[last_idx].data.last_params) = (char**) malloc(  
                                                                                 (size - i + 1) * sizeof(char*));  
                                 if (*(param[last_idx].data.last_params) == NULL) {  
                                         ret.type = CFG_PARSE_PARAM_ERROR;                                          ret.type = CFG_PARSE_PARAM_ERROR;
                                         return ret;                                          return ret;
                                 }                                  }
   
                                 printf("last_params ptr = %p, alloc size = %d\n",                                  printf("cfg_parse_param(): %s: new ptr = %p\n",
                                                                                 *(param[last_idx].data.last_params), size-i+1);                                                                                  cfg_param_type_str[param[modify_idx].type],
                                                                                   *ptr);
   
                                   printf("cfg_parse_param(): %s: new val = '%s'\n",
                                                                                   cfg_param_type_str[param[modify_idx].type],
                                                                                   *ptr);
   
                                   printf("cfg_parse_param(): %s: new size = %d\n",
                                                                                   cfg_param_type_str[param[modify_idx].type],
                                                                                   strlen(*ptr));
   
                                 // Duping data to the array.                          }
                                 for (k = 0; k < size - i; k++) {                          break;
                                         (*(param[last_idx].data.last_params))[k] =          };
                                                 strdup(array[i+k]);          if (strchr(array[i], '=') != NULL) {
   
                                         printf("%d: strduping '%s' to %p\n",          }
                                                                                         k, array[i+k], (*(param[last_idx].data.last_params))[k]);          else {
                                 }          }
   }
   else {
           ret.type = CFG_PARSE_PARAM_UNKNOWN;
           ret.param_no = i;
           return ret;
   }
   }
   else {
   
                                 // last_params is a NULL terminated array of ptr to char          printf("processing last parameters\n");
                                 (*(param[last_idx].data.last_params))[size - i] = NULL;  
   
                                 printf("and finally settinup NULL to %p\n",          if (last_idx >= 0) {
                                                                                 (*(param[last_idx].data.last_params))[size-i]);                  register int k;
                         }  
                         else {  
                                 // do_nothing();  
                                 // copy/paste from MS-Windows 98 :)  
                         }  
   
                         // Doesn't matter if we have or have not set last_idx, we                  // Allocating the right size of last_params.
                         // set up ret.param_no to the beginning of last parameters                  *(param[last_idx].data.last_params) = (char**) malloc(
                         // and returning with success.                                                                  (size - i + 1) * sizeof(char*));
                         ret.type = CFG_PARSE_PARAM_OK;                  if (*(param[last_idx].data.last_params) == NULL) {
                         ret.param_no = i;                          ret.type = CFG_PARSE_PARAM_ERROR;
                           return ret;
                         // And now the finally exit. We could do 'return ret'  
                         // statement, but we want exit from the end of this function.  
                         i = size;  
                 }                  }
   
                   printf("last_params ptr = %p, alloc size = %d\n",
                                                                   *(param[last_idx].data.last_params), size-i+1);
   
                   // Duping data to the array.
                   for (k = 0; k < size - i; k++) {
                           (*(param[last_idx].data.last_params))[k] =
                                   strdup(array[i+k]);
   
                           printf("%d: strduping '%s' to %p\n",
                                                                           k, array[i+k], (*(param[last_idx].data.last_params))[k]);
                   }
   
                   // last_params is a NULL terminated array of ptr to char
                   (*(param[last_idx].data.last_params))[size - i] = NULL;
   
                   printf("and finally settinup NULL to %p\n",
                                                                   (*(param[last_idx].data.last_params))[size-i]);
           }
           else {
                   // do_nothing();
                   // copy/paste from MS-Windows 98 :)
         }          }
   
         return ret;          // Doesn't matter if we have or have not set last_idx, we
           // set up ret.param_no to the beginning of last parameters
           // and returning with success.
           ret.type = CFG_PARSE_PARAM_OK;
           ret.param_no = i;
   
           // And now the finally exit. We could do 'return ret'
           // statement, but we want exit from the end of this function.
           i = size;
   }
   }
   
   return ret;
 }  }
 */  */
   

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