[9fans] Plumber architecture question

2019-01-05 Thread Ethan Gardener
Every so often, I start wondering why the plumber isn't simpler.  Here's my 
simpler design:  There is no plumber.  Instead, `plumb` reads the plumbing 
files and acts accordingly.  To receive input from the plumber, programs post a 
pipe in /srv.  No need for a special-purpose filesystem.

It will break if multiple processes post the same pipe, the second process 
won't be able to create the pipe.  Isn't that a good thing?  Plumber behaviour 
is to send messages to all recipients, which has surprised me a few times when 
I wasn't quite alert.

It would also break my use case of separate plumber instances for separate 
activities; there is only one #s, but I don't think anyone does this other than 
me.  It can be done another way, with plumber rules to discriminate by 
directory, but that takes a bit more setup.  I would work if there could be 
multiple srv(3) filesystems, which I think would sometimes be useful for other 
tasks too.  To make this work, all the programs which currently address 
'#s/filename' would have to be changed to address the full path.  Then creation 
permission would control which of the srv filesystems gets the pipe. 

Just musing on architecture.  Comments welcome.

-- 
2.1.3. Life with eternal upgrades



[9fans] Raspberry Pi 3 B+ image of 9front

2019-01-05 Thread Raingloom
Has anyone made one? I'm trying to put one together but the Plan 9 disk tools 
are... well they are quite different to what I'm used to. I managed to build 
the kernel and the userspace (with CONF=rpi2, which is afaik the correct one 
for rpi3 too?) and am trying to mirror the partitioning of the image by Richard 
Miller (at least more or less, I'll probably have to change things for HJFS) 
and combine the contents from that and a 9front VM.
Is that a good way to go ahead?



Re: [9fans] Plumber architecture question

2019-01-05 Thread Ethan Gardener
On Sat, Jan 5, 2019, at 2:12 PM, erik quanstrom wrote:
> you need plumber so cpu can be transparent to plumbing.

Good point.  I think it could be done with multi-/srv, but I see one problem: 
you wouldn't want cpu to export all of /srv.  (Right?)  I think it could be 
dealt with by mounting a separate #s instance (for want of a better name) just 
for the plumber-replacement pipes.  



Re: [9fans] Raspberry Pi 3 B+ image of 9front

2019-01-05 Thread cinap_lenrek
richard miller did a very fine job with the image.

9front used to have a image to download based on it for the raspi1,
but it is quite old and nobody updated it.

in the last release, we updated the kernel from richards
code and made the /sys/lib/dist/mkfile able to produce a
bootable sdcard image with hjfs filesystem.

documentation in the fqa is under way.

you can build a bootable sdcard image by running:

# build arm userspace
objtype=arm
cd /sys/src
mk install

# build kernel
cd /sys/src/9/bcm

# pi1 kernel (optional)
mk 'CONF=pi' install

# pi2/3 kernel
# mk 'CONF=pi2' install (pi2 is default)
mk install

# download firmware
cd /sys/src/boot/bcm
mk

# build bootable hjfs sdcard image
cd /sys/lib/dist
mk /tmp/mysdcard.pi.img

# copy to sdcard
cat /tmp/mysdcard.pi.img > /dev/sdM0/data

--
cinap



Re: [9fans] Plumber architecture question

2019-01-05 Thread erik quanstrom
you need plumber so cpu can be transparent to plumbing.- erik

Re: [9fans] Raspberry Pi 3 B+ image of 9front

2019-01-05 Thread Chris McGee
I have been intending to try out the new raspberry pi updates too for
9front, but haven't had the chance yet.

A couple of years ago I was building the sd-card images for my raspberry
pis by using qemu to bring up an x86 install of 9front and doing a
cross-compile within to build the new disk image. Here's a script that I
used after the manual 9front install to do that plus a bunch of other
things that you probably don't care about. It does need significant cleanup
and updates.

https://github.com/sirnewton01/rpi-9front/blob/master/postsetup.rc

I'm hoping that it is at least some help to others.

Chris

On Sat, Jan 5, 2019 at 12:10 PM Raingloom  wrote:

> Has anyone made one? I'm trying to put one together but the Plan 9 disk
> tools are... well they are quite different to what I'm used to. I managed
> to build the kernel and the userspace (with CONF=rpi2, which is afaik the
> correct one for rpi3 too?) and am trying to mirror the partitioning of the
> image by Richard Miller (at least more or less, I'll probably have to
> change things for HJFS) and combine the contents from that and a 9front VM.
> Is that a good way to go ahead?
>
>


Re: [9fans] How does one read a file line by line in an rc script?

2019-01-05 Thread Steve Simon
What are you running this on, is this byron's rc on unix?

I just tried the secript I posted, cut and pasted into a
tiny shell scropt called testread, and it just worked™

maybe some other part of your script has a problem?

My script below
-snip-snip-
#!/bin/rc

cat $1 | while(line=`{read}){
echo $line
}

-snip-snip-


Also, I didn't have the time to read all of your previous question,
but I think what you are after is $"varname, this expands to the value
of the variable but as a single argument, no matter if it, when
it was assigned, had multiple, white space seperated words in it.

for example:  (NB: hugo% is my prompt)

hugo% fred=(a b c d)

hugo% echo $fred^-letter
a-letter b-letter c-letter d-letter

hugo% echo $"fred^-letter
a b c d-letter

-Steve



Re: [9fans] rc scripts, how to get spaces in array elements generated by command output?

2019-01-05 Thread Mack Wallace
Thank you Anthony!

I had thought that IFS in Plan 9 was not the way to go after reading from ‘Rc - 
The Plan 9 Shell’ 

 “IFS is no longer used, except in the one case where it was indispensable:
  converting command output into argument lists during command 
substitution.”

The document then followed about avoiding a UNIX security hole, and lacking 
examples was not sure what this meant. Of course, in retrospect, it means 
exactly what I want to do.

So what I’ve ended up doing:

headrec = `{read $1 | sed ’s/^/,/; s/\\”/☹/g; s/,”([^”]*)”/,☺\1☻/g; s/,”/,☺/; 
:MC; s/☺([^☻]*),([^☻]*)/☺\1☯\2/g; tMC; s/^,//; s/,/♪/g’}
oldifs = $ifs
ifs = ♪
headers = `{echo $headrec | sed ‘/s/☹/\\”/g; s/(☺|☻)/“/g; s/☯/,/g’}
ifs = $oldifs

I’m not sure if there is a cleaner way to do this - but it gets the array of 
headers how they should be.

I’ll look at your other message.

Thanks,

Mack




> On Jan 5, 2019, at 6:52 PM, Anthony Martin  wrote:
> 
> Mack Wallace  once said:
>> My question: Is there a way to take the string output of a command that
>> contains spaces and make it a single element of an array in rc script?
>> 
>> [...]
>> 
>> However, if I am receiving output from sed that contains spaces from
>> the following script line
>> 
>> string_var = `{echo some_string | sed ’s/x/y/g’}
>> 
>> If the output was ‘hello world’, string_var would become a two
>> element array which
>> echo $some_string(1) 
>> echo $some_string(2)
>> 
>> Would output 
>> hello
>> world
> 
> You need to change the input field separator, $ifs.
> 
> The default value is any whitespace character:
> 
>   % x = `{echo -n hello world}
>   % echo $#x
>   2
>   % echo $x(1)
>   hello
>   % echo $x(2)
>   world
> 
> Using only newline as the separator yields:
> 
>   % ifs = '
>   ' # this is a newline character
>   %   y = `{echo -n hello world}
>   % echo $#y
>   1
>   % echo $y(1)
>   hello world
> 
> You might want to use a comma instead:
> 
>   % ifs = ,
>   % z = `{echo -n hello world,good luck}
>   % echo $#z
>   2
>   % echo $z(1)
>   hello world
>   % echo $z(2)
>   good luck
> 
> Cheers,
>  Anthony
> 
> 



[9fans] rc scripts, how to get spaces in array elements generated by command output?

2019-01-05 Thread Mack Wallace
I apologize if this is not the correct forum for this question. However, since 
I am trying to write a script in Plan 9’s rc shell, this seemed to be the best 
place to go - as most scripting resources are based on bash, and I could not 
find the answer in the rc references I could find. - and I’m rather new to 
scripting in general as it is.

My question: Is there a way to take the string output of a command that 
contains spaces and make it a single element of an array in rc script?

For example:

If I declare an array and output its contents with the following script:

declared_array = (‘hello world’ ‘good luck’)
echo $declared_array(1) 
echo $declared_array(2)

I will get:

hello world
good luck
 

However, if I am receiving output from sed that contains spaces from the 
following script line

string_var = `{echo some_string | sed ’s/x/y/g’}

If the output was ‘hello world’, string_var would become a two element array 
which
echo $some_string(1) 
echo $some_string(2)

Would output 
hello
world


The long version of what I am trying to do. 

I am trying to take a .CSV spreadsheet and make each row into a separate text 
file with the column header followed by the data for however many columns there 
are. The script will also make an index file of all files generated. This is so 
I can use Russ Cox’s Slide+ script to view each file, make changes, notes - and 
eventually use another script to put all the files back together into a new 
.CSV.

I already have a sed script that obfuscates extra quotes and commas of each 
record and returns a long string that’s comma delimited


The first task of the script is to read headers (first line) and store them to 
be used for each file. I want to anticipate that there may be spaces in 
individual headings. 


Ideally, I’d like to do this in one shot, with each heading being an individual 
element of an array. I tried changing the comma delimiters to various types of 
quotes in the sed script to keep headers with spaces together, but without 
success. So, to move on, I obfuscated the spaces and changed the commas to 
spaces. This allows the header row to be broken up appropriately, but then I 
still have to reverse the obfuscation.

header = `{read $1 | sed ’s/^/,/; s/\\”/☹/g; s/,”([^”]*)”/,☺\1☻/g; s/,”/,☺/; 
:MC; s/☺([^☻]*),([^☻]*)/☺\1☯\2/g; tMC; s/^,//; s/ /♪/g; s/,/ /g’}
(I quickly typed the script line, so there may be mistakes - the characters 
used for obfuscation will probably be \x02 ..\x05, however, I’m using unicode 
characters here as they are easier to see and debug.)


I could run sed for each header every time I generate a file, but that seems 
quite redundant if I can just run sed for the header once and save the result 
in a manner that is easily accessible. 

This is my first foray into scripting, so I am not sure what is good practice 
and form. Any suggestions are appreciated.

Thanks and best regards.

Mack




Re: [9fans] rc scripts, how to get spaces in array elements generated by command output?

2019-01-05 Thread Anthony Martin
Mack Wallace  once said:
> My question: Is there a way to take the string output of a command that
> contains spaces and make it a single element of an array in rc script?
>
> [...]
> 
> However, if I am receiving output from sed that contains spaces from
> the following script line
> 
> string_var = `{echo some_string | sed ’s/x/y/g’}
> 
> If the output was ‘hello world’, string_var would become a two
> element array which
> echo $some_string(1) 
> echo $some_string(2)
> 
> Would output 
> hello
> world

You need to change the input field separator, $ifs.

The default value is any whitespace character:

% x = `{echo -n hello world}
% echo $#x
2
% echo $x(1)
hello
% echo $x(2)
world

Using only newline as the separator yields:

% ifs = '
' # this is a newline character
%   y = `{echo -n hello world}
% echo $#y
1
% echo $y(1)
hello world

You might want to use a comma instead:

% ifs = ,
% z = `{echo -n hello world,good luck}
% echo $#z
2
% echo $z(1)
hello world
% echo $z(2)
good luck

Cheers,
  Anthony



Re: [9fans] Raspberry Pi 3 B+ image of 9front

2019-01-05 Thread Raingloom
> build bootable hjfs sdcard image
>
> =
>
> cd /sys/lib/dist
> mk /tmp/mysdcard.pi.img

This last step fails with:

mk: don’t know how to make '/n/src9/sys/lib/sysconf g/proto/cmpdistproto’ in 
directory /sys/lib/dist




Re: [9fans] How does one read a file line by line in an rc script?

2019-01-05 Thread Mack Wallace
Thank you Steve.

But unfortunately...

That gives me “rc (testread): variable name not singleton!”

Trying the read with the -m option gets me the following errors repeated over 
and over until I escape out.
“awk i/o error occurred on /dev/stdin
 source line number 1
awk: i/o error occurred while closing /dev/stdin
 source line number 1" 

From the command line:

cat testdata | read

Gives me the first line of the file.

cat testdata | read -m

Puts all lines of the file to stdout.

There was a sample script at the bottom of 
http://doc.cat-v.org/plan_9/4th_edition/papers/rc 
 that I’ve copied below.

It creates its own read function. This is for getting text from stdin. But I’m 
not seeing how it works - or if it is a path to get where I want to go. I tried 
to copy that read function and put it at the top of my script and the 
“while(read line) syntax below my other work. When I ran the script it just 
waits for some input - after which, it runs trough my other lines, not 
responding to my input file as $1 is defined in the function, and then when it 
gets to the while, it prompts me again. I tried to cat into the awk ‘{print; 
exit}’ in the while structure - but that didn’t work either.


hmmm….

Mack




t=/tmp/holmdel$pid

fn read{
$1=‘{awk ’{print;exit}’}
}

ifs=’
’  # just a newline

fn sigexit sigint sigquit sighup{
rm -f $t
exit
}

cat <<’!’ >$t
Allentown 
...
Holmdel
...
West Long Branch
!

while(){
   lab=‘{fortune $t}
   echo $lab
   if(~ $lab Holmdel){
  echo You lose.
  exit
   }
   while(read lab; ! grep -i -s $lab $t) echo No such location.
   if(~ $lab [hH]olmdel){
  echo You win.
  exit
   }
}





> On Jan 5, 2019, at 5:45 PM, Steve Simon  wrote:
> 
> 
> try
> 
> cat $1 | while(line=`{read}){
> echo $line
> }
> 
> no doubt you cam do without the cat but i am unsure off hand where to put the 
> redirect in and i am not on plan9 just now.
> 
> -Steve
> 
> On 5 Jan 2019, at 10:34 pm, Mack Wallace  > wrote:
> 
>> Another, probably more stupid question - How does one read a text file line 
>> by line in an rc script.
>> 
>> In bash this works:
>> 
>> #!/bin/bash  
>> 
>> while read line  
>> do  
>> echo $line  
>> done < $1 
>> 
>> I’ve tried:
>> 
>> #!/bin/rc  
>> 
>> while (line=`{read $1})  
>> {
>> echo $line  
>> } 
>> 
>> Which produces the first line of the file in an infinite loop. I’ve tried 
>> the -m argument with no output.
>> 
>> 
>> It’s probably simple, but just can’t seem to find the equivalent.
>> 
>> Regards,
>> 
>> Mack
>> 
>> 
>> 



Re: [9fans] Raspberry Pi 3 B+ image of 9front

2019-01-05 Thread cinap_lenrek
oh yeah. sorry.

just do this before:

bind / /n/src9

i missed this because that step is implied by sys/lib/rootbind
that i use when building iso from a separate clean repository.

--
cinap



Re: [9fans] Raspberry Pi 3 B+ image of 9front

2019-01-05 Thread Raingloom
Thanks! I managed to boot it but ran into some problems with my USB keyboard, 
the screen is basically flooded with "read returned 0" errors, but the mouse 
works without problems, even if I plug it in late.
I'll take a proper screenshot of the log when I have more time.


Sent with ProtonMail Secure Email.

‐‐‐ Original Message ‐‐‐
On Sunday, January 6, 2019 12:37 AM,  wrote:

> oh yeah. sorry.
>
> just do this before:
>
> bind / /n/src9
>
> i missed this because that step is implied by sys/lib/rootbind
> that i use when building iso from a separate clean repository.
>
> -
>
> cinap





[9fans] How does one read a file line by line in an rc script?

2019-01-05 Thread Mack Wallace
Another, probably more stupid question - How does one read a text file line by 
line in an rc script.

In bash this works:

#!/bin/bash  

while read line  
do  
echo $line  
done < $1 

I’ve tried:

#!/bin/rc  

while (line=`{read $1})  
{
echo $line  
} 

Which produces the first line of the file in an infinite loop. I’ve tried the 
-m argument with no output.


It’s probably simple, but just can’t seem to find the equivalent.

Regards,

Mack





Re: [9fans] How does one read a file line by line in an rc script?

2019-01-05 Thread Steve Simon

try

cat $1 | while(line=`{read}){
echo $line
}

no doubt you cam do without the cat but i am unsure off hand where to put the 
redirect in and i am not on plan9 just now.

-Steve

> On 5 Jan 2019, at 10:34 pm, Mack Wallace  wrote:
> 
> Another, probably more stupid question - How does one read a text file line 
> by line in an rc script.
> 
> In bash this works:
> 
> #!/bin/bash  
> 
> while read line  
> do  
> echo $line  
> done < $1 
> 
> I’ve tried:
> 
> #!/bin/rc  
> 
> while (line=`{read $1})  
> {
> echo $line  
> } 
> 
> Which produces the first line of the file in an infinite loop. I’ve tried the 
> -m argument with no output.
> 
> 
> It’s probably simple, but just can’t seem to find the equivalent.
> 
> Regards,
> 
> Mack
> 
> 
> 


Re: [9fans] How does one read a file line by line in an rc script?

2019-01-05 Thread Mack Wallace
Thanks...


I'm running Bell Labs Plan 9 in Virtualbox. (I’m not sure how to get the 
version from the os or from rc)

I copied and pasted the snip directly into a script with only that in it - same 
error as before:“rc (testread): variable name not singleton!”

As for the second part - I will move that to the other thread. There are now 
some things I’m exploring there with the ifs variable, (which I thought the ifs 
variable was limited in plan 9 from what I read). 

Mack
 

> On Jan 5, 2019, at 6:46 PM, Steve Simon  wrote:
> 
> What are you running this on, is this byron's rc on unix?
> 
> I just tried the secript I posted, cut and pasted into a
> tiny shell scropt called testread, and it just worked™
> 
> maybe some other part of your script has a problem?
> 
> My script below
> -snip-snip-
> #!/bin/rc
> 
> cat $1 | while(line=`{read}){
> echo $line
> }
> 
> -snip-snip-
> 
> 
> Also, I didn't have the time to read all of your previous question,
> but I think what you are after is $"varname, this expands to the value
> of the variable but as a single argument, no matter if it, when
> it was assigned, had multiple, white space seperated words in it.
> 
> for example:  (NB: hugo% is my prompt)
> 
>   hugo% fred=(a b c d)
> 
>   hugo% echo $fred^-letter
>   a-letter b-letter c-letter d-letter
> 
>   hugo% echo $"fred^-letter
>   a b c d-letter
> 
> -Steve
> 
> 




Re: [9fans] How does one read a file line by line in an rc script?

2019-01-05 Thread Anthony Martin
Mack Wallace  once said:
> Another, probably more stupid question - How does one read a text file
> line by line in an rc script.

You should really read the rc(1) man page. It will answer your
questions.

Here the functions foo and bar are equivalent:

fn foo {
<$1 while(l = `{read}) echo $l
}

fn bar {
{ while(l = `{read}) echo $l } <$1
}

Think about why this one is not like the others:

fn baz {
while(l = `{read}){ echo $l } <$1
}

Cheers,
  Anthony