summaryrefslogtreecommitdiff
path: root/src/cp.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1993-04-02 04:26:26 +0000
committerJim Meyering <jim@meyering.net>1993-04-02 04:26:26 +0000
commitee871dbed84a671bad1217b23ad3802ab023e26c (patch)
treee35f1c605334d3d40c2ea1cd67fada6cd41d9d62 /src/cp.c
parent0a6061f1f9178df1bfddaff7b25dbf5393833096 (diff)
downloadcoreutils-ee871dbed84a671bad1217b23ad3802ab023e26c.tar.xz
Add --help and --version options.
Diffstat (limited to 'src/cp.c')
-rw-r--r--src/cp.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/src/cp.c b/src/cp.c
index 9eef69c9f..f3a7c0a97 100644
--- a/src/cp.c
+++ b/src/cp.c
@@ -24,6 +24,7 @@
#include <getopt.h>
#include "cp.h"
#include "backupfile.h"
+#include "version.h"
#ifndef _POSIX_VERSION
uid_t geteuid ();
@@ -56,13 +57,13 @@ static int re_protect ();
/* Initial number of entries in the inode hash table. */
#define INITIAL_ENTRY_TAB_SIZE 70
+/* The invocation name of this program. */
+char *program_name;
+
/* A pointer to either lstat or stat, depending on
whether dereferencing of symlinks is done. */
static int (*xstat) ();
-/* The invocation name of this program. */
-char *program_name;
-
/* If nonzero, copy all files except directories and, if not dereferencing
them, symbolic links, as if they were regular files. */
static int flag_copy_as_regular = 1;
@@ -117,6 +118,12 @@ static int umask_kill;
/* This process's effective user ID. */
static uid_t myeuid;
+/* If non-zero, display usage information and exit. */
+static int flag_help;
+
+/* If non-zero, print the version on standard error. */
+static int flag_version;
+
static struct option const long_opts[] =
{
{"archive", no_argument, NULL, 'a'},
@@ -134,6 +141,8 @@ static struct option const long_opts[] =
{"update", no_argument, &flag_update, 1},
{"verbose", no_argument, &flag_verbose, 1},
{"version-control", required_argument, NULL, 'V'},
+ {"help", no_argument, &flag_help, 1},
+ {"version", no_argument, &flag_version, 1},
{NULL, 0, NULL, 0}
};
@@ -252,6 +261,12 @@ main (argc, argv)
if (flag_hard_link && flag_symbolic_link)
usage ("cannot make both hard and symbolic links");
+ if (flag_version)
+ fprintf (stderr, "%s\n", version_string);
+
+ if (flag_help)
+ usage (NULL);
+
if (make_backups)
backup_type = get_version (version);