Thanks for the help erik!

This is the best I made for now...

/////////////////////////////////////
/////////////////////////////////////

#!/bin/rc

rm -f /tmp/$pid^'.'aispell*

args=()
spellflags=()
for(x){
        switch($x){
        case -d*
                spellflags=($spellflags $x)
        case -p*
                spellflags=($spellflags $x)
        case -T*
                spellflags=($spellflags $x)
        case *
                args = ($args $x)
        }
}

dir = /mnt/wsys
if(! test -f $dir/cons)
        dir = /mnt/term/$dir
id=`{cat $dir/new/ctl}
id=$id(1)

if(~ $#args 1 && ~ $args /*){
        adir = `{basename -d $args}
        args = `{basename $args}
        echo 'name '^$adir^/-spell > $dir/$id/ctl
        cd $adir
}
if not {
        echo 'name '^`{pwd}^/-spell > $dir/$id/ctl
}

{
        echo noscroll
        if(~ $#args 0){
                cat > /tmp/$pid^'.'aispell0
                i = /tmp/$pid^'.'aispell0
                winname = `{sed 's/ .*//g' < /mnt/acme/$winid/tag}
                if(~ $winname '') winname = nonamedwindow
                for(j in `{$home/local/bin/ispell -a $spellflags < $i | grep 
'^[&#]' | sed 's/ /_/g'}){
                        {cat $i; echo} | $home/local/bin/acme/spout | # spout 
needs \n
                        grep `{echo $j |
                        awk -F_ '{print $2}'} |
                        awk -F: '{OFS=":";$1 = "'$i'"; print}' >> 
/tmp/$pid^'.'aispell 
                } 
                sort -u /tmp/$pid^'.'aispell > $dir/$id/body
                rm -f /tmp/$pid^'.'aispell*
        }
        if not for(i in $args){
                for(j in `{ $home/local/bin/ispell -a $spellflags < $i | grep 
'^[&#]' | sed 's/ /_/g'}){
                {cat $i; echo} | $home/local/bin/acme/spout |
                grep `{echo $j | awk -F_ '{print $2}'} |
                awk -F: '{OFS=":";$1 = "'$i'"; print}'>> /tmp/$pid^'.'aispell
                }
                sort -u /tmp/$pid^'.'aispell > $dir/$id/body
                rm -f /tmp/$pid^'.'aispell
        }
        echo clean
}> $dir/$id/ctl


/////////////////////////////////////
/////////////////////////////////////

Is 
        grep '^[&#]' | sed 's/ /_/g' 

better than

        awk '/^[&#]/{gsub(/ /,"_"); print}'
?

I can use sed instead of awk in 
        awk -F: '{OFS=":";$1 = "'$i'"; print}'

but if the tag name contains the character used in sed as '/' it will
cause errors.  I discovered working in this script that acme has problems
with file names containing whitespaces (I only can open it at startup
and if you click in the tag strange things happens...) so a solution would
be:

sed 's ^[^:]*: '$winname': g'

> and i think further simplification is possible by using
> {} instead of the temporary file dance.

I don't have the knowledge to make a better redirection work with the
standard input sent to the script.  Specially with the output of the
statements inside the for loop.  The file funky dance was the only way I
found to make the work. 

> and i'd imagine that that's where the bug is.

The script works fine, 'aispell /some/file', 'aispell < /some/file' and
executing  '> aispell' in a acme's window with some text selected works as
expected.  But executing '> aispelles' in a acme's window, where aispelles
is a function:

        'fn aispelles {/aispell/path -despaƱol -Tutf8 
-p/personal/dictionary/path $*}' 

doesn't works.  But this function in win or outside acme works fine
('aispelles < /some/file' and 'aispelles /some/file'), so I
don't know what is the problem.

Also, I corrected a bug related with spout, it needs \n previous to EOF, so
the last line in a input without \n now doesn't stay out of the check.

I have looked in the acme scripts a lot and I can't find any example of
getting the dot address, only in c code.  If anyone knows how to make it
in rc, I will be very grateful.  I think with the feature of selecting a address
in the output of the script executed to any selected text in a window,
and pointing the cursor in the right position, the work will
be finish.

I'm learning a lot about Plan9, acme, rc, awk, sed ... perhaps I should have to 
wait
until I have the skills and knowledge about programming and Plan9 before
posting anything like this in the list, but I thought this could be useful
for someone.

Regards,
trebol.

Reply via email to