#!/usr/bin/env perl # # $NetBSD: makesites.pl,v 1.14 2005/05/07 22:52:30 heinz Exp $ # Copyright at end # Make sites.xml from sites.{head,data,tail} $^W=1; $|=1; $base='sites'; $list_totals=0; # List the total entries in each section (soon) $use_paragraphs=1; # Use paragraph breaks between each entry my $cvstag; $output[0]=&read_file("$base.head"); push(@output,"\ \n\n"); push(@output,&read_datafile("$base.data")); push(@output,&read_file("$base.tail")); @output[0] =~ s/(/\1$cvstag"\/>/; open(OUT,">$base.xml") || &fail("Unable to write $base.xml: $!"); print OUT @output; close(OUT); push(@totals," ---\n",sprintf("%5d Total entries\n",$total_entries)); print @totals; exit(0); sub fail { print STDERR "\a",@_,"\n"; exit(3); } sub process_entry { my(%entry)=@_; my($line); if( ! %entry ) { return } $line=''; if( $use_paragraphs ) { $line.=''; } if( !defined($entry{'title'}) ) { &fail("Missing 'title:' element for entry at line $."); } $line.=''; if( defined($entry{'url'}) ) { $line.="$entry{'title'}"; } else { $line.="$entry{'title'}"; } $line.="\n"; if( defined($entry{'arch'}) ) { $line.=" ($entry{'arch'})"; } if( !( defined($entry{'hide'}) && $entry{'hide'} eq 'yes' ) && ( defined($entry{'name'}) || defined($entry{'email'}) ) ) { #$line.=' '; $line.=' '; if( defined($entry{'name'}) ) { $line.=" $entry{'name'}"; } if( defined($entry{'email'}) ) { $line.=" $entry{'email'}"; } $line.=' '; # $line.=''; } if( defined($entry{'use'}) ) { $line.="\n$entry{'use'}\n"; } ++$total_entries; if( $use_paragraphs ) { $line.=''; } $line.="\n\n"; } sub process_section { my($section,@block)=@_; my(@list); my $sectid = $section; $sectid =~ s/\s+/-/; # avoid white space in id attributes @list=("\n$section"); push(@totals,sprintf("%5d $section\n",scalar(@block))); if( $list_totals ) { push(@list," (".scalar(@block)." entries)"); } (@list,"\n\n\n",@block,"\n\n"); } sub read_datafile { my($file)=@_; my($section); my($element,$null,$value,@output,@block); my(@validtypes)=('section', 'title','url','arch','use','name', 'email','hide','link','update'); my(%validtypes); foreach(@validtypes) { $validtypes{$_}=1; } open(DATA,$file) || &fail("Unable to open '$file': $!"); while( ) { if (m/# (.NetBSD:.*)/) { $cvstag = $1; } s/#.*//; s/ä/ä/g; s/ö/ö/g; s/ü/ü/g; if( ( ($element,$null,$value) = /^([\S]+):(\s*(\S.*)|)/ ) ) { if( ! defined($validtypes{$element}) ) { &fail("Unknown element '$element' at line $.\n"); } if( !defined($value) ) # Ignore blank entries { next; } if( $element eq 'section' ) { if( defined($section) ) { push(@output,&process_section($section,@block)); @block=(); } $section=$value; } else { $entry{$element}=$value; } } elsif( /\S.*/ ) { &fail("Line $. not in 'element: value' format.\n"); } elsif( %entry ) { defined($section) || &fail("Cannot output entry before section"); push(@block,&process_entry(%entry)); undef %entry; } } push(@block,&process_entry(%entry)); push(@output,&process_section($section,@block)); close(DATA); @output; } sub read_file { my($file)=@_; my($data); $data=''; open(FILE,$file) || &fail("Unable to read '$file': $!"); read(FILE,$data,-s $file); close(FILE); $data =~ s/\$NetBSD[^\$]+\$/\$NetBSD\$/g; $data; } # Copyright (c) 1997 The NetBSD Foundation, Inc. # All rights reserved. # # This code is derived from software contributed to The NetBSD Foundation # by David Brownlee / absolute # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # 3. All advertising materials mentioning features or use of this software # must display the following acknowledgement: # This product includes software developed by the NetBSD # Foundation, Inc. and its contributors. # 4. Neither the name of The NetBSD Foundation nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE.