Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Remove Remarks for Programs
#1
For @Dimster.  (Beta Version).

Note: Formerly incorrectly titled as a Remline clone. Thanks ahenry for the heads up!

This one lets you use the clipboard to add the path and file name, but if you prefer to just open a dialog box and select the file, I combined my remover with Steve's open dialog in post #14, here: https://qb64phoenix.com/forum/showthread...3#pid29513

Code: (Select All)
_Title "Pete's Remark-Disable"
Width 80, 25
_Font 16
_ScreenMove 20, 0
Dim i As _Integer64
Dim col As Integer
_Clipboard$ = "C:\qb64pe\steve-junk.bas"
If Len(_Clipboard$) > 100 Then
    Print "Warning: This application will erase your current clipboard contents."
    Print: Print "Press Enter to continue or Esc to quit..."
    Do
        b$ = InKey$
        If Len(b$) Then
            If b$ = Chr$(27) Then System
            If b$ = Chr$(13) Then Exit Do
        End If
        _Limit 60
    Loop
    _Clipboard$ = Chr$(0)
Else
    hold$ = _Clipboard$
    _Clipboard$ = Chr$(0)
End If
Cls
Do
    redo1:
    While -1
        Locate 1, 1: View Print CsrLin To _Height - 1: Cls 2: View Print
        Locate 1, 1: Print "Paste directory name: ": Locate 3, 1, 1, 7, 30
        Do
            _Limit 60
            b$ = InKey$
            If Len(b$) Then
                _Limit 10
                Select Case b$
                    Case Chr$(27): System
                    Case Chr$(13): dir1$ = _CWD$: Exit Do
                    Case Chr$(32): GoSub manual: If x$ = "" Then redo = 1: b$ = Chr$(8): Exit While
                End Select
            End If
            If Len(_Clipboard$) Then GoSub clip: dir1$ = x$: Exit Do
        Loop
        _Clipboard$ = Chr$(0)
        If Right$(dir1$, 1) <> "\" Then dir1$ = dir1$ + "\"
        Locate 3, 1: Print dir1$
        If _DirExists(dir1$) Then Exit While Else Print "Directory not found: "; dir1$; " Any key to redo...";: Sleep
    Wend
    If b$ = Chr$(8) Then Exit Do
    redo2:
    While -1
        Locate 5, 1: View Print CsrLin To _Height - 1: Cls 2: View Print
        Locate 5, 1: Print "Paste file name: ": Locate 7, 1
        If Len(filehold$) Then
            file1$ = filehold$: filehold$ = ""
        Else
            Do
                _Limit 60
                b$ = InKey$
                If Len(b$) Then
                    Select Case b$
                        Case Chr$(27): System
                        Case Chr$(8): redo = 1: Exit While
                        Case Chr$(32): GoSub manual: If x$ = "" Then redo = 2: b$ = Chr$(8): Exit While
                    End Select
                End If
                If Len(_Clipboard$) Then GoSub clip: file1$ = x$: Exit Do
            Loop
        End If
        _Clipboard$ = Chr$(0)
        If InStr(file1$, ".") = 0 Then file1$ = file1$ + ".bas"
        Print file1$
        If _FileExists(dir1$ + file1$) Then Exit Do Else Print "File not found: "; dir1$ + file1$; " Any key to redo...";: Sleep
    Wend
    If b$ = Chr$(8) Then Exit Do
Loop
If b$ = Chr$(8) Then GoTo redo1
If _FileExists(dir1$ + file1$) Then Else Print: Print "Error. File not found: "; dir1$ + file1$: End
Open dir1$ + file1$ For Binary As #1
a$ = Space$(LOF(1))
Get #1, , a$
Close #1
quote = 0: col = 0: i = 0: new$ = ""
Do
    i = i + 1
    x$ = Mid$(a$, i, 1)
    If Asc(x$) > 32 Then col = col + 1
    x2$ = LCase$(Mid$(a$, i, 4))
    If Mid$(x2$, 1, 1) = "'" Then
        If LTrim$(Mid$(a$, i + 2, 1)) = "$" Then x2$ = ""
    ElseIf x2$ = "rem " Then
        If Mid$(a$, i + 4, 1) <> "$" Then x2$ = "'" Else x2$ = ""
    End If
    If LCase$(Mid$(a$, i, 5)) = "data " Then dta = -1
    Select Case Mid$(x2$, 1, 1)
        Case "'"
            If quote = 0 And dta = 0 Then
                q = InStr(i, a$ + Chr$(13), Chr$(13))
                If col = 1 Then lineout% = 2 Else lineout% = 0
                i = q + lineout% - 1
                new$ = RTrim$(new$)
                If Right$(new$, 1) = ":" Then
                    new$ = Mid$(new$, 1, Len(new$) - 1) ' Remove trailing colon.
                End If
                col = 0
                _Continue
            End If
        Case Chr$(34)
            If dta = 0 Then quote = 1 - quote
        Case ":"
            If dta Then dta = 0
        Case Chr$(13), Chr$(10)
            quote = 0: col = 0: dta = 0
    End Select
    new$ = new$ + x$
Loop Until i >= Len(a$)
_Clipboard$ = a$
GoSub makefile
_KeyClear
Sleep 5
System

clip:
x$ = _Trim$(_Clipboard$)
If InStr(x$, Chr$(13)) Then x$ = Mid$(x$, 1, InStr(x$, Chr$(13)) - 1)
If InStr(x$, ".") And InStr(x$, "\") <> 0 Then
    If dir1$ = "" Then
        filehold$ = Mid$(x$, _InStrRev(x$, "\") + 1)
        x$ = Mid$(x$, 1, _InStrRev(x$, "\"))
    ElseIf dir2$ = "" Then
        filehold$ = Mid$(x$, _InStrRev(x$, "\") + 1)
        x$ = Mid$(x$, 1, _InStrRev(x$, "\"))
    End If
End If
Return

manual:
y = CsrLin: x = 12
Line Input "Type name: ", x$: Locate y, x
If Len(x$) Then _Clipboard$ = x$ Else _Clipboard$ = Chr$(0)
Return

makefile:
file1_nc$ = Mid$(file1$, 1, InStr(file1$, ".") - 1) + "_nc" + Mid$(file1$, InStr(file1$, "."))
If _FileExists(dir1$ + file1_nc$) Then
    x$ = "File: " + file1_nc$ + " already exists. Overwrite? Y/N: "
    Print: Print x$;
    Do
        _Limit 30
        b$ = InKey$
        If Len(b$) Then
            Select Case UCase$(b$)
                Case "Y": Print "Y": Exit Do
                Case "N", Chr$(27): Print: Print "File creation aborted by user...": End
            End Select
        End If
    Loop
End If
Open dir1$ + file1_nc$ For Output As #3
Print #3, new$
Close #3
Print: Print "Loading "; file1_nc$
Shell _DontWait _Hide "QB64pe.exe " + file1_nc$
Rem Shell _DontWait _Hide "notepad " + file1_nc$
Return

Utility to remove remarks and make a new file using your old file name + "_nc" added for "no comments."
It will not overwrite your original file and warns if you are going to overwrite a "_nc" file. (Like if you run it more than once).

1) Run program.

2) Go to File Explorer and copy the path to the clipboard. It will be included on the screen. You can also just press Enter if you are working out of the QB64 folder, or you can press the spacebar and it will let you type the path, manually.

3) Do the same for the file name. For .bas files you do not ave to add the extension.

4) Press any key to begin.

It will make the new 'remarkless' version and open it in QB64. If you don't want that 'feature' just REMARK out the SHELL statement.

This is a beta version, so let me know if you find any bugs or a remark situation it can't handle. Oh, it does remove trailing colons, and lines that are fully remarked, and it also skips removal for any ' or Rem keywords inside quotes. What I didn't add is the remote instances where QB64 programs have that trailing _ symbol to line wrap code that is very long.

test file: Name as: "junkme.bas"

Code: (Select All)
  ' $Dynamic
    Rem $Dynamic
  ' Simple rem line.
  ' "***": for i = 1 to 5
  Print " ' this should not be removed. Rem 123" rem this should be removed.
    a$ = "apple": ' apple
      b$ = "orange": Rem orange
        c$ = "pear" ' pear
  d$ = "banana" Rem banana
  ' line 1
      ' line 2
  Rem line 3
  Data don't
  Data "don't"
    Data "don't": ' remark.
        Data "don't": Rem remark.
    Data don't ' remark is part of data and should stay.
  Data don't rem remark is part of data and should stay, too.
Pete
Reply


Messages In This Thread
Remove Remarks for Programs - by Pete - 10-26-2024, 02:01 AM
RE: Remline clone for QB64. - by ahenry3068 - 10-26-2024, 03:33 AM
RE: Remline clone for QB64. - by ahenry3068 - 10-26-2024, 03:51 AM
RE: Remline clone for QB64. - by Pete - 10-26-2024, 04:02 AM
RE: Remline clone for QB64. - by ahenry3068 - 10-26-2024, 07:25 AM
RE: Remove Remarks for Programs - by SMcNeill - 10-26-2024, 08:16 AM
RE: Remove Remarks for Programs - by PhilOfPerth - 10-26-2024, 09:50 AM
RE: Remove Remarks for Programs - by Dimster - 10-26-2024, 01:14 PM
RE: Remove Remarks for Programs - by Dimster - 10-26-2024, 02:01 PM
RE: Remove Remarks for Programs - by SMcNeill - 10-26-2024, 09:42 PM
RE: Remove Remarks for Programs - by Pete - 10-26-2024, 10:31 PM
RE: Remove Remarks for Programs - by SMcNeill - 10-26-2024, 10:47 PM
RE: Remove Remarks for Programs - by Pete - 10-26-2024, 11:03 PM
RE: Remove Remarks for Programs - by PhilOfPerth - 10-26-2024, 11:26 PM
RE: Remove Remarks for Programs - by Pete - 10-26-2024, 11:29 PM
RE: Remove Remarks for Programs - by Dimster - 10-27-2024, 12:49 PM
RE: Remove Remarks for Programs - by SMcNeill - 10-27-2024, 01:04 PM
RE: Remove Remarks for Programs - by Dimster - 10-27-2024, 02:22 PM



Users browsing this thread: 1 Guest(s)