1 | // |
2 | // TestApp.cpp |
3 | // |
4 | // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. |
5 | // and Contributors. |
6 | // |
7 | // SPDX-License-Identifier: BSL-1.0 |
8 | // |
9 | |
10 | |
11 | #if defined(_WIN32) |
12 | #define _CRT_SECURE_NO_DEPRECATE |
13 | #endif |
14 | |
15 | |
16 | #include <string> |
17 | #include <iostream> |
18 | #include <cstdlib> |
19 | #include <csignal> |
20 | |
21 | |
22 | int main(int argc, char** argv) |
23 | { |
24 | if (argc > 1) |
25 | { |
26 | std::string arg(argv[1]); |
27 | if (arg == "-hello" ) |
28 | { |
29 | std::cout << "Hello, world!" ; |
30 | } |
31 | else if (arg == "-count" ) |
32 | { |
33 | int n = 0; |
34 | int c = std::cin.get(); |
35 | while (c != -1) { ++n; c = std::cin.get(); } |
36 | return n; |
37 | } |
38 | else if (arg == "-env" ) |
39 | { |
40 | const char* s = std::getenv("TESTENV" ); |
41 | if (s) |
42 | { |
43 | std::cout << s; |
44 | return 0; |
45 | } |
46 | else return 1; |
47 | } |
48 | else if (arg == "-raise-int" ) |
49 | { |
50 | std::signal(SIGINT, SIG_DFL); |
51 | std::raise(SIGINT); |
52 | } |
53 | else if (arg == "-echo-args" ) |
54 | { |
55 | for (int i = 2; i < argc; ++i) |
56 | { |
57 | std::cout << argv[i] << std::endl; |
58 | } |
59 | } |
60 | } |
61 | return argc - 1; |
62 | } |
63 | |