Subversion Repositories SvarDOS

Rev

Rev 2064 | Rev 2066 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2064 Rev 2065
Line 362... Line 362...
362
  printf(invalidDrive);
362
  printf(invalidDrive);
363
  exit(1);
363
  exit(1);
364
}
364
}
365
 
365
 
366
 
366
 
367
/* Takes a fullpath, splits into drive (C:, or \\server\share) and path */
-
 
368
static void splitpath(char *fullpath, char *drive, char *path);
-
 
369
 
-
 
370
/**
367
/**
371
 * Takes a given path, strips any \ or / that may appear on the end.
368
 * Takes a given path, strips any \ or / that may appear on the end.
372
 * Returns a pointer to its static buffer containing path
369
 * Returns a pointer to its static buffer containing path
373
 * without trailing slash and any necessary display conversions.
370
 * without trailing slash and any necessary display conversions.
374
 */
371
 */
375
static char *fixPathForDisplay(char *path);
372
static char *fixPathForDisplay(char *path);
376
 
373
 
377
/* Displays error message for invalid path; Does NOT exit */
374
/* Displays error message for invalid path; Does NOT exit */
378
static void showInvalidPath(char *path) {
375
static void showInvalidPath(const char *badpath) {
379
  char partialPath[PATH_MAX], dummy[PATH_MAX];
-
 
380
 
-
 
381
  pprintf("%s\n", path);
376
  pprintf("%s\n", badpath);
382
  splitpath(path, dummy, partialPath);
-
 
383
  pprintf(invalidPath, fixPathForDisplay(partialPath));
377
  pprintf(invalidPath, badpath);
384
}
378
}
385
 
379
 
386
/* Displays error message for out of memory; Does NOT exit */
380
/* Displays error message for out of memory; Does NOT exit */
387
static void showOutOfMemory(const char *path) {
381
static void showOutOfMemory(const char *path) {
388
  pprintf(outOfMemory, path);
382
  pprintf(outOfMemory, path);
389
}
383
}
390
 
384
 
391
 
385
 
392
/**
-
 
393
 * Takes a fullpath, splits into drive (C:, or \\server\share) and path
-
 
394
 * It assumes a colon as the 2nd character means drive specified,
-
 
395
 * a double slash \\ (\\, //, \/, or /\) specifies network share.
-
 
396
 * If neither drive nor network share, then assumes whole fullpath
-
 
397
 * is path, and sets drive to "".
-
 
398
 * If drive specified, then set drive to it and colon, eg "C:", with
-
 
399
 * the rest of fullpath being set in path.
-
 
400
 * If network share, the slash slash followed by the server name,
-
 
401
 * another slash and either the rest of fullpath or up to, but not
-
 
402
 * including, the next slash are placed in drive, eg "\\KJD\myshare";
-
 
403
 * the rest of the fullpath including the slash are placed in
-
 
404
 * path, eg "\mysubdir"; where fullpath is "\\KJD\myshare\mysubdir".
-
 
405
 * None of these may be NULL, and drive and path must be large
-
 
406
 * enough to hold fullpath.
-
 
407
 */
-
 
408
static void splitpath(char *fullpath, char *drive, char *path) {
-
 
409
  char *src = fullpath;
-
 
410
  char oldchar;
-
 
411
 
-
 
412
  /* If either network share or path only starting at root directory */
-
 
413
  if ( (*src == '\\') || (*src == '/') )
-
 
414
  {
-
 
415
    src++;
-
 
416
 
-
 
417
    if ( (*src == '\\') || (*src == '/') ) /* network share */
-
 
418
    {
-
 
419
      src++;
-
 
420
 
-
 
421
      /* skip past server name */
-
 
422
      while ( (*src != '\\') && (*src != '/') && (*src != '\0') )
-
 
423
        src++;
-
 
424
 
-
 
425
      /* skip past slash (\ or /) separating  server from share */
-
 
426
      if (*src != '\0') src++;
-
 
427
 
-
 
428
      /* skip past share name */
-
 
429
      while ( (*src != '\\') && (*src != '/') && (*src != '\0') )
-
 
430
        src++;
-
 
431
 
-
 
432
      /* src points to start of path, either a slash or '\0' */
-
 
433
      oldchar = *src;
-
 
434
      *src = '\0';
-
 
435
 
-
 
436
      /* copy server name to drive */
-
 
437
      strcpy(drive, fullpath);
-
 
438
 
-
 
439
      /* restore character used to mark end of server name */
-
 
440
      *src = oldchar;
-
 
441
 
-
 
442
      /* copy path */
-
 
443
      strcpy(path, src);
-
 
444
    }
-
 
445
    else /* path only starting at root directory */
-
 
446
    {
-
 
447
      /* no drive, so set path to same as fullpath */
-
 
448
      drive[0] = 0;
-
 
449
      strcpy(path, fullpath);
-
 
450
    }
-
 
451
  }
-
 
452
  else
-
 
453
  {
-
 
454
    if (*src != '\0') src++;
-
 
455
 
-
 
456
    /* Either drive and path or path only */
-
 
457
    if (*src == ':')
-
 
458
    {
-
 
459
      /* copy drive specified */
-
 
460
      *drive = *fullpath;  drive++;
-
 
461
      *drive = ':';        drive++;
-
 
462
      *drive = '\0';
-
 
463
 
-
 
464
      /* copy path */
-
 
465
      src++;
-
 
466
      strcpy(path, src);
-
 
467
    }
-
 
468
    else
-
 
469
    {
-
 
470
      /* no drive, so set path to same as fullpath */
-
 
471
      drive[0] = 0;
-
 
472
      strcpy(path, fullpath);
-
 
473
    }
-
 
474
  }
-
 
475
}
-
 
476
 
-
 
477
 
-
 
478
/* Parses the command line and sets global variables. */
386
/* Parses the command line and sets global variables. */
479
static void parseArguments(int argc, char **argv) {
387
static void parseArguments(int argc, char **argv) {
480
  int i;
388
  int i;
481
 
389
 
482
  /* if no drive specified on command line, use current */
390
  /* if no drive specified on command line, use current */
Line 733... Line 641...
733
  *(padding + len - 4) = '\0';
641
  *(padding + len - 4) = '\0';
734
 
642
 
735
  return padding;
643
  return padding;
736
}
644
}
737
 
645
 
738
/**
-
 
739
 * Takes a given path, strips any \ or / that may appear on the end.
-
 
740
 * Returns a pointer to its static buffer containing path
-
 
741
 * without trailing slash and any necessary display conversions.
-
 
742
 */
-
 
743
static char *fixPathForDisplay(char *path) {
-
 
744
  static char buffer[PATH_MAX];
-
 
745
  int pathlen;
-
 
746
 
-
 
747
  strcpy(buffer, path);
-
 
748
  pathlen = strlen(buffer);
-
 
749
  if (pathlen > 1) {
-
 
750
    pathlen--;
-
 
751
    if ((buffer[pathlen] == '\\') || (buffer[pathlen] == '/')) {
-
 
752
      buffer[pathlen] = '\0'; // strip off trailing slash on end
-
 
753
    }
-
 
754
  }
-
 
755
 
-
 
756
  return buffer;
-
 
757
}
-
 
758
 
646
 
759
/**
647
/**
760
 * Displays the current path, with necessary padding before it.
648
 * Displays the current path, with necessary padding before it.
761
 * A \ or / on end of currentpath is not shown.
649
 * A \ or / on end of currentpath is not shown.
762
 * moreSubdirsFollow should be nonzero if this is not the last
650
 * moreSubdirsFollow should be nonzero if this is not the last