-
Notifications
You must be signed in to change notification settings - Fork 4
/
cout.c
181 lines (145 loc) · 5.82 KB
/
cout.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/* INFO ************************************************************************
** **
** cutils **
** ====== **
** **
** Modern and Lightweight C Utilities **
** Version: 0.8.95.968 (20140904) **
** **
** File: cout.c **
** **
** For more information about the project, visit <http://www.cutils.org>. **
** Copyright (C) 2014 Peter Varo **
** **
** This program is free software: you can redistribute it and/or modify it **
** under the terms of the GNU General Public License as published by the **
** Free Software Foundation, either version 3 of the License, or **
** (at your option) any later version. **
** **
** This program is distributed in the hope that it will be useful, but **
** WITHOUT ANY WARRANTY; without even the implied warranty of **
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. **
** See the GNU General Public License for more details. **
** **
** You should have received a copy of the GNU General Public License **
** along with this program, most likely a file in the root directory, **
** called 'LICENSE'. If not, see <http://www.gnu.org/licenses>. **
** **
************************************************************************ INFO */
/* Include standard headers */
#include <stdio.h> /* stdout, fprintf(), snprintf() */
#include <stdbool.h> /* bool */
/* Include cutils headers */
#include "internal/fmtc.h"
/* TODO: - add arrays (eg. char[]) => _Generic sees char* and char[] differently
- add pointers (eg. int*)
- add qualifiers (eg. const void*) */
/*----------------------------------------------------------------------------*/
void
cutils_cout_char_print(char character)
{
#define BUFFER_SIZE 8
char buffer[BUFFER_SIZE];
cutils_fmtc_repr(buffer, BUFFER_SIZE, &character, 1);
fprintf(stdout, "%s\n", buffer);
}
/*----------------------------------------------------------------------------*/
void
cutils_cout_signed_char_print(signed char character)
{
fprintf(stdout, "%d\n", character);
}
/*----------------------------------------------------------------------------*/
void
cutils_cout_unsigned_char_print(unsigned char character)
{
fprintf(stdout, "%u\n", character);
}
/*----------------------------------------------------------------------------*/
void
cutils_cout_char_ptr_print(char *string)
{
size_t string_size = snprintf(NULL, 0, "%s", string);
size_t buffer_size = string_size*2;
char *buffer = malloc(buffer_size);
cutils_fmtc_repr(buffer, buffer_size, string, string_size);
fprintf(stdout, "%s\n", buffer);
}
/*----------------------------------------------------------------------------*/
void
cutils_cout_short_print(short number)
{
fprintf(stdout, "%hd\n", number);
}
/*----------------------------------------------------------------------------*/
void
cutils_cout_unsigned_short_print(unsigned short number)
{
fprintf(stdout, "%hu\n", number);
}
/*----------------------------------------------------------------------------*/
void
cutils_cout_int_print(int number)
{
fprintf(stdout, "%d\n", number);
}
/*----------------------------------------------------------------------------*/
void
cutils_cout_unsigned_int_print(unsigned int number)
{
fprintf(stdout, "%uu\n", number);
}
/*----------------------------------------------------------------------------*/
void
cutils_cout_long_print(long number)
{
fprintf(stdout, "%ldl\n", number);
}
/*----------------------------------------------------------------------------*/
void
cutils_cout_unsigned_long_print(unsigned long number)
{
fprintf(stdout, "%luul\n", number);
}
/*----------------------------------------------------------------------------*/
void
cutils_cout_long_long_print(long long number)
{
fprintf(stdout, "%lldll\n", number);
}
/*----------------------------------------------------------------------------*/
void
cutils_cout_unsigned_long_long_print(unsigned long long number)
{
fprintf(stdout, "%lluull\n", number);
}
/*----------------------------------------------------------------------------*/
void
cutils_cout_float_print(float number)
{
fprintf(stdout, "%ff\n", number);
}
/*----------------------------------------------------------------------------*/
void
cutils_cout_double_print(double number)
{
fprintf(stdout, "%lf\n", number);
}
/*----------------------------------------------------------------------------*/
void
cutils_cout_long_double_print(long double number)
{
fprintf(stdout, "%Lf\n", number);
}
/*----------------------------------------------------------------------------*/
void
cutils_cout_bool_print(bool boolean)
{
fprintf(stdout, "%s\n", boolean ? "true" : "false");
}
/*----------------------------------------------------------------------------*/
void
cutils_cout_void_ptr_print(void *pointer)
{
fprintf(stdout, "<pointer to %p>\n", pointer);
}