Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Remove Remarks for Programs
#11
I updated mine and included a test file.

I'm old school, that's for sure. I do love the new QB64 features that cut out a lot of code but I'm just set in may ways about coding the routines from scratch. It's all I can do to stop myself from just writing the routine in machine code! j/k. Only did that headache once.

Steve, if you run my test code with your routine, you will see you need to add a few things...

Test file results after running Steve's routine...
--------------------------------------------------------------------------- 

Rem $Dynamic


Print " ' this should not be removed. Rem 123" rem this should be removed.
a$ = "apple":
b$ = "orange": Rem orange
c$ = "pear"
d$ = "banana" Rem banana
 
     
Rem line 3
Data don
Data "don't"
Data "don't":
Data "don't": Rem remark.
Data don
Data don
---------------------------------------------------------------------------


Test file results after running Pete's routine...
---------------------------------------------------------------------------
' $Dynamic
Rem $Dynamic
Print " ' this should not be removed. Rem 123"
a$ = "apple"
b$ = "orange"
c$ = "pear"
d$ = "banana"
Data don't
Data "don't"
Data "don't"
Data "don't"
Data don't ' remark is part of data and should stay.
Data don't rem remark is part of data and should stay, too.
----------------------------------------------------------------------------

The test file is posted in post #1, but I'll repost it here so it's easy to see

Test file --------------------------
  ' $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.
---------------------------------------------------------------------------

The random indentations were made to make sure the routines can handle indenting.

If you guys find any errors in mine, let me know. There's a good chance I may have missed something. Actually Steve got ' $ for meta commands, and I added Rem $, which was also used back in the day. I love it that forums provide more hands on deck to make improving a project easier. Thanks guys,

Pete
Reply
#12
I didn't code mine to look for REM or DATA at all.  I figure those are generally edge cases and not something which I tend to code into my own stuff very often.  

If DATA has colons in it, then  they should be inside quotes, INHO.  If not, then you're ust asking for troubles. Tongue

It'd be easy enough to expand upon, if one needed to, but I think it does everything I need for my personal use.  

Personally, I think before I tried to remove remarks from code like you're testing, I'd first do a simple Find-and-Replace for " REM " and replace that with " ' ".  Big Grin
Reply
#13
Basically that replace Rem with ' is what mine is essentially doing.

Now back in the day, we were a pretty tough bunch. Find one little oopsie in a routine and 10 members were eating your lunch! Ah, the good ol' days. No participation trophies. Big Grin 

Okay, I'll comprise, for our kids sake: @Dimster, here is a combo of Pete and Steve's remark remover. It uses Steve's new age QB64  cool way to look up your file, with my remove remarks code. It's EXCELLENT!

Code: (Select All)
_Title "Pete and Steve's Excellent Adventure"
Do
BasIn$ = _OpenFileDialog$("File to Remove Comments From", "", "*.bas|*.bi|*.bm", "QB64PE files", 0)
If BasIn$ <> "" Then
period = _InStrRev(BasIn$, ".")
BasOut$ = Left$(BasIn$, period - 1) + "_nc" + Mid$(BasIn$, period)
Open BasIn$ For Binary As #1
a$ = Space$(LOF(1))
Get #1, , a$
Close #1
Open BasOut$ For Output As #2
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$)
Print #2, new$
Shell _DontWait _Hide "QB64pe.exe " + BasOut$
Rem Shell _DontWait _Hide "notepad " + BasOut$
Rem _OpenFileDialog$("Here's your RemLess file!", BasOut$)
Close #2: Exit Do
Else
Exit Do
End If
Loop
System

Well, it beats the hell out of anything Bill (Sheldon) and Ted (Clippy) could ever put together. Big Grin

Pete


For Phil. Rem/Unrem any of the last few lines for how you would like to gain access to the new file.
Reply
#14
(10-26-2024, 11:03 PM)Pete Wrote: Basically that replace Rem with ' is what mine is essentially doing.

Now back in the day, we were a pretty tough bunch. Find one little oopsie in a routine and 10 members were eating your lunch! Ah, the good ol' days. No participation trophies. Big Grin 

Okay, I'll comprise, for our kids sake: @Dimster, here is a combo of Pete and Steve's remark remover. It uses Steve's new age QB64  cool way to look up your file, with my remove remarks code. It's EXCELLENT!

Code: (Select All)

_Title "Pete and Steve's Excellent Adventure"
Do
    BasIn$ = _OpenFileDialog$("File to Remove Comments From", "", "*.bas|*.bi|*.bm", "QB64PE files", 0)
    If BasIn$ <> "" Then
        period = _InStrRev(BasIn$, ".")
        BasOut$ = Left$(BasIn$, period - 1) + "_nc" + Mid$(BasIn$, period)
        Open BasIn$ For Binary As #1
        a$ = Space$(LOF(1))
        Get #1, , a$
        Close #1
        Open BasOut$ For Output As #2
        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$)
        Print #2, new$
        Close #2: Exit Do
    Else
        Exit Do
    End If
Loop
System

Well, it beats the hell out of anything Bill (Sheldon) and Ted (Clippy) could ever put together. Big Grin


Pete

Very nice! But it would be nicer if it told you it was successful, and the name of the new file. I was looking at the one created prevously (by Steve's version), not realizing it had a different name, and could see no improvements..
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply
#15
@PhilOfPerth

Well, there's at least one of that ******* tough crowd from days past I mentioned. Okay, okay, okay... Now it opens the new code in the QB64 IDE.

Pete Big Grin
Shoot first and shoot people who ask questions, later.
Reply
#16
Steve - I make the change to line 26 as you suggested but now getting an invalid name error on that line. I believe the old line 26 simply read "Print #2, o$". Is that correct?
Pete - not sure what I'm doing wrong but seems I'm constantly getting "File Not Found". Something seems to be off with path?
Reply
#17
(10-26-2024, 09:42 PM)SMcNeill Wrote: Change line 26 to:

If _TRME$(o$) <> "" _OrElse temp$ = "" Then Print #1, o$

That should get rid of those blank lines for you, while preserving blank lines which existed originally in your code between SUBS or whatever.

(10-27-2024, 12:49 PM)Dimster Wrote: Steve - I make the change to line 26 as you suggested but now getting an invalid name error on that line. I believe the old line 26 simply read "Print #2, o$". Is that correct?
Pete - not sure what I'm doing wrong but seems I'm constantly getting "File Not Found". Something seems to be off with path?

Invalid name is correct, as I can't type on the iPad worth a hoot at 2am. Tongue

Try this:

If _TRIM$(o$) <> "" _OrElse temp$ = "" Then Print #2, o$

Whole version with the change to completely eliminate those extra lines for you:

Code: (Select All)
Do
BasIn$ = _OpenFileDialog$("File to Remove Comments From", "", "*.bas|*.bi|*.bm", "QB64PE files", 0)
If BasIn$ <> "" Then
period = _InStrRev(BasIn$, ".")
BasOut$ = Left$(BasIn$, period - 1) + " (No Rem)" + Mid$(BasIn$, period)
Open BasIn$ For Binary As #1
Open BasOut$ For Output As #2
Do Until EOF(1)
Line Input #1, temp$
in_quote = 0
For p = 1 To Len(temp$)
m$ = Mid$(temp$, p, 1)
Select Case m$
Case Chr$(34) 'quote
in_quote = Not in_quote
Case "'" 'Remark character
If Not in_quote Then 'remark found
If p = 1 _Andalso Mid$(temp$, 2, 1) = "$" Then p = Len(temp$) + 1 'it's a metacommand
Exit For
End If
Case "$"
If p = 1 Then p = Len(temp$) + 1 'it's a metacommand
End Select
Next
o$ = Left$(temp$, p - 1)
If _Trim$(o$) <> "" _Orelse temp$ = "" Then Print #2, o$
Loop
Else System
End If
Loop
Reply
#18
Like a charm Steve, like a charm. Cleans a programs' comments up so nicely.
Reply




Users browsing this thread: 3 Guest(s)