File: rangecvt.pl

package info (click to toggle)
bibclean 2.11.4-6
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny
  • size: 5,212 kB
  • ctags: 1,545
  • sloc: ansic: 10,737; makefile: 817; perl: 66; sh: 40; awk: 27; sed: 6
file content (88 lines) | stat: -rw-r--r-- 2,381 bytes parent folder | download | duplicates (4)
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
#! /usr/bin/perl

# This script takes the output of pdftotext on
# http://www.isbn-international.org/en/identifiers/List-of-Ranges.pdf
# and converts it to C source for the database section in isbn.c.

# Written by Henning Makholm <henning@makholm.net>, December 2004
# Changed (fighting bit rot), November 2005
# Distribution of modified or unmodified versions of this file is
# permitted without any restrictions.

use strict ;
use warnings ;

my %groups ;

if( open ISBNC, "<", "isbn.c" ) {
    while( <ISBNC> ) {
        last if /ISBN_range\[\]/ ;
    }
    my $curcmt ;
    while( <ISBNC> ) {
        if( /^\s+{ "(\d+)-\d+",\s+"(\d+)-\d+"/ && $1 eq $2 ) {
            my $group = $1 ;
            if( defined $curcmt &&
                $curcmt =~ /\*\/\s*$/ &&
                !exists $groups{$group} ) {
                $groups{$group} = $curcmt ;
            }
            undef $curcmt ;
        } elsif( /^\s*\/\*/ ) {
            $curcmt = $_ ;
        } elsif( /^\s*\};/ ) {
            last ;
        } elsif( defined $curcmt ) {
            $curcmt .= $_ ;
        }
    }
    close ISBNC ;
}

print "     /* Table generated by $0 */\n\n" ;

my $prevgroup = '-' ;
sub putline($$$$) {
    my ($group,$begin,$end,$extra) = @_ ;
    if( $group ne $prevgroup ) {
        print "\n" if $prevgroup ne '-' ;
        if( exists $groups{$group} ) {
            print $groups{$group} ;
        } else {
            print "     /* XXX: group $group? */\n" ;
        }
        $prevgroup = $group ;
    }
    my $line = "     { \"$group-$begin\",\t\"$group-$end\" $extra},\n" ;
    $line =~ s[^(.*)\t][$1 . ("\t" x int((39-length $1)/8))]e ;
    print $line ;
}
    

while( <> ) {
    chomp ;
    s/\f// ;
    if( s/\((.*)// ) {
        my $x = $1 ;
        while( $x !~ /\)/ ) {
            defined($x = <>) or die "unterminated parenthesis" ;
        }
    }
    if( /^(\d+)\s+(\d+)(\s+|\s*-)\s*(\d+)\s*$/ && length($2) == length($4) ) {
        putline($1,$2,$4,"");
    } elsif( /^(\d+)\s+(\d+)\s*$/ ) {
        putline($1,$2,$2,"");
    } elsif( /^\s+(\d+)\s*(no ranges fixed yet\s*)?$/ ) {
        putline($1,"0","0","/* <-no assignments yet */ ");
    } elsif( /^(Group Number\s*Ranges)?\s*$/ ) {
        # all OK
    } else {
        print STDERR "strange line '$_'\n" ;
    }
}

print "\n" ;
print "     { (const char*)NULL,\t(const char*)NULL }\n" ;