From: Ethan Grammatikidis <eekee57@fastmail.fm>
To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net>
Subject: Re: [9fans] rc word splitting trouble
Date: Sat, 3 Apr 2010 18:24:44 +0100 [thread overview]
Message-ID: <11C11BC0-346A-4E77-9909-B87667FE6EF2@fastmail.fm> (raw)
In-Reply-To: <79bfa351ebdb8906c17ec13976aa3e15@ladd.quanstro.net>
[-- Attachment #1: Type: text/plain, Size: 1475 bytes --]
On 3 Apr 2010, at 15:38, erik quanstrom wrote:
>> % fullloc = '/one/two?three+four'
>> % params = `{echo $fullloc | sed -e 's;.*\?;;' -e 's;\+; ;g'}
>> % for(param in $params) echo ' <li>'$"param
>> <li>three
>> <li>four
>>
>> The 2nd and 3rd command lines are copied directly from the script,
>> but
>> the script itself outputs the following:
>>
>> <li>three four
>>
>> The sed expressions appear to be working correctly, to my eyes, so I
>> don't understand what's going on.
>
> i suspect your ifs is set to something funky.
>
> inserting a "whatis params" in your script would be pretty
> interesting. note that gnu sed will eat your regular expression
> since you \? is their meta character.
sed is p9p sed, verified with which, but ty.
You're right about ifs, "whatis ifs" showed it up. It is set to
newline-only for one line within the read loop, using the "var=foo
command" syntax, but "command" in this case is another assignment.
When I add a no-op command to the end (making it "assignment
assignment command") rc complains "params: not found" and fails to run
the loop properly. I don't know what kind of state the parser got into
to produce that error.
Anyway, I've fixed it for now by re-setting ifs after the line in
question.
I'm attaching the script; an embedded carriage-return makes a mess of
both pasting the line here and posting it in a pastebin. The problem
line is the first one in the while block.
[-- Attachment #2: web-script.rc --]
[-- Type: application/octet-stream, Size: 1113 bytes --]
# munch on request
reqlines = ''
done = false
while(~ $"done 'false') {
ifs = '
' line = `{read |sed 's/\r//g'}
# echo '^'$"line'$' > /dev/stderr
reqlines = $"reqlines$"line'
'
ifs='
'
if(echo $"line | grep '^GET ' > /dev/null) {
method = `{echo $"line | sed 's; .*;;'}
fullloc = `{echo $"line | sed -e 's;[^ ]* /;/;' -e 's; .*;;'}
location = `{echo $"fullloc | sed 's;\?.*;;'}
params = `{echo $fullloc | sed -e 's;.*\?;;' -e 's;\+; ;g'}
}
if(~ $"line '')
done = true
}
# spew our junk
echo HTTP/1.0 200 OK
echo Content-type text/html
echo
cat << EOF
<html>
<head>
<title>Hello!</title>
</head>
<body>
EOF
echo '<p>Request received:
<pre>'
echo -n $reqlines
echo '</pre>'
echo '<ul><li>Method:' $"method
echo '<li>Location (complete):' $"fullloc
echo '<li>Location:' $"location
echo '<li>Parameters:<ul>'
for(param in $params) echo ' <li>'$"param
echo ' </ul>'
echo '</ul>'
echo '<pre>'
echo '% whatis ifs'
whatis ifs
echo '% whatis params'
whatis params
echo '% which sed'
which sed
echo '</pre>'
echo '
</body>
</html>
'
[-- Attachment #3: Type: text/plain, Size: 345 bytes --]
>
> you can accomplish something that's equivalent in rc without
> an explicit loop:
>
> echo '<li>' ^ $params
Good to know. I haven't used it here because the for loop generates
nicer html from nicer source, if that makes sense.
>
> - erik
>
--
Simplicity does not precede complexity, but follows it. -- Alan Perlis
prev parent reply other threads:[~2010-04-03 17:24 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-04-03 14:21 Ethan Grammatikidis
2010-04-03 14:38 ` erik quanstrom
2010-04-03 17:24 ` Ethan Grammatikidis [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=11C11BC0-346A-4E77-9909-B87667FE6EF2@fastmail.fm \
--to=eekee57@fastmail.fm \
--cc=9fans@9fans.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).