[ros-diffs] [tkreuzer] 49499: [CRT] New implementation of all printf functions. It's stream based (like MS one is) rather than buffer based (like our old is). Floating point is not 100% finished, but current i...

tkreuzer at svn.reactos.org tkreuzer at svn.reactos.org
Fri Nov 5 22:21:37 UTC 2010


Author: tkreuzer
Date: Fri Nov  5 22:21:36 2010
New Revision: 49499

URL: http://svn.reactos.org/svn/reactos?rev=49499&view=rev
Log:
[CRT]
New implementation of all printf functions. It's stream based (like MS one is) rather than buffer based (like our old is). Floating point is not 100% finished, but current implementation is good enough to boot. It can be enabled by a config switch.

Added:
    trunk/reactos/lib/sdk/crt/printf/   (with props)
    trunk/reactos/lib/sdk/crt/printf/_cprintf.c   (with props)
    trunk/reactos/lib/sdk/crt/printf/_snprintf.c   (with props)
    trunk/reactos/lib/sdk/crt/printf/_snwprintf.c   (with props)
    trunk/reactos/lib/sdk/crt/printf/_vcprintf.c   (with props)
    trunk/reactos/lib/sdk/crt/printf/_vsnprintf.c   (with props)
    trunk/reactos/lib/sdk/crt/printf/_vsnwprintf.c   (with props)
    trunk/reactos/lib/sdk/crt/printf/fprintf.c   (with props)
    trunk/reactos/lib/sdk/crt/printf/fwprintf.c   (with props)
    trunk/reactos/lib/sdk/crt/printf/printf.c   (with props)
    trunk/reactos/lib/sdk/crt/printf/sprintf.c   (with props)
    trunk/reactos/lib/sdk/crt/printf/streamout.c   (with props)
    trunk/reactos/lib/sdk/crt/printf/swprintf.c   (with props)
    trunk/reactos/lib/sdk/crt/printf/vfprintf.c   (with props)
    trunk/reactos/lib/sdk/crt/printf/vfwprintf.c   (with props)
    trunk/reactos/lib/sdk/crt/printf/vprintf.c   (with props)
    trunk/reactos/lib/sdk/crt/printf/vsprintf.c   (with props)
    trunk/reactos/lib/sdk/crt/printf/vswprintf.c   (with props)
    trunk/reactos/lib/sdk/crt/printf/vwprintf.c   (with props)
    trunk/reactos/lib/sdk/crt/printf/wprintf.c   (with props)
    trunk/reactos/lib/sdk/crt/printf/wstreamout.c   (with props)
    trunk/reactos/lib/sdk/crt/stdio/lock_file.c   (with props)
Modified:
    trunk/reactos/   (props changed)
    trunk/reactos/boot/freeldr/freeldr/debug.c
    trunk/reactos/config.template.rbuild
    trunk/reactos/lib/rtl/rtl.rbuild
    trunk/reactos/lib/rtl/sprintf.c
    trunk/reactos/lib/rtl/swprintf.c
    trunk/reactos/lib/sdk/crt/conio/cprintf.c
    trunk/reactos/lib/sdk/crt/crt.rbuild
    trunk/reactos/lib/sdk/crt/libcntpr.rbuild
    trunk/reactos/lib/sdk/crt/mbstring/mbstrlen.c
    trunk/reactos/lib/sdk/crt/stdio/file.c
    trunk/reactos/lib/sdk/crt/stdio/lnx_sprintf.c
    trunk/reactos/lib/sdk/crt/string/wcs.c
    trunk/reactos/modules/directory.rbuild

Propchange: trunk/reactos/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Nov  5 22:21:36 2010
@@ -1,4 +1,4 @@
 /branches/header-work:45691-47721
-/branches/reactos-yarotows:45219-49273
+/branches/reactos-yarotows:45219-46371,46373-48025,48027-49273
 /branches/ros-amd64-bringup:36852
 /branches/ros-amd64-bringup/reactos:34711-34712,34741,34743,34770,34780-34782,34803,34812,34839,34842,34864,34870,34874,34877,34908-34909,34917,34965,35323-35324,35347-35348,35361,35436,35509,35515,35588,35655,35683,35739,35746,35762,35771,35777,35781,35789,35805,35823,35827,35902,35904-35906,35942,35947-35949,35952-35953,35966,36011-36013,36172,36360,36380,36388-36389,36393,36397,36443,36445,36475,36502-36503,36505,36570,36614,36852,36898-36899,36930,36936,36949,36951,36958,36961,36964,36969,36972,36987-36988,36990,36992,37019,37322-37323,37333-37334,37434,37472,37475,37536,37820-37821,37868-37869,37873,37990-37991,38013-38014,38092,38100,38148-38151,38264-38265,38268,38355,39151,39333,39335,39345,39639,40120,40122-40123,40125,40127-40128,40155,40247,40324,40608,40753,40926-40928,40986-40987,40989,40991,40993,40995-40996,41000-41001,41027-41030,41044-41045,41047-41050,41052,41070,41082-41086,41097-41098,41101,41449,41479-41480,41483-41485,41499-41500,41502,41531,41536,41540,41546-41547,41549,43080,43426,43451,43454,43506,43566,43574,43598,43600-43602,43604-43605,43677,43682,43757,43775,43836,43838-43840,43852,43857-43858,43860,43905-43907,43952,43954,43965,43969,43979,43981,43992,44002,44036-44037,44039-44040,44044-44045,44053,44065,44095,44123,44143-44144,44205,44238,44257,44259,44294,44338-44339,44385,44389,44391,44426,44460,44467-44468,44470-44471,44499,44501,44503-44504,44506,44510-44512,44521,44523-44526,44530,44540,44601,44634,44639,44772,44818,45124,45126-45127,45430,46394,46404,46478,46511,46523-46524,46526,46534-46535,46537-46539,46589,46805,46868,47472,47846-47847,47878,47882

