home *** CD-ROM | disk | FTP | other *** search
-
- #include "stdafx.h"
-
- #include "dshell.h"
-
- #ifdef _INTERNAL_DEBUG_SUPPORT_
- #include "__file__.ver"
- #else
- #include "__file__.h"
- #endif
- #include "corver.h"
-
- int _cdecl wmain(int argc, WCHAR *argv[])
- {
- DebuggerShell *shell;
-
- // Ensure that cordbg will work with remote. Remote doesn't like
- // buffered output, so we remove the default buffer from stdout
- // with this call.
- setbuf(stdout, NULL);
-
- shell = new DebuggerShell(stdin, stdout);
-
- if (shell == NULL)
- {
- fprintf(stderr, "Initialization failed. Reason: out of memory.\n");
- return (-1);
- }
-
- #ifdef _INTERNAL_DEBUG_SUPPORT_
- shell->Write(L"%s. Version %s", VER_FILEDESCRIPTION_WSTR, VER_FILEVERSION_WSTR);
- #else
- shell->Write(L"%s. ", VER_FILEDESCRIPTION_WSTR);
- #endif
-
- shell->Write(L"\n%s\n\n", VER_LEGALCOPYRIGHT_DOS_STR);
-
- if ((argc > 1) && ((argv[1][0] == '/' || argv[1][0] == '-') && argv[1][1] == '?'))
- {
- shell->Write(L"Usage: CORDBG [<program name> [<program args>]] [<CorDbg optional args>]\n");
-
- delete shell;
- return (0);
- }
-
- HRESULT hr = shell->Init();
-
- if (SUCCEEDED(hr))
- {
- //
- // Process command line arguments
- //
- if (argc > 1)
- {
- int cmdLen = 1; // Start at one to handle the null char
-
- if (argv[1][0] != '!')
- {
- cmdLen += 5; // Implied "!run " command
- }
-
- for (int i = 1; i < argc; i++)
- {
- cmdLen += wcslen(argv[i]) + 1; // Add one to handle space between args
- }
-
- // Allocate the string on the stack
- WCHAR *command = (WCHAR *) _alloca(cmdLen * sizeof(WCHAR));
- command[0] = L'\0';
-
- if (argv[1][0] != L'!')
- {
- wcscpy(command, L"!run "); // Implied "!run " command
- }
-
- for (WCHAR **arg = &(argv[1]), **end = &(argv[0]) + argc; arg < end; arg++)
- {
- wcscat(command, *arg);
- if (arg + 1 != end)
- {
- wcscat(command, L" ");
- }
- }
-
- //
- // Go through the command line and execute the various commands
- //
- for (WCHAR *cmd = NULL, *ptr = command; *ptr != L'\0'; ptr++)
- {
- if (*ptr == L'!' || *(ptr + 1) == L'\0')
- {
- // Overwrite '!' with null char to terminate current command
- if (*ptr == L'!')
- {
- *ptr = L'\0';
-
- // Get rid of trailing spaces on commands
- if (ptr > command)
- {
- *(ptr-1) = L'\0';
- }
- }
-
- // If we've reached the end of a command, execute it
- if (cmd != NULL)
- {
- shell->Write(shell->GetPrompt());
- shell->Write(L" %s\n", cmd);
- shell->DoCommand(cmd);
- }
-
- // Save the beginning of the next command
- cmd = ptr + 1;
- }
- }
- }
-
- // Read commands from the user prompt
- while (!shell->m_quit)
- shell->ReadCommand();
- }
- else
- {
- shell->Write(L"Initialization failed. Reason: ");
- shell->ReportError(hr);
- }
-
- delete shell;
-
- return (0);
- }
-