示例#1
0
文件: ui.c 项目: AdamGreenhill/monks
void create_win_data_data_box(){
	if(!win_data_box){
		destroy_win(win_data_box);
	}
	if(!win_data){
		destroy_win(win_data);
	}

	refresh();

	header_box = create_newwin(header_box_height, header_box_width, header_box_starty, header_box_startx);
	mvwprintw(header_box, 1, 1,
		"%-15.20s"       /* Process name */
		"%10s"           /* PID          */
		" %-15.10s"      /* Operation    */
		"%-50.45s"       /* Path         */
		"%-10.10s"       /* Result       */
		" %-7.7s",       /* Details      */
		"Process name", "PID", "Operation", "Path", "Result", "Details");

	wrefresh(header_box);

	win_data_box = create_newwin(win_data_box_height, win_data_box_width, win_data_box_starty, win_data_box_startx);
	win_data = create_newwin(win_data_height, win_data_width, win_data_starty, win_data_startx);

	wclear(win_data);
	wrefresh(win_data);
}
示例#2
0
文件: gfx.c 项目: norips/projetEPP
void erase_game(game newGame, WINDOW *my_win, WINDOW **car, WINDOW *score)
{
    destroy_win(my_win); /*Destroy window    */
    for (int i = 0; i < game_nb_pieces(newGame); i++) /*to create new one */
        destroy_win(car[i]); /*                  */
    destroy_win(score); /*                  */
}
示例#3
0
文件: main.c 项目: SGOrava/Miny
void restart_prepare (WINDOW *my_win, WINDOW *info_win, WINDOW *smyle_win, int sirka, int vyska) {
	/* Lokálne premenné */
	int i, j;


	/* postupne prejde všetky políčka hracieho poľa a všetko vynuluje */
	for (i = 0; i < sirka; i++) {
		for (j = 0; j < vyska; j++) {
			/* Vymazanie mín z hracieho poľa */
			min_pole[i][j] = 0;

			/* Vymazanie označenia políčok */
			uhadol[i][j] = 0;

			/* Vymazanie vypočítaných mín okolo políčka */
			pole_hodnot[i][j] = 0;
		}
	}


	/* Uvoľnenie pridelenej amäte */
	uvolni_pamet(sirka);


	/* Zrušenie vytvorených okien */
	destroy_win(my_win);
	destroy_win(info_win);
	destroy_win(smyle_win);


	/* Vymazanie hlavného okna, refresh hlavného okna */
	clear();
	refresh();
}
示例#4
0
文件: e.c 项目: erich0929/programming
int main(void)
{
	WINDOW *wnd;
	int x,y,width,height;
	int ch;

	initscr ();
	cbreak ();
	nodelay (stdscr, TRUE);
	keypad (stdscr, TRUE);

	height = 3;
	width = 10;
/*	y = (LINES - height) / 2; 
	x = (COLS - width) / 2; */
	y = 10;
	x = 10;
	printw ("Press F1 to exit x: %d, y: %d", x ,y);
	refresh ();
	wnd = create_newwin (height, width, x, y);

	while ((ch = getch ()) != KEY_F(1)) {
		if (ch == ERR) {
			wmove (wnd, 1, 1);
			usleep (99000);
			wprintw (wnd, "%d%d%d", rand()%10, rand()%10, rand()%10);
			wrefresh (wnd);	
		}
		else {	
			switch (ch) {
					case KEY_LEFT:
							destroy_win (wnd);
							wnd = create_newwin (height, width, y, --x);
							break;
					case KEY_UP :
							destroy_win (wnd);
							wnd = create_newwin (height, width, --y, x);
							break;
					case KEY_DOWN :
							destroy_win (wnd);
							wnd = create_newwin (height, width, ++y, x);
							break;
					case KEY_RIGHT :
							destroy_win (wnd);
							wnd = create_newwin (height, width, y, ++x);
							break;
			}
		}
	}

	endwin ();
	return 0;
}
示例#5
0
//THIS CREATES ALL THE ENEMIES AND DROPS ALL ENEMIES ONE UNIT DOWN. ALSO CHECKS FOR PLAYER DEATH CONDITION
int drop_enemy(int *address_score,int player_y,int player_x)
{
	//increases the score
	(*address_score)++;
	time_t t;
	//this is an array of windows where each enemy is represented by a window
	static WINDOW *enemies[100];
	static int enemy_num=0;
	static int i=0;
	int j,x,y;

	srand((unsigned) time(&t));
	
				   
	//just creating the enemies the first time (create 2 enemies at a time)   
	if (enemy_num<81)
	{
		enemies[enemy_num]=create_enemywin(0,rand()%COLS); 
		enemies[++enemy_num]=create_enemywin(0,rand()%COLS); 
		enemy_num++;
	}
	//after the enemies have been created for the first time
	else
	{
		//destroy the enemy windows when they reach the bottom of the screen and recreate them at random positions at the top (2 at a time)
		destroy_win(enemies[i]);
		destroy_win(enemies[i+1]);
		enemies[i]=create_enemywin(0,rand()%COLS);  
		enemies[i+1]=create_enemywin(0,rand()%COLS);  
		i=i+2;
		if (i==80)
		{
			i=0;
		}
	}
	
	//move all enemy windows 2 spaces down by destroying them and recreating them 2 spaces down
	for (j=0;j<=enemy_num;j++)
	{
		getbegyx(enemies[j],y,x);
		//checks for player collision with enemies
		if ((player_x<x+7) && (player_x>x-5) && (player_y<=y+5) && (player_y>=y-3))
		{
			return 1;
		}
		destroy_win(enemies[j]);
		enemies[j]=create_enemywin(y+2,x); 
	}

	refresh();
	return 0;
}
示例#6
0
int main(int argc, char *argv[])
{
  WINDOW *my_win;
	int startx, starty, width, height;
	int ch;

	initscr();			/* Start curses mode 		*/
 	noecho();
	cbreak();			/* Line buffering disabled, Pass on
					 * everty thing to me 		*/
	keypad(stdscr, TRUE);		/* I need that nifty F1 	*/

	height = 3;
	width = 10;
	starty = (LINES - height) / 2;	/* Calculating for a center placement */
	startx = (COLS - width) / 2;	/* of the window		*/
	printw("Press F1 to exit");
	refresh();
	my_win = create_newwin(height, width, starty, startx);

	while((ch = getch()) != KEY_F(1))
	{
    switch(ch)
		{
      case KEY_LEFT:
      case 'h':
				destroy_win(my_win);
				my_win = create_newwin(height, width, starty,--startx);
				break;
			case KEY_RIGHT:
                        case 'l':
				destroy_win(my_win);
				my_win = create_newwin(height, width, starty,++startx);
				break;
			case KEY_UP:
                        case 'k':
				destroy_win(my_win);
				my_win = create_newwin(height, width, --starty,startx);
				break;
			case KEY_DOWN:
                        case 'j':
				destroy_win(my_win);
				my_win = create_newwin(height, width, ++starty,startx);
				break;
		}
	}

	endwin();			/* End curses mode		  */
	return 0;
}
示例#7
0
int main(int argc, char *argv[]) {


    init_ncurses();
    refresh();

    for (int i=0; i<NPILAS; i++)
      win[i] = create_newwin(H, W, 1, 1 + i * W);

    for (int i=0; i<NPILAS; i++)
	p[i] = create_stack(N);

    /* Inicializar */
    for (int i=N-1; i>=0; i--)
	push(i+1, p[0]);

    traslada(N, 0, 2);
   
    for (int i=0; i<NPILAS; i++)
	destroy_stack(p[i]);

    for (int i=0; i<NPILAS; i++)
	destroy_win(win[i]);
    end_ncurses();

    return EXIT_SUCCESS;
}
示例#8
0
void login_ncurses::input_name(char *name)
{
    WINDOW *login_win = NULL;
    int row = 0, col = 0;

    initscr();			/* Start curses mode 		  */
    cbreak();

    int height = 6;
    int width = 30;
    int starty = (LINES - height) / 2;
    int startx = (COLS - width) / 2;

    refresh();
    login_win = create_newwin(height, width, starty, startx);

    getmaxyx(login_win, row, col);
    mvwprintw(login_win, row/2, (col - 9 - 16)/2, "new player name: ");
    wrefresh(login_win);

    wattron(login_win, A_BOLD);
    wgetnstr(login_win, name, sizeof(name) - 1);
    wattroff(login_win, A_BOLD);

    destroy_win(login_win);
    refresh();
    endwin();
}
示例#9
0
void login_ncurses::input_account(char *account)
{
    WINDOW *login_win = NULL;
    int row = 0, col = 0;

    setlocale(LC_ALL,"");  // must before the first init
    initscr();
    cbreak();

    int height = 6;
    int width = 30;
    int starty = (LINES - height) / 2;
    int startx = (COLS - width) / 2;

    refresh();
    login_win = create_newwin(height, width, starty, startx);

    getmaxyx(login_win, row, col);
    mvwprintw(login_win, row/2, (col - 9 - 16)/2, "account: ");
    wrefresh(login_win);

    wattron(login_win, A_BOLD);
    wgetnstr(login_win, account, 31);
    wattroff(login_win, A_BOLD);

    destroy_win(login_win);
    refresh();
    endwin();
}
示例#10
0
int main(int argc, char ** argv)
{
    WINDOW * my_win;
    int startx, starty, width, height;
    int ch;

    initscr();
    cbreak(); // Line buffering disabled, Pass on everty thing to me
    keypad(stdscr, TRUE); // I need that nifty F1

    height = 3;
    width = 10;
    starty = (LINES - height) / 2; // Calculating for a center placement
    startx = (COLS  - width)  / 2; // of the window
    printw("Press F1 to exit");
    refresh();

    my_win = create_newwin(height, width, starty, startx);

    while ((ch = getch()) != KEY_F(1)) {
        switch (ch) {
        case KEY_LEFT:
            destroy_win(my_win);
            my_win = create_newwin(height, width, starty,--startx);
            break;

        case KEY_RIGHT:
            destroy_win(my_win);
            my_win = create_newwin(height, width, starty,++startx);
            break;

        case KEY_UP:
            destroy_win(my_win);
            my_win = create_newwin(height, width, --starty,startx);
            break;

        case KEY_DOWN:
            destroy_win(my_win);
            my_win = create_newwin(height, width, ++starty,startx);
            break;
        }
    }

    endwin();
    return 0;
}
示例#11
0
void wrapNcs::bye(){
 /*This method will replace exitEvent function*/
	int hIntro,wIntro,xIntro,yIntro;
	hIntro=LINES-10;
	wIntro=COLS-10;
	xIntro=(COLS-wIntro)/2;
	yIntro=(LINES-hIntro)/2;
	WINDOW *deco_w1=create_newwin(hIntro,wIntro,yIntro,xIntro);
	WINDOW *deco_w2=create_newwin(hIntro-4,wIntro-4,yIntro+2,xIntro+2);
	WINDOW *winText=create_newwinInv(hIntro-6,wIntro-6,yIntro+3,xIntro+3);
	wprintw(winText,"%s",str.c_str());
	wprintw(winText,"\nbye bye !! \nhit F2 key to finish\n");
	wrefresh(winText);
	while(getch()!=KEY_F(2)){}
	destroy_win(winText);
	destroy_win(deco_w1);
	destroy_win(deco_w2);
}
示例#12
0
int vuumuurconf_print_warning(const char *title, char *fmt, ...)
{
    va_list ap;
    char long_str[512] = "";

    WINDOW *err_win = NULL, *print_err_win = NULL;
    PANEL *my_panels[1];
    int height = 8, width, startx, starty, max_height, max_width;

    va_start(ap, fmt);
    vsnprintf(long_str, sizeof(long_str), fmt, ap);
    va_end(ap);

    getmaxyx(stdscr, max_height, max_width);
    width = (int)StrLen(long_str) + 15;
    if (width > max_width) {
        width = max_width - 10;
    }
    starty = (max_height - height) / 2;
    startx = (max_width - width) / 2;
    err_win = create_newwin(
            height, width, starty, startx, title, vccnf.color_win);
    assert(err_win);
    print_err_win = newwin(height - 4, width - 6, starty + 2, startx + 3);
    assert(print_err_win);
    wbkgd(print_err_win, vccnf.color_win);
    my_panels[0] = new_panel(err_win);
    keypad(err_win, TRUE);
    wprintw(print_err_win, "%s: %s", gettext("Warning"), long_str);
    mvwprintw(err_win, height - 2, 2, gettext("Press any key to continue..."));
    update_panels();
    doupdate();

    (void)wgetch(print_err_win);

    del_panel(my_panels[0]);
    destroy_win(print_err_win);
    destroy_win(err_win);
    update_panels();
    doupdate();
    return (0);
}
示例#13
0
文件: example7.c 项目: firisu/sandbox
int main(int argc, char *argv[]) {
	WINDOW *my_win;
	int startx, starty, width, height;
	int ch;

	initscr();
	cbreak();

	keypad(stdscr, TRUE);

	height = 3;
	width = 10;
	starty = (LINES - height) / 2;
	startx = (COLS - width) / 2;
	printw("Press F1 to exit");
	refresh();
	my_win = create_newwin(height, width, starty, startx);

	while ((ch = getch()) != KEY_F(1)) {
		switch(ch) {
			case KEY_LEFT:
				destroy_win(my_win);
				my_win = create_newwin(height, width, starty, --startx);
				break;
			case KEY_RIGHT:
				destroy_win(my_win);
				my_win = create_newwin(height, width, starty, ++startx);
				break;
			case KEY_UP:
				destroy_win(my_win);
				my_win = create_newwin(height, width, --starty, startx);
				break;
			case KEY_DOWN:
				destroy_win(my_win);
				my_win = create_newwin(height, width, ++starty, startx);
				break;
		}
	}

	endwin();
	return 0;
}
示例#14
0
/** A method to give a brief introduction and do some initialization*/
void wrapNcs::introduction(string text){
	int hIntro,wIntro,xIntro,yIntro;
	hIntro=LINES-10;
	wIntro=COLS-10;
	xIntro=(COLS-wIntro)/2;
	yIntro=(LINES-hIntro)/2;
	WINDOW *deco_w1=create_newwin(hIntro,wIntro,yIntro,xIntro);
	WINDOW *deco_w2=create_newwin(hIntro-4,wIntro-4,yIntro+2,xIntro+2);
	WINDOW *winText=create_newwinInv(hIntro-6,wIntro-6,yIntro+3,xIntro+3);
	wprintw(winText,"%s",text.c_str());
	wprintw(winText,"\nPlease Input:");
//	while(getch()!=KEY_RIGHT){}
	char temp[80];
	wgetstr(winText,temp);
	wrefresh(winText);
	str.assign(temp);
	destroy_win(winText);
	destroy_win(deco_w1);
	destroy_win(deco_w2);
	clear();
	refresh();
	
}
示例#15
0
static int
trafvol_section_destroy(void)
{
    size_t  i = 0;

    // Un post form and free the memory
    unpost_form(TrafVolSection.form);
    free_form(TrafVolSection.form);

    for(i = 0; i < TrafVolSection.n_fields; i++)
    {
        free_field(TrafVolSection.fields[i]);
    }
    free(TrafVolSection.fields);

    del_panel(TrafVolSection.panel[0]);
    destroy_win(TrafVolSection.win);

    return(0);
}
示例#16
0
文件: filter.c 项目: ewf75/vuurmuur
int
filter_input_box(const int debuglvl, struct vrmr_filter *filter)
{
    WINDOW  *ib_win = NULL;
    PANEL   *my_panels[1];
    FIELD   *cur = NULL,
            *prev = NULL;
    FORM    *my_form = NULL;
    int     height = 0,
            width = 0,
            startx = 0,
            starty = 0,
            max_height = 0,
            max_width = 0,
            ch = 0,
            rows = 0,
            cols = 0,
            quit = 0;
    size_t  i = 0;
    char    not_defined = FALSE;

    /* init fields */
    memset(&FiFi, 0, sizeof(struct FilterFields_));

    /* set the window size */
    getmaxyx(stdscr, max_height, max_width);
    height = 9;
    width = 48;

    /* print on the center of the screen */
    starty = (max_height - height) / 2;
    startx = (max_width - width) / 2;

    /* create window */
    ib_win = create_newwin(height, width, starty, startx, gettext("Filter"), vccnf.color_win);
    if(ib_win == NULL)
    {
        vrmr_error(-1, VR_ERR, gettext("creating window failed."));
        return(-1);
    }

    my_panels[0] = new_panel(ib_win);
    if(my_panels[0] == NULL)
    {
        vrmr_error(-1, VR_ERR, gettext("creating panel failed."));
        return(-1);
    }

    FiFi.n_fields = 2;

    FiFi.fields = (FIELD **)calloc(FiFi.n_fields + 1, sizeof(FIELD *));
    if(FiFi.fields == NULL)
    {
        vrmr_error(-1, VR_ERR, gettext("calloc failed: %s (in: %s:%d)."),
                                strerror(errno), __FUNC__, __LINE__);
        return(-1);
    }

    FiFi.string_fld = (FiFi.fields[0] = new_field(1, 31, 3,  4, 0, 0));
    FiFi.check_fld = (FiFi.fields[1]  = new_field(1,  1, 5,  5, 0, 0));

    set_field_back(FiFi.string_fld, vccnf.color_win_rev);
    field_opts_off(FiFi.string_fld, O_AUTOSKIP);
    set_field_status(FiFi.string_fld, FALSE);
    set_field_buffer_wrap(debuglvl, FiFi.string_fld, 0, filter->str);


    set_field_back(FiFi.check_fld, vccnf.color_win);
    field_opts_off(FiFi.check_fld, O_AUTOSKIP);
    set_field_status(FiFi.check_fld, FALSE);
    set_field_buffer_wrap(debuglvl, FiFi.check_fld, 0, filter->neg ? "X" : " ");

    my_form = new_form(FiFi.fields);
    scale_form(my_form, &rows, &cols);
    keypad(ib_win, TRUE);
    set_form_win(my_form, ib_win);
    set_form_sub(my_form, derwin(ib_win, rows, cols, 1, 2));
    post_form(my_form);

    /* XXX: we really should have a wrapper function to just print
     * in the middle of a window to prevent hacks like this. */
    char *s = gettext("Enter filter (leave empty for no filter)");
    mvwprintw(ib_win, 2, (width - StrLen(s))/2, s);
    mvwprintw(ib_win, 6, 6, "[");
    mvwprintw(ib_win, 6, 8, "]");
    mvwprintw(ib_win, 6, 11, gettext("show lines that don't match"));

    update_panels();
    doupdate();

    if(!(cur = current_field(my_form)))
    {
        vrmr_error(-1, VR_INTERR, "NULL pointer (in: %s:%d).",
                                __FUNC__, __LINE__);
        return(-1);
    }

    while(quit == 0)
    {
        /* draw nice markers */
        draw_field_active_mark(cur, prev, ib_win, my_form, vccnf.color_win_mark|A_BOLD);

        not_defined = 0;

        /* get user input */
        ch = wgetch(ib_win);

        if(cur == FiFi.check_fld)
        {
            if(nav_field_toggleX(debuglvl, my_form, ch) < 0)
                not_defined = 1;
        }
        else if(cur == FiFi.string_fld)
        {
            if(nav_field_simpletext(debuglvl, my_form, ch) < 0)
                not_defined = 1;
        }
        else
        {
            not_defined = 1;
        }

        /* the rest is handled here */
        if(not_defined)
        {
            switch(ch)
            {
                case KEY_UP:

                    form_driver(my_form, REQ_PREV_FIELD);
                    form_driver(my_form, REQ_END_LINE);
                    break;

                case KEY_DOWN:
                case 9: // tab

                    form_driver(my_form, REQ_NEXT_FIELD);
                    form_driver(my_form, REQ_END_LINE);
                    break;

                case 10: // enter

                    if(cur == FiFi.check_fld)
                    {
                        quit = 1;
                    }
                    else
                    {
                        form_driver(my_form, REQ_NEXT_FIELD);
                        form_driver(my_form, REQ_END_LINE);
                    }
                    break;

                case 27:
                case KEY_F(10):
                case 'q':
                case 'Q':

                    quit = 1;
                    break;
            }
        }

        /* before we get the new 'cur', store cur in prev */
        prev = cur;
        if(!(cur = current_field(my_form)))
        {
            vrmr_error(-1, VR_INTERR, "NULL pointer (in: %s).", __FUNC__);
            return(-1);
        }

        /* draw and set cursor */
        wrefresh(ib_win);
        pos_form_cursor(my_form);
    }

    /* save here */
    if(filter_save(debuglvl, filter) < 0)
    {
        vrmr_error(-1, VR_ERR, gettext("setting filter failed."));
    }

    unpost_form(my_form);
    free_form(my_form);

    for(i=0; i < FiFi.n_fields; i++)
    {
        free_field(FiFi.fields[i]);
    }
    free(FiFi.fields);

    del_panel(my_panels[0]);
    destroy_win(ib_win);

    update_panels();
    doupdate();

    return(0);
}
void Draft::makeBoard(Team *arr, vector<NodeData*>& a, int teams) {
	int sY = 8, sX = 0, w = 14, h = 4, ch, j = 0, z = 0;
	string tName;			
	WINDOW *board[BOARD_SIZE]; //timer + players + menu  + roster + titles +    title +    teams(2)
					   //ar[34]  arr[33]   ar[32]  ar[31]   arr[20-29]    ar[30]  ar[0-19]

	initscr();											//start curses
	cbreak();											//line buffer off
	keypad(stdscr, TRUE);								//to use f1
	printw("Press cntr+c to exit");						//print 
	refresh();											//output

	board[TITLE] = createWin(4, 100, 1, 0);				//title
	wattron(board[TITLE], A_BOLD);
	mvwprintw(board[TITLE], 1, 10, "John Zoeller Draft");	//print T
	wrefresh(board[TITLE]);								//output

	board[34] = createWin(4, 40, 1, 101);				//timer
	wattron(board[34], A_BOLD);
	mvwprintw(board[34], 1, 1, "ROUND");				//print time
	wrefresh(board[34]);								//output

	for(int k = 0; k < 10; k++){						//team names
		board[k + 20] = createWin(3, 14, 5, (sX + (w * k)));
		wattron(board[k + 20], A_BOLD);	

		if(arr[k].getUser()){
			tName = to_string(arr[k].getPosition()) + " " + arr[k].getName();
			wattron(board[k + 20], A_UNDERLINE);
		} else
			tName = to_string(k + 1) + " Auto";

		mvwprintw(board[k + 20], 1, 1, tName.c_str());
		wrefresh(board[k + 20]);
	} 

	for(int i = 0; i < 10; i++)
		board[i] = createWin(h, w, (sY + (h * j)), (sX + (w * i)));

	j++;

	for(int a = 19; a >= 10; a--){
		board[a] = createWin(h, w, (sY + (h * j)), (sX + (w * z)));
		z++;
	}

	int dims[] = { 22, 45, 16, 0 };
	makeWindow("PLAYERS", dims, PLAYERS_AVAILABLE);


	board[33] = createWin(22, 45, 16, 0);				//players
	wattron(board[33], A_BOLD);
	mvwprintw(board[33], 1, 1, "PLAYERS");				//print title
	wattroff(board[33], A_BOLD);
	wrefresh(board[33]);								//output

	board[32] = createWin(10, 45, 16, 46);				//menu
	wattron(board[32], A_BOLD);
	mvwprintw(board[32], 1, 1, "MENU");					//print title
	wattroff(board[32], A_BOLD);
	wrefresh(board[32]);								//output

	board[31] = createWin(22, 45, 16, 92);				//roster
	wattron(board[31], A_BOLD);
	mvwprintw(board[31], 1, 1, "MY ROSTER");				//print title
	wattroff(board[31], A_BOLD);
	wrefresh(board[31]);								//output

	while((ch = getch()) != KEY_F(1)){					//drafting
		startDraft(arr, a, teams, board);
	}

	for(int i = 0; i < 35; i++){						//delete windows
		if(board[i] != NULL)
			destroy_win(board[i]);
	}

	endwin();
}
示例#18
0
int main(int argc, char *argv[])
{
    // Initial values
    WINDOW *title_win;  // Title window pointer
    FORM   *title_form;


    int row, col;

    // Start screen
    initscr();
    clear();
    noecho();
    cbreak();

    if (has_colors() == TRUE)   // Test if terminal has color
        start_color();

    getmaxyx(stdscr, row, col);

    // Check if terminal is a proper size
    if (row < MIN_HEIGHT || col < MIN_WIDTH) {
        char term_size_err1[] = "Your terminal is too small!";
        char term_size_err2[] = "Resize and try again.";
        mvprintw(row / 2 - 1, (col - strlen(term_size_err1)) / 2, "%s", term_size_err1);
        mvprintw(row / 2    , (col - strlen(term_size_err2)) / 2, "%s", term_size_err2);
        getch();
        endwin();
        return 0;
    }

    
    // Header
    header(col);

    // Staffs
    staff(row, col);
    refresh();

    // Title Window
    int startx = (col - TITLE_WINDOW_WIDTH) / 2;
    int starty = (row - TITLE_WINDOW_HEIGHT) / 2;
    
    title_win = title_info_win(TITLE_WINDOW_HEIGHT, TITLE_WINDOW_WIDTH, starty, startx);
    keypad(title_win, true);

    int x_mins[8] = {
                        WIN_X_BUFFER + strlen("Project Title: "),
                        WIN_X_BUFFER + strlen("Song Title: "),
                        WIN_X_BUFFER + strlen("Artist:     "),
                        WIN_X_BUFFER + strlen("Tabbed by:  "),
                        WIN_X_BUFFER + strlen("Email:      "),
                        WIN_X_BUFFER + strlen("Number of Strings: "),
                        WIN_X_BUFFER + strlen("Tuning: (1)"),
                        TITLE_WINDOW_WIDTH - WIN_X_BUFFER - strlen("OK") - strlen("CANCEL") - 9,
                    };

    
    
    /* Input fields for windows */
    fields[0] = new_field(1, TITLE_WINDOW_WIDTH - x_mins[0] - 2 * WIN_X_BUFFER, WIN_Y_BUFFER + WIN_HEADER     , x_mins[0], 0, 0); 
    fields[1] = new_field(1, TITLE_WINDOW_WIDTH - x_mins[1] - 2 * WIN_X_BUFFER, WIN_Y_BUFFER + WIN_HEADER + 4 , x_mins[1], 0, 0); 
    fields[2] = new_field(1, TITLE_WINDOW_WIDTH - x_mins[2] - 2 * WIN_X_BUFFER, WIN_Y_BUFFER + WIN_HEADER + 6 , x_mins[2], 0, 0); 
    fields[3] = new_field(1, TITLE_WINDOW_WIDTH - x_mins[3] - 2 * WIN_X_BUFFER, WIN_Y_BUFFER + WIN_HEADER + 8 , x_mins[3], 0, 0); 
    fields[4] = new_field(1, TITLE_WINDOW_WIDTH - x_mins[4] - 2 * WIN_X_BUFFER, WIN_Y_BUFFER + WIN_HEADER + 10, x_mins[4], 0, 0); 
    fields[5] = new_field(1, 1                                                , WIN_Y_BUFFER + WIN_HEADER + 14, x_mins[5], 0, 0); 

    int i;
    for (i = 0; i < strings; i++)
        fields[6 + i]  = new_field(1, 2, WIN_Y_BUFFER + WIN_HEADER + 16, x_mins[6] + i * 6, 0, 0);

    for (i = 0; i < 8 - strings; i++)
        fields[6 + strings + i] = NULL;
    
    for (i = 0; i < 12; i++) {  // Needs to be able to change with string change
        set_field_back(fields[i], A_UNDERLINE);
        field_opts_off(fields[i], O_AUTOSKIP);
    }

    
    /* Create the title window form */
    set_form_win(title_form, title_win);
    title_form = new_form(fields);
    post_form(title_form);
    refresh();

    int movements[8][2] = {
                            {WIN_Y_BUFFER + WIN_HEADER      , x_mins[0]},
                            {WIN_Y_BUFFER + WIN_HEADER + 4  , x_mins[1]},
                            {WIN_Y_BUFFER + WIN_HEADER + 6  , x_mins[2]},
                            {WIN_Y_BUFFER + WIN_HEADER + 8  , x_mins[3]},
                            {WIN_Y_BUFFER + WIN_HEADER + 10 , x_mins[4]},
                            {WIN_Y_BUFFER + WIN_HEADER + 14 , x_mins[5]},
                            {WIN_Y_BUFFER + WIN_HEADER + 16 , x_mins[6]},
                            {WIN_Y_BUFFER + WIN_HEADER + 20 , x_mins[7]},
                          };

    int y, x;

    wmove(title_win, movements[0][0], movements[0][1]);
    wrefresh(title_win);

    while (true) {
        ch = wgetch(title_win);
        getyx(title_win, y, x);
        if (ch ==  KEY_UP) {
            if (y == movements[7][0])
                move(movements[6][0], movements[6][1]);
            else if (y == movements[6][0] && x == movements[6][1]) {
                form_driver(title_form, REQ_PREV_FIELD);
                form_driver(title_form, REQ_END_LINE);
            } else if (y != movements[7][0] && y != movements[6][0]){
                form_driver(title_form, REQ_PREV_FIELD);
                form_driver(title_form, REQ_END_LINE);
            }
        } else if (ch == KEY_DOWN) {
            if (y == movements[6][0])
                move(movements[7][0], movements[7][1]);
            else if (y != movements[7][0] && y != movements[6][0]){
                form_driver(title_form, REQ_NEXT_FIELD);
                form_driver(title_form, REQ_END_LINE);
            }
        } else if (ch == KEY_LEFT) {
            if (y == movements[6][0]) {
                form_driver(title_form, REQ_PREV_FIELD);
                form_driver(title_form, REQ_END_LINE);
            } else if (y == movements[7][0] && x == (movements[7][1] + BUTTON_WIDTH)){  // Is at CANCEL button
                move(movements[7][0], movements[7][1]);
            }
        } else if (ch == KEY_RIGHT) {
            if (y == movements[6][0]) {
                form_driver(title_form, REQ_NEXT_FIELD);
                form_driver(title_form, REQ_END_LINE);
            } else if (y == movements[7][0] && x == movements[7][1]) {   // Is at OK button
                move(movements[7][0], movements[7][1] + BUTTON_WIDTH);
            }
        } else if (ch == '\n' && y == movements[7][0]) {
            if (x == movements[7][1]) { // OK
                continue;
            } else {    // CANCEL
                clear();
                endwin();
                break;
            }

        /* ch is a letter, number or special char */
        } else if (((ch >= 'a'&& ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9') ||
                    (ch >= 33 && ch <= 46) || ch == ' ' || ch == 64)) {
            form_driver(title_form, ch);
        }
    }


    getch();
    destroy_win(title_win);
    clear();
    refresh();
    getch();
    endwin();

    return 0;
}
示例#19
0
文件: cpext.c 项目: rinukkusu/cpext
void cleanup()
{
	destroy_win(my_window);
	endwin();
}
示例#20
0
文件: help.c 项目: ewf75/vuurmuur
void
print_list(const int debuglvl, struct vrmr_list *list, char *title, int height,
        int width, int starty, int startx, char utf8)
{
    WINDOW      *boxwin = NULL,
                *printwin = NULL;
    PANEL       *panel[2];
    int         ch;

    helpword    *hw = NULL;
    size_t      start_print = 1,
                end_print = 1;
    char        done = 0;
    int         i = 0;
    size_t      size = 0;


    end_print = (size_t)height - 2;

    if(!(boxwin = create_newwin(height, width, starty, startx, title, vccnf.color_win)))
    {
        vrmr_error(-1, VR_ERR, "could not create window (in: %s:%d).", __FUNC__, __LINE__);
        return;
    }
    if(!(panel[0] = new_panel(boxwin)))
    {
        vrmr_error(-1, VR_ERR, "could not create panel (in: %s:%d).", __FUNC__, __LINE__);
        return;
    }
    if(!(printwin = newwin(height-2, width-4, starty+1, startx+2)))
    {
        vrmr_error(-1, VR_ERR, "could not create window (in: %s:%d).", __FUNC__, __LINE__);
        return;
    }
    (void)wbkgd(printwin, vccnf.color_win);
    if(!(panel[1] = new_panel(printwin)))
    {
        vrmr_error(-1, VR_ERR, "could not create panel (in: %s:%d).", __FUNC__, __LINE__);
        return;
    }
    keypad(printwin, TRUE);

    size = StrLen(gettext("Press <F10> to close this window."));

    mvwprintw(boxwin, height-1, (int)(width-size)/2, " %s ", gettext("Press <F10> to close this window."));
    wrefresh(boxwin);

    while(!done)
    {
        werase(printwin);

        if(list->len == 0)
        {
            wprintw(printwin, gettext("The requested helptext was not found.\n"));
        }

#ifdef USE_WIDEC
        if(utf8 == UTF8_TRUE)
            do_wide_print(debuglvl, printwin, list, start_print,
                    end_print);
        else
#endif /* USE_WIDEC */
            do_print(debuglvl, printwin, list, start_print,
                    end_print);

        update_panels();
        doupdate();

        /* get user input */
        ch = wgetch(printwin);

        switch(ch)
        {
            case KEY_DOWN:

                if(list->len > 0)
                {
                    if(!(hw = list->bot->data))
                    {
                        vrmr_error(-1, VR_INTERR, "NULL pointer (in: %s:%d).", __FUNC__, __LINE__);
                        return;
                    }

                    if(end_print < hw->line_num)
                    {
                        start_print++;
                        end_print++;
                    }
                }
                break;

            case KEY_UP:

                if(list->len > 0)
                {
                    if(start_print > 1)
                    {
                        start_print--;
                        end_print--;
                    }
                }
                break;
        
            case KEY_PPAGE:

                if(list->len > 0)
                {
                    i = (height - 2)/3;

                    while((start_print - i) < 1)
                        i--;

                    start_print = start_print - i;
                    end_print = end_print - i;
                }

                break;

            case KEY_NPAGE:

                if(list->len > 0)
                {
                    i = (height - 2)/3;

                    if(!(hw = list->bot->data))
                    {
                        vrmr_error(-1, VR_INTERR, "NULL pointer (in: %s:%d).", __FUNC__, __LINE__);
                        return;
                    }

                    while((end_print + i) > hw->line_num)
                        i--;

                    start_print = start_print + i;
                    end_print = end_print + i;
                }

                break;

            default:

                done = 1;
                break;
        }
    }

    del_panel(panel[0]);
    del_panel(panel[1]);
    destroy_win(printwin);
    destroy_win(boxwin);

    update_panels();
    doupdate();
    return;
}
示例#21
0
int Login_win()
{
    const char title[] = "中国人民银行现代化支付系统";
    const char opermesg[]="柜员号:";		/* message to be appeared on the screen */
    const char pwdmesg[]= "密码  :";
 
    int row,col;				/* to store the number of rows and *
                                          * the number of colums of the screen */
    char id[USR_LEN + 1];
    char pwd[PASSWORD_LEN + 1];
    char ch;
    int ret(0);

    initscr();				/* start the curses mode */
    getmaxyx(stdscr,row,col);		/* get the number of rows and columns */
 
    WINDOW * loginwin;
    loginwin = main_win();
 
    mvwprintw(loginwin,row/2 - 3,(col-strlen(title))/2,"%s",title);
    mvwprintw(loginwin,row/2,(col-strlen(opermesg))/2 - 2,"%s",opermesg);/* print the message at the center of the screen */
    mvwprintw(loginwin,row/2 + 2,(col-strlen(pwdmesg))/2 - 2,"%s",pwdmesg);/* print the message at the center of the screen */     
 
    wrefresh(loginwin);
    raw();
    noecho();    //当执行wgetch()函数的时候关闭键盘回显
    
    keypad(loginwin,TRUE);
    
    string login_id;

    const char * strSQL = "select pwd,operid from operinfo where operid = '000001' ";

    db2_exec_query(oper , strSQL);

    do
    {
	clear_line(loginwin,row/2,(col-strlen(opermesg))/2 + 6,USR_LEN);
	read_line(loginwin,id,USR_LEN,0);
	 
        ret = check_operid(id);
	 
        if(ret == -2)
        {
            show_msg(loginwin,"Importation is NULL,input again");
            continue;
        }
  	else if(ret == -1)
        {
            show_msg(loginwin,"The format importation is wrong,input 0-9 digit");
            continue;
        }

        login_id.assign(id);

        if( !(oper.operid == login_id) )
        {
            mvwprintw(loginwin,LINES - 2,0,"User ID is not exist,Please press any key to continue");
            wrefresh(loginwin);
            wgetch(loginwin);
            clear_line(loginwin,LINES - 2,0,100);
			
            continue;
        }
        else
            break;
    }while(1);
    
    //refresh();
    int ret1(0);  

    do
    {
        clear_line(loginwin,row/2 + 2,(col-strlen(pwdmesg))/2 + 6,PASSWORD_LEN);
        read_line(loginwin,pwd,PASSWORD_LEN,1);
	wrefresh(loginwin);
        
        //ret1 = check_operpwd(pwd);
	 
        //if(ret1 == -1)
        //{
        //    show_msg(loginwin,"Input Invalid,Please press any key to continue");
        //    continue;
        //}

        GetOperPasswdMd5(pwd);

        mvwprintw(loginwin,LINES - 4, 0, "1 md5: %s ",operpwd.c_str());
        mvwprintw(loginwin,LINES - 5, 0, "2 md5: %s ",oper.pwd);
        
        if( !(oper.pwd == operpwd) )
        {
            clear_line(loginwin,LINES - 2,0,100);
                mvwprintw(loginwin,LINES - 2,0,"User Passwd is invalid,Please press any key to continue");
                    clear_line(loginwin,LINES - 2,0,100);
                        read_line(loginwin,pwd,PASSWORD_LEN,1);
        
            continue;
        }
        else
        {
            break;
        }
    }while(1);
    //clear_line(loginwin,LINES - 2,0,100);
    //mvwprintw(loginwin,LINES - 2, 0, "操作员 %s 签到成功...",id);   

    wrefresh(loginwin);

    destroy_win(loginwin);

    clear_win(stdscr,0,0,24,80);  //多窗口操作清窗口操作
    wrefresh(stdscr);
    endwin();
    return 0;
}
示例#22
0
/*

    returns 1 if yes, 0 if no
*/
int confirm(const char *title, const char *text, chtype forecolor,
        chtype backcolor, int def)
{
    int retval = 0;
    ITEM **menu_items;
    MENU *confirm_menu;
    PANEL *my_panels[1];
    WINDOW *confirm_win, *dw;
    ITEM *cur;

    int height = 7, width = 25, startx = 5, starty = 5, max_x = 0, max_y = 0;
    const char *choices[] = {STR_YES, STR_NO};

    size_t n_choices = 2, i = 0;

    int ch, quit = 0;

    char *print_title;

    /* safety */
    vrmr_fatal_if_null(title);
    vrmr_fatal_if_null(text);

    if (width - 4 < (int)StrLen(text))
        width = (int)StrLen(text) + 4;
    if (width - 6 < (int)StrLen(title))
        width = (int)StrLen(title) + 6;
    getmaxyx(stdscr, max_y, max_x);
    startx = (max_x - width) / 2;
    starty = (max_y - height) / 2;

    print_title = malloc(StrMemLen(title) + 3);
    vrmr_fatal_alloc("malloc", print_title);
    snprintf(print_title, StrMemLen(title) + 3, " %s ", title);

    menu_items = (ITEM **)calloc(n_choices + 1, sizeof(ITEM *));
    vrmr_fatal_alloc("calloc", menu_items);
    for (i = 0; i < n_choices; ++i) {
        menu_items[i] = new_item(choices[i], NULL);
    }
    menu_items[n_choices] = (ITEM *)NULL;
    confirm_menu = new_menu((ITEM **)menu_items);
    vrmr_fatal_if_null(confirm_menu);
    confirm_win = newwin(height, width, starty, startx);
    wbkgd(confirm_win, backcolor);
    keypad(confirm_win, TRUE);
    wrefresh(confirm_win);
    my_panels[0] = new_panel(confirm_win);
    set_menu_win(confirm_menu, confirm_win);
    dw = derwin(confirm_win, height - 4, 10, 4, (width) / 2 - 5);
    set_menu_sub(confirm_menu, dw);
    set_menu_format(confirm_menu, height - 4, 2);
    box(confirm_win, 0, 0);
    print_in_middle(confirm_win, 0, 0, width, print_title, backcolor);
    print_in_middle(confirm_win, 2, 0, width, text, backcolor);
    set_menu_back(confirm_menu, backcolor);
    set_menu_fore(confirm_menu, forecolor);
    post_menu(confirm_menu);

    /* set the cursor to the 'no' position */
    if (!def) {
        menu_driver(confirm_menu, REQ_RIGHT_ITEM);
    }
    update_panels();
    doupdate();

    while (quit == 0) {
        ch = wgetch(confirm_win);
        switch (ch) {
            case KEY_DOWN:
                menu_driver(confirm_menu, REQ_LEFT_ITEM);
                break;
            case KEY_UP:
                menu_driver(confirm_menu, REQ_RIGHT_ITEM);
                break;
            case KEY_LEFT:
                menu_driver(confirm_menu, REQ_LEFT_ITEM);
                break;
            case KEY_RIGHT:
                menu_driver(confirm_menu, REQ_RIGHT_ITEM);
                break;

            case 10: // enter
            {
                cur = current_item(confirm_menu);
                vrmr_fatal_if_null(cur);
                if (strcmp((char *)item_name(cur), STR_YES) == 0) {
                    retval = 1;
                }
                quit = 1;
                break;
            }

            case 'y':
            case 'Y':
                retval = 1;
                quit = 1;
                break;

            case 'n':
            case 'N':
                retval = 0;
                quit = 1;
                break;

            case 27:
            case KEY_F(10):
            case 'q':
            case 'Q':
                quit = 1;
                break;
        }
    }

    unpost_menu(confirm_menu);
    free_menu(confirm_menu);
    for (i = 0; i < n_choices; ++i)
        free_item(menu_items[i]);
    free(menu_items);
    destroy_win(dw);
    del_panel(my_panels[0]);
    destroy_win(confirm_win);
    free(print_title);
    update_panels();
    doupdate();
    return (retval);
}
示例#23
0
Console::~Console(void) {
    running = false;
    destroy_win(cmd_window);
    destroy_win(chat_window);
    endwin();
}
示例#24
0
char *input_box(size_t length, const char *title, const char *description)
{
    WINDOW *ib_win = NULL;
    PANEL *my_panels[1];
    FIELD **fields;
    FORM *my_form = NULL;
    int height, width, startx, starty, max_height, max_width, ch = 0, rows,
                                                              cols, quit = 0, i;
    char *result_ptr = NULL, *temp_ptr = NULL;

    /* create a buffer with the size of 'length' */
    if (!(temp_ptr = malloc(length))) {
        vrmr_error(-1, VR_ERR, gettext("malloc failed: %s"), strerror(errno));
        return (NULL);
    }

    // set the window size
    getmaxyx(stdscr, max_height, max_width);
    height = 8;
    if (length < 16) {
        width = 37; // minimum TODO: why 37?
    } else if ((int)length + 8 > max_width) {
        free(temp_ptr);
        return NULL;
    } else {
        width = (int)length + 8;
        if ((int)StrLen(title) + 8 > width)
            width = (int)StrLen(title) + 8;
        if ((int)StrLen(description) + 8 > width)
            width = (int)StrLen(description) + 8;
    }
    // print on the centre of the screen
    starty = (max_height - height) / 2;
    startx = (max_width - width) / 2;

    // create window
    ib_win = create_newwin(
            height, width, starty, startx, title, vccnf.color_win);
    my_panels[0] = new_panel(ib_win);
    fields = (FIELD **)calloc(1 + 1, sizeof(FIELD *));
    fields[0] = new_field_wrap(
            1, (int)length - 1, 3, (int)(((width - length) / 2) - 2), 0, 0);
    set_field_back(fields[0], vccnf.color_win_rev);
    field_opts_off(fields[0], O_AUTOSKIP);
    set_field_status(fields[0], FALSE);
    my_form = new_form(fields);
    scale_form(my_form, &rows, &cols);
    keypad(ib_win, TRUE);
    set_form_win(my_form, ib_win);
    set_form_sub(my_form, derwin(ib_win, rows, cols, 1, 2));
    post_form(my_form);

    mvwprintw(ib_win, 2, 4, "%s", description);
    mvwprintw(ib_win, 6, 4, gettext("Note: whitespaces not allowed."));

    update_panels();
    doupdate();

    while (quit == 0) {
        ch = wgetch(ib_win);
        switch (ch) {
            case 27:
            case KEY_F(10):
            case 10: // enter
                // Go to next field
                form_driver_wrap(my_form, REQ_NEXT_FIELD);
                form_driver_wrap(my_form, REQ_END_LINE);
                quit = 1;
                break;
            case KEY_BACKSPACE:
            case 127:
                form_driver_wrap(my_form, REQ_PREV_CHAR);
                form_driver_wrap(my_form, REQ_DEL_CHAR);
                form_driver_wrap(my_form, REQ_END_LINE);
                break;
            case KEY_DC:
                form_driver_wrap(my_form, REQ_PREV_CHAR);
                form_driver_wrap(my_form, REQ_DEL_CHAR);
                form_driver_wrap(my_form, REQ_END_LINE);
                break;
            default:
                // If this is a normal character, it gets printed
                form_driver_wrap(my_form, ch);
                break;
        }
    }

    // status_print(status_win, "data: '%s' (%d)", field_buffer(fields[0], 0),
    // length);
    (void)strlcpy(temp_ptr, field_buffer(fields[0], 0), length);

    // get the length of the entry
    i = strlen(temp_ptr);
    while (i--) {
        if (isspace(temp_ptr[i]))
            temp_ptr[i] = '\0';
        else
            break;
    }

    if (!(result_ptr = strdup(temp_ptr))) {
        vrmr_error(-1, VR_ERR, gettext("malloc failed: %s"), strerror(errno));
        goto end;
    }

    if (result_ptr[0] == '\0') {
        free(result_ptr);
        result_ptr = NULL;
    }

end:
    free(temp_ptr);
    unpost_form(my_form);
    free_form(my_form);
    free_field(fields[0]);
    free(fields);
    del_panel(my_panels[0]);
    destroy_win(ib_win);
    update_panels();
    doupdate();
    return (result_ptr);
}
示例#25
0
int main(int argc, char *argv[])
{
    struct vrmr_ctx vctx;

    int retval = 0, optch = 0;

    static char optstring[] = "c:d:hVW";
    struct option long_options[] = {
            {"configfile", required_argument, NULL, 'c'},
            {"debug", required_argument, NULL, 'd'},
            {"help", no_argument, NULL, 'h'},
            {"version", no_argument, NULL, 'V'},
            {"wizard", no_argument, NULL, 'W'},
            {0, 0, 0, 0},
    };
    int longopt_index = 0;

    int debug_level = NONE;
    PANEL *main_panels[5];
    char *s = NULL;

    /* some defaults */
    vuurmuur_semid = -1;
    vuurmuur_shmid = -1;
    vuurmuurlog_semid = -1;
    vuurmuurlog_shmid = -1;

    /* create the version string */
    snprintf(version_string, sizeof(version_string),
            "%s (using libvuurmuur %s)", VUURMUURCONF_VERSION,
            libvuurmuur_get_version());

    /* some initilization */
    if (vrmr_init(&vctx, "vuurmuur_conf") < 0)
        exit(EXIT_FAILURE);

    /* settings file */
    memset(vccnf.configfile_location, 0, sizeof(vccnf.configfile_location));
    if (vctx.conf.etcdir[0] == '\0')
        (void)strlcpy(vccnf.configfile_location, VUURMUURCONF_CONFIGFILE,
                sizeof(vccnf.configfile_location));
    else
        (void)snprintf(vccnf.configfile_location,
                sizeof(vccnf.configfile_location),
                "%s/vuurmuur/vuurmuur_conf.conf", vctx.conf.etcdir);

#ifdef ENABLE_NLS
    setlocale(LC_ALL, "");
    setlocale(LC_TIME, "");
    setlocale(LC_MESSAGES, "");
    setlocale(LC_COLLATE, "");
    setlocale(LC_CTYPE, "");
    setlocale(LC_MONETARY, "");
    setlocale(LC_NUMERIC, "");
#endif

    /* check if we are in utf-8 mode */
    utf8_mode = 0;

    if ((s = getenv("LC_ALL")) || (s = getenv("LC_CTYPE")) ||
            (s = getenv("LANG"))) {
        if (strstr(s, "UTF-8"))
            utf8_mode = 1;
    }

#ifdef ENABLE_NLS
    bindtextdomain("vuurmuur", xstr(VRMR_LOCALEDIR));
    textdomain("vuurmuur");
#endif

    /* process commandline options */
    while ((optch = getopt_long(argc, argv, optstring, long_options,
                    &longopt_index)) != -1) {
        switch (optch) {
            case 'h':
                print_commandline_args();
                break;

            /* configfile */
            case 'c':

                if (strlcpy(vctx.conf.configfile, optarg,
                            sizeof(vctx.conf.configfile)) >=
                        sizeof(vctx.conf.configfile)) {
                    vrmr_error(EXIT_FAILURE, VR_ERR,
                            gettext("commandline argument too long for option "
                                    "-c."));
                    exit(EXIT_FAILURE);
                }
                break;

            case 'd':

                /* convert the debug string and check the result */
                debug_level = atoi(optarg);
                if (debug_level < 0 || debug_level > HIGH) {
                    vrmr_error(EXIT_FAILURE, VR_ERR,
                            gettext("commandline debuglevel out of range."));
                    exit(EXIT_FAILURE);
                }
                vrmr_debug_level = debug_level;

                fprintf(stdout, "vuurmuur_conf: debugging enabled.\n");
                fprintf(stdout, "vuurmuur_conf: debug level: %d\n",
                        debug_level);
                break;

            case 'V':
                /* print version */
                fprintf(stdout, "Vuurmuur_conf %s\n", version_string);
                fprintf(stdout, "%s\n", VUURMUUR_COPYRIGHT);

                exit(EXIT_SUCCESS);

            case 'W': {
                char wizard_path[512] = "";
                snprintf(wizard_path, sizeof(wizard_path),
                        "%s/scripts/vuurmuur-wizard.sh", vctx.conf.datadir);
                printf("Running %s...\n", wizard_path);
                exec_wizard(wizard_path);
                exit(EXIT_SUCCESS);
            }
            default:

                vrmr_error(EXIT_FAILURE, VR_ERR,
                        gettext("unknown commandline option."));
                exit(EXIT_FAILURE);
        }
    }

    /*  close the STDERR_FILENO because it gives us annoying "Broken
        Pipe" errors on some systems with bash3. Let's see if this
        has negative side-effects. */
    close(STDERR_FILENO);

    /* init vuurmuur_conf config already to get background */
    (void)init_vcconfig(&vctx.conf, vccnf.configfile_location, &vccnf);

    /* Initialize curses */
    (void)initscr();
    (void)start_color();
    (void)cbreak();
    (void)noecho();
    (void)keypad(stdscr, (bool)TRUE);

    setup_colors();

    /* create the three main windows */
    if (!(status_frame_win = create_newwin(
                  3, COLS, LINES - 3, 0, NULL, vccnf.color_bgd)))
        exit(EXIT_FAILURE);
    if (!(status_win = create_newwin(
                  1, COLS - 4, LINES - 2, 2, NULL, vccnf.color_bgd)))
        exit(EXIT_FAILURE);
    if (!(top_win = create_newwin(3, COLS, 0, 0, NULL, vccnf.color_bgd)))
        exit(EXIT_FAILURE);
    if (!(main_win = create_newwin(
                  LINES - 6, COLS, 3, 0, NULL, vccnf.color_bgd)))
        exit(EXIT_FAILURE);
    if (!(mainlog_win = newwin(LINES - 8, COLS - 2, 4, 1)))
        exit(EXIT_FAILURE);

    (void)wbkgd(mainlog_win, vccnf.color_bgd);

    wattron(status_frame_win, vccnf.color_bgd);
    mvwprintw(status_frame_win, 0, 2, " %s ", gettext("Status"));
    mvwprintw(status_frame_win, 2,
            (int)(COLS - 4 - StrLen(vctx.user_data.realusername) - 6),
            " user: %s ", vctx.user_data.realusername);
    wattroff(status_frame_win, vccnf.color_bgd);

    /* Attach a panel to each window */
    main_panels[0] = new_panel(top_win);
    main_panels[1] = new_panel(main_win);
    main_panels[2] = new_panel(status_win);
    main_panels[3] = new_panel(mainlog_win);
    main_panels[4] = new_panel(status_frame_win);

    (void)update_panels();
    (void)doupdate();

    /* init the vrprint functions for the Gui */
    vrprint.error = vuumuurconf_print_error;
    vrprint.warning = vuumuurconf_print_warning;
    vrprint.info = vuumuurconf_print_info;

    if (status_print(status_win, gettext("This is Vuurmuur_conf %s, %s"),
                version_string, VUURMUUR_COPYRIGHT) < 0)
        exit(EXIT_FAILURE);

    /* setup the global busywin */
    VrBusyWinCreate();
    VrBusyWinHide();

    // form_test();

    /* startup_screen inits the config, loads the zones, rules, etc */
    if (startup_screen(&vctx, &vctx.rules, &vctx.zones, &vctx.services,
                &vctx.interfaces, &vctx.blocklist, &vctx.reg) < 0) {
        /* failure! Lets quit. */

        /* delete panels and windows */
        (void)del_panel(main_panels[0]);
        (void)del_panel(main_panels[1]);
        (void)del_panel(main_panels[2]);
        (void)del_panel(main_panels[3]);
        (void)del_panel(main_panels[4]);
        (void)destroy_win(top_win);
        (void)destroy_win(main_win);
        (void)destroy_win(status_win);
        (void)destroy_win(status_frame_win);
        /* clear screen */
        (void)refresh();
        /* end ncurses mode */
        (void)endwin();

        exit(EXIT_FAILURE);
    }

    /* setup statuslist */
    (void)setup_statuslist();

    status_print(status_win, STR_READY);

    mm_status_checkall(&vctx, NULL, &vctx.rules, &vctx.zones, &vctx.interfaces,
            &vctx.services);
    /* main menu loop */
    while (main_menu(&vctx, &vctx.rules, &vctx.zones, &vctx.interfaces,
                   &vctx.services, &vctx.blocklist, &vctx.reg) == 1)
        ;
    /* clean up the status list */
    vrmr_list_cleanup(&vuurmuur_status.StatusList);

    /* detach from shared memory, if we were attached */
    if (vuurmuur_shmp != NULL && vuurmuur_shmp != (char *)(-1) &&
            vuurmuur_shmtable != 0) {
        if (vrmr_lock(vuurmuur_semid)) {
            vuurmuur_shmtable->configtool.connected = 3;
            vrmr_unlock(vuurmuur_semid);
        }
        (void)shmdt(vuurmuur_shmp);
    }
    if (vuurmuurlog_shmp != NULL && vuurmuurlog_shmp != (char *)(-1) &&
            vuurmuurlog_shmtable != 0) {
        if (vrmr_lock(vuurmuurlog_semid)) {
            vuurmuurlog_shmtable->configtool.connected = 3;
            vrmr_unlock(vuurmuurlog_semid);
        }
        (void)shmdt(vuurmuurlog_shmp);
    }

    /* destroy the global busywin */
    VrBusyWinDelete();

    /* delete panels and windows */
    (void)del_panel(main_panels[0]);
    (void)del_panel(main_panels[1]);
    (void)del_panel(main_panels[2]);
    (void)del_panel(main_panels[3]);
    (void)del_panel(main_panels[4]);

    (void)destroy_win(mainlog_win);
    (void)destroy_win(top_win);
    (void)destroy_win(main_win);
    (void)destroy_win(status_win);
    (void)destroy_win(status_frame_win);
    /* clear screen */
    (void)refresh();

    /* end ncurses mode */
    (void)endwin();

    /* set error functions to the stdout versions */
    vrprint.error = vrmr_stdoutprint_error;
    vrprint.warning = vrmr_stdoutprint_warning;
    vrprint.info = vrmr_stdoutprint_info;
    vrprint.debug = vrmr_stdoutprint_debug;
    vrprint.audit = vrmr_stdoutprint_audit;

    /* unload the backends */
    if (vrmr_backends_unload(&vctx.conf, &vctx) < 0) {
        vrmr_error(-1, VR_ERR, gettext("unloading the backends failed"));
        retval = -1;
    }

    /* cleanup the datastructures */
    (void)vrmr_list_cleanup(&vctx.blocklist.list);
    (void)vrmr_destroy_serviceslist(&vctx.services);
    (void)vrmr_destroy_zonedatalist(&vctx.zones);
    (void)vrmr_rules_cleanup_list(&vctx.rules);
    (void)vrmr_destroy_interfaceslist(&vctx.interfaces);
    vrmr_deinit(&vctx);
    return (retval);
}
示例#26
0
/**
 * Process user input
 * This function only looks at a single character typed at a time.
 * Once it sees a newline character it will then call process_user
 * to process the user input
 */
int handle_user(){
	refresh();
	int c = getch();
	if(c == ERR){
		return 0;
	}
	switch(c){
		case '\n':
			if(process_user(buffer) != 0){
				return 1;
			}
			buffer_pos = 0;
			break;
		case KEY_F(4):
			close_interface();
			exit(0);
		case KEY_F(1):
		case KEY_F(2):
		case KEY_F(3):
		case KEY_F(5):
		case KEY_F(6):
		case KEY_F(7):
		case KEY_F(8):
		case KEY_F(9):
		case KEY_F(10):
		case KEY_F(11):
		case KEY_F(12):
			break;
		case KEY_UP:
		case KEY_DOWN:
			break;
		case KEY_LEFT:
			break;
		case KEY_RIGHT:
			break;
		case KEY_BACKSPACE:
		case KEY_DC:
			// delete the current character
			buffer[buffer_pos] = 0;
			buffer_pos --;
			// sanity check
			if(buffer_pos < 0){
				buffer_pos = 0;
			}
			buffer[buffer_pos] = 0;

			// ugly hack to clear the line, we rebuild the window >.<
			destroy_win(windows[INPUT_WIN]);
			windows[INPUT_WIN] = create_newwin(4, COLS, LINES-4, 0);
			print_prompt(windows[INPUT_WIN]);

			wprintw(windows[INPUT_WIN],"%s",buffer);
			wrefresh(windows[INPUT_WIN]);
			break;
		default:
			buffer[buffer_pos++] = (char)c;

			wprintw(windows[INPUT_WIN],"%c",c);
			wrefresh(windows[INPUT_WIN]);
	}
	return 0;

}
int selectionsort(void) {
	WINDOW *win1, *win2, *win3;
	FILE *fp1;
	int startx_of_box, starty_of_box, width_of_box, height_of_box, max_x, max_y, start_y, start_x;  
	int choice, i, j, iter_no = 1, inner_iter, random = 1;
	int min, min_index, x_box1, x_box2;
	char c;
	data ssort;

	init_sort_info(&ssort); /* initialise number of swaps and comparisons to 0 */
	win3 = NULL; /* win3 will be used for displaying the final box after each iteration */
	cbreak();
	
	fp1 = fopen("files/selectionsort.txt", "r");
	if(fp1 == NULL) { /* display error */
		fprintf(stdout, "\vfopen: files/selectionsort.txt :: %s\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t \v", strerror(errno));
                endwin();
                exit(0);
	}	
	
	getmaxyx(stdscr, max_y, max_x); /* get max coordinates of the screen */
	print_in_middle(stdscr, 3, 0, max_x, "SELECTION SORT", COLOR_PAIR(3));
	
	start_y = max_y / 5;
	start_x = max_x / 4 + 4;
	print_intro(fp1, start_y, start_x); /* print the introduction page of Selection Sort */
	
	instruction(max_y - 2, 0, "Press <ENTER> to CONTINUE or 'p' to return to the previous menu.");
	c = getch();
	if(c == 'p') { /* exit */
		clear();
		fclose(fp1);
		curs_set(TRUE);
		return 0;
	}	
	else {
		get_num_elem(&ssort); /* get the number of elements to perform sorting on */
		clear();
		
		while(random != 0) { /* this loop is required because sometimes random function generates already sorted elements */
			random = num_generator(&ssort); /* randomly generate 'elements' numbers and store in ssort.numbers[elements] */
			message(max_y); /* print "generating random numbers..." */
		}
		clear();
		
		print_in_middle(stdscr, 3, 0, max_x, "SELECTION SORT", COLOR_PAIR(3));
		
		inner_iter = ssort.elements;
		height_of_box = 3; /* height of box */
		width_of_box = 4; /* width of box */
		starty_of_box = (max_y - height_of_box) / 4 + 5;  /* starting y coordinate of the box */
		startx_of_box = max_x / 4 + 2;  /* starting x coordinate of the box */
		
		instruction(max_y - 3, 0, "Press <ENTER> to START.");
		instruction(max_y - 2, 0, "Press 'p' to go to the Main Menu.\n");
		
		curs_set(FALSE); /* curs_set(TRUE) shows a dirty cursor at top-left of the box */
		win1 = create_newwin(height_of_box, width_of_box, starty_of_box, startx_of_box); /* create windows */
		startx_of_box += 8;
		win2 = create_newwin(height_of_box, width_of_box, starty_of_box, startx_of_box);
		
		attron(A_BOLD);	
		print_numbers(&ssort, max_y, max_x);
		attroff(A_BOLD);
		
		choice = getch();
		if(choice == 'p') { /* exit */
			clear();
			curs_set(TRUE);
			fclose(fp1);
			free(ssort.numbers);
			destroy_win(win1);
			destroy_win(win2);
			return 0;
		}	
		if(choice == ENTER) { /* start the animation */
			move(max_y - 3, 0);
			clrtoeol();
			
			attron(A_BOLD);
			mvprintw(max_y - 12, 0, "GREEN: Smallest element in the current list.");
			mvprintw(max_y - 10, 0, "YELLOW: Final position of element.");
			attroff(A_BOLD);
			
			instruction(max_y - 3, 0, "Press <RIGHT ARROW KEY> to proceed to the next step.");
			sleep(3);
			attron(A_BOLD);
			refresh();
			destroy_win(win1);
			x_box1 = startx_of_box;
			for(j = 0; j < ssort.elements - 1; j++) {
				sleep(1);
				mvprintw(max_y / 4, (max_x - 19) / 2,"Iteration number: %d", iter_no);
				
				destroy_win(win2);
				print_numbers(&ssort, max_y, max_x);
				x_box2 = x_box1 + 5;
				win1 = create_newwin(height_of_box, width_of_box, starty_of_box, x_box1);
				win2 = create_newwin(height_of_box, width_of_box, starty_of_box, x_box1 + 5);
				
				print_numbers(&ssort, max_y, max_x);
				
				min = ssort.numbers[j];
				min_index = j;
				
				move(max_y - 19, 0);
				clrtoeol();
				mvprintw(max_y - 19, max_x / 4 + 18, "Minimum element is %d.", ssort.numbers[j]);
				refresh();
				for(i = j + 1; i < inner_iter; i++) {
					sleep(1);
					print_numbers(&ssort, max_y, max_x);
					destroy_win(win2);
					win2 = create_newwin(height_of_box, width_of_box, starty_of_box, x_box2);
					if(ssort.numbers[i] < min) {
						print_numbers(&ssort, max_y, max_x);
						sleep(1);
						min = ssort.numbers[i];
						min_index = i;
						move(max_y - 19, 0);
						clrtoeol();
						mvprintw(max_y - 19, max_x / 4 + 18, "New minimum element is %d.", ssort.numbers[i]);
						refresh();
					}
					else {
						move(max_y - 19, 0);
						clrtoeol();
						mvprintw(max_y - 19, max_x / 4 + 18, "Minimum element remains %d.", ssort.numbers[min_index]);
						refresh();
					}	
					ssort.comparisons++; /* increment the number of comparisons in ssort */
					print_numbers(&ssort, max_y, max_x);
					choice = getch();
					if(choice == 'p') { /* exit */
						clear();
						curs_set(TRUE);
						fclose(fp1);
						free(ssort.numbers);
						destroy_win(win1);
						destroy_win(win2);
						return 0;
					}
					x_box2 += 5;
				}
				iter_no++;
				/* place a box over the smallest number */
				box_over_num(min_index, win3, max_y, max_x, height_of_box, width_of_box, 3);
				print_numbers(&ssort, max_y, max_x);
				sleep(1);
				
				move(max_y - 19, 0);
				clrtoeol();
				mvprintw(max_y - 19, max_x / 4 + 18, "Now %d and %d get swapped.", ssort.numbers[min_index], ssort.numbers[j]);
				refresh();
				sleep(2);
				
				destroy_win(win3);
				print_numbers(&ssort, max_y, max_x);
				win3 = NULL;
				
				ssort.numbers[min_index] = ssort.numbers[j];
				ssort.numbers[j] = min;
				ssort.swaps++;
				/* place a box over the number, now in its final position */
				box_over_num(j, win3, max_y, max_x, height_of_box, width_of_box, 4);
				
				x_box1 += 5;
				print_numbers(&ssort, max_y, max_x);
			}
			destroy_win(win1);
			destroy_win(win2);
			print_numbers(&ssort, max_y, max_x);
			sleep(1);
			
			clear_boxes(starty_of_box); /* clear the boxes from the screen */
			
			move(max_y - 19, 0);
			clrtobot();
			mvprintw(max_y - 17, max_x / 4 + 15, "Yeah! The numbers are sorted!!");
			mvprintw(max_y - 13, max_x / 4 + 15, "Info:");
			mvprintw(max_y - 11, max_x / 4 + 15, "Number of swaps = %d", ssort.swaps);
			mvprintw(max_y - 9, max_x / 4 + 15, "Number of comparisons = %d", ssort.comparisons);
			attroff(A_BOLD);
		}
		move(max_y - 4, 0);
		clrtobot();
		curs_set(TRUE);
		instruction(max_y - 2, 0, "Press any key to continue.\n");
		getch();
	}
	fclose(fp1);
	free(ssort.numbers);
	return 0;
}
示例#28
0
/*  startup_screen

    This is the splash-screen which calls the startup functions,
    like loading the plugins, zones, services etc.

    Returncodes:
         0: ok
        -1: error
*/
int startup_screen(struct vrmr_ctx *vctx, struct vrmr_rules *rules,
        struct vrmr_zones *zones, struct vrmr_services *services,
        struct vrmr_interfaces *interfaces, struct vrmr_blocklist *blocklist,
        struct vrmr_regex *reg)
{
    WINDOW *startup_win = NULL, *startup_print_win = NULL;
    PANEL *startup_panel[2];
    int retval = 0, maxy = 0, maxx = 0, y = 0, x = 0, width = 50, heigth = 15,
        result = 0, config_done = 0, cnfresult = 0;
    int print_pan_width = 40;

    // get screensize and set windowlocation
    getmaxyx(stdscr, maxy, maxx);
    y = (maxy - heigth) / 2;
    x = (maxx - width) / 2;

    // create the windows and panels
    startup_win = create_newwin(heigth, width, y, x, "Vuurmuur_conf",
            vccnf.color_win_init | A_BOLD);
    startup_print_win = newwin(1, print_pan_width, y + heigth - 3, x + 5);
    wbkgd(startup_print_win, vccnf.color_win_init | A_BOLD);
    startup_panel[0] = new_panel(startup_win);
    startup_panel[1] = new_panel(startup_print_win);
    update_panels();
    doupdate();

    // print the logo: it looks a bit weird here because of escape sequences
    // also print version
    mvwprintw(startup_win, 3, 4, "  \\\\   //           |\\\\ //|            ");
    mvwprintw(startup_win, 4, 4, "   \\\\ // | | | | |] ||\\//|| | | | | |] ");
    mvwprintw(startup_win, 5, 4,
            "    \\//  \\/| \\/| |\\ ||   || \\/| \\/| |\\ ");
    mvwprintw(startup_win, 6, 4, "                                Config ");
    mvwprintw(startup_win, 7, 4, "  ------------------------------------ ");
    mvwprintw(startup_win, 9, 3, "%s ", VUURMUUR_COPYRIGHT);
    mvwprintw(startup_win, 10, 3, gettext("Version: %s"), VUURMUURCONF_VERSION);
    mvwprintw(startup_win, 12, 4, "[");
    mvwprintw(startup_win, 12, 4 + print_pan_width + 1, "]");

    /* initialize the vuurmuur conf config */
    /* TRANSLATORS: max 40 characters */
    werase(startup_print_win);
    wprintw(startup_print_win, "%s...", STR_LOAD_VUURMUUR_CONF_SETTINGS);
    update_panels();
    doupdate();
    if (vrmr_debug_level > LOW)
        sleep(1);
    while (!config_done) {
        result = init_vcconfig(&vctx->conf, vccnf.configfile_location, &vccnf);
        if (result == VRMR_CNF_E_UNKNOWN_ERR || result == VRMR_CNF_E_PARAMETER)
            return (-1);
        else if (result == VRMR_CNF_E_FILE_PERMISSION) {
            return (-1);
        }
        /* missing file? use defaults */
        else if (result == VRMR_CNF_E_FILE_MISSING) {
            vcconfig_use_defaults(&vccnf);

            werase(startup_print_win);
            wprintw(startup_print_win, "%s... %s",
                    STR_LOAD_VUURMUUR_CONF_SETTINGS, STR_COK);
            update_panels();
            doupdate();
            config_done = 1;
        } else if (result == VRMR_CNF_E_MISSING_VAR ||
                   result == VRMR_CNF_E_ILLEGAL_VAR ||
                   result == VRMR_CNF_W_MISSING_VAR ||
                   result == VRMR_CNF_W_ILLEGAL_VAR) {
            if (confirm(gettext("Problem with the Vuurmuur_conf settings"),
                        gettext("Do you want to edit the settings now?"),
                        vccnf.color_win_note, vccnf.color_win_note_rev | A_BOLD,
                        1)) {
                /* this prompt the user with the config menu */
                cnfresult = edit_vcconfig();
                if (cnfresult < 0)
                    return (-1);
            } else {
                /* if the user doesn't want to solve the problem we exit if we
                   had an error in case of a warning, we continue
                */
                if (result == VRMR_CNF_E_MISSING_VAR ||
                        result == VRMR_CNF_E_FILE_MISSING)
                    return (-1);
                else {
                    // TODO: print warning to warn the user that the config is
                    // not yet ok?
                    config_done = 1;
                }
            }
        } else if (result == VRMR_CNF_OK) {
            werase(startup_print_win);
            wprintw(startup_print_win, "%s... %s",
                    STR_LOAD_VUURMUUR_CONF_SETTINGS, STR_COK);
            update_panels();
            doupdate();
            config_done = 1;
        } else {
            vrmr_error(-1, VR_ERR,
                    "unknown return code from init_vcconfig. This can't be "
                    "good");
            return (-1);
        }

        if (config_done == 0) {
            werase(startup_print_win);
            wprintw(startup_print_win, "%s...",
                    STR_LOAD_VUURMUUR_CONF_SETTINGS);
            update_panels();
            doupdate();
        }
    }

    /* initialize the config */
    config_done = 0;
    werase(startup_print_win);
    wprintw(startup_print_win, "%s...", STR_LOAD_VUURMUUR_CONFIG);
    update_panels();
    doupdate();
    if (vrmr_debug_level > LOW)
        sleep(1);
    while (!config_done) {
        result = vrmr_init_config(&vctx->conf);
        if (result == VRMR_CNF_E_UNKNOWN_ERR || result == VRMR_CNF_E_PARAMETER)
            return (-1);
        else if (result == VRMR_CNF_E_FILE_PERMISSION) {
            return (-1);
        } else if (result == VRMR_CNF_E_FILE_MISSING ||
                   result == VRMR_CNF_E_MISSING_VAR ||
                   result == VRMR_CNF_E_ILLEGAL_VAR ||
                   result == VRMR_CNF_W_MISSING_VAR ||
                   result == VRMR_CNF_W_ILLEGAL_VAR) {
            if (confirm(gettext("Problem with the Vuurmuur config"),
                        gettext("Do you want to edit the config now?"),
                        vccnf.color_win_note, vccnf.color_win_note_rev | A_BOLD,
                        1)) {
                /* this prompt the user with the config menu */
                cnfresult = config_menu(&vctx->conf);
                if (cnfresult < 0)
                    return (-1);
            } else {
                /* if the user doesn't want to solve the problem we exit if we
                   had an error in case of a warning, we continue
                */
                if (result == VRMR_CNF_E_MISSING_VAR ||
                        result == VRMR_CNF_E_FILE_MISSING)
                    return (-1);
                else {
                    // TODO: print warning to warn the user that the config is
                    // not yet ok?
                    config_done = 1;
                }
            }
        } else if (result == VRMR_CNF_OK) {
            werase(startup_print_win);
            wprintw(startup_print_win, "%s... %s", STR_LOAD_VUURMUUR_CONFIG,
                    STR_COK);
            update_panels();
            doupdate();
            config_done = 1;
        } else {
            vrmr_error(-1, VR_INTERR,
                    "unknown return code from vrmr_init_config. This can't be "
                    "good");
            return (-1);
        }

        if (config_done == 0) {
            werase(startup_print_win);
            wprintw(startup_print_win, "%s...", STR_LOAD_VUURMUUR_CONFIG);
            update_panels();
            doupdate();
        }
    }

    /* config done, so now we can use logprinting */
    if (vrmr_debug_level >= LOW)
        vrprint.info = vuumuurconf_print_info;
    else
        vrprint.info = vrmr_logprint_info;

    vrprint.debug = vrmr_logprint_debug;
    vrprint.audit = vrmr_logprint_audit;

    /* print that we started */
    vrmr_audit("started: effective user %s (%ld), real user %s (%ld).",
            vctx->user_data.username, (long)vctx->user_data.user,
            vctx->user_data.realusername, (long)vctx->user_data.realuser);

    /* now load the backends */
    werase(startup_print_win);
    wprintw(startup_print_win, "%s...", STR_LOAD_PLUGINS);
    update_panels();
    doupdate();
    if (vrmr_debug_level > LOW)
        sleep(1);
    result = vrmr_backends_load(&vctx->conf, vctx);
    if (result < 0) {
        vrmr_error(-1, VR_ERR, gettext("loading the plugins failed."));
        return (-1);
    }
    werase(startup_print_win);
    wprintw(startup_print_win, "%s... %s", STR_LOAD_PLUGINS, STR_COK);
    update_panels();
    doupdate();

    /* init services */
    /* TRANSLATORS: max 40 characters */
    werase(startup_print_win);
    wprintw(startup_print_win, "%s...", STR_INIT_SERVICES);
    update_panels();
    doupdate();
    if (vrmr_debug_level > LOW)
        sleep(1);
    result = vrmr_init_services(vctx, services, reg);
    if (result < 0) {
        vrmr_error(-1, VR_ERR, gettext("intializing the services failed."));
        return (-1);
    }
    /* TRANSLATORS: max 40 characters */
    werase(startup_print_win);
    wprintw(startup_print_win, "%s... %s", STR_INIT_SERVICES, STR_COK);
    update_panels();
    doupdate();

    /* init interfaces */
    /* TRANSLATORS: max 40 characters */
    werase(startup_print_win);
    wprintw(startup_print_win, "%s...", STR_INIT_INTERFACES);
    update_panels();
    doupdate();
    if (vrmr_debug_level > LOW)
        sleep(1);
    result = vrmr_init_interfaces(vctx, interfaces);
    if (result < 0) {
        vrmr_error(-1, VR_ERR, gettext("intializing the interfaces failed."));
        return (-1);
    }
    /* TRANSLATORS: max 40 characters */
    werase(startup_print_win);
    wprintw(startup_print_win, "%s... %s", STR_INIT_INTERFACES, STR_COK);
    update_panels();
    doupdate();

    /* init zones */
    /* TRANSLATORS: max 40 characters */
    werase(startup_print_win);
    wprintw(startup_print_win, "%s...", STR_INIT_ZONES);
    update_panels();
    doupdate();
    if (vrmr_debug_level > LOW)
        sleep(1);
    result = vrmr_init_zonedata(vctx, zones, interfaces, reg);
    if (result < 0) {
        vrmr_error(-1, VR_ERR, gettext("intializing the zones failed."));
        return (-1);
    }
    /* TRANSLATORS: max 40 characters */
    werase(startup_print_win);
    wprintw(startup_print_win, "%s... %s", STR_INIT_ZONES, STR_COK);
    update_panels();
    doupdate();

    /* init rules */
    /* TRANSLATORS: max 40 characters */
    werase(startup_print_win);
    wprintw(startup_print_win, "%s...", STR_INIT_RULES);
    update_panels();
    doupdate();
    if (vrmr_debug_level > LOW)
        sleep(1);
    result = vrmr_rules_init_list(vctx, &vctx->conf, rules, reg);
    if (result < 0) {
        /* TRANSLATORS: max 40 characters */
        werase(startup_print_win);
        wprintw(startup_print_win, "%s... %s", STR_INIT_RULES, STR_CFAILED);
        update_panels();
        doupdate();
    } else {
        /* TRANSLATORS: max 40 characters */
        werase(startup_print_win);
        wprintw(startup_print_win, "%s... %s", STR_INIT_RULES, STR_COK);
        update_panels();
        doupdate();
    }

    /* load the blockfile */
    /* TRANSLATORS: max 40 characters */
    werase(startup_print_win);
    wprintw(startup_print_win, "%s...", STR_INIT_BLOCKLIST);
    update_panels();
    doupdate();
    if (vrmr_debug_level > LOW)
        sleep(1);
    result = vrmr_blocklist_init_list(vctx, &vctx->conf, zones, blocklist,
            /*load_ips*/ FALSE, /*no_refcnt*/ FALSE);
    if (result < 0) {
        /* TRANSLATORS: max 40 characters */
        werase(startup_print_win);
        wprintw(startup_print_win, "%s... %s", STR_INIT_BLOCKLIST, STR_CFAILED);
        update_panels();
        doupdate();
    } else {
        /* TRANSLATORS: max 40 characters */
        werase(startup_print_win);
        wprintw(startup_print_win, "%s... %s", STR_INIT_BLOCKLIST, STR_COK);
        update_panels();
        doupdate();
    }

    /*
        try to connect to vuurmuur trough shm
    */
    vuurmuur_shmtable = NULL;
    werase(startup_print_win);
    wprintw(startup_print_win, "%s Vuurmuur...", STR_CONNECTING_TO);
    update_panels();
    doupdate();
    vuurmuur_pid = get_vuurmuur_pid("/var/run/vuurmuur.pid", &vuurmuur_shmid);
    if (vuurmuur_shmid > 0) {
        /* attach to shared memory */
        vuurmuur_shmp = shmat(vuurmuur_shmid, 0, 0);
        if (vuurmuur_shmp == (char *)(-1)) {
            vrmr_error(-1, VR_ERR,
                    gettext("attaching to shared memory failed: %s"),
                    strerror(errno));
        } else {
            vuurmuur_shmtable = (struct vrmr_shm_table *)vuurmuur_shmp;
            vuurmuur_semid = vuurmuur_shmtable->sem_id;

            /* now try to connect to the shared memory */
            if (vrmr_lock(vuurmuur_semid)) {
                vuurmuur_shmtable->configtool.connected = 1;
                (void)snprintf(vuurmuur_shmtable->configtool.name,
                        sizeof(vuurmuur_shmtable->configtool.name),
                        "Vuurmuur_conf %s (user: %s)", version_string,
                        vctx->user_data.realusername);
                (void)strlcpy(vuurmuur_shmtable->configtool.username,
                        vctx->user_data.realusername,
                        sizeof(vuurmuur_shmtable->configtool.username));
                vrmr_unlock(vuurmuur_semid);

                werase(startup_print_win);
                wprintw(startup_print_win, "%s Vuurmuur... %s",
                        STR_CONNECTING_TO, STR_COK);
                update_panels();
                doupdate();
            } else {
                werase(startup_print_win);
                wprintw(startup_print_win, "%s Vuurmuur... %s",
                        STR_CONNECTING_TO, STR_CFAILED);
                update_panels();
                doupdate();
                vuurmuur_shmp = NULL;
            }
        }
    } else {
        /* TRANSLATORS: max 40 characters */
        werase(startup_print_win);
        wprintw(startup_print_win, "%s Vuurmuur... %s", STR_CONNECTING_TO,
                STR_CFAILED);
        update_panels();
        doupdate();
        vuurmuur_shmp = NULL;
    }

    /*
        try to connect to vuurmuur trough shm
    */
    vuurmuurlog_shmtable = NULL;
    /* TRANSLATORS: max 40 characters */
    werase(startup_print_win);
    wprintw(startup_print_win, "%s Vuurmuur_log...", STR_CONNECTING_TO);
    update_panels();
    doupdate();
    vuurmuurlog_pid =
            get_vuurmuur_pid("/var/run/vuurmuur_log.pid", &vuurmuurlog_shmid);
    if (vuurmuurlog_shmid > 0) {
        /* attach to shared memory */
        vuurmuurlog_shmp = shmat(vuurmuurlog_shmid, 0, 0);
        if (vuurmuurlog_shmp == (char *)(-1)) {
            vrmr_error(-1, VR_ERR, "attaching to shared memory failed: %s",
                    strerror(errno));
        } else {
            vuurmuurlog_shmtable = (struct vrmr_shm_table *)vuurmuurlog_shmp;
            vuurmuurlog_semid = vuurmuurlog_shmtable->sem_id;

            vrmr_debug(LOW, "vuurmuur_log: sem_id: %d.", vuurmuurlog_semid);

            /* now try to connect to the shared memory */
            if (vrmr_lock(vuurmuurlog_semid)) {
                vuurmuurlog_shmtable->configtool.connected = 1;
                (void)snprintf(vuurmuurlog_shmtable->configtool.name,
                        sizeof(vuurmuurlog_shmtable->configtool.name),
                        "Vuurmuur_conf %s (user: %s)", version_string,
                        vctx->user_data.realusername);
                (void)strlcpy(vuurmuurlog_shmtable->configtool.username,
                        vctx->user_data.realusername,
                        sizeof(vuurmuurlog_shmtable->configtool.username));
                vrmr_unlock(vuurmuurlog_semid);

                werase(startup_print_win);
                wprintw(startup_print_win, "%s Vuurmuur_log... %s",
                        STR_CONNECTING_TO, STR_COK);
                update_panels();
                doupdate();
            } else {
                werase(startup_print_win);
                wprintw(startup_print_win, "%s Vuurmuur_log... %s",
                        STR_CONNECTING_TO, STR_CFAILED);
                update_panels();
                doupdate();
                vuurmuurlog_shmp = NULL;
            }
        }
    } else {
        werase(startup_print_win);
        wprintw(startup_print_win, "%s Vuurmuur_log... %s", STR_CONNECTING_TO,
                STR_CFAILED);
        update_panels();
        doupdate();
        vuurmuurlog_shmp = NULL;
    }

    /* cleanup */
    del_panel(startup_panel[0]);
    del_panel(startup_panel[1]);

    destroy_win(startup_print_win);
    destroy_win(startup_win);

    update_panels();
    doupdate();

    return (retval);
}
示例#29
0
int main(int argc, char *argv[])
{
    WINDOW *my_win, *score;
    WINDOW **car;
    game newGame, tmpGame;
    MEVENT event;

    int ch = 0, choosenCar = -1, soluce_move = 0;
    char message[1024];
    bool quit = false;
    bool show_solution = false;
    gameStruct *resultSolv = NULL;
    //INIT
    setup();
    //END INIT
    //Wait for good size
    wait_for_size(MINH, MINW);
    //Instruction
    show_instruction(MINH, MINW);
    while (!quit) {
        quit = false;
        show_solution = false;
        soluce_move = 0;
        strcpy(message, "Playing");
        //Select game
        newGame = select_game();
        //Check for level file
        if (handle_level(&tmpGame)) {
            delete_game(newGame);
            newGame = tmpGame;
            MAXCOL = game_width(newGame);
            MAXROW = game_height(newGame);
            MINH = MAXROW * SIZE + 2;
            MINW = MAXCOL * SIZE;
        }
        car = malloc(sizeof (WINDOW*) * game_nb_pieces(newGame));
        //First draw
        draw_game(newGame, 0, 0, MAXROW, MAXCOL, &my_win, car, &score, choosenCar, message, gameOverRh);
        //Loop while the game is not finished
        while (!game_over(newGame)) {
            //Print on bottom of grid
            mvprintw(MAXROW * SIZE + 1, 0, "Please choose car :");
            ch = getch();
            if (ch == 's' && !show_solution) {
                show_solution = true;
                strcpy(message, "Solution");
                resultSolv = solv(newGame, gameOverRh,true);
                if(!resultSolv){
                    strcpy(message, "No solution");
                    show_solution=false;
                }
            }
            if (show_solution) {
                newGame = play_solution(newGame, resultSolv, soluce_move++);
            } else {
                if (KEY_MOUSE == ch) {
                    /* Mouse event. */
                    if (OK == getmouse(&event)) {
                        choosenCar = get_car_with_mouse(event.y, event.x, car, game_nb_pieces(newGame));
                    }
                } else {
                    if (ch == 'q') {
                        quit = true;
                        break;
                    }
                    play_input(newGame, ch, &choosenCar);
                }
            }
            wait_for_size(MINH, MINW);
            erase_game(newGame, my_win, car, score);
            draw_game(newGame, 0, 0, MAXROW, MAXCOL, &my_win, car, &score, choosenCar, message, gameOverRh);
        }
        if (!quit) {
            display_score(newGame);
        }
        for (int i = 0; i < game_nb_pieces(newGame); i++) {
            destroy_win(car[i]);
        }
        destroy_win(my_win);
        destroy_win(score);
        free(car);
        delete_game(newGame);
        if (resultSolv != NULL) {
            delete_game(resultSolv->current);
            free(resultSolv->move);
            free(resultSolv);
            resultSolv = NULL;
        }
    }
    endwin(); /* End curses mode		  */
    return 0;
}
示例#30
0
int main(int argc, char *argv[])
{	
	//initializing
	initscr(); 				//starts ncurses			
	cbreak();				//allows input to be accessed as soon as it is typed without having to press the 'enter' key		
	keypad(stdscr, TRUE); 	//allows arrow keys and F1,F2,etc to be read
	noecho();   			//does not echo the typed characters on the screen
	curs_set(0); 			//does not display the curser
	start_color();  		//starts colour functionality
	
	
	start_screen();			//calls the start screen function (in start_end_screen.c)
	
	//variable declaration
	WINDOW *my_win,*enemy_win;
	int startx, starty;
	int ch,end_game=0,first_time=1;
	int score=0;
	time_t t;
	//seed the random function
	srand((unsigned) time(&t));
		
	//initial placement of player is in the centre of the screen
	starty = (LINES) / 2;	
	startx = (COLS) / 2;	
	refresh();
	//create player
	my_win = create_playerwin(starty, startx);
	
	
	//this is to space out the enemies to be dropped and make sure that even if a value for getchar() isnt enetered the game loop continues. i.e. enemies continue to be dropped. - but remember with just this, the game will do a loop without this delay if the player gives an input in less than 0.5 seconds. So this case is handled later. Lets call it 'case1'. . 
	/* So if this is changed for difficulty also correspondingly change the place where case1 is handled where get_time_gap() is called in main*/
	halfdelay(5);	//this waits for 0.5 seconds for an input, if no input is given, it skips the scan statement and continues the program
	
	//game loop - ch holds the currently entered button
	while((ch = getch()) != 'q')
	{	
		//for movement - the player window is destroyed and recreated at the new position
		switch(ch)
		{	case KEY_LEFT:
				if (startx==0) //left side boundary for player
				{
					break;
				}
				destroy_win(my_win);
				my_win = create_playerwin(starty,--startx);
				break;
			case KEY_RIGHT:
				if (startx>=COLS-6)  //right side boundary for the player (the -6 is to account for the size of the player object)
				{
					break;
				}
				destroy_win(my_win);
				my_win = create_playerwin(starty,++startx);
				break;
			case KEY_UP:
				if (starty==1)  //top boundary for the player
				{
					break;
				}
				destroy_win(my_win);
				my_win = create_playerwin(--starty,startx);
				break;
			case KEY_DOWN:   //bottom boundary for the player (the -4 is to account for the size of the player object)
				if (starty==LINES-4)
				{
					break;
				}
				destroy_win(my_win);
				my_win = create_playerwin(++starty,startx);
				break;
			//pausing the game
			case 'p':
				cbreak();
				mvprintw(0,0,"Press any key to resume. SCORE: %d           ",score);
				getch();
				halfdelay(5);
				break;
		}
		
		//for the first time the time must be set (the time at the previous instant when the enemy was dropped is recorded and the time elapsed since then is checked. If it reaches 0.5 seconds, it drops the next enemy)
		if (first_time==1)
		{
			first_time=0;
			gettimeofday(&time1,NULL);
		}
		gettimeofday(&time2,NULL);
		
		//print important game statistics and instructions
		mvprintw(0,0,"Press 'q' to quit. 'p' to pause. SCORE: %d",score);
		
		//this condition is to ensure that the game loop waits for 0.5 sec before executing again in the situation that the player has entered an input quickly. It takes care of 'case1'
	/* So if this is changed for difficulty, also correspondingly change the place where case1 was mentioned in the half_delay function*/
		if (get_time_gap()<500000.0) 
		{
			continue;
		}
		//end game becomes 1 if you have been hit
		end_game=drop_enemy(&score,starty,startx);
		if (end_game==1)
		{
			break; //breaks the game loop
		}
		gettimeofday(&time1,NULL);
	}
	//call the high scores screen (in start_end_screen.c)
	high_scores(score);	
	endwin();
	/* End curses mode */			
	return 0;
}