convert line ends
[canaan.git] / prj / tech / libsrc / lg / lgprntf.c
blob588dccab6c54d9c4d5b2cd9fa35c1b2e14ac80df
1 /*
2 * $Source: x:/prj/tech/libsrc/lg/RCS/lgprntf.c $
3 * $Revision: 1.2 $
4 * $Author: TOML $
5 * $Date: 1996/10/10 11:59:56 $
7 * no-floats baby printf.
8 */
10 #include <io.h>
11 #include <stdarg.h>
12 #include <dbg.h>
13 #include <lgsprntf.h>
14 #include <memall.h>
15 #include <tmpalloc.h>
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
30 PRINT_BUF_SIZE. */
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"));
40 return 0;
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. */
46 r=printf(s);
47 TempFree(s);
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(). */
59 va_start(arg,fmt);
60 r=lg_vprintf(fmt,arg);
61 va_end(arg);
63 return r;