Author Topic: Text search  (Read 397 times)

John

  • Sr. Member
  • ****
  • Posts: 378
    • View Profile
Re: Text search
« Reply #15 on: 13. May 2018, 17:46:09 »
Mike brings up an interesting issue with the use of LIKE in this example. Since SPLITA is removing the line terminator as the split character the CHOMP shouldn't be needed. Here is my solution to the problem.

Code: [Select]
OPEN "warpeace.txt" FOR INPUT AS 1
flen = FILELEN("warpeace.txt")
fstr = INPUT(flen, 1)
SPLITA fstr BY chr(10) to farr
lnum = 1
OPTION COMPARE sbCaseInsensitive
FOR idx = 0 to UBOUND(farr)
  IF " " & farr[idx] & " " LIKE "*PrInCe*" THEN PRINT FORMAT("%~[000000] ~", lnum), farr[idx],"\n"
  lnum += 1
NEXT


jrs@jrs-laptop:~/sb/examples/test$ time scriba findit.sb > findit.out

real   0m0.531s
user   0m0.520s
sys   0m0.012s
jrs@jrs-laptop:~/sb/examples/test$ tail -n50 findit.out
[062012] am! No, it can't be!" Pierre kept saying as he kissed Princess
[062065] crossed his mind: "Wasn't it all a dream? Isn't Princess Mary
[062067] this- and suddenly Princess Mary will tell her, and she will be sure
[062105] bliss he now knew. Prince Vasili, who having obtained a new post and
[062135] to Princess Mary with a gaily mocking smile: "He looks just, yes, just
[062146] little of Pierre, but when Princess Mary mentioned him a
[062150] The change that took place in Natasha at first surprised Princess
[062157] Princess Mary felt that she had no right to reproach her even in her
[062164] When Princess Mary returned to her room after her nocturnal talk
[062175] at her seemed to Princess Mary, and sorry as she was to see her
[062179] "But what's to be done? She can't help it," thought the princess.
[062187] But noticing the grieved expression on Princess Mary's face she
[062197] "Then why are you crying? I am happy for your sake," said Princess
[062743] flight from it, the death of Prince Andrew, Natasha's despair, Petya's
[062871] At the beginning of winter Princess Mary came to Moscow. From
[062876] "I never expected anything else of him," said Princess Mary to
[062891] When the princess came out of the countess' room Nicholas met her
[062900] princess' carriage had disappeared.
[062905] Nicholas did not reply and tried to avoid speaking of the princess
[062914] princess, but his silence irritated her.
[062951] by Nicholas, Princess Mary confessed to herself that she had been
[062983] With Mademoiselle Bourienne's help the princess had maintained the
[062993] looked at the princess. She still sat motionless with a look of
[062999] "Good-by, Princess!" said he.
[063012] "Yes, Princess," said Nicholas at last with a sad smile, "it doesn't
[063018] Princess Mary gazed intently into his eyes with her own luminous
[063032] princess had caught a glimpse of the man she had known and loved,
[063042] why. "Thank you, Princess," he added softly. "Sometimes it is hard."
[063044] "So that's why! That's why!" a voice whispered in Princess Mary's
[063065] "Princess, for God's sake!" he exclaimed, trying to stop her.
[063066] "Princess!"
[063079] In the winter of 1813 Nicholas married Princess Mary and moved to
[063313] and Sonya, blaming himself and commending her. He had asked Princess
[063350] same scale as under the old prince.
[063402] Ivanovich, the late prince's architect, who was living on in
[063649] when she and Countess Mary spoke of Prince Andrew (she never mentioned
[063650] him to her husband, who she imagined was jealous of Prince Andrew's
[063837] Rostovs he had received a letter from Prince Theodore, asking him to
[063962] "And have you talked everything well over with Prince Theodore?" she
[063968] he did frighten me... You've seen the princess? Is it true she's in
[064250] questions as to whether Prince Vasili had aged and whether Countess
[064282] Nicholas and Natasha always brought him back to the health of Prince
[064297] translate things into his mother's language, "Prince Alexander
[064305] "Well, and how is Prince Alexander to blame? He is a most
[064422] Prince Theodore, and she helped him by asking how his affairs with
[064423] Prince Theodore had gone.
[064479] his brows. "Prince Theodore and all those. To encourage culture and
[064909] right, and let there be but one banner- that of active virtue.' Prince
[065024] Prince Andrew- and his father had neither shape nor form, but he
[065031] Prince Andrew in the house, Nicholas never imagined him in human
jrs@jrs-laptop:~/sb/examples/test$

jj2007

  • Full Member
  • ***
  • Posts: 138
  • MasmBasic rocks
    • View Profile
    • MasmBasic - faster than C
Re: Text search
« Reply #16 on: 13. May 2018, 18:00:43 »
the absence of a character is not a character

Mike,
I had understood that when I saw the red matches posted above, thanks anyway. The logic is not that straightforward, I suppose it's documented somewhere. In any case, it's kind of an overkill for what is effectively a case-insensitive Instr().

Attached my version. It produces exactly the same output as John's version.

John

  • Sr. Member
  • ****
  • Posts: 378
    • View Profile
Re: Text search
« Reply #17 on: 13. May 2018, 18:11:17 »
Quote
In any case, it's kind of an overkill for what is effectively a case-insensitive Instr().

In this case, you're right. LIKE is best used with the JOKER() function to extract data within a pattern. The INSTR() seems twice as fast.

Code: [Select]
OPEN "warpeace.txt" FOR INPUT AS 1
flen = FILELEN("warpeace.txt")
fstr = INPUT(flen, 1)
SPLITA fstr BY "\n" to farr
OPTION COMPARE sbCaseInsensitive
FOR idx = 0 to UBOUND(farr)
  IF INSTR(farr[idx], "PrInCe") THEN PRINT FORMAT("%~[000000] ~", idx + 1), farr[idx],"\n"
NEXT


jrs@jrs-laptop:~/sb/examples/test$ time scriba findit.sb > findit.out

real   0m0.270s
user   0m0.244s
sys   0m0.024s
jrs@jrs-laptop:~/sb/examples/test$ tail -n50 findit.out
[062012] am! No, it can't be!" Pierre kept saying as he kissed Princess
[062065] crossed his mind: "Wasn't it all a dream? Isn't Princess Mary
[062067] this- and suddenly Princess Mary will tell her, and she will be sure
[062105] bliss he now knew. Prince Vasili, who having obtained a new post and
[062135] to Princess Mary with a gaily mocking smile: "He looks just, yes, just
[062146] little of Pierre, but when Princess Mary mentioned him a
[062150] The change that took place in Natasha at first surprised Princess
[062157] Princess Mary felt that she had no right to reproach her even in her
[062164] When Princess Mary returned to her room after her nocturnal talk
[062175] at her seemed to Princess Mary, and sorry as she was to see her
[062179] "But what's to be done? She can't help it," thought the princess.
[062187] But noticing the grieved expression on Princess Mary's face she
[062197] "Then why are you crying? I am happy for your sake," said Princess
[062743] flight from it, the death of Prince Andrew, Natasha's despair, Petya's
[062871] At the beginning of winter Princess Mary came to Moscow. From
[062876] "I never expected anything else of him," said Princess Mary to
[062891] When the princess came out of the countess' room Nicholas met her
[062900] princess' carriage had disappeared.
[062905] Nicholas did not reply and tried to avoid speaking of the princess
[062914] princess, but his silence irritated her.
[062951] by Nicholas, Princess Mary confessed to herself that she had been
[062983] With Mademoiselle Bourienne's help the princess had maintained the
[062993] looked at the princess. She still sat motionless with a look of
[062999] "Good-by, Princess!" said he.
[063012] "Yes, Princess," said Nicholas at last with a sad smile, "it doesn't
[063018] Princess Mary gazed intently into his eyes with her own luminous
[063032] princess had caught a glimpse of the man she had known and loved,
[063042] why. "Thank you, Princess," he added softly. "Sometimes it is hard."
[063044] "So that's why! That's why!" a voice whispered in Princess Mary's
[063065] "Princess, for God's sake!" he exclaimed, trying to stop her.
[063066] "Princess!"
[063079] In the winter of 1813 Nicholas married Princess Mary and moved to
[063313] and Sonya, blaming himself and commending her. He had asked Princess
[063350] same scale as under the old prince.
[063402] Ivanovich, the late prince's architect, who was living on in
[063649] when she and Countess Mary spoke of Prince Andrew (she never mentioned
[063650] him to her husband, who she imagined was jealous of Prince Andrew's
[063837] Rostovs he had received a letter from Prince Theodore, asking him to
[063962] "And have you talked everything well over with Prince Theodore?" she
[063968] he did frighten me... You've seen the princess? Is it true she's in
[064250] questions as to whether Prince Vasili had aged and whether Countess
[064282] Nicholas and Natasha always brought him back to the health of Prince
[064297] translate things into his mother's language, "Prince Alexander
[064305] "Well, and how is Prince Alexander to blame? He is a most
[064422] Prince Theodore, and she helped him by asking how his affairs with
[064423] Prince Theodore had gone.
[064479] his brows. "Prince Theodore and all those. To encourage culture and
[064909] right, and let there be but one banner- that of active virtue.' Prince
[065024] Prince Andrew- and his father had neither shape nor form, but he
[065031] Prince Andrew in the house, Nicholas never imagined him in human
jrs@jrs-laptop:~/sb/examples/test$


« Last Edit: 13. May 2018, 20:04:28 by John »

Mike Lobanovsky

  • Full Member
  • ***
  • Posts: 175
    • View Profile
    • Freestyle BASIC Script Language
Re: Text search
« Reply #18 on: 14. May 2018, 01:18:52 »
In any case, it's kind of an overkill for what is effectively a case-insensitive Instr().

That's correct Jochen, but I noted from the very beginning that LIKE was sort of a show-off. Naturally, SB does have its own case-(in)sensitive INSTR/INSTRREV functions.

At any rate, SB is just an interpreter and as such, it can't compete with MASM speed-wise. Sometimes you should be more lenient to your opponents. :)

In every other respect, SB is a solid piece of SW with a very good design and professional implementation. And it is multiplatform too.
Mike
____________________________________________________________________________________________
(3.6GHz i5-3470, 16GB RAM / 2 x nVidia GTX 650Ti SLI-bridged, 2GB VRAM / x64 Win 7, x86 elementaryOS Luna)

John

  • Sr. Member
  • ****
  • Posts: 378
    • View Profile
Re: Text search
« Reply #19 on: 14. May 2018, 02:45:39 »
Quote
In every other respect, SB is a solid piece of SW with a very good design and professional implementation. And it is multiplatform too.

I fell in love with Script BASIC on our first date.  :-*

jj2007

  • Full Member
  • ***
  • Posts: 138
  • MasmBasic rocks
    • View Profile
    • MasmBasic - faster than C
Re: Text search
« Reply #20 on: 14. May 2018, 18:47:23 »
SB is just an interpreter and as such, it can't compete with MASM speed-wise. Sometimes you should be more lenient to your opponents. :)

Hey, I didn't complain about speed differences :)

I was just curious why we came to different results - and you clarified the issue, thanks ;-)

John

  • Sr. Member
  • ****
  • Posts: 378
    • View Profile
Re: Text search
« Reply #21 on: 14. May 2018, 20:02:46 »
Quote
Hey, I didn't complain about speed differences.

I would be interested in the performance difference between your MASM BASIC and OxygenBasic. Which do you think is more feature rich?

Mike Lobanovsky

  • Full Member
  • ***
  • Posts: 175
    • View Profile
    • Freestyle BASIC Script Language
Re: Text search
« Reply #22 on: 14. May 2018, 21:18:15 »
Which do you think is more feature rich?

John,

O2 is 64-bit capable as-is while MB isn't. Another point, O2 is JIT capable while MB isn't. Yet one more point, O2 is basically ready to go multiplatform any time while MB may not, as per its MASM license.

Both of them are perfectly competitive performance-wise, probably with only minor differences in either direction in some synthetic tests.

Otherwise, MB is feature rich. Especially in the hands of its creator. :)
Mike
____________________________________________________________________________________________
(3.6GHz i5-3470, 16GB RAM / 2 x nVidia GTX 650Ti SLI-bridged, 2GB VRAM / x64 Win 7, x86 elementaryOS Luna)

