-forgot that svn doesnt auto commits new files -_-

This commit is contained in:
fix94.1 2013-02-07 12:32:15 +00:00
parent b2b2fe2ea1
commit d8acff9fb0
2 changed files with 88 additions and 0 deletions

64
source/gui/fmt.c Normal file
View File

@ -0,0 +1,64 @@
// Simplified use of sprintf
#include "fmt.h"
#include <gccore.h>
#include <string.h>
#include <stdarg.h>
#include <stdio.h>
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;
}
}
}

24
source/gui/fmt.h Normal file
View File

@ -0,0 +1,24 @@
#ifndef _FMT_H_
#define _FMT_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdlib.h>
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_