[BACK]Return to cond.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / usr.bin / make

Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.

Diff for /src/usr.bin/make/cond.c between version 1.45 and 1.46

version 1.45, 2008/11/22 23:42:16 version 1.46, 2008/11/23 10:52:58
Line 92  __RCSID("$NetBSD$");
Line 92  __RCSID("$NetBSD$");
  */   */
   
 #include    <ctype.h>  #include    <ctype.h>
   #include    <errno.h>    /* For strtoul() error checking */
   
 #include    "make.h"  #include    "make.h"
 #include    "hash.h"  #include    "hash.h"
Line 146  static Boolean CondDoMake(int, char *);
Line 147  static Boolean CondDoMake(int, char *);
 static Boolean CondDoExists(int, char *);  static Boolean CondDoExists(int, char *);
 static Boolean CondDoTarget(int, char *);  static Boolean CondDoTarget(int, char *);
 static Boolean CondDoCommands(int, char *);  static Boolean CondDoCommands(int, char *);
 static char * CondCvtArg(char *, double *);  static Boolean CondCvtArg(char *, double *);
 static Token CondToken(Boolean);  static Token CondToken(Boolean);
 static Token CondT(Boolean);  static Token CondT(Boolean);
 static Token CondF(Boolean);  static Token CondF(Boolean);
Line 488  CondDoCommands(int argLen, char *arg)
Line 489  CondDoCommands(int argLen, char *arg)
 /*-  /*-
  *-----------------------------------------------------------------------   *-----------------------------------------------------------------------
  * CondCvtArg --   * CondCvtArg --
  *      Convert the given number into a double. If the number begins   *      Convert the given number into a double.
  *      with 0x, it is interpreted as a hexadecimal integer   *      We try a base 10 or 16 integer conversion first, if that fails
  *      and converted to a double from there. All other strings just have   *      then we try a floating point conversion instead.
  *      strtod called on them.  
  *   *
  * Results:   * Results:
  *      Sets 'value' to double value of string.   *      Sets 'value' to double value of string.
  *      Returns NULL if string was fully consumed,   *      Returns 'true' if the convertion suceeded
  *      else returns remaining input.  
  *  
  * Side Effects:  
  *      Can change 'value' even if string is not a valid number.  
  *  
  *   *
  *-----------------------------------------------------------------------   *-----------------------------------------------------------------------
  */   */
 static char *  static Boolean
 CondCvtArg(char *str, double *value)  CondCvtArg(char *str, double *value)
 {  {
     if ((*str == '0') && (str[1] == 'x')) {      char *eptr, ech;
         long i;      unsigned long l_val;
       double d_val;
         for (str += 2, i = 0; *str; str++) {  
             int x;      errno = 0;
             if (isdigit((unsigned char) *str))      l_val = strtoul(str, &eptr, str[1] == 'x' ? 16 : 10);
                 x  = *str - '0';      ech = *eptr;
             else if (isxdigit((unsigned char) *str))      if (ech == 0 && errno != ERANGE) {
                 x = 10 + *str - (isupper((unsigned char) *str) ? 'A' : 'a');          d_val = str[0] == '-' ? -(double)-l_val : (double)l_val;
             else  
                 break;  
             i = (i << 4) + x;  
         }  
         *value = (double) i;  
         return *str ? str : NULL;  
     } else {      } else {
         char *eptr;          if (ech != 0 && ech != '.' && ech != 'e' && ech != 'E')
         *value = strtod(str, &eptr);              return FALSE;
         return *eptr ? eptr : NULL;          d_val = strtod(str, &eptr);
           if (*eptr)
               return FALSE;
     }      }
   
       *value = d_val;
       return TRUE;
 }  }
   
 /*-  /*-
  *-----------------------------------------------------------------------   *-----------------------------------------------------------------------
  * CondGetString --   * CondGetString --
Line 762  do_string_compare:
Line 756  do_string_compare:
          * lhs and the rhs to a double and compare the two.           * lhs and the rhs to a double and compare the two.
          */           */
         double          left, right;          double          left, right;
         char    *cp;  
   
         if (CondCvtArg(lhs, &left))          if (!CondCvtArg(lhs, &left) || !CondCvtArg(rhs, &right))
             goto do_string_compare;  
         if ((cp = CondCvtArg(rhs, &right)) &&  
                 cp == rhs)  
             goto do_string_compare;              goto do_string_compare;
   
         if (DEBUG(COND)) {          if (DEBUG(COND)) {
Line 950  compare_function(Boolean doEval)
Line 940  compare_function(Boolean doEval)
          * binary operator) and set to invert the evaluation           * binary operator) and set to invert the evaluation
          * function if condInvert is TRUE.           * function if condInvert is TRUE.
          */           */
         if (isdigit((unsigned char)condExpr[0])) {          if (isdigit((unsigned char)condExpr[0]) || strchr("+-", condExpr[0])) {
             /*              /*
              * Variables may already be substituted               * Variables may already be substituted
              * by the time we get here.               * by the time we get here.

Legend:
Removed from v.1.45  
changed lines
  Added in v.1.46

CVSweb <webmaster@jp.NetBSD.org>