| 1 | // Licensed to the .NET Foundation under one or more agreements. |
| 2 | // The .NET Foundation licenses this file to you under the MIT license. |
| 3 | // See the LICENSE file in the project root for more information. |
| 4 | |
| 5 | #ifndef __CONSOLEARGS_H__ |
| 6 | #define __CONSOLEARGS_H__ |
| 7 | |
| 8 | #include "list.h" |
| 9 | #include "tree.h" |
| 10 | #include <strsafe.h> |
| 11 | |
| 12 | #include "palclr.h" |
| 13 | |
| 14 | typedef tree<LPCWSTR> b_tree; |
| 15 | typedef list<WCHAR*> WStrList; |
| 16 | |
| 17 | const LPCWSTR kOutOfMemory = W("Out of memory" ); |
| 18 | |
| 19 | class ConsoleArgs |
| 20 | { |
| 21 | public: |
| 22 | // Place the fully-qualified filename in the given output buffer |
| 23 | bool GetFullFileName(LPCWSTR szSource, __out_ecount(cbFilenameBuffer) LPWSTR filenameBuffer, DWORD cbFilenameBuffer, bool fOutputFilename); |
| 24 | |
| 25 | ConsoleArgs() : |
| 26 | m_rgArgs(NULL), |
| 27 | m_listArgs(NULL), |
| 28 | m_errorOccurred(false), |
| 29 | m_lastErrorMessage(nullptr) |
| 30 | { |
| 31 | }; |
| 32 | |
| 33 | ~ConsoleArgs() |
| 34 | { |
| 35 | CleanUpArgs(); |
| 36 | }; |
| 37 | |
| 38 | // returns false if there are errors |
| 39 | bool ExpandResponseFiles(__in int argc, __deref_in_ecount(argc) const LPCWSTR * argv, int * pargc2, __deref_out_ecount(*pargc2) LPWSTR ** pppargv2); |
| 40 | |
| 41 | // Frees all memory used by the arg list and the argv/argc array |
| 42 | void CleanUpArgs(); |
| 43 | |
| 44 | LPCWSTR ErrorMessage() |
| 45 | { |
| 46 | if (m_errorOccurred) |
| 47 | { |
| 48 | return m_lastErrorMessage; |
| 49 | } |
| 50 | else |
| 51 | { |
| 52 | return nullptr; |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | private: |
| 57 | void SetErrorMessage(__in LPCWSTR pwzMessage); |
| 58 | b_tree * MakeLeaf( LPCWSTR szText); |
| 59 | void CleanupTree( b_tree * root); |
| 60 | HRESULT TreeAdd( b_tree ** root, LPCWSTR szAdd); |
| 61 | void TextToArgs( LPCWSTR szText, WStrList ** listReplace); |
| 62 | bool ReadTextFile(LPCWSTR pwzFilename, __deref_out LPWSTR *ppwzTextBuffer); |
| 63 | void ProcessResponseArgs(); |
| 64 | |
| 65 | LPWSTR * m_rgArgs; |
| 66 | WStrList * m_listArgs; |
| 67 | |
| 68 | bool m_errorOccurred; |
| 69 | LPCWSTR m_lastErrorMessage; |
| 70 | }; |
| 71 | |
| 72 | #endif // __CONSOLEARGS_H__ |
| 73 | |