9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] watching plumber
@ 2010-03-12 23:25 Rudolf Sykora
  2010-03-12 23:54 ` erik quanstrom
  2010-03-13 10:45 ` Rudolf Sykora
  0 siblings, 2 replies; 14+ messages in thread
From: Rudolf Sykora @ 2010-03-12 23:25 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

Hello,

I wanted to add a plumbing rule. I added this:

type is text
data matches '[^{}]+'
data matches '(figs/([a-zA-Z0-9[\].-_]*/)*)([a-zA-Z0-9.-_]+)'
arg isdir $1
plumb start grep $2 $1/_source | sed -e 's/\.eps/.g/' | \
	plumb -i -d edit

However, it doesn't work. Is there any simple way how one can analyze
what is wrong? I.e. to see that some rules are matched, others not, so
that one can get the idea where the problem is (how far in the rules
one gets)?

Also. When having a rule like this

data matches '(abc(def)*)(ghi)'

what is going to be in $1, $2... Is ghi the contents of $2 or not?

The plumber's behaviour I want to achieve is quite difficult to
explain, nonetheless:
for a text in an editor like
{figs/10[CuNi]/Cxy}
I want to find a line in figs/10[CuNi]/_source containing Cxy, it will
be something like /abc/Cxy.eps and I really want to open a file
/abc/Cxy.g in the editor.

Thanks for any comments!
Ruda



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

* Re: [9fans] watching plumber
  2010-03-12 23:25 [9fans] watching plumber Rudolf Sykora
@ 2010-03-12 23:54 ` erik quanstrom
  2010-03-13  0:16   ` Rudolf Sykora
  2010-03-13 10:45 ` Rudolf Sykora
  1 sibling, 1 reply; 14+ messages in thread
From: erik quanstrom @ 2010-03-12 23:54 UTC (permalink / raw)
  To: 9fans

> what is going to be in $1, $2... Is ghi the contents of $2 or not?

this is easy to test:

; echo abcdefghi | sed 's/(abc(def)*)(ghi)/\1/'
abcdef
; echo abcdefghi | sed 's/(abc(def)*)(ghi)/\2/'
def
; echo abcdefghi | sed 's/(abc(def)*)(ghi)/\3/'
ghi

- erik



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

* Re: [9fans] watching plumber
  2010-03-12 23:54 ` erik quanstrom
@ 2010-03-13  0:16   ` Rudolf Sykora
  2010-03-13  0:39     ` erik quanstrom
  0 siblings, 1 reply; 14+ messages in thread
From: Rudolf Sykora @ 2010-03-13  0:16 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On 13 March 2010 00:54, erik quanstrom <quanstro@quanstro.net> wrote:
>> what is going to be in $1, $2... Is ghi the contents of $2 or not?
>
> this is easy to test:
>
> ; echo abcdefghi | sed 's/(abc(def)*)(ghi)/\1/'
> abcdef
> ; echo abcdefghi | sed 's/(abc(def)*)(ghi)/\2/'
> def
> ; echo abcdefghi | sed 's/(abc(def)*)(ghi)/\3/'
> ghi
>
> - erik
>

Ok, thats fine. But
;9 echo abcdefdffghi | 9 sed 's/(abc(d?f)*)(ghi)/\1/'
abcdefdffghi
;9 echo abcdefdffghi | 9 sed 's/(abc(d?f)*)(ghi)/\2/'
abcdefdffghi
;9 echo abcdefdffghi | 9 sed 's/(abc(d?f)*)(ghi)/\3/'
abcdefdffghi
;9 echo abcdefdffghi | 9 sed 's/(abc(d?f)*)(ghi)/\4/'
abcdefdffghi
;9 echo abcdefdffghi | 9 sed 's/(abc(d?f)*)(ghi)/\5/'
abcdefdffghi
;9 echo abcdefdffghi | 9 sed 's/(abc(d?f)*)(ghi)/\6/'
abcdefdffghi

