How to fix corrupt text pointers
Attached isa spec called FIXBADTEXT.SPXthat will try to fix up as much corrupted text area as possible. In particular this will try to fix up records that have textareastatus=5 that neither ~adjust nor rawcopy can fix up.
If you have a lot of cases with corrupted text area (textareastatus>2) then you may need to increase the amount of core that Mentor needs to run this proc.
mentor fixbadtext.spx -fixbadtext.out
If there are either no cases with corrupted text, or no cases with text, the program does not create an output file, because it would be no different than the input file.
Change the following two defines:Set Input to the name of your Input TR fileSet CaseIDloc to location of the CASE IDSet Output to the name of the TR file you want to create>Define @Input BadText>Define @CaseIDLoc 1.4>Define @Output GoodTextYou need to set the following define, so the program will know where the textarea Starts on this Case. If this is incorrectly specified, this program will either incorrectly error on every case, or produce no output at all.>Define @TextStart 201 ''Where Text Starts in Data casesYou can change the following define if the program is unable to convert all the quoted strings correctly. You can change the quotes to any other character you want.'>Define @ChangeQuotes 'You can comment out the next line to save all the intermediate files>Define @DelTemp** 11/21/06 ** Changed printfile to always be 300 Add defines for Case ID location** 06/22/07 ** Fixed bug with CaseID= not on ~Input line (7.7 Problem)***************** YOU SHOULD NOT MODIFY LINES BELOW ************************************** UNLESS YOU ARE SURE WHAT YOU ARE DOING **********************>Define @CreateFiles>Define @RunProc''>Define @Debug>PurgeSame>LocFormat 1~In $~Out Fxtex^aux,ASCII,Len=40>IfDef @MPE>Else TrimBlanks>Endif~Def Proc= Makeaux:Blank [1-40$]Modify [1.20$] = ">Define @Dataend">FillDefinesInQuotesModify [21.10$] = "@TextStart">-FillDefinesInQuotesIf [22,...,28#"/"] Then While True Copy [22-31] = [21-30] Blank [21] If [28#"/"] Then Modify [21.10] = (([21.7] - 1) * 80) + Max([29.2],[29]) - 1 Goto OutWhile Endif EndWhileOutWhile:Else Modify [21.10] = @TextStart - 1EndifWriteCase }~EXC PROC= MAKEAUX~In @Input,textloc=@TextStart NumBuf=2 Study=Orig Dot=100~In $ NewBuf Study=Memry Len=100~Out FixTxAX2 ASCII Len=40>Ifdef @MPE>ElseTrimblanks>Endif~Set Logging>Prtfile Fixtx^Prt,-FormFeed,PgWid=300~DefNumBadText: [!1.7]NumGoodText: [!11.7]NumNoText: [!21.7]StatusFlag: [31] ''1=Bad, 2=Good, 3=No TextProc= PrintBadText:If FirstCase Choosefile "Memry" Next First Modify Memry!NumBadText = 0 Modify Memry!NumGoodText = 0 Modify Memry!NumNoText = 0 Choosefile "Orig"EndifIf TextAreaStatus > 2 Modify Memry!NumBadText += 1 Error Case_Number Dt *Else If TextAreaStatus = 2 Modify Memry!NumGoodText += 1 Else Modify Memry!NumNoText += 1 EndifEndifIf LastCase If Memry!NumBadText > 0 Modify Memry!StatusFlag = 1 Else If Memry!NumGoodText > 0 Modify Memry!StatusFlag = 2 Else Modify Memry!StatusFlag = 3 Endif Endif Choosefile "Memry" WriteCaseEndif}~Exc Proc=PrintBadText on Orig~In;>Prtfile~Set -LOGGING~In FixtxAX2 ASCII=40 ReadCase~Goto (BADTEXT,GOODTEXT,NOTEXT) [StatusFlag#1/2/3]~NOTEXT:CLeanerTermPrt "EITHER THERE IS NO TEXT IN THIS FILE OR TEXTSTART WAS INCORRECTLY SET"Say "EITHER THERE IS NO TEXT IN THIS FILE OR TEXTSTART WAS INCORRECTLY SET"~Goto (Bottom) True~GOODTEXT:CleanerTermPrt "THERE ARE NO CASES IN THIS RUN WITH CORRUPTED TEXT!!! NOTHING TO DO!!"Say "THERE ARE NO CASES IN THIS RUN WITH CORRUPTED TEXT!!! NOTHING TO DO!!"~Goto (Bottom) True~BADTEXT:In;&Fxtex^aux>IfDef @CreateFiles~In fixtx^prt,ascii=400,length=1000,numbuf=3,study=input,dot=100~In $,newbuf,study=outpt~In $,newbuf,study=memry~Output modtext1,ascii,len=132,trimblanks,#1~Output modtext2,ascii,len=132,trimblanks,#2~Output Modtext3,ascii,len=132,trimblanks,#3~DefData: [1.400$]BackPoint: [901.5]CaseNumb: [906.5]HoldCase: [401.400$]HoldCase1: [402.400$]Pending: [1]NotFirst: [!2.2]BadBack: [!4]Proc= MakeProc:If FirstCase Choosefile "Outpt" Next Choosefile "Memry" Next Choosefile "Input"Endif>Ifdef @ChangeQuotes>FillDefinesInQuotesModify Data = SubStitute(Data,"""","@ChangeQuotes")>-FillDefinesInQuotes>ElseModify Data = SubStitute(Data,"""","""""")>EndifChoosefile "Outpt"If Memry!Pending = 1 If Memry!BadBack = 0 If [1.4^B] Modify Outpt!Data = " " Join Strip(Outpt![(Data) 1.390$]) & Join " Join "" "" Join &" WriteCase #2>Repeat $a=6,86,166,246; $B=87,167,247,327 If [(Data) $A.80 ^NB] If [(Data) $B.50 ^NB] Modify Outpt!Data = " """ Join [(Data) $A.80$$L] Join & """ Join &" WriteCase #2 Else Modify Outpt!Data = " """ Join [(Data) $A.80$] Join """" Endif Endif>EndRepeat Else WriteCase #2 Blank Outpt!Data Blank Memry!Pending Endif Else If [1.4^B] Modify Outpt!Data = " Error ""Line1: " Join Strip([HoldCase$]) & Join """" WriteCase #2 Else Blank Memry!Pending Endif EndifEndifIf [1.12#" error 1:"] Modify CaseNumb = Max([14],[14.2],[14.3],[14.4],[14.5]) If Memry!NotFirst = 1 Blank Outpt!Data WriteCase #2 Modify Outpt!Data = "Endif" WriteCase #1 WriteCase #2 WriteCase #3 Blank Outpt!Data Else Modify Memry!NotFirst += 1 Endif Modify Outpt!Data = "If Case_Number = " Join Strip([CaseNumb$]) WriteCase #1 WriteCase #2 WriteCase #3 Blank Outpt!DataEndifIf [1.4#"TEX:" ] Blank Memry!Badback Modify BackPoint = Max([6],[6.2],[6.3],[6.4],[6.5]) If [BackPoint #1-@DataEnd] Else Modify Memry!Badback = 1 Endif If Memry!Badback = 0 Modify Outpt!Data = " Blank Fixed![" Join Strip([BackPoint$]) Join "]" WriteCase #1 Modify Outpt!Data = " EraseText Fixed![" Join Strip([BackPoint$]) & Join "$T]" WriteCase #3>Ifdef @Debug Modify Outpt!Data = " Error ""ET " Join Strip([BackPoint$]) Join """" WriteCase #3>Endif Endif Copy HoldCase = [15.400] While Maxtimes=20 True If [(HoldCase) 1.1#"="] Copy HoldCase = HoldCase1 Goto Out Else Copy HoldCase = HoldCase1 Endif EndWhile Out: Blank Outpt!Data WriteCase #2 If Memry!BadBack = 0 Modify Outpt!Data = " If Fixed![" Join Strip([BackPoint$]) Join "^nb] " WriteCase #2 Modify Outpt!Data = " Error ""Multiple Back Pointers to column " & Join Strip([Backpoint$]) Join " - Following Text Lost!!!""" WriteCase #2 Modify Outpt!Data = " Prt ""15gs"" Fixed![" Join Strip([Backpoint$]) Join "$T]" WriteCase #2 Modify Outpt!Data = " Endif" WriteCase #2 If [(HoldCase) 81.80 ^NB] Modify Outpt!Data = " Modify Fixed![" Join Strip([BackPoint$]) Join & "$T] = """ Join [(HoldCase) 1.80$L] Join """ Join &" WriteCase #2 Else Modify Outpt!Data = " Modify Fixed![" Join Strip([BackPoint$]) Join & "$T] = """ Join Strip([(HoldCase) 1.80$]) Join """" Endif>Repeat $a=81,161,241; $b=161,241,321 If [(HoldCase) $A.80 ^NB] If [(HoldCase) $B.80 ^NB] Modify Outpt!Data = " """ Join [(HoldCase) $A.80$$L] Join & """ Join &" WriteCase #2 Else Modify Outpt!Data = " """ Join [(HoldCase) $A.80$] Join """" Endif Endif>EndRepeat Else Modify Outpt!Data = " Error ""Following Text Dropped Due to Bad " && "back pointer""" WriteCase #2 Modify Outpt!Data = " Error ""Line1: " Join Strip([HoldCase$]) Join & """" WriteCase #2 Endif Modify Memry!Pending = 1EndifIf [1.80^B] and Memry!NotFirst = 1 Blank Outpt!Data WriteCase #2 Modify Outpt!Data = "Endif" WriteCase #1 WriteCase #2 WriteCase #3 Blank Outpt!Data Modify Memry!NotFirst += 1Endif}~Exc Proc= MakeProc on Input>Endif>IfDef @RunProc~In ;~In @Input,Textloc=@TextStart,NumBuf=2,Study=Input,Dot=100~Out @Output~In $,ID=@CaseIDLoc,Length=32000,Textloc=@TextStart,NewBuf,Study=Fixed~DefProc= Fixup:If FirstCase Choosefile "Fixed" Next First Choosefile "Input"Endif>Repeat $a=1,2; $b="No Text","Text Area is Okay"If Text_Area_Status = $A Error Summary_Only "$B" WriteCase Goto DoneEndif>EndRepeatError "Text Area Status BAD!">Repeat $a=3,4,5,6; $b="Blank Front Pointers",& "Text Area not blank after last answer",& "Bad Front Pointers, Not Blank",& "Bad Back Pointers. Very Bad!"If Text_Area_Status = $A Error "$B" Goto FixTextEndif>EndRepeatFixText:Copy Fixed![1-@DataEnd] = [1-@DataEnd]&modtext1&modtext2Choosefile "Fixed"Putid Input!Case_IDWriteCaseIf Fixed!TextAreaStatus <= 2 Error Summary_Only "Text Area Fixed"Else Error "Text Area Still Bad!!!!"EndifChoosefile "Input"&modtext3Done: }>Printfile Fixtx^log,user~Exc Proc=Fixup on Input>Endif~Bottom:Comment>Ifdef @DelTemp>Delete Fxtex^ax2>Delete Fxtex^aux>Delete Modtext1>Delete Modtext2>Delete Modtext3>Delete Fxtex^Prt>Endif~End