source: trunk/texinfo/intl/printf.c@ 2618

Last change on this file since 2618 was 2617, checked in by bird, 20 years ago

GNU Texinfo 4.8

File size: 7.6 KB
Line 
1/* Formatted output to strings, using POSIX/XSI format strings with positions.
2 Copyright (C) 2003 Free Software Foundation, Inc.
3 Written by Bruno Haible <[email protected]>, 2003.
4
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of the GNU Library General Public License as published
7 by the Free Software Foundation; either version 2, or (at your option)
8 any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public
16 License along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
18 USA. */
19
20#ifdef HAVE_CONFIG_H
21# include <config.h>
22#endif
23
24#ifdef __GNUC__
25# define alloca __builtin_alloca
26# define HAVE_ALLOCA 1
27#else
28# ifdef _MSC_VER
29# include <malloc.h>
30# define alloca _alloca
31# else
32# if defined HAVE_ALLOCA_H || defined _LIBC
33# include <alloca.h>
34# else
35# ifdef _AIX
36 #pragma alloca
37# else
38# ifndef alloca
39char *alloca ();
40# endif
41# endif
42# endif
43# endif
44#endif
45
46#include <stdio.h>
47
48#if !HAVE_POSIX_PRINTF
49
50#include <stdlib.h>
51#include <string.h>
52
53/* When building a DLL, we must export some functions. Note that because
54 the functions are only defined for binary backward compatibility, we
55 don't need to use __declspec(dllimport) in any case. */
56#if defined _MSC_VER && BUILDING_DLL
57# define DLL_EXPORTED __declspec(dllexport)
58#else
59# define DLL_EXPORTED
60#endif
61
62#define STATIC static
63
64/* Define auxiliary functions declared in "printf-args.h". */
65#include "printf-args.c"
66
67/* Define auxiliary functions declared in "printf-parse.h". */
68#include "printf-parse.c"
69
70/* Define functions declared in "vasnprintf.h". */
71#define vasnprintf libintl_vasnprintf
72#include "vasnprintf.c"
73#if 0 /* not needed */
74#define asnprintf libintl_asnprintf
75#include "asnprintf.c"
76#endif
77
78DLL_EXPORTED
79int
80libintl_vfprintf (FILE *stream, const char *format, va_list args)
81{
82 if (strchr (format, '$') == NULL)
83 return vfprintf (stream, format, args);
84 else
85 {
86 size_t length;
87 char *result = libintl_vasnprintf (NULL, &length, format, args);
88 int retval = -1;
89 if (result != NULL)
90 {
91 if (fwrite (result, 1, length, stream) == length)
92 retval = length;
93 free (result);
94 }
95 return retval;
96 }
97}
98
99DLL_EXPORTED
100int
101libintl_fprintf (FILE *stream, const char *format, ...)
102{
103 va_list args;
104 int retval;
105
106 va_start (args, format);
107 retval = libintl_vfprintf (stream, format, args);
108 va_end (args);
109 return retval;
110}
111
112DLL_EXPORTED
113int
114libintl_vprintf (const char *format, va_list args)
115{
116 return libintl_vfprintf (stdout, format, args);
117}
118
119DLL_EXPORTED
120int
121libintl_printf (const char *format, ...)
122{
123 va_list args;
124 int retval;
125