2 Copyright © 1995-2008, The AROS Development Team. All rights reserved.
8 #include "dos_intern.h"
12 LONG
putNumber(CONST_STRPTR
*format
, IPTR
**args
, ULONG base
, BPTR fh
,
13 struct DosLibrary
*DOSBase
);
14 STRPTR
writeNumber(char *buffer
, ULONG base
, ULONG n
, BOOL minus
,
15 struct DosLibrary
*DOSBase
);
17 /*****************************************************************************
20 #include <proto/dos.h>
22 AROS_LH3(LONG
, VFWritef
,
25 AROS_LHA(BPTR
, fh
, D1
),
26 AROS_LHA(CONST_STRPTR
, fmt
, D2
),
27 AROS_LHA(const IPTR
*, argarray
, D3
),
30 struct DosLibrary
*, DOSBase
, 58, Dos
)
34 Write a formatted string (with supplied values) to a specified file.
35 The string may be of any length and the routine is buffered.
36 The following format commands may be used (preceded by a '%') a la printf.
39 Tx -- writes a left justified string padding it to be (at least)
42 Ox -- octal number; maximum width x characters
43 Xx -- hexadecimal number; maximum width x characters
44 Ix -- decimal number; maximum width x chararcters
45 N -- decimal number; any length
46 Ux -- unsigned decimal number; maximum width x characters
49 Note: 'x' above is the character value - '0'.
53 fh -- file to write the output to
55 argarray -- pointer to an array of formatting values
59 The number of bytes written or -1 if there was an error.
73 *****************************************************************************/
77 #define bLast (sizeof(ULONG)*8/3 + 1)
79 char buffer
[bLast
+ 1];
81 LONG count
= 0; /* Number of characters written */
82 CONST_STRPTR format
= fmt
;
83 const IPTR
*args
= argarray
;
86 STRPTR wBuf
; /* Pointer to first number character in buffer */
88 LONG i
; /* Loop variable */
91 BOOL quitNow
= FALSE
; /* Takes care of the case "...%" as format
95 while (*format
!= 0 && !quitNow
)
103 case 'S': /* Regular c string */
105 string
= (STRPTR
)*args
;
115 FPutC(fh
, *string
++);
121 case 'T': /* BCPL string (possibly filled out) */
126 if (BADDR(*args
) == NULL
)
131 for (i
= 0; i
< AROS_BSTR_strlen((BSTR
)*args
); i
++)
133 FPutC(fh
, AROS_BSTR_getchar((BSTR
)*args
, i
));
139 /* If needed, write out spaces to fill field. */
148 case 'C': /* Character */
150 FPutC(fh
, (char)*args
);
155 case 'O': /* Octal number */
157 count
+= putNumber(&format
, (IPTR
**)&args
, 8, fh
, DOSBase
);
160 case 'X': /* Hexadecimal number */
162 count
+= putNumber(&format
, (IPTR
**)&args
, 16, fh
, DOSBase
);
165 case 'I': /* Decimal number */
167 count
+= putNumber(&format
, (IPTR
**)&args
, 10, fh
, DOSBase
);
170 case 'N': /* Decimal number (no length restriction) */
187 /* Write decimal number */
188 wBuf
= writeNumber(&buffer
[bLast
], 10, number
, minus
, DOSBase
);
198 case 'U': /* Unsigned decimal number */
206 wBuf
= writeNumber(&buffer
[bLast
], 10, number
, FALSE
, DOSBase
);
208 for (i
= 0; i
< len
; i
++)
221 case '$': /* Skip argument */
225 case 0: /* Stupid user... */
229 default: /* Ability to print '%':s */
237 /* A regular character */
251 LONG
putNumber(CONST_STRPTR
*format
, IPTR
**args
, ULONG base
, BPTR fh
,
252 struct DosLibrary
*DOSBase
)
254 char buffer
[bLast
+ 1];
257 LONG len
; /* Maximum width of number (ASCII) */
260 LONG i
; /* Loop variable */
265 len
= **format
- '0';
276 aNum
= writeNumber(&buffer
[bLast
], base
, number
, minus
, DOSBase
);
278 /* Write the textual number to the file */
279 for (i
= 0; i
< len
; i
++)
292 /* Generate a text string from a number */
293 STRPTR
writeNumber(char *buffer
, ULONG base
, ULONG n
, BOOL minus
,
294 struct DosLibrary
*DOSBase
)
301 *--buffer
= val
< 10 ? val
+ '0' : val
- 10 + 'A';