--- make_poll.pl 2003/10/21 16:55:06 1.14
+++ make_poll.pl 2003/11/08 01:08:44 1.17
@@ -23,15 +23,16 @@
my $poll;
my $dowarn = 1;
-my $pitanje_nr = 0; # curr. pitanje
-my $pitanje_tag = ""; # originalni oblik broja pitanja
-my $page_nr = 1; # prvo pitanje na strani
+my $q_type = "q"; # q=question, u=unnumbered question
+my %question_nr; # curr. question numbers
+my $question_tag = ""; # originalni oblik broja questions
+my $page_nr = 1; # prvo question na strani
my $p_suffix=""; # if more than one box per question
my $curr_suffix=""; # trenutni suffix
-my @stack_pit; # stack pitanja (pitanje, suffix)
+my @stack_que; # stack of questions (question, suffix)
my @sql_create = ("id serial",
"http_referer character varying(500)",
@@ -85,7 +86,28 @@
'thanks' => "thanks.html"
);
-my %html; # buffer for suck(_file)ed html files
+# buffer for suck(_file)ed html files
+# and additional markup before and after tags
+my %html = (
+ 'hr_before' => "
",
+ 'hr_after' => "
", + 'que_after' => "
", + 'subque_before' => '", + 'ans_after' => "
", + 'html_before' => "", + 'html_after' => "
", + +); + +# name of database colums +# for questions +my $q_db_col = "q"; +# for unnumbered questions +my $u_db_col = "u"; + #------------------------------------------------------------------ @@ -138,7 +160,7 @@ #------------------------------------------------------------------ -$html{'kraj'}=suck_file($include_files{'thanks'}); +$html{'thanks'}=suck_file($include_files{'thanks'}); #------------------------------------------------------------------ @@ -222,7 +244,7 @@ $page_nr++; open(PAGE, ">$poll/$next_fn") or die "Couldn't open $next_fn for writing:\n$!"; print PAGE php_header($page_nr,@last_sql_update); -print PAGE "$html{'header'} $html{'kraj'} $html{'footer'}"; +print PAGE "$html{'header'} $html{'thanks'} $html{'footer'}"; close(PAGE); # dump sql structure @@ -265,215 +287,199 @@ ## End of main ################ -# return unique name of pitanje -sub new_pit { - my $out="p".$pitanje_nr; +# return unique name of question +sub new_que { + my $out=$q_type.( $question_nr{$q_type} || 0 ); $out .= "_".$p_suffix if ($p_suffix); $curr_suffix=$p_suffix; $p_suffix++; return $out; } -# current pitanje -sub curr_pit { - return "p".$pitanje_nr.$curr_suffix; +# current question +sub curr_que { + return $q_type.( $question_nr{$q_type} || 0 ).$curr_suffix; } #---------------------------------------------------------- sub starthndl { - my ($xp, $el, %atts) = @_; + my ($xp, $el, %atts) = @_; -# return unless ($in_poll or $el eq 'slideshow'); +# return unless ($in_poll or $el eq 'slideshow'); - unless ($in_poll) { - $in_poll = $xp->depth + 1; - return; - } + unless ($in_poll) { + $in_poll = $xp->depth + 1; + return; + } - if ($Mode) { + if ($Mode) { + if ($Mode eq 'pass') { + $Markedup_Text .= "\n" . $xp->recognized_string; + } elsif ($Mode eq 'object') { + push(@Ostack, $Object); - if ($Mode eq 'pass') { - $Markedup_Text .= "\n" . $xp->recognized_string; - } - elsif ($Mode eq 'object') { - push(@Ostack, $Object); + $Object = { + _Atts => \%atts, + _Text => '' + }; + bless $Object, "Slideobj::$el"; + } - $Object = {_Atts => \%atts, - _Text => '' - }; - bless $Object, "Slideobj::$el"; - } + # skip does nothing + return; + } - # skip does nothing - return; - } + unless ($after_head) { + if ($el eq 'head') { + $after_head = 1; + start_mode($xp, 'object'); - unless ($after_head) { - if ($el eq 'head') { - $after_head = 1; - start_mode($xp, 'object'); - - push(@closure_stack, $closure); - $closure = - sub { - my ($xp, $text) = @_; - - unless (defined $text) { - - $header = $Object; - } - }; + push(@closure_stack, $closure); + $closure = sub { + my ($xp, $text) = @_; - return; - } + unless (defined $text) { + $header = $Object; + } + }; + return; + } -# die "The head element must be the first thing in the slideshow"; - } +# die "The head element must be the first thing in the slideshow"; + } - my $new_closure; + my $new_closure; - my $subname = "Poll::$el"; + my $subname = "Poll::$el"; - if (defined &$subname) { - no strict 'refs'; + if (defined &$subname) { + no strict 'refs'; - &$subname($xp, $el, \%atts, \$new_closure); - } - else { - $body .= x($xp->recognized_string); - $new_closure = - sub { - my ($xp, $text) = @_; - - if (defined $text) { - $body .= x($text); - } - else { - $body .= x("$el>"); + &$subname($xp, $el, \%atts, \$new_closure); + } else { + $body .= x($xp->recognized_string); + $new_closure = sub { + my ($xp, $text) = @_; + + if (defined $text) { + $body .= x($text); + } else { + $body .= x("$el>"); + } + }; } - }; - } - push(@closure_stack, $closure); - $closure = $new_closure; -} # End starthndl + push(@closure_stack, $closure); + $closure = $new_closure; +} # End starthndl sub endhndl { - my ($xp, $el) = @_; + my ($xp, $el) = @_; - return unless $in_poll; + return unless $in_poll; - my $lev = $xp->depth; + my $lev = $xp->depth; - if ($lev == $in_poll - 1) { - $in_poll = 0; - $xp->finish; - return; - } - - if ($Mode_level == $lev) { - - if ($Mode eq 'pass') { - &$closure($xp, $Markedup_Text) - if (defined $closure); - } + if ($lev == $in_poll - 1) { + $in_poll = 0; + $xp->finish; + return; + } + + if ($Mode_level == $lev) { + + if ($Mode eq 'pass') { + &$closure($xp, $Markedup_Text) if (defined $closure); + } - $Mode = $Mode_level = 0; - } + $Mode = $Mode_level = 0; + } - if ($Mode) { - if ($Mode eq 'pass') { - $Markedup_Text .= "$el>"; - } - elsif ($Mode eq 'object') { - my $this = $Object; - if (2 == keys %$this) { - $this = $this->{_Text}; - } - - $Object = pop(@Ostack); - - my $slot = $Object->{$el}; - if (defined $slot) { - if (ref($slot) eq 'ARRAY') { - push(@$slot, $this); - } - else { - $Object->{$el} = [$slot, $this]; - } - } - else { - $Object->{$el} = $this; - } - } + if ($Mode) { + if ($Mode eq 'pass') { + $Markedup_Text .= "$el>"; + } elsif ($Mode eq 'object') { + my $this = $Object; + if (2 == keys %$this) { + $this = $this->{_Text}; + } - return; - } + $Object = pop(@Ostack); + + my $slot = $Object->{$el}; + if (defined $slot) { + if (ref($slot) eq 'ARRAY') { + push(@$slot, $this); + } else { + $Object->{$el} = [$slot, $this]; + } + } else { + $Object->{$el} = $this; + } + } + + return; + } - &$closure($xp) - if defined $closure; + &$closure($xp) if defined $closure; - $closure = pop(@closure_stack); + $closure = pop(@closure_stack); } # End endhndl #---------------------------------------------------------- sub text { - my ($xp, $data) = @_; + my ($xp, $data) = @_; - return unless $in_poll; + return unless $in_poll; - if ($Mode ) { + if ($Mode) { - if ($Mode eq 'pass') { - my $safe = sgml_escape($data); + if ($Mode eq 'pass') { + my $safe = sgml_escape($data); - $Text .= $safe; - $Markedup_Text .= $safe; - } - elsif ($Mode eq 'object') { - $Object->{_Text} .= $data - if $data =~ /\S/; - } + $Text .= $safe; + $Markedup_Text .= $safe; + } elsif ($Mode eq 'object') { + $Object->{_Text} .= $data if $data =~ /\S/; + } - return; - } + return; + } - &$closure($xp, sgml_escape($data)) - if (defined $closure); + &$closure($xp, sgml_escape($data)) if (defined $closure); } # End text sub start_mode { - my ($xp, $mode) = @_; + my ($xp, $mode) = @_; - if ($mode eq 'pass') { - $Text = ''; - $Markedup_Text = ''; - } - elsif ($mode eq 'object') { - $Object = {_Atts => undef, - _Text => undef - }; - } + if ($mode eq 'pass') { + $Text = ''; + $Markedup_Text = ''; + } elsif ($mode eq 'object') { + $Object = { + _Atts => undef, + _Text => undef + }; + } - $Mode = $mode; - $Mode_level = $xp->depth; + $Mode = $mode; + $Mode_level = $xp->depth; } # End start_mode sub sgml_escape { - my ($str) = @_; + my ($str) = @_; - $str =~ s/\&/\&/g; - $str =~ s/\</g; - $str =~ s/>/\>/g; + $str =~ s/\&/\&/g; + $str =~ s/\</g; + $str =~ s/>/\>/g; - $str; + $str; } # End sgml_escape - ################################################################ package Poll; @@ -517,18 +523,18 @@ my ($xp, $el, $attref, $ncref) = @_; - $pitanje_tag=""; + $question_tag=""; $$ncref = sub { my ($xp, $text) = @_; if (defined($text)) { $body.=x($text); chomp $text; - $pitanje_tag .= x($text); + $question_tag .= x($text); } else { - $pitanje_nr = $pitanje_tag; - $pitanje_nr =~ s/[^0-9a-zA-Z]//g; - print "$pitanje_nr "; + $question_nr{$q_type} = $question_tag; + $question_nr{$q_type} =~ s/[^0-9a-zA-Z]//g; + print "$question_nr{$q_type} "; } $p_suffix=""; }; @@ -536,19 +542,24 @@ sub hr { - $body .= ""; + my $nonum = x($attref->{unnumbered}); + if ($nonum) { + $q_type = $u_db_col; # unnumbered questions + } else { + $q_type = $q_db_col; + } + + $question_nr{$q_type}++; + + $body.=$html{'que_before'} if ($html{'que_before'}); $$ncref = sub { my ($xp, $text) = @_; @@ -556,43 +567,44 @@ if (defined $text) { $body.=x($text); } else { - $body.="
"; + $body.=$html{'que_after'} if ($html{'que_after'}); } } } -sub podpit { +sub subque { package main; my ($xp, $el, $attref, $ncref) = @_; - $body.='"; - + $body.=$html{'ans_before'} if ($html{'ans_before'}); + $$ncref = sub { my ($xp, $text) = @_; if (defined $text) { $body .= x($text); } else { - $body .= "
"; + $body.=$html{'ans_after'} if ($html{'ans_after'}); } } } @@ -640,7 +652,7 @@ } else { my $opt; my $id=1; - my $p=new_pit(); + my $p=new_que(); $body.="