Example #1
0
/* main:
 * Entry point. See usage(). */
int main(int argc, char **argv) {
    pthread_t thread;
    struct sigaction sa = {};

    setlocale(LC_ALL, "");

    /* TODO: tidy this up */
    /* read command line options and config file */   
    config_init();
    options_set_defaults();
    options_read_args(argc, argv);
    /* If a config was explicitly specified, whinge if it can't be found */
    read_config(options.config_file, options.config_file_specified);
    options_make();
    
    sa.sa_handler = finish;
    sigaction(SIGINT, &sa, NULL);

    pthread_mutex_init(&tick_mutex, NULL);

    packet_init();

    init_history();

    if (options.no_curses) {
      tui_init();
    }
    else {
      ui_init();
    }

    pthread_create(&thread, NULL, (void*)&packet_loop, NULL);

    /* Keep the starting time (used for timed termination) */
    first_timestamp = time(NULL);

    if (options.no_curses) {
      if (options.timed_output) {
        while(!foad) {
          sleep(1);
        }
      }
      else {
        tui_loop();
      }
    }
    else {
      ui_loop();
    }

    pthread_cancel(thread);

    ui_finish();
    
    return 0;
}
Example #2
0
int main(int argc, char **argv)
{
	int rc = 0;
	struct cfgdata_t cfg;
	struct params_t params;
	kx_inputs inputs;

	lg = log_open(16);
	log_msg(lg, "%s starting", PACKAGE_STRING);

	initmode = do_init();

	/* Get cmdline parameters */
	params.cfg = &cfg;
	init_cfgdata(&cfg);
	cfg.angle = 0;	/* No rotation by default */
	parse_cmdline(&cfg);

	kxb_ttydev = cfg.ttydev;
	setup_terminal(kxb_ttydev, &kxb_echo_state, 1);
	/* Setup function that will restore terminal when exit() will called */
	atexit(atexit_restore_terminal);

	log_msg(lg, "FB angle is %d, tty is %s", cfg.angle, cfg.ttydev);

#ifdef USE_MACHINE_KERNEL
	machine_kernel = get_machine_kernelpath();	/* FIXME should be passed as arg to get_bootinfo() */
#endif

#ifdef USE_DELAY
	/* extra delay for initializing slow SD/CF */
	sleep(USE_DELAY);
#endif

	int no_ui = 1;	/* UI presence flag */
#ifdef USE_FBMENU
	params.gui = NULL;
	if (no_ui) {
		params.gui = gui_init(cfg.angle);
		if (NULL == params.gui) {
			log_msg(lg, "Can't initialize GUI");
		} else no_ui = 0;
	}
#endif
#ifdef USE_TEXTUI
	FILE *ttyfp;
	params.tui = NULL;
	if (no_ui) {

		if (cfg.ttydev) ttyfp = fopen(cfg.ttydev, "w");
		else ttyfp = stdout;

		params.tui = tui_init(ttyfp);
		if (NULL == params.tui) {
			log_msg(lg, "Can't initialize TUI");
			if (ttyfp != stdout) fclose(ttyfp);
		} else no_ui = 0;
	}
#endif
	if (no_ui) exit(-1); /* Exit if no one UI was initialized */
	
	params.menu = build_menu(&params);
	params.bootcfg = NULL;
	scan_devices(&params);

	if (-1 == fill_menu(&params)) {
		exit(-1);
	}

	/* Collect input devices */
	inputs_init(&inputs, 8);
	inputs_open(&inputs);
	inputs_preprocess(&inputs);

	/* Run main event loop
	 * Return values: <0 - error, >=0 - selected item id */
	rc = do_main_loop(&params, &inputs);

#ifdef USE_FBMENU
	if (params.gui) {
		if (rc < 0) gui_clear(params.gui);
		gui_destroy(params.gui);
	}
#endif
#ifdef USE_TEXTUI
	if (params.tui) {
		tui_destroy(params.tui);
		if (ttyfp != stdout) fclose(ttyfp);
	}
#endif
	inputs_close(&inputs);
	inputs_clean(&inputs);

	log_close(lg);
	lg = NULL;

	/* rc < 0 indicate error */
	if (rc < 0) exit(rc);

	menu_destroy(params.menu, 0);

	if (rc >= A_DEVICES) {
		start_kernel(&params, rc - A_DEVICES);
	}

	/* When we reach this point then some error has occured */
	DPRINTF("We should not reach this point!");
	exit(-1);
}
Example #3
0
int main(int argc, char **argv) {
    pthread_t thread;
    struct sigaction sa = {};
	time_t timer_log;//time_t就是long int 类
	struct tm *tblock =NULL;/*定义一个变量*/

#if 1 

	if(daemon(0, 0) < 0)
	{
		perror("error daemon...\n");
		exit(1);
	}
#endif

    setlocale(LC_ALL, "");


#if 1
		//FILE *fp_log;				 /*定义一个文件指针*/
		int i_log;
		fp_log=fopen("/var/log/iftopd.log", "a+");	
		if(fp_log==NULL)				 /*判断文件是否打开成功*/
		   printf("File open error");  /*提示打开不成功*/
		else
		{  

			//time_t timer_log;//time_t就是long int 类
			//struct tm *tblock =NULL;		
			timer_log = time(NULL);//这一句也可以改成time(&timer);	
			tblock = localtime(&timer_log); 
			fprintf(fp_log,"start iftop time is: %s\n",asctime(tblock));				
	
		}


#endif 

    /* TODO: tidy this up */
    /* read command line options and config file */   
    config_init();
    options_set_defaults();
    options_read_args(argc, argv);
    /* If a config was explicitly specified, whinge if it can't be found */
    read_config(options.config_file, options.config_file_specified);
    options_make();
/*  修正参数 */
	correction_parameter();
    
    sa.sa_handler = finish;
    sigaction(SIGINT, &sa, NULL);

    pthread_mutex_init(&tick_mutex, NULL);

    packet_init();

    init_history();

    if (options.no_curses) {
      tui_init();
    }
    else {
      ui_init();
    }

    pthread_create(&thread, NULL, (void*)&packet_loop, NULL);

    /* Keep the starting time (used for timed termination) */
    first_timestamp = time(NULL);

    if (options.no_curses) {
      if (options.timed_output) {
        while(!foad) {
          sleep(1);
        }
      }
      else {
        tui_loop();
      }
    }
    else {
      ui_loop();
    }

    pthread_cancel(thread);

#if 1

#if  1
fprintf(fp_log," interface***** = %s \n",options.interface);
fprintf(fp_log," speed_second_time = %d \n",options.speed_second_time);
fprintf(fp_log," num_lines = %d \n",options.num_lines);

#endif


#if 1
	if( NULL != fp_log)
	{
		time(&timer_log);
		tblock = localtime(&timer_log);	
		fprintf(fp_log,"close iftop time is: %s\n",asctime(tblock));	
	}
	
#endif
	i_log = fclose(fp_log); 		   /*关闭打开的文件*/
	if(i_log!=0) 				/*判断文件是否关闭成功*/
		printf("File close error"); 		/*提示关闭	失败提示*/
	
#endif
    ui_finish();
    
    return 0;
}
Example #4
0
int main(void)
{
    tui_init();

    tab_window *ltab = malloc(sizeof *ltab);
    tab_window *rtab = malloc(sizeof *ltab);
    int ch;
    void (*p)(tab_window *, const char *);
    tab_window *active_tab;
    ltab->win = tui_new_win(0, 0, LINES, COLS / 2 , 2);
    rtab->win = tui_new_win(0, COLS / 2, LINES, COLS / 2, 2);

    mvwprintw(ltab->win->decoration, 1,1, "/");
    mvwprintw(rtab->win->decoration, 1,1, "/");

    set_panel_userptr(ltab->win->panel, rtab);
    set_panel_userptr(rtab->win->panel, ltab);

    top_panel(ltab->win->panel);

    active_tab = ltab;

    strncpy(ltab->path, "/", PATH_MAX - 1);
    strncpy(rtab->path, "/", PATH_MAX - 1);
    ltab->items_num = scan_dir(ltab->path, &ltab->files, dirsortbyname);
    rtab->items_num = scan_dir(rtab->path, &rtab->files, dirsortbyname);

    tui_make_menu(ltab, event_handler);
    tui_make_menu(rtab, event_handler);

    touchwin(panel_window(active_tab->win->panel));
    update_panels();
    doupdate();

    while ((ch = getch()) != KEY_F(12))
    {
        p = (void (*)(tab_window *, const char *))(uintptr_t)item_userptr(current_item(active_tab->menu));
        switch (ch)
        {
            case '\t':
                active_tab = (tab_window *) panel_userptr(active_tab->win->panel);
                top_panel(active_tab->win->panel);
                break;
            case KEY_DOWN:
                menu_driver(active_tab->menu, REQ_DOWN_ITEM);
                break;
            case KEY_UP:
                menu_driver(active_tab->menu, REQ_UP_ITEM);
                break;
            case KEY_NPAGE:
                menu_driver(active_tab->menu, REQ_SCR_DPAGE);
                break;
            case KEY_PPAGE:
                menu_driver(active_tab->menu, REQ_SCR_UPAGE);
                break;
            case KEY_HOME:
                menu_driver(active_tab->menu, REQ_FIRST_ITEM);
                break;
            case KEY_END:
                menu_driver(active_tab->menu, REQ_LAST_ITEM);
                break;
            case 13: // enter
                p(active_tab, "select");
                break;
            case KEY_F(2):
                p(active_tab, "remove");
                break;
            case KEY_F(3):
                p(active_tab, "rename");
                break;
            default:break;
        }
        touchwin(panel_window(active_tab->win->panel));
        update_panels();
        doupdate();
    }
    for(int i = 0; i < ltab->items_num ; ++i)
    {
        free(ltab->files[i]);
    }
    free(ltab->files);
    for(int i = 0; i < rtab->items_num; ++i)
    {
        free(rtab->files[i]);
    }
    free(rtab->files);
    tui_destroy_menu(rtab);
    tui_destroy_menu(ltab);
    tui_del_win(ltab);
    tui_del_win(rtab);
    free(ltab);
    free(rtab);
    endwin();
}
Example #5
0
File: client.c Project: nia40m/msgr
int main(int argc, char *argv[])
{
	int opt;
	pthread_t thread_reciever;
	pthread_t thread_sender;
	char addr[STR_LNGTH] = "";
	char name[STR_LNGTH] = "";
	char room[STR_LNGTH] = "";

	while ((opt = getopt(argc, argv, "a:n:r:")) != -1) {
		switch (opt) {
		case 'a':
			strncpy(addr, optarg, STR_LNGTH - 1);
			break;
		case 'n':
			strncpy(name, optarg, STR_LNGTH - 1);
			break;
		case 'r':
			strncpy(room, optarg, STR_LNGTH - 1);
			break;
		default:
			fprintf(stderr, "Usage: %s "
				"-a address -n name -r room\n", argv[0]);
			exit(EXIT_FAILURE);
		}
	}

	/* Check for undefined arguments */
	if (*addr == '\0' || *name == '\0' || *room == '\0') {
		fprintf(stderr, "Usage: %s "
			"-a address -n name -r room\n", argv[0]);
		exit(EXIT_FAILURE);
	}

	sockfd = msgr_connect(addr, name, room);
	switch (sockfd) {
	case CONN_FAIL:
		perror("client");
		exit(EXIT_FAILURE);
	case CONN_NAMEUSED:
		fprintf(stderr, "Requested username currently in use. "
			"Please choose another name and try again.\n");
		exit(EXIT_FAILURE);
	case CONN_SRVERROR:
		fprintf(stderr, "Server error.\n");
		exit(EXIT_FAILURE);
	case CONN_ERROR:
		fprintf(stderr, "Connection error.\n");
		exit(EXIT_FAILURE);
	}

	tui_init();

	pthread_create(&thread_reciever, NULL, &reciever, NULL);
	pthread_create(&thread_sender, NULL, &sender, name);

	pthread_join(thread_sender, NULL);
	pthread_cancel(thread_reciever);

	tui_end();

	close(sockfd);
	exit(EXIT_SUCCESS);
}
Example #6
0
int tui_num_cols(void)
{
    if (text_mode_info.screenwidth == 0)
        tui_init();
    return text_mode_info.screenwidth;
}
Example #7
0
int tui_num_lines(void)
{
    if (text_mode_info.screenheight == 0)
        tui_init();
    return text_mode_info.screenheight;
}