Parsing in diary

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

kresten
Posts: 153
Joined: Tue Sep 30, 2008 3:01 pm
Location: Copenhagen
Contact:

Parsing in diary

Post by kresten » Thu Oct 19, 2023 11:54 pm

I need help in improving a parsing function in an intended downloadable freeware diary standalone
With the help from others, many years ago, a setup was accomplished, where parsing for ocurrences of a word ( or a pictogram) in the accumulating mainstack of daycards were/are placed (and accumulated) in in a seperate folder "Parsings" and then copied into a specific substack "Parseviewer".
I have 2 reasons to avoid the use of the separate "Parsings " Folder : Over years of daily use of my personal diary I have never felt the need to look into its accumulated hundreds of previous parsings.
My other motive is that I want the future downloads of the standalones to be as simple as possible. It will be complicated enough with a folder containing 12 pictogram fonts.
I have experimented the last month to modify the parse handler to deliver its result directly in the parseviewer substack , without a Parsing folder, but all my attempts have failed.

two handlers "phenoparse" and "glyphparse"

Code: Select all

on phenoparse
   global phenodate,destination,cue
   ask "Which word shall be searched?"
   if it is empty then
      exit phenoparse
   else
      put it into cue
   end if
   ask "How many lines before ?" with "0"
   if it is cancel then
      exit phenoparse
   end if
   put it into avant
   ask "How many lines after ?" with "0"
   if it is cancel then
      exit phenoparse
   end if
   put it into apres
   put "Parsed for" && cue && phenodate & ".html" into filename
   put the effective filename of this stack into destination
   set the itemdelimiter to "/"
   delete last item of destination
   delete last item of destination
   delete last item of destination
   open file destination &"/"& parsings &"/"& filename
   lock screen
   set lockmessages to true
   go first card of stack "Phenomenalog"
   find string cue in field "TextField"
   if the result is "not found" then
      answer "Cannot find this word"
      exit phenoparse
   else
      put short name of this card && the foundchunk into start
      put short name of this card into hitcard
      write "<p>" & short name of this card & "</p>" to file destination & "/" & parsings  &"/"& filename
      write the htmltext of line (word 2 of the foundline) - avant to (word 2 of the foundline) + apres of field "Textfield" to file destination & "/" & parsings  &"/"& filename
   end if
   repeat
      set cursor to busy
      find string cue in field "TextField"
      if short name of this card && the foundchunk is start then
         exit repeat
      end if
      if short name of this card is not hitcard then
         put short name of this card into hitcard
         write "<p> ----------------------</p>" to file destination  &"/"&  parsings  &"/"& filename
         write "<p>" & short name of this card & "</p>" to file destination & "/" & parsings &"/"& filename
      end if
      write the htmltext of line (word 2 of the foundline) - avant to (word 2 of the foundline) + apres of field "Textfield" to file destination  & "/" & parsings & "/" & filename
   end repeat
   --  save file filename
   close file destination & "/" & parsings  & "/" & filename
   go last card
   put return & phenodate && the time && "Parsed:" && cue after field "TextField"
   go stack "Parseviewer"
   show stack "Parseviewer"
   set the htmltext of field "Showfield" to URL ("file:"& destination  & "/" & parsings  & "/" & filename)
end phenoparse 
----------------
Ny

Code: Select all

