/usr/bin/cssort is in cstocs 1:3.42-3.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | #!/usr/bin/perl -w
eval 'exec /usr/bin/perl -w -S $0 ${1+"$@"}'
if 0; # not running under some shell
eval 'exec perl -S $0 "$@"'
if 0;
use vars qw( $running_under_some_shell );
=head1 NAME
cssort -- Czech sort
=head1 FORMAT
cssort [ C<-c>B<list> | C<-f>B<list> [C<-d>B<regexp>]] [files ...]
=head1 SYNOPSIS
cssort -c10-15,50-,25-45 < file
cssort -f3,5-6 < file
cssort -f3,5-6 -s: < file
=head1 DESCRIPTION
Cssort is a utility that sorts input lines according to rules used in
the Czech language. You can run it without any options, then it just
uses whole lines for sorting. With the options, it's possible to
specify parts of the lines to be used for comparison.
=over 4
=item B<list>
A comma-separated list of integer field numbers or field ranges. The
are indexed from 1 and if a range is open (eg. C<5->), it means all
remaining fields from the starting number.
=item B<-c>
Stands for columns and the list that follows specifies byte ranges on
the line. You will probably use this option to sort data with fixed
width fields.
=item B<-f>
Fields that will be used for sort.
=item B<-d>
Delimiter that separates fields in the B<-f> option. It is a Perl
regular expression, the default is C<[ \t]+>, which means any number
of spaces or tabs in a row.
=back
The program assumes ISO-8859-2 encoding. Some way to specify another
input encoding will come in the next versions. If you need to sort
files with different encodings, you might want to check the B<cstocs>
conversion utility.
=head1 SEE ALSO
Cz::Sort(3), cstocs(1).
=head1 AUTHOR
Jan Pazdziora, adelton@fi.muni.cz.
=cut
use strict;
use Getopt::Std;
use Cz::Sort;
my %opts = (
'd' => '[ \t]+',
);
getopt('dfce', \%opts);
if (defined $opts{'h'})
{
print STDERR <<"EOF";
This is cssort version $Cz::Sort::VERSION.
Usage info: cssort [ -clist | -flist [-dregexp]] [files ...]
-c Columns
-f Field numbers
-d Delimiter, field separator
Lists are comma separated lists of field (column) numbers or ranges.
Example: cssort -c10-15,50-,25-45 cssort -f3,5-6 -s:
EOF
exit(1);
}
my $switch = 'c';
my $option = $opts{$switch};
if (not defined $option)
{
$switch = 'f';
$option = $opts{$switch};
}
if (not defined $option)
{
$switch = undef;
}
my $conversion;
if (defined $opts{'e'})
{
require Cz::Cstocs;
$conversion = new Cz::Cstocs $opts{'e'}, 'il2';
}
if (defined $switch)
{
my (@starts, @lengths, @array);
for (split /,/, $option)
{
if (/^\d+$/)
{ push @starts, $_ - 1; push @lengths, 1; }
elsif (/^(\d+)-(\d+)$/)
{ push @starts, $1 - 1; push @lengths, ($2 - $1 + 1); }
elsif (/^(\d+)-$/)
{ push @starts, $1 - 1; push @lengths, undef; }
else
{ die "Cssort: wrong option '$_' for switch -$switch\n"; }
}
if ($switch eq 'c')
{
while (<>)
{
chomp;
my $line = [ $_ ];
my $i;
for ($i = 0; $i < @starts; $i++)
{
if ($starts[$i] >= length $_)
{ push @$line, undef; }
elsif (defined $lengths[$i])
{ push @$line, substr $_, $starts[$i], $lengths[$i]; }
else
{ push @$line, substr $_, $starts[$i]; }
}
push @array, $line;
}
}
else
{
my $regexp = $opts{'d'};
while (<>)
{
chomp;
my @items = split /$regexp/so;
my $line = [ $_ ];
my $i;
for ($i = 0; $i < @starts; $i++)
{
push @$line, @items[$starts[$i] .. (defined $lengths[$i] ? $starts[$i] + $lengths[$i] - 1 : $#items )];
}
push @array, $line;
}
}
print map { $_->[0] . "\n" }
sort
{
my $len = ( @$a >= @$b ? @$a : @$b);
my $i;
for ($i = 1; $i < $len; $i++)
{
if (not defined $a->[$i])
{
return 0 if not defined $b->[$i];
return -1;
}
if (not defined $b->[$i])
{
return 1;
}
my $result = czcmp($a->[$i], $b->[$i]);
return $result if $result != 0;
}
return 0;
} @array;
}
else
{ print czsort <>; }
|