ACC SHELL

Path : /var/lib/ntp/var/lib/ntp/proc/self/root/usr/bin/
File Upload :
Current File : //var/lib/ntp/var/lib/ntp/proc/self/root/usr/bin/xwdiff

#!/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












ACC SHELL 2018