9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: Sape Mullender <sape@plan9.bell-labs.com>
To: 9fans@cse.psu.edu
Subject: Re: [9fans] conversion of charsets in upas/fs
Date: Tue,  1 Feb 2005 15:41:16 -0500	[thread overview]
Message-ID: <a911fbfff731b0a56b03c75d36097e47@plan9.bell-labs.com> (raw)
In-Reply-To: <5d1294dbc2ec360ffbcdcc8fd86e829f@voidness.de>

[-- Attachment #1: Type: text/plain, Size: 67 bytes --]

This might help to change you umlauts into real ones :-)

	Sape

[-- Attachment #2: utf2latin.c --]
[-- Type: text/plain, Size: 1858 bytes --]

#include <stdio.h>

FILE *f;

main(int argc, char ** argv)
{	int c, c1, c2;
	unsigned int r;
	char buf[8];

	if (argc > 2) {
		fprintf(stderr, "Usage: %s [ file ]\n", argv[0]);
		return;
	}
	if (argc == 2) {
		f = fopen(argv[1],"r");
		if (f == NULL) {
			fprintf(stderr, "Can't open %s\n", argv[1]);
			return;
		}
	} else {
		f = stdin;
	}
	while ((c = getc(f)) != EOF) {
		if (c < 0x80) putchar(c);
		else if ((c & 0xe0) == 0xc0) {
			/* two-char rune */
			c1 = c;
			r = (c & 0x1f) << 6;
			if ((c = getc(f)) == EOF) {
				fprintf(stderr, "EOF in rune\n");
				putchar(c1);
				break;
			}
			if ((c & 0xc0) != 0x80) {
				fprintf(stderr, "Bad rune %x, %x\n", r, c);
				putchar(c1);
				putchar(c);
				continue;
			}
			r = r | (c & 0x3f);
			if (r < 0x100) putchar(r);
			else {
				fprintf(stderr, "Rune too big %x\n", r);
				putchar(c1);
				putchar(c);
			}
		} else if ((c & 0xf0) == 0xe0) {
			/* three-char rune */
			r = (c & 0xf) << 12;
			c1 = c;
			if ((c = getc(f)) == EOF) {
				fprintf(stderr, "EOF in rune\n");
				putchar(c1);
				break;
			}
			if ((c & 0xc0) != 0x80) {
				fprintf(stderr, "Bad rune %x, %x\n", r, c);
				putchar(c1);
				putchar(c);
				continue;
			}
			c2 = c;
			r = r | ((c & 0x3f) << 6);
			if ((c = getc(f)) == EOF) {
				fprintf(stderr, "EOF in rune\n");
				putchar(c1);
				putchar(c2);
				break;
			}
			if ((c & 0xc0) != 0x80) {
				fprintf(stderr, "Bad rune %x, %x\n", r, c);
				putchar(c1);
				putchar(c2);
				putchar(c);
				continue;
			}
			r = r | (c & 0x3f);
			if (r < 0x100) putchar(r);
			else {
				fprintf(stderr, "Rune too big %x\n", r);
				putchar(c1);
				putchar(c2);
				putchar(c);
			}
		} else {
			fprintf(stderr, "Bad rune %x, %x\n", r, c);
			putchar(c);
		}
	}
	fflush(f);
	return;
}

[-- Attachment #3: latin2utf.c --]
[-- Type: text/plain, Size: 555 bytes --]

#include <stdio.h>

FILE *f;

main(int argc, char ** argv)
{	int c;
	unsigned int r;
	char buf[8];

	if (argc > 2) {
		fprintf(stderr, "Usage: %s [ file ]\n", argv[0]);
		return;
	}
	if (argc == 2) {
		f = fopen(argv[1],"r");
		if (f == NULL) {
			fprintf(stderr, "Can't open %s\n", argv[1]);
			return;
		}
	} else {
		f = stdin;
	}
	while ((c = getc(f)) != EOF) {
		if (c < 0x80) putchar(c);
		else {
			/* print a two-char rune */
			putchar(0xc0 | (c >> 6));
			putchar(0x80 | (c & 0x3f));
		}
	}
	fflush(f);
	return;
}

  reply	other threads:[~2005-02-01 20:41 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-01-29 13:57 Heiko Dudzus
2005-01-31  1:21 ` Kenji Okamoto
2005-01-31 14:05   ` Heiko Dudzus
2005-01-31 18:40     ` Russ Cox
2005-01-31 19:19       ` boyd, rounin
2005-02-01  8:24       ` Heiko Dudzus
2005-02-01 10:29         ` Heiko Dudzus
2005-02-01 17:11           ` Heiko Dudzus
2005-02-01 20:41             ` Sape Mullender [this message]
2005-02-01 20:45               ` boyd, rounin
2005-02-01 18:26           ` Russ Cox
2005-02-01 18:37             ` rog
2005-02-01 19:50               ` boyd, rounin
2005-02-02 10:59               ` Heiko Dudzus
2005-02-02 13:48                 ` Russ Cox
2005-02-02 23:41                   ` Heiko Dudzus
2005-02-01  1:42     ` Kenji Okamoto
2005-02-01  3:42       ` 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=a911fbfff731b0a56b03c75d36097e47@plan9.bell-labs.com \
    --to=sape@plan9.bell-labs.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).