From d8acff9fb0633191122c4d292d4b9212cc26eb92 Mon Sep 17 00:00:00 2001 From: "fix94.1" Date: Thu, 7 Feb 2013 12:32:15 +0000 Subject: [PATCH] -forgot that svn doesnt auto commits new files -_- --- source/gui/fmt.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++ source/gui/fmt.h | 24 ++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 source/gui/fmt.c create mode 100644 source/gui/fmt.h diff --git a/source/gui/fmt.c b/source/gui/fmt.c new file mode 100644 index 00000000..32bb2e59 --- /dev/null +++ b/source/gui/fmt.c @@ -0,0 +1,64 @@ + +// Simplified use of sprintf +#include "fmt.h" +#include +#include +#include +#include + +int currentStr = 0; +static char fmt_buffer[MAX_USES][MAX_MSG_SIZE]; +char *fmt(const char *format, ...) +{ + va_list va; + va_start(va, format); + currentStr = (currentStr + 1) % MAX_USES; + vsnprintf(fmt_buffer[currentStr], MAX_MSG_SIZE - 1, format, va); + fmt_buffer[currentStr][MAX_MSG_SIZE - 1] = '\0'; + va_end(va); + return fmt_buffer[currentStr]; +} + +void Asciify(wchar_t *str) +{ + const wchar_t *ptr = str; + wchar_t *ctr = str; + + while(*ptr != '\0') + { + switch(*ptr) + { + case 0x14c: + *ctr = 0x4f; + break; + } + *ctr = *ptr; + ++ptr; + ++ctr; + } + *ctr = '\0'; +} + +void Asciify2(char *str) +{ + u8 i = 0; + for(i = 0; i < strlen(str); ++i) + { + if(str[i] < 0x20 || str[i] > 0x7F) + str[i] = '_'; + else switch(str[i]) + { + case '*': + case '\"': + case '|': + case '<': + case '>': + case '?': + case ':': + str[i] = '_'; + break; + default: + break; + } + } +} diff --git a/source/gui/fmt.h b/source/gui/fmt.h new file mode 100644 index 00000000..988f1b3e --- /dev/null +++ b/source/gui/fmt.h @@ -0,0 +1,24 @@ + +#ifndef _FMT_H_ +#define _FMT_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +enum { + MAX_MSG_SIZE = 1024, + MAX_USES = 8, +}; + +char *fmt(const char *format, ...); +void Asciify(wchar_t *str); +void Asciify2(char *str); + +#ifdef __cplusplus +} +#endif + +#endif //_FMT_H_