#!/usr/local/bin/perl # Extract entries from the CSS properties database # The database has the following format: # name;; values;; initial-value;; applies-to;; # inherited;; percentages;; media;; computed value # Special characters: # 1) Translate "*" into the words "all elements" # 1.a) Translate "XX" into "not defined for shorthand properties" # 2) "" means the value is defined elsewhere. Translate to # <name> # 3) "<'name'>" means the set of values is the same as for the # property with the same name. Translate to # <'name'> # # Ian Jacobs - ij@w3.org (Based on work by Arnaud Le Hors) # $Id: pextr,v 1.31 2006-10-09 18:55:53 ihickson Exp $ # $PROGNAME = substr($0, rindex($0, "/") + 1); if (!$ARGV[0]) { print "Usage: $PROGNAME file [tgt_dir]\n"; exit 1; } # copy file in memory if (!open(input, $ARGV[0])) { print "$PROGNAME Error: Cannot open file: $ARGV[0]\n"; exit 1; } $buf = ""; while () { $buf .= $_; } close(input); $path = ""; if ($ARGV[1]) { $path = "$ARGV[1]/"; } # regexps $sp = "[ \t\n]*"; # whitespace $patt = "$sp(.*?)$sp"; $blockst = "[/][*]"; $blocket = "[*][/]"; sub format_property { my $name = $_[0]; my $values = $_[1]; my $init = $_[2]; my $applies = $_[3]; my $inherited = $_[4]; my $percentages = $_[5]; my $media = $_[6]; my $compval = $_[7]; #Do next three lines in src files to get headings right. print output "
\n"; print output "
\n"; @names = split(/[, \t\n]+/, $name); $comma = ""; foreach $n (@names) { print output "$comma'$n'"; $comma = ", "; } print output "\n
\n"; print output "\n"; # We use cellspacing/cellpadding until more browsers # handle tables correctly. &format_values($values); &format_init($init); &format_applies($applies); &format_inherited($inherited); &format_percentages($percentages); &format_media($media); &format_compval($compval); print output "
\n"; print output "
\n"; print output "
\n\n"; } sub clean { $_[0] =~ s/<([^>']*)>/<$1><\/span>/g; $_[0] =~ s/<[']([^']*)[']>/<'$1'><\/span>/g; $_[0] =~ s/\{([^\}]*)\}([^{]*)\{\}/$2<\/a>/g; return $_[0]; } # Include an nbsp before TD since CSS not used to # align tables yet. sub format_values { $values = clean($_[0]); $values =~ s/inherit/inherit<\/span>/g; print output ""; print output "Value:  "; print output "$values\n"; } sub format_init { #Note that in the case of properties, <> are removed in text. $init = clean($_[0]); $init =~ s/XX/not defined for shorthand properties/g; print output ""; print output "Initial:  "; print output "$init\n"; } sub format_applies { #Note that in the case of properties, <> are removed in text. $applies = clean($_[0]); $applies =~ s/^\*$/all elements/g; print output ""; print output "Applies to:  "; print output "$applies\n"; } sub format_inherited { $inherited = clean($_[0]); print output ""; print output "Inherited:  "; print output "$inherited\n"; } sub format_percentages { #Note that in the case of properties, <> are removed in text. $perc = clean($_[0]); print output ""; print output "Percentages:  "; print output "$perc\n"; } sub format_media { $fmedia = $_[0]; $fmedia =~ s/visual/visual<\/a>/; $fmedia =~ s/aural/aural<\/a>/; $fmedia =~ s/tactile/tactile<\/a>/; $fmedia =~ s/continuous/continuous<\/a>/; $fmedia =~ s/paged/paged<\/a>/; $fmedia =~ s/grid/grid<\/a>/; $fmedia =~ s/interactive/interactive<\/a>/; $fmedia =~ s/static/static<\/a>/; $fmedia =~ s/all/all<\/a>/; print output ""; print output "Media:  "; print output "$fmedia\n"; } sub format_compval { $values = clean($_[0]); $values =~ s/inherit/inherit<\/span>/g; print output ""; print output "Computed value:  "; print output "$values\n"; } # extract every possible block $_ = $buf; while (/$blockst(?:.*?)$blocket/s) { $placeholder = $'; my $h = $&; if ($h =~ /$blockst$patt;;$patt;;$patt;;$patt;;$patt;;$patt;;$patt;;$patt$blocket/s) { # Set parameters first (before any modifications) my $props = $1; my $values = $2; my $init = $3; my $applies = $4; my $inherited = $5; my $percentage = $6; my $media = $7; my $compval = $8; my @names = split(/[, \t\n]+/, $props); my $name = $names[0]; $output = "$path$name.srb"; print "\textracting $output\n"; open(output, "> $output"); &format_property($props, $values, $init, $applies, $inherited, $percentage, $media, $compval); close(output); } else { warn "Incorrect syntax for property definition: $h\n"; } $_ = $placeholder; }