Modified: trunk/reactos/boot/freeldr/freeldr/debug.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/debug.c?rev=49499&r1=49498&r2=49499&view=diff
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/debug.c [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/freeldr/debug.c [iso-8859-1] Fri Nov  5 22:21:36 2010
@@ -66,6 +66,19 @@
 
 BOOLEAN	DebugStartOfLine = TRUE;
 
+// We need to emulate these, because the original ones don't work in freeldr
+int __cdecl wctomb(char *mbchar, wchar_t wchar)
+{
+    *mbchar = wchar;
+    return 1;
+}
+
+int __cdecl mbtowc (wchar_t *wchar, const char *mbchar, size_t count)
+{
+    *wchar = *mbchar;
+    return 1;
+}
+
 VOID DebugInit(VOID)
 {
 	if (DebugPort & RS232)

Modified: trunk/reactos/config.template.rbuild
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/config.template.rbuild?rev=49499&r1=49498&r2=49499&view=diff
==============================================================================
--- trunk/reactos/config.template.rbuild [iso-8859-1] (original)
+++ trunk/reactos/config.template.rbuild [iso-8859-1] Fri Nov  5 22:21:36 2010
@@ -104,4 +104,9 @@
 -->
 <property name="NEWCC" value="0" />
 
+<!--
+    Whether to compile the new sprintf
+-->
+<property name="NEWSPRINTF" value="1" />
+
 </group>

Modified: trunk/reactos/lib/rtl/rtl.rbuild
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/rtl.rbuild?rev=49499&r1=49498&r2=49499&view=diff
==============================================================================
--- trunk/reactos/lib/rtl/rtl.rbuild [iso-8859-1] (original)
+++ trunk/reactos/lib/rtl/rtl.rbuild [iso-8859-1] Fri Nov  5 22:21:36 2010
@@ -6,6 +6,11 @@
 	<define name="_NTSYSTEM_" />
 	<define name="_NTDLLBUILD_" />
 	<include base="rtl">.</include>
+
+	<if property="NEWSPRINTF" value="1">
+		<define name="USE_NEW_SPRINTF" />
+	</if>
+
 	<if property="ARCH" value="i386">
 		<directory name="i386">
 			<file>debug_asm.S</file>

Modified: trunk/reactos/lib/rtl/sprintf.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/sprintf.c?rev=49499&r1=49498&r2=49499&view=diff
==============================================================================
--- trunk/reactos/lib/rtl/sprintf.c [iso-8859-1] (original)
+++ trunk/reactos/lib/rtl/sprintf.c [iso-8859-1] Fri Nov  5 22:21:36 2010
@@ -1,3 +1,5 @@
+
+#ifndef USE_NEW_SPRINTF
 /*
  * PROGRAMMERS:     David Welch
  *                  Eric Kohl
@@ -741,3 +743,5 @@
 }
 
 /* EOF */
+#endif
+

Modified: trunk/reactos/lib/rtl/swprintf.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/swprintf.c?rev=49499&r1=49498&r2=49499&view=diff
==============================================================================
--- trunk/reactos/lib/rtl/swprintf.c [iso-8859-1] (original)
+++ trunk/reactos/lib/rtl/swprintf.c [iso-8859-1] Fri Nov  5 22:21:36 2010
@@ -1,3 +1,4 @@
+#ifndef USE_NEW_SPRINTF
 /*
  * PROGRAMMERS:     David Welch
  *                  Eric Kohl
@@ -740,3 +741,4 @@
 }
 
 /* EOF */
+#endif

Modified: trunk/reactos/lib/sdk/crt/conio/cprintf.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/conio/cprintf.c?rev=49499&r1=49498&r2=49499&view=diff
==============================================================================
--- trunk/reactos/lib/sdk/crt/conio/cprintf.c [iso-8859-1] (original)
+++ trunk/reactos/lib/sdk/crt/conio/cprintf.c [iso-8859-1] Fri Nov  5 22:21:36 2010
@@ -5,6 +5,7 @@
  * PURPOSE:          C Runtime
  * PROGRAMMER:       Magnus Olsen (Imported from wine cvs 2006-05-23)
  */
+#ifndef USE_NEW_SPRINTF
 
 #include <precomp.h>
 
@@ -38,3 +39,5 @@
       free (mem);
   return retval;
 }
+
+#endif

Modified: trunk/reactos/lib/sdk/crt/crt.rbuild
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/crt.rbuild?rev=49499&r1=49498&r2=49499&view=diff
==============================================================================
--- trunk/reactos/lib/sdk/crt/crt.rbuild [iso-8859-1] (original)
+++ trunk/reactos/lib/sdk/crt/crt.rbuild [iso-8859-1] Fri Nov  5 22:21:36 2010
@@ -26,6 +26,33 @@
 	<define name="_MSVCRT_" />
 	<define name="_MT" />
 	<define name="_CRTBLD" />
+
+	<if property="NEWSPRINTF" value="1">
+	<define name="USE_NEW_SPRINTF" />
+	<directory name="printf">
+		<file>_cprintf.c</file>
+		<file>_snprintf.c</file>
+		<file>_snwprintf.c</file>
+		<file>_vcprintf.c</file>
+		<file>_vsnprintf.c</file>
+		<file>_vsnwprintf.c</file>
+		<file>fprintf.c</file>
+		<file>fwprintf.c</file>
+		<file>printf.c</file>
+		<file>sprintf.c</file>
+		<file>streamout.c</file>
+		<file>swprintf.c</file>
+		<file>vfprintf.c</file>
+		<file>vfwprintf.c</file>
+		<file>vprintf.c</file>
+		<file>vsprintf.c</file>
+		<file>vswprintf.c</file>
+		<file>vwprintf.c</file>
+		<file>wprintf.c</file>
+		<file>wstreamout.c</file>
+	</directory>
+	</if>
+
 	<directory name="conio">
 		<file>cgets.c</file>
 		<file>cprintf.c</file>
@@ -123,6 +150,7 @@
 		<file>ldiv.c</file>
 		<file>logf.c</file>
 		<file>modf.c</file>
+		<file>powf.c</file>
 		<file>rand.c</file>
 		<file>s_modf.c</file>
 		<file>sinf.c</file>
@@ -343,6 +371,7 @@
 		<file>wpopen.c</file>
 		<file>wstat.c</file>
 		<file>wstat64.c</file>
+		<file>lock_file.c</file>
 	</directory>
 	<directory name="stdlib">
 		<file>_exit.c</file>

Modified: trunk/reactos/lib/sdk/crt/libcntpr.rbuild
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/libcntpr.rbuild?rev=49499&r1=49498&r2=49499&view=diff
==============================================================================
--- trunk/reactos/lib/sdk/crt/libcntpr.rbuild [iso-8859-1] (original)
+++ trunk/reactos/lib/sdk/crt/libcntpr.rbuild [iso-8859-1] Fri Nov  5 22:21:36 2010
@@ -9,6 +9,25 @@
 	<define name="_LIBCNT_" />
 	<define name="_CRTBLD" />
 	<define name="__CRT__NO_INLINE" />
+
+	<if property="NEWSPRINTF" value="1">
+	<define name="USE_NEW_SPRINTF" />
+	<directory name="printf">
+		<file>_snprintf.c</file>
+		<file>_snwprintf.c</file>
+		<file>_vcprintf.c</file>
+		<file>_vsnprintf.c</file>
+		<file>_vsnwprintf.c</file>
+		<file>sprintf.c</file>
+		<file>streamout.c</file>
+		<file>swprintf.c</file>
+		<file>vprintf.c</file>
+		<file>vsprintf.c</file>
+		<file>vswprintf.c</file>
+		<file>wstreamout.c</file>
+	</directory>
+	</if>
+
 	<if property="ARCH" value="i386">
 		<define name="__MINGW_IMPORT">"extern __attribute__ ((dllexport))"</define>
 	</if>
@@ -32,6 +51,9 @@
 				<file>seh.s</file>
 			</directory>
 		</if>
+	</directory>
+	<directory name="float">
+		<file>isnan.c</file>
 	</directory>
 	<directory name="math">
 		<if property="ARCH" value="i386">
@@ -54,6 +76,7 @@
 				<file>floor_asm.s</file>
 				<file>ftol_asm.s</file>
 				<file>log_asm.s</file>
+				<file>log10_asm.s</file>
 				<file>pow_asm.s</file>
 				<file>sin_asm.s</file>
 				<file>sqrt_asm.s</file>
@@ -207,6 +230,10 @@
 		<file>wtol.c</file>
 	</directory>
 
+	<directory name="mbstring">
+		<file>mbstrlen.c</file>
+	</directory>
+
 	<directory name="wstring">
 		<file>wcsicmp.c</file>
 		<file>wcslwr.c</file>

Modified: trunk/reactos/lib/sdk/crt/mbstring/mbstrlen.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/mbstring/mbstrlen.c?rev=49499&r1=49498&r2=49499&view=diff
==============================================================================
--- trunk/reactos/lib/sdk/crt/mbstring/mbstrlen.c [iso-8859-1] (original)
+++ trunk/reactos/lib/sdk/crt/mbstring/mbstrlen.c [iso-8859-1] Fri Nov  5 22:21:36 2010
@@ -12,7 +12,12 @@
 #include <mbstring.h>
 #include <stdlib.h>
 
+#ifdef _LIBCNT_
+unsigned short *NlsLeadByteInfo;
+#define isleadbyte(c) NlsLeadByteInfo[c]
+#else
 int isleadbyte(int byte);
+#endif
 
 /*
  * @implemented

Propchange: trunk/reactos/lib/sdk/crt/printf/
------------------------------------------------------------------------------
--- bugtraq:logregex (added)
+++ bugtraq:logregex Fri Nov  5 22:21:36 2010
@@ -1,0 +1,2 @@
+([Ii]ssue|[Bb]ug)s? #?(\d+)(,? ?#?(\d+))*(,? ?(and |or )?#?(\d+))?
+(\d+)

Propchange: trunk/reactos/lib/sdk/crt/printf/
------------------------------------------------------------------------------
    bugtraq:message = See issue #%BUGID% for more details.

Propchange: trunk/reactos/lib/sdk/crt/printf/
------------------------------------------------------------------------------
    bugtraq:url = http://www.reactos.org/bugzilla/show_bug.cgi?id=%BUGID%

Propchange: trunk/reactos/lib/sdk/crt/printf/
------------------------------------------------------------------------------
    tsvn:logminsize = 10

Added: trunk/reactos/lib/sdk/crt/printf/_cprintf.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/printf/_cprintf.c?rev=49499&view=auto
==============================================================================
--- trunk/reactos/lib/sdk/crt/printf/_cprintf.c (added)
+++ trunk/reactos/lib/sdk/crt/printf/_cprintf.c [iso-8859-1] Fri Nov  5 22:21:36 2010
@@ -1,0 +1,25 @@
+/*
+ * COPYRIGHT:       GNU GPL, see COPYING in the top level directory
+ * PROJECT:         ReactOS crt library
+ * FILE:            lib/sdk/crt/printf/_vcprintf.c
+ * PURPOSE:         Implementation of _vcprintf
+ * PROGRAMMER:      Timo Kreuzer
+ */
+
+#include <stdarg.h>
+
+int _vcprintf(const char* format, va_list argptr);
+
+int
+_cdecl
+_cprintf(const char * format, ...)
+{
+    va_list argptr;
+    int result;
+
+    va_start(argptr, format);
+    result = _vcprintf(format, argptr);
+    va_end(argptr);
+    return result;
+}
+

Propchange: trunk/reactos/lib/sdk/crt/printf/_cprintf.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: trunk/reactos/lib/sdk/crt/printf/_snprintf.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/printf/_snprintf.c?rev=49499&view=auto
==============================================================================
--- trunk/reactos/lib/sdk/crt/printf/_snprintf.c (added)
+++ trunk/reactos/lib/sdk/crt/printf/_snprintf.c [iso-8859-1] Fri Nov  5 22:21:36 2010
@@ -1,0 +1,39 @@
+/*
+ * COPYRIGHT:       GNU GPL, see COPYING in the top level directory
+ * PROJECT:         ReactOS crt library
+ * FILE:            lib/sdk/crt/printf/_snprintf.c
+ * PURPOSE:         Implementation of _snprintf
+ * PROGRAMMER:      Timo Kreuzer
+ */
+
+#include <stdio.h>
+#include <stdarg.h>
+#include <tchar.h>
+
+int _cdecl streamout(FILE *stream, const char *format, va_list argptr);
+
+int
+_cdecl
+_snprintf(char *buffer, size_t count, const char *format, ...)
+{
+    va_list argptr;
+    int result;
+    FILE stream;
+
+    stream._base = buffer;
+    stream._ptr = stream._base;
+    stream._charbuf = 0;
+    stream._bufsiz = (unsigned long)-1;
+    stream._cnt = stream._bufsiz;
+    stream._flag = 0;
+    stream._tmpfname = 0;
+
+    va_start(argptr, format);
+    result = streamout(&stream, format, argptr);
+    va_end(argptr);
+    
+    *stream._ptr = '\0';
+    return result;
+}
+
+

Propchange: trunk/reactos/lib/sdk/crt/printf/_snprintf.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: trunk/reactos/lib/sdk/crt/printf/_snwprintf.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/printf/_snwprintf.c?rev=49499&view=auto
==============================================================================
--- trunk/reactos/lib/sdk/crt/printf/_snwprintf.c (added)
+++ trunk/reactos/lib/sdk/crt/printf/_snwprintf.c [iso-8859-1] Fri Nov  5 22:21:36 2010
@@ -1,0 +1,42 @@
+/*
+ * COPYRIGHT:       GNU GPL, see COPYING in the top level directory
+ * PROJECT:         ReactOS crt library
+ * FILE:            lib/sdk/crt/printf/_snwprintf.c
+ * PURPOSE:         Implementation of _snwprintf
+ * PROGRAMMER:      Timo Kreuzer
+ */
+
+#include <stdio.h>
+#include <stdarg.h>
+
+int _cdecl wstreamout(FILE *stream, const wchar_t *format, va_list argptr);
+
+int
+__cdecl
+_snwprintf(
+   wchar_t *buffer,
+   size_t count,
+   const wchar_t *format,
+   ...)
+{
+    va_list argptr;
+    int result;
+    FILE stream;
+
+    stream._base = (char*)buffer;
+    stream._ptr = stream._base;
+    stream._bufsiz = count * sizeof(wchar_t);
+    stream._cnt = stream._bufsiz;
+    stream._flag = _IOSTRG | _IOWRT;
+    stream._tmpfname = 0;
+    stream._charbuf = 0;
+
+    va_start(argptr, format);
+    result = wstreamout(&stream, format, argptr);
+    va_end(argptr);
+
+    /* Only zero terminate if there is enough space left */
+    if (stream._cnt >= sizeof(wchar_t)) *(wchar_t*)stream._ptr = L'\0';
+
+    return result;
+}

Propchange: trunk/reactos/lib/sdk/crt/printf/_snwprintf.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: trunk/reactos/lib/sdk/crt/printf/_vcprintf.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/printf/_vcprintf.c?rev=49499&view=auto
==============================================================================
--- trunk/reactos/lib/sdk/crt/printf/_vcprintf.c (added)
+++ trunk/reactos/lib/sdk/crt/printf/_vcprintf.c [iso-8859-1] Fri Nov  5 22:21:36 2010
@@ -1,0 +1,18 @@
+/*
+ * COPYRIGHT:       GNU GPL, see COPYING in the top level directory
+ * PROJECT:         ReactOS crt library
+ * FILE:            lib/sdk/crt/printf/_vcprintf.c
+ * PURPOSE:         Implementation of _vcprintf
+ * PROGRAMMER:      Timo Kreuzer
+ */
+
+#include <stdarg.h>
+
+int
+_cdecl
+_vcprintf(const char* format, va_list va)
+{
+    return 0;
+}
+
+

Propchange: trunk/reactos/lib/sdk/crt/printf/_vcprintf.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: trunk/reactos/lib/sdk/crt/printf/_vsnprintf.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/printf/_vsnprintf.c?rev=49499&view=auto
==============================================================================
--- trunk/reactos/lib/sdk/crt/printf/_vsnprintf.c (added)
+++ trunk/reactos/lib/sdk/crt/printf/_vsnprintf.c [iso-8859-1] Fri Nov  5 22:21:36 2010
@@ -1,0 +1,37 @@
+/*
+ * COPYRIGHT:       GNU GPL, see COPYING in the top level directory
+ * PROJECT:         ReactOS crt library
+ * FILE:            lib/sdk/crt/printf/_vsnprintf.c
+ * PURPOSE:         Implementation of _vsnprintf
+ * PROGRAMMER:      Timo Kreuzer
+ */
+
+#include <stdio.h>
+#include <stdarg.h>
+
+int _cdecl streamout(FILE *stream, const char *format, va_list argptr);
+
+int
+__cdecl
+_vsnprintf(
+   char *buffer,
+   size_t count,
+   const char *format,
+   va_list argptr)
+{
+    int result;
+    FILE stream;
+
+    stream._base = buffer;
+    stream._ptr = stream._base;
+    stream._bufsiz = count;
+    stream._cnt = stream._bufsiz;
+    stream._flag = _IOSTRG | _IOWRT;
+    stream._tmpfname = 0;
+    stream._charbuf = 0;
+
+    result = streamout(&stream, format, argptr);
+    *stream._ptr = '\0';
+
+    return result;
+}

Propchange: trunk/reactos/lib/sdk/crt/printf/_vsnprintf.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: trunk/reactos/lib/sdk/crt/printf/_vsnwprintf.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/printf/_vsnwprintf.c?rev=49499&view=auto
==============================================================================
--- trunk/reactos/lib/sdk/crt/printf/_vsnwprintf.c (added)
+++ trunk/reactos/lib/sdk/crt/printf/_vsnwprintf.c [iso-8859-1] Fri Nov  5 22:21:36 2010
@@ -1,0 +1,37 @@
+/*
+ * COPYRIGHT:       GNU GPL, see COPYING in the top level directory
+ * PROJECT:         ReactOS crt library
+ * FILE:            lib/sdk/crt/printf/_vsnwprintf.c
+ * PURPOSE:         Implementation of _vsnwprintf
+ * PROGRAMMER:      Timo Kreuzer
+ */
+
+#include <stdio.h>
+#include <stdarg.h>
+
+int _cdecl wstreamout(FILE *stream, const wchar_t *format, va_list argptr);
+
+int
+__cdecl
+_vsnwprintf(
+   wchar_t *buffer,
+   size_t count,
+   const wchar_t *format,
+   va_list argptr)
+{
+    int result;
+    FILE stream;
+
+    stream._base = (char*)buffer;
+    stream._ptr = stream._base;
+    stream._bufsiz = count * sizeof(wchar_t);
+    stream._cnt = stream._bufsiz;
+    stream._flag = _IOSTRG | _IOWRT;
+    stream._tmpfname = 0;
+    stream._charbuf = 0;
+
+    result = wstreamout(&stream, format, argptr);
+    *(wchar_t*)stream._ptr = L'\0';
+
+    return result;
+}

Propchange: trunk/reactos/lib/sdk/crt/printf/_vsnwprintf.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: trunk/reactos/lib/sdk/crt/printf/fprintf.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/printf/fprintf.c?rev=49499&view=auto
==============================================================================
--- trunk/reactos/lib/sdk/crt/printf/fprintf.c (added)
+++ trunk/reactos/lib/sdk/crt/printf/fprintf.c [iso-8859-1] Fri Nov  5 22:21:36 2010
@@ -1,0 +1,24 @@
+/*
+ * COPYRIGHT:       GNU GPL, see COPYING in the top level directory
+ * PROJECT:         ReactOS crt library
+ * FILE:            lib/sdk/crt/printf/fprintf.c
+ * PURPOSE:         Implementation of fprintf
+ * PROGRAMMER:      Timo Kreuzer
+ */
+
+#include <stdio.h>
+#include <stdarg.h>
+
+int
+_cdecl
+fprintf(FILE *stream, const char *format, ...)
+{
+    va_list argptr;
+    int result;
+
+    va_start(argptr, format);
+    result = vfprintf(stream, format, argptr);
+    va_end(argptr);
+    return result;
+}
+

Propchange: trunk/reactos/lib/sdk/crt/printf/fprintf.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: trunk/reactos/lib/sdk/crt/printf/fwprintf.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/printf/fwprintf.c?rev=49499&view=auto
==============================================================================
--- trunk/reactos/lib/sdk/crt/printf/fwprintf.c (added)
+++ trunk/reactos/lib/sdk/crt/printf/fwprintf.c [iso-8859-1] Fri Nov  5 22:21:36 2010
@@ -1,0 +1,23 @@
+/*
+ * COPYRIGHT:       GNU GPL, see COPYING in the top level directory
+ * PROJECT:         ReactOS crt library
+ * FILE:            lib/sdk/crt/printf/fwprintf.c
+ * PURPOSE:         Implementation of fwprintf
+ * PROGRAMMER:      Timo Kreuzer
+ */
+
+#include <stdio.h>
+#include <stdarg.h>
+
+int
+__cdecl
+fwprintf(FILE* file, const wchar_t *format, ...)
+{
+    va_list argptr;
+    int result;
+
+    va_start(argptr, format);
+    result = vfwprintf(file, format, argptr);
+    va_end(argptr);
+    return result;
+}

Propchange: trunk/reactos/lib/sdk/crt/printf/fwprintf.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: trunk/reactos/lib/sdk/crt/printf/printf.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/printf/printf.c?rev=49499&view=auto
==============================================================================
--- trunk/reactos/lib/sdk/crt/printf/printf.c (added)
+++ trunk/reactos/lib/sdk/crt/printf/printf.c [iso-8859-1] Fri Nov  5 22:21:36 2010
@@ -1,0 +1,27 @@
+/*
+ * COPYRIGHT:       GNU GPL, see COPYING in the top level directory
+ * PROJECT:         ReactOS crt library
+ * FILE:            lib/sdk/crt/printf/printf.c
+ * PURPOSE:         Implementation of printf
+ * PROGRAMMER:      Timo Kreuzer
+ */
+
+#include <stdio.h>
+#include <stdarg.h>
+#include <tchar.h>
+
+int _cdecl streamout(FILE *stream, const char *format, va_list argptr);
+
+int
+_cdecl
+printf(const char *format, ...)
+{
+    va_list argptr;
+    int result;
+
+    va_start(argptr, format);
+    result = streamout(stdout, format, argptr);
+    va_end(argptr);
+    return result;
+}
+

Propchange: trunk/reactos/lib/sdk/crt/printf/printf.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: trunk/reactos/lib/sdk/crt/printf/sprintf.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/printf/sprintf.c?rev=49499&view=auto
==============================================================================
--- trunk/reactos/lib/sdk/crt/printf/sprintf.c (added)
+++ trunk/reactos/lib/sdk/crt/printf/sprintf.c [iso-8859-1] Fri Nov  5 22:21:36 2010
@@ -1,0 +1,38 @@
+/*
+ * COPYRIGHT:       GNU GPL, see COPYING in the top level directory
+ * PROJECT:         ReactOS crt library
+ * FILE:            lib/sdk/crt/printf/sprintf.c
+ * PURPOSE:         Implementation of sprintf
+ * PROGRAMMER:      Timo Kreuzer
+ */
+
+#include <stdio.h>
+#include <stdarg.h>
+#include <limits.h>
+
+int _cdecl streamout(FILE *stream, const char *format, va_list argptr);
+
+int
+_cdecl
+sprintf(char *buffer, const char *format, ...)
+{
+    va_list argptr;
+    int result;
+    FILE stream;
+
+    stream._base = buffer;
+    stream._ptr = stream._base;
+    stream._charbuf = 0;
+    stream._bufsiz = INT_MAX;
+    stream._cnt = stream._bufsiz;
+    stream._flag = 0;
+    stream._tmpfname = 0;
+
+    va_start(argptr, format);
+    result = streamout(&stream, format, argptr);
+    va_end(argptr);
+    
+    *stream._ptr = '\0';
+    return result;
+}
+

Propchange: trunk/reactos/lib/sdk/crt/printf/sprintf.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: trunk/reactos/lib/sdk/crt/printf/streamout.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/printf/streamout.c?rev=49499&view=auto
==============================================================================
--- trunk/reactos/lib/sdk/crt/printf/streamout.c (added)
+++ trunk/reactos/lib/sdk/crt/printf/streamout.c [iso-8859-1] Fri Nov  5 22:21:36 2010
@@ -1,0 +1,629 @@
+/*
+ * COPYRIGHT:       GNU GPL, see COPYING in the top level directory
+ * PROJECT:         ReactOS crt library
+ * FILE:            lib/sdk/crt/printf/streamout.c
+ * PURPOSE:         Implementation of streamout
+ * PROGRAMMER:      Timo Kreuzer
+ */
+
+#include <stdio.h>
+#include <stdarg.h>
+#include <tchar.h>
+#include <strings.h>
+#include <math.h>
+
+#ifdef _UNICODE
+#define streamout wstreamout
+#define format_float format_floatw
+#endif
+
+#define MB_CUR_MAX 10
+#define BUFFER_SIZE (32 + 17)
+
+int mbtowc(wchar_t *wchar, const char *mbchar, size_t count);
+int wctomb(char *mbchar, wchar_t wchar);
+
+typedef struct _STRING
+{
+  unsigned short Length;
+  unsigned short MaximumLength;
+  void *Buffer;
+} STRING;
+
+enum
+{
+    /* Formatting flags */
+    FLAG_ALIGN_LEFT =    0x01,
+    FLAG_FORCE_SIGN =    0x02,
+    FLAG_FORCE_SIGNSP =  0x04,
+    FLAG_PAD_ZERO =      0x08,
+    FLAG_SPECIAL =       0x10,
+
+    /* Data format flags */
+    FLAG_SHORT =         0x100,
+    FLAG_LONG =          0x200,
+    FLAG_WIDECHAR =      FLAG_LONG,
+    FLAG_INT64 =         0x400,
+#ifdef _WIN64
+    FLAG_INTPTR =        FLAG_INT64,
+#else
+    FLAG_INTPTR =        0,
+#endif
+    FLAG_LONGDOUBLE =    0x800,
+};
+
+#define va_arg_f(argptr, flags) \
+    (flags & FLAG_INT64) ? va_arg(argptr, __int64) : \
+    (flags & FLAG_SHORT) ? (short)va_arg(argptr, int) : \
+    va_arg(argptr, int)
+
+#define va_arg_fu(argptr, flags) \
+    (flags & FLAG_INT64) ? va_arg(argptr, unsigned __int64) : \
+    (flags & FLAG_SHORT) ? (unsigned short)va_arg(argptr, int) : \
+    va_arg(argptr, unsigned int)
+
+#define va_arg_ffp(argptr, flags) \
+    (flags & FLAG_LONGDOUBLE) ? va_arg(argptr, long double) : \
+    va_arg(argptr, double)
+
+#ifdef _LIBCNT_
+# define _flsbuf(chr, stream) 0
+#endif
+
+#define get_exp(f) floor(f > 0 ? log10(f) : log10(-f))
+
+void
+#ifdef _LIBCNT
+/* Due to restrictions in kernel mode regarding the use of floating point,
+   we prevent it from being inlined */
+__declspec(noinline)
+#endif
+format_float(
+    TCHAR chr,
+    unsigned int flags,
+    int precision,
+    TCHAR **string,
+    const TCHAR **prefix,
+    va_list *argptr)
+{
+    static const TCHAR digits_l[] = _T("0123456789abcdef0x");
+    static const TCHAR digits_u[] = _T("0123456789ABCDEF0X");
+    static const TCHAR _nan[] = _T("#QNAN");
+    static const TCHAR _infinity[] = _T("#INF");
+    const TCHAR *digits = digits_l;
+    int exponent = 0;
+    long double fpval;
+    int num_digits, val32, base = 10;
+    __int64 val64;
+
+    if (precision == -1) precision = 6;
+
+    fpval = va_arg_ffp(*argptr, flags);
+    exponent = get_exp(fpval);
+
+    switch (chr)
+    {
+        case _T('G'):
+            digits = digits_u;
+        case _T('g'):
+            if (exponent < -4 || exponent >= precision) goto case_e;
+            break;              
+
+        case _T('E'):
+            digits = digits_u;
+        case _T('e'):
+        case_e:
+            fpval /= pow(10., exponent);
+            val32 = exponent >= 0 ? exponent : -exponent;
+
+            // FIXME: handle length of exponent field: 
+            // http://msdn.microsoft.com/de-de/library/0fatw238%28VS.80%29.aspx
+            num_digits = 3;
+            while (num_digits--)
+            {
+                *--(*string) = digits[val32 % 10];
+                val32 /= 10;
+            }
+
+            /* Sign for the exponent */
+            *--(*string) = exponent > 0 ? _T('+') : _T('-');
+
+            /* Add 'e' or 'E' separator */
+            *--(*string) = digits[0xe];
+            break;
+
+        case _T('A'):
+            digits = digits_u;
+        case _T('a'):
+//            base = 16;
+            // FIXME: TODO
+
+        case _T('f'):
+            break;
+    }
+
+    /* CHECKME: Windows seems to handle a max of 17 digits(?) */
+    num_digits = precision <= 17 ? precision : 17;
+
+    /* Handle sign */
+    if (fpval < 0)
+    {
+        fpval = -fpval;
+        *prefix = _T("-");
+    }
+    else if (flags & FLAG_FORCE_SIGN)
+        *prefix = _T("+");
+    else if (flags & FLAG_FORCE_SIGNSP)
+        *prefix = _T(" ");
+
+    /* Handle special cases first */
+    if (_isnan(fpval))
+    {
+        (*string) -= sizeof(_nan) / sizeof(TCHAR) - 1;
+        _tcscpy((*string), _nan);
+        val64 = 1;
+    }
+    else if (!_finite(fpval))
+    {
+        (*string) -= sizeof(_infinity) / sizeof(TCHAR) - 1;
+        _tcscpy((*string), _infinity);
+        val64 = 1;
+    }
+    else
+    {
+        val64 = (__int64)fpval;
+        fpval -= val64;
+        fpval *= pow(10., precision);
+        
+        while (num_digits--)
+        {
+            *--(*string) = digits[(__int64)fpval % 10];
+            fpval /= 10;
+        }
+    }
+
+    *--(*string) = _T('.');
+
+    /* Gather digits in reverse order */
+    do
+    {
+        *--(*string) = digits[val64 % base];
+        val64 /= base;
+    }
+    while (val64);
+
+}
+
+static
+int
+streamout_char(FILE *stream, int chr)
+{
+    /* Flush the buffer if neccessary */
+    if (stream->_cnt < sizeof(TCHAR))
+    {
+        return _flsbuf(chr, stream) != EOF;
+    }
+
+    *(TCHAR*)stream->_ptr = chr;
+    stream->_ptr += sizeof(TCHAR);
+    stream->_cnt -= sizeof(TCHAR);
+
+    return 1;
+}
+
+static
+int
+streamout_astring(FILE *stream, const char *string, int count)
+{
+    TCHAR chr;
+    int written = 0;
+
+    while (count--)
+    {
+#ifdef _UNICODE
+        int len;
+        if ((len = mbtowc(&chr, string, MB_CUR_MAX)) < 1) break;
+        string += len;
+#else
+        chr = *string++;
+#endif
+        if (streamout_char(stream, chr) == 0) return -1;
+        written++;
+    }
+
+    return written;
+}
+
+static
+int
+streamout_wstring(FILE *stream, const wchar_t *string, int count)
+{
+    wchar_t chr;
+    int written = 0;
+
+    while (count--)
+    {
+#ifndef _UNICODE
+        char mbchar[MB_CUR_MAX], *ptr = mbchar;
+        int mblen;
+
+        mblen = wctomb(mbchar, *string++);
+        if (mblen <= 0) return written;
+
+        while (chr = *ptr++, mblen--)
+#else
+        chr = *string++;
+#endif
+        {
+            if (streamout_char(stream, chr) == 0) return -1;
+            written++;
+        }
+    }
+
+    return written;
+}
+
+#ifdef _UNICODE
+#define streamout_string streamout_wstring
+#else
+#define streamout_string streamout_astring
+#endif
+
+
+int
+_cdecl
+streamout(FILE *stream, const TCHAR *format, va_list argptr)
+{
+    static const TCHAR digits_l[] = _T("0123456789abcdef0x");
+    static const TCHAR digits_u[] = _T("0123456789ABCDEF0X");
+    static const char *_nullstring = "(null)";
+    TCHAR buffer[BUFFER_SIZE + 1];
+    TCHAR chr, *string;
+    STRING *nt_string;
+    const TCHAR *digits, *prefix;
+    int base, len, prefixlen, fieldwidth, precision, padding;
+    int written = 1, written_all = 0;
+    unsigned int flags;
+    __int64 val64;
+
+    buffer[BUFFER_SIZE] = '\0';
+
+    while (written >= 0)
+    {
+        chr = *format++;
+
+        /* Check for end of format string */
+        if (chr == _T('\0')) break;
+
+        /* Check for 'normal' character */
+        if (chr != _T('%'))
+        {
+            /* Write the character to the stream */
+            if ((written = streamout_char(stream, chr)) == -1) return -1;
+            written_all += written;
+            /* Continue with next char */
+            continue;
+        }
+
+        /* Handle flags */
+        flags = 0;
+        while (1)
+        {
+            chr = *format++;
+                 if (chr == _T('-')) flags |= FLAG_ALIGN_LEFT;
+            else if (chr == _T('+')) flags |= FLAG_FORCE_SIGN;
+            else if (chr == _T(' ')) flags |= FLAG_FORCE_SIGNSP;
+            else if (chr == _T('0')) flags |= FLAG_PAD_ZERO;
+            else if (chr == _T('#')) flags |= FLAG_SPECIAL;
+            else break;
+        }
+
+        /* Handle field width modifier */
+        if (chr == _T('*'))
+        {
+            fieldwidth = va_arg(argptr, int);
+            chr = *format++;
+        }
+        else
+        {
+            fieldwidth = 0;
+            while (chr >= _T('0') && chr <= _T('9'))
+            {
+                fieldwidth = fieldwidth * 10 + (chr - _T('0'));
+                chr = *format++;
+            }
+        }
+
+        /* Handle precision modifier */
+        if (chr == '.')
+        {
+            chr = *format++;
+            
+            if (chr == _T('*'))
+            {
+                precision = va_arg(argptr, int);
+                chr = *format++;
+            }
+            else 
+            {
+                precision = 0;
+                while (chr >= _T('0') && chr <= _T('9'))
+                {
+                    precision = precision * 10 + (chr - _T('0'));
+                    chr = *format++;
+                }
+            }
+        }
+        else precision = -1;
+
+        /* Handle argument size prefix */
+        while (1)
+        {
+                 if (chr == _T('h')) flags |= FLAG_SHORT;
+            else if (chr == _T('w')) flags |= FLAG_WIDECHAR;
+            else if (chr == _T('L')) flags |= 0; // FIXME: long double
+            else if (chr == _T('l'))
+            {
+                flags |= FLAG_LONG;
+#if SUPPORT_LL
+                if (format[0] == _T('l'))
+                {
+                    format++;
+                    flags |= FLAG_INT64;
+                }
+#endif
+            }
+            else if (chr == _T('I'))
+            {
+                if (format[0] == _T('3') && format[1] == _T('2'))
+                {
+                    format += 2;
+                }
+                else if (format[0] == _T('6') && format[1] == _T('4'))
+                {
+                    format += 2;
+                    flags |= FLAG_INT64;
+                }
+                else if (format[0] == _T('x') || format[0] == _T('X') ||
+                         format[0] == _T('d') || format[0] == _T('i') ||
+                         format[0] == _T('u') || format[0] == _T('o'))
+                {
+                    flags |= FLAG_INTPTR;
+                }
+                else break;
+            }
+            else break;
+            chr = *format++;
+        }
+
+        /* Handle the format specifier */
+        digits = digits_l;
+        string = &buffer[BUFFER_SIZE];
+        base = 10;
+        prefix = 0;
+        switch (chr)
+        {
+            case _T('n'):
+                if (flags & FLAG_INT64)
+                    *va_arg(argptr, __int64*) = written_all;
+                else if (flags & FLAG_SHORT)
+                    *va_arg(argptr, short*) = written_all;
+                else
+                    *va_arg(argptr, int*) = written_all;
+                continue;
+
+            case _T('C'):
+#ifndef _UNICODE
+                if (!(flags & FLAG_SHORT)) flags |= FLAG_WIDECHAR;
+#endif
+                goto case_char;
+
+            case _T('c'):
+#ifdef _UNICODE
+                if (!(flags & FLAG_SHORT)) flags |= FLAG_WIDECHAR;
+#endif
+            case_char:
+                string = buffer;
+                len = 1;
+                if (flags & FLAG_WIDECHAR)
+                {
+                    ((wchar_t*)string)[0] = va_arg(argptr, int);
+                    ((wchar_t*)string)[1] = _T('\0');
+                }
+                else
+                {
+                    ((char*)string)[0] = va_arg(argptr, int);
+                    ((char*)string)[1] = _T('\0');
+                }
+                break;
+
+            case _T('Z'):
+                nt_string = va_arg(argptr, void*);
+                if (nt_string && (string = nt_string->Buffer))
+                {
+                    len = nt_string->Length;
+                    if (flags & FLAG_WIDECHAR) len /= sizeof(wchar_t);
+                    break;
+                }
+                string = 0;
+                goto case_string;
+
+            case _T('S'):
+                string = va_arg(argptr, void*);
+#ifndef _UNICODE
+                if (!(flags & FLAG_SHORT)) flags |= FLAG_WIDECHAR;
+#endif
+                goto case_string;
+
+            case _T('s'):
+                string = va_arg(argptr, void*);
+#ifdef _UNICODE
+                if (!(flags & FLAG_SHORT)) flags |= FLAG_WIDECHAR;
+#endif
+
+            case_string:
+                if (!string)
+                {
+                    string = (TCHAR*)_nullstring;
+                    flags &= ~FLAG_WIDECHAR;
+                }
+
+                if (flags & FLAG_WIDECHAR)
+                    len = wcslen((wchar_t*)string);
+                else
+                    len = strlen((char*)string);
+                if (precision >= 0 && len > precision) len = precision;
+                break;
+
+            case _T('G'):
+            case _T('E'):
+            case _T('A'):
+            case _T('g'):
+            case _T('e'):
+            case _T('a'):
+            case _T('f'):
+#ifdef _UNICODE
+                flags |= FLAG_WIDECHAR;
+#else
+                flags &= ~FLAG_WIDECHAR;
+#endif
+                /* Use external function, one for kernel one for user mode */
+                format_float(chr, flags, precision, &string, &prefix, &argptr);
+                len = _tcslen(string);
+                break;
+
+            case _T('d'):
+            case _T('i'):
+                val64 = va_arg_f(argptr, flags);
+
+                if (val64 < 0)
+                {
+                    val64 = -val64;
+                    prefix = _T("-");
+                }
+                else if (flags & FLAG_FORCE_SIGN)
+                    prefix = _T("+");
+                else if (flags & FLAG_FORCE_SIGNSP)
+                    prefix = _T(" ");
+
+                goto case_number;
+
+            case _T('o'):
+                base = 8;
+                if (flags & FLAG_SPECIAL) prefix = _T("0");
+                /* Fall through */
+
+            case _T('u'):
+                val64 = (unsigned __int64)va_arg_fu(argptr, flags);
+                goto case_number;
+
+            case _T('p'):
+                precision = 2 * sizeof(void*);
+                flags &= ~FLAG_PAD_ZERO;
+                flags |= FLAG_INTPTR;
+                /* Fall through */
+
+            case _T('X'):
+                digits = digits_u;
+                /* Fall through */
+
+            case _T('x'):
+                val64 = (unsigned __int64)va_arg_fu(argptr, flags);
+                base = 16;
+                if (flags & FLAG_SPECIAL)
+                {
+                    prefix = &digits[16];
+                }
+
+            case_number:
+#ifdef _UNICODE
+                flags |= FLAG_WIDECHAR;
+#else
+                flags &= ~FLAG_WIDECHAR;
+#endif
+                /* Gather digits in reverse order */
+                do
+                {
+                    *--string = digits[val64 % base];
+                    val64 /= base;
+                    precision--;
+                }
+                while (val64);
+
+                while (precision-- > 0) *--string = '0';
+                len = _tcslen(string);
+                break;
+
+            default:
+                /* Treat anything else as a new character */
+                format--;
+                continue;
+        }
+
+        /* Calculate padding */
+        prefixlen = prefix ? _tcslen(prefix) : 0;
+        padding = fieldwidth - len - prefixlen;
+
+        /* Optional left space padding */
+        if ((flags & (FLAG_ALIGN_LEFT | FLAG_PAD_ZERO)) == 0)
+        {
+            while (padding-- > 0)
+            {
+                if ((written = streamout_char(stream, _T(' '))) == -1) return -2;
+                written_all += written;
+            }
+        }
+
+        /* Optional prefix */
+        if (prefix)
+        {
+            written = streamout_string(stream, prefix, prefixlen);
+            if (written == -1) return -3;
+            written_all += written;
+        }
+
+        /* Optional left '0' padding */
+        if ((flags & (FLAG_ALIGN_LEFT | FLAG_PAD_ZERO)) == FLAG_PAD_ZERO)
+        {
+            while (padding-- > 0)
+            {
+                if ((written = streamout_char(stream, _T('0'))) == -1) return -4;
+                written_all += written;
+            }
+        }
+
+        /* Output the string */
+        if (flags & FLAG_WIDECHAR)
+            written = streamout_wstring(stream, (wchar_t*)string, len);
+        else
+            written = streamout_astring(stream, (char*)string, len);
+        if (written == -1) return -5;
+        written_all += written;
+
+#if 0 && SUPPORT_FLOAT
+        /* Optional right '0' padding */
+        while (precision-- > 0)
+        {
+            if ((written = streamout_char(stream, _T('0'))) == -1) return -6;
+            written_all += written;
+            len++;
+        }
+#endif
+
+        /* Optional right padding */
+        if (flags & FLAG_ALIGN_LEFT)
+        {
+            while (padding-- > 0)
+            {
+                if ((written = streamout_char(stream, _T(' '))) == -1) return -7;
+                written_all += written;
+            }
+        }
+        
+    }
+
+    if (written == -1) return -8;
+
+    return written_all;
+}
+

Propchange: trunk/reactos/lib/sdk/crt/printf/streamout.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: trunk/reactos/lib/sdk/crt/printf/swprintf.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/printf/swprintf.c?rev=49499&view=auto
==============================================================================
--- trunk/reactos/lib/sdk/crt/printf/swprintf.c (added)
+++ trunk/reactos/lib/sdk/crt/printf/swprintf.c [iso-8859-1] Fri Nov  5 22:21:36 2010
@@ -1,0 +1,39 @@
+/*
+ * COPYRIGHT:       GNU GPL, see COPYING in the top level directory
+ * PROJECT:         ReactOS crt library
+ * FILE:            lib/sdk/crt/printf/swprintf.c
+ * PURPOSE:         Implementation of swprintf
+ * PROGRAMMER:      Timo Kreuzer
+ */
+
+#include <stdio.h>
+#include <stdarg.h>
+#include <limits.h>
+
+int _cdecl wstreamout(FILE *stream, const wchar_t *format, va_list argptr);
+
+int
+_cdecl
+swprintf(wchar_t *buffer, const wchar_t *format, ...)
+{
+    va_list argptr;
+    int result;
+    FILE stream;
+
+    stream._base = (char*)buffer;
+    stream._ptr = stream._base;
+    stream._charbuf = 0;
+    stream._bufsiz = INT_MAX;
+    stream._cnt = stream._bufsiz;
+    stream._flag = 0;
+    stream._tmpfname = 0;
+
+    va_start(argptr, format);
+    result = wstreamout(&stream, format, argptr);
+    va_end(argptr);
+    
+    *(wchar_t*)stream._ptr = '\0';
+    return result;
+}
+
+

Propchange: trunk/reactos/lib/sdk/crt/printf/swprintf.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: trunk/reactos/lib/sdk/crt/printf/vfprintf.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/printf/vfprintf.c?rev=49499&view=auto
==============================================================================
--- trunk/reactos/lib/sdk/crt/printf/vfprintf.c (added)
+++ trunk/reactos/lib/sdk/crt/printf/vfprintf.c [iso-8859-1] Fri Nov  5 22:21:36 2010
@@ -1,0 +1,29 @@
+/*
+ * COPYRIGHT:       GNU GPL, see COPYING in the top level directory
+ * PROJECT:         ReactOS crt library
+ * FILE:            lib/sdk/crt/printf/vfprintf.c
+ * PURPOSE:         Implementation of vfprintf
+ * PROGRAMMER:      Timo Kreuzer
+ */
+
+#include <stdio.h>
+#include <stdarg.h>
+
+void _cdecl _lock_file(FILE* file);
+void _cdecl _unlock_file(FILE* file);
+int _cdecl streamout(FILE *stream, const char *format, va_list argptr);
+
+int
+_cdecl
+vfprintf(FILE *stream, const char *format, va_list argptr)
+{
+    int result;
+
+    _lock_file(stream);
+    
+    result = streamout(stream, format, argptr);
+    
+    _unlock_file(stream);
+
+    return result;
+}

Propchange: trunk/reactos/lib/sdk/crt/printf/vfprintf.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: trunk/reactos/lib/sdk/crt/printf/vfwprintf.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/printf/vfwprintf.c?rev=49499&view=auto
==============================================================================
--- trunk/reactos/lib/sdk/crt/printf/vfwprintf.c (added)
+++ trunk/reactos/lib/sdk/crt/printf/vfwprintf.c [iso-8859-1] Fri Nov  5 22:21:36 2010
@@ -1,0 +1,20 @@
+/*
+ * COPYRIGHT:       GNU GPL, see COPYING in the top level directory
+ * PROJECT:         ReactOS crt library
+ * FILE:            lib/sdk/crt/printf/vfwprintf.c
+ * PURPOSE:         Implementation of vfwprintf
+ * PROGRAMMER:      Timo Kreuzer
+ */
+
+#include <stdio.h>
+#include <stdarg.h>
+
+int _cdecl wstreamout(FILE *stream, const wchar_t *format, va_list argptr);
+
+int
+__cdecl
+vfwprintf(FILE* file, const wchar_t *format, va_list argptr)
+{
+    return wstreamout(file, format, argptr);
+}
+

Propchange: trunk/reactos/lib/sdk/crt/printf/vfwprintf.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: trunk/reactos/lib/sdk/crt/printf/vprintf.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/printf/vprintf.c?rev=49499&view=auto
==============================================================================
--- trunk/reactos/lib/sdk/crt/printf/vprintf.c (added)
+++ trunk/reactos/lib/sdk/crt/printf/vprintf.c [iso-8859-1] Fri Nov  5 22:21:36 2010
@@ -1,0 +1,19 @@
+/*
+ * COPYRIGHT:       GNU GPL, see COPYING in the top level directory
+ * PROJECT:         ReactOS crt library
+ * FILE:            lib/sdk/crt/printf/vprintf.c
+ * PURPOSE:         Implementation of vprintf
+ * PROGRAMMER:      Timo Kreuzer
+ */
+
+#include <stdio.h>
+#include <stdarg.h>
+
+int _cdecl streamout(FILE *stream, const char *format, va_list argptr);
+
+int
+__cdecl
+vprintf(const char *format, va_list argptr)
+{
+    return streamout(stdout, format, argptr);
+}

Propchange: trunk/reactos/lib/sdk/crt/printf/vprintf.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: trunk/reactos/lib/sdk/crt/printf/vsprintf.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/printf/vsprintf.c?rev=49499&view=auto
==============================================================================
--- trunk/reactos/lib/sdk/crt/printf/vsprintf.c (added)
+++ trunk/reactos/lib/sdk/crt/printf/vsprintf.c [iso-8859-1] Fri Nov  5 22:21:36 2010
@@ -1,0 +1,38 @@
+#include "myfunc.h"
+/*
+ * COPYRIGHT:       GNU GPL, see COPYING in the top level directory
+ * PROJECT:         ReactOS crt library
+ * FILE:            lib/sdk/crt/printf/vsprintf.c
+ * PURPOSE:         Implementation of vsprintf
+ * PROGRAMMER:      Timo Kreuzer
+ */
+
+#include <stdio.h>
+#include <stdarg.h>
+#include <limits.h>
+
+int _cdecl streamout(FILE *stream, const char *format, va_list argptr);
+
+int
+__cdecl
+vsprintf(
+   char *buffer,
+   const char *format,
+   va_list argptr)
+{
+    int result;
+    FILE stream;
+
+    stream._base = buffer;
+    stream._ptr = stream._base;
+    stream._charbuf = 0;
+    stream._bufsiz = INT_MAX;
+    stream._cnt = stream._bufsiz;
+    stream._flag = _IOSTRG|_IOWRT|_IOMYBUF;
+    stream._tmpfname = 0;
+
+    result = streamout(&stream, format, argptr);
+    *stream._ptr = '\0';
+
+    return result;
+}

Propchange: trunk/reactos/lib/sdk/crt/printf/vsprintf.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: trunk/reactos/lib/sdk/crt/printf/vswprintf.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/printf/vswprintf.c?rev=49499&view=auto
==============================================================================
--- trunk/reactos/lib/sdk/crt/printf/vswprintf.c (added)
+++ trunk/reactos/lib/sdk/crt/printf/vswprintf.c [iso-8859-1] Fri Nov  5 22:21:36 2010
@@ -1,0 +1,18 @@
+/*
+ * COPYRIGHT:       GNU GPL, see COPYING in the top level directory
+ * PROJECT:         ReactOS crt library
+ * FILE:            lib/sdk/crt/printf/vswprintf.c
+ * PURPOSE:         Implementation of vswprintf
+ * PROGRAMMER:      Timo Kreuzer
+ */
+
+#include <stdio.h>
+#include <stdarg.h>
+#include <limits.h>
+
+int
+__cdecl
+vswprintf(wchar_t *buffer, const wchar_t *format, va_list argptr)
+{
+    return _vsnwprintf(buffer, INT_MAX, format, argptr);
+}

Propchange: trunk/reactos/lib/sdk/crt/printf/vswprintf.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: trunk/reactos/lib/sdk/crt/printf/vwprintf.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/printf/vwprintf.c?rev=49499&view=auto
==============================================================================
--- trunk/reactos/lib/sdk/crt/printf/vwprintf.c (added)
+++ trunk/reactos/lib/sdk/crt/printf/vwprintf.c [iso-8859-1] Fri Nov  5 22:21:36 2010
@@ -1,0 +1,19 @@
+/*
+ * COPYRIGHT:       GNU GPL, see COPYING in the top level directory
+ * PROJECT:         ReactOS crt library
+ * FILE:            lib/sdk/crt/printf/vwprintf.c
+ * PURPOSE:         Implementation of vwprintf
+ * PROGRAMMER:      Timo Kreuzer
+ */
+
+#include <stdio.h>
+#include <stdarg.h>
+
+int _cdecl wstreamout(FILE *stream, const wchar_t *format, va_list argptr);
+
+int
+__cdecl
+vwprintf(const wchar_t *format, va_list argptr)
+{
+    return wstreamout(stdout, format, argptr);
+}

Propchange: trunk/reactos/lib/sdk/crt/printf/vwprintf.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: trunk/reactos/lib/sdk/crt/printf/wprintf.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/printf/wprintf.c?rev=49499&view=auto
==============================================================================
--- trunk/reactos/lib/sdk/crt/printf/wprintf.c (added)
+++ trunk/reactos/lib/sdk/crt/printf/wprintf.c [iso-8859-1] Fri Nov  5 22:21:36 2010
@@ -1,0 +1,25 @@
+/*
+ * COPYRIGHT:       GNU GPL, see COPYING in the top level directory
+ * PROJECT:         ReactOS crt library
+ * FILE:            lib/sdk/crt/printf/wprintf.c
+ * PURPOSE:         Implementation of wprintf
+ * PROGRAMMER:      Timo Kreuzer
+ */
+
+#include <stdio.h>
+#include <stdarg.h>
+
+int _cdecl wstreamout(FILE *stream, const wchar_t *format, va_list argptr);
+
+int
+__cdecl
+wprintf(const wchar_t *format, ...)
+{
+    va_list argptr;
+    int result;
+
+    va_start(argptr, format);
+    result = wstreamout(stdout, format, argptr);
+    va_end(argptr);
+    return result;
+}

Propchange: trunk/reactos/lib/sdk/crt/printf/wprintf.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: trunk/reactos/lib/sdk/crt/printf/wstreamout.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/printf/wstreamout.c?rev=49499&view=auto
==============================================================================
--- trunk/reactos/lib/sdk/crt/printf/wstreamout.c (added)
+++ trunk/reactos/lib/sdk/crt/printf/wstreamout.c [iso-8859-1] Fri Nov  5 22:21:36 2010
@@ -1,0 +1,12 @@
+/*
+ * COPYRIGHT:       GNU GPL, see COPYING in the top level directory
+ * PROJECT:         ReactOS crt library
+ * FILE:            lib/sdk/crt/printf/wstreamout.c
+ * PURPOSE:         Implementation of wstreamout
+ * PROGRAMMER:      Timo Kreuzer
+ */
+
+#define _UNICODE
+#define UNICODE
+
+#include "streamout.c"

Propchange: trunk/reactos/lib/sdk/crt/printf/wstreamout.c
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: trunk/reactos/lib/sdk/crt/stdio/file.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/stdio/file.c?rev=49499&r1=49498&r2=49499&view=diff
==============================================================================
--- trunk/reactos/lib/sdk/crt/stdio/file.c [iso-8859-1] (original)
+++ trunk/reactos/lib/sdk/crt/stdio/file.c [iso-8859-1] Fri Nov  5 22:21:36 2010
@@ -2814,6 +2814,7 @@
   return file;
 }
 
