/[wopi]/make_poll.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /make_poll.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by dpavlin, Thu Apr 24 16:43:09 2003 UTC revision 1.5 by dpavlin, Thu Apr 24 17:55:17 2003 UTC
# Line 1  Line 1 
1  #!/usr/bin/perl -w  #!/usr/bin/perl -w
2  #  #
3    # Dobrica Pavlinusic <dpavlin@rot13.org>
4    #
5    # Originally made for proof. during April 2001; later released under GPL v2
6    #
7    # 2003-04-dd general cleanup in preparation of release
8    
9  use strict;  use strict;
10    
11  use XML::Parser;  use XML::Parser;
12  use Text::Iconv;  use common;
   
 # 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]);  
 }  
13    
14  $|=1;  $|=1;
15    
16  my $Usage =<<'End_of_Usage;';  my $Usage =<<'End_of_Usage;';
17  slides [-h] [-d dir] [-mode mode] slide-doc  I will write usage information here. I promise!
   
 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.  
   
18  End_of_Usage;  End_of_Usage;
19    
20  my @Modes = qw(object pass skip);  my @Modes = qw(object pass skip);
21    
22  my $dir;  my $dir;
23  my $dowarn = 1;  my $dowarn = 1;
 my $dostyle = 0;  
24    
25  my $pitanje_nr = 0;             # curr. pitanje  my $pitanje_nr = 0;             # curr. pitanje
26  my $pitanje_tag = "";           # originalni oblik broja pitanja  my $pitanje_tag = "";           # originalni oblik broja pitanja
# Line 134  while (defined($ARGV[0]) and $ARGV[0] =~ Line 115  while (defined($ARGV[0]) and $ARGV[0] =~
115      print $Usage;      print $Usage;
116      exit;      exit;
117    }    }
   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";  
   }  
118  }  # End of option processing  }  # End of option processing
119    
120  my $docfile = shift;  my $xmlfile = shift;
121    
122  die "No docfile provided:\n$Usage" unless defined $docfile;  die "No poll xml file provided!\n$Usage" unless defined $xmlfile;
123    
124  die "Can't read $docfile" unless -r $docfile;  die "Can't read $xmlfile" unless -r $xmlfile;
125    
126  if (defined $dir) {  if (defined $dir) {
127    die "$dir isn't a directory" unless -d $dir;    die "$dir isn't a directory" unless -d $dir;
128  }  }
129  else {  else {
130    $docfile =~ m!([^/.]+)(?:\.[^/.]*)?$!;    $xmlfile =~ m!([^/.]+)(?:\.[^/.]*)?$!;
131    $dir = $1;    $dir = $1;
132    if (-e $dir) {    if (-e $dir) {
133      die "$dir exists but isn't a directory"      die "$dir exists but isn't a directory"
# Line 175  else { Line 138  else {
138    }    }
139  }  }
140    
141  my $in_slideshow = 0;  my $in_poll = 0;
142  my $after_head = 0;  my $after_head = 0;
143    
144  my $Mode = 0;  my $Mode = 0;
# Line 186  my $Markedup_Text; Line 149  my $Markedup_Text;
149  my $Object;  my $Object;
150  my @Ostack = ();  my @Ostack = ();
151    
152  my $intext = 0;  #my $intext = 0;
153  my $closure;  my $closure;
154  my @closure_stack = ();  my @closure_stack = ();
155    
156  my $style_link = '';  #my $style_link = '';
157    
158  my $index = 'index.html';  #my $index = 'index.html';
159  my @slidetitle;  #my @slidetitle;
160  my $body;  my $body;
161  my $inlist = 0;  #my $inlist = 0;
162    
163  my @Titles;  #my @Titles;
164    
165  my $header;  my $header;
166    
 my $prolog = "<html><head>\n";  
 $prolog .= "<!-- Generated by $0 on " . gmtime() . " GMT -->\n";  
   
