Beispiel #1
0
int teacher_form(char *database){
	refresh();
	teacher xteacher;
	noecho();
	WINDOW *win;
	int y,x;
	start_color();
	getmaxyx(stdscr,y,x);
	win = newwin(0, 0, 0, 0);
	init_pair(1, COLOR_RED, COLOR_BLACK);
	box(win, 0, 0);
	print_in_middle(win, y/4 + 1, 0, x, "Enter the Name of Teacher", COLOR_PAIR(1));
	print_form_str(win,y,x);
	scanstr(win,xteacher.name, x/3 - 1);	
	clear();
	refresh();
	box(win, 0, 0);
	print_in_middle(win, y/4 + 1, 0, x, "Enter the weekly hours for the teacher", COLOR_PAIR(1));
	print_form_int(win, y, x);	
	xteacher.week_time = scanint(win);
	add_teacher(database, &xteacher);
	refresh();
	endwin();
	clear();
	return 0;
}
Beispiel #2
0
int show_teacher_info(char *database, int choice) {
	int c;
	teacher xteacher;
	xteacher = get_teacher(database,choice);
	refresh();
	noecho();
	curs_set(0);
	WINDOW *win;
	int y,x;
	start_color();
	getmaxyx(stdscr,y,x);
	win = newwin(0, 0, 0, 0);
	init_pair(1, COLOR_RED, COLOR_BLACK);
	box(win, 0, 0);
	print_in_middle(win, y/4 + 1, 0, x, "Info", COLOR_PAIR(1));
	mvwhline(win, y/4, x/4, ACS_HLINE, x/2);
	mvwhline(win, y/4 + 2, x/4, ACS_HLINE, x/2);
	mvwhline(win, y/2, x/4, ACS_HLINE, x/2);
	mvwvline(win, y/4 + 1, x/4 , ACS_VLINE, y/4 - 1);
	mvwaddch(win, y/4, x/4 , ACS_ULCORNER);
	mvwaddch(win, y/2, x/4 , ACS_LLCORNER);
	mvwaddch(win, y/4, 3*x/4 , ACS_URCORNER);
	mvwaddch(win, y/2, 3*x/4 , ACS_LRCORNER);
	mvwvline(win, y/4 + 1, 3*x/4, ACS_VLINE, y/4 - 1);
	mvwaddch(win, y/4 + 2, 3*x/4 , ACS_RTEE);
	mvwaddch(win, y/4 + 2, x/4 , ACS_LTEE);
	wrefresh(win);
	mvwaddch(win, y - 3, 0, ACS_LTEE);
	mvwhline(win, y - 3, 1, ACS_HLINE, x - 2);
	mvwaddch(win, y - 3, x - 1, ACS_RTEE);
	move(y/4 + 3,x/3 + 2);
	printw("Name - %s",xteacher.name);
	move(y/4 + 5,x/3 + 2);
	printw("Max Weekly Hours - %d",xteacher.week_time);
	mvwprintw(win,y - 2, 2,"A:Add Allocation\tB:Back\tQ:Quit");
	refresh();
	while((c = wgetch(win))){
		switch(c) {
			case KEY_DOWN:
			case KEY_UP:
				return 0;
			case 'B':
			case 'b':
				curs_set(1);
				return 1;
			case 'Q':
			case 'q':
				curs_set(1);
				return INT_MIN;
			case 'A':
			case 'a':
				return 2;
			default:
				break;
		}
		wrefresh(win);
	}
	curs_set(1);
	return 0;
}
Beispiel #3
0
void draw_menu(WINDOW *win, MENU *menu){

	int i;

	int MENU_WIDTH = 20;
	int SCREEN_WIDTH = 100;

	clear();

	/* Print a border around the main window and print a title */
	box(win, 0, 0);

	print_in_middle(win, 1, 0, MENU_WIDTH, "Game mode", COLOR_PAIR(0));
	mvwaddch(win, 2, 0, ACS_LTEE);
	mvwhline(win, 2, 1, ACS_HLINE, MENU_WIDTH);
	mvwaddch(win, 2, MENU_WIDTH + 1, ACS_RTEE);
	mvprintw(3, (SCREEN_WIDTH/2) - (36/2), "textris - An ASCII based Tetris game");

	//decorative shapes
	for(i =0; i<7; i++){
		shape s;
		s.rotation = 0;
		s.type = i;
		s.x = 0;
		s.y = 0;
		draw_shape(s, (i*10) + (SCREEN_WIDTH/2) - ((10*7)/2), 15);
	}
	wrefresh(win);
	refresh();
}
Beispiel #4
0
void Help(int *value)
{
  int c;
  int output = 0;
  // Create new window
  WINDOW *help_win;
  help_win = newwin(15, 50, 4, 4);
  keypad(help_win, TRUE);          // Enable keyboard input
  box(help_win, 0, 0);             // Put a box around the wimdow
  // Add title
  print_in_middle(help_win, 1, 0, 50, "HELP", COLOR_PAIR(1));
  mvwaddch(help_win, 2, 0, ACS_LTEE);
  mvwhline(help_win, 2, 1, ACS_HLINE, 48);
  mvwaddch(help_win, 2, 39, ACS_RTEE);
  // Add text
  mvwaddstr(help_win, 3, 2, "WE BOTH KNOW YOU DON'T NEED HELP! ");
  mvwaddstr(help_win, 4, 2, "JUST GO AND PLAY");
  mvwaddstr(help_win, 6, 2, "Press q to go back");
  wrefresh(help_win);              // Refres the window
  // Wait for correct user input
  while((c = wgetch(help_win)) != 'q'){}
  // Destroy the window
  endwin();
  //Write the output
  *value = output;
}
Beispiel #5
0
int print_menu()
{	int choice, i;
	
	choice = 0;
	while(1)
	{	clear();
		printw("\n\n");
		print_in_middle(1, 1, 0, "* * *   Welcome to typing practice (Version 1.0) * * * ", NULL);
		printw("\n\n\n");
		for(i = 0;i <= n_groups - 1; ++i)
			printw("\t%3d: \tPractice %s\n", i + 1, groups[i]);
		printw("\t%3d: \tExit\n", i + 1);
	
		printw("\n\n\tChoice: ");
		refresh();
		echo();
		scanw("%d", &choice);
		noecho();
	
		if(choice >= 1 && choice <= n_groups + 1)
			break;
		else
		{	attron(A_REVERSE);
			mvprintw(STATUSY, STATUSX, "Wrong choice\tPress any key to continue");
			attroff(A_REVERSE);
			getch();
		}
	}
	return choice;
}
int main(int argc, char const *argv[]) {
    ITEM **my_items;
    int c;
    MENU *my_menu;
    WINDOW *my_menu_win;
    int n_choices, i;

    initscr();
    start_color();
    cbreak();
    noecho();
    keypad(stdscr, TRUE);
    init_pair(1, COLOR_RED, COLOR_BLACK);

    n_choices = ARRAY_SIZE(choices);
    my_items = (ITEM **) calloc(n_choices, sizeof(ITEM *));
    for (i = 0; i < n_choices; ++i)
        my_items[i] = new_item(choices[i], choices[i]);

    my_menu = new_menu((ITEM **) my_items);
    my_menu_win = newwin(10, 40, 4, 4);
    keypad(my_menu_win, TRUE);

    set_menu_win(my_menu, my_menu_win);
    set_menu_sub(my_menu, derwin(my_menu_win, 6, 38, 3, 1));

    set_menu_mark(my_menu, " * ");

    box(my_menu_win, 0, 0);
    print_in_middle(my_menu_win, 1, 0, 40, "My Menu", COLOR_PAIR(1));
    mvwaddch(my_menu_win, 2, 0, ACS_LTEE);
    mvwhline(my_menu_win, 2, 1, ACS_HLINE, 38);
    mvwaddch(my_menu_win, 2, 39, ACS_RTEE);
    mvprintw(LINES - 2, 0, "F1 to exit");
    refresh();

    post_menu(my_menu);
    wrefresh(my_menu_win);

    while ((c = wgetch(my_menu_win)) != KEY_F(1)) {
        switch (c) {
        case KEY_DOWN:
            menu_driver(my_menu, REQ_DOWN_ITEM);
            break;
        case KEY_UP:
            menu_driver(my_menu, REQ_UP_ITEM);
            break;
        }
        wrefresh(my_menu_win);
    }

    unpost_menu(my_menu);
    free_menu(my_menu);
    for (i = 0; i < n_choices; ++i)
        free_item(my_items[i]);

    endwin();
    return 0;
}
Beispiel #7
0
void Play(int *value)
{
  int c;
  int output = 3; // Set default output value to "Exit"
  // Create new window
  WINDOW *game_win;
  game_win = newwin(15,50,4,4);
  keypad(game_win, TRUE);           // Enable keyboard input
  box(game_win, 0, 0);              // Put a box around the wimdow
  // Add title
  print_in_middle(game_win, 1, 0, 50, "THE GAME", COLOR_PAIR(1));
  mvwaddch(game_win, 2, 0, ACS_LTEE);
  mvwhline(game_win, 2, 1, ACS_HLINE, 48);
  mvwaddch(game_win, 2, 39, ACS_RTEE);
  //sleep(500);
  //Add text
  mvwaddstr(game_win, 2, 2, "This is it, the faith of the whole world is in");
  //sleep(500);
  mvwaddstr(game_win, 3, 2, "your hands. You are the only one who has the");
  //sleep(500);
  mvwaddstr(game_win, 4, 2, "power to defeat evil forces and save the human");
  mvwaddstr(game_win, 5, 2, "kind.");
  //sleep(500);
  mvwaddstr(game_win, 5, 7, "... or DESTROY IT!!!");
  //sleep(500);
  mvwaddstr(game_win, 7, 2, "The power is in your hands. Take the controller");
  mvwaddstr(game_win, 8, 2, "and make your choise:");
  mvwaddstr(game_win, 9, 4, "press A");
  mvwaddstr(game_win, 9, 16, "press B");
  wrefresh(game_win);              // Refres the window

  bool done = false;
  bool win = false;
  // Wait for correct user input
  while(!done && (c = wgetch(game_win)) != 'q')
  {
      //To do:
      //Choose wining button at random
      //For now:
      if (c == 'a' || c == 'A')
      {
        win = true;
        done = true;
      }
      if (c == 'b' || c == 'B')
      {
        win = false;
        done = true;
      }
  }
  // Destroy the window
  endwin();
  // Salute the winner or admit the looser
  if (win)
    Winner(&output);
  else
    Looser(&output);
  *value = output;
}
Beispiel #8
0
/* Show the window with a border and a label. */
void
wins_show (WINDOW *win, char *label)
{
  int width = getmaxx (win);

  box (win, 0, 0);
  mvwaddch (win, 2, 0, ACS_LTEE);
  mvwhline (win, 2, 1, ACS_HLINE, width - 2);
  mvwaddch (win, 2, width - 1, ACS_RTEE);

  print_in_middle (win, 1, 0, width, label);
}
Beispiel #9
0
/* Show the window with a border and a label */
void win_show(WINDOW *win, char *label, int label_color)
{	int startx, starty, height, width;

	getbegyx(win, starty, startx);
	getmaxyx(win, height, width);

	box(win, 0, 0);
	mvwaddch(win, 2, 0, ACS_LTEE); 
	mvwhline(win, 2, 1, ACS_HLINE, width - 2); 
	mvwaddch(win, 2, width - 1, ACS_RTEE); 
	
	print_in_middle(win, 1, 0, width, label, COLOR_PAIR(label_color));
}
Beispiel #10
0
int main(int argc, char *argv[])
{	initscr();			/* Start curses mode 		*/
	if(has_colors() == FALSE)
	{	endwin();
		printf("You terminal does not support color\n");
		exit(1);
	}
	start_color();			/* Start color 			*/
	init_pair(1, COLOR_RED, COLOR_BLACK);

	attron(COLOR_PAIR(1));
	print_in_middle(stdscr, LINES / 2, 0, 0, "Viola !!! In color ...");
	attroff(COLOR_PAIR(1));
    	getch();
	endwin();
}
void traceExplorateur()
{
    wbkgd(stdscr, COLOR_PAIR(5));
    box(stdscr, 0, 0);
    print_in_middle(stdscr, 1, 0, COLS, (char *) "Explorer", COLOR_PAIR(6) | A_BOLD);
    mvwaddch(stdscr, 2, 0, ACS_LTEE);
    mvwhline(stdscr, 2, 1, ACS_HLINE, COLS - 2);
    mvwaddch(stdscr, 2, COLS -1, ACS_RTEE);

    mvwaddch(stdscr, LINES - 5, 0, ACS_LTEE);
    mvwhline(stdscr, LINES - 5, 1, ACS_HLINE, COLS - 2);
    mvwaddch(stdscr, LINES - 5, COLS -1, ACS_RTEE);

    mvwaddch(stdscr, 2, COLS / 2, ACS_TTEE);
    mvwvline(stdscr, 3, COLS / 2, ACS_VLINE, LINES - 7);
    mvwaddch(stdscr, LINES - 5, COLS / 2, ACS_BTEE);
}
Beispiel #12
0
int main (int argc, char **argv)
{
	initscr();
	if (has_colors() == FALSE)
	{
		endwin();	
		printf("You terminal does not support color\n");
		exit(1);
	}
	start_color();
	init_pair(1, COLOR_WHITE, COLOR_BLACK);
	attron(COLOR_PAIR(1));
	print_in_middle(stdscr, LINES / 2, 0, 0, "Hello world!");
	attroff(COLOR_PAIR(1));
	getch();
	endwin();
	return 0;
}
Beispiel #13
0
void help(){
  WINDOW* helpwin = newwin( 20, 50, (GLOBAL_HEIGHT - 20)/2, (GLOBAL_WIDTH - 50) / 2 );
  wbkgd( helpwin, COLOR_PAIR( YB ) );
  box( helpwin, 0, 0 );

  print_in_middle( helpwin, 3, "Cavez of Phear" );
  mvwaddstr( helpwin,  6, 5, "   arrows --> MOVE PLAYER" );
  mvwaddstr( helpwin,  7, 5, "   h      --> HELP" );
  mvwaddstr( helpwin,  8, 5, "   t      --> KABOOM" );
  mvwaddstr( helpwin,  9, 5, "   b      --> BOMB" );
  mvwaddstr( helpwin, 10, 5, "   k      --> harakiri" );
  mvwaddstr( helpwin, 11, 5, " q - ESC  --> MENU" );

  wrefresh( helpwin );
  nodelay( stdscr, FALSE );
  getch();
  nodelay( stdscr, TRUE );
  delwin( helpwin );
}
Beispiel #14
0
void ehelp(){
  curs_set( FALSE );
  WINDOW* helpwin = newwin( 20, 50, (GLOBAL_HEIGHT - 20)/2, (GLOBAL_WIDTH - 50) / 2 );
  wbkgd( helpwin, COLOR_PAIR( YB ) );
  box( helpwin, 0, 0 );
  print_in_middle( helpwin, 3, "MENU" );
  mvwaddstr( helpwin,  5, 5, "0  -  9   --> SET OBJ" );
  mvwaddstr( helpwin,  6, 5, "   l      --> DRAWN LOCK ON/OFF" );
  mvwaddstr( helpwin,  7, 5, "   h      --> HELP" );
  mvwaddstr( helpwin,  8, 5, "   s      --> SAVE" );
  mvwaddstr( helpwin,  9, 5, "   a      --> SET ALL CHARACTERS" );
  mvwaddstr( helpwin, 10, 5, "   r      --> RELOAD LEVEL" );
  mvwaddstr( helpwin, 11, 5, "q  - ESC  --> MENU" );
  wrefresh( helpwin );
  nodelay( stdscr, FALSE );
  getch();
  nodelay( stdscr, TRUE );
  delwin( helpwin );
  curs_set( TRUE );
}
Beispiel #15
0
/**
 * dest should have enough space (at least len) to hold the string.
 */
void get_text_string_from_centered_panel(char const *const prompt, char *dest, int len)
{
  WINDOW *panel_win;
  PANEL *the_panel;
  int panel_height=6,panel_width;
  /* char *dest = malloc(100); */

  int promptlen = strlen(prompt);
  panel_width = MAX(30, promptlen+5);

  /* Create the window to hold the panel */
  panel_win = newwin(panel_height,
                     panel_width,
                     (LINES-panel_height)/2,
                     (COLS-panel_width)/2);
  box(panel_win, 0, 0);
  print_in_middle(panel_win, 1,
          0, panel_width,
          prompt, COLOR_PAIR(6));
  wattron(panel_win, COLOR_PAIR(5));
  mvwhline(panel_win, 3, 2, ' ', panel_width-4);
  curs_set(1); // make cursor visible
  echo();
  mvwgetnstr(panel_win, 3, 2, dest, len);
  noecho();
  curs_set(0); // make cursor invisible
  wattroff(panel_win, COLOR_PAIR(5));
  
  /* create the panel from our window */
  the_panel = new_panel(panel_win);
  top_panel(the_panel);
  update_panels();
  doupdate();

  del_panel(the_panel);
  update_panels();
  delwin(panel_win);
  doupdate();
}
Beispiel #16
0
void Looser(int *output)
{
  int c;
  *output = 3;
  // Create new window
  WINDOW *win;
  win = newwin(15, 50, 4, 4);
  keypad(win, TRUE);          // Enable keyboard input
  box(win, 0, 0);             // Put a box around the wimdow
  // Add title
  print_in_middle(win, 1, 0, 50, "WHAT HAVE YOU DONE!?", COLOR_PAIR(1));
  mvwaddch(win, 2, 0, ACS_LTEE);
  mvwhline(win, 2, 1, ACS_HLINE, 48);
  mvwaddch(win, 2, 39, ACS_RTEE);
  //sleep(500);
  // Add text
  mvwaddstr(win, 3, 2, "We all put our faith in you and now, that you ");
  //sleep(500);
  mvwaddstr(win, 4, 2, "have lost, there is no more hope...");
  mvwaddstr(win, 5, 2, "no more future...");
  //sleep(500);
  mvwaddstr(win, 7, 2, "Still think you can make this right?");
  mvwaddstr(win, 8, 2, "Press Y to go again");
  mvwaddstr(win, 8, 28, "Press X to quit");
  wrefresh(win);              // Refres the window
  // Wait for correct user input
  while((c = wgetch(win)) != 'x')
  {
    if (c == 'y' || c == 'Y')
      {
        *output = 0;
        break;
      }
  }
  // Destroy the window
  endwin();
}
Beispiel #17
0
int main(int argc, char *argv[])
{	int n_discs;
	peg my_pegs[3];

	initscr();	/* Start curses mode 		*/
	cbreak();	/* Line buffering disabled. Pass on every thing */
	keypad(stdscr, TRUE);
	curs_set(FALSE);
	
	print_in_middle(0, LINES / 2, COLS, welcome_string, NULL);
	scanw("%d", &n_discs);	

	timeout(TIME_OUT);
	noecho();
	store_n_discs = n_discs;

	init_pegs(my_pegs, n_discs);
	show_pegs(stdscr, my_pegs, n_discs);
	solve_hanoi(my_pegs, n_discs, 0, 1, 2);

	free_pegs(my_pegs, n_discs);
	endwin();		/* End curses mode		  */
	return 0;
}
Beispiel #18
0
void Winner(int *output)
{
  int c;
  *output = 3;
  // Create new window
  WINDOW *win_win;
  win_win = newwin(15, 50, 4, 4);
  keypad(win_win, TRUE);          // Enable keyboard input
  box(win_win, 0, 0);             // Put a box around the wimdow
  // Add title
  print_in_middle(win_win, 1, 0, 50, "CONGRATULATIONS", COLOR_PAIR(1));
  mvwaddch(win_win, 2, 0, ACS_LTEE);
  mvwhline(win_win, 2, 1, ACS_HLINE, 48);
  mvwaddch(win_win, 2, 39, ACS_RTEE);
  //sleep(500);
  // Add text
  mvwaddstr(win_win, 3, 2, "How does it feel to be a hero?");
  //sleep(500);
  mvwaddstr(win_win, 4, 2, "It must feel grate! Keep it up like this!");
  //sleep(500);
  mvwaddstr(win_win, 6, 2, "Still feeling lucky?");
  mvwaddstr(win_win, 7, 2, "Press Y to go again");
  mvwaddstr(win_win, 7, 22, "Press X to quit");
  wrefresh(win_win);              // Refres the window
  // Wait for correct user input
  while((c = wgetch(win_win)) != 'x')
  {
    if (c == 'y' || c == 'Y')
      {
        *output = 0;
        break;
      }
  }
  // Destroy the window
  endwin();
}
Beispiel #19
0
int filedlg_display(struct filedlg *fd)
{
    char fmt[5];
    int width, height;
    int lwidth;
    int file;
    int i;
    int attr;
    static char *label = "Select a file or press q to cancel.";

    curs_set(0);

    /* Check that a file is loaded */
    if (fd == NULL || fd->buf == NULL || fd->buf->files == NULL) {
        wrefresh(fd->win);
        return 0;
    }

    /* Initialize variables */
    getmaxyx(fd->win, height, width);

    /* The status bar and display line 
     * Fake the display function to think the height is 2 lines less */
    height -= 2;

    /* Set starting line number (center source file if it's small enough) */
    if (fd->buf->length < height)
        file = (fd->buf->length - height) / 2;
    else {
        file = fd->buf->sel_line - height / 2;
        if (file > fd->buf->length - height)
            file = fd->buf->length - height;
        else if (file < 0)
            file = 0;
    }

    /* Print 'height' lines of the file, starting at 'file' */
    lwidth = (int) log10(fd->buf->length) + 1;
    sprintf(fmt, "%%%dd", lwidth);

    print_in_middle(fd->win, 0, width, label);
    wmove(fd->win, 0, 0);

    for (i = 1; i < height + 1; i++, file++) {
        wmove(fd->win, i, 0);
        if (has_colors()) {
            /* Outside of filename, just finish drawing the vertical file */
            if (file < 0 || file >= fd->buf->length) {
                int j;

                for (j = 1; j < lwidth; j++)
                    waddch(fd->win, ' ');
                waddch(fd->win, '~');
                wattron(fd->win, A_BOLD);
                waddch(fd->win, VERT_LINE);
                wattroff(fd->win, A_BOLD);
                for (j = 2 + lwidth; j < width; j++)
                    waddch(fd->win, ' ');
            }
            /* Mark the current file with an arrow */
            else if (file == fd->buf->sel_line) {
                wattron(fd->win, A_BOLD);
                wprintw(fd->win, fmt, file + 1);
                wattroff(fd->win, A_BOLD);
                if (hl_groups_get_attr(hl_groups_instance, HLG_ARROW,
                                &attr) == -1)
                    return -1;
                wattron(fd->win, attr);
                waddch(fd->win, '-');
                waddch(fd->win, '>');
                wattroff(fd->win, attr);
                if (fd->buf->cur_line != NULL)
                    hl_wprintw(fd->win, fd->buf->cur_line, width - lwidth - 2,
                            fd->buf->sel_col);
                else
                    hl_wprintw(fd->win, fd->buf->files[file],
                            width - lwidth - 2, fd->buf->sel_col);
            }
            /* Ordinary file */
            else {
                wprintw(fd->win, fmt, file + 1);
                wattron(fd->win, A_BOLD);
                waddch(fd->win, VERT_LINE);
                wattroff(fd->win, A_BOLD);
                waddch(fd->win, ' ');

                /* No special file information */
                if (file == fd->buf->sel_line && fd->buf->cur_line != NULL)
                    hl_wprintw(fd->win, fd->buf->cur_line, width - lwidth - 2,
                            fd->buf->sel_col);
                else
                    hl_wprintw(fd->win, fd->buf->files[file],
                            width - lwidth - 2, fd->buf->sel_col);
            }
        } else {
            wprintw(fd->win, "%s\n", fd->buf->files[file]);
        }
    }

    /* Add the 2 lines back in so the status bar can be drawn */
    height += 2;

    /* Update status bar */
    wmove(fd->win, height, 0);

    /* Print white background */
    if (hl_groups_get_attr(hl_groups_instance, HLG_STATUS_BAR, &attr) == -1)
        return -1;
    wattron(fd->win, attr);

    for (i = 0; i < width; i++)
        mvwprintw(fd->win, height - 1, i, " ");

    if (regex_search && regex_direction)
        mvwprintw(fd->win, height - 1, 0, "Search:%s", regex_line);
    else if (regex_search)
        mvwprintw(fd->win, height - 1, 0, "RSearch:%s", regex_line);

    wattroff(fd->win, attr);

    wmove(fd->win, height - (file - fd->buf->sel_line) - 1, lwidth + 2);
    wrefresh(fd->win);

    return 0;
}
Beispiel #20
0
void display_execution(int num_instruction, mot * tab_mot_instruction, int nb_instruction, int* registres,int nb_reg, int PC, int SP, int SR){
        ITEM *item_en_cour = NULL; 
    
        char ** tab_instruction;
        // for instructions
        ITEM **instructions_items;
	int c;		
        WINDOW *instructions_win;
	MENU *instruction_menu;
	int i;
	instructions_items = (ITEM **)calloc(nb_instruction + 1, sizeof(ITEM *));
        int menu_instruction_alrdy_dlt = 0; //pour ne pas supprimer le menu 2 fois --> évite les erreur de segmentation lorsqu'on quitte
        
        
        char ** files;  //in case of F2
        
        // for register
        char  ** tab_register;
        ITEM **register_items;
	WINDOW *register_win;
	MENU *register_menu;
	register_items = (ITEM **)calloc(nb_reg + 1 +3, sizeof(ITEM *)); //+3 pour PC SP et SR
        int menu_register_alrdy_dlt = 0; //pour ne pas supprimer le menu 2 fois --> évite les erreur de segmentation lorsqu'on quitte
        
        
        char dest_string[5];
        char source_string[5];
        char brut_string[10];
        char pc_string[6], sp_string[6], sr_string[6];
        
        
        
        int is_brut = 0; //si le mot précedent contient un mode direct, alors le mot suivant est un brut //si DIRIMM les 2 suivant sont des brut
        
        
        //allocation de mémoire pour les insctruction sous forme de chaine
        tab_instruction = (char**) malloc (nb_instruction* sizeof(char*));
        
        
        
        //allocation de mémoire pour le tabeau de registre sous forme de string
        tab_register = (char**) malloc (nb_reg* sizeof(char *));
        
        int num_choix;
        char * choix = NULL;

         
	for(i = 0; i < nb_instruction; ++i){
            
            tab_instruction[i] = malloc(50 * sizeof(char)); //plus simple pour le moment, une instruction ne peut dépasser 50caractères ... a améliorer si assez de temps
                
            
            if(is_brut == 0){
               
                
                
                sprintf(dest_string, "%d", tab_mot_instruction[i].codage.dest);
                sprintf(source_string, "%d", tab_mot_instruction[i].codage.source);
                
                //si l'instruction contient une source ou destination en mode immediat ou direct, la prochaine instruction sera un brut
                if(is_brut==2 || tab_mot_instruction[i].codage.mode == REGIMM || tab_mot_instruction[i].codage.mode == INDIMM || tab_mot_instruction[i].codage.mode == REGDIR || tab_mot_instruction[i].codage.mode ==  DIRREG){
                    is_brut = 1;
                }
                if(tab_mot_instruction[i].codage.mode == DIRIMM){
                    is_brut = 2;
                }
                
                strcpy(tab_instruction[i], codeop_tostring(tab_mot_instruction[i].codage.codeop) ); //on met tout les élément sous forme de string concaténé et espacé
                strcat(tab_instruction[i], "    "); 
                strcat(tab_instruction[i], mode_tostring(tab_mot_instruction[i].codage.mode));
                strcat(tab_instruction[i], "    "); 
                strcat(tab_instruction[i], dest_string);
                strcat(tab_instruction[i], "    "); 
                strcat(tab_instruction[i], source_string);
            }
            else{
               sprintf(brut_string, "%d", tab_mot_instruction[i].brut); 
               strcpy(tab_instruction[i], brut_string ); 
               if(is_brut == 2){
                   is_brut = 1; // cas du DIRIMM
               } else{
                   is_brut = 0;
               }
            }
                

                //mvprintw(i+2, 0, "%s", tab_instruction[i]);
                instructions_items[i] = new_item(tab_instruction[i], ""); //ajoute les éléments dans mon tableau d'item
                
                if(i == num_instruction){
                        //on sauvegarde l'adresse de l'item que l'on est entrain de traiter (celui donner par num_instruction)
                        item_en_cour = instructions_items[i];
                        //n le desactive, cela permet de lui doonner une autre apparence pur le repérer
                        item_opts_off(instructions_items[i], O_SELECTABLE);
                }
        }
                
        
        
        
        
        for(i = 0; i < nb_reg; ++i){
                //contient le registre sous forme de string par exemple R1 ou PC
                tab_register[i] = malloc(3 * sizeof(char));
                
                sprintf(tab_register[i], "R%i: %d",i, registres[i]);
                
                //mvprintw(i+2, 0, "%s", tab_instruction[i]);
                register_items[i] = new_item(tab_register[i], ""); //ajoute les éléments dans mon tableau d'item
        }
                sprintf(pc_string, "%d", PC);
                sprintf(sp_string, "%d", SP);
                sprintf(sr_string, "%d", SR);
                register_items[nb_reg] = new_item("PC:", pc_string); //register_items[8]
                register_items[nb_reg+1] = new_item("SP:", sp_string); //register_items[9]
                register_items[nb_reg+2] = new_item("SR:", sr_string);  //register_items[10]
                //pour cacher la selection du premier registre
                item_opts_off(register_items[0], O_SELECTABLE);
        
        
	instruction_menu = new_menu((ITEM **)instructions_items); //creer un menu contenant les instructions
        
        register_menu = new_menu((ITEM **)register_items); //creer un menu contenant les registres
	mvprintw(LINES - 2, 0, "F9 to close the menu"); 
        
        
        
        instructions_win = newwin((LINES-4)/2, 40 , 3, (COLS/2)- (COLS-4)/4); //créer une nouvelle fenetre pour les instructions
        register_win = newwin(16, 20 , 3, (COLS/2) + 10); //créer une nouvelle fenetre pour les registres
        
        keypad(instructions_win, TRUE); //active le clavier sur les instructions
       
        
        
        /* Set main window and sub window */
        set_menu_win(instruction_menu, instructions_win); //set main menu
        set_menu_sub(instruction_menu, derwin(instructions_win, ((LINES-4)/2)-4, 38, 3, 1)); // set sub window
        set_menu_format(instruction_menu, ((LINES-4)/2)-4, 1);
        
        set_menu_win(register_menu, register_win); //set main menu
        set_menu_sub(register_menu, derwin(register_win, 13, 18, 3, 1)); // set sub window
        set_menu_format(register_menu, 13, 1);
        
        
        
        
       /* Set menu mark to the string " * " */
        set_menu_mark(instruction_menu, " * ");
        set_menu_mark(register_menu, "");
        
        
        /* Print a border around the main window and print a title */
        box(instructions_win, 0, 0);
        print_in_middle(instructions_win, 1, 0, 40, "liste des instructions", COLOR_PAIR(1));
	mvwaddch(instructions_win, 2, 0, ACS_LTEE);
	mvwhline(instructions_win, 2, 1, ACS_HLINE, 43);
	mvwaddch(instructions_win, 2, 39, ACS_RTEE);
        
        box(register_win, 0, 0);
        print_in_middle(register_win, 1, 0, 20, "Registres", COLOR_PAIR(1));
	mvwaddch(register_win, 2, 0, ACS_LTEE);
	mvwhline(register_win, 2, 1, ACS_HLINE, 22);
	mvwaddch(register_win, 2, 19, ACS_RTEE);
	refresh();
        
	post_menu(instruction_menu);
        post_menu(register_menu);
        
        //on se place sur l'instruction en cour
        set_current_item (instruction_menu, item_en_cour);
        
	wrefresh(instructions_win);
        wrefresh(register_win);
       

	while((c = getch()) != KEY_F(9) && c != 32)
	{   switch(c)
	    {	case KEY_F(5):
                mvprintw(LINES-2, 0, "Exiting...");
                endwin();			/* End curses mode		  */
                exit(0);
            
                case KEY_F(2):
                        files = list_file("", &i);
                        draw_menu(files, execute_file_menu, "", i);
                        
                case KEY_DOWN:
		        menu_driver(instruction_menu, REQ_DOWN_ITEM);
			break;
		case KEY_UP:
			menu_driver(instruction_menu, REQ_UP_ITEM);
			break;
                
            
                //case KEY_NPAGE:
		//	menu_driver(my_menu, REQ_SCR_DPAGE);
		//	break;
                //case KEY_PPAGE:
		//	menu_driver(my_menu, REQ_SCR_UPAGE);
		//	break;
        
            
                case 10:
                        move(20, 0);
			clrtoeol();
                       
			break;
                 

		}
                wrefresh(instructions_win);
	}
        if(menu_instruction_alrdy_dlt == 0){
                clean_menu(instruction_menu);
                clean_window(instructions_win);
        }
                if(menu_register_alrdy_dlt == 0){
                clean_menu(register_menu);
                clean_window(register_win);
        }
    
    
}
Beispiel #21
0
int main()
{	ITEM **my_items;
	int c;
	MENU *my_menu;
        WINDOW *my_menu_win;
        int n_choices, i;
	/* Initialize curses */
	initscr();
	start_color();
        cbreak();
        noecho();
	keypad(stdscr, TRUE);
	clear();	
	refresh();
	init_pair(1, COLOR_RED, COLOR_BLACK);
	getmaxyx(stdscr,y,x);
	/* Create items */
        n_choices = ARRAY_SIZE(choices);
        my_items = (ITEM **)calloc(n_choices, sizeof(ITEM *));
        for(i=0;i<n_choices;++i)
	{
                my_items[i] = new_item(choices[i],"");
		set_item_userptr(my_items[i], func);
	}
	my_items[n_choices] = (ITEM *)NULL;
	/* Crate menu */
	my_menu = new_menu((ITEM **)my_items);
	/* Create the window to be associated with the menu */
        my_menu_win = newwin(10, 45, (y/2)-6,(x/2)-22 );
        keypad(my_menu_win, TRUE);
     
	/* Set main window and sub window */
        set_menu_win(my_menu, my_menu_win);
        set_menu_sub(my_menu, derwin(my_menu_win, 6, 40, 3, 1));
	/* Set menu mark to the string " * " */
        set_menu_mark(my_menu, " * ");
	/* Print a border around the main window and print a title */
        box(my_menu_win, 0, 0);
	print_in_middle(my_menu_win, 1, 0, 45, "Welcome to Ncurses Phone Book (NPB)", COLOR_PAIR(1));
	mvwaddch(my_menu_win, 2, 0, ACS_LTEE);
	mvwhline(my_menu_win, 2, 1, ACS_HLINE, 43);
	mvwaddch(my_menu_win, 2, 44, ACS_RTEE);
	mvprintw(LINES - 2, 0, "Press ESC to exit");
	refresh();
	/* Post the menu */
	post_menu(my_menu);
	wrefresh(my_menu_win);
//upon();
	while((c = wgetch(my_menu_win)) != 27)
	{       switch(c)
	        {	case KEY_DOWN:
				menu_driver(my_menu, REQ_DOWN_ITEM);
				break;
			case KEY_UP:
				menu_driver(my_menu, REQ_UP_ITEM);
				break;
			case 10: /* Enter */
			{	ITEM *cur;
				void (*p)(char *);
				cur = current_item(my_menu);
				p = item_userptr(cur);
				p((char *)item_name(cur));
				refresh();
				//printw("%s",item_name(cur));
				if(!strcmp("[6] Exit",item_name(cur)))
				{
					unpost_menu(my_menu);
				        free_menu(my_menu);
					endwin();
					return 0;
				}
				else if(!strcmp("[3] Searching for a contact by name",item_name(cur)))
				{
					upon("Search by name");
					//if(strlen(str)>1)
					
					clear();
					set_menu_sub(my_menu, derwin(my_menu_win, 6, 40, 3, 1));
					/* Set menu mark to the string " * " */
				        set_menu_mark(my_menu, " * ");
					/* Print a border around the main window and print a title */
				        box(my_menu_win, 0, 0);
					print_in_middle(my_menu_win, 1, 0, 45, "Welcome to Simple Phone Book Application", COLOR_PAIR(1));
					mvwaddch(my_menu_win, 2, 0, ACS_LTEE);
					mvwhline(my_menu_win, 2, 1, ACS_HLINE, 43);
					mvwaddch(my_menu_win, 2, 44, ACS_RTEE);
					mvprintw(LINES - 2, 0, "Press ESC to exit");
					refresh();
					/* Post the menu */
					post_menu(my_menu);
					wrefresh(my_menu_win);
				}
				else if(!strcmp("[4] Searching for a contact by number",item_name(cur)))
				{
					upon("Search by number");
					clear();
					set_menu_sub(my_menu, derwin(my_menu_win, 6, 40, 3, 1));
					/* Set menu mark to the string " * " */
				        set_menu_mark(my_menu, " * ");
					/* Print a border around the main window and print a title */
				        box(my_menu_win, 0, 0);
					print_in_middle(my_menu_win, 1, 0, 45, "Welcome to Simple Phone Book Application", COLOR_PAIR(1));
					mvwaddch(my_menu_win, 2, 0, ACS_LTEE);
					mvwhline(my_menu_win, 2, 1, ACS_HLINE, 43);
					mvwaddch(my_menu_win, 2, 44, ACS_RTEE);
					mvprintw(LINES - 2, 0, "Press ESC to exit");
					refresh();
					/* Post the menu */
					post_menu(my_menu);
					wrefresh(my_menu_win);
				}
				else if(!strcmp("[2] Removing a contact",item_name(cur)))
				{
					upon("Enter contact name to remove");
					clear();
					set_menu_sub(my_menu, derwin(my_menu_win, 6, 40, 3, 1));
					/* Set menu mark to the string " * " */
				        set_menu_mark(my_menu, " * ");
					/* Print a border around the main window and print a title */
				        box(my_menu_win, 0, 0);
					print_in_middle(my_menu_win, 1, 0, 45, "Welcome to Simple Phone Book Application", COLOR_PAIR(1));
					mvwaddch(my_menu_win, 2, 0, ACS_LTEE);
					mvwhline(my_menu_win, 2, 1, ACS_HLINE, 43);
					mvwaddch(my_menu_win, 2, 44, ACS_RTEE);
					mvprintw(LINES - 2, 0, "Press ESC to exit");
					refresh();
					/* Post the menu */
					post_menu(my_menu);
					wrefresh(my_menu_win);
				}
				else if(!strcmp("[5] Displaying contact list",item_name(cur)))
				{
					show();
					clear();
					set_menu_sub(my_menu, derwin(my_menu_win, 6, 40, 3, 1));
					/* Set menu mark to the string " * " */
				        set_menu_mark(my_menu, " * ");
					/* Print a border around the main window and print a title */
				        box(my_menu_win, 0, 0);
					print_in_middle(my_menu_win, 1, 0, 45, "Welcome to Simple Phone Book Application", COLOR_PAIR(1));
					mvwaddch(my_menu_win, 2, 0, ACS_LTEE);
					mvwhline(my_menu_win, 2, 1, ACS_HLINE, 43);
					mvwaddch(my_menu_win, 2, 44, ACS_RTEE);
					mvprintw(LINES - 2, 0, "Press ESC to exit");
					refresh();
					/* Post the menu */
					post_menu(my_menu);
					wrefresh(my_menu_win);
				}
				else if(!strcmp("[1] Adding a contact",item_name(cur)))
				{
					int ret=uponadd();			
					clear();
					set_menu_sub(my_menu, derwin(my_menu_win, 6, 40, 3, 1));
					/* Set menu mark to the string " * " */
				        set_menu_mark(my_menu, " * ");
					/* Print a border around the main window and print a title */
				        box(my_menu_win, 0, 0);
					print_in_middle(my_menu_win, 1, 0, 45, "Welcome to Simple Phone Book Application", COLOR_PAIR(1));
					mvwaddch(my_menu_win, 2, 0, ACS_LTEE);
					mvwhline(my_menu_win, 2, 1, ACS_HLINE, 43);
					mvwaddch(my_menu_win, 2, 44, ACS_RTEE);
					mvprintw(LINES - 2, 0, "Press ESC to exit");
					refresh();
					/* Post the menu */
					post_menu(my_menu);
					wrefresh(my_menu_win);
					if(ret==1)
					{
					int trash=outprint();
					clear();
					set_menu_sub(my_menu, derwin(my_menu_win, 6, 40, 3, 1));
					/* Set menu mark to the string " * " */
				        set_menu_mark(my_menu, " * ");
					/* Print a border around the main window and print a title */
				        box(my_menu_win, 0, 0);
					print_in_middle(my_menu_win, 1, 0, 45, "Welcome to Simple Phone Book Application", COLOR_PAIR(1));
					mvwaddch(my_menu_win, 2, 0, ACS_LTEE);
					mvwhline(my_menu_win, 2, 1, ACS_HLINE, 43);
					mvwaddch(my_menu_win, 2, 44, ACS_RTEE);
					mvprintw(LINES - 2, 0, "Press ESC to exit");
					refresh();
					/* Post the menu */
					post_menu(my_menu);
					wrefresh(my_menu_win);
					}
				}
				pos_menu_cursor(my_menu);
				break;
			}
		}
                wrefresh(my_menu_win);
	}	
	/* Unpost and free all the memory taken up */
        unpost_menu(my_menu);
        free_menu(my_menu);
//        for(i = 0; i < n_choices; ++i)
  //              free_item(my_items[i]);
	endwin();
}
Beispiel #22
0
/* layman's scrollable window... */
void show_scroll_win(WINDOW *main_window,
		const char *title,
		const char *text)
{
	int res;
	int total_lines = get_line_no(text);
	int x, y;
	int start_x = 0, start_y = 0;
	int text_lines = 0, text_cols = 0;
	int total_cols = 0;
	int win_cols = 0;
	int win_lines = 0;
	int i = 0;
	WINDOW *win;
	WINDOW *pad;
	PANEL *panel;

	/* find the widest line of msg: */
	total_lines = get_line_no(text);
	for (i = 0; i < total_lines; i++) {
		const char *line = get_line(text, i);
		int len = get_line_length(line);
		total_cols = max(total_cols, len+2);
	}

	/* create the pad */
	pad = newpad(total_lines+10, total_cols+10);
	wattrset(pad, attributes[SCROLLWIN_TEXT]);
	fill_window(pad, text);

	win_lines = min(total_lines+4, LINES-2);
	win_cols = min(total_cols+2, COLS-2);
	text_lines = max(win_lines-4, 0);
	text_cols = max(win_cols-2, 0);

	/* place window in middle of screen */
	y = (LINES-win_lines)/2;
	x = (COLS-win_cols)/2;

	win = newwin(win_lines, win_cols, y, x);
	keypad(win, TRUE);
	/* show the help in the help window, and show the help panel */
	wattrset(win, attributes[SCROLLWIN_BOX]);
	box(win, 0, 0);
	wattrset(win, attributes[SCROLLWIN_HEADING]);
	mvwprintw(win, 0, 3, " %s ", title);
	panel = new_panel(win);

	/* handle scrolling */
	do {

		copywin(pad, win, start_y, start_x, 2, 2, text_lines,
				text_cols, 0);
		print_in_middle(win,
				text_lines+2,
				0,
				text_cols,
				"<OK>",
				attributes[DIALOG_MENU_FORE]);
		wrefresh(win);

		res = wgetch(win);
		switch (res) {
		case KEY_NPAGE:
		case ' ':
			start_y += text_lines-2;
			break;
		case KEY_PPAGE:
			start_y -= text_lines+2;
			break;
		case KEY_HOME:
			start_y = 0;
			break;
		case KEY_END:
			start_y = total_lines-text_lines;
			break;
		case KEY_DOWN:
		case 'j':
			start_y++;
			break;
		case KEY_UP:
		case 'k':
			start_y--;
			break;
		case KEY_LEFT:
		case 'h':
			start_x--;
			break;
		case KEY_RIGHT:
		case 'l':
			start_x++;
			break;
		}
		if (res == 10 || res == 27 || res == 'q'
		    || res == KEY_F(F_BACK) || res == KEY_F(F_EXIT)) {
			break;
		}
		if (start_y < 0)
			start_y = 0;
		if (start_y >= total_lines-text_lines)
			start_y = total_lines-text_lines;
		if (start_x < 0)
			start_x = 0;
		if (start_x >= total_cols-text_cols)
			start_x = total_cols-text_cols;
	} while (res);

	del_panel(panel);
	delwin(win);
	refresh_all_windows(main_window);
}
Beispiel #23
0
void draw_menu(char ** menu_liste, void (*ptrfonction)(int,const char *, char *), char * folder, int taille_menu){
        ITEM **my_items;
	int c;		
        WINDOW *my_menu_win;
	MENU *my_menu;
	int i;
	ITEM *cur_item;
        my_items = (ITEM **)calloc(taille_menu + 1, sizeof(ITEM *));
        int menu_alrdy_dlt = 0; //pour ne pas supprimer le menu 2 fois --> évite les erreur de segmentation lorsqu'on quitte
        char ** files; //pour le cas ou on utilise F2 (ouvrir un fichier)
        
        int num_choix;
        char choix[FILE_MAX];

	for(i = 0; i < taille_menu; ++i){
	        my_items[i] = new_item(menu_liste[i], ""); //ajoute les éléments dans mon tableau d'item
        }
	//my_items[taille_menu+1] = (ITEM *)NULL; //ajoute un item vide à la fin du tableau
        my_menu = new_menu((ITEM **)my_items); //creer un menu contenan les items
	mvprintw(LINES - 2, 0, "F9 to close the menu"); //affiche un pied de page pour fermer le menu
        
        my_menu_win = newwin(10, 45, (LINES-10)/2, (COLS-45)/2); //créer une nouvelle fenetre
        keypad(my_menu_win, TRUE); //active le clavier pour le menu
       
        
        
        
        /* Set main window and sub window */
        set_menu_win(my_menu, my_menu_win); //set main menu
        set_menu_sub(my_menu, derwin(my_menu_win, 6, 38, 3, 1)); // set sub window
        set_menu_format(my_menu, 5, 1);
        
       /* Set menu mark to the string " * " */
        set_menu_mark(my_menu, " * ");
        
        /* Print a border around the main window and print a title */
        box(my_menu_win, 0, 0);
        print_in_middle(my_menu_win, 1, 0, 45, "Menu Principal", COLOR_PAIR(1));
	mvwaddch(my_menu_win, 2, 0, ACS_LTEE);
	mvwhline(my_menu_win, 2, 1, ACS_HLINE, 43);
	mvwaddch(my_menu_win, 2, 44, ACS_RTEE);
	refresh();
        
	post_menu(my_menu);
	wrefresh(my_menu_win);
       

	while((c = getch()) != KEY_F(9) && c != 27)
	{   switch(c)
	    {	case KEY_F(5):
                        mvprintw(LINES-2, 0, "Exiting...");
                        endwin();			/* End curses mode		  */
                        exit(0);
            
                case KEY_F(2):
                        files = list_file("", &i);
                        clean_menu(my_menu);
                        clean_window(my_menu_win);
                        draw_menu(files, execute_file_menu, "", i);
                        return;
                    
                case KEY_DOWN:
		        menu_driver(my_menu, REQ_DOWN_ITEM);
			break;
		case KEY_UP:
			menu_driver(my_menu, REQ_UP_ITEM);
			break;
                
            
                case KEY_NPAGE:
			menu_driver(my_menu, REQ_SCR_DPAGE);
			break;
                case KEY_PPAGE:
			menu_driver(my_menu, REQ_SCR_UPAGE);
			break;
        
            
                case 10:
                        move(20, 0);
			clrtoeol();
                        num_choix = item_index(current_item(my_menu));
                        strcpy(choix, item_name(current_item(my_menu)));
			//mvprintw(5, 0, "Item selected is : %s", item_name(current_item(my_menu)));
                        clean_menu(my_menu);
                        menu_alrdy_dlt = 1;
                        clean_window(my_menu_win);
                        (*ptrfonction)(num_choix, choix, folder);
			pos_menu_cursor(my_menu);
			break;
                 

		}
                wrefresh(my_menu_win);
	}
        if(menu_alrdy_dlt == 0)
                clean_menu(my_menu);
        clean_window(my_menu_win);
        
       
        
    
}
Beispiel #24
0
int main()
{	ITEM **my_items;
	int c;				
	MENU *my_menu;
        WINDOW *my_menu_win;
        int n_choices, i;
	
	/* Initialize curses */
	initscr();
	start_color();
        cbreak();
        noecho();
	keypad(stdscr, TRUE);
	init_pair(1, COLOR_RED, COLOR_BLACK);

	/* Create items */
        n_choices = ARRAY_SIZE(choices);
        my_items = (ITEM **)calloc(n_choices, sizeof(ITEM *));
        for(i = 0; i < n_choices; ++i)
                my_items[i] = new_item(choices[i], choices[i]);

	/* Crate menu */
	my_menu = new_menu((ITEM **)my_items);

	/* Create the window to be associated with the menu */
        my_menu_win = newwin(10, 40, 4, 4);
        keypad(my_menu_win, TRUE);
     
	/* Set main window and sub window */
        set_menu_win(my_menu, my_menu_win);
        set_menu_sub(my_menu, derwin(my_menu_win, 6, 38, 3, 1));

	/* Set menu mark to the string " * " */
        set_menu_mark(my_menu, " * ");

	/* Print a border around the main window and print a title */
        box(my_menu_win, 0, 0);
	print_in_middle(my_menu_win, 1, 0, 40, "My Menu", COLOR_PAIR(1));
	mvwaddch(my_menu_win, 2, 0, ACS_LTEE);
	mvwhline(my_menu_win, 2, 1, ACS_HLINE, 38);
	mvwaddch(my_menu_win, 2, 39, ACS_RTEE);
	mvprintw(LINES - 2, 0, "F1 to exit");
	refresh();
        
	/* Post the menu */
	post_menu(my_menu);
	wrefresh(my_menu_win);

	while((c = wgetch(my_menu_win)) != KEY_F(1))
	{       switch(c)
	        {	case KEY_DOWN:
				menu_driver(my_menu, REQ_DOWN_ITEM);
				break;
			case KEY_UP:
				menu_driver(my_menu, REQ_UP_ITEM);
				break;
		}
                wrefresh(my_menu_win);
	}	

	/* Unpost and free all the memory taken up */
        unpost_menu(my_menu);
        free_menu(my_menu);
        for(i = 0; i < n_choices; ++i)
                free_item(my_items[i]);
	endwin();
}
Beispiel #25
0
int main_giris()
{	
	ITEM **my_items;
	int c;				
	MENU *my_menu;
	int n_choices, i;
	ITEM *cur_item;	
	WINDOW *my_menu_win;
	
char *anamenu[] = {
        _("Market ") ,
        _("Current Module"),
	_("Cheque Module"),
	_("Stock Module"),
        _("Reports"),
        _("Configuration"),
        _("Help"),
        _("About"),
        _("Exit"),
        (char *)NULL,
                  };
	  
  	(int) signal (SIGINT, sonlandir);
  	(int) signal (SIGILL, sonlandir);
  	(int) signal (SIGTERM, sonlandir);	
		  
	//backup control
	yedek_kontrol_et();

	initscr();
	start_color();
	cbreak();
	noecho();
	keypad(stdscr, TRUE);
	
	//sql configuration 
	ayar_dosyasi_oku ();
	
	ana_win = newwin(LINES, 80, 0, 0);
	temizle_win=newwin(LINES, 80, 0, 0);
	
	init_pair(1, COLOR_WHITE, COLOR_RED);
	init_pair(2, COLOR_WHITE, COLOR_BLUE);
	
	terminal_kontrol_et();
	if (irsaliye_gun_kontrol())  mesaj( _("Some bills not prepared. Don't forget.!") );
			
	kullanici_onayla();
	
	init_pair(1, COLOR_WHITE, COLOR_RED);
	init_pair(2, COLOR_WHITE, COLOR_BLUE);
	
	baslik_goruntule();

    	n_choices = ARRAY_SIZE(anamenu);
	my_items = (ITEM **)calloc(n_choices, sizeof(ITEM *));
	for(i = 0; i < n_choices; ++i)
	my_items[i] = new_item(anamenu[i], " ");

	my_menu = new_menu((ITEM **)my_items);

	my_menu_win = newwin(15, 50, 5, 10);
	keypad(my_menu_win, TRUE);
     
	set_menu_win(my_menu, my_menu_win);
	set_menu_sub(my_menu, derwin(my_menu_win, 10, 40, 4, 2));

	set_menu_mark(my_menu, mark);

	box(my_menu_win, 0, 0);
	print_in_middle(my_menu_win, 1, 0, 45, "Options", COLOR_PAIR(1));
	mvwaddch(my_menu_win, 2, 0, ACS_LTEE);
	mvwhline(my_menu_win, 2, 1, ACS_HLINE, 48);
	mvwaddch(my_menu_win, 2, 49, ACS_RTEE);
        
	post_menu(my_menu);
	wrefresh(my_menu_win);

	while((c = wgetch(my_menu_win)) )
	{       switch(c)
	        {				
			case KEY_DOWN:
				menu_driver(my_menu, REQ_DOWN_ITEM);
				break;
			case KEY_UP:
				menu_driver(my_menu, REQ_UP_ITEM);
				break;
			case 10:
				cur_item = current_item(my_menu);
				    switch(item_index(cur_item) + 1)
				        {
				case 1:	/* Kasa satis */
						//satis
						if ( haklari_kontrol_et(0)==1 )	market_ana_ekran();
							else {mesaj(_("Access denied.!!!"));}
						baslik_goruntule();
						touchwin(my_menu_win);
						wrefresh(my_menu_win);
						baslik_yaz();
						refresh();
						break;
					
				case 2:	/*cari*/
						//stok giris kontrolu
						if ( haklari_kontrol_et(0)==1 )	cari();
							else {mesaj(_("Access denied.!!!"));}
						baslik_goruntule();
						touchwin(my_menu_win);
						wrefresh(my_menu_win);
						baslik_yaz();
						refresh();
						break;
	    			case 3:	/*ceksenet*/
						
						//cari giris kontrolu
						if ( haklari_kontrol_et(1)==1 )	ceksenet();
							else {mesaj(_("Access denied.!!!"));}
						baslik_goruntule();						
						touchwin(my_menu_win);
						wrefresh(my_menu_win);
						baslik_yaz();						
						refresh();
						break;
							
				case 4:	/*stok*/
						
						//cari giris kontrolu
						if ( haklari_kontrol_et(1)==1 )	stok();
							else {mesaj(_("Access denied.!!!"));}
						baslik_goruntule();						
						touchwin(my_menu_win);
						wrefresh(my_menu_win);
						baslik_yaz();						
						refresh();
						break;
							
							
				case 5:	/*raporlar*/

						//rapor giris kontrolu
						if ( haklari_kontrol_et(2)==1 ) raporlar();
						else
						{mesaj(_("Access denied.!!!"));}
						baslik_goruntule();
						touchwin(my_menu_win);
						wrefresh(my_menu_win);
						baslik_yaz();
						refresh();
						break;
						
				case 6:	/*ayarlar*/
						
						ayarlar();
						baslik_goruntule();
						touchwin(my_menu_win);
						wrefresh(my_menu_win);
						baslik_yaz();						
						refresh();
						break;
					
				case 7:/*yardým*/
						
						yardim();

						baslik_goruntule();
						touchwin(my_menu_win);
						wrefresh(my_menu_win);
						baslik_yaz();
						refresh();
						break;
					
				case 8:/*hakkýnda*/
						hakkinda();
					
						baslik_goruntule();
						touchwin(my_menu_win);
						wrefresh(my_menu_win);
						baslik_yaz();
						refresh();
						break;
					
				case 9:/*Kapat*/
					donen_deger=onayla(cikis_onay);
						if (donen_deger==1)
								{
								// donen deger evet ise kapat
								beep();
								touchwin(ana_win);
								wrefresh(ana_win);
								unpost_menu(my_menu);
								free_menu(my_menu);
								for(i = 0; i < n_choices; ++i)
								free_item(my_items[i]);
								endwin();
								return;
								}
						touchwin(ana_win);
						wrefresh(ana_win);								
						touchwin(my_menu_win);
						wrefresh(my_menu_win);		
						break;	
	        }

				wrefresh(my_menu_win);
				pos_menu_cursor(my_menu);
		}
                wrefresh(my_menu_win);
	}	

}
Beispiel #26
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);
}
Beispiel #27
0
int filedlg_display(struct filedlg *fd)
{
    char fmt[16];
    int width, height;
    int lwidth;
    int file;
    int i;
    int statusbar;
    int arrow_attr;
    int count = sbcount(fd->buf->files);
    int hlsearch = cgdbrc_get_int(CGDBRC_HLSEARCH);
    static const char label[] = "Select a file or press q to cancel.";
    int inc_search_attr = hl_groups_get_attr(hl_groups_instance, HLG_INCSEARCH);
    int search_attr = hl_groups_get_attr(hl_groups_instance, HLG_SEARCH);

    swin_curs_set(0);

    statusbar = hl_groups_get_attr(hl_groups_instance, HLG_STATUS_BAR);
    arrow_attr = hl_groups_get_attr(hl_groups_instance, HLG_SELECTED_LINE_ARROW);

    /* Check that a file is loaded */
    if (fd == NULL || fd->buf == NULL || fd->buf->files == NULL) {
        swin_wrefresh(fd->win);
        return 0;
    }

    /* Initialize variables */
    height = swin_getmaxy(fd->win);
    width = swin_getmaxx(fd->win);

    /* The status bar and display line 
     * Fake the display function to think the height is 2 lines less */
    height -= 2;

    /* Set starting line number (center source file if it's small enough) */
    if (count < height)
        file = (count - height) / 2;
    else {
        file = fd->buf->sel_line - height / 2;
        if (file > count - height)
            file = count - height;
        else if (file < 0)
            file = 0;
    }

    /* Print 'height' lines of the file, starting at 'file' */
    lwidth = log10_uint(count) + 1;
    snprintf(fmt, sizeof(fmt), "%%%dd", lwidth);

    print_in_middle(fd->win, 0, width, label);

    swin_wmove(fd->win, 0, 0);

    for (i = 1; i < height + 1; i++, file++) {
        swin_wmove(fd->win, i, 0);

        /* Outside of filename, just finish drawing the vertical file */
        if (file < 0 || file >= count) {
            int j;

            for (j = 1; j < lwidth; j++)
                swin_waddch(fd->win, ' ');
            swin_waddch(fd->win, '~');

            swin_wattron(fd->win, SWIN_A_BOLD);
            swin_waddch(fd->win, SWIN_SYM_VLINE);
            swin_wattroff(fd->win, SWIN_A_BOLD);

            for (j = 2 + lwidth; j < width; j++)
                swin_waddch(fd->win, ' ');
            continue;
        }

        int x, y;
        char *filename = fd->buf->files[file];

        /* Mark the current file with an arrow */
        if (file == fd->buf->sel_line) {
            swin_wattron(fd->win, SWIN_A_BOLD);
            swin_wprintw(fd->win, fmt, file + 1);
            swin_wattroff(fd->win, SWIN_A_BOLD);

            swin_wattron(fd->win, arrow_attr);
            swin_waddch(fd->win, '-');
            swin_waddch(fd->win, '>');
            swin_wattroff(fd->win, arrow_attr);

        }
        else {
            /* Ordinary file */
            swin_wprintw(fd->win, fmt, file + 1);

            swin_wattron(fd->win, SWIN_A_BOLD);
            swin_waddch(fd->win, SWIN_SYM_VLINE);
            swin_wattroff(fd->win, SWIN_A_BOLD);

            swin_waddch(fd->win, ' ');
        }

        y = swin_getcury(fd->win);
        x = swin_getcurx(fd->win);

        hl_printline(fd->win, filename, strlen(filename),
                     NULL, -1, -1, fd->buf->sel_col, width - lwidth - 2);

        if (hlsearch && fd->last_hlregex) {
            struct hl_line_attr *attrs = hl_regex_highlight(
                    &fd->last_hlregex, filename, search_attr);

            if (sbcount(attrs)) {
                hl_printline_highlight(fd->win, filename, strlen(filename),
                             attrs, x, y, fd->buf->sel_col, width - lwidth - 2);
                sbfree(attrs);
            }
        }

        if (regex_search && file == fd->buf->sel_line) {
            struct hl_line_attr *attrs = hl_regex_highlight(
                    &fd->hlregex, filename, inc_search_attr);

            if (sbcount(attrs)) {
                hl_printline_highlight(fd->win, filename, strlen(filename),
                             attrs, x, y, fd->buf->sel_col, width - lwidth - 2);
                sbfree(attrs);
            }
        }
    }

    /* Add the 2 lines back in so the status bar can be drawn */
    height += 2;

    /* Update status bar */
    swin_wmove(fd->win, height, 0);

    /* Print white background */
    swin_wattron(fd->win, statusbar);

    for (i = 0; i < width; i++)
        swin_mvwprintw(fd->win, height - 1, i, " ");

    if (regex_search && regex_direction)
        swin_mvwprintw(fd->win, height - 1, 0, "Search:%s", regex_line);
    else if (regex_search)
        swin_mvwprintw(fd->win, height - 1, 0, "RSearch:%s", regex_line);

    swin_wattroff(fd->win, statusbar);

    swin_wmove(fd->win, height - (file - fd->buf->sel_line) - 1, lwidth + 2);
    swin_wrefresh(fd->win);

    return 0;
}
Beispiel #28
0
void Menu(int *value)
{
    ITEM **my_items;
  	int c;
  	MENU *my_menu;
    WINDOW *my_menu_win;
    int n_choices, i;
    int output = 3;

  	// Create Menu items
          n_choices = ARRAY_SIZE(choices);
          my_items = (ITEM **)calloc(n_choices, sizeof(ITEM *));
          for(i = 0; i < n_choices; ++i)
                  my_items[i] = new_item(choices[i], "");

  	// Crate Menu
  	my_menu = new_menu((ITEM **)my_items);

  	// Create the window to be associated with the menu
          my_menu_win = newwin(15, 50, 4, 4);
          keypad(my_menu_win, TRUE);          // Enable keyboard on that window

  	// Set main window and sub window
          set_menu_win(my_menu, my_menu_win);
          set_menu_sub(my_menu, derwin(my_menu_win, 6, 38, 3, 1));

  	// Set menu mark to the string " * "
          set_menu_mark(my_menu, " * ");

  	// Print a border around the main window and print a title
          box(my_menu_win, 0, 0);
  	print_in_middle(my_menu_win, 1, 0, 50, "THE GAME", COLOR_PAIR(1));
  	mvwaddch(my_menu_win, 2, 0, ACS_LTEE);
  	mvwhline(my_menu_win, 2, 1, ACS_HLINE, 48);
  	mvwaddch(my_menu_win, 2, 39, ACS_RTEE);

  	/* Post the menu */
  	post_menu(my_menu);
  	wrefresh(my_menu_win);              // Refres the window

    bool done = false;
  	while(!done && (c = wgetch(my_menu_win)) != 'q' )
  	{       switch(c)
  	        {	case KEY_DOWN:
        				menu_driver(my_menu, REQ_DOWN_ITEM);
        				break;
        			case KEY_UP:
        				menu_driver(my_menu, REQ_UP_ITEM);
        				break;
              case 10:          // ENTER was pressed
          			if(item_index(current_item(my_menu)) == 0)
                { // First menu item was selected (Play)
                  output = 1;
                  done = true;
                }
                if(item_index(current_item(my_menu)) == 1)
                { // Second menu item was selected (Help))
                  output = 2;
                  done = true;
                }
                if(item_index(current_item(my_menu)) == 2)
                { // Third menu item was selected (Exit)
                  output = 3;
                  done = true;
                }
                  break;
  		      }
            wrefresh(my_menu_win);              // Refres the window
  	}

  	// Unpost and free all the memory taken up
          unpost_menu(my_menu);
          free_menu(my_menu);
          for(i = 0; i < n_choices; ++i)
                  free_item(my_items[i]);
  	endwin();
    *value = output;
}
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;
}
int quicksort(void) {
	WINDOW *win1;
	FILE *fp1;
	int max_x, max_y, start_y, start_x, starty_of_box, height_of_box = 3;
	int choice, random = 1, ret_val;
	char c;
	data qcsort;

	init_sort_info(&qcsort); /* initialise number of swaps and comparisons to 0 */
	cbreak();
	init_pair(2, COLOR_RED, COLOR_BLACK);
	
	fp1 = fopen("files/quicksort.txt", "r");
	if(fp1 == NULL) { /* display error */
		fprintf(stdout, "\vfopen: files/quicksort.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 the max dimensions of the screen */
	print_in_middle(stdscr, 3, 0, max_x, "QUICKSORT", 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 Quicksort */
	
	instruction(max_y - 2, 0, "Press <ENTER> to CONTINUE or 'p' to return to the previous menu.");
	c = getch();
	if(c == 'p') {
		clear();
		curs_set(TRUE);
		fclose(fp1);
		return 0;
	}	
	else {
		(qcsort.comparisons)++; /* this is incremented as the partition function has a do...while */
		get_num_elem(&qcsort); /* 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(&qcsort); /* randomly generate 'elements' numbers and store in qcsort.numbers[elements] */
			message(max_y); /* print "generating random numbers..." */
		}
		clear();
		
		print_in_middle(stdscr, 3, 0, max_x, "QUICKSORT", COLOR_PAIR(3));
		
		instruction(max_y - 3, 0, "Press <ENTER> to START.");
		instruction(max_y - 2, 0, "Press 'p' to go to the Main Menu.");
		curs_set(FALSE); /* curs_set(TRUE) shows a dirty cursor at top-left of the box */
		
		attron(A_BOLD);
		print_numbers(&qcsort, max_y, max_x);
		attroff(A_BOLD);
		win1 = NULL; /* win1 will be used for displaying the final box after each iteration */
		choice = getch();
		if(choice == 'p') {
			clear();
			curs_set(TRUE);
			fclose(fp1);
			free(qcsort.numbers);
			return 0;
		}	
		else if(choice == ENTER) { /* start the animation */
			move(max_y - 3, 0);
			clrtoeol();
			attron(A_BOLD);
			mvprintw(max_y - 12, 0, "RED: Current position of pivot.");
			mvprintw(max_y - 10, 0, "GREEN: 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);
			
			ret_val = quicksort_driver(qcsort.numbers, 0, qcsort.elements - 1, max_y, max_x, &qcsort, win1);
			if(ret_val == INT_MIN) { /* exit */
				clear();
				curs_set(TRUE);
				fclose(fp1);
				free(qcsort.numbers);
				return 0;
			}	
			
			sleep(1);
			starty_of_box = (max_y - height_of_box) / 4 + 5;
			move(starty_of_box - 2, 0); /* to delete the letter 'i' which remains after the animation */
			clrtoeol();
			move(starty_of_box - 1, 0); /* to delete the letter 'j' which remains after the animation */
			clrtoeol();
			clear_boxes(starty_of_box); /* clear the boxes off the screen */
			move(max_y - 19, 0);
			clrtobot();
			attron(A_BOLD);
			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", qcsort.swaps);
			mvprintw(max_y - 9, max_x / 4 + 15, "Number of comparisons = %d", qcsort.comparisons);
		}
		curs_set(TRUE);
		move(max_y - 5, 0);
		clrtobot();
		instruction(max_y - 2, 0, "Press any key to continue.\n");
		getch();
	}
	attroff(A_BOLD);
	fclose(fp1);
	free(qcsort.numbers);
	return 0;
}