Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Program Real Line Counter. Anyone want to jump in?
#12
For fun, I also started something more compact using a slightly different approach...

Code: (Select All)
DIM i AS _INTEGER64

x$ = UCASE$(_CLIPBOARD$)
IF RIGHT$(x$, 2) <> CHR$(13) + CHR$(10) THEN x$ = x$ + CHR$(13) + CHR$(10) ' Compensates for 1-line no return Notepad copy.

PRINT "Line count analysis...": PRINT

DO
    LINE INPUT "Count statements beginning with REM or ' as a line? [Y] / [N]: "; rem_ans$: PRINT
    rem_ans$ = UCASE$(rem_ans$)
    IF INSTR("YN", rem_ans$) THEN EXIT DO
LOOP

PRINT "Press [1] to parse all colons or [2] the exclude colons after an IF statement.": PRINT

DO
    _LIMIT 30
    b$ = INKEY$
    IF LEN(b$) THEN
        SELECT CASE b$
            CASE CHR$(27): SYSTEM
            CASE "1": PRINT "Parsing all significant colons...": EXIT DO
            CASE "2": myopt = -1: PRINT "Parsing all significant colons not used in IF/THEN one line statements.": EXIT DO
        END SELECT
    END IF
LOOP
PRINT
_KEYCLEAR

FOR i = 1 TO LEN(x$)
    a$ = MID$(x$, i, 1)
    'PRINT i; ASC(MID$(x$, i, 1)); MID$(x$, i, 1); "  p1$ = "; parse1$; "  p2$ = "; parse2$; "  p3$ = "; parse3$: SLEEP
    IF a$ = CHR$(13) OR a$ = CHR$(10) THEN
        IF a$ = CHR$(10) THEN
            c$ = "": parse1$ = "": parse2$ = "": parse3$ = "": ide_line_cnt = ide_line_cnt + 1
            'PRINT s$, LEN(s$): SLEEP
            IF LEN(s$) = 0 THEN blank_line_cnt = blank_line_cnt + 1
            s$ = ""
        END IF
    ELSE
        s$ = s$ + a$
        c$ = c$ + a$
        IF myopt THEN
            IF c$ = "THEN " THEN IF parse1$ = "" AND parse2$ = "" THEN parse3$ = "off"
        END IF
        IF a$ = "'" OR c$ = "REM " THEN
            IF parse1$ = "" AND parse2$ = "" THEN parse1$ = "off"
            IF _TRIM$(s$) = _TRIM$(c$) THEN rem_lines = rem_lines + 1
        END IF
        IF a$ = " " THEN c$ = ""
        IF parse1$ <> "off" THEN
            IF a$ = CHR$(34) THEN IF parse1$ = "" AND parse3$ = "" THEN IF parse2$ = "off" THEN parse2$ = "" ELSE parse2$ = "off"
            IF parse2$ <> "off" THEN
                IF parse3$ <> "off" THEN
                    IF col$ = "on" THEN IF a$ <> " " AND a$ <> ":" THEN col$ = ""
                    IF a$ = ":" AND col$ = "" THEN col$ = "on": c_cnt = c_cnt + 1
                END IF
            END IF
        END IF
    END IF
    IF a$ = "_" THEN IF MID$(x$, i + 1, 1) = CHR$(13) THEN IF parse1$ = "" AND parse2$ = "" AND parse3$ = "" THEN cont_lines = cont_lines + 1
NEXT
IF rem_ans$ = "Y" THEN
    PRINT "IDE Lines ="; ide_line_cnt; "  Statement Lines ="; ide_line_cnt - blank_line_cnt - cont_lines; "  Real Lines ="; ide_line_cnt - blank_line_cnt - cont_lines + c_cnt
ELSE
    PRINT "IDE Lines ="; ide_line_cnt; "  Statement Lines Without Remark Lines ="; ide_line_cnt - blank_line_cnt - cont_lines - rem_lines; "  Real Lines ="; ide_line_cnt - blank_line_cnt - cont_lines - rem_lines + c_cnt
END IF

Pete
Reply


Messages In This Thread
RE: Program Real Line Counter. Anyone want to jump in? - by Pete - 10-23-2022, 01:51 AM



Users browsing this thread: 22 Guest(s)