FreeBSD/contrib/diff/src/context.c
/* Print a portion of an edit script in context 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.  */
Print a portion of an edit script in context 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.
Print a portion of an edit script in context 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_context_hunk (struct change *hunk)
{
  lin first0, last0, first1, last1, i;
  char const *prefix;
  char const *function;
  FILE *out;
  enum changes changes = analyze_hunk (hunk, &first0, &last0, &first1, &last1);
  if (! changes)
    return;
  i = - files[0].prefix_lines;
  first0 = MAX (first0 - context, i);
  first1 = MAX (first1 - context, i);
  if (last0 < files[0].valid_lines - context)
    last0 += context;
  else
    last0 = files[0].valid_lines - 1;
  if (last1 < files[1].valid_lines - context)
    last1 += context;
  else
    last1 = files[1].valid_lines - 1;
  function = 0;
  if (function_regexp.fastmap)
    function = find_function (files[0].linbuf, first0);
  begin_output ();
  out = outfile;
  fprintf (out, "***************");
  if (function)
    print_context_function (out, function);
  fprintf (out, "\n*** ");
  print_context_number_range (&files[0], first0, last0);
  fprintf (out, " ****\n");
  if (changes & OLD)
    {
      struct change *next = hunk;
      for (i = first0; i <= last0; i++)
	{
	  while (next && next->line0 + next->deleted <= i)
	    next = next->link;
	  prefix = " ";
	  if (next && next->line0 <= i)
	    prefix = (next->inserted > 0 ? "!" : "-");
	  print_1_line (prefix, &files[0].linbuf[i]);
	}
    }
  fprintf (out, "--- ");
  print_context_number_range (&files[1], first1, last1);
  fprintf (out, " ----\n");
  if (changes & NEW)
    {
      struct change *next = hunk;
      for (i = first1; i <= last1; i++)
	{
	  while (next && next->line1 + next->inserted <= i)
	    next = next->link;
	  prefix = " ";
	  if (next && next->line1 <= i)
	    prefix = (next->deleted > 0 ? "!" : "+");
	  print_1_line (prefix, &files[1].linbuf[i]);
	}
    }
}
static void pr_context_hunk ( struct change * hunk ) { lin first0 , last0 , first1 , last1 , i ; char const * prefix ; char const * function ; FILE * out ; enum changes changes = analyze_hunk ( hunk , & first0 , & last0 , & first1 , & last1 ) ; if ( ! changes ) return ; i = - files [ 0 ] . prefix_lines ; first0 = MAX ( first0 - context , i ) ; first1 = MAX ( first1 - context , i ) ; if ( last0 < files [ 0 ] . valid_lines - context ) last0 += context ; else last0 = files [ 0 ] . valid_lines - 1 ; if ( last1 < files [ 1 ] . valid_lines - context ) last1 += context ; else last1 = files [ 1 ] . valid_lines - 1 ; function = 0 ; if ( function_regexp . fastmap ) function = find_function ( files [ 0 ] . linbuf , first0 ) ; begin_output ( ) ; out = outfile ; fprintf ( out , " " ) ; if ( function ) print_context_function ( out , function ) ; fprintf ( out , " \n " ) ; print_context_number_range ( & files [ 0 ] , first0 , last0 ) ; fprintf ( out , " \n " ) ; if ( changes & OLD ) { struct change * next = hunk ; for ( i = first0 ; i <= last0 ; i ++ ) { while ( next && next -> line0 + next -> deleted <= i ) next = next -> link ; prefix = " " ; if ( next && next -> line0 <= i ) prefix = ( next -> inserted > 0 ? " " : " " ) ; print_1_line ( prefix , & files [ 0 ] . linbuf [ i ] ) ; } } fprintf ( out , " " ) ; print_context_number_range ( & files [ 1 ] , first1 , last1 ) ; fprintf ( out , " \n " ) ; if ( changes & NEW ) { struct change * next = hunk ; for ( i = first1 ; i <= last1 ; i ++ ) { while ( next && next -> line1 + next -> inserted <= i ) next = next -> link ; prefix = " " ; if ( next && next -> line1 <= i ) prefix = ( next -> deleted > 0 ? " " : " " ) ; print_1_line ( prefix , & files [ 1 ] . linbuf [ i ] ) ; } } }
Print a portion of an edit script in context format.
Print a portion of an edit script in context format .
/* Determine range of line numbers involved in each file.  */ /* Include a context's width before and after.  */ /* If desired, find the preceding function definition line in file 0.  */ /* Skip past changes that apply (in file 0)
	     only to lines before line I.  */ /* Compute the marking for line I.  */ /* The change NEXT covers this line.
	       If lines were inserted here in file 1, this is "changed".
	       Otherwise it is "deleted".  */ /* Skip past changes that apply (in file 1)
	     only to lines before line I.  */ /* Compute the marking for line I.  */ /* The change NEXT covers this line.
	       If lines were deleted here in file 0, this is "changed".
	       Otherwise it is "inserted".  */