| … | |
… | |
| 7 | |
7 | |
| 8 | |
8 | |
| 9 | BEGIN { |
9 | BEGIN { |
| 10 | be_strict(); |
10 | be_strict(); |
| 11 | } |
11 | } |
| 12 | sub _PG_export { |
12 | #sub _PG_export { |
| 13 | my @EXPORT= ( |
13 | # my @EXPORT= ( |
| 14 | '&_PG_init', |
14 | # '&_PG_init', |
| 15 | '&ANS', |
15 | # '&ANS', |
| 16 | '&ANS_NUM_TO_NAME', |
16 | # '&ANS_NUM_TO_NAME', |
| 17 | '&DOCUMENT', |
17 | # '&DOCUMENT', |
| 18 | '&ENDDOCUMENT', |
18 | # '&ENDDOCUMENT', |
| 19 | '&HEADER_TEXT', |
19 | # '&HEADER_TEXT', |
| 20 | 'NAMED_ANS', |
20 | # 'NAMED_ANS', |
| 21 | 'NEW_ANS_NAME', |
21 | # 'NEW_ANS_NAME', |
| 22 | 'RECORD_ANS_NAME', |
22 | # 'RECORD_ANS_NAME', |
| 23 | 'TEXT', |
23 | # 'TEXT', |
| 24 | ); |
24 | # ); |
| 25 | @EXPORT; |
25 | # @EXPORT; |
| 26 | } |
26 | #} |
| 27 | sub _PG_init{ |
27 | sub _PG_init{ |
| 28 | |
28 | |
| 29 | } |
29 | } |
| 30 | |
30 | |
| 31 | #package PG; |
31 | #package PG; |
| … | |
… | |
| 125 | $STRINGforHEADER_TEXT =""; |
125 | $STRINGforHEADER_TEXT =""; |
| 126 | @PG_ANSWERS=(); |
126 | @PG_ANSWERS=(); |
| 127 | @main::PG_ANSWER_ENTRY_ORDER = (); |
127 | @main::PG_ANSWER_ENTRY_ORDER = (); |
| 128 | @PG_UNLABELED_ANSWERS = (); |
128 | @PG_UNLABELED_ANSWERS = (); |
| 129 | %PG_ANSWERS_HASH = (); |
129 | %PG_ANSWERS_HASH = (); |
| 130 | eval q{ #make sure that "main" points to the current safe compartment by evaluating these lines. |
130 | #eval q{ #make sure that "main" points to the current safe compartment by evaluating these lines. |
|
|
131 | # when using forking the safe compartment always has the same name, so this isn't needed. |
| 131 | $main::ANSWER_PREFIX = 'AnSwEr'; |
132 | $main::ANSWER_PREFIX = 'AnSwEr'; |
| 132 | %main::PG_FLAGS=(); #global flags |
133 | %main::PG_FLAGS=(); #global flags |
| 133 | $main::showPartialCorrectAnswers = 0 unless defined($main::showPartialCorrectAnswers ); |
134 | $main::showPartialCorrectAnswers = 0 unless defined($main::showPartialCorrectAnswers ); |
| 134 | $main::solutionExists =0; |
135 | $main::solutionExists =0; |
| 135 | %main::gifs_created = (); |
136 | %main::gifs_created = (); |
| 136 | |
137 | |
| 137 | die "The environment variable envir has not been defined" unless defined(%main::envir); |
138 | die "The environment variable envir has not been defined" unless defined(%main::envir); |
| 138 | }; |
139 | #}; |
| 139 | foreach my $var ( eval q{keys %main::envir} ) { |
140 | foreach my $var ( keys %main::envir ) { |
| 140 | eval("\$main::$var =\$main::envir{'$var'}"); |
141 | eval("\$main::$var =\$main::envir{'$var'}"); |
| 141 | warn "Problem defining ", q{\$main::$var}, " while inititializing the PG problem: $@" if $@; |
142 | warn "Problem defining ", q{\$main::$var}, " while inititializing the PG problem: $@" if $@; |
| 142 | } |
143 | } |
| 143 | eval q{ |
144 | #eval q{ |
| 144 | @main::submittedAnswers = @{$main::refSubmittedAnswers} if defined($main::refSubmittedAnswers); |
145 | @main::submittedAnswers = @{$main::refSubmittedAnswers} if defined($main::refSubmittedAnswers); |
| 145 | $main::PG_original_problemSeed = $main::problemSeed; |
146 | $main::PG_original_problemSeed = $main::problemSeed; |
| 146 | $main::PG_random_generator = new PGrandom($main::problemSeed) || die "Can't create random number generator."; |
147 | $main::PG_random_generator = new PGrandom($main::problemSeed) || die "Can't create random number generator."; |
| 147 | $main::ans_rule_count = 0; # counts questions |
148 | $main::ans_rule_count = 0; # counts questions |
| 148 | }; |
149 | #}; |
| 149 | #warn "key1", join( "<>",keys %main::); |
150 | #warn "key1", join( "<>",keys %main::); |
| 150 | #warn "key2", join( "<>",eval q{ keys %main::}); |
151 | #warn "key2", join( "<>",eval q{ keys %main::}); |
| 151 | # end unpacking of environment variables. |
152 | # end unpacking of environment variables. |
| 152 | } |
153 | } |
| 153 | |
154 | |
| … | |
… | |
| 305 | } |
306 | } |
| 306 | $index++; |
307 | $index++; |
| 307 | } |
308 | } |
| 308 | |
309 | |
| 309 | $STRINGforOUTPUT .="\n"; |
310 | $STRINGforOUTPUT .="\n"; |
| 310 | eval q{ #make sure that "main" points to the current safe compartment by evaluating these lines. |
311 | ##eval q{ #make sure that "main" points to the current safe compartment by evaluating these lines. |
| 311 | $main::PG_FLAGS{'showPartialCorrectAnswers'} = $main::showPartialCorrectAnswers; |
312 | $main::PG_FLAGS{'showPartialCorrectAnswers'} = $main::showPartialCorrectAnswers; |
| 312 | $main::PG_FLAGS{'recordSubmittedAnswers'} = $main::recordSubmittedAnswers; |
313 | $main::PG_FLAGS{'recordSubmittedAnswers'} = $main::recordSubmittedAnswers; |
| 313 | # $main::PG_FLAGS{'hintExists'} = $main::hintExists; |
314 | # $main::PG_FLAGS{'hintExists'} = $main::hintExists; |
| 314 | $main::PG_FLAGS{'solutionExists'} = $main::solutionExists; |
315 | $main::PG_FLAGS{'solutionExists'} = $main::solutionExists; |
| 315 | $main::PG_FLAGS{ANSWER_ENTRY_ORDER} = \@main::PG_ANSWER_ENTRY_ORDER; |
316 | $main::PG_FLAGS{ANSWER_ENTRY_ORDER} = \@main::PG_ANSWER_ENTRY_ORDER; |
| … | |
… | |
| 336 | } elsif (defined(&std_problem_grader)) { |
337 | } elsif (defined(&std_problem_grader)) { |
| 337 | $main::PG_FLAGS{PROBLEM_GRADER_TO_USE} = \&std_problem_grader; # defined in PGanswermacros.pl |
338 | $main::PG_FLAGS{PROBLEM_GRADER_TO_USE} = \&std_problem_grader; # defined in PGanswermacros.pl |
| 338 | } else { |
339 | } else { |
| 339 | # PGtranslator will install its default problem grader |
340 | # PGtranslator will install its default problem grader |
| 340 | } |
341 | } |
| 341 | }; |
342 | ##}; |
| 342 | warn "ERROR: The problem grader is not a subroutine" unless ref( $main::PG_FLAGS{PROBLEM_GRADER_TO_USE}) eq 'CODE'; |
343 | warn "ERROR: The problem grader is not a subroutine" unless ref( $main::PG_FLAGS{PROBLEM_GRADER_TO_USE}) eq 'CODE'; |
| 343 | # return results |
344 | # return results |
| 344 | (\$STRINGforOUTPUT, \$STRINGforHEADER_TEXT,\%PG_ANSWERS_HASH,\%main::PG_FLAGS); |
345 | (\$STRINGforOUTPUT, \$STRINGforHEADER_TEXT,\%PG_ANSWERS_HASH,\%main::PG_FLAGS); |
| 345 | } |
346 | } |
| 346 | |
347 | |