Johnny Chen | d5e111c | 2010-09-15 22:27:29 +0000 | [diff] [blame] | 1 | //===-- main.cpp ------------------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include <cstdlib> |
| 11 | #include <string> |
| 12 | #include <fstream> |
Johnny Chen | f7f6271 | 2010-09-15 22:48:40 +0000 | [diff] [blame] | 13 | #include <iostream> |
Johnny Chen | d5e111c | 2010-09-15 22:27:29 +0000 | [diff] [blame] | 14 | |
| 15 | int |
| 16 | main(int argc, char const *argv[]) |
| 17 | { |
Johnny Chen | d5e111c | 2010-09-15 22:27:29 +0000 | [diff] [blame] | 18 | // The program writes its output to the "output.txt" file. |
| 19 | std::ofstream outfile("output.txt"); |
| 20 | |
Johnny Chen | f7f6271 | 2010-09-15 22:48:40 +0000 | [diff] [blame] | 21 | for (unsigned i = 0; i < argc; ++i) { |
| 22 | std::string theArg(argv[i]); |
| 23 | if (i == 1 && "A" == theArg) |
Johnny Chen | d5e111c | 2010-09-15 22:27:29 +0000 | [diff] [blame] | 24 | outfile << "argv[1] matches\n"; |
| 25 | |
Johnny Chen | f7f6271 | 2010-09-15 22:48:40 +0000 | [diff] [blame] | 26 | if (i == 2 && "B" == theArg) |
Johnny Chen | d5e111c | 2010-09-15 22:27:29 +0000 | [diff] [blame] | 27 | outfile << "argv[2] matches\n"; |
| 28 | |
Johnny Chen | f7f6271 | 2010-09-15 22:48:40 +0000 | [diff] [blame] | 29 | if (i == 3 && "C" == theArg) |
Johnny Chen | d5e111c | 2010-09-15 22:27:29 +0000 | [diff] [blame] | 30 | outfile << "argv[3] matches\n"; |
| 31 | } |
| 32 | |
Johnny Chen | 80554b8 | 2010-12-04 00:44:56 +0000 | [diff] [blame^] | 33 | // For passing environment vars from the debugger to the launched process. |
Johnny Chen | d5e111c | 2010-09-15 22:27:29 +0000 | [diff] [blame] | 34 | if (::getenv("MY_ENV_VAR")) { |
| 35 | std::string MY_ENV_VAR(getenv("MY_ENV_VAR")); |
| 36 | if ("YES" == MY_ENV_VAR) { |
| 37 | outfile << "Environment variable 'MY_ENV_VAR' successfully passed.\n"; |
| 38 | } |
| 39 | } |
| 40 | |
Johnny Chen | 80554b8 | 2010-12-04 00:44:56 +0000 | [diff] [blame^] | 41 | |
| 42 | // For passing host environment vars to the launched process. |
| 43 | if (::getenv("MY_HOST_ENV_VAR1")) { |
| 44 | std::string MY_HOST_ENV_VAR1(getenv("MY_HOST_ENV_VAR1")); |
| 45 | if ("VAR1" == MY_HOST_ENV_VAR1) { |
| 46 | outfile << "The host environment variable 'MY_HOST_ENV_VAR1' successfully passed.\n"; |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | if (::getenv("MY_HOST_ENV_VAR2")) { |
| 51 | std::string MY_HOST_ENV_VAR2(getenv("MY_HOST_ENV_VAR2")); |
| 52 | if ("VAR2" == MY_HOST_ENV_VAR2) { |
| 53 | outfile << "The host environment variable 'MY_HOST_ENV_VAR2' successfully passed.\n"; |
| 54 | } |
| 55 | } |
| 56 | |
Johnny Chen | f7f6271 | 2010-09-15 22:48:40 +0000 | [diff] [blame] | 57 | std::cout << "This message should go to standard out.\n"; |
| 58 | |
Johnny Chen | d5e111c | 2010-09-15 22:27:29 +0000 | [diff] [blame] | 59 | return 0; |
| 60 | } |