--- make_poll.pl 2003/04/24 16:43:09 1.3 +++ make_poll.pl 2003/04/24 17:55:17 1.5 @@ -1,45 +1,26 @@ #!/usr/bin/perl -w # +# Dobrica Pavlinusic +# +# Originally made for proof. during April 2001; later released under GPL v2 +# +# 2003-04-dd general cleanup in preparation of release use strict; use XML::Parser; -use Text::Iconv; - -# output charset -my $charset='ISO-8859-2'; - -Text::Iconv->raise_error(0); # Conversion errors raise exceptions -my $from_utf8 = Text::Iconv->new('UTF8', $charset); -sub x { - return $from_utf8->convert($_[0]); -} +use common; $|=1; my $Usage =<<'End_of_Usage;'; -slides [-h] [-d dir] [-mode mode] slide-doc - -Convert a slideshow document into html, with a separate html document -for each slide and an index to all of them. - - -h Print this message and exit - - -w warn about unrecognized tags - - -d Use dir as directory into which to write html pages. Defaults - to basename of supplied doc file. - - -mode Output mode. Choices are html, html-style. Default is - html-style. - +I will write usage information here. I promise! End_of_Usage; my @Modes = qw(object pass skip); my $dir; my $dowarn = 1; -my $dostyle = 0; my $pitanje_nr = 0; # curr. pitanje my $pitanje_tag = ""; # originalni oblik broja pitanja @@ -134,37 +115,19 @@ print $Usage; exit; } - elsif ($opt eq '-d') { - $dir = shift; - } - elsif ($opt eq '-w') { - $dowarn = 1; - } - elsif ($opt eq '-mode') { - my $marg = shift; - if ($marg eq 'html') { - $dostyle = 0; - } - else { - die "Unrecognized mode: $marg\n$Usage"; - } - } - else { - die "Unrecognized option: $opt\n$Usage"; - } } # End of option processing -my $docfile = shift; +my $xmlfile = shift; -die "No docfile provided:\n$Usage" unless defined $docfile; +die "No poll xml file provided!\n$Usage" unless defined $xmlfile; -die "Can't read $docfile" unless -r $docfile; +die "Can't read $xmlfile" unless -r $xmlfile; if (defined $dir) { die "$dir isn't a directory" unless -d $dir; } else { - $docfile =~ m!([^/.]+)(?:\.[^/.]*)?$!; + $xmlfile =~ m!([^/.]+)(?:\.[^/.]*)?$!; $dir = $1; if (-e $dir) { die "$dir exists but isn't a directory" @@ -175,7 +138,7 @@ } } -my $in_slideshow = 0; +my $in_poll = 0; my $after_head = 0; my $Mode = 0; @@ -186,31 +149,28 @@ my $Object; my @Ostack = (); -my $intext = 0; +#my $intext = 0; my $closure; my @closure_stack = (); -my $style_link = ''; +#my $style_link = ''; -my $index = 'index.html'; -my @slidetitle; +#my $index = 'index.html'; +#my @slidetitle; my $body; -my $inlist = 0; +#my $inlist = 0; -my @Titles; +#my @Titles; my $header; -my $prolog = "\n"; -$prolog .= "\n"; - my $page_number = 0; my $p = new XML::Parser(ErrorContext => 3, Handlers => {Start => \&starthndl, End => \&endhndl, Char => \&text}); -$p->parsefile($docfile); +$p->parsefile($xmlfile); #---------------------------------------------------------- @@ -260,6 +220,9 @@ print PHP $head_php; close(PHP); +# 01.php -> index.php +rename "$dir/01.php","$dir/index.php" || die "can't rename '$dir/01.php' to index.php"; + ################ ## End of main ################ @@ -277,13 +240,15 @@ return "p".$pitanje_nr.$curr_suffix; } +#---------------------------------------------------------- + sub starthndl { my ($xp, $el, %atts) = @_; -# return unless ($in_slideshow or $el eq 'slideshow'); +# return unless ($in_poll or $el eq 'slideshow'); - unless ($in_slideshow) { - $in_slideshow = $xp->depth + 1; + unless ($in_poll) { + $in_poll = $xp->depth + 1; return; } @@ -330,7 +295,7 @@ my $new_closure; - my $subname = "Slideshow::$el"; + my $subname = "Poll::$el"; if (defined &$subname) { no strict 'refs'; @@ -359,12 +324,12 @@ sub endhndl { my ($xp, $el) = @_; - return unless $in_slideshow; + return unless $in_poll; my $lev = $xp->depth; - if ($lev == $in_slideshow - 1) { - $in_slideshow = 0; + if ($lev == $in_poll - 1) { + $in_poll = 0; $xp->finish; return; } @@ -414,10 +379,12 @@ $closure = pop(@closure_stack); } # End endhndl +#---------------------------------------------------------- + sub text { my ($xp, $data) = @_; - return unless $in_slideshow; + return unless $in_poll; if ($Mode ) { @@ -467,15 +434,9 @@ $str; } # End sgml_escape -sub slidename { - my ($num) = @_; - - sprintf("slide%03d.html", $num); -} # End slidename - ################################################################ -package Slideshow; +package Poll; sub page { package main; @@ -490,8 +451,6 @@ print "p[$page_nr] "; if (defined $last_fn) { - # 01.php -> index.php - $last_fn="index.php" if ($last_fn eq "01.php"); open(PAGE, ">$dir/$last_fn") or die "Couldn't open $last_fn for writing:\n$!"; if ($page_nr == 2) { print PAGE '{db_user}); + $prefix=x($attref->{prefix}); + } +} + #---------------------------------------------------------------