Diff
Not logged in

Differences From Artifact [3e69c3a670]:

To Artifact [fde3a1b61d]:


357
358
359
360
361
362
363
364
365

366
367
368
369
370
371


372
373
374

375
376
377
378
379
380
381
382


383
384

385
386
387

388
389
390
391
392
393
394
395
396



397
398
399
400
401
402

403
404
405

406
407
408
409
410
411
412

413
414
415
416

417
418
419

420
421
422
423
424
425
426
427
428
429

430
431
432
433

434
435
436
437
438
439
440
441
442
443
444
445
446
447

448
449
450
451
452
453
454
357
358
359
360
361
362
363


364
365
366
367
368


369
370
371
372

373
374
375
376
377
378
379


380
381
382

383
384
385

386
387
388
389
390
391
392



393
394
395
396
397
398
399
400

401
402
403

404
405
406
407
408
409
410

411
412
413
414

415
416
417

418
419
420
421
422
423
424
425
426
427

428
429
430
431

432
433
434
435
436
437
438
439
440
441
442
443
444
445

446
447
448
449
450
451
452
453







-
-
+




-
-
+
+


-
+






-
-
+
+

-
+


-
+






-
-
-
+
+
+





-
+


-
+






-
+



-
+


-
+









-
+



-
+













-
+







** quote + quote not in quoted string -> empty string
** quote -> begin quoted string
**
** Results:
** Fills argcPtr with the number of arguments and argvPtr with the array
** of arguments.
*/
#include <tchar.h>
#define tchar_isspace(X)  ((X)==TEXT(' ') || (X)==TEXT('\t'))
#define wchar_isspace(X)  ((X)==L' ' || (X)==L'\t')
static void parse_windows_command_line(
  int *argcPtr,   /* Filled with number of argument strings. */
  void *argvPtr   /* Filled with argument strings (malloc'd). */
){
  TCHAR *cmdLine, *p, *arg, *argSpace;
  TCHAR **argv;
  WCHAR *cmdLine, *p, *arg, *argSpace;
  WCHAR **argv;
  int argc, size, inquote, copy, slashes;

  cmdLine = GetCommandLine();
  cmdLine = GetCommandLineW();

  /*
  ** Precompute an overly pessimistic guess at the number of arguments in
  ** the command line by counting non-space spans.
  */
  size = 2;
  for(p=cmdLine; *p!=TEXT('\0'); p++){
    if( tchar_isspace(*p) ){
  for(p=cmdLine; *p!=L'\0'; p++){
    if( wchar_isspace(*p) ){
      size++;
      while( tchar_isspace(*p) ){
      while( wchar_isspace(*p) ){
        p++;
      }
      if( *p==TEXT('\0') ){
      if( *p==L'\0' ){
        break;
      }
    }
  }

  argSpace = fossil_malloc(size * sizeof(char*)
    + (_tcslen(cmdLine) * sizeof(TCHAR)) + sizeof(TCHAR));
  argv = (TCHAR**)argSpace;
  argSpace += size*(sizeof(char*)/sizeof(TCHAR));
    + (wcslen(cmdLine) * sizeof(WCHAR)) + sizeof(WCHAR));
  argv = (WCHAR**)argSpace;
  argSpace += size*(sizeof(char*)/sizeof(WCHAR));
  size--;

  p = cmdLine;
  for(argc=0; argc<size; argc++){
    argv[argc] = arg = argSpace;
    while( tchar_isspace(*p) ){
    while( wchar_isspace(*p) ){
      p++;
    }
    if (*p == TEXT('\0')) {
    if (*p == L'\0') {
      break;
    }
    inquote = 0;
    slashes = 0;
    while(1){
      copy = 1;
      while( *p==TEXT('\\') ){
      while( *p==L'\\' ){
        slashes++;
        p++;
      }
      if( *p==TEXT('"') ){
      if( *p==L'"' ){
        if( (slashes&1)==0 ){
          copy = 0;
          if( inquote && p[1]==TEXT('"') ){
          if( inquote && p[1]==L'"' ){
            p++;
            copy = 1;
          }else{
            inquote = !inquote;
          }
        }
        slashes >>= 1;
      }
      while( slashes ){
        *arg = TEXT('\\');
        *arg = L'\\';
        arg++;
        slashes--;
      }
      if( *p==TEXT('\0') || (!inquote && tchar_isspace(*p)) ){
      if( *p==L'\0' || (!inquote && wchar_isspace(*p)) ){
        break;
      }
      if( copy!=0 ){
        *arg = *p;
        arg++;
      }
      p++;
    }
    *arg = '\0';
    argSpace = arg + 1;
  }
  argv[argc] = NULL;
  *argcPtr = argc;
  *((TCHAR ***)argvPtr) = argv;
  *((WCHAR ***)argvPtr) = argv;
}
#endif /* defined(_WIN32) */


/*
** Convert all arguments from mbcs (or unicode) to UTF-8. Then
** search g.argv for arguments "--args FILENAME". If found, then