summaryrefslogtreecommitdiff
path: root/Source/Applications/Shell/Applets/cat.cpp
blob: 169226e5d3c1e0dc2736e5b5a89d3022e2fe80c1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <App/StreamApp.proto.h>

class rot13 : public StreamApp {
	public:
	rot13() : StreamApp("cat", "Concatenate some input files") {
		addFlag("r", "rot13", "Apply a ROT13 encryption to the output", FT_BOOL, "");
	}
	int run();
};

APP(rot13);

int rot13::run() {
	while (!in->eof()) {
		String s = in->get();
		if (in->eof() && s.empty()) break;
		if (bFlag("rot13")) {
			for (u32int i = 0; i < s.size(); i++) {
				WChar &c = s[i];
				if (c >= WChar('A') and c <= WChar('Z')) {
					c += 13;
					if (c > WChar('Z')) c -= 26;
				}
				if (c >= WChar('a') and c <= WChar('z')) {
					c += 13;
					if (c > WChar('z')) c -= 26;
				}
			}
		}
		*out << s << ENDL;
	}
	return 0;
}