]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
Add support for --no-target-directory option.
authorJim Meyering <jim@meyering.net>
Wed, 30 Jun 2004 18:39:42 +0000 (18:39 +0000)
committerJim Meyering <jim@meyering.net>
Wed, 30 Jun 2004 18:39:42 +0000 (18:39 +0000)
(NO_TARGET_DIRECTORY_OPTION): New constant.
(long_options, usage, main): Add support for
(enum): Sort values.

src/mv.c

index 071620602c627307fd5303c2288911c78f02076f..7655a01a802836cd501b4abda9d9e7e9cce01324 100644 (file)
--- a/src/mv.c
+++ b/src/mv.c
    non-character as a pseudo short option, starting with CHAR_MAX + 1.  */
 enum
 {
-  TARGET_DIRECTORY_OPTION = CHAR_MAX + 1,
+  NO_TARGET_DIRECTORY_OPTION = CHAR_MAX + 1,
+  REPLY_OPTION,
   STRIP_TRAILING_SLASHES_OPTION,
-  REPLY_OPTION
+  TARGET_DIRECTORY_OPTION
 };
 
 /* The name this program was run with. */
@@ -77,6 +78,7 @@ static struct option const long_options[] =
   {"backup", optional_argument, NULL, 'b'},
   {"force", no_argument, NULL, 'f'},
   {"interactive", no_argument, NULL, 'i'},
+  {"no-target-directory", no_argument, NULL, NO_TARGET_DIRECTORY_OPTION},
   {"reply", required_argument, NULL, REPLY_OPTION},
   {"strip-trailing-slashes", no_argument, NULL, STRIP_TRAILING_SLASHES_OPTION},
   {"suffix", required_argument, NULL, 'S'},
@@ -329,6 +331,7 @@ Mandatory arguments to long options are mandatory for short options too.\n\
 "), stdout);
       fputs (_("\
       --target-directory=DIRECTORY  move all SOURCE arguments into DIRECTORY\n\
+      --no-target-directory    treat DEST as a normal file\n\
   -u, --update                 move only when the SOURCE file is newer\n\
                                  than the destination file or when the\n\
                                  destination file is missing\n\
@@ -364,6 +367,7 @@ main (int argc, char **argv)
   char *version_control_string = NULL;
   struct cp_options x;
   char *target_directory = NULL;
+  bool no_target_directory = false;
   int n_files;
   char **file;
 
@@ -408,6 +412,9 @@ main (int argc, char **argv)
        case 'i':
          x.interactive = I_ASK_USER;
          break;
+       case NO_TARGET_DIRECTORY_OPTION:
+         no_target_directory = true;
+         break;
        case REPLY_OPTION:
          x.interactive = XARGMATCH ("--reply", optarg,
                                     reply_args, reply_vals);
@@ -459,7 +466,19 @@ main (int argc, char **argv)
       usage (EXIT_FAILURE);
     }
 
-  if (!target_directory)
+  if (no_target_directory)
+    {
+      if (target_directory)
+       error (EXIT_FAILURE, 0,
+              _("Cannot combine --target-directory "
+                "and --no-target-directory"));
+      if (2 < n_files)
+       {
+         error (0, 0, _("extra operand %s"), quote (file[2]));
+         usage (EXIT_FAILURE);
+       }
+    }
+  else if (!target_directory)
     {
       if (2 <= n_files && target_directory_operand (file[n_files - 1]))
        target_directory = file[--n_files];