File wdiff-0.5.93-lermen.patch of Package wdiff

--- wdiff-0.5.93/src/wdiff.c.orig	2009-08-03 21:20:25.673199000 +0200
+++ wdiff-0.5.93/src/wdiff.c	2009-08-03 23:23:17.744638000 +0200
@@ -16,6 +16,10 @@
    along with this program; if not, write to the Free Software Foundation,
    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
 
+#ifdef LERMEN_STUFF
+#define LVERSION "L3"
+#endif
+
 #include "system.h"
 
 /* Exit codes values.  */
@@ -112,11 +116,15 @@ struct option const longopts[] =
   {"no-init-term", 0, NULL, 'K'},
   {"no-inserted" , 0, NULL, '2'},
   {"printer"     , 0, NULL, 'p'},
+  {"punctuation" , 0, NULL, 'P'},
   {"start-delete", 1, NULL, 'w'},
   {"start-insert", 1, NULL, 'y'},
   {"statistics"  , 0, NULL, 's'},
   {"terminal"    , 0, NULL, 't'},
   {"version"     , 0, NULL, 'v'},
+#ifdef LERMEN_STUFF
+  {"context"     , 1, NULL, 'c'},
+#endif
   {NULL          , 0, NULL, 0}
 };
 
@@ -126,6 +134,7 @@ int inhibit_left;		/* inhibit display of
 int inhibit_right;		/* inhibit display of left side words */
 int inhibit_common;		/* inhibit display of common words */
 int ignore_case;		/* ignore case in comparisons */
+int ignore_punct;		/* ignore punctuation (treat as whitespace) */
 int show_statistics;		/* if printing summary statistics */
 int no_wrapping;		/* end/restart strings at end of lines */
 int autopager;			/* if calling the pager automatically */
@@ -225,6 +234,142 @@ setup_signals (void)
 }
 
 
+#ifdef LERMEN_STUFF
+
+/* we intercept output to 'output_file' in order to catch some lines
+ * of context _before_ and _after_ the emphasized parts
+ */
+ 
+#define BUFLINE_SIZE 1024
+struct bufline {
+  struct bufline *next;
+  char line[BUFLINE_SIZE];
+};
+
+static struct bufline *headbufline = 0;
+static struct bufline *tailbufline = 0;
+static int bufcols = 0;
+static int in_emphasize = 0;
+static int context_lines = 0;
+static int bufline_overrun = 0;
+static int behind_emphasize = 0;
+
+static void init_savebuffers(int lines)
+{
+  struct bufline *p;
+  int i;
+
+  if (headbufline) return;
+  context_lines = ++lines;
+  headbufline = p = malloc(sizeof(struct bufline));
+  for (i=0; i<lines; i++) {
+    p->next = malloc(sizeof(struct bufline));
+    p = p->next;
+  }
+  p->next = tailbufline = headbufline;  /* close the circle */    
+}
+
+static inline void inc_headbuf(void)
+{
+  headbufline = headbufline->next;
+  if (headbufline == tailbufline) {
+    bufline_overrun = 1;
+    tailbufline = tailbufline->next;
+  }
+}
+
+static void flush_buflines(void)
+{
+  if (!bufcols && (headbufline == tailbufline)) return;
+  if (bufcols) {
+    headbufline->line[bufcols] = 0;
+    inc_headbuf();
+    bufcols = 0;
+  }
+  while (headbufline != tailbufline) {
+    if (bufline_overrun) {
+      fprintf(output_file, "\n%s\n", SEPARATOR_LINE);
+      bufline_overrun = 0;
+    }
+    fputs(tailbufline->line, output_file);
+    tailbufline = tailbufline->next;
+  }
+}
+
+static inline void save_char(int c)
+{
+  headbufline->line[bufcols++] = c;
+  if (c == '\n') {
+    headbufline->line[bufcols] = 0;
+    inc_headbuf();
+    bufcols = 0;
+  }
+}
+
+static inline int our_putc(int c, FILE *stream)
+{
+  if (context_lines && stream == output_file) {
+    if (!in_emphasize) {
+      if (behind_emphasize) {
+        if (c == '\n') behind_emphasize--;
+      }
+      else {
+        save_char(c);
+        return (int)((unsigned char) c);
+      }
+    }
+  }
+  return putc(c, stream);
+}
+#undef putc
+#define putc our_putc
+
+
+static void real_start_of_delete (void);
+static void real_end_of_delete (void);
+static void real_start_of_insert (void);
+static void real_end_of_insert (void);
+
+static void our_start_of_delete (void)
+{
+  if (context_lines) flush_buflines();
+  in_emphasize = 1;
+  real_start_of_delete();
+}
+static void our_end_of_delete (void)
+{
+  real_end_of_delete();
+  in_emphasize = 0;
+  behind_emphasize = context_lines;
+}
+static void our_start_of_insert (void)
+{
+  if (context_lines) flush_buflines();
+  in_emphasize = 1;
+  real_start_of_insert();
+}
+static void our_end_of_insert (void)
+{
+  real_end_of_insert();
+  in_emphasize = 0;
+  behind_emphasize = context_lines;
+}
+
+#define start_of_delete our_start_of_delete
+#define end_of_delete our_end_of_delete
+#define start_of_insert our_start_of_insert
+#define end_of_insert our_end_of_insert
+
+#else /* not LERMEN_STUFF */
+
+#define start_of_delete real_start_of_delete
+#define end_of_delete real_end_of_delete
+#define start_of_insert real_start_of_insert
+#define end_of_insert real_end_of_insert
+
+#endif
+
+
 /* Terminal initialization.  */
 
 static void
@@ -305,7 +450,7 @@ putc_for_tputs (int chr)
 `---------------------------*/
 
 static void
-start_of_delete (void)
+real_start_of_delete (void)
 {
 
   /* Avoid any emphasis if it would be useless.  */
@@ -327,7 +472,7 @@ start_of_delete (void)
 `-------------------------*/
 
 static void
-end_of_delete (void)
+real_end_of_delete (void)
 {
 
   /* Avoid any emphasis if it would be useless.  */
@@ -349,7 +494,7 @@ end_of_delete (void)
 `---------------------------*/
 
 static void
-start_of_insert (void)
+real_start_of_insert (void)
 {
 
   /* Avoid any emphasis if it would be useless.  */
@@ -371,7 +516,7 @@ start_of_insert (void)
 `-------------------------*/
 
 static void
-end_of_insert (void)
+real_end_of_insert (void)
 {
 
   /* Avoid any emphasis if it would be useless.  */
@@ -388,6 +533,12 @@ end_of_insert (void)
   copy_mode = COPY_NORMAL;
 }
 
+/*----------------------------------------------------------------.
+| We say "white space", but we actually mean space or punctuation |
+`----------------------------------------------------------------*/
+
+#define is_space_or_punct(c) (isspace(c) || ignore_punct && ispunct(c))
+
 /*--------------------------------.
 | Skip over white space on SIDE.  |
 `--------------------------------*/
@@ -398,7 +549,7 @@ skip_whitespace (SIDE *side)
   if (interrupted)
     longjmp (signal_label, 1);
 
-  while (isspace (side->character))
+  while (is_space_or_punct (side->character))
     side->character = getc (side->file);
 }
 
@@ -412,7 +563,7 @@ skip_word (SIDE *side)
   if (interrupted)
     longjmp (signal_label, 1);
 
-  while (side->character != EOF && !isspace (side->character))
+  while (side->character != EOF && !is_space_or_punct (side->character))
     side->character = getc (side->file);
   side->position++;
 }
@@ -433,7 +584,7 @@ copy_whitespace (SIDE *side, FILE *file)
       /* While changing lines, ensure we stop any special display prior
 	 to, and restore the special display after.  When copy_mode is
 	 anything else than COPY_NORMAL, file is always output_file.  We
-	 care underlining whitespace or overstriking it with itself,
+	 care about underlining whitespace or overstriking it with itself,
 	 because "less" understands these things as emphasis requests.  */
 
       switch (copy_mode)
@@ -969,7 +1120,10 @@ launch_input_program (void)
 static void
 complete_input_program (void)
 {
-  fclose (input_file);
+  if (input_file) {
+    fclose (input_file);
+    input_file = NULL;
+  }
   wait (NULL);
 }
 
