12286d8edStholo /* Normal-format output routines for GNU DIFF.
2b2346922Stholo Copyright (C) 1988, 1989, 1993, 1998 Free Software Foundation, Inc.
32286d8edStholo
42286d8edStholo This file is part of GNU DIFF.
52286d8edStholo
62286d8edStholo GNU DIFF is free software; you can redistribute it and/or modify
72286d8edStholo it under the terms of the GNU General Public License as published by
82286d8edStholo the Free Software Foundation; either version 2, or (at your option)
92286d8edStholo any later version.
102286d8edStholo
112286d8edStholo GNU DIFF is distributed in the hope that it will be useful,
122286d8edStholo but WITHOUT ANY WARRANTY; without even the implied warranty of
132286d8edStholo MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
142286d8edStholo GNU General Public License for more details.
152286d8edStholo
16*c71bc7e2Stholo */
172286d8edStholo
182286d8edStholo
192286d8edStholo #include "diff.h"
202286d8edStholo
212286d8edStholo static void print_normal_hunk PARAMS((struct change *));
222286d8edStholo
232286d8edStholo /* Print the edit-script SCRIPT as a normal diff.
242286d8edStholo INF points to an array of descriptions of the two files. */
252286d8edStholo
262286d8edStholo void
print_normal_script(script)272286d8edStholo print_normal_script (script)
282286d8edStholo struct change *script;
292286d8edStholo {
302286d8edStholo print_script (script, find_change, print_normal_hunk);
312286d8edStholo }
322286d8edStholo
332286d8edStholo /* Print a hunk of a normal diff.
342286d8edStholo This is a contiguous portion of a complete edit script,
352286d8edStholo describing changes in consecutive lines. */
362286d8edStholo
372286d8edStholo static void
print_normal_hunk(hunk)382286d8edStholo print_normal_hunk (hunk)
392286d8edStholo struct change *hunk;
402286d8edStholo {
412286d8edStholo int first0, last0, first1, last1, deletes, inserts;
422286d8edStholo register int i;
432286d8edStholo
442286d8edStholo /* Determine range of line numbers involved in each file. */
452286d8edStholo analyze_hunk (hunk, &first0, &last0, &first1, &last1, &deletes, &inserts);
462286d8edStholo if (!deletes && !inserts)
472286d8edStholo return;
482286d8edStholo
492286d8edStholo begin_output ();
502286d8edStholo
512286d8edStholo /* Print out the line number header for this hunk */
522286d8edStholo print_number_range (',', &files[0], first0, last0);
53b2346922Stholo printf_output ("%c", change_letter (inserts, deletes));
542286d8edStholo print_number_range (',', &files[1], first1, last1);
55b2346922Stholo printf_output ("\n");
562286d8edStholo
572286d8edStholo /* Print the lines that the first file has. */
582286d8edStholo if (deletes)
592286d8edStholo for (i = first0; i <= last0; i++)
602286d8edStholo print_1_line ("<", &files[0].linbuf[i]);
612286d8edStholo
622286d8edStholo if (inserts && deletes)
63b2346922Stholo printf_output ("---\n");
642286d8edStholo
652286d8edStholo /* Print the lines that the second file has. */
662286d8edStholo if (inserts)
672286d8edStholo for (i = first1; i <= last1; i++)
682286d8edStholo print_1_line (">", &files[1].linbuf[i]);
692286d8edStholo }
70