2 * $Source: x:/prj/tech/libsrc/lg/RCS/lgprntf.c $
5 * $Date: 1996/10/10 11:59:56 $
7 * no-floats baby printf.
17 /* arbitrary maximum size of string buffer. */
18 #define PRINT_BUF_SIZE 2048
20 /* these baby-printf routines allocate a temporary buffer via the temp
21 mem routines, then call lg_sprintf() which does all the real work,
22 and use write() to output the string to stdout. see comments of
23 lg_sprintf() for a comprehensive list of differences between it and
24 the c-library version. */
26 /* stripped-down vprintf which supports fixed-point numbers instead of
27 floats. fmt is the format string, and arg is the list of the rest
28 of the arguments. returns the number of characters written or <0 if
29 there was an error. this can only print a string of up to
31 int lg_vprintf(char *fmt
,va_list arg
)
33 char *s
; /* buffer for string */
34 int n
; /* number of characters in string */
35 int r
; /* number of characters printed */
37 /* allocate a temporary buffer, and sprintf() the string there. */
38 if ((s
=TempMalloc(PRINT_BUF_SIZE
))==NULL
) {
39 Warning(("lg_vprintf: can't allocate %d byte buffer for string"));
42 if ((n
=lg_vsprintf(s
,fmt
,arg
))>=PRINT_BUF_SIZE
)
43 Warning(("lg_vprintf: string buffer overflow"));
44 /* copy string to stdout, free buffer. */
48 return r
; /* return #of chars or -1 if error */
51 /* stripped-down printf. arguments are format string (fmt), and values
52 to printf. returns number of characters written. */
53 int lg_printf(char *fmt
,...)
55 va_list arg
; /* argument list */
56 int r
; /* nubmer of characters printed */
58 /* set up arg list and use lg_printf(). */
60 r
=lg_vprintf(fmt
,arg
);