Userspace: Start work on shell
This commit is contained in:
@@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.26)
|
||||
project(userspace CXX)
|
||||
|
||||
set(USERSPACE_PROJECTS
|
||||
Shell
|
||||
cat
|
||||
test
|
||||
yes
|
||||
|
||||
18
userspace/Shell/CMakeLists.txt
Normal file
18
userspace/Shell/CMakeLists.txt
Normal file
@@ -0,0 +1,18 @@
|
||||
cmake_minimum_required(VERSION 3.26)
|
||||
|
||||
project(Shell CXX)
|
||||
|
||||
set(SOURCES
|
||||
main.cpp
|
||||
)
|
||||
|
||||
add_executable(Shell ${SOURCES})
|
||||
target_compile_options(Shell PUBLIC -O2 -g)
|
||||
add_dependencies(Shell libc-install)
|
||||
target_link_options(Shell PUBLIC -nodefaultlibs)
|
||||
target_link_libraries(Shell PUBLIC ${BANAN_LIB}/libc.a)
|
||||
|
||||
add_custom_target(Shell-install
|
||||
COMMAND cp ${CMAKE_CURRENT_BINARY_DIR}/Shell ${BANAN_BIN}/
|
||||
DEPENDS Shell
|
||||
)
|
||||
27
userspace/Shell/main.cpp
Normal file
27
userspace/Shell/main.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
#include <stdio.h>
|
||||
#include <termios.h>
|
||||
|
||||
struct termios old_termios, new_termios;
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
for (int i = 0; i < argc; i++)
|
||||
printf("%s\n", argv[i]);
|
||||
|
||||
tcgetattr(0, &old_termios);
|
||||
|
||||
new_termios = old_termios;
|
||||
new_termios.c_lflag &= ~(ECHO | ICANON);
|
||||
tcsetattr(0, TCSANOW, &new_termios);
|
||||
|
||||
while (true)
|
||||
{
|
||||
char c;
|
||||
fread(&c, 1, sizeof(char), stdin);
|
||||
fputc(c, stdout);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
tcsetattr(0, TCSANOW, &old_termios);
|
||||
return 0;
|
||||
}
|
||||
@@ -21,10 +21,6 @@ int main(int argc, char** argv)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
printf("argc %d, argv %p\n", argc, argv);
|
||||
for (int i = 0; i < argc; i++)
|
||||
printf("%s\n", argv[i]);
|
||||
|
||||
if (argc > 1)
|
||||
{
|
||||
for (int i = 1; i < argc; i++)
|
||||
|
||||
Reference in New Issue
Block a user