=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/diff/diff.c,v retrieving revision 1.5 retrieving revision 1.6 diff -c -r1.5 -r1.6 *** src/usr.bin/diff/diff.c 2003/06/25 07:26:59 1.5 --- src/usr.bin/diff/diff.c 2003/06/25 17:49:22 1.6 *************** *** 1,4 **** ! /* $OpenBSD: diff.c,v 1.5 2003/06/25 07:26:59 tedu Exp $ */ /* * Copyright (C) Caldera International Inc. 2001-2002. --- 1,4 ---- ! /* $OpenBSD: diff.c,v 1.6 2003/06/25 17:49:22 millert Exp $ */ /* * Copyright (C) Caldera International Inc. 2001-2002. *************** *** 53,196 **** char pr[] = _PATH_PR; static void noroom(void); int main(int argc, char **argv) { ! char *argp; ifdef1 = "FILE1"; ifdef2 = "FILE2"; status = 2; diffargv = argv; ! argc--, argv++; ! while (argc > 2 && argv[0][0] == '-') { ! argp = &argv[0][1]; ! argv++, argc--; ! while (*argp) ! switch (*argp++) { ! #ifdef notdef ! case 'I': ! opt = D_IFDEF; ! wantelses = 0; ! continue; ! case 'E': ! opt = D_IFDEF; ! wantelses = 1; ! continue; ! case '1': ! opt = D_IFDEF; ! ifdef1 = argp; ! *--argp = 0; ! continue; ! #endif ! case 'D': ! /* -Dfoo = -E -1 -2foo */ ! wantelses = 1; ! ifdef1 = ""; ! /* fall through */ ! #ifdef notdef ! case '2': ! #endif ! opt = D_IFDEF; ! ifdef2 = argp; ! *--argp = 0; ! continue; ! case 'e': ! opt = D_EDIT; ! continue; ! case 'f': ! opt = D_REVERSE; ! continue; ! case 'n': ! opt = D_NREVERSE; ! continue; ! case 'b': ! bflag = 1; ! continue; ! case 'w': ! wflag = 1; ! continue; ! case 'i': ! iflag = 1; ! continue; ! case 't': ! tflag = 1; ! continue; ! case 'c': ! opt = D_CONTEXT; ! if (isdigit(*argp)) { ! context = atoi(argp); ! while (isdigit(*argp)) ! argp++; ! if (*argp) { ! fprintf(stderr, ! "diff: -c: bad count\n"); ! done(0); ! } ! argp = ""; ! } else ! context = 3; ! continue; ! case 'h': ! hflag++; ! continue; ! case 'S': ! if (*argp == 0) { ! fprintf(stderr, "diff: use -Sstart\n"); ! done(0); ! } ! start = argp; ! *--argp = 0; /* don't pass it on */ ! continue; ! case 'r': ! rflag++; ! continue; ! case 's': ! sflag++; ! continue; ! case 'l': ! lflag++; ! continue; ! default: ! fprintf(stderr, "diff: -%s: unknown option\n", ! --argp); ! done(0); ! } } ! if (argc != 2) { ! fprintf(stderr, "diff: two filename arguments required\n"); ! done(0); ! } file1 = argv[0]; file2 = argv[1]; ! if (hflag && opt) { ! fprintf(stderr, ! "diff: -h doesn't support -e, -f, -n, -c, or -I\n"); ! done(0); ! } if (!strcmp(file1, "-")) stb1.st_mode = S_IFREG; ! else if (stat(file1, &stb1) < 0) { ! fprintf(stderr, "diff: "); ! perror(file1); ! done(0); ! } if (!strcmp(file2, "-")) stb2.st_mode = S_IFREG; ! else if (stat(file2, &stb2) < 0) { ! fprintf(stderr, "diff: "); ! perror(file2); ! done(0); ! } if ((stb1.st_mode & S_IFMT) == S_IFDIR && (stb2.st_mode & S_IFMT) == S_IFDIR) { diffdir(argv); } else diffreg(); done(0); - /* notreached */ - return (0); } int --- 53,153 ---- char pr[] = _PATH_PR; static void noroom(void); + __dead void usage(void); int main(int argc, char **argv) { ! int ch; ifdef1 = "FILE1"; ifdef2 = "FILE2"; status = 2; diffargv = argv; ! ! while ((ch = getopt(argc, argv, "bC:cDefhilnrS:stw")) != -1) { ! switch (ch) { ! case 'b': ! bflag++; ! break; ! case 'C': ! opt = D_CONTEXT; ! if (!isdigit(*optarg)) ! usage(); ! context = atoi(optarg); /* XXX - use strtol */ ! break; ! case 'c': ! opt = D_CONTEXT; ! context = 3; ! break; ! case 'D': ! /* -Dfoo = -E -1 -2foo */ ! opt = D_IFDEF; ! ifdef1 = ""; ! ifdef2 = optarg; ! wantelses++; ! break; ! case 'e': ! opt = D_EDIT; ! break; ! case 'f': ! opt = D_REVERSE; ! break; ! case 'h': ! hflag++; ! break; ! case 'i': ! iflag++; ! break; ! case 'l': ! lflag++; ! break; ! case 'n': ! opt = D_NREVERSE; ! break; ! case 'r': ! opt = D_REVERSE; ! break; ! case 'S': ! start = optarg; ! break; ! case 's': ! sflag++; ! break; ! case 't': ! tflag++; ! break; ! case 'w': ! wflag++; ! break; ! default: ! usage(); ! break; ! } } ! argc -= optind; ! argv += optind; ! ! if (argc != 2) ! errx(1, "two filename arguments required"); file1 = argv[0]; file2 = argv[1]; ! if (hflag && opt) ! errx(1, "-h doesn't support -D, -c, -C, -e, -f, -I or -n"); if (!strcmp(file1, "-")) stb1.st_mode = S_IFREG; ! else if (stat(file1, &stb1) < 0) ! err(1, "%s", file1); if (!strcmp(file2, "-")) stb2.st_mode = S_IFREG; ! else if (stat(file2, &stb2) < 0) ! err(1, "%s", file2); if ((stb1.st_mode & S_IFMT) == S_IFDIR && (stb2.st_mode & S_IFMT) == S_IFDIR) { diffdir(argv); } else diffreg(); done(0); } int *************** *** 207,213 **** return (a > b ? a : b); } ! void done(int sig) { if (tempfile) --- 164,170 ---- return (a > b ? a : b); } ! __dead void done(int sig) { if (tempfile) *************** *** 240,245 **** static void noroom(void) { ! fprintf(stderr, "diff: files too big, try -h\n"); done(0); } --- 197,212 ---- static void noroom(void) { ! warn("files too big, try -h"); done(0); + } + + __dead void + usage(void) + { + (void)fprintf(stderr, "usage: diff [-c | -C lines | -e | -f | -h | -n ] [-biwt] file1 file2\n" + "usage: diff [-Dstring] [-biw] file1 file2\n" + "usage: diff [-l] [-r] [-s] [-c | -C lines | -e | -f | -h | -n ] [-biwt]\n [-Sname] dir1 dir2\n"); + + exit(1); }