annotate th_string.h @ 567:b75f42ca08ef

Massage th_vprintf_do() a bit, and factor out the format specifier handling into a separate function and use through a callback. This breaks the th_vprintf_do() API, unfortunately, but should make for further flexibility in future.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 08 Jan 2020 02:17:37 +0200
parents 3a852e9f70a6
children 2fbe42d957c4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 * Miscellaneous string-handling related utility-functions
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 * Programmed and designed by Matti 'ccr' Hamalainen
553
3a852e9f70a6 Bump copyright years.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
4 * (C) Copyright 2002-2020 Tecnic Software productions (TNSP)
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 *
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 * Please read file 'COPYING' for information on license and distribution.
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 */
438
6245c825268b More Doxygenization.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
8 /// @file
6245c825268b More Doxygenization.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
9 /// @brief String utility functions
49
598609fb49b0 Change how "config.h" is included, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
10 #ifndef TH_STRING_H
598609fb49b0 Change how "config.h" is included, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
11 #define TH_STRING_H
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 #include "th_util.h"
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 #include <stdlib.h>
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 #include <ctype.h>
14
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
16 #include <stdarg.h>
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17
91
eca8ffe4e260 Move C++ guard.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
18 #ifdef __cplusplus
eca8ffe4e260 Move C++ guard.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
19 extern "C" {
eca8ffe4e260 Move C++ guard.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
20 #endif
eca8ffe4e260 Move C++ guard.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
21
438
6245c825268b More Doxygenization.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
22 /** @def String utility wrapper macros
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 */
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
24 #define th_isalnum(c) isalnum((int)(unsigned char) c)
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
25 #define th_isalpha(c) isalpha((int)(unsigned char) c)
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
26 #define th_isascii(c) isascii((int)(unsigned char) c)
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
27 #define th_isblank(c) isblank((int)(unsigned char) c)
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
28 #define th_iscntrl(c) iscntrl((int)(unsigned char) c)
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
29 #define th_isdigit(c) isdigit((int)(unsigned char) c)
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
30 #define th_isgraph(c) isgraph((int)(unsigned char) c)
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
31 #define th_islower(c) islower((int)(unsigned char) c)
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
32 #define th_isprint(c) isprint((int)(unsigned char) c)
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
33 #define th_ispunct(c) ispunct((int)(unsigned char) c)
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
34 #define th_isspace(c) isspace((int)(unsigned char) c)
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
35 #define th_isupper(c) isupper((int)(unsigned char) c)
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
36 #define th_isxdigit(c) isxdigit((int)(unsigned char) c)
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
37 #define th_iscrlf(c) ((c=='\r')||(c=='\n'))
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
39 #define th_isspecial(q) (((q >= 0x5b) && (q <= 0x60)) || ((q >= 0x7b) && (q <= 0x7d)))
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
41 #define th_tolower(c) tolower((int)(unsigned char) c)
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
42 #define th_toupper(c) toupper((int)(unsigned char) c)
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44
438
6245c825268b More Doxygenization.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
45 /** @def String trimming option flags for th_strdup_trim()
6245c825268b More Doxygenization.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
46 */
90
2b1f7f1ca8e4 Add new function th_strdup_trim().
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
47 enum
2b1f7f1ca8e4 Add new function th_strdup_trim().
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
48 {
372
3d32a0c72dc7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 370
diff changeset
49 TH_TRIM_START = 1,
3d32a0c72dc7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 370
diff changeset
50 TH_TRIM_END = 2,
3d32a0c72dc7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 370
diff changeset
51 TH_TRIM_BOTH = 3
90
2b1f7f1ca8e4 Add new function th_strdup_trim().
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
52 };
2b1f7f1ca8e4 Add new function th_strdup_trim().
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
53
2b1f7f1ca8e4 Add new function th_strdup_trim().
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
54
438
6245c825268b More Doxygenization.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
55 /** @def Internal *printf() implementation flags
6245c825268b More Doxygenization.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
56 */
299
0311f139fcf6 Refactor how various printf modifier flags etc. are handled. Still needs
Matti Hamalainen <ccr@tnsp.org>
parents: 279
diff changeset
57 enum
0311f139fcf6 Refactor how various printf modifier flags etc. are handled. Still needs
Matti Hamalainen <ccr@tnsp.org>
parents: 279
diff changeset
58 {
372
3d32a0c72dc7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 370
diff changeset
59 TH_PF_NONE = 0x0000,
3d32a0c72dc7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 370
diff changeset
60 TH_PF_ALT = 0x0001,
3d32a0c72dc7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 370
diff changeset
61 TH_PF_SIGN = 0x0002,
3d32a0c72dc7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 370
diff changeset
62 TH_PF_SPACE = 0x0004,
3d32a0c72dc7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 370
diff changeset
63 TH_PF_GROUP = 0x0008,
299
0311f139fcf6 Refactor how various printf modifier flags etc. are handled. Still needs
Matti Hamalainen <ccr@tnsp.org>
parents: 279
diff changeset
64
372
3d32a0c72dc7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 370
diff changeset
65 TH_PF_ZERO = 0x0100,
3d32a0c72dc7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 370
diff changeset
66 TH_PF_LEFT = 0x0200,
330
b2c4b0b4d44f Add initial support for ll and L printf modifiers.
Matti Hamalainen <ccr@tnsp.org>
parents: 309
diff changeset
67
372
3d32a0c72dc7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 370
diff changeset
68 TH_PF_LONG = 0x1000,
3d32a0c72dc7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 370
diff changeset
69 TH_PF_LONGLONG = 0x2000,
3d32a0c72dc7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 370
diff changeset
70 TH_PF_POINTER = 0x4000,
3d32a0c72dc7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 370
diff changeset
71 TH_PF_UPCASE = 0x8000,
299
0311f139fcf6 Refactor how various printf modifier flags etc. are handled. Still needs
Matti Hamalainen <ccr@tnsp.org>
parents: 279
diff changeset
72 };
0311f139fcf6 Refactor how various printf modifier flags etc. are handled. Still needs
Matti Hamalainen <ccr@tnsp.org>
parents: 279
diff changeset
73
0311f139fcf6 Refactor how various printf modifier flags etc. are handled. Still needs
Matti Hamalainen <ccr@tnsp.org>
parents: 279
diff changeset
74
438
6245c825268b More Doxygenization.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
75 /** @def Internal *printf() context structure
6245c825268b More Doxygenization.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
76 */
251
7b76108248e9 More work on printing functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
77 typedef struct
7b76108248e9 More work on printing functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
78 {
439
9b5a6fb05565 Adjust wording.
Matti Hamalainen <ccr@tnsp.org>
parents: 438
diff changeset
79 char *buf; ///< Resulting string buffer pointer (might not be used if printing to file or such)
438
6245c825268b More Doxygenization.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
80 size_t size, pos; ///< Size of result string buffer, and current position in it
6245c825268b More Doxygenization.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
81 int ipos; ///< Signed position
439
9b5a6fb05565 Adjust wording.
Matti Hamalainen <ccr@tnsp.org>
parents: 438
diff changeset
82 void *data; ///< Pointer to other data (for example a FILE pointer)
374
1d8ae82304ec Rename s/th_printf_ctx/th_vprintf_cts/g.
Matti Hamalainen <ccr@tnsp.org>
parents: 373
diff changeset
83 } th_vprintf_ctx;
251
7b76108248e9 More work on printing functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
84
7b76108248e9 More work on printing functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
85
448
57a3472131fd Typofix.
Matti Hamalainen <ccr@tnsp.org>
parents: 443
diff changeset
86 /** @def putch() helper function typedef for internal printf() implementation
438
6245c825268b More Doxygenization.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
87 */
374
1d8ae82304ec Rename s/th_printf_ctx/th_vprintf_cts/g.
Matti Hamalainen <ccr@tnsp.org>
parents: 373
diff changeset
88 typedef int (*th_vprintf_putch)(th_vprintf_ctx *ctx, const char ch);
277
7450d744e633 Rename internal functions and add a typedef for function pointer used for vputch().
Matti Hamalainen <ccr@tnsp.org>
parents: 268
diff changeset
89
7450d744e633 Rename internal functions and add a typedef for function pointer used for vputch().
Matti Hamalainen <ccr@tnsp.org>
parents: 268
diff changeset
90
567
b75f42ca08ef Massage th_vprintf_do() a bit, and factor out the format specifier handling
Matti Hamalainen <ccr@tnsp.org>
parents: 553
diff changeset
91 /** @def formatting helper function typedef for internal printf() implementation
b75f42ca08ef Massage th_vprintf_do() a bit, and factor out the format specifier handling
Matti Hamalainen <ccr@tnsp.org>
parents: 553
diff changeset
92 */
b75f42ca08ef Massage th_vprintf_do() a bit, and factor out the format specifier handling
Matti Hamalainen <ccr@tnsp.org>
parents: 553
diff changeset
93 typedef int (*th_vprintf_format)(
b75f42ca08ef Massage th_vprintf_do() a bit, and factor out the format specifier handling
Matti Hamalainen <ccr@tnsp.org>
parents: 553
diff changeset
94 th_vprintf_ctx *ctx, th_vprintf_putch vputch,
b75f42ca08ef Massage th_vprintf_do() a bit, and factor out the format specifier handling
Matti Hamalainen <ccr@tnsp.org>
parents: 553
diff changeset
95 int f_width, int f_prec, int f_flags,
b75f42ca08ef Massage th_vprintf_do() a bit, and factor out the format specifier handling
Matti Hamalainen <ccr@tnsp.org>
parents: 553
diff changeset
96 const char fmt, va_list ap);
b75f42ca08ef Massage th_vprintf_do() a bit, and factor out the format specifier handling
Matti Hamalainen <ccr@tnsp.org>
parents: 553
diff changeset
97
b75f42ca08ef Massage th_vprintf_do() a bit, and factor out the format specifier handling
Matti Hamalainen <ccr@tnsp.org>
parents: 553
diff changeset
98
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99 /* Normal NUL-terminated string functions
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100 */
186
1ee46a95aa8c Clean up the code, add argument identifiers to function prototypes and
Matti Hamalainen <ccr@tnsp.org>
parents: 167
diff changeset
101 char *th_strdup(const char *src);
1ee46a95aa8c Clean up the code, add argument identifiers to function prototypes and
Matti Hamalainen <ccr@tnsp.org>
parents: 167
diff changeset
102 char *th_strndup(const char *src, const size_t n);
486
bf984b494f07 Add function argument name to prototypes.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
103 char *th_strdup_trim(const char *src, const int flags);
bf984b494f07 Add function argument name to prototypes.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
104 char *th_strndup_trim(const char *src, const size_t n, const int flags);
81
c9c0541bed90 Add th_strndup().
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
105
487
702c64a6c570 Add new string helper functions th_strndup_no0() and th_strndup_no0_trim()
Matti Hamalainen <ccr@tnsp.org>
parents: 486
diff changeset
106 char *th_strndup_no0(const char *src, const size_t len);
702c64a6c570 Add new string helper functions th_strndup_no0() and th_strndup_no0_trim()
Matti Hamalainen <ccr@tnsp.org>
parents: 486
diff changeset
107 char *th_strndup_no0_trim(const char *src, const size_t len, const int flags);
702c64a6c570 Add new string helper functions th_strndup_no0() and th_strndup_no0_trim()
Matti Hamalainen <ccr@tnsp.org>
parents: 486
diff changeset
108
186
1ee46a95aa8c Clean up the code, add argument identifiers to function prototypes and
Matti Hamalainen <ccr@tnsp.org>
parents: 167
diff changeset
109 int th_strcasecmp(const char *haystack, const char *needle);
1ee46a95aa8c Clean up the code, add argument identifiers to function prototypes and
Matti Hamalainen <ccr@tnsp.org>
parents: 167
diff changeset
110 int th_strncasecmp(const char *haystack, const char *needle, size_t n);
1ee46a95aa8c Clean up the code, add argument identifiers to function prototypes and
Matti Hamalainen <ccr@tnsp.org>
parents: 167
diff changeset
111 char *th_strrcasecmp(char *haystack, const char *needle);
1ee46a95aa8c Clean up the code, add argument identifiers to function prototypes and
Matti Hamalainen <ccr@tnsp.org>
parents: 167
diff changeset
112 void th_strip_ctrlchars(char *str);
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
113
228
ca9cd98dbcff Initial work on printf() style function family implementation.
Matti Hamalainen <ccr@tnsp.org>
parents: 220
diff changeset
114 int th_vsnprintf(char *buf, size_t size, const char *fmt, va_list ap);
ca9cd98dbcff Initial work on printf() style function family implementation.
Matti Hamalainen <ccr@tnsp.org>
parents: 220
diff changeset
115 int th_snprintf(char *buf, size_t size, const char *fmt, ...);
ca9cd98dbcff Initial work on printf() style function family implementation.
Matti Hamalainen <ccr@tnsp.org>
parents: 220
diff changeset
116 int th_vfprintf(FILE *fh, const char *fmt, va_list ap);
ca9cd98dbcff Initial work on printf() style function family implementation.
Matti Hamalainen <ccr@tnsp.org>
parents: 220
diff changeset
117 int th_fprintf(FILE *fh, const char *fmt, ...);
ca9cd98dbcff Initial work on printf() style function family implementation.
Matti Hamalainen <ccr@tnsp.org>
parents: 220
diff changeset
118
ca9cd98dbcff Initial work on printf() style function family implementation.
Matti Hamalainen <ccr@tnsp.org>
parents: 220
diff changeset
119
186
1ee46a95aa8c Clean up the code, add argument identifiers to function prototypes and
Matti Hamalainen <ccr@tnsp.org>
parents: 167
diff changeset
120 char *th_strdup_vprintf(const char *fmt, va_list ap);
1ee46a95aa8c Clean up the code, add argument identifiers to function prototypes and
Matti Hamalainen <ccr@tnsp.org>
parents: 167
diff changeset
121 char *th_strdup_printf(const char *fmt, ...);
14
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
122
186
1ee46a95aa8c Clean up the code, add argument identifiers to function prototypes and
Matti Hamalainen <ccr@tnsp.org>
parents: 167
diff changeset
123 void th_pstr_vprintf(char **buf, const char *fmt, va_list ap);
1ee46a95aa8c Clean up the code, add argument identifiers to function prototypes and
Matti Hamalainen <ccr@tnsp.org>
parents: 167
diff changeset
124 void th_pstr_printf(char **buf, const char *fmt, ...);
30
10d2dc143e4b Add helper functions th_pstr_vprintf() and th_pstr_printf().
Matti Hamalainen <ccr@tnsp.org>
parents: 29
diff changeset
125
443
1d2d214ac433 Rename functions th_pstrcat() and th_pstrcpy() to th_pstr_cat() and th_pstr_cpy()
Matti Hamalainen <ccr@tnsp.org>
parents: 439
diff changeset
126 int th_pstr_cpy(char **pdst, const char *src);
1d2d214ac433 Rename functions th_pstrcat() and th_pstrcpy() to th_pstr_cat() and th_pstr_cpy()
Matti Hamalainen <ccr@tnsp.org>
parents: 439
diff changeset
127 int th_pstr_cat(char **pdst, const char *src);
186
1ee46a95aa8c Clean up the code, add argument identifiers to function prototypes and
Matti Hamalainen <ccr@tnsp.org>
parents: 167
diff changeset
128
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
129
451
db45d6d2e576 Expose some of the internal vprintf() implementation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 448
diff changeset
130 /* Internal printf() implementation. NOTICE! This API may be unstable.
db45d6d2e576 Expose some of the internal vprintf() implementation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 448
diff changeset
131 */
546
edfe8ac12408 Add function typedef th_vprintf_altfmt_func and #define
Matti Hamalainen <ccr@tnsp.org>
parents: 529
diff changeset
132 #define TH_VPRINTF_ALTFMT_FUNC(fname) char * fname ( \
547
c21051972015 Add int *prec and change int flags to int *flags in th_vprintf_altfmt_func
Matti Hamalainen <ccr@tnsp.org>
parents: 546
diff changeset
133 const char *buf, const size_t len, const int vret, int *prec, int *flags)
546
edfe8ac12408 Add function typedef th_vprintf_altfmt_func and #define
Matti Hamalainen <ccr@tnsp.org>
parents: 529
diff changeset
134
edfe8ac12408 Add function typedef th_vprintf_altfmt_func and #define
Matti Hamalainen <ccr@tnsp.org>
parents: 529
diff changeset
135 typedef char * (*th_vprintf_altfmt_func)(
547
c21051972015 Add int *prec and change int flags to int *flags in th_vprintf_altfmt_func
Matti Hamalainen <ccr@tnsp.org>
parents: 546
diff changeset
136 const char *buf, const size_t len, const int vret, int *prec, int *flags);
546
edfe8ac12408 Add function typedef th_vprintf_altfmt_func and #define
Matti Hamalainen <ccr@tnsp.org>
parents: 529
diff changeset
137
edfe8ac12408 Add function typedef th_vprintf_altfmt_func and #define
Matti Hamalainen <ccr@tnsp.org>
parents: 529
diff changeset
138
567
b75f42ca08ef Massage th_vprintf_do() a bit, and factor out the format specifier handling
Matti Hamalainen <ccr@tnsp.org>
parents: 553
diff changeset
139 int th_vprintf_do(th_vprintf_ctx *ctx, th_vprintf_putch vputch,
b75f42ca08ef Massage th_vprintf_do() a bit, and factor out the format specifier handling
Matti Hamalainen <ccr@tnsp.org>
parents: 553
diff changeset
140 th_vprintf_format vformat, const char *fmt, va_list ap);
b75f42ca08ef Massage th_vprintf_do() a bit, and factor out the format specifier handling
Matti Hamalainen <ccr@tnsp.org>
parents: 553
diff changeset
141
451
db45d6d2e576 Expose some of the internal vprintf() implementation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 448
diff changeset
142 int th_vprintf_put_str(th_vprintf_ctx *ctx, th_vprintf_putch vputch,
db45d6d2e576 Expose some of the internal vprintf() implementation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 448
diff changeset
143 const char *str, int f_flags, const int f_width, const int f_prec);
546
edfe8ac12408 Add function typedef th_vprintf_altfmt_func and #define
Matti Hamalainen <ccr@tnsp.org>
parents: 529
diff changeset
144
451
db45d6d2e576 Expose some of the internal vprintf() implementation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 448
diff changeset
145 int th_vprintf_put_int(th_vprintf_ctx *ctx, th_vprintf_putch vputch,
db45d6d2e576 Expose some of the internal vprintf() implementation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 448
diff changeset
146 va_list ap, const int f_radix, int f_flags, int f_width, int f_prec,
546
edfe8ac12408 Add function typedef th_vprintf_altfmt_func and #define
Matti Hamalainen <ccr@tnsp.org>
parents: 529
diff changeset
147 const BOOL f_unsig, th_vprintf_altfmt_func f_alt);
edfe8ac12408 Add function typedef th_vprintf_altfmt_func and #define
Matti Hamalainen <ccr@tnsp.org>
parents: 529
diff changeset
148
edfe8ac12408 Add function typedef th_vprintf_altfmt_func and #define
Matti Hamalainen <ccr@tnsp.org>
parents: 529
diff changeset
149 int th_vprintf_put_int_format(th_vprintf_ctx *ctx, th_vprintf_putch vputch,
451
db45d6d2e576 Expose some of the internal vprintf() implementation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 448
diff changeset
150 char *buf, int f_flags, int f_width, int f_prec, int f_len, int vret,
546
edfe8ac12408 Add function typedef th_vprintf_altfmt_func and #define
Matti Hamalainen <ccr@tnsp.org>
parents: 529
diff changeset
151 BOOL f_neg, BOOL f_unsig, th_vprintf_altfmt_func f_alt);
edfe8ac12408 Add function typedef th_vprintf_altfmt_func and #define
Matti Hamalainen <ccr@tnsp.org>
parents: 529
diff changeset
152
451
db45d6d2e576 Expose some of the internal vprintf() implementation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 448
diff changeset
153
546
edfe8ac12408 Add function typedef th_vprintf_altfmt_func and #define
Matti Hamalainen <ccr@tnsp.org>
parents: 529
diff changeset
154 TH_VPRINTF_ALTFMT_FUNC(th_vprintf_altfmt_oct);
edfe8ac12408 Add function typedef th_vprintf_altfmt_func and #define
Matti Hamalainen <ccr@tnsp.org>
parents: 529
diff changeset
155 TH_VPRINTF_ALTFMT_FUNC(th_vprintf_altfmt_hex);
452
4471eadea472 Oops, forgot to rename th_printf_altfmt_* from the header file.
Matti Hamalainen <ccr@tnsp.org>
parents: 451
diff changeset
156
451
db45d6d2e576 Expose some of the internal vprintf() implementation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 448
diff changeset
157
db45d6d2e576 Expose some of the internal vprintf() implementation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 448
diff changeset
158 #define TH_PFUNC_NAME th_vprintf_buf_int
db45d6d2e576 Expose some of the internal vprintf() implementation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 448
diff changeset
159 #define TH_PFUNC_TYPE_S int
db45d6d2e576 Expose some of the internal vprintf() implementation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 448
diff changeset
160 #define TH_PFUNC_TYPE_U unsigned int
db45d6d2e576 Expose some of the internal vprintf() implementation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 448
diff changeset
161 #define TH_PFUNC_HEADER 1
db45d6d2e576 Expose some of the internal vprintf() implementation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 448
diff changeset
162 #include "th_printf1.c"
db45d6d2e576 Expose some of the internal vprintf() implementation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 448
diff changeset
163
db45d6d2e576 Expose some of the internal vprintf() implementation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 448
diff changeset
164
db45d6d2e576 Expose some of the internal vprintf() implementation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 448
diff changeset
165 #define TH_PFUNC_NAME th_vprintf_buf_int64
db45d6d2e576 Expose some of the internal vprintf() implementation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 448
diff changeset
166 #define TH_PFUNC_TYPE_S int64_t
db45d6d2e576 Expose some of the internal vprintf() implementation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 448
diff changeset
167 #define TH_PFUNC_TYPE_U uint64_t
db45d6d2e576 Expose some of the internal vprintf() implementation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 448
diff changeset
168 #define TH_PFUNC_HEADER 1
db45d6d2e576 Expose some of the internal vprintf() implementation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 448
diff changeset
169 #include "th_printf1.c"
db45d6d2e576 Expose some of the internal vprintf() implementation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 448
diff changeset
170
db45d6d2e576 Expose some of the internal vprintf() implementation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 448
diff changeset
171
525
59b8f15c5334 Add (compile-time enabled via TH_PRINTF_DEBUG define) global variable for
Matti Hamalainen <ccr@tnsp.org>
parents: 497
diff changeset
172 #ifdef TH_PRINTF_DEBUG
59b8f15c5334 Add (compile-time enabled via TH_PRINTF_DEBUG define) global variable for
Matti Hamalainen <ccr@tnsp.org>
parents: 497
diff changeset
173 extern BOOL th_printf_debug;
529
c44ebf5b08fd Improve printf debugging in tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 525
diff changeset
174 extern char *th_printf_debug_prefix;
525
59b8f15c5334 Add (compile-time enabled via TH_PRINTF_DEBUG define) global variable for
Matti Hamalainen <ccr@tnsp.org>
parents: 497
diff changeset
175 #endif
59b8f15c5334 Add (compile-time enabled via TH_PRINTF_DEBUG define) global variable for
Matti Hamalainen <ccr@tnsp.org>
parents: 497
diff changeset
176
59b8f15c5334 Add (compile-time enabled via TH_PRINTF_DEBUG define) global variable for
Matti Hamalainen <ccr@tnsp.org>
parents: 497
diff changeset
177
78
2579250f2a84 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
178 /* Parsing, matching
2579250f2a84 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
179 */
14
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
180 const char *th_findnext(const char *, size_t *);
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
181 const char *th_findsep(const char *, size_t *, char);
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
182 const char *th_findseporspace(const char *, size_t *, char);
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
183
457
85fa3d333556 Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents: 454
diff changeset
184 BOOL th_strmatch(const char *haystack, const char *pattern);
85fa3d333556 Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents: 454
diff changeset
185 BOOL th_strcasematch(const char *haystack, const char *pattern);
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
186
497
ff3ebe22f6c5 Change int th_get_hex_triplet(const char *str) API to
Matti Hamalainen <ccr@tnsp.org>
parents: 487
diff changeset
187 BOOL th_get_hex_triplet(const char *str, unsigned int *value);
457
85fa3d333556 Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents: 454
diff changeset
188 BOOL th_get_boolean(const char *str, BOOL *value);
479
77ad030e82c9 Add th_get_int() helper function.
Matti Hamalainen <ccr@tnsp.org>
parents: 457
diff changeset
189 BOOL th_get_int(const char *str, unsigned int *value, BOOL *neg);
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
190
162
578d9298cc1e Actually, move th_print_wrap() to th_string module.
Matti Hamalainen <ccr@tnsp.org>
parents: 144
diff changeset
191 void th_print_wrap(FILE *fh, const char *str, int spad, int rpad, int width);
578d9298cc1e Actually, move th_print_wrap() to th_string module.
Matti Hamalainen <ccr@tnsp.org>
parents: 144
diff changeset
192
21
1f7d8693fda8 Add functions for growing a string/buffer and concatenating characters and/or other strings to it.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
193
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
194 #ifdef __cplusplus
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
195 }
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
196 #endif
129
aa2d608fb3f3 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
197 #endif // TH_STRING_H