this I don't understand...
maybe it's too late for me...
Thanks
Ruda



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

* Re: [9fans] watching plumber
  2010-03-13  0:16   ` Rudolf Sykora
@ 2010-03-13  0:39     ` erik quanstrom
  2010-03-13  8:19       ` Rudolf Sykora
  0 siblings, 1 reply; 14+ messages in thread
From: erik quanstrom @ 2010-03-13  0:39 UTC (permalink / raw)
  To: 9fans

> Ok, thats fine. But
> ;9 echo abcdefdffghi | 9 sed 's/(abc(d?f)*)(ghi)/\1/'
>
> this I don't understand...
> maybe it's too late for me...

you're re doesn't match at all.  therefore no
substitutation is made.  perhaps it would be
easier to see with this formulation:

9 echo abcdefdffghi | 9 sed -n 's/(abc(d?f)*)(ghi)/\1/p'

- erik



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

* Re: [9fans] watching plumber
  2010-03-13  0:39     ` erik quanstrom
@ 2010-03-13  8:19       ` Rudolf Sykora
  0 siblings, 0 replies; 14+ messages in thread
From: Rudolf Sykora @ 2010-03-13  8:19 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On 13 March 2010 01:39, erik quanstrom <quanstro@labs.coraid.com> wrote:
>> Ok, thats fine. But
>> ;9 echo abcdefdffghi | 9 sed 's/(abc(d?f)*)(ghi)/\1/'
>>
>> this I don't understand...
>> maybe it's too late for me...
>
> you're re doesn't match at all.  therefore no
> substitutation is made.  perhaps it would be
> easier to see with this formulation:
>

Yes. Of course. I was just really tired at the point to not notice...
Actually, what I was trying to check was

;9 echo abcdefdffghi | 9 sed 's/(abc(d.?f)*)(ghi)/\6/'
sed: Invalid back reference \6
;9 echo abcdefdffghi | 9 sed 's/(abc(d.?f)*)(ghi)/\1/'
abcdefdff
;9 echo abcdefdffghi | 9 sed 's/(abc(d.?f)*)(ghi)/\2/'
dff
;9 echo abcdefdffghi | 9 sed 's/(abc(d.?f)*)(ghi)/\3/'
ghi
;

i.e. not just '?' but '.?' to see what will be where in \1, \2... And
the above shows, hopefully now, that for construction like (regexp)*
the last match is stores in the corresponding (here) \2. And the order
of \1, \2, ...  ($1, $2... for the plumber then) is determined by the
opening (.

Thanks
Ruda



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

* Re: [9fans] watching plumber
  2010-03-12 23:25 [9fans] watching plumber Rudolf Sykora
  2010-03-12 23:54 ` erik quanstrom
@ 2010-03-13 10:45 ` Rudolf Sykora
  2010-03-13 15:31   ` erik quanstrom
  1 sibling, 1 reply; 14+ messages in thread
From: Rudolf Sykora @ 2010-03-13 10:45 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

Hello,

having a rule in lib/plumbing with the action

plumb start 9 cat /home/ruda/CALC/manu/$1_source | plumb -i -d edit -a
action=showdata

I am getting this message when it is used

/home/ruda/CALC/systems/ni4ni4ni4_264_fcc001_2/rotxy/Cxy.eps
/home/ruda/CALC/systems/ni4ni4ni4_264_fcc001_2/rotzx/Czx.eps
cat: can't open |: No such file or directory

(somehow it appears in the terminal)
what am I doing wrong?

Also, as I am using p9p now, I don't know who interprets the part
after the 'plumb start'. I first, believing that rc does the job, had
e.g.
cat /home/ruda/CALC/manu/^$1^_source
there (note the ^s), but then those ^s stayed intact in the name
(which wasn't naturally found).

Btw. It quite surprised me that a line beginning with # is considered
as an empty line instead of being ignored. Thus when I commented out a
line inside a block of rules, the block was disintegrated into two,
which really didn't work. (So one must not comment out anything inside
a block, i.e. between the rules.)

