topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Tuesday April 16, 2024, 3:29 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Parsing of Fortune Files  (Read 20555 times)

transitionality

  • Participant
  • Joined in 2008
  • *
  • default avatar
  • Posts: 9
    • View Profile
    • Donate to Member
Parsing of Fortune Files
« on: July 16, 2008, 07:18 AM »
I am having some trouble with the parsing of fortune files.

First off, I note that I like to have a blank line separating the quote from the speaker, as follows:

"The time you enjoy wasting is not wasted time."

-- Bertrand Russell

%

.....

However, Popup Wisdom displays such formatting as follows:

"The time you enjoy wasting is not wasted time."
-- Bertrand Russell

So I tried putting a space on the blank line separating the quote from the speaker.

"The time you enjoy wasting is not wasted time."
(there's one space here)
-- Bertrand Russell

%

.....

But Popup Wisdom displays such a quote as follows:

"The time you enjoy wasting is not wasted time."
 -- Bertrand Russell

In other words, it ignores the line with the single space on it, and concatenates the space with the content of the line following it, displaying the result on one line.

Now, I know that I can always try and convert my quotes file to Popup Wisdom's own format to get the precise formatting that I want, but that's a lot of work, especially for multi-line, oddly formatted quotes. I haven't figured out a way to automate the conversion. I'd much rather be able to use fortune format.

I'm also not sure if the above is buggy or expected behavior, not being intimately familiar with the fortune format specification. Nor am I sure if there is a way to get the behavior that I want using the fortune format.

I am open to ideas and suggestions. Thanks.
« Last Edit: July 16, 2008, 07:30 AM by transitionality »

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,900
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: Parsing of Fortune Files
« Reply #1 on: July 16, 2008, 07:48 AM »
let me see if i can't fix this to respect newlines in fortune files that use the % format to separate items.

transitionality

  • Participant
  • Joined in 2008
  • *
  • default avatar
  • Posts: 9
    • View Profile
    • Donate to Member
Re: Parsing of Fortune Files
« Reply #2 on: July 16, 2008, 07:56 AM »
Like I said, I'm not sure what the specification is. I wouldn't want to cause you to fall out of spec merely to convenience me. But if it is within spec, that would be great.

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,900
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: Parsing of Fortune Files
« Reply #3 on: July 16, 2008, 08:08 AM »
my memory is (and it's been a while since i worked on this), that popup wisdom knows how to read 2 kinds of fortune file formats.

one involves each quote on its own line.  in such a case youd have to use \n to indicate a newline -- no real option there.
the other format uses % signs to separate fortunes.  there is no reason that it shouldn't respect newlines in such a case.

transitionality

  • Participant
  • Joined in 2008
  • *
  • default avatar
  • Posts: 9
    • View Profile
    • Donate to Member
Re: Parsing of Fortune Files
« Reply #4 on: July 16, 2008, 08:24 AM »
See here for some more detail, under "Cookie-Jar Format".

Apparently %% is a valid delimiter too, so maybe you could support that as well?
« Last Edit: July 16, 2008, 08:26 AM by transitionality »

transitionality

  • Participant
  • Joined in 2008
  • *
  • default avatar
  • Posts: 9
    • View Profile
    • Donate to Member
Re: Parsing of Fortune Files
« Reply #5 on: July 16, 2008, 11:59 AM »
Paying attention to this problem, I also notice a couple of other things.

* When a quote is displayed, a newline is appended to the bottom of it. Is this by design, or is it an oversight? When the quote is copied and pasted, the newline makes it different from the quote as copied and pasted from the quotes file. If the newline at the bottom is by design -- to put some space between the text and the buttons at the bottom -- perhaps it can be used for display purposes, but not appended to the copied text when the copy button is pressed.

* As quotes are parsed from a BSD-style fortunes file, it would be useful to ignore all whitespace from the % to the first non-whitespace character, and again, ignore all whitespace from the last non-whitespace character to the next %. That way,

%



"The time you enjoy wasting is not wasted time."

-- Bertrand Russell


%


gets parsed as

"The time you enjoy wasting is not wasted time."

-- Bertrand Russell

which is probably a sensible way to do it. There's a reference to this in the source I gave in the previous message, but it's a suggestion rather than a rule. What do people think?
« Last Edit: July 16, 2008, 12:03 PM by transitionality »

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,900
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: Parsing of Fortune Files
« Reply #6 on: July 16, 2008, 12:59 PM »
easy to do and makes sense to me.

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,900
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: Parsing of Fortune Files
« Reply #7 on: July 18, 2008, 12:56 PM »
Can you try this new version and let me know if the issues have been fixed:
https://www.donation...PopUpWisdomSetup.exe

(see help file bottom for list of changes)

transitionality

  • Participant
  • Joined in 2008
  • *
  • default avatar
  • Posts: 9
    • View Profile
    • Donate to Member
Re: Parsing of Fortune Files
« Reply #8 on: July 22, 2008, 02:45 AM »
I uninstalled the previous version and installed the latest version in a clean directory, so there would be no complications.

I created a fortune file with %% delimiters, and unfortunately it did not work. Every separate non-blank line was parsed as a separate quote, even lines containing the %% delimiter.

When I search-and-replaced the %% delimiters with the % delimiter, the program failed in a different way. The whitespace preceding and trailing the quote were ignored, as expected, but the newlines within the quotes were not respected except for the author line (starting with a dash), instead they were substituted with spaces. So:


.....

%

"Do I contradict myself?
Very well then I contradict myself,
(I am large, I contain multitudes.)"

-- Walt Whitman, from _Song of Myself_

%

.....

got displayed as:

"Do I contradict myself? Very well then I contradict myself, (I am large, I contain multitudes.)"
 -- Walt Whitman, from _Song of Myself_

(with one space at the beginning of the author line, substituting for the newline that was supposed to be before it)

Clearly, some things are amiss.

Edit: I think I figured out the problem. For %-using fortune files, within the quote, you're substituting a space for single newlines, but you are displaying newlines if two or more consecutive newlines are involved (except the very first newline gets substituted with a space again). Why you're doing it this way, I don't know. It's probably a bug.
« Last Edit: July 22, 2008, 02:59 AM by transitionality »

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,900
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: Parsing of Fortune Files
« Reply #9 on: July 22, 2008, 06:20 AM »
i just uploaded a minor update.

it should fix the space at begining of line problem.

the conversion of normal newlines into spaces is by design since fortune files seem to be most often formatted with hard newlines for linebreaks which isn't appropriate for popup wisdom.

you have a couple of choices for forcing newlines in these files. you can manually put a \n where you want a newline, or you can start lines which should start on a new line with a space or you can put 2 newlines (or more) to indicate a break.

transitionality

  • Participant
  • Joined in 2008
  • *
  • default avatar
  • Posts: 9
    • View Profile
    • Donate to Member
Re: Parsing of Fortune Files
« Reply #10 on: July 22, 2008, 01:16 PM »
you have a couple of choices for forcing newlines in these files. you can manually put a \n where you want a newline

if i were willing to do this, i would have used popupwisdom's own format

or you can start lines which should start on a new line with a space or you can put 2 newlines (or more) to indicate a break.

meh. none of this is wysiwyg. wouldn't it be nice to have a wysiwyg file format, that would be pleasant to read and work with, as well as being used as a data format?

i do appreciate the work you've put into compliance with the cookie-jar format, and i understand why it needs to work the way it does, but perhaps you can appreciate the feature request i defined above.

maybe you can define a new format, unique to popupwisdom, that is similar to the cookie-jar format but is wysiwyg. you get newlines and spaces and tabs if you put them, where you put them, and nowhere else, (except whitespace between content and delimiter is ignored, like you currently do with cookie-jar format). in this new and original file format, you would probably want to define a new delimiter different from % or %%. you could call it popup wisdom wysiwyg file format. it shouldn't be too much work on top of work you've already done, but i feel like it would be a useful and worthy addition.

what do people think about this?
« Last Edit: July 22, 2008, 01:52 PM by transitionality »