on glyphparse
   global phenodate,searchpattern,fontlist,targetfield,destination,selchunk,tekst
   ask "How many lines before ?" with "0"
   if it is cancel then
      exit glyphparse
   end if
   put it into avant
   ask "How many lines after ?" with "0"
   if it is cancel then
      exit glyphparse
   end if
   put it into apres
   put searchpattern into tekst
   ask "Save parsing as:" with tekst
   put it into tekst
   repeat with x = 1 to the number of chars of tekst
      if the chartonum of char x of tekst = 9 then put "_" into char x of tekst
   end repeat
   put the effective filename of this stack into destination
   set the itemdelimiter to "/"
   --   delete last item of destination
   --   delete last item of destination
   --   delete last item of destination
   --   delete last item of destination
   delete last item of destination
   delete last item of destination
   delete last item of destination
   put destination & "/" & parsings & "/" & "Parsed_for" & "_" & tekst & ".html" into filename
   open file filename
   lock screen
   set cursor to busy
   set lockmessages to true
   go first card of stack "Phenomenalog"
   put empty into hitcard
   repeat until hitcard is not empty
      put empty into ffontlist
      --      find whole searchpattern in field targetfield
      find whole searchpattern in field "Textfield"
      if the result is empty then
         put word 2 of the foundchunk into fstartchar
         put word 4 of the foundchunk into fendchar
         put word 7 of the foundchunk into ftargetfield
         repeat with y = fstartchar to fendchar
            put the textfont of char y of field ftargetfield after ffontlist
         end repeat
         if fontlist = ffontlist then
            put short name of this card && the foundchunk into start
            put short name of this card into hitcard
            write "<p>" & short name of this card & "</p>" to file filename
            write the htmltext of line (word 2 of the foundline) - avant to (word 2 of the foundline) + apres of field "Textfield" to file filename
         end if
      else next repeat
   end repeat
   repeat
      --      find whole searchpattern in field targetfield
      find whole searchpattern in field "Textfield"
      if short name of this card && the foundchunk is start then
         exit repeat
      end if
      if the result is empty then
         put empty into ffontlist
         put word 2 of the foundchunk into fstartchar
         put word 4 of the foundchunk into fendchar
         put word 7 of the foundchunk into ftargetfield
         repeat with y = fstartchar to fendchar
            put the textfont of char y of field ftargetfield after ffontlist
         end repeat
         if fontlist = ffontlist then
            if short name of this card is not hitcard then
               put short name of this card into hitcard
               write "<p> ----------------------</p>" to file filename
               write "<p>" & short name of this card & "</p>" to file filename
            end if
            write the htmltext of line (word 2 of the foundline) - avant to (word 2 of the foundline) + apres of field "Textfield" to file filename
         end if
      end if
   end repeat
   close file filename
   go last card
   put return & phenodate && the time && "Parsed:" && tekst after field "TextField"
   go stack "Parseviewer"
   set the iconic of stack "Parseviewer" to false
   show stack "Parseviewer"
   set the htmltext of field "Showfield" to \
         URL ("file:" & filename)
   set the  iconic of stack "Phenomenalog" to true
end glyphparse

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9670
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Parsing in diary

Post by dunbarx » Fri Oct 20, 2023 4:03 am

Hi.

Hard to know how to answer this. First off, please use the code tags above (</>) to display handlers you submit. Second, we do not have the dataset that is to be searched and parsed. Can you send a stack that has those missing parts, for example, the field "textField"?

I have answered similar questions by building a new stack with the necessary controls to at least prevent the handler from failing. Add a text field with some random data in it and I have oftentimes been able to see what is going on. But this one seems to complicated for me to do that.

Craig

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Parsing in diary

Post by Klaus » Fri Oct 20, 2023 9:40 am

Hi Kresten,

I added the CODE tags for you.


Best

Klaus

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Parsing in diary

Post by Klaus » Fri Oct 20, 2023 10:20 am

At a quick glance I noticed that you use -> filename as the name for a variable.
That is a reserved word in LC (sic!) which may cause problems, please replace with e.g. tFilename!

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Parsing in diary

Post by Klaus » Fri Oct 20, 2023 12:38 pm

Another problem may be that you do not use parens when concatenating filenames:

Code: Select all

...
## open file destination &"/"& parsings &"/"& filename
open file (destination &"/"& parsings &"/"& tFilename)
...
You could/should save some typing, put the name into a variable and use that variable througout:

Code: Select all

...
put (destination &"/"& parsings &"/"& tFilename) into tFilenameParsing
...
open file tFilenameParsing
## etc...
...

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9670
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Parsing in diary

Post by dunbarx » Fri Oct 20, 2023 2:29 pm

I added the CODE tags....
Thanks, Klaus. I hesitated to do that since the text is not my property.

And there will likely be several small issues with the original code, another being the use of "start" as a variable name. "Start" is also a reserved word.

Kresten, use letter prefixes to identify your variables, such as "t" as Klaus mentioned. Or use strings that clearly cannot be reserved, such as "myRepositoryForPrimeNumbers".

But I still feel that we cannot help more without a way to run your code, either in the stack you have, or a minimal "test" stack that will not fail for one of several possible reasons.

Craig

kresten
Posts: 153
Joined: Tue Sep 30, 2008 3:01 pm
Location: Copenhagen
Contact:

Re: Parsing in diary

Post by kresten » Fri Oct 20, 2023 2:59 pm

Thanks. I have tried to attach relevant files, but it seems difficult. The "add files for attachments" refuses folders and refuses also an isolated mainstack.. "Dragging and dropping them in the message box" does that refer to the field I write into here?, or where else ?

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9670
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Parsing in diary

Post by dunbarx » Fri Oct 20, 2023 3:08 pm

Kersten.

You have to zip all attachments. We only need a single stack (not a folder) that can run the two handlers you posted.

Craig

kresten
Posts: 153
Joined: Tue Sep 30, 2008 3:01 pm
Location: Copenhagen
Contact:

Re: Parsing in diary

Post by kresten » Sat Oct 21, 2023 12:05 am

