| … | |
… | |
| 452 | if ($displayMode eq 'pg') { |
452 | if ($displayMode eq 'pg') { |
| 453 | my %envir=defineProblemEnvir($mode, 0, $psvn, $Course, undef()); |
453 | my %envir=defineProblemEnvir($mode, 0, $psvn, $Course, undef()); |
| 454 | my $input_string= join("",<INPUT>); |
454 | my $input_string= join("",<INPUT>); |
| 455 | my ($PG_PROBLEM_TEXT_REF, $PG_HEADER_TEXT_REF, $PG_ANSWER_HASH_REF, $PG_FLAGS_REF); |
455 | my ($PG_PROBLEM_TEXT_REF, $PG_HEADER_TEXT_REF, $PG_ANSWER_HASH_REF, $PG_FLAGS_REF); |
| 456 | |
456 | |
|
|
457 | # BEGIN fork |
|
|
458 | if (open TEX_PIPE, "-|") { |
|
|
459 | # parent: |
|
|
460 | local $/ = "\n"; |
|
|
461 | my $curr_pg_compile_error = <TEX_PIPE>; |
|
|
462 | chomp $curr_pg_compile_error; |
|
|
463 | push @PG_COMPILE_ERRORS, $curr_pg_compile_error if $curr_pg_compile_error; |
|
|
464 | |
|
|
465 | undef $/; |
|
|
466 | $texSource .= <TEX_PIPE>; |
|
|
467 | } else { |
|
|
468 | # child: |
|
|
469 | $texSource = ''; # clear this at beginning of fork |
|
|
470 | @PG_COMPILE_ERRORS = (); # clear this as well |
|
|
471 | # ----- |
| 457 | my $pt = new PGtranslator; |
472 | my $pt = new PGtranslator; |
| 458 | $pt -> evaluate_modules( @{main::modules_to_evaluate}) ; |
473 | $pt -> evaluate_modules( @{main::modules_to_evaluate}) ; |
| 459 | $pt -> load_extra_packages(@{main::extra_packages_to_be_loaded}); |
474 | $pt -> load_extra_packages(@{main::extra_packages_to_be_loaded}); |
| 460 | # The variables in the two preceding lines are defined in PG_module_list.pl |
475 | # The variables in the two preceding lines are defined in PG_module_list.pl |
| 461 | # require "${courseScriptsDirectory}PG_module_list.pl"; |
476 | # require "${courseScriptsDirectory}PG_module_list.pl"; |
| 462 | # (Modules are defined by require statement above found near the top of this file) |
477 | # (Modules are defined by require statement above found near the top of this file) |
| 463 | $pt->environment(\%envir); |
478 | $pt->environment(\%envir); |
| 464 | $pt->initialize(); |
479 | $pt->initialize(); |
| 465 | $pt->set_mask(); |
480 | $pt->set_mask(); |
| 466 | $pt->source_string($input_string); |
481 | $pt->source_string($input_string); |
| 467 | $pt->unrestricted_load("${courseScriptsDirectory}PG.pl"); |
482 | $pt->unrestricted_load("${courseScriptsDirectory}PG.pl"); |
| 468 | $pt->unrestricted_load("${courseScriptsDirectory}dangerousMacros.pl"); |
483 | $pt->unrestricted_load("${courseScriptsDirectory}dangerousMacros.pl"); |
| 469 | $pt->translate(); |
484 | $pt->translate(); |
| 470 | |
485 | |
| 471 | $PG_PROBLEM_TEXT_REF = $pt->ra_text(); |
486 | $PG_PROBLEM_TEXT_REF = $pt->ra_text(); |
| 472 | $PG_HEADER_TEXT_REF = $pt->r_header;#\$PG_HEADER_TEXT; |
487 | $PG_HEADER_TEXT_REF = $pt->r_header;#\$PG_HEADER_TEXT; |
| 473 | $PG_ANSWER_HASH_REF = $pt->rh_correct_answers; |
488 | $PG_ANSWER_HASH_REF = $pt->rh_correct_answers; |
| 474 | $PG_FLAGS_REF = $pt->rh_flags; |
489 | $PG_FLAGS_REF = $pt->rh_flags; |
| 475 | |
490 | |
| 476 | $texSource .= join '', @{$PG_PROBLEM_TEXT_REF}; |
491 | $texSource .= join '', @{$PG_PROBLEM_TEXT_REF}; |
|
|
492 | |
|
|
493 | # begin non-FORK code |
| 477 | if (defined($PG_FLAGS_REF->{'error_flag'}) and $PG_FLAGS_REF->{'error_flag'} == 1) { |
494 | # if (defined($PG_FLAGS_REF->{'error_flag'}) and $PG_FLAGS_REF->{'error_flag'} == 1) { |
| 478 | push(@PG_COMPILE_ERRORS, qq{<A HREF="#problem0">$probSetHeader</A>} ); |
495 | # push(@PG_COMPILE_ERRORS, qq{<A HREF="#problem0">$probSetHeader</A>} ); |
|
|
496 | # } |
|
|
497 | # end non-FORK code |
|
|
498 | |
|
|
499 | # begin FORK-only code |
|
|
500 | my $stupid_forked_error_string; |
|
|
501 | if (defined($PG_FLAGS_REF->{'error_flag'}) and $PG_FLAGS_REF->{'error_flag'} ==1) { |
|
|
502 | $texSource = qq{<A HREF="#problem0">$probSetHeader</A>} . "\n" . $texSource; |
|
|
503 | } else { |
|
|
504 | $texSource = "\n" . $texSource; |
| 479 | } |
505 | } |
|
|
506 | # end FORK code |
| 480 | |
507 | |
| 481 | if (defined($Global::WARNINGS) and $Global::WARNINGS) { |
508 | if (defined($Global::WARNINGS) and $Global::WARNINGS) { |
| 482 | my $warnings = '{\\bf WARNINGS:\par{\\tiny ' . $Global::WARNINGS . ' }}'; |
509 | my $warnings = '{\\bf WARNINGS:\par{\\tiny ' . $Global::WARNINGS . ' }}'; |
| 483 | $warnings =~ s|/|\\\-/|g; # allow linebreaks in the middle of URLs |
510 | $warnings =~ s|/|\\\-/|g; # allow linebreaks in the middle of URLs |
| 484 | $warnings =~ s/<br>/\\par\n/ig; # introduce breaks at linebreaks and paragraphs |
511 | $warnings =~ s/<br>/\\par\n/ig; # introduce breaks at linebreaks and paragraphs |
| 485 | $warnings =~ s/<p>/\\par\n/ig; |
512 | $warnings =~ s/<p>/\\par\n/ig; |
| 486 | $warnings =~ s/\#/\\\#/g; # protect against some of the symbols which are reserved in tex |
513 | $warnings =~ s/\#/\\\#/g; # protect against some of the symbols which are reserved in tex |
| 487 | $warnings =~ s/\_/\\\_/g; |
514 | $warnings =~ s/\_/\\\_/g; |
| 488 | $warnings =~ s/\>/\\\>/g; |
515 | $warnings =~ s/\>/\\\>/g; |
| 489 | $warnings =~ s/\</\\\</g; |
516 | $warnings =~ s/\</\\\</g; |
| 490 | $texSource .= $warnings; |
517 | $texSource .= $warnings; |
|
|
518 | } |
|
|
519 | $Global::WARNINGS = ''; # reset the Global::WARNINGS parameter |
|
|
520 | # ----- |
|
|
521 | print $texSource; |
|
|
522 | exit; |
| 491 | } |
523 | } |
| 492 | |
524 | # END fork |
| 493 | $Global::WARNINGS = ''; # reset the Global::WARNINGS parameter |
|
|
| 494 | } else { |
525 | } else { |
| 495 | $texSource .= "Don't understand languages with extension $displayMode.<BR>\n"; |
526 | $texSource .= "Don't understand languages with extension $displayMode.<BR>\n"; |
| 496 | } |
527 | } |
| 497 | close INPUT; |
528 | close INPUT; |
| 498 | } else { |
529 | } else { |
| … | |
… | |
| 557 | # push(@PG_COMPILE_ERRORS, qq{<A HREF="#problem$probNum">$probNum</A>} ); |
588 | # push(@PG_COMPILE_ERRORS, qq{<A HREF="#problem$probNum">$probNum</A>} ); |
| 558 | # } |
589 | # } |
| 559 | # end non-FORK code |
590 | # end non-FORK code |
| 560 | |
591 | |
| 561 | # begin FORK-only code |
592 | # begin FORK-only code |
| 562 | my $stupid_forked_error_string; |
|
|
| 563 | if (defined($PG_FLAGS_REF->{'error_flag'}) and $PG_FLAGS_REF->{'error_flag'} ==1) { |
593 | if (defined($PG_FLAGS_REF->{'error_flag'}) and $PG_FLAGS_REF->{'error_flag'} ==1) { |
| 564 | $texSource = qq{<A HREF="#problem$probNum">$probNum</A>} . "\n" . $texSource; |
594 | $texSource = qq{<A HREF="#problem$probNum">$probNum</A>} . "\n" . $texSource; |
| 565 | } else { |
595 | } else { |
| 566 | $texSource = "\n" . $texSource; |
596 | $texSource = "\n" . $texSource; |
| 567 | } |
597 | } |