[system] / trunk / pg / macros / dangerousMacros.pl Repository:
ViewVC logotype

Diff of /trunk/pg/macros/dangerousMacros.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1250 Revision 1267
97 97
98} 98}
99 99
100my $debugON = 0; 100my $debugON = 0;
101 101
102sub _dangerousMacros_init { 102# grab read only variables from the current safe compartment
103
104my ($macroDirectory,
105 $courseScriptsDirectory,
106 $templateDirectory,
107 $scriptDirectory,
108 $externalTTHPath,
109 );
110
111sub _dangerousMacros_init { #FIXME use local envir instead of local variables?
112 $macroDirectory = eval('$main::macroDirectory') ;
113 $courseScriptsDirectory = eval('$main::courseScriptsDirectory');
114 $templateDirectory = eval('$main::templateDirectory');
115 $scriptDirectory = eval('$main::scriptDirectory');
116 $externalTTHPath = eval('$envir{externalTTHPath}');
117 warn "dangerousmacros initialized" if $debugON;
118 warn eval(q! "dangerousmacros.pl externalTTHPath is ".$main::externalTTHPath;!) if $debugON;
119 warn eval(q! "dangerousmacros.pl: The envir variable $main::{envir} is".join(" ",%main::envir)!) if $debugON;
103} 120}
104 121
105sub _dangerousMacros_export { 122sub _dangerousMacros_export {
106 my @EXPORT= ( 123 my @EXPORT= (
107 '&_dangerousMacros_init', 124 '&_dangerousMacros_init',
165# The only difficulty with defining loadMacros inside the Safe compartment is that 182# The only difficulty with defining loadMacros inside the Safe compartment is that
166# the error reporting does not work with syntax errors. 183# the error reporting does not work with syntax errors.
167# A kludge using require works around this problem 184# A kludge using require works around this problem
168 185
169 186
170my ($macroDirectory,
171 $courseScriptsDirectory,
172 $templateDirectory,
173 $scriptDirectory,
174 );
175 187
176sub loadMacros { 188sub loadMacros {
177 my @files = @_; 189 my @files = @_;
178 my $fileName; 190 my $fileName;
179 eval {main::time_it("begin load macros");}; 191 eval {main::time_it("begin load macros");};
180 ############################################################################### 192 ###############################################################################
181 # At this point the directories have been defined from %envir and we can define 193 # At this point the directories have been defined from %envir and we can define
182 # the directories for this file 194 # the directories for this file
183 ############################################################################### 195 ###############################################################################
184 196
185 $macroDirectory = eval('$main::macroDirectory') unless defined($macroDirectory); 197 # special case inits
186 $courseScriptsDirectory = eval('$main::courseScriptsDirectory') unless defined($courseScriptsDirectory); 198 foreach my $file ('PG.pl','dangerousMacros.pl','IO.pl') {
187 $templateDirectory = eval('$main::courseScriptsDirectory') unless defined($templateDirectory); 199 my $macro_file_name = $file;
188 $scriptDirectory = eval('$main::scriptDirectory') unless defined($scriptDirectory); 200 $macro_file_name =~s/\.pl//; # trim off the extension
189 201 $macro_file_name =~s/\.pg//; # sometimes the extension is .pg (e.g. CAPA files)
190 unless (defined( eval('$main::externalTTHPath') and eval('$main::externalTTHPath') )){ 202 my $init_subroutine_name = "_${macro_file_name}_init";
203 my $init_subroutine = eval { \&{$init_subroutine_name} };
204 use strict;
205 my $macro_file_loaded = defined($init_subroutine);
206 warn "dangerousMacros: macro init $init_subroutine_name defined |$init_subroutine| |$macro_file_loaded|" if $debugON;
207 if ( defined( &{$init_subroutine} ) ) {
208
209 warn "dangerousMacros: initializing $macro_file_name" if $debugON;
210 &$init_subroutine();
211 }
212 }
213 unless (defined( $externalTTHPath)){
191 warn "WARNING::Please make sure that the DOCUMENT() statement comes before<BR>\n" . 214 warn "WARNING::Please make sure that the DOCUMENT() statement comes before<BR>\n" .
192 " the loadMacros() statement in the problem template.<p>" . 215 " the loadMacros() statement in the problem template.<p>" .
193 " The externalTTHPath variable |$main::externalTTHPath| was\n". 216 " The externalTTHPath variable |$externalTTHPath| was\n".
194 " not defined which usually indicates the problem above.<br>\n"; 217 " not defined which usually indicates the problem above.<br>\n";
195 218
196 } 219 }
197 #warn "running load macros"; 220 #warn "running load macros";
198 while (@files) { 221 while (@files) {
249 warn "init file defined: $macro_file_name = ", defined(&{$init_subroutine}) if $debugON; 272 warn "init file defined: $macro_file_name = ", defined(&{$init_subroutine}) if $debugON;
250 273
251 if ( defined( &{$init_subroutine} ) ) { 274 if ( defined( &{$init_subroutine} ) ) {
252 275
253 warn "dangerousMacros: initializing $macro_file_name" if $debugON; 276 warn "dangerousMacros: initializing $macro_file_name" if $debugON;
254 &$init_subroutine($main::displayMode); 277 &$init_subroutine();
255 } 278 }
256 #warn "main:: contains <br>\n $macro_file_name ".join("<br>\n $macro_file_name ", %main::); 279 #warn "main:: contains <br>\n $macro_file_name ".join("<br>\n $macro_file_name ", %main::);
257 280
258 } 281 }
259 eval{main::time_it("end load macros");}; 282 eval{main::time_it("end load macros");};
386sub tth { 409sub tth {
387 my $inputString = shift; 410 my $inputString = shift;
388 411
389 # read the contents of the tthPreamble.tex file, unless it has already been read 412 # read the contents of the tthPreamble.tex file, unless it has already been read
390 unless ( defined( $tthPreambleContents) ) { 413 unless ( defined( $tthPreambleContents) ) {
391 $tthPreambleFile = "${main::templateDirectory}tthPreamble.tex" if ( -r "${main::templateDirectory}tthPreamble.tex" ); 414 $tthPreambleFile = "${templateDirectory}tthPreamble.tex" if ( -r "${templateDirectory}tthPreamble.tex" );
392 if ( defined($tthPreambleFile) ) { 415 if ( defined($tthPreambleFile) ) {
393 local(*TTHIN); 416 local(*TTHIN);
394 open (TTHIN, "${main::templateDirectory}tthPreamble.tex") || die "Can't open file ${main::templateDirectory}tthPreamble.tex"; 417 open (TTHIN, "${templateDirectory}tthPreamble.tex") || die "Can't open file ${templateDirectory}tthPreamble.tex";
395 #my @tthPreambleArray = <TTHIN>; 418 #my @tthPreambleArray = <TTHIN>;
396 local($/); 419 local($/);
397 $/ = undef; 420 $/ = undef;
398 $tthPreambleContents = <TTHIN>;#join("",@tthPreambleArray); 421 $tthPreambleContents = <TTHIN>;#join("",@tthPreambleArray);
399 close(TTHIN); 422 close(TTHIN);
746 769
747# local constants $User, $psvn $setNumber $probNum $displayMode 770# local constants $User, $psvn $setNumber $probNum $displayMode
748 771
749sub sourceAlias { 772sub sourceAlias {
750 my $path_to_file = shift; 773 my $path_to_file = shift;
774 my $envir = PG_restricted_eval(q!$main::envir!);
751 my $user = $main::inputs_ref->{user}; 775 my $user = $envir->{inputs_ref}->{user};
752 $user = " " unless defined($user); 776 $user = " " unless defined($user);
753 my $out = "source.pl?probSetKey=$main::psvn". 777 my $out = 'source.pl?probSetKey=' . $envir->{psvn}.
754 "&amp;probNum=$main::probNum" . 778 '&amp;probNum=' . $envir->{probNum} .
755 "&amp;Mode=$main::displayMode" . 779 '&amp;Mode=' . $envir->{displayMode} .
756 "&amp;course=". $main::courseName . 780 '&amp;course=' . $envir->{courseName} .
757 "&amp;user=" . $user . 781 '&amp;user=' . $user .
758 "&amp;displayPath=$path_to_file" . 782 '&amp;displayPath=' . $path_to_file .
759 "&amp;key=". $main::sessionKey; 783 '&amp;key=' . $envir->{sessionKey};
760 784
761 $out; 785 $out;
762} 786}
763 787
764 788
765sub alias { 789sub alias {
766 # input is a path to the original auxiliary file 790 # input is a path to the original auxiliary file
767 #my $fileName = $main::fileName; 791 my $envir = eval(q!\%main::envir!); # get the current root environment
792 my $fileName = $envir->{fileName};
768 #my $htmlDirectory = $main::htmlDirectory; 793 my $htmlDirectory = $envir->{htmlDirectory};
769 #my $htmlURL = $main::htmlURL; 794 my $htmlURL = $envir->{htmlURL};
770 #my $tempDirectory = $main::tempDirectory; 795 my $tempDirectory = $envir->{tempDirectory};
771 #my $tempURL = $main::tempURL; 796 my $tempURL = $envir->{tempURL};
772 #my $studentLogin = $main::studentLogin; 797 my $studentLogin = $envir->{studentLogin};
773 #my $psvnNumber = $main::psvnNumber; 798 my $psvnNumber = $envir->{psvnNumber};
774 #my $setNumber = $main::setNumber; 799 my $setNumber = $envir->{setNumber};
775 #my $probNum = $main::probNum; 800 my $probNum = $envir->{probNum};
776 #my $displayMode = $main::displayMode; 801 my $displayMode = $envir->{displayMode};
777 802 my $externalGif2EpsPath = $envir->{externalGif2EpsPath};
803 my $externalPng2EpsPath = $envir->{externalPng2EpsPath};
778 804
779 my $aux_file_path = shift @_; 805 my $aux_file_path = shift @_;
780 warn "Empty string used as input into the function alias" unless $aux_file_path; 806 warn "Empty string used as input into the function alias" unless $aux_file_path;
781 807
782 # problem specific data 808 # problem specific data
783 warn "The path to the current problem file template is not defined." unless $main::fileName; 809 warn "The path to the current problem file template is not defined." unless $fileName;
784 warn "The current studentLogin is not defined " unless $main::studentLogin; 810 warn "The current studentLogin is not defined " unless $studentLogin;
785 warn "The current problem set number is not defined" if $main::setNumber eq ""; # allow for sets equal to 0 811 warn "The current problem set number is not defined" if $setNumber eq ""; # allow for sets equal to 0
786 warn "The current problem number is not defined" if $main::probNum eq ""; 812 warn "The current problem number is not defined" if $probNum eq "";
787 warn "The current problem set version number (psvn) is not defined" unless $main::psvnNumber; 813 warn "The current problem set version number (psvn) is not defined" unless $psvnNumber;
788 warn "The displayMode is not defined" unless $main::displayMode; 814 warn "The displayMode is not defined" unless $displayMode;
789 815
790 # required macros 816 # required macros
791 warn "The macro &surePathToTmpFile can't be found" unless defined(&surePathToTmpFile); 817 warn "The macro &surePathToTmpFile can't be found" unless defined(&surePathToTmpFile);
792 warn "The macro &convertPath can't be found" unless defined(&convertPath); 818 warn "The macro &convertPath can't be found" unless defined(&convertPath);
793 warn "The macro &directoryFromPath can't be found" unless defined(&directoryFromPath); 819 warn "The macro &directoryFromPath can't be found" unless defined(&directoryFromPath);
794 warn "Can't execute the gif2eps script at ${main::externalGif2EpsPath}" unless ( -x "${main::externalGif2EpsPath}" ); 820 warn "Can't execute the gif2eps script at ${externalGif2EpsPath}" unless ( -x "${externalGif2EpsPath}" );
795 warn "Can't execute the png2eps script at ${main::externalPng2EpsPath}" unless ( -x "${main::externalPng2EpsPath}" ); 821 warn "Can't execute the png2eps script at ${externalPng2EpsPath}" unless ( -x "${externalPng2EpsPath}" );
796 822
797 # required directory addresses (and URL address) 823 # required directory addresses (and URL address)
798 warn "htmlDirectory is not defined in $main::htmlDirectory" unless $main::htmlDirectory; 824 warn "htmlDirectory is not defined in $htmlDirectory" unless $htmlDirectory;
799 warn "htmlURL is not defined in \$main::htmlURL" unless $main::htmlURL; 825 warn "htmlURL is not defined in \$htmlURL" unless $htmlURL;
800 warn "tempURL is not defined in \$main::tempURL" unless $main::tempURL; 826 warn "tempURL is not defined in \$tempURL" unless $tempURL;
801 #warn "The scripts directory is not defined in \$main::scriptDirectory" unless $main::scriptDirectory;
802 # with the creation of externalGif2EpsPath and externalPng2EpsPath, the scripts directory is no longer used
803 827
804 # determine extension, if there is one 828 # determine extension, if there is one
805 # if extension exists, strip and use the value for $ext 829 # if extension exists, strip and use the value for $ext
806 # files without extensions are considered to be picture files: 830 # files without extensions are considered to be picture files:
807 831
831 # .html FILES in HTML, HTML_tth, HTML_dpng, HTML_img and Latex2HTML mode 855 # .html FILES in HTML, HTML_tth, HTML_dpng, HTML_img and Latex2HTML mode
832 ################################################################################ 856 ################################################################################
833 857
834 # No changes are made for auxiliary files in the 858 # No changes are made for auxiliary files in the
835 # ${Global::htmlDirectory} subtree. 859 # ${Global::htmlDirectory} subtree.
836 if ( $aux_file_path =~ m|^$main::tempDirectory| ) { 860 if ( $aux_file_path =~ m|^$tempDirectory| ) {
837 $adr_output = $aux_file_path; 861 $adr_output = $aux_file_path;
838 $adr_output =~ s|$main::tempDirectory|$main::tempURL/|; 862 $adr_output =~ s|$tempDirectory|$tempURL/|;
839 $adr_output .= ".$ext"; 863 $adr_output .= ".$ext";
840 } elsif ($aux_file_path =~ m|^$main::htmlDirectory| ) { 864 } elsif ($aux_file_path =~ m|^$htmlDirectory| ) {
841 $adr_output = $aux_file_path; 865 $adr_output = $aux_file_path;
842 $adr_output =~ s|$main::htmlDirectory|$main::htmlURL|; 866 $adr_output =~ s|$htmlDirectory|$htmlURL|;
843 $adr_output .= ".$ext"; 867 $adr_output .= ".$ext";
844 } else { 868 } else {
845 # HTML files not in the htmlDirectory are assumed under live under the 869 # HTML files not in the htmlDirectory are assumed under live under the
846 # templateDirectory in the same directory as the problem. 870 # templateDirectory in the same directory as the problem.
847 # Create an alias file (link) in the directory html/tmp/html which 871 # Create an alias file (link) in the directory html/tmp/html which
849 # Create all of the subdirectories of html/tmp/html which are needed 873 # Create all of the subdirectories of html/tmp/html which are needed
850 # using sure file to path. 874 # using sure file to path.
851 875
852 # $fileName is obtained from environment for PGeval 876 # $fileName is obtained from environment for PGeval
853 # it gives the full path to the current problem 877 # it gives the full path to the current problem
854 my $filePath = directoryFromPath($main::fileName); 878 my $filePath = directoryFromPath($fileName);
855 my $htmlFileSource = convertPath("$main::templateDirectory${filePath}$aux_file_path.html"); 879 my $htmlFileSource = convertPath("$templateDirectory${filePath}$aux_file_path.html");
856 my $link = "html/$main::studentLogin-$main::psvnNumber-set$main::setNumber-prob$main::probNum-$aux_file_path.$ext"; 880 my $link = "html/$studentLogin-$psvnNumber-set$setNumber-prob$probNum-$aux_file_path.$ext";
857 my $linkPath = surePathToTmpFile($link); 881 my $linkPath = surePathToTmpFile($link);
858 $adr_output = "${main::tempURL}$link"; 882 $adr_output = "${tempURL}$link";
859 if (-e $htmlFileSource) { 883 if (-e $htmlFileSource) {
860 if (-e $linkPath) { 884 if (-e $linkPath) {
861 unlink($linkPath) || warn "Unable to unlink alias file at |$linkPath|"; 885 unlink($linkPath) || warn "Unable to unlink alias file at |$linkPath|";
862 # destroy the old link. 886 # destroy the old link.
863 } 887 }
866 } else { 890 } else {
867 warn("The macro alias cannot find an HTML file at: |$htmlFileSource|"); 891 warn("The macro alias cannot find an HTML file at: |$htmlFileSource|");
868 } 892 }
869 } 893 }
870 } elsif ($ext eq 'gif') { 894 } elsif ($ext eq 'gif') {
871 if ( $main::displayMode eq 'HTML' || 895 if ( $displayMode eq 'HTML' ||
872 $main::displayMode eq 'HTML_tth'|| 896 $displayMode eq 'HTML_tth'||
873 $main::displayMode eq 'HTML_dpng'|| 897 $displayMode eq 'HTML_dpng'||
874 $main::displayMode eq 'HTML_img'|| 898 $displayMode eq 'HTML_img'||
875 $main::displayMode eq 'Latex2HTML') { 899 $displayMode eq 'Latex2HTML') {
876 ################################################################################ 900 ################################################################################
877 # .gif FILES in HTML, HTML_tth, HTML_dpng, HTML_img, and Latex2HTML modes 901 # .gif FILES in HTML, HTML_tth, HTML_dpng, HTML_img, and Latex2HTML modes
878 ################################################################################ 902 ################################################################################
879 903
880 #warn "tempDirectory is $main::tempDirectory"; 904 #warn "tempDirectory is $tempDirectory";
881 #warn "file Path for auxiliary file is $aux_file_path"; 905 #warn "file Path for auxiliary file is $aux_file_path";
882 906
883 # No changes are made for auxiliary files in the htmlDirectory or in the tempDirectory subtree. 907 # No changes are made for auxiliary files in the htmlDirectory or in the tempDirectory subtree.
884 if ( $aux_file_path =~ m|^$main::tempDirectory| ) { 908 if ( $aux_file_path =~ m|^$tempDirectory| ) {
885 $adr_output = $aux_file_path; 909 $adr_output = $aux_file_path;
886 $adr_output =~ s|$main::tempDirectory|$main::tempURL|; 910 $adr_output =~ s|$tempDirectory|$tempURL|;
887 $adr_output .= ".$ext"; 911 $adr_output .= ".$ext";
888 #warn "adress out is $adr_output"; 912 #warn "adress out is $adr_output";
889 } elsif ($aux_file_path =~ m|^$main::htmlDirectory| ) { 913 } elsif ($aux_file_path =~ m|^$htmlDirectory| ) {
890 $adr_output = $aux_file_path; 914 $adr_output = $aux_file_path;
891 $adr_output =~ s|$main::htmlDirectory|$main::htmlURL|; 915 $adr_output =~ s|$htmlDirectory|$htmlURL|;
892 $adr_output .= ".$ext"; 916 $adr_output .= ".$ext";
893 } else { 917 } else {
894 # files not in the htmlDirectory sub tree are assumed to live under the templateDirectory 918 # files not in the htmlDirectory sub tree are assumed to live under the templateDirectory
895 # subtree in the same directory as the problem. 919 # subtree in the same directory as the problem.
896 920
897 # For a gif file the alias macro creates an alias under the html/images directory 921 # For a gif file the alias macro creates an alias under the html/images directory
898 # which points to the gif file in the problem directory. 922 # which points to the gif file in the problem directory.
899 # All of the subdirectories of html/tmp/gif which are needed are also created. 923 # All of the subdirectories of html/tmp/gif which are needed are also created.
900 my $filePath = directoryFromPath($main::fileName); 924 my $filePath = directoryFromPath($fileName);
901 925
902 # $fileName is obtained from environment for PGeval 926 # $fileName is obtained from environment for PGeval
903 # it gives the full path to the current problem 927 # it gives the full path to the current problem
904 my $gifSourceFile = convertPath("$main::templateDirectory${filePath}$aux_file_path.gif"); 928 my $gifSourceFile = convertPath("$templateDirectory${filePath}$aux_file_path.gif");
905 #my $link = "gif/$main::studentLogin-$main::psvnNumber-set$main::setNumber-prob$main::probNum-$aux_file_path.$ext"; 929 #my $link = "gif/$studentLogin-$psvnNumber-set$setNumber-prob$probNum-$aux_file_path.$ext";
906 my $link = "gif/$main::setNumber-prob$main::probNum-$aux_file_path.$ext"; 930 my $link = "gif/$setNumber-prob$probNum-$aux_file_path.$ext";
907 931
908 my $linkPath = surePathToTmpFile($link); 932 my $linkPath = surePathToTmpFile($link);
909 $adr_output = "${main::tempURL}$link"; 933 $adr_output = "${tempURL}$link";
910 #warn "linkPath is $linkPath"; 934 #warn "linkPath is $linkPath";
911 #warn "adr_output is $adr_output"; 935 #warn "adr_output is $adr_output";
912 if (-e $gifSourceFile) { 936 if (-e $gifSourceFile) {
913 if (-e $linkPath) { 937 if (-e $linkPath) {
914 unlink($linkPath) || warn "Unable to unlink old alias file at $linkPath"; 938 unlink($linkPath) || warn "Unable to unlink old alias file at $linkPath";
917 || warn "The macro alias cannot create a link from |$linkPath| to |$gifSourceFile| <BR>" ; 941 || warn "The macro alias cannot create a link from |$linkPath| to |$gifSourceFile| <BR>" ;
918 } else { 942 } else {
919 warn("The macro alias cannot find a GIF file at: |$gifSourceFile|"); 943 warn("The macro alias cannot find a GIF file at: |$gifSourceFile|");
920 } 944 }
921 } 945 }
922 } elsif ($main::displayMode eq 'TeX') { 946 } elsif ($displayMode eq 'TeX') {
923 ################################################################################ 947 ################################################################################
924 # .gif FILES in TeX mode 948 # .gif FILES in TeX mode
925 ################################################################################ 949 ################################################################################
926 950
927 if ($envir{texDisposition} eq "pdf") { 951 if ($envir{texDisposition} eq "pdf") {
928 # We're going to create PDF files with our TeX (using pdflatex), so we 952 # We're going to create PDF files with our TeX (using pdflatex), so we
929 # need images in PNG format. 953 # need images in PNG format.
930 954
931 my $gifFilePath; 955 my $gifFilePath;
932 956
933 if ($aux_file_path =~ m/^$main::htmlDirectory/ or $aux_file_path =~ m/^$main::tempDirectory/) { 957 if ($aux_file_path =~ m/^$htmlDirectory/ or $aux_file_path =~ m/^$tempDirectory/) {
934 # we've got a full pathname to a file 958 # we've got a full pathname to a file
935 $gifFilePath = "$aux_file_path.gif"; 959 $gifFilePath = "$aux_file_path.gif";
936 } else { 960 } else {
937 # we assume the file is in the same directory as the problem source file 961 # we assume the file is in the same directory as the problem source file
938 $gifFilePath = $main::templateDirectory . directoryFromPath($main::fileName) . "$aux_file_path.gif"; 962 $gifFilePath = $templateDirectory . directoryFromPath($fileName) . "$aux_file_path.gif";
939 } 963 }
940 964
941 my $gifFileName = fileFromPath($gifFilePath); 965 my $gifFileName = fileFromPath($gifFilePath);
942 966
943 $gifFileName =~ /^(.*)\.gif$/; 967 $gifFileName =~ /^(.*)\.gif$/;
944 my $pngFilePath = surePathToTmpFile("$main::tempDirectory/png/$1.png"); 968 my $pngFilePath = surePathToTmpFile("$tempDirectory/png/$1.png");
945 my $returnCode = system "$envir{externalGif2PngPath} $gifFilePath $pngFilePath"; 969 my $returnCode = system "$envir{externalGif2PngPath} $gifFilePath $pngFilePath";
946 970
947 if ($returnCode or not -e $pngFilePath) { 971 if ($returnCode or not -e $pngFilePath) {
948 die "failed to convert gif->png with $envir{externalGif2PngPath}: $!\n"; 972 die "failed to convert gif->png with $envir{externalGif2PngPath}: $!\n";
949 } 973 }
957 # This is statement used below is system dependent. 981 # This is statement used below is system dependent.
958 # Notice that the range of colors is restricted when converting to postscript to keep the files small 982 # Notice that the range of colors is restricted when converting to postscript to keep the files small
959 # "cat $gifSourceFile | /usr/math/bin/giftopnm | /usr/math/bin/pnmtops -noturn > $adr_output" 983 # "cat $gifSourceFile | /usr/math/bin/giftopnm | /usr/math/bin/pnmtops -noturn > $adr_output"
960 # "cat $gifSourceFile | /usr/math/bin/giftopnm | /usr/math/bin/pnmdepth 1 | /usr/math/bin/pnmtops -noturn > $adr_output" 984 # "cat $gifSourceFile | /usr/math/bin/giftopnm | /usr/math/bin/pnmdepth 1 | /usr/math/bin/pnmtops -noturn > $adr_output"
961 ################################################################################ 985 ################################################################################
962 if ($aux_file_path =~ m|^$main::htmlDirectory| or $aux_file_path =~ m|^$main::tempDirectory|) { 986 if ($aux_file_path =~ m|^$htmlDirectory| or $aux_file_path =~ m|^$tempDirectory|) {
963 # To serve an eps file copy an eps version of the gif file to the subdirectory of eps/ 987 # To serve an eps file copy an eps version of the gif file to the subdirectory of eps/
964 my $linkPath = directoryFromPath($main::fileName); 988 my $linkPath = directoryFromPath($fileName);
965 989
966 my $gifSourceFile = "$aux_file_path.gif"; 990 my $gifSourceFile = "$aux_file_path.gif";
967 my $gifFileName = fileFromPath($gifSourceFile); 991 my $gifFileName = fileFromPath($gifSourceFile);
968 $adr_output = surePathToTmpFile("$main::tempDirectory/eps/$main::studentLogin-$main::psvnNumber-$gifFileName.eps") ; 992 $adr_output = surePathToTmpFile("$tempDirectory/eps/$studentLogin-$psvnNumber-$gifFileName.eps") ;
969 993
970 if (-e $gifSourceFile) { 994 if (-e $gifSourceFile) {
971 #system("cat $gifSourceFile | /usr/math/bin/giftopnm | /usr/math/bin/pnmdepth 1 | /usr/math/bin/pnmtops -noturn>$adr_output") 995 #system("cat $gifSourceFile | /usr/math/bin/giftopnm | /usr/math/bin/pnmdepth 1 | /usr/math/bin/pnmtops -noturn>$adr_output")
972 system("${main::externalGif2EpsPath} $gifSourceFile $adr_output" ) 996 system("${externalGif2EpsPath} $gifSourceFile $adr_output" )
973 && die "Unable to create eps file:\n |$adr_output| from file\n |$gifSourceFile|\n in problem $main::probNum " . 997 && die "Unable to create eps file:\n |$adr_output| from file\n |$gifSourceFile|\n in problem $probNum " .
974 "using the system dependent script\n |${main::externalGif2EpsPath}| \n"; 998 "using the system dependent script\n |${externalGif2EpsPath}| \n";
975 } else { 999 } else {
976 die "|$gifSourceFile| cannot be found. Problem number: |$main::probNum|"; 1000 die "|$gifSourceFile| cannot be found. Problem number: |$probNum|";
977 } 1001 }
978 } else { 1002 } else {
979 # To serve an eps file copy an eps version of the gif file to a subdirectory of eps/ 1003 # To serve an eps file copy an eps version of the gif file to a subdirectory of eps/
980 my $filePath = directoryFromPath($main::fileName); 1004 my $filePath = directoryFromPath($fileName);
981 my $gifSourceFile = "${main::templateDirectory}${filePath}$aux_file_path.gif"; 1005 my $gifSourceFile = "${templateDirectory}${filePath}$aux_file_path.gif";
982 #print "content-type: text/plain \n\nfileName = $fileName and aux_file_path =$aux_file_path<BR>"; 1006 #print "content-type: text/plain \n\nfileName = $fileName and aux_file_path =$aux_file_path<BR>";
983 $adr_output = surePathToTmpFile("eps/$main::studentLogin-$main::psvnNumber-set$main::setNumber-prob$main::probNum-$aux_file_path.eps"); 1007 $adr_output = surePathToTmpFile("eps/$studentLogin-$psvnNumber-set$setNumber-prob$probNum-$aux_file_path.eps");
984 1008
985 if (-e $gifSourceFile) { 1009 if (-e $gifSourceFile) {
986 #system("cat $gifSourceFile | /usr/math/bin/giftopnm | /usr/math/bin/pnmdepth 1 | /usr/math/bin/pnmtops -noturn>$adr_output") && 1010 #system("cat $gifSourceFile | /usr/math/bin/giftopnm | /usr/math/bin/pnmdepth 1 | /usr/math/bin/pnmtops -noturn>$adr_output") &&
987 #warn "Unable to create eps file: |$adr_output|\n from file\n |$gifSourceFile|\n in problem $main::probNum"; 1011 #warn "Unable to create eps file: |$adr_output|\n from file\n |$gifSourceFile|\n in problem $probNum";
988 #warn "Help ${main::externalGif2EpsPath}" unless -x "${main::externalGif2EpsPath}"; 1012 #warn "Help ${:externalGif2EpsPath}" unless -x "${main::externalGif2EpsPath}";
989 system("${main::externalGif2EpsPath} $gifSourceFile $adr_output" ) 1013 system("${externalGif2EpsPath} $gifSourceFile $adr_output" )
990 && die "Unable to create eps file:\n |$adr_output| from file\n |$gifSourceFile|\n in problem $main::probNum " . 1014 && die "Unable to create eps file:\n |$adr_output| from file\n |$gifSourceFile|\n in problem $probNum " .
991 "using the system dependent script\n |${main::externalGif2EpsPath}| \n "; 1015 "using the system dependent script\n |${externalGif2EpsPath}| \n ";
992 } else { 1016 } else {
993 die "|$gifSourceFile| cannot be found. Problem number: |$main::probNum|"; 1017 die "|$gifSourceFile| cannot be found. Problem number: |$probNum|";
994 } 1018 }
995 } 1019 }
996 } 1020 }
997 } else { 1021 } else {
998 wwerror("Error in alias: dangerousMacros.pl","unrecognizable displayMode = $main::displayMode",""); 1022 wwerror("Error in alias: dangerousMacros.pl","unrecognizable displayMode = $displayMode","");
999 } 1023 }
1000 } elsif ($ext eq 'png') { 1024 } elsif ($ext eq 'png') {
1001 if ( $main::displayMode eq 'HTML' || 1025 if ( $displayMode eq 'HTML' ||
1002 $main::displayMode eq 'HTML_tth'|| 1026 $displayMode eq 'HTML_tth'||
1003 $main::displayMode eq 'HTML_dpng'|| 1027 $displayMode eq 'HTML_dpng'||
1004 $main::displayMode eq 'HTML_img'|| 1028 $displayMode eq 'HTML_img'||
1005 $main::displayMode eq 'Latex2HTML') { 1029 $displayMode eq 'Latex2HTML') {
1006 ################################################################################ 1030 ################################################################################
1007 # .png FILES in HTML, HTML_tth, HTML_dpng, HTML_img, and Latex2HTML modes 1031 # .png FILES in HTML, HTML_tth, HTML_dpng, HTML_img, and Latex2HTML modes
1008 ################################################################################ 1032 ################################################################################
1009 1033
1010 #warn "tempDirectory is $main::tempDirectory"; 1034 #warn "tempDirectory is $tempDirectory";
1011 #warn "file Path for auxiliary file is $aux_file_path"; 1035 #warn "file Path for auxiliary file is $aux_file_path";
1012 1036
1013 # No changes are made for auxiliary files in the htmlDirectory or in the tempDirectory subtree. 1037 # No changes are made for auxiliary files in the htmlDirectory or in the tempDirectory subtree.
1014 if ( $aux_file_path =~ m|^$main::tempDirectory| ) { 1038 if ( $aux_file_path =~ m|^$tempDirectory| ) {
1015 $adr_output = $aux_file_path; 1039 $adr_output = $aux_file_path;
1016 $adr_output =~ s|$main::tempDirectory|$main::tempURL|; 1040 $adr_output =~ s|$tempDirectory|$tempURL|;
1017 $adr_output .= ".$ext"; 1041 $adr_output .= ".$ext";
1018 #warn "adress out is $adr_output"; 1042 #warn "adress out is $adr_output";
1019 } elsif ($aux_file_path =~ m|^$main::htmlDirectory| ) { 1043 } elsif ($aux_file_path =~ m|^$htmlDirectory| ) {
1020 $adr_output = $aux_file_path; 1044 $adr_output = $aux_file_path;
1021 $adr_output =~ s|$main::htmlDirectory|$main::htmlURL|; 1045 $adr_output =~ s|$htmlDirectory|$htmlURL|;
1022 $adr_output .= ".$ext"; 1046 $adr_output .= ".$ext";
1023 } else { 1047 } else {
1024 # files not in the htmlDirectory sub tree are assumed to live under the templateDirectory 1048 # files not in the htmlDirectory sub tree are assumed to live under the templateDirectory
1025 # subtree in the same directory as the problem. 1049 # subtree in the same directory as the problem.
1026 1050
1027 # For a png file the alias macro creates an alias under the html/images directory 1051 # For a png file the alias macro creates an alias under the html/images directory
1028 # which points to the png file in the problem directory. 1052 # which points to the png file in the problem directory.
1029 # All of the subdirectories of html/tmp/gif which are needed are also created. 1053 # All of the subdirectories of html/tmp/gif which are needed are also created.
1030 my $filePath = directoryFromPath($main::fileName); 1054 my $filePath = directoryFromPath($fileName);
1031 1055
1032 # $fileName is obtained from environment for PGeval 1056 # $fileName is obtained from environment for PGeval
1033 # it gives the full path to the current problem 1057 # it gives the full path to the current problem
1034 my $pngSourceFile = convertPath("$main::templateDirectory${filePath}$aux_file_path.png"); 1058 my $pngSourceFile = convertPath("$templateDirectory${filePath}$aux_file_path.png");
1035 my $link = "gif/$main::studentLogin-$main::psvnNumber-set$main::setNumber-prob$main::probNum-$aux_file_path.$ext"; 1059 my $link = "gif/$studentLogin-$psvnNumber-set$setNumber-prob$probNum-$aux_file_path.$ext";
1036 my $linkPath = surePathToTmpFile($link); 1060 my $linkPath = surePathToTmpFile($link);
1037 $adr_output = "${main::tempURL}$link"; 1061 $adr_output = "${tempURL}$link";
1038 #warn "linkPath is $linkPath"; 1062 #warn "linkPath is $linkPath";
1039 #warn "adr_output is $adr_output"; 1063 #warn "adr_output is $adr_output";
1040 if (-e $pngSourceFile) { 1064 if (-e $pngSourceFile) {
1041 if (-e $linkPath) { 1065 if (-e $linkPath) {
1042 unlink($linkPath) || warn "Unable to unlink old alias file at $linkPath"; 1066 unlink($linkPath) || warn "Unable to unlink old alias file at $linkPath";
1045 || warn "The macro alias cannot create a link from |$linkPath| to |$pngSourceFile| <BR>" ; 1069 || warn "The macro alias cannot create a link from |$linkPath| to |$pngSourceFile| <BR>" ;
1046 } else { 1070 } else {
1047 warn("The macro alias cannot find a PNG file at: |$pngSourceFile|"); 1071 warn("The macro alias cannot find a PNG file at: |$pngSourceFile|");
1048 } 1072 }
1049 } 1073 }
1050 } elsif ($main::displayMode eq 'TeX') { 1074 } elsif ($displayMode eq 'TeX') {
1051 ################################################################################ 1075 ################################################################################
1052 # .png FILES in TeX mode 1076 # .png FILES in TeX mode
1053 ################################################################################ 1077 ################################################################################
1054 1078
1055 if ($envir{texDisposition} eq "pdf") { 1079 if ($envir{texDisposition} eq "pdf") {
1056 # We're going to create PDF files with our TeX (using pdflatex), so we 1080 # We're going to create PDF files with our TeX (using pdflatex), so we
1057 # need images in PNG format. what luck! they're already in PDF format! 1081 # need images in PNG format. what luck! they're already in PDF format!
1058 1082
1059 my $pngFilePath; 1083 my $pngFilePath;
1060 1084
1061 if ($aux_file_path =~ m/^$main::htmlDirectory/ or $aux_file_path =~ m/^$main::tempDirectory/) { 1085 if ($aux_file_path =~ m/^$htmlDirectory/ or $aux_file_path =~ m/^$tempDirectory/) {
1062 # we've got a full pathname to a file 1086 # we've got a full pathname to a file
1063 $pngFilePath = "$aux_file_path.png"; 1087 $pngFilePath = "$aux_file_path.png";
1064 } else { 1088 } else {
1065 # we assume the file is in the same directory as the problem source file 1089 # we assume the file is in the same directory as the problem source file
1066 $pngFilePath = $main::templateDirectory . directoryFromPath($main::fileName) . "$aux_file_path.png"; 1090 $pngFilePath = $templateDirectory . directoryFromPath($fileName) . "$aux_file_path.png";
1067 } 1091 }
1068 1092
1069 $adr_output = $pngFilePath; 1093 $adr_output = $pngFilePath;
1070 } else { 1094 } else {
1071 # Since we're not creating PDF files, we're probably just using a plain 1095 # Since we're not creating PDF files, we're probably just using a plain
1076 # Notice that the range of colors is restricted when converting to postscript to keep the files small 1100 # Notice that the range of colors is restricted when converting to postscript to keep the files small
1077 # "cat $pngSourceFile | /usr/math/bin/pngtopnm | /usr/math/bin/pnmtops -noturn > $adr_output" 1101 # "cat $pngSourceFile | /usr/math/bin/pngtopnm | /usr/math/bin/pnmtops -noturn > $adr_output"
1078 # "cat $pngSourceFile | /usr/math/bin/pngtopnm | /usr/math/bin/pnmdepth 1 | /usr/math/bin/pnmtops -noturn > $adr_output" 1102 # "cat $pngSourceFile | /usr/math/bin/pngtopnm | /usr/math/bin/pnmdepth 1 | /usr/math/bin/pnmtops -noturn > $adr_output"
1079 ################################################################################ 1103 ################################################################################
1080 1104
1081 if ($aux_file_path =~ m|^$main::htmlDirectory| or $aux_file_path =~ m|^$main::tempDirectory|) { 1105 if ($aux_file_path =~ m|^$htmlDirectory| or $aux_file_path =~ m|^$tempDirectory|) {
1082 # To serve an eps file copy an eps version of the png file to the subdirectory of eps/ 1106 # To serve an eps file copy an eps version of the png file to the subdirectory of eps/
1083 my $linkPath = directoryFromPath($main::fileName); 1107 my $linkPath = directoryFromPath($fileName);
1084 1108
1085 my $pngSourceFile = "$aux_file_path.png"; 1109 my $pngSourceFile = "$aux_file_path.png";
1086 my $pngFileName = fileFromPath($pngSourceFile); 1110 my $pngFileName = fileFromPath($pngSourceFile);
1087 $adr_output = surePathToTmpFile("$main::tempDirectory/eps/$main::studentLogin-$main::psvnNumber-$pngFileName.eps") ; 1111 $adr_output = surePathToTmpFile("$tempDirectory/eps/$studentLogin-$psvnNumber-$pngFileName.eps") ;
1088 1112
1089 if (-e $pngSourceFile) { 1113 if (-e $pngSourceFile) {
1090 #system("cat $pngSourceFile | /usr/math/bin/pngtopnm | /usr/math/bin/pnmdepth 1 | /usr/math/bin/pnmtops -noturn>$adr_output") 1114 #system("cat $pngSourceFile | /usr/math/bin/pngtopnm | /usr/math/bin/pnmdepth 1 | /usr/math/bin/pnmtops -noturn>$adr_output")
1091 system("${main::externalPng2EpsPath} $pngSourceFile $adr_output" ) 1115 system("${externalPng2EpsPath} $pngSourceFile $adr_output" )
1092 && die "Unable to create eps file:\n |$adr_output| from file\n |$pngSourceFile|\n in problem $main::probNum " . 1116 && die "Unable to create eps file:\n |$adr_output| from file\n |$pngSourceFile|\n in problem $probNum " .
1093 "using the system dependent script\n |${main::externalPng2EpsPath}| \n"; 1117 "using the system dependent script\n |${externalPng2EpsPath}| \n";
1094 } else { 1118 } else {
1095 die "|$pngSourceFile| cannot be found. Problem number: |$main::probNum|"; 1119 die "|$pngSourceFile| cannot be found. Problem number: |$probNum|";
1096 } 1120 }
1097 } else { 1121 } else {
1098 # To serve an eps file copy an eps version of the png file to a subdirectory of eps/ 1122 # To serve an eps file copy an eps version of the png file to a subdirectory of eps/
1099 my $filePath = directoryFromPath($main::fileName); 1123 my $filePath = directoryFromPath($fileName);
1100 my $pngSourceFile = "${main::templateDirectory}${filePath}$aux_file_path.png"; 1124 my $pngSourceFile = "${templateDirectory}${filePath}$aux_file_path.png";
1101 #print "content-type: text/plain \n\nfileName = $fileName and aux_file_path =$aux_file_path<BR>"; 1125 #print "content-type: text/plain \n\nfileName = $fileName and aux_file_path =$aux_file_path<BR>";
1102 $adr_output = surePathToTmpFile("eps/$main::studentLogin-$main::psvnNumber-set$main::setNumber-prob$main::probNum-$aux_file_path.eps") ; 1126 $adr_output = surePathToTmpFile("eps/$studentLogin-$psvnNumber-set$setNumber-prob$probNum-$aux_file_path.eps") ;
1103 if (-e $pngSourceFile) { 1127 if (-e $pngSourceFile) {
1104 #system("cat $pngSourceFile | /usr/math/bin/pngtopnm | /usr/math/bin/pnmdepth 1 | /usr/math/bin/pnmtops -noturn>$adr_output") && 1128 #system("cat $pngSourceFile | /usr/math/bin/pngtopnm | /usr/math/bin/pnmdepth 1 | /usr/math/bin/pnmtops -noturn>$adr_output") &&
1105 #warn "Unable to create eps file: |$adr_output|\n from file\n |$pngSourceFile|\n in problem $main::probNum"; 1129 #warn "Unable to create eps file: |$adr_output|\n from file\n |$pngSourceFile|\n in problem $probNum";
1106 #warn "Help ${main::externalPng2EpsPath}" unless -x "${main::externalPng2EpsPath}"; 1130 #warn "Help ${externalPng2EpsPath}" unless -x "${externalPng2EpsPath}";
1107 system("${main::externalPng2EpsPath} $pngSourceFile $adr_output" ) 1131 system("${externalPng2EpsPath} $pngSourceFile $adr_output" )
1108 && die "Unable to create eps file:\n |$adr_output| from file\n |$pngSourceFile|\n in problem $main::probNum " . 1132 && die "Unable to create eps file:\n |$adr_output| from file\n |$pngSourceFile|\n in problem $probNum " .
1109 "using the system dependent script\n |${main::externalPng2EpsPath}| \n "; 1133 "using the system dependent script\n |${externalPng2EpsPath}| \n ";
1110 } else { 1134 } else {
1111 die "|$pngSourceFile| cannot be found. Problem number: |$main::probNum|"; 1135 die "|$pngSourceFile| cannot be found. Problem number: |$probNum|";
1112 } 1136 }
1113 } 1137 }
1114 } 1138 }
1115 } else { 1139 } else {
1116 wwerror("Error in alias: dangerousMacros.pl","unrecognizable displayMode = $main::displayMode",""); 1140 warn "Error in alias: dangerousMacros.pl","unrecognizable displayMode = $displayMode","";
1117 } 1141 }
1118 } else { # $ext is not recognized 1142 } else { # $ext is not recognized
1119 ################################################################################ 1143 ################################################################################
1120 # FILES with unrecognized file extensions in any display modes 1144 # FILES with unrecognized file extensions in any display modes
1121 ################################################################################ 1145 ################################################################################
1122 1146
1123 warn "Error in the macro alias. Alias does not understand how to process files with extension $ext. (Path ot problem file is $main::fileName) "; 1147 warn "Error in the macro alias. Alias does not understand how to process files with extension $ext. (Path ot problem file is $fileName) ";
1124 } 1148 }
1125 1149
1126 warn "The macro alias was unable to form a URL for some auxiliary file used in this problem." unless $adr_output; 1150 warn "The macro alias was unable to form a URL for some auxiliary file used in this problem." unless $adr_output;
1127 return $adr_output; 1151 return $adr_output;
1128} 1152}

Legend:
Removed from v.1250  
changed lines
  Added in v.1267

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9