Eskil

Check-in [354450a2ac]
Login

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

Overview
Comment:Pass ::argv to plugin
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 354450a2ac3060dedd57d3c400e884539dfcd70c
User & Date: peter 2015-03-16 19:44:35.003
Context
2015-03-16
20:12
Merge better in diffWithSeparator check-in: 4df34e6bc2 user: peter tags: trunk
19:44
Pass ::argv to plugin check-in: 354450a2ac user: peter tags: trunk
19:17
Include plugins in syntax check check-in: 263c36a391 user: peter tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Changes to Changes.
1
2

3
4
5
6
7
8
9
2015-03-16
 Added csv plugin.


2015-03-15
 Extended Mercurial support to commit, revert, log and directory diff.

2015-03-09
 Released 2.7



>







1
2
3
4
5
6
7
8
9
10
2015-03-16
 Added csv plugin.
 Pass ::argv to plugins.

2015-03-15
 Extended Mercurial support to commit, revert, log and directory diff.

2015-03-09
 Released 2.7

Changes to doc/plugins.txt.
12
13
14
15
16
17
18

19
20
21
22
23
24
25
The plugin is executed in a safe interpreter and thus cannot do any
damage.

A plugin is set up with these global variables filled in:
::WhoAmI  : The name of the plugin
::Info    : The contents of -plugininfo parameter
::Pref    : A copy if Eskil's internal preferences array.


Example plugins are included in the kit.

A plugin may give a result that has a line-by-line correspondence to
the original, in which case the preprocessed data is used for comparing
while the original is used for displaying.  The main plugin procedure
returns 0 to signify this case.







>







12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
The plugin is executed in a safe interpreter and thus cannot do any
damage.

A plugin is set up with these global variables filled in:
::WhoAmI  : The name of the plugin
::Info    : The contents of -plugininfo parameter
::Pref    : A copy if Eskil's internal preferences array.
::argv    : A copy of the command line from Eskil's invocation

Example plugins are included in the kit.

A plugin may give a result that has a line-by-line correspondence to
the original, in which case the preprocessed data is used for comparing
while the original is used for displaying.  The main plugin procedure
returns 0 to signify this case.
Changes to htdocs/plugins.wiki.
34
35
36
37
38
39
40

41
42
43
44
45
46
47
In addition to the standard safe interpreter environment, a plugin has
access to stdout as well.

A plugin is set up with these global variables filled in:
  *  ::WhoAmI : The name of the plugin
  *  ::Info   : The contents of -plugininfo parameter
  *  ::Pref   : A copy if Eskil's internal preferences array.


<h1>File plugin</h1>

To process the files being compared, the following procedure should be
defined in the plugin file:

<pre>proc PreProcess {side chi cho} {...}</pre>







>







34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
In addition to the standard safe interpreter environment, a plugin has
access to stdout as well.

A plugin is set up with these global variables filled in:
  *  ::WhoAmI : The name of the plugin
  *  ::Info   : The contents of -plugininfo parameter
  *  ::Pref   : A copy if Eskil's internal preferences array.
  *  ::argv   : A copy of the command line from Eskil's invocation

<h1>File plugin</h1>

To process the files being compared, the following procedure should be
defined in the plugin file:

<pre>proc PreProcess {side chi cho} {...}</pre>
Changes to plugins/csv.tcl.
10
11
12
13
14
15
16








17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43




44
45
46
47
48
49
50
51
52
53




54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#       examples/dir*/csv1.txt

# A plugin must define this procedure to do the job.
# side: left or right
# chi:  An input channel for reading the original file.
# cho:  An output channel for writing the processed file.
proc PreProcess {side chi cho} {








    # Look for parameters in info string
    set opts(-ignore) ""
    set opts(-key) ""
    set opts(-header) 0
    foreach {opt val} $::Info {
        set opts($opt) $val
    }
    # If any column is given by name, assume the file starts with
    # a header line of column names
    foreach col [concat $opts(-ignore) $opts(-key)] {
        if {![string is integer $col]} {
            set opts(-header) 1
        }
    }
    if {$opts(-header)} {
        set nameLine [gets $chi]
        # Keep it first in file
        puts $cho $nameLine
        set nameList [split $nameLine ","]
    }

    set icol {}
    foreach col $opts(-ignore) {
        if {[string is integer $col]} {
            lappend icol $col
        } else {
            lappend icol [lsearch $nameList $col]




        }
    }
    set icol [lsort -integer $icol]

    set kcol {}
    foreach col $opts(-key) {
        if {[string is integer $col]} {
            lappend kcol $col
        } else {
            lappend kcol [lsearch $nameList $col]




        }
    }

    set olines {}
    while {[gets $chi line] >= 0} {
        set items [split $line ","]
        foreach i $icol {
            lset items $i ""
        }
        lappend olines $items
    }
    # Sort on keys
    foreach i [lreverse $kcol] {
        set olines [lsort -index $i $olines]
    }
    foreach items $olines {
        puts $cho [join $items ","]
    }

    # Signal that the file after processing should be used both
    # for comparison and for displaying.
    return 1
}







>
>
>
>
>
>
>
>


















|







|
>
>
>
>









|
>
>
>
>





|










|






10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#       examples/dir*/csv1.txt

# A plugin must define this procedure to do the job.
# side: left or right
# chi:  An input channel for reading the original file.
# cho:  An output channel for writing the processed file.
proc PreProcess {side chi cho} {
    # Pick default -sep from command line
    set opts(-sep) ","
    set i [lsearch -exact $::argv "-sep"]
    if {$i >= 0} {
        incr i
        set opts(-sep) [lindex $::argv $i]
    }

    # Look for parameters in info string
    set opts(-ignore) ""
    set opts(-key) ""
    set opts(-header) 0
    foreach {opt val} $::Info {
        set opts($opt) $val
    }
    # If any column is given by name, assume the file starts with
    # a header line of column names
    foreach col [concat $opts(-ignore) $opts(-key)] {
        if {![string is integer $col]} {
            set opts(-header) 1
        }
    }
    if {$opts(-header)} {
        set nameLine [gets $chi]
        # Keep it first in file
        puts $cho $nameLine
        set nameList [split $nameLine $opts(-sep)]
    }

    set icol {}
    foreach col $opts(-ignore) {
        if {[string is integer $col]} {
            lappend icol $col
        } else {
            set i [lsearch $nameList $col]
            if {$i < 0} {
                return -code error "CSV Plugin Error: No such heading '$col'"
            }
            lappend icol $i
        }
    }
    set icol [lsort -integer $icol]

    set kcol {}
    foreach col $opts(-key) {
        if {[string is integer $col]} {
            lappend kcol $col
        } else {
            set i [lsearch $nameList $col]
            if {$i < 0} {
                return -code error "CSV Plugin Error: No such heading '$col'"
            }
            lappend kcol $i
        }
    }

    set olines {}
    while {[gets $chi line] >= 0} {
        set items [split $line $opts(-sep)]
        foreach i $icol {
            lset items $i ""
        }
        lappend olines $items
    }
    # Sort on keys
    foreach i [lreverse $kcol] {
        set olines [lsort -index $i $olines]
    }
    foreach items $olines {
        puts $cho [join $items $opts(-sep)]
    }

    # Signal that the file after processing should be used both
    # for comparison and for displaying.
    return 1
}
Changes to src/plugin.tcl.
152
153
154
155
156
157
158



159
160
161
162
163
164
165
        set descr [dict get $info descr]
        puts "Plugin \"$plugin\" : $descr"
    }
}

proc preparePlugin {top} {
    disallowEdit $top



    $::eskil($top,plugin) eval [list array set ::Pref [array get ::Pref]]
    set out1 [tmpFile]
    set out2 [tmpFile]

    set chi [open $::eskil($top,leftFile) r]
    set cho [open $out1 w]
    set chi2 [open $::eskil($top,rightFile) r]







>
>
>







152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
        set descr [dict get $info descr]
        puts "Plugin \"$plugin\" : $descr"
    }
}

proc preparePlugin {top} {
    disallowEdit $top
    # Pass ::argv to plugin
    $::eskil($top,plugin) eval [list set ::argv $::eskil(argv)]
    # Pass ::Pref to plugin
    $::eskil($top,plugin) eval [list array set ::Pref [array get ::Pref]]
    set out1 [tmpFile]
    set out2 [tmpFile]

    set chi [open $::eskil($top,leftFile) r]
    set cho [open $out1 w]
    set chi2 [open $::eskil($top,rightFile) r]