Subversion Repositories wimsdev

Rev

Rev 4158 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
20 reyssat 1
!if $wims_read_parm!=slib_header
2
 !goto proc
3
!endif
4
slib_title=Sort data according to a column
5
slib_parms=3\
6
1,the number of column for sort key\
7
,option words (accepts <tt>nocase numeric reverse</tt>)\
8
,2-dimensional data arranged in rows and columns
9
slib_author=Gang Xiao
10
slib_out=the sorted data
11
slib_example= 3,nocase, 3,5,oui;caen, arles,nice;paris,nice,caen\
12
2,numeric, 3,5,oui;caen, 6,non;paris,1,oui
13
!exit
14
 
15
:proc
16
slib_ltest=!linecnt $wims_read_parm
17
!if $slib_ltest>1
18
 slib_inp=!lines2rows $wims_read_parm
19
 slib_type=lines
20
!else
21
 slib_inp=$wims_read_parm
22
 slib_type=rows
23
!endif
24
slib_n=!item 1 of $slib_inp
25
slib_option=!item 2 of $slib_inp
26
slib_data=!item 3 to -1 of $slib_inp
27
slib_r1=!row 1 of $slib_data
28
slib_N=!itemcnt $slib_r1
29
!bound $slib_n between integer 1 and $slib_N default 1
30
slib_key=!column $slib_n of $slib_data
31
slib_tt=0
32
!if reverse iswordof $slib_option
33
 slib_tt=$[$slib_tt+1]
34
!endif
35
!if numeric iswordof $slib_option
36
 slib_tt=$[$slib_tt+2]
37
!endif
38
!if nocase iswordof $slib_option
39
 slib_tt=$[$slib_tt+4]
40
!endif
41
 
42
!goto sort$slib_tt
43
 
44
:sort0
45
 slib_out=!sort items $slib_key
46
 !goto send
47
:sort1
48
 slib_out=!sort reverse items $slib_key
49
 !goto send
50
:sort2
51
 slib_out=!sort numeric items $slib_key
52
 !goto send
53
:sort3
54
 slib_out=!sort reverse numeric items $slib_key
55
 !goto send
56
:sort4
57
 slib_out=!sort nocase items $slib_key
58
 !goto send
59
:sort5
60
 slib_out=!sort reverse nocase items $slib_key
61
 !goto send
62
:sort6
63
 slib_out=!sort numeric nocase items $slib_key
64
 !goto send
65
:sort7
66
 slib_out=!sort numeric nocase reverse items $slib_key
67
 
68
:send
69
slib_out=!row $wims_sort_order of $slib_data
70
!if $slib_type=lines
71
 slib_out=!rows2lines $slib_out
72
!endif