Beispiel #1
0
static void
print_normal_hunk (struct change *hunk)
{
  lin first0, last0, first1, last1;
  register lin i;

  /* Determine range of line numbers involved in each file.  */
  enum changes changes = analyze_hunk (hunk, &first0, &last0, &first1, &last1);
  if (!changes)
    return;

  begin_output ();

  /* Print out the line number header for this hunk */
  print_number_range (',', &files[0], first0, last0);
  fprintf (outfile, "%c", change_letter[changes]);
  print_number_range (',', &files[1], first1, last1);
  fprintf (outfile, "\n");

  /* Print the lines that the first file has.  */
  if (changes & OLD)
    for (i = first0; i <= last0; i++)
      print_1_line ("<", &files[0].linbuf[i]);

  if (changes == CHANGED)
    fprintf (outfile, "---\n");

  /* Print the lines that the second file has.  */
  if (changes & NEW)
    for (i = first1; i <= last1; i++)
      print_1_line (">", &files[1].linbuf[i]);
}
Beispiel #2
0
static void
pr_forward_ed_hunk (struct change *hunk)
{
  lin i, f0, l0, f1, l1;

  /* Determine range of line numbers involved in each file.  */
  enum changes changes = analyze_hunk (hunk, &f0, &l0, &f1, &l1);
  if (!changes)
    return;

  begin_output ();

  fputc (change_letter[changes], outfile);
  print_number_range (' ', files, f0, l0);
  fputc ('\n', outfile);

  /* If deletion only, print just the number range.  */

  if (changes == OLD)
    return;

  /* For insertion (with or without deletion), print the number range
     and the lines from file 2.  */

  for (i = f1; i <= l1; i++)
    print_1_line ("", &files[1].linbuf[i]);

  fputs (".\n", outfile);
}
Beispiel #3
0
static void
print_ed_hunk (struct change *hunk)
{
  lin f0, l0, f1, l1;
  enum changes changes;

#ifdef DEBUG
  debug_script (hunk);
#endif

  /* Determine range of line numbers involved in each file.  */
  changes = analyze_hunk (hunk, &f0, &l0, &f1, &l1);
  if (!changes)
    return;

  begin_output ();

  /* Print out the line number header for this hunk */
  print_number_range (',', &files[0], f0, l0);
  fputc (change_letter[changes], outfile);
  fputc ('\n', outfile);

  /* Print new/changed lines from second file, if needed */
  if (changes != OLD)
    {
      lin i;
      bool insert_mode = true;

      for (i = f1; i <= l1; i++)
	{
	  if (!insert_mode)
	    {
	      fputs ("a\n", outfile);
	      insert_mode = true;
	    }
	  if (files[1].linbuf[i][0] == '.' && files[1].linbuf[i][1] == '\n')
	    {
	      /* The file's line is just a dot, and it would exit
		 insert mode.  Precede the dot with another dot, exit
		 insert mode and remove the extra dot.  */
	      fputs ("..\n.\ns/.//\n", outfile);
	      insert_mode = false;
	    }
	  else
	    print_1_line ("", &files[1].linbuf[i]);
	}

      if (insert_mode)
	fputs (".\n", outfile);
    }
}