Thanks for any comments!
Ruda



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

* Re: [9fans] watching plumber
  2010-03-13 10:45 ` Rudolf Sykora
@ 2010-03-13 15:31   ` erik quanstrom
  2010-03-13 17:14     ` Rudolf Sykora
  0 siblings, 1 reply; 14+ messages in thread
From: erik quanstrom @ 2010-03-13 15:31 UTC (permalink / raw)
  To: 9fans

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="UTF-8", Size: 2121 bytes --]

> plumb start 9 cat /home/ruda/CALC/manu/$1_source | plumb -i -d edit -a
> action=showdata
>
> I am getting this message when it is used
>
> /home/ruda/CALC/systems/ni4ni4ni4_264_fcc001_2/rotxy/Cxy.eps
> /home/ruda/CALC/systems/ni4ni4ni4_264_fcc001_2/rotzx/Czx.eps

why are you executing a rule instead of directly plumbing to edit?
i'm not sure all of the wheres and whys of what you're doing, but
it smells too complicated.  also, using annoying characters like
'[' and '] in filenames is complicating matters.

> Also, as I am using p9p now, I don't know who interprets the part
> after the 'plumb start'. I first, believing that rc does the job, had
> e.g.
> cat /home/ruda/CALC/manu/^$1^_source
> there (note the ^s), but then those ^s stayed intact in the name
> (which wasn't naturally found).

both the plumber and rc get a crack at it.  it's like `` in the
bourne shell.

so, for example, if i want to quote something in rc because i've
got a globbing character or other problem, i'd need a rule like
this:

type	is	text
data	matches	'\* x \*'
plumb	start	rc -c 'echo '''$0''' >> /tmp/junk'

3 's are needed.  two to generate a character-stuffed quote and
one to terminate or start quoting.  $0 must be interpreted by
plumber.

by the way, there's a (mostly harmless) bug in plumb's
basic rules:

/n/sources/plan9//sys/lib/plumb/basic:92,98 - basic:92,98
  # man index entries are synthesized
  type is text
  data matches '([a-zA-Z¡-￿0-9_\-./]+)\(([1-8])\)'
- plumb start rc -c 'man -b '$2' '$1'
+ plumb start rc -c 'man -b '$2' '$1

  # start rule for images without known suffixes
  dst is image

the reason this extra ' at the end is not flagged is
because the plumber doesn't check for unterminated
quotes.  this change to plumb's source would need
to be made to enable checking:

/n/sources/plan9//sys/src/cmd/plumb/rules.c:330,335 - rules.c:331,339
  	if(ends)
  		*ends = s;
  	*p = '\0';
+ 	/* disabled due to default plumbing having broken rule */
+ 	if(0 && quoting)
+ 		return "eof-in-quoted-string";
  	return ebuf;
  }

- erik



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

* Re: [9fans] watching plumber
  2010-03-13 15:31   ` erik quanstrom
@ 2010-03-13 17:14     ` Rudolf Sykora
  2010-03-13 19:18       ` Rudolf Sykora
  0 siblings, 1 reply; 14+ messages in thread
From: Rudolf Sykora @ 2010-03-13 17:14 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

> why are you executing a rule instead of directly plumbing to edit?
> i'm not sure all of the wheres and whys of what you're doing, but
> it smells too complicated.  also, using annoying characters like
> '[' and '] in filenames is complicating matters.

I'm executing a rule since I really need to prepare the stuff.
Actually it's not 'cat' I want to execute, but grep:

type is text
data matches '[^{}]+'
data matches '(figs/([a-zA-Z0-9[\].-_]*/)*)([a-zA-Z0-9.-_]+)'
arg isdir $1
plumb start 9 grep $3 /home/ruda/CALC/manu/$1_source | plumb -i -d
edit -a action=showdata

and even in this a step is missing (I started with simple rule and
complicate it step by step, checking it works). The final rule should
be sth. like

