r109942 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109941‎ | r109942 | r109943 >
Date:19:54, 24 January 2012
Author:amire80
Status:ok (Comments)
Tags:
Comment:
Made it work with use strict, so it will be easier to debug. The commit is very big, but no functional changes are supposed to be here.
Modified paths:
  • /trunk/extensions/timeline/EasyTimeline.pl (modified) (history)

Diff [purge]

Index: trunk/extensions/timeline/EasyTimeline.pl
@@ -70,8 +70,11 @@
7171 # - change svg encoding from iso-8859-1 -> UTF-8
7272 # - allow font to be specified using -f option as opposed to hardcoded FreeSans.
7373
74 -our $VERSION = "1.13";
 74+use strict;
 75+use warnings;
7576
 77+our $VERSION = '1.90';
 78+
7679 use Time::Local;
7780 use Getopt::Std;
7881 use Cwd;
@@ -81,6 +84,7 @@
8285 # Many of these should be refactored.
8386 my @PlotLines;
8487 my $CntErrors = 0;
 88+my @Errors;
8589 my @Info;
8690 my @Warnings;
8791
@@ -137,8 +141,8 @@
138142 my $Line;
139143 my $NoData;
140144
141 -my %Consts; # see sub GetDefine
142 -my %Colors; # see sub StoreColor
 145+my %Consts; # see sub GetDefine
 146+my %Colors; # see sub StoreColor
143147 my %BackgroundColors;
144148 my %Axis;
145149 my @Bars;
@@ -158,7 +162,7 @@
159163 my @PlotText;
160164 my $MaxBarWidth;
161165 my %BarWidths;
162 -my $maxwidth; # XXX problematic
 166+
163167 my $Preset;
164168 my @PresetList;
165169 my %Scales;
@@ -170,8 +174,22 @@
171175
172176 my $firstcmd;
173177
 178+my @PlotTextsPng;
 179+my @PlotTextsSvg;
 180+my @linksSVG;
 181+my @textsSVG;
 182+
 183+my @TextData;
 184+
 185+my ($sign, $posy1, $posy2);
 186+
 187+my $script;
 188+my @PlotBarsNow;
 189+
 190+my $command;
 191+
174192 # BEGIN
175 -$| = 1; # flush screen output
 193+local $| = 1; # flush screen output
