summaryrefslogtreecommitdiff
path: root/src/link.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2002-04-12 10:41:22 +0000
committerJim Meyering <jim@meyering.net>2002-04-12 10:41:22 +0000
commit21126e288b1e38bea8f1de8893e26a124ab99961 (patch)
treeb5a89df0db91389098e930eb9ec74f521abfe620 /src/link.c
parentd1aa15101c90a9544f8e6e8486ff0c426069dbdf (diff)
downloadcoreutils-21126e288b1e38bea8f1de8893e26a124ab99961.tar.xz
Include long-options.h.
[long_opts]: Remove. (usage): Tweak --help output; use *_OPTION_DESCRIPTION macros. (main): Don't use getopt directly. Use parse_long_options instead. Tweak a diagnostic. Use EXIT_FAILURE rather than a literal `1'.
Diffstat (limited to 'src/link.c')
-rw-r--r--src/link.c65
1 files changed, 25 insertions, 40 deletions
diff --git a/src/link.c b/src/link.c
index 949474a09..cf9c657d7 100644
--- a/src/link.c
+++ b/src/link.c
@@ -1,5 +1,5 @@
-/* `link` utility for GNU.
- Copyright (C) 2001 Free Software Foundation, Inc.
+/* link utility for GNU.
+ Copyright (C) 2001, 2002 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -19,7 +19,7 @@
/* Implementation overview:
- Simply calls the system 'link' function */
+ Simply call the system 'link' function */
#include <config.h>
#include <stdio.h>
@@ -29,6 +29,7 @@
#include "system.h"
#include "error.h"
+#include "long-options.h"
#include "quote.h"
/* The official name of this program (e.g., no `g' prefix). */
@@ -39,13 +40,6 @@
/* Name this program was run with. */
char *program_name;
-static struct option const long_opts[] =
-{
- {GETOPT_HELP_OPTION_DECL},
- {GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
-};
-
void
usage (int status)
{
@@ -54,15 +48,14 @@ usage (int status)
program_name);
else
{
- printf (_("Usage: %s [OPTION]... FILE1 FILE2\n"), program_name);
printf (_("\
-Create a new directory entry FILE2 pointing to the same file as FILE1.\n\
-\n\
- --help display this help and exit\n\
- --version output version information and exit\n\
-\n\
-"),
- program_name, program_name);
+Usage: %s FILE1 FILE2\n\
+ or: %s OPTION\n"), program_name, program_name);
+ fputs (_("Call the link function to create a link named FILE2\
+ to an existing FILE1.\n\n"),
+ stdout);
+ fputs (HELP_OPTION_DESCRIPTION, stdout);
+ fputs (VERSION_OPTION_DESCRIPTION, stdout);
puts (_("\nReport bugs to <bug-fileutils@gnu.org>."));
}
exit (status);
@@ -71,9 +64,6 @@ Create a new directory entry FILE2 pointing to the same file as FILE1.\n\
int
main (int argc, char **argv)
{
- int fail = 0;
- int c;
-
program_name = argv[0];
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
@@ -81,37 +71,32 @@ main (int argc, char **argv)
atexit (close_stdout);
- while ((c = getopt_long (argc, argv, "", long_opts, NULL)) != -1)
+ parse_long_options (argc, argv, PROGRAM_NAME, GNU_PACKAGE, VERSION,
+ AUTHORS, usage);
+
+ /* The above handles --help and --version.
+ Since there is no other invocation of getopt, handle `--' here. */
+ if (1 < argc && STREQ (argv[1], "--"))
{
- switch (c)
- {
- case 0: /* Long option. */
- break;
- case_GETOPT_HELP_CHAR;
- case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
- default:
- usage (1);
- }
+ --argc;
+ ++argv;
}
- if (optind+2 > argc)
+ if (argc < 3)
{
error (0, 0, _("too few arguments"));
usage (1);
}
- if (optind+2 < argc)
+ if (3 < argc)
{
error (0, 0, _("too many arguments"));
usage (1);
}
- if (link(argv[optind],argv[optind+1]) != 0)
- {
- fail = 1;
- error (0, errno, _("linking %s to %s"),
- quote_n(0,argv[optind]), quote_n(1,argv[optind+1]));
- }
+ if (link (argv[1], argv[2]) != 0)
+ error (EXIT_FAILURE, errno, _("cannot create link %s to %s"),
+ quote_n (0, argv[2]), quote_n (1, argv[1]));
- exit (fail);
+ exit (0);
}