9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: Russ Cox <rsc@swtch.com>
To: Fans of the OS Plan 9 from Bell Labs <9fans@cse.psu.edu>
Subject: Re: [9fans] tcs bug.
Date: Wed, 31 Aug 2005 17:36:14 -0400	[thread overview]
Message-ID: <ee9e417a050831143661c4f847@mail.gmail.com> (raw)
In-Reply-To: <W841833196585841125485492@webmail2>

You've invented buffered I/O.

#include <u.h>
#include <libc.h>
#include <bio.h>

void
usage(void)
{
	fprint(2, "usage: runecvt [-l | -t | -u] [file...]\n");
	exits("usage");
}

void
convert(Biobuf *bin, Biobuf *bout, Rune (*fn)(Rune))
{
	int c;
	
	while((c = Bgetrune(bin)) != -1)
		Bputrune(bout, fn(c));
}

void
main(int argc, char **argv)
{
	int i;
	Biobuf *b, bin, bout;
	Rune (*fn)(Rune);
	
	fn = toupperrune;
	ARGBEGIN{
	case 'l':
		fn = tolowerrune;
		break;
	case 't':
		fn = totitlerune;
		break;
	case 'u':
		fn = toupperrune;
		break;
	default:
		usage();
	}ARGEND
	
	Binit(&bout, 1, OWRITE);
	if(argc == 0){
		Binit(&bin, 0, OREAD);
		convert(&bin, &bout, fn);
	}else{
		for(i=0; i<argc; i++){
			if((b = Bopen(argv[i], OREAD)) == nil)
				sysfatal("open %s: %r", argv[i]);
			convert(b, &bout, fn);
		}
	}
	Bterm(&bout);
	exits(nil);
}


  reply	other threads:[~2005-08-31 21:36 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-08-31 10:51 quanstro
2005-08-31 21:36 ` Russ Cox [this message]
  -- strict thread matches above, loose matches on Subject: below --
2005-09-01  0:36 quanstro
2005-08-31  6:07 arisawa
2005-08-31  9:11 ` arisawa
2005-08-31  9:17   ` Rob Pike
2005-08-31 10:48     ` arisawa
2005-08-31 11:22       ` arisawa
2005-08-29 23:23 [9fans] some Plan9 related ideas Bhanu Nagendra Pisupati
2005-08-30 17:07 ` [9fans] " Dave Eckhardt
2005-08-30 17:33   ` Francisco Ballesteros
2005-08-30 17:46     ` Russ Cox
2005-08-31  5:54       ` [9fans] tcs bug arisawa
2005-08-31  5:57         ` Rob Pike

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=ee9e417a050831143661c4f847@mail.gmail.com \
    --to=rsc@swtch.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).