Rick3137

  • Full Member
  • ***
  • Posts: 112
    • View Profile
    • Rick's Programs
Re: Text search
« Reply #23 on: 15. May 2018, 16:28:39 »
    I'm not sure if it actually goes here, but I recently wrote a program that uses a text search.
    This program, written with NaaLaa, does a text search of a .exe file or any other type.

    It does a search for the letters "http". You can use this to see where a program might be reporting back to.

    Also, I would like to know if it works without having NaaLaa installed on your computer.
    That would tell me that I have all the needed Dll's.

    It is a Windows10 program.

http://rb23.yolasite.com  Ricks Programs
http://rb27.synthasite.com   Sight and Sound

John

  • Sr. Member
  • ****
  • Posts: 378
    • View Profile
Re: Text search
« Reply #24 on: 17. May 2018, 03:46:14 »
If you guys are getting tired of searching for Prince(ss), HERE is something to take the edge off.  :D

jj2007

  • Full Member
  • ***
  • Posts: 138
  • MasmBasic rocks
    • View Profile
    • MasmBasic - faster than C
Re: Text search
« Reply #25 on: 17. May 2018, 18:36:15 »
    I'm not sure if it actually goes here, but I recently wrote a program that uses a text search.
    This program, written with NaaLaa, does a text search of a .exe file or any other type.

    It does a search for the letters "http". You can use this to see where a program might be reporting back to.

    Also, I would like to know if it works without having NaaLaa installed on your computer.
    That would tell me that I have all the needed Dll's.

    It is a Windows10 program.

