Annotation of solidite/utils/echo.cpp, revision 1.1.1.1
1.1 user 1: /* Copyright (c) 2026 The Solidite Developers
2: *
3: * This program is free software: you can redistribute it and/or modify it under
4: * the terms of the GNU Affero General Public License as published by the Free
5: * Software Foundation, either version 3 of the License, or (at your option)
6: * any later version.
7: *
8: * This program is distributed in the hope that it will be useful, but WITHOUT
9: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10: * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
11: * details.
12: *
13: * You should have received a copy of the GNU Affero General Public License
14: * along with this program. If not, see <https://www.gnu.org/licenses/>. */
15:
16:
17: #include <iostream>
18: #include <string>
19:
20: #include <cstdint>
21:
22: int main(int argc, char* argv[]) {
23: std::string to_stdout;
24: for (int i = 1; i < argc; ++i) {
25: if (i != argc - 1) {
26: to_stdout += std::string(argv[i]) + ' ';
27: continue;
28: }
29: to_stdout += std::string(argv[i]) + '\n';
30: }
31:
32: char escape;
33: for (size_t i = 0; i < to_stdout.length(); ++i) {
34: if (to_stdout[i] == '\\') {
35: escape = to_stdout[i+1];
36: // get the escape character before erasal
37: to_stdout.erase(i, 2);
38: switch (escape) {
39: case 'a':
40: to_stdout.insert(i, "\a");
41: break;
42: case 'b':
43: to_stdout.insert(i, "\b");
44: break;
45: case 'c':
46: to_stdout.erase(to_stdout.length() - 1, 1);
47: break;
48: case 'n':
49: to_stdout.insert(i, "\n");
50: break;
51: case 'r':
52: to_stdout.insert(i, "\r");
53: break;
54: case 't':
55: to_stdout.insert(i, "\t");
56: break;
57: case 'v':
58: to_stdout.insert(i, "\v");
59: break;
60: case '\\':
61: to_stdout.insert(i, "\\");
62: break;
63: default:
64: if (i == to_stdout.length())
65: to_stdout.insert(i, "\\\n");
66: break;
67: }
68: }
69: }
70:
71: std::cout << to_stdout;
72: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>