| … | |
… | |
| 695 | $out; |
695 | $out; |
| 696 | } |
696 | } |
| 697 | |
697 | |
| 698 | |
698 | |
| 699 | sub alias { |
699 | sub alias { |
| 700 | # input is a path to the original auxiliary file |
700 | # input is a path to the original auxiliary file |
| 701 | # my $fileName = $main::fileName; |
701 | #my $fileName = $main::fileName; |
| 702 | # my $htmlDirectory = $main::htmlDirectory; |
702 | #my $htmlDirectory = $main::htmlDirectory; |
| 703 | # my $htmlURL = $main::htmlURL; |
703 | #my $htmlURL = $main::htmlURL; |
| 704 | # my $tempDirectory = $main::tempDirectory; |
704 | #my $tempDirectory = $main::tempDirectory; |
| 705 | # my $tempURL = $main::tempURL; |
705 | #my $tempURL = $main::tempURL; |
| 706 | # my $studentLogin = $main::studentLogin; |
706 | #my $studentLogin = $main::studentLogin; |
| 707 | # my $psvnNumber = $main::psvnNumber; |
707 | #my $psvnNumber = $main::psvnNumber; |
| 708 | # my $setNumber = $main::setNumber; |
708 | #my $setNumber = $main::setNumber; |
| 709 | # my $probNum = $main::probNum; |
709 | #my $probNum = $main::probNum; |
| 710 | # my $displayMode = $main::displayMode; |
710 | #my $displayMode = $main::displayMode; |
| 711 | |
711 | |
| 712 | |
712 | |
| 713 | my $aux_file_path = shift @_; |
713 | my $aux_file_path = shift @_; |
| 714 | warn "Empty string used as input into the function alias" unless $aux_file_path; |
714 | warn "Empty string used as input into the function alias" unless $aux_file_path; |
|
|
715 | |
| 715 | # problem specific data |
716 | # problem specific data |
| 716 | warn "The path to the current problem file template is not defined." unless $main::fileName; |
717 | warn "The path to the current problem file template is not defined." unless $main::fileName; |
| 717 | warn "The current studentLogin is not defined " unless $main::studentLogin; |
718 | warn "The current studentLogin is not defined " unless $main::studentLogin; |
| 718 | warn "The current problem set number is not defined" if $main::setNumber eq ""; # allow for sets equal to 0 |
719 | warn "The current problem set number is not defined" if $main::setNumber eq ""; # allow for sets equal to 0 |
| 719 | warn "The current problem number is not defined" if $main::probNum eq ""; |
720 | warn "The current problem number is not defined" if $main::probNum eq ""; |
| 720 | warn "The current problem set version number (psvn) is not defined" unless $main::psvnNumber; |
721 | warn "The current problem set version number (psvn) is not defined" unless $main::psvnNumber; |
| 721 | warn "The displayMode is not defined" unless $main::displayMode; |
722 | warn "The displayMode is not defined" unless $main::displayMode; |
|
|
723 | |
| 722 | # required macros |
724 | # required macros |
| 723 | warn "The macro &surePathToTmpFile can't be found" unless defined(&surePathToTmpFile); |
725 | warn "The macro &surePathToTmpFile can't be found" unless defined(&surePathToTmpFile); |
| 724 | warn "The macro &convertPath can't be found" unless defined(&convertPath); |
726 | warn "The macro &convertPath can't be found" unless defined(&convertPath); |
| 725 | warn "The macro &directoryFromPath can't be found" unless defined(&directoryFromPath); |
727 | warn "The macro &directoryFromPath can't be found" unless defined(&directoryFromPath); |
| 726 | warn "Can't execute the gif2eps script at ${main::externalGif2EpsPath}" unless ( -x "${main::externalGif2EpsPath}" ); |
728 | warn "Can't execute the gif2eps script at ${main::externalGif2EpsPath}" unless ( -x "${main::externalGif2EpsPath}" ); |
| 727 | warn "Can't execute the png2eps script at ${main::externalPng2EpsPath}" unless ( -x "${main::externalPng2EpsPath}" ); |
729 | warn "Can't execute the png2eps script at ${main::externalPng2EpsPath}" unless ( -x "${main::externalPng2EpsPath}" ); |
|
|
730 | |
| 728 | # required directory addresses (and URL address) |
731 | # required directory addresses (and URL address) |
| 729 | warn "htmlDirectory is not defined in $main::htmlDirectory" unless $main::htmlDirectory; |
732 | warn "htmlDirectory is not defined in $main::htmlDirectory" unless $main::htmlDirectory; |
| 730 | warn "htmlURL is not defined in \$main::htmlURL" unless $main::htmlURL; |
733 | warn "htmlURL is not defined in \$main::htmlURL" unless $main::htmlURL; |
| 731 | warn "tempURL is not defined in \$main::tempURL" unless $main::tempURL; |
734 | warn "tempURL is not defined in \$main::tempURL" unless $main::tempURL; |
| 732 | #warn "The scripts directory is not defined in \$main::scriptDirectory" unless $main::scriptDirectory; |
735 | #warn "The scripts directory is not defined in \$main::scriptDirectory" unless $main::scriptDirectory; |
| 733 | # with the creation of externalGif2EpsPath and externalPng2EpsPath, the scripts directory is no longer used |
736 | # with the creation of externalGif2EpsPath and externalPng2EpsPath, the scripts directory is no longer used |
| 734 | |
737 | |
| 735 | # determine extension, if there is one |
738 | # determine extension, if there is one |
| 736 | #if extension exists, strip and use the value for $ext |
739 | # if extension exists, strip and use the value for $ext |
| 737 | # files without extensions are considered to be picture files: |
740 | # files without extensions are considered to be picture files: |
| 738 | |
741 | |
| 739 | my $ext; |
742 | my $ext; |
| 740 | if ($aux_file_path =~ s/\.([^\.]*)$// ) { |
743 | if ($aux_file_path =~ s/\.([^\.]*)$// ) { |
| 741 | $ext = $1; |
744 | $ext = $1; |
| 742 | } else { |
745 | } else { |
| 743 | warn "This file name $aux_file_path did not have an extension.<BR> " . |
746 | warn "This file name $aux_file_path did not have an extension.<BR> " . |
| 744 | "Every file name used as an argument to alias must have an extension.<BR> " . |
747 | "Every file name used as an argument to alias must have an extension.<BR> " . |
| 745 | "The permissable extensions are .gif, .png, and .html .<BR>"; |
748 | "The permissable extensions are .gif, .png, and .html .<BR>"; |
| 746 | $ext = "gif"; |
749 | $ext = "gif"; |
|
|
750 | } |
|
|
751 | |
|
|
752 | # $adr_output is a url in HTML and Latex2HTML modes |
|
|
753 | # and a complete path in TEX mode. |
|
|
754 | my $adr_output; |
|
|
755 | |
|
|
756 | # in order to facilitate maintenance of this macro the routines for handling |
|
|
757 | # different file types are defined separately. This involves some redundancy |
|
|
758 | # in the code but it makes it easier to define special handling for a new file |
|
|
759 | # type, (but harder to change the behavior for all of the file types at once |
|
|
760 | # (sigh) ). |
|
|
761 | |
|
|
762 | |
|
|
763 | if ($ext eq 'html') { |
|
|
764 | ################################################################################ |
|
|
765 | # .html FILES in HTML, HTML_tth, HTML_dpng, HTML_img and Latex2HTML mode |
|
|
766 | ################################################################################ |
| 747 | |
767 | |
| 748 | |
|
|
| 749 | } |
|
|
| 750 | |
|
|
| 751 | # $adr_output is a url in HTML and Latex2HTML modes |
|
|
| 752 | # and a complete path in TEX mode. |
|
|
| 753 | my $adr_output; |
|
|
| 754 | |
|
|
| 755 | # in order to facilitate maintenance of this macro the routines for handling |
|
|
| 756 | # different file types are defined separately. This involves some redundancy |
|
|
| 757 | # in the code but it makes it easier to define special handling for a new file |
|
|
| 758 | # type, (but harder to change the behavior for all of the file types at once |
|
|
| 759 | # (sigh) ). |
|
|
| 760 | ##################################################### |
|
|
| 761 | # .html FILES in HTML, HTML_tth, HTML_dpng, HTML_img and Latex2HTML mode |
|
|
| 762 | ##################################################### |
|
|
| 763 | |
|
|
| 764 | if ($ext eq 'html') { |
|
|
| 765 | # No changes are made for auxiliary files in the |
768 | # No changes are made for auxiliary files in the |
| 766 | # ${Global::htmlDirectory} subtree. |
769 | # ${Global::htmlDirectory} subtree. |
| 767 | if ( $aux_file_path =~ m|^$main::tempDirectory| ) { |
770 | if ( $aux_file_path =~ m|^$main::tempDirectory| ) { |
| 768 | $adr_output = $aux_file_path; |
771 | $adr_output = $aux_file_path; |
| 769 | $adr_output =~ s|$main::tempDirectory|$main::tempURL/|; |
772 | $adr_output =~ s|$main::tempDirectory|$main::tempURL/|; |
| 770 | $adr_output .= ".$ext"; |
773 | $adr_output .= ".$ext"; |
| 771 | } elsif ($aux_file_path =~ m|^$main::htmlDirectory| ) { |
774 | } elsif ($aux_file_path =~ m|^$main::htmlDirectory| ) { |
| 772 | $adr_output = $aux_file_path; |
775 | $adr_output = $aux_file_path; |
| 773 | $adr_output =~ s|$main::htmlDirectory|$main::htmlURL|; |
776 | $adr_output =~ s|$main::htmlDirectory|$main::htmlURL|; |
| 774 | $adr_output .= ".$ext"; |
777 | $adr_output .= ".$ext"; |
| 775 | } else { |
778 | } else { |
| 776 | |
|
|
| 777 | # HTML files not in the htmlDirectory are assumed under live under the |
779 | # HTML files not in the htmlDirectory are assumed under live under the |
| 778 | # templateDirectory in the same directory as the problem. |
780 | # templateDirectory in the same directory as the problem. |
| 779 | # Create an alias file (link) in the directory html/tmp/html which |
781 | # Create an alias file (link) in the directory html/tmp/html which |
| 780 | # points to the original file and return the URL of this alias. |
782 | # points to the original file and return the URL of this alias. |
| 781 | # Create all of the subdirectories of html/tmp/html which are needed |
783 | # Create all of the subdirectories of html/tmp/html which are needed |
| 782 | # using sure file to path. |
784 | # using sure file to path. |
|
|
785 | |
| 783 | # $fileName is obtained from environment for PGeval |
786 | # $fileName is obtained from environment for PGeval |
| 784 | # it gives the full path to the current problem |
787 | # it gives the full path to the current problem |
| 785 | my $filePath = directoryFromPath($main::fileName); |
788 | my $filePath = directoryFromPath($main::fileName); |
| 786 | my $htmlFileSource = convertPath("$main::templateDirectory${filePath}$aux_file_path.html"); |
789 | my $htmlFileSource = convertPath("$main::templateDirectory${filePath}$aux_file_path.html"); |
| 787 | my $link = "html/$main::studentLogin-$main::psvnNumber-set$main::setNumber-prob$main::probNum-$aux_file_path.$ext"; |
790 | my $link = "html/$main::studentLogin-$main::psvnNumber-set$main::setNumber-prob$main::probNum-$aux_file_path.$ext"; |
| 788 | my $linkPath = surePathToTmpFile($link); |
791 | my $linkPath = surePathToTmpFile($link); |
| 789 | $adr_output = "${main::tempURL}$link"; |
792 | $adr_output = "${main::tempURL}$link"; |
| 790 | if (-e $htmlFileSource) { |
793 | if (-e $htmlFileSource) { |
| 791 | if (-e $linkPath) { |
794 | if (-e $linkPath) { |
| 792 | unlink($linkPath) || warn "Unable to unlink alias file at |$linkPath|"; |
795 | unlink($linkPath) || warn "Unable to unlink alias file at |$linkPath|"; |
| 793 | # destroy the old link. |
796 | # destroy the old link. |
| 794 | } |
|
|
| 795 | symlink( $htmlFileSource, $linkPath) || |
|
|
| 796 | warn "The macro alias cannot create a link from |$linkPath| to |$htmlFileSource| <BR>" ; |
|
|
| 797 | } else { |
|
|
| 798 | warn("The macro alias cannot find an HTML file at: |$htmlFileSource|"); |
|
|
| 799 | } |
797 | } |
|
|
798 | symlink( $htmlFileSource, $linkPath) |
|
|
799 | || warn "The macro alias cannot create a link from |$linkPath| to |$htmlFileSource| <BR>" ; |
|
|
800 | } else { |
|
|
801 | warn("The macro alias cannot find an HTML file at: |$htmlFileSource|"); |
|
|
802 | } |
| 800 | } |
803 | } |
| 801 | |
|
|
| 802 | ##################################################### |
|
|
| 803 | # .gif FILES in HTML, HTML_tth, HTML_dpng, HTML_img Latex2HTML and TeX modes |
|
|
| 804 | ##################################################### |
|
|
| 805 | |
|
|
| 806 | } elsif ($ext eq 'gif') { |
804 | } elsif ($ext eq 'gif') { |
| 807 | if ( $main::displayMode eq 'HTML' || |
805 | if ( $main::displayMode eq 'HTML' || |
| 808 | $main::displayMode eq 'HTML_tth'|| |
806 | $main::displayMode eq 'HTML_tth'|| |
| 809 | $main::displayMode eq 'HTML_dpng'|| |
807 | $main::displayMode eq 'HTML_dpng'|| |
| 810 | $main::displayMode eq 'HTML_img'|| |
808 | $main::displayMode eq 'HTML_img'|| |
| 811 | $main::displayMode eq 'Latex2HTML') { |
809 | $main::displayMode eq 'Latex2HTML') { |
|
|
810 | ################################################################################ |
|
|
811 | # .gif FILES in HTML, HTML_tth, HTML_dpng, HTML_img, and Latex2HTML modes |
|
|
812 | ################################################################################ |
|
|
813 | |
| 812 | # warn "tempDirectory is $main::tempDirectory"; |
814 | #warn "tempDirectory is $main::tempDirectory"; |
| 813 | # warn "file Path for auxiliary file is $aux_file_path"; |
815 | #warn "file Path for auxiliary file is $aux_file_path"; |
|
|
816 | |
| 814 | # No changes are made for auxiliary files in the htmlDirectory or in the tempDirectory subtree. |
817 | # No changes are made for auxiliary files in the htmlDirectory or in the tempDirectory subtree. |
| 815 | if ( $aux_file_path =~ m|^$main::tempDirectory| ) { |
818 | if ( $aux_file_path =~ m|^$main::tempDirectory| ) { |
| 816 | $adr_output = $aux_file_path; |
819 | $adr_output = $aux_file_path; |
| 817 | $adr_output =~ s|$main::tempDirectory|$main::tempURL|; |
820 | $adr_output =~ s|$main::tempDirectory|$main::tempURL|; |
| 818 | $adr_output .= ".$ext"; |
821 | $adr_output .= ".$ext"; |
| 819 | # warn "adress out is $adr_output"; |
822 | #warn "adress out is $adr_output"; |
| 820 | } elsif ($aux_file_path =~ m|^$main::htmlDirectory| ) { |
823 | } elsif ($aux_file_path =~ m|^$main::htmlDirectory| ) { |
| 821 | $adr_output = $aux_file_path; |
824 | $adr_output = $aux_file_path; |
| 822 | $adr_output =~ s|$main::htmlDirectory|$main::htmlURL|; |
825 | $adr_output =~ s|$main::htmlDirectory|$main::htmlURL|; |
| 823 | $adr_output .= ".$ext"; |
826 | $adr_output .= ".$ext"; |
| 824 | } else { |
827 | } else { |
| 825 | # files not in the htmlDirectory sub tree are assumed to live under the templateDirectory |
828 | # files not in the htmlDirectory sub tree are assumed to live under the templateDirectory |
| 826 | # subtree in the same directory as the problem. |
829 | # subtree in the same directory as the problem. |
|
|
830 | |
| 827 | # For a gif file the alias macro creates an alias under the html/images directory |
831 | # For a gif file the alias macro creates an alias under the html/images directory |
| 828 | # which points to the gif file in the problem directory. |
832 | # which points to the gif file in the problem directory. |
| 829 | # All of the subdirectories of html/tmp/gif which are needed are also created. |
833 | # All of the subdirectories of html/tmp/gif which are needed are also created. |
| 830 | my $filePath = directoryFromPath($main::fileName); |
834 | my $filePath = directoryFromPath($main::fileName); |
| 831 | |
835 | |
| 832 | # $fileName is obtained from environment for PGeval |
836 | # $fileName is obtained from environment for PGeval |
| 833 | # it gives the full path to the current problem |
837 | # it gives the full path to the current problem |
| 834 | my $gifSourceFile = convertPath("$main::templateDirectory${filePath}$aux_file_path.gif"); |
838 | my $gifSourceFile = convertPath("$main::templateDirectory${filePath}$aux_file_path.gif"); |
| 835 | #my $link = "gif/$main::studentLogin-$main::psvnNumber-set$main::setNumber-prob$main::probNum-$aux_file_path.$ext"; |
839 | #my $link = "gif/$main::studentLogin-$main::psvnNumber-set$main::setNumber-prob$main::probNum-$aux_file_path.$ext"; |
| 836 | my $link = "gif/$main::setNumber-prob$main::probNum-$aux_file_path.$ext"; |
840 | my $link = "gif/$main::setNumber-prob$main::probNum-$aux_file_path.$ext"; |
| 837 | |
841 | |
| 838 | my $linkPath = surePathToTmpFile($link); |
842 | my $linkPath = surePathToTmpFile($link); |
| 839 | $adr_output = "${main::tempURL}$link"; |
843 | $adr_output = "${main::tempURL}$link"; |
| 840 | #warn "linkPath is $linkPath"; |
844 | #warn "linkPath is $linkPath"; |
| 841 | #warn "adr_output is $adr_output"; |
845 | #warn "adr_output is $adr_output"; |
| 842 | if (-e $gifSourceFile) { |
846 | if (-e $gifSourceFile) { |
| 843 | if (-e $linkPath) { |
847 | if (-e $linkPath) { |
| 844 | unlink($linkPath) || warn "Unable to unlink old alias file at $linkPath"; |
848 | unlink($linkPath) || warn "Unable to unlink old alias file at $linkPath"; |
| 845 | } |
849 | } |
| 846 | |
|
|
| 847 | symlink($gifSourceFile, $linkPath) || |
850 | symlink($gifSourceFile, $linkPath) |
| 848 | warn "The macro alias cannot create a link from |$linkPath| to |$gifSourceFile| <BR>" ; |
851 | || warn "The macro alias cannot create a link from |$linkPath| to |$gifSourceFile| <BR>" ; |
| 849 | } else { |
852 | } else { |
| 850 | warn("The macro alias cannot find a GIF file at: |$gifSourceFile|"); |
853 | warn("The macro alias cannot find a GIF file at: |$gifSourceFile|"); |
| 851 | } |
854 | } |
| 852 | } |
855 | } |
| 853 | ##################################################### |
|
|
| 854 | # .gif FILES in TeX mode |
|
|
| 855 | ##################################################### |
|
|
| 856 | |
|
|
| 857 | } elsif ($main::displayMode eq 'TeX') { |
856 | } elsif ($main::displayMode eq 'TeX') { |
| 858 | |
|
|
| 859 | ################################################################################ |
857 | ################################################################################ |
| 860 | #### |
858 | # .gif FILES in TeX mode |
|
|
859 | ################################################################################ |
|
|
860 | |
|
|
861 | if ($envir{texDisposition} eq "pdf") { |
|
|
862 | # We're going to create PDF files with our TeX (using pdflatex), so we |
|
|
863 | # need images in PNG format. |
|
|
864 | |
|
|
865 | my $gifFilePath; |
|
|
866 | |
|
|
867 | if ($aux_file_path =~ m/^$main::htmlDirectory/ or $aux_file_path =~ m/^$main::tempDirectory/) { |
|
|
868 | # we've got a full pathname to a file |
|
|
869 | $gifFilePath = "$aux_file_path.gif"; |
|
|
870 | } else { |
|
|
871 | # we assume the file is in the same directory as the problem source file |
|
|
872 | $gifFilePath = $main::templateDirectory . directoryFromPath($main::fileName) . "$aux_file_path.gif"; |
|
|
873 | } |
|
|
874 | |
|
|
875 | my $gifFileName = fileFromPath($gifFilePath); |
|
|
876 | |
|
|
877 | $gifFileName =~ /^(.*)\.gif$/; |
|
|
878 | my $pngFilePath = surePathToTmpFile("$main::tempDirectory/png/$1.png"); |
|
|
879 | my $returnCode = system "$envir{externalGif2PngPath} $gifFilePath $pngFilePath"; |
|
|
880 | |
|
|
881 | if ($returnCode or not -e $pngFilePath) { |
|
|
882 | die "failed to convert gif->png with $envir{externalGif2PngPath}: $!\n"; |
|
|
883 | } |
|
|
884 | |
|
|
885 | $adr_output = $pngFilePath; |
|
|
886 | } else { |
|
|
887 | # Since we're not creating PDF files, we're probably just using a plain |
|
|
888 | # vanilla latex. Hence, we need EPS images. |
|
|
889 | |
|
|
890 | ################################################################################ |
| 861 | ## This is statement used below is system dependent. |
891 | # This is statement used below is system dependent. |
| 862 | # Notice that the range of colors is restricted when converting to postscript to keep the files small |
892 | # Notice that the range of colors is restricted when converting to postscript to keep the files small |
| 863 | # "cat $gifSourceFile | /usr/math/bin/giftopnm |/usr/math/bin/pnmtops -noturn>$adr_output" |
893 | # "cat $gifSourceFile | /usr/math/bin/giftopnm | /usr/math/bin/pnmtops -noturn > $adr_output" |
| 864 | # "cat $gifSourceFile | /usr/math/bin/giftopnm | /usr/math/bin/pnmdepth 1 | /usr/math/bin/pnmtops -noturn>$adr_output" |
894 | # "cat $gifSourceFile | /usr/math/bin/giftopnm | /usr/math/bin/pnmdepth 1 | /usr/math/bin/pnmtops -noturn > $adr_output" |
| 865 | #### |
|
|
| 866 | ################################################################################ |
895 | ################################################################################ |
| 867 | |
|
|
| 868 | if ($aux_file_path =~ m|^$main::htmlDirectory| or $aux_file_path =~ m|^$main::tempDirectory|) { |
896 | if ($aux_file_path =~ m|^$main::htmlDirectory| or $aux_file_path =~ m|^$main::tempDirectory|) { |
| 869 | |
|
|
| 870 | # To serve an eps file copy an eps version of the gif file to the subdirectory of eps/ |
897 | # To serve an eps file copy an eps version of the gif file to the subdirectory of eps/ |
| 871 | my $linkPath = directoryFromPath($main::fileName); |
898 | my $linkPath = directoryFromPath($main::fileName); |
| 872 | |
899 | |
| 873 | my $gifSourceFile = "$aux_file_path.gif"; |
900 | my $gifSourceFile = "$aux_file_path.gif"; |
| 874 | my $gifFileName = fileFromPath($gifSourceFile); |
901 | my $gifFileName = fileFromPath($gifSourceFile); |
| 875 | $adr_output = surePathToTmpFile("$main::tempDirectory/eps/$main::studentLogin-$main::psvnNumber-$gifFileName.eps") ; |
902 | $adr_output = surePathToTmpFile("$main::tempDirectory/eps/$main::studentLogin-$main::psvnNumber-$gifFileName.eps") ; |
| 876 | |
903 | |
| 877 | if (-e $gifSourceFile) { |
904 | if (-e $gifSourceFile) { |
| 878 | #system("cat $gifSourceFile | /usr/math/bin/giftopnm | /usr/math/bin/pnmdepth 1 | /usr/math/bin/pnmtops -noturn>$adr_output") && |
905 | #system("cat $gifSourceFile | /usr/math/bin/giftopnm | /usr/math/bin/pnmdepth 1 | /usr/math/bin/pnmtops -noturn>$adr_output") |
| 879 | system("${main::externalGif2EpsPath} $gifSourceFile $adr_output" ) && |
906 | system("${main::externalGif2EpsPath} $gifSourceFile $adr_output" ) |
| 880 | die "Unable to create eps file:\n |$adr_output| from file\n |$gifSourceFile|\n in problem $main::probNum " . |
907 | && die "Unable to create eps file:\n |$adr_output| from file\n |$gifSourceFile|\n in problem $main::probNum " . |
| 881 | "using the system dependent script\n |${main::externalGif2EpsPath}| \n"; |
908 | "using the system dependent script\n |${main::externalGif2EpsPath}| \n"; |
| 882 | |
|
|
| 883 | } else { |
909 | } else { |
| 884 | die "|$gifSourceFile| cannot be found. Problem number: |$main::probNum|"; |
910 | die "|$gifSourceFile| cannot be found. Problem number: |$main::probNum|"; |
| 885 | } |
911 | } |
| 886 | |
|
|
| 887 | } else { |
912 | } else { |
| 888 | # To serve an eps file copy an eps version of the gif file to a subdirectory of eps/ |
913 | # To serve an eps file copy an eps version of the gif file to a subdirectory of eps/ |
| 889 | my $filePath = directoryFromPath($main::fileName); |
914 | my $filePath = directoryFromPath($main::fileName); |
| 890 | my $gifSourceFile = "${main::templateDirectory}${filePath}$aux_file_path.gif"; |
915 | my $gifSourceFile = "${main::templateDirectory}${filePath}$aux_file_path.gif"; |
| 891 | #print "content-type: text/plain \n\nfileName = $fileName and aux_file_path =$aux_file_path<BR>"; |
916 | #print "content-type: text/plain \n\nfileName = $fileName and aux_file_path =$aux_file_path<BR>"; |
| 892 | $adr_output = surePathToTmpFile("eps/$main::studentLogin-$main::psvnNumber-set$main::setNumber-prob$main::probNum-$aux_file_path.eps") ; |
917 | $adr_output = surePathToTmpFile("eps/$main::studentLogin-$main::psvnNumber-set$main::setNumber-prob$main::probNum-$aux_file_path.eps"); |
|
|
918 | |
| 893 | if (-e $gifSourceFile) { |
919 | if (-e $gifSourceFile) { |
| 894 | #system("cat $gifSourceFile | /usr/math/bin/giftopnm | /usr/math/bin/pnmdepth 1 | /usr/math/bin/pnmtops -noturn>$adr_output") && |
920 | #system("cat $gifSourceFile | /usr/math/bin/giftopnm | /usr/math/bin/pnmdepth 1 | /usr/math/bin/pnmtops -noturn>$adr_output") && |
| 895 | #warn "Unable to create eps file: |$adr_output|\n from file\n |$gifSourceFile|\n in problem $main::probNum"; |
921 | #warn "Unable to create eps file: |$adr_output|\n from file\n |$gifSourceFile|\n in problem $main::probNum"; |
| 896 | #warn "Help ${main::externalGif2EpsPath}" unless -x "${main::externalGif2EpsPath}"; |
922 | #warn "Help ${main::externalGif2EpsPath}" unless -x "${main::externalGif2EpsPath}"; |
| 897 | system("${main::externalGif2EpsPath} $gifSourceFile $adr_output" ) && |
923 | system("${main::externalGif2EpsPath} $gifSourceFile $adr_output" ) |
| 898 | die "Unable to create eps file:\n |$adr_output| from file\n |$gifSourceFile|\n in problem $main::probNum " . |
924 | && die "Unable to create eps file:\n |$adr_output| from file\n |$gifSourceFile|\n in problem $main::probNum " . |
| 899 | "using the system dependent script\n |${main::externalGif2EpsPath}| \n "; |
925 | "using the system dependent script\n |${main::externalGif2EpsPath}| \n "; |
| 900 | |
|
|
| 901 | |
|
|
| 902 | } else { |
926 | } else { |
| 903 | die "|$gifSourceFile| cannot be found. Problem number: |$main::probNum|"; } |
927 | die "|$gifSourceFile| cannot be found. Problem number: |$main::probNum|"; |
|
|
928 | } |
| 904 | } |
929 | } |
| 905 | |
930 | } |
| 906 | } else { |
931 | } else { |
| 907 | wwerror("Error in alias: dangerousMacros.pl","unrecognizable displayMode = $main::displayMode",""); |
932 | wwerror("Error in alias: dangerousMacros.pl","unrecognizable displayMode = $main::displayMode",""); |
| 908 | } |
933 | } |
| 909 | ##################################################### |
|
|
| 910 | # .png FILES in HTML, HTML_tth, HTML_dpng, HTML_img, Latex2HTML and TeX modes |
|
|
| 911 | ##################################################### |
|
|
| 912 | |
|
|
| 913 | } elsif ($ext eq 'png') { |
934 | } elsif ($ext eq 'png') { |
| 914 | if ( $main::displayMode eq 'HTML' || |
935 | if ( $main::displayMode eq 'HTML' || |
| 915 | $main::displayMode eq 'HTML_tth'|| |
936 | $main::displayMode eq 'HTML_tth'|| |
| 916 | $main::displayMode eq 'HTML_dpng'|| |
937 | $main::displayMode eq 'HTML_dpng'|| |
| 917 | $main::displayMode eq 'HTML_img'|| |
938 | $main::displayMode eq 'HTML_img'|| |
| 918 | $main::displayMode eq 'Latex2HTML') { |
939 | $main::displayMode eq 'Latex2HTML') { |
|
|
940 | ################################################################################ |
|
|
941 | # .png FILES in HTML, HTML_tth, HTML_dpng, HTML_img, and Latex2HTML modes |
|
|
942 | ################################################################################ |
|
|
943 | |
| 919 | # warn "tempDirectory is $main::tempDirectory"; |
944 | #warn "tempDirectory is $main::tempDirectory"; |
| 920 | # warn "file Path for auxiliary file is $aux_file_path"; |
945 | #warn "file Path for auxiliary file is $aux_file_path"; |
|
|
946 | |
| 921 | # No changes are made for auxiliary files in the htmlDirectory or in the tempDirectory subtree. |
947 | # No changes are made for auxiliary files in the htmlDirectory or in the tempDirectory subtree. |
| 922 | if ( $aux_file_path =~ m|^$main::tempDirectory| ) { |
948 | if ( $aux_file_path =~ m|^$main::tempDirectory| ) { |
| 923 | $adr_output = $aux_file_path; |
949 | $adr_output = $aux_file_path; |
| 924 | $adr_output =~ s|$main::tempDirectory|$main::tempURL|; |
950 | $adr_output =~ s|$main::tempDirectory|$main::tempURL|; |
| 925 | $adr_output .= ".$ext"; |
951 | $adr_output .= ".$ext"; |
| 926 | # warn "adress out is $adr_output"; |
952 | #warn "adress out is $adr_output"; |
| 927 | } elsif ($aux_file_path =~ m|^$main::htmlDirectory| ) { |
953 | } elsif ($aux_file_path =~ m|^$main::htmlDirectory| ) { |
| 928 | $adr_output = $aux_file_path; |
954 | $adr_output = $aux_file_path; |
| 929 | $adr_output =~ s|$main::htmlDirectory|$main::htmlURL|; |
955 | $adr_output =~ s|$main::htmlDirectory|$main::htmlURL|; |
| 930 | $adr_output .= ".$ext"; |
956 | $adr_output .= ".$ext"; |
| 931 | } else { |
957 | } else { |
| 932 | # files not in the htmlDirectory sub tree are assumed to live under the templateDirectory |
958 | # files not in the htmlDirectory sub tree are assumed to live under the templateDirectory |
| 933 | # subtree in the same directory as the problem. |
959 | # subtree in the same directory as the problem. |
|
|
960 | |
| 934 | # For a png file the alias macro creates an alias under the html/images directory |
961 | # For a png file the alias macro creates an alias under the html/images directory |
| 935 | # which points to the png file in the problem directory. |
962 | # which points to the png file in the problem directory. |
| 936 | # All of the subdirectories of html/tmp/gif which are needed are also created. |
963 | # All of the subdirectories of html/tmp/gif which are needed are also created. |
| 937 | my $filePath = directoryFromPath($main::fileName); |
964 | my $filePath = directoryFromPath($main::fileName); |
| 938 | |
965 | |
| 939 | # $fileName is obtained from environment for PGeval |
966 | # $fileName is obtained from environment for PGeval |
| 940 | # it gives the full path to the current problem |
967 | # it gives the full path to the current problem |
| 941 | my $pngSourceFile = convertPath("$main::templateDirectory${filePath}$aux_file_path.png"); |
968 | my $pngSourceFile = convertPath("$main::templateDirectory${filePath}$aux_file_path.png"); |
| 942 | my $link = "gif/$main::studentLogin-$main::psvnNumber-set$main::setNumber-prob$main::probNum-$aux_file_path.$ext"; |
969 | my $link = "gif/$main::studentLogin-$main::psvnNumber-set$main::setNumber-prob$main::probNum-$aux_file_path.$ext"; |
| 943 | my $linkPath = surePathToTmpFile($link); |
970 | my $linkPath = surePathToTmpFile($link); |
| 944 | $adr_output = "${main::tempURL}$link"; |
971 | $adr_output = "${main::tempURL}$link"; |
| 945 | #warn "linkPath is $linkPath"; |
972 | #warn "linkPath is $linkPath"; |
| 946 | #warn "adr_output is $adr_output"; |
973 | #warn "adr_output is $adr_output"; |
| 947 | if (-e $pngSourceFile) { |
974 | if (-e $pngSourceFile) { |
| 948 | if (-e $linkPath) { |
975 | if (-e $linkPath) { |
| 949 | unlink($linkPath) || warn "Unable to unlink old alias file at $linkPath"; |
976 | unlink($linkPath) || warn "Unable to unlink old alias file at $linkPath"; |
| 950 | } |
977 | } |
| 951 | |
|
|
| 952 | symlink($pngSourceFile, $linkPath) || |
978 | symlink($pngSourceFile, $linkPath) |
| 953 | warn "The macro alias cannot create a link from |$linkPath| to |$pngSourceFile| <BR>" ; |
979 | || warn "The macro alias cannot create a link from |$linkPath| to |$pngSourceFile| <BR>" ; |
| 954 | } else { |
980 | } else { |
| 955 | warn("The macro alias cannot find a PNG file at: |$pngSourceFile|"); |
981 | warn("The macro alias cannot find a PNG file at: |$pngSourceFile|"); |
| 956 | } |
982 | } |
| 957 | } |
983 | } |
| 958 | ##################################################### |
|
|
| 959 | # .png FILES in TeX mode |
|
|
| 960 | ##################################################### |
|
|
| 961 | |
|
|
| 962 | } elsif ($main::displayMode eq 'TeX') { |
984 | } elsif ($main::displayMode eq 'TeX') { |
| 963 | |
|
|
| 964 | ################################################################################ |
985 | ################################################################################ |
| 965 | #### |
986 | # .png FILES in TeX mode |
|
|
987 | ################################################################################ |
|
|
988 | |
|
|
989 | if ($envir{texDisposition} eq "pdf") { |
|
|
990 | # We're going to create PDF files with our TeX (using pdflatex), so we |
|
|
991 | # need images in PNG format. what luck! they're already in PDF format! |
|
|
992 | |
|
|
993 | my $pngFilePath; |
|
|
994 | |
|
|
995 | if ($aux_file_path =~ m/^$main::htmlDirectory/ or $aux_file_path =~ m/^$main::tempDirectory/) { |
|
|
996 | # we've got a full pathname to a file |
|
|
997 | $pngFilePath = "$aux_file_path.png"; |
|
|
998 | } else { |
|
|
999 | # we assume the file is in the same directory as the problem source file |
|
|
1000 | $pngFilePath = $main::templateDirectory . directoryFromPath($main::fileName) . "$aux_file_path.png"; |
|
|
1001 | } |
|
|
1002 | |
|
|
1003 | $adr_output = $pngFilePath; |
|
|
1004 | } else { |
|
|
1005 | # Since we're not creating PDF files, we're probably just using a plain |
|
|
1006 | # vanilla latex. Hence, we need EPS images. |
|
|
1007 | |
|
|
1008 | ################################################################################ |
| 966 | ## This is statement used below is system dependent. |
1009 | # This is statement used below is system dependent. |
| 967 | # Notice that the range of colors is restricted when converting to postscript to keep the files small |
1010 | # Notice that the range of colors is restricted when converting to postscript to keep the files small |
| 968 | # "cat $pngSourceFile | /usr/math/bin/pngtopnm |/usr/math/bin/pnmtops -noturn>$adr_output" |
1011 | # "cat $pngSourceFile | /usr/math/bin/pngtopnm | /usr/math/bin/pnmtops -noturn > $adr_output" |
| 969 | # "cat $pngSourceFile | /usr/math/bin/pngtopnm | /usr/math/bin/pnmdepth 1 | /usr/math/bin/pnmtops -noturn>$adr_output" |
1012 | # "cat $pngSourceFile | /usr/math/bin/pngtopnm | /usr/math/bin/pnmdepth 1 | /usr/math/bin/pnmtops -noturn > $adr_output" |
| 970 | #### |
|
|
| 971 | ################################################################################ |
1013 | ################################################################################ |
| 972 | |
1014 | |
| 973 | if ($aux_file_path =~ m|^$main::htmlDirectory| or $aux_file_path =~ m|^$main::tempDirectory|) { |
1015 | if ($aux_file_path =~ m|^$main::htmlDirectory| or $aux_file_path =~ m|^$main::tempDirectory|) { |
| 974 | |
|
|
| 975 | # To serve an eps file copy an eps version of the png file to the subdirectory of eps/ |
1016 | # To serve an eps file copy an eps version of the png file to the subdirectory of eps/ |
| 976 | my $linkPath = directoryFromPath($main::fileName); |
1017 | my $linkPath = directoryFromPath($main::fileName); |
| 977 | |
1018 | |
| 978 | my $pngSourceFile = "$aux_file_path.png"; |
1019 | my $pngSourceFile = "$aux_file_path.png"; |
| 979 | my $pngFileName = fileFromPath($pngSourceFile); |
1020 | my $pngFileName = fileFromPath($pngSourceFile); |
| 980 | $adr_output = surePathToTmpFile("$main::tempDirectory/eps/$main::studentLogin-$main::psvnNumber-$pngFileName.eps") ; |
1021 | $adr_output = surePathToTmpFile("$main::tempDirectory/eps/$main::studentLogin-$main::psvnNumber-$pngFileName.eps") ; |
| 981 | |
1022 | |
| 982 | if (-e $pngSourceFile) { |
1023 | if (-e $pngSourceFile) { |
| 983 | #system("cat $pngSourceFile | /usr/math/bin/pngtopnm | /usr/math/bin/pnmdepth 1 | /usr/math/bin/pnmtops -noturn>$adr_output") && |
1024 | #system("cat $pngSourceFile | /usr/math/bin/pngtopnm | /usr/math/bin/pnmdepth 1 | /usr/math/bin/pnmtops -noturn>$adr_output") |
| 984 | system("${main::externalPng2EpsPath} $pngSourceFile $adr_output" ) && |
1025 | system("${main::externalPng2EpsPath} $pngSourceFile $adr_output" ) |
| 985 | die "Unable to create eps file:\n |$adr_output| from file\n |$pngSourceFile|\n in problem $main::probNum " . |
1026 | && die "Unable to create eps file:\n |$adr_output| from file\n |$pngSourceFile|\n in problem $main::probNum " . |
| 986 | "using the system dependent script\n |${main::externalPng2EpsPath}| \n"; |
1027 | "using the system dependent script\n |${main::externalPng2EpsPath}| \n"; |
| 987 | |
|
|
| 988 | } else { |
1028 | } else { |
| 989 | die "|$pngSourceFile| cannot be found. Problem number: |$main::probNum|"; |
1029 | die "|$pngSourceFile| cannot be found. Problem number: |$main::probNum|"; |
| 990 | } |
1030 | } |
| 991 | |
|
|
| 992 | } else { |
1031 | } else { |
| 993 | # To serve an eps file copy an eps version of the png file to a subdirectory of eps/ |
1032 | # To serve an eps file copy an eps version of the png file to a subdirectory of eps/ |
| 994 | my $filePath = directoryFromPath($main::fileName); |
1033 | my $filePath = directoryFromPath($main::fileName); |
| 995 | my $pngSourceFile = "${main::templateDirectory}${filePath}$aux_file_path.png"; |
1034 | my $pngSourceFile = "${main::templateDirectory}${filePath}$aux_file_path.png"; |
| 996 | #print "content-type: text/plain \n\nfileName = $fileName and aux_file_path =$aux_file_path<BR>"; |
1035 | #print "content-type: text/plain \n\nfileName = $fileName and aux_file_path =$aux_file_path<BR>"; |
| 997 | $adr_output = surePathToTmpFile("eps/$main::studentLogin-$main::psvnNumber-set$main::setNumber-prob$main::probNum-$aux_file_path.eps") ; |
1036 | $adr_output = surePathToTmpFile("eps/$main::studentLogin-$main::psvnNumber-set$main::setNumber-prob$main::probNum-$aux_file_path.eps") ; |
| 998 | if (-e $pngSourceFile) { |
1037 | if (-e $pngSourceFile) { |
| 999 | #system("cat $pngSourceFile | /usr/math/bin/pngtopnm | /usr/math/bin/pnmdepth 1 | /usr/math/bin/pnmtops -noturn>$adr_output") && |
1038 | #system("cat $pngSourceFile | /usr/math/bin/pngtopnm | /usr/math/bin/pnmdepth 1 | /usr/math/bin/pnmtops -noturn>$adr_output") && |
| 1000 | #warn "Unable to create eps file: |$adr_output|\n from file\n |$pngSourceFile|\n in problem $main::probNum"; |
1039 | #warn "Unable to create eps file: |$adr_output|\n from file\n |$pngSourceFile|\n in problem $main::probNum"; |
| 1001 | #warn "Help ${main::externalPng2EpsPath}" unless -x "${main::externalPng2EpsPath}"; |
1040 | #warn "Help ${main::externalPng2EpsPath}" unless -x "${main::externalPng2EpsPath}"; |
| 1002 | system("${main::externalPng2EpsPath} $pngSourceFile $adr_output" ) && |
1041 | system("${main::externalPng2EpsPath} $pngSourceFile $adr_output" ) |
| 1003 | die "Unable to create eps file:\n |$adr_output| from file\n |$pngSourceFile|\n in problem $main::probNum " . |
1042 | && die "Unable to create eps file:\n |$adr_output| from file\n |$pngSourceFile|\n in problem $main::probNum " . |
| 1004 | "using the system dependent script\n |${main::externalPng2EpsPath}| \n "; |
1043 | "using the system dependent script\n |${main::externalPng2EpsPath}| \n "; |
| 1005 | |
|
|
| 1006 | |
|
|
| 1007 | } else { |
1044 | } else { |
| 1008 | die "|$pngSourceFile| cannot be found. Problem number: |$main::probNum|"; } |
1045 | die "|$pngSourceFile| cannot be found. Problem number: |$main::probNum|"; |
|
|
1046 | } |
| 1009 | } |
1047 | } |
| 1010 | |
1048 | } |
| 1011 | } else { |
1049 | } else { |
| 1012 | wwerror("Error in alias: dangerousMacros.pl","unrecognizable displayMode = $main::displayMode",""); |
1050 | wwerror("Error in alias: dangerousMacros.pl","unrecognizable displayMode = $main::displayMode",""); |
| 1013 | } |
1051 | } |
| 1014 | ##################################################### |
|
|
| 1015 | # FILES with unrecognized file extensions in all display modes |
|
|
| 1016 | ##################################################### |
|
|
| 1017 | |
|
|
| 1018 | } else { # $ext is not recognized |
1052 | } else { # $ext is not recognized |
| 1019 | warn "Error in the macro alias. Alias does not understand how to process |
1053 | ################################################################################ |
| 1020 | files with extension $ext. (Path ot problem file is $main::fileName) "; |
1054 | # FILES with unrecognized file extensions in any display modes |
|
|
1055 | ################################################################################ |
| 1021 | |
1056 | |
|
|
1057 | warn "Error in the macro alias. Alias does not understand how to process files with extension $ext. (Path ot problem file is $main::fileName) "; |
| 1022 | } |
1058 | } |
|
|
1059 | |
| 1023 | warn "The macro alias was unable to form a URL for some auxiliary file used in this problem." unless $adr_output; |
1060 | warn "The macro alias was unable to form a URL for some auxiliary file used in this problem." unless $adr_output; |
| 1024 | $adr_output; |
1061 | return $adr_output; |
| 1025 | ; |
|
|
| 1026 | |
|
|
| 1027 | } |
1062 | } |
| 1028 | |
1063 | |
| 1029 | |
1064 | |
| 1030 | |
1065 | |
| 1031 | |
1066 | |