Hi Rick,

It works fine on my Win7-64 machine. Attached my version; inter alia, there is a little file DownloadAndShow.exe that does something entirely harmless:

include \masm32\MasmBasic\MasmBasic.inc         ; download
  Init
  ; Let esi="http://retrogamecoding.org/board/index.php?topic=653"
  Let esi="356=cipot?php.xedni/draob/gro.gnidocemagorter//:ptth"
  PrintLine esi
   Let edi=FileRead$(Mirror$(esi))
   Inkey NoTag$(edi)
EndOfCode


Plus source & exe of a program that can detect, inter alia, the mirrored http:// in DownloadAndShow.exe ;-)

Just drag a file over SpyWareScanMB.exe, or launch it and pick a file.

P.S.: Thanks for the inspiration, Rick. In the Firefox installer (C:\Users\xxx\Documents\Firefox Installer.exe), it finds some goodies:
Code: [Select]
URLs found in "C:\Users\xxxx\Documents\Firefox Installer.exe":
http://schemas.microsoft.com/SMI/2005/WindowsSettings
http://ocsp.digicert.com
http://cacerts.digicert.com/DigiCertAssuredIDRootCA.crt
http://crl4.digicert.com/DigiCertAssuredIDRootCA.crl
http://crl3.digicert.com/sha2-assured-cs-g1.crl
http://ocsp.digicert.com
http://cacerts.digicert.com/DigiCertSHA2AssuredIDCodeSigningCA.crt
http://ts-ocsp.ws.symantec.com
http://ts-aia.ws.symantec.com/tss-ca-g2.cer
http://ts-crl.ws.symantec.com/tss-ca-g2.crl

