Eskil

Diff
Login

Differences From Artifact [ce103c93d2]:

To Artifact [4131c2e1a5]:


1



2
3
4

5



6
7
8
9

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
1
2
3
4
5
6

7
8
9
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

+
+
+


-
+

+
+
+



-
+







-
+

+
+
+
+
-
-
-
+
+
+
-
-
-
+
+
+
-
-
-
-
+
+
+
+
+
+
+





-
+

-
+


-
+







-
+













-
+







##Eskil Plugin : Compare comma separated value (CSV) files
## Option -csvignore : A list of columns to ignore
## Option -csvkey    : A list of columns to sort on before comparison
## Flag   -csvheader : First line is a header line defining names of columns

# Example file for a plugin.
# A plugin must start exactly like this one.
# A plugin's first line must start exactly like this one.
# The text after : is the summary you can get at the command line

# A plugin may declare command line options that should be allowed through
# to ::argv

# This plugin compares CSV files with some preprocessing available
# Example usage:
# eskil -plugin csv -plugininfo "-ignore {head3 head5} -key head2" -sep , \
# eskil -plugin csv -csvignore "head3 head5" -csvkey head2 -sep , \
#       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
    # Look for parameters in command line
    set opts(-sep) ","
    set opts(-csvignore) ""
    set opts(-csvkey) ""
    set opts(-csvheader) 0
    foreach opt {-sep -csvignore -csvkey} {
    set i [lsearch -exact $::argv "-sep"]
    if {$i >= 0} {
        incr i
        set i [lsearch -exact $::argv $opt]
        if {$i >= 0} {
            incr i
        set opts(-sep) [subst -nocommands -novariables [lindex $::argv $i]]
    }

        }
        set opts($opt) [lindex $::argv $i]
    }
    # Look for parameters in info string
    set opts(-ignore) ""
    set opts(-key) ""
    set opts(-header) 0
    set opts(-sep) [subst -nocommands -novariables $opts(-sep)]
    set i [lsearch -exact $::argv "-csvheader"]
    if {$i >= 0} {
        set opts(-csvheader) 1
    }

    # Also allow options via info
    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)] {
    foreach col [concat $opts(-csvignore) $opts(-csvkey)] {
        if {![string is integer $col]} {
            set opts(-header) 1
            set opts(-csvheader) 1
        }
    }
    if {$opts(-header)} {
    if {$opts(-csvheader)} {
        set nameLine [gets $chi]
        # Keep it first in file
        puts $cho $nameLine
        set nameList [split $nameLine $opts(-sep)]
    }

    set icol {}
    foreach col $opts(-ignore) {
    foreach col $opts(-csvignore) {
        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) {
    foreach col $opts(-csvkey) {
        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'"
            }