// Remove Studio Markers from Source Code // by Marcia Booth - Data Access Corporation // Created on October, 2005 // // Modified by Allan Kim Eriksen // This will also: // - Right trim lines // - Remove more studio markers. // - Correct an error that added an extra empty line for each source file. // - All ending blank lines are not written back to the source file. // - Added a business process that makes it possible to change all files for a complete workspace. // It will traverse recursively through all directories in the workspace. // - Removes any LOCAL statements // // Modified by Nils Svedmyr, Wil van Antwerpen // Use SourceCode.inc Use akefs.pkg Use cButtonDPI.pkg Use Windows.pkg Define C_WorkspaceMode For 0 Define C_FileMode For 1 Activate_View Activate_oCleanMarkersView for oCleanMarkersView Object oCleanMarkersView is a dbView Set Location to 48 20 Set Size to 259 348 Set Border_Style to Border_Thick Set pbAutoActivate to True Set Label to "Cleanup Source" Set Icon to "CleanMarkers.ico" Set pbAcceptDropFiles to True Property tCleanupActions pCleanupActions Property Integer piChangedFileCount 0 Property Integer piFileCount 0 Property String[] pCommands Property tCounters pTotalCounters Property Boolean pbToggleState True Property Boolean pbCreateBackupFile True Object oReportUnusedLocals is a cReportUnusedLocals End_Object Object oActions_Grp is a Group Set Size to 117 297 Set Location to 3 34 Set Label to 'Cleanup Actions To Perform' Set peAnchors to anTopLeftRight Object oRemoveMarkers_cb is a CheckBox Set Size to 10 177 Set Location to 14 12 Set Label to "Remove Studio Markers" Set psToolTip to 'Removes all old //AB-xxxx IDE markers' Set Checked_State to True End_Object Object oRTrimLines_cb is a CheckBox Set Size to 10 50 Set Location to 25 12 Set Label to 'Remove trailing spaces' Set Checked_State to True End_Object Object oRemoveLocals_cb is a CheckBox Set Size to 10 50 Set Location to 36 12 Set Label to 'Remove "Local" from variable declarations' Set psToolTip to 'Removes all "Local" from variable declaration lines in functions and procedures' Set Checked_State to True End_Object Object oTabSize_sf is a SpinForm Set Size to 12 28 Set Location to 35 223 Set Label to "Tab Size:" Set Label_Col_Offset to 3 Set Label_Justification_Mode to JMode_Right Set psToolTip to "Select the indent size you want to use when breaking a line on rewriting a single line to multiple lines" Procedure OnStartup Integer iTabSize Get StudioCodeEditorSettings of ghoApplication CS_StudioTabSize True to iTabSize Set Value to iTabSize End_Procedure Send OnStartup End_Object Object oRemoveFonts_cb is a CheckBox Set Size to 10 50 Set Location to 47 12 Set Label to "Remove Hardcoded Fonts" Set psToolTip to 'Removes hardcoded "MS Sans Serif" fonts if present' Set Checked_State to True End_Object Object oIfElseSemicolumn_cb is a CheckBox Set Size to 10 50 Set Location to 58 12 Set Label to "Rewrite single line if/else to use to multiple lines" Set Checked_State to True End_Object Object oSplitBy_rgp is a RadioGroup Set Location to 49 187 Set Size to 26 100 Set Label to "Use:" Object oRadio1 is a Radio Set Label to "' ;'" Set Size to 10 20 Set Location to 10 5 Set psToolTip to "Break the line with a space followed by a semi column" End_Object Object oRadio2 is a Radio Set Label to "';'" Set Size to 10 19 Set Location to 10 27 Set psToolTip to "Break the line with a semi column" End_Object Object oRadio3 is a Radio Set Label to "Begin/End" Set Size to 10 47 Set Location to 10 49 Set psToolTip to "Break the line by adding a begin / end block" End_Object Set Current_Radio to 2 // Nils preference! End_Object Object oPropertyPublic_cb is a CheckBox Set Size to 10 50 Set Location to 69 12 Set Label to "Remove Property keyword 'public'" Set Checked_State to True End_Object Object oPropertyPrivate_cb is a CheckBox Set Size to 10 50 Set Location to 80 12 Set Label to "Remove Property keyword 'private'" Set Checked_State to False End_Object Object oRemoveEndComments_cb is a CheckBox Set Size to 10 50 Set Location to 91 12 Set Label to "Remove comments after end_class/end_object/end_function/end_procedure" Set Checked_State to True End_Object Object oReportUnusedLocals_cb is a CheckBox Set Size to 10 50 Set Location to 103 12 Set Label to 'Report Unused Local Variables' Set psToolTip to ('Saves all unused local variables to:' * CS_LogfileName) End_Object Object oToggle_btn is a cButtonDPI Set Size to 13 84 Set Location to 102 187 Set Label to "Toggle Checkboxes" Set psImage to "SelectInvert.ico" Procedure OnClick Send ToggleAll End_Procedure End_Object Procedure ToggleAll Boolean bState Get pbToggleState to bState Move (not(bState)) to bState Set Checked_State of oRemoveMarkers_cb to bState Set Checked_State of oRTrimLines_cb to bState Set Checked_State of oRemoveLocals_cb to bState Set Checked_State of oRemoveFonts_cb to bState Set Checked_State of oIfElseSemicolumn_cb to bState Set Checked_State of oPropertyPublic_cb to bState Set Checked_State of oPropertyPrivate_cb to bState Set Checked_State of oRemoveEndComments_cb to bState Set Checked_State of oReportUnusedLocals_cb to bState Set pbToggleState to bState End_Procedure End_Object Object oSelectFileOrWorkspace is a RadioGroup Set Location to 121 34 Set Size to 30 100 Set Label to "Run process on:" Object oRadio1 is a Radio Set Label to "Workspace" Set Size to 10 45 Set Location to 15 12 End_Object Object oRadio2 is a Radio Set Label to "File" Set Size to 10 29 Set Location to 15 61 End_Object Procedure Notify_Select_State Integer iToItem Integer iFromItem Boolean bIsFile Forward Send Notify_Select_State iToItem iFromItem Move (iToItem = C_FileMode) to bIsFile // Set Enabled_State of oSourceFile_fm to bIsFile End_Procedure End_Object Object oSwsFilePath_fm is a Form Set Size to 12 297 Set Location to 162 34 Set Label_Justification_Mode to JMode_Top Set Label to "Select the .sws file from the workspace that you want to run against:" Set Label_Col_Offset to 0 Set Prompt_Button_Mode to PB_PromptOn Set peAnchors to anTopLeftRight Set Prompt_Button_Mode to pb_PromptOn Procedure Prompt Boolean bOpen bReadOnly String sFileName Get Show_Dialog of oSwsOpenDialog to bOpen If bOpen Begin Get File_Name of oSwsOpenDialog to sFileName Set Value to sFileName End End_Procedure Function WorkspacePath Returns String String sSWSFile String sPath Get value To sSWSFile Get ParseFoldername sSWSFile To sPath If (sPath<>"") Begin Get vFolderFormat sPath To sPath End Function_Return sPath End_Function End_Object Object oSourceFile_fm is a Form Set Label to "Enter the name of the source file to be parsed:" Set Size to 12 297 Set Location to 185 34 Set Label_Col_Offset to 0 Set Label_Justification_Mode to jMode_Top Set peAnchors to anTopLeftRight Set Prompt_Button_Mode to pb_PromptOn Procedure Prompt Boolean bOpen bReadOnly String sFileName Get Show_Dialog of oOpenDialog to bOpen If bOpen Begin Get File_Name of oOpenDialog to sFileName Set Value to sFileName // check if user is opening file as read_only Get TickReadOnly_State of oOpenDialog to bReadOnly If bReadOnly Begin Send Info_Box ("Files should not be opened as ReadOnly.") "Cleanup Source" End End End_Procedure End_Object Object oOpenDialog is a OpenDialog Set Dialog_Caption to "Select a source file" Set Filter_String to "Programs|*.src|Views|*.vw|Dialogs|*.dg|Data Dictionaries|*.dd|Include files|*.inc|Report Views|*.rv|Selection Lists|*.sl|Web Object|*.wo|Packages|*.pkg|Business Processes|*.bp|Menus|*.mn|Header Files|*.h|Sture's Files|*.nui;*.utl|Any file|*.*" End_Object Object oSwsOpenDialog is a OpenDialog Set Dialog_Caption to "Select a DataFlex workspace project file" Set Filter_String to "DataFlex Workspace Files|*.sws|Any file|*.*" End_Object Object oFormParsedExt_cf is a ComboForm Set Size to 11 297 Set Location to 210 34 Set Label to " File extensions to parse:" Set Label_Col_Offset to 0 Set Label_Justification_Mode to JMode_Top Set peAnchors to anTopLeftRight Set Label_Row_Offset to 1 Set Combo_Sort_State to False Procedure Combo_Fill_List String sVDFExtensions sVDFVersion Integer iMajorVersion iMinorVersion Forward Send Combo_Fill_List Move FMAC_VERSION to iMajorVersion Move FMAC_REVISION to iMinorVersion Move (String(iMajorVersion) + "." + String(iMinorVersion)) to sVDFVersion Get StudioFileExtensions sVDFVersion to sVDFExtensions Send Combo_Add_Item CS_StdExtensions Send Combo_Add_Item CS_VDFAndTemplExt Send Combo_Add_Item CS_PkgIncExt Send Combo_Add_Item CS_SrcPkgExt If (sVDFExtensions <> String(cx_RegKeyVDFKeyDoesNotExist)) Begin Send Combo_Add_Item sVDFExtensions End Set Value to CS_StdExtensions End_Procedure Function StudioFileExtensions String sVDFVersion Returns String Handle hoReg String sStudioRegPath sRetval Boolean bExists bOk Get Create (RefClass(cRegistry)) to hoReg Move CS_StudioPath to sStudioRegPath If (sVDFVersion > "17.1") Begin Move (Replace("Visual ", sStudioRegPath, "")) to sStudioRegPath End Move (sStudioRegPath + sVDFVersion + CS_StudioPathEnd) to sStudioRegPath Set phRootKey of hoReg to HKEY_CURRENT_USER // First check if the VDF version is installed Get KeyExists of hoReg sStudioRegPath to bExists If (bExists = False) Begin Send Destroy of hoReg Function_Return cx_RegKeyVDFKeyDoesNotExist End Get OpenKey of hoReg sStudioRegPath to bOk If (bOk = True) Begin Set pfAccessRights of hoReg to KEY_READ Get ReadString of hoReg CS_VdfExtensionsKey to sRetval End Send CloseKey of hoReg Send Destroy of hoReg Function_Return sRetval End_Function // To "un-select" the text in the comboform on startup Procedure DoApplyAnchors Integer Arg1 Integer Arg2 Handle hoBkComboForm Integer iStart iEnd If (Focus(Desktop)=Self) Begin Get SelStart to iStart Get SelEnd to iEnd End Forward Send DoApplyAnchors Arg1 Arg2 Send SetSel iStart iEnd End_Procedure End_Object Object oCreateBackupFiles_cb is a CheckBox Set Size to 14 50 Set Location to 225 34 Set Label to "Create backup files in backup folder (\SCTBackup\)" Set psToolTip to "If the Backup folder doesn't exist under the AppSrc folder, it will be created. Note: The .cmbak extension ia ADDED to the current file name." Set Checked_State to True End_Object // // Reads the settings from the checkboxes and applies those by writing them out // to our properties // Procedure ReadSettings Boolean bChecked tCleanupActions CleanupActions Get Checked_State of oCreateBackupFiles_cb to bChecked Set pbCreateBackupFile to bChecked Move (Checked_State(oRemoveMarkers_cb)) to CleanupActions.bRemoveMarkers Move (Checked_State(oRTrimLines_cb)) to CleanupActions.bRTrimLines Move (Checked_State(oRemoveLocals_cb)) to CleanupActions.bRemoveLocal Move (Checked_State(oRemoveFonts_cb)) to CleanupActions.bRemoveFonts Move (Checked_State(oIfElseSemiColumn_cb)) to CleanupActions.bInlineIfElse Move (Checked_State(oPropertyPublic_cb)) to CleanupActions.bPropertyPublic Move (Checked_State(oPropertyPrivate_cb)) to CleanupActions.bPropertyPrivate Move (Checked_State(oRemoveEndComments_cb)) to CleanupActions.bRemoveEndComments Move (Checked_State(oReportUnusedLocals_cb)) to CleanupActions.bUnusedLocals Set pCleanupActions to CleanupActions End_Procedure // // At least one action should be selected. // Function ValidActions Returns Boolean Boolean bClean Boolean bRtrim Boolean bLocal Boolean bFonts Boolean bChecked Boolean bInlineIfElse Boolean bPublic Boolean bPrivate Boolean bEndComments Boolean bUnusedLocals tCleanupActions CleanupActions Get pCleanupActions to CleanupActions Move CleanupActions.bRemoveMarkers to bClean Move CleanupActions.bRTrimLines to bRTrim Move CleanupActions.bRemoveFonts to bFonts Move CleanupActions.bRemoveLocal to bLocal Move CleanupActions.bInlineIfElse to bInlineIfElse Move CleanupActions.bPropertyPublic to bPublic Move CleanupActions.bPropertyPrivate to bPrivate Move CleanupActions.bRemoveEndComments to bEndComments Move CleanupActions.bUnusedLocals to bUnusedLocals Move (bClean or bRTrim or bFonts or bLocal or bInlineIfElse or bPublic or bPrivate or bEndComments or bUnusedLocals) to bChecked If (bChecked = False) Begin Send Info_Box "You should at least check ONE action for the process to run." End Function_Return bChecked End_Function Object oGenerateBtn is a cButtonDPI Set Label to "PROCESS!" Set Size to 14 63 Set Location to 241 122 Set peAnchors to anBottomRight Set FontWeight to fw_Bold Set psImage to "Process.ico" Procedure RemoveUnusedVariablesLogFile String sPath Boolean bOK tCleanupActions CleanupActions Get pCleanupActions to CleanupActions // Remove the current (old) log file for unused variables. If (CleanupActions.bUnusedLocals = True) Begin Get vFolderFormat sPath to sPath Get vDeleteFile (sPath + CS_BackupFolder + "\" + CS_LogfileName) to bOK End End_Procedure Procedure OnClick String sFileName sPath sText sSWSFile Integer eRadio Boolean bFolderExists Boolean bFileExists Boolean bOK tCleanupActions CleanupActions Send ReadSettings Get pCleanupActions to CleanupActions Move False to Err Move 0 to LastErr Get ValidActions to bOk If (bOk) Begin Send InitializeCounters Get Current_Radio of oSelectFileOrWorkspace to eRadio If (eRadio = C_WorkspaceMode) Begin Set Value of oSourceFile_fm to "" // This is required to have the file extension test work correctly at all times (a file might have been selected) Get WorkspacePath Of oSwsFilePath_fm To sPath // // PHvW 08/06/2018 Let see if the directory does exist.... // Get vFolderExists sPath To bFolderExists If (bFolderExists = False) Begin Send Stop_Box "Directory does not exists" "Process Halted" Procedure_Return End Send RemoveUnusedVariablesLogFile sPath Send DoProcess of oBPO Get pbOk of oBPO to bOk End Else Begin Get value of oSourceFile_fm to sFileName File_Exist sFileName bFileExists If (bFileExists = False) Begin Send Stop_Box "File does not exists" "Process Halted" Procedure_Return End Get WorkspacePath Of oSwsFilePath_fm To sPath Send RemoveUnusedVariablesLogFile sPath Get ProcessFile sFileName to bOK End If (bOK) Begin If (CleanupActions.bUnusedLocals = True) Begin Get Value of oSourceFile_fm to sFileName Get vFolderFormat sPath to sPath Runprogram Shell Background (sPath + CS_BackupFolder +"\" + CS_LogfileName) End Get CleanupResult to sText Send Info_Box (sText+"\n\nParsing completed.") "Source Code Tool" End Else Begin Send Info_Box "Parsed File could not be created. " "Source Code Tool" End End End_Procedure Procedure DoEnable Boolean bEnabled Integer eRadio String sDirectory sFileName Get Value of oSourceFile_fm to sFileName Get Value of oSwsFilePath_fm to sDirectory Get Current_Radio of oSelectFileOrWorkspace to eRadio If (eRadio = C_WorkspaceMode) Begin Move (sDirectory <> "") To bEnabled End Else If (eRadio = C_FileMode) Begin Move (sFileName <> "" and sDirectory <> "") To bEnabled End Set Enabled_State to bEnabled End_Procedure End_Object Object oCompareBtn is a cButtonDPI Set Size to 14 63 Set Location to 241 195 Set Label to 'Compare' Set psToolTip to "Compare file changes after running cleanup" Set psImage to "Compare.ico" Set peAnchors to anBottomRight Set pbAutoEnable to True Procedure OnClick Boolean bExist Integer iRadio String sCompareApp Get psFileCompareApp of ghoApplication to sCompareApp File_Exist sCompareApp bExist If (bExist) Begin Get Current_Radio of oSelectFileOrWorkspace to iRadio If (iRadio = 0) Begin Send ComparePaths sCompareApp End Else If (iRadio = 1) Begin Send CompareFiles sCompareApp End End Else Begin Send Info_Box "A file compare application is not set or not valid.\nPlease select a valid file comparison application from the menu." End End_Procedure Procedure ComparePaths String sCompareApp Boolean bExist String sPath sPathBackup Get WorkspacePath Of oSwsFilePath_fm To sPath If (sPath <> "") Begin Get vFolderFormat sPath to sPath Move (sPath + CS_BackupFolder) to sPathBackup File_Exist sPathBackup bExist If (bExist) Begin Runprogram Background ('"' + sCompareApp + '"') ('"' + sPath + '" "' + sPathBackup + '"') End End End_Procedure Procedure CompareFiles String sCompareApp Boolean bExist String sFileName sFile sFileBackup Get Value of oSourceFile_fm to sFileName If (sFileName<>"") Begin File_Exist sFileName bExist If (bExist) Begin Get BackupFile To sFileBackup If (sFileBackup<>"") Begin Runprogram Background ('"' + sCompareApp + '"') ('"' + sFileName + '" "' + sFileBackup + '"') End End Else Begin Send Info_Box ("The file in the source file"*sFileName*"\nDoes not exist.") End End Else Begin Send Info_Box "You have to select a file first." End End_Procedure Function BackupFile Returns String String sDirSep sFileBackup sPath sFileName sFile Boolean bExists Move (SysConf(SYSCONF_DIR_SEPARATOR)) to sDirSep // normally \ (backslash) Get Value of oSourceFile_fm to sFileName If (Right(sFileName, 1) = sDirSep) Begin Move (Left(sFileName, (Length(sFileName) -1))) to sFileName End Get WorkspacePath Of oSwsFilePath_fm To sPath Get ParseFileName sFileName to sFile Move (sPath + CS_BackupFolder + String(sDirSep) + sFile) to sFileBackup File_Exist sFileBackup bExists If (bExists = False) Begin Function_Return "" End Function_Return sFileBackup End_Function Procedure DoEnable String sBackupName Get BackupFile to sBackupName Set Enabled_State to (sBackupName <> "") End_Procedure End_Object Object oOpenSourceFolder_btn is a cButtonDPI Set Label to "Open Folder" Set Size to 14 63 Set Location to 241 261 Set peAnchors to anBottomRight Set psImage to "ActionOpen.ico" Set pbAutoEnable to True Procedure OnClick String sFileName sPath Get Value of oSourceFile_fm to sFileName Get WorkspacePath Of oSwsFilePath_fm To sPath If (sFileName <> "") Begin Get ParseFolderName sFileName to sPath End Runprogram Shell Background sPath End_Procedure Procedure DoEnable String sFileName sPath Get Value of oSourceFile_fm to sFileName Get Value of oSwsFilePath_fm to sPath If (sFileName <> "") Begin Get ParseFolderName sFileName to sPath End Set Enabled_State to (sPath <> "") End_Procedure End_Object Object oBPO is a BusinessProcess Property Boolean pbOk Procedure OnProcess String sDirName Boolean bOk Send SetProgressBarText Get WorkspacePath Of oSwsFilePath_fm To sDirName Get RecursiveSearchDirectoryFiles sDirName to bOK Set pbOk to bOk End_Procedure Function RecursiveSearchDirectoryFiles String sSourceDirname Returns Boolean Boolean bOk bStop Integer iCnt iMax String sFile sLine sEval sExt sSourceFile Handle hoDir Move 0 to iCnt Get Value of oSourceFile_fm to sSourceFile Get Create (RefClass(cDirectory)) to hoDir Get vFolderFormat sSourceDirname to sSourceDirname Move (sSourceDirname + "*.*") to sFile Get SearchSingleDirectory of hoDir sFile DIRMODE_DIRECTORIES_ONLY to iMax Decrement iMax For iCnt from 0 to iMax Get Searchresult of hoDir iCnt LIST_FILENAME to sLine If (sLine <> "." and sLine <> ".." and sLine <> ".svn" and sLine <> ".git" and ; sLine <> ".hg" and Lowercase(sLine) <> "apphtml" and sLine <> CS_BackupFolder) Begin Get RecursiveSearchDirectoryFiles (sSourceDirname + sLine) to bOk If (not(bOk)) Begin Send Destroy of hoDir Function_Return False End Get Cancel_Check to bStop If bStop Begin Send Destroy of hoDir Function_Return False End End Loop Get SearchSingleDirectory of hoDir sFile DIRMODE_FILES_ONLY to iMax Decrement iMax For iCnt from 0 to iMax Get Searchresult of hoDir iCnt LIST_FILENAME to sLine Get ParseFileExtension sLine to sExt Move (Lowercase(sExt)) to sExt Get Value of oFormParsedExt_cf to sEval // Remove wildcard characters. Move (Replaces("*", sEval, "")) to sEval Move (Lowercase(sEval)) to sEval If ((Pos("." + sExt + ";", sEval)) or sSourceFile <> "") Begin Send Update_status (sSourceDirname + sLine) Get ProcessFile (sSourceDirname + sLine) to bOK If (not(bOk)) Begin Send Destroy of hoDir Function_Return False End End Get Cancel_Check to bStop If bStop Begin Send Destroy of hoDir Function_Return False End Loop Send Destroy of hoDir Move True to bOk Function_Return bOk End_Function Procedure Update_Status String sProgress Integer eRadio String sPath Get Current_Radio of oSelectFileOrWorkspace to eRadio If (eRadio=C_WorkspaceMode) Begin Get WorkspacePath Of oSwsFilePath_fm To sPath If (sPath<>"") Begin // Strip out the path, so that you can see the filename without it getting cut off. Move (Replace(sPath,sProgress,"..")) to sProgress End End Forward Send Update_Status sProgress End_Procedure Procedure SetProgressBarText Boolean bCleanMarkers Boolean bRTrimSource Boolean bRemoveLocal Boolean bRemoveFonts Boolean bInlineIfElse Boolean bPublic Boolean bPrivate Boolean bEndComments String sMessage Boolean bUnusedLocals tCleanupActions CleanupActions Get pCleanupActions to CleanupActions Move CleanupActions.bRemoveMarkers to bCleanMarkers Move CleanupActions.bRTrimLines to bRTrimSource Move CleanupActions.bRemoveLocal to bRemoveLocal Move CleanupActions.bRemoveFonts to bRemoveFonts Move CleanupActions.bUnusedLocals to bUnusedLocals Move CleanupActions.bInlineIfElse to bInlineIfElse Move CleanupActions.bPropertyPublic to bPublic Move CleanupActions.bPropertyPrivate to bPrivate Move CleanupActions.bRemoveEndComments to bEndComments Move "" to sMessage If (bCleanMarkers) ; Move "Removing Studio Markers\n" to sMessage If (bRTrimSource) ; Move (sMessage+"Removing end of line whitespace\n") to sMessage If (bRemoveLocal) ; Move (sMessage+"Removing local keyword from variables\n") to sMessage If (bRemoveFonts) ; Move (sMessage+"Removing typeface MS Sans Serif\n") to sMessage If (bInlineIfElse) ; Move (sMessage+"Rewriting if/else single line compound statement to multiple lines with ;\n") to sMessage If (bPublic or bPrivate) ; Move (sMessage+"Removing public/private keyword from properties\n") to sMessage If (bEndComments) ; Move (sMessage+"Removing end comments\n") to sMessage If (bUnusedLocals) Begin Move (sMessage + "Finding unused local variables\n") to sMessage End Move (sMessage+"...") to sMessage Move (Replaces("\n",sMessage,CS_LF)) to sMessage Set Process_Caption to "DataFlex Source Code Tool" Set Process_Message to sMessage Set Process_Title to "Code cleanup" End_Procedure Set Display_Error_State to True Set Allow_Cancel_State to True End_Object Procedure AddCommand String sCommand String[] Commands Get pCommands To Commands Move (Lowercase(sCommand)) To sCommand Move sCommand To Commands[SizeOfArray(Commands)] Set pCommands 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 pCommands 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 Integer iRetval String sCmdLineFile sSWSFile If (iRetval=0) Begin Send AddAllCommands Get psAutoLoadAppSrc of ghoApplication to sCmdLineFile Set Value of oSourceFile_fm to sCmdLineFile Get psSWSFile of ghoApplication to sSWSFile Set Value of oSwsFilePath_fm to sSWSFile If (sCmdLineFile <> "") Begin Set Current_Radio of oSelectFileOrWorkspace to 1 End End Procedure_Return iRetval End_Procedure // Allow a file or a folder to be dropped on the view: Procedure OnFileDropped String sFilename Boolean bLast String sFileExt Boolean bFile bExists Forward Send OnFileDropped sFilename bLast If (bLast = True) Begin // Try to find out if a file or a folder name // was dropped on the view: Get ParseFileExtension sFilename To sFileExt Move (lowercase(sFileExt)) To sFileExt Move (sFileExt <> "sws") to bFile If (bFile = True) Begin Set Current_Radio of oSelectFileOrWorkspace to C_FileMode Set Value of oSourceFile_fm to sFilename End Else Begin Set Current_Radio of oSelectFileOrWorkspace to C_WorkspaceMode Set Value of oSwsFilePath_fm to sFileName End End Else Begin Send Info_Box "Only one file or .sws project can be dropped on the view. The last workspace file will be used." End End_Procedure Procedure CloseChannel Integer iChannel Close_Input channel iChannel Send Seq_Release_Channel iChannel End_Procedure 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 End_Function // RTrim trailing spaces if present. Function RemoveTrailingSpaces String ByRef sLine Returns Boolean Integer iBefore iAfter Boolean bChanged Move False To bChanged Move (Length(sLine)) To iBefore Move (Rtrim(sLine)) to sLine Move (Length(sLine)) To iAfter If (iBefore <> iAfter) Begin Move True to bChanged End 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 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 RemoveComments String ByRef sLine Returns Boolean Boolean bRemoved Integer iPos Move False to bRemoved Move (Pos("//",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 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 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) ; Move True to bChanged End Move (Left(sTestLine, 11)) to sTest If (sTest = "end_object ") Begin Get RemoveComments (&sLine) to bRemoved If (bRemoved) ; Move True to bChanged End Move (Left(sTestLine, 13)) to sTest If (sTest = "end_function ") Begin Get RemoveComments (&sLine) to bRemoved If (bRemoved) ; Move True to bChanged End Move (Left(sTestLine, 14)) to sTest If (sTest = "end_procedure ") Begin Get RemoveComments (&sLine) to bRemoved If (bRemoved) ; Move True to bChanged End Function_Return bChanged End_Function Function TestCommands String sTest Returns Integer Boolean bRemoved Integer iCount Integer iPos Integer iItem Integer iTest String sCommand String[] Commands Move 0 to iPos Get RemoveComments (&sTest) to bRemoved Get pCommands to Commands Move (SizeOfArray(Commands)) to iCount For iItem from 0 to (iCount-1) Move Commands[iItem] 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) ; Move iTest to iPos Else Begin If (iTest0) 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 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 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 to bChanged End End End Function_Return bChanged End_Function // Removes hardcoded MS Sans Serif fonts if present. Function IsSansSerifTypeFaceLine String sLine Returns Boolean String sTest Boolean bIsFontLine Move False to bIsFontLine 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 bIsFontLine End Function_Return bIsFontLine End_Function Function ParseFile String sParsedFile Integer iInChannel Integer iOutChannel tCounters ByRef Counters Returns Boolean Boolean bParseOK bMarkerFound bChanged Boolean bCleanMarkers Boolean bRTrimSource Boolean bRemoveLocal Boolean bRemoveFonts Boolean bUnusedLocals Boolean bIsFontLine Boolean bPublic Boolean bPrivate Boolean bInlineIfElse Boolean bEndComments Boolean bEndOfFile Boolean bReadAhead Integer iLine Integer eSplitBy String sLineBreak String sSourceFile String sLine String sNextLine String sBasePath tCleanupActions CleanupActions Move False to bParseOK Move False to bEndOfFile Move False to bReadAhead Move "" to sLineBreak Move "" to sNextLine Move 0 to iLine Get pCleanupActions to CleanupActions Move CleanupActions.bRemoveMarkers to bCleanMarkers Move CleanupActions.bRTrimLines to bRTrimSource Move CleanupActions.bRemoveLocal to bRemoveLocal Move CleanupActions.bRemoveFonts to bRemoveFonts Move CleanupActions.bUnusedLocals to bUnusedLocals Move CleanupActions.bPropertyPublic to bPublic Move CleanupActions.bPropertyPrivate to bPrivate Move CleanupActions.bInlineIfElse to bInlineIfElse Move CleanupActions.bRemoveEndComments to bEndComments Get BackupFileName sParsedFile to sSourceFile // Need to use binary read mode if we want to preserve tab characters and not have automatic tab replacement // filemode options don't seem to work as documented, not sure why, but I stop caring about that now. //Direct_Input channel iInChannel ("binary: "+"cr: 13: "+"eof: 26: "+sSourceFile) //Direct_Input channel iInChannel ("binary: "+"cr: 13:"+"eof: 26:"+sSourceFile) Direct_Input channel iInChannel ("binary:"+sSourceFile) Direct_Output channel iOutChannel (sParsedFile) Repeat If (bReadAhead=False) Begin Readln channel iInChannel sLine End Else Begin Move sNextLine to sLine Move False to bReadAhead Move "" to sNextLine End Move (SeqEof) to bEndOfFile Increment iLine Move False to bMarkerFound Move False to bIsFontLine // On line 1 we determine if the file has CRLF or LF line endings. If (iLine=1) Begin // The readline automatically reads Until LF, but does not report LF back in the string If (Length(sLine) >= 1 and Right(sLine,1)=CS_CR) Begin Move CS_CRLF to sLineBreak End Else Begin Move CS_LF to sLineBreak End End If (sLineBreak=CS_CRLF) Begin If (Right(sLine,1)=CS_CR) Begin Move (Left(sLine,Length(sLine)-1)) to sLine End Else Begin // if reading last line then bEndOfFile is still not set so can't test for that // unless we read ahead! Move True to bReadAhead Readln channel iInChannel sNextLine If (SeqEof) Begin Move "" to sLineBreak End End End If (Length(sLine)=0) Begin If (bEndOfFile=False) Begin // We only want this for lines that are actually not even having a space, so a test for sLine="" // doesn't work as sLine="" == sLine=" " == sLine=" " etcetera Write channel iOutChannel sLineBreak End End Else Begin If (bCleanMarkers) Begin Get FindStudioMarker sLine to bMarkerFound If (bMarkerFound) ; Increment Counters.iRemoveMarker End If (bMarkerFound=False) Begin If (bRemoveLocal) Begin Get RemoveLocal (&sLine) to bChanged If (bChanged) ; Increment Counters.iRemoveLocal End If (bRemoveFonts) Begin Get IsSansSerifTypeFaceLine sLine to bIsFontLine If (bIsFontLine) ; Increment Counters.iRemoveFonts End If (bPublic) Begin Get RemovePropertyPublic (&sLine) to bChanged If (bChanged) ; Increment Counters.iRemovePublic End If (bPrivate) Begin Get RemovePropertyPrivate (&sLine) to bChanged If (bChanged) ; Increment Counters.iRemovePrivate End If (bInlineIfElse) Begin Get Current_Radio of oSplitBy_rgp to eSplitBy Get SplitInlineIfElseLine (&sLine) eSplitBy to bChanged If (bChanged) ; Increment Counters.iInlineIfElse End If (bEndComments) Begin Get RemoveEndComments (&sLine) to bChanged If (bChanged) ; Increment Counters.iEndComments End If (bRTrimSource) Begin // should be after remove end comments Get RemoveTrailingSpaces (&sLine) to bChanged If (bChanged) ; Increment Counters.iTrimmed End If (bIsFontLine=False) Begin Write channel iOutChannel sLine sLineBreak End End End Until (bEndOfFile) If (bUnusedLocals = True) Begin Set psParsedFile of oReportUnusedLocals to sParsedFile Set psSourceName of oReportUnusedLocals to sSourceFile Get WorkspacePath Of oSwsFilePath_fm To sBasePath Move (sBasePath+CS_BackupFolder) To sBasePath Set psOutputPath Of oReportUnusedLocals To sBasePath Set piOutputType of oReportUnusedLocals to 1 Send DoProcess to oReportUnusedLocals End If (Err = False) Begin Move True to bParseOK End Function_Return bParseOK End_Function Function AvailableChannel Returns Integer Integer iChannelAvailable Get Seq_New_Channel to iChannelAvailable Function_Return iChannelAvailable End_Function // Changed to use .cmbak instead of a normal .BAK as I don't want the // utility to overwrite the normal .BAK files. By using a unique // file extension, they are easy to select and delete all of them in one // go. Function BackupFileName String sFile Returns String String sBkupFile sPath sFileName String sWSBasePath String sBkupPath Boolean bFolderExists Integer iRetval Get WorkspacePath Of oSwsFilePath_fm To sWSBasePath Get ParseFolderName sFile To sPath Move (Replace(sWSBasePath,sPath,"")) To sPath // Only want the subfolder structure Move (sWSBasePath+ CS_BackupFolder + "\" + sPath ) to sBkupPath Get vFolderExists sBkUpPath to bFolderExists If (bFolderExists = False) Begin Get vshCreateDirectoryEX sBkupPath to iRetval If (iRetval = True) Begin Get YesNo_Box "Warning! The Backup folder could not be created. You should abort the program now, fix the cause of the problem and start it again. Abort program?" to iRetval If (iRetval = MBR_Yes) Begin Close_Input Close_Output Send Exit_Application End End End Get vFolderFormat sBkUpPath To sBkUpPath Get ParseFileName sFile To sFileName Move (sBkUpPath + sFileName ) To sBkupFile Function_Return sBkupFile End_Function Function SaveFileBackup String sFileName Returns Boolean Boolean bOK Integer iRetVal String sBKFile Move False to bOK Get BackupFileName sFileName to sBKFile Get FileCopy sFileName sBKFile to iRetVal // ToDo: //Get vMoveFile sFileName sBKFile to iErr Get FileExists sBKFile to bOK Function_Return bOK End_Function Procedure InitializeCounters tCounters EmptyTotals Set piChangedFileCount to 0 Set piFileCount to 0 Set pTotalCounters to EmptyTotals End_Procedure Procedure TallyCounters tCounters Counters tCounters Totals Get pTotalCounters to Totals Move (Counters.iTrimmed + Totals.iTrimmed ) To Totals.iTrimmed Move (Counters.iRemoveMarker + Totals.iRemoveMarker ) To Totals.iRemoveMarker Move (Counters.iRemoveLocal + Totals.iRemoveLocal ) To Totals.iRemoveLocal Move (Counters.iRemoveFonts + Totals.iRemoveFonts ) To Totals.iRemoveFonts Move (Counters.iRemovePublic + Totals.iRemovePublic ) To Totals.iRemovePublic Move (Counters.iRemovePrivate + Totals.iRemovePrivate) To Totals.iRemovePrivate Move (Counters.iInlineIfElse + Totals.iInlineIfElse ) To Totals.iInlineIfElse Move (Counters.iEndComments + Totals.iEndComments ) To Totals.iEndComments Get ReadString of ghoApplication CS_UnusedVariables CS_NoOfErrorFiles "" to Totals.iNoOfErrorFiles Set pTotalCounters to Totals End_Procedure Function CleanupResult Returns String String sText Integer iChangedFiles Integer iFileCount tCounters Totals Get pTotalCounters to Totals Get piChangedFileCount to iChangedFiles Get piFileCount to iFileCount Move ("Totals Files changed:" * Trim(iChangedFiles) * "out of" * Trim(iFileCount) * "Files.\n") to sText Move (sText + "\nStatistics:") to sText Move (sText + "\nRight trimmed" * Trim(Totals.iTrimmed) * "lines") to sText Move (sText + "\nMarkers removed" * Trim(Totals.iRemoveMarker)) to sText Move (sText + "\nLocal keywords removed" * Trim(Totals.iRemoveLocal)) to sText Move (sText + "\nStatic fonts removed" * Trim(Totals.iRemoveFonts)) to sText Move (sText + "\nPublic keywords removed" * Trim(Totals.iRemovePublic)) to sText Move (sText + "\nPrivate keywords removed" * Trim(Totals.iRemovePrivate)) to sText Move (sText + "\nIf/Else lines changed" * Trim(Totals.iInlineIfElse)) to sText Move (sText + "\nEnd Comments removed" * Trim(Totals.iEndComments)) to sText Move (sText + "\nNumber of files with Unused Local Variables" * Trim(Totals.iNoOfErrorFiles)) to sText Function_Return sText End_Function // // Checks the counters to see if the file was changed // Function FileCountersChanged tCounters Counters Returns Boolean Boolean bChanged Move False To bChanged If (Counters.iTrimmed<>0) Begin Move True To bChanged End If (Counters.iRemoveMarker <> 0) Begin Move True To bChanged End If (Counters.iRemoveLocal <> 0) Begin Move True To bChanged End If (Counters.iRemoveFonts <> 0) Begin Move True To bChanged End If (Counters.iRemovePublic <> 0) Begin Move True To bChanged End If (Counters.iRemovePrivate <> 0) Begin Move True To bChanged End If (Counters.iInlineIfElse <> 0) Begin Move True To bChanged End If (Counters.iEndComments <> 0) Begin Move True to bChanged End Function_Return bChanged End_Function Procedure IncrementChangedFiles Integer iCount Get piChangedFileCount to iCount Increment iCount Set piChangedFileCount to iCount End_Procedure Procedure IncrementFileCount Integer iCount Get piFileCount to iCount Increment iCount Set piFileCount to iCount End_Procedure // // Processes the file passed and performs the actions that have been chosen // This function will always create a backup file and then call parsefile // for the actual work. // After the work has been done, it will remove the backup file OR // rename it to .bak depending on if you wanted to save the backup file or not. // Function ProcessFile String sFileName Returns Boolean Boolean bSuccess Boolean bSaveBak Boolean bChanged Integer iInChannel iOutChannel iIgnored structFileTime ftLastWrite String sBKFile tCounters Counters // copy file to Get SaveFileBackup sFileName to bSuccess Get pbCreateBackupFile to bSaveBak If (bSuccess) Begin // open available channels Get AvailableChannel to iInChannel Get AvailableChannel to iOutChannel If ((iInChannel <> DF_SEQ_CHANNEL_NOT_AVAILABLE) and (iOutChannel <> DF_SEQ_CHANNEL_NOT_AVAILABLE)) Begin Get GetFileLastWriteTime sFileName to ftLastWrite // parse file Get ParseFile sFileName iInChannel iOutChannel (&Counters) to bSuccess Send CloseChannel iInChannel Send CloseChannel iOutChannel Send IncrementFileCount Get FileCountersChanged Counters to bChanged If (bChanged) Begin Send IncrementChangedFiles Send TallyCounters Counters End Else Begin // while the file was rewritten, it has not changed, so restore the file // modified date/time and get rid of the backup file. Send SetFileLastWriteTime sFileName ftLastWrite If (bSaveBak) Begin Get BackupFileName sFileName to sBKFile Get FileDelete sBKFile to iIgnored End End End End If (bSaveBak=False) Begin Get BackupFileName sFileName to sBKFile Get FileDelete sBKFile to iIgnored End Function_Return bSuccess End_Function On_Key Key_Ctrl+Key_F4 Send None End_Object