Beispiel #1
0
/***************************************
 *単語を追加する
 ***************************************/
void add_word(char *word)
{
    Word *pos;
    Word *prev; /*posの後ろを1つ遅れてついていくポインタ*/
    Word *new_word;
    int  result;

    prev = NULL;
    for(pos = word_header; pos != NULL; pos = pos->next) {
        result = strcmp(pos->name, word);
        if(result => 0)
            break;

        prev = pos;
    }
    if(word_header != NULL && result == 0) {
        /*同一の単語が見つかった*/
pos->count++:
    } else {
        new_word = create_word(word);
        if(prev == NULL) {
            /* 冒頭に挿入 */
            new_word->next = word_header;
            word_header = new_word;
        } else {
            new_word->next = pos;
            prev->next = new_word;
        }
    }
}
Beispiel #2
0
//load words into an avl tree
TREE_NODE * index_file(char *file_name){
  FILE *file;
  file = fopen(file_name,"r");
  if(!file){
    printf("arquivo de entrada invalido\n");
    return NULL;
  }

  wchar_t line [ 10000 ];
  wchar_t *token;
  wchar_t *state;
  const wchar_t delimiters[] = L" \n,.;'\"?-|:*&!@$%{}()[]<>\\";//only consider letters
  int current_line = 1;
  TREE_NODE *tree = NULL;
  W_TOKEN *w_token = NULL;

  while ( fgetws ( line, sizeof(line), file ) ){//read line by line
    for (token = wcstok(line, delimiters, &state);
           token != NULL;
           token = wcstok(NULL, delimiters, &state)) {
      if(token) w_token = create_word(token);
      insert_avl(&tree, (void *)w_token, lex_order, current_line);
      }
    current_line++;
  }

  fclose ( file );
  return tree;
}
Beispiel #3
0
void doprim(cell *up)
{
	create_word((token_t)next_prim, up);
    tokstore(T(LASTP), (xt_t)V(TORIGIN) + next_prim);
//  tokstore(T(LASTP), XT_FROM_CT(next_prim*sizeof(token_t)));  // For &data[] version
//  tokstore(T(LASTP), XT_FROM_CT(next_prim)));  // For &tokens[] version

//	tokstore(CT_FROM_XT(V(DP) - sizeof(token_t)), &tokens[next_prim]);
	next_prim++;
}
Beispiel #4
0
/******************************************************************
函数:WinProc ()
功能:处理主窗口消息
*******************************************************************/
LRESULT CALLBACK WinProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	HDC         hdc;
	PAINTSTRUCT ps;
	RECT        rect;
	TCHAR		aChar ,scoreString[20];

	switch (message)
	{
	case WM_CREATE:         // 创建消息
		if (gbInGame == TRUE)
		{
			create_word();
		}
		return 0;
	case WM_KEYDOWN:         // 击键消息
		switch (wParam)
		{
			if (gbInGame == FALSE)
			{
				case VK_RETURN:
					gbInGame = TRUE;
					break;
			}
		case VK_ESCAPE:
			MessageBox (hWnd, TEXT ("退出游戏!"), TEXT ("ESC"), MB_OK);
			PostQuitMessage(0);
			break;
		}
		return 0;

	case WM_CHAR:
		if (gbInGame == TRUE)
		{
			aChar = wParam;
			if (getChar[0] == 0)
			{
				if (LOWORD(wParam) == VK_RETURN)// 每一轮字符串打完后要按回车才继续进行游戏
				{
					create_word();
				}
			}
			goal(getChar, aChar);
			InvalidateRect(hWnd, NULL, TRUE);
		}
		return 0;

		case WM_PAINT:              // 客户区重绘消息
		// 取得设备环境句柄
		hdc = BeginPaint (hWnd, &ps); 
		// 取得窗口客户区矩形
		GetClientRect (hWnd, &rect);
		if (gbInGame == FALSE)
		{
			// 输出文字
			DrawText (hdc, TEXT("按 ENTER(回车) 键开始游戏"),
				-1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
			rect.top = rect.bottom - 150;
		} 
		else
		{
			// 输出文字
			DrawText (hdc, getChar,
				-1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
			rect.top = rect.bottom - 150;
			// The wsprintf function formats and stores a series of characters 
			// and values in a buffer. 
			wsprintf(scoreString, TEXT("得分:%d"), score);
			DrawText (hdc, scoreString,
				-1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER);

			if (getChar[0] == 0){
				rect.top = rect.bottom - 200;
				DrawText(hdc, TEXT("按 ENTER(回车) 键继续"),
					-1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
			}
			// 释放资源
			EndPaint (hWnd, &ps);
		}
		return 0;

	case WM_DESTROY:
		PostQuitMessage(0);
		return 0;

	}

	// 调用缺省消息处理过程
	return DefWindowProc (hWnd, message, wParam, lParam);

} // 函数 WinProc 结束
Beispiel #5
0
void docftok(cell *up)
{
	create_word((token_t)DOCON, up);
	ncomma(next_prim);  // Don't do ++ here because ncomma has side effects
	++next_prim;
}
Beispiel #6
0
void doconstant(cell *up)
{
	create_word((token_t)DOCON, up);
	ncomma(stack);
}
Beispiel #7
0
void dodefer(cell *up)
{
	create_word((token_t)DODEFER, up);
	unumcomma(V(NUM_USER));
	V(NUM_USER) += sizeof(cell);
}
Beispiel #8
0
void docolon(cell *up)     { create_word((token_t)DOCOLON, up); V(STATE) = 1;}