@@ -151,43 +151,83 @@ 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
+ argv0_ = new char *[argc0_ + 1 ];
209
+ for (int i = 0 ; i < argc0_; ++i) {
210
+ argv0_[i] = new char [strlen (other.argv0_ [i]) + 1 ];
211
+ strcpy (argv0_[i], other.argv0_ [i]);
212
+ }
213
+ argv0_[argc0_] = NULL ;
214
+ }
215
+ #else
216
+ argv0_ = other.argv0_ ;
217
+ #endif
186
218
ResetStringPieces ();
187
219
return *this ;
188
220
}
189
221
190
222
CommandLine::~CommandLine () {
223
+ #if defined(OS_WIN)
224
+ if (!argv0_)
225
+ return ;
226
+ for (int i = 0 ; i < argc0_; i++) {
227
+ delete[] argv0_[i];
228
+ }
229
+ delete[] argv0_;
230
+ #endif
191
231
}
192
232
193
233
#if defined(OS_WIN)
@@ -248,12 +288,34 @@ CommandLine CommandLine::FromString(const string16& command_line) {
248
288
void CommandLine::InitFromArgv (int argc,
249
289
const CommandLine::CharType* const * argv) {
250
290
StringVector new_argv;
291
+ argc0_ = argc;
292
+ #if !defined(OS_WIN)
293
+ argv0_ = (char **)argv;
294
+ #else
295
+ argv0_ = new char *[argc + 1 ];
296
+ for (int i = 0 ; i < argc; ++i) {
297
+ std::string str (base::WideToUTF8 (argv[i]));
298
+ argv0_[i] = new char [str.length () + 1 ];
299
+ strcpy (argv0_[i], str.c_str ());
300
+ }
301
+ argv0_[argc] = NULL ;
302
+ #endif
251
303
for (int i = 0 ; i < argc; ++i)
252
304
new_argv.push_back (argv[i]);
253
305
InitFromArgv (new_argv);
254
306
}
255
307
256
308
void CommandLine::InitFromArgv (const StringVector& argv) {
309
+ #if !defined(OS_MACOSX)
310
+ original_argv_ = argv;
311
+ #else
312
+ for (size_t index = 0 ; index < argv.size (); ++index) {
313
+ if (argv[index].compare (0 , strlen (" --psn_" ), " --psn_" ) != 0 &&
314
+ argv[index].compare (0 , strlen (" -psn_" ), " -psn_" ) != 0 ) {
315
+ original_argv_.push_back (argv[index]);
316
+ }
317
+ }
318
+ #endif
257
319
argv_ = StringVector (1 );
258
320
switches_.clear ();
259
321
switches_by_stringpiece_.clear ();
@@ -390,6 +452,12 @@ void CommandLine::AppendArgNative(const CommandLine::StringType& value) {
390
452
argv_.push_back (value);
391
453
}
392
454
455
+ #if defined(OS_MACOSX)
456
+ void CommandLine::FixOrigArgv4Finder (const CommandLine::StringType& value) {
457
+ original_argv_.push_back (value);
458
+ }
459
+ #endif
460
+
393
461
void CommandLine::AppendArguments (const CommandLine& other,
394
462
bool include_program) {
395
463
if (include_program)
0 commit comments