9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] rc funny / my lack of understanding
@ 2003-01-03 14:23 steve.simon
  2003-01-03 16:00 ` Russ Cox
  0 siblings, 1 reply; 2+ messages in thread
From: steve.simon @ 2003-01-03 14:23 UTC (permalink / raw)
  To: 9fans

[-- Attachment #1: Type: text/plain, Size: 610 bytes --]



Hi,

Attached is a bit of hget + rc + sam -d to get recent AP newswire
stories.

It has two modes - without an arg it lists the stories, with one it
prints that story.

The if statement seems to confuse the here document syntax of rc and it
start interpreting the tmp file as commands - all very odd.

If I remove the if statement and implement the program as two scripts
envoked seperately it works so the basic code must be right... I think.

I tried running the sam -d here document in a subshell ( @{...} )
but it still did the same thing.

Confused of Winchester,

-Steve



 

[-- Attachment #2: Newswire --]
[-- Type: application/octet-stream, Size: 675 bytes --]

#!/bin/rc
#
#	get AP news headline list or the given story
#

tmp=/tmp/tmp.$pid
wire='http://www.newsday.com/news/nationworld/wire'

if ( ~ $#* 0 ){
	hget $wire | grep headlines > $tmp
	sam -d $tmp >[2] /dev/null << 'EOF'
		,x/^.*sns-/d
		,x/,0,[0-9]*\.story.*">/c/@/
		,x/<\/a>/d
		w
	EOF
	awk -F@ '{printf("%-45s %s\n", $1, $2);}' $tmp
	rm -f $tmp
	exit 0
}

hget $wire/^sns-^$1^.story > $tmp
sam -d $tmp >[2] /dev/null << 'EOF'
	0,/END RELATED CONTENT RAIL/ d
	/^<\/font>$/,$ d
	,x/&copy;/ c/(c)/
	,x/&nbsp;/ c/ /
	,x/&lt;/ c/</
	,x/&gt;/ c/>/
	,x/&amp;/ c/&/
	,x/&nbsp;/ c/ /
	,x/&[a-z0-9][a-z0-9]*;/ d
	,x/<br>/ c/\n/
	,x/<[^>]*>/ d
	/^ *$/ d
	w
EOF
fmt $tmp
rm -f $tmp

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [9fans] rc funny / my lack of understanding
  2003-01-03 14:23 [9fans] rc funny / my lack of understanding steve.simon
@ 2003-01-03 16:00 ` Russ Cox
  0 siblings, 0 replies; 2+ messages in thread
From: Russ Cox @ 2003-01-03 16:00 UTC (permalink / raw)
  To: 9fans

Here documents have to come after all the braces
have been closed, so you say

if(foo){
	cat <<EOF
	echo hi
}
Hello world
EOF

and not

if(foo){
	cat <<EOF
Hello world
EOF
	echo hi
}

it is admittedly very strange.



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2003-01-03 16:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-01-03 14:23 [9fans] rc funny / my lack of understanding steve.simon
2003-01-03 16:00 ` Russ Cox

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).