@@ -151,43 +151,84 @@ string16 QuoteForCommandLineToArgvW(const string16& arg,
151
151
152
152
CommandLine::CommandLine (NoProgram no_program)
153
153
: argv_(1 ),
154
- begin_args_ (1 ) {
154
+ begin_args_ (1 ),
155
+ argc0_(0 ), argv0_(NULL ) {
155
156
}
156
157
157
158
CommandLine::CommandLine (const FilePath& program)
158
159
: argv_(1 ),
159
- begin_args_(1 ) {
160
+ begin_args_(1 ),
161
+ argc0_(0 ), argv0_(NULL ) {
160
162
SetProgram (program);
161
163
}
162
164
163
165
CommandLine::CommandLine (int argc, const CommandLine::CharType* const * argv)
164
166
: argv_(1 ),
165
- begin_args_(1 ) {
167
+ begin_args_(1 ),
168
+ argc0_(0 ), argv0_(NULL ) {
166
169
InitFromArgv (argc, argv);
167
170
}
168
171
169
172
CommandLine::CommandLine (const StringVector& argv)
170
173
: argv_(1 ),
171
- begin_args_(1 ) {
174
+ begin_args_(1 ),
175
+ argc0_(0 ), argv0_(NULL ) {
172
176
InitFromArgv (argv);
173
177
}
174
178
175
179
CommandLine::CommandLine (const CommandLine& other)
176
180
: argv_(other.argv_),
181
+ original_argv_(other.original_argv_),
177
182
switches_(other.switches_),
178
- begin_args_(other.begin_args_) {
183
+ begin_args_(other.begin_args_),
184
+ argc0_(other.argc0_), argv0_(NULL ) {
185
+
186
+ #if defined(OS_WIN)
187
+ if (other.argv0_ ) {
188
+ argv0_ = new char *[argc0_ + 1 ];
189
+ for (int i = 0 ; i < argc0_; ++i) {
190
+ argv0_[i] = new char [strlen (other.argv0_ [i]) + 1 ];
191
+ strcpy (argv0_[i], other.argv0_ [i]);
192
+ }
193
+ argv0_[argc0_] = NULL ;
194
+ }
195
+ #else
196
+ argv0_ = other.argv0_ ;
197
+ #endif
179
198
ResetStringPieces ();
180
199
}
181
200
182
201
CommandLine& CommandLine::operator =(const CommandLine& other) {
183
202
argv_ = other.argv_ ;
203
+ original_argv_ = other.original_argv_ ;
184
204
switches_ = other.switches_ ;
185
205
begin_args_ = other.begin_args_ ;
206
+ #if defined(OS_WIN)
207
+ if (other.argv0_ ) {
208
+ argc0_ = other.argc0_ ;
209
+ argv0_ = new char *[argc0_ + 1 ];
210
+ for (int i = 0 ; i < argc0_; ++i) {
211
+ argv0_[i] = new char [strlen (other.argv0_ [i]) + 1 ];
212
+ strcpy (argv0_[i], other.argv0_ [i]);
213
+ }
214
+ argv0_[argc0_] = NULL ;
215
+ }
216
+ #else
217
+ argv0_ = other.argv0_ ;
218
+ #endif
186
219
ResetStringPieces ();
187
220
return *this ;
188
221
}
189
222
190
223
CommandLine::~CommandLine () {
224
+ #if defined(OS_WIN)
225
+ if (!argv0_)
226
+ return ;
227
+ for (int i = 0 ; i < argc0_; i++) {
228
+ delete[] argv0_[i];
229
+ }
230
+ delete[] argv0_;
231
+ #endif
191
232
}
192
233
193
234
#if defined(OS_WIN)
@@ -259,12 +300,34 @@ CommandLine CommandLine::FromString(const string16& command_line) {
259
300
void CommandLine::InitFromArgv (int argc,
260
301
const CommandLine::CharType* const * argv) {
261
302
StringVector new_argv;
303
+ argc0_ = argc;
304
+ #if !defined(OS_WIN)
305
+ argv0_ = (char **)argv;
306
+ #else
307
+ argv0_ = new char *[argc + 1 ];
308
+ for (int i = 0 ; i < argc; ++i) {
309
+ std::string str (base::WideToUTF8 (argv[i]));
310
+ argv0_[i] = new char [str.length () + 1 ];
311
+ strcpy (argv0_[i], str.c_str ());
312
+ }
313
+ argv0_[argc] = NULL ;
314
+ #endif
262
315
for (int i = 0 ; i < argc; ++i)
263
316
new_argv.push_back (argv[i]);
264
317
InitFromArgv (new_argv);
265
318
}
266
319
267
320
void CommandLine::InitFromArgv (const StringVector& argv) {
321
+ #if !defined(OS_MACOSX)
322
+ original_argv_ = argv;
323
+ #else
324
+ for (size_t index = 0 ; index < argv.size (); ++index ) {
325
+ if (argv[index ].compare (0 , strlen (" --psn_" ), " --psn_" ) != 0 &&
326
+ argv[index ].compare (0 , strlen (" -psn_" ), " -psn_" ) != 0 ) {
327
+ original_argv_.push_back (argv[index ]);
328
+ }
329
+ }
330
+ #endif
268
331
argv_ = StringVector (1 );
269
332
switches_.clear ();
270
333
switches_by_stringpiece_.clear ();
@@ -401,6 +464,12 @@ void CommandLine::AppendArgNative(const CommandLine::StringType& value) {
401
464
argv_.push_back (value);
402
465
}
403
466
467
+ #if defined(OS_MACOSX)
468
+ void CommandLine::FixOrigArgv4Finder (const CommandLine::StringType& value) {
469
+ original_argv_.push_back (value);
470
+ }
471
+ #endif
472
+
404
473
void CommandLine::AppendArguments (const CommandLine& other,
405
474
bool include_program) {
406
475
if (include_program)
0 commit comments