diff options
| author | John "Lameguy" Wilbert Villamor <lameguy64@gmail.com> | 2022-01-18 08:31:14 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-18 08:31:14 +0800 |
| commit | 05d44488bd5587786f4bd0286fc0f555c79aa46a (patch) | |
| tree | 5740f396d10a9580c3a39ca536544436898ff1b6 /libpsn00b/libc | |
| parent | 08de895e8582dbc70b639ae5f511ab9ebfb4d68a (diff) | |
| parent | e9475e283a82665fe6c19bebc3318b5084f15a2e (diff) | |
| download | psn00bsdk-05d44488bd5587786f4bd0286fc0f555c79aa46a.tar.gz | |
Merge pull request #44 from spicyjpeg/actions
GitHub Actions CI, psxcd and libc fixes, new examples
Diffstat (limited to 'libpsn00b/libc')
| -rw-r--r-- | libpsn00b/libc/scanf.c | 7 | ||||
| -rw-r--r-- | libpsn00b/libc/string.c | 14 | ||||
| -rw-r--r-- | libpsn00b/libc/vsprintf.c | 11 |
3 files changed, 30 insertions, 2 deletions
diff --git a/libpsn00b/libc/scanf.c b/libpsn00b/libc/scanf.c index b6d4510..ae3c714 100644 --- a/libpsn00b/libc/scanf.c +++ b/libpsn00b/libc/scanf.c @@ -8,6 +8,9 @@ #include <string.h> #include <strings.h> +// Uncomment to enable support for %f. +//#define ALLOW_FLOAT + char libc_vsscanf_buf[512]; char libc_vsscanf_allow[256]; @@ -354,7 +357,8 @@ int vsscanf(const char *str, const char *format, va_list ap) r++; } break; - + +#ifdef ALLOW_FLOAT case 'f': // Floating point number libc_vsscanf_get_element(libc_vsscanf_buf, &str[sp], elem_skip_space, fsz); fbuf = strtod(libc_vsscanf_buf, &ep); @@ -380,6 +384,7 @@ int vsscanf(const char *str, const char *format, va_list ap) conv = 0; break; +#endif } } diff --git a/libpsn00b/libc/string.c b/libpsn00b/libc/string.c index 445b227..a1a9a05 100644 --- a/libpsn00b/libc/string.c +++ b/libpsn00b/libc/string.c @@ -8,6 +8,10 @@ #include <string.h> #include <stdlib.h> +// Uncomment to enable strtod(), strtold() and strtof(). Note that these +// functions use extremely slow software floats. +//#define ALLOW_FLOAT + int tolower(int chr) { return (chr >='A' && chr<='Z') ? (chr + 32) : (chr); @@ -252,6 +256,8 @@ long strtol(const char *nptr, char **endptr, int base) return (long)strtoll(nptr, endptr, base); } +#ifdef ALLOW_FLOAT + double strtod(const char *nptr, char **endptr) { char strbuf[64]; @@ -302,6 +308,8 @@ double strtod(const char *nptr, char **endptr) return (i + d)*s; } +#endif + /* implementation by Lameguy64, behaves like OpenWatcom's strtok() */ /* BIOS strtok seemed either bugged, or designed for wide chars */ @@ -344,6 +352,8 @@ char *strtok( char *s1, char *s2 ) } /* strtok */ +#ifdef ALLOW_FLOAT + long double strtold(const char *nptr, char **endptr) { return (long double)strtod(nptr, endptr); @@ -352,4 +362,6 @@ long double strtold(const char *nptr, char **endptr) float strtof(const char *nptr, char **endptr) { return (float)strtod(nptr, endptr); -}
\ No newline at end of file +} + +#endif diff --git a/libpsn00b/libc/vsprintf.c b/libpsn00b/libc/vsprintf.c index 0a99dcc..9ca4cc5 100644 --- a/libpsn00b/libc/vsprintf.c +++ b/libpsn00b/libc/vsprintf.c @@ -6,6 +6,10 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <stdarg.h> + +// Uncomment to enable support for %f. +//#define ALLOW_FLOAT #define SPRINTF_ALT_FLAG (1<<0) #define SPRINTF_ZERO_FLAG (1<<1) @@ -208,6 +212,8 @@ int libc_ulltoa(unsigned long i, char *dst, int n) return n2; } +#ifdef ALLOW_FLOAT + void libc_float_to_string(float fl, char *dst, int n) { unsigned int *p = (unsigned int*)&fl; @@ -365,6 +371,8 @@ void libc_double_to_string(double fl, char *dst, int n) char libc_sprintf_floatbuf[64]; +#endif + int vsnprintf(char *string, unsigned int size, const char *fmt, va_list ap) { int string_pos,fmt_pos; @@ -732,6 +740,7 @@ int vsnprintf(char *string, unsigned int size, const char *fmt, va_list ap) directive_coming = 0; break; +#ifdef ALLOW_FLOAT case 'f': libc_double_to_string(va_arg(ap, double), libc_sprintf_floatbuf, 64); @@ -740,6 +749,8 @@ int vsnprintf(char *string, unsigned int size, const char *fmt, va_list ap) directive_coming = 0; break; +#endif + case 'n': // Number of characters written *(va_arg(ap,unsigned int*)) = string_pos; |