+#ifndef USE_NEW_SPRINTF
 /*********************************************************************
  *		vfprintf (MSVCRT.@)
  */
@@ -2947,6 +2948,7 @@
     va_end(valist);
     return res;
 }
+#endif
 
 /*********************************************************************
  *		ungetc (MSVCRT.@)
@@ -2984,6 +2986,7 @@
 	return mwc;
 }
 
+#ifndef USE_NEW_SPRINTF
 /*********************************************************************
  *		wprintf (MSVCRT.@)
  */
@@ -2996,6 +2999,7 @@
     va_end(valist);
     return res;
 }
+#endif
 
 /*********************************************************************
  *		_getmaxstdio (MSVCRT.@)

Modified: trunk/reactos/lib/sdk/crt/stdio/lnx_sprintf.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/stdio/lnx_sprintf.c?rev=49499&r1=49498&r2=49499&view=diff
==============================================================================
--- trunk/reactos/lib/sdk/crt/stdio/lnx_sprintf.c [iso-8859-1] (original)
+++ trunk/reactos/lib/sdk/crt/stdio/lnx_sprintf.c [iso-8859-1] Fri Nov  5 22:21:36 2010
@@ -14,7 +14,7 @@
  *  Lars Wirzenius & Linus Torvalds
  *  Wirzenius wrote this portably, Torvalds fucked it up :-)
  */
