omi-eikyo/src/m_str.c

75 lines
1.1 KiB
C

// Copyright © 2017 Project Golan, all rights reserved.
// See COPYING for more information.
#include "m_str.h"
#include "m_types.h"
#if __GDCC__
#include <Doominati.h>
#endif
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <stdlib.h>
// Extern Functions ----------------------------------------------------------|
//
// M_StrFmt
//
char *M_StrFmt(char const *fmt, ...)
{
#if __GDCC__
[[__no_init]]
#endif
static char bufs[3][0x2800];
static int idx;
va_list va;
if(++idx == M_countof(bufs)) idx = 0;
va_start(va, fmt);
vsnprintf(bufs[idx], sizeof(bufs[idx]), fmt, va);
va_end(va);
return bufs[idx];
}
//
// M_StrHash
//
mword M_StrHash(char const *s)
{
mword h = 0;
for(; *s; s++)
h = h * 101 + *s;
return h;
}
#if __GDCC__
//
// M_StrCreate
//
__str M_StrCreate(char const *s)
{
return DGE_String_Create(s, strlen(s));
}
//
// M_StrGet
//
char *M_StrGet(__str name)
{
[[__no_init]]
static char bufs[3][0x2800];
static int idx;
if(++idx == M_countof(bufs)) idx = 0;
DGE_Text_Read(name, bufs[idx], sizeof(bufs[idx]));
return bufs[idx];
}
#endif
// EOF