diff --git a/userspace/CMakeLists.txt b/userspace/CMakeLists.txt index e08c40b421..65ee48c678 100644 --- a/userspace/CMakeLists.txt +++ b/userspace/CMakeLists.txt @@ -5,6 +5,7 @@ project(userspace CXX) set(USERSPACE_PROJECTS Shell cat + echo test yes ) diff --git a/userspace/echo/CMakeLists.txt b/userspace/echo/CMakeLists.txt new file mode 100644 index 0000000000..fd01c8a662 --- /dev/null +++ b/userspace/echo/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.26) + +project(echo CXX) + +set(SOURCES + main.cpp +) + +add_executable(echo ${SOURCES}) +target_compile_options(echo PUBLIC -O2 -g) +target_link_libraries(echo PUBLIC libc) + +add_custom_target(echo-install + COMMAND cp ${CMAKE_CURRENT_BINARY_DIR}/echo ${BANAN_BIN}/ + DEPENDS echo +) diff --git a/userspace/echo/main.cpp b/userspace/echo/main.cpp new file mode 100644 index 0000000000..14aa424d55 --- /dev/null +++ b/userspace/echo/main.cpp @@ -0,0 +1,40 @@ +#include +#include + +void print_argument(const char* arg) +{ + while (*arg) + { + if (*arg == '\\') + { + switch (*(++arg)) + { + case 'a': fputc('\a', stdout); break; + case 'b': fputc('\b', stdout); break; + case 'c': exit(0); + case 'f': fputc('\f', stdout); break; + case 'n': fputc('\n', stdout); break; + case 'r': fputc('\r', stdout); break; + case 't': fputc('\t', stdout); break; + case 'v': fputc('\v', stdout); break; + case '\\': fputc('\\', stdout); break; + default: break; + } + } + else + fputc(*arg, stdout); + arg++; + } +} + +int main(int argc, char** argv) +{ + for (int i = 1; i < argc; i++) + { + print_argument(argv[i]); + if (i < argc - 1) + fputc(' ', stdout); + } + printf("\n"); + return 1; +}