Applied patch from I.Q. to add -s to cmp.

This commit is contained in:
Mark Whitley 2001-04-25 20:41:02 +00:00
parent c29c44c00e
commit 207587a9b4
5 changed files with 49 additions and 18 deletions

View File

@ -115,6 +115,7 @@
#define cmp_trivial_usage \ #define cmp_trivial_usage \
"FILE1 [FILE2]" "FILE1 [FILE2]"
#define cmp_full_usage \ #define cmp_full_usage \
"\t-s\tquiet mode - do not print\n" \
"Compare files." "Compare files."
#define cp_trivial_usage \ #define cp_trivial_usage \

32
cmp.c
View File

@ -26,28 +26,42 @@
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <stdlib.h> #include <stdlib.h>
#include <getopt.h>
#include "busybox.h" #include "busybox.h"
int cmp_main(int argc, char **argv) int cmp_main(int argc, char **argv)
{ {
FILE *fp1 = NULL, *fp2 = stdin; FILE *fp1 = NULL, *fp2 = stdin;
char *filename1 = argv[1], *filename2 = "-"; char *filename1, *filename2 = "-";
int c1, c2, char_pos = 1, line_pos = 1; int c, c1, c2, char_pos = 1, line_pos = 1, silent = FALSE;
/* parse argv[] */ while ((c = getopt(argc, argv, "s")) != EOF) {
if (argc < 2 || 3 < argc) switch (c) {
show_usage(); case 's':
silent = TRUE;
break;
default:
show_usage();
}
}
fp1 = xfopen(argv[1], "r"); filename1 = argv[optind];
if (argv[2] != NULL) { switch (argc - optind) {
fp2 = xfopen(argv[2], "r"); case 2:
filename2 = argv[2]; fp2 = xfopen(filename2 = argv[optind + 1], "r");
case 1:
fp1 = xfopen(filename1, "r");
break;
default:
show_usage();
} }
do { do {
c1 = fgetc(fp1); c1 = fgetc(fp1);
c2 = fgetc(fp2); c2 = fgetc(fp2);
if (c1 != c2) { if (c1 != c2) {
if (silent)
return EXIT_FAILURE;
if (c1 == EOF) if (c1 == EOF)
printf("EOF on %s\n", filename1); printf("EOF on %s\n", filename1);
else if (c2 == EOF) else if (c2 == EOF)

View File

@ -26,28 +26,42 @@
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <stdlib.h> #include <stdlib.h>
#include <getopt.h>
#include "busybox.h" #include "busybox.h"
int cmp_main(int argc, char **argv) int cmp_main(int argc, char **argv)
{ {
FILE *fp1 = NULL, *fp2 = stdin; FILE *fp1 = NULL, *fp2 = stdin;
char *filename1 = argv[1], *filename2 = "-"; char *filename1, *filename2 = "-";
int c1, c2, char_pos = 1, line_pos = 1; int c, c1, c2, char_pos = 1, line_pos = 1, silent = FALSE;
/* parse argv[] */ while ((c = getopt(argc, argv, "s")) != EOF) {
if (argc < 2 || 3 < argc) switch (c) {
show_usage(); case 's':
silent = TRUE;
break;
default:
show_usage();
}
}
fp1 = xfopen(argv[1], "r"); filename1 = argv[optind];
if (argv[2] != NULL) { switch (argc - optind) {
fp2 = xfopen(argv[2], "r"); case 2:
filename2 = argv[2]; fp2 = xfopen(filename2 = argv[optind + 1], "r");
case 1:
fp1 = xfopen(filename1, "r");
break;
default:
show_usage();
} }
do { do {
c1 = fgetc(fp1); c1 = fgetc(fp1);
c2 = fgetc(fp2); c2 = fgetc(fp2);
if (c1 != c2) { if (c1 != c2) {
if (silent)
return EXIT_FAILURE;
if (c1 == EOF) if (c1 == EOF)
printf("EOF on %s\n", filename1); printf("EOF on %s\n", filename1);
else if (c2 == EOF) else if (c2 == EOF)

View File

@ -115,6 +115,7 @@
#define cmp_trivial_usage \ #define cmp_trivial_usage \
"FILE1 [FILE2]" "FILE1 [FILE2]"
#define cmp_full_usage \ #define cmp_full_usage \
"\t-s\tquiet mode - do not print\n" \
"Compare files." "Compare files."
#define cp_trivial_usage \ #define cp_trivial_usage \

View File

@ -115,6 +115,7 @@
#define cmp_trivial_usage \ #define cmp_trivial_usage \
"FILE1 [FILE2]" "FILE1 [FILE2]"
#define cmp_full_usage \ #define cmp_full_usage \
"\t-s\tquiet mode - do not print\n" \
"Compare files." "Compare files."
#define cp_trivial_usage \ #define cp_trivial_usage \