// Nils 2018-08-21 // Various source code refactoring functions/procedures // for the DFRefactor project. // Was lifted from the CleanMarkers.vw business process object (oBPO) // to here to make it easier to replace/add to this logic. // Wil 2018-09-03 // Moved code into a dbView subclass instead. // Use Dfclient.pkg Use SourceCode.inc Use cRemoveUnusedLocals.pkg Class cRefactorDbView is a dbView Procedure Construct_Object Forward Send Construct_Object Set Border_Style to Border_Thick Set pbAutoActivate to True Property Boolean pbToggleState True Property tRefactorActions pRefactorActions Property tRefactorCheckbox[] paRefactorCheckboxes Property String[] paCommands End_Procedure Function TimeSpanToString TimeSpan tsTime Returns String Integer iDays iHours iMinutes iSeconds iMilliseconds String sTime Move "" to sTime Move (SpanDays(tsTime)) to iDays Move (SpanHours(tsTime)) to iHours Move (SpanMinutes(tsTime)) to iMinutes Move (SpanSeconds(tsTime)) to iSeconds Move (SpanMilliSeconds(tsTime)) to iMilliSeconds If (iDays > 0) Begin // Don't show days if it is zero Move (String(iDays) + ":") to sTime End If (iHours < 10) Begin Move (sTime+"0") to sTime End Move (sTime + String(iHours) + ":") to sTime If (iMinutes < 10) Begin Move (sTime + "0") to sTime End Move (sTime + String(iMinutes) + ":") to sTime If (iSeconds < 10) Begin Move (sTime + "0") to sTime End Move (sTime + String(iSeconds) + "." + String(iMilliSeconds)) to sTime Function_Return sTime End_Function Procedure RegisterRefactorCheckbox Handle hObject tRefactorCheckbox[] aRefactorCheckboxes Get paRefactorCheckboxes to aRefactorCheckboxes Move hObject to aRefactorCheckboxes[SizeOfArray(aRefactorCheckboxes)].hObject Move (SortArray(aRefactorCheckboxes)) to aRefactorCheckboxes Set paRefactorCheckboxes to aRefactorCheckboxes End_Procedure Procedure RefactorCheckboxChanged Boolean bState Handle hObject Boolean bReportFunction tRefactorCheckbox[] aRefactorCheckboxes tRefactorCheckbox CheckboxSearch Integer iIndex Get paRefactorCheckboxes to aRefactorCheckboxes Move hObject to CheckboxSearch.hObject Move (SearchArray(CheckboxSearch, aRefactorCheckboxes)) to iIndex If (iIndex <> -1) Begin Move bState to aRefactorCheckboxes[iIndex].bChecked Move bReportFunction to aRefactorCheckboxes[iIndex].bReportFunction End Set paRefactorCheckboxes to aRefactorCheckboxes End_Procedure // Pass False to return no of selected Refactor functions. // Pass True to return no of selected Report functions. Function IsRefactorFunctions Boolean bReportFunctionsOnly Returns Integer Integer iCount iSize iRefactorFunctions tRefactorCheckbox[] aRefactorCheckboxes Move 0 to iRefactorFunctions Get paRefactorCheckboxes to aRefactorCheckboxes Move (SizeOfArray(aRefactorCheckboxes)) to iSize Decrement iSize For iCount From 0 to iSize If (bReportFunctionsOnly = False) Begin If (bReportFunctionsOnly = False and aRefactorCheckboxes[iCount].bChecked = True and aRefactorCheckboxes[iCount].bReportFunction = False) Begin Increment iRefactorFunctions End End Else Begin If (aRefactorCheckboxes[iCount].bChecked = True and aRefactorCheckboxes[iCount].bReportFunction = True) Begin Increment iRefactorFunctions End End Loop Function_Return iRefactorFunctions End_Function Function SelectedFunctions Returns Integer Integer iRefactorFunctions iReportFunctions Get IsRefactorFunctions False to iRefactorFunctions Get IsRefactorFunctions True to iReportFunctions Function_Return (iRefactorFunctions + iReportFunctions) End_Function Procedure ToggleAll tRefactorCheckbox[] aRefactorCheckboxes Boolean bState Integer iSize iCount Get pbToggleState to bState Move (not(bState)) to bState Get paRefactorCheckboxes to aRefactorCheckboxes Move (SizeOfArray(aRefactorCheckboxes)) to iSize Decrement iSize For iCount From 0 to iSize Set Checked_State of aRefactorCheckboxes[iCount].hObject to bState Loop Set pbToggleState to bState End_Procedure Procedure AddCommand String sCommand String[] Commands Get paCommands to Commands Move (Lowercase(sCommand)) to sCommand Move sCommand to Commands[SizeOfArray(Commands)] Set paCommands to Commands End_Procedure // // Command line used for testing against inline if/else statements. // Note that it is not a complete command list and that we should be careful // about commands that might be used as functions or in functions! // For example, it is by intention that none of the variable declaration commands // are added as things like If (Convert(sVer,String)="ab") would complicate our testing // // All commands can be entered case insensitive // Standalone commands can end on a end of line, such as Abort. // Other commands need more parameters and in such case we can improve our success rate // by adding a space character. // Procedure AddAllCommands String[] Empty Set paCommands to Empty //Send AddCommand "Repeat" // nope it is a function too Send AddCommand "Abort" Send AddCommand "Abort_Transaction" Send AddCommand "Activate_View " Send AddCommand "Add " Send AddCommand "Address " Send AddCommand "Append " Send AddCommand "Append_Output " Send AddCommand "Attach " Send AddCommand "Begin_Constraints" Send AddCommand "Begin_Transaction" Send AddCommand "Broadcast " Send AddCommand "Broadcast_Focus " Send AddCommand "Calc " Send AddCommand "Calculate " Send AddCommand "Call_Driver " Send AddCommand "CallStackDump " Send AddCommand "Case " Send AddCommand "Clear " Send AddCommand "Close " Send AddCommand "Close_Input" Send AddCommand "Close_Output" Send AddCommand "Constrain " Send AddCommand "Constrained_Clear " Send AddCommand "Constrained_Find " Send AddCommand "Constraint_Set" Send AddCommand "Constraint_Validate" Send AddCommand "Copy_db " Send AddCommand "Copy_Records " Send AddCommand "Copyfile " Send AddCommand "Create_Field " Send AddCommand "Create_Index " Send AddCommand "Declare_DataFile " Send AddCommand "Decrement " Send AddCommand "Delegate " Send AddCommand "Delete " Send AddCommand "Delete_db " Send AddCommand "Delete_Field " Send AddCommand "Delete_Index " Send AddCommand "Direct_Input " Send AddCommand "Direct_Output " Send AddCommand "DiskFree " Send AddCommand "EraseFile " Send AddCommand "Error " Send AddCommand "Field_Map " Send AddCommand "File_Exist " Send AddCommand "Fill_Field " Send AddCommand "Find " Send AddCommand "For " Send AddCommand "For_All " Send AddCommand "Forward " Send AddCommand "Function_Return " // you might have code that does not return a value, I'd consider that a warning Send AddCommand "Get " Send AddCommand "Get_Argument_Size " Send AddCommand "Get_Attribute " Send AddCommand "Get_Channel_Position " Send AddCommand "Get_Channel_Size " Send AddCommand "Get_Current_Directory " Send AddCommand "Get_Current_Input_Channel " Send AddCommand "Get_Current_Output_Channel " Send AddCommand "Get_Current_User_Count " Send AddCommand "Get_Date_Attribute " Send AddCommand "Get_Directory " Send AddCommand "Get_Environment " Send AddCommand "Get_Field_Value " Send AddCommand "Get_FieldNumber " Send AddCommand "Get_File_Mod_Time " Send AddCommand "Get_File_Path " Send AddCommand "Get_FileNumber " Send AddCommand "Get_Licensed_Max_Users " Send AddCommand "Get_StrictEval " Send AddCommand "Get_Transaction_Retry " Send AddCommand "Get_Windows_Directory " Send AddCommand "GetAddress " Send AddCommand "GetBuff " Send AddCommand "GetBuff_String " Send AddCommand "GetDskInfo " Send AddCommand "Global_Variable " Send AddCommand "Include_Resource " Send AddCommand "Increment " Send AddCommand "Indicate " Send AddCommand "Indicator " Send AddCommand "Load_Def " Send AddCommand "Load_Driver " Send AddCommand "Lock" Send AddCommand "Login " Send AddCommand "Logout" Send AddCommand "Make_Directory " Send AddCommand "Make_File " Send AddCommand "Make_Temp_File " Send AddCommand "Move " Send AddCommand "Movedate " Send AddCommand "Moveint " Send AddCommand "Movenum " Send AddCommand "Movereal " Send AddCommand "Movestr " Send AddCommand "NewRecord " Send AddCommand "On_Item" Send AddCommand "On_key " Send AddCommand "Open " Send AddCommand "Output " Send AddCommand "Output_Aux_File " Send AddCommand "Output_Wrap" Send AddCommand "Playwave " Send AddCommand "Procedure_Return" Send AddCommand "Property " Send AddCommand "Put " Send AddCommand "Read " Send AddCommand "Read_Block " Send AddCommand "Read_hex " Send AddCommand "Readln " Send AddCommand "Reg_Close_Key " Send AddCommand "Reg_Enum_Key " Send AddCommand "Reg_Enum_Key_Info " Send AddCommand "Reg_Enum_Value " Send AddCommand "Relate " Send AddCommand "Remove_Directory " Send AddCommand "Renamefile " Send AddCommand "Report_Breaks " Send AddCommand "Reread" Send AddCommand "RunProgram " Send AddCommand "Save " Send AddCommand "SaveRecord " Send AddCommand "Send " Send AddCommand "Set " Send AddCommand "Set_Argument_Size " Send AddCommand "Set_Attribute " Send AddCommand "Set_Channel_Position " Send AddCommand "Set_Date_Attribute " Send AddCommand "Set_Directory " Send AddCommand "Set_Field_Value " Send AddCommand "Set_File_Mod_Time " Send AddCommand "Set_Foreign_Profile_String " Send AddCommand "set_registry_root " Send AddCommand "Set_Relate " Send AddCommand "Set_StrictEval " Send AddCommand "Set_Transaction_Retry " Send AddCommand "Shift_State " Send AddCommand "Show " Send AddCommand "Showln" Send AddCommand "Sleep " Send AddCommand "Sort " Send AddCommand "Start_UI" Send AddCommand "Structure_Abort " Send AddCommand "Structure_Copy " Send AddCommand "Structure_End " Send AddCommand "Structure_Start " Send AddCommand "Subtract " Send AddCommand "Sysdate " Send AddCommand "Sysdate4 " Send AddCommand "Unload_Driver " Send AddCommand "Unlock" Send AddCommand "Valid_Drive " Send AddCommand "ValueTreeDeserializeParameter " Send AddCommand "ValueTreeSerializeParameter " Send AddCommand "VConstrain " Send AddCommand "Version_Information " Send AddCommand "VFind " Send AddCommand "Virtual_Key " Send AddCommand "WebGet " Send AddCommand "WebPublishFunction " Send AddCommand "WebPublishProcedure " Send AddCommand "WebSet " Send AddCommand "WebSetResponsive " Send AddCommand "While " Send AddCommand "Write " Send AddCommand "Write_Hex " Send AddCommand "WriteLn" Send AddCommand "ZeroFile " Send AddCommand "ZeroString " Send AddCommand "ZeroType " End_Procedure Procedure Activating Send AddAllCommands End_Procedure // Returns True if no marker is found. Function FindStudioMarker String sLine Returns Boolean Boolean bFound Move False to bFound Move (Trim(sLine)) to sLine Case Begin Case (sLine = "//AB-IgnoreStart") Move True to bFound Case Break Case (sLine = "//AB-IgnoreEnd") Move True to bFound Case Break Case (sLine = "//AB-StoreStart") Move True to bFound Case Break Case (sLine = "//AB-StoreEnd") Move True to bFound Case Break Case (sLine = "//AB-StoreTopStart") Move True to bFound Case Break Case (sLine = "//AB-StoreTopEnd") Move True to bFound Case Break Case (sLine = "//AB-PanelStoreTopStart") Move True to bFound Case Break Case (sLine = "//AB-PanelStoreTopEnd") Move True to bFound Case Break Case (sLine = "//AB-PanelStoreStart") Move True to bFound Case Break Case (sLine = "//AB-PanelStoreEnd") Move True to bFound Case Break Case (sLine = "//AB-ClientStoreTopStart") Move True to bFound Case Break Case (sLine = "//AB-ClientStoreTopEnd") Move True to bFound Case Break Case (sLine = "//AB-ClientStoreStart") Move True to bFound Case Break Case (sLine = "//AB-ClientStoreEnd") Move True to bFound Case Break Case (sLine = "//AB-DDOStart") Move True to bFound Case Break Case (sLine = "//AB-DDOEnd") Move True to bFound Case Break Case (Left(sLine, 6) = "//AB/ ") Move True to bFound Case Break Case (sLine = "//AB-MenuPackage") Move True to bFound Case Break Case (sLine = "//AB-End") Move True to bFound Case Break Case (sLine = "//AB-ToolbarPackage") Move True to bFound Case Break Case (sLine = "//AB-ViewStart") Move True to bFound Case Break Case (sLine = "//AB-ViewEnd") Move True to bFound Case Break Case (sLine = "//AB-StatusBarPackage") Move True to bFound Case Break Case (sLine = "//IDE-FileType=ftApplication") Move True to bFound Case Break Case End Function_Return (bFound = False) End_Function // RTrim trailing spaces if present. Function RemoveTrailingSpaces String ByRef sLine Returns Boolean Integer iBefore iAfter Boolean bChanged Move (Length(sLine)) to iBefore Move (RTrim(sLine)) to sLine Move (Length(sLine)) to iAfter Move (iBefore <> iAfter) to bChanged Function_Return bChanged End_Function // Removes local statement if present. Function RemoveLocal String ByRef sLine Returns Boolean Boolean bChanged String sTest Integer iPos Move False to bChanged Move (LTrim(sLine)) to sTest Move (Left(sTest, 6)) to sTest Move (Lowercase(sTest)) to sTest If (sTest = "local ") Begin // local must be the first word in the line. // Now find the local statement in the line and remove it. Move (Lowercase(sLine)) to sTest Move (Pos("local ", sTest)) to iPos If (iPos > 0) Begin Move (Remove(sLine, iPos, 6)) to sLine Move True to bChanged End End Function_Return bChanged End_Function // Note: The sKeywords string must be separated by "|" _and_ end with a "|". Function IsKeywordInLine String sKeywords String sLine Returns Boolean String sKeyword Move (Lowercase(sKeywords)) to sKeywords Move (Lowercase(sLine)) to sLine Get RemoveStringsFromLine sLine to sLine While (sKeywords <> "") Move (Left(sKeywords, (Pos("|", sKeywords)))) to sKeyword Move (Replace(sKeyword, sKeywords, "")) to sKeywords Move (Trim(Replace("|", sKeyword, ""))) to sKeyword If ((sKeyword <> "") and ((Pos((" " + sKeyword + " "), sLine)) <> 0) ) Begin Function_Return True End Loop Function_Return False End_Function // helper function for IsKeywordInLine, when a keyword is found in a string declaration Function RemoveStringsFromLine String sLine Returns String Integer iLength iPos Boolean bSep1 bSep2 String sChar sSep1 sSep2 sReturn Move False to bSep1 Move False to bSep2 Move "'" to sSep1 Move '"' to sSep2 Move "" to sReturn Move (Length(sLine)) to iLength For iPos From 1 to iLength Move (Mid(sLine, 1, iPos)) to sChar If (bSep1 = False and bSep2 = False) Begin If (sChar = sSep1) Begin Move True to bSep1 End Else If (sChar = sSep2) Begin Move True to bSep2 End If (bSep1=False and bSep2=False) Begin Move (sReturn + sChar) to sReturn End End Else Begin If (bSep1) Begin If (sChar=sSep1) Begin Move False to bSep1 End End Else If (bSep2) Begin If (sChar=sSep2) Begin Move False to bSep2 End End End Loop Function_Return sReturn End_Function // Replaces "Calc/MoveInt/MoveNum/MoveReal/MoveStr" statements to "Move" if present. Function ReplaceCalcToMoveStatement String ByRef sLine Returns Boolean Boolean bChanged bIsIn String sTest sStart sStop Integer iPos Move False to bChanged Move (Trim(sLine)) to sTest If (sTest = "") Begin Function_Return False End Move (Lowercase(sLine)) to sTest Get OverstrikeStrings sTest to sTest // Check if this is a comment line, in case we do nothing. Move (LTrim(sTest)) to sStart If (Left(sStart, 2) = CS_CommentSymbol) Begin Function_Return False End // Replaces all quotes string contents to "_" so we don't get false positives. // Check if line contains one of the keywords and that none of the keywords are within quotes. Get IsKeywordInLine "calc|moveint|movenum|movereal|movestr|" sTest to bIsIn If (bIsIn = False) Begin Function_Return False End Case Begin Case (Pos("calc ", sTest)) Move (Pos("calc ", sTest)) to iPos Move (Left(sLine, (iPos -1))) to sStart Move (Mid(sLine, CI_EOL, (iPos + 4))) to sStop Move (sStart + "Move" + sStop) to sLine Move True to bChanged Case Break Case (Pos("moveint ", sTest)) Move (Pos("moveint ", sTest)) to iPos Move (Left(sLine, (iPos -1))) to sStart Move (Mid(sLine, CI_EOL, (iPos + 7))) to sStop Move (sStart + "Move" + sStop) to sLine Move True to bChanged Case Break Case (Pos("movenum ", sTest)) Move (Pos("movenum ", sTest)) to iPos Move (Left(sLine, (iPos -1))) to sStart Move (Mid(sLine, CI_EOL, (iPos + 7))) to sStop Move (sStart + "Move" + sStop) to sLine Move True to bChanged Case Break Case (Pos("movereal ", sTest)) Move (Pos("movereal ", sTest)) to iPos Move (Left(sLine, (iPos -1))) to sStart Move (Mid(sLine, CI_EOL, (iPos + 8))) to sStop Move (sStart + "Move" + sStop) to sLine Move True to bChanged Case Break Case (Pos("movestr ", sTest)) Move (Pos("movestr ", sTest)) to iPos Move (Left(sLine, (iPos -1))) to sStart Move (Mid(sLine, CI_EOL, (iPos + 7))) to sStop Move (sStart + "Move" + sStop) to sLine Move True to bChanged Case Break Case End Function_Return bChanged End_Function Function RemovePropertyPublicPrivate String ByRef sLine String sPubPriv Returns Boolean Boolean bChanged String sTest Integer iPos Move False to bChanged Move (LTrim(sLine)) to sTest Move (Left(sTest, 9)) to sTest Move (Lowercase(sTest)) to sTest If (sTest = "property ") Begin Move (Lowercase(sLine) + " ") to sTest // add a space to the test at the end for if the keyword is at the end of the line. Move (Pos(" "+ sPubPriv + " ", sTest)) to iPos If (iPos = 0) Begin // if there's a tab char instead of a space then.. Move (Pos(Character(9) + sPubPriv + " ", sTest)) to iPos End If (iPos > 0) Begin Move (Overstrike(Repeat(" ", Length(sPubPriv)), sLine, iPos + 1)) to sLine // skip first character, don't overwrite a tab with a space Move True to bChanged End End Function_Return bChanged End_Function Function RemovePropertyPublic String ByRef sLine Returns Boolean Boolean bChanged Get RemovePropertyPublicPrivate (&sLine) "public" to bChanged Function_Return bChanged End_Function Function RemovePropertyPrivate String ByRef sLine Returns Boolean Boolean bChanged Get RemovePropertyPublicPrivate (&sLine) "private" to bChanged Function_Return bChanged End_Function Function LineEndHasBeginOrSemicolumn String sLine Returns Boolean Boolean bRemoved Boolean bStop String sTest Move sLine to sLine // dummy line which appears to fix a runtime byref error (???) Get RemoveComments (&sLine) to bRemoved Move (RTrim(sLine)) to sTest If (Right(sTest, 1) = ";") Begin Move True to bStop End If (bStop = False) Begin Move (Lowercase(sTest)) to sTest If (Right(sTest, 5) = "begin") Begin Move True to bStop End End Function_Return bStop End_Function Function RemoveComments String ByRef sLine Returns Boolean Boolean bRemoved Integer iPos Move False to bRemoved Move (Pos(CS_CommentSymbol, sLine)) to iPos If (iPos > 0) Begin Move (Left(sLine, iPos - 1)) to sLine Move True to bRemoved End Function_Return bRemoved End_Function Function RemoveEndComments String ByRef sLine Returns Boolean Boolean bChanged Boolean bRemoved String sTestLine String sTest Move False to bChanged Move (LTrim(sLine)) to sTestLine Move (Lowercase(sTestLine)) to sTestLine Move (Left(sTestLine, 10)) to sTest If (sTest = "end_class ") Begin Get RemoveComments (&sLine) to bRemoved If (bRemoved) Begin Move True to bChanged End End Move (Left(sTestLine, 11)) to sTest If (sTest = "end_object ") Begin Get RemoveComments (&sLine) to bRemoved If (bRemoved) Begin Move True to bChanged End End Move (Left(sTestLine, 13)) to sTest If (sTest = "end_function ") Begin Get RemoveComments (&sLine) to bRemoved If (bRemoved) Begin Move True to bChanged End End Move (Left(sTestLine, 14)) to sTest If (sTest = "end_procedure ") Begin Get RemoveComments (&sLine) to bRemoved If (bRemoved) Begin Move True to bChanged End End Function_Return bChanged End_Function // Tests if the lowercase character passed in sLine on position iPos is // a valid character in a class name Function IsValidClassCharacter String sLine Integer iPos Returns Boolean Boolean bIsValid String sChar Move False to bIsValid Move (Mid(sLine, 1, iPos)) to sChar If ("abcdefghijklmnopqrstuvwxyz1234567890_" contains sChar) Begin Move True to bIsValid End Function_Return bIsValid End_Function // (nicked from cSciLexer.pkg) // Sometimes a method has extra embedded spaces between its parameters. This confuses the parameter // counting and doesn't look nice in presenting in tooltip et al. // We reduce the spaces here to just one. // Procedure StripConcatenatingSpaces String ByRef sText While (Pos(" ",sText)<>0) Move (Replaces(" ",sText," ")) To sText // as doc says you can't reduce 3+ spaces to 1 without running a loop Loop End_Procedure // Rewrites Get Create U_Class to Get Create (RefClass(Class)) Function ChangeUClassToRefClass String ByRef sLine Returns Boolean Boolean bChanged Boolean bValid Boolean bIgnore String sTest String sClassName String sOldStyle sNewStyle Integer iPos Move False to bChanged Move "" to sClassName Move (Lowercase(sLine)) to sTest Move (Replaces(Character(9), sTest, " ")) to sTest // tab Send StripConcatenatingSpaces (&sTest) // Two lines which are mostly for protection when running DfRefactor on the DfRefactor code itself Get RemoveComments (&sTest) To bIgnore // Don't rewrite this in a comment Get RemoveStringsFromLine sTest To sTest // If this is in a string then obviously leave it alone too If (Pos(" create u_", sTest)) Begin Move (Lowercase(sLine)) to sTest Move (Pos("u_", sTest)) to iPos Get IsValidClassCharacter sTest iPos to bValid While (bValid) Move (sClassName + Mid(sLine, 1, iPos)) to sClassName Increment iPos Get IsValidClassCharacter sTest iPos to bValid Loop End If (sClassName <> "") Begin Move True to bChanged Move sClassName to sOldStyle Move (Right(sClassName, Length(sClassName) - 2)) to sClassName // strip away the "U_" Move ("(RefClass(" + sClassName + "))") to sNewStyle Move (Replace(sOldStyle, sLine, sNewStyle)) to sLine End Function_Return bChanged End_Function // ToDo: ChangeGetAddress // Change 'GetAddress of sVal to aAddress -> Move (AddressOf(sVal)) to aAddress' // For the function to do anything, the line needs to contain a "GetAddress" command. Function ChangeGetAddress String ByRef sLine Returns Boolean Boolean bChanged String sText Integer iPos Move False to bChanged Move sLine to sText Move (Lowercase(Trim(sText))) to sText Move (Pos("getaddress ", sText)) to iPos If (iPos = 0) Begin Function_Return bChanged End Function_Return bChanged End_Function // Change 'IN' to 'Contains' Function ChangeInToContains String ByRef sLine Returns Boolean Boolean bChanged String sPattern String sMatched sRemain sHost sSub tRegexMatch[] myReg Move (Replaces('`', '(".*"|`.*`|\S+)\s+in\s+(".*"|`.*`|\S+)', "'")) to sPattern Get Regex_Match sLine sPattern True to myReg If (SizeOfArray(myReg)) Begin Move myReg[0].Val to sMatched Move (Replaces('`', '(".*"|`.*`|\S+)\s+', "'")) to sPattern Get Regex_Match sMatched sPattern True to myReg Move (Trim(myReg[0].Val)) to sSub Move (Trim(Replace(sSub, sMatched, ''))) to sRemain // Remove the subString Move (Remove(sRemain,0 ,2)) to sRemain // Remove the 'In' Move (Replaces('`', '\s+(".*"|`.*`|\S+)', "'")) to sPattern Get Regex_Match sRemain sPattern True to myReg Move (Trim(myReg[0].Val)) to sHost Move True to bChanged Move (Replace(sMatched, sLine, ("(" + sHost + ' contains ' + sSub + ")"))) to sLine End Function_Return bChanged End_Function // ToDo: ChangeCompareOperators // Change 'If sTmp Ne '' Begin -> If (sTmp <> '') Begin' Function ChangeCompareOperators String ByRef sLine Returns Boolean Boolean bChanged String sText Move False to bChanged Move sLine to sText Move (Lowercase(Trim(sText))) to sText Function_Return bChanged End_Function Function TestCommands String sTest Returns Integer Boolean bRemoved Integer iCount iSize iPos iTest String sCommand String[] asCommands Move 0 to iPos Get RemoveComments (&sTest) to bRemoved Get paCommands to asCommands Move (SizeOfArray(asCommands)) to iSize Decrement iSize For iCount From 0 to iSize Move asCommands[iCount] to sCommand Move (Pos(" " + sCommand, sTest)) to iTest // The command MUST have a space before it, after it not always If (iTest <> 0) Begin If (iPos = 0) Begin Move iTest to iPos End Else Begin If (iTest < iPos) Begin Move iTest to iPos End End End Loop Function_Return iPos End_Function // // This will pad out the strings in a line and overstrike them // with _ characters for a "string" and + characters for a 'string' // Function OverstrikeStrings String sLine Returns String Boolean bDoubleQuote Boolean bSingleQuote Integer iChar Integer iLength String sChar Move (Length(sLine)) to iLength For iChar From 1 to iLength Move (Mid(sLine, 1, iChar)) to sChar If (sChar = Character(9)) Begin // tab characters should be treated as a single space char, this keeps the Move (Overstrike(" ",sLine, iChar)) to sLine // position in the string the same. Move " " to sChar End If (bDoubleQuote and sChar= '"') Begin Move (Overstrike("_", sLine, iChar)) to sLine Move "" to sChar Move False to bDoubleQuote End If (bSingleQuote and sChar = "'") Begin Move (Overstrike("+", sLine, iChar)) to sLine Move "" to sChar Move False to bSingleQuote End If (bSingleQuote = False and sChar ='"') Begin Move True to bDoubleQuote End If (bDoubleQuote = False and sChar = "'") Begin Move True to bSingleQuote End If bDoubleQuote Begin Move (Overstrike("_", sLine, iChar)) to sLine End Else If bSingleQuote Begin Move (Overstrike("+", sLine, iChar)) to sLine End Loop Function_Return sLine End_Function Function BreakupCompoundStatement Integer iLineIndent String ByRef sLine Integer eSplitBy Integer iTabSize Returns Boolean Boolean bChanged Integer iPos String sLineIndent String sIndent String sLine1 sLine2 String sTest Move False to bChanged Move (Lowercase(sLine)) to sTest Move (Repeat(" ", iTabSize - 1)) to sIndent // it's tabsize-1 because the text still has a space in front of it Move (Repeat(" ", iLineIndent)) to sLineIndent Get OverstrikeStrings sTest to sTest Get TestCommands sTest to iPos If (iPos <> 0) Begin Move True to bChanged If (eSplitBy = CI_SplitBySpaceSemiColumn) Begin Move (Insert(" ;" + CS_CRLF + sLineIndent + sIndent, sLine, iPos)) to sLine End Else If (eSplitBy = CI_SplitBySemiColumn) Begin Move (Insert(";" + CS_CRLF + sLineIndent + sIndent, sLine, iPos)) to sLine End Else If (eSplitBy = CI_SplitByBeginEnd) Begin Move (Insert(" Begin" + CS_CRLF + sLineIndent + sIndent, sLine, iPos)) to sLine Move (sLine + CS_CRLF + sLineIndent + "End") to sLine End // Remove any spaces before the point on which we break the line Move (Left(sLine, iPos - 1)) to sLine1 Move (Right(sLine, Length(sLine) - (iPos - 1))) to sLine2 Move (RTrim(sLine1)) to sLine1 Move (sLine1 + sLine2) to sLine End Function_Return bChanged End_Function Function SplitInlineIfElseLine String ByRef sLine Integer eSplitBy Integer iTabSize Returns Boolean Boolean bStop Boolean bChanged Integer iIndent String sTest Move False to bChanged Move (LTrim(sLine)) to sTest Move (Pos(sTest,sLine) - 1) to iIndent Move (Left(sTest, 3)) to sTest Move (Lowercase(sTest)) to sTest If (sTest = "if ") Begin Get LineEndHasBeginOrSemicolumn sLine to bStop If (bStop = False) Begin // It's one of those single line if statements, break it up Move (Lowercase(sLine)) to sTest Get BreakupCompoundStatement iIndent (&sLine) eSplitBy iTabSize to bChanged End End Else Begin Move (LTrim(sLine)) to sTest Move (Left(sTest, 5)) to sTest Move (Lowercase(sTest)) to sTest If (sTest = "else ") Begin Get LineEndHasBeginOrSemicolumn sLine to bStop If (bStop = False) Begin Get BreakupCompoundStatement iIndent (&sLine) eSplitBy iTabSize to bChanged End End End Function_Return bChanged End_Function // To remove hardcoded MS Sans Serif fonts if present. Function IsNotSansSerifTypeFaceLine String sLine Returns Boolean String sTest Boolean bWriteLine Move False to bWriteLine Move (Trim(sLine)) to sTest Move (Lowercase(sTest)) to sTest Move (Replaces(" ", sTest, "")) to sTest Move (Replaces("'", sTest, "*")) to sTest Move (Replaces('"', sTest, "*")) to sTest If (sTest <> 'settypefaceto*mssansserif*') Begin Move True to bWriteLine End Function_Return bWriteLine End_Function Function IsProjectObjectStructureStart String sLine Returns Boolean Boolean bFound Move (sLine contains (CS_CommentSymbol * CS_ProjectObjectStructure)) to bFound Function_Return bFound End_Function Function ProjectObjectStructureLine String sLine String[] ByRef asObjectNames Returns Boolean Boolean bWriteLine Integer iPos iSize String sObjectName Move (Trim(sLine)) to sLine Move True to bWriteLine Move (Pos(CS_CommentSymbol, sLine)) to iPos If (iPos = 1) Begin Move (Lowercase(sLine)) to sLine Move (not(sLine contains " is a " or sLine contains " is an ")) to bWriteLine If (bWriteLine = False) Begin Move (SizeOfArray(asObjectNames)) to iSize Move (Pos(" is a", sLine)) to iPos Move (Left(sLine, (iPos -1))) to sObjectName Move (Replace(CS_CommentSymbol, sObjectName, "")) to sObjectName Move (Trim(sObjectName)) to sObjectName Move (Lowercase(sObjectName)) to asObjectNames[iSize] End End If (sLine = (CS_CommentSymbol * Lowercase(CS_ProjectObjectStructure))) Begin Move False to bWriteLine End Function_Return bWriteLine End_Function Function IsRegisterAllObjectsStart String sLine Returns Boolean Boolean bFound Move (sLine contains (CS_CommentSymbol * CS_RegisterAllObjects)) to bFound Function_Return bFound End_Function Function IsRegisterAllObjectsEnd String sLine Returns Boolean Boolean bFound Integer iPos String sFirstWord Move False to bFound Move (Lowercase(sLine)) to sLine Move (Trim(sLine)) to sLine If (Left(sLine, 2) <> CS_CommentSymbol) Begin Move (Pos(" ", sLine)) to iPos If (iPos <> 0) Begin Move (Left(sLine, (iPos -1))) to sFirstWord Move (sFirstWord = "object" or sFirstWord = "activate_view" or sFirstWord = "deferred_view") to bFound End End Function_Return bFound End_Function Function IsRegisterObjectLine String sLine Returns Boolean Boolean bFound Integer iPos Move False to bFound Move (Pos(CS_RegisterObject, sLine)) to iPos If (iPos = 1) Begin Move True to bFound End Function_Return bFound End_Function Function IsRegisterObjectInArray String sLine String[] ByRef asObjectNames Returns Boolean Boolean bWriteLine bRegisterObjectStart Integer iPos Move False to bWriteLine Get IsRegisterAllObjectsStart sLine to bRegisterObjectStart If (bRegisterObjectStart = False) Begin Move (Lowercase(sLine)) to sLine Move (Replace("register_object", sLine, "")) to sLine Move (Trim(sLine)) to sLine Move (SearchArray(sLine, asObjectNames)) to iPos Move (iPos = -1) to bWriteLine End Function_Return bWriteLine End_Function Function RemoveMultipleEmptyLines String[] ByRef asSourceFile Integer iMaxNoOfEmptyLines Returns Integer String[] asSourceFileOut Integer iCount iSize iCurrentNoOfEmptyLines iEmptyLines String sLine Boolean bImageStart bImageEnd bMakeImageTest Move False to bImageStart Move False to bImageEnd Move True to bMakeImageTest Move 0 to iCurrentNoOfEmptyLines Move (SizeOfArray(asSourceFile)) to iSize Decrement iSize For iCount from 0 to iSize Move (Trim(asSourceFile[iCount])) to sLine If (bMakeImageTest = True) Begin If (bImageStart = False and bImageEnd = False) Begin Get IsImagePageStartOrEnd sLine True to bImageStart End End If (bImageStart = False and bImageEnd = False) Begin If (sLine = "") Begin Increment iCurrentNoOfEmptyLines End Else Begin Move 0 to iCurrentNoOfEmptyLines End End If (iCurrentNoOfEmptyLines <= iMaxNoOfEmptyLines) Begin Move asSourceFile[iCount] to asSourceFileOut[SizeOfArray(asSourceFileOut)] End If (bMakeImageTest = True) Begin If (bImageStart = True) Begin Get IsImagePageStartOrEnd sLine False to bImageEnd If (bImageEnd = True) Begin Move False to bImageStart Move False to bImageEnd Move False to bMakeImageTest End End End Loop Move (SizeOfArray(asSourceFile) - SizeOfArray(asSourceFileOut)) to iEmptyLines Move asSourceFileOut to asSourceFile Function_Return iEmptyLines End_Function Function IsImagePageStartOrEnd String sLine Boolean bCheckImageStart Returns Boolean Boolean bFound Integer iPos Move False to bFound Move (Trim(sLine)) to sLine If (bCheckImageStart = True) Begin Get IsImageStart sLine to bFound End Else Begin Move (Pos(CS_ImageNameEnd, sLine)) to iPos If (iPos = 1) Begin Move True to bFound End End Function_Return bFound End_Function Function IsImageStart String sLine Returns Boolean Boolean bIsChar Integer iPos String sChar Move False to bIsChar Move (Trim(sLine)) to sLine Move (Pos(CS_ImageNameStart, sLine)) to iPos If (iPos = 1) Begin Move (Mid(sLine, 1, 2)) to sChar Move ("abcdefghijklmnopqrstuvwxyz" contains Lowercase(sChar)) to bIsChar End Function_Return bIsChar End_Function End_Class