/* Généré par gen_typedebug.tcl depuis tclTypeDebug.tcl : ne pas modifier. */
static const char typeDebugScript[] =
"# tclTypeDebug.tcl -- v16y : le crochet par défaut de « type debug ».\n"
"#\n"
"# Source de tclTypeDebug.h (une chaîne C, chargée par « type debug on ») :\n"
"# tclsh gen_typedebug.tcl\n"
"# Chargé une fois par interpréteur (garde sur ::tcl::typedebug::hit).\n"
"#\n"
"# hit NOTE MOTS INDICE appelé par la trace avant une commande dont\n"
"# l'argument INDICE porte la note NOTE (0 : un\n"
"# arrêt « type debug next », note @next)\n"
"# when ?NOM ?EXPR?\? les conditions des notes @NOM\n"
"# console ?on|off? la console Tk (sinon l'invite sur stdin)\n"
"# report INV NOMS le texte de « type debug report »\n"
"\n"
"if {[info commands ::tcl::typedebug::hit] eq {}} {\n"
"namespace eval ::tcl::typedebug {\n"
" variable run 0\t\t;# 1 : plus d'arrêt (r)\n"
" variable when {}\t\t;# NOM -> expression\n"
" variable hits {}\t\t;# NOM -> passages\n"
" variable ui stdin\t\t;# stdin | tk\n"
" variable action {}\t\t;# console : ce que l'utilisateur a choisi\n"
" variable stop {}\t\t;# console : l'arrêt courant (dict)\n"
"\n"
" proc short {v {n 60}} {\n"
" set s [string map {\\n { } \\t { }} $v]\n"
" if {[string length $s] > $n} {set s [string range $s 0 $n-4]...}\n"
" return $s\n"
" }\n"
"\n"
" # Le lieu de la commande tracée : UP cadres sous l'appelant de where.\n"
" proc where {{up 3}} {\n"
" set n [info frame]\n"
" for {set k [expr {$n - $up}]} {$k > 0} {incr k -1} {\n"
" set f [info frame $k]\n"
" if {[dict exists $f file] && [dict exists $f line]} {\n"
" return \"[file tail [dict get $f file]]:[dict get $f line]\"\n"
" }\n"
" }\n"
" return ?\n"
" }\n"
"\n"
" # type debug when ?NOM ?EXPR?\? : sans argument, toutes les conditions ;\n"
" # EXPR vide : retire la condition.\n"
" proc when {args} {\n"
" variable when\n"
" switch [llength $args] {\n"
" 0 {return $when}\n"
" 1 {\n"
" set n [string trimleft [lindex $args 0] @]\n"
" return [expr {[dict exists $when $n] ? [dict get $when $n] : {}}]\n"
" }\n"
" 2 {\n"
" lassign $args n e\n"
" set n [string trimleft $n @]\n"
" if {$e eq {}} {\n"
" dict unset when $n\n"
" } else {\n"
" # l'expression doit au moins se compiler\n"
" if {[catch {apply [list {value cmd arg hits} [list expr $e]] 0 {} {} 0} msg opt]\n"
" && [lrange [dict get $opt -errorcode] 0 1] eq {TCL PARSE}} {\n"
" return -code error \"type debug when: $msg\"\n"
" }\n"
" dict set when $n $e\n"
" }\n"
" return\n"
" }\n"
" }\n"
" return -code error {wrong # args: should be \"type debug when ?note ?expr?\?\"}\n"
" }\n"
"\n"
" proc reset {} {\n"
" variable run 0\n"
" variable hits {}\n"
" }\n"
"\n"
" proc hit {note words index} {\n"
" variable run\n"
" variable when\n"
" variable hits\n"
" set name [string range $note 1 end]\n"
" dict incr hits $name\n"
" set cmd [lindex $words 0]\n"
" set full [uplevel 1 [list namespace which -command $cmd]]\n"
" set lv [expr {[info level] - 1}]\n"
" set in [expr {$lv > 0 ? \"[lindex [info level $lv] 0]\" : \"(global)\"}]\n"
" set value {}\n"
" if {$index == 0} {\n"
" set what {}\n"
" set line \"$note [short $words]\"\n"
" } else {\n"
" set value [lindex $words $index]\n"
" set what \"argument $index\"\n"
" if {$full ne \"\" && [info procs $full] ne \"\"} {\n"
" set a [info args $full]\n"
" if {$index - 1 < [llength $a]} {set what [lindex $a [expr {$index - 1}]]}\n"
" set cmd $full\n"
" }\n"
" set line \"$note $cmd $what = [short $value]\"\n"
" }\n"
" # une condition : la note ne se signale que si elle est vraie\n"
" if {[dict exists $when $name]} {\n"
" if {[catch {apply [list {value cmd arg hits} [list expr [dict get $when $name]]] \\\n"
" $value $cmd $what [dict get $hits $name]} ok]} {\n"
" set line \"$line (condition: $ok)\"\n"
" } elseif {![string is true -strict $ok]} {\n"
" return\n"
" }\n"
" }\n"
" set at [where]\n"
" set line \"$line ($at, in $in)\"\n"
" set stop [expr {$note ne \"@trace\" && !$run}]\n"
" variable ui\n"
" if {$ui eq \"tk\" && [winfo exists .tcltypedebug]} {\n"
" return [TkHit $line $stop [dict create note $note cmd $cmd \\\n"
" what $what value $value words $words at $at in $in level $lv]]\n"
" }\n"
" puts stderr $line\n"
" if {!$stop} return\n"
" while 1 {\n"
" puts -nonewline stderr \"step> \"; flush stderr\n"
" if {[gets stdin line] < 0} {set run 1; return}\n"
" set line [string trim $line]\n"
" switch -- $line {\n"
" {} - c {return}\n"
" s {type debug next; return}\n"
" r {set run 1; return}\n"
" o {set run 0; type debug off; return}\n"
" q {return -code error \"type debug: stopped at $cmd\"}\n"
" w {for {set k $lv} {$k > 0} {incr k -1} {puts stderr \" $k: [short [info level $k]]\"}; continue}\n"
" v {puts stderr \" [uplevel 1 {info locals}]\"; continue}\n"
" h - ? {puts stderr { c: continue s: step (stop at the next command) r: run (no more pauses) o: debug off q: stop (error) w: where v: local variables p NAME: a variable other: a Tcl command, run here}; continue}\n"
" }\n"
" if {[lindex $line 0] eq \"p\" && [llength $line] == 2} {\n"
" set line [list set [lindex $line 1]]\n"
" }\n"
" if {[catch {uplevel 1 $line} r]} {puts stderr \" error: $r\"} else {puts stderr \" $r\"}\n"
" }\n"
" }\n"
"\n"
" # ---------------------------------------------------------------- Tk\n"
"\n"
" # type debug console ?on|off?\n"
" proc console {{how on}} {\n"
" variable ui\n"
" switch -- $how {\n"
" on {\n"
" if {[catch {package require Tk} msg]} {\n"
" return -code error \"type debug console: Tk is not available ($msg)\"\n"
" }\n"
" TkBuild\n"
" set ui tk\n"
" }\n"
" off {\n"
" set ui stdin\n"
" destroy .tcltypedebug\n"
" variable action c\t;# un arrêt en cours continue\n"
" }\n"
" default {return -code error {wrong # args: should be \"type debug console ?on|off?\"}}\n"
" }\n"
" return\n"
" }\n"
"\n"
" proc TkBuild {} {\n"
" set w .tcltypedebug\n"
" if {[winfo exists $w]} {wm deiconify $w; raise $w; return}\n"
" toplevel $w\n"
" wm title $w \"type debug\"\n"
" wm geometry $w 860x600\n"
" wm protocol $w WM_DELETE_WINDOW {::tcl::typedebug::console off}\n"
"\n"
" ttk::frame $w.top -padding 6\n"
" ttk::label $w.top.where -text \"(en marche)\" -font TkHeadingFont -anchor w\n"
" ttk::label $w.top.value -text \"\" -anchor w -font TkFixedFont\n"
" pack $w.top.where $w.top.value -side top -fill x\n"
"\n"
" ttk::frame $w.bar -padding {6 0}\n"
" foreach {b label key} {c Continuer F5 s Pas F10 r Courir F8 q Arrêter F12 o Couper {}} {\n"
" ttk::button $w.bar.$b -text [expr {$key ne {} ? \"$label ($key)\" : $label}] \\\n"
" -command [list ::tcl::typedebug::TkAct $b]\n"
" pack $w.bar.$b -side left -padx 2\n"
" if {$key ne {}} {bind $w <$key> [list ::tcl::typedebug::TkAct $b]}\n"
" }\n"
"\n"
" ttk::panedwindow $w.pw -orient vertical\n"
" ttk::panedwindow $w.pw.h -orient horizontal\n"
" ttk::labelframe $w.pw.h.stack -text Pile -padding 2\n"
" listbox $w.pw.h.stack.l -exportselection 0 -font TkFixedFont -width 30 -activestyle none\n"
" pack $w.pw.h.stack.l -fill both -expand 1\n"
" bind $w.pw.h.stack.l <<ListboxSelect>> {::tcl::typedebug::TkAct vars}\n"
" ttk::labelframe $w.pw.h.vars -text Variables -padding 2\n"
" ttk::treeview $w.pw.h.vars.t -columns {type value} -height 8\n"
" $w.pw.h.vars.t heading #0 -text nom -anchor w\n"
" $w.pw.h.vars.t heading type -text {type {notes}} -anchor w\n"
" $w.pw.h.vars.t heading value -text valeur -anchor w\n"
" $w.pw.h.vars.t column #0 -width 110 -stretch 0\n"
" $w.pw.h.vars.t column type -width 120 -stretch 0\n"
" $w.pw.h.vars.t column value -width 300\n"
" ttk::scrollbar $w.pw.h.vars.s -command [list $w.pw.h.vars.t yview]\n"
" $w.pw.h.vars.t configure -yscrollcommand [list $w.pw.h.vars.s set]\n"
" pack $w.pw.h.vars.s -side right -fill y\n"
" pack $w.pw.h.vars.t -fill both -expand 1\n"
" $w.pw.h add $w.pw.h.stack -weight 1\n"
" $w.pw.h add $w.pw.h.vars -weight 3\n"
"\n"
" ttk::labelframe $w.pw.log -text Journal -padding 2\n"
" text $w.pw.log.t -height 10 -font TkFixedFont -wrap none -state disabled\n"
" ttk::scrollbar $w.pw.log.s -command [list $w.pw.log.t yview]\n"
" $w.pw.log.t configure -yscrollcommand [list $w.pw.log.s set]\n"
" $w.pw.log.t tag configure stop -foreground #b00000\n"
" $w.pw.log.t tag configure out -foreground #005a9e\n"
" $w.pw.log.t tag configure err -foreground #b00000\n"
" pack $w.pw.log.s -side right -fill y\n"
" pack $w.pw.log.t -fill both -expand 1\n"
" $w.pw add $w.pw.h -weight 2\n"
" $w.pw add $w.pw.log -weight 1\n"
"\n"
" ttk::frame $w.cmd -padding 6\n"
" ttk::label $w.cmd.l -text \"Tcl :\"\n"
" ttk::entry $w.cmd.e -font TkFixedFont\n"
" bind $w.cmd.e <Return> {::tcl::typedebug::TkAct eval}\n"
" pack $w.cmd.l -side left\n"
" pack $w.cmd.e -side left -fill x -expand 1 -padx {4 0}\n"
"\n"
" pack $w.top -side top -fill x\n"
" pack $w.bar -side top -fill x\n"
" pack $w.cmd -side bottom -fill x\n"
" pack $w.pw -side top -fill both -expand 1 -padx 6\n"
" TkState 0\n"
" }\n"
"\n"
" proc TkLog {text {tag {}}} {\n"
" set t .tcltypedebug.pw.log.t\n"
" $t configure -state normal\n"
" $t insert end $text\\n $tag\n"
" $t see end\n"
" $t configure -state disabled\n"
" }\n"
"\n"
" proc TkState {stopped} {\n"
" set w .tcltypedebug\n"
" foreach b {c s r q} {\n"
" $w.bar.$b state [expr {$stopped ? {!disabled} : {disabled}}]\n"
" }\n"
" $w.cmd.e state [expr {$stopped ? {!disabled} : {disabled}}]\n"
" if {!$stopped} {\n"
" $w.top.where configure -text \"(en marche)\"\n"
" $w.top.value configure -text \"\"\n"
" $w.pw.h.stack.l delete 0 end\n"
" $w.pw.h.vars.t delete [$w.pw.h.vars.t children {}]\n"
" }\n"
" }\n"
"\n"
" # Appelé par hit, au niveau de l'appelant de la commande tracée.\n"
" proc TkHit {line stop info} {\n"
" variable action\n"
" variable stopInfo $info\n"
" if {!$stop} {\n"
" TkLog $line\n"
" return\n"
" }\n"
" TkLog $line stop\n"
" set w .tcltypedebug\n"
" set lv [dict get $info level]\n"
" $w.top.where configure -text \"[dict get $info note] [short [dict get $info words] 70] ([dict get $info at], in [dict get $info in])\"\n"
" if {[dict get $info what] ne {}} {\n"
" set v [dict get $info value]\n"
" $w.top.value configure -text \"[dict get $info what] = [short $v 70] [TkTypeOf $v]\"\n"
" } else {\n"
" $w.top.value configure -text \"\"\n"
" }\n"
" set l $w.pw.h.stack.l\n"
" $l delete 0 end\n"
" for {set k $lv} {$k > 0} {incr k -1} {\n"
" $l insert end \"$k [short [info level $k] 40]\"\n"
" }\n"
" $l insert end \"0 (global)\"\n"
" $l selection set 0\n"
" TkVars\n"
" TkState 1\n"
" wm deiconify $w; raise $w\n"
" focus $w.cmd.e\n"
" # Les gestionnaires d'événements tournent au niveau global : ils ne\n"
" # voient pas la pile arrêtée. Ils posent une action ; c'est ici,\n"
" # dans la pile, qu'on lit les variables et qu'on évalue.\n"
" while 1 {\n"
" set action {}\n"
" vwait ::tcl::typedebug::action\n"
" if {![winfo exists $w]} {set action c; break}\n"
" switch -- $action {\n"
" vars {TkVars; continue}\n"
" eval {TkEval; continue}\n"
" }\n"
" break\n"
" }\n"
" if {[winfo exists $w]} {TkState 0}\n"
" switch -- $action {\n"
" s {type debug next}\n"
" r {variable run 1}\n"
" o {variable run 0; type debug off}\n"
" q {return -code error \"type debug: stopped at [dict get $info cmd]\"}\n"
" }\n"
" return\n"
" }\n"
"\n"
" proc TkAct {a} {\n"
" variable action\n"
" set action $a\n"
" }\n"
"\n"
" # Le type et les notes d'une valeur, pour l'affichage.\n"
" proc TkTypeOf {v} {\n"
" set t [type get $v]\n"
" set n [note get $v]\n"
" if {$n ne {} && $n ne $t} {return [string trim \"$t {$n}\"]}\n"
" return $t\n"
" }\n"
"\n"
" # Le niveau choisi dans la pile (#k).\n"
" proc TkLevel {} {\n"
" set l .tcltypedebug.pw.h.stack.l\n"
" set s [$l curselection]\n"
" if {$s eq {}} {set s 0}\n"
" return [lindex [$l get $s] 0]\n"
" }\n"
"\n"
" proc TkVars {} {\n"
" set t .tcltypedebug.pw.h.vars.t\n"
" $t delete [$t children {}]\n"
" set k [TkLevel]\n"
" if {$k == 0} {\n"
" set names [lsort [lmap n [info globals] {\n"
" if {[string match tcl_* $n] || [string match auto_* $n]\n"
" || $n in {env errorInfo errorCode argv argv0 argc}} continue\n"
" set n\n"
" }]]\n"
" } else {\n"
" set names [lsort [uplevel #$k {info locals}]]\n"
" }\n"
" foreach n $names {\n"
" if {[uplevel #$k [list array exists $n]]} {\n"
" $t insert {} end -text $n -values [list array \"([uplevel #$k [list array size $n]] éléments)\"]\n"
" } elseif {[uplevel #$k [list info exists $n]]} {\n"
" set v [uplevel #$k [list set $n]]\n"
" $t insert {} end -text $n -values [list [TkTypeOf $v] [short $v 80]]\n"
" } else {\n"
" $t insert {} end -text $n -values [list {} (indéfinie)]\n"
" }\n"
" }\n"
" }\n"
"\n"
" proc TkEval {} {\n"
" set e .tcltypedebug.cmd.e\n"
" set script [$e get]\n"
" if {$script eq {}} return\n"
" $e delete 0 end\n"
" TkLog \"% $script\"\n"
" if {[catch {uplevel #[TkLevel] $script} r]} {\n"
" TkLog \" $r\" err\n"
" } else {\n"
" TkLog \" $r\" out\n"
" }\n"
" TkVars\n"
" }\n"
"\n"
" # ------------------------------------------------------------ rapport\n"
"\n"
" proc distance {a b} {\n"
" set la [string length $a]; set lb [string length $b]\n"
" set prev {}; for {set j 0} {$j <= $lb} {incr j} {lappend prev $j}\n"
" for {set i 1} {$i <= $la} {incr i} {\n"
" set cur [list $i]\n"
" for {set j 1} {$j <= $lb} {incr j} {\n"
" set c [expr {[string index $a $i-1] ne [string index $b $j-1]}]\n"
" lappend cur [expr {min([lindex $prev $j] + 1, [lindex $cur end] + 1, [lindex $prev $j-1] + $c)}]\n"
" }\n"
" set prev $cur\n"
" }\n"
" lindex $prev end\n"
" }\n"
"\n"
" proc near {name names} {\n"
" set best {}; set bd 3\n"
" foreach t [lsort $names] {\n"
" set d [distance [string tolower $name] [string tolower $t]]\n"
" if {$d < $bd && $d <= max(1, [string length $name] / 3)} {set best $t; set bd $d}\n"
" }\n"
" return $best\n"
" }\n"
"\n"
" proc report {inv names} {\n"
" if {![dict size $inv]} {return \"no notes seen\"}\n"
" set out {}\n"
" foreach name [lsort [dict keys $inv]] {\n"
" set e [dict get $inv $name]\n"
" set n [dict get $e count]\n"
" set l \"$name: seen $n time[expr {$n > 1 ? {s} : {}}], first at [dict get $e where], via [join [dict get $e commands] {, }]\"\n"
" append l \"\\n values: [join [lmap p [dict get $e samples] {short [lindex $p 0]}] { | }]\"\n"
" switch [dict get $e status] {\n"
" ok {append l \"\\n now a type: the values seen fit it\"}\n"
" mismatch {\n"
" append l \"\\n now a type, but:\"\n"
" foreach p [dict get $e errors] {append l \"\\n [short [lindex $p 0]] ([lindex $p 1]): [lindex $p 2]\"}\n"
" }\n"
" default {\n"
" set t [near $name $names]\n"
" if {$t ne {}} {append l \"\\n not a type; did you mean $t?\"} else {append l \"\\n not a type yet\"}\n"
" }\n"
" }\n"
" lappend out $l\n"
" }\n"
" join $out \\n\n"
" }\n"
"}\n"
"}\n"
;