stty: trim too verbose error messages (-40 bytes)
[oweals/busybox.git] / coreutils / cp.c
index 9f6c12367af0ff7d5160ded666af356e56d49ba1..e48e21c9708c60d7762808d7b8e52737f07baf08 100644 (file)
@@ -5,7 +5,7 @@
  * Copyright (C) 2000 by Matt Kraai <kraai@alumni.carnegiemellon.edu>
  * SELinux support by Yuichi Nakamura <ynakam@hitachisoft.jp>
  *
- * Licensed under GPL v2 or later, see file LICENSE in this tarball for details.
+ * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  */
 
 /* http://www.opengroup.org/onlinepubs/007904975/utilities/cp.html */
  * Size reduction.
  */
 
+//usage:#define cp_trivial_usage
+//usage:       "[OPTIONS] SOURCE DEST"
+//usage:#define cp_full_usage "\n\n"
+//usage:       "Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY\n"
+//usage:     "\n       -a      Same as -dpR"
+//usage:       IF_SELINUX(
+//usage:     "\n       -c      Preserve security context"
+//usage:       )
+//usage:     "\n       -R,-r   Recurse"
+//usage:     "\n       -d,-P   Preserve symlinks (default if -R)"
+//usage:     "\n       -L      Follow all symlinks"
+//usage:     "\n       -H      Follow symlinks on command line"
+//usage:     "\n       -p      Preserve file attributes if possible"
+//usage:     "\n       -f      Overwrite"
+//usage:     "\n       -i      Prompt before overwrite"
+//usage:     "\n       -l,-s   Create (sym)links"
+
 #include "libbb.h"
 #include "libcoreutils/coreutils.h"
 
@@ -35,10 +52,9 @@ int cp_main(int argc, char **argv)
                OPT_a = 1 << (sizeof(FILEUTILS_CP_OPTSTR)-1),
                OPT_r = 1 << (sizeof(FILEUTILS_CP_OPTSTR)),
                OPT_P = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+1),
-               OPT_H = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+2),
-               OPT_v = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+3),
+               OPT_v = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+2),
 #if ENABLE_FEATURE_CP_LONG_OPTIONS
-               OPT_parents = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+4),
+               OPT_parents = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+3),
 #endif
        };
 
@@ -48,7 +64,7 @@ int cp_main(int argc, char **argv)
        // -r and -R are the same
        // -R (and therefore -r) turns on -d (coreutils does this)
        // -a = -pdR
-       opt_complementary = "-2:l--s:s--l:Pd:rRd:Rd:apdR:HL";
+       opt_complementary = "-2:l--s:s--l:Pd:rRd:Rd:apdR";
 #if ENABLE_FEATURE_CP_LONG_OPTIONS
        applet_long_options =
                "archive\0"        No_argument "a"
@@ -64,7 +80,7 @@ int cp_main(int argc, char **argv)
                ;
 #endif
        // -v (--verbose) is ignored
-       flags = getopt32(argv, FILEUTILS_CP_OPTSTR "arPHv");
+       flags = getopt32(argv, FILEUTILS_CP_OPTSTR "arPv");
        /* Options of cp from GNU coreutils 6.10:
         * -a, --archive
         * -f, --force
@@ -113,17 +129,14 @@ int cp_main(int argc, char **argv)
         */
        argc -= optind;
        argv += optind;
-       flags ^= FILEUTILS_DEREFERENCE; /* the sense of this flag was reversed */
+       /* Reverse this bit. If there is -d, bit is not set: */
+       flags ^= FILEUTILS_DEREFERENCE;
        /* coreutils 6.9 compat:
         * by default, "cp" derefs symlinks (creates regular dest files),
         * but "cp -R" does not. We switch off deref if -r or -R (see above).
         * However, "cp -RL" must still deref symlinks: */
        if (flags & FILEUTILS_DEREF_SOFTLINK) /* -L */
                flags |= FILEUTILS_DEREFERENCE;
-       /* The behavior of -H is *almost* like -L, but not quite, so let's
-        * just ignore it too for fun. TODO.
-       if (flags & OPT_H) ... // deref command-line params only
-       */
 
 #if ENABLE_SELINUX
        if (flags & FILEUTILS_PRESERVE_SECURITY_CONTEXT) {