[LON-CAPA-cvs] cvs: capa /capa51/pProj capaCommon.c

albertel lon-capa-cvs@mail.lon-capa.org
Thu, 01 Dec 2005 20:05:25 -0000


albertel		Thu Dec  1 15:05:25 2005 EDT

  Modified files:              
    /capa/capa51/pProj	capaCommon.c 
  Log:
  - BUG#4475 making the number parser more picky
  now only accepts
  
  number (*|x|X) 10 ^ (-|+|) integer
  or
  10 ^ (-|+|) integer
  
  rather than what it did previously which was:
  number (*|x|X) number ^ (-|+|) number
  or
  number ^ (-|+|) number
  
  
  
Index: capa/capa51/pProj/capaCommon.c
diff -u capa/capa51/pProj/capaCommon.c:1.24 capa/capa51/pProj/capaCommon.c:1.25
--- capa/capa51/pProj/capaCommon.c:1.24	Tue Jun  1 15:57:18 2004
+++ capa/capa51/pProj/capaCommon.c	Thu Dec  1 15:05:22 2005
@@ -2454,7 +2454,8 @@
 /*          num_p  : the numerical part in string */
 /*          unit_p : the unit string */
 /* num_p is used to calculate sig figs */
-/* return :   0  empty string          */
+/* return :  -1  invalid string        */
+/*            0  empty string          */
 /*            1  number without units  */
 /*            2  empty number with units */
 /*            3  number with units       */
@@ -2505,8 +2506,11 @@
     
     e_part = 1.0;  /* default power */
     base_str[b_idx] = 0; /* initialize base_str[] */
-    while( isdigit(buf[idx]) || buf[idx] == '.' ) { /* should start with a digit or . */
+    if( buf[idx] == '1' && buf[idx+1] == '0') {
       base_str[b_idx++] = buf[idx++];
+      base_str[b_idx++] = buf[idx++];
+    } else {
+      return (-1);
     }
     base_str[b_idx] = 0; /* terminate base_str[] */
     while( isspace(buf[idx]) ) { idx++; } /* skip over white spaces */
@@ -2520,7 +2524,7 @@
       while( isspace(buf[idx]) ) { idx++; }
       if( isdigit(buf[idx]) || buf[idx] == '+' || buf[idx] == '-' )  {
         exp_str[e_idx] = 0;  /* initialize exp_str[], again */
-        while( isdigit(buf[idx]) || buf[idx] == '.' || buf[idx] == '+' || buf[idx] == '-' ) {
+        while( isdigit(buf[idx]) /*|| buf[idx] == '.'*/ || buf[idx] == '+' || buf[idx] == '-' ) {
           exp_str[e_idx++] = buf[idx++];
         }
         exp_str[e_idx] = 0;  /* terminate exp_str[] */
@@ -2554,7 +2558,7 @@
     while( isspace(buf[idx]) ) { idx++; }
     if( isdigit(buf[idx]) || buf[idx] == '+' || buf[idx] == '-' )  {
         exp_str[e_idx] = 0;
-        while( isdigit(buf[idx]) || buf[idx] == '.' || buf[idx] == '+' || buf[idx] == '-' ) {
+        while( isdigit(buf[idx]) /*|| buf[idx] == '.'*/ || buf[idx] == '+' || buf[idx] == '-' ) {
           exp_str[e_idx++] = buf[idx++];
         }
         exp_str[e_idx] = 0;
@@ -2565,6 +2569,9 @@
     }
     sscanf(exp_str, "%lg", &e_part);
     sscanf(num_str, "%lg", &n_part);
+    if( n_part != 10 ) {
+      return (-1);
+    }
     result = pow(n_part,e_part);
     errcode = errcode | 1;
   } else {  /* number unit */
@@ -2953,8 +2960,10 @@
                 all_alphabet = 0;
               }
             }
-            if( !all_alphabet ) { /* answer string is not all alphabets */
+            if( !all_alphabet ) {
               outcome = split_num_unit(ans,&n_part,num_str,unit_str);
+	    }
+	    if( outcome > 0 ) {
               if( outcome > 1 ) { /* with both num and unit parts or only unit part */
                 if( u_p != NULL ) {
 		  result = check_correct_unit(unit_str,u_p,&scale);
@@ -3122,6 +3131,8 @@
             }
             if( !all_alphabet ) {
               outcome = split_num_unit(answer,&n_part,input,unit_str);
+	    }
+	    if( outcome > 0 ) {
               if( outcome > 1 ) { /* with both num and unit parts or only unit part */
                 if( p->ans_unit != NULL ) {
 		  result = check_correct_unit(unit_str,p->ans_unit,&scale);