process.pl 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #!/usr/bin/perl
  2. #
  3. # Author:
  4. # Sean MacIsaac
  5. #
  6. use strict;
  7. my $full_expand = 1;
  8. my @template;
  9. my $n;
  10. if ($#ARGV != 2) {
  11. print "process.pl command_file template_file directory_prefix\n";
  12. exit ();
  13. }
  14. my $menu = "";
  15. open COMMANDS, $ARGV[0] || die "Can not open $ARGV[0]";
  16. while (<COMMANDS>) {
  17. chop;
  18. my @command = split /,/;
  19. if ($command[0] != -1) {
  20. $menu .= "\t\t";
  21. $menu .= "<tr><td valign=\"top\" class=\"navi" . $command[0];
  22. $menu .= "\"><a class=\"navi" . $command[0];
  23. $menu .= "\"";
  24. $menu .= " HREF=\"$command[2]\">$command[1]</A></td></tr>\n\n";
  25. }
  26. }
  27. close COMMANDS;
  28. open TEMPLATE, $ARGV[1] || die "Can not open $ARGV[1]";
  29. while (<TEMPLATE>) {
  30. push @template, $_;
  31. }
  32. close TEMPLATE;
  33. open COMMANDS, $ARGV[0] || die "Can not open $ARGV[0]";
  34. while (<COMMANDS>) {
  35. chop;
  36. my @command = split /,/;
  37. if ($command[2] =~ /^http:/){
  38. } else {
  39. $n = $ARGV[2] . "/" . $command[2];
  40. open OUTPUT, ">" . $n || die "Can not create $n";
  41. my $content = "";
  42. open INPUT, "src/$command[3]" || die "Can not open $command[3]";
  43. while (<INPUT>) {
  44. $content .= $_;
  45. }
  46. close INPUT;
  47. my $line;
  48. my $temp;
  49. my $tit;
  50. my $title;
  51. my $css;
  52. my $script;
  53. $tit = $command[1];
  54. $css = $command[4];
  55. $script = $command[5];
  56. foreach $line (@template) {
  57. $temp = $line;
  58. $title = "$tit / Mono";
  59. $temp =~ s/#TITLE#/$title/;
  60. $temp =~ s/#CONTENT#/$content/;
  61. $temp =~ s/#MENU#/$menu/;
  62. if ($css) {
  63. $temp =~ s/#CSS#/<LINK rel="stylesheet" type="text\/css" href="$css">/;
  64. } else {
  65. $temp =~ s/#CSS#//;
  66. }
  67. if ($script) {
  68. $temp =~ s/#SCRIPT#/<SCRIPT src="$script"><\/SCRIPT>/;
  69. } else {
  70. $temp =~ s/#SCRIPT#//;
  71. }
  72. print OUTPUT $temp;
  73. }
  74. }
  75. close OUTPUT;
  76. }