# rmce.pl # Program Authors: A. Ian McLeod, Ying Zhang & Valery Didinchuk # Department of Statistical & Actuarial Sciences, # University of Western Ontario. # email for Ian McLeod: aim@uwo.ca #------------------------------------------------------ ## # Usage: # Running program rmce.pl from command-line: # # > perl rmce.pl ExamName.rtf [NumberOfVersionExam] [PassWordForSeed] # # Input program rmce.pl: # ExamName.rtf - The Rich Text Format file is created by user. # This file must include MarkUp Strings for rmce.pl program. # NumberOfVersionExam - Number of versions created by rmce.pl program # ( Default 0-version file. This 0-version file has same order of sections, questions and aswers.) # PassWordForSeed - String for definition $GLOBAL_SEED_FOR_RANDOM (Default seed's value for random function = 175). # # Output program rmce.pl: # Program create file ---> $TheExamKeyText file , new $TheNameForDir dir and new version ExamName.rtf inside this dir. # If program finds dir with same name than creats dir and $TheExamKeyText file with version of name. # # Format in ExamName.rtf: # # &SeparateLineQuestion --- Begin range of a separate line between questions # . . . . . . . . . # &SeparateLineSection --- Begin range of a separate line between sections # . . . . . . . . . # &MainTitle --- Begin range of a title ( in the exam file can be only one title ) # . . . . . . . . . # &Section[R] --- Begin range of a section without [with] random order ( in the exam file can be many sections ) # . . . . . . . . . # &Question[Number][Keep][R] --- Begin range of a question without [with] random order ( in the exam file can be many questions ) # | |__ mark for question which needs to keep same position in the exam file # |__ number shows how many question can put per page # . . . . . . . . . . # &A --- Begin range of a answer ( in the exam file can not more than 5 answer! ) # . . . . . . . . . . # &B --- Begin range of a answer # . . . . . . . . . . # &C --- Begin range of a answer # . . . . . . . . . . # &D --- Begin range of a answer # . . . . . . . . . . # &E --- Begin range of a answer # . . . . . . . . . . # &EndAnswers --- End of answers for question in ExamName.rtf file. # . . . . . . . . . . # &EndQuestions --- End of questions for section in ExamName.rtf file. # . . . . . . . . . . # &EndExam --- End of ExamName.rtf file where the program takes a title, sections, questions and aswers. # # # Format in ExamKeyText.txt: # # Key for ExamName.rtf! ...Line 1 - Included The Name of Exam file # MarkingScheme=3,0,1,0 # correct, wrong, blank, bonus ... Line 2 - Special string for definition @Weights list in Marker.pl program. # Date:9/19/00 9:32:20 ...Line 3 - Date creating file # MaxNumQuestion=5 ...Line 4 - Max Number Question in compounds of Exam # TotlNumQuestion=8 ...Line 5 - Totl Number Question in Exam # MaxNumSection=2 ...Line 6 - Max Number Section in compounds of Exam # TotlNumberExams=2 ...Line 7 - Totl Number Version Exams # Exam0 ...Line 8 - Begin Exam Zero version # 5 4 4 4 3 5 ...Line 9 - 5-Quantity Question in 1-Compound-Section, 4-Quantity Answers in Question 1, 4-Quantity Answer in Question 2, ... # 2 3 4 ...Line 10- 2-Quantity Question in 2-Compound-Section, 3-Quantity Answers in Question 1, 4-Quantity Answer in Question 2 # N... ...Line i - N-Quantity Question in (i-6)-Compound-Section, ... # NumberQuestion ...Line N - Number Answer in Question NumberQuestion # END Exam0 ...Line - N+1 End Exam Zero Version # Exam1 ...Line - N+2 End Exam 1 version # 1 5 3 5 2 1 4 ...Line K - Compound 1, Question 5 in Compound 1, Order Numbers Answer-3 5 2 1 4 in Question 5 # 1 1 4 3 1 2 ...Line K+1 - Compound 1, Question 1 in Compound 1, Order Numbers Answer-4 3 1 2 in Question 1 # ........ # 2 3 3 4 2 1 ...Line K+TotlNumberQuestion - Compound 2, Question 3 in Compound 2, Order Numbers Answer-3 4 2 1 in Question 3 # END Exam1 ..... ...... ....... ..... # ......... .......... ........... ....... #-------------------------------------------------------------------------------------------------------------------- # # # Sub intChr sums the characters values from string # and returns this The Sum. # sub intChr{ my( $myStr ) = @_; my $myI; my $myChr; my $myInt; my $myLength; my $myCount; my $mySumInt; $myLength = length( $myStr ); $myCount = 0; $mySumInt = 0; while( $myCount < $myLength ){ $myChr = substr( $myStr, $myCount, 1 ); ++$myCount; $myInt = 0; for( $myI = 0; $myI<=255; ++$myI){ if( $myChr eq chr($myI) ){ $myInt = $myI; last;} } $mySumInt = $mySumInt + $myInt; } return( $mySumInt ); } # END sub intChr _____________________________________________________ # # Sub checkNameDir checks if in the DIR ther is DIR with name $NameDir # and returns 1 if it is found or 0 if not. # sub checkNameDir{ my( $NameDir, $CheckPath ) = @_; my @myAllNames; opendir( DIR, $CheckPath ); @myAllNames = readdir( DIR ); closedir DIR; foreach $DirName ( @myAllNames ){ if ( $DirName =~ m/$NameDir/ and $NameDir =~ m/$DirName/ ){ return( 1 ); } } return( 0 ); } # END checkNameDir _________________________________________________ # # Sub seekNrindexRTF checks if in the $BuffStr string # after control word $PrefMark ther is "d" caharacter and # returns -1 if it is found or the popsition of # the last (that is, the rightmost) match for the string. # sub seekNrindexRTF{ my( $PrefMark, $BuffStr ) = @_; my $myNrindex; my $myBuffStr; my $myEndBuff; my $myCheckMark; $myNrindex = -1; $myBuffStr = $BuffStr; $myCheckMark = $PrefMark."d"; $myCheckMark = "d"; while( $myNrindex eq -1 or $myBuffStr ne "" ){ $myNrindex = rindex($myBuffStr,$PrefMark); $myEndBuff = substr($myBuffStr,$myNrindex, length( $PrefMark )+1 ); if( !( $myEndBuff =~ /[d]/ ) ){ return( $myNrindex ); } else{ $myBuffStr0 = substr( $myBuffStr, 0, $myNrindex ); } } if( $myBuffStr eq "" ){ print " Error in sub seekNrindexRTF!\n"; print " There isn't control word - $PrefMark!\n"; } return( $myNrindex ); } # END seekNrindexRTF _________________________________________________ # # Sub seekNrindexRTF checks if in the $BuffStr string # after control word $PrefMark ther is "d" caharacter and # returns -1 if it is found or the popsition of # the last (that is, the rightmost) match for the string. # sub checkKeepQuestion{ my( $iNQ, @ArrayQuestionKeep ) = @_; my $myNumKeep; my $iKeep; $iNQ = 0+$iNQ; $myNumKeep = $#ArrayQuestionKeep+1; for( $iKeep=0; $iKeep < $myNumKeep; ++$iKeep ){ # print " iKeep=$iKeep; $ArrayQuestionKeep[ $iKeep ], iNQ =$iNQ ;\n"; if( $ArrayQuestionKeep[ $iKeep ] eq $iNQ ){ return( 1 );} } return( 0 ); }; # END sub checkKeepQuestion ______________________________________________ # # Sub fillStr inserts the number or one of caharacters (A,B,C,D,E) # in the string and this string. # sub fillStr{ my( $String, $Number, $Type ) = @_; my $lenString; my $myString; my $StrInt = "StrInt"; my @myChar = ( A, B, C, D, E ); my $myCountmyChar = $#myChar+1; $lenString = length( $String ); $myString = ""; $Number = 0+$Number; if( $Type =~ /$StrInt/ and $Number >= 0 ) { $myString = $myString.$Number."."; }else{ if( $Number >= 0 and $Number > $myCountmyChar ){ print " Number = $Number\n"; print " Error in fillStr sub! You have more than $myCountmyChar Answer!\n"; return( $myString ); }; if( $Number >= 0 ){ $myString = $myString.$myChar[$Number];}; # if( $Number >= 0 ){ $myString = $myString.$myChar[$Number].")";}; } if( $lenString < length($myString) ){ print " Error in fillStr sub! You have very short $String!\n"; return( $myString ); } while( $lenString > length($myString) ){ $myString = " ".$myString; }; return( $myString ); }; # # Sub random is Pseudo-random Number Generator. # Input - one argument: $myMaxVal >= 0 ; # retern number between 0 and the $myMaxVal;# # Used global Value: $GLOBAL_SEED_FOR_RANDOM; # This value is used to produce the same series of numbers # each time you run program. # sub random{ my( $myMaxVal ) = @_; my $mySeed; my $myiX; my $myiY; my $myiZ; my $myRandom; $myMaxVal = 0 + $myMaxVal; while( $GLOBAL_SEED_FOR_RANDOM > 2727 ) { $GLOBAL_SEED_FOR_RANDOM = int($GLOBAL_SEED_FOR_RANDOM/71); }; $myiX = $GLOBAL_SEED_FOR_RANDOM * 11; $myiY = $GLOBAL_SEED_FOR_RANDOM * 11; $myiZ = $GLOBAL_SEED_FOR_RANDOM * 11; $GLOBAL_SEED_FOR_RANDOM = $GLOBAL_SEED_FOR_RANDOM + 3; # $myiX = 171 * ( $myiX % 177 ) - 2 * ( $myiX % 177 ); $myiY = 172 * ( $myiY % 176 ) - 35 * ( $myiY % 176 ); $myiZ = 170 * ( $myiZ % 178 ) - 63 * ( $myiZ % 178 ); # if( $myiX < 0 ) { $myiX = $myiX + 30269; } if( $myiY < 0 ) { $myiY = $myiY + 30307; } if( $myiZ < 0 ) { $myiZ = $myiZ + 30323; } # $myRandom = $myiX / 30269.0 + $myiY / 30307.0 + $myiZ / 30323.0; $myRandom = abs( $myRandom - int( $myRandom ) ); if( $myMaxVal >= 0 ){ $myRandom = int( abs($myMaxVal * $myRandom)); } else{ print " Error: The argument in random sub cann't be < 0!\n"; $myRandom = -1; }; # return( $myRandom ); } # # END sub random # # # Sub randomNumVal is Pseudo-random Number of elements of @Array Generator. # Input - one argument: @Array - list of elements; # return $myRandomVal-number between 0 and the max number of @Array list, # @Array list without $myRandomVal-number and with changed order. # # sub randomNumVal{ my ( @Array ) = @_; my $myMaxNumArr = $#Array; my @myArray =(); my( $myRandomNum) = -1; my $myRandomVal = -1; my $i = 0; if( $myMaxNumArr >=0){ $myRandomNum = int( &random( $myMaxNumArr ) ); }; for( $i = 0; $i <= $myMaxNumArr; ++$i ){ if( $myRandomNum eq $i ) { $myRandomVal = $Array[$i]; }else{ unshift( @myArray, $Array[$i] ) }; }; if( $myRandomVal < 0 ) { print " You have wrong random number in sub randomNumVal!"; return( -1 ); }; return( $myRandomVal, @myArray ); }; # # END randomNumVal # # # Sub getNumQuestions get information from @myList list: # Input: # $NumSection - number section, # $KeepMark - mark for question which needs to keep same position in the exam file # @myList - the list includes information about dividing the exam file on sections, # questions, answers and another markup information. # Return: # $mySectionMark - markup: random questions in this section or not. # $myNumQuestion - number of questions in this section # @myArrayQuestionKeep - the list with information about which question needs # to keep same position. # sub getNumQuestions{ my ( $NumSection, $KeepMark, @myList ) = @_; my $myNumLine = $#myList; my $myNumSection = 0; my $BuffNumQuestion = 0; my $myNumQuestion = 0; my $myStr3 = ""; my $mySectionMark; my $myBuffSectionMark; my $myBuffQuestionMark; my $myBuffQuestionKeep; my @myArrayQuestionKeep; my $myNumQuestion; my $myQuestionPerPage; my $i; $NumSection = 0+$NumSection; @myArrayQuestionKeep = (); for( $i = 0; $i <= $myNumLine; ++$i ){ ( $myBuffSectionMark, $myNumSection, $myBuffQuestionMark, $myBuffQuestionKeep,$myQuestionPerPage, $BuffNumQuestion, $myStr3 ) = split(/[","]/, $myList[$i] ); $myNumSection = 0+$myNumSection; $myNumQuestion = 0+$BuffNumQuestion; if( $myNumSection eq $NumSection and $myBuffQuestionKeep =~ /$KeepMark/ ) { push( @myArrayQuestionKeep, $myNumQuestion ); } }; if( $myNumLine eq $NumSection ) { ( $mySectionMark, $myNumSection, $myBuffQuestionMark, $myBuffQuestionKeep,$myQuestionPerPage, $myNumQuestion, $myStr3 ) = split(/[","]/, $myList[$myNumLine] ); return( $mySectionMark, $myNumQuestion, @myArrayQuestionKeep ); }; $myNumQuestion = 0; for( $i = 0; $i <= $myNumLine; ++$i ){ ( $myBuffSectionMark, $myNumSection, $myBuffQuestionMark, $myBuffQuestionKeep, $myQuestionPerPage, $BuffNumQuestion, $myStr3 ) = split(/[","]/, $myList[$i] ); $myNumSection = 0+$myNumSection; if( $myNumSection > $NumSection ) { return( $mySectionMark, $myNumQuestion, @myArrayQuestionKeep ); } $myNumQuestion = 0+$BuffNumQuestion; $mySectionMark = $myBuffSectionMark ; }; if( $myNumSection eq $NumSection ) { return( $mySectionMark, $myNumQuestion, @myArrayQuestionKeep ); } print " You have wrong number $NumSection for Section in sub getNumQuestion !"; return( "", -1, @myArrayQuestionKeep ); } # END sub getNumQuestions # # Sub getNumAnswers get information from @myList list: # Input: # $NumSection - number section, # $NumQuestion - number question, # @myList - the list includes information about dividing the exam file on sections, # questions, answers and another markup information. # Return: # $myQuestionMark - markup: random answers in this question or not. # $myQuestionPerPage - markup: how many question keeps per page. # $myNumQuestion - number of answers in this question. # sub getNumAnswers{ my ( $NumSection, $NumQuestion, @myList ) = @_; my $myNumLine = $#myList+1; my $myNumSection = 0; my $myNumQuestion = 0; my $myNumAnswers = 0; my @myListAnswers = (); my $myMark; my $myBuffSectionMark; my $myBuffQuestionKeep; my $myQuestionMark; my $myQuestionPerPage; my $i; $NumSection = 0+$NumSection; $NumQuestion = 0+$NumQuestion; for( $i = 0; $i <=$myNumLine; ++$i ){ ( $myBuffSectionMark, $myNumSection, $myQuestionMark, $myBuffQuestionKeep,$myQuestionPerPage, $myNumQuestion, @myListAnswers ) = split(/[","]/, $myList[$i] ); # print " myList[$i]=$myList[$i];\n"; # print " myQuestionMark=$myQuestionMark; myBuffQuestionKeep=$myBuffQuestionKeep; myQuestionPerPage=$myQuestionPerPage; myNumQuestion=$myNumQuestion;\n"; $myNumQuestion = 0+$myNumQuestion; $myNumSection = 0+$myNumSection; if( $NumQuestion eq $myNumQuestion and $myNumSection eq $NumSection ){ $myNumAnswers = $#myListAnswers; return( $myQuestionMark,$myQuestionPerPage, $myNumAnswers ); }; }; print " You have wrong number $NumSection for Section or number $NumQuestion for Question in sub getNumAnswers !"; return( "",-1, -1 ); } # END sub getNumAnswers # # main program # $TheExamFile = $ARGV[0]; $TheNumberOfExam = 0 + $ARGV[1]; if( $TheExamFile eq "" ){ print " Input a name of EXAM file: "; $TheExamFile = ; chomp( $TheExamFile ); print " Input a number of versins of EXAM files: "; $TheNumberOfExam = 0 + ; } $TheARGV3 = $ARGV[2]; $TheExtensionFile = substr($TheExamFile,rindex($TheExamFile,".")); $myNameTitle =""; @mySectionQA = (); @mySecQuestionA = (); @myLocalQuestions = (); @mySecQuestAnswers =(); @myLocalQuestionAnswers = (); @myLocalAnswers = (); $myLocalSecQuestAnswers =" 0, 0"; #=========== Definition Global Values and Mark for Program ================================================================================= $GLOBAL_SEED_FOR_RANDOM = 175; # Default seed's value for random function. $cBeginMark="&"; # First character in MarkUp String for ExamName.rtf file. $sSeparateLineQuestion = $cBeginMark."SeparateLineQuestion";# MarkUp for a separate line between questions for ExamName.rtf file. $sSeparateLineSection = $cBeginMark."SeparateLineSection"; # MarkUp for a separate line between sections for ExamName.rtf file. $sTitle = $cBeginMark."MainTitle"; # MarkUp for the title for ExamName.rtf file. $sSection = $cBeginMark."Section"; # MarkUp for the section without random order for ExamName.rtf file. $sSectionR = $cBeginMark."SectionR"; # MarkUp for the section with random order for ExamName.rtf file. $sQuestion = $cBeginMark."Question"; # MarkUp for the question without random order for ExamName.rtf file. $sQuestionR = $cBeginMark."QuestionR"; # MarkUp for the question with random order for ExamName.rtf file. $sEndAnswers = $cBeginMark."EndAnswers"; # MarkUp for the End of answers for question for ExamName.rtf file. $sEndQuestions= $cBeginMark."EndQuestions"; # MarkUp for the End of questions for question for ExamName.rtf file. $BlankEndAnswers = " "; $sAnswer = $cBeginMark."A"; # MarkUp for the answer for program. $sAnswerA = $cBeginMark."A"; # MarkUp for the answer for ExamName.rtf file. $sAnswerB = $cBeginMark."B"; # MarkUp for the answer for ExamName.rtf file. $sAnswerC = $cBeginMark."C"; # MarkUp for the answer for ExamName.rtf file. $sAnswerD = $cBeginMark."D"; # MarkUp for the answer for ExamName.rtf file. $sAnswerE = $cBeginMark."E"; # MarkUp for the answer for ExamName.rtf file. $sEndExam = $cBeginMark."EndExam"; # MarkUp for the end of ExamName.rtf file where the program takes a title, sections, questions and aswers. $RamMark = " R"; # MarkUp for random sub for program. $KeepMark = "Keep"; # MarkUp for the question that keeps same position in all version of ExamName.rtf files. $TheExamKeyText = "ExamKeyText"; # First part in name of key file for EXAM $TheNameForDir = "Exam"; # First part in name of dir for EXAM $NotRamMark = " "; # $NotKeepMark = " "; # $PrefMarkRTF = "\\par "; $NewPageMark = "\\page "; $PrefMarkHTM = "

