Parsing commandline arguments

This commit is contained in:
2025-09-13 15:43:31 +02:00
parent dc3d80d707
commit e6891b39cc
18 changed files with 448 additions and 59 deletions

View File

@ -1,60 +1,42 @@
#include <stdint.h>
#include <string/string.h>
#include <system/system.h>
#include <sysdefs/ioctl.h>
#include <sysdefs/ipcpipe.h>
#include <sysdefs/processctl.h>
#include <uprintf.h>
#include <ansiq/all.h>
#include <string/char.h>
void *string_memset2(void *p, int c, size_t n) {
char *cp = p;
for (size_t i = 0; i < n; i++) cp[i] = c;
return p;
}
void main(void) {
uprintf(ANSIQ_CUR_SET(0, 0));
uprintf(ANSIQ_SCR_CLR_ALL);
int32_t ioh = ioctl(IOCTL_NOHANDLE,
IOCTL_OPENF,
(uint64_t)"temp:/hello.txt",
IOCTL_F_WRITE | IOCTL_F_READ | IOCTL_F_MAKE,
0
);
char *text = "Hello from FS";
ioctl(ioh, IOCTL_WRITE, (uint64_t)text, string_len(text), 0);
char buf[0x100] = {0};
ioctl(ioh, IOCTL_READ, (uint64_t)buf, string_len(text), 0);
uprintf("file contents: %s\n", buf);
ioctl(ioh, IOCTL_CLOSEF, 0, 0, 0);
uprintf("Hello world using uprintf\n");
const char *tbargs[] = { "-i" };
int32_t tb = processctl(-1, PCTL_SPAWN, (uint64_t)"base:/bin/tb", (uint64_t)tbargs, 1);
char *tbargs[] = { "-m", "interactive" };
int32_t tb = processctl(-1, PCTL_SPAWN, (uint64_t)"base:/bin/tb", (uint64_t)&tbargs, 2);
uint64_t selfpid = (uint64_t)processctl(-1, PCTL_GETPID, 0, 0, 0);
ipcpipe(tb, IPCPIPE_OUT, IPCPIPE_REPLACE, (uint8_t *)selfpid, IPCPIPE_OUT);
processctl(tb, PCTL_RUN, 0, 0, 0);
while(processctl(tb, PCTL_POLLSTATE, 0, 0, 0) != 2);
if (ipcpipe(IPCPIPE_SELFPID, 10, IPCPIPE_MAKE, NULL, 0) < 0) {
uprintf("failed to create 10th pipe\n");
}
ipcpipe(IPCPIPE_SELFPID, 10, IPCPIPE_MAKE, NULL, 0);
ipcpipe(IPCPIPE_SELFPID, 10, IPCPIPE_ADD_BCAST, NULL, 1);
int32_t r = ipcpipe(IPCPIPE_SELFPID, 10, IPCPIPE_ADD_BCAST, NULL, 1);
uprintf("%d\n", r);
while(1) {
while(processctl(tb, PCTL_POLLSTATE, 0, 0, 0) != 2) {
int32_t kbchr;
int32_t read = ipcpipe(IPCPIPE_SELFPID, 10, IPCPIPE_READ, (uint8_t *)&kbchr, sizeof(kbchr));
if (read > 0) {
kbchr &= 0xFF;
if ((kbchr >= 0x20 && kbchr <= 0x7F) || kbchr == 0xA) {
uprintf("%c", kbchr & 0xFF);
uint8_t c = kbchr & 0xff;
if (string_chr_isascii(c)) {
if (c != 0) {
ipcpipe(tb, IPCPIPE_IN, IPCPIPE_WRITE, &c, 1);
}
if (string_chr_isprint(c)) {
uprintf("%c", c);
}
}
}
}
for(;;);
}