MSVCRT_scanf: Handle %n

Uwe Bonnes bon at elektron.ikp.physik.tu-darmstadt.de
Sun Oct 5 10:03:31 CDT 2003


Changelog:
	dlls/msvcrt/scan.h
	%n returns the number of consumed characters
-- 
Uwe Bonnes                bon at elektron.ikp.physik.tu-darmstadt.de

Institut fuer Kernphysik  Schlossgartenstrasse 9  64289 Darmstadt
--------- Tel. 06151 162516 -------- Fax. 06151 164321 ----------
Index: wine/dlls/msvcrt/scanf.h
===================================================================
RCS file: /home/wine/wine/dlls/msvcrt/scanf.h,v
retrieving revision 1.10
diff -u -r1.10 scanf.h
--- wine/dlls/msvcrt/scanf.h	13 May 2003 23:38:46 -0000	1.10
+++ wine/dlls/msvcrt/scanf.h	5 Oct 2003 14:59:11 -0000
@@ -42,15 +42,15 @@
 #endif /* WIDE_SCANF */
 
 #ifdef CONSOLE
-#define _GETC_(file) _getch()
-#define _UNGETC_(nch, file) _ungetch(nch)
+#define _GETC_(file) _getch();consumed++
+#define _UNGETC_(nch, file) _ungetch(nch);consumed--
 #define _FUNCTION_ _cscanf(const _CHAR_ *format, ...)
 #else
 #ifdef STRING
 #undef _EOF_
 #define _EOF_ 0
-#define _GETC_(file) *file++
-#define _UNGETC_(nch, file) file--
+#define _GETC_(file) *file++,consumed++
+#define _UNGETC_(nch, file) file--,consumed--
 #ifdef WIDE_SCANF
 #define _FUNCTION_ MSVCRT_swscanf(const MSVCRT_wchar_t *file, const MSVCRT_wchar_t *format, ...)
 #else /* WIDE_SCANF */
@@ -58,12 +58,12 @@
 #endif /* WIDE_SCANF */
 #else /* STRING */
 #ifdef WIDE_SCANF
-#define _GETC_(file) MSVCRT_fgetwc(file)
-#define _UNGETC_(nch, file) MSVCRT_ungetwc(nch, file)
+#define _GETC_(file) MSVCRT_fgetwc(file),consumed++
+#define _UNGETC_(nch, file) MSVCRT_ungetwc(nch, file);consumed--
 #define _FUNCTION_ MSVCRT_fwscanf(MSVCRT_FILE* file, const MSVCRT_wchar_t *format, ...)
 #else /* WIDE_SCANF */
-#define _GETC_(file) MSVCRT_fgetc(file)
-#define _UNGETC_(nch, file) MSVCRT_ungetc(nch, file)
+#define _GETC_(file) MSVCRT_fgetc(file),consumed++
+#define _UNGETC_(nch, file) MSVCRT_ungetc(nch, file);consumed--
 #define _FUNCTION_ MSVCRT_fscanf(MSVCRT_FILE* file, const char *format, ...)
 #endif /* WIDE_SCANF */
 #endif /* STRING */
@@ -76,7 +76,7 @@
  * more types of format spec.
  */
 int _FUNCTION_ {
-    int rd = 0;
+    int rd = 0, consumed = 0;
     int nch;
     va_list ap;
     if (!*format) return 0;
@@ -428,9 +428,10 @@
 	        }
 		break;
 	    case 'n': {
+	      TRACE("treating \'n\' consumed %d prefetched %d\n", consumed, (nch!=_EOF_)? 1 : 0);
  		    if (!suppress) {
 			int*n = va_arg(ap, int*);
-			*n = rd;
+			*n = consumed - (nch!=_EOF_);
 		    }
 	        }
 		break;



More information about the wine-patches mailing list