feat(options): implement StormSetOption

This commit is contained in:
phaneron 2025-03-31 14:29:51 -04:00
parent 09e7076a9b
commit 2ffa8217c0
4 changed files with 149 additions and 0 deletions

108
storm/option/Option.cpp Normal file
View file

@ -0,0 +1,108 @@
#include "storm/option/Option.hpp"
#include "storm/option/Options.hpp"
#include "storm/Error.hpp"
int32_t StormSetOption(int32_t optname, const void* optval, uint32_t optlen) {
SErrSetLastError(ERROR_INVALID_PARAMETER);
if (!optval) {
return 0;
}
uint32_t val;
switch (optname) {
case 1:
if (optlen != 4) {
return 0;
}
g_opt.serrleaksilentwarning = *static_cast<const int32_t*>(optval);
SErrSetLastError(0);
return 1;
case 2:
val = *static_cast<const int32_t*>(optval);
if (optlen != 4 || !val || (val ^ (val - 1)) != 2 * val - 1) {
return 0;
}
g_opt.wavechunksize = val;
SErrSetLastError(0);
return 1;
case 3:
if (optlen != 4) {
return 0;
}
g_opt.smemleaksilentwarning = *static_cast<const int32_t*>(optval);
SErrSetLastError(0);
return 1;
case 4:
if (optlen != 4) {
return 0;
}
g_opt.opt0C = *static_cast<const int32_t*>(optval);
SErrSetLastError(0);
return 1;
case 5:
if (optlen != 4) {
return 0;
}
g_opt.opt10 = *static_cast<const int32_t*>(optval);
SErrSetLastError(0);
return 1;
case 6:
if (optlen != 8) {
return 0;
}
s_alloccount = static_cast<const uint32_t*>(optval)[0];
s_freecount = static_cast<const uint32_t*>(optval)[1];
SErrSetLastError(0);
return 1;
case 7:
if (optlen != 4) {
return 0;
}
g_opt.opt14 = *static_cast<const int32_t*>(optval);
SErrSetLastError(0);
return 1;
case 9:
if (optlen != 4) {
return 0;
}
g_opt.opt18 = *static_cast<const int32_t*>(optval) != 0;
SErrSetLastError(0);
return 1;
case 10:
if (optlen != 4) {
return 0;
}
g_opt.opt1C = *static_cast<const int32_t*>(optval) != 0;
SErrSetLastError(0);
return 1;
case 11:
if (optlen != 4) {
return 0;
}
g_opt.sregunicode = *static_cast<const int32_t*>(optval) != 0;
SErrSetLastError(0);
return 1;
case 12:
if (optlen != 4) {
return 0;
}
g_opt.opt24 = *static_cast<const int32_t*>(optval) != 0;
SErrSetLastError(0);
return 1;
case 13:
if (optlen != 4) {
return 0;
}
g_opt.opt28 = *static_cast<const int32_t*>(optval) != 0;
SErrSetLastError(0);
return 1;
default:
return 0;
}
}
int32_t StormGetOption(int32_t optname, void* optval, uint32_t* optlen) {
// TODO
return 0;
}

10
storm/option/Option.hpp Normal file
View file

@ -0,0 +1,10 @@
#ifndef STORM_OPTION_OPTION_HPP
#define STORM_OPTION_OPTION_HPP
#include <cstdint>
int32_t StormSetOption(int32_t optname, const void* optval, uint32_t optlen);
int32_t StormGetOption(int32_t optname, void* optval, uint32_t* optlen);
#endif

6
storm/option/Options.cpp Normal file
View file

@ -0,0 +1,6 @@
#include "storm/option/Options.hpp"
STORMOPTIONS g_opt;
uint32_t s_alloccount;
uint32_t s_freecount;

25
storm/option/Options.hpp Normal file
View file

@ -0,0 +1,25 @@
#ifndef STORM_OPTION_OPTIONS_HPP
#define STORM_OPTION_OPTIONS_HPP
#include <cstdint>
struct STORMOPTIONS {
int32_t smemleaksilentwarning;
int32_t serrleaksilentwarning;
uint32_t wavechunksize;
int32_t opt0C;
int32_t opt10;
int32_t opt14;
int32_t opt18;
int32_t opt1C;
int32_t sregunicode;
int32_t opt24;
int32_t opt28;
};
extern STORMOPTIONS g_opt;
extern uint32_t s_alloccount;
extern uint32_t s_freecount;
#endif