home *** CD-ROM | disk | FTP | other *** search
- Index: version.c
- Prereq: 1.14";
- @@ -1,3 +1,3 @@
- =/* Version number of GNU diff. */
- =
- -char *version_string = "1.14";
- +char *version_string = "1.14u";
- Index: analyze.c
- @@ -751,5 +751,5 @@
- = {
- = setup_output (files[0].name, files[1].name, depth);
- - if (output_style == OUTPUT_CONTEXT)
- + if (output_style == OUTPUT_CONTEXT || output_patch_flag)
- = print_context_header (files);
- =
- Index: context.c
- @@ -22,4 +22,5 @@
- =
- =static void pr_context_hunk ();
- +static void pr_unidiff_hunk ();
- =static struct change *find_hunk ();
- =static void mark_ignorable ();
- @@ -38,8 +39,19 @@
- = struct file_data *inf;
- ={
- - fprintf (outfile, "*** %s\t%s", inf[0].name,
- + if (output_patch_flag)
- + {
- + char *cp = strlen (inf[0].name) <= strlen (inf[1].name)
- + ? inf[0].name : inf[1].name;
- + if (cp[0] == '.' && cp[1] == '/')
- + cp += 2;
- + fprintf (outfile, "Index: %s\n", cp);
- + }
- + else
- + {
- + fprintf (outfile, "*** %s\t%s", inf[0].name,
- = ctime (&inf[0].stat.st_mtime));
- - fprintf (outfile, "--- %s\t%s", inf[1].name,
- + fprintf (outfile, "--- %s\t%s", inf[1].name,
- = ctime (&inf[1].stat.st_mtime));
- + }
- =}
- =
- @@ -62,5 +74,8 @@
- = find_function_last_match = -1;
- =
- - print_script (script, find_hunk, pr_context_hunk);
- + if (unidiff_flag)
- + print_script (script, find_hunk, pr_unidiff_hunk);
- + else
- + print_script (script, find_hunk, pr_context_hunk);
- =}
- =
- @@ -189,4 +204,125 @@
- =
- = print_1_line (prefix, &files[1].linbuf[i]);
- + }
- + }
- +}
- +
- +/* Print a pair of line numbers with a comma, translated for file FILE.
- + If the second number is smaller, use the first in place of it.
- +
- + Args A and B are internal line numbers.
- + We print the translated (real) line numbers. */
- +
- +static void
- +print_unidiff_number_range (file, a, b)
- + struct file_data *file;
- + int a, b;
- +{
- + int trans_a, trans_b;
- + translate_range (file, a, b, &trans_a, &trans_b);
- +
- + /* Note: we can have B < A in the case of a range of no lines.
- + In this case, we should print the line number before the range,
- + which is B. */
- + if (trans_b < trans_a)
- + fprintf (outfile, "%d,0", trans_b);
- + else
- + fprintf (outfile, "%d,%d", trans_a, trans_b - trans_a + 1);
- +}
- +
- +/* Print a portion of an edit script in unidiff format.
- + HUNK is the beginning of the portion to be printed.
- + The end is marked by a `link' that has been nulled out.
- +
- + Prints out lines from both files, and precedes each
- + line with the appropriate flag-character. */
- +
- +static void
- +pr_unidiff_hunk (hunk)
- + struct change *hunk;
- +{
- + int first0, last0, first1, last1, show_from, show_to, i, j, k;
- + struct change *next;
- + int lastline;
- + char *function;
- + int function_length;
- +
- + /* Determine range of line numbers involved in each file. */
- +
- + analyze_hunk (hunk, &first0, &last0, &first1, &last1, &show_from, &show_to);
- +
- + if (!show_from && !show_to)
- + return;
- +
- + /* Include a context's width before and after. */
- +
- + first0 = max (first0 - context, 0);
- + first1 = max (first1 - context, 0);
- + last0 = min (last0 + context, files[0].buffered_lines - 1);
- + last1 = min (last1 + context, files[1].buffered_lines - 1);
- +
- + /* If desired, find the preceding function definition line in file 0. */
- + function = 0;
- + if (function_regexp)
- + find_function (&files[0], first0, &function, &function_length);
- +
- + /* If we looked for and found a function this is part of,
- + include its name in the header of the diff section. */
- +
- + fprintf (outfile, "@@ -");
- + print_unidiff_number_range (&files[0], first0, last0);
- + fprintf (outfile, " +");
- + print_unidiff_number_range (&files[1], first1, last1);
- + fprintf (outfile, " @@");
- +
- + if (function)
- + {
- + putc (' ', outfile);
- + fwrite (function, 1, min (function_length - 1, 40), outfile);
- + }
- + putc ('\n', outfile);
- +
- + next = hunk;
- + i = first0;
- + j = first1;
- +
- + while (i <= last0 || j <= last1)
- + {
- +
- + /* If the line isn't a difference, output the context from file 0. */
- +
- + if (!next || i < next->line0)
- + {
- + if (output_patch_flag)
- + putc ('=', outfile);
- + else
- + putc (' ', outfile);
- + print_1_line ("", &files[0].linbuf[i++]);
- + j++;
- + }
- + else
- + {
- + /* For each difference, first output the deleted part. */
- +
- + k = next->deleted;
- + while (k--)
- + {
- + putc ('-', outfile);
- + print_1_line ("", &files[0].linbuf[i++]);
- + }
- +
- + /* Then output the inserted part. */
- +
- + k = next->inserted;
- + while (k--)
- + {
- + putc ('+', outfile);
- + print_1_line ("", &files[1].linbuf[j++]);
- + }
- +
- + /* We're done with this hunk, so on to the next! */
- +
- + next = next->link;
- +
- = }
- = }
- Index: diff.c
- @@ -96,4 +96,6 @@
- = {"expand-tabs", 0, 0, 't'},
- = {"ignore-all-space", 0, 0, 'w'},
- + {"unidiff", 0, 0, 'u'},
- + {"patch", 0, 0, 'P'},
- = {"version", 0, 0, 'v'},
- = {0, 0, 0, 0}
- @@ -133,4 +135,6 @@
- = ifdef_string = NULL;
- = heuristic = FALSE;
- + unidiff_flag = 0;
- + output_patch_flag = 0;
- = dir_start_file = NULL;
- = msg_chain = NULL;
- @@ -141,5 +145,5 @@
- =
- = while ((c = getopt_long (argc, argv,
- - "0123456789abBcC:dD:efF:hHiI:lnNpqrsS:tTvw",
- + "0123456789abBcC:dD:efF:hHiI:lnNpPqrsS:tTuUvw",
- = longopts, &longind)) != EOF)
- = {
- @@ -284,4 +288,8 @@
- = break;
- =
- + case 'P':
- + output_patch_flag = 1;
- + break;
- +
- = case 'q':
- = no_details_flag = 1;
- @@ -322,4 +330,15 @@
- = break;
- =
- + case 'U':
- + /* Choose patch-style unidiff. */
- + output_patch_flag = 1;
- +
- + /* Falls through. */
- + case 'u':
- + /* Output the context diff in unidiff format. */
- + specify_style (OUTPUT_CONTEXT);
- + unidiff_flag = 1;
- + break;
- +
- = case 'w':
- = /* Ignore horizontal whitespace when comparing lines. */
- @@ -378,5 +397,5 @@
- ={
- = fprintf (stderr, "\
- -Usage: diff [-#] [-abBcdefhHilnNprstTvw] [-C lines] [-F regexp] [-I regexp]\n\
- +Usage: diff [-#] [-abBcdefhHilnNpPrstTuUvw] [-C lines] [-F regexp] [-I regexp]\n\
- = [-S file] [-D symbol] [+ignore-blank-lines] [+context[=lines]]\n\
- = [+ifdef symbol] [+show-function-line regexp] [+speed-large-files]\n");
- @@ -388,5 +407,5 @@
- = [+rcs] [+show-c-function] [+binary] [+brief] [+recursive]\n\
- = [+report-identical-files] [+expand-tabs] [+ignore-all-space]\n\
- - [+version] path1 path2\n");
- + [+unidiff] [+patch] [+version] path1 path2\n");
- = exit (1);
- =}
- @@ -429,5 +448,6 @@
- = char *name = name0 == 0 ? name1 : name0;
- = char *dir = name0 == 0 ? dir1 : dir0;
- - message ("Only in %s: %s\n", dir, name);
- + if (!output_patch_flag)
- + message ("Only in %s: %s\n", dir, name);
- = /* Return 1 so that diff_dirs will return 1 ("some files differ"). */
- = return 1;
- @@ -535,5 +555,6 @@
- = /* But don't compare dir contents one level down
- = unless -r was specified. */
- - message ("Common subdirectories: %s and %s\n",
- + if (!output_patch_flag)
- + message ("Common subdirectories: %s and %s\n",
- = inf[0].name, inf[1].name);
- = val = 0;
- @@ -601,5 +622,6 @@
- = {
- = char *dir = (inf[0].desc == -1) ? dir1 : dir0;
- - message ("Only in %s: %s\n", dir, name0);
- + if (!output_patch_flag)
- + message ("Only in %s: %s\n", dir, name0);
- = val = 1;
- = }
- Index: diff.h
- @@ -185,4 +185,10 @@
- =EXTERN int heuristic;
- =
- +/* Do we want to output the context diff in unidiff style? */
- +EXTERN int unidiff_flag;
- +
- +/* Reduce extraneous output when they're outputting a patch. */
- +EXTERN int output_patch_flag;
- +
- =/* Name of program the user invoked (for error messages). */
- =EXTERN char * program;
- Index: util.c
- @@ -170,5 +170,5 @@
- = /* If handling multiple files (because scanning a directory),
- = print which files the following output is about. */
- - if (depth > 0)
- + if (depth > 0 && !output_patch_flag)
- = printf ("%s\n", name);
- = }
-