mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Remove ReadParamString implementation from asteroids.
This commit is contained in:
parent
c55a2882dc
commit
fd256bbb51
1 changed files with 1 additions and 49 deletions
|
@ -9,6 +9,7 @@
|
|||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <error.h>
|
||||
#include <readparamstring.h>
|
||||
|
||||
// This define runs the game without actually setting the video mode and
|
||||
// checking whether the frame was actually copied to the screen. useful for
|
||||
|
@ -1077,55 +1078,6 @@ char* GetCurrentVideoMode()
|
|||
return mode;
|
||||
}
|
||||
|
||||
// TODO: This should be in libc and not use libmaxsi.
|
||||
#include <libmaxsi/platform.h>
|
||||
#include <libmaxsi/string.h>
|
||||
using namespace Maxsi;
|
||||
extern "C" bool ReadParamString(const char* str, ...)
|
||||
{
|
||||
if ( strchr(str, '\n') ) { errno = EINVAL; }
|
||||
const char* keyname;
|
||||
va_list args;
|
||||
while ( *str )
|
||||
{
|
||||
size_t varlen = strcspn(str, ",");
|
||||
if ( !varlen ) { str++; continue; }
|
||||
size_t namelen = strcspn(str, "=");
|
||||
if ( !namelen ) { errno = EINVAL; goto cleanup; }
|
||||
if ( !str[namelen] ) { errno = EINVAL; goto cleanup; }
|
||||
if ( varlen < namelen ) { errno = EINVAL; goto cleanup; }
|
||||
size_t valuelen = varlen - 1 /*=*/ - namelen;
|
||||
char* name = String::Substring(str, 0, namelen);
|
||||
if ( !name ) { goto cleanup; }
|
||||
char* value = String::Substring(str, namelen+1, valuelen);
|
||||
if ( !value ) { delete[] name; goto cleanup; }
|
||||
va_start(args, str);
|
||||
while ( (keyname = va_arg(args, const char*)) )
|
||||
{
|
||||
char** nameptr = va_arg(args, char**);
|
||||
if ( strcmp(keyname, name) ) { continue; }
|
||||
*nameptr = value;
|
||||
break;
|
||||
}
|
||||
va_end(args);
|
||||
if ( !keyname ) { delete[] value; }
|
||||
delete[] name;
|
||||
str += varlen;
|
||||
str += strspn(str, ",");
|
||||
}
|
||||
return true;
|
||||
|
||||
cleanup:
|
||||
va_start(args, str);
|
||||
while ( (keyname = va_arg(args, const char*)) )
|
||||
{
|
||||
char** nameptr = va_arg(args, char**);
|
||||
delete[] *nameptr; *nameptr = NULL;
|
||||
}
|
||||
va_end(args);
|
||||
return false;
|
||||
}
|
||||
|
||||
int atoi_safe(const char* str)
|
||||
{
|
||||
if ( !str ) { return 0; }
|
||||
|
|
Loading…
Add table
Reference in a new issue