version 1.27, 2009/06/07 13:15:13 |
version 1.28, 2009/06/07 13:29:50 |
|
|
int Iflag = 0; /* ignore sets matching regexp */ |
int Iflag = 0; /* ignore sets matching regexp */ |
int lflag; /* print only left column for identical lines */ |
int lflag; /* print only left column for identical lines */ |
int sflag; /* skip identical lines */ |
int sflag; /* skip identical lines */ |
FILE *outfile; /* file to save changes to */ |
FILE *outfp; /* file to save changes to */ |
const char *tmpdir; /* TMPDIR or /tmp */ |
const char *tmpdir; /* TMPDIR or /tmp */ |
|
|
static struct option longopts[] = { |
static struct option longopts[] = { |
|
|
size_t diffargc = 0, wflag = WIDTH; |
size_t diffargc = 0, wflag = WIDTH; |
int ch, fd[2], status; |
int ch, fd[2], status; |
pid_t pid; |
pid_t pid; |
|
const char *outfile = NULL; |
char **diffargv, *diffprog = "diff", *filename1, *filename2, |
char **diffargv, *diffprog = "diff", *filename1, *filename2, |
*tmp1, *tmp2, *s1, *s2; |
*tmp1, *tmp2, *s1, *s2; |
|
|
|
|
lflag = 1; |
lflag = 1; |
break; |
break; |
case 'o': |
case 'o': |
if ((outfile = fopen(optarg, "w")) == NULL) |
outfile = optarg; |
err(2, "could not open: %s", optarg); |
|
break; |
break; |
case 'S': |
case 'S': |
diffargv[diffargc++] = "--strip-trailing-cr"; |
diffargv[diffargc++] = "--strip-trailing-cr"; |
|
|
if (argc != 2) |
if (argc != 2) |
usage(); |
usage(); |
|
|
|
if (outfile && (outfp = fopen(outfile, "w")) == NULL) |
|
err(2, "could not open: %s", optarg); |
|
|
if ((tmpdir = getenv("TMPDIR")) == NULL || *tmpdir == '\0') |
if ((tmpdir = getenv("TMPDIR")) == NULL || *tmpdir == '\0') |
tmpdir = _PATH_TMP; |
tmpdir = _PATH_TMP; |
|
|
|
|
static void |
static void |
printcol(const char *s, size_t *col, const size_t col_max) |
printcol(const char *s, size_t *col, const size_t col_max) |
{ |
{ |
|
|
for (; *s && *col < col_max; ++s) { |
for (; *s && *col < col_max; ++s) { |
size_t new_col; |
size_t new_col; |
|
|
|
|
case '1': |
case '1': |
/* Choose left column as-is. */ |
/* Choose left column as-is. */ |
if (s1 != NULL) |
if (s1 != NULL) |
fprintf(outfile, "%s\n", s1); |
fprintf(outfp, "%s\n", s1); |
|
|
/* End of command parsing. */ |
/* End of command parsing. */ |
break; |
break; |
|
|
case '2': |
case '2': |
/* Choose right column as-is. */ |
/* Choose right column as-is. */ |
if (s2 != NULL) |
if (s2 != NULL) |
fprintf(outfile, "%s\n", s2); |
fprintf(outfp, "%s\n", s2); |
|
|
/* End of command parsing. */ |
/* End of command parsing. */ |
break; |
break; |
|
|
* should quit. |
* should quit. |
*/ |
*/ |
QUIT: |
QUIT: |
fclose(outfile); |
fclose(outfp); |
exit(0); |
exit(0); |
} |
} |
|
|
|
|
freediff(diffp); |
freediff(diffp); |
} |
} |
|
|
/* Write to outfile, prompting user if lines are different. */ |
/* Write to outfp, prompting user if lines are different. */ |
if (outfile) |
if (outfp) |
switch (divc) { |
switch (divc) { |
case ' ': case '(': case ')': |
case ' ': case '(': case ')': |
fprintf(outfile, "%s\n", left); |
fprintf(outfp, "%s\n", left); |
break; |
break; |
case '|': case '<': case '>': |
case '|': case '<': case '>': |
prompt(left, right); |
prompt(left, right); |