Last active
February 7, 2022 20:30
-
-
Save Naheulf/142b261dfc9b5efba043cd8624357803 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| EnableExplicit | |
| CompilerIf #PB_Compiler_OS = #PB_OS_Windows | |
| #NL$ = #CRLF$ | |
| CompilerElse | |
| #NL$ = #LF$ | |
| CompilerEndIf | |
| #Regex = 0 | |
| #File = 0 | |
| Global ShowClean = #True | |
| Procedure$ SelectFile() | |
| Shared ShowClean | |
| Protected File$ | |
| CompilerIf #PB_Compiler_Debugger | |
| File$ = #PB_Compiler_File | |
| CompilerEndIf | |
| If CountProgramParameters() = 1 | |
| File$ = ProgramParameter(0) | |
| ShowClean = #False | |
| EndIf | |
| If FileSize(File$) < 0 | |
| File$ = OpenFileRequester("File to check", File$, "*.*", 0) | |
| ShowClean = #True | |
| EndIf | |
| If File$ = #Empty$ | |
| End -1 | |
| EndIf | |
| ProcedureReturn File$ | |
| EndProcedure | |
| Procedure CheckFile(File$) | |
| #Title = "PB Tool : Trailing space/tab checker" | |
| Shared ShowClean | |
| Protected LineNo = 0, Count = -1, Flags | |
| Protected Line$, Message$ | |
| If ReadFile(#File, File$) | |
| CreateRegularExpression(#Regex, "[^ \t].*( |\t)+$") | |
| Count = 0 | |
| While Eof(#File) = 0 | |
| LineNo + 1 | |
| Line$ = ReadString(#File) | |
| If MatchRegularExpression(#Regex, Line$) | |
| Count + 1 | |
| Message$ + "Line "+LineNo+": "+Line$+#NL$ | |
| EndIf | |
| Wend | |
| If Count | |
| Message$ = "Found "+Count+" Line(s) with trailing space or tab."+#NL$+#NL$+Message$ | |
| Flags = #PB_MessageRequester_Warning | |
| MessageRequester(#Title, Message$, Flags) | |
| ElseIf ShowClean | |
| Message$ = "This file seem clean." | |
| Flags = #PB_MessageRequester_Info | |
| MessageRequester(#Title, Message$, Flags) | |
| EndIf | |
| FreeRegularExpression(#Regex) | |
| Else | |
| Count = -1 | |
| Message$ = "Unable to open the file : "+#NL$+File$ | |
| MessageRequester(#Title, Message$, Flags) | |
| EndIf | |
| ProcedureReturn Count | |
| EndProcedure | |
| End CheckFile(SelectFile()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment