Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Program Real Line Counter. Anyone want to jump in?
#11
Okay, added Steve's suggestions and Mark's REM option.

Code: (Select All)
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": myopt = 3: PRINT "Parsing all significant colons...": PRINT
            CASE "2": myopt = 4: PRINT "Parsing all significant colons not used in IF/THEN one line statements.": PRINT
        END SELECT
        IF myopt THEN EXIT DO
    END IF
LOOP
_KEYCLEAR

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

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

    DO
        IF RIGHT$(RTRIM$(statement$), 1) = "_" THEN ' Combined statement.
            statement$ = statement$ + UCASE$(MID$(x$, 1, INSTR(x$, CHR$(13)) - 1))
            x$ = MID$(x$, INSTR(x$, CHR$(10)) + 1)
            program_ide_lines = program_ide_lines + 1
        ELSE
            EXIT DO
        END IF
    LOOP

    IF LEN(_TRIM$(statement$)) THEN
        program_ide_lines = program_ide_lines + 1
        FOR i = 1 TO myopt
            SELECT CASE i
                CASE 1: mychr$ = CHR$(34)
                CASE 2: mychr$ = "'"
                CASE 3: mychr$ = "REM "
                CASE 4: mychr$ = " THEN "
            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
                            IF myopt = 3 THEN IF rem_ans$ = "N" THEN IF MID$(statement$, 1, 4) = "REM " OR LEFT$(statement$, 1) = "'" THEN linecnt = linecnt - 1: real_line_cnt = real_line_cnt - 1
                            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)
        ' Parse significant single colons.
        DO UNTIL INSTR(statement$, " ") = 0
            statement$ = MID$(statement$, 1, INSTR(statement$, " ") - 1) + MID$(statement$, INSTR(statement$, " ") + 1)
        LOOP
        ' Now look for double or multiple colons and remove them
        DO UNTIL INSTR(statement$, "::") = 0
            statement$ = MID$(statement$, 1, INSTR(statement$, ":") - 1) + MID$(statement$, INSTR(statement$, ":") + 1)
        LOOP
        ' 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
LOOP UNTIL x$ = ""
IF rem_ans$ = "Y" THEN
    PRINT "Program IDE lines ="; program_ide_lines; "  Line count ="; linecnt; "  Real line count ="; real_line_cnt
ELSE
    PRINT "Program IDE lines ="; program_ide_lines; "  Line count without remark lines ="; linecnt; "  Real line count ="; real_line_cnt
END IF


Pete
Shoot first and shoot people who ask questions, later.
Reply


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



Users browsing this thread: 16 Guest(s)