]> granicus.if.org Git - icu/commitdiff
ICU-8579 added u_printf
authorAbhinav Gupta <mail@abhinavg.net>
Fri, 16 Sep 2011 17:44:06 +0000 (17:44 +0000)
committerAbhinav Gupta <mail@abhinavg.net>
Fri, 16 Sep 2011 17:44:06 +0000 (17:44 +0000)
X-SVN-Rev: 30677

icu4c/source/io/ucln_io.h
icu4c/source/io/unicode/ustdio.h
icu4c/source/io/uprintf.c

index e26c1b68833d8407475a8d9eb77213944759531b..105eca8b136701d00efd4215abc6ea9986bd4c95 100644 (file)
@@ -1,7 +1,7 @@
 /*
 ******************************************************************************
 *                                                                            *
-* Copyright (C) 2001-2006, International Business Machines                   *
+* Copyright (C) 2001-2011, International Business Machines                   *
 *                Corporation and others. All Rights Reserved.                *
 *                                                                            *
 ******************************************************************************
@@ -26,6 +26,7 @@ as the functions are suppose to be called. */
 typedef enum ECleanupIOType {
     UCLN_IO_START = -1,
     UCLN_IO_LOCBUND,
+    UCLN_IO_PRINTF,
     UCLN_IO_COUNT /* This must be last */
 } ECleanupIOType;
 
index 9bcc797b292d31086f060cb698775709f639741c..cae7d9baf8a03cbec7fc9fa950cc7e846b78ae98 100644 (file)
@@ -1,7 +1,7 @@
 /*
 ******************************************************************************
 *
-*   Copyright (C) 1998-2010, International Business Machines
+*   Copyright (C) 1998-2011, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 *
 ******************************************************************************
@@ -441,6 +441,17 @@ U_STABLE UConverter* U_EXPORT2 u_fgetConverter(UFILE *f);
 
 /* Output functions */
 
+/**
+ * Write formatted data to <TT>stdout</TT>.
+ * @param patternSpecification A pattern specifying how <TT>u_printf</TT> will
+ * interpret the variable arguments received and format the data.
+ * @return The number of Unicode characters written to <TT>stdout</TT>
+ * @draft ICU 49
+ */
+U_DRAFT int32_t U_EXPORT2
+u_printf(const char *patternSpecification,
+         ... );
+
 /**
  * Write formatted data to a UFILE.
  * @param f The UFILE to which to write.
index d95c02c671c3cf3aa778b4fc1b238af717faea4f..be50f054f2f99ec5725d1cc1d1eec2eb39478df1 100644 (file)
@@ -1,7 +1,7 @@
 /*
 ******************************************************************************
 *
-*   Copyright (C) 1998-2004, International Business Machines
+*   Copyright (C) 1998-2011, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 *
 ******************************************************************************
 
 #include "uprintf.h"
 #include "ufile.h"
+#include "ucln_io.h"
 #include "locbund.h"
 
 #include "cmemory.h"
 
+UFILE *gStdOut = NULL;
+
+static UBool U_CALLCONV uprintf_cleanup()
+{
+    if (gStdOut != NULL) {
+        u_fclose(gStdOut);
+        gStdOut = NULL;
+    }
+}
+
+static UFILE * U_EXPORT2
+u_get_stdout()
+{
+    if (gStdOut == NULL) {
+        gStdOut = u_finit(stdout, NULL, NULL);
+        ucln_io_registerCleanup(UCLN_IO_PRINTF, &uprintf_cleanup);
+    }
+    return gStdOut;
+}
+
 static int32_t U_EXPORT2
 u_printf_write(void          *context,
                const UChar   *str,
@@ -92,6 +113,18 @@ u_fprintf(    UFILE        *f,
     return count;
 }
 
+U_CAPI int32_t U_EXPORT2
+u_printf(const char *patternSpecification,
+         ...)
+{
+    va_list ap;
+    int32_t count;
+    va_start(ap, patternSpecification);
+    count = u_vfprintf(u_get_stdout(), patternSpecification, ap);
+    va_end(ap);
+    return count;
+}
+
 U_CAPI int32_t U_EXPORT2 
 u_fprintf_u(    UFILE        *f,
             const UChar    *patternSpecification,