From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <9c806dc17e198357b033c8ae81271a3d@plan9.bell-labs.com> To: 9fans@cse.psu.edu Subject: Re: [9fans] wiki editing via web browser From: Peter Bosch In-Reply-To: <20040406020524.GA29916@submarine> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Date: Tue, 6 Apr 2004 09:08:48 -0400 Topicbox-Message-UUID: 5247fcb6-eacd-11e9-9e20-41e7f4b1d025 > On Tue, Apr 06, 2004 at 02:39:44AM +0200, boyd, rounin wrote: >> > P.S. Back in my childhood I though that Russian military tongue was >> > practically Morse code ... >> >> -.-. --.- > > .-- - ..-. ..--.. #include #include #include #include static char*asciitab[] = { ".-", // A "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--..", // Z }; static char*numtab[] = { "-----", // 0 ".----", "..---", "...--", "....-", ".....", "-....", "--...", "---..", "----.", }; static struct { char c; char *m; } specials[] = { { '.', ".-.-.-" }, { ',', "--..--" }, { '?', "..--.." }, { '@', ".--.-." }, { ' ', " " }, }; int morsefmt(Fmt *f) { char *p, *src, *dst, c; int rv, len, i; src = va_arg(f->args, char*); len = strlen(src); p = dst = malloc(len * 6 + 1); if(dst == nil) return fmtstrcpy(f, "(romanfmt)"); while(c = *src++){ if(c == '\n') continue; if(isalpha(c)){ c = toupper(c); assert(c >= 'A' && c <= 'Z'); c -= 'A'; len = strlen(asciitab[c]); memcpy(p, asciitab[c], len); p += len; continue; } if(isdigit(c)){ assert(c >= '0' && c <= '9'); c -= '0'; len = strlen(numtab[c]); memcpy(p, numtab[c], len); p += len; continue; } for(i = 0; i < nelem(specials); i++) if(specials[i].c == c) break; if(i == nelem(specials)){ *p++ = '?'; continue; } len = strlen(specials[i].m); memcpy(p, specials[i].m, len); p += len; } *p = 0; rv = fmtstrcpy(f, dst); free(dst); return rv; } void main(void) { Biobuf b; char *p; Binit(&b, 0, OREAD); fmtinstall('M', morsefmt); while((p = Brdline(&b, '\n')) != nil){ p[Blinelen(&b)] = 0; print("[%s] %M\n", p, p); } Bterm(&b); exits(0); }