home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / progmisc / dif115as.zip / IFDEF.C < prev    next >
C/C++ Source or Header  |  1992-02-22  |  3KB  |  97 lines

  1. /* #ifdef-format output routines for GNU DIFF.
  2.    Copyright (C) 1989 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU DIFF.
  5.  
  6. GNU DIFF is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY.  No author or distributor
  8. accepts responsibility to anyone for the consequences of using it
  9. or for whether it serves any particular purpose or works at all,
  10. unless he says so in writing.  Refer to the GNU DIFF General Public
  11. License for full details.
  12.  
  13. Everyone is granted permission to copy, modify and redistribute
  14. GNU DIFF, but only under the conditions described in the
  15. GNU DIFF General Public License.   A copy of this license is
  16. supposed to have been given to you along with GNU DIFF so you
  17. can know your rights and responsibilities.  It should be in a
  18. file named COPYING.  Among other things, the copyright notice
  19. and this notice must be preserved on all copies.  */
  20. /* MS-DOS port (c) 1990 by Thorsten Ohl, ohl@gnu.ai.mit.edu
  21. This port is also distributed under the terms of the GNU General
  22. Public License as published by the Free Software Foundation.
  23.  
  24. Please note that this file is not identical to the original GNU release,
  25. you should have received this code as patch to the official release.
  26.  
  27. $Header: e:/gnu/diff/RCS/ifdef.c 1.15.0.1 91/03/11 22:12:20 tho Exp $  */
  28.  
  29. #include "diff.h"
  30.  
  31. #ifdef __STDC__
  32. static  void print_ifdef_hunk(struct change *);
  33. #else
  34. static void print_ifdef_hunk ();
  35. struct change *find_change ();
  36. #endif /* __STDC__ */
  37.  
  38. static int next_line;
  39.  
  40. /* Print the edit-script SCRIPT as a merged #ifdef file.  */
  41.  
  42. void
  43. print_ifdef_script (script)
  44.      struct change *script;
  45. {
  46.   next_line = 0;
  47.   print_script (script, find_change, print_ifdef_hunk);
  48.   while (next_line < files[0].buffered_lines)
  49.     print_1_line ("", &files[0].linbuf[next_line++]);
  50. }
  51.  
  52. /* Print a hunk of an ifdef diff.
  53.    This is a contiguous portion of a complete edit script,
  54.    describing changes in consecutive lines.  */
  55.  
  56. static void
  57. print_ifdef_hunk (hunk)
  58.      struct change *hunk;
  59. {
  60.   int first0, last0, first1, last1, deletes, inserts;
  61.   register int i;
  62.  
  63.   /* Determine range of line numbers involved in each file.  */
  64.   analyze_hunk (hunk, &first0, &last0, &first1, &last1, &deletes, &inserts);
  65.   if (!deletes && !inserts)
  66.     return;
  67.  
  68.   /* Print out lines up to this change.  */
  69.   while (next_line < first0)
  70.     print_1_line ("", &files[0].linbuf[next_line++]);
  71.  
  72.   /* Print out stuff deleted from first file.  */
  73.   if (deletes)
  74.     {
  75.       fprintf (outfile, "#ifndef %s\n", ifdef_string);
  76.       for (i = first0; i <= last0; i++)
  77.     print_1_line ("", &files[0].linbuf[i]);
  78.       next_line = i;
  79.     }
  80.  
  81.   /* Print out stuff inserted from second file.  */
  82.   if (inserts)
  83.     {
  84.       if (deletes)
  85.     fprintf (outfile, "#else /* %s */\n", ifdef_string);
  86.       else
  87.     fprintf (outfile, "#ifdef %s\n", ifdef_string);
  88.       for (i = first1; i <= last1; i++)
  89.     print_1_line ("", &files[1].linbuf[i]);
  90.     }
  91.  
  92.   if (inserts)
  93.     fprintf (outfile, "#endif /* %s */\n", ifdef_string);
  94.   else
  95.     fprintf (outfile, "#endif /* not %s */\n", ifdef_string);
  96. }
  97.