Rev 8687 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 8687 | Rev 8718 | ||
---|---|---|---|
1 | /////////////////////////////////////////////////////////////////////////////// |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // \author (c) Marco Paland (info@paland.com) |
2 | // \author (c) Marco Paland (info@paland.com) |
3 | // 2014-2019, PALANDesign Hannover, Germany |
3 | // 2014-2019, PALANDesign Hannover, Germany |
4 | // |
4 | // |
5 | // \license The MIT License (MIT) |
5 | // \license The MIT License (MIT) |
6 | // |
6 | // |
7 | // Permission is hereby granted, free of charge, to any person obtaining a copy |
7 | // Permission is hereby granted, free of charge, to any person obtaining a copy |
8 | // of this software and associated documentation files (the "Software"), to deal |
8 | // of this software and associated documentation files (the "Software"), to deal |
9 | // in the Software without restriction, including without limitation the rights |
9 | // in the Software without restriction, including without limitation the rights |
10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
11 | // copies of the Software, and to permit persons to whom the Software is |
11 | // copies of the Software, and to permit persons to whom the Software is |
12 | // furnished to do so, subject to the following conditions: |
12 | // furnished to do so, subject to the following conditions: |
13 | // |
13 | // |
14 | // The above copyright notice and this permission notice shall be included in |
14 | // The above copyright notice and this permission notice shall be included in |
15 | // all copies or substantial portions of the Software. |
15 | // all copies or substantial portions of the Software. |
16 | // |
16 | // |
17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
23 | // THE SOFTWARE. |
23 | // THE SOFTWARE. |
24 | // |
24 | // |
25 | // \brief Tiny printf, sprintf and snprintf implementation, optimized for speed on |
25 | // \brief Tiny printf, sprintf and snprintf implementation, optimized for speed on |
26 | // embedded systems with a very limited resources. |
26 | // embedded systems with a very limited resources. |
27 | // Use this instead of bloated standard/newlib printf. |
27 | // Use this instead of bloated standard/newlib printf. |
28 | // These routines are thread safe and reentrant. |
28 | // These routines are thread safe and reentrant. |
29 | // |
29 | // |
30 | /////////////////////////////////////////////////////////////////////////////// |
30 | /////////////////////////////////////////////////////////////////////////////// |
31 | 31 | ||
32 | #ifndef _STDIO_H_ |
32 | #ifndef _STDIO_H_ |
33 | #define _STDIO_H_ |
33 | #define _STDIO_H_ |
34 | 34 | ||
35 | #include |
35 | #include |
36 | #include |
36 | #include |
37 | #include |
37 | #include |
38 | 38 | ||
39 | extern int _FUNC(puts)(const char *str); |
39 | extern int _FUNC(puts)(const char *str); |
40 | extern int _FUNC(printf)(const char* format, ...); |
40 | extern int _FUNC(printf)(const char* format, ...); |
41 | extern int _FUNC(sprintf)(char* buffer, const char* format, ...); |
41 | extern int _FUNC(sprintf)(char* buffer, const char* format, ...); |
42 | extern int _FUNC(snprintf)(char* buffer, size_t count, const char* format, ...); |
42 | extern int _FUNC(snprintf)(char* buffer, size_t count, const char* format, ...); |
43 | extern int _FUNC(vsnprintf)(char* buffer, size_t count, const char* format, va_list va); |
43 | extern int _FUNC(vsnprintf)(char* buffer, size_t count, const char* format, va_list va); |
44 | extern int _FUNC(vprintf)(const char* format, va_list va); |
44 | extern int _FUNC(vprintf)(const char* format, va_list va); |
45 | 45 | ||
46 | extern void _FUNC(debug_printf)(const char* format, ...); |
46 | extern void _FUNC(debug_printf)(const char* format, ...); |
47 | 47 | ||
48 | typedef size_t fpos_t; |
48 | typedef size_t fpos_t; |
49 | 49 | ||
50 | #define _STDIO_F_R 1 << 0 // Read |
50 | #define _STDIO_F_R 1 << 0 // Read |
51 | #define _STDIO_F_W 1 << 1 // Write |
51 | #define _STDIO_F_W 1 << 1 // Write |
52 | #define _STDIO_F_A 1 << 2 // Append |
52 | #define _STDIO_F_A 1 << 2 // Append |
53 | #define _STDIO_F_X 1 << 3 // eXclusive |
53 | #define _STDIO_F_X 1 << 3 // eXclusive |
54 | #define _STDIO_F_B 1 << 4 // Binary |
54 | #define _STDIO_F_B 1 << 4 // Binary |
55 | 55 | ||
56 | typedef struct FILE_s { |
56 | typedef struct FILE_s { |
57 | char *name; |
57 | char *name; |
58 | fpos_t position; |
58 | fpos_t position; |
59 | int error; |
59 | int error; |
60 | int eof; |
60 | int eof; |
61 | int kind; // 0 - undiefned, 1 - text, 2 - binary |
61 | int kind; // 0 - undiefned, 1 - text, 2 - binary |
62 | int orientation; // 0 - undiefned, 1 - byte, 2 - wide |
62 | int orientation; // 0 - undiefned, 1 - byte, 2 - wide |
63 | int mode; // flags _STDIO_F_* |
63 | int mode; // flags _STDIO_F_* |
64 | int append_offset; // do not seek before this point ("a" mode) |
64 | int append_offset; // do not seek before this point ("a" mode) |
65 | int __ungetc_emu_buff; // Uses __ungetc_emu (temporary solution!) |
65 | int __ungetc_emu_buff; // Uses __ungetc_emu (temporary solution!) |
66 | int start_size; |
66 | int start_size; |
67 | } FILE; |
67 | } FILE; |
68 | 68 | ||
69 | #define _IOFBF 0 |
69 | #define _IOFBF 0 |
70 | #define _IOLBF 1 |
70 | #define _IOLBF 1 |
71 | #define _IONBF 2 |
71 | #define _IONBF 2 |
72 | 72 | ||
73 | #define BUFSIZ 1024 |
73 | #define BUFSIZ 1024 |
74 | 74 | ||
75 | #define EOF -1 |
75 | #define EOF -1 |
76 | 76 | ||
77 | #define FOPEN_MAX 0xffffffff |
77 | #define FOPEN_MAX 0xffffffff |
78 | 78 | ||
79 | #define FILENAME_MAX 255 |
79 | #define FILENAME_MAX 255 |
80 | 80 | ||
81 | #define L_tmpnam FILENAME_MAX |
81 | #define L_tmpnam FILENAME_MAX |
82 | 82 | ||
83 | #define SEEK_CUR 0 |
83 | #define SEEK_CUR 0 |
84 | #define SEEK_END 1 |
84 | #define SEEK_END 1 |
85 | #define SEEK_SET 2 |
85 | #define SEEK_SET 2 |
86 | 86 | ||
87 | #define TMP_MAX FOPEN_MAX |
87 | #define TMP_MAX FOPEN_MAX |
88 | 88 | ||
89 | #define stderr (FILE*)3 |
89 | #define stderr (FILE*)3 |
90 | #define stdin (FILE*)1 |
90 | #define stdin (FILE*)1 |
91 | #define stdout (FILE*)2 |
91 | #define stdout (FILE*)2 |
92 | 92 | ||
93 | extern int _FUNC(fgetc)(FILE *); |
93 | extern int _FUNC(fgetc)(FILE *); |
94 | extern char* _FUNC(fgets)(char *restrict, int, FILE *restrict); |
94 | extern char* _FUNC(fgets)(char *restrict, int, FILE *restrict); |
95 | extern int _FUNC(fprintf)(FILE *restrict, const char *restrict, ...); |
95 | extern int _FUNC(fprintf)(FILE *restrict, const char *restrict, ...); |
96 | extern int _FUNC(fputc)(int, FILE *); |
96 | extern int _FUNC(fputc)(int, FILE *); |
97 | extern int _FUNC(fputs)(const char *restrict, FILE *restrict); |
97 | extern int _FUNC(fputs)(const char *restrict, FILE *restrict); |
98 | extern size_t _FUNC(fread)(void *restrict, size_t size, size_t count, FILE *restrict); |
98 | extern size_t _FUNC(fread)(void *restrict, size_t size, size_t count, FILE *restrict); |
99 | extern int _FUNC(fscanf)(FILE *restrict, const char *restrict, ...); |
99 | extern int _FUNC(fscanf)(FILE *restrict, const char *restrict, ...); |
100 | extern size_t _FUNC(fwrite)(const void *restrict, size_t size, size_t count, FILE *restrict); |
100 | extern size_t _FUNC(fwrite)(const void *restrict, size_t size, size_t count, FILE *restrict); |
101 | extern int _FUNC(getc)(FILE *); |
101 | extern int _FUNC(getc)(FILE *); |
102 | #define getc _FUNC(fgetc) |
102 | #define getc _FUNC(fgetc) |
103 | extern int _FUNC(getchar)(void); |
103 | extern int _FUNC(getchar)(void); |
104 | extern int _FUNC(printf)(const char *restrict, ...); |
104 | extern int _FUNC(printf)(const char *restrict, ...); |
105 | extern int _FUNC(putc)(int, FILE *); |
105 | extern int _FUNC(putc)(int, FILE *); |
106 | extern int _FUNC(putchar)(int); |
106 | extern int _FUNC(putchar)(int); |
107 | extern int _FUNC(puts)(const char *); |
107 | extern int _FUNC(puts)(const char *); |
108 | extern int _FUNC(scanf)(const char *restrict, ...); |
108 | extern int _FUNC(scanf)(const char *restrict, ...); |
109 | extern char* _FUNC(gets)(char *str); |
109 | extern char* _FUNC(gets)(char *str); |
110 | //extern int _FUNC(ungetc)(int, FILE *); |
110 | extern int _FUNC(ungetc)(int, FILE *); |
111 | extern int _FUNC(vfprintf)(FILE *restrict, const char *restrict, va_list); |
111 | extern int _FUNC(vfprintf)(FILE *restrict, const char *restrict, va_list); |
112 | extern int _FUNC(vfscanf)(FILE *restrict, const char *restrict, va_list); |
112 | extern int _FUNC(vfscanf)(FILE *restrict, const char *restrict, va_list); |
113 | extern int _FUNC(vprintf)(const char *restrict, va_list); |
113 | extern int _FUNC(vprintf)(const char *restrict, va_list); |
114 | extern int _FUNC(vscanf)(const char *restrict, va_list); |
114 | extern int _FUNC(vscanf)(const char *restrict, va_list); |
- | 115 | extern int _FUNC(sscanf)(const char*, const char *restrict, ...); |
|
115 | extern int _FUNC(vsscanf)(const char *, const char*, va_list); |
116 | extern int _FUNC(vsscanf)(const char *, const char*, va_list); |
116 | 117 | ||
117 | extern int _FUNC(remove)(const char *); |
118 | extern int _FUNC(remove)(const char *); |
118 | extern int _FUNC(rename)(const char *, const char *); |
119 | extern int _FUNC(rename)(const char *, const char *); |
119 | extern FILE* _FUNC(tmpfile)(void); |
120 | extern FILE* _FUNC(tmpfile)(void); |
120 | extern char* _FUNC(tmpnam)(char *); |
121 | extern char* _FUNC(tmpnam)(char *); |
121 | 122 | ||
122 | extern int _FUNC(fclose)(FILE *); |
123 | extern int _FUNC(fclose)(FILE *); |
123 | extern int _FUNC(fflush)(FILE *); |
124 | extern int _FUNC(fflush)(FILE *); |
124 | extern FILE* _FUNC(fopen)(const char *restrict, const char *restrict); |
125 | extern FILE* _FUNC(fopen)(const char *restrict, const char *restrict); |
125 | extern FILE* _FUNC(freopen)(const char *restrict, const char *restrict, FILE *restrict); |
126 | extern FILE* _FUNC(freopen)(const char *restrict, const char *restrict, FILE *restrict); |
126 | extern void _FUNC(setbuf)(FILE *restrict, char *restrict); |
127 | extern void _FUNC(setbuf)(FILE *restrict, char *restrict); |
127 | extern int _FUNC(setvbuf)(FILE *restrict, char *restrict, int, size_t); |
128 | extern int _FUNC(setvbuf)(FILE *restrict, char *restrict, int, size_t); |
128 | 129 | ||
129 | extern int _FUNC(fgetpos)(FILE *restrict, fpos_t *restrict); |
130 | extern int _FUNC(fgetpos)(FILE *restrict, fpos_t *restrict); |
130 | extern int _FUNC(fseek)(FILE *, long, int); |
131 | extern int _FUNC(fseek)(FILE *, long, int); |
131 | extern int _FUNC(fsetpos)(FILE *, const fpos_t *); |
132 | extern int _FUNC(fsetpos)(FILE *, const fpos_t *); |
132 | extern long _FUNC(ftell)(FILE *); |
133 | extern long _FUNC(ftell)(FILE *); |
133 | extern void _FUNC(rewind)(FILE *); |
134 | extern void _FUNC(rewind)(FILE *); |
134 | 135 | ||
135 | extern void _FUNC(clearerr)(FILE *); |
136 | extern void _FUNC(clearerr)(FILE *); |
136 | extern int _FUNC(feof)(FILE *); |
137 | extern int _FUNC(feof)(FILE *); |
137 | extern int _FUNC(ferror)(FILE *); |
138 | extern int _FUNC(ferror)(FILE *); |
138 | extern void _FUNC(perror)(const char *); |
139 | extern void _FUNC(perror)(const char *); |
139 | 140 | ||
140 | extern size_t _FUNC(fread)(void *restrict, size_t, size_t, FILE *restrict); |
141 | extern size_t _FUNC(fread)(void *restrict, size_t, size_t, FILE *restrict); |
141 | 142 | ||
142 | extern int _FUNC(getchar)(void); |
143 | extern int _FUNC(getchar)(void); |
143 | 144 | ||
144 | extern void _FUNC(con_set_title)(const char*); |
145 | extern void _FUNC(con_set_title)(const char*); |
145 | 146 | ||
146 | #endif // _STDIO_H_><>><>><>><>><> |
147 | #endif // _STDIO_H_><>><>><>><>><> |