summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/chgrp.c16
-rw-r--r--src/chmod.c15
-rw-r--r--src/chown.c15
-rw-r--r--src/cp.c21
-rw-r--r--src/dd.c6
-rw-r--r--src/df.c21
-rw-r--r--src/du.c16
-rw-r--r--src/install.c16
-rw-r--r--src/ln.c19
-rw-r--r--src/mkdir.c21
-rw-r--r--src/mkfifo.c17
-rw-r--r--src/mknod.c15
-rw-r--r--src/mv.c15
-rw-r--r--src/rm.c21
-rw-r--r--src/rmdir.c21
-rw-r--r--src/touch.c19
16 files changed, 252 insertions, 22 deletions
diff --git a/src/chgrp.c b/src/chgrp.c
index 2d4fe213e..2dba1eed4 100644
--- a/src/chgrp.c
+++ b/src/chgrp.c
@@ -23,8 +23,10 @@
#include <grp.h>
#include <getopt.h>
#include "system.h"
+#include "version.h"
#if !defined (isascii) || defined (STDC_HEADERS)
+#undef isascii
#define isascii(c) 1
#endif
@@ -70,6 +72,12 @@ static int changes_only;
/* The name of the group to which ownership of the files is being given. */
static char *groupname;
+/* 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_options[] =
{
{"recursive", no_argument, 0, 'R'},
@@ -77,6 +85,8 @@ static struct option const long_options[] =
{"silent", no_argument, 0, 'f'},
{"quiet", no_argument, 0, 'f'},
{"verbose", no_argument, 0, 'v'},
+ {"help", no_argument, &flag_help, 1},
+ {"version", no_argument, &flag_version, 1},
{0, 0, 0, 0}
};
@@ -118,6 +128,12 @@ main (argc, argv)
if (optind >= argc - 1)
usage ();
+ if (flag_version)
+ fprintf (stderr, "%s\n", version_string);
+
+ if (flag_help)
+ usage ();
+
parse_group (argv[optind++], &group);
for (; optind < argc; ++optind)
diff --git a/src/chmod.c b/src/chmod.c
index 3df4b99ab..de93b0f0c 100644
--- a/src/chmod.c
+++ b/src/chmod.c
@@ -28,6 +28,7 @@
#include <sys/types.h>
#include "modechange.h"
#include "system.h"
+#include "version.h"
int lstat ();
@@ -57,6 +58,12 @@ static int verbose;
/* If nonzero, describe only modes that change. */
static int changes_only;
+/* 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_options[] =
{
{"recursive", no_argument, 0, 'R'},
@@ -64,6 +71,8 @@ static struct option const long_options[] =
{"silent", no_argument, 0, 'f'},
{"quiet", no_argument, 0, 'f'},
{"verbose", no_argument, 0, 'v'},
+ {"help", no_argument, &flag_help, 1},
+ {"version", no_argument, &flag_version, 1},
{0, 0, 0, 0}
};
@@ -136,6 +145,12 @@ main (argc, argv)
if (optind >= argc)
usage ();
+ if (flag_version)
+ fprintf (stderr, "%s\n", version_string);
+
+ if (flag_help)
+ usage ();
+
changes = mode_compile (argv[modeind],
MODE_MASK_EQUALS | MODE_MASK_PLUS | MODE_MASK_MINUS);
if (changes == MODE_INVALID)
diff --git a/src/chown.c b/src/chown.c
index 37a881e2f..e693e662a 100644
--- a/src/chown.c
+++ b/src/chown.c
@@ -35,6 +35,7 @@
#include <grp.h>
#include <getopt.h>
#include "system.h"
+#include "version.h"
#ifndef _POSIX_VERSION
struct passwd *getpwnam ();
@@ -81,6 +82,12 @@ static char *username;
/* The name of the group to which ownership of the files is being given. */
static char *groupname;
+/* 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_options[] =
{
{"recursive", no_argument, 0, 'R'},
@@ -88,6 +95,8 @@ static struct option const long_options[] =
{"silent", no_argument, 0, 'f'},
{"quiet", no_argument, 0, 'f'},
{"verbose", no_argument, 0, 'v'},
+ {"help", no_argument, &flag_help, 1},
+ {"version", no_argument, &flag_version, 1},
{0, 0, 0, 0}
};
@@ -131,6 +140,12 @@ main (argc, argv)
if (optind >= argc - 1)
usage ();
+ if (flag_version)
+ fprintf (stderr, "%s\n", version_string);
+
+ if (flag_help)
+ usage ();
+
e = parse_user_spec (argv[optind], &user, &group, &username, &groupname);
if (e)
error (1, 0, "%s: %s", argv[optind], e);
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);
diff --git a/src/dd.c b/src/dd.c
index c8a433740..cdf5234fd 100644
--- a/src/dd.c
+++ b/src/dd.c
@@ -57,6 +57,7 @@
#include <ctype.h>
#if !defined (isascii) || defined (STDC_HEADERS)
+#undef isascii
#define isascii(c) 1
#endif
@@ -307,7 +308,10 @@ static unsigned char const ebcdic_to_ascii[] =
070, 071, 0372, 0373, 0374, 0375, 0376, 0377
};
+/* 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_options[] =
@@ -337,7 +341,7 @@ main (argc, argv)
scanargs (argc, argv);
if (flag_version)
- fprintf (stderr, "%s", version_string);
+ fprintf (stderr, "%s\n", version_string);
if (flag_help)
usage ("", NULL, NULL);
diff --git a/src/df.c b/src/df.c
index 994987f3f..bdc834cac 100644
--- a/src/df.c
+++ b/src/df.c
@@ -37,6 +37,7 @@
#include "mountlist.h"
#include "fsusage.h"
#include "system.h"
+#include "version.h"
char *strstr ();
char *xmalloc ();
@@ -55,6 +56,9 @@ static void show_disk ();
static void show_point ();
static void usage ();
+/* Name this program was run with. */
+char *program_name;
+
/* If nonzero, show inode information. */
static int inode_format;
@@ -71,9 +75,6 @@ static int posix_format;
/* Nonzero if errors have occurred. */
static int exit_status;
-/* Name this program was run with. */
-char *program_name;
-
/* A filesystem type to display. */
struct fs_type_list
@@ -103,6 +104,12 @@ static struct fs_type_list *fs_exclude_list;
/* Linked list of mounted filesystems. */
static struct mount_entry *mount_list;
+/* 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_options[] =
{
{"all", no_argument, &show_all_fs, 1},
@@ -111,6 +118,8 @@ static struct option const long_options[] =
{"portability", no_argument, &posix_format, 1},
{"type", required_argument, 0, 't'},
{"exclude-type", required_argument, 0, 'x'},
+ {"help", no_argument, &flag_help, 1},
+ {"version", no_argument, &flag_version, 1},
{NULL, 0, NULL, 0}
};
@@ -163,6 +172,12 @@ main (argc, argv)
}
}
+ if (flag_version)
+ fprintf (stderr, "%s\n", version_string);
+
+ if (flag_help)
+ usage ();
+
if (optind != argc)
{
/* Display explicitly requested empty filesystems. */
diff --git a/src/du.c b/src/du.c
index 5543ceea8..90cb303b0 100644
--- a/src/du.c
+++ b/src/du.c
@@ -43,6 +43,7 @@
#include <getopt.h>
#include <sys/types.h>
#include "system.h"
+#include "version.h"
int lstat ();
int stat ();
@@ -152,9 +153,14 @@ static struct stat stat_buf;
static int (*xstat) ();
/* The exit status to use if we don't get any fatal errors. */
-
static int exit_status;
+/* 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_options[] =
{
{"all", no_argument, &opt_all, 1},
@@ -167,6 +173,8 @@ static struct option const long_options[] =
{"separate-dirs", no_argument, &opt_separate_dirs, 1},
{"summarize", no_argument, &opt_summarize_only, 1},
{"total", no_argument, &opt_combined_arguments, 1},
+ {"help", no_argument, &flag_help, 1},
+ {"version", no_argument, &flag_version, 1},
{NULL, 0, NULL, 0}
};
@@ -253,6 +261,12 @@ main (argc, argv)
if (opt_all && opt_summarize_only)
usage ("cannot both summarize and show all entries");
+ if (flag_version)
+ fprintf (stderr, "%s\n", version_string);
+
+ if (flag_help)
+ usage ("");
+
/* Initialize the hash structure for inode numbers. */
hash_init (INITIAL_HASH_MODULE, INITIAL_ENTRY_TAB_SIZE);
diff --git a/src/install.c b/src/install.c
index 4fccb8447..dd8b58cc7 100644
--- a/src/install.c
+++ b/src/install.c
@@ -59,9 +59,11 @@
#include <pwd.h>
#include <grp.h>
#include "system.h"
+#include "version.h"
#include "modechange.h"
#if !defined (isascii) || defined (STDC_HEADERS)
+#undef isascii
#define isascii(c) 1
#endif
@@ -130,6 +132,12 @@ static int strip_files;
/* If nonzero, install a directory instead of a regular file. */
static int dir_arg;
+/* 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_options[] =
{
{"strip", no_argument, NULL, 's'},
@@ -137,6 +145,8 @@ static struct option const long_options[] =
{"group", required_argument, NULL, 'g'},
{"mode", required_argument, NULL, 'm'},
{"owner", required_argument, NULL, 'o'},
+ {"help", no_argument, &flag_help, 1},
+ {"version", no_argument, &flag_version, 1},
{NULL, 0, NULL, 0}
};
@@ -190,6 +200,12 @@ main (argc, argv)
|| (optind == argc - 1 && !dir_arg))
usage ();
+ if (flag_version)
+ fprintf (stderr, "%s\n", version_string);
+
+ if (flag_help)
+ usage ();
+
if (symbolic_mode)
{
struct mode_change *change = mode_compile (symbolic_mode, 0);
diff --git a/src/ln.c b/src/ln.c
index 3907399ee..673410363 100644
--- a/src/ln.c
+++ b/src/ln.c
@@ -25,6 +25,7 @@
#include <getopt.h>
#include "system.h"
#include "backupfile.h"
+#include "version.h"
int link (); /* Some systems don't declare this anywhere. */
@@ -41,6 +42,9 @@ void error ();
static void usage ();
static int do_link ();
+/* The name by which the program was run, for error messages. */
+char *program_name;
+
/* A pointer to the function used to make links. This will point to either
`link' or `symlink'. */
static int (*linkfunc) ();
@@ -60,8 +64,11 @@ static int verbose;
/* If nonzero, allow the superuser to make hard links to directories. */
static int hard_dir_link;
-/* The name by which the program was run, for error messages. */
-char *program_name;
+/* 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_options[] =
{
@@ -73,6 +80,8 @@ static struct option const long_options[] =
{"symbolic", no_argument, &symbolic_link, 1},
{"verbose", no_argument, &verbose, 1},
{"version-control", required_argument, NULL, 'V'},
+ {"help", no_argument, &flag_help, 1},
+ {"version", no_argument, &flag_version, 1},
{NULL, 0, NULL, 0}
};
@@ -142,6 +151,12 @@ main (argc, argv)
if (optind == argc)
usage ();
+ if (flag_version)
+ fprintf (stderr, "%s\n", version_string);
+
+ if (flag_help)
+ usage ();
+
if (make_backups)
backup_type = get_version (version);
diff --git a/src/mkdir.c b/src/mkdir.c
index 00bde815f..3d98ac627 100644
--- a/src/mkdir.c
+++ b/src/mkdir.c
@@ -32,22 +32,31 @@
#include <sys/types.h>
#include "system.h"
#include "modechange.h"
+#include "version.h"
int make_path ();
void error ();
static void usage ();
+/* The name this program was run with. */
+char *program_name;
+
/* If nonzero, ensure that a path exists. */
static int path_mode;
-/* The name this program was run with. */
-char *program_name;
+/* 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 longopts[] =
{
{"mode", required_argument, NULL, 'm'},
{"path", no_argument, &path_mode, 1},
+ {"help", no_argument, &flag_help, 1},
+ {"version", no_argument, &flag_version, 1},
{NULL, 0, NULL, 0}
};
@@ -84,7 +93,13 @@ main (argc, argv)
if (optind == argc)
usage ();
-
+
+ if (flag_version)
+ fprintf (stderr, "%s\n", version_string);
+
+ if (flag_help)
+ usage ();
+
newmode = 0777 & ~umask (0);
parent_mode = newmode | 0300; /* u+wx */
if (symbolic_mode)
diff --git a/src/mkfifo.c b/src/mkfifo.c
index 075cece51..a6a78f105 100644
--- a/src/mkfifo.c
+++ b/src/mkfifo.c
@@ -27,6 +27,7 @@
#include <sys/types.h>
#include "system.h"
#include "modechange.h"
+#include "version.h"
void error ();
@@ -35,9 +36,17 @@ static void usage ();
/* The name this program was run with. */
char *program_name;
+/* 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 longopts[] =
{
{"mode", required_argument, NULL, 'm'},
+ {"help", no_argument, &flag_help, 1},
+ {"version", no_argument, &flag_version, 1},
{NULL, 0, NULL, 0}
};
@@ -72,7 +81,13 @@ main (argc, argv)
if (optind == argc)
usage ();
-
+
+ if (flag_version)
+ fprintf (stderr, "%s\n", version_string);
+
+ if (flag_help)
+ usage ();
+
newmode = 0666 & ~umask (0);
if (symbolic_mode)
{
diff --git a/src/mknod.c b/src/mknod.c
index 66029ad0f..7e65ac01f 100644
--- a/src/mknod.c
+++ b/src/mknod.c
@@ -32,6 +32,7 @@
#include <sys/types.h>
#include "system.h"
#include "modechange.h"
+#include "version.h"
void error ();
@@ -40,9 +41,17 @@ static void usage ();
/* The name this program was run with. */
char *program_name;
+/* 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 longopts[] =
{
{"mode", required_argument, NULL, 'm'},
+ {"help", no_argument, &flag_help, 1},
+ {"version", no_argument, &flag_version, 1},
{NULL, 0, NULL, 0}
};
@@ -71,6 +80,12 @@ main (argc, argv)
}
}
+ if (flag_version)
+ fprintf (stderr, "%s\n", version_string);
+
+ if (flag_help)
+ usage ();
+
newmode = 0666 & ~umask (0);
if (symbolic_mode)
{
diff --git a/src/mv.c b/src/mv.c
index 9d28d4a87..91906e139 100644
--- a/src/mv.c
+++ b/src/mv.c
@@ -45,6 +45,7 @@
#include <sys/types.h>
#include "system.h"
#include "backupfile.h"
+#include "version.h"
#ifndef _POSIX_VERSION
uid_t geteuid ();
@@ -86,6 +87,12 @@ static int stdin_tty;
/* 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_options[] =
{
{"backup", no_argument, NULL, 'b'},
@@ -95,6 +102,8 @@ static struct option const long_options[] =
{"update", no_argument, &update, 1},
{"verbose", no_argument, &verbose, 1},
{"version-control", required_argument, NULL, 'V'},
+ {"help", no_argument, &flag_help, 1},
+ {"version", no_argument, &flag_version, 1},
{NULL, 0, NULL, 0}
};
@@ -154,6 +163,12 @@ main (argc, argv)
if (argc < optind + 2)
usage ();
+ if (flag_version)
+ fprintf (stderr, "%s\n", version_string);
+
+ if (flag_help)
+ usage ();
+
if (make_backups)
backup_type = get_version (version);
diff --git a/src/rm.c b/src/rm.c
index 4b6c2d2eb..0dec9d133 100644
--- a/src/rm.c
+++ b/src/rm.c
@@ -21,6 +21,7 @@
#include <getopt.h>
#include <sys/types.h>
#include "system.h"
+#include "version.h"
#ifdef _POSIX_SOURCE
/* POSIX.1 doesn't have inodes, so fake them to avoid lots of ifdefs. */
@@ -46,6 +47,9 @@ static int remove_file ();
static int rm ();
static void usage ();
+/* Name this program was run with. */
+char *program_name;
+
/* Path of file now being processed; extended as necessary. */
static char *pathname;
@@ -53,9 +57,6 @@ static char *pathname;
made larger when necessary, but never smaller. */
static int pnsize;
-/* Name this program was run with. */
-char *program_name;
-
/* If nonzero, display the name of each file removed. */
static int verbose;
@@ -76,6 +77,12 @@ static int unlink_dirs;
/* If nonzero, stdin is a tty. */
static int stdin_tty;
+/* 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[] =
{
{"directory", no_argument, &unlink_dirs, 1},
@@ -83,6 +90,8 @@ static struct option const long_opts[] =
{"interactive", no_argument, NULL, 'i'},
{"recursive", no_argument, &recursive, 1},
{"verbose", no_argument, &verbose, 1},
+ {"help", no_argument, &flag_help, 1},
+ {"version", no_argument, &flag_version, 1},
{NULL, 0, NULL, 0}
};
@@ -129,6 +138,12 @@ main (argc, argv)
}
}
+ if (flag_version)
+ fprintf (stderr, "%s\n", version_string);
+
+ if (flag_help)
+ usage ();
+
if (optind == argc)
{
if (ignore_missing_files)
diff --git a/src/rmdir.c b/src/rmdir.c
index 35bd7d652..aaaeb4df6 100644
--- a/src/rmdir.c
+++ b/src/rmdir.c
@@ -26,6 +26,7 @@
#include <getopt.h>
#include <sys/types.h>
#include "system.h"
+#include "version.h"
void error ();
void strip_trailing_slashes ();
@@ -33,15 +34,23 @@ void strip_trailing_slashes ();
static void remove_parents ();
static void usage ();
+/* The name this program was run with. */
+char *program_name;
+
/* If nonzero, remove empty parent directories. */
static int empty_paths;
-/* The name this program was run with. */
-char *program_name;
+/* 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 longopts[] =
{
{"path", no_argument, &empty_paths, 1},
+ {"help", no_argument, &flag_help, 1},
+ {"version", no_argument, &flag_version, 1},
{NULL, 0, NULL, 0}
};
@@ -72,7 +81,13 @@ main (argc, argv)
if (optind == argc)
usage ();
-
+
+ if (flag_version)
+ fprintf (stderr, "%s\n", version_string);
+
+ if (flag_help)
+ usage ();
+
for (; optind < argc; ++optind)
{
/* Stripping slashes is harmless for rmdir;
diff --git a/src/touch.c b/src/touch.c
index 65d76279f..7be500bdf 100644
--- a/src/touch.c
+++ b/src/touch.c
@@ -37,6 +37,7 @@
#include <getopt.h>
#include <sys/types.h>
#include "system.h"
+#include "version.h"
#ifdef STDC_HEADERS
#include <time.h>
@@ -61,6 +62,9 @@ static int utime_now ();
#define CH_ATIME 1
#define CH_MTIME 2
+/* The name by which this program was run. */
+char *program_name;
+
/* Which timestamps to change. */
static int change_times;
@@ -90,8 +94,11 @@ static char *ref_file;
/* Info about the reference file. */
static struct stat ref_stats;
-/* The name by which this program was run. */
-char *program_name;
+/* 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 longopts[] =
{
@@ -99,6 +106,8 @@ static struct option const longopts[] =
{"no-create", no_argument, 0, 'c'},
{"date", required_argument, 0, 'd'},
{"file", required_argument, 0, 'r'},
+ {"help", no_argument, &flag_help, 1},
+ {"version", no_argument, &flag_version, 1},
{0, 0, 0, 0}
};
@@ -183,6 +192,12 @@ main (argc, argv)
}
}
+ if (flag_version)
+ fprintf (stderr, "%s\n", version_string);
+
+ if (flag_help)
+ usage ();
+
if (change_times == 0)
change_times = CH_ATIME | CH_MTIME;