plumb start grep $3 /home/ruda/CALC/manu/$1/_source | sed -e
's/\.eps/.g/' | plumb -i -d edit

but I am not there yet. Similarly to the problem with 'cat' now I am
getting (with the last but one rule):

;/home/ruda/CALC/manu/figs/4Co4Ni4Co/_source:/home/ruda/CALC/systems/co4ni4co4_264_fcc001/rotxy/Cxy.eps
grep: can't open |: No such file or directory
grep: can't open plumb: No such file or directory
grep: can't open -i: No such file or directory
grep: can't open -d: No such file or directory
grep: can't open edit: No such file or directory
grep: can't open -a: No such file or directory
grep: can't open action=showdata: No such file or directory

as if the rule was sending all stuff to grep as arguments...

Yes, the [ ] characters are annoying... but now it's not them causing
the problem, they are not present now.
And yes, it perhaps is fairly complicated, but it can help me a bit if
working. It'd be just my personal rule...

I think the thing with arguments (i.e why everything is considered an
argument to grep in the last example), is the last problem on my way.

and the [ ] characters ... I may get rid of them in the future for
some other unicode characters which could serve the purpose of
brackets.

Thanks
Ruda



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

* Re: [9fans] watching plumber
  2010-03-13 17:14     ` Rudolf Sykora
@ 2010-03-13 19:18       ` Rudolf Sykora
  2010-03-13 23:05         ` erik quanstrom
  0 siblings, 1 reply; 14+ messages in thread
From: Rudolf Sykora @ 2010-03-13 19:18 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

Hello,

now I am having an even simpler problem. :)

I just added this rule to lib/plumbing (to its end)

type text
plumb to edit

then for whatever sent the editor tries to open a file with the $data
name. To not open but only show $data (thus sort of echo) I tried

plumb to edit -a action=showdata

This didn't work, the editor again tried to open the $data file, so I
deduced 'plumb to edit' can't have additional parameters... (right?)
... and tried

plumb start echo $data | plumb -i -d edit -a action=showdata

which, however, does seemingly nothing... I don't understand why...

Thanks for any comments!
Ruda



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

* Re: [9fans] watching plumber
  2010-03-13 19:18       ` Rudolf Sykora
@ 2010-03-13 23:05         ` erik quanstrom
  2010-03-14 15:55           ` Rudolf Sykora
  0 siblings, 1 reply; 14+ messages in thread
From: erik quanstrom @ 2010-03-13 23:05 UTC (permalink / raw)
  To: 9fans

> This didn't work, the editor again tried to open the $data file, so I
> deduced 'plumb to edit' can't have additional parameters... (right?)
> ... and tried
>
> plumb start echo $data | plumb -i -d edit -a action=showdata
>
> which, however, does seemingly nothing... I don't understand why...

because the arguments to start are not a shell script, they are a command
plus arguments.  in this case you are running /bin/echo with arguments
	$data '|' plumb -i -d edit -a 'action=showdata'
i think what you intend to write is more like
	plumb start rc -c 'echo '$data' | plumb -i -d edit -a ''action=showdata'''

with a little bit of hindsight, perhaps it might have been easier for
the plumber to make the arguments a shell script and feed the literal text
to the shell.

in any event, that's not what we've got.  and you can easily get around
this by writing a shell script that keeps the complication out of the
plumber's rules.

- erik



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

* Re: [9fans] watching plumber
  2010-03-13 23:05         ` erik quanstrom
@ 2010-03-14 15:55           ` Rudolf Sykora
  2010-03-14 20:11             ` erik quanstrom
  0 siblings, 1 reply; 14+ messages in thread
From: Rudolf Sykora @ 2010-03-14 15:55 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

> i think what you intend to write is more like
>        plumb start rc -c 'echo '$data' | plumb -i -d edit -a ''action=showdata'''

Yes. This works! :)

> with a little bit of hindsight, perhaps it might have been easier for
> the plumber to make the arguments a shell script and feed the literal text
> to the shell.

Well. So now I just don't understand how the examples in
Plumbing and Other Utilities by Rob Pike, page 11
could work... Was there a rewrite? The example there is no longer
valid... :( That cost me quite some time...

> - erik

Thanks!
Ruda



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

* Re: [9fans] watching plumber
  2010-03-14 15:55           ` Rudolf Sykora
