"O'Connor's Song" and aemenu (SOLVED)

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

"O'Connor's Song" and aemenu (SOLVED)

#1 Post by musher0 »

Hello people.

I'm banging my head on this problem: can we process apostrophes AND
spaces at the same time in the same string?

My practical situation is as follows:

for the sake of argument, let's say I have a song, in ogg format, named
"O'Connor's Song". The file name is thus: OConnor's Song.ogg

I am trying to fit that as a line in aemenu. (Aemenu is a stand-alone
component of the aewm window manager.)

The structure of this menu has to be as follows:
cmd title executable

We can also have:
cmd "Longer Title" "executable some-parameter"

Back to my fictitious example, to incorporate O'Connor's Song in this
structure, I must use the form:

Code: Select all

cmd "O'Connor's Song" "play O'Connor's Song.ogg"
(or mplayer instead of play, it doesn't matter).

I can solve the spaces problem by writing this:

Code: Select all

cmd "O'Connor's Song" "play 'O'Connor's Song.ogg'"
Since the file name is between apostrophes, the spaces are interpreted ok.

This is where I am stumped. The piece will not play because there are
apostrophes in the parameter for the executable: "O'Connor's". Play does
not find the song, 'O', obviously, because I have used the apostrophe as
delimiter.

It's as if we cannot compensate for spaces AND apostrophes in the same
string at the same time.

If anyone can shed some light on this subject, I'll be grateful.

BFN.
Last edited by musher0 on Sat 19 Aug 2017, 08:00, edited 1 time in total.
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#2 Post by SFR »

How about this?

Code: Select all

# set cmd "O'Connor's Song" "play \"O'Connor's Song.ogg\""
# 
# echo $1
cmd
# echo $2
O'Connor's Song
# echo $3
play "O'Connor's Song.ogg"
#
Greetings!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#3 Post by musher0 »

SFR wrote:How about this?

Code: Select all

# set cmd "O'Connor's Song" "play "O'Connor's Song.ogg""
# 
# echo $1
cmd
# echo $2
O'Connor's Song
# echo $3
play "O'Connor's Song.ogg"
#
Greetings!
Hello SFR.

Thanks for responding.

Your solution will work at the console, but I have to construct the menu.

Perhaps I should have said it explicitly. That's what I meant by "one step
removed" in the sub-title.

The construction script has to contain:

Code: Select all

> song-menu
echo "cmd "O'Connor's Song" "play "O'Connor's Song.ogg"" >> song-menu
I cannot use " three times in the executable part (2nd part), only two
times, otherwise nothing will play.

Also I do not understand your "echoes" $1, $2 and $3. In this
example, you are using a matrix, yes? Why separate when one needs
to concatenate?

I tried this:

Code: Select all

set "cmd "O'Connor's Song" "play "O'Connor's Song.ogg""";echo $1;echo $2;echo $3
Result is this:
cmd "O'Connor's Song" "play "O'Connor's Song.ogg""
aemenu will stop reading after "play ".

Thanks in advance for any further explanation.

BFN.
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#4 Post by MochiMoppel »

Code: Select all

echo "cmd \"O'Connor's Song\" \"play \\\"O'Connor's Song.ogg\\\"\""  >> song-menu
Result in song-menu:

Code: Select all

cmd "O'Connor's Song" "play \"O'Connor's Song.ogg\""
Should work if your aemenu is able to pass the executable part correctly to the shell command interpreter.

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#5 Post by musher0 »

The 3 escape characters ( "\\\" ) do the work! Thanks, MochiMoppei.

I'll mark this problem as solved.

Have a great day!
Attachments
Spaces-&-apostrophes-2.jpg
(149.32 KiB) Downloaded 119 times
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#6 Post by SFR »

Also I do not understand your "echoes" $1, $2 and $3. In this
example, you are using a matrix, yes? Why separate when one needs
to concatenate?
The 'set' and 'echos' were merely a demo to show what's the actual outcome of, mainly, this string:

Code: Select all

"play \"O'Connor's Song.ogg\""
Could've just use 'echo', actually (it was late, nevermind ;)).

From what I see now, I overlooked the requirement of having the whole string (incl. 'play') wrapped in quotes, not only the filename.
Fortunately, Mochi provided the correct way.

Greetings!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#7 Post by musher0 »

Thanks for the explanation, SFR.

BFN.
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

Post Reply