/[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.4 by dpavlin, Thu Apr 24 17:25:44 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    
# Line 18  sub x { Line 23  sub x {
23  $|=1;  $|=1;
24    
25  my $Usage =<<'End_of_Usage;';  my $Usage =<<'End_of_Usage;';
26  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.  
   
27  End_of_Usage;  End_of_Usage;
28    
29  my @Modes = qw(object pass skip);  my @Modes = qw(object pass skip);
30    
31  my $dir;  my $dir;
32  my $dowarn = 1;  my $dowarn = 1;
 my $dostyle = 0;  
33    
34  my $pitanje_nr = 0;             # curr. pitanje  my $pitanje_nr = 0;             # curr. pitanje
35  my $pitanje_tag = "";           # originalni oblik broja pitanja  my $pitanje_tag = "";           # originalni oblik broja pitanja
# Line 134  while (defined($ARGV[0]) and $ARGV[0] =~ Line 124  while (defined($ARGV[0]) and $ARGV[0] =~
124      print $Usage;      print $Usage;
125      exit;      exit;
126    }    }
   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";  
   }  
127  }  # End of option processing  }  # End of option processing
128    
129  my $docfile = shift;  my $xmlfile = shift;
130    
131  die "No docfile provided:\n$Usage" unless defined $docfile;  die "No poll xml file provided!\n$Usage" unless defined $xmlfile;
132    
133  die "Can't read $docfile" unless -r $docfile;  die "Can't read $xmlfile" unless -r $xmlfile;
134    
135  if (defined $dir) {  if (defined $dir) {
136    die "$dir isn't a directory" unless -d $dir;    die "$dir isn't a directory" unless -d $dir;
137  }  }
138  else {  else {
139    $docfile =~ m!([^/.]+)(?:\.[^/.]*)?$!;    $xmlfile =~ m!([^/.]+)(?:\.[^/.]*)?$!;
140    $dir = $1;    $dir = $1;
141    if (-e $dir) {    if (-e $dir) {
142      die "$dir exists but isn't a directory"      die "$dir exists but isn't a directory"
# Line 175  else { Line 147  else {
147    }    }
148  }  }
149    
150  my $in_slideshow = 0;  my $in_poll = 0;
151  my $after_head = 0;  my $after_head = 0;
152    
153  my $Mode = 0;  my $Mode = 0;
# Line 186  my $Markedup_Text; Line 158  my $Markedup_Text;
158  my $Object;  my $Object;
159  my @Ostack = ();  my @Ostack = ();
160    
161  my $intext = 0;  #my $intext = 0;
162  my $closure;  my $closure;
163  my @closure_stack = ();  my @closure_stack = ();
164    
165  my $style_link = '';  #my $style_link = '';
166    
167  my $index = 'index.html';  #my $index = 'index.html';
168  my @slidetitle;  #my @slidetitle;
169  my $body;  my $body;
170  my $inlist = 0;  #my $inlist = 0;
171    
172  my @Titles;  #my @Titles;
173    
174  my $header;  my $header;
175    
 my $prolog = "<html><head>\n";  
 $prolog .= "<!-- Generated by $0 on " . gmtime() . " GMT -->\n";  
   
176  my $page_number = 0;  my $page_number = 0;
177    
178  my $p = new XML::Parser(ErrorContext => 3,  my $p = new XML::Parser(ErrorContext => 3,
179                          Handlers => {Start => \&starthndl,                          Handlers => {Start => \&starthndl,
180                                       End   => \&endhndl,                                       End   => \&endhndl,
181                                       Char  => \&text});                                       Char  => \&text});
182  $p->parsefile($docfile);  $p->parsefile($xmlfile);
183    
184  #----------------------------------------------------------  #----------------------------------------------------------
185    
# Line 260  $head_php=~ s/##TEXT##/Ispunili ste %02d Line 229  $head_php=~ s/##TEXT##/Ispunili ste %02d
229  print PHP $head_php;  print PHP $head_php;
230  close(PHP);  close(PHP);
231    
232    # 01.php -> index.php
233    rename "$dir/01.php","$dir/index.php" || die "can't rename '$dir/01.php' to index.php";
234    
235  ################  ################
236  ## End of main  ## End of main
237  ################  ################
# Line 277  sub curr_pit { Line 249  sub curr_pit {
249          return "p".$pitanje_nr.$curr_suffix;          return "p".$pitanje_nr.$curr_suffix;
250  }  }
251    
252    #----------------------------------------------------------
253    
254  sub starthndl {  sub starthndl {
255    my ($xp, $el, %atts) = @_;    my ($xp, $el, %atts) = @_;
256    
257  #  return unless ($in_slideshow or $el eq 'slideshow');  #  return unless ($in_poll or $el eq 'slideshow');
258    
259    unless ($in_slideshow) {    unless ($in_poll) {
260      $in_slideshow = $xp->depth + 1;      $in_poll = $xp->depth + 1;
261      return;      return;
262    }    }
263    
# Line 330  sub starthndl { Line 304  sub starthndl {
304    
305    my $new_closure;    my $new_closure;
306    
307    my $subname = "Slideshow::$el";    my $subname = "Poll::$el";
308    
309    if (defined &$subname) {    if (defined &$subname) {
310      no strict 'refs';      no strict 'refs';
# Line 359  sub starthndl { Line 333  sub starthndl {
333  sub endhndl {  sub endhndl {
334    my ($xp, $el) = @_;    my ($xp, $el) = @_;
335    
336    return unless $in_slideshow;    return unless $in_poll;
337    
338    my $lev = $xp->depth;    my $lev = $xp->depth;
339    
340    if ($lev == $in_slideshow - 1) {    if ($lev == $in_poll - 1) {
341      $in_slideshow = 0;      $in_poll = 0;
342      $xp->finish;      $xp->finish;
343      return;      return;
344    }    }
# Line 414  sub endhndl { Line 388  sub endhndl {
388    $closure = pop(@closure_stack);    $closure = pop(@closure_stack);
389  }  # End endhndl  }  # End endhndl
390    
391    #----------------------------------------------------------
392    
393  sub text {  sub text {
394    my ($xp, $data) = @_;    my ($xp, $data) = @_;
395    
396    return unless $in_slideshow;    return unless $in_poll;
397    
398    if ($Mode ) {    if ($Mode ) {
399    
# Line 467  sub sgml_escape { Line 443  sub sgml_escape {
443    $str;    $str;
444  }  # End sgml_escape  }  # End sgml_escape
445    
 sub slidename {  
   my ($num) = @_;  
   
   sprintf("slide%03d.html", $num);  
 }  # End slidename  
   
446  ################################################################  ################################################################
447    
448  package Slideshow;  package Poll;
449    
450  sub page {  sub page {
451          package main;          package main;
# Line 490  sub page { Line 460  sub page {
460                          print "p[$page_nr] ";                          print "p[$page_nr] ";
461    
462                          if (defined $last_fn) {                          if (defined $last_fn) {
                                 # 01.php -> index.php  
                                 $last_fn="index.php" if ($last_fn eq "01.php");  
463                                  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$!";
464                                  if ($page_nr == 2) {                                  if ($page_nr == 2) {
465                                          print PAGE '<?php                                          print PAGE '<?php
# Line 545  sub nr { Line 513  sub nr {
513          $$ncref = sub {          $$ncref = sub {
514                  my ($xp, $text) = @_;                  my ($xp, $text) = @_;
515                  if (defined($text)) {                  if (defined($text)) {
516                          $body.=$text;                          $body.=x($text);
517                          chomp $text;                          chomp $text;
518                          $pitanje_tag .= $text;                          $pitanje_tag .= x($text);
519                  } else {                  } else {
520                          $pitanje_nr = $pitanje_tag;                          $pitanje_nr = $pitanje_tag;
521                          $pitanje_nr =~ s/[^0-9a-zA-Z]//g;                          $pitanje_nr =~ s/[^0-9a-zA-Z]//g;
# Line 805  sub checkboxes { Line 773  sub checkboxes {
773          }          }
774  }  }
775    
776    # read configuration data
777    #
778    # FIX: write actually this :-)
779    sub config {
780            package main;
781            my ($xp, $el, $attref, $ncref) = @_;
782    
783            $$ncref = sub {
784                    my ($xp, $text) = @_;
785                    $db_user=x($attref->{db_user});
786                    $prefix=x($attref->{prefix});
787            }
788    }
789    
790  #---------------------------------------------------------------  #---------------------------------------------------------------

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

  ViewVC Help
Powered by ViewVC 1.1.26