@ 2010-03-14 20:11             ` erik quanstrom
  2010-03-15  4:53               ` Anthony Sorace
  0 siblings, 1 reply; 14+ messages in thread
From: erik quanstrom @ 2010-03-14 20:11 UTC (permalink / raw)
  To: 9fans

> Well. So now I just don't understand how the examples in
> Plumbing and Other Utilities by Rob Pike, page 11
> could work... Was there a rewrite? The example there is no longer
> valid... :( That cost me quite some time...

it is a very good question that should be answered.

for reference, the first example on p. 11 is:

	# rule set for microsoft word documents
	type is text
	data matches '[a-zA-Z0-9_\-./]+'
	data matches '([a-zA-Z0-9_\-./]+)\.doc'
	arg isfile $0
	plumb start doc2txt $data | \
	    plumb -i -d edit -a action=showdata -a filename=$0


it doesn't appear that plumber has had any changes
since the beginning of sources.  does anyone with a
2e licence know if plumber used to accept rules
like this; that is shell script fragments?

- erik



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

* Re: [9fans] watching plumber
  2010-03-14 20:11             ` erik quanstrom
@ 2010-03-15  4:53               ` Anthony Sorace
  2010-03-18 15:34                 ` erik quanstrom
  0 siblings, 1 reply; 14+ messages in thread
From: Anthony Sorace @ 2010-03-15  4:53 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

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

Erik asked:

> does anyone with a 2e licence know if plumber used to accept rules
> like this; that is shell script fragments?

It did not - because the plumber did not exist in 2e or earlier. Like
a handful of other things, it was originally drafted for Inferno and
then backported (with improvements) to Plan 9.

Looking at my current Inferno rules, they look like the rules we see
in Plan 9. I've not looked beyond my own rules to see if they accept
the other style.


[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 201 bytes --]

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

* Re: [9fans] watching plumber
  2010-03-15  4:53               ` Anthony Sorace
@ 2010-03-18 15:34                 ` erik quanstrom
  0 siblings, 0 replies; 14+ messages in thread
From: erik quanstrom @ 2010-03-18 15:34 UTC (permalink / raw)
  To: 9fans

> Erik asked:
>
> > does anyone with a 2e licence know if plumber used to accept rules
> > like this; that is shell script fragments?
>
> It did not - because the plumber did not exist in 2e or earlier. Like
> a handful of other things, it was originally drafted for Inferno and
> then backported (with improvements) to Plan 9.
>
> Looking at my current Inferno rules, they look like the rules we see
> in Plan 9. I've not looked beyond my own rules to see if they accept
> the other style.

so, the question still is: fix the documentation or fix the source code?

- erik



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

end of thread, other threads:[~2010-03-18 15:34 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-12 23:25 [9fans] watching plumber Rudolf Sykora
2010-03-12 23:54 ` erik quanstrom
2010-03-13  0:16   ` Rudolf Sykora
2010-03-13  0:39     ` erik quanstrom
2010-03-13  8:19       ` Rudolf Sykora
2010-03-13 10:45 ` Rudolf Sykora
2010-03-13 15:31   ` erik quanstrom
2010-03-13 17:14     ` Rudolf Sykora
2010-03-13 19:18       ` Rudolf Sykora
2010-03-13 23:05         ` erik quanstrom
2010-03-14 15:55           ` Rudolf Sykora
2010-03-14 20:11             ` erik quanstrom
2010-03-15  4:53               ` Anthony Sorace
2010-03-18 15:34                 ` erik quanstrom

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