Skip to content

Instantly share code, notes, and snippets.

@Naheulf
Last active February 7, 2022 20:30
Show Gist options
  • Select an option

  • Save Naheulf/142b261dfc9b5efba043cd8624357803 to your computer and use it in GitHub Desktop.

Select an option

Save Naheulf/142b261dfc9b5efba043cd8624357803 to your computer and use it in GitHub Desktop.
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