15 #include "win32ArgParser.h" 19 #include "memoryBase.h" 20 #include "textEncoder.h" 21 #include "globPattern.h" 23 #include "executionEnvironment.h" 58 assert(_argc == (
int)_args.size());
61 for (
int i = 0; i < _argc; ++i) {
62 PANDA_FREE_ARRAY(_argv[i]);
64 PANDA_FREE_ARRAY(_argv);
79 set_command_line(
const string &command_line) {
82 const char *p = command_line.c_str();
84 parse_unquoted_arg(p);
87 while (*p !=
'\0' && isspace(*p)) {
92 assert(_argc == 0 && _argv == NULL);
93 _argc = (int)_args.size();
94 _argv = (
char **)PANDA_MALLOC_ARRAY(_argc *
sizeof(
char *));
95 for (
int i = 0; i < _argc; ++i) {
96 const string &arg = _args[i];
97 char *astr = (
char *)PANDA_MALLOC_ARRAY(arg.size() + 1);
98 memcpy(astr, arg.data(), arg.size());
99 astr[arg.size()] =
'\0';
111 void Win32ArgParser::
112 set_command_line(
const wstring &command_line) {
116 set_command_line(encoder.
get_text());
126 void Win32ArgParser::
127 set_system_command_line() {
128 LPWSTR command_line = GetCommandLineW();
129 set_command_line(command_line);
142 char **Win32ArgParser::
165 bool Win32ArgParser::
171 if (!envvar.empty()) {
191 HANDLE toolhelp = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
193 PROCESSENTRY32 entry;
194 memset(&entry, 0,
sizeof(entry));
195 entry.dwSize =
sizeof(entry);
197 DWORD current_id = GetCurrentProcessId();
198 DWORD parent_id = -1;
200 if (Process32First(toolhelp, &entry)) {
202 if (entry.th32ProcessID == current_id) {
203 parent_id = entry.th32ParentProcessID;
206 }
while (Process32Next(toolhelp, &entry));
210 if (parent_id != -1) {
213 if (Process32First(toolhelp, &entry)) {
215 if (entry.th32ProcessID == parent_id) {
219 }
while (Process32Next(toolhelp, &entry));
223 CloseHandle(toolhelp);
225 if (basename ==
"cmd.exe") {
239 string Win32ArgParser::
240 parse_quoted_arg(
const char *&p) {
245 while (*p !=
'\0' && *p != quote) {
261 for (
int i = 0; i < num_slashes; i += 2) {
266 if ((num_slashes & 1) == 0) {
280 for (
int i = 0; i < num_slashes; ++i) {
307 void Win32ArgParser::
308 parse_unquoted_arg(
const char *&p) {
310 bool contains_quotes =
false;
311 while (*p !=
'\0' && !isspace(*p)) {
314 contains_quotes =
true;
315 result += parse_quoted_arg(p);
325 if (!contains_quotes && glob.has_glob_characters()) {
329 vector_string expand;
330 if (glob.match_files(expand) != 0) {
332 vector_string::const_iterator ei;
333 for (ei = expand.begin(); ei != expand.end(); ++ei) {
357 void Win32ArgParser::
358 save_arg(
const string &arg) {
359 _args.push_back(arg);
string get_basename() const
Returns the basename part of the filename.
This class can be used to convert text between multiple representations, e.g.
static TextEncoder::Encoding get_filesystem_encoding()
Specifies the default encoding to be used for all subsequent Filenames objects.
The name of a file, such as a texture file or an Egg file.
static string get_environment_variable(const string &var)
Returns the definition of the indicated environment variable, or the empty string if the variable is ...
void set_encoding(Encoding encoding)
Specifies how the string set via set_text() is to be interpreted.
void set_wtext(const wstring &wtext)
Changes the text that is stored in the encoder.
string to_os_specific() const
Converts the filename from our generic Unix-like convention (forward slashes starting with the root a...
This class can be used to test for string matches against standard Unix-shell filename globbing conve...
string get_text() const
Returns the current text, as encoded via the current encoding system.
static Filename from_os_specific(const string &os_specific, Type type=T_general)
This named constructor returns a Panda-style filename (that is, using forward slashes, and no drive letter) based on the supplied filename string that describes a filename in the local system conventions (for instance, on Windows, it may use backslashes or begin with a drive letter and a colon).