diff --git a/paw/stos/ex/cmdline.c b/paw/stos/ex/cmdline.c new file mode 100644 index 0000000..f241e06 --- /dev/null +++ b/paw/stos/ex/cmdline.c @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2026, Chloe M. + * Provided under the BSD-3 clause. + * + * Description: Command line parser + * Author: Chloe M. + */ + +#include +#include +#include +#include + +#define KEY_BOOTCONS "bootcons" +#define VALUE_TRUE "true" +#define VALUE_FALSE "false" + +#include + +/* + * Enable or disable the boot console + * + * @CmdValue: Command value + */ +static VOID +CmdSetBootCons(CHAR *CmdValue) +{ + if (CmdValue == NULL) { + return; + } + + if (RtlMemCmp(CmdValue, VALUE_TRUE, sizeof(VALUE_TRUE)) == 0) { + BootVidInitCons(NULL); + } +} + +/* + * TODO: Handle ';' seperator + */ +VOID +CmdLineParse(const CHAR *CmdLine) +{ + CHAR KeyBuf[128]; + CHAR ValBuf[128]; + USHORT KeyBufLen = 0; + USHORT ValBufLen = 0; + BOOLEAN ParseVal = false; + const CHAR *Head; + + if (CmdLine == NULL) { + return; + } + + Head = CmdLine; + while (*Head != '\0') { + if (*Head == '=') { + ParseVal = true; + ++Head; + continue; + } + + if (!ParseVal && KeyBufLen < sizeof(KeyBuf) - 1) { + KeyBuf[KeyBufLen++] = *Head++; + continue; + } + + if (ParseVal && ValBufLen < sizeof(ValBuf) - 1) { + ValBuf[ValBufLen++] = *Head++; + continue; + } + + /* Handle overflows */ + if (!ParseVal && KeyBufLen >= sizeof(KeyBuf) - 1) + return; + if (ParseVal && ValBufLen >= sizeof(ValBuf) - 1) + return; + + ++Head; + } + + KeyBuf[KeyBufLen] = '\0'; + ValBuf[ValBufLen] = '\0'; + + switch (KeyBuf[0]) { + case 'b': + if (RtlMemCmp(KeyBuf, KEY_BOOTCONS, sizeof(KEY_BOOTCONS)) == 0) { + CmdSetBootCons(ValBuf); + } + + break; + } +} + +VOID +ExCmdLineInit(VOID) +{ + BPAL_HANDLE BpalHandle; + + KeBpalGetHandle(&BpalHandle); + CmdLineParse(BpalHandle.CommandLine); +} diff --git a/paw/stos/head/ex/cmdline.h b/paw/stos/head/ex/cmdline.h new file mode 100644 index 0000000..4305a54 --- /dev/null +++ b/paw/stos/head/ex/cmdline.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2026, Chloe M. + * Provided under the BSD-3 clause. + * + * Description: Command line + * Author: Chloe M. + */ + +#ifndef _EX_CMDLINE_H_ +#define _EX_CMDLINE_H_ 1 + +#include + +/* + * Initialize the command line parser + */ +VOID ExCmdLineInit(VOID); + +#endif /* !_EX_CMDLINE_H_ */