From mboxrd@z Thu Jan 1 00:00:00 1970 Date: Sun, 15 Dec 2013 11:55:54 +0000 From: trebol To: 9fans@9fans.net Message-ID: <52ad98ca.fWxfWqxL4mycUn65%trebol55555@aol.com> User-Agent: Heirloom mailx 12.5 6/20/10 MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Subject: [9fans] Spell checking with acme in p9p Topicbox-Message-UUID: 9a22a9f4-ead8-11e9-9d60-3106f5b1d025 When recently I discovered Plan9, the first things I missed were a non-only-English spell checker, support for other languages in troff (mostly hyphenation), and other dictionaries for dict. I've ported "international ispell" to ape and write aispell, a modified version of aspell script that work with ispell, I've formatted GCIDE, "Chambers's Twentieth Century Dictionary", "Diccionario de la Real Academia de la Lengua Espa=F1ola", "Moby Thesaursus" and "OpenThesaurus-es", and I was hopping working in troff when I'll learn programming. The lack of a web browser capable of deal with today's madness and the portability limitation of ape (at least for a ignorant like me) forcesme to deal with other OS I have to install and maintaining, so the simplicity and cleanness I like so much of plan9 become useless. Thanks to Russ Cox for= P9P! =20 I've write a script for p9p too, you only need to install gnu aspell (or other spell checker with "ispell -a" support) and compile a slightly modified spout.c with rune support (I've called it uspout), so y= ou can use the script like native acme's aspell script. This is from my README.= PLAN9 file: [...] In the acme directory are aispell, an equivalent script of aspell and uspout.c, slighted modified spout.c for UTF-8 runes, needed by aispell to support non English languages. You can pass ispell options as arguments to aispell, for example for use the Spanish dictionary you can = put in the tag: >aispell -despa=F1ol -Tutf8=20 Or put 'aispell -despa=F1ol -Tutf8 $*' in a script and call it aispelles, for example. Defining a function in lib/profile didn't work for me... You can use it in any text selected, but for now, if it doesn't start at the beginning of the buffer, the output's addresses will be wrong. This package install American and British dictionaries. If you are interested, look at the Spanish_ispell package = I've ported from http://www.datsi.fi.upm.es/~coes. [...] In P9P you don't need "-Tutf8". I was going to ask for a directory in sources, but I haven't see any interest in those things in the list. I h= ope=20 that this will help you. The script and spout's source are small, so I'm going to paste both here. trebol. #!/usr/local/plan9/bin/rc # Don't forget to check the path! # aispell_p9p rm -f /tmp/$pid^'.'aispell spellpgr=3Daspell args=3D() spellflags=3D() for(x){ switch($x){ case -d* spellflags=3D($spellflags $x) case -p* spellflags=3D($spellflags $x) case -T* spellflags=3D($spellflags $x) case * args=3D($args $x) } } id=3D`{9p read acme/new/ctl} id=3D$id(1) echo 'name '^`{pwd}^/-spell | 9p write acme/$id/ctl { if(~ $#args 0){ cat > /tmp/$pid^'.'aispell args=3D/tmp/$pid^'.'aispell pipe=3D1 } for(i in $args){ name=3D$i if(~ $pipe 1){ name=3D`{9p read acme/$winid/tag | 9 sed 's/ .*//g'} if(~ name '') name=3Dnonamedwindow } for(j in `{{cat $i; echo} | uspout | 9 sort -t: -u +2 | 9 sed 's/$/\!/g= ' | $spellpgr -a $spellflags | 9 grep '^[&#]' | 9 sed 's/ /_/g'}){ # {cat $i; echo} is for uspout, needs \n. Also I want to make a list of= lines, so j can't have spaces=20 miss=3D`{ echo $j | awk -F_ '{print $2}'} sug=3D`{ echo $j | 9 sed 's/^.*://g'} # Can't put 9 grep -v '^#' here.= .. {cat $i; echo} | uspout | 9 grep '.*:'$miss'$' | 9 sed 's/$/ '$sug'/g' | # If I put 9 grep -v '^#' above, this 9 sed cu= ts output, I don't know why ... 9 sed 's/#_.*$//g' | 9 sed 's/_/ /g' | # If I put 9 sed 's/_/ /g' above, variables don't w= ork in 9 sed. Again, I don't know why... 9 sed s',^,'$name',g' | 9p write acme/$id/body } } rm -f /tmp/$pid^'.'aispell echo clean | 9p write acme/$id/ctl } ------------------------ ------------------------ uspout.c's source: #include #include #include #include void spout(int, char*); Biobuf bout; void main(int argc, char *argv[]) { int i, fd; Binit(&bout, 1, OWRITE); if(argc =3D=3D 1) spout(0, ""); else for(i=3D1; i' '; c++){ n++; s++; } inword =3D 0; w =3D s; t =3D s; do{ c =3D *(uchar*)t; if(c < Runeself) wid =3D 1; else{ wid =3D chartorune(&r, t); c =3D r; } wordchar =3D 0; if(isalpharune(c)) wordchar =3D 1; if(inword && !wordchar){ if(c=3D=3D'\'' && isalpha(t[1])) goto Continue; m =3D t-w; if(m > 1){ memmove(buf, w, m); buf[m] =3D 0; Bprint(&bout, "%s:#%d,#%d:%s\n", name, wn, n, buf); } inword =3D 0; }else if(!inword && wordchar){ wn =3D n; w =3D t; inword =3D 1; } if(c=3D=3D'\\' && (isalpha(t[1]) || t[1]=3D=3D'(')){ switch(t[1]){ case '(': m =3D 4; break; case 'f': if(t[2] =3D=3D '(') m =3D 5; else m =3D 3; break; case 's': if(t[2] =3D=3D '+' || t[2]=3D=3D'-'){ if(t[3] =3D=3D '(') m =3D 6; else m =3D 4; }else{ if(t[2] =3D=3D '(') m =3D 5; else if(t[2]=3D=3D'1' || t[2]=3D=3D'2' || t[2]=3D=3D'3') m =3D 4; else m =3D 3; } break; default: m =3D 2; } while(m-- > 0){ if(*t =3D=3D '\n') break; n++; t++; } continue; } Continue: n++; t +=3D wid; }while(c !=3D '\n'); } Bterm(&b); }