[Msvcrt] Scanf and %[z-a] (1/2)

Peter Berg Larsen pebl at math.ku.dk
Mon Jan 5 19:49:49 CST 2004


Changelog:
- %[a-z] and %[z-a] are interpreted as equivalent to %[abcde...z]
  and adds scanf tests
-------------- next part --------------
diff -urp wine-20031212-org/dlls/msvcrt/scanf.h wine/dlls/msvcrt/scanf.h
--- wine-20031212-org/dlls/msvcrt/scanf.h	2003-10-10 02:00:19.000000000 +0200
+++ wine/dlls/msvcrt/scanf.h	2004-01-04 16:52:32.000000000 +0100
@@ -461,13 +461,17 @@ int _FUNCTION_ {
 			format++;
 		    }
                     while(*format && (*format != ']')) {
+			/* According to:
+			 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/html/_crt_scanf_width_specification.asp
+			 * "Note that %[a-z] and %[z-a] are interpreted as equivalent to %[abcde...z]." */
 			if((*format == '-') && (*(format + 1) != ']')) {
-			    int n = 0;
-			    for(;(n + *(format - 1)) < *(format + 1); n++)
-				RtlSetBits(&bitMask, n + *(format - 1), 1);
+			    if ((*(format - 1)) < *(format + 1))
+				RtlSetBits(&bitMask, *(format - 1) +1 , *(format + 1) - *(format - 1));
+			    else
+				RtlSetBits(&bitMask, *(format + 1)    , *(format - 1) - *(format + 1));			      
 			    format++;
-			}
-			RtlSetBits(&bitMask, *format, 1);
+			} else
+			    RtlSetBits(&bitMask, *format, 1);
 			format++;
 		    }
                     /* read until char is not suitable */
diff -urp wine-20031212-org/dlls/msvcrt/tests/scanf.c wine/dlls/msvcrt/tests/scanf.c
--- wine-20031212-org/dlls/msvcrt/tests/scanf.c	2003-10-28 01:04:42.000000000 +0100
+++ wine/dlls/msvcrt/tests/scanf.c	2004-01-04 05:24:46.000000000 +0100
@@ -57,19 +57,32 @@ static void test_sscanf( void )
     ok( sscanf(buffer, format, &result) == 1, "sscanf failed" );
     ok( result == 12, "sscanf reads %x instead of %x", result, 12 );
 
-    /*Check float */
+    /* Check float */
     ret = sprintf(buffer,"%f %f",res1, res2);
     ret = sscanf(buffer,"%f%f",&res11, &res12);
     ok( (res11 == res1) && (res12 == res2), "Error reading floats");
+
+    /* check strings */
     ret = sprintf(buffer," %s", pname);
     ret = sscanf(buffer,"%*c%[^\n]",buffer1);
     ok( ret == 1, "Error with format \"%s\"","%*c%[^\n]");
     ok( strncmp(pname,buffer1,strlen(buffer1)) == 0, "Error with \"%s\" \"%s\"",pname, buffer1);
+
+    ret = sscanf("abcefgdh","%*[a-cg-e]%c",&buffer[0]);
+    ok( ret == 1, "Error with format \"%s\"","%*[a-cg-e]%c");
+    ok( buffer[0] == 'd', "Error with \"abcefgdh\" \"%c\"", buffer[0]);
+
+    ret = sscanf("abcefgdh","%*[a-cd-dg-e]%c",&buffer[0]);
+    ok( ret == 1, "Error with format \"%s\"","%*[a-cd-dg-e]%c");
+    ok( buffer[0] == 'h', "Error with \"abcefgdh\" \"%c\"", buffer[0]);
+
+    /* check digits */
     ret = sprintf(buffer,"%d:%d:%d",hour,min,sec);
     ret = sscanf(buffer,"%d%n",&number,&number_so_far);
     ok(ret == 1 , "problem with format arg \"%%d%%n\"");
     ok(number == hour,"Read wrong arg %d instead of %d",number, hour);
     ok(number_so_far == 2,"Read wrong arg for \"%%n\" %d instead of 2",number_so_far);
+
     ret = sscanf(buffer+2,"%*c%n",&number_so_far);
     ok(ret == 0 , "problem with format arg \"%%*c%%n\"");
     ok(number_so_far == 1,"Read wrong arg for \"%%n\" %d instead of 2",number_so_far);


More information about the wine-patches mailing list