From c392c0d799d763edee18a452c189c48376a4f33f Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 26 Apr 2019 00:57:37 +0200 Subject: Userland: Add a simple /bin/tr program. --- Userland/tr.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Userland/tr.cpp diff --git a/Userland/tr.cpp b/Userland/tr.cpp new file mode 100644 index 0000000000..c9be4b0f3a --- /dev/null +++ b/Userland/tr.cpp @@ -0,0 +1,28 @@ +#include +#include +#include +#include +#include + +int main(int argc, char** argv) +{ + if (argc != 3) { + printf("usage: tr "); + return 0; + } + + char from = argv[1][0]; + char to = argv[2][0]; + + for (;;) { + char ch = fgetc(stdin); + if (feof(stdin)) + break; + if (ch == from) + putchar(to); + else + putchar(ch); + } + + return 0; +} -- cgit v1.2.3