1*c9733229SMatthew Dillon /* $OpenBSD: diff.c,v 1.68 2023/01/05 00:00:44 millert Exp $ */
2*c9733229SMatthew Dillon
3*c9733229SMatthew Dillon /*
4*c9733229SMatthew Dillon * Copyright (c) 2003 Todd C. Miller <millert@openbsd.org>
5*c9733229SMatthew Dillon *
6*c9733229SMatthew Dillon * Permission to use, copy, modify, and distribute this software for any
7*c9733229SMatthew Dillon * purpose with or without fee is hereby granted, provided that the above
8*c9733229SMatthew Dillon * copyright notice and this permission notice appear in all copies.
9*c9733229SMatthew Dillon *
10*c9733229SMatthew Dillon * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11*c9733229SMatthew Dillon * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12*c9733229SMatthew Dillon * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13*c9733229SMatthew Dillon * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14*c9733229SMatthew Dillon * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15*c9733229SMatthew Dillon * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16*c9733229SMatthew Dillon * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*c9733229SMatthew Dillon *
18*c9733229SMatthew Dillon * Sponsored in part by the Defense Advanced Research Projects
19*c9733229SMatthew Dillon * Agency (DARPA) and Air Force Research Laboratory, Air Force
20*c9733229SMatthew Dillon * Materiel Command, USAF, under agreement number F39502-99-1-0512.
21*c9733229SMatthew Dillon */
22*c9733229SMatthew Dillon
23*c9733229SMatthew Dillon #include <sys/stat.h>
24*c9733229SMatthew Dillon
25*c9733229SMatthew Dillon #include <ctype.h>
26*c9733229SMatthew Dillon #include <err.h>
27*c9733229SMatthew Dillon #include <errno.h>
28*c9733229SMatthew Dillon #include <getopt.h>
29*c9733229SMatthew Dillon #include <stdlib.h>
30*c9733229SMatthew Dillon #include <stdio.h>
31*c9733229SMatthew Dillon #include <stdarg.h>
32*c9733229SMatthew Dillon #include <string.h>
33*c9733229SMatthew Dillon #include <unistd.h>
34*c9733229SMatthew Dillon #include <limits.h>
35*c9733229SMatthew Dillon
36*c9733229SMatthew Dillon #include "diff.h"
37*c9733229SMatthew Dillon #include "xmalloc.h"
38*c9733229SMatthew Dillon
39*c9733229SMatthew Dillon static const char diff_version[] = "DragonFlyBSD diff 20240601";
40*c9733229SMatthew Dillon int Nflag, Pflag, rflag, sflag, Tflag;
41*c9733229SMatthew Dillon int diff_format, diff_context, status;
42*c9733229SMatthew Dillon char *start, *ifdefname, *diffargs, *label[2], *ignore_pats;
43*c9733229SMatthew Dillon struct stat stb1, stb2;
44*c9733229SMatthew Dillon struct excludes *excludes_list;
45*c9733229SMatthew Dillon regex_t ignore_re;
46*c9733229SMatthew Dillon
47*c9733229SMatthew Dillon #define OPTIONS "0123456789abC:cdD:efhI:iL:nNPpqrS:sTtU:uwX:x:"
48*c9733229SMatthew Dillon static struct option longopts[] = {
49*c9733229SMatthew Dillon { "text", no_argument, 0, 'a' },
50*c9733229SMatthew Dillon { "ignore-space-change", no_argument, 0, 'b' },
51*c9733229SMatthew Dillon { "context", optional_argument, 0, 'C' },
52*c9733229SMatthew Dillon { "ifdef", required_argument, 0, 'D' },
53*c9733229SMatthew Dillon { "minimal", no_argument, 0, 'd' },
54*c9733229SMatthew Dillon { "ed", no_argument, 0, 'e' },
55*c9733229SMatthew Dillon { "forward-ed", no_argument, 0, 'f' },
56*c9733229SMatthew Dillon { "ignore-matching-lines", required_argument, 0, 'I' },
57*c9733229SMatthew Dillon { "ignore-case", no_argument, 0, 'i' },
58*c9733229SMatthew Dillon { "label", required_argument, 0, 'L' },
59*c9733229SMatthew Dillon { "new-file", no_argument, 0, 'N' },
60*c9733229SMatthew Dillon { "rcs", no_argument, 0, 'n' },
61*c9733229SMatthew Dillon { "unidirectional-new-file", no_argument, 0, 'P' },
62*c9733229SMatthew Dillon { "show-c-function", no_argument, 0, 'p' },
63*c9733229SMatthew Dillon { "brief", no_argument, 0, 'q' },
64*c9733229SMatthew Dillon { "recursive", no_argument, 0, 'r' },
65*c9733229SMatthew Dillon { "report-identical-files", no_argument, 0, 's' },
66*c9733229SMatthew Dillon { "starting-file", required_argument, 0, 'S' },
67*c9733229SMatthew Dillon { "expand-tabs", no_argument, 0, 't' },
68*c9733229SMatthew Dillon { "initial-tab", no_argument, 0, 'T' },
69*c9733229SMatthew Dillon { "unified", optional_argument, 0, 'U' },
70*c9733229SMatthew Dillon { "ignore-all-space", no_argument, 0, 'w' },
71*c9733229SMatthew Dillon { "exclude", required_argument, 0, 'x' },
72*c9733229SMatthew Dillon { "exclude-from", required_argument, 0, 'X' },
73*c9733229SMatthew Dillon { NULL, 0, 0, '\0'}
74*c9733229SMatthew Dillon };
75*c9733229SMatthew Dillon
76*c9733229SMatthew Dillon void usage(void);
77*c9733229SMatthew Dillon void push_excludes(char *);
78*c9733229SMatthew Dillon void push_ignore_pats(char *);
79*c9733229SMatthew Dillon void read_excludes_file(char *file);
80*c9733229SMatthew Dillon void set_argstr(char **, char **);
81*c9733229SMatthew Dillon
82*c9733229SMatthew Dillon int
main(int argc,char ** argv)83*c9733229SMatthew Dillon main(int argc, char **argv)
84*c9733229SMatthew Dillon {
85*c9733229SMatthew Dillon char *ep, **oargv;
86*c9733229SMatthew Dillon long l;
87*c9733229SMatthew Dillon int ch, dflags, lastch, gotstdin, prevoptind, newarg;
88*c9733229SMatthew Dillon
89*c9733229SMatthew Dillon oargv = argv;
90*c9733229SMatthew Dillon gotstdin = 0;
91*c9733229SMatthew Dillon dflags = 0;
92*c9733229SMatthew Dillon lastch = '\0';
93*c9733229SMatthew Dillon prevoptind = 1;
94*c9733229SMatthew Dillon newarg = 1;
95*c9733229SMatthew Dillon while ((ch = getopt_long(argc, argv, OPTIONS, longopts, NULL)) != -1) {
96*c9733229SMatthew Dillon switch (ch) {
97*c9733229SMatthew Dillon case '0': case '1': case '2': case '3': case '4':
98*c9733229SMatthew Dillon case '5': case '6': case '7': case '8': case '9':
99*c9733229SMatthew Dillon if (newarg)
100*c9733229SMatthew Dillon usage(); /* disallow -[0-9]+ */
101*c9733229SMatthew Dillon else if (lastch == 'c' || lastch == 'u')
102*c9733229SMatthew Dillon diff_context = 0;
103*c9733229SMatthew Dillon else if (!isdigit(lastch) || diff_context > INT_MAX / 10)
104*c9733229SMatthew Dillon usage();
105*c9733229SMatthew Dillon diff_context = (diff_context * 10) + (ch - '0');
106*c9733229SMatthew Dillon break;
107*c9733229SMatthew Dillon case 'a':
108*c9733229SMatthew Dillon dflags |= D_FORCEASCII;
109*c9733229SMatthew Dillon break;
110*c9733229SMatthew Dillon case 'b':
111*c9733229SMatthew Dillon dflags |= D_FOLDBLANKS;
112*c9733229SMatthew Dillon break;
113*c9733229SMatthew Dillon case 'C':
114*c9733229SMatthew Dillon case 'c':
115*c9733229SMatthew Dillon diff_format = D_CONTEXT;
116*c9733229SMatthew Dillon if (optarg != NULL) {
117*c9733229SMatthew Dillon l = strtol(optarg, &ep, 10);
118*c9733229SMatthew Dillon if (*ep != '\0' || l < 0 || l >= INT_MAX)
119*c9733229SMatthew Dillon usage();
120*c9733229SMatthew Dillon diff_context = (int)l;
121*c9733229SMatthew Dillon } else
122*c9733229SMatthew Dillon diff_context = 3;
123*c9733229SMatthew Dillon break;
124*c9733229SMatthew Dillon case 'd':
125*c9733229SMatthew Dillon dflags |= D_MINIMAL;
126*c9733229SMatthew Dillon break;
127*c9733229SMatthew Dillon case 'D':
128*c9733229SMatthew Dillon diff_format = D_IFDEF;
129*c9733229SMatthew Dillon ifdefname = optarg;
130*c9733229SMatthew Dillon break;
131*c9733229SMatthew Dillon case 'e':
132*c9733229SMatthew Dillon diff_format = D_EDIT;
133*c9733229SMatthew Dillon break;
134*c9733229SMatthew Dillon case 'f':
135*c9733229SMatthew Dillon diff_format = D_REVERSE;
136*c9733229SMatthew Dillon break;
137*c9733229SMatthew Dillon case 'h':
138*c9733229SMatthew Dillon /* silently ignore for backwards compatibility */
139*c9733229SMatthew Dillon break;
140*c9733229SMatthew Dillon case 'I':
141*c9733229SMatthew Dillon push_ignore_pats(optarg);
142*c9733229SMatthew Dillon break;
143*c9733229SMatthew Dillon case 'i':
144*c9733229SMatthew Dillon dflags |= D_IGNORECASE;
145*c9733229SMatthew Dillon break;
146*c9733229SMatthew Dillon case 'L':
147*c9733229SMatthew Dillon if (label[0] == NULL)
148*c9733229SMatthew Dillon label[0] = optarg;
149*c9733229SMatthew Dillon else if (label[1] == NULL)
150*c9733229SMatthew Dillon label[1] = optarg;
151*c9733229SMatthew Dillon else
152*c9733229SMatthew Dillon usage();
153*c9733229SMatthew Dillon break;
154*c9733229SMatthew Dillon case 'N':
155*c9733229SMatthew Dillon Nflag = 1;
156*c9733229SMatthew Dillon break;
157*c9733229SMatthew Dillon case 'n':
158*c9733229SMatthew Dillon diff_format = D_NREVERSE;
159*c9733229SMatthew Dillon break;
160*c9733229SMatthew Dillon case 'p':
161*c9733229SMatthew Dillon dflags |= D_PROTOTYPE;
162*c9733229SMatthew Dillon break;
163*c9733229SMatthew Dillon case 'P':
164*c9733229SMatthew Dillon Pflag = 1;
165*c9733229SMatthew Dillon break;
166*c9733229SMatthew Dillon case 'r':
167*c9733229SMatthew Dillon rflag = 1;
168*c9733229SMatthew Dillon break;
169*c9733229SMatthew Dillon case 'q':
170*c9733229SMatthew Dillon diff_format = D_BRIEF;
171*c9733229SMatthew Dillon break;
172*c9733229SMatthew Dillon case 'S':
173*c9733229SMatthew Dillon start = optarg;
174*c9733229SMatthew Dillon break;
175*c9733229SMatthew Dillon case 's':
176*c9733229SMatthew Dillon sflag = 1;
177*c9733229SMatthew Dillon break;
178*c9733229SMatthew Dillon case 'T':
179*c9733229SMatthew Dillon Tflag = 1;
180*c9733229SMatthew Dillon break;
181*c9733229SMatthew Dillon case 't':
182*c9733229SMatthew Dillon dflags |= D_EXPANDTABS;
183*c9733229SMatthew Dillon break;
184*c9733229SMatthew Dillon case 'U':
185*c9733229SMatthew Dillon case 'u':
186*c9733229SMatthew Dillon diff_format = D_UNIFIED;
187*c9733229SMatthew Dillon if (optarg != NULL) {
188*c9733229SMatthew Dillon l = strtol(optarg, &ep, 10);
189*c9733229SMatthew Dillon if (*ep != '\0' || l < 0 || l >= INT_MAX)
190*c9733229SMatthew Dillon usage();
191*c9733229SMatthew Dillon diff_context = (int)l;
192*c9733229SMatthew Dillon } else
193*c9733229SMatthew Dillon diff_context = 3;
194*c9733229SMatthew Dillon break;
195*c9733229SMatthew Dillon case 'v':
196*c9733229SMatthew Dillon printf("%s\n", diff_version);
197*c9733229SMatthew Dillon exit(0);
198*c9733229SMatthew Dillon case 'w':
199*c9733229SMatthew Dillon dflags |= D_IGNOREBLANKS;
200*c9733229SMatthew Dillon break;
201*c9733229SMatthew Dillon case 'X':
202*c9733229SMatthew Dillon read_excludes_file(optarg);
203*c9733229SMatthew Dillon break;
204*c9733229SMatthew Dillon case 'x':
205*c9733229SMatthew Dillon push_excludes(optarg);
206*c9733229SMatthew Dillon break;
207*c9733229SMatthew Dillon default:
208*c9733229SMatthew Dillon usage();
209*c9733229SMatthew Dillon break;
210*c9733229SMatthew Dillon }
211*c9733229SMatthew Dillon lastch = ch;
212*c9733229SMatthew Dillon newarg = optind != prevoptind;
213*c9733229SMatthew Dillon prevoptind = optind;
214*c9733229SMatthew Dillon }
215*c9733229SMatthew Dillon argc -= optind;
216*c9733229SMatthew Dillon argv += optind;
217*c9733229SMatthew Dillon
218*c9733229SMatthew Dillon /*
219*c9733229SMatthew Dillon * Do sanity checks, fill in stb1 and stb2 and call the appropriate
220*c9733229SMatthew Dillon * driver routine. Both drivers use the contents of stb1 and stb2.
221*c9733229SMatthew Dillon */
222*c9733229SMatthew Dillon if (argc != 2)
223*c9733229SMatthew Dillon usage();
224*c9733229SMatthew Dillon if (ignore_pats != NULL) {
225*c9733229SMatthew Dillon char buf[BUFSIZ];
226*c9733229SMatthew Dillon int error;
227*c9733229SMatthew Dillon
228*c9733229SMatthew Dillon if ((error = regcomp(&ignore_re, ignore_pats,
229*c9733229SMatthew Dillon REG_NEWLINE | REG_EXTENDED)) != 0) {
230*c9733229SMatthew Dillon regerror(error, &ignore_re, buf, sizeof(buf));
231*c9733229SMatthew Dillon if (*ignore_pats != '\0')
232*c9733229SMatthew Dillon errx(2, "%s: %s", ignore_pats, buf);
233*c9733229SMatthew Dillon else
234*c9733229SMatthew Dillon errx(2, "%s", buf);
235*c9733229SMatthew Dillon }
236*c9733229SMatthew Dillon }
237*c9733229SMatthew Dillon if (strcmp(argv[0], "-") == 0) {
238*c9733229SMatthew Dillon fstat(STDIN_FILENO, &stb1);
239*c9733229SMatthew Dillon gotstdin = 1;
240*c9733229SMatthew Dillon } else if (stat(argv[0], &stb1) != 0)
241*c9733229SMatthew Dillon err(2, "%s", argv[0]);
242*c9733229SMatthew Dillon if (strcmp(argv[1], "-") == 0) {
243*c9733229SMatthew Dillon fstat(STDIN_FILENO, &stb2);
244*c9733229SMatthew Dillon gotstdin = 1;
245*c9733229SMatthew Dillon } else if (stat(argv[1], &stb2) != 0)
246*c9733229SMatthew Dillon err(2, "%s", argv[1]);
247*c9733229SMatthew Dillon if (gotstdin && (S_ISDIR(stb1.st_mode) || S_ISDIR(stb2.st_mode)))
248*c9733229SMatthew Dillon errx(2, "can't compare - to a directory");
249*c9733229SMatthew Dillon set_argstr(oargv, argv);
250*c9733229SMatthew Dillon if (S_ISDIR(stb1.st_mode) && S_ISDIR(stb2.st_mode)) {
251*c9733229SMatthew Dillon if (diff_format == D_IFDEF)
252*c9733229SMatthew Dillon errx(2, "-D option not supported with directories");
253*c9733229SMatthew Dillon diffdir(argv[0], argv[1], dflags);
254*c9733229SMatthew Dillon } else {
255*c9733229SMatthew Dillon if (S_ISDIR(stb1.st_mode)) {
256*c9733229SMatthew Dillon argv[0] = splice(argv[0], argv[1]);
257*c9733229SMatthew Dillon if (stat(argv[0], &stb1) == -1)
258*c9733229SMatthew Dillon err(2, "%s", argv[0]);
259*c9733229SMatthew Dillon }
260*c9733229SMatthew Dillon if (S_ISDIR(stb2.st_mode)) {
261*c9733229SMatthew Dillon argv[1] = splice(argv[1], argv[0]);
262*c9733229SMatthew Dillon if (stat(argv[1], &stb2) == -1)
263*c9733229SMatthew Dillon err(2, "%s", argv[1]);
264*c9733229SMatthew Dillon }
265*c9733229SMatthew Dillon print_status(diffreg(argv[0], argv[1], dflags), argv[0], argv[1],
266*c9733229SMatthew Dillon "");
267*c9733229SMatthew Dillon }
268*c9733229SMatthew Dillon exit(status);
269*c9733229SMatthew Dillon }
270*c9733229SMatthew Dillon
271*c9733229SMatthew Dillon void
set_argstr(char ** av,char ** ave)272*c9733229SMatthew Dillon set_argstr(char **av, char **ave)
273*c9733229SMatthew Dillon {
274*c9733229SMatthew Dillon size_t argsize;
275*c9733229SMatthew Dillon char **ap;
276*c9733229SMatthew Dillon
277*c9733229SMatthew Dillon argsize = 4 + *ave - *av + 1;
278*c9733229SMatthew Dillon diffargs = xmalloc(argsize);
279*c9733229SMatthew Dillon strlcpy(diffargs, "diff", argsize);
280*c9733229SMatthew Dillon for (ap = av + 1; ap < ave; ap++) {
281*c9733229SMatthew Dillon if (strcmp(*ap, "--") != 0) {
282*c9733229SMatthew Dillon strlcat(diffargs, " ", argsize);
283*c9733229SMatthew Dillon strlcat(diffargs, *ap, argsize);
284*c9733229SMatthew Dillon }
285*c9733229SMatthew Dillon }
286*c9733229SMatthew Dillon }
287*c9733229SMatthew Dillon
288*c9733229SMatthew Dillon /*
289*c9733229SMatthew Dillon * Read in an excludes file and push each line.
290*c9733229SMatthew Dillon */
291*c9733229SMatthew Dillon void
read_excludes_file(char * file)292*c9733229SMatthew Dillon read_excludes_file(char *file)
293*c9733229SMatthew Dillon {
294*c9733229SMatthew Dillon FILE *fp;
295*c9733229SMatthew Dillon char *buf, *pattern;
296*c9733229SMatthew Dillon size_t len;
297*c9733229SMatthew Dillon
298*c9733229SMatthew Dillon if (strcmp(file, "-") == 0)
299*c9733229SMatthew Dillon fp = stdin;
300*c9733229SMatthew Dillon else if ((fp = fopen(file, "r")) == NULL)
301*c9733229SMatthew Dillon err(2, "%s", file);
302*c9733229SMatthew Dillon while ((buf = fgetln(fp, &len)) != NULL) {
303*c9733229SMatthew Dillon if (buf[len - 1] == '\n')
304*c9733229SMatthew Dillon len--;
305*c9733229SMatthew Dillon pattern = xmalloc(len + 1);
306*c9733229SMatthew Dillon memcpy(pattern, buf, len);
307*c9733229SMatthew Dillon pattern[len] = '\0';
308*c9733229SMatthew Dillon push_excludes(pattern);
309*c9733229SMatthew Dillon }
310*c9733229SMatthew Dillon if (strcmp(file, "-") != 0)
311*c9733229SMatthew Dillon fclose(fp);
312*c9733229SMatthew Dillon }
313*c9733229SMatthew Dillon
314*c9733229SMatthew Dillon /*
315*c9733229SMatthew Dillon * Push a pattern onto the excludes list.
316*c9733229SMatthew Dillon */
317*c9733229SMatthew Dillon void
push_excludes(char * pattern)318*c9733229SMatthew Dillon push_excludes(char *pattern)
319*c9733229SMatthew Dillon {
320*c9733229SMatthew Dillon struct excludes *entry;
321*c9733229SMatthew Dillon
322*c9733229SMatthew Dillon entry = xmalloc(sizeof(*entry));
323*c9733229SMatthew Dillon entry->pattern = pattern;
324*c9733229SMatthew Dillon entry->next = excludes_list;
325*c9733229SMatthew Dillon excludes_list = entry;
326*c9733229SMatthew Dillon }
327*c9733229SMatthew Dillon
328*c9733229SMatthew Dillon void
push_ignore_pats(char * pattern)329*c9733229SMatthew Dillon push_ignore_pats(char *pattern)
330*c9733229SMatthew Dillon {
331*c9733229SMatthew Dillon size_t len;
332*c9733229SMatthew Dillon
333*c9733229SMatthew Dillon if (ignore_pats == NULL)
334*c9733229SMatthew Dillon ignore_pats = xstrdup(pattern);
335*c9733229SMatthew Dillon else {
336*c9733229SMatthew Dillon /* old + "|" + new + NUL */
337*c9733229SMatthew Dillon len = strlen(ignore_pats) + strlen(pattern) + 2;
338*c9733229SMatthew Dillon ignore_pats = xreallocarray(ignore_pats, 1, len);
339*c9733229SMatthew Dillon strlcat(ignore_pats, "|", len);
340*c9733229SMatthew Dillon strlcat(ignore_pats, pattern, len);
341*c9733229SMatthew Dillon }
342*c9733229SMatthew Dillon }
343*c9733229SMatthew Dillon
344*c9733229SMatthew Dillon void
print_only(const char * path,size_t dirlen,const char * entry)345*c9733229SMatthew Dillon print_only(const char *path, size_t dirlen, const char *entry)
346*c9733229SMatthew Dillon {
347*c9733229SMatthew Dillon if (dirlen > 1)
348*c9733229SMatthew Dillon dirlen--;
349*c9733229SMatthew Dillon printf("Only in %.*s: %s\n", (int)dirlen, path, entry);
350*c9733229SMatthew Dillon }
351*c9733229SMatthew Dillon
352*c9733229SMatthew Dillon void
print_status(int val,char * path1,char * path2,const char * entry)353*c9733229SMatthew Dillon print_status(int val, char *path1, char *path2, const char *entry)
354*c9733229SMatthew Dillon {
355*c9733229SMatthew Dillon switch (val) {
356*c9733229SMatthew Dillon case D_BINARY:
357*c9733229SMatthew Dillon printf("Binary files %s%s and %s%s differ\n",
358*c9733229SMatthew Dillon path1, entry, path2, entry);
359*c9733229SMatthew Dillon break;
360*c9733229SMatthew Dillon case D_DIFFER:
361*c9733229SMatthew Dillon if (diff_format == D_BRIEF)
362*c9733229SMatthew Dillon printf("Files %s%s and %s%s differ\n",
363*c9733229SMatthew Dillon path1, entry, path2, entry);
364*c9733229SMatthew Dillon break;
365*c9733229SMatthew Dillon case D_SAME:
366*c9733229SMatthew Dillon if (sflag)
367*c9733229SMatthew Dillon printf("Files %s%s and %s%s are identical\n",
368*c9733229SMatthew Dillon path1, entry, path2, entry);
369*c9733229SMatthew Dillon break;
370*c9733229SMatthew Dillon case D_MISMATCH1:
371*c9733229SMatthew Dillon printf("File %s%s is a directory while file %s%s is a regular file\n",
372*c9733229SMatthew Dillon path1, entry, path2, entry);
373*c9733229SMatthew Dillon break;
374*c9733229SMatthew Dillon case D_MISMATCH2:
375*c9733229SMatthew Dillon printf("File %s%s is a regular file while file %s%s is a directory\n",
376*c9733229SMatthew Dillon path1, entry, path2, entry);
377*c9733229SMatthew Dillon break;
378*c9733229SMatthew Dillon case D_SKIPPED1:
379*c9733229SMatthew Dillon printf("File %s%s is not a regular file or directory and was skipped\n",
380*c9733229SMatthew Dillon path1, entry);
381*c9733229SMatthew Dillon break;
382*c9733229SMatthew Dillon case D_SKIPPED2:
383*c9733229SMatthew Dillon printf("File %s%s is not a regular file or directory and was skipped\n",
384*c9733229SMatthew Dillon path2, entry);
385*c9733229SMatthew Dillon break;
386*c9733229SMatthew Dillon }
387*c9733229SMatthew Dillon }
388*c9733229SMatthew Dillon
389*c9733229SMatthew Dillon void
usage(void)390*c9733229SMatthew Dillon usage(void)
391*c9733229SMatthew Dillon {
392*c9733229SMatthew Dillon (void)fprintf(stderr,
393*c9733229SMatthew Dillon "usage: diff [-abdipTtw] [-c | -e | -f | -n | -q | -u] [-I pattern] [-L label]\n"
394*c9733229SMatthew Dillon " file1 file2\n"
395*c9733229SMatthew Dillon " diff [-abdipTtw] [-I pattern] [-L label] -C number file1 file2\n"
396*c9733229SMatthew Dillon " diff [-abditw] [-I pattern] -D string file1 file2\n"
397*c9733229SMatthew Dillon " diff [-abdipTtw] [-I pattern] [-L label] -U number file1 file2\n"
398*c9733229SMatthew Dillon " diff [-abdiNPprsTtw] [-c | -e | -f | -n | -q | -u] [-I pattern]\n"
399*c9733229SMatthew Dillon " [-L label] [-S name] [-X file] [-x pattern] dir1 dir2\n");
400*c9733229SMatthew Dillon
401*c9733229SMatthew Dillon exit(2);
402*c9733229SMatthew Dillon }
403