summaryrefslogtreecommitdiff
path: root/gnu/usr.bin/cvs/diff/diff.c
diff options
context:
space:
mode:
Diffstat (limited to 'gnu/usr.bin/cvs/diff/diff.c')
-rw-r--r--gnu/usr.bin/cvs/diff/diff.c97
1 files changed, 71 insertions, 26 deletions
diff --git a/gnu/usr.bin/cvs/diff/diff.c b/gnu/usr.bin/cvs/diff/diff.c
index c0e37d7d421..3467b537aec 100644
--- a/gnu/usr.bin/cvs/diff/diff.c
+++ b/gnu/usr.bin/cvs/diff/diff.c
@@ -1,5 +1,5 @@
/* GNU DIFF entry routine.
- Copyright (C) 1988, 1989, 1992, 1993, 1994, 1997 Free Software Foundation, Inc.
+ Copyright (C) 1988, 1989, 1992, 1993, 1994, 1997, 1998 Free Software Foundation, Inc.
This file is part of GNU DIFF.
@@ -231,10 +231,11 @@ static struct option const longopts[] =
};
int
-diff_run (argc, argv, out)
+diff_run (argc, argv, out, callbacks_arg)
int argc;
char *argv[];
char *out;
+ const struct diff_callbacks *callbacks_arg;
{
int val;
int c;
@@ -242,6 +243,9 @@ diff_run (argc, argv, out)
int width = DEFAULT_WIDTH;
int show_c_function = 0;
int optind_old;
+ int opened_file = 0;
+
+ callbacks = callbacks_arg;
/* Do our initializations. */
initialize_main (&argc, &argv);
@@ -476,7 +480,14 @@ diff_run (argc, argv, out)
break;
case 'v':
- printf ("diff - GNU diffutils version %s\n", diff_version_string);
+ if (callbacks && callbacks->write_stdout)
+ {
+ (*callbacks->write_stdout) ("diff - GNU diffutils version ");
+ (*callbacks->write_stdout) (diff_version_string);
+ (*callbacks->write_stdout) ("\n");
+ }
+ else
+ printf ("diff - GNU diffutils version %s\n", diff_version_string);
return 0;
case 'w':
@@ -555,7 +566,8 @@ diff_run (argc, argv, out)
case 141:
usage ();
- check_output (stdout);
+ if (! callbacks || ! callbacks->write_stdout)
+ check_output (stdout);
return 0;
case 142:
@@ -645,23 +657,35 @@ diff_run (argc, argv, out)
switch_string = option_list (argv + 1, optind - 1);
- if (out == NULL)
- outfile = stdout;
+ if (callbacks && callbacks->write_output)
+ {
+ if (out != NULL)
+ {
+ diff_error ("write callback with output file", 0, 0);
+ return 2;
+ }
+ }
else
{
-#if HAVE_SETMODE
- /* A diff which is full of ^Z and such isn't going to work
- very well in text mode. */
- if (binary_I_O)
- outfile = fopen (out, "wb");
+ if (out == NULL)
+ outfile = stdout;
else
+ {
+#if HAVE_SETMODE
+ /* A diff which is full of ^Z and such isn't going to work
+ very well in text mode. */
+ if (binary_I_O)
+ outfile = fopen (out, "wb");
+ else
#endif
- outfile = fopen (out, "w");
- if (outfile == NULL)
- {
- perror_with_name ("could not open output file");
- return 2;
- }
+ outfile = fopen (out, "w");
+ if (outfile == NULL)
+ {
+ perror_with_name ("could not open output file");
+ return 2;
+ }
+ opened_file = 1;
+ }
}
/* Set the jump buffer, so that diff may abort execution without
@@ -669,7 +693,7 @@ diff_run (argc, argv, out)
if ((val = setjmp (diff_abort_buf)) != 0)
{
optind = optind_old;
- if (outfile != stdout)
+ if (opened_file)
fclose (outfile);
return val;
}
@@ -682,10 +706,14 @@ diff_run (argc, argv, out)
free (switch_string);
optind = optind_old;
- check_output (outfile);
- if (outfile != stdout)
+
+ if (! callbacks || ! callbacks->write_output)
+ check_output (outfile);
+
+ if (opened_file)
if (fclose (outfile) != 0)
- perror ("close error on output file");
+ perror_with_name ("close error on output file");
+
return val;
}
@@ -799,10 +827,27 @@ usage ()
{
char const * const *p;
- printf ("Usage: %s [OPTION]... FILE1 FILE2\n\n", diff_program_name);
- for (p = option_help; *p; p++)
- printf (" %s\n", *p);
- printf ("\nIf FILE1 or FILE2 is `-', read standard input.\n");
+ if (callbacks && callbacks->write_stdout)
+ {
+ (*callbacks->write_stdout) ("Usage: ");
+ (*callbacks->write_stdout) (diff_program_name);
+ (*callbacks->write_stdout) (" [OPTION]... FILE1 FILE2\n\n");
+ for (p = option_help; *p; p++)
+ {
+ (*callbacks->write_stdout) (" ");
+ (*callbacks->write_stdout) (*p);
+ (*callbacks->write_stdout) ("\n");
+ }
+ (*callbacks->write_stdout)
+ ("\nIf FILE1 or FILE2 is `-', read standard input.\n");
+ }
+ else
+ {
+ printf ("Usage: %s [OPTION]... FILE1 FILE2\n\n", diff_program_name);
+ for (p = option_help; *p; p++)
+ printf (" %s\n", *p);
+ printf ("\nIf FILE1 or FILE2 is `-', read standard input.\n");
+ }
}
static int
@@ -1147,7 +1192,7 @@ compare_files (dir0, name0, dir1, name1, depth)
inf[0].name, inf[1].name);
}
else
- fflush (outfile);
+ flush_output ();
if (free0)
free (free0);