-
+#ifndef USE_NEW_SPRINTF
 #include <precomp.h>
 
 #include <wchar.h>
@@ -879,3 +879,4 @@
 }
 #endif
 /* EOF */
+#endif

Added: trunk/reactos/lib/sdk/crt/stdio/lock_file.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/stdio/lock_file.c?rev=49499&view=auto
==============================================================================
--- trunk/reactos/lib/sdk/crt/stdio/lock_file.c (added)
+++ trunk/reactos/lib/sdk/crt/stdio/lock_file.c [iso-8859-1] Fri Nov  5 22:21:36 2010
@@ -1,0 +1,15 @@
+
+#include <stdio.h>
+
+void
+_cdecl
+_lock_file(FILE* file)
+{
+}
+
+void
+_cdecl
+_unlock_file(FILE* file)
+{
+}
+

Propchange: trunk/reactos/lib/sdk/crt/stdio/lock_file.c
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: trunk/reactos/lib/sdk/crt/string/wcs.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/string/wcs.c?rev=49499&r1=49498&r2=49499&view=diff
==============================================================================
--- trunk/reactos/lib/sdk/crt/string/wcs.c [iso-8859-1] (original)
+++ trunk/reactos/lib/sdk/crt/string/wcs.c [iso-8859-1] Fri Nov  5 22:21:36 2010
@@ -388,6 +388,7 @@
     return r;
 }
 
+#ifndef USE_NEW_SPRINTF
 static int pf_handle_string_format( pf_output *out, const void* str, int len,
                              pf_flags *flags, BOOL capital_letter)
 {
@@ -879,6 +880,7 @@
     return _vsnwprintf( str, INT_MAX, format, args );
 }
 #endif
+#endif
 
 /*********************************************************************
  *		wcscoll (MSVCRT.@)

Modified: trunk/reactos/modules/directory.rbuild
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/modules/directory.rbuild?rev=49499&r1=49498&r2=49499&view=diff
==============================================================================
--- trunk/reactos/modules/directory.rbuild [iso-8859-1] (original)
+++ trunk/reactos/modules/directory.rbuild [iso-8859-1] Fri Nov  5 22:21:36 2010
@@ -22,4 +22,11 @@
 			</xi:fallback>
 		</xi:include>
 	</directory>
+	<!-- directory name="3rdparty">
+		<xi:include href="3rdparty/directory.rbuild">
+			<xi:fallback>
+				<xi:include href="empty.rbuild" />
+			</xi:fallback>
+		</xi:include>
+	</directory -->
 </group>




More information about the Ros-diffs mailing list