2 Copyright © 1995-2013, 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
)
33 Write a formatted string (with supplied values) to a specified file.
34 The string may be of any length and the routine is buffered.
35 The following format commands may be used (preceded by a '%') a la
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'.
52 fh - file to write the output to
54 argarray - pointer to an array of formatting values
57 The number of bytes written or -1 if there was an error.
70 *****************************************************************************/
74 #define bLast (sizeof(ULONG)*8/3 + 1)
76 char buffer
[bLast
+ 1];
78 LONG count
= 0; /* Number of characters written */
79 CONST_STRPTR format
= fmt
;
80 const IPTR
*args
= argarray
;
83 STRPTR wBuf
; /* Pointer to first number character in buffer */
85 LONG i
; /* Loop variable */
88 BOOL quitNow
= FALSE
; /* Takes care of the case "...%" as format
92 while (*format
!= 0 && !quitNow
)
100 case 'S': /* Regular c string */
102 string
= (STRPTR
)*args
;
112 FPutC(fh
, *string
++);
118 case 'T': /* BCPL string (possibly filled out) */
123 if (BADDR(*args
) == NULL
)
128 for (i
= 0; i
< AROS_BSTR_strlen((BSTR
)*args
); i
++)
130 FPutC(fh
, AROS_BSTR_getchar((BSTR
)*args
, i
));
136 /* If needed, write out spaces to fill field. */
145 case 'C': /* Character */
147 FPutC(fh
, (char)*args
);
152 case 'O': /* Octal number */
154 count
+= putNumber(&format
, (IPTR
**)&args
, 8, fh
, DOSBase
);
157 case 'X': /* Hexadecimal number */
159 count
+= putNumber(&format
, (IPTR
**)&args
, 16, fh
, DOSBase
);
162 case 'I': /* Decimal number */
164 count
+= putNumber(&format
, (IPTR
**)&args
, 10, fh
, DOSBase
);
167 case 'N': /* Decimal number (no length restriction) */
184 /* Write decimal number */
185 wBuf
= writeNumber(&buffer
[bLast
], 10, number
, minus
, DOSBase
);
195 case 'U': /* Unsigned decimal number */
203 wBuf
= writeNumber(&buffer
[bLast
], 10, number
, FALSE
, DOSBase
);
205 for (i
= 0; i
< len
; i
++)
218 case '$': /* Skip argument */
222 case 0: /* Stupid user... */
226 default: /* Ability to print '%':s */
234 /* A regular character */
248 LONG
putNumber(CONST_STRPTR
*format
, IPTR
**args
, ULONG base
, BPTR fh
,
249 struct DosLibrary
*DOSBase
)
251 char buffer
[bLast
+ 1];
254 LONG len
; /* Maximum width of number (ASCII) */
257 LONG i
; /* Loop variable */
262 len
= **format
- '0';
273 aNum
= writeNumber(&buffer
[bLast
], base
, number
, minus
, DOSBase
);
275 /* Write the textual number to the file */
276 for (i
= 0; i
< len
; i
++)
289 /* Generate a text string from a number */
290 STRPTR
writeNumber(char *buffer
, ULONG base
, ULONG n
, BOOL minus
,
291 struct DosLibrary
*DOSBase
)
298 *--buffer
= val
< 10 ? val
+ '0' : val
- 10 + 'A';