Mercurial > hg > lukkari
comparison parsedata.pl @ 174:eaac0a84a7d2
Cosmetics.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 24 Aug 2015 16:05:10 +0300 |
parents | 34ce8339b956 |
children | 9c3100ab29cc |
comparison
equal
deleted
inserted
replaced
173:d98aaa540459 | 174:eaac0a84a7d2 |
---|---|
326 } | 326 } |
327 return undef; | 327 return undef; |
328 } | 328 } |
329 | 329 |
330 | 330 |
331 sub getDataStruct($$); | 331 sub get_hour_data_struct($$); |
332 | 332 |
333 sub getDataStruct($$) | 333 sub get_hour_data_struct($$) |
334 { | 334 { |
335 my @out = (); | 335 my @out = (); |
336 my ($tmp, $first) = @_; | 336 my ($tmp, $first) = @_; |
337 | 337 |
338 if (ref($tmp) eq "ARRAY") | 338 if (ref($tmp) eq "ARRAY") |
339 { | 339 { |
340 my @str = (); | 340 my @str = (); |
341 foreach my $item (@{$tmp}) | 341 foreach my $item (@{$tmp}) |
342 { | 342 { |
343 push(@str, getDataStruct($item, 0)); | 343 push(@str, get_hour_data_struct($item, 0)); |
344 } | 344 } |
345 if (scalar(@str) > 0) | 345 if (scalar(@str) > 0) |
346 { | 346 { |
347 push(@out, "array(".join(", ", @str).")") if ($opt_mode eq "php"); | 347 push(@out, "array(".join(", ", @str).")") if ($opt_mode eq "php"); |
348 push(@out, "<group>".join("", @str)."</group>") if ($opt_mode eq "xml"); | 348 push(@out, "<group>".join("", @str)."</group>") if ($opt_mode eq "xml"); |
351 elsif (ref($tmp) eq "HASH") | 351 elsif (ref($tmp) eq "HASH") |
352 { | 352 { |
353 my @str = (); | 353 my @str = (); |
354 foreach my $key (keys %{$tmp}) | 354 foreach my $key (keys %{$tmp}) |
355 { | 355 { |
356 push(@out, "\"".$key."\" => ".getDataStruct($$tmp{$key}, 1)) if ($opt_mode eq "php"); | 356 push(@out, "\"".$key."\" => ".get_hour_data_struct($$tmp{$key}, 1)) if ($opt_mode eq "php"); |
357 push(@out, "<".$key.">".getDataStruct($$tmp{$key}, 1)."</".$key.">") if ($opt_mode eq "xml"); | 357 push(@out, "<".$key.">".get_hour_data_struct($$tmp{$key}, 1)."</".$key.">") if ($opt_mode eq "xml"); |
358 } | 358 } |
359 if (scalar(@str) > 0) | 359 if (scalar(@str) > 0) |
360 { | 360 { |
361 push(@out, "array(".join(", ", @str).")") if ($opt_mode eq "php"); | 361 push(@out, "array(".join(", ", @str).")") if ($opt_mode eq "php"); |
362 push(@out, join("", @str)) if ($opt_mode eq "xml"); | 362 push(@out, join("", @str)) if ($opt_mode eq "xml"); |
525 } | 525 } |
526 | 526 |
527 binmode STDOUT, ':encoding(utf-8)'; | 527 binmode STDOUT, ':encoding(utf-8)'; |
528 | 528 |
529 ### Output data in desired format | 529 ### Output data in desired format |
530 if ($opt_mode eq "php") { | 530 if ($opt_mode eq "php") |
531 { | |
531 print "<?\n". | 532 print "<?\n". |
532 "\$classInfo = array(\n". | 533 "\$classInfo = array(\n". |
533 " \"general\" => array(".join(", ", map { "\"".escape($_)."\""; } @{$class{"info"}})."),\n". | 534 " \"general\" => array(".join(", ", map { "\"".escape($_)."\""; } @{$class{"info"}})."),\n". |
534 " \"info\" => array(".join(", ", map { "\"".escape(html_collapse($_, 1))."\""; } @{$class{"data"}})."),\n". | 535 " \"info\" => array(".join(", ", map { "\"".escape(html_collapse($_, 1))."\""; } @{$class{"data"}})."),\n". |
535 " \"tags\" => array(".join(", ", map { "\"".escape(html_collapse($_, 0))."\""; } @{$class{"data"}})."),\n". | 536 " \"tags\" => array(".join(", ", map { "\"".escape(html_collapse($_, 0))."\""; } @{$class{"data"}})."),\n". |
538 " \"lastHour\" => $lastHour,\n". | 539 " \"lastHour\" => $lastHour,\n". |
539 " \"totalHours\" => $totalHours\n". | 540 " \"totalHours\" => $totalHours\n". |
540 ");\n\n"; | 541 ");\n\n"; |
541 | 542 |
542 print "\$classHourTimes = array(\n"; | 543 print "\$classHourTimes = array(\n"; |
543 foreach my $chour (@$hourTimes) { | 544 foreach my $chour (@$hourTimes) |
545 { | |
544 print " array(\"start\" => ".$$chour{"start"}.", \"end\" => ".$$chour{"end"}."),\n"; | 546 print " array(\"start\" => ".$$chour{"start"}.", \"end\" => ".$$chour{"end"}."),\n"; |
545 } | 547 } |
546 print ");\n\n"; | 548 print ");\n\n"; |
547 | 549 |
548 print "\$classHourDefs = array(\n"; | 550 print "\$classHourDefs = array(\n"; |
549 foreach my $cid (sort { $a <=> $b } keys %{$hourDefs}) { | 551 foreach my $cid (sort { $a <=> $b } keys %{$hourDefs}) |
550 print " $cid => array(".getDataStruct($$hourDefs{$cid}, 0)."),\n"; | 552 { |
553 print " $cid => array(".get_hour_data_struct($$hourDefs{$cid}, 0)."),\n"; | |
551 } | 554 } |
552 print ");\n\n"; | 555 print ");\n\n"; |
553 | 556 |
554 print | 557 print |
555 "\$classDayTable = array(\n"; | 558 "\$classDayTable = array(\n"; |
561 } | 564 } |
562 } | 565 } |
563 print ");\n?>\n"; | 566 print ");\n?>\n"; |
564 } | 567 } |
565 | 568 |
566 elsif ($opt_mode eq "xml") { | 569 elsif ($opt_mode eq "xml") |
570 { | |
567 print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n". | 571 print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n". |
568 "<timetable>\n". | 572 "<timetable>\n". |
569 " <class>\n". | 573 " <class>\n". |
570 " <general>".join("", map { "<item>".$_."</item>"; } @{$class{"info"}})."</general>\n". | 574 " <general>".join("", map { "<item>".$_."</item>"; } @{$class{"info"}})."</general>\n". |
571 " <info>".join("", map { "<item>".html_collapse($_, 1)."</item>"; } @{$class{"data"}})."</info>\n". | 575 " <info>".join("", map { "<item>".html_collapse($_, 1)."</item>"; } @{$class{"data"}})."</info>\n". |
575 " <totalhours>$totalHours</totalhours>\n". | 579 " <totalhours>$totalHours</totalhours>\n". |
576 " </class>\n"; | 580 " </class>\n"; |
577 | 581 |
578 print " <hours>\n"; | 582 print " <hours>\n"; |
579 my $cid = 0; | 583 my $cid = 0; |
580 foreach my $chour (@$hourTimes) { | 584 foreach my $chour (@$hourTimes) |
585 { | |
581 print " <hour id=\"".$cid."\"><start>".$$chour{"start"}."</start><end>".$$chour{"end"}."</end></hour>\n"; | 586 print " <hour id=\"".$cid."\"><start>".$$chour{"start"}."</start><end>".$$chour{"end"}."</end></hour>\n"; |
582 $cid++; | 587 $cid++; |
583 } | 588 } |
584 print " </hours>\n\n"; | 589 print " </hours>\n\n"; |
585 | 590 |
586 print " <classes>\n"; | 591 print " <classes>\n"; |
587 foreach $cid (sort { $a <=> $b } keys %{$hourDefs}) { | 592 foreach $cid (sort { $a <=> $b } keys %{$hourDefs}) |
588 print " <class id=\"$cid\">".getDataStruct($$hourDefs{$cid}, 0)."</class>\n"; | 593 { |
594 print " <class id=\"$cid\">".get_hour_data_struct($$hourDefs{$cid}, 0)."</class>\n"; | |
589 } | 595 } |
590 print " </classes>\n\n"; | 596 print " </classes>\n\n"; |
591 | 597 |
592 print " <days>\n"; | 598 print " <days>\n"; |
593 for (my $y = 0; $y < $maxDays; $y++) | 599 for (my $y = 0; $y < $maxDays; $y++) |