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