コード例 #1
0
ファイル: exception.c プロジェクト: pyer/forth
/*
 * show the error, along with info like the block, filename, line numer.
 */
static void show_error (const char* str)
{
    if (! str) str = "";
    int len = strlen(str);
    pf_outf ("\nError: %.*s ", len, str);
    show_word();
    pf_longjmp_abort ();
}
コード例 #2
0
int main(int argc,char *argv[],char *env[])
{
	pdict = dict_create();

	FILE *fp = fopen(FILE_NAME,"r");
	if(fp == NULL)
	{
		perror("fopen");
		return FAILED;
	}
	
	char english[1000];
	char chinese[1000];

	while(!feof(fp))
	{
		memset(english,0,sizeof(english));
		memset(chinese,0,sizeof(chinese));
		
		if(fgets(english,sizeof(english),fp) == NULL)
			break;
		*strchr(english,'\n') = 0;
		
		if(fgets(chinese,sizeof(chinese),fp) == NULL)
			break;
		*strchr(chinese,'\n') = 0;

		dict_insert(pdict,english,chinese);
	}

	signal(28,handle);

	show_window();
	move_xy(3,15);

	char key;
	while(1)
	{
		key = get_key();	
		switch(key)
		{
			case ESC:
				clear_screen();
				move_xy(1,1);
				return 0;
			case BACKSPACE:
				if(buf_i > 0)
				{
					move_left(1);
					putchar(' ');
					fflush(stdout);
					move_left(1);

					buf_i--;
					input_buf[buf_i] = 0;

					show_word(pdict,input_buf);
				}
				break;
			default:
			if(buf_i <= win_y - 20 && isprint(key))
			{
				putchar(key);
				fflush(stdout);

				input_buf[buf_i] = key;
				buf_i++;
				input_buf[buf_i] = 0;

				show_word(pdict,input_buf);
			}	
		}
	}

	return 0;
}