<commit_before>/**
 * gen_keystroke.c
 *
 * Copyright (c) 2004, 2005
 *	libchewing Core Team. See ChangeLog for details.
 *
 * See the file "COPYING" for information on usage and redistribution
 * of this file.
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "chewing.h"

/* Only used by calculating char position */
#include "internal/chewing-utf8-util.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if defined HAVE_NCURSESW_CURSES_H
#  include <ncursesw/curses.h>
#elif defined HAVE_NCURSESW_H
#  include <ncursesw.h>
#elif defined HAVE_NCURSES_CURSES_H
#  include <ncurses/curses.h>
#elif defined HAVE_NCURSES_H
#  include <ncurses.h>
#elif defined HAVE_CURSES_H
#  include <curses.h>
#else
#  error "SysV or X/Open-compatible Curses header file required"
#endif
#include <locale.h>

/* Avoid incorrect KEY_ENTER definition */
#ifdef KEY_ENTER
#undef KEY_ENTER
#endif

/* Key list */
#define KEY_ENTER	'\n'
#define KEY_TAB		'\t'
#define KEY_ESC		(27)
#define KEY_CTRL_A	(1)
#define KEY_CTRL_(n)	(KEY_CTRL_A + (n) - 'A')
#define KEY_SPACE	' '

#define CTRL_0		KEY_F0
#define CTRL_1		KEY_F(1)
#define CTRL_2		KEY_F(2)
#define CTRL_3		KEY_F(3)
#define CTRL_4		KEY_F(4)
#define CTRL_5		KEY_F(5)
#define CTRL_6		KEY_F(6)
#define CTRL_7		KEY_F(7)
#define CTRL_8		KEY_F(8)
#define CTRL_9		KEY_F(9)

/* Spacing */
#define FILL_LINE  "--------------------------------------------------------"
#define FILL_BLANK "                                                               "

static int hasColor = 0;
static int selKey_define[ 11 ] = {'1','2','3','4','5','6','7','8','9','0',0}; /* Default */

void drawline( int x, int y )
{
	move( x, y );
	addstr( FILL_LINE );
}

void show_edit_buffer( int x, int y, ChewingContext *ctx )
{
	int i, cursor, count;
	char *buffer_string;
	char *p;
	move( x, y );
	addstr( FILL_BLANK );
	if ( ! chewing_buffer_Check( ctx ) ) {
		move( x, y );
		return;
	}
	buffer_string = chewing_buffer_String( ctx );
	mvaddstr( x, y, buffer_string );
	cursor = chewing_cursor_Current( ctx );
	p = buffer_string;
	count = 0;
	for ( i = 0 ;i < cursor; i++ ) {
		count += ueBytesFromChar(*p) <= 1 ? 1 : 2;
		p += ueBytesFromChar(*p);
	}
	move( x, count );
	free( buffer_string );
}

void show_interval_buffer( int x, int y, ChewingContext *ctx )
{
	char *buf;
	char *p;
	int buf_len;
	char out_buf[ 100 ];
	int i, count;
	int arrPos[ 50 ];
	IntervalType it;

	move( x, y );
	addstr( FILL_BLANK );
	move( x, y );

	/* Check if buffer is available. */
	if ( ! chewing_buffer_Check( ctx ) ) {
		return;
	}

	buf = chewing_buffer_String( ctx );
	buf_len = chewing_buffer_Len( ctx );

	p = buf;
	count = 0;
	for ( i = 0 ;i < buf_len; i++ ) {
		arrPos[ i ] = count;
		count += ueBytesFromChar(*p) <= 1 ? 1 : 2;
		p += ueBytesFromChar(*p);
	}
	arrPos[ i ] = count;

	memset( out_buf, ' ', count * ( sizeof( char ) ) );
	out_buf[ count ] = '\0';

	chewing_interval_Enumerate( ctx );
	while ( chewing_interval_hasNext( ctx ) ) {
		chewing_interval_Get( ctx, &it );
		out_buf[ arrPos[ it.from ] ] = '[';
		out_buf[ arrPos[ it.to ] - 1 ] =  ']';
		memset(
			&out_buf[ arrPos[ it.from ] + 1 ], '-',
			arrPos[ it.to ] - arrPos[ it.from ] - 2 );
	}
	addstr( out_buf );
}

void showZuin( ChewingContext *ctx )
{
	int zuin_count;
	char *zuin_string;
	if ( chewing_get_ChiEngMode( ctx ) )
		addstr( "[中]" );
	else
		addstr( "[英]" );
	addstr( "        " );
	zuin_string = chewing_zuin_String( ctx, &zuin_count );
	addstr( zuin_string );
	free( zuin_string );
}

void show_zuin_buffer( int x, int y, ChewingContext *ctx )
{
	move( x, y );
	addstr( FILL_BLANK );
	move( x, y );
	if ( hasColor )
		attron( COLOR_PAIR( 1 ) );
	showZuin( ctx );
	if ( hasColor )
		attroff( COLOR_PAIR( 1 ) );
}

void show_full_shape( int x, int y, ChewingContext *ctx )
{
	move( x, y );
	addstr( "[" );
	if ( hasColor )
		attron( COLOR_PAIR( 2 ) );
	if ( chewing_get_ShapeMode( ctx ) == FULLSHAPE_MODE )
		addstr( "全形" );
	else
		addstr( "半形" );
	if ( hasColor )
		attroff( COLOR_PAIR( 2 ) );
	addstr( "]" );
}

void show_userphrase( int x, int y, ChewingContext *ctx )
{
	char *aux_string;
	if ( chewing_aux_Length( ctx ) == 0 )
		return;

	move( x, y );
	addstr( FILL_BLANK );
	move( x, y );
	if ( hasColor )
		attron( COLOR_PAIR( 2 ) );
	aux_string = chewing_aux_String( ctx );
	addstr( aux_string );
	free( aux_string );
	if ( hasColor )
		attroff( COLOR_PAIR( 2 ) );
}

void show_choose_buffer( int x, int y, ChewingContext *ctx )
{
	int i = 1;
	int currentPageNo;
	char str[ 20 ];
	char *cand_string;
	move( x, y );
	addstr( FILL_BLANK );
	move( x, y );
	
	if ( chewing_cand_TotalPage( ctx ) == 0 )
		return;
	
	chewing_cand_Enumerate( ctx );
	while ( chewing_cand_hasNext( ctx ) ) {
		if ( i > chewing_cand_ChoicePerPage( ctx ) )
			break;
		sprintf( str, "%d.", i );
		if ( hasColor )
			attron( COLOR_PAIR( 3 ) );
		addstr( str );
		if ( hasColor )
			attroff( COLOR_PAIR( 3 ) );
		cand_string = chewing_cand_String( ctx );
		sprintf( str, " %s ", cand_string );
		addstr( str );
		free( cand_string );
		i++;
	}
	currentPageNo = chewing_cand_CurrentPage( ctx );
	if ( chewing_cand_TotalPage( ctx ) != 1 ) {
		if ( currentPageNo == 0 )
			addstr( "  >" );
		else if ( currentPageNo == ( chewing_cand_TotalPage( ctx ) - 1 ) )
			addstr( "<  " );
		else
			addstr( "< >" );
	}
}

void show_commit_string( int x, int y, ChewingContext *ctx )
{
	char *commit_string;
#if 0
	if ( pgo->keystrokeRtn & KEYSTROKE_COMMIT ) {
		for ( i = 0; i < pgo->nCommitStr; i++ ) {
			mvaddstr( x, y, (const char *) pgo->commitStr[ i ].s );
			y = ( y >= 54 ) ?
				0 : 
				( y + strlen( (const char *) pgo->commitStr[ i ].s ) - 3 < 0 ? y + 1 : y + 2 );
			x = ( y == 0 ) ? ( x + 1 ) : x;
		}
	}
#endif
	if ( chewing_commit_Check( ctx ) ) {
		commit_string = chewing_commit_String( ctx );
		mvaddstr( x, y, FILL_BLANK);
		mvaddstr( x, y, commit_string );
		free( commit_string );
	}
}

int main( int argc, char *argv[] )
{
	ChewingContext *ctx;
	FILE *fout;
	char *prefix = CHEWING_DATA_PREFIX;
	int ch;
	int add_phrase_length;

	if ( argc < 2 ) {<commit_msg>Remove trailing white spaces<commit_after>/**
 * gen_keystroke.c
 *
 * Copyright (c) 2004, 2005
 *	libchewing Core Team. See ChangeLog for details.
 *
 * See the file "COPYING" for information on usage and redistribution
 * of this file.
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "chewing.h"

/* Only used by calculating char position */
#include "internal/chewing-utf8-util.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if defined HAVE_NCURSESW_CURSES_H
#  include <ncursesw/curses.h>
#elif defined HAVE_NCURSESW_H
#  include <ncursesw.h>
#elif defined HAVE_NCURSES_CURSES_H
#  include <ncurses/curses.h>
#elif defined HAVE_NCURSES_H
#  include <ncurses.h>
#elif defined HAVE_CURSES_H
#  include <curses.h>
#else
#  error "SysV or X/Open-compatible Curses header file required"
#endif
#include <locale.h>

/* Avoid incorrect KEY_ENTER definition */
#ifdef KEY_ENTER
#undef KEY_ENTER
#endif

/* Key list */
#define KEY_ENTER	'\n'
#define KEY_TAB		'\t'
#define KEY_ESC		(27)
#define KEY_CTRL_A	(1)
#define KEY_CTRL_(n)	(KEY_CTRL_A + (n) - 'A')
#define KEY_SPACE	' '

#define CTRL_0		KEY_F0
#define CTRL_1		KEY_F(1)
#define CTRL_2		KEY_F(2)
#define CTRL_3		KEY_F(3)
#define CTRL_4		KEY_F(4)
#define CTRL_5		KEY_F(5)
#define CTRL_6		KEY_F(6)
#define CTRL_7		KEY_F(7)
#define CTRL_8		KEY_F(8)
#define CTRL_9		KEY_F(9)

/* Spacing */
#define FILL_LINE  "--------------------------------------------------------"
#define FILL_BLANK "                                                               "

static int hasColor = 0;
static int selKey_define[ 11 ] = {'1','2','3','4','5','6','7','8','9','0',0}; /* Default */

void drawline( int x, int y )
{
	move( x, y );
	addstr( FILL_LINE );
}

void show_edit_buffer( int x, int y, ChewingContext *ctx )
{
	int i, cursor, count;
	char *buffer_string;
	char *p;
	move( x, y );
	addstr( FILL_BLANK );
	if ( ! chewing_buffer_Check( ctx ) ) {
		move( x, y );
		return;
	}
	buffer_string = chewing_buffer_String( ctx );
	mvaddstr( x, y, buffer_string );
	cursor = chewing_cursor_Current( ctx );
	p = buffer_string;
	count = 0;
	for ( i = 0 ;i < cursor; i++ ) {
		count += ueBytesFromChar(*p) <= 1 ? 1 : 2;
		p += ueBytesFromChar(*p);
	}
	move( x, count );
	free( buffer_string );
}

void show_interval_buffer( int x, int y, ChewingContext *ctx )
{
	char *buf;
	char *p;
	int buf_len;
	char out_buf[ 100 ];
	int i, count;
	int arrPos[ 50 ];
	IntervalType it;

	move( x, y );
	addstr( FILL_BLANK );
	move( x, y );

	/* Check if buffer is available. */
	if ( ! chewing_buffer_Check( ctx ) ) {
		return;
	}

	buf = chewing_buffer_String( ctx );
	buf_len = chewing_buffer_Len( ctx );

	p = buf;
	count = 0;
	for ( i = 0 ;i < buf_len; i++ ) {
		arrPos[ i ] = count;
		count += ueBytesFromChar(*p) <= 1 ? 1 : 2;
		p += ueBytesFromChar(*p);
	}
	arrPos[ i ] = count;

	memset( out_buf, ' ', count * ( sizeof( char ) ) );
	out_buf[ count ] = '\0';

	chewing_interval_Enumerate( ctx );
	while ( chewing_interval_hasNext( ctx ) ) {
		chewing_interval_Get( ctx, &it );
		out_buf[ arrPos[ it.from ] ] = '[';
		out_buf[ arrPos[ it.to ] - 1 ] =  ']';
		memset(
			&out_buf[ arrPos[ it.from ] + 1 ], '-',
			arrPos[ it.to ] - arrPos[ it.from ] - 2 );
	}
	addstr( out_buf );
}

void showZuin( ChewingContext *ctx )
{
	int zuin_count;
	char *zuin_string;
	if ( chewing_get_ChiEngMode( ctx ) )
		addstr( "[中]" );
	else
		addstr( "[英]" );
	addstr( "        " );
	zuin_string = chewing_zuin_String( ctx, &zuin_count );
	addstr( zuin_string );
	free( zuin_string );
}

void show_zuin_buffer( int x, int y, ChewingContext *ctx )
{
	move( x, y );
	addstr( FILL_BLANK );
	move( x, y );
	if ( hasColor )
		attron( COLOR_PAIR( 1 ) );
	showZuin( ctx );
	if ( hasColor )
		attroff( COLOR_PAIR( 1 ) );
}

void show_full_shape( int x, int y, ChewingContext *ctx )
{
	move( x, y );
	addstr( "[" );
	if ( hasColor )
		attron( COLOR_PAIR( 2 ) );
	if ( chewing_get_ShapeMode( ctx ) == FULLSHAPE_MODE )
		addstr( "全形" );
	else
		addstr( "半形" );
	if ( hasColor )
		attroff( COLOR_PAIR( 2 ) );
	addstr( "]" );
}

void show_userphrase( int x, int y, ChewingContext *ctx )
{
	char *aux_string;
	if ( chewing_aux_Length( ctx ) == 0 )
		return;

	move( x, y );
	addstr( FILL_BLANK );
	move( x, y );
	if ( hasColor )
		attron( COLOR_PAIR( 2 ) );
	aux_string = chewing_aux_String( ctx );
	addstr( aux_string );
	free( aux_string );
	if ( hasColor )
		attroff( COLOR_PAIR( 2 ) );
}

void show_choose_buffer( int x, int y, ChewingContext *ctx )
{
	int i = 1;
	int currentPageNo;
	char str[ 20 ];
	char *cand_string;
	move( x, y );
	addstr( FILL_BLANK );
	move( x, y );

	if ( chewing_cand_TotalPage( ctx ) == 0 )
		return;

	chewing_cand_Enumerate( ctx );
	while ( chewing_cand_hasNext( ctx ) ) {
		if ( i > chewing_cand_ChoicePerPage( ctx ) )
			break;
		sprintf( str, "%d.", i );
		if ( hasColor )
			attron( COLOR_PAIR( 3 ) );
		addstr( str );
		if ( hasColor )
			attroff( COLOR_PAIR( 3 ) );
		cand_string = chewing_cand_String( ctx );
		sprintf( str, " %s ", cand_string );
		addstr( str );
		free( cand_string );
		i++;
	}
	currentPageNo = chewing_cand_CurrentPage( ctx );
	if ( chewing_cand_TotalPage( ctx ) != 1 ) {
		if ( currentPageNo == 0 )
			addstr( "  >" );
		else if ( currentPageNo == ( chewing_cand_TotalPage( ctx ) - 1 ) )
			addstr( "<  " );
		else
			addstr( "< >" );
	}
}

void show_commit_string( int x, int y, ChewingContext *ctx )
{
	char *commit_string;
#if 0
	if ( pgo->keystrokeRtn & KEYSTROKE_COMMIT ) {
		for ( i = 0; i < pgo->nCommitStr; i++ ) {
			mvaddstr( x, y, (const char *) pgo->commitStr[ i ].s );
			y = ( y >= 54 ) ?
				0 :
				( y + strlen( (const char *) pgo->commitStr[ i ].s ) - 3 < 0 ? y + 1 : y + 2 );
			x = ( y == 0 ) ? ( x + 1 ) : x;
		}
	}
#endif
	if ( chewing_commit_Check( ctx ) ) {
		commit_string = chewing_commit_String( ctx );
		mvaddstr( x, y, FILL_BLANK);
		mvaddstr( x, y, commit_string );
		free( commit_string );
	}
}

int main( int argc, char *argv[] )
{
	ChewingContext *ctx;
	FILE *fout;
	char *prefix = CHEWING_DATA_PREFIX;
	int ch;
	int add_phrase_length;

	if ( argc < 2 ) {
{'fraction_non_alphanumeric': 0.1618811881188119, 'fraction_numerical': 0.015346534653465346, 'mean_word_length': 3.1695906432748537, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2841688', 'n_tokens_mistral': 5367, 'n_tokens_neox': 5022, 'n_words': 1281}