------------------------------------------------------------------------------ Find in command tail, failing that find in environment, failing that return a default. Up to caller to delete the string returned.
| 57 | // failing that return a default. |
| 58 | // Up to caller to delete the string returned. |
| 59 | static string vtkTestingGetArgOrEnvOrDefault( |
| 60 | const string& argName, // argument idnetifier flag. eg "-D" |
| 61 | vector<string>& argv, // command tail |
| 62 | const string& env, // environment variable name to find |
| 63 | const string& def) // default to use if "env" is not found. |
| 64 | { |
| 65 | string argValue; |
| 66 | |
| 67 | // Search command tail. |
| 68 | int argc = static_cast<int>(argv.size()); |
| 69 | for (int i = 0; i < argc; i++) |
| 70 | { |
| 71 | if ((i < (argc - 1)) && (argName == argv[i])) |
| 72 | { |
| 73 | argValue = argv[i + 1]; |
| 74 | } |
| 75 | } |
| 76 | // If not found search environment. |
| 77 | if (argValue.empty() && !(env.empty() || def.empty())) |
| 78 | { |
| 79 | char* foundenv = getenv(env.c_str()); |
| 80 | if (foundenv) |
| 81 | { |
| 82 | argValue = foundenv; |
| 83 | } |
| 84 | else |
| 85 | { |
| 86 | // Not found, fall back to default. |
| 87 | argValue = def; |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | return argValue; |
| 92 | } |
| 93 | |
| 94 | //------------------------------------------------------------------------------ |
| 95 | // Description: |
no test coverage detected