aboutsummaryrefslogtreecommitdiffstats
path: root/english/template/debian/legal_lists.wml
blob: 9c4b67d35ea585a1aab80992795152726f7d9594 (plain) (blame)
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
# Copyright (C) 2004 Frank Lichtenheld
# derived from wml::debian::recent_list
# $Id$

#use wml::debian::ctime
#use wml::debian::common_tags
#use wml::debian::legal_tags
#use wml::debian::openrecode

<perl>

use Encode;

my ($listhead, $listfoot, $elemhead, $elemdate, $elemfoot, $elemrealfoot);

sub get_alphabetical_list {

    my ($isfree, $format) = @_;
    my $eng_dir = "$(ENGLISHDIR)";
    my $cur_dir = "legal/licenses";
    my $match = "dls-.*";

<protect pass="2">
    if ($format =~ order) {
	$listhead = '<ol>';
	$listfoot = '</ol>';
	$elemhead = '<li>';
	$elemfoot = '- ';
	$elemrealfoot = '</li>';
    } elsif ($format =~ bullet) {
	$listhead = '<ul>';
	$listfoot = '</ul>';
	$elemhead = '<li>';
	$elemfoot = '- ';
	$elemrealfoot = '</li>';
    } elsif ($format =~ list) {
	$listhead = '<dl>';
	$listhead = '<dl compact>' if $format eq "cdeflist";
	$listfoot = '</dl>';
	$elemhead = '<dt>';
	$elemfoot = '</dt><dd>';
	$elemrealfoot = '</dd>';
    } elsif ($format =~ table) {
	$listhead = '<table>';
	$listfoot = '</table>';
	$elemhead = '<tr><td>';
	$elemdate = '</td><td>';
	$elemfoot = '';
	$elemrealfoot = '</td></tr>';
    } else {
	$listhead = '';
	$listfoot = '';
	$elemhead = '';
	$elemfoot = '- ';
	$elemrealfoot = '';
    }
</protect>

      opendir DIR, "$eng_dir/$cur_dir" or die "couldn't open directory: $!";
      my @files = grep { /^$match\.wml$/ 
         && -f "$eng_dir/$cur_dir/$_" 
        } readdir(DIR);
      closedir DIR;

      @files = sort {$a cmp $b} @files;
    
      #warn "files: " . join " ", @files; warn "\n";
      #warn "eng_dir=$eng_dir cur_dir=$cur_dir
      #warn isfree=$isfree format=$format match=$match\n";
    
      my %str = grab_titles( $isfree, $eng_dir, $cur_dir, $match, @files );
      
      $str{head} = "$listhead";
      $str{foot} = "$listfoot";

      return %str;
}

# grab_titles is an auxiliary function to get_recent_list, which actually
# does the real work.
sub grab_titles {
    my ( $isfree, $eng_dir, $cur_dir, $match, @files) = @_;
    my ( %str_by_letter, %str );
    
    foreach $file (@files) {
	(my $trans_title = $file) =~ s/wml/title/;
	my $base = $1 if ($file =~ m|^($match).wml|);
	#warn "$file -> $base\n";
        
	# read file in
	my $fh = openrecode($file, $trans_title, "$eng_dir/$cur_dir/$file")
	    or die "couldn't open $eng_dir/$cur_dir/$file: $!\n";
	my $content;
	<protect pass=2>
	{
	    local $/;
	    $content = <$fh>;
	}
	</protect>
        close $fh;

	my ($title, $just);
        open DATAFILE, "$eng_dir/$cur_dir/$base.data" 
            or do {
                warn "couldn't open $eng_dir/$cur_dir/$base.data: $!\n";
                next;
            };
        <protect pass=2>
        my ( $free, $l_name, $rdate );
        foreach my $l (Encode::decode_utf8(<DATAFILE>)) {
            if ($l =~ /^<define-tag pagetitle>(.*)<\/define-tag>/) 
            { $title = Encode::encode_utf8(qq/$1/); }
            if ($l =~ /^<define-tag license-name>(.*)<\/define-tag>/) 
            { $l_name = Encode::encode_utf8(qq/$1/); }
            elsif ($l =~ /^<define-tag report_date>(.*)<\/define-tag>/) 
            { $rdate = Encode::encode_utf8(qq/$1/); }
            elsif ($l =~ /^<define-tag isfree>(.*)<\/define-tag>/) 
            { $free = Encode::encode_utf8(qq/$1/); }
        }
        </protect>
	close DATAFILE;
        if ($isfree && ($free ne $isfree)) { next; }
        $rdate = newsdate($rdate);
        if ($free eq 'yes') {
            $free = '<dls-result isfree="yes" />';
        } elsif ($free eq 'no') {
            $free = '<dls-result isfree="no" />';
        } elsif ($free eq 'non-dist') {
            $free = '<dls-result isfree="non-dist" />';
        }
        $str{$l_name} = "$elemhead<tt>[$rdate]</tt> "
            ."<strong><a href=\"$base\">$title</a></strong>$elemfoot "
            ."$l_name &ndash; $free<br />$elemrealfoot\n";
    } # for each file
    my $fl = '';
    foreach (sort keys %str) {
        my $fl = uc( substr( $_, 0, 1) );
        if ($fl !~ /^\w$/) { $fl = '_'; }
        $str_by_letter{$fl} .= $str{$_};
    }
    return %str_by_letter;
}

# iso2stamp converts a date in ISO format (YYYY-MM-DD) to an
# unix timestamp for 23:59:59 on the specified day
# Input: $time - String with the ISO date
# Output: integer timestamp
sub iso2stamp {
    my $time = shift;

    if ($time =~ /undated/) {
	return 0;
    }
    my ($year, $month, $day) = ($time =~ /(\d{4})-(\d{1,2})-(\d{1,2})/);
    unless ($year && $month && $day) { warn "not an ISO date: $time\n"; }
    
    return timegm( 59, 59, 23, $day, $month-1, $year);
}

</perl>

© 2014-2024 Faster IT GmbH | imprint | privacy policy