aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Whitley <markw@lineo.com>2001-04-25 20:41:02 +0000
committerMark Whitley <markw@lineo.com>2001-04-25 20:41:02 +0000
commit207587a9b4d7323169eadfcd5dd517605a912569 (patch)
tree4cd9a232bb89d7e8d8a6333843689689a9fe85d4
parentc29c44c00e8f65d96bffa37a521b4d4be1f913ce (diff)
downloadbusybox-207587a9b4d7323169eadfcd5dd517605a912569.tar.gz
Applied patch from I.Q. to add -s to cmp.
-rw-r--r--applets/usage.h1
-rw-r--r--cmp.c32
-rw-r--r--coreutils/cmp.c32
-rw-r--r--include/usage.h1
-rw-r--r--usage.h1
5 files changed, 49 insertions, 18 deletions
diff --git a/applets/usage.h b/applets/usage.h
index 1e3023d1f..d85857fb5 100644
--- a/applets/usage.h
+++ b/applets/usage.h
@@ -115,6 +115,7 @@
#define cmp_trivial_usage \
"FILE1 [FILE2]"
#define cmp_full_usage \
+ "\t-s\tquiet mode - do not print\n" \
"Compare files."
#define cp_trivial_usage \
diff --git a/cmp.c b/cmp.c
index 24b6c3f92..6d579461d 100644
--- a/cmp.c
+++ b/cmp.c
@@ -26,28 +26,42 @@
#include <string.h>
#include <errno.h>
#include <stdlib.h>
+#include <getopt.h>
#include "busybox.h"
int cmp_main(int argc, char **argv)
{
FILE *fp1 = NULL, *fp2 = stdin;
- char *filename1 = argv[1], *filename2 = "-";
- int c1, c2, char_pos = 1, line_pos = 1;
+ char *filename1, *filename2 = "-";
+ int c, c1, c2, char_pos = 1, line_pos = 1, silent = FALSE;
- /* parse argv[] */
- if (argc < 2 || 3 < argc)
- show_usage();
+ while ((c = getopt(argc, argv, "s")) != EOF) {
+ switch (c) {
+ case 's':
+ silent = TRUE;
+ break;
+ default:
+ show_usage();
+ }
+ }
- fp1 = xfopen(argv[1], "r");
- if (argv[2] != NULL) {
- fp2 = xfopen(argv[2], "r");
- filename2 = argv[2];
+ filename1 = argv[optind];
+ switch (argc - optind) {
+ case 2:
+ fp2 = xfopen(filename2 = argv[optind + 1], "r");
+ case 1:
+ fp1 = xfopen(filename1, "r");
+ break;
+ default:
+ show_usage();
}
do {
c1 = fgetc(fp1);
c2 = fgetc(fp2);
if (c1 != c2) {
+ if (silent)
+ return EXIT_FAILURE;
if (c1 == EOF)
printf("EOF on %s\n", filename1);
else if (c2 == EOF)
diff --git a/coreutils/cmp.c b/coreutils/cmp.c
index 24b6c3f92..6d579461d 100644
--- a/coreutils/cmp.c
+++ b/coreutils/cmp.c
@@ -26,28 +26,42 @@
#include <string.h>
#include <errno.h>
#include <stdlib.h>
+#include <getopt.h>
#include "busybox.h"
int cmp_main(int argc, char **argv)
{
FILE *fp1 = NULL, *fp2 = stdin;
- char *filename1 = argv[1], *filename2 = "-";
- int c1, c2, char_pos = 1, line_pos = 1;
+ char *filename1, *filename2 = "-";
+ int c, c1, c2, char_pos = 1, line_pos = 1, silent = FALSE;
- /* parse argv[] */
- if (argc < 2 || 3 < argc)
- show_usage();
+ while ((c = getopt(argc, argv, "s")) != EOF) {
+ switch (c) {
+ case 's':
+ silent = TRUE;
+ break;
+ default:
+ show_usage();
+ }
+ }
- fp1 = xfopen(argv[1], "r");
- if (argv[2] != NULL) {
- fp2 = xfopen(argv[2], "r");
- filename2 = argv[2];
+ filename1 = argv[optind];
+ switch (argc - optind) {
+ case 2:
+ fp2 = xfopen(filename2 = argv[optind + 1], "r");
+ case 1:
+ fp1 = xfopen(filename1, "r");
+ break;
+ default:
+ show_usage();
}
do {
c1 = fgetc(fp1);
c2 = fgetc(fp2);
if (c1 != c2) {
+ if (silent)
+ return EXIT_FAILURE;
if (c1 == EOF)
printf("EOF on %s\n", filename1);
else if (c2 == EOF)
diff --git a/include/usage.h b/include/usage.h
index 1e3023d1f..d85857fb5 100644
--- a/include/usage.h
+++ b/include/usage.h
@@ -115,6 +115,7 @@
#define cmp_trivial_usage \
"FILE1 [FILE2]"
#define cmp_full_usage \
+ "\t-s\tquiet mode - do not print\n" \
"Compare files."
#define cp_trivial_usage \
diff --git a/usage.h b/usage.h
index 1e3023d1f..d85857fb5 100644
--- a/usage.h
+++ b/usage.h
@@ -115,6 +115,7 @@
#define cmp_trivial_usage \
"FILE1 [FILE2]"
#define cmp_full_usage \
+ "\t-s\tquiet mode - do not print\n" \
"Compare files."
#define cp_trivial_usage \