normal.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /* Normal-format output routines for GNU DIFF.
  2. Copyright (C) 1988, 1989, 1993 Free Software Foundation, Inc.
  3. This file is part of GNU DIFF.
  4. GNU DIFF is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. GNU DIFF is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU DIFF; see the file COPYING. If not, write to
  14. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
  15. #include "diff.h"
  16. static void print_normal_hunk PARAMS((struct change *));
  17. /* Print the edit-script SCRIPT as a normal diff.
  18. INF points to an array of descriptions of the two files. */
  19. void
  20. print_normal_script (script)
  21. struct change *script;
  22. {
  23. print_script (script, find_change, print_normal_hunk);
  24. }
  25. /* Print a hunk of a normal diff.
  26. This is a contiguous portion of a complete edit script,
  27. describing changes in consecutive lines. */
  28. static void
  29. print_normal_hunk (hunk)
  30. struct change *hunk;
  31. {
  32. int first0, last0, first1, last1, deletes, inserts;
  33. register int i;
  34. /* Determine range of line numbers involved in each file. */
  35. analyze_hunk (hunk, &first0, &last0, &first1, &last1, &deletes, &inserts);
  36. if (!deletes && !inserts)
  37. return;
  38. begin_output ();
  39. /* Print out the line number header for this hunk */
  40. print_number_range (',', &files[0], first0, last0);
  41. fprintf (outfile, "%c", change_letter (inserts, deletes));
  42. print_number_range (',', &files[1], first1, last1);
  43. fprintf (outfile, "\n");
  44. /* Print the lines that the first file has. */
  45. if (deletes)
  46. for (i = first0; i <= last0; i++)
  47. print_1_line ("<", &files[0].linbuf[i]);
  48. if (inserts && deletes)
  49. fprintf (outfile, "---\n");
  50. /* Print the lines that the second file has. */
  51. if (inserts)
  52. for (i = first1; i <= last1; i++)
  53. print_1_line (">", &files[1].linbuf[i]);
  54. }