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/cfg+.c between version 1.1 and 1.2

version 1.1, 2001/10/03 19:12:04 version 1.2, 2001/10/04 11:55:04
Line 4 
Line 4 
   
 #include "cfg.h"  #include "cfg.h"
   
 /*  
    int cfg_parse(  
    const CFG_CONTEXT con  
    );  
    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;  
         }  
 }  
   
 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]);  
   
         switch (param[modify_idx].type) {  
                 default:  
                         ret.type = CFG_PARSE_PARAM_ERROR;  
                         return ret;  
                         break;  
   
                 case CFG_PARAM_LAST_PARAMS:  
                         break;  
   
                 case CFG_PARAM_BOOLEAN:  
                         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) {  
   
         }  
         else {  
         }  
 }  
 else {  
         ret.type = CFG_PARSE_PARAM_UNKNOWN;  
         ret.param_no = i;  
         return ret;  
 }  
 }  
 else {  
   
         printf("processing last parameters\n");  
   
         if (last_idx >= 0) {  
                 register int k;  
   
                 // Allocating the right size of last_params.  
                 *(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;  
                         return ret;  
                 }  
   
                 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 :)  
         }  
   
         // 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;  
 }  
 */  
   
 CFG_CONTEXT cfg_get_context(  CFG_CONTEXT cfg_get_context(
                                                 const struct cfg_option *options                                                  const struct cfg_option *options
                                                 )                                                  )
Line 295  CFG_CONTEXT cfg_get_cmdline_context(
Line 38  CFG_CONTEXT cfg_get_cmdline_context(
 }  }
   
 CFG_CONTEXT cfg_get_cfgfile_context(  CFG_CONTEXT cfg_get_cfgfile_context(
                                                 const int begin_line,                                                  const long begin_pos,
                                                 const int end_line,                                                  const long end_pos,
                                                 const char *filename,                                                  const char *filename,
                                                 const struct cfg_option *options                                                  const struct cfg_option *options
                                                 )                                                  )
Line 307  CFG_CONTEXT cfg_get_cfgfile_context(
Line 50  CFG_CONTEXT cfg_get_cfgfile_context(
         if (con == NULL)          if (con == NULL)
                 return NULL;                  return NULL;
   
         con->begin_line = begin_line;          con->begin_pos = begin_pos;
         con->end_line = end_line;          con->end_pos = end_pos;
         con->filename = filename;          con->filename = filename;
   
         return con;          return con;

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

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