RE: Program Real Line Counter. Anyone want to jump in? - OldMoses - 10-23-2022
Pete's "Double Parked Colon Enforcer" has an ominous sound to it, but still a useful tool.
I think I'll bugger a few of my programs with it. I tend to use a lot of comments and whitespace and always wondered how many actual code lines the big ones contain.
RE: Program Real Line Counter. Anyone want to jump in? - bplus - 10-23-2022
(10-23-2022, 05:28 AM)Pete Wrote: Well unless anyone else has anything missed to add, I think this cake is backed. I like method #2 best, but I haven't speed tested them. Too me, QB64 handles these types a text functions so fast, it really doesn't make much of a difference.
Now, if nothing more gets added, we just need some beta tests to see if anything can be broke or simply doesn't function as expected.
Pete
(10-23-2022, 06:03 AM)PhilOfPerth Wrote: I'm a bit bemused by all of this... why is it important to know how many lines it can be broken down into? Does this have a bearing on a programmes's speed, or usefulness, or memory-useage? Surely the file size and design can tell you what you need to know?
(10-23-2022, 06:10 AM)Pete Wrote: 1) It's parsing, which makes it fun.
2) Practical use: Contests.
Once in a blue moon someone will put together a contest. Maybe write a pong game in 100 lines or less. Maybe even fewest lines wins. Anyway, colons make it possible to place many statements on a single line. Parsing out the colons, which serve that purpose, makes judging the actual lines used to code the program quantifiable.
Pete
Like I always say, "Don't take it parsenally!"
(10-23-2022, 08:35 AM)SMcNeill Wrote: Now what you need to work on is a QB64PE-Merge program which recursively loads all $INCLUDE files and then saves the whole program as a singular BAS file for total line count, quick reference, formatting, and debugging purposes. 
Ha! I am jumping in today because what I would like to do is rewrite MasterGY's 89 IDE lines with 20 blank lines but 85 colons to 174 IDE lines without all the dang colons, so I might begin to study the thing.
So that would be the use of this little excursion.
Steve makes a good point about counting lines in includes. Using include for my GUI experiment was not really helpful but then I was still working on the Include code.
So the cake may be baked but I haven't gazed upon it frosted.
Oh I missed Old Moses post, yes it is interesting how many actual LOC it took to do something or what some function costs in LOC.
Isn't it a sign of a smart coder to get something done with less LOC and not taking off points for blank lines and comments.
RE: Program Real Line Counter. Anyone want to jump in? - Pete - 10-23-2022
Those Q-B-64 IF THENs add some more
Type um up, execute, optimize and sell it to the app store
But I gotta keep coding
Ohh, I'm parsing my life away
Lookin' for a better way... for me...
- I thought I saw an Eddie Rabbit. I did , I did!
Seriously, if this app can help with a contest, great, or if someone just wants to compare how many lines of code it took them to make a project, without changing their coding style well that's nice, too; but if it never gets used it was still fun to think through and code.
As for the $INCLUDE, I thought about that but it isn't practical letting anyone use it in a contest, so no worries about INCLUDING $INCLUDE in this app and I won't be going down that Eddie Rabbit hole anytime soon. Decades ago I wrote a program that rewrote itself on the fly, similar to how $INCLUDE works. Just another Eddie Rabbit, I mean Cheap Trick way of coding to break the rules. Kind of like the snow job I made for the Winter forum banner!
Pete
RE: Program Real Line Counter. Anyone want to jump in? - Pete - 10-23-2022
Ah, thought of another one.
Now I need to figure out a way to exclude a colon used as a label
Myline:
This gets a lilte wonkie because labels can have other statements on them..
Myline: a = 2
I would write that as:
Myline:
a = 2
...but coding styles differ.
Remarks are already in the code so no problem with...
Myline: ' Hey, that's my line!
Wait, I think I have it. In the case of a label the IDE pins the colon to the last character. No space. Of course if someone is writing in Notepad, it's not always going to be that way.
This one might not fit all possible conditions outside the IDE. I'm sure not going to add keyword parsing to this little app.
Pete
RE: Program Real Line Counter. Anyone want to jump in? - bplus - 10-23-2022
Oh I am glad I read this before I started rewriting source programs!
Good catch Sir Pete!
RE: Program Real Line Counter. Anyone want to jump in? - Pete - 10-23-2022
(10-23-2022, 06:21 PM)bplus Wrote: Oh I am glad I read this before I started rewriting source programs!
Good catch Sir Pete!
@bplus
Well I think I have that worked out now.
ALSO, and this is a biggie...
After the program finishes the real lines are placed on your clipboard. You could try and copy the forum code for MG's shadow effects to your clipboard, run this app, open an IDE, and paste 155 un-colonized lines that should run the same as the original.
Now in DEBUG stage. Found one bug with failure to close IF/THEN tags in complex nested statement blocks.
Code: (Select All) WIDTH 100, 25
_SCREENMOVE _MIDDLE
DIM i AS _INTEGER64
z$ = _CLIPBOARD$
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. [2] to exclude colons in one-line IF/THEN statements.": 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)
IF a$ = CHR$(13) OR a$ = CHR$(10) THEN
IF a$ = CHR$(10) THEN
IF label_check THEN
tmp$ = _TRIM$(MID$(s$, INSTR(s$, ":") + 1))
IF MID$(tmp$, 1, 3) = "REM" OR LEFT$(tmp$, 1) = "'" OR tmp$ = CHR$(10) + CHR$(13) OR tmp$ = "" THEN ELSE MID$(z$, label_check, 1) = CHR$(0): c_cnt = c_cnt + 1
END IF
if_block$ = "": then_marker = 0
c$ = "": parse1$ = "": parse2$ = "": parse3$ = "": label_check = 0: ide_line_cnt = ide_line_cnt + 1
IF parse4$ = "off" THEN rem_lines = rem_lines + 1
IF LEN(s$) = 0 THEN blank_line_cnt = blank_line_cnt + 1
s$ = ""
ELSE
IF if_block$ = "on" THEN
MID$(z$, i, 1) = CHR$(255): MID$(z$, then_marker, 1) = CHR$(0): c_cnt = c_cnt + 1 ' Add one line for the END IF
if_block$ = "": then_marker = 0
END IF
END IF
ELSE
s$ = s$ + a$
c$ = c$ + a$
IF myopt THEN IF c$ = "THEN " THEN IF parse1$ = "" AND parse2$ = "" AND parse4$ = "" THEN parse3$ = "off"
IF myopt = 0 THEN IF c$ = "THEN " THEN then_marker = i
IF s$ = "$IF THEN" THEN parse4$ = "off": parse1$ = "": parse2$ = "": parse3$ = ""
IF a$ = "'" OR c$ = "REM " THEN
IF parse1$ = "" AND parse2$ = "" AND parse3$ = "" AND parse4$ = "" THEN parse1$ = "off"
IF _TRIM$(s$) = _TRIM$(c$) THEN rem_lines = rem_lines + 1
END IF
IF parse4$ = "off" THEN IF s$ = "$END IF " THEN parse4$ = ""
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 parse4$ <> "off" THEN
IF myopt = 0 AND then_marker THEN IF a$ = ":" THEN IF if_block$ = "" THEN if_block$ = "on"
IF col$ = "on" THEN IF a$ <> " " AND a$ <> ":" THEN col$ = ""
IF a$ = ":" THEN ' Test for label.
IF INSTR(MID$(LTRIM$(s$), 1, INSTR(LTRIM$(s$), ":")), " ") = 0 THEN
label_check = i + 1
ELSE
IF col$ = "" THEN col$ = "on": c_cnt = c_cnt + 1: MID$(z$, i, 1) = CHR$(0)
END IF
END IF
END IF
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
_CLIPBOARD$ = ""
FOR i = 1 TO LEN(z$)
a$ = MID$(z$, i, 1)
IF a$ = CHR$(0) THEN
concat$ = concat$ + CHR$(13) + CHR$(10)
ELSEIF a$ = CHR$(255) THEN
concat$ = concat$ + CHR$(13) + "END IF"
ELSE
concat$ = concat$ + a$
END IF
NEXT
_CLIPBOARD$ = concat$
PRINT: PRINT "Program line rewrite was added to your clipboard."
Pete
RE: Program Real Line Counter. Anyone want to jump in? - bplus - 10-23-2022
Well if that's it, my work is done!
I hope you did keep the blank lines because those are relief to eyes and comments are needed for help explaining...
RE: Program Real Line Counter. Anyone want to jump in? - Pete - 10-23-2022
This one does keep the blank lines, it just ignores them in the count. It could be easily modified to strip the blank lines out. I'm considering that for a proof of real line numbers. For instance, if you run MG's app through the program with "Y" and "1" options, you get a paste of 175 IDE lines, so 20 of those are blank lines for spacing.
Pete
RE: Program Real Line Counter. Anyone want to jump in? - bplus - 10-23-2022
(10-23-2022, 07:39 PM)Pete Wrote: This one does keep the blank lines, it just ignores them in the count. It could be easily modified to strip the blank lines out. I'm considering that for a proof of real line numbers. For instance, if you run MG's app through the program with "Y" and "1" options, you get a paste of 175 IDE lines, so 20 of those are blank lines for spacing.
Pete
That's just about it! I see only one missed colon after Do but all the colons enclosed in Print " : " preserved.
I ran the revised program and according to screen shot is working fine.
Rewrite MasterGy's Shadowing:
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
End If
'window
monx = 800
mony = Int(monx / _DesktopWidth * _DesktopHeight)
monm = monx * .008
mon = _NewImage(monx, mony, 32)
Screen mon
_FullScreen
_DisplayOrder _Hardware , _Software
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
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
PSet (t, t2), _RGBA32(0, 0, 0, Int(255 / (cube_deep - 1) * t2) - 3)
Next t2, t
cube_text = _CopyImage(temp, 33)
_FreeImage temp
'mask distance behind texture
Dim shdw_m(15000)
For t = 0 To 15000
shdw_m(t) = Interpolate(.999, .97, 1 / 15000 * t)
Next t
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
For t = 0 To 2
obj(obj_c - 1, 3 + t) = mapdim / 2
obj(obj_c - 1, t) = mapdim / 2
Next t
For t = 0 To 2
me(t) = mapdim / 2
Next t
light = .2
me(4) = -.2
ut_me4 = -.2
ylook_limit = 80 'radian
_Dest mon
Locate 1, 1
Print "moving:WASD looking:mouse light adjust : mousewheel"
Dim p(3, 2), p2(3, 2), pc(7, 9)
Do:
_Limit 30
'control
mouse_sens_xy = .01
mouse_sens_z = .01
mousex = 0
mousey = 0
mousew = 0
While _MouseInput
mousex = mousex + _MouseMovementX
mousey = mousey + _MouseMovementY
mousew = mousew + _MouseWheel
Wend
me(3) = me(3) + mousex * mouse_sens_xy
me(4) = me(4) + mousey * mouse_sens_z
ylook_deg = ((me(4) / pip180) + 90)
If Abs(ylook_deg) > ylook_limit Then me(4) = ut_me4 Else ut_me4 = me(4)
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
Locate 2, 1
Print "light:"; Int(light * 100); "% "
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
deg_XY = -90 * Abs(ka) + 90 * Abs(kd)
szog_xy = me(3) + deg_XY * pip180
szog_z = me(4)
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
'draw cubes
px1 = cube_res / 2
px2 = cube_res - 2
dl = cube_deep - 3
c_dis = Interpolate(50, 2500, light)
temp = cube_deep / c_dis
For a_obj = 0 To obj_c - 1
For t = 0 To 7
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
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
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
'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
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
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
px4 = px3 * cosrot_cs - py3 * sinrot_cs
py4 = px3 * sinrot_cs + py3 * cosrot_cs
px = -px4
py = -py4
pz2 = -pz3
End Sub
This one is a keeper for me! (Well, they both are!) Thanks
RE: Program Real Line Counter. Anyone want to jump in? - Pete - 10-23-2022
Well I'd wait a bit until we can thoroughly debug it. I found one bug with a very nested IF/THEN program... this one!
It misses the closing END IF tags in two instances. I will investigate and edit the code above when I find it.
Pete
|