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/cmdline.c between version 1.3 and 1.4

version 1.3, 2001/10/23 15:41:32 version 1.4, 2001/11/13 16:19:44
Line 1 
Line 1 
 /* TODO: ./configure check HAVE_FLOAT_H je dolezity!!! */  /* TODO: ./configure check HAVE_FLOAT_H je dolezity!!! */
 /* no uz ani nie, ked mam limits.h :P */  /* no uz ani nie, ked mam limits.h :P */
   
   #include <math.h>
 #include <limits.h>  #include <limits.h>
   #include <float.h>
   #include <errno.h>
   
   
 static int cfg_cmdline_get_next_opt(const CFG_CONTEXT con);  static int cfg_cmdline_get_next_opt(const CFG_CONTEXT con);
Line 95  static int cfg_cmdline_get_next_opt(cons
Line 98  static int cfg_cmdline_get_next_opt(cons
                         case CFG_INTEGER:                          case CFG_INTEGER:
                         case CFG_UNSIGNED_INT:                          case CFG_UNSIGNED_INT:
                         case CFG_LONG:                          case CFG_LONG:
                                 /*  
                                    case POPT_ARG_INT:  
                                    case POPT_ARG_LONG:  
                                    {   long aLong = 0;  
                                    char *end;  
   
                                    if (con->os->nextArg) {  
                                    aLong = strtol(con->os->nextArg, &end, 0);  
                                    if (!(end && *end == '\0'))  
                                    return POPT_ERROR_BADNUMBER;  
                                    }  
   
                                    if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_LONG) {                                  if (con->cur_arg == NULL)
                                    if (aLong == LONG_MIN || aLong == LONG_MAX)                                          return CFG_ERR_NOARG;
                                    return POPT_ERROR_OVERFLOW;  
                                    if (poptSaveLong(opt, aLong))  
                                    return POPT_ERROR_BADOPERATION;  
                                    } else {  
                                    if (aLong > INT_MAX || aLong < INT_MIN)  
                                    return POPT_ERROR_OVERFLOW;  
                                    if (poptSaveInt(opt, aLong))  
                                    return POPT_ERROR_BADOPERATION;  
                                    }  
                                    }   break;  
   
                                  */  
                                 {                                  {
                                         register long value;                                          register long value;
                                         char *end;                                          char *end;
Line 142  static int cfg_cmdline_get_next_opt(cons
Line 123  static int cfg_cmdline_get_next_opt(cons
   
                                                 if (con->options[opt_idx].value != NULL)                                                  if (con->options[opt_idx].value != NULL)
                                                         *((unsigned int *)con->options[opt_idx].value) =                                                          *((unsigned int *)con->options[opt_idx].value) =
                                                                 value;                                                                  (unsigned int) value;
                                         }                                          }
                                         else {                                          else {
                                                 if (value > INT_MAX || value < INT_MIN)                                                  printf("testing: %ld < %d < (%ld) < %d < %ld\n",
                                                                                                   LONG_MIN,
                                                                                                   INT_MIN,
                                                                                                   value,
                                                                                                   INT_MAX,
                                                                                                   LONG_MAX);
   
                                                   if (value >= INT_MAX || value <= INT_MIN)
                                                         return CFG_ERROR_OVERFLOW;                                                          return CFG_ERROR_OVERFLOW;
   
                                                 if (con->options[opt_idx].value != NULL)                                                  if (con->options[opt_idx].value != NULL)
                                                         *((int *)con->options[opt_idx].value) = value;                                                          *((int *)con->options[opt_idx].value) =
                                                                   (int) value;
                                         }                                          }
   
                                         if (! (con->cur_opt_type & CFG_LONG_SEPINIT)                                          if (! (con->cur_opt_type & CFG_LONG_SEPINIT)
Line 166  static int cfg_cmdline_get_next_opt(cons
Line 155  static int cfg_cmdline_get_next_opt(cons
                                 break;                                  break;
   
                         case CFG_UNSIGNED_LONG:                          case CFG_UNSIGNED_LONG:
                                 break;  
   
                         case CFG_FLOAT:                                  if (con->cur_arg == NULL)
                                           return CFG_ERR_NOARG;
   
                                   {
                                           register long value;
                                           char *end;
   
                                           value = strtoul(con->cur_arg, &end, 0);
                                           if (!(end && *end == '\0'))
                                                   return CFG_ERROR_BADNUMBER;
   
                                           if (value == ULONG_MAX /* || value == 0 */)
                                                   return CFG_ERROR_OVERFLOW;
   
                                           if (con->options[opt_idx].value != NULL)
                                                   *((unsigned long *)con->options[opt_idx].value) = value;
                                   }
                                 break;                                  break;
   
                           case CFG_FLOAT:
                         case CFG_DOUBLE:                          case CFG_DOUBLE:
   
                                   if (con->cur_arg == NULL)
                                           return CFG_ERR_NOARG;
   
                                   {
                                           double value;
                                           char *end;
   
                                           value = strtod(con->cur_arg, &end);
                                           if (*end)
                                                   return CFG_ERROR_BADNUMBER;
   
                                           if (value == +HUGE_VAL || value == -HUGE_VAL)
                                                   return CFG_ERROR_OVERFLOW;
                                           if (value == 0.0 && errno == ERANGE)
                                                   return CFG_ERROR_OVERFLOW;
   
                                           if (con->options[opt_idx].type == CFG_FLOAT) {
   #ifdef ABS
   #undef ABS
   #endif
   #define ABS(a) (((a) < 0) ? -(a) : (a))
   
                                                   if (ABS(value) > FLT_MAX)
                                                           return CFG_ERROR_OVERFLOW;
                                                   if (ABS(value) < FLT_MIN)
                                                           return CFG_ERROR_OVERFLOW;
   
                                                   if (con->options[opt_idx].value != NULL)
                                                           *((float *)con->options[opt_idx].value) =
                                                                   (float) value;
                                           }
                                           else {
                                                   if (con->options[opt_idx].value != NULL)
                                                           *((double *)con->options[opt_idx].value) = value;
                                           }
                                   }
                                 /*                                  /*
                                    case POPT_ARG_FLOAT:                                     case POPT_ARG_FLOAT:
                                    case POPT_ARG_DOUBLE:                                     case POPT_ARG_DOUBLE:
Line 368  static int search_cur_opt(const CFG_CONT
Line 410  static int search_cur_opt(const CFG_CONT
 }  }
   
 /* 0 - No, 1 - Short, 2 - Long */  /* 0 - No, 1 - Short, 2 - Long */
 static int is_cmdline_option(const CFG_CONTEXT con, char *s) {  /*
         register int i, size, ret;     static int is_cmdline_option(const CFG_CONTEXT con, char *s) {
      register int i, size, ret;
         size = ret = 0;  
   
         for (i = 0; con->short_option_prefix[i] != NULL; i++) {  
                 if (strstr(s, con->short_option_prefix[i]) == s) {  
                         size = strlen(con->short_option_prefix[i]);  
                         ret = 1;  
                         break;  
                 }  
         }  
   
         for (i = 0; con->long_option_prefix[i] != NULL; i++) {     size = ret = 0;
                 if (ret == 1 && strlen(con->long_option_prefix[i]) <= size)  
                         continue;  
   
                 if (strstr(s, con->long_option_prefix[i]) == s) {     for (i = 0; con->short_option_prefix[i] != NULL; i++) {
                         size = strlen(con->long_option_prefix[i]);     if (strstr(s, con->short_option_prefix[i]) == s) {
                         ret = 2;     size = strlen(con->short_option_prefix[i]);
                         break;     ret = 1;
                 }     break;
         }     }
      }
   
      for (i = 0; con->long_option_prefix[i] != NULL; i++) {
      if (ret == 1 && strlen(con->long_option_prefix[i]) <= size)
      continue;
   
      if (strstr(s, con->long_option_prefix[i]) == s) {
      size = strlen(con->long_option_prefix[i]);
      ret = 2;
      break;
      }
      }
   
         return ret;     return ret;
 }     }
    */
   

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

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