Program Real Line Counter. Anyone want to jump in?
#1
Mark asked about this, so I thought I whip up a little something to find out how many real line numbers are in a program. By real line numbers I'm talking about excluding spaces, but adding a line number count for the proper use of colons to separate statements on a single line.

I haven't goof proofed this yet, but I was hoping before going any further I could get some feedback or if anyone would like to modify it, etc. that's fine too. It might be fun for contests, etc. to have an "OFFICIAL" (ha ha) QB64 program line counter.

So basically it roots out trailing colons, REM statements with colons, both ' and REM, and any colons enclosed in quotes like PRINT statements. Did I miss anything? For instance, this routine counts...

CASE 1: PRINT "foo"

That colon is counted as an extra line.

CASE 1
     PRINT "foo"

If you think more conditions apply, it might be easy to add in the select case portion.

To try, just copy a forum post program or IDE program to the clipboard and run this code.
Code: (Select All)
PRINT "Line count analysis...": PRINT

x$ = _CLIPBOARD$

DO
    ' parse clipboard
    statement$ = UCASE$(MID$(x$, 1, INSTR(x$, CHR$(13)) - 1))
    x$ = MID$(x$, INSTR(x$, CHR$(10)) + 1)

    IF LEN(_TRIM$(statement$)) THEN
        program_ide_lines = program_ide_lines + 1
        FOR i = 1 TO 3
            SELECT CASE i
                CASE 1: mychr$ = CHR$(34)
                CASE 2: mychr$ = "'"
                CASE 3: mychr$ = "REM"
            END SELECT

            SELECT CASE i
                CASE 1 '  Double polling for enclosed quotes.

                    DO UNTIL INSTR(statement$, mychr$) = 0
                        IF INSTR(statement$, mychr$) THEN
                            statement$ = MID$(statement$, 1, INSTR(statement$, mychr$) - 1) + MID$(statement$, INSTR(INSTR(statement$, mychr$) + 1, statement$, mychr$) + 1)
                        END IF
                    LOOP
                CASE ELSE
                    DO UNTIL INSTR(statement$, mychr$) = 0
                        IF INSTR(statement$, mychr$) THEN
                            statement$ = MID$(statement$, 1, INSTR(statement$, mychr$) - 1)
                        END IF
                    LOOP
            END SELECT
        NEXT
        IF RIGHT$(RTRIM$(statement$), 1) = ":" THEN statement$ = MID$(RTRIM$(statement$), 1, LEN(RTRIM$(statement$)) - 1)

        REM PRINT statement$,

        ' count colons

        seed% = 0: linecnt = linecnt + 1: real_line_cnt = real_line_cnt + 1
        DO UNTIL INSTR(seed%, statement$, ":") = 0
            seed% = INSTR(seed%, statement$, ":") + 1
            real_line_cnt = real_line_cnt + 1
        LOOP
    ELSE
        program_ide_lines = program_ide_lines + 1
    END IF
    IF INSTR(x$, CHR$(10)) = 0 THEN myexit = myexit + 1
LOOP UNTIL myexit = 2
PRINT "Program IDE lines ="; program_ide_lines; "  Line count ="; linecnt; "  Real line count ="; real_line_cnt


Pete
Reply


Messages In This Thread
Program Real Line Counter. Anyone want to jump in? - by Pete - 10-22-2022, 08:10 PM



Users browsing this thread: 18 Guest(s)