home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / programming / utils / hwgrcs / hwgdiff / rcs.rcsfiles / ifdef.c,v < prev    next >
Encoding:
Text File  |  1993-02-20  |  2.7 KB  |  112 lines

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