Split date out of shell

This commit is contained in:
Ali Mashtizadeh 2022-12-10 01:01:38 -05:00
parent dfff32378c
commit 19b1bf216f
5 changed files with 37 additions and 40 deletions

View File

@ -174,6 +174,7 @@ SConscript('sys/SConscript', variant_dir='build/sys')
SConscript('lib/libc/SConscript', variant_dir='build/lib/libc')
#SConscript('lib/liblwip/SConscript', variant_dir='build/lib/liblwip')
SConscript('bin/cat/SConscript', variant_dir='build/bin/cat')
SConscript('bin/date/SConscript', variant_dir='build/bin/date')
SConscript('bin/ethdump/SConscript', variant_dir='build/bin/ethdump')
SConscript('bin/ethinject/SConscript', variant_dir='build/bin/ethinject')
SConscript('bin/ls/SConscript', variant_dir='build/bin/ls')
@ -201,6 +202,7 @@ if env["BOOTDISK"] == "1":
bootdisk = env.BuildImage('#build/bootdisk.img', '#release/bootdisk.manifest')
Depends(bootdisk, "#build/tools/newfs_o2fs/newfs_o2fs")
Depends(bootdisk, "#build/bin/cat/cat")
Depends(bootdisk, "#build/bin/date/date")
Depends(bootdisk, "#build/bin/ethdump/ethdump")
Depends(bootdisk, "#build/bin/ethinject/ethinject")
Depends(bootdisk, "#build/bin/ls/ls")

23
bin/date/SConscript Normal file
View File

@ -0,0 +1,23 @@
import sys
Import('env')
cross_env = env.Clone()
src = [ ]
src_common = [
"date.c"
]
src.append(env["CRTBEGIN"])
src.append(src_common)
src.append(env["CRTEND"])
cross_env.Append(LINKFLAGS = ['-nostdlib'])
cross_env.Append(CPPFLAGS = ['-fno-builtin', '-nostdinc'])
cross_env.Append(CPPPATH = ['#build/include'])
cross_env.Append(LIBPATH = ['#build/lib/libc'], LIBS = ['c'])
cross_env.Program("date", src)

11
bin/date/date.c Normal file
View File

@ -0,0 +1,11 @@
#include <stdio.h>
#include <time.h>
int
main(int argc, const char *argv[])
{
time_t t = time(NULL);
fputs(ctime(&t), stdout);
}

View File

@ -2,7 +2,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
// Castor Only
#include <syscall.h>
@ -33,11 +32,9 @@ void
Cmd_Help(int argc, const char *argv[])
{
printf("bkpt Trigger a kernel breakpoint\n");
printf("date Print current date and time\n");
printf("echo Echo arguments\n");
printf("exit Exit shell\n");
printf("help Display the list of commands\n");
printf("spawn Spawn a process\n");
}
void
@ -52,39 +49,6 @@ Cmd_Echo(int argc, const char *argv[])
printf("\n");
}
void
Cmd_Date(int argc, const char *argv[])
{
time_t t = time(NULL);
fputs(ctime(&t), stdout);
}
void
Cmd_Hexdump(int argc, const char *argv[])
{
}
void
Cmd_Spawn(int argc, const char *argv[])
{
uint64_t status;
if (argc != 2) {
fputs("Requires an argument\n", stdout);
return;
}
printf("%s\n", argv[1]);
status = OSSpawn(argv[1]);
if (SYSCALL_ERRCODE(status) != 0) {
printf("Spawn failed: %d\n", status);
return;
}
// XXX: check errors
status = OSWait(status);
printf("Process result: %d\n", status);
}
const char *searchpath[] = {
"",
"/sbin/",
@ -160,14 +124,10 @@ DispatchCommand(char *buf)
Cmd_Help(argc, (const char **)argv);
} else if (strcmp(argv[0], "bkpt") == 0) {
asm volatile("int3");
} else if (strcmp(argv[0], "date") == 0) {
Cmd_Date(argc, (const char **)argv);
} else if (strcmp(argv[0], "echo") == 0) {
Cmd_Echo(argc, (const char **)argv);
} else if (strcmp(argv[0], "exit") == 0) {
exit(0);
} else if (strcmp(argv[0], "spawn") == 0) {
Cmd_Spawn(argc, (const char **)argv);
} else if (strcmp(argv[0], "#") == 0) {
// Ignore comments
} else if (buf[0] == '\0') {

View File

@ -6,6 +6,7 @@ DIR /
END
DIR bin
FILE cat build/bin/cat/cat
FILE date build/bin/date/date
FILE ethdump build/bin/ethdump/ethdump
FILE ethinject build/bin/ethinject/ethinject
FILE ls build/bin/ls/ls