=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/sdiff/sdiff.c,v retrieving revision 1.27 retrieving revision 1.28 diff -c -r1.27 -r1.28 *** src/usr.bin/sdiff/sdiff.c 2009/06/07 13:15:13 1.27 --- src/usr.bin/sdiff/sdiff.c 2009/06/07 13:29:50 1.28 *************** *** 1,4 **** ! /* $OpenBSD: sdiff.c,v 1.27 2009/06/07 13:15:13 ray Exp $ */ /* * Written by Raymond Lai . --- 1,4 ---- ! /* $OpenBSD: sdiff.c,v 1.28 2009/06/07 13:29:50 ray Exp $ */ /* * Written by Raymond Lai . *************** *** 65,71 **** int Iflag = 0; /* ignore sets matching regexp */ int lflag; /* print only left column for identical lines */ int sflag; /* skip identical lines */ ! FILE *outfile; /* file to save changes to */ const char *tmpdir; /* TMPDIR or /tmp */ static struct option longopts[] = { --- 65,71 ---- int Iflag = 0; /* ignore sets matching regexp */ int lflag; /* print only left column for identical lines */ int sflag; /* skip identical lines */ ! FILE *outfp; /* file to save changes to */ const char *tmpdir; /* TMPDIR or /tmp */ static struct option longopts[] = { *************** *** 160,165 **** --- 160,166 ---- size_t diffargc = 0, wflag = WIDTH; int ch, fd[2], status; pid_t pid; + const char *outfile = NULL; char **diffargv, *diffprog = "diff", *filename1, *filename2, *tmp1, *tmp2, *s1, *s2; *************** *** 218,225 **** lflag = 1; break; case 'o': ! if ((outfile = fopen(optarg, "w")) == NULL) ! err(2, "could not open: %s", optarg); break; case 'S': diffargv[diffargc++] = "--strip-trailing-cr"; --- 219,225 ---- lflag = 1; break; case 'o': ! outfile = optarg; break; case 'S': diffargv[diffargc++] = "--strip-trailing-cr"; *************** *** 250,255 **** --- 250,258 ---- if (argc != 2) usage(); + if (outfile && (outfp = fopen(outfile, "w")) == NULL) + err(2, "could not open: %s", optarg); + if ((tmpdir = getenv("TMPDIR")) == NULL || *tmpdir == '\0') tmpdir = _PATH_TMP; *************** *** 375,381 **** static void printcol(const char *s, size_t *col, const size_t col_max) { - for (; *s && *col < col_max; ++s) { size_t new_col; --- 378,383 ---- *************** *** 441,447 **** case '1': /* Choose left column as-is. */ if (s1 != NULL) ! fprintf(outfile, "%s\n", s1); /* End of command parsing. */ break; --- 443,449 ---- case '1': /* Choose left column as-is. */ if (s1 != NULL) ! fprintf(outfp, "%s\n", s1); /* End of command parsing. */ break; *************** *** 453,459 **** case '2': /* Choose right column as-is. */ if (s2 != NULL) ! fprintf(outfile, "%s\n", s2); /* End of command parsing. */ break; --- 455,461 ---- case '2': /* Choose right column as-is. */ if (s2 != NULL) ! fprintf(outfp, "%s\n", s2); /* End of command parsing. */ break; *************** *** 486,492 **** * should quit. */ QUIT: ! fclose(outfile); exit(0); } --- 488,494 ---- * should quit. */ QUIT: ! fclose(outfp); exit(0); } *************** *** 886,896 **** freediff(diffp); } ! /* Write to outfile, prompting user if lines are different. */ ! if (outfile) switch (divc) { case ' ': case '(': case ')': ! fprintf(outfile, "%s\n", left); break; case '|': case '<': case '>': prompt(left, right); --- 888,898 ---- freediff(diffp); } ! /* Write to outfp, prompting user if lines are different. */ ! if (outfp) switch (divc) { case ' ': case '(': case ')': ! fprintf(outfp, "%s\n", left); break; case '|': case '<': case '>': prompt(left, right);