9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: Roman Shaposhnick <rvs@sun.com>
To: 9fans@cse.psu.edu
Subject: Re: [9fans] wiki editing via web browser
Date: Wed,  7 Apr 2004 00:25:14 -0700	[thread overview]
Message-ID: <20040407072514.GA7733@submarine> (raw)
In-Reply-To: <9c806dc17e198357b033c8ae81271a3d@plan9.bell-labs.com>

Wow! That's the spirit.

Thanks,
Roman.

On Tue, Apr 06, 2004 at 09:08:48AM -0400, Peter Bosch wrote:
> > 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 <u.h>
> #include <libc.h>
> #include <bio.h>
> #include <ctype.h>
> 
> 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);
> }
> 


  parent reply	other threads:[~2004-04-07  7:25 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-04-05 16:37 andrey mirtchovski
2004-04-05 16:41 ` andrey mirtchovski
2004-04-05 17:49   ` Russ Cox
2004-04-05 17:41     ` a
2004-04-05 18:00       ` andrey mirtchovski
2004-04-05 18:18         ` David Tolpin
2004-04-05 18:43           ` andrey mirtchovski
2004-04-05 19:11             ` George Michaelson
2004-04-05 19:21               ` Axel Belinfante
2004-04-05 19:29               ` Roman Shaposhnick
2004-04-05 20:48                 ` Wes Kussmaul
2004-04-05 23:00                   ` 9nut
2004-04-06  0:39                 ` boyd, rounin
2004-04-06  2:05                   ` Roman Shaposhnick
2004-04-06 13:08                     ` Peter Bosch
2004-04-06 23:53                       ` Bruce Ellis
2004-04-07  7:25                       ` Roman Shaposhnick [this message]
2004-04-06  0:35               ` boyd, rounin
2004-04-05 21:51           ` boyd, rounin
2004-04-06 16:58         ` ron minnich
2004-04-06 14:06           ` Noah Evans
2004-04-06 17:18             ` andrey mirtchovski
2004-04-06 18:47               ` Russ Cox
2004-04-07  1:08           ` Geoff Collyer
2004-04-07  1:12             ` boyd, rounin
2004-04-05 18:07       ` Russ Cox

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040407072514.GA7733@submarine \
    --to=rvs@sun.com \
    --cc=9fans@cse.psu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).