53 assert(_argc == (
int)_args.size());
55 if (_argv !=
nullptr) {
56 for (
int i = 0; i < _argc; ++i) {
57 PANDA_FREE_ARRAY(_argv[i]);
59 PANDA_FREE_ARRAY(_argv);
72set_command_line(
const string &command_line) {
75 const char *p = command_line.c_str();
77 parse_unquoted_arg(p);
80 while (*p !=
'\0' && isspace(*p)) {
85 assert(_argc == 0 && _argv ==
nullptr);
86 _argc = (int)_args.size();
87 _argv = (
char **)PANDA_MALLOC_ARRAY(_argc *
sizeof(
char *));
88 for (
int i = 0; i < _argc; ++i) {
89 const string &arg = _args[i];
90 char *astr = (
char *)PANDA_MALLOC_ARRAY(arg.size() + 1);
91 memcpy(astr, arg.data(), arg.size());
92 astr[arg.size()] =
'\0';
102set_command_line(
const std::wstring &command_line) {
104 encoder.
set_encoding(Filename::get_filesystem_encoding());
106 set_command_line(encoder.
get_text());
114set_system_command_line() {
115 LPWSTR command_line = GetCommandLineW();
116 set_command_line(command_line);
126char **Win32ArgParser::
150 if (!envvar.empty()) {
151 std::istringstream strm(envvar);
169 HANDLE toolhelp = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
171 PROCESSENTRY32 entry;
172 memset(&entry, 0,
sizeof(entry));
173 entry.dwSize =
sizeof(entry);
175 DWORD current_id = GetCurrentProcessId();
176 DWORD parent_id = -1;
178 if (Process32First(toolhelp, &entry)) {
180 if (entry.th32ProcessID == current_id) {
181 parent_id = entry.th32ParentProcessID;
184 }
while (Process32Next(toolhelp, &entry));
188 if (parent_id != -1) {
191 if (Process32First(toolhelp, &entry)) {
193 if (entry.th32ProcessID == parent_id) {
197 }
while (Process32Next(toolhelp, &entry));
201 CloseHandle(toolhelp);
203 if (basename ==
"cmd.exe") {
214string Win32ArgParser::
215parse_quoted_arg(
const char *&p) {
220 while (*p !=
'\0' && *p != quote) {
235 for (
int i = 0; i < num_slashes; i += 2) {
240 if ((num_slashes & 1) == 0) {
252 for (
int i = 0; i < num_slashes; ++i) {
276parse_unquoted_arg(
const char *&p) {
278 bool contains_quotes =
false;
279 while (*p !=
'\0' && !isspace(*p)) {
282 contains_quotes =
true;
283 result += parse_quoted_arg(p);
293 if (!contains_quotes && glob.has_glob_characters()) {
297 vector_string expand;
298 if (glob.match_files(expand) != 0) {
300 vector_string::const_iterator ei;
301 for (ei = expand.begin(); ei != expand.end(); ++ei) {
323save_arg(
const string &arg) {
324 _args.push_back(arg);
get_environment_variable
Returns the definition of the indicated environment variable, or the empty string if the variable is ...
The name of a file, such as a texture file or an Egg file.
std::string get_basename() const
Returns the basename part of the filename.
std::string to_os_specific() const
Converts the filename from our generic Unix-like convention (forward slashes starting with the root a...
static Filename from_os_specific(const std::string &os_specific, Type type=T_general)
This named constructor returns a Panda-style filename (that is, using forward slashes,...
This class can be used to test for string matches against standard Unix- shell filename globbing conv...
This class can be used to convert text between multiple representations, e.g.
void set_encoding(Encoding encoding)
Specifies how the string set via set_text() is to be interpreted.
get_text
Returns the current text, as encoded via the current encoding system.
void set_wtext(const std::wstring &wtext)
Changes the text that is stored in the encoder.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.