ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/enametoolong/shortener
Revision: 1.1
Committed: Wed May 7 09:20:49 2025 UTC (2 months, 1 week ago) by root
Branch: MAIN
CVS Tags: HEAD
Log Message:
*** empty log message ***

File Contents

# Content
1 #!/usr/bin/perl
2
3 use strict;
4
5 $| = 1;
6
7 # to be on the safe side:
8 binmode STDIN;
9 binmode STDOUT;
10 binmode STDERR;
11
12 my %cache;
13
14 while () {
15 alarm 30;
16 4 == read STDIN, my $len, 4
17 or exit 0;
18 $len = unpack "N", $len;
19 $len < 10000 or die;
20 $len == read STDIN, my $path, $len
21 or die;
22 alarm 0;
23
24 # shorten path
25 my @short;
26
27 for (split /\//, $path) {
28
29 if (255 < length) {
30 # remove short-enough extension
31 s/((?:\..{1,5}){0,3})\z//s;
32 my $ext = $1;
33
34 while (255 < length "$_$ext") {
35 # remove a single utf-8 char from the end
36 s/(?:[\x01-\x7f]|[\xc0-\xff][\x80-\xbf]+|.)\z//s;
37 }
38
39 $_ .= $ext;
40 }
41
42 push @short, $_;
43 }
44
45 my $short = join "/", @short;
46
47 warn "shorten:\n$path\n$short\n";
48
49 print pack "N/a", $short;
50 }