/*
 * Paraselene
 * Copyright (c) 2009  Akira Terasaki
 * このファイルは同梱されている License.txt に定めた条件に同意できる場合にのみ
 * 利用可能です。
 */
import java.io.*;
import java.util.*;


public class CharMake {
	private static ArrayList<String[]>	list = new ArrayList<String[]>();

	private static void echo( BufferedWriter w, String[] tgt ) throws Exception {
		w.write( "\t/**\n" );
		w.write( "\t * " );
		w.write( tgt[0] );
		w.write( " " );
		w.write( tgt[3] );
		w.write( "\n\t */\n\t_" );
		w.write( tgt[0].substring( 1, tgt[0].length() - 1 ) );
		w.write( "( '\\u" );
		int	len = 4 - tgt[2].length();
		for ( int i = 0; i < len; i++ )	w.write( "0" );
		w.write( tgt[2] );
		w.write( "', \"" );
		w.write( tgt[0] );
		w.write( "\" )" );
	}

	private static void echo( BufferedWriter w ) throws Exception {
		int	cnt = list.size();
		for ( int i = 0; i < cnt; i++ ) {
			echo( w, list.get( i ) );
			if ( i == (cnt - 1) ) {
				w.write( ";\n" );
			}
			else {
				w.write( ",\n" );
			}
		}
	}

	public static void main( String[] argv ) throws Exception {
		BufferedReader	br = new BufferedReader(
			new InputStreamReader(
				new FileInputStream( "../template/char.txt" )
			)
		);
		while( true ) {
			String	line = br.readLine();
			if ( line == null )	break;
			String[]	l = line.split( "\t" );
			list.add( l );
		}
		br.close();

		br = new BufferedReader(
			new InputStreamReader(
				new FileInputStream( "../template/WebChar.java" )
			)
		);
		BufferedWriter	bw = new BufferedWriter(
			new OutputStreamWriter(
				new FileOutputStream( "../paraselene/WebChar.java" )
			)
		);
		while( true ) {
			String	line = br.readLine();
			if ( line == null )	break;
			if ( "#".equals( line ) ) {
				echo( bw );
				bw.write(
					String.format(
						"\tprivate static final long serialVersionUID = %dL;\n",
						new Date().getTime()
					)
				);
				continue;
			}
			bw.write( line );
			bw.write( "\n" );
		}
		bw.close();
		br.close();
	}
}

