Date: Fri, 4 Jul 2008 20:12:56 GMT From: Gabor Kovesdan <gabor@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 144660 for review Message-ID: <200807042012.m64KCuj5064702@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=144660 Change 144660 by gabor@gabor_server on 2008/07/04 20:12:48 - Implement --from-file and --to-file Affected files ... .. //depot/projects/soc2008/gabor_textproc/diff/diff.c#9 edit Differences ... ==== //depot/projects/soc2008/gabor_textproc/diff/diff.c#9 (text+ko) ==== @@ -58,7 +58,9 @@ HELP_OPT = CHAR_MAX + 1, NORMAL_OPT, FCASE_SENSITIVE_OPT, - FCASE_IGNORE_OPT + FCASE_IGNORE_OPT, + FROMFILE_OPT, + TOFILE_OPT }; #define OPTIONS "0123456789abC:cdD:efhI:iL:lnNPpqrS:sTtU:uvwX:x:" @@ -75,9 +77,10 @@ { "line-format", required_argument, NULL, OPT_LF }, { "LTYPE-line-format", required_argument, NULL, OPT_LLF }, { "tabsize", optional_argument, NULL, OPT_TSIZE }, - { "unidirectional-new-file", no_argument, NULL, OPT_UNINF }, - { "from-file", required_argument, NULL, OPT_FFILE }, - { "to-file", required_argument, NULL, OPT_TOFILE }, + { "unidirectional-new-file", no_argument, NULL, OPT_UNINF }, */ + { "from-file", required_argument, NULL, FROMFILE_OPT }, + { "to-file", required_argument, NULL, TOFILE_OPT }, +/* XXX: UNIMPLEMENTED { "horizon-lines", required_argument, NULL, OPT_HLINES }, { "speed-large-files", no_argument, NULL, OPT_LFILES }, */ { "help", no_argument, NULL, HELP_OPT }, @@ -129,8 +132,9 @@ int main(int argc, char **argv) { - char *ep, **oargv; + char *ep, *fromfile = NULL, *tofile = NULL, **oargv; int ch, lastch, gotstdin, prevoptind, newarg; + char *dst, *src; oargv = argv; gotstdin = 0; @@ -252,10 +256,22 @@ case 'x': push_excludes(optarg); break; + case FROMFILE_OPT: + if (tofile != NULL) + err(2, "--from-file and --to-file are both specified"); + asprintf(&fromfile, "%s", optarg); + break; + case TOFILE_OPT: + if (fromfile != NULL) + err(2, "--from-file and --to-file are both specified"); + asprintf(&tofile, "%s", optarg); + break; case FCASE_SENSITIVE_OPT: + /* this is the default */ break; case FCASE_IGNORE_OPT: fcase_behave = FCASE_IGNORE; + break; case NORMAL_OPT: /* compatibility, this is the default */ break; @@ -275,7 +291,11 @@ * Do sanity checks, fill in stb1 and stb2 and call the appropriate * driver routine. Both drivers use the contents of stb1 and stb2. */ - if (argc != 2) + if (fromfile != NULL || tofile != NULL) { + if (argc < 1) + usage(); + } + else if (argc != 2 ) usage(); if (ignore_pats != NULL) { char buf[BUFSIZ]; @@ -290,36 +310,58 @@ errx(2, "%s", buf); } } - if (strcmp(argv[0], "-") == 0) { - fstat(STDIN_FILENO, &stb1); - gotstdin = 1; - } else if (stat(argv[0], &stb1) != 0) - err(2, "%s", argv[0]); - if (strcmp(argv[1], "-") == 0) { - fstat(STDIN_FILENO, &stb2); - gotstdin = 1; - } else if (stat(argv[1], &stb2) != 0) - err(2, "%s", argv[1]); - if (gotstdin && (S_ISDIR(stb1.st_mode) || S_ISDIR(stb2.st_mode))) - errx(2, "can't compare - to a directory"); - set_argstr(oargv, argv); - if (S_ISDIR(stb1.st_mode) && S_ISDIR(stb2.st_mode)) { - if (format == D_IFDEF) - errx(2, "-D option not supported with directories"); - diffdir(argv[0], argv[1]); + + if (fromfile != NULL) { + src = fromfile; + dst = argv[0]; + } else if (tofile != NULL) { + dst = tofile; + src = argv[0]; } else { - if (S_ISDIR(stb1.st_mode)) { - argv[0] = splice(argv[0], argv[1]); - if (stat(argv[0], &stb1) < 0) - err(2, "%s", argv[0]); + src = argv[0]; + dst = argv[1]; + } + + for (ch = 1; src && dst;ch++) { + if (strcmp(src, "-") == 0) { + fstat(STDIN_FILENO, &stb1); + gotstdin = 1; + } else if (stat(src, &stb1) != 0) + err(2, "%s", src); + if (strcmp(dst, "-") == 0) { + fstat(STDIN_FILENO, &stb2); + gotstdin = 1; + } else if (stat(dst, &stb2) != 0) + err(2, "%s", dst); + if (gotstdin && (S_ISDIR(stb1.st_mode) || S_ISDIR(stb2.st_mode))) + errx(2, "can't compare - to a directory"); +/* XXX: ??? + set_argstr(oargv, argv); */ + if (S_ISDIR(stb1.st_mode) && S_ISDIR(stb2.st_mode)) { + if (format == D_IFDEF) + errx(2, "-D option not supported with directories"); + diffdir(src, dst); + } else { + if (S_ISDIR(stb1.st_mode)) { + src = splice(src, dst); + if (stat(argv[0], &stb1) < 0) + err(2, "%s", argv[0]); + } + if (S_ISDIR(stb2.st_mode)) { + argv[1] = splice(dst, src); + if (stat(argv[1], &stb2) < 0) + err(2, "%s", argv[1]); + } + print_status(diffreg(src, dst, 0), src, dst, + NULL); + if (fromfile != NULL) + dst = argv[ch]; + else if (tofile != NULL) + src = argv[ch]; + else + break; } - if (S_ISDIR(stb2.st_mode)) { - argv[1] = splice(argv[1], argv[0]); - if (stat(argv[1], &stb2) < 0) - err(2, "%s", argv[1]); - } - print_status(diffreg(argv[0], argv[1], 0), argv[0], argv[1], - NULL); + } exit(status); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200807042012.m64KCuj5064702>