Eskil

Check-in [08aa583d40]
Login

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

Overview
Comment:Added -nospace option to sort plugin.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 08aa583d40858b060bf89589f001f412c5c64c20f67b4be80e341c358dbe66c7
User & Date: peter 2024-03-07 21:29:06.071
Context
2024-03-07
22:05
Allow deleting of balloon. Handle Notebook balloon. check-in: 5d5fdb0972 user: peter tags: trunk
21:29
Added -nospace option to sort plugin. check-in: 08aa583d40 user: peter tags: trunk
2023-04-27
21:41
Release 2.8.5 check-in: fb5bb6de64 user: peter tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Changes to plugins/sort.tcl.
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
##Eskil Plugin : Compare files after sorting lines
## Flag -sortwords : Sort words within each line first.

#
# This plugin compares files after sorting the lines in each side

# Example file for a plugin.
# 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

# 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 command line
    set opts(-sortwords) 0

    set i [lsearch -exact $::argv "-sortwords"]
    if {$i >= 0} {
        set opts(-sortwords) 1




    }

    set data [read $chi]
    set endingNewLine 0
    if {[string index $data end] eq "\n"} {
        set data [string range $data 0 end-1]
        set endingNewLine 1


>

















>



>
>
>
>







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
##Eskil Plugin : Compare files after sorting lines
## Flag -sortwords : Sort words within each line first.
## Flag -nospace : Ignore space
#
# This plugin compares files after sorting the lines in each side

# Example file for a plugin.
# 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

# 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 command line
    set opts(-sortwords) 0
    set opts(-nospace) 0
    set i [lsearch -exact $::argv "-sortwords"]
    if {$i >= 0} {
        set opts(-sortwords) 1
    }
    set i [lsearch -exact $::argv "-nospace"]
    if {$i >= 0} {
        set opts(-nospace) 1
    }

    set data [read $chi]
    set endingNewLine 0
    if {[string index $data end] eq "\n"} {
        set data [string range $data 0 end-1]
        set endingNewLine 1
37
38
39
40
41
42
43












44
45


46
47
48
49
50
51
52
53
            set words [regexp -all -inline {\w+} $line]
            set words [lsort -dictionary $words]
            lappend newlines [join $words]
        }
        set lines $newlines
    }













    # Allow sort parameters in info
    set lines [lsort -dictionary {*}$::Info $lines]


    puts -nonewline $cho [join $lines \n]
    if {$endingNewLine} {
        puts $cho ""
    }
    # Signal that the file after processing should be used both
    # for comparison and for displaying.
    return 1
}







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








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
            set words [regexp -all -inline {\w+} $line]
            set words [lsort -dictionary $words]
            lappend newlines [join $words]
        }
        set lines $newlines
    }

    if {$opts(-nospace)} {
        set sortlines {}
        foreach line $lines {
            set nospace [regsub -all {\s+} $line ""]
            lappend sortlines [list $nospace $line]
        }
        set sortlines [lsort -dictionary {*}$::Info  -index 0 $sortlines]
        set lines {}
        foreach line $sortlines {
            lappend lines [lindex $line 1]
        }
    } else {
        # Allow sort parameters in info
        set lines [lsort -dictionary {*}$::Info $lines]
    }

    puts -nonewline $cho [join $lines \n]
    if {$endingNewLine} {
        puts $cho ""
    }
    # Signal that the file after processing should be used both
    # for comparison and for displaying.
    return 1
}