Use Windows.pkg Use DFClient.pkg Use Dfline.pkg Use cTextEdit.pkg Use cRegistry.pkg Use seq_chnl.pkg Use BatchDD.pkg Use dfSpnFrm.pkg Use File_dlg.pkg Use vWin32fh.pkg Use akefs.pkg Use NewStatPnl.pkg Use ReportUnusedLocals.pkg #IFNDEF cx_RegKeyAlreadyExist Enum_List Define cx_RegKeyAlreadyExist Define cx_RegKeyCreated Define cx_RegkeyFailed Define cx_RegKeyVDFKeyDoesNotExist Define CX_InstalledOkVdfUnder16 End_Enum_List #ENDIF Struct tCleanupActions Boolean bRemoveMarkers Boolean bRTrimLines Boolean bRemoveLocal Boolean bRemoveFonts Boolean bUnusedLocals Boolean bInlineIfElse Boolean bPropertyPublic Boolean bPropertyPrivate Boolean bRemoveEndComments End_Struct Struct tCounters Integer iTrimmed Integer iRemoveMarker Integer iRemoveLocal Integer iRemoveFonts Integer iInlineIfElse Integer iRemovePublic Integer iRemovePrivate Integer iEndComments Integer iNoOfErrorFiles End_Struct Define CS_CommentSymbol for ("/"+"/") Define CS_OpenFileStdFilter for "All files *.*|*.*|Programs *.src|*.src|Views *.vw|*.vw|Report Views *.rv|*.rv|Selection Lists *.sl|*.sl|Web Object *.wo|*.wo|Packages *.pkg|*.pkg" Define CS_StudioToolsPathStart for "Software\Data Access Worldwide\DataFlex Tools\" Define CS_StudioToolsPathEnd for "\Studio\Preferences\File Extensions" Define CS_StudioCodeEditorPath for "\Studio\Code-Editor" Define CS_StudioFontName for "FontName" Define CS_StudioFontSize for "FontSize" Define CS_StudioExpandTabs for "ExpandTabs" Define CS_StudioIndentStyle for "IndentStyle" Define CS_StudioTabSize for "TabSize" Define CS_VdfExtensionsKey for "VdfExtensions" Define CS_StudioEditorSettingsStart for "DataFlex Studio" Define CS_StudioEditorSettingsEnd for "Code Editor Settings" Define CS_IdleText for "Idle..." Define CS_WorkingText for "Working..." Define CS_ReadyText for "Ready!" Define CS_Default_Dialog_Caption for "Select a source file" Define CS_Folder_Dialog_Caption for "Select a Filename - Only the foldername will be returned" Define CS_Default_Filter_String for "All Files *.*|*.*|Programs *.src|*.src|Views *.vw|*.vw|Report Views *.rv|*.rv|Selection Lists *.sl|*.sl|Web Object *.wo|*.wo|Packages *.pkg|*.pkg" Define CS_Folder_Filter_String for "All files|*.*" Define CS_BackupFolder for "SCTBackup" Define CS_LF for (Character(10)) Define CS_CR for (Character(13)) Define CS_CRLF for (Character(13) + character(10)) Define CI_SplitBySpaceSemiColumn for 0 Define CI_SplitBySemiColumn for 1 Define CI_SplitByBeginEnd for 2 Define CS_StudioPath for "Software\Data Access Worldwide\Visual DataFlex Tools\" Define CS_StudioPathEnd for "\Studio\Preferences\File Extensions" // Running cleanmarkers on web files does break stuff badly //Define CS_VDFAndWebExt for "*.src;*.vw;*.sl;*.dg;*.rv;*.bp;*.pkg;*.wo;*.dd;*.inc;*.tpl;*.dfo;*.asp;*.asa;*.htm;*.css;*.js" //Define CS_HTMLExtOnly for "*.htm;*.asp;*.css;*.js" //Define CS_FDTAGExt for "*.fd;*.tag;*.def" Define CS_VDFAndTemplExt for "*.src;*.vw;*.sl;*.dg;*.rv;*.bp;*.pkg;*.wo;*.dd;*.inc;*.dfo;*.tpl" Define CS_DDDEFExt for "*.dd" Define CS_PkgIncExt for "*.pkg;*.inc;*.mac" Define CS_SrcPkgExt for "*.src;*.pkg" Define CS_AllExt for "*.*" Define CS_StdExtensions for "*.src;*.vw;*.sl;*.dg;*.rv;*.pkg;*.cl;*.wo;*.dd;*.bp;*.inc;*.nui;*.utl;*.mn;*.mnu" Define CS_VdfExtensionsKey for "VdfExtensions" Class cCodeIndenter is a cObject Procedure Construct_Object Forward Send Construct_Object Property Integer piLevel Property String[] psIndentWords Property String[] psUnIndentWords Property String[] psIgnoreWords Property String[] ptArray Property Boolean pbCaseBlock Property Integer piTabSize 4 Property Boolean pbExpandTabs False End_Procedure Procedure Init String[] vEmpty Set ptArray to vEmpty Set piLevel to 0 End_Procedure Function TabCount Returns String String sData sSpacer Integer iCtr iCount iTabSize Boolean bExpandTabs Get pbExpandTabs to bExpandTabs If (bExpandTabs = True) Begin Get piTabSize to iTabSize Move (Repeat(" ", iTabSize)) to sSpacer End Get piLevel to iCount For iCtr from 1 to iCount If (bExpandTabs = True) Begin Move (sData + String(sSpacer)) to sData End Else Begin // Tab-character. Move (sData + (Character(9))) to sData End Loop Function_Return sData End_Function Procedure AdjustTabCount Integer iDir Integer iLevel Get piLevel to iLevel Move (iLevel+ iDir) to iLevel Set piLevel to iLevel End_Procedure Procedure AddIgnoreWord String sWord String[] sData Integer iSize Get psIgnoreWords to sData Move (SizeOfArray(sData)) to iSize Move sWord to sData[iSize] Set psIgnoreWords to sData End_Procedure Procedure AddIndentWord String sWord String[] sData Integer iSize Get psIndentWords to sData Move (SizeOfArray(sData)) to iSize Move sWord to sData[iSize] Set psIndentWords to sData End_Procedure Procedure AddUnIndentWord String sWord String[] sData Integer iSize Get psUnIndentWords to sData Move (SizeOfArray(sData)) to iSize Move sWord to sData[iSize] Set psUnIndentWords to sData End_Procedure Function HasIfBegin String sLine Returns Boolean UChar[] vArray Boolean bHas Integer iSize iComments String sStart sFin Move (Pos(("/"+"/"), sLine)) to iComments If (iComments) Begin Move (Trim(Left(sLine, iComments -1))) to sLine End Move (StringToUCharArray( (Uppercase(sLine)))) to vArray Move (SizeOfArray(vArray)) to iSize Move (UCharArrayToString( vArray,2)) to sStart Move (UCharArrayToString( vArray,iSize, (iSize-5))) to sFin Move (sStart = 'IF' and sFin = 'BEGIN') to bHas // 2016-10-18 Nils Svedmyr // There is another peculiar (old) construct like the following; // "Else If "xxx" In sFileName Begin" // ...and we deal with that here. If (bHas = False) Begin Move (UCharArrayToString(vArray, 7)) to sStart Move (sStart = 'ELSE IF' and sFin = 'BEGIN') to bHas End Function_Return bHas End_Function Function HasCase String sLine Returns Boolean Integer iPos1 iPos2 Move (Uppercase(sLine)) to sLine Move (Pos('CASE (', sLine)) to iPos1 Move (Pos('CASE ELSE', sLine)) to iPos2 Function_Return (iPos1 or iPos2) End_Function Function HasIgnoreWord String sLine Returns Boolean String[] sData Integer iSize iCtr Boolean bHas String sOne Get psIgnoreWords to sData Move (Uppercase(sLine)) to sLine Move (SizeOfArray(sData)) to iSize Decrement iSize For iCtr from 0 to iSize Move (Uppercase(sData[iCtr])) to sOne If ((Pos(sOne, sLine)) = 1) Begin Move True to bHas End Loop Function_Return bHas End_Function Function HasIndentWord String sLine Returns Boolean String[] sData Integer iSize iCtr Boolean bHas String sOne Get psIndentWords to sData Move (Uppercase(sLine)) to sLine Move (SizeOfArray(sData)) to iSize Decrement iSize For iCtr from 0 to iSize Move (Uppercase(sData[iCtr])) to sOne If ((Pos(sOne, sLine)) = 1) Begin Move True to bHas End Loop Function_Return bHas End_Function Function HasUnIndentWord String sLine Returns Boolean String[] sData Integer iSize iCtr Boolean bHas String sOne Get psUnIndentWords to sData Move (Uppercase(sLine)) to sLine Move (SizeOfArray(sData)) to iSize Decrement iSize For iCtr from 0 to iSize Move (Uppercase(sData[iCtr])) to sOne If ((Pos(sOne, sLine)) = 1) Begin Move True to bHas End Loop Function_Return bHas End_Function Function CodeLineHasComments String sLine Returns Boolean Integer iPos iPos2 Move (Pos(CS_CommentSymbol, sLine)) to iPos Move (Pos((":" + CS_CommentSymbol), sLine)) to iPos2 // Internet address! "http:" // In case of internet address; If (iPos2 > 0 and iPos2 < iPos) Begin Function_Return 0 End Function_Return iPos End_Function Function AdjustLine String sOrigLine Returns String String sTab sLine Move (Trim(sOrigLine)) to sLine Get TabCount to sTab Move (sTab + sLine) to sLine Function_Return sLine End_Function Procedure ProcessLine String sOrigLine String sLine sComment sLeft String[] sArray Integer iCommentPos UChar[] ptLine Boolean bIndent bUnIndent bIgnore bIfBegin bCase bNoAdjust Move (Trim(sOrigLine)) to sLine Get CodeLineHasComments sLine to iCommentPos If (iCommentPos > 1) Begin Move (Left(sLine, (iCommentPos-1))) to sLeft Move (Trim(sLeft)) to sLine Move (Mid(sLine, 999, iCommentPos)) to sComment End // Else If (iCommentPos = 1) Begin // Move True to bNoAdjust // End Get HasCase sLine to bCase Get HasIfBegin sLine to bIfBegin Get HasIgnoreWord sLine to bIgnore Get HasIndentWord sLine to bIndent Get HasUnIndentWord sLine to bUnIndent Case Begin Case (bNoAdjust) Move sOrigLine to sLine Case Break Case (bIgnore) Get AdjustLine sOrigLine to sLine Case Break Case (bCase) Send AdjustTabCount -1 Get AdjustLine sOrigLine to sLine Send AdjustTabCount 1 Case Break Case (bIndent or bIfBegin) Get AdjustLine sOrigLine to sLine Send AdjustTabCount 1 Case Break Case (bUnIndent) Send AdjustTabCount -1 Get AdjustLine sOrigLine to sLine Case Break Case Else Get AdjustLine sOrigLine to sLine Case Break Case End Send AddLine (sLine + (If((iCommentPos > 1), sComment, ''))) End_Procedure Procedure AddLine String sLine String[] vLines Integer iSize Get ptArray to vLines Move (SizeOfArray(vLines)) to iSize Move (sLine + (Character(13)) + (Character(10))) to vLines[iSize] Set ptArray to vLines End_Procedure Procedure End_Construct_Object // extend as required // would be better loaded form an INI file // Forward Send End_Construct_Object Send AddIgnoreWord 'Function_return' Send AddIgnoreWord 'Procedure_return' Send AddIgnoreWord 'Case Break' Send AddIgnoreWord 'Define ' Send AddIgnoreWord '#ELSE' Send AddIgnoreWord 'External_Function' Send AddIgnoreWord 'Returns ' // 2016-10-18 Nils Svedmyr // These have been read from DataFlex.lng in the DataFlex Lib folder, // and a few added // // Words that starts an indentation; Send AddIndentWord 'Begin' Send AddIndentWord 'Begin_Row' Send AddIndentWord 'Begin_Transaction' Send AddIndentWord 'Case Begin' Send AddIndentWord 'Cd_Popup_Object' Send AddIndentWord 'Class' Send AddIndentWord 'Deferred_View' Send AddIndentWord 'DFBeginHeader' Send AddIndentWord 'DFCreate_Menu' Send AddIndentWord 'Enum_List' Send AddIndentWord 'Enumeration_List' Send AddIndentWord 'For ' Send AddIndentWord 'For_all' Send AddIndentWord 'Function' Send AddIndentWord 'Object' Send AddIndentWord 'Procedure' Send AddIndentWord 'Procedure_Section' Send AddIndentWord 'Repeat' Send AddIndentWord 'Struct' Send AddIndentWord 'For_Each' Send AddIndentWord 'While' // Extra; Send AddIndentWord 'Else Begin' Send AddIndentWord 'Type ' Send AddIndentWord 'Reread' Send AddIndentWord 'Lock' Send AddIndentWord '#COMMAND' Send AddIndentWord '#HEADER' Send AddIndentWord '#IFDEF' Send AddIndentWord '#IFNDEF' Send AddIndentWord '#IF' Send AddIndentWord '#IFSame' // Words that ends an indentation; Send AddUnIndentWord 'End' Send AddUnIndentWord 'Loop' Send AddUnIndentWord 'Until' Send AddUnIndentWord 'End_Row' Send AddUnIndentWord 'End_Transaction' Send AddUnIndentWord 'Case End' Send AddUnIndentWord 'Cd_End_Object' Send AddUnIndentWord 'End_Class' Send AddUnIndentWord 'DFEndHeader' Send AddUnIndentWord 'End_Pull_Down' Send AddUnIndentWord 'End_Menu' Send AddUnIndentWord 'End_Enum_list' Send AddUnIndentWord 'End_Enumeration_list' Send AddUnIndentWord 'End_For_All' Send AddUnIndentWord 'End_Function' Send AddUnIndentWord 'End_Object' Send AddUnIndentWord 'End_Procedure' Send AddUnIndentWord 'End_Struct' Send AddUnIndentWord '#ENDHEADER' Send AddUnIndentWord 'End_for_Each' Send AddUnIndentWord 'Type_End' Send AddUnIndentWord 'Unlock' Send AddUnIndentWord 'Case Break' Send AddUnIndentWord '#ENDCOMMAND' Send AddUnIndentWord '#ENDIF' End_Procedure End_Class