/*
******************************************************************************
* *
-* Copyright (C) 2001-2006, International Business Machines *
+* Copyright (C) 2001-2011, International Business Machines *
* Corporation and others. All Rights Reserved. *
* *
******************************************************************************
typedef enum ECleanupIOType {
UCLN_IO_START = -1,
UCLN_IO_LOCBUND,
+ UCLN_IO_PRINTF,
UCLN_IO_COUNT /* This must be last */
} ECleanupIOType;
/*
******************************************************************************
*
-* Copyright (C) 1998-2010, International Business Machines
+* Copyright (C) 1998-2011, International Business Machines
* Corporation and others. All Rights Reserved.
*
******************************************************************************
/* 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.
/*
******************************************************************************
*
-* 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,
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,