I first tried uploading folder, Too large. Then i zipped just the mainstack, but was told it was too big. 2,3 MB ! Last i tried to attach a zipped version of folder with the 12 glyph fonts, but the reply was again that it was too big. Only 570 KB !
How do we get around those barriers ? :? :?

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Parsing in diary

Post by Klaus » Sat Oct 21, 2023 9:25 am

Hi Kresten,

I'm afraid this is a limitation of the forum that we cannot change.
if you do not have webspace somewhere, you could use a file hoster like https://wetransfer.com

Best

Klaus

stam
Posts: 2686
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Parsing in diary

Post by stam » Sat Oct 21, 2023 6:52 pm

I would recommend MEGA as a hosting service.
You get 20 Gb storage free and it's extremely security conscious. Probably one the most secure services of it's kind:
https://mega.io

you can upload there and create a share link which you can post here.

kresten
Posts: 153
Joined: Tue Sep 30, 2008 3:01 pm
Location: Copenhagen
Contact:

Re: Parsing in diary

Post by kresten » Sun Oct 22, 2023 12:34 am

Thank you for the two sites. I fought my way with retransfer.com, before I saw the link to Mega.
Wetransfer provided me with this link : https://we.tl/t-knP56b1Okt
It is free, but lasts only one week.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7238
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Parsing in diary

Post by jacque » Sun Oct 22, 2023 6:35 pm

stam wrote:
Sat Oct 21, 2023 6:52 pm
I would recommend MEGA as a hosting service.
You get 20 Gb storage free and it's extremely security conscious. Probably one the most secure services of it's kind:
https://mega.io
They may be secure but they accept anything. Some years ago someone pirated one of my apps and hosted it there and was selling it as his own. They did honor my takedown notice promptly but it was months before I found out.

On the other hand I suppose all hosting services allow any and all uploads, but a one week download limit would have saved me lost income.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

stam
Posts: 2686
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Parsing in diary

Post by stam » Mon Oct 23, 2023 10:56 am

jacque wrote:
Sun Oct 22, 2023 6:35 pm
stam wrote:
Sat Oct 21, 2023 6:52 pm
I would recommend MEGA as a hosting service.
You get 20 Gb storage free and it's extremely security conscious. Probably one the most secure services of it's kind:
https://mega.io
They may be secure but they accept anything. Some years ago someone pirated one of my apps and hosted it there and was selling it as his own. They did honor my takedown notice promptly but it was months before I found out.

On the other hand I suppose all hosting services allow any and all uploads, but a one week download limit would have saved me lost income.
My point was you are much less likely to have your Mega account hacked and your storage hijacked for illicit uses. This obviously doesn't cover bad actors performing nefarious actions on their own accounts. That would be a bit like blaming your Parker pen for being used by someone else to forge your signature ;)

But I am sorry to hear you got ripped of Jacque - that is sadly part and parcel of selling software. I think one should safely assume that any commercially available app one releasers will be shared/hacked/keygen'd if it's of any value to anyone - assuming the opposite is overly optimistic. So take that as a compliment I guess :)

No hosting service will permit pirating if they find out about it - it's in their EULA, so it's not a matter of honouring your request, it's the law as set by themselves and pretty much every hosting service, and I've never known any service to risk police/fraud investigation ;)
Actually there was one prominent German one that got shut down after fraud investigation, can't remember it's name now...

Asking all hosting services to to limit download links to 1 week stop stop developers from getting ripped off is too drastic - keeping in mind that's actually a tiny percentage of the use-cases for such a service, most users would be severely inconvenienced so never going to happen.

Perhaps it would be more helpful to keep an eye on sites that share links to such things if you have such concerns.
There are some well known sites - especially a prominent MacOS one who's name I won't share here for obvious reasons, that have links to illegal download mirrors, keygens, hacks etc for almost all known Mac software, and I mean all. If I was selling Mac software I'd be sure to monitor that website regualarly. I'm sure the same exists for Windows and I guess Android.

The WeTransfer thing came about as a way to bypass restriction on attachment sizes in emails (you know, for 'business' users to share their powerpointless presentations), so for that it it may make sense.

However in this current use-case on the forum that would be less helpful - if someone visited the forum a month later, they would not be able to review the shared stack if shared with WeTransfer. While that may or may not be his particular OP's desire, sharing stacks often is helpful for subsequent users, so permanence is desirable and the WeTransfer model would be unhelpful...

But even so, if that was important to you, Mega lets you set an expiry date for your download link, which is defined by you, not the provider.

So, back to my original point: I'd recommend using Mega ;)

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9389
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Parsing in diary

Post by richmond62 » Mon Oct 23, 2023 11:45 am

I have used DropBox for about 15 years without any obvious problems.

https://www.dropbox.com/

Post Reply

Return to “Talking LiveCode”