コード例 #1
0
ファイル: main.c プロジェクト: darkwave3137/workspace
int main()
{
	int x;
	char a[20];
	WORD_NODE *root;
	root = creat();
	for(;;){	
		printf("input the value for fun()\n1: add\n2: del\n3: find\n");
		scanf("%d", &x);
		getchar();
		if(x == 1)
			add_words(root);
		if(x == 2){
			printf("please input the word:\n");
			gets(a);
			del_words(root, a);
		}
		if(x == 3){
			printf("please input the word:\n");
			gets(a);
			if(find_words(root, a))
				printf("exist\n");
			else printf("NONE\n");
		}
	}
	return 0;

}
コード例 #2
0
int main(int argc,char *argv[])
{
	int num_words,i;
	struct timeval t0,t1;
	char search_word[1001];

	// handle command line argument
	if (argc != 2) {
		printf("Syntax: %s num_words\n",argv[0]);
		exit(1);
	}
	num_words = atoi(argv[1]);

	// initialize search_word to 1, 1, ..., 101, a word which is not added
	for (i = 0; i < 1000; i++)
		search_word[i] = 1;
	search_word[999] = 101;
	search_word[1000] = '\0';

	// add words
	ws_init();
	add_words(num_words);

	// time a worst case find
	gettimeofday(&t0,NULL);
	ws_find_word(search_word); // entire list will be searched
	gettimeofday(&t1,NULL);

	// display the difference
	printf("After %d words loaded, find in %d microseconds.\n",
	 num_words,tv_diff(t0,t1));

	return 0;
}
コード例 #3
0
ファイル: main.c プロジェクト: AstoniaDev/openMerc
LRESULT FAR PASCAL _export MainWndProc(HWND hWnd, UINT message,WPARAM wParam, LPARAM lParam)
{
	PAINTSTRUCT ps;
	int keys;
	extern int ser_ver,xmove;

	keys=0;
	if (GetAsyncKeyState(VK_SHIFT)&0x8000) keys|=1;
	if (GetAsyncKeyState(VK_CONTROL)&0x8000) keys|=2;

	switch (message) {
		case    WM_SYSKEYDOWN:
		case WM_KEYDOWN:
			switch ((int)wParam) {
				case    27:         cmd(CL_CMD_RESET,0,0); show_shop=0; noshop=QSIZE*12; xmove=0; break;	//ESC
				case    'p':            if (keys) button_command(16);
					else cmd(CL_CMD_MODE,2,0); break;		//F1
				case    'q':            if (keys) button_command(17);
					else cmd(CL_CMD_MODE,1,0); break;		//F2
				case    'r':            if (keys) button_command(18);
					else cmd(CL_CMD_MODE,0,0); break;		//F3
				case    's':            if (keys) button_command(19);
					else pdata.show_proz=1-pdata.show_proz; break;	//F4
				case    't':            if (keys) button_command(20);			//F5
					else do_alpha++; if (do_alpha==3) do_alpha=0; dd_invalidate_alpha(); break;
				case    'u':            if (keys) button_command(21);
					else pdata.hide=1-pdata.hide; break;		//F6
				case    'v':            if (keys) button_command(22);
					else pdata.show_names=1-pdata.show_names; break;//F7
				case    'w':            if (keys) button_command(23);break;			   //F8
				case    'x':            if (keys) button_command(24);
					else dd_savescreen(); break;						   //F9
				case  'y':        if (keys)	button_command(25);
					else {
						gamma+=250;
						if (gamma>6000)	gamma=5000;
						xlog(2,"Set gamma correction to %1.2f",gamma/5000.0);
						dd_invalidate_cache();
					}
					break;		// F10
				case    'z':        if (keys) button_command(26);
					else {
						xlog(2," ");											//F11
						xlog(2,"Client Version %d.%02d.%02d",VERSION>>16,(VERSION>>8)&255,VERSION&255);
						xlog(2,"Server Version %d.%02d.%02d",ser_ver>>16,(ser_ver>>8)&255,ser_ver&255);
						xlog(2,"MAXX=%d, MAXY=%d, MAXXO=%d",MAXX,MAXY,MAXXOVER);
						xlog(2,"R=%04X, G=%04X, B=%04X",RED,GREEN,BLUE);
						xlog(2,"RGBM=%d",RGBM);
						xlog(2,"MAXCACHE=%d",MAXCACHE);
						xlog(2,"Hit=%d, Miss=%d, Invis=%d",dd_cache_hit,dd_cache_miss,invisible);
						xlog(2,"Ratio=%.2f%%",100.0/(dd_cache_hit+dd_cache_miss)*dd_cache_hit);
						xlog(2,"Skip=%d%% Idle=%d%%",pskip,pidle);
						xlog(2,"MaxMem=%dK, UsedMem=%dK",maxmem>>10,usedmem>>10);
						xlog(2,"MemBlocks=%d (T=%d,GC=%d)",blockcnt,blocktot,blockgc);
						xlog(2,"MaxVid=%dK, UsedVid=%dK",(maxvid*32*32*2)>>10,(usedvid*32*32*2)>>10);
						xlog(2,"cachex=%d, cachey=%d, MAXXOVER=%d",cachex,cachey,MAXXOVER);
						xlog(2,"usedvidmemflag=%d",usedvidmem);
						xlog(2,"alphapix=%d, fullpix=%d, ratio=%.2f",alphapix,fullpix,100.0/(alphapix+fullpix+1)*alphapix);

//                                do_ticker=1-do_ticker;
					}
					break;

				case    '{':            if (keys) button_command(27);
					else cmd_exit();
					break;		   //F12


					// text editor
				case  9:          complete_word();
					break;

				case    8:              if (cur_pos && in_len) { //BACKSPACE
						if (tabmode) {
							in_len=cur_pos; tabmode=0; tabstart=0;
						}
						if (cur_pos>in_len)	cur_pos=in_len;
						memmove(input+cur_pos-1,input+cur_pos,120-cur_pos);
						in_len--;
						cur_pos--;
					}
					break;
				case 46:             if (in_len) { // DEL
						if (tabmode) {
							in_len=cur_pos; tabmode=0; tabstart=0;
						} else {
							memmove(input+cur_pos,input+cur_pos+1,120-cur_pos);
							in_len--;
						}
					}
					break;
				case 33:          if (logstart<22*8) {
						logstart+=11; logtimer=TICKS*30;
					}
					break;
				case 34:          if (logstart>0) {
						logstart-=11; logtimer=TICKS*30;
					}
					break;
				case 36:          cur_pos=0; tabmode=0; tabstart=0; break; // HOME
				case 35:          cur_pos=in_len; tabmode=0; tabstart=0; break;	// END
				case 37:          if (cur_pos) cur_pos--;
					tabmode=0; tabstart=0;
					break;
				case 39:          if (cur_pos<115) cur_pos++;
					tabmode=0; tabstart=0;
					break;
				case 38:          if (hist_nr<19) {
						memcpy(history[hist_nr],input,128);
						hist_len[hist_nr]=in_len;
						hist_nr++;

						memcpy(input,history[hist_nr],128);
						in_len=cur_pos=hist_len[hist_nr];

						tabmode=0; tabstart=0;
					}
					break;
				case 40:          if (hist_nr>0) {
						memcpy(history[hist_nr],input,128);
						hist_len[hist_nr]=in_len;

						hist_nr--;

						memcpy(input,history[hist_nr],128);
						in_len=cur_pos=hist_len[hist_nr];

						tabmode=0; tabstart=0;
					}
					break;
/*           default:          xlog(3,"key=%d",(int)wParam);
							 break;*/

			}
			break;

		case WM_CHAR:
			switch ((int)wParam) {
				case    13:            if (in_len==0) break;

					if (tabmode) {
						tabmode=0; tabstart=0;
						in_len--;
					}

					memmove(history[2],history[1],18*128);
					memmove(&hist_len[2],&hist_len[1],sizeof(int)*18);

					memcpy(history[1],input,128);
					hist_len[1]=in_len;

					input[in_len]=0;
					in_len=0;
					cur_pos=0;
					view_pos=0;
					hist_nr=0;

					add_words();

					say(input);

					break;

				default:                if ((int)wParam>31 && (int)wParam<128 && in_len<115) {
						if (tabmode) {
							if (!isalnum((char)wParam))	in_len--;
							cur_pos=in_len;
							tabmode=0;
							tabstart=0;
						}
						if (cur_pos>in_len)	cur_pos=in_len;
						memmove(input+cur_pos+1,input+cur_pos,120-cur_pos);
						input[cur_pos]=(char)wParam;
						in_len++;
						cur_pos++;
					}
					break;
			}
			break;

		case WM_PAINT:
			BeginPaint(hWnd,&ps);
			EndPaint(hWnd,&ps);
			break;

		case WM_DESTROY:
			PostQuitMessage(0);
			break;

		case WM_MOUSEMOVE:
			mouse(LOWORD(lParam),HIWORD(lParam),MS_MOVE);
			mx=LOWORD(lParam);
			my=HIWORD(lParam);
			break;

		case WM_LBUTTONDOWN:
			mouse(LOWORD(lParam),HIWORD(lParam),MS_LB_DOWN);
			break;

		case WM_LBUTTONUP:
			mouse(LOWORD(lParam),HIWORD(lParam),MS_LB_UP);
			break;

		case WM_RBUTTONDOWN:
			mouse(LOWORD(lParam),HIWORD(lParam),MS_RB_DOWN);
			break;

		case WM_RBUTTONUP:
			mouse(LOWORD(lParam),HIWORD(lParam),MS_RB_UP);
			break;

		default:
			return(DefWindowProc(hWnd, message, wParam, lParam));
	}
	return 0;
}