1// This file is part of SmallBASIC
2//
3// formating numbers and strings
4//
5// This program is distributed under the terms of the GPL v2.0 or later
6// Download the GNU Public License (GPL) from www.gnu.org
7//
8// Copyright(C) 2000 Nicholas Christopoulos
9
10#if !defined(_sb_fmt_h)
11#define _sb_fmt_h
12
13#include "common/sys.h"
14
15#if defined(__cplusplus)
16extern "C" {
17#endif
18
19/**
20 * @ingroup str
21 *
22 * Part of floating point to string (by using integers) algorithm
23 * where x any number 2^31 > x >= 0
24 *
25 * @param x is the number
26 * @param dest is the string buffer
27 */
28void fptoa(var_num_t x, char *dest);
29
30/**
31 * @ingroup str
32 *
33 * best float to string
34 *
35 * @param x is the number
36 * @param dest is the string buffer
37 */
38void bestfta(var_num_t x, char *dest);
39
40/**
41 * @ingroup str
42 *
43 * float to string (user, E mode)
44 *
45 * @param x is the number
46 * @param dest is the string buffer
47 */
48void expfta(var_num_t x, char *dest);
49
50/**
51 * @ingroup str
52 *
53 * format: format a number
54 *
55 * symbols:
56 @code
57 # = digit or space
58 0 = digit or zero
59 ^ = exponential digit/format
60 . = decimal point
61 , = thousands
62 - = minus for negative
63 + = sign of number
64 @endcode
65 *
66 * @param dest is the string buffer
67 * @param fmt_cnst is the format string
68 * @param x is the number
69 */
70char *format_num(const char *fmt_cnst, var_num_t x);
71
72/**
73 * @ingroup str
74 *
75 * format: format a string
76 *
77 * symbols:
78 @code
79 & the whole string
80 ! the first char
81 \\ segment
82 @endcode
83 *
84 * @param dest is the string buffer
85 * @param fmt_cnst is the format string
86 * @param str is the source string
87 */
88char *format_str(const char *fmt_cnst, const char *str);
89
90/**
91 * @ingroup str
92 *
93 * creates the internal-format queue
94 *
95 * @note part of USING
96 *
97 * @param fmt_cnst is the format
98 */
99void build_format(const char *fmt_cnst);
100
101/**
102 * @ingroup str
103 *
104 * clears the internal-format queue
105 *
106 * @note part of USING
107 */
108void free_format(void);
109
110/**
111 * @ingroup str
112 *
113 * prints a number using the queued format
114 *
115 * @note part of USING
116 *
117 * @param x is the number
118 * @param output is the output-set-of-routines code (see PV_xxx macros)
119 * @param handle is the output handle (depented on output-code)
120 */
121void fmt_printN(var_num_t x, int output, intptr_t handle);
122
123/**
124 * @ingroup str
125 *
126 * prints a string using the queued format
127 *
128 * @note part of USING
129 *
130 * @param str is the string
131 * @param output is the output-set-of-routines code (see PV_xxx macros)
132 * @param handle is the output handle (depented on output-code)
133 */
134void fmt_printS(const char *str, int output, intptr_t handle);
135
136#if defined(__cplusplus)
137}
138#endif
139#endif
140