167  my $page_number = 0;  my $page_number = 0;
168    
169  my $p = new XML::Parser(ErrorContext => 3,  my $p = new XML::Parser(ErrorContext => 3,
170                          Handlers => {Start => \&starthndl,                          Handlers => {Start => \&starthndl,
171                                       End   => \&endhndl,                                       End   => \&endhndl,
172                                       Char  => \&text});                                       Char  => \&text});
173  $p->parsefile($docfile);  $p->parsefile($xmlfile);
174    
175  #----------------------------------------------------------  #----------------------------------------------------------
176    
# Line 260  $head_php=~ s/##TEXT##/Ispunili ste %02d Line 220  $head_php=~ s/##TEXT##/Ispunili ste %02d
220  print PHP $head_php;  print PHP $head_php;
221  close(PHP);  close(PHP);
222    
223    # 01.php -> index.php
224    rename "$dir/01.php","$dir/index.php" || die "can't rename '$dir/01.php' to index.php";
225    
226  ################  ################
227  ## End of main  ## End of main
228  ################  ################
# Line 277  sub curr_pit { Line 240  sub curr_pit {
240          return "p".$pitanje_nr.$curr_suffix;          return "p".$pitanje_nr.$curr_suffix;
241  }  }
242    
243    #----------------------------------------------------------
244    
245  sub starthndl {  sub starthndl {
246    my ($xp, $el, %atts) = @_;    my ($xp, $el, %atts) = @_;
247    
248  #  return unless ($in_slideshow or $el eq 'slideshow');  #  return unless ($in_poll or $el eq 'slideshow');
249    
250    unless ($in_slideshow) {    unless ($in_poll) {
251      $in_slideshow = $xp->depth + 1;      $in_poll = $xp->depth + 1;
252      return;      return;
253    }    }
254    
# Line 330  sub starthndl { Line 295  sub starthndl {
295    
296    my $new_closure;    my $new_closure;
297    
298    my $subname = "Slideshow::$el";    my $subname = "Poll::$el";
299    
300    if (defined &$subname) {    if (defined &$subname) {
301      no strict 'refs';      no strict 'refs';
# Line 359  sub starthndl { Line 324  sub starthndl {
324  sub endhndl {  sub endhndl {
325    my ($xp, $el) = @_;    my ($xp, $el) = @_;
326    
327    return unless $in_slideshow;    return unless $in_poll;
328    
329    my $lev = $xp->depth;    my $lev = $xp->depth;
330    
331    if ($lev == $in_slideshow - 1) {    if ($lev == $in_poll - 1) {
332      $in_slideshow = 0;      $in_poll = 0;
333      $xp->finish;      $xp->finish;
334      return;      return;
335    }    }
# Line 414  sub endhndl { Line 379  sub endhndl {
379    $closure = pop(@closure_stack);    $closure = pop(@closure_stack);
380  }  # End endhndl  }  # End endhndl
381    
382    #----------------------------------------------------------
383    
384  sub text {  sub text {
385    my ($xp, $data) = @_;    my ($xp, $data) = @_;
386    
387    return unless $in_slideshow;    return unless $in_poll;
388    
389    if ($Mode ) {    if ($Mode ) {
390    
# Line 467  sub sgml_escape { Line 434  sub sgml_escape {
434    $str;    $str;
435  }  # End sgml_escape  }  # End sgml_escape
436    
 sub slidename {  
   my ($num) = @_;  
   
   sprintf("slide%03d.html", $num);  
 }  # End slidename  
   
437  ################################################################  ################################################################
438    
439  package Slideshow;  package Poll;
440    
441  sub page {  sub page {
442          package main;          package main;
# Line 490  sub page { Line 451  sub page {
451                          print "p[$page_nr] ";                          print "p[$page_nr] ";
452    
453                          if (defined $last_fn) {                          if (defined $last_fn) {
                                 # 01.php -> index.php  
                                 $last_fn="index.php" if ($last_fn eq "01.php");  
454                                  open(PAGE, ">$dir/$last_fn") or die "Couldn't open $last_fn for writing:\n$!";                                  open(PAGE, ">$dir/$last_fn") or die "Couldn't open $last_fn for writing:\n$!";
455                                  if ($page_nr == 2) {                                  if ($page_nr == 2) {
456                                          print PAGE '<?php                                          print PAGE '<?php
# Line 545  sub nr { Line 504  sub nr {
504          $$ncref = sub {          $$ncref = sub {
505                  my ($xp, $text) = @_;                  my ($xp, $text) = @_;
506                  if (defined($text)) {                  if (defined($text)) {
507                          $body.=$text;                          $body.=x($text);
508                          chomp $text;                          chomp $text;
509                          $pitanje_tag .= $text;                          $pitanje_tag .= x($text);
510                  } else {                  } else {
511                          $pitanje_nr = $pitanje_tag;                          $pitanje_nr = $pitanje_tag;
512                          $pitanje_nr =~ s/[^0-9a-zA-Z]//g;                          $pitanje_nr =~ s/[^0-9a-zA-Z]//g;
# Line 805  sub checkboxes { Line 764  sub checkboxes {
764          }          }
765  }  }
766    
767    # read configuration data
768    #
769    # FIX: write actually this :-)
770    sub config {
771            package main;
772            my ($xp, $el, $attref, $ncref) = @_;
773    
774            $$ncref = sub {
775                    my ($xp, $text) = @_;
776                    $db_user=x($attref->{db_user});
777                    $prefix=x($attref->{prefix});
778            }
779    }
780    
781  #---------------------------------------------------------------  #---------------------------------------------------------------

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.5

  ViewVC Help
Powered by ViewVC 1.1.26