Skip to content

Instantly share code, notes, and snippets.

@m039
Created June 12, 2011 16:46
Show Gist options
  • Save m039/1021744 to your computer and use it in GitHub Desktop.
Save m039/1021744 to your computer and use it in GitHub Desktop.
Print a katakana table to the stdout in the utf8 format.
/* Author: m039 <flam44 (at) gmail (dot) com> */
#include <stdio.h>
/* Code point ranges */
#define MINUSCULE 0x000d8 /* 0 to 7F */
#define ALPHA 0x00251 /* 80 to 7FF */
#define KATAKANA_NI 0x030A0 /* 800 to FFFF */
#define CLEF 0x1D11E /* 10000 to 10FFFF */
typedef unsigned int character;
void utf8(character ch, char **string) {
char *src;
if (*string == NULL) {
return;
}
src = *string;
if (ch <= 0x7f) {
src[0] = ch;
*string += 1;
} else if (ch <= 0x0007ff) {
src[0] = 0xc0 | (ch >> 6) & 0x1f;
src[1] = 0x80 | (ch & 0x3f);
*string += 2;
} else if (ch <= 0x00ffff) {
src[0] = 0xe0 | (ch >> 12) & 0x0f;
src[1] = 0x80 | (ch >> 6) & 0x3f;
src[2] = 0x80 | (ch & 0x3f);
*string += 3;
} else if (ch <= 0x10ffff) {
src[0] = 0xf0 | (ch >> 18) & 0x07;
src[1] = 0x80 | (ch >> 12) & 0x3f;
src[2] = 0x80 | (ch >> 6) & 0x3f;
src[3] = 0x80 | (ch & 0x3f);
*string += 4;
}
}
static char g_buffer[512];
void fill_with_codes(char *buffer) {
char *p = buffer;
utf8(MINUSCULE, &p);
utf8(ALPHA, &p);
utf8(KATAKANA_NI, &p);
utf8(CLEF, &p);
*p++ = '\n';
*p++ = 0;
}
#define KATAKANA KATAKANA_NI
void fill_with_katakana(char *buffer) {
int i, j;
char *p = buffer;
for (i = 0; i < 0x10; i++) {
for (j = 0; j < 6; j++) {
utf8(KATAKANA + i + 0x10 * j, &p);
}
*p++ = '\n';
}
*p = 0;
}
void main() {
fill_with_katakana(g_buffer);
printf(g_buffer);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment