Posts: 2,160
Threads: 222
Joined: Apr 2022
Reputation:
102
10-22-2022, 08:10 PM
(This post was last modified: 10-22-2022, 10:25 PM by Pete.)
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
Posts: 3,932
Threads: 175
Joined: Apr 2022
Reputation:
215
Yes you are on track. The case of difficulty I have in mind is a legit one line use of colon in an Single line IF.
It might be debatable if that is legit use of colon as not counting as more than one statement, I would say... I don't know!?
If there is an IF, THEN if something follow THEN ignore it? (as far as colon counting goes).
If a <> b then a = a + 1 : b = b + 3 : goto anotherLine
Isn't that one line equivalent to
if a<>b then
a = a+1
b = b+ 3
goto anotherLine
end if
Do you see what I am getting at?
b = b + ...
Posts: 2,695
Threads: 326
Joined: Apr 2022
Reputation:
217
Don't forget to count underscore ending lines as continuous lines.
PRINT _
"Hello _
World"
The above is only one line of code, formatted to lay across multiple lines in the IDE for readability.
Posts: 2,695
Threads: 326
Joined: Apr 2022
Reputation:
217
10-22-2022, 08:52 PM
(This post was last modified: 10-22-2022, 08:52 PM by SMcNeill.)
And, of course, colons don't necessary mean there's an extra line after them. I've seen code by at least a few of our members that looks like:
Locate 10, 10:: Print "Hello World"
Multiple colons for formatting, or searching, or some oddish reason -- but they do exist in various code snippets people have shared in the past.
Posts: 3,932
Threads: 175
Joined: Apr 2022
Reputation:
215
(10-22-2022, 08:52 PM)SMcNeill Wrote: And, of course, colons don't necessary mean there's an extra line after them. I've seen code by at least a few of our members that looks like:
Locate 10, 10:: Print "Hello World"
Multiple colons for formatting, or searching, or some oddish reason -- but they do exist in various code snippets people have shared in the past.
Someone's just colon happy, it should count against them for the excess ;-)
b = b + ...
Posts: 2,160
Threads: 222
Joined: Apr 2022
Reputation:
102
10-22-2022, 09:17 PM
(This post was last modified: 10-22-2022, 10:12 PM by Pete.
Edit Reason: Improved for Notepad 1-liners.
)
Try this...
Code: (Select All) PRINT "Line count analysis...": PRINT
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
x$ = _CLIPBOARD$
IF RIGHT$(x$, 2) <> CHR$(13) + CHR$(10) THEN x$ = x$ + CHR$(13) + CHR$(10) ' Compenstates for 1-line no return Notepad copy.
DO
' parse clipboard
statement$ = UCASE$(MID$(x$, 1, INSTR(x$, CHR$(13)) - 1))
IF INSTR(statement$, CHR$(10)) THEN BEEP
IF INSTR(statement$, CHR$(13)) THEN BEEP
'''IF statement$ = CHR$(10) THEN statement$ = ""
x$ = MID$(x$, INSTR(x$, CHR$(13)) + 2)
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
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
LOOP UNTIL x$ = ""
PRINT "Program IDE lines ="; program_ide_lines; " Line count ="; linecnt; " Real line count ="; real_line_cnt
Shoot first and shoot people who ask questions, later.
Posts: 3,932
Threads: 175
Joined: Apr 2022
Reputation:
215
10-22-2022, 10:18 PM
(This post was last modified: 10-22-2022, 10:18 PM by bplus.)
OK I put my counts at bottom in comment:
Code: (Select All) Print "Line count analysis...": Print ' 1
Print "Press [1] to parse all colons or [2] the exclude colons after an IF statement.": Print '2
Do
_Limit 30
b$ = InKey$
If Len(b$) Then
Select Case b$
Case Chr$(27): System ' 3
Case "1": myopt = 3: Print "Parsing all significant colons...": Print ' 6
Case "2": myopt = 4: Print "Parsing all significant colons not used in IF/THEN one line statements.": Print ' 9
End Select
If myopt Then Exit Do
End If
Loop
x$ = _Clipboard$ + Chr$(13)
Do
' parse clipboard
statement$ = UCase$(Mid$(x$, 1, InStr(x$, Chr$(13)) - 1))
If statement$ = Chr$(10) Then statement$ = ""
x$ = Mid$(x$, InStr(x$, Chr$(13)) + 1)
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) '10
Case 2: mychr$ = "'" '11
Case 3: mychr$ = "REM " '12
Case 4: mychr$ = " THEN " '13
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 ' 15
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$ = ""
Print "Program IDE lines ="; program_ide_lines; " Line count ="; linecnt; " Real line count ="; real_line_cnt
' 66 lines 9 blank lines = 57 + 15 colons = 72
They match what your code comes up with but should we count a line that is only a comment?
b = b + ...
Posts: 2,160
Threads: 222
Joined: Apr 2022
Reputation:
102
Sounds like another option. Oh shite on a stike, multiple options makes me think of what Steve is doing with pointers. Oh the freakin' horror! Oh well, Halloween's closing in.
Next up will address your REM lines, and Steve's two observations. Stay tuned. Same bat channel. Same bat station.
Pete
Posts: 3,932
Threads: 175
Joined: Apr 2022
Reputation:
215
Meanwhile at another loacation MasterGy's Shaddowing program hand counted at 89 Ide - 20 blank + 85 = 154 LOC
Petes colon code got 155 and I wouldn't be surprised if I missed a colon:
Code: (Select All) picture$ = "" '<-------- enter an image or leave the field blank
'texture
If _FileExists(picture$) Then
text = _LoadImage(picture$, 33)
Else
temp = _NewImage(1, 1, 32): _Dest temp: Cls , _RGB32(255, 255, 255): text = _CopyImage(temp, 33): _FreeImage temp ' 4
End If
'window
monx = 800: mony = Int(monx / _DesktopWidth * _DesktopHeight): monm = monx * .008: mon = _NewImage(monx, mony, 32): Screen mon: _FullScreen: _DisplayOrder _Hardware , _Software '10
Const pip180 = 3.141592 / 180
Dim Shared me(9), cosrotz, sinrotz, cosrotx, sinrotx, sinrot_cs, cosrot_cs
'cube locations, sizes
Randomize Timer
cube_res = 1000: cube_deep = 1000 '11
temp = _NewImage(cube_res - 1, cube_deep - 1, 32): _Dest temp: For t = 0 To cube_res - 1: For t2 = 0 To cube_deep - 1 ' 14
PSet (t, t2), _RGBA32(0, 0, 0, Int(255 / (cube_deep - 1) * t2) - 3)
Next t2, t: cube_text = _CopyImage(temp, 33): _FreeImage temp ' 16
'mask distance behind texture
Dim shdw_m(15000): For t = 0 To 15000: shdw_m(t) = Interpolate(.999, .97, 1 / 15000 * t): Next t ' 19
mapdim = 1000
'make cubes
obj_c = 200
Dim obj(obj_c - 1, 9): _Source deep_text: For t = 0 To obj_c - 2: For t2 = 0 To 2: obj(t, t2) = mapdim * Rnd: obj(t, t2 + 3) = 10 + 40 * Rnd: Next t2, t ' 25
For t = 0 To 2: obj(obj_c - 1, 3 + t) = mapdim / 2: obj(obj_c - 1, t) = mapdim / 2: Next t ' 28
For t = 0 To 2: me(t) = mapdim / 2: Next t: light = .2: me(4) = -.2: ut_me4 = -.2: ylook_limit = 80 'radian ' 34
_Dest mon
Locate 1, 1: Print "moving:WASD looking:mouse light adjust : mousewheel" ' 35
Dim p(3, 2), p2(3, 2), pc(7, 9)
Do: _Limit 30
'control
mouse_sens_xy = .01: mouse_sens_z = .01 ' 36
mousex = 0: mousey = 0: mousew = 0: While _MouseInput: mousex = mousex + _MouseMovementX: mousey = mousey + _MouseMovementY: mousew = mousew + _MouseWheel: Wend ' 43
me(3) = me(3) + mousex * mouse_sens_xy: me(4) = me(4) + mousey * mouse_sens_z ' 44
ylook_deg = ((me(4) / pip180) + 90): If Abs(ylook_deg) > ylook_limit Then me(4) = ut_me4 Else ut_me4 = me(4) ' 45
rot_cs = (rot_cs + mousex * .001 * Abs(Sin(me(4)))) * .9
light = light - mousew * 0.005: If light < 0 Then light = 0 Else If light > 1 Then light = 1 ' 46
Locate 2, 1: Print "light:"; Int(light * 100); "% " ' 47
position_speed = 5
kw = _KeyDown(119): ks = _KeyDown(115): ka = _KeyDown(97): kd = _KeyDown(100): new_direction = (Abs(ka Or kd Or kw) Or -Abs(ks)) * position_speed ' 51
deg_XY = -90 * Abs(ka) + 90 * Abs(kd): szog_xy = me(3) + deg_XY * pip180: szog_z = me(4) ' 53
me(0) = me(0) - Sin(szog_xy) * (1 - Cos(szog_z)) * new_direction
me(1) = me(1) - Cos(szog_xy) * (1 - Cos(szog_z)) * new_direction
me(2) = me(2) - Cos(szog_z + _Pi) * new_direction
cosrotz = Cos(me(3)): sinrotz = Sin(me(3)): cosrotx = Cos(me(4)): sinrotx = Sin(me(4)): cosrot_cs = Cos(rot_cs): sinrot_cs = Sin(rot_cs) 'to rotating angles ' 58
'draw cubes
px1 = cube_res / 2: px2 = cube_res - 2 ' 59
dl = cube_deep - 3: c_dis = Interpolate(50, 2500, light): temp = cube_deep / c_dis ' 61
For a_obj = 0 To obj_c - 1: For t = 0 To 7 ' 62
For t2 = 0 To 2: pc(t, t2) = (obj(a_obj, 3 + t2) * (Sgn(t And 2 ^ t2) * 2 - 1) + (obj(a_obj, t2) - me(t2))): Next t2 ' 64
rotate pc(t, 0), pc(t, 1), pc(t, 2)
pc(t, 3) = Sqr(pc(t, 0) * pc(t, 0) + pc(t, 1) * pc(t, 1) + pc(t, 2) * pc(t, 2))
sm = shdw_m(Abs(Int(pc(t, 2))))
For t2 = 0 To 2: pc(t, 4 + t2) = pc(t, t2) * sm: Next t2 ' 66
Next t
For t = 0 To 5: For t2 = 0 To 3: side(t2) = Val(Mid$("024623673175105445670123", 1 + t * 4 + t2, 1)): For t3 = 0 To 2: p(t2, t3) = pc(side(t2), t3): p2(t2, t3) = pc(side(t2), t3 + 4): Next t3, t2 ' 72
'texture
_MapTriangle (0, 0)-(_Width(text) - 1, 0)-(0, _Height(text)), text To(p(0, 0), p(0, 1), p(0, 2))-(p(1, 0), p(1, 1), p(1, 2))-(p(2, 0), p(2, 1), p(2, 2)), , _Smooth
_MapTriangle (_Width(text), _Height(text))-(_Width(text) - 1, 0)-(0, _Height(text)), text To(p(3, 0), p(3, 1), p(3, 2))-(p(1, 0), p(1, 1), p(1, 2))-(p(2, 0), p(2, 1), p(2, 2)), , _Smooth
'shadow mask
For t2 = 0 To 3: py(t2) = Int(temp * pc(side(t2), 3)): If py(t2) > dl Then py(t2) = dl ' 74
Next t2
_MapTriangle (1, py(0))-(px1, py(1))-(px2, py(2)), cube_text To(p2(0, 0), p2(0, 1), p2(0, 2))-(p2(1, 0), p2(1, 1), p2(1, 2))-(p2(2, 0), p2(2, 1), p2(2, 2)), , _Smooth
_MapTriangle (1, py(3))-(px1, py(1))-(px2, py(2)), cube_text To(p2(3, 0), p2(3, 1), p2(3, 2))-(p2(1, 0), p2(1, 1), p2(1, 2))-(p2(2, 0), p2(2, 1), p2(2, 2)), , _Smooth
Next t, a_obj
_Display
Loop
Function Interpolate (a, b, x): Interpolate = a + (b - a) * x: End Function ' 76
Sub rotate (px, py, pz2): px3 = px * cosrotz - py * sinrotz: py2 = px * sinrotz + py * cosrotz: py3 = py2 * cosrotx - pz2 * sinrotx: pz3 = py2 * sinrotx + pz2 * cosrotx '80
px4 = px3 * cosrot_cs - py3 * sinrot_cs: py4 = px3 * sinrot_cs + py3 * cosrot_cs: px = -px4: py = -py4: pz2 = -pz3: End Sub ' 85
' hand cound 89 Ide - 20 blank + 85 colons = 154 lines
It has another line now with my last comment added.
b = b + ...
Posts: 2,160
Threads: 222
Joined: Apr 2022
Reputation:
102
10-22-2022, 11:23 PM
(This post was last modified: 10-23-2022, 12:32 AM by Pete.)
Ah let's not call it "Pete's colon count." I'd like to think when I'm counting out loud I can't be accused of talking out of my ASCII.
So in that program, there are 90 colons, but 4 of them are enclosed in parentheses as PRINT statement, so that makes 86 extra lines produced by colons to add to the 69 program lines that contain remarks or statements, making a total of 155 real coding lines.
The not counting remark lines is a little wonkie, because it was an afterthought. I'll post that below, soon.
Pete
|