"; $PrefMarkTEX = "TEX"; $ExtensionRTF = ".rtf"; $ExtensionTEX = ".tex"; $ExtensionHTM = ".htm"; $PrefMark = ""; $TheNameForExamNFile = ""; $myMarkingScheme ="MarkingScheme=3,0,1,0 # correct, wrong, blank, bonus \n"; #========================================================================================================================================= if( lc($TheExtensionFile) =~ /$ExtensionRTF/ ){ $PrefMark = $PrefMarkRTF; } if( lc($TheExtensionFile) =~ /$ExtensionHTM/ ){ $PrefMark = $PrefMarkHTM; } ################################################################################### if( lc($TheExtensionFile) =~ /$ExtensionTEX/ ){ $PrefMark = $PrefMarkTEX; } if( $PrefMark eq "" ){ print " You can use only $ExtensionRTF or $ExtensionHTM files!"; print " Press to continue!"; $SSS = ; exit; } #################################################################################### $myStrVal = ""; $myKeyStart = 0; $myBuffStr = ""; $myStartLine =""; $myEndLine = ""; if( !open( INEXAM, $TheExamFile ) ) { $myCodeError = 1; print "The $TheExamFile file could not be found. \n"; print " Press to continue!"; $SSS = ; exit; } binmode( INEXAM ); $SizeFile = (-s $TheExamFile ); sysread( INEXAM, $TheBuff, $SizeFile); $myNameRange = ""; $TheChar = '1'; $StartWord = 0; $TheWord = ""; $myBuffStr = ""; $StartBuffStr = 1; $NumChar = 0; $KeyTop = 0; $TopFile = ""; $NumTitle = 0; $NumSection = 0; $NumQuestion = 0; $NumAnswer = 0; $mySeparateLineQuestion = ""; $mySeparateLineSection = ""; $NumChar = -1; $TheBottomFile =""; $FirstBuffStr = 0; $TotlQuestion = 0; $MaxNumQuestion = 0; $PrefForBuff =""; $cBackSlash ="\\"; ############################################################ print " Please wait! ... Program reads file $TheExamFile!\n"; ############################################################ #-------------------------------------------------------------- # BEGIN LOOP FOR READ THEBUFF #-------------------------------------------------------------- while( $NumChar <= $SizeFile ){ ++$NumChar; $TheChar = substr( $TheBuff,$NumChar,1); $BuffBackSlash = ""; if( $StartWord eq 1 and $TheChar eq $cBackSlash ){ while( !($TheChar =~/\s/) ){ $BuffBackSlash = $BuffBackSlash.$TheChar; ++$NumChar; $TheChar = substr( $TheBuff,$NumChar,1); }; $BuffBackSlash = $BuffBackSlash.$TheChar; ++$NumChar; $TheChar = substr( $TheBuff,$NumChar,1); } if( !( $TheChar =~ /$cBeginMark/ ) and $StartWord eq 1 and $TheChar =~ /\W/ ){ $TheChar = $BuffBackSlash.$TheChar; $StartWord = 0; } if( $StartWord eq 1 ){ $TheWord = $TheWord.$TheChar; } if( $TheChar =~ /$cBeginMark/ ){ $TheWord = $TheChar; $StartWord = 1; $StartBuffStr = 0; } if( $TheWord ne "" and $StartWord eq 0 ){ $myStrVal = ""; if( $TheWord =~ /$sSeparateLineQuestion/ ){ $myStrVal = $sSeparateLineQuestion; }; if( $TheWord =~ /$sSeparateLineSection/ ){ $myStrVal = $sSeparateLineSection; }; if( $TheWord =~ /$sTitle/ ){ $myStrVal = $sTitle; }; if( $TheWord =~ /$sEndAnswers/ ){ $myStrVal = $sEndAnswers; }; if( $TheWord =~ /$sEndQuestions/ ){ $myStrVal = $sEndQuestions; }; if( $TheWord =~ /$sSection/ ){ $mySectionMarkR = $NotRamMark; $myStrVal = $sSection; if( $TheWord =~ /$sSectionR/ ){ $myStrVal = $sSection." "; $mySectionMarkR = $RamMark; }; }; if( $TheWord =~ /$sQuestion/ ){ $myQuestionMarkR = $NotRamMark; $myQuestionKeep = $NotKeepMark; $myQuestionPerPage = 0; $myStrVal = $sQuestion; $TheWordR = $TheWord; $TheWordR =~ s/\d//g; $TheWordR =~ s/$KeepMark//g; # print " TheWordR=$TheWordR; sQuestionR=$sQuestionR; RamMark=$RamMark;\n"; if( $TheWordR =~ /$sQuestionR/ ){ $myQuestionMarkR = $RamMark; $myStrVal = $myStrVal.$NotRamMark; }; if( $TheWord =~ /$KeepMark/ ){ $myQuestionKeep = $KeepMark; $myStrVal = $myStrVal.$NotKeepMark; }; if( $TheWord =~ /\d/ ){ $myQuestionPerPage = $TheWord; $myQuestionPerPage =~ s/\D//g; $myQuestionPerPage = 0 + $myQuestionPerPage; $myStrVal =~ s/\d/ /g; }; # print " myStrVal=$myStrVal; myQuestionMarkR=$myQuestionMarkR; myQuestionKeep=$myQuestionKeep; myQuestionPerPage$myQuestionPerPage;\n"; }; $TheUCWord = uc($TheWord); if( $TheUCWord =~ /$sAnswerA/ and $sAnswerA =~ /$TheUCWord/ or $TheUCWord =~ /$sAnswerB/ and $sAnswerB =~ /$TheUCWord/ or $TheUCWord =~ /$sAnswerC/ and $sAnswerC =~ /$TheUCWord/ or $TheUCWord =~ /$sAnswerD/ and $sAnswerD =~ /$TheUCWord/ or $TheUCWord =~ /$sAnswerE/ and $sAnswerE =~ /$TheUCWord/ ){ $myStrVal = $sAnswer; }; if( $TheWord =~ /$sEndExam/ ){ $myStrVal = $sEndExam; }; if( $myNameRange ne "" and $myStrVal ne "" ){ ########################################################################################## if( $PrefMark eq $PrefMarkHTM ){ $UCrindex = rindex($myBuffStr,uc($PrefMark)); $LCrindex = rindex($myBuffStr,lc($PrefMark)); if( $UCrindex > $LCrindex ){ $Nrindex = $UCrindex; } else{ $Nrindex = $LCrindex; } }else{ $Nrindex = rindex($myBuffStr,$PrefMark); } if( $Nrindex < 0 and $PrefMark ne $PrefMarkTEX ) { print "\n ############################################################\n"; print " You have wrong file! Each MarkUp must to begin new line!\n"; print " Press to continue!\n"; print " ############################################################\n"; $SSS = ; exit; } ####################################################################################### $myCopyStr = $myBlank.$PrefForBuff.$myNameRange.substr( $myBuffStr, 0, $Nrindex ); $PrefForBuff = substr($myBuffStr,$Nrindex); $myBuffStr = $TheChar; $FirstBuffStr = 1; $myBlank = ""; if( $myNameRange =~ /$sSeparateLineQuestion/ ){ ############################################################ print " $myNameRange .... complete!\n"; ############################################################ $mySeparateLineQuestion = $myCopyStr; } if( $myNameRange =~ /$sSeparateLineSection/ ){ ############################################################ print " $myNameRange .... complete!\n"; ############################################################ $mySeparateLineSection = $myCopyStr; } if( $myNameRange =~ /$sTitle/ ){ ############################################################ print " $myNameRange .... complete!\n"; ############################################################ $myNameTitle = $myCopyStr; if( $NumTitle > 0 ) { print " You can have two $sTitle in file !\n";} ++$NumTitle; $myLocalQuestionAnswers =(); $myLocalSecQuestAnswers = $mySectionMarkR.", 0, 0"; $mySecQuestionA = (); $myLocalQuestionEnd = (); @mySectionQA = (); $myLocalSectionEnd = (); $NumSection = -1; $NumQuestion = -1; $NumAnswer = -1; } if( $myNameRange =~ /$sSection/ ){ ++$NumSection; $ShowNum = $NumSection+1; ############################################################ print " $myNameRange.$ShowNum ....\n"; ############################################################ $mySectionQA[$NumSection] = $myCopyStr; $myLocalSectionEnd[$NumSection] = ""; if( $NumSection > 0 ){ push( @myNumSecQuestAnswers, $myLocalSecQuestAnswers ); } $myLocalSecQuestAnswers = ""; $myLocalSecQuestAnswers = $mySectionMarkR. ", ".$NumSection.", 0"; if( $MaxNumQuestion < $NumQuestion ){ $MaxNumQuestion = $NumQuestion;} $NumQuestion = -1; $NumAnswer = -1; } if( $myNameRange =~ /$sEndQuestions/ ){ ########################################################### print "\n sEndQuestions => $sEndQuestions .... complete!\n"; ############################################################ $myLocalSectionEnd[$NumSection] = $myCopyStr; ########################################################!!!!!!!!!!!!!!!!!!!! # $myBlank = $myCopyStr; # $myBlank =~ s/$sEndQuestions/$BlankEndAnswers/g; ########################################################!!!!!!!!!!!!!!!!!!!! } if( $myNameRange =~ /$sQuestion/ ){ ++$NumQuestion; ++$TotlQuestion; $ShowNum = $NumQuestion+1; ############################################################ print "\n $myNameRange.$ShowNum .... "; ############################################################ if( $NumSection < 0 ){ print " Error!!!\n"; print " You have not $sSection befor $sQuestion!\n"; print " Press to continue!"; $SSS = ; exit; } $mySecQuestionA[$NumSection][$NumQuestion] = $myCopyStr; $myLocalQuestionEnd[$NumSection][$NumQuestion] = ""; if( $NumQuestion > 0 ){ push( @myNumSecQuestAnswers, $myLocalSecQuestAnswers );} $myLocalSecQuestAnswers =$mySectionMarkR.", ".$NumSection.",".$myQuestionMarkR.",".$myQuestionKeep.", ".$myQuestionPerPage.", ".$NumQuestion; # print " myStrVal=$myStrVal; myQuestionMarkR=$myQuestionMarkR; myQuestionKeep=$myQuestionKeep; myQuestionPerPage$myQuestionPerPage;\n"; # print " myLocalSecQuestAnswers=$myLocalSecQuestAnswers;"; # $rrr=; $NumAnswer = -1; } if( $myNameRange =~ /$sEndAnswers/ ){ ########################################################### print "\n sEndAnswers => $sEndAnswers .... complete!\n"; ############################################################ $myLocalQuestionEnd[$NumSection][$NumQuestion] = $myCopyStr; ########################################################!!!!!!!!!!!!!!!!!!!! # $myBlank = $myCopyStr; # $myBlank =~ s/$sEndAnswers/$BlankEndAnswers/g; ########################################################!!!!!!!!!!!!!!!!!!!! } if( $myNameRange =~ /$sAnswer/ ){ ++$NumAnswer; $ShowNum = $NumAnswer+1; ############################################################ print " $myNameRange.$ShowNum,"; ############################################################ if( $NumSection < 0 or $NumQuestion < 0 ){ print " Error!!!\n"; print " You have not $sSection or $sQuestion befor $sAnswer !\n"; print " Press to continue!"; $SSS = ; exit; } $myLocalQuestionAnswers[$NumSection][$NumQuestion][$NumAnswer] = $myCopyStr; $myLocalSecQuestAnswers = $myLocalSecQuestAnswers.", ".$NumAnswer; } if( $myStrVal =~ /$sEndExam/ ){ push( @myNumSecQuestAnswers, $myLocalSecQuestAnswers ); ############################################################ print "\n All questions and answers complete!\n"; ############################################################ if( $MaxNumQuestion < $NumQuestion ){ $MaxNumQuestion = $NumQuestion;} $TheBottomFile= substr( $TheBuff,$NumChar); $NumChar = $SizeFile+1; } } if( $myStrVal eq "" ) { $myBuffStr = $myBuffStr.$TheWord; $StartBuffStr = 1; }else{ if( $myNameRange eq "" ){ ############################################################ print " The header of file .... complete!\n"; ############################################################ $TopFile = $myBuffStr; $myBuffStr = $TheChar; $FirstBuffStr = 1; } $myNameRange = $myStrVal; $StartBuffStr = 1; } $TheWord = ""; } #___ End Check $TheWord _________________________________________ if( $StartBuffStr eq 1 and $FirstBuffStr eq 0 ){ $myBuffStr = $myBuffStr.$TheChar; } if( $FirstBuffStr eq 1 ){ $FirstBuffStr = 0; } } #___ End Read $TheChar _________________________________________ #-------------------------------------------------------------- # END LOOP FOR READ THEBUFF if( !($myStrVal =~ /$sEndExam/) ){ print "\n ############################################################\n"; print " $TheExamFile file hasn't $sEndExam MarkUp!!! \n"; print " Press to continue!"; print "\n ############################################################\n"; $SSS = ; exit; } #-------------------------------------------------------------- #--- Last push in @myNumSecQuestAnswers ... ------------------ if( $myNameRange =~ /$sAnswer/ ){ push( @myNumSecQuestAnswers, $myLocalSecQuestAnswers ); } #--- Last push in @myNumSecQuestAnswers ... ------------------ close( INEXAM ); # $TheNumberOfExam = 5; # --------------------------------------------------------------- # # Keep trac of the time # |----------------------------------------------------------- ( $Second, $Minute, $Hour, $DayOfMonth, $Month, $Year, $WeekDay, $DayOfYear, $IsDST ) = localtime( time ); $RealMonth = $Month + 1; $RealYear = $Year + 1900; $RealDate = "$RealMonth/$DayOfMonth/$RealYear "; $RealTime = "$Hour:$Minute:$Second"; if( $TheARGV3 ne ""){ $GLOBAL_SEED_FOR_RANDOM = &intChr( $TheARGV3 ); } ###################### ## $myPath = $PathDir."."; $myPath = ".".$cBackSlash; $NumberDir = 0; $NameDir = $TheNameForDir; while( &checkNameDir($NameDir, $myPath ) eq 1 ){ $NameDir = $TheNameForDir.++$NumberDir; } if( $NumberDir ne 0 ){ $TheExamKeyText = $TheExamKeyText.$NumberDir; }; $TheExamKeyText = $TheExamKeyText.".txt"; ################################################################################################################# # $NumberFile = 0; # $CheckName = $TheExamKeyText.".txt"; # while( &checkNameDir($CheckName, $myPath ) eq 1 ){ $CheckName = $TheExamKeyText.++$NumberFile.".txt"; } # $TheExamKeyText = $CheckName; ################################################################################################################# mkdir( $NameDir, 0755 ); # $myPath = $myPath.$NameDir."\\"; $myPath = $myPath.$NameDir.$cBackSlash; $TypeInt = "StrInt"; $TypeChar = "StrChar"; $MaxNumQuestion = $MaxNumQuestion + 1; if( !open( OUTKEYFILE, ">$TheExamKeyText" ) ) { $myCodeError = 1; print "The file $TheExamKeyText could not be found. \n"; print " Press to continue!"; $SSS = ; exit; } print OUTKEYFILE "Key for $TheExamFile !\n"; print OUTKEYFILE $myMarkingScheme; print OUTKEYFILE "Date:$RealDate; Time:$RealTime\n"; print OUTKEYFILE "MaxNumQuestion=$MaxNumQuestion\n"; print OUTKEYFILE "TotlNumQuestion=$TotlQuestion\n"; $MaxNumSection=$NumSection+1; print OUTKEYFILE "MaxNumSection=$MaxNumSection\n"; print OUTKEYFILE "TotlNumberExams=$TheNumberOfExam\n"; $myStrNumber = &fillStr( $sSeparateLineQuestion, -1, $TypeInt ); $mySeparateLineQuestion =~ s/$sSeparateLineQuestion/$myStrNumber/g; $myStrNumber = &fillStr( $sSeparateLineSection, -1, $TypeInt ); $mySeparateLineSection =~ s/$sSeparateLineSection/$myStrNumber/g; $myStrNumber = &fillStr( $sTitle, -1, $TypeInt ); $myNameTitle =~ s/$sTitle/$myStrNumber/g; for( $iExam=0; $iExam <= $TheNumberOfExam; ++$iExam ){ print OUTKEYFILE "Exam".$iExam."\n"; $TheExamNFile = $myPath.$TheNameForExamNFile.$iExam.$TheExtensionFile; if( !open( OUTFILE, ">$TheExamNFile" ) ) { $myCodeError = 1; print "The file $TheExamNFile could not be found. \n"; print " Press to continue!"; $SSS = ; exit; } binmode( OUTFILE ); $BuffTopFile = $TopFile.$NewPageMark; syswrite( OUTFILE, $BuffTopFile, length($BuffTopFile) ) ; syswrite( OUTFILE, $myNameTitle, length($myNameTitle) ); @ArraySections = (); $TotlQuestion = 0; $NowQuestionInPage = 0; $OldMarkQuestionInPage = 1000; $CheckMarkQuestionInPage = 0; for( $iZ=0; $iZ <= $NumSection; ++$iZ ){ push( @ArraySections, $iZ ) }; for( $iS = 0; $iS <=$NumSection; ++$iS ){ $iSR = $iS; ######## NOT RANDOM SECTION if($iExam ne 0 ){ ($iSR, @ArraySections ) = &randomNumVal( @ArraySections ); } $myBuffStr = $mySectionQA[$iSR]; #----------------------------------------------------------------------------- $myStrNumSection =""; if( $PrefMark ne $PrefMarkTEX ) { $myStrNumSection = &fillStr( $sSection, -1, $TypeInt); } $myBuffStr =~ s/$sSection/$myStrNumSection/g; #----------------------------------------------------------------------------- #print " \n Section myBuffStr=\n $myBuffStr \n __________________"; ######################### syswrite( OUTFILE, $myBuffStr, length($myBuffStr) ); ( $mySectionMarkR, $NumQuestions, @ArrayQuestionKeep ) = &getNumQuestions( $iSR, $KeepMark, @myNumSecQuestAnswers ); # print " mySectionMarkR=$mySectionMarkR, NumQuestions=$NumQuestions, ArrayQuestionKeep=@ArrayQuestionKeep\n"; $NumForPrint = $NumQuestions+1; if( $iExam eq 0 ){ print OUTKEYFILE $NumForPrint; } @ArrayQuestions = (); for( $iZ=0; $iZ <= $NumQuestions; ++$iZ ){ ( $KeepQuestion ) = &checkKeepQuestion( $iZ, @ArrayQuestionKeep ); if( $KeepQuestion eq 0 ){ push( @ArrayQuestions, $iZ ); } }; for( $iQ = 0; $iQ <= $NumQuestions; ++$iQ ){ $iQR = $iQ; if( $iExam ne 0 ){ ( $KeepQuestion ) = &checkKeepQuestion( $iQR, @ArrayQuestionKeep ); if( $mySectionMarkR =~ /$RamMark/ and $KeepQuestion eq 0 ){ ($iQR, @ArrayQuestions ) = &randomNumVal( @ArrayQuestions ); }; $NumiSR = $iSR + 1; $NumiQR = $iQR + 1; print OUTKEYFILE $NumiSR." ".$NumiQR; # print " KeepQuestion=$KeepQuestion; NumiSR=$NumiSR; NumiQR=$NumiQR;\n"; # $SSS = ; } $myBuffStr = $mySecQuestionA[$iSR][$iQR]; ($myQuestionMarkR, $myQuestionPerPage, $NumAnswers) = &getNumAnswers( $iSR, $iQR, @myNumSecQuestAnswers ); # print " myQuestionMarkR=$myQuestionMarkR; myQuestionPerPage=$myQuestionPerPage; NumAnswers=$NumAnswers;\n"; $NumForPrint = $NumAnswers+1; ++$NowQuestionInPage; if( $OldMarkQuestionInPage > $myQuestionPerPage ) { $OldMarkQuestionInPage = $myQuestionPerPage; }; if( $myQuestionPerPage != 0 and $OldMarkQuestionInPage < $NowQuestionInPage ){ $OldMarkQuestionInPage = $myQuestionPerPage; $myBuffStr = $NewPageMark.$myBuffStr; $NowQuestionInPage = 1; } #----------------------------------------------------------------------------- ++$TotlQuestion; $myStrNumQuestion =""; if( $PrefMark ne $PrefMarkTEX ) { $myStrNumQuestion = &fillStr( $sQuestion, $TotlQuestion, $TypeInt ); } $myBuffStr =~ s/$sQuestion/$myStrNumQuestion/g; #----------------------------------------------------------------------------- # print " \n Question myBuffStr=\n $myBuffStr \n __________________"; # $SSS = ; # syswrite( OUTFILE, $myBuffStr, length($myBuffStr) ); if( $iExam eq 0 ){ print OUTKEYFILE " ".$NumForPrint; } # @ArrayAnswers = (); for( $iZ=0; $iZ <= $NumAnswers; ++$iZ ){ push( @ArrayAnswers, $iZ ) }; for( $iA = 0; $iA <= $NumAnswers; ++$iA ){ $iAR = $iA; if( $iExam ne 0 ){ if( $myQuestionMarkR =~ /$RamMark/ ){($iAR, @ArrayAnswers ) = &randomNumVal( @ArrayAnswers ); } # print " 1= $myQuestionMarkR; $RamMark; iAR=$iAR; iAR=$iAR;\n"; $NumiAR= $iAR + 1; print OUTKEYFILE " ".$NumiAR; # print " myQuestionMarkR=$myQuestionMarkR; iAR=$iAR; NumiAR =$NumiAR; ArrayAnswers=@ArrayAnswers;"; # $SSS = ; } $myBuffStr = $myLocalQuestionAnswers[$iSR][$iQR][$iAR]; #----------------------------------------------------------------------------- $myStrNumAnswer =""; if( $PrefMark ne $PrefMarkTEX ) { $myStrNumAnswer = &fillStr( $sAnswer, $iA, $TypeChar ); } $myBuffStr =~ s/$sAnswer/$myStrNumAnswer/g; #----------------------------------------------------------------------------- syswrite( OUTFILE, $myBuffStr, length($myBuffStr) ); }; $myBuffStr = $myLocalQuestionEnd[$iSR][$iQR]; # $myBuffStr =~ s/$sEndAnswers/$BlankEndAnswers/g; $myBuffStr =~ s/$sEndAnswers//g; syswrite( OUTFILE, $myBuffStr, length($myBuffStr) ); if( $iExam ne 0 ){ print OUTKEYFILE "\n"; } syswrite( OUTFILE, $mySeparateLineQuestion, length($mySeparateLineQuestion) ); syswrite( OUTFILE, $mySeparateLineQuestion, length($mySeparateLineQuestion) ); }; $myBuffStr = $myLocalSectionEnd[$iSR]; # $myBuffStr =~ s/$sEndQuestions/$BlankEndAnswers/g; $myBuffStr =~ s/$sEndQuestions//g; syswrite( OUTFILE, $myBuffStr, length($myBuffStr) ); if( $iExam eq 0 ){ print OUTKEYFILE "\n"; } syswrite( OUTFILE, $mySeparateLineSection, length($mySeparateLineSection) ); }; syswrite( OUTFILE, $TheBottomFile, length($TheBottomFile) ); close( OUTFILE ); print OUTKEYFILE "END Exam".$iExam."\n"; ############################################################ print " File - $TheExamNFile .... complete!\n"; ############################################################ } close( OUTKEYFILE ); print " $PathDir Press to continue!"; $SSS = ; # |--------------