PatternFindStr() hangs

Discuss any general programming issues here
Post Reply
bitRocky
Posts: 148
Joined: Fri Nov 14, 2014 6:01 pm

PatternFindStr() hangs

Post by bitRocky »

Hi,
I try to parse a html page with PatternFindStr() to get the title/name/version of a Plugin.

But the script hangs in PatternFindStr(), the cpu goes to 100% and the script never ends before the first entry is found.

The script first downloads the Download.html file of the Hollywood plugins.

Maybe the patterns are wrong?
jPV helped me here for my ytSearch program, but sometimes ytSearch hangs in PatternFindStr().
Here it hangs all the time before the first entry with the download.html file.

I want to make a Updater program which shows the online versions of all plugins, then compares it with the local versions.

Code: Select all

@REQUIRE "hurl", {Link=True} 

; <td><div id="info"><abbr title="Load and play AHX and HivelyTracker modules with Hollywood" rel="tooltip">i</abbr></div></td>
Local TITLE_START$ = [[<td><div id="info"><abbr title="]]
Local TITLE_END$   = [[" ]]
; <td>AHX</td>
Local NAME_START$ = [[<td>]]
Local NAME_END$   = [[</td>]]
;<td>1.3</td>
Local VERSION_START$ = [[<td>]]
Local VERSION_END$   = [[</td>]]

Local pat$ = TITLE_START$ .. "(.-)" .. TITLE_END$ .. ".-" 
pat$ = pat$ .. NAME_START$ .. "(.-)" .. NAME_END$ .. ".-"
pat$ = pat$ .. VERSION_START$ .. "(.-)" .. VERSION_END$ .. ".-"

Function p_GetOnlineVersions()
Local cnt, err, buff$, len

	DebugPrint("p_GetOnlineVersions")

	buff$, len= DownloadFile("https://www.hollywood-mal.com/download.html", {Adapter = "hurl"})
	;err, buff$, len = ?FileToString("download.html")

	DebugPrint("len = "..len)
	If len <= 0
		DebugPrint("Failed to download the PlugIns versions!")
	Else
		cnt = 0
		DebugPrint("pat$ = "..pat$)
		
		For title$, name$, version$ In PatternFindStr(buff$, pat$)
			DebugPrint("title$ = >"..title$.."< name$ = >"..name$.."< version$ = >"..version$.."<")
			cnt=cnt+1 If cnt > 10 Then Break
		Next
	EndIf
EndFunction

p_GetOnlineVersions()
If I use PatternFindStrDirect() in a while loop, it doesn't hangs!

Code: Select all

		s = 1 cnt = 0
		While s > 0
			s, e, title$, name$, version$ = PatternFindStrDirect(buff$, pat$, s+1)
			If s > 0
				DebugPrint("s = "..s.." e = "..e.." title$ = >"..title$.."< name$ = >"..name$.."< version$ = >"..version$.."<")
			EndIf 
			cnt=cnt+1 If cnt > 10 Then Break
		Wend
plouf
Posts: 666
Joined: Sun Feb 04, 2018 11:51 pm
Location: Athens,Greece

Re: PatternFindStr() hangs

Post by plouf »

where it hangs?
you example runs fine here, and shows some text in debug print
Christos
bitRocky
Posts: 148
Joined: Fri Nov 14, 2014 6:01 pm

Re: PatternFindStr() hangs

Post by bitRocky »

It hangs on the first call to PatternFindStr().
I'm running it under MorphOS, where do you ran it?
User avatar
jPV
Posts: 734
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Re: PatternFindStr() hangs

Post by jPV »

bitRocky wrote: Fri May 09, 2025 5:50 pm But the script hangs in PatternFindStr(), the cpu goes to 100% and the script never ends before the first entry is found.
Hmm.. it doesn't hang here. It debugprints 11 plugin lines and exits. BTW. the last ".-" is useless on the pat$.

I'm running it on MorphOS too. Do you have the latest Hollywood btw?

jPV helped me here for my ytSearch program, but sometimes ytSearch hangs in PatternFindStr().
Yeah, in ytSearch we'd need to finetune the pattern. I noticed an issue if the last word in description is the search word (the pattern doesn't match to its end then, which makes it heavy when it tries to find matches from that on), but I haven't had time to take another look on it yet. I'll try to check it out soonish.
bitRocky
Posts: 148
Joined: Fri Nov 14, 2014 6:01 pm

Re: PatternFindStr() hangs

Post by bitRocky »

jPV wrote: Sat May 10, 2025 2:00 pm I'm running it on MorphOS too. Do you have the latest Hollywood btw?
No, I have v9.1, could it be this?
I can't test it with the V10 Hollywood Player ATM.
jPV helped me here for my ytSearch program, but sometimes ytSearch hangs in PatternFindStr().
Yeah, in ytSearch we'd need to finetune the pattern. I noticed an issue if the last word in description is the search word (the pattern doesn't match to its end then, which makes it heavy when it tries to find matches from that on), but I haven't had time to take another look on it yet. I'll try to check it out soonish.
Then at least ytSearch hangs also for you?
bitRocky
Posts: 148
Joined: Fri Nov 14, 2014 6:01 pm

Re: PatternFindStr() hangs

Post by bitRocky »

I tried again and it doesn't hangs here!?
So I added another pattern to the the first archive name, to get the real basename of the plugin, and now it hangs.
When executing the script with System/Hollywood v9.1 and also when compiling as applet and then executing with HollywoodPlayer v10.0.
All under MorphOS.

Could you try this code again?

Code: Select all

@REQUIRE "hurl", {Link=True} 

; <td><div id="info"><abbr title="Load and play AHX and HivelyTracker modules with Hollywood" rel="tooltip">i</abbr></div></td>
TITLE_START$ = [[<td><div id="info"><abbr title="]]
TITLE_END$   = [[" ]]
; <td>AHX</td>
NAME_START$ = [[<td>]]
NAME_END$   = [[</td>]]
;<td>1.3</td>
VERSION_START$ = [[<td>]]
VERSION_END$   = [[</td>]]
;<td align="center"><a href="https://www.hollywood-mal.com/download/HTTPStreamer_Amiga.lha"><img src="img/i_disk.gif" border=0></a></td>
ANAME_START$   = [[<a href="https://www.hollywood-mal.com/download/]]
ANAME_END$     = [["]]

pat$ = TITLE_START$ .. "(.-)" .. TITLE_END$ .. ".-" 
pat$ = pat$ .. NAME_START$ .. "(.-)" .. NAME_END$ .. ".-"
pat$ = pat$ .. VERSION_START$ .. "(.-)" .. VERSION_END$ .. ".-"
pat$ = pat$ .. ANAME_START$ .. "(.-)" .. ANAME_END$

Function p_GetOnlineVersions()
Local cnt, err, buff$, len

	DebugPrint("p_GetOnlineVersions")

	buff$, len= DownloadFile("https://www.hollywood-mal.com/download.html", {Adapter = "hurl"})
	;err, buff$, len = ?FileToString("download.html")

	DebugPrint("len = "..len)
	If len <= 0
		DebugPrint("Failed to download the PlugIns versions!")
	Else
		cnt = 0
	
		DebugPrint("pat$ = "..pat$)
/*
		s = 1 
		While s > 0
			s, e, title$, name$, version$ = PatternFindStrDirect(buff$, pat$, s+1)
			If s > 0
				DebugPrint("s = "..s.." e = "..e.." title$ = >"..title$.."< name$ = >"..name$.."< version$ = >"..version$.."<")
			EndIf 
			cnt=cnt+1  If cnt > 10 Then Break
		Wend
*/
		For title$, name$, version$ In PatternFindStr(buff$, pat$)
			;DB("")
			DebugPrint("title$ = >"..title$.."< name$ = >"..name$.."< version$ = >"..version$.."<")
			cnt=cnt+1 If cnt > 10 Then Break
		Next
	EndIf
	
EndFunction

p_GetOnlineVersions()
User avatar
jPV
Posts: 734
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Re: PatternFindStr() hangs

Post by jPV »

bitRocky wrote: Sun May 11, 2025 8:03 pm So I added another pattern to the the first archive name, to get the real basename of the plugin, and now it hangs.
Yeah, it hangs here too, or at least makes full CPU load when it's trying to parse it. Maybe it would recover from that if you'd wait long enough.

But the issue is that you didn't escape the magic characters of the search pattern. It seems that unintentional use of the "-" character causes the trouble in this case.

This would be the correct string if you want to use the magic characters as plain characters:

Code: Select all

ANAME_START$   = [[<a href="https://www%.hollywood%-mal%.com/download/]]
See the magic characters in the PatternReplaceStr() documentation.
bitRocky
Posts: 148
Joined: Fri Nov 14, 2014 6:01 pm

Re: PatternFindStr() hangs

Post by bitRocky »

You are right! Thanks!
Post Reply