Warning: While this proggie finds interesting http:// and https:// matches in exes and dlls, it is not a replacement for an AntiVirus. Malware writers use more sophisticated tricks to hide their URLs 8)
« Last Edit: 18. May 2018, 03:43:25 by jj2007 »

John

  • Sr. Member
  • ****
  • Posts: 378
    • View Profile
Re: Text search
« Reply #26 on: 18. May 2018, 13:45:13 »
http://schemas.microsoft.com/SMI/2005/WindowsSettings

The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

Interesting the links are HTTP and not HTTPS. Is there some advantage of not using a secure connection?


Rick3137

  • Full Member
  • ***
  • Posts: 112
    • View Profile
    • Rick's Programs
Re: Text search
« Reply #27 on: 18. May 2018, 18:15:26 »
 Thanks JJ for the report.

 I tried out your program. Very nice.

 I do this programming thing mainly as a mental exercise. Maybe I can keep my old brain from going to a complete stop.

 I think my main problem is an old stroke I had several years ago knocked out some memory cells.
 
http://rb23.yolasite.com  Ricks Programs
http://rb27.synthasite.com   Sight and Sound

jj2007

  • Full Member
  • ***
  • Posts: 138
  • MasmBasic rocks
    • View Profile
    • MasmBasic - faster than C
Re: Text search
« Reply #28 on: 18. May 2018, 18:30:12 »
I tried out your program. Very nice.

Thanks ;-)

Quote
I do this programming thing mainly as a mental exercise. Maybe I can keep my old brain from going to a complete stop.

Compliments, you have really lots of good stuff on your site!

B+

  • Sr. Member
  • ****
  • Posts: 498
    • View Profile
Re: Text search
« Reply #29 on: 20. May 2018, 19:34:23 »
Rick, JJ cool application!

Thanks JJ