@@ -1077,6 +1231,7 @@ complete_output_program (void)
   if (output_file && output_file != stdout)
     {
       fclose (output_file);
+      output_file = NULL;
       wait (NULL);
     }
 
@@ -1107,29 +1262,29 @@ print_statistics (void)
   count_common_right
     = count_total_right - count_isolated_right - count_changed_right;
 
-  printf (_("%s: %d words"), left_side->filename, count_total_left);
+  fprintf (stderr, "%s: %d words", left_side->filename, count_total_left);
   if (count_total_left > 0)
     {
-      printf (_("  %d %d%% common"), count_common_left,
+      fprintf (stderr, "  %d %d%% common", count_common_left,
 	      count_common_left * 100 / count_total_left);
-      printf (_("  %d %d%% deleted"), count_isolated_left,
+      fprintf (stderr, "  %d %d%% deleted", count_isolated_left,
 	      count_isolated_left * 100 / count_total_left);
-      printf (_("  %d %d%% changed"), count_changed_left,
+      fprintf (stderr, "  %d %d%% changed", count_changed_left,
 	      count_changed_left * 100 / count_total_left);
     }
-  printf ("\n");
+  fprintf (stderr, "\n");
 
-  printf (_("%s: %d words"), right_side->filename, count_total_right);
+  fprintf (stderr, _("%s: %d words"), right_side->filename, count_total_right);
   if (count_total_right > 0)
     {
-      printf (_("  %d %d%% common"), count_common_right,
+      fprintf (stderr, "  %d %d%% common", count_common_right,
 	      count_common_right * 100 / count_total_right);
-      printf (_("  %d %d%% inserted"), count_isolated_right,
+      fprintf (stderr, "  %d %d%% inserted", count_isolated_right,
 	      count_isolated_right * 100 / count_total_right);
-      printf (_("  %d %d%% changed"), count_changed_right,
+      fprintf (stderr, "  %d %d%% changed", count_changed_right,
 	      count_changed_right * 100 / count_total_right);
     }
-  printf ("\n");
+  fprintf (stderr, "\n");
 }
 
 
@@ -1186,6 +1341,10 @@ Mandatory arguments to long options are
   -1, --no-deleted           inhibit output of deleted words\n\
   -2, --no-inserted          inhibit output of inserted words\n\
   -3, --no-common            inhibit output of common words\n"));
+#ifdef LERMEN_STUFF
+      printf (_("\
+  -c  --context              like -3, but print given context lines\n"));
+#endif
       printf (_("\
   -a, --auto-pager           automatically calls a pager\n\
   -h, --help                 print this help\n\
@@ -1194,6 +1353,7 @@ Mandatory arguments to long options are
   -n, --avoid-wraps          do not extend fields through newlines\n\
   -p, --printer              overstrike as for printers\n"));
       printf (_("\
+  -P, --punctuation          treat punctuation like white space\n\
   -s, --statistics           say how many words deleted, inserted etc.\n\
   -t, --terminal             use termcap as for terminal displays\n\
   -v, --version              print program version then exit\n\
@@ -1255,7 +1415,7 @@ main (int argc, char *const argv[])
   count_changed_right = 0;
 
   while (option_char = getopt_long (argc, (char **) argv,
-				    "123CKahilnpstvw:x:y:z:", longopts, NULL),
+				    "123CKahilnpPstvw:x:y:z:c:", longopts, NULL),
 	 option_char != EOF)
     switch (option_char)
       {
@@ -1301,6 +1461,10 @@ main (int argc, char *const argv[])
 	overstrike = 1;
 	break;
 
+      case 'P':
+	ignore_punct = 1;
+	break;
+
       case 's':
 	show_statistics = 1;
 	break;
@@ -1320,9 +1484,13 @@ main (int argc, char *const argv[])
 #endif
 
       case 'v':
+#ifdef LERMEN_STUFF
+	printf ("wdiff (GNU %s) %s %s\n", PACKAGE, VERSION, LVERSION);
+#else
 	printf ("wdiff (GNU %s) %s\n", PACKAGE, VERSION);
+#endif
 	fputs (_("\
 \n\
 Copyright (C) 1992, 1997 Free Software Foundation, Inc.\n"),
 	     stdout);
 	fputs (_("\
@@ -1351,6 +1520,12 @@ Written by Franc,ois Pinard <pinard@iro.
 	user_insert_end = optarg;
 	break;
 
+#ifdef LERMEN_STUFF
+      case 'c':
+	init_savebuffers(atoi(optarg));
+	break;
+#endif
+
       default:
 	usage (EXIT_FAILURE);
       }
@@ -1361,6 +1536,13 @@ Written by Franc,ois Pinard <pinard@iro.
       usage (EXIT_FAILURE);
     }
 
+#ifdef LERMEN_STUFF
+  if (context_lines) {
+     inhibit_common = 0;
+     if (inhibit_right && inhibit_left) inhibit_right = 0;
+  }
+#endif
+
   /* If find_termcap still undecided, make it true only if autopager is set
      while stdout is directed to a terminal.  This decision might be
      reversed later, if the pager happens to be "less".  */
--- wdiff-0.5.93/src/xwdiff.orig	2009-08-03 21:36:17.993713000 +0200
+++ wdiff-0.5.93/src/xwdiff	2009-08-03 21:36:17.997709000 +0200
@@ -0,0 +1,307 @@
+#!/bin/bash
+# the next line restarts using wish \
+exec wish "$0" "$@"
+
+proc positionWindow w {
+  wm geometry $w +100+100
+}
+
+proc positionWindowRelative {w masterw dx dy} {
+  set xx [split [wm geometry $masterw] +]
+  wm geometry $w "+[expr [lindex $xx 1] + $dx]+[expr [lindex $xx 2] + $dy]"
+}
+
+proc positionSubWindow {w} {
+  positionWindowRelative $w . 0 +45
+}
+
+set answer 0
+
+proc ___read_and_display_output { w titletext but1 but2 movto filehandle} {
+    global answer
+    if {$w != ""} {
+      catch {destroy $w}
+      toplevel $w
+      set w_ $w
+    } else {
+      set w_ .
+    }
+    wm title $w_ $titletext
+    wm iconname $w_ $titletext
+    positionWindow $w_
+    set line ""
+
+
+    frame $w.buttons
+    pack  $w.buttons -side bottom -expand y -fill x -pady 2m
+    set answer 0
+    button $w.buttons.but1 -text $but1 -width 20 -command "destroy $w; global answer; set answer 0"
+    if { "$but2" == "" } {
+	pack $w.buttons.but1 -side left -expand 1
+    } else {
+	button $w.buttons.but2 -text $but2 -width 20 -command "destroy $w; global answer; set answer 1"
+	pack $w.buttons.but1 $w.buttons.but2 -side left -expand 1
+    }
+    text $w.text -relief sunken -bd 2 -yscrollcommand "$w.scroll set" -setgrid 1 -height 25 -width 80
+    scrollbar $w.scroll -command "$w.text yview"
+    pack $w.scroll -side right -fill y
+    pack $w.text -expand yes -fill both
+    $w.text configure -background #fff2dc
+    $w.text configure -font -*-courier-medium-r-*-*-14-*-*-*-*-*-*-*
+
+    $w.text tag configure overstrike -overstrike on
+    $w.text tag configure boldoverstrike -overstrike on -font -*-courier-bold-r-*-*-14-*-*-*-*-*-*-*
+    $w.text tag configure bold -font -*-courier-bold-r-*-*-14-*-*-*-*-*-*-*
+#    $w.text tag configure color1 -background black -foreground white
+#    $w.text tag configure color1 -foreground #ff1800
+#    $w.text tag configure color1 -foreground #0000c0
+    $w.text tag configure boldblue -font -*-courier-bold-r-*-*-14-*-*-*-*-*-*-* -foreground #0000b0
+    set instag boldblue
+    set deltag boldoverstrike
+    set tag ""
+    set need_newline 0;
+    while {[eof $filehandle] == 0} {
+       set ret [gets $filehandle line]
+       if {$ret < 0} {
+          continue
+       }
+       if {[string compare "\x1bY1" $line] == 0} {
+         set need_newline 0;
+         set tag $instag
+         continue
+       }
+       if {[string compare "\x1bY0" $line] == 0} {
+         set need_newline 0;
+         set tag ""
+         continue
+       }
+       if {[string compare "\x1bX1" $line] == 0} {
+         set need_newline 0;
+         set tag $deltag
+         continue
+       }
+       if {[string compare "\x1bX0" $line] == 0} {
+         set need_newline 0;
+         set tag ""
+         continue
+       }
+       if {$need_newline} {$w.text insert end "\n"}
+       set need_newline 1;
+       $w.text insert end $line $tag
+    }
+    $w.text yview moveto $movto
+    vwait answer
+    return $answer
+}
+
+set lastsearchtx ""
+set lastcur ""
+
+# textSearch --
+# Search for all instances of a given string in a text widget and
+# apply a given tag to each instance found.
+#
+# Arguments:
+# w -		The window in which to search.  Must be a text widget.
+# string -	The string to search for.  The search is done using
+#		exact matching only;  no special characters.
+# tag -		Tag to apply to each instance of a matching string.
+
+proc textSearch {w string tag} {
+    global lastcur
+    $w tag remove search 0.0 end
+    set lastcur ""
+    if {$string == ""} {
+	return
+    }
+    set cur 1.0
+    while 1 {
+	set cur [$w search -nocase -count length $string $cur end]
+	if {$cur == ""} {
+	    if {$lastcur != ""} {$w yview $lastcur}
+	    break
+	}
+        if {$lastcur == ""} {set lastcur $cur}
+	$w tag add $tag $cur "$cur + $length char"
+	set cur [$w index "$cur + $length char"]
+    }
+}
+
+
+proc textSearchjmp {w string tag} {
+  global lastsearchtx lastcur
+  if { ($lastcur != "") && ([string compare $lastsearchtx $string] == 0) } {
+puts ">$lastcur< >$lastsearchtx<"
+     set lastcur [lindex [$w tag nextrange $tag [expr $lastcur + 1.0] end] 0]
+puts ">$lastcur<"
+     if {$lastcur != ""} {$w yview $lastcur}
+  } else {
+     textSearch $w $string $tag
+     set lastsearchtx $string
+  }
+}
+
+proc gotopos {w pos} {
+  global lastcur
+  $w yview $pos
+  set lastcur [ $w index $pos ]
+}
+
+proc read_and_display_output { w titletext but1 but2 movto filehandle} {
+    global answer lastcur
+    if {$w != ""} {
+      catch {destroy $w}
+      toplevel $w
+      set w_ $w
+    } else {
+      set w_ .
+    }
+    wm title $w_ $titletext
+    wm iconname $w_ $titletext
+    positionWindow $w_
+    set line ""
+
+
+    frame $w.buttons
+    pack  $w.buttons -side bottom -expand y -fill x -pady 2m
+    set answer 0
+    button $w.buttons.but1 -text $but1 -command "destroy $w; global answer; set answer 0"
+    if { "$but2" == "" } {
+	pack $w.buttons.but1 -side left -expand 1
+    } else {
+	button $w.buttons.but2 -text $but2 -width 20 -command "destroy $w; global answer; set answer 1"
+	pack $w.buttons.but1 $w.buttons.but2 -side left -expand 1
+    }
+
+    button $w.buttons.top -text "Go top" -anchor w -command \
+	"gotopos $w.text 1.0"
+    button $w.buttons.bot -text "Go bottom" -anchor w -command \
+	"gotopos $w.text end"
+    pack $w.buttons.top $w.buttons.bot -side left -expand 1
+
+    label $w.buttons.label -textvariable lastcur -anchor w -width 8
+    button $w.buttons.search -text "Search" -anchor w -command \
+	"textSearchjmp $w.text \$searchString search"
+    entry $w.buttons.entry -width 40 -textvariable searchString
+    pack $w.buttons.label $w.buttons.entry $w.buttons.search -side left -padx 2
+    bind $w.buttons.entry <Return> "textSearchjmp $w.text \$searchString search"
+
+    text $w.text -relief sunken -bd 2 -yscrollcommand "$w.scroll set" -setgrid 1 -height 25 -width 80
+    scrollbar $w.scroll -command "$w.text yview"
+    pack $w.scroll -side right -fill y
+    pack $w.text -expand yes -fill both
+    $w.text configure -background #fff2dc
+    $w.text configure -font -*-courier-medium-r-*-*-14-*-*-*-*-*-*-*
+
+    $w.text tag configure overstrike -overstrike on
+    $w.text tag configure boldoverstrike -overstrike on -font -*-courier-bold-r-*-*-14-*-*-*-*-*-*-*
+    $w.text tag configure bold -font -*-courier-bold-r-*-*-14-*-*-*-*-*-*-*
+#    $w.text tag configure color1 -background black -foreground white
+#    $w.text tag configure color1 -foreground #ff1800
+#    $w.text tag configure color1 -foreground #0000c0
+    $w.text tag configure boldblue -font -*-courier-bold-r-*-*-14-*-*-*-*-*-*-* -foreground #0000b0
+
+$w.text tag configure search -background #c83000 -foreground white \
+       -relief raised -borderwidth 2
+
+    set instag boldblue
+    set deltag boldoverstrike
+    set tag ""
+    set need_newline 0;
+    while {[eof $filehandle] == 0} {
+       set ret [gets $filehandle line]
+       if {$ret < 0} {
+          continue
+       }
+       if {[string compare "\x1bY1" $line] == 0} {
+         set need_newline 0;
+         set tag $instag
+         continue
+       }
+       if {[string compare "\x1bY0" $line] == 0} {
+         set need_newline 0;
+         set tag ""
+         continue
+       }
+       if {[string compare "\x1bX1" $line] == 0} {
+         set need_newline 0;
+         set tag $deltag
+         continue
+       }
+       if {[string compare "\x1bX0" $line] == 0} {
+         set need_newline 0;
+         set tag ""
+         continue
+       }
+       if {$need_newline} {$w.text insert end "\n"}
+       set need_newline 1;
+       $w.text insert end $line $tag
+    }
+    $w.text yview moveto $movto
+    vwait answer
+    return $answer
+}
+
+proc usage {} {
+  puts {
+USAGE:
+  xwdiff oldfile newfile
+  xwdiff -w numcontextlines oldfile newfile >prepared_diff_file
+  xwdiff -view TitleText <prepared_diff_file
+  xwdiff -a numcontextlines oldfile newfile >plain_ascii_diff
+}
+  exit 1
+}
+
+set secondphase "-view"
+set option_W    "-w"
+set option_D    "-a"
+set arg1 [lindex $argv 0]
+
+if { [string compare $arg1 $option_W] == 0 } {
+  set context [lindex $argv 1]
+  set n1 [lindex $argv 2]
+  set n2 [lindex $argv 3]
+  if {$n2 == ""} {usage} 
+  catch {exec wdiff -w "\n\x1bX1\n" -x "\n\x1bX0\n" \
+     -y "\n\x1bY1\n" -z "\n\x1bY0\n" -c $context $n1 $n2 >@ file1 }
+  exit
+}
+
+if { [string compare $arg1 $option_D] == 0 } {
+  set context [lindex $argv 1]
+  set n1 [lindex $argv 2]
+  set n2 [lindex $argv 3]
+  if {$n2 == ""} {usage} 
+#  catch {exec wdiff -w "\n\[---\n" -x "\n---\]\n" \
+#     -y "\n\{+++\n" -z "\n+++\}\n" -c $context $n1 $n2 >@ file1}
+  catch {exec wdiff -w "\n\[OLD\n" -x "\n\\OLD\]\n" \
+     -y "\n\{NEW\n" -z "\n\\NEW\}\n" -c $context $n1 $n2 >@ file1}
+  exit
+}
+
+if { [string compare $arg1 $secondphase] } {
+  set n1 [lindex $argv 0]
+  set n2 [lindex $argv 1]
+  if {$n2 == ""} {usage}
+  catch { exec wdiff -w "\n\x1bX1\n" -x "\n\x1bX0\n" -y "\n\x1bY1\n" \
+     -z "\n\x1bY0\n" -c4 $n1 $n2 | $argv0 $secondphase "xwdiff $n2"}
+  exit
+}
+
+set arg2 [lindex $argv 1]
+if {$arg2 == ""} {usage} 
+
+read_and_display_output "" $arg2 Quit "" 0 file0
+exit
+
+
+
+
+
+
+
+
+
+
+
openSUSE Build Service is sponsored by