New option: --strip-trailing-slashes.
authorJim Meyering <jim@meyering.net>
Sun, 16 Apr 2000 13:51:22 +0000 (13:51 +0000)
committerJim Meyering <jim@meyering.net>
Sun, 16 Apr 2000 13:51:22 +0000 (13:51 +0000)
(enum) [STRIP_TRAILING_SLASHES_OPTION]: New member.
(remove_trailing_slashes): New global.
(long_opts): New getopt spec.
(usage): Describe.
(do_copy): Strip trailing slashes on SOURCE names only if the new
option has been specified.
(main): New case.

src/cp.c

index 4c214b5..4600289 100644 (file)
--- a/src/cp.c
+++ b/src/cp.c
@@ -60,7 +60,8 @@ struct dir_attr
 enum
 {
   TARGET_DIRECTORY_OPTION = CHAR_MAX + 1,
-  SPARSE_OPTION
+  SPARSE_OPTION,
+  STRIP_TRAILING_SLASHES_OPTION
 };
 
 int stat ();
@@ -81,6 +82,9 @@ char *program_name;
    as its destination instead of the usual "e_dir/e_file." */
 static int flag_path = 0;
 
+/* Remove any trailing slashes from each SOURCE argument.  */
+static int remove_trailing_slashes;
+
 static char const *const sparse_type_string[] =
 {
   "never", "auto", "always", 0
@@ -108,6 +112,7 @@ static struct option const long_opts[] =
   {"path", no_argument, NULL, 'P'},
   {"preserve", no_argument, NULL, 'p'},
   {"recursive", no_argument, NULL, 'R'},
+  {"strip-trailing-slash", no_argument, NULL, STRIP_TRAILING_SLASHES_OPTION},
   {"suffix", required_argument, NULL, 'S'},
   {"symbolic-link", no_argument, NULL, 's'},
   {"target-directory", required_argument, NULL, TARGET_DIRECTORY_OPTION},
@@ -150,6 +155,8 @@ Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.\n\
                                  special files like FIFOs or /dev/zero\n\
       --sparse=WHEN            control creation of sparse files\n\
   -R, --recursive              copy directories recursively\n\
+      --strip-trailing-slashes remove any trailing slashes from each SOURCE\n\
+                                 argument\n\
   -s, --symbolic-link          make symbolic links instead of copying\n\
   -S, --suffix=SUFFIX          override the usual backup suffix\n\
       --target-directory=DIRECTORY  move all SOURCE arguments into DIRECTORY\n\
@@ -486,7 +493,8 @@ do_copy (int n_files, char **file, const char *target_directory,
          char *arg_in_concat = NULL;
          char *arg = file[i];
 
-         strip_trailing_slashes (arg);
+         if (remove_trailing_slashes)
+           strip_trailing_slashes (arg);
 
          if (flag_path)
            {
@@ -598,7 +606,8 @@ do_copy (int n_files, char **file, const char *target_directory,
 
          tmp_source = (char *) alloca (strlen (source) + 1);
          strcpy (tmp_source, source);
-         strip_trailing_slashes (tmp_source);
+         if (remove_trailing_slashes)
+           strip_trailing_slashes (tmp_source);
          source_base = base_name (tmp_source);
 
          new_dest = (char *) alloca (strlen (dest)
@@ -746,6 +755,10 @@ main (int argc, char **argv)
          x.copy_as_regular = 0;
          break;
 
+       case STRIP_TRAILING_SLASHES_OPTION:
+         remove_trailing_slashes = 1;
+         break;
+
        case 's':
 #ifdef S_ISLNK
          x.symbolic_link = 1;