176194
177195 print "EasyTimeline version $VERSION\n"
178196 . "Copyright (C) 2004 Erik Zachte\n"
@@ -196,10 +214,10 @@
197215 &WritePlotFile;
198216 }
199217
200 -if ($CntErrors == 1) {
 218+if ($CntErrors == 1) {
201219 &Abort("1 error found");
202220 }
203 -elsif ($CntErrors > 1) {
 221+elsif ($CntErrors > 1) {
204222 &Abort("$CntErrors errors found");
205223 }
206224 else {
@@ -231,7 +249,6 @@
232250 exit;
233251
234252 sub ParseArguments {
235 - my $options;
236253 getopt("iTAPef", \%options);
237254
238255 &Abort("Specify input file as: -i filename") if (!defined($options{"i"}));
@@ -763,7 +780,7 @@
764781 $barset = ""; # $barcount = "" ;
765782
766783 # warn "data: $data";
767 - my $data2; # = $data;
 784+ my $data2; # = $data;
768785 ($data2, $text) = &ExtractText($data2);
769786 @Attributes = split(" ", $data2);
770787
@@ -1120,7 +1137,7 @@
11211138 $width = 2.0;
11221139
11231140 # warn "data: $data";
1124 - my $data2; # = $data;
 1141+ my $data2; # = $data;
11251142
11261143 LineData:
11271144 while ((!$InputParsed) && (!$NoData)) {
@@ -1690,7 +1707,7 @@
16911708 sub ParsePlotData {
16921709 my $attrvalue2;
16931710 my $BarsCommandFound = @Bars;
1694 - my $prevbar = "";
 1711+ my $prevbar = "";
16951712 my $barndx;
16961713
16971714 if ( (!(defined($DateFormat)))
@@ -2158,11 +2175,14 @@
21592176 }
21602177 elsif ($#Bars == 0) {
21612178 $bar = $Bars[0];
 2179+
21622180 # warn "data: $data";
2163 - &Info(q(), # $data,
 2181+ &Info(
 2182+ q(), # $data,
21642183 "PlotData incomplete. Attribute 'bar' missing, value '"
21652184 . $Bars[0]
2166 - . "' assumed.");
 2185+ . "' assumed."
 2186+ );
21672187 }
21682188 else { $bar = "1"; }
21692189
@@ -2292,41 +2312,7 @@
22932313 if ($align eq "") { $align = "center"; }
22942314 if ($color eq "") { $color = "black"; }
22952315 if ($fontsize eq "") { $fontsize = "S"; }
2296 - # $adjust Doesn't seem to be used anywhere
2297 - # if ($adjust eq "") { $adjust = "0,0"; }
22982316
2299 - # $textdetails = " textdetails: align=$align size=$size" ;
2300 - # if ($textcolor eq "")
2301 - # { $textcolor = "black" ; }
2302 - # if ($color ne "")
2303 - # { $textdetails .= " color=$textcolor" ; }
2304 -
2305 - # my ($xpos, $ypos) ;
2306 - # my $barcnt = 0 ;
2307 - # for ($b = 0 ; $b <= $#Bars ; $b++)
2308 - # {
2309 - # if (lc($Bars[$b]) eq lc($bar))
2310 - # { $barcnt = ($b + 1) ; last ; }
2311 - # }
2312 -
2313 - # if ($Axis{"time"} eq "x")
2314 - # { $xpos = "$at(s)" ; $ypos = "[$barcnt](s)" ; }
2315 - # else
2316 - # { $ypos = "$at(s)" ; $xpos = "[$barcnt](s)" ; }
2317 -
2318 - # if ($shift ne "")
2319 - # {
2320 - # my ($shiftx, $shifty) = split (",", $shift) ;
2321 - # if ($shiftx > 0)
2322 - # { $xpos .= "+$shiftx" ; }
2323 - # if ($shiftx < 0)
2324 - # { $xpos .= "$shiftx" ; }
2325 - # if ($shifty > 0)
2326 - # { $ypos .= "+$shifty" ; }
2327 - # if ($shifty < 0)
2328 - # { $ypos .= "$shifty" ; }
2329 - # }
2330 -
23312317 $text =~ s/\,/\#\%\$/g;
23322318 $link =~ s/\,/\#\%\$/g;
23332319 $hint =~ s/\,/\#\%\$/g;
@@ -2351,20 +2337,21 @@
23522338 );
23532339 }
23542340
2355 - $maxwidth = 0;
2356 - my $key;
2357 - foreach $key (keys %BarWidths) {
2358 - if ($BarWidths{$key} == 0) {
 2341+ my $maxwidth = 0;
 2342+ foreach my $bar_width (keys %BarWidths) {
 2343+ if ($BarWidths{$bar_width} == 0) {
23592344 &Warning(
2360 - "PlotData incomplete. No bar width defined for bar '$key', assume width from widest bar (used for line marks)."
 2345+ "PlotData incomplete. No bar width defined for bar '$bar_width', assume width from widest bar (used for line marks)."
23612346 );
23622347 }
2363 - elsif ($BarWidths{$key} > $maxwidth) {
2364 - $maxwidth = $BarWidths{$key};
 2348+ elsif ($BarWidths{$bar_width} > $maxwidth) {
 2349+ $maxwidth = $BarWidths{$bar_width};
23652350 }
23662351 }
2367 - foreach $key (keys %BarWidths) {
2368 - if ($BarWidths{$key} == 0) { $BarWidths{$key} = $maxwidth; }
 2352+ foreach my $bar_width (keys %BarWidths) {
 2353+ if ($BarWidths{$bar_width} == 0) {
 2354+ $BarWidths{$bar_width} = $maxwidth;
 2355+ }
23692356 }
23702357 }
23712358
@@ -2470,7 +2457,7 @@
24712458
24722459 if (!ValidAttributes("Scale" . $scale)) { return; }
24732460
2474 - &CheckPreset(Scale . $scale);
 2461+ &CheckPreset('Scale' . $scale);
24752462
24762463 $Scales{$scale} = $true;
24772464
@@ -2619,8 +2606,8 @@
26202607 $textcolor = $TextDefs{"textcolor"};
26212608 }
26222609
2623 - warn "data: $data";
2624 - my $data2 = $data;
 2610+ # warn "data: $data"; # XXX $data is probably not really used
 2611+ my $data2; # = $data; # XXX see above
26252612 ($data2, $text) = &ExtractText($data2);
26262613 @Attributes = split(" ", $data2);
26272614
@@ -2773,7 +2760,7 @@
27742761 if (defined($tabs) && ($tabs ne "")) {
27752762 $tabs =~ s/^\s*$hBrO (.*) $hBrC\s*$/$1/x;
27762763 my @Tabs = split(",", $tabs);
2777 - foreach $tab (@Tabs) {
 2764+ foreach my $tab (@Tabs) {
27782765 $tab =~ s/\s* (.*) \s*$/$1/x;
27792766 if (!($tab =~ /\d+\-(?:center|left|right)$/)) {
27802767 &Error(
@@ -2784,7 +2771,7 @@
27852772 }
27862773 }
27872774
2788 - @Text = split('\^', $text);
 2775+ my @Text = split('\^', $text);
27892776 if ($#Text > $#Tabs + 1) {
27902777 &Error( "TextData invalid. "
27912778 . $#Text
@@ -2811,7 +2798,7 @@
28122799
28132800 &CheckPreset("TimeAxis");
28142801
2815 - foreach $attribute (keys %Attributes) {
 2802+ foreach my $attribute (keys %Attributes) {
28162803 my $attrvalue = $Attributes{$attribute};
28172804
28182805 if ($attribute =~ /Format/i) {
@@ -2934,7 +2921,7 @@
29352922 my ($val, $dim);
29362923
29372924 if ($Image{"width"} =~ /auto/i) {
2938 - foreach $attribute ("width", "left", "right") {
 2925+ foreach my $attribute ("width", "left", "right") {
29392926 if ($PlotArea{$attribute} =~ /\%/) {
29402927 &Error2( "You specified 'ImageSize = width:auto'.\n"
29412928 . " This implies absolute values in PlotArea attributes 'left', 'right' and/or 'width' (no \%).\n"
@@ -2956,7 +2943,7 @@
29572944 }
29582945
29592946 if ($Image{"height"} =~ /auto/i) {
2960 - foreach $attribute ("height", "top", "bottom") {
 2947+ foreach my $attribute ("height", "top", "bottom") {
29612948 if ($PlotArea{$attribute} =~ /\%/) {
29622949 &Error2( "You specified 'ImageSize = height:auto'.\n"
29632950 . " This implies absolute values in PlotArea attributes 'top', 'bottom' and/or 'height' (no \%).\n"
@@ -3069,6 +3056,7 @@
30703057 if ( (defined($Scales{"Major"}))
30713058 || (defined($Scales{"Minor"})))
30723059 {
 3060+ my $margin;
30733061 if (defined($Scales{"Major"})) { $margin = 0.2; }
30743062 else { $margin = 0.05; }
30753063
@@ -3216,10 +3204,10 @@
32173205 push @PlotTextsPng, $textdetails . "\n";
32183206 push @PlotTextsSvg, $textdetails . "\n";
32193207
3220 - $text2 = $text;
 3208+ my $text2 = $text;
32213209 $text2 =~ s/\[\[//g;
32223210 $text2 =~ s/\]\]//g;
3223 - if ($text2 =~ /^\s/) {
 3211+ if ($text2 =~ /^\s/) {
32243212 push @PlotTextsPng, " text: \n\\$text2\n\n";
32253213 }
32263214 else {
@@ -3239,7 +3227,7 @@
32403228 $text2 =~ s/^ ([^\[]+) \]\]/\[$lcnt\[$1\]$lcnt\]/x;
32413229 }
32423230
3243 - $text3 = &EncodeHtml($text2);
 3231+ my $text3 = &EncodeHtml($text2);
32443232 if ($text2 ne $text3) {
32453233
32463234 # put placeholder in Ploticus input file
@@ -3251,7 +3239,7 @@
32523240 while (length($text3) < length($text2)) { $text3 .= "x"; }
32533241 }
32543242
3255 - if ($text3 =~ /^\s/) {
 3243+ if ($text3 =~ /^\s/) {
32563244 push @PlotTextsSvg, " text: \n\\$text3\n\n";
32573245 }
32583246 else {
@@ -3299,7 +3287,7 @@
33003288 my $pos2 = index($text, "]]") + 1;
33013289 if (($pos1 > -1) && ($pos2 > -1)) {
33023290 for (my $i = 0; $i < length($text); $i++) {
3303 - $c = substr($text, $i, 1);
 3291+ my $c = substr($text, $i, 1);
33043292 if ($c ne "\n") {
33053293 if (($i < $pos1) || ($i > $pos2)) {
33063294 substr($text, $i, 1) = " ";
@@ -3368,7 +3356,7 @@
33693357 s/\s* (.*) \s*$/$1/x;
33703358 }
33713359
3372 - $posx0 = $posx;
 3360+ my $posx0 = $posx;
33733361 my @Text;
33743362 my $dy = 0;
33753363
@@ -3401,32 +3389,37 @@
34023390 push @Text, $text;
34033391 }
34043392
3405 - foreach $text (@Text) { # XXX $text should be renamed here
3406 - if ($text !~ /^[\n\s]*$/) {
 3393+ foreach my $text_item (@Text) {
 3394+ if ($text_item !~ /^[\n\s]*$/) {
34073395 $link2 = "";
34083396 $hint2 = "";
3409 - ($text, $link2, $hint2) = &ProcessWikiLink($text, $link2, $hint2);
 3397+ ($text_item, $link2, $hint2) =
 3398+ &ProcessWikiLink($text_item, $link2, $hint2);
34103399
34113400 if ($link2 eq "") {
34123401 $link2 = $link;
3413 - if (($link ne "") && ($text !~ /\[\[.*\]\]/)) {
3414 - $text = "[[" . $text . "]]";
 3402+ if (($link ne "") && ($text_item !~ /\[\[.*\]\]/)) {
 3403+ $text_item = "[[" . $text_item . "]]";
34153404 }
34163405 }
34173406 if ($hint2 eq "") { $hint2 = $hint; }
34183407
34193408 &WriteProcAnnotate(
3420 - $bar, $shiftx, $posx, $posy, $text,
 3409+ $bar, $shiftx, $posx, $posy, $text_item,
34213410 $textcolor, $fontsize, $align, $link2, $hint2
34223411 );
34233412 }
34243413
34253414 if ($#Tabs >= 0) {
34263415 $tab = shift(@Tabs);
 3416+ my $dx;
34273417 ($dx, $align) = split("\-", $tab);
34283418 $posx = $posx0 + &Normalize($dx);
34293419 }
3430 - if ($posy =~ /\+/) { ($posy1, $posy2) = split('\+', $posy); }
 3420+
 3421+ if ($posy =~ /\+/) {
 3422+ ($posy1, $posy2) = split('\+', $posy);
 3423+ }
34313424 elsif ($posy =~ /.+\-/) {
34323425 if ($posy =~ /^\-/) {
34333426 ($sign, $posy1, $posy2) = split('\-', $posy);
@@ -3438,7 +3431,10 @@
34393432 $posy2 = -$posy2;
34403433 }
34413434 }
3442 - else { $posy1 = $posy; $posy2 = 0; }
 3435+ else {
 3436+ $posy1 = $posy;
 3437+ $posy2 = 0;
 3438+ }
34433439
34443440 $posy2 -= $dy;
34453441
@@ -3448,38 +3444,12 @@
34493445 }
34503446 }
34513447
3452 -sub WriteProcDrawCommandsOld {
3453 - my $posx = shift;
3454 - my $posy = shift;
3455 - my $text = shift;
3456 - my $textcolor = shift;
3457 - my $fontsize = shift;
3458 - my $link = shift;
3459 - my $hint = shift;
3460 -
3461 - $posx0 = $posx;
3462 - my @Text = split('\^', $text);
3463 - my $align = "text";
3464 - foreach $text (@Text) {
3465 - push @TextData, " mov $posx $posy\n";
3466 - push @TextData, " textsize $fontsize\n";
3467 - push @TextData, " color $textcolor\n";
3468 - push @TextData, " $align $text\n";
3469 -
3470 - $tab = shift(@Tabs);
3471 - ($dx, $align) = split("\-", $tab);
3472 - $posx = $posx0 + &Normalize($dx);
3473 - if ($align =~ /left/i) { $align = "text"; }
3474 - elsif ($align =~ /right/i) { $align = "rightjust"; }
3475 - else { $align = "centext"; }
3476 - }
3477 -}
3478 -
34793448 sub WritePlotFile {
34803449 &WriteTexts;
34813450
34823451 $script = "";
3483 - my ($color);
 3452+
 3453+ my $AxisBars;
34843454 if ($Axis{"time"} eq "x") { $AxisBars = "y"; }
34853455 else { $AxisBars = "x"; }
34863456
@@ -3491,6 +3461,7 @@
34923462 # @Bars = @BarsTmp ;
34933463 # }
34943464
 3465+ my $file_script;
34953466 if ($tmpdir ne "") {
34963467 $file_script = $tmpdir . $pathseparator . "EasyTimeline.txt.$$";
34973468 }
@@ -3518,8 +3489,10 @@
35193490 }
35203491 $script .= "\n";
35213492
3522 - $barcnt = $#Bars + 1;
 3493+ my $barcnt = $#Bars + 1;
35233494
 3495+ my ($U, $x);
 3496+
35243497 # if ($AlignBars eq "justify") && ($#Bars > 0)
35253498 #
35263499 # given P = plotwidth in pixels
@@ -3550,6 +3523,7 @@
35513524 $AlignBars = "early";
35523525 }
35533526
 3527+ my $extent;
35543528 if ($Axis{"time"} eq "x") { $extent = "height"; }
35553529 else { $extent = "width"; }
35563530
@@ -3560,6 +3534,7 @@
35613535
35623536 if ($MaxBarWidth == $PlotArea{$extent}) { $PlotArea{$extent} += 0.01; }
35633537
 3538+ my ($till, $from);
35643539 if ($MaxBarWidth == $PlotArea{$extent}) {
35653540 $till = 1;
35663541 $from = 1;
@@ -3653,7 +3628,7 @@
36543629 # $script .= " clickmapurl: http://www.wikipedia.org/wiki/Vladimir_Lenin\n" ;
36553630
36563631 #proc legendentry
3657 - foreach $color (sort keys %Colors) {
 3632+ foreach my $color (sort keys %Colors) {
36583633 $script .= "#proc legendentry\n";
36593634 $script .= " sampletype: color\n";
36603635
@@ -3672,9 +3647,9 @@
36733648 $script .= " delim: comma\n";
36743649 $script .= " data:\n";
36753650
3676 - $maxwidth = 0;
3677 - foreach $entry (@PlotBars) {
3678 - ($width) = split(",", $entry);
 3651+ my $maxwidth = 0;
 3652+ foreach my $entry (@PlotBars) {
 3653+ my ($width) = split(",", $entry);
36793654 if ($width > $maxwidth) { $maxwidth = $width; }
36803655 }
36813656
@@ -3714,8 +3689,9 @@
37153690
37163691 $script .= "\n([inc3])\n\n"; # will be replace by rects
37173692
3718 - %x = %BarWidths;
3719 - foreach $entry (@PlotLines) {
 3693+ # %x = %BarWidths; # XXX doesn't seem to be used
 3694+ my ($bar, $width);
 3695+ foreach my $entry (@PlotLines) {
37203696 ($bar) = split(",", $entry);
37213697 $bar =~ s/\#.*//;
37223698 $width = $BarWidths{$bar};
@@ -3725,6 +3701,9 @@
37263702 @PlotBarsNow = @PlotLines;
37273703 &PlotBars;
37283704
 3705+ my ($scriptPng1, $scriptPng2, $scriptPng3);
 3706+ my ($scriptSvg1, $scriptSvg2);
 3707+
37293708 #proc axis
37303709 if ($#Bars > 0) {
37313710 $scriptPng2 = "#proc " . $AxisBars . "axis\n";
@@ -3750,23 +3729,28 @@
37513730 $scriptPng2 .= " stubs: text\n";
37523731 $scriptSvg2 .= " stubs: text\n";
37533732
3754 - # XXX huh? Yields a warning.
37553733 my $text;
37563734 my $link;
37573735 my $hint;
37583736
 3737+ my @Bars2;
 3738+
37593739 undef(@Bars2);
3760 - foreach $bar (@Bars) {
3761 - if ($AxisBars eq "y") { push @Bars2, $bar; }
3762 - else { unshift @Bars2, $bar; }
 3740+ foreach my $bar_iter (@Bars) {
 3741+ if ($AxisBars eq "y") {
 3742+ push @Bars2, $bar_iter;
 3743+ }
 3744+ else {
 3745+ unshift @Bars2, $bar_iter;
 3746+ }
37633747 }
37643748
3765 - foreach $bar (@Bars2) {
 3749+ foreach my $bar2_iter (@Bars2) {
37663750 $hint = "";
3767 - $text = $BarLegend{ lc($bar) };
 3751+ $text = $BarLegend{ lc($bar2_iter) };
37683752 if ($text =~ /^\s*$/) { $text = "\\"; }
37693753
3770 - $link = $BarLink{ lc($bar) };
 3754+ $link = $BarLink{ lc($bar2_iter) };
37713755 if (!defined($link)) {
37723756 if ($text =~ /\[.*\]/) {
37733757 ($text, $link, $hint) =
@@ -3782,7 +3766,9 @@
37833767 $scriptSvg2 .=
37843768 "[" . $lcnt . "[" . $text . "]" . $lcnt . "]\n";
37853769 }
3786 - else { $scriptSvg2 .= "$text\n"; }
 3770+ else {
 3771+ $scriptSvg2 .= "$text\n";
 3772+ }
37873773 }
37883774 $scriptPng2 .= "\n";
37893775 $scriptSvg2 .= "\n";
@@ -3803,12 +3789,12 @@
38043790 $scriptPng2 .= " stubs: text\n";
38053791
38063792 $barcnt = $#Bars + 1;
3807 - foreach $bar (@Bars2) {
 3793+ foreach my $bars2_iter (@Bars2) {
38083794 $hint = "";
3809 - $text = $BarLegend{ lc($bar) };
 3795+ $text = $BarLegend{ lc($bars2_iter) };
38103796 if ($text =~ /^\s*$/) { $text = "\\"; }
38113797
3812 - $link = $BarLink{ lc($bar) };
 3798+ $link = $BarLink{ lc($bars2_iter) };
38133799 if (!defined($link)) {
38143800 if ($text =~ /\[.*\]/) {
38153801 ($text, $link, $hint) =
@@ -3844,23 +3830,25 @@
38453831 $script .= "\n([inc2])\n\n";
38463832
38473833 if ($#PlotTextsPng >= 0) {
3848 - foreach $command (@PlotTextsPng) {
3849 - if ($command =~ /^\s*location/) {
3850 - $command =~ s/(.*)\[(.*)\](.*)/$1 . ($#Bars - $2 + 2) . $3/xe;
 3834+ foreach my $plot_texts_png_command (@PlotTextsPng) {
 3835+ if ($plot_texts_png_command =~ /^\s*location/) {
 3836+ $plot_texts_png_command =~
 3837+ s/(.*)\[(.*)\](.*)/$1 . ($#Bars - $2 + 2) . $3/xe;
38513838 }
38523839
3853 - $scriptPng1 .= $command;
 3840+ $scriptPng1 .= $plot_texts_png_command;
38543841 }
38553842 $scriptPng1 .= "\n";
38563843 }
38573844
38583845 if ($#PlotTextsSvg >= 0) {
3859 - foreach $command (@PlotTextsSvg) {
3860 - if ($command =~ /^\s*location/) {
3861 - $command =~ s/(.*)\[(.*)\](.*)/$1 . ($#Bars - $2 + 2) . $3/xe;
 3846+ foreach my $plot_texts_svg_command (@PlotTextsSvg) {
 3847+ if ($plot_texts_svg_command =~ /^\s*location/) {
 3848+ $plot_texts_svg_command =~
 3849+ s/(.*)\[(.*)\](.*)/$1 . ($#Bars - $2 + 2) . $3/xe;
38623850 }
38633851
3864 - $scriptSvg1 .= $command;
 3852+ $scriptSvg1 .= $plot_texts_svg_command;
38653853 }
38663854 $scriptSvg1 .= "\n";
38673855 }
@@ -3880,7 +3868,7 @@
38813869 if ($#TextData >= 0) {
38823870 $script .= "#proc drawcommands\n";
38833871 $script .= " commands:\n";
3884 - foreach $entry (@TextData) { $script .= $entry; }
 3872+ foreach my $entry (@TextData) { $script .= $entry; }
38853873 $script .= "\n";
38863874 }
38873875
@@ -3895,7 +3883,7 @@
38963884 return;
38973885 }
38983886
3899 - $perColumn = 999;
 3887+ my $perColumn = 999;
39003888 if ($Legend{"orientation"} =~ /ver/i) {
39013889 if ($Legend{"columns"} > 1) {
39023890 $perColumn = 0;
@@ -3905,7 +3893,7 @@
39063894 }
39073895 }
39083896
3909 - for ($l = 1; $l <= $Legend{"columns"}; $l++) {
 3897+ for (1 .. $Legend{"columns"}) {
39103898 $script .= "#proc legend\n";
39113899 $script .= " noclear: yes\n";
39123900 if ($Legend{"orientation"} =~ /ver/i) {
@@ -3920,8 +3908,8 @@
39213909 . ($Legend{"left"} + 0.2) . " "
39223910 . $Legend{"top"} . "\n";
39233911 $script .= " specifyorder:\n";
3924 - for ($l2 = 1; $l2 <= $perColumn; $l2++) {
3925 - $category = shift(@LegendData);
 3912+ for (1 .. $perColumn) {
 3913+ my $category = shift(@LegendData);
39263914 if (defined($category)) { $script .= "$category\n"; }
39273915 }
39283916 $script .= "\n";
@@ -3931,6 +3919,7 @@
39323920
39333921 $script .= "#endproc\n";
39343922
 3923+ my $pl;
39353924 print "\nGenerating output:\n";
39363925 if ($ploticus_command ne "") {
39373926 $pl = $ploticus_command;
@@ -3944,7 +3933,7 @@
39453934 . $pl . "\" ("
39463935 . $ploticus_command . ")\n";
39473936
3948 - $script_save = $script;
 3937+ my $script_save = $script;
39493938
39503939 $script =~ s/\(\[inc1\]\)/$scriptSvg1/;
39513940 $script =~ s/\(\[inc2\]\)/$scriptSvg2/;
@@ -3968,7 +3957,7 @@
39693958 print FILE_OUT &DecodeInput($script);
39703959 close "FILE_OUT";
39713960
3972 - $map = ($MapSVG) ? "-map" : "";
 3961+ my $map = ($MapSVG) ? "-map" : "";
39733962
39743963 print "Running Ploticus to generate svg file\n";
39753964
@@ -4053,30 +4042,32 @@
40544043 }
40554044 }
40564045
4057 - if (-e $file_htmlmap
4058 - ) # correct click coordinates of right aligned texts (Ploticus bug)
4059 - {
 4046+ # correct click coordinates of right aligned texts (Ploticus bug)
 4047+ if (-e $file_htmlmap) {
40604048 open "FILE_IN", "<", $file_htmlmap;
4061 - @map = <FILE_IN>;
 4049+ my @map = <FILE_IN>;
40624050 close "FILE_IN";
40634051
4064 - foreach $line (@map) {
 4052+ my @map2;
 4053+ foreach my $line (@map) {
40654054 chomp $line;
40664055 if ($line =~ /\&\&/) {
4067 - $coords = $line;
4068 - $shift = $line;
 4056+ my $coords = $line;
 4057+ my $shift = $line;
40694058 $coords =~ s/^.*coords\=\"([^\"]*)\".*$/$1/;
4070 - $shift =~ s/^.*\&\&([^\"]*)\".*$/$1/;
 4059+ $shift =~ s/^.*\&\&([^\"]*)\".*$/$1/; # XXX?
40714060 $line =~ s/\&\&[^\"]*//;
4072 - (@updcoords) = split(",", $coords);
4073 - $maplength = $updcoords[2] - $updcoords[0];
 4061+ my (@updcoords) = split(",", $coords);
 4062+ my $maplength = $updcoords[2] - $updcoords[0];
40744063 $updcoords[0] = $updcoords[0] - 2 * ($maplength - 25);
40754064 $updcoords[2] = $updcoords[0] + $maplength;
4076 - $coordsnew = join(",", @updcoords);
 4065+ my $coordsnew = join(",", @updcoords);
40774066 $line =~ s/$coords/$coordsnew/;
40784067 push @map2, $line . "\n";
40794068 }
4080 - else { push @map2, $line . "\n"; }
 4069+ else {
 4070+ push @map2, $line . "\n";
 4071+ }
40814072 }
40824073
40834074 open "FILE_OUT", ">", $file_htmlmap;
@@ -4086,13 +4077,12 @@
40874078
40884079 if (-e $file_vector) {
40894080 open "FILE_IN", "<", $file_vector;
4090 - @svg = <FILE_IN>;
 4081+ my @svg = <FILE_IN>;
40914082 close "FILE_IN";
40924083
4093 - foreach $line (@svg) {
4094 - $line =~ s/\{\{(\d+)\}\}x+/$textsSVG[$1]/gxe;
4095 - $line =~
4096 - s/\[(\d+)\[ (.*?) \]\d+\]/'<a style="fill:blue;" xlink:href="' . $linksSVG[$1] . '">' . $2 . '<\/a>'/gxe;
 4084+ foreach (@svg) {
 4085+ s/\{\{(\d+)\}\}x+/$textsSVG[$1]/gxe;
 4086+ s/\[(\d+)\[ (.*?) \]\d+\]/'<a style="fill:blue;" xlink:href="' . $linksSVG[$1] . '">' . $2 . '<\/a>'/gxe;
40974087 }
40984088
40994089 open "FILE_OUT", ">", $file_vector;
@@ -4105,13 +4095,15 @@
41064096 $map = "";
41074097 if ($linkmap) {
41084098 open "FILE_IN", "<", $file_htmlmap;
4109 - while ($line = <FILE_IN>) { $map .= $line; }
 4099+ while (my $line = <FILE_IN>) {
 4100+ $map .= $line;
 4101+ }
41104102 close "FILE_IN";
41114103 }
41124104 print "Generating html test file\n";
4113 - $width = sprintf("%.0f", $Image{"width"} * 100);
4114 - $height = sprintf("%.0f", $Image{"height"} * 100);
4115 - $html = <<__HTML__ ;
 4105+ $width = sprintf("%.0f", $Image{"width"} * 100);
 4106+ my $height = sprintf("%.0f", $Image{"height"} * 100);
 4107+ my $html = <<__HTML__ ;
41164108
41174109 <html>
41184110 <head>
@@ -4168,8 +4160,9 @@
41694161 }
41704162
41714163 sub WriteTexts {
4172 - my ($line, $xpos, $ypos);
4173 - foreach $line (@PlotText) {
 4164+ my ($xpos, $ypos);
 4165+
 4166+ foreach my $line (@PlotText) {
41744167 my (
41754168 $at, $bar, $text, $textcolor, $fontsize,
41764169 $align, $shift, $link, $hint
@@ -4191,8 +4184,10 @@
41924185 }
41934186 else { $ypos = "$at(s)"; $xpos = "[$barcnt](s)"; }
41944187
 4188+ # XXX - $shiftx was defined inside the if block.
 4189+ my ($shiftx, $shifty);
41954190 if ($shift ne "") {
4196 - my ($shiftx, $shifty) = split(",", $shift);
 4191+ ($shiftx, $shifty) = split(",", $shift);
41974192 if ($shiftx > 0) { $xpos .= "+$shiftx"; }
41984193 if ($shiftx < 0) { $xpos .= "$shiftx"; }
41994194 if ($shifty > 0) { $ypos .= "+$shifty"; }
@@ -4208,14 +4203,15 @@
42094204 }
42104205
42114206 sub PlotBars {
 4207+ my @PlotBarsLater;
42124208
42134209 #proc getdata / #proc bars
42144210 while ($#PlotBarsNow >= 0) {
42154211 undef @PlotBarsLater;
42164212
4217 - $maxwidth = 0;
4218 - foreach $entry (@PlotBarsNow) {
4219 - ($width) = split(",", $entry);
 4213+ my $maxwidth = 0;
 4214+ foreach my $entry (@PlotBarsNow) {
 4215+ my ($width) = split(",", $entry);
42204216 if ($width > $maxwidth) { $maxwidth = $width; }
42214217 }
42224218
@@ -4223,7 +4219,7 @@
42244220 $script .= " delim: comma\n";
42254221 $script .= " data:\n";
42264222
4227 - foreach $entry (@PlotBarsNow) {
 4223+ foreach my $entry (@PlotBarsNow) {
42284224 my ($width, $bar, $from, $till, $color, $link, $hint) =
42294225 split(",", $entry);
42304226 if ($width < $maxwidth) {
@@ -4250,24 +4246,17 @@
42514247 }
42524248 $script .= "\n";
42534249
4254 - #proc bars
 4250+ # proc bars
42554251 $script .= "#proc bars\n";
42564252 $script .= " axis: " . $Axis{"time"} . "\n";
42574253 $script .= " barwidth: $maxwidth\n";
42584254 $script .= " outline: no\n";
42594255
4260 - # $script .= " thinbarline: width=5\n" ;
42614256 if ($Axis{"time"} eq "x") { $script .= " horizontalbars: yes\n"; }
42624257 $script .= " locfield: 1\n";
42634258 $script .= " segmentfields: 2 3\n";
42644259 $script .= " colorfield: 4\n";
42654260
4266 - # $script .= " outline: width=1\n" ;
4267 - # $script .= " barwidthfield: 5\n" ;
4268 - # if ($fields[4] ne "")
4269 - # { $script .= " clickmapurl: " . &LinkToUrl ($text) . "\n" ; }
4270 - # if ($fields[5] ne "")
4271 - # { $script .= " clickmaplabel: $text\n" ; }
42724261 $script .= " clickmapurl: \@\@5\n";
42734262 $script .= " clickmaplabel: \@\@6\n";
42744263 $script .= "\n";
@@ -4281,7 +4270,7 @@
42824271 my $grid = shift;
42834272 my ($color, $from, $till, $start);
42844273
4285 - %x = %Period;
 4274+ # %x = %Period; # XXX doesn't seem to be used
42864275
42874276 # if (($DateFormat =~ /\//) && ($grid))
42884277 # { return ; }
@@ -4354,7 +4343,7 @@
43554344 # $start =~ s/.*\///g ; # delete dd mm if present
43564345 $start = &DateToFloat($start);
43574346 if ($Axis{"order"} =~ /reverse/i) {
4358 - $loop = 0;
 4347+ my $loop = 0;
43594348 $start = -$start;
43604349 while ($start - $Scales{"$scale inc"} >= -$Period{"till"}) {
43614350 $start -= $Scales{"$scale inc"};
@@ -4400,23 +4389,30 @@
44014390
44024391 if ($#DrawLines < 0) { return; }
44034392
 4393+ my @DrawLinesNow;
44044394 undef(@DrawLinesNow);
44054395
4406 - foreach $line (@DrawLines) {
4407 - if ($line =~ /\|$layer\n/) { push @DrawLinesNow, $line; }
 4396+ foreach my $line (@DrawLines) {
 4397+ if ($line =~ /\|$layer\n/) {
 4398+ push @DrawLinesNow, $line;
 4399+ }
44084400 }
44094401
44104402 if ($#DrawLinesNow < 0) { return; }
44114403
4412 - foreach $entry (@DrawLinesNow) {
 4404+ foreach my $entry (@DrawLinesNow) {
44134405 chomp($entry);
44144406 $script .= "#proc line\n";
44154407
 4408+ my ($mode, $at, $from, $till, $color, $width, $points);
 4409+
44164410 # $script .= " notation: scaled\n" ;
44174411 if ($entry =~ /^[12]/) {
44184412 ($mode, $at, $from, $till, $color, $width) = split('\|', $entry);
44194413 }
4420 - else { ($mode, $points, $color, $width) = split('\|', $entry); }
 4414+ else {
 4415+ ($mode, $points, $color, $width) = split('\|', $entry);
 4416+ }
44214417
44224418 $script .= " linedetails: width=$width color=$color style=0\n";
44234419
@@ -4470,10 +4466,14 @@
44714467 }
44724468 }
44734469
4474 - if ($mode == 3) # draw free line
4475 - {
4476 - @Points = split(",", $points);
4477 - foreach $point (@Points) { $point = &Normalize($point); }
 4470+ # draw free line
 4471+ if ($mode == 3) {
 4472+ my @Points = split(",", $points);
 4473+
 4474+ foreach my $point (@Points) {
 4475+ $point = &Normalize($point);
 4476+ }
 4477+
44784478 if ( ($Points[0] > $Image{"width"})
44794479 || ($Points[1] > $Image{"height"})
44804480 || ($Points[2] > $Image{"width"})
@@ -4514,7 +4514,9 @@
45154515 }
45164516 return ($true);
45174517 }
4518 - else { return ($false); }
 4518+ else {
 4519+ return ($false);
 4520+ }
45194521 }
45204522
45214523 # Can be much simpler
@@ -4657,14 +4659,15 @@
46584660 return (sprintf("%.3f", ($from + $till) / 2));
46594661 }
46604662
4661 - $from2 = &DaysFrom1800($from);
4662 - $till2 = &DaysFrom1800($till);
4663 - my $date = &DateFrom1800(int(($from2 + $till2) / 2));
 4663+ my $from2 = &DaysFrom1800($from);
 4664+ my $till2 = &DaysFrom1800($till);
 4665+ my $date = &DateFrom1800(int(($from2 + $till2) / 2));
46644666 return ($date);
46654667 }
46664668
46674669 sub DaysFrom1800 {
4668 - @mmm = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
 4670+ my @mmm = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
 4671+ my ($day, $month, $year);
46694672 my $date = shift;
46704673 if ($DateFormat eq "dd/mm/yyyy") {
46714674 $day = substr($date, 0, 2);
@@ -4681,11 +4684,11 @@
46824685 return;
46834686 }
46844687
4685 - $days = ($year - 1800) * 365;
 4688+ my $days = ($year - 1800) * 365;
46864689 $days += int(($year - 1 - 1800) / 4);
46874690 $days -= int(($year - 1 - 1800) / 100);
46884691 if ($month > 1) {
4689 - for ($m = $month - 2; $m >= 0; $m--) {
 4692+ for (my $m = $month - 2; $m >= 0; $m--) {
46904693 $days += $mmm[$m];
46914694 if ($m == 1) {
46924695 if ((($year % 4) == 0) && (($year % 100) != 0)) { $days++; }
@@ -4710,16 +4713,16 @@
47114714 sub DateFrom1800 {
47124715 my $days = shift;
47134716
4714 - @mmm = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
 4717+ my @mmm = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
47154718
4716 - $year = 1800;
 4719+ my $year = 1800;
47174720 while ($days > 365 + (($year % 4) == 0)) {
47184721 if ((($year % 4) == 0) && (($year % 100) != 0)) { $days -= 366; }
47194722 else { $days -= 365; }
47204723 $year++;
47214724 }
47224725
4723 - $month = 0;
 4726+ my $month = 0;
47244727 while ($days > $mmm[$month]) {
47254728 $days -= $mmm[$month];
47264729 if ($month == 1) {
@@ -4727,9 +4730,10 @@
47284731 }
47294732 $month++;
47304733 }
4731 - $day = $days;
 4734+ my $day = $days;
47324735
47334736 $month++;
 4737+ my $date;
47344738 if ($DateFormat eq "dd/mm/yyyy") {
47354739 $date = sprintf("%02d/%02d/%04d", $day, $month, $year);
47364740 }
@@ -4739,6 +4743,7 @@
47404744 }
47414745
47424746 sub ExtractText {
 4747+
47434748 # my $data = shift;
47444749 my $data2 = shift;
47454750 my $text = "";
@@ -4794,7 +4799,7 @@
47954800
47964801 sub BarDefined {
47974802 my $bar = shift;
4798 - foreach $bar2 (@Bars) {
 4803+ foreach my $bar2 (@Bars) {
47994804 if (lc($bar2) eq lc($bar)) { return ($true); }
48004805 }
48014806
@@ -4914,27 +4919,32 @@
49154920 my @Required = split(",", shift);
49164921 my @Allowed = split(",", shift);
49174922
4918 - my $attribute;
49194923 my %Attributes2 = %Attributes;
49204924
4921 - $hint = "\nSyntax: '$name =";
4922 - foreach $attribute (@Required) { $hint .= " $attribute:.."; }
4923 - foreach $attribute (@Allowed) { $hint .= " [$attribute:..]"; }
 4925+ my $hint = "\nSyntax: '$name =";
 4926+ foreach my $required_attribute (@Required) {
 4927+ $hint .= " $required_attribute:..";
 4928+ }
 4929+ foreach my $allowed_attribute (@Allowed) {
 4930+ $hint .= " [$allowed_attribute:..]";
 4931+ }
49244932 $hint .= "'";
49254933
4926 - foreach $attribute (@Required) {
4927 - if ( (!defined($Attributes{$attribute}))
4928 - || ($Attributes{$attribute} eq ""))
 4934+ foreach my $required_attribute (@Required) {
 4935+ if ( (!defined($Attributes{$required_attribute}))
 4936+ || ($Attributes{$required_attribute} eq ""))
49294937 {
49304938 &Error("$name definition incomplete. $hint");
49314939 undef(@Attributes);
49324940 return ($false);
49334941 }
4934 - delete($Attributes2{$attribute});
 4942+ delete($Attributes2{$required_attribute});
49354943 }
4936 - foreach $attribute (@Allowed) { delete($Attributes2{$attribute}); }
 4944+ foreach my $allowed_attribute (@Allowed) {
 4945+ delete($Attributes2{$allowed_attribute});
 4946+ }
49374947
4938 - @AttrKeys = keys %Attributes2;
 4948+ my @AttrKeys = keys %Attributes2;
49394949 if ($#AttrKeys >= 0) {
49404950 if ($AttrKeys[0] eq "single") {
49414951 &Error(
@@ -4955,10 +4965,11 @@
49564966
49574967 sub CheckPreset {
49584968 my $command = shift;
4959 - my ($preset, $action, $attrname, $attrvalue);
 4969+ my ($action, $attrname, $attrvalue);
49604970
49614971 my $newcommand = $true;
49624972 my $addvalue = $true;
 4973+ my $prevcommand;
49634974 if ($command =~ /^$prevcommand$/i) { $newcommand = $false; }
49644975 if ((!$newcommand) && ($command =~ /^(?:DrawLines|PlotData|TextData)$/i))
49654976 {
@@ -4966,8 +4977,9 @@
49674978 }
49684979 $prevcommand = $command;
49694980
4970 - foreach $preset (@PresetList) {
 4981+ foreach my $preset (@PresetList) {
49714982 if ($preset =~ /^$command\|/i) {
 4983+ my $attrpreset;
49724984 ($command, $action, $attrname, $attrpreset) =
49734985 split('\|', $preset);
49744986 if ($attrname eq "") { $attrname = "single"; }
@@ -5066,7 +5078,7 @@
50675079
50685080 my @Show = split("\n", $show);
50695081 $text = "";
5070 - foreach $part (@Show) {
 5082+ foreach my $part (@Show) {
50715083 if ($brdouble) { $part = "[[" . $hide . "|" . $part . "]]"; }
50725084 else { $part = "[" . $hide . "|" . $part . "]"; }
50735085 }
@@ -5122,40 +5134,6 @@
51235135 $text =~ s/\[+ ([^\]]+) \]+/$1/gx;
51245136 $text =~ s/\{\{\{ ([^\}]*) \}\}\}/[[$1]]/x;
51255137 }
5126 -
5127 - # if ($text =~ /\[\[.+\]\]/)
5128 - # {
5129 - # $wikilink = $true ;
5130 - # $link = $text ;
5131 - # $link =~ s/\n//g ;
5132 - # $link =~ s/^.*?\[\[/[[/x ;
5133 - # $link =~ s/\| .*? \]\].*$/]]/x ;
5134 - # $link =~ s/\]\].*$/]]/x ;
5135 - # $text =~ s/\[\[ [^\|\]]+ \| (.*?) \]\]/[[$1]]/x ;
5136 - # $text =~ s/\[\[ [^\:\]]+ \: (.*?) \]\]/[[$1]]/x ;
5137 -
5138 - # # remove remaining links
5139 - # $text =~ s/\[\[ ([^\]]+) \]\]/^%#$1#%^/x ;
5140 - # $text =~ s/\[+ ([^\]]+) \]+/$1/gx ;
5141 - # $text =~ s/\^$hPerc\# (.*?) \#$hPerc\^/[[$1]]/x ;
5142 - # }
5143 - # elsif ($text =~ /\[.+\]/)
5144 - # {
5145 - # $link = $text ;
5146 - # $link =~ s/\n//g ;
5147 - # $link =~ s/^.*?\[/[/x ;
5148 - # $link =~ s/\| .*? \].*$/]/x ;
5149 - # $link =~ s/\].*$/]/x ;
5150 - # $link =~ s/\[ ([^\]]+) \]/$1/x ;
5151 - # $text =~ s/\[ [^\|\]]+ \| (.*?) \]/[[$1]]/x ;
5152 -
5153 - # # remove remaining links
5154 - # $text =~ s/\[\[ ([^\]]+) \]\]/^%#$1#%^/x ;
5155 - # $text =~ s/\[+ ([^\]]+) \]+/$1/gx ;
5156 - # $text =~ s/\^$hPerc\# (.*?) \#$hPerc\^/[[$1]]/x ;
5157 -## $text =~ s/\[\[ (.*) \]\]/$1/gx ;
5158 - # }
5159 -
51605138 }
51615139
51625140 if ($wikilink) {
@@ -5176,14 +5154,12 @@
51775155 $link = &EncodeURL($title);
51785156 if (($hint eq "") && ($title ne "")) { $hint = "$wiki: $title"; }
51795157 }
5180 - else {
5181 -
5182 - # $wiki = "en" ;
 5158+ else { # $wiki = "en" ;
51835159 $title = $link;
51845160 $title =~ s/^\[\[(.*)\]\]$/$1/x;
51855161 $title =~ s/ /_/g;
5186 - $link = $articlepath;
5187 - $urlpart = &EncodeURL($title);
 5162+ $link = $articlepath;
 5163+ my $urlpart = &EncodeURL($title);
51885164 $link =~ s/\$1/$urlpart/;
51895165 if (($hint eq "") && ($title ne "")) { $hint = "$title"; }
51905166 }
@@ -5303,12 +5279,13 @@
53045280 "<p>EasyTimeline $VERSION</p><p><b>Timeline generation failed: "
53055281 . &EncodeHtml($msg)
53065282 . "</b></p>\n";
5307 - foreach $line (@Errors) { print FILE_OUT &EncodeHtml($line) . "\n"; }
 5283+ foreach my $line (@Errors) {
 5284+ print FILE_OUT &EncodeHtml($line) . "\n";
 5285+ }
53085286 close "FILE_OUT";
53095287
5310 - if ($makehtml
5311 - ) # generate html test file, which would normally contain png + svg (+ image map)
5312 - {
 5288+ # generate html test file, which would normally contain png + svg (+ image map)
 5289+ if ($makehtml) {
53135290 open "FILE_IN", "<", $file_errors;
53145291 open "FILE_OUT", ">", $file_html;
53155292 print FILE_OUT
@@ -5356,13 +5333,13 @@
53575334 elsif ($ord >= 240) { $value = $ord - 240; }
53585335 elsif ($ord >= 224) { $value = $ord - 224; }
53595336 else { $value = $ord - 192; }
5360 - for ($c = 1; $c < length($unicode); $c++) {
 5337+ for (my $c = 1; $c < length($unicode); $c++) {
53615338 $value = $value * 64 + ord(substr($unicode, $c, 1)) - 128;
53625339 }
53635340
53645341 # $html = "\&\#" . $value . ";" ; any unicode can be specified as html char
53655342
5366 - if (($value >= 128) && ($value <= 255)) {
 5343+ if (($value >= 128) && ($value <= 255)) {
53675344 return (chr($value));
53685345 }
53695346 else {

Comments

#Comment by Raindrift (talk | contribs)   19:56, 26 January 2012

Looks good. Since this runs external commands, please be extra careful to make sure you test in taint mode (perl -T).

Status & tagging log