Eskil

Check-in [b4d998f4b8]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Support multiple plugins from command line.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: b4d998f4b8587130ec2699e7932064cefc2957b11a1354c3ffb35d1dc9a92a89
User & Date: peter 2017-12-04 23:06:18.754
Context
2017-12-04
23:13
Bumped revision to 2.8.0 check-in: fafe561dbd user: peter tags: trunk
23:06
Support multiple plugins from command line. check-in: b4d998f4b8 user: peter tags: trunk
21:51
Use newer packages. check-in: 57967f90ad user: peter tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Changes to Changes.



1
2
3
4
5
6
7



2017-12-02
 Support multiple plugins.
 Changed default pivot to 10. Include GUI choice for 1.

2017-12-01
 Added GUI for multiple plugins. No function yet.

>
>
>







1
2
3
4
5
6
7
8
9
10
2017-12-04
 Support multiple plugins from command line.

2017-12-02
 Support multiple plugins.
 Changed default pivot to 10. Include GUI choice for 1.

2017-12-01
 Added GUI for multiple plugins. No function yet.

Changes to doc/plugins.txt.
1
2
3
4
5
6


7
8
9
10




11
12
13
14
15
16
17
Eskil provides a plugin system where a plugin can preprocess data
before being compared and displayed.

The command line options for plugins are:
  -plugin plugin     : Use plugin
  -plugininfo info   : Pass info to plugin (plugin specific)


  -plugindump plugin : Dump plugin source to stdout
  -pluginlist        : List known plugins
  -pluginallow       : Allow full access privilege for a plugin.
A plugin may further define command line options that it accepts.





A plugin is a Tcl script that must follow a specific format.
Dump one of the included plugins to see what it looks like.
The plugin is executed in a safe interpreter and thus cannot do any
damage. You can turn this safety off with -pluginallow.

A plugin is set up with these global variables filled in:
|





>
>


<

>
>
>
>







1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
18
19
20
21
22
Eskil provides a plugin system where plugins can preprocess data
before being compared and displayed.

The command line options for plugins are:
  -plugin plugin     : Use plugin
  -plugininfo info   : Pass info to plugin (plugin specific)
  -pluginallow       : Allow full access privilege for a plugin.
Command line options for info:
  -plugindump plugin : Dump plugin source to stdout
  -pluginlist        : List known plugins

A plugin may further define command line options that it accepts.

Multiple -plugin may be given and they will be applied in the given
order. Any -plugininfo and -pluginallow belongs to the last -plugin
before them.

A plugin is a Tcl script that must follow a specific format.
Dump one of the included plugins to see what it looks like.
The plugin is executed in a safe interpreter and thus cannot do any
damage. You can turn this safety off with -pluginallow.

A plugin is set up with these global variables filled in:
Changes to src/plugin.tcl.
485
486
487
488
489
490
491





492
493
494
495
496
497
498
499










500
501
502
503












504
505
506
507
508
509
510

    set arg $::eskil($top,edit,pluginname,$n)
    set pOpts {}
    if {$arg ne ""} {
        set res [LocatePlugin $arg]
        set pOpts [dict get $res opts]
    }





    # Look for declarations of command line options
    set t 0
    set ::eskil($top,edit,opts,$n) $pOpts
    foreach {name flag doc} $pOpts {
        ttk::label $w.l$t -text $name
        addBalloon $w.l$t $doc
        grid $w.l$t -sticky "w" -padx 3 -pady 3
        if {$flag} {










            ttk::checkbutton $w.s$t -text "On" \
                    -variable ::eskil($top,edit,$name,$n)
            grid $w.s$t -row $t -column 1 -sticky "w" -padx 3 -pady 3
        } else {












            ttk::entry $w.s$t \
                    -textvariable ::eskil($top,edit,$name,$n)
            grid $w.s$t -row $t -column 1 -sticky we -padx 3 -pady 3
        }
        incr t
    }
    grid columnconfigure $w 1 -weight 1







>
>
>
>
>








>
>
>
>
>
>
>
>
>
>




>
>
>
>
>
>
>
>
>
>
>
>







485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537

    set arg $::eskil($top,edit,pluginname,$n)
    set pOpts {}
    if {$arg ne ""} {
        set res [LocatePlugin $arg]
        set pOpts [dict get $res opts]
    }
    # Look for defaults on the command line
    set pArgv $::eskil(argv)
    if {[info exists ::eskil($top,pluginargv,$n)]} {
        lappend pArgv {*}$::eskil($top,pluginargv,$n)
    }
    # Look for declarations of command line options
    set t 0
    set ::eskil($top,edit,opts,$n) $pOpts
    foreach {name flag doc} $pOpts {
        ttk::label $w.l$t -text $name
        addBalloon $w.l$t $doc
        grid $w.l$t -sticky "w" -padx 3 -pady 3
        if {$flag} {
            # Initialise if given.
            if {[lsearch -exact $pArgv $name] >= 0} {
                set ::eskil($top,edit,$name,$n) 1
                # Move responsibility from global argv
                set ix [lsearch -exact $::eskil(argv) $name]
                if {$ix >= 0} {
                    set ::eskil(argv) [lreplace $::eskil(argv) $ix $ix]
                    lappend ::eskil($top,pluginargv,$n) $name
                }
            }
            ttk::checkbutton $w.s$t -text "On" \
                    -variable ::eskil($top,edit,$name,$n)
            grid $w.s$t -row $t -column 1 -sticky "w" -padx 3 -pady 3
        } else {
            # Initialise if given.
            set ix [lsearch -exact $pArgv $name]
            if {$ix >= 0} {
                set ::eskil($top,edit,$name,$n) [lindex $pArgv $ix+1]
                # Move responsibility from global argv
                set ix [lsearch -exact $::eskil(argv) $name]
                if {$ix >= 0} {
                    lappend ::eskil($top,pluginargv,$n) $name \
                            [lindex $::eskil(argv) $ix+1]
                    set ::eskil(argv) [lreplace $::eskil(argv) $ix $ix+1]
                }
            }
            ttk::entry $w.s$t \
                    -textvariable ::eskil($top,edit,$name,$n)
            grid $w.s$t -row $t -column 1 -sticky we -padx 3 -pady 3
        }
        incr t
    }
    grid columnconfigure $w 1 -weight 1
Changes to src/startup.tcl.
367
368
369
370
371
372
373

374
375
376
377
378
379
380
381
382
383
                set chunk [string range $d 0 $ci-1]
                set d [string trim [string range $d $ci end]]
            }
            puts "$outName$chunk"
            set outName [format %*s $indent ""]
        }
    }

    if {$::eskil(opts,src) ne ""} {
        puts ""
        printPlugin $::eskil(opts,src) 1
    }
}

#####################################
# Option/flag handling helpers
#####################################
# Validators







>
|

|







367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
                set chunk [string range $d 0 $ci-1]
                set d [string trim [string range $d $ci end]]
            }
            puts "$outName$chunk"
            set outName [format %*s $indent ""]
        }
    }
    # Dump any plugin that has options defined
    foreach {plugin _} $::eskil(opts,src) {
        puts ""
        printPlugin $plugin 1
    }
}

#####################################
# Option/flag handling helpers
#####################################
# Validators
434
435
436
437
438
439
440








441





442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466









467
468
469
470
471
472
473
            addFlags $name
        } else {
            addOpt $name
        }
        docFlag $name "Plugin $arg : $doc"
        addSource $name $arg
    }








}





# Option database setup
proc initOpts {} {
    set ::eskil(opts) {}
    set ::eskil(opts,info) {}
    set ::eskil(opts,src) ""
    set ::eskil(defoptinfo) {
        flag 0
        given 0
        multi 0
        type ""
        validator ""
        filter ""
        sideeffect ""
        shortdescr ""
        longdescr ""
        source ""
    } 
}
# Add a command line flag that do not take a value
proc addFlags {args} {
    foreach name $args {
        dict set ::eskil(opts) $name 0
        dict set ::eskil(opts,info) $name $::eskil(defoptinfo)
        dict set ::eskil(opts,info) $name flag  1
    }









}
# Document a flag or option
proc docFlag {name short {long {}}} {
    dict set ::eskil(opts,info) $name shortdescr $short
    dict set ::eskil(opts,info) $name longdescr $long
}








>
>
>
>
>
>
>
>
|
>
>
>
>
>




|




















>
>
>
>
>
>
>
>
>







435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
            addFlags $name
        } else {
            addOpt $name
        }
        docFlag $name "Plugin $arg : $doc"
        addSource $name $arg
    }
    # Special:
    # If a -plugin is given and plugininfo and pluginallow is not
    # balanced, extend them.
    set n [llength [dict get $::eskil(opts) -plugin]]
    # Validator is called after this -plugin was added.
    incr n -1
    while {[llength [dict get $::eskil(opts) -plugininfo]] < $n} {
        dict lappend ::eskil(opts) -plugininfo ""
    }
    while {[llength [dict get $::eskil(opts) -pluginallow]] < $n} {
        dict lappend ::eskil(opts) -pluginallow 0
    }
}

# Option database setup
proc initOpts {} {
    set ::eskil(opts) {}
    set ::eskil(opts,info) {}
    set ::eskil(opts,src) {}
    set ::eskil(defoptinfo) {
        flag 0
        given 0
        multi 0
        type ""
        validator ""
        filter ""
        sideeffect ""
        shortdescr ""
        longdescr ""
        source ""
    } 
}
# Add a command line flag that do not take a value
proc addFlags {args} {
    foreach name $args {
        dict set ::eskil(opts) $name 0
        dict set ::eskil(opts,info) $name $::eskil(defoptinfo)
        dict set ::eskil(opts,info) $name flag  1
    }
}
# Add a command line flag that do not take a value, but can be given multiple
proc addMultFlags {args} {
    foreach name $args {
        dict set ::eskil(opts) $name {}
        dict set ::eskil(opts,info) $name $::eskil(defoptinfo)
        dict set ::eskil(opts,info) $name flag  1
        dict set ::eskil(opts,info) $name multi 1
    }
}
# Document a flag or option
proc docFlag {name short {long {}}} {
    dict set ::eskil(opts,info) $name shortdescr $short
    dict set ::eskil(opts,info) $name longdescr $long
}

508
509
510
511
512
513
514

515

516
517
518
519
520
521
522
}
# Add a filter command prefix to an Opt
proc addFilter {name cmd} {
    dict set ::eskil(opts,info) $name filter $cmd
}
# Add a source reference to an Opt
proc addSource {name src} {

    set ::eskil(opts,src) $src

    dict set ::eskil(opts,info) $name source $src
}
# Add a sideeffect to an Opt
##nagelfar syntax addSideEffect x c
proc addSideEffect {name script} {
    dict set ::eskil(opts,info) $name sideeffect $script
}







>
|
>







531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
}
# Add a filter command prefix to an Opt
proc addFilter {name cmd} {
    dict set ::eskil(opts,info) $name filter $cmd
}
# Add a source reference to an Opt
proc addSource {name src} {
    # Remember them if needed for -help
    dict set ::eskil(opts,src) $src 1
    # This points to the plugin the Opt belongs to.
    dict set ::eskil(opts,info) $name source $src
}
# Add a sideeffect to an Opt
##nagelfar syntax addSideEffect x c
proc addSideEffect {name script} {
    dict set ::eskil(opts,info) $name sideeffect $script
}
678
679
680
681
682
683
684
685

686
687
688
689
690
691
692
693
694
695
696
697
698
699
    addFlags -foreach -close
    docFlag -foreach "Open one diff window per file listed"
    docFlag -close   "Close windows with no changes"
    addFlags -nonewline -nonewline+ -nocdiff
    docFlag -nonewline  "Try to ignore newline changes"
    docFlag -nonewline+ "Try to ignore newline changes, and don't display"
    docFlag -nocdiff    "Disable C version of DiffUtil. For debug"
    addFlags -pluginlist -pluginallow

    docFlag -pluginlist  "List known plugins"
    docFlag -pluginallow "Allow full access privilege for a plugin"
    # Options that take values
    addOpt   -plugin
    docFlag  -plugin "Preprocess files using plugin"
    addValidator -plugin optValidatePlugin
    addOpt   -plugininfo
    docFlag  -plugininfo "Pass info to plugin (plugin specific)"
    addOpt   -plugindump
    docFlag  -plugindump "Dump plugin source to stdout"
    # These options affect Pref
    addPrefOpt -pivot             pivot             optValidatePositive
    docFlag    -pivot "Pivot setting for diff algorithm (10)"
    addPrefOpt -context           context           optValidateNatural







|
>

|

|


|







703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
    addFlags -foreach -close
    docFlag -foreach "Open one diff window per file listed"
    docFlag -close   "Close windows with no changes"
    addFlags -nonewline -nonewline+ -nocdiff
    docFlag -nonewline  "Try to ignore newline changes"
    docFlag -nonewline+ "Try to ignore newline changes, and don't display"
    docFlag -nocdiff    "Disable C version of DiffUtil. For debug"
    addFlags -pluginlist
    addMultFlags -pluginallow
    docFlag -pluginlist  "List known plugins"
    docFlag -pluginallow "Allow full access privilege for plugin"
    # Options that take values
    addMultOpt -plugin
    docFlag  -plugin "Preprocess files using plugin"
    addValidator -plugin optValidatePlugin
    addMultOpt -plugininfo
    docFlag  -plugininfo "Pass info to plugin (plugin specific)"
    addOpt   -plugindump
    docFlag  -plugindump "Dump plugin source to stdout"
    # These options affect Pref
    addPrefOpt -pivot             pivot             optValidatePositive
    docFlag    -pivot "Pivot setting for diff algorithm (10)"
    addPrefOpt -context           context           optValidateNatural
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
        printUsage
        exit
    }

    # All options have been parsed, extract them to where they need to go

    # Straight to locals
    set plugin      [optGet -plugin]
    set plugininfo  [optGet -plugininfo]
    set plugindump  [optGet -plugindump]
    set pluginlist  [optGet -pluginlist]
    set pluginallow [optGet -pluginallow]
    set noautodiff  [optGet -nodiff]
    set nocdiff     [optGet -nocdiff]
    set dodir       [optGet -dir]
    set doclip      [optGet -clip]
    set dopatch     [optGet -patch]
    set doreview    [optGet -review]
    set autobrowse  [optGet -browse]







|
|


|







836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
        printUsage
        exit
    }

    # All options have been parsed, extract them to where they need to go

    # Straight to locals
    set pluginL     [optGet -plugin]
    set plugininfoL [optGet -plugininfo]
    set plugindump  [optGet -plugindump]
    set pluginlist  [optGet -pluginlist]
    set pluginallowL [optGet -pluginallow]
    set noautodiff  [optGet -nodiff]
    set nocdiff     [optGet -nocdiff]
    set dodir       [optGet -dir]
    set doclip      [optGet -clip]
    set dopatch     [optGet -patch]
    set doreview    [optGet -review]
    set autobrowse  [optGet -browse]
913
914
915
916
917
918
919





920

921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
        printPlugins
        exit
    }
    if {$plugindump ne ""} {
        printPlugin $plugindump
        exit
    }





    if {$plugin ne ""} {

        set pinterp [createPluginInterp $plugin $plugininfo $pluginallow pinfo]
        if {$pinterp eq ""} {
            # This should not happen since the validator should handle it
            puts "Bad plugin: $plugin"
            printPlugins
            exit
        }
        # TBD: Support multiple plugins on command line.
        set opts(plugin,1) $pinterp
        set opts(pluginname,1) $plugin
        set opts(pluginallow,1) $pluginallow
        set opts(plugininfo,1) $plugininfo
        set opts(pluginpinfo,1) $pinfo
    }

    # Store the command line given opts
    set ::eskil(defaultopts) [array get opts]

    # Do we start in clip diff mode?
    if {$doclip} {







>
>
>
>
>
|
>







<
|
|
|
|
|







939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959

960
961
962
963
964
965
966
967
968
969
970
971
        printPlugins
        exit
    }
    if {$plugindump ne ""} {
        printPlugin $plugindump
        exit
    }
    set t 0
    foreach plugin $pluginL {
        set plugininfo [lindex $plugininfoL $t]
        set pluginallow [lindex $pluginallowL $t]
        # If pluginallow list is too short
        if {$pluginallow eq ""} { set pluginallow 0 }
        incr t
        set pinterp [createPluginInterp $plugin $plugininfo $pluginallow pinfo]
        if {$pinterp eq ""} {
            # This should not happen since the validator should handle it
            puts "Bad plugin: $plugin"
            printPlugins
            exit
        }

        set opts(plugin,$t) $pinterp
        set opts(pluginname,$t) $plugin
        set opts(pluginallow,$t) $pluginallow
        set opts(plugininfo,$t) $plugininfo
        set opts(pluginpinfo,$t) $pinfo
    }

    # Store the command line given opts
    set ::eskil(defaultopts) [array get opts]

    # Do we start in clip diff mode?
    if {$doclip} {