72 lines
1.7 KiB
C
72 lines
1.7 KiB
C
/// Kernel command line code, extremely slow, extremely unsafe, extremely painful
|
|
|
|
#include <lcrash/cmdline.h>
|
|
|
|
#include <lcrash/types.h>
|
|
|
|
#define POOL_SIZE 0x800
|
|
#define SLOT_COUNT 0x40
|
|
|
|
c8 CmdlineMemoryPool[POOL_SIZE] = {};
|
|
c8* CmdlineKeys[SLOT_COUNT] = {};
|
|
c8* CmdlineValues[SLOT_COUNT] = {};
|
|
u32 CmdlineEntryCount = 0;
|
|
|
|
void CmdlineParse(const c8* CommandLine) {
|
|
enum PARSE_STATE { PSWS, PSKey, PSValue };
|
|
|
|
int PoolPosition = 0;
|
|
int SlotPosition = 0;
|
|
c8* KeyStart = 0;
|
|
c8* ValueStart = 0;
|
|
enum PARSE_STATE State = PSWS;
|
|
|
|
for (int i = 0; CommandLine[i] != 0; i++) {
|
|
switch (State) {
|
|
case PSWS: {
|
|
if (!(CommandLine[i] == '\n'
|
|
||CommandLine[i] == '\r'
|
|
||CommandLine[i] == ' ')) {
|
|
State = PSKey;
|
|
KeyStart = CmdlineMemoryPool + PoolPosition;
|
|
} else continue;
|
|
}
|
|
case PSKey: {
|
|
if (CommandLine[i] == '=') {
|
|
State = PSValue;
|
|
CmdlineKeys[SlotPosition] = KeyStart;
|
|
CmdlineMemoryPool[PoolPosition++] = 0;
|
|
ValueStart = CmdlineMemoryPool + PoolPosition;
|
|
continue;
|
|
} else CmdlineMemoryPool[PoolPosition++] = CommandLine[i];
|
|
continue;
|
|
}
|
|
case PSValue: {
|
|
if (CommandLine[i] == '\n'
|
|
||CommandLine[i] == '\r'
|
|
||CommandLine[i] == ' ') {
|
|
State = PSWS;
|
|
CmdlineValues[SlotPosition++] = ValueStart;
|
|
CmdlineMemoryPool[PoolPosition++] = 0;
|
|
} else CmdlineMemoryPool[PoolPosition++] = CommandLine[i];
|
|
}
|
|
}
|
|
}
|
|
|
|
if (State == PSValue) CmdlineValues[SlotPosition++] = ValueStart;
|
|
|
|
CmdlineEntryCount = SlotPosition;
|
|
}
|
|
|
|
const c8* CmdlineGet(const c8* Param) {
|
|
for (int i = 0; i < CmdlineEntryCount; i++) {
|
|
for (int j = 0; Param[j - 1] != 0; j++) {
|
|
if (CmdlineKeys[i][j] != Param[j]) goto next;
|
|
}
|
|
|
|
return CmdlineValues[i];
|
|
next: }
|
|
|
|
return 0;
|
|
}
|