Browse Source

Userland: Add a simple /bin/tr program.

Andreas Kling 6 years ago
parent
commit
c392c0d799
1 changed files with 28 additions and 0 deletions
  1. 28 0
      Userland/tr.cpp

+ 28 - 0
Userland/tr.cpp

@@ -0,0 +1,28 @@
+#include <AK/QuickSort.h>
+#include <AK/Vector.h>
+#include <AK/AKString.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+int main(int argc, char** argv)
+{
+    if (argc != 3) {
+        printf("usage: tr <from> <to>");
+        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;
+}