Beispiel #1
0
void		loop_it(t_tout *tout)
{
	unsigned long	key;
	int				refresh;

	while ((key = 0) || (read(0, &key, 6)) != 0)
	{
		refresh = 1;
		if (key == KEY_ESCAPE || key == 'q')
			abort_exit(0);
		else if (key == KEY_SPACE)
			select_deselect(tout);
		else if (key == KEY_ENTER)
			print_white(tout);
		else if (key == KEY_UP || key == KEY_DOWN)
			up_down(tout, key);
		else if (key == KEY_LEFT || key == KEY_RIGHT)
			left_right(tout, key);
		else if (key == KEY_BACKSPACE || key == KEY_DELETE)
			remove_word(tout);
		else
			refresh = 0;
		if (refresh)
			refresh_screen(0);
	}
}
Beispiel #2
0
int displaybmp_32bit(int x, int y, BMPheader_t* bmp)
{
    if(bmp->BitsPerPixel != 24)return 1;
    
    static u32int w, h, pixel;
    static int R, G, B;
    h = bmp->Height;
    w = bmp->Width;
    
    while(w % 4)
    {
          //Width not multiple of 4
          w++;
    }
    
    for(y=h-1;y>=0;y--)
         for(x=0;x<w;x++)
              //Only print actual pixels, for null values just iterate
              pixel = 0;
              if(x <= bmp->Width)
                   R = (int)((bmp + bmp->Offset)+(y*w)+x)+2;
                   G = (int)((bmp + bmp->Offset)+(y*w)+x)+1;
                   B = (int)((bmp + bmp->Offset)+(y*w)+x);
                   pixel = R<<16 | G<<8 | B;
                   g_write_pixel(x,y,pixel);
    refresh_screen();
    return 0;
}
Beispiel #3
0
void				input_loop(void)
{
	unsigned long	keycode;
	t_environment	*env;
	int				should_refresh;

	env = get_set_environment(NULL);
	while (keycode = 0, (read(0, &keycode, 6)) != 0)
	{
		should_refresh = 1;
		if (keycode == KEY_BACKSPACE || keycode == KEY_DELETE)
			remove_selected(env);
		else if (keycode == KEY_SPACE)
			select_deselect(env);
		else if (keycode == KEY_ENTER)
			return_highlighted_words(env);
		else if (keycode == KEY_LEFT || keycode == KEY_RIGHT)
			handle_left_right(env, keycode);
		else if (keycode == KEY_DOWN || keycode == KEY_UP)
			handle_up_down(env, keycode);
		else if (keycode == KEY_ESCAPE || keycode == 'q')
			abort_exit(0);
		else
			should_refresh = 0;
		if (should_refresh)
			refresh_screen(0);
	}
}
Beispiel #4
0
void shell_mode() {

    char arriving_char;
    char c;

    print_initial_prompt_lines();

    while (1) {

        if (current_vt == CHAT_VT && serial_received()) {
            arriving_char = read_serial();
            parse_arriving_char(arriving_char);
        }

        while ((c = getc()) == -1)
            ;

        if (current_vt == CHAT_VT) {
            parse_departing_char(c);
        } else {
            parse_command_char(c);
        }

        refresh_screen();
    }
}
Beispiel #5
0
void print_initial_prompt_lines() {
    for (; current_vt < 3; current_vt++) {
        printf("guest@J2OS-terminal-%d:/$ ", current_vt + 1);
    }
    current_vt = 0;
    refresh_screen();
}
Beispiel #6
0
void
sort_by_field(char *name)
{
	int field;

	select_none();

	name = (name == NULL) ? opt_get_str(STR_SORT_FIELD) : name;
	find_field_number(name, &field);

	if(field < 0) {
		if(name == opt_get_str(STR_SORT_FIELD))
			statusline_msg(_("Invalid field value defined "
				"in configuration"));
		else
			statusline_msg(_("Invalid field value for sorting"));

		return;
	}

	sort_field = field;

	qsort((void *)database, items, sizeof(list_item), namecmp);

	refresh_screen();
}
Beispiel #7
0
void
term_check_refresh(void)
{
	if (term_reset_flag)
	{
		refresh_screen(0, NULL);
		term_reset_flag = 0;
	}
}
Beispiel #8
0
void
sort_surname()
{
	select_none();

	qsort((void *)database, items, sizeof(list_item), surnamecmp);

	refresh_screen();
}
Beispiel #9
0
void amx_clrscr(void)
{
  if (createconsole(0, NULL)) {
    assert(lines != NULL);
    memset(lines, __T(' '), NUM_LINES * NUM_COLUMNS);
    csrx = csry = 0;
    refresh_screen(0, NUM_LINES);
  } /* if */
}
Beispiel #10
0
void init_ui(char *name)
{
	init_curses();
	init_tree(name);
	init_lines();
	print_line(FILE(tree_root)->line);
	open_directory(tree_root);
	refresh_screen();
}
Beispiel #11
0
static void			restart(int signum)
{
	t_environment	*env;

	(void)signum;
	env = get_set_environment(NULL);
	setup_terminal(env);
	set_signals(&restart);
	refresh_screen(0);
}
Beispiel #12
0
void amx_gotoxy(int x,int y)
{
  if (createconsole(0, NULL)) {
    if (x>0 && x<=NUM_COLUMNS)
      csrx=x-1;
    if (y>0 && y<=NUM_LINES)
      csry=y-1;
    refresh_screen(0, 0); /* only to set the cursor at the correct location */
  } /* if */
}
void handle_init(void) {
	// Create a window and text layers
	window = window_create();
		
	// Create the Time Layer, set the font, and text alignment
	time_layer = text_layer_create(GRect(0, 5, 144, 168));
	text_layer_set_font(time_layer, fonts_get_system_font(FONT_KEY_BITHAM_42_BOLD));
	text_layer_set_text_alignment(time_layer, GTextAlignmentCenter);
	
	// Add the time layer to the window
	layer_add_child(window_get_root_layer(window), text_layer_get_layer(time_layer));

	//Create a horizontal divider
	line_layer = layer_create(GRect(8, 60, 128, 2));
	layer_set_update_proc(line_layer, line_layer_update_callback);
	layer_add_child(window_get_root_layer(window), line_layer);
	
	// Create the Date Layer, set the font, and text alignment
	date_layer = text_layer_create(GRect(0, 70, 144, 108));
	text_layer_set_font(date_layer, fonts_get_system_font(FONT_KEY_BITHAM_30_BLACK));
	text_layer_set_text_alignment(date_layer, GTextAlignmentCenter);
	
	// Add the date layer to the window
	layer_add_child(window_get_root_layer(window), text_layer_get_layer(date_layer));
	
	// Create the Year Layer, set the font, and text alignment
	year_layer = text_layer_create(GRect(0, 100, 144, 108));
	text_layer_set_font(year_layer, fonts_get_system_font(FONT_KEY_BITHAM_30_BLACK));
	text_layer_set_text_alignment(year_layer, GTextAlignmentCenter);
	
	// Add the year layer to the window
	layer_add_child(window_get_root_layer(window), text_layer_get_layer(year_layer));	
	
	// Create the info layer, set the font, text and alignment
	info_layer = text_layer_create(GRect(0, 140, 144, 30));
	text_layer_set_font(info_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
	text_layer_set_text_alignment(info_layer, GTextAlignmentCenter);
	text_layer_set_text(info_layer, "www.dozenal.org");
	
	// Add the info layer to the window
	layer_add_child(window_get_root_layer(window), text_layer_get_layer(info_layer));
	
	// Push the window
	window_stack_push(window, true);
	
	// initiate the screen
	time_t now = time(NULL);
	refresh_screen(localtime(&now));
	
	// Register the time handler function
	tick_timer_service_subscribe(SECOND_UNIT, handle_minute_tick);
	
	// App Logging!
	// APP_LOG(APP_LOG_LEVEL_DEBUG, "Just pushed a window!");
}
Beispiel #14
0
void watch_events(void)
{
	GNode *modified_directory, *removed_file;
	File *new_file;
	gboolean refresh_request = FALSE;
	struct timeval time;
	struct inotify_event *event;
	int n, i;
	fd_set fds;

	CHECK_INOTIFY_ENABLED();
again:	time.tv_sec = 0;
	time.tv_usec = 0;
	FD_ZERO(&fds);
	FD_SET(inotify_descriptor, &fds);
	while ((n = select(inotify_descriptor + 1, &fds, NULL, NULL, &time)) == 1) {
again2:		if ((n = read(inotify_descriptor, events_buffer, BUFFER_LENGTH)) > 0) {
			for (i = 0; i < n; i += sizeof(struct inotify_event) + event->len) {
				event = (struct inotify_event *) (events_buffer + i);
				if (debug_inotify == TRUE)
					dump_event(event);
				modified_directory = (GNode *) g_hash_table_lookup(
						watches_table, &(event->wd));

				if (event->mask & IN_CREATE || event->mask & IN_MOVED_TO) {
					if ((new_file = create_new_file(event->name,
									get_path(modified_directory), FALSE)) != NULL)
						refresh_request |= insert_in_tree(modified_directory, new_file);
				} else if (event->mask & IN_DELETE || event->mask & IN_MOVED_FROM) {
					if ((removed_file = search_node_by_name(modified_directory,
									event->name)) != NULL)
						refresh_request |= remove_from_tree(removed_file, FALSE);
				} else if (event->mask & IN_UNMOUNT) {
					refresh_request |= remove_from_tree(modified_directory, TRUE);
				}
			}
		} else if (n == -1) {
			if (errno == EINTR)
				goto again2;
			else
				PRINT_ERRNO_AND_EXIT();
		}
	}
	if (n == -1) {
		if (errno == EINTR)
			goto again;
		else
			PRINT_ERRNO_AND_EXIT();
	}
	if (refresh_request == TRUE)
		refresh_screen();
}
static int alphabet_game_start_response_focus(p_void_data_t p_void_data, const m_evt_code_t *p_m_evt_code, int sel_index)
{
	const unsigned int usec=DELAY_TIME_MAX;
	alphabet_game_t *ag=(alphabet_game_t *)p_void_data;
	const m_evt_code_t *m_evt_code=p_m_evt_code;
	int sel_ndx=sel_index;
	if((NULL==ag)||(NULL==m_evt_code)){
		return RET_FAILED;
	}

	if(FALSE==judge_cur_sort_foremost_alphabet(ag,ag->alphabet_id[sel_ndx])){
		show_prompt(&ag->scr,ALPHABET_GAME_HELP_SELECT_WRONG,strlen(ALPHABET_GAME_HELP_SELECT_WRONG),COLOR_MSG_ERROR);
		refresh_screen(ag->scr.win);
		sleep_delay_time(usec);
	}else{
		ctrl_tool_set_visible(ag->child_status_start,sel_index,FALSE);
		dec_remain_alphabet_num(ag);
	}

	if(0>=get_remain_alphabet_num(ag)){//enter next level
		set_enter_next_level(ag,TRUE);
		switch(get_cur_level(ag)){
			case LEVEL_ONE:
				set_cur_level(ag,LEVEL_TWO);				
				set_total_time(ag,ALPHABET_GAME_START_TIME_TWO);
				//set_remain_time(ag,ALPHABET_GAME_START_TIME_TWO);
				set_total_alphabet_num(ag,ALPHABET_GAME_START_LEVEL_TWO_ALPHABET_NUM);
				set_remain_alphabet_num(ag,get_total_alphabet_num(ag));	
				break;
			case LEVEL_TWO:
				set_cur_level(ag,LEVEL_THREE);
				set_total_time(ag,ALPHABET_GAME_START_TIME_THREE);
				//set_remain_time(ag,ALPHABET_GAME_START_TIME_THREE);
				set_total_alphabet_num(ag,ALPHABET_GAME_START_LEVEL_THREE_ALPHABET_NUM);
				set_remain_alphabet_num(ag,get_total_alphabet_num(ag));	
				break;
			case LEVEL_THREE:
				set_cur_level(ag,LEVEL_ONE);				
				set_total_time(ag,ALPHABET_GAME_START_TIME_ONE);
				//set_remain_time(ag,ALPHABET_GAME_START_TIME_ONE);
				set_total_alphabet_num(ag,ALPHABET_GAME_START_LEVEL_ONE_ALPHABET_NUM);
				exit_child_status_start(ag);
				break;
			default:
				set_cur_status(ag,MAIN_STATUS);
				break;
		}
	}
		
	return RET_SUCCESS;
}
Beispiel #16
0
void list_tracks()
{	
	refresh_screen();
	
	int cur_print_line = MESSAGE_LINE;
	
	mvprintw(cur_print_line, OUTPUT_COL, "CD Track Listing:");
	
	cur_print_line += 2;
	
	FILE *fp = fopen(tracks_file, "r");
	if (NULL == fp)
	{
		mvprintw(ERROR_LINE, OUTPUT_COL, "%s\n", "save_record(): fopen error");
		refresh();
		return;
	}
	
	char buf[1024];
	memset(buf, 0, sizeof(buf));
	int len = strlen(cur_cd_cat);
	
	while (fgets(buf, sizeof(buf), fp))
	{
		if (strncmp(buf, cur_cd_cat, len) == 0)
		{
			char *track_ptr = buf;
			int separator_count = 0;
			while (*track_ptr != '\0')
			{
				if (*track_ptr == ',') ++ separator_count;
				
				if (separator_count >= 2) 
				{
					++ track_ptr;
					break;
				}
				
				++ track_ptr;
			}
			
			mvprintw(cur_print_line ++, OUTPUT_COL, "%s", track_ptr);
		}
	}
	
	refresh();
	
	fclose(fp);
	
	cd_pause(cur_print_line + 1);
}
Beispiel #17
0
void amx_clreol(void)
{
  if (createconsole(0, NULL)) {
    int i;
    int size=NUM_COLUMNS-csrx;
    int pos=csry*NUM_COLUMNS+csrx;
    assert(lines!=NULL);
    for (i=0; i<size; i++) {
      lines[pos+i]=__T(' ');
      //??? lines[pos+i+1]=attrib;
    } /* for */
    refresh_screen(csry, csry + 1);
  } /* if */
}
Beispiel #18
0
int					main(int argc, char **argv)
{
	t_environment	*env;

	if (argc < 2)
		ft_putendl_fd_exit("Usage: ft_select [parameters]", 2, 1);
	env = malloc(sizeof(t_environment));
	setup_environment(env, argc, argv);
	get_set_environment(env);
	set_signals(&restart);
	refresh_screen(0);
	input_loop();
	return (0);
}
void		move_down(t_list *list)
{
  t_list	*tmp;

  tmp = list->next;
  while (tmp && tmp->current == 0)
    tmp = tmp->next;
  if (tmp->prev != list)
    tmp->prev->current = 1;
  else
    tmp->prev->prev->current = 1;
  tmp->current = 0;
  refresh_screen(&list);
}
Beispiel #20
0
void *read_ts(void *data)
{
	int x,y;
	unsigned int i;
	unsigned int mode =0;
	while(1)
	{
		struct ts_sample samp;
		int ret;

		ret = ts_read(data, &samp,1);
		if(ret<0)
		{
			perror("ts_read");
			close_framebuffer();
			exit(1);
		}
		if(ret!=1)
			continue;
		for(i=0;i<NR_BUTTONS;i++)
			if(button_handle(&buttons[i],&samp))
				switch(i)
				{
					case 0://clear button clicked
						mode = 0;
						refresh_screen();
						break;
					case 1://exit button clicked
						mode = 1;
						put_string_center(xres/2,yres/2, "Bye~!!",1);
						sleep(2);
						fillrect(0,0,xres-1,yres-1,0);
						exit(1);
						break;
				}
		if(samp.pressure>0)
		{
			if(mode == 0x80000000)
				line(x,y,samp.x,samp.y,2);
			x = samp.x;
			y = samp.y;
			mode|=0x80000000;
		}
		else
		{
			mode&=~0x80000000;
		}
	}
}
Beispiel #21
0
static void
reap_child(GPid pid, gint status, gpointer data)
{
	ChildProcess *cp = data;
	if (cp->callback) {
		cp->callback(status, cp->data);
	}
	g_free(cp);
	clean_pid();
	wm->mode = GNT_KP_MODE_NORMAL;
	endwin();
	setup_io();
	refresh();
	refresh_screen();
}
void		move_up(t_list *list)
{
  t_list	*tmp;
  
  
  tmp = list->next;
  while (tmp && tmp->current == 0)
    tmp = tmp->next;
  tmp->current = 0;
  if (tmp->next != list)
    tmp->next->current = 1;
  else
    tmp->next->next->current = 1;
  refresh_screen(&list);
}
Beispiel #23
0
static void scroll() {
	int i;
	unsigned char *ptr;

	ptr = &(video_buffer_g[0][0]);
	if (g_video_ram == 0) return;
	for (i = 0; i < COLUMNS * (LINES - 1) * 2; i++) /* copy the data from next line to prev line */
	{
		*(g_video_ram + i) = ptr[i + 2 * COLUMNS];
		*(ptr + i) = ptr[i + 2 * COLUMNS];
	}
	for (i = COLUMNS * (LINES - 1) * 2; i < COLUMNS * (LINES) * 2; i++) /* clear the last line */
	{
		*(g_video_ram + i) = 0;
		*(ptr + i) = 0;
	}
	refresh_screen();
}
Beispiel #24
0
int amx_putstr(const TCHAR *format)
{
  if (createconsole(0, NULL)) {
    int pos, i;

    pos=csry * NUM_COLUMNS + csrx;
    assert(lines!=NULL);
    for (i=0; string[i]!=__T('\0'); i++) {
      if (csry<NUM_LINES && csrx<NUM_COLUMNS) {
        if (string[i]==__T('\r')) {
          csrx=0;
          pos=csry * NUM_COLUMNS + csrx;
        } else if (string[i]==__T('\n')) {
          csrx=0;
          csry++;
          if (csry>=NUM_LINES)
            scroll_window(0, -1);
          pos=csry * NUM_COLUMNS + csrx;
        } else if (string[i]==__T('\b')) {
          if (csrx>0) {
            csrx--;
            pos--;
            lines[pos]=__T(' ');
            //??? lines[pos+1]=attrib;
          } /* if */
        } else {
          lines[pos]=string[i];
          //??? lines[pos+1]=attrib;
          pos++;
          csrx++;
          if (csrx>=NUM_COLUMNS && autowrap) {
            csrx=0;
            csry++;
            if (csry>=NUM_LINES)
              scroll_window(0, -1);
            pos=csry * NUM_COLUMNS + csrx;
          } /* if */
        } /* if */
      } /* if */
    } /* for */
    refresh_screen(csry,csry+1);
  } /* if */
  return 0;
}
Beispiel #25
0
void main(){
	//init timer1 and two external interrupts
	hardware_init();
	//init screen
	game_init();
	//begin game
	while(1){
		//every 0.03s refresh screen
		if(count>=screen_count){
			if(switchS==0){
				//check button
				handle_button();
			}
			//refresh screen
			refresh_screen();
			//clear count
			count=0;
		}
	}
}
Beispiel #26
0
int displaybmp_8bit(int x, int y, BMPheader_t* bmp)
{
    if(bmp->BitsPerPixel != 8)return 1;
    
    static u32int w, h;
    h = bmp->Height;
    w = bmp->Width;
    
    while(w % 4)
    {
          //Width not multiple of 4
          w++;
    }
    
    for(y=h-1;y>=0;y--)
         for(x=0;x<w;x++)
              //Only print actual pixels, for null values just iterate
              if(x <= bmp->Width)
                   //TODO: get RGB value from quad/pallette
                   g_write_pixel(x,y,(u32int)((bmp + bmp->Offset)+(y*w)+x));
    refresh_screen();
              
    return 0;
}
Beispiel #27
0
int amx_putchar(int c)
{
  if (createconsole(0, NULL)) {
    if (csry<NUM_LINES && csrx<NUM_COLUMNS) {
      int pos=csry*NUM_COLUMNS+csrx;
      assert(lines!=NULL);
      if (c==__T('\r')) {
        csrx=0;
      } else if (c==__T('\n')) {
        csrx=0;
        csry++;
        if (csry>=NUM_LINES)
          scroll_window(0, -1);
      } else if (c==__T('\b')) {
        if (csrx>0) {
          csrx--;
          pos--;
          lines[pos]=__T(' ');
          //??? lines[pos+1]=attrib;
        } /* if */
      } else {
        lines[pos]=(TCHAR)c;
        //??? lines[pos+1]=attrib;
        csrx++;
        if (csrx>=NUM_COLUMNS && autowrap) {
          csrx=0;
          csry++;
          if (csry>=NUM_LINES)
            scroll_window(0, -1);
        } /* if */
      } /* if */
      refresh_screen(csry,csry+1);
    } /* if */
  } /* if */
  return 1;
}
Beispiel #28
0
int main()
{
	struct tsdev *ts;
	unsigned int i;
	int ret,count;
	int connect = 0;
	char buff[10]="";
	char myaddr[16] = "";
	char *fbuff;
	pthread_t ts_thread;
	char *tsdevice = "/dev/ts0";
	int read_flag;

	signal(SIGSEGV, sig);
	signal(SIGINT, sig);
	signal(SIGTERM, sig);

	//open touchscreen device
	ts = ts_open(tsdevice,0);

	if(!ts)
	{
		perror(tsdevice);
		exit(1);
	}

	if(ts_config(ts))
	{
		perror("ts_config");
		exit(1);
	}
	if(open_framebuffer()){
		close_framebuffer();
		exit(1);
	}

	for(i=0;i<NR_COLORS;i++)
		setcolor(i,palette[i]);

	/* button settings for server program 
	 * server program only have clear and exit button.
	 */
	memset(&buttons,0,sizeof(buttons));
	buttons[0].w  = 70;
	buttons[0].h  = 20;
	buttons[0].x = 40; buttons[0].y = 200;
	buttons[0].text = "Clear";
	buttons[1].w = 20;
	buttons[1].h = 20;
	buttons[1].x = 280; buttons[1].y = 20;
	buttons[1].text = "Exit";

	refresh_screen();
	//sleep(30);
	reset_ipaddr();
	//strcpy(myaddr,ipaddr[mylocation]);
	strcpy(myaddr,my_ipaddr);
#ifdef DEBUG
	printf("ipaddr[mylocation] : %s\n",ipaddr[mylocation]);
	printf("my_ipaddr : %s\n",my_ipaddr);
	printf("myaddr : %s\n",myaddr);
#endif

	serv_sock = tcp_server_listen(ip2port(myaddr,7777),2);
	if(serv_sock < 0)
	{
		perror("tcp_server_listen");
		close_framebuffer();
		exit(1);
	}
	else
	{
		printf("server started!!! Ip: %s Port : %d\n",myaddr,ip2port(myaddr,7777));
	}

	pthread_create(&ts_thread, NULL, read_ts,ts);
	while(1)
	{

		clnt_sock = tcp_server_accept(serv_sock);
		if(clnt_sock <0)
		{
			perror("tcp_server_accept");
			exit(1);
		}
		else{
			//connect = 1;
#ifdef DEBUG
			printf("accept successful!!\n");
#endif
		}

		while(1)
		{
			ret = read(clnt_sock,buff,10);
#ifdef DEBUG
			printf("buff = %s\n",buff);
#endif

			if(!strcmp(buff,"Merge"))
			{
				//merge mode
				buff[0] = '\0';
#ifdef DEBUG
				printf("Merge mode on\n");
				printf("is buff cleared ? : %s\n",buff);
#endif
				ret = write(clnt_sock,fbuffer,fix.smem_len);

				if(ret<=0)
				{
					perror("write");
					exit(1);
				}
#ifdef DEBUG
				else
				{
					printf("server sent : %d\n",ret);
				}
				sleep(1);
#endif
			}
			/*
			   else if(!strcmp(buff,"Send"))
			   {
			   buff[0] = '\0';
			   count=0;
			   read_flag=0;
			   while(!read_flag)
			   {
			   ret = read(clnt_sock,fbuff+count,fix.smem_len);
			   if(ret<=0)				
			   {
			   perror("read");
			   exit(1);
			   }
			   count+=ret;
			   printf(" read : %d\n",count);
			   if(count>=fix.smem_len)
			   {
			   read_flag = 1;
			   }
			   }
			   for(i=0;i<fix.smem_len;i++)
			   {
			   fbuffer[i]|=fbuff[i];
			   }

			   }
			   */
			   else if(!strcmp(buff,"Split"))
			   {
				   //split mode
				   buff[0] = '\0';
				   sleep(1);
#ifdef DEBUG
				   printf("Split mode on\n");
				   printf("is buff cleared ? : %s\n",buff);
#endif
			   }
			   else if(!strcmp(buff,"Exit"))
			   {
				   buff[0] = '\0';
				   sleep(1);
#ifdef DEBUG
				   printf("Exit\n");
				   printf("is buff cleared ? : %s\n",buff);
#endif
				   break;
			   }
			   else
			   {
				   buff[0] = '\0';
				   sleep(1);
				   //	continue;
				   break;
			   }

		}
		close(clnt_sock);
		pthread_cancel(ts_thread);
	}
	pthread_join(ts_thread, NULL);
	close(serv_sock);
}
Beispiel #29
0
void io (const char *what)
{
	static	int	first_time = 1;
		long	clock_timeout = 0, 
			timer_timeout = 0,
			real_timeout = 0; 
static	struct	timeval my_now,
			my_timer,
			*time_ptr = &my_timer;

	int		hold_over,
			rc;
	fd_set		rd, 
			wd;

	get_time(&my_now);
	now = my_now.tv_sec;
	
	/* CHECK FOR CPU SAVER MODE */
	if (!cpu_saver && get_int_var(CPU_SAVER_AFTER_VAR))
		if (now - idle_time > get_int_var(CPU_SAVER_AFTER_VAR) * 60)
			cpu_saver_on(0, NULL);

	rd = readables;
	wd = writables;
	FD_ZERO(&wd);
	FD_ZERO(&rd);

	set_screens(&rd, &wd);
	set_server_bits(&rd, &wd);
	set_process_bits(&rd);
	set_socket_read(&rd, &wd);
	icmp_sockets(&rd, &wd);
	
#if defined(WANT_THREAD)
#ifdef WANT_NSLOOKUP
	set_dns_output_fd(&rd);
#endif
#ifdef WANT_PTEST
	set_ptest_output_fd(&rd);
#endif
#ifdef WANT_MP3PLAYER
	set_mp3_output_fd(&rd);
#endif
	
# if defined(GTK)
	if (tgtk_okay())
		tgtk_set_output_fd(&rd);
# endif
#endif
	clock_timeout = (timeout_select - (my_now.tv_sec % timeout_select)) * 1000;
	if (cpu_saver && get_int_var(CPU_SAVER_EVERY_VAR))
		clock_timeout += (get_int_var(CPU_SAVER_EVERY_VAR) - 1) * 60000;

	timer_timeout = TimerTimeout();

	if ((hold_over = unhold_windows()))
		real_timeout = 0;
	else if (timer_timeout <= clock_timeout)
		real_timeout = timer_timeout;
	else
		real_timeout = clock_timeout;

	if (real_timeout == -1)
		time_ptr = NULL;
	else
	{
		time_ptr->tv_sec = real_timeout / 1000;
		time_ptr->tv_usec = ((real_timeout % 1000) * 1000);
	}
	
	/* GO AHEAD AND WAIT FOR SOME DATA TO COME IN */
	switch ((rc = new_select(&rd, &wd, time_ptr)))
	{
		case 0:
			break;
		case -1:
		{
			/* if we just got a sigint */
			first_time = 0;
			if (cntl_c_hit)
				edit_char('\003');
			else if (errno && errno != EINTR)
			{
				int ii = 0;
				fd_set rd1, wd1;
				char ii_buff_r[500];
				char ii_buff_w[500];
				int ii_r[FD_SETSIZE];
				int ii_w[FD_SETSIZE];
				yell("Select failed with [%d:%s]", errno, strerror(errno));
				/* Reseed fd_sets so we can dig further */
				yell("Packing fd_sets... Dump of fd's set in fd_set");
				ii_buff_r[0] = '\0';
				ii_buff_w[0] = '\0';
				for (ii = 0; ii < FD_SETSIZE; ii++) {
					ii_r[ii] = 0;
					ii_w[ii] = 0;
				}
				FD_ZERO(&wd1);
				FD_ZERO(&rd1);
				set_screens(&rd1, &wd1);
				set_server_bits(&rd1, &wd1);
				set_process_bits(&rd1);
				set_socket_read(&rd1, &wd1);
				icmp_sockets(&rd1, &wd1);
#if defined(WANT_THREAD)
#ifdef WANT_NSLOOKUP
				set_dns_output_fd(&rd1);
#endif
#ifdef WANT_PTEST
				set_ptest_output_fd(&rd1);
#endif
#ifdef WANT_MP3PLAYER
				set_mp3_output_fd(&rd1);
#endif
	
# if defined(GTK)
	if (tgtk_okay())
				tgtk_set_output_fd(&rd1);
# endif
#endif
				for (ii = 0; ii <= global_max_fd; ii++) {
					fd_set rblah, wblah;
					memcpy(&rblah, &rd1, sizeof(fd_set));
					FD_SET(ii, &rblah);
					if (memcmp(&rblah, &rd1, sizeof(fd_set)) == 0) {
						char blahblah[20];
						sprintf(blahblah, "%d ", ii);
						strcat(ii_buff_r, blahblah);
						ii_r[ii] = 1;
					}
					memcpy(&wblah, &wd1, sizeof(fd_set));
					FD_SET(ii, &wblah);
					if (memcmp(&wblah, &wd1, sizeof(fd_set)) == 0) {
						char blahblah[20];
						yell("blah");
						sprintf(blahblah, "%d ", ii);
						strcat(ii_buff_w, blahblah);
						ii_w[ii] = 1;
					}
				}
				yell("Read fd's in set: %s", (ii_buff_r[0] == '\0') ? "<NONE>" : ii_buff_r);
				for (ii = 0; ii <= global_max_fd; ii++) {
					if (ii_r[ii] == 1) {
						struct stat st;
						if (fstat(ii, &st) == -1) {
							yell("READ FD %d is causing the select failure!", ii);
						}
						else {
							if (S_ISSOCK(st.st_mode))
								yell("READ FD %d is a socket!", ii);
							else if (S_ISREG(st.st_mode))
								yell("READ FD %d is a regular file!", ii);
							else if (S_ISFIFO(st.st_mode))
								yell("READ FD %d is a FIFO!", ii);
							else ;
						}
					}
				}
				yell("Write fd's in set: %s", (ii_buff_w[0] == '\0') ? "<NONE>" : ii_buff_w);
				for (ii = 0; ii <= global_max_fd; ii++) {
					if (ii_w[ii] == 1) {
						struct stat st;
						if (fstat(ii, &st) == -1) {
							yell("WRITE FD %d is causing the select failure!", ii);
						}
						else {
							if (S_ISSOCK(st.st_mode))
								yell("WRITE FD %d is a socket!", ii);
							else if (S_ISREG(st.st_mode))
								yell("WRITE FD %d is a regular file!", ii);
							else if (S_ISFIFO(st.st_mode))
								yell("WRITE FD %d is a FIFO!", ii);
							else ;
						}
					}
				}
				sleep(10);
			}
			else 
			{
#if 0
				yell("errno 0 rc = -1, maybe it'll go away");
				sleep(10);
#endif
			}
			break;

		}

		/* we got something on one of the descriptors */
		default:
		{
			cntl_c_hit = 0;
			now = time(NULL);
			make_window_current(NULL);
			do_screens(&rd);
			check_icmpresult(&rd, &wd);
#if defined(WANT_THREAD)
#ifdef WANT_NSLOOKUP
			dns_check(&rd);
#endif
#ifdef WANT_PTEST
			ptest_check(&rd);
#endif
#ifdef WANT_MP3PLAYER
			mp3_check(&rd);
#endif
# if defined(GTK)
			if (tgtk_okay())
				tgtk_check(&rd);
# endif
#endif
			do_server(&rd, &wd);
			do_processes(&rd);
			scan_sockets(&rd, &wd);
			clean_sockets();
			break;
		} 
	}

	now = time(NULL);
	ExecuteTimers();

        get_child_exit(-1);
	if (update_refresh)
	{
		update_refresh = 0;
		refresh_screen(0, NULL);
	}
	if (!hold_over)
		cursor_to_input();


	if (update_clock(RESET_TIME))
	{
		if (get_int_var(CLOCK_VAR))
		{
			update_all_status(current_window, NULL, 0);
			cursor_to_input();
		}
		clean_queue(get_int_var(TRANSFER_TIMEOUT_VAR)); /* timeout if send time is greater than 5 minutes */
	}

	/* (set in term.c) -- we should redraw the screen here */
	if (need_redraw)
		refresh_screen(0, NULL);
#ifdef WANT_THREAD
	if (scan_done)
		scan_is_done();	
#endif
	alloca(0);
	return;
}
Beispiel #30
0
int main()
{
	int ch;
	
	initscr();			/* start curses	*/
	raw();				/* disable line buffering */
	keypad(stdscr, TRUE);
	noecho();

	start_color();
	use_default_colors();
	init_pair(10, COLOR_WHITE, COLOR_RED);

	statuswin = subwin(stdscr, 1, 0, 0, 0);
	hdrwin = subwin(stdscr, 1, 0, 1, 0);

	blockpad = newpad(1000, 60);

	errorw = statuswin;

	wclear(stdscr);

	db_connect();
	if (db_is_connected())
	{
		reporterror("connected");
		rels = db_fetch_relations(&nrels);
		if (rels)
			display_relations(hdrwin, blockpad, rels, nrels);
	}

	move_selection(0);
	refresh();

	for (;;)
	{
		refresh_screen();

		ch = getch();

		werase(statuswin);
		wrefresh(statuswin);

		switch (ch)
		{
			case KEY_UP:
				if (displayed_block != InvalidBlockNumber)
					scroll_blockpad(-1);
				else
					move_selection(-1);
				break;
			case KEY_DOWN:
				if (displayed_block != InvalidBlockNumber)
					scroll_blockpad(1);
				else
					move_selection(1);
				break;
			case KEY_NPAGE:
				if (displayed_block != InvalidBlockNumber)
					scroll_blockpad(15);
				else
					move_selection(15);
				break;
			case KEY_PPAGE:
				if (displayed_block != InvalidBlockNumber)
					scroll_blockpad(-15);
				else
					move_selection(-15);
				break;

			case KEY_ENTER:
			case KEY_RIGHT:
				if (displayed_block == InvalidBlockNumber)
				{
					block = db_fetch_block(rels[selected_rel].relname, "main", 0);
					if (block)
					{
						blockpad_pos_save = blockpad_pos;
						blockpad_pos = 0;
						displayed_block = 0;
						display_block(hdrwin, blockpad, block, displayed_block);
					}
				}
				else
				{
					displayed_block++;
					block = db_fetch_block(rels[selected_rel].relname, "main", displayed_block);
					if (block)
					{
						blockpad_pos_save = blockpad_pos;
						blockpad_pos = 0;
						display_block(hdrwin, blockpad, block, displayed_block);
					}
				}
				break;

			case KEY_LEFT:
				if (displayed_block != InvalidBlockNumber)
				{
					displayed_block--;
					if (displayed_block == InvalidBlockNumber)
					{
						blockpad_pos = blockpad_pos_save;
						if (displayed_block == InvalidBlockNumber)
						{
							display_relations(hdrwin, blockpad, rels, nrels);
							mvwchgat(blockpad, selected_rel, 0, 40, A_REVERSE, 0, NULL);
						}
					}
					else
					{
						block = db_fetch_block(rels[selected_rel].relname, "main", displayed_block);
						if (block)
						{
							blockpad_pos_save = blockpad_pos;
							blockpad_pos = 0;
							display_block(hdrwin, blockpad, block, displayed_block);
						}
					}

				}
				break;

			case 'g':				/* goto block */
				if (displayed_block != InvalidBlockNumber)
				{
					char str[11];
					BlockNumber blkno;
					char *endptr;

					werase(hdrwin);
					mvwprintw(hdrwin, 0, 0, "Goto block: ");
					refresh_screen();
					echo();
					getnstr(str, sizeof(str) - 1);
					noecho();

					blkno = strtoul(str, &endptr, 10);
					if (*endptr != '\0')
					{
						werase(hdrwin);
						mvwprintw(hdrwin, 0, 0, "Invalid block number");
					}
					else
					{
						block = db_fetch_block(rels[selected_rel].relname, "main", blkno);
						if (block)
						{
							displayed_block = blkno;
							blockpad_pos_save = blockpad_pos;
							blockpad_pos = 0;
							display_block(hdrwin, blockpad, block, displayed_block);
						}
					}
				}
				break;

			case 'q':
				endwin();			/* End curses mode		  */
				exit(0);
				break;
			default:
				reporterror("unknown key: %c", ch);
		}
	}
	endwin();			/* End curses mode		  */

	return 0;
}