Mercurial > hg > th-libs
annotate th_printf.c @ 531:f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 28 Dec 2019 11:09:29 +0200 |
parents | |
children | ef0d732fabe0 |
rev | line source |
---|---|
531
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1 /* |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2 * A printf() implementation |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
3 * Programmed and designed by Matti 'ccr' Hamalainen |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
4 * (C) Copyright 2016-2019 Tecnic Software productions (TNSP) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
5 * |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
6 * Please read file 'COPYING' for information on license and distribution. |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
7 */ |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
8 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
9 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
10 #ifdef TH_PRINTF_DEBUG |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
11 BOOL th_printf_debug = FALSE; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
12 char *th_printf_debug_prefix = NULL; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
13 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
14 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
15 static void pflag(char *buf, const char *str, const int sep, const int flags, const int flg) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
16 { |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
17 strcat(buf, (flags & flg) ? str : " "); |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
18 if (sep) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
19 strcat(buf, "|"); |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
20 } |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
21 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
22 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
23 static const char *get_flags(const int flags) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
24 { |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
25 static char buf[256]; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
26 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
27 buf[0] = 0; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
28 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
29 pflag(buf, "ALT", 1, flags, TH_PF_ALT); |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
30 pflag(buf, "SGN", 1, flags, TH_PF_SIGN); |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
31 pflag(buf, "SPC", 1, flags, TH_PF_SPACE); |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
32 pflag(buf, "GRP", 1, flags, TH_PF_GROUP); |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
33 pflag(buf, "ZER", 1, flags, TH_PF_ZERO); |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
34 pflag(buf, "LFT", 0, flags, TH_PF_LEFT); |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
35 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
36 return buf; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
37 } |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
38 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
39 #define PP_LINE(...) \ |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
40 do { \ |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
41 if (th_printf_debug) { \ |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
42 if (th_printf_debug_prefix != NULL) \ |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
43 fputs(th_printf_debug_prefix, stdout); \ |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
44 fprintf(stdout, __VA_ARGS__); \ |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
45 } \ |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
46 } while (0) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
47 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
48 #define PP_PRINTF(...) \ |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
49 do { \ |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
50 if (th_printf_debug) { \ |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
51 fprintf(stdout, __VA_ARGS__); \ |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
52 } \ |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
53 } while (0) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
54 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
55 #else |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
56 #define PP_LINE(...) /* stub */ |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
57 #define PP_PRINTF(...) /* stub */ |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
58 #endif |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
59 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
60 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
61 static int th_vprintf_put_pstr(th_vprintf_ctx *ctx, th_vprintf_putch vputch, const char *str) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
62 { |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
63 while (*str) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
64 { |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
65 int ret; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
66 if ((ret = vputch(ctx, *str++)) == EOF) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
67 return ret; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
68 } |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
69 return 0; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
70 } |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
71 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
72 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
73 static int th_vprintf_put_repch(th_vprintf_ctx *ctx, th_vprintf_putch vputch, int count, const char ch) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
74 { |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
75 while (count-- > 0) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
76 { |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
77 int ret; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
78 if ((ret = vputch(ctx, ch)) == EOF) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
79 return ret; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
80 } |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
81 return 0; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
82 } |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
83 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
84 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
85 static int th_printf_pad_pre(th_vprintf_ctx *ctx, th_vprintf_putch vputch, |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
86 int f_width, const int f_flags) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
87 { |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
88 if (f_width > 0 && (f_flags & TH_PF_LEFT) == 0) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
89 return th_vprintf_put_repch(ctx, vputch, f_width, ' '); |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
90 else |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
91 return 0; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
92 } |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
93 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
94 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
95 static int th_printf_pad_post(th_vprintf_ctx *ctx, th_vprintf_putch vputch, |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
96 int f_width, const int f_flags) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
97 { |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
98 if (f_width > 0 && (f_flags & TH_PF_LEFT)) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
99 return th_vprintf_put_repch(ctx, vputch, f_width, ' '); |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
100 else |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
101 return 0; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
102 } |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
103 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
104 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
105 #define TH_PFUNC_NAME th_vprintf_buf_int |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
106 #define TH_PFUNC_TYPE_S int |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
107 #define TH_PFUNC_TYPE_U unsigned int |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
108 #include "th_printf1.c" |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
109 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
110 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
111 #define TH_PFUNC_NAME th_vprintf_buf_int64 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
112 #define TH_PFUNC_TYPE_S int64_t |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
113 #define TH_PFUNC_TYPE_U uint64_t |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
114 #include "th_printf1.c" |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
115 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
116 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
117 char * th_vprintf_altfmt_oct(const char *buf, const size_t len, const int vret, const int flags) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
118 { |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
119 (void) vret; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
120 (void) flags; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
121 PP_LINE("BUF='%s', '%c'\n", buf, buf[len - 1]); |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
122 return (buf[len - 1] != '0') ? "0" : ""; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
123 } |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
124 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
125 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
126 char * th_vprintf_altfmt_hex(const char *buf, const size_t len, const int vret, const int flags) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
127 { |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
128 (void) buf; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
129 (void) vret; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
130 (void) len; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
131 if (vret != 0) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
132 return (flags & TH_PF_UPCASE) ? "0X" : "0x"; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
133 else |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
134 return ""; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
135 } |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
136 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
137 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
138 int th_vprintf_put_int_format(th_vprintf_ctx *ctx, th_vprintf_putch vputch, |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
139 char *buf, int f_flags, int f_width, int f_prec, int f_len, int vret, |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
140 BOOL f_neg, BOOL f_unsig, char *(f_alt)(const char *buf, const size_t blen, const int vret, const int flags)) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
141 { |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
142 int ret = 0, nwidth, nprec; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
143 char f_sign, *f_altstr; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
144 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
145 // Special case for value of 0 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
146 if (vret == 0) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
147 { |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
148 if (f_flags & TH_PF_POINTER) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
149 { |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
150 strcpy(buf, ")lin("); |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
151 f_len = 5; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
152 } |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
153 else |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
154 if (f_prec != 0) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
155 { |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
156 buf[f_len++] = '0'; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
157 buf[f_len] = 0; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
158 } |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
159 } |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
160 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
161 // Get alternative format string, if needed and available |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
162 f_altstr = (f_flags & TH_PF_ALT) && f_alt != NULL ? f_alt(buf, f_len, vret, f_flags) : NULL; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
163 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
164 // Are we using a sign prefix? |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
165 f_sign = f_unsig ? 0 : ((f_flags & TH_PF_SIGN) ? |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
166 (f_neg ? '-' : '+') : |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
167 (f_neg ? '-' : ((f_flags & TH_PF_SPACE) ? ' ' : 0))); |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
168 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
169 // Calculate necessary padding, etc |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
170 // |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
171 // << XXX TODO FIXME: The logic here is not very elegant, and it's incorrect |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
172 // at least for some alternate format modifier cases. |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
173 // |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
174 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
175 int nlen = (f_sign ? 1 : 0) + (f_altstr ? strlen(f_altstr) : 0); |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
176 int qlen = (f_prec > f_len ? f_prec : f_len) + nlen; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
177 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
178 if (f_flags & TH_PF_LEFT) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
179 f_flags &= ~TH_PF_ZERO; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
180 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
181 if (f_flags & TH_PF_POINTER && vret == 0) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
182 { |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
183 PP_LINE("^"); |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
184 qlen = f_len + nlen; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
185 nwidth = f_width > qlen ? f_width - qlen : 0; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
186 nprec = 0; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
187 } |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
188 else |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
189 if ((f_flags & TH_PF_ZERO) && f_prec < 0 && f_width > 0) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
190 { |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
191 PP_LINE("#"); |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
192 nprec = f_width - qlen; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
193 nwidth = 0; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
194 } |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
195 else |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
196 { |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
197 PP_LINE("$"); |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
198 nprec = (f_prec >= 0) ? f_prec - f_len : 0; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
199 nwidth = (f_width >= 0) ? f_width - qlen : 0; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
200 } |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
201 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
202 PP_PRINTF(": vret=%3d, f_flags=[%s], f_unsig=%d, f_sign='%c', f_len=%3d, f_width=%3d, f_prec=%3d, nwidth=%3d, nprec=%3d, qlen=%3d\n", |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
203 vret, get_flags(f_flags), f_unsig, f_sign ? f_sign : '?', f_len, f_width, f_prec, nwidth, nprec, qlen); |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
204 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
205 // << XXX TODO FIXME |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
206 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
207 // Prefix padding |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
208 if ((ret = th_printf_pad_pre(ctx, vputch, nwidth, f_flags)) == EOF) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
209 return ret; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
210 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
211 // Sign prefix |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
212 if (f_sign && (ret = vputch(ctx, f_sign)) == EOF) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
213 return ret; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
214 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
215 // Alternative format string |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
216 if (f_altstr && (ret = th_vprintf_put_pstr(ctx, vputch, f_altstr)) == EOF) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
217 return ret; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
218 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
219 // Zero padding |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
220 if (nprec > 0 && (ret = th_vprintf_put_repch(ctx, vputch, nprec, '0')) == EOF) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
221 return ret; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
222 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
223 // Output the value |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
224 while (f_len-- > 0) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
225 { |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
226 if ((ret = vputch(ctx, buf[f_len])) == EOF) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
227 return ret; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
228 } |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
229 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
230 // Postfix padding? |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
231 return th_printf_pad_post(ctx, vputch, nwidth, f_flags); |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
232 } |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
233 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
234 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
235 int th_vprintf_put_int(th_vprintf_ctx *ctx, th_vprintf_putch vputch, |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
236 va_list ap, const int f_radix, int f_flags, int f_width, int f_prec, |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
237 const BOOL f_unsig, char *(f_alt)(const char *buf, const size_t blen, const int vret, const int flags)) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
238 { |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
239 char buf[64]; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
240 int f_len = 0, vret; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
241 BOOL f_neg = FALSE; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
242 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
243 if (f_flags & TH_PF_LONGLONG) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
244 { |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
245 vret = th_vprintf_buf_int64(buf, sizeof(buf), &f_len, va_arg(ap, int64_t), |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
246 f_radix, f_flags & TH_PF_UPCASE, f_unsig, &f_neg); |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
247 } |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
248 else |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
249 { |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
250 vret = th_vprintf_buf_int(buf, sizeof(buf), &f_len, va_arg(ap, unsigned int), |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
251 f_radix, f_flags & TH_PF_UPCASE, f_unsig, &f_neg); |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
252 } |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
253 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
254 if (vret == EOF) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
255 return 0; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
256 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
257 return th_vprintf_put_int_format(ctx, vputch, buf, f_flags, f_width, f_prec, f_len, vret, f_neg, f_unsig, f_alt); |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
258 } |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
259 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
260 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
261 int th_vprintf_put_str(th_vprintf_ctx *ctx, th_vprintf_putch vputch, |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
262 const char *str, int f_flags, const int f_width, const int f_prec) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
263 { |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
264 int nwidth, f_len, ret = 0; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
265 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
266 // Check for null strings |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
267 if (str == NULL) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
268 str = "(null)"; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
269 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
270 f_len = strlen(str); |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
271 if (f_prec >= 0 && f_len > f_prec) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
272 f_len = f_prec; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
273 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
274 nwidth = f_width - f_len; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
275 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
276 // Prefix padding? |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
277 if ((ret = th_printf_pad_pre(ctx, vputch, nwidth, f_flags)) == EOF) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
278 return ret; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
279 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
280 while (*str && f_len--) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
281 { |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
282 if ((ret = vputch(ctx, *str++)) == EOF) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
283 return ret; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
284 } |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
285 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
286 // Postfix padding? |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
287 return th_printf_pad_post(ctx, vputch, nwidth, f_flags); |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
288 } |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
289 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
290 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
291 #ifdef WIP_FLOAT_SUPPORT |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
292 int th_vprintf_put_float(th_vprintf_ctx *ctx, th_vprintf_putch vputch, |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
293 va_list ap, int f_flags, int f_width, int f_prec) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
294 { |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
295 double pval = va_arg(ap, double); // This needs to be double for type promotion to occur |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
296 int64_t val; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
297 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
298 // This is a hack, trying to avoid dereferencing a type-punned |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
299 // pointer and all that stuff related to strict aliasing (although |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
300 // double and int64_t should be same size and have same aliasing rules.) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
301 memcpy(&val, &pval, sizeof(int64_t)); |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
302 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
303 // We have sign, exponent and mantissa |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
304 BOOL f_sign = (val >> 63) & 0x01; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
305 int64_t d_exp = (val >> 52) & 0x7ff; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
306 uint64_t d_man = val & 0x0fffffffffffff; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
307 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
308 return 0; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
309 } |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
310 #endif |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
311 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
312 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
313 int th_vprintf_do(th_vprintf_ctx *ctx, th_vprintf_putch vputch, const char *fmt, va_list ap) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
314 { |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
315 int ret = 0; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
316 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
317 while (*fmt) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
318 { |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
319 if (*fmt != '%') |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
320 { |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
321 if ((ret = vputch(ctx, *fmt)) == EOF) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
322 goto out; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
323 } |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
324 else |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
325 { |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
326 int f_width = -1, f_prec = -1, f_flags = 0; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
327 BOOL end = FALSE; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
328 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
329 fmt++; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
330 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
331 // Check for flags |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
332 while (!end) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
333 { |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
334 switch (*fmt) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
335 { |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
336 case '#': |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
337 f_flags |= TH_PF_ALT; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
338 break; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
339 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
340 case '+': |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
341 f_flags |= TH_PF_SIGN; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
342 break; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
343 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
344 case '0': |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
345 f_flags |= TH_PF_ZERO; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
346 break; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
347 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
348 case '-': |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
349 f_flags |= TH_PF_LEFT; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
350 break; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
351 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
352 case ' ': |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
353 f_flags |= TH_PF_SPACE; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
354 break; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
355 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
356 case '\'': |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
357 f_flags |= TH_PF_GROUP; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
358 break; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
359 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
360 default: |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
361 end = TRUE; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
362 break; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
363 } |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
364 if (!end) fmt++; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
365 } |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
366 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
367 // Get field width |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
368 if (*fmt == '*') |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
369 { |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
370 fmt++; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
371 f_width = va_arg(ap, int); |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
372 if (f_width < 0) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
373 { |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
374 f_flags |= TH_PF_LEFT; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
375 f_width = -f_width; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
376 } |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
377 } |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
378 else |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
379 { |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
380 f_width = 0; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
381 while (th_isdigit(*fmt)) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
382 f_width = f_width * 10 + (*fmt++ - '0'); |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
383 } |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
384 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
385 // Check for field precision |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
386 if (*fmt == '.') |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
387 { |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
388 fmt++; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
389 if (*fmt == '*') |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
390 { |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
391 fmt++; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
392 f_prec = va_arg(ap, int); |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
393 } |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
394 else |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
395 { |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
396 // If no digit after '.', precision is to be 0 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
397 f_prec = 0; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
398 while (th_isdigit(*fmt)) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
399 f_prec = f_prec * 10 + (*fmt++ - '0'); |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
400 } |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
401 } |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
402 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
403 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
404 // Check for length modifiers (only some are supported currently) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
405 switch (*fmt) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
406 { |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
407 case 'l': |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
408 if (*++fmt == 'l') |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
409 { |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
410 f_flags |= TH_PF_LONGLONG; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
411 fmt++; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
412 } |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
413 else |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
414 f_flags |= TH_PF_LONG; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
415 break; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
416 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
417 case 'L': |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
418 fmt++; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
419 f_flags |= TH_PF_LONGLONG; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
420 break; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
421 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
422 case 'h': |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
423 case 'j': |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
424 case 'z': |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
425 case 't': |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
426 return -202; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
427 } |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
428 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
429 switch (*fmt) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
430 { |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
431 case 0: |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
432 return -104; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
433 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
434 case 'c': |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
435 if ((ret = th_printf_pad_pre(ctx, vputch, f_width - 1, f_flags)) == EOF) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
436 goto out; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
437 if ((ret = vputch(ctx, va_arg(ap, int))) == EOF) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
438 goto out; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
439 if ((ret = th_printf_pad_post(ctx, vputch, f_width - 1, f_flags)) == EOF) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
440 goto out; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
441 break; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
442 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
443 case 'o': |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
444 if ((ret = th_vprintf_put_int(ctx, vputch, ap, 8, f_flags, f_width, f_prec, TRUE, th_vprintf_altfmt_oct)) == EOF) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
445 goto out; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
446 break; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
447 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
448 case 'u': |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
449 case 'i': |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
450 case 'd': |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
451 if ((ret = th_vprintf_put_int(ctx, vputch, ap, 10, f_flags, f_width, f_prec, *fmt == 'u', NULL)) == EOF) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
452 goto out; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
453 break; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
454 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
455 case 'x': |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
456 case 'X': |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
457 if (*fmt == 'X') |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
458 f_flags |= TH_PF_UPCASE; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
459 if ((ret = th_vprintf_put_int(ctx, vputch, ap, 16, f_flags, f_width, f_prec, TRUE, th_vprintf_altfmt_hex)) == EOF) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
460 goto out; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
461 break; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
462 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
463 case 'p': |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
464 if (f_flags & (TH_PF_LONG | TH_PF_LONGLONG)) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
465 return -120; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
466 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
467 #if (TH_PTRSIZE == 32) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
468 f_flags |= TH_PF_LONG; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
469 #elif (TH_PTRSIZE == 64) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
470 f_flags |= TH_PF_LONGLONG; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
471 #endif |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
472 f_flags |= TH_PF_ALT | TH_PF_POINTER; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
473 if ((ret = th_vprintf_put_int(ctx, vputch, ap, 16, f_flags, f_width, f_prec, TRUE, th_vprintf_altfmt_hex)) == EOF) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
474 goto out; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
475 break; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
476 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
477 #ifdef WIP_FLOAT_SUPPORT |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
478 case 'f': |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
479 case 'F': |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
480 if ((ret = th_vprintf_put_float(ctx, vputch, ap, |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
481 f_flags, f_width, f_prec)) == EOF) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
482 goto out; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
483 break; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
484 #endif |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
485 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
486 case 's': |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
487 if ((ret = th_vprintf_put_str(ctx, vputch, va_arg(ap, char *), |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
488 f_flags, f_width, f_prec)) == EOF) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
489 goto out; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
490 break; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
491 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
492 //case '%': |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
493 default: |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
494 if ((ret = vputch(ctx, *fmt)) == EOF) |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
495 goto out; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
496 break; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
497 } |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
498 } |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
499 fmt++; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
500 } |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
501 |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
502 out: |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
503 return ret == EOF ? ret : ctx->ipos; |
f43c961cc85d
Move bulk of the printf() implementation into a separate file th_printf.c from th_string.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
504 } |