78 lines · 1.5 KB · C
RawDownload
#include <u.h>#include <libc.h>#include <ctype.h>#include <bio.h> /* See also /sys/src/cmd/aux/mklatinkbd.c */ /* Definition from /sys/src/9/port/latin1.c *//* * The code makes two assumptions: strlen(ld) is 1 or 2; latintab[i].ld can be a * prefix of latintab[j].ld only when j<i. */struct cvlist{	char	*ld;		/* must be seen before using this conversion */	char	*si;		/* options for last input characters */	Rune	*so;		/* the corresponding Rune for each si entry */} latintab[] = {#include "/sys/src/9/port/latin1.h"	0,	0,		0}; /* Do Javascript strings have the same escapes as C? */voidcprint(Biobuf *out, char *s){	for(; *s; ++s){		switch(*s){		case '\'':		case '\"':		case '\\':			Bprint(out, "\\%c", *s);			break;		case '\t':			Bprint(out, "\\t");			break;		default:			Bprint(out, "%c", *s);			break;		}	}} /* Assumes no dangerous characters in rune string. *//* XXX Large characters will break with Javascript's use of UTF-16! */ voidmain(int argc, char **argv){	struct cvlist *l;	Biobuf out;	char *name; 	if(Binit(&out, 1, OWRITE) == Beof)		exits("Binit"); 	if(argc >= 1)		name = argv[0];	else		name = "latin2js"; 	Bprint(&out, "/* Generated by %s. */\n", name);	Bprint(&out, "var Composetab = {\n"); 	for(l = latintab; l->ld; ++l){		Bprint(&out, "\t\"");		cprint(&out, l->ld);		Bprint(&out, "\": {from:\"");		cprint(&out, l->si);		Bprint(&out, "\", to:\"");		Bprint(&out, "%S", l->so);		Bprint(&out, "\"},\n");	} 	Bprint(&out, "};\n"); 	exits("");}