int main(int argc, char *argv[]) { WINDOW *my_win; int startx, starty, width, height; int ch; initscr(); /* Start curses mode */ 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(); /* End curses mode */ return 0; }
void init_ammo() { current_ammo = MAX_AMMO; ammo_screen_starting_y = TOTAL_SCREEN_ROWS/2 + MAIN_SCREEN_ROWS/2; ammo_screen_starting_x = TOTAL_SCREEN_COLS/2 - AMMO_SCREEN_COLS/2; ammo_screen = create_newwin (AMMO_SCREEN_ROWS, AMMO_SCREEN_COLS, ammo_screen_starting_y, ammo_screen_starting_x); render_ammo(); }
void wrapNcs::printEquations(string eqLeft,string eqRight,string operation) { winEQ = create_newwin(height, width+3, starty, startx); mvprintw((starty-2)+height/2,startx+width/2,"%s",eqLeft.c_str()); mvprintw((starty-2)+(height/2) +1,startx+width/2,"%s",eqRight.c_str()); mvprintw((starty-2)+height/2 +1,((startx)+width/2) -1,"%s",operation.c_str()); mvprintw(((starty-2)+(height/2))+2,((startx)+width/2) ,"%s","______"); curserReposition(); char temp[80]; getstr(temp); str.assign(temp); }
static void create_date_edit (void) { GtkWidget *datedit; TestGnomeApp *app; time_t curtime = time(NULL); datedit = gnome_date_edit_new(curtime,1,1); app = create_newwin(TRUE,"testGNOME","Date Edit"); bonobo_window_set_contents (BONOBO_WINDOW (app->app), datedit); gtk_widget_show(datedit); gtk_widget_show(app->app); }
static void create_entry(void) { TestGnomeApp *app; GtkWidget *entry; app = create_newwin(TRUE,"testGNOME","Entry"); entry = gnome_entry_new("test-entry"); g_assert(entry != NULL); bonobo_window_set_contents(BONOBO_WINDOW(app->app), entry); gtk_widget_show(entry); gtk_widget_show(app->app); }
Console::Console(void) { initscr(); // Start curses mode cbreak(); // Disable line buffering // nocbreak(); start_color(); // Enable color support init_pair(1, COLOR_WHITE, COLOR_BLUE); init_pair(2, COLOR_RED, COLOR_WHITE); // Chat cursor y-position chat_curs_y = CHAT_WINDOW_STARTY; // CMD cursor x-position cmd_curs_x = CMD_WINDOW_STARTX; // Disable cursor curs_set(0); // Setup chat and command windows chat_window = create_newwin(LINES - CMD_WINDOW_HEIGHT, COLS, 0, 0); cmd_window = create_newwin(CMD_WINDOW_HEIGHT, COLS, LINES - CMD_WINDOW_HEIGHT, 0); // Initial running state running = true; // Set window background colors wbkgd(chat_window, COLOR_PAIR(1)); wbkgd(cmd_window, COLOR_PAIR(2)); // Set initial window content mvwprintw(chat_window, CHAT_WINDOW_STARTY, CHAT_WINDOW_STARTX, CHAT_WINDOW_CONTENT); mvwprintw(cmd_window, CMD_WINDOW_STARTY, CMD_WINDOW_STARTX, CMD_WINDOW_CONTENT); wmove(cmd_window, CMD_WINDOW_STARTY, CMD_WINDOW_STARTX + 2); // Paint initial frame refresh(); }
/** 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(); }
/* * PixmapEntry */ static void create_pixmap_entry(void) { TestGnomeApp *app; GtkWidget *entry; app = create_newwin (TRUE, "testGNOME", "Pixmap Entry"); entry = gnome_pixmap_entry_new ("Foo", "Pixmap", TRUE); bonobo_window_set_contents (BONOBO_WINDOW (app->app), entry); gtk_widget_show (entry); gtk_widget_show (app->app); }
static void create_icon_list(void) { TestGnomeApp *app; GtkWidget *sw; GtkWidget *iconlist; GdkPixbuf *pix; int i; app = create_newwin(TRUE,"testGNOME","Icon List"); sw = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); bonobo_window_set_contents (BONOBO_WINDOW (app->app), sw); gtk_widget_set_size_request (sw, 430, 300); gtk_widget_show (sw); iconlist = gnome_icon_list_new (80, NULL, GNOME_ICON_LIST_IS_EDITABLE); gtk_container_add (GTK_CONTAINER (sw), iconlist); g_signal_connect (iconlist, "select_icon", G_CALLBACK (select_icon), NULL); g_signal_connect (iconlist, "unselect_icon", G_CALLBACK (unselect_icon), NULL); GTK_WIDGET_SET_FLAGS(iconlist, GTK_CAN_FOCUS); pix = gdk_pixbuf_new_from_xpm_data ((const gchar **)bomb_xpm); gtk_widget_grab_focus (iconlist); gnome_icon_list_freeze (GNOME_ICON_LIST (iconlist)); for (i = 0; i < 30; i++) { gnome_icon_list_append_pixbuf (GNOME_ICON_LIST(iconlist), pix, "bomb.xpm", "Foo"); gnome_icon_list_append_pixbuf (GNOME_ICON_LIST(iconlist), pix, "bomb.xpm", "Bar"); gnome_icon_list_append_pixbuf (GNOME_ICON_LIST(iconlist), pix, "bomb.xpm", "LaLa"); } gnome_icon_list_append (GNOME_ICON_LIST(iconlist), "non-existant.png", "No Icon"); gnome_icon_list_set_selection_mode (GNOME_ICON_LIST (iconlist), GTK_SELECTION_EXTENDED); gnome_icon_list_thaw (GNOME_ICON_LIST (iconlist)); gtk_widget_show (iconlist); gtk_widget_show(app->app); }
void cockpit_init() { initscr(); /* Start curses mode */ cbreak(); if(has_colors() == FALSE) { endwin(); printf("Your terminal does not support color\n"); exit(1); } start_color(); // Start color init_pair(1, COLOR_BLUE, COLOR_BLACK); init_pair(2, COLOR_RED, COLOR_BLACK); init_pair(3, COLOR_RED, COLOR_WHITE); init_pair(4, COLOR_BLACK, COLOR_RED); //check if the screen is big enough if((LINES < MIN_ROW)| (COLS < MIN_COL)){ endwin(); printf("your screen is too small %d x %d ,please resize it !\n",LINES,COLS); exit(1); } //generate separating line attron(COLOR_PAIR(1)); mvhline(COCKPIT_HEIGHT+1,0,'=',COLS); attroff(COLOR_PAIR(1)); refresh(); roll=newwin(ROLL_HEIGHT,ROLL_WIDTH, ROLL_Y,ROLL_X); show_roll(roll,0); pitch=newwin(PITCH_HEIGHT,PITCH_WIDTH, PITCH_Y,PITCH_X); show_pitch(pitch,0); yaw=newwin(YAW_HEIGHT,YAW_WIDTH, YAW_Y,YAW_X); show_yaw(yaw,0); heading=newwin(HEAD_HEIGHT,HEAD_WIDTH,HEAD_Y,HEAD_X); show_heading(heading,0); other=newwin(OTHER_HEIGHT,OTHER_WIDTH,OTHER_Y,OTHER_X); console=create_newwin(CONSOLE_HEIGHT,COLS, COCKPIT_HEIGHT+2,0); keypad(console,TRUE); scrollok(console,TRUE); printx(console,"please enter the COM name,enter 'y' to use default /dev/ttyUSB0:"); wrefresh(console); }
void wrapNcs::printInfo(string information, int flag) { winINFO = create_newwin(hInfo,wInfo,yInfo,xInfo); if(flag==1) //lets use green color for indicating success. init_pair(1, COLOR_GREEN, COLOR_BLACK); else // lets use red color for indicating error. init_pair(1, COLOR_RED, COLOR_BLACK); /* Some decoration console can afford*/ attron(A_BOLD); attron(COLOR_PAIR(1)); mvprintw(yInfo+1,xInfo+1,"%s",information.c_str()); attroff(A_BOLD); attroff(COLOR_PAIR(1)); }
static void create_file_entry(void) { TestGnomeApp *app; GtkWidget *entry; GtkWidget *l1,*l2; GtkWidget *but; GtkWidget *box; app = create_newwin(TRUE,"testGNOME","File Entry"); box = gtk_vbox_new(FALSE,5); entry = gnome_file_entry_new("Foo","Bar"); gtk_box_pack_start(GTK_BOX(box),entry,FALSE,FALSE,0); l1 = gtk_label_new("File name: "); gtk_box_pack_start(GTK_BOX(box),l1,FALSE,FALSE,0); l2 = gtk_label_new("File name(if exists only): "); gtk_box_pack_start(GTK_BOX(box),l2,FALSE,FALSE,0); but = gtk_button_new_with_label("Update file labels"); g_object_set_data(G_OBJECT(but),"l1",l1); g_object_set_data(G_OBJECT(but),"l2",l2); g_signal_connect(but,"clicked", G_CALLBACK(file_entry_update_files), entry); gtk_box_pack_start(GTK_BOX(box),but,FALSE,FALSE,0); but = gtk_toggle_button_new_with_label("Make browse dialog modal"); g_signal_connect(but,"toggled", G_CALLBACK(file_entry_modal_toggle), entry); gtk_box_pack_start(GTK_BOX(box),but,FALSE,FALSE,0); but = gtk_toggle_button_new_with_label("Directory only picker"); g_signal_connect(but,"toggled", G_CALLBACK(file_entry_directory_toggle), entry); gtk_box_pack_start(GTK_BOX(box),but,FALSE,FALSE,0); bonobo_window_set_contents (BONOBO_WINDOW(app->app), box); gtk_widget_show_all(app->app); }
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); }
static void create_href(void) { TestGnomeApp *app; GtkWidget *vbox, *href, *ent1, *ent2, *wid; app = create_newwin(TRUE,"testGNOME","HRef test"); vbox = gtk_vbox_new(FALSE, 5); gtk_container_set_border_width(GTK_CONTAINER(vbox), 5); bonobo_window_set_contents(BONOBO_WINDOW(app->app), vbox); href = gnome_href_new("http://www.gnome.org/", "Gnome Website"); gtk_box_pack_start(GTK_BOX(vbox), href, FALSE, FALSE, 0); wid = gtk_hseparator_new(); gtk_box_pack_start(GTK_BOX(vbox), wid, TRUE, FALSE, 0); wid = gtk_label_new("The launch behaviour of the\n" "configured with the control center"); gtk_box_pack_start(GTK_BOX(vbox), wid, TRUE, FALSE, 0); ent1 = gtk_entry_new(); gtk_entry_set_text (GTK_ENTRY(ent1), "http://www.gnome.org/"); gtk_box_pack_start (GTK_BOX(vbox), ent1, TRUE, TRUE, 0); ent2 = gtk_entry_new (); gtk_entry_set_text (GTK_ENTRY(ent2), "Gnome Website"); gtk_box_pack_start (GTK_BOX(vbox), ent2, TRUE, TRUE, 0); wid = gtk_button_new_with_label ("set href props"); g_object_set_data (G_OBJECT(wid), "href", href); g_object_set_data (G_OBJECT(wid), "url", ent1); g_object_set_data (G_OBJECT(wid), "label", ent2); g_signal_connect (wid, "clicked", G_CALLBACK(href_cb), NULL); gtk_box_pack_start (GTK_BOX(vbox), wid, TRUE, TRUE, 0); gtk_widget_show_all(app->app); }
int main(int argc, char** argv) { initscr(); cbreak(); noecho(); curs_set(FALSE); if (has_colors() == TRUE) { start_color(); init_pair(1, COLOR_GREEN, COLOR_BLACK); init_pair(2, COLOR_YELLOW, COLOR_BLACK); init_pair(3, COLOR_MAGENTA, COLOR_BLACK); init_pair(4, COLOR_RED, COLOR_BLACK); init_pair(5, COLOR_BLACK, COLOR_BLACK); init_pair(6, COLOR_CYAN, COLOR_BLACK); if (can_change_color() == TRUE) { init_color(COLOR_WHITE, 1000, 0, 0); init_pair(7, COLOR_WHITE, COLOR_BLACK); } } int height = 20; int width = 30; WINDOW *mapwin; mapwin = create_newwin(height, width, (LINES - height) / 2, (COLS - width) / 2); Framework * fm = new Framework("Player_A", "Test_Dungeon", stdscr); fm->play(); endwin(); return 0; }
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; }
int main(void) { int l_init = 0; l_init = zlog_init("/etc/zlog.conf"); if (l_init) { printf("logging init failed"); return -1; } c = zlog_get_category("hngui"); if (!c) { printf("Logging init (category) fail\n"); return -1; } zlog_info(c, "Program starting... "); DIR *d; struct dirent *dir; d = opendir("/var/tmp"); if (d) { while ((dir = readdir(d)) != NULL) { zlog_info(c, "%s", dir->d_name); } closedir(d); } zlog_info(c, "Created Tree From Sample Text.."); SetExpansionState(tree, TRUE); LogPrintTree(c, tree, PRINT_ONLY_EXPANDED_NODES); zlog_info(c, "Tree Size: %d\n", TotalSize(tree)); initscr(); mousemask(ALL_MOUSE_EVENTS, NULL); cbreak(); noecho(); nonl(); curs_set(0); keypad(stdscr, TRUE); start_color(); curs_set(0); init_pair(1, COLOR_YELLOW, COLOR_BLACK); init_pair(2, COLOR_RED, COLOR_BLACK); init_pair(3, COLOR_YELLOW, COLOR_BLUE); init_pair(4, COLOR_RED, COLOR_BLUE); int startx, starty, width, height; height = LINES - 2; width = COLS - 2; starty = (LINES - height) / 4; /* Calculating for a center placement */ startx = (COLS - width) / 2; /* of */ refresh(); win = create_newwin(height, width, starty, startx); if (win == NULL) { zlog_info(c, "Window Was null...\n"); endwin(); printf("Window was null??\n"); return -1; } zlog_info(c, "Rendering Tree into window %p \n", win); RenderTreeIntoWindow(tree); refresh(); wrefresh(win); int ch; while ((ch = getch()) != KEY_F(4)) { zlog_info(c, "Trapped Keypress %d", ch ); MEVENT event; switch (ch) { case KEY_RESIZE: zlog_info(c, "Resize()"); RenderTreeIntoWindow(tree); refresh(); wrefresh(win); break; case KEY_F(3): zlog_info(c, "F3=> Refresh"); RefreshData(); break; case KEY_LEFT: zlog_info(c, "Left key"); toggleExpand(win, false); break; case KEY_RIGHT: zlog_info(c, "Right key"); toggleExpand(win, true); break; case KEY_UP: zlog_info(c, "Up Key"); moveUp(win); break; case KEY_DOWN: zlog_info(c, "Down Key"); moveDown(win); break; } if (getmouse(&event) == OK) { zlog_info(c, "Mouse => %d, %d", event.x, event.y); } //LogPrintTree(c, tree, PRINT_ALL_TREE); } endwin(); return 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); }
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); }
/** * 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 main (void) { /* * Defimovanie lokálnych premenných funkcie */ WINDOW *my_win, *info_win, *smyle_win; int startx, starty, w_width, w_height; int width, height; int poloha_x, poloha_y; int old_x, old_y; int oznacil; short zacal; int min; int ch; char *dopln; int i, j, u, z; //long start_time, end_time; /* Inicializovanie/zapnutie curses módu */ initscr(); /* inicializácie konfigurácie */ config_init(); /* Kontrola či terminál podporuje farby */ if (has_colors() == FALSE) { endwin(); printf("Vas terminal nepodporuje farby!\n"); exit(1); } /* * Aktivácia pomocných funkcií pre curses mód * * raw - vypnutie bufferovania riadkov (disable line buffering) * * noecho - po stlačení kláves sa nebudú vypisovať * curs_set - vypnutie kurzoru (schovanie) * start_color - zapnutie podpory farieb * keypad - aktivácia F kláves (F1, F2...) */ raw(); cbreak(); noecho(); //nodelay(stdscr, true); curs_set(0); use_default_colors(); start_color(); keypad(stdscr, TRUE); /* Inicializovanie generátoru náhodných čísel */ srand(time(0)); /* * Inicializovanie párov farieb * * 0 - základný systémový/všeobecný * 1 - zvýraznenie vybraného políčka * 2 - farba neuhádnutej míny * 3 - farba uhádnutej míny * 4 - farba zle označenej míny * * 5 - farba čísla 1 * 6 - farba čísla 2 * 7 - farba čísla 3 * 8 - farba čísla 4 * 9 - farba čísla 5 * 10 - farba čísla 6 * 11 - farba čísla 7 * 12 - farba čísla 8 */ init_pair(1, COLOR_WHITE, COLOR_RED); init_pair(2, COLOR_YELLOW, COLOR_DEFAULT); init_pair(3, COLOR_GREEN, COLOR_DEFAULT); init_pair(4, COLOR_RED, COLOR_DEFAULT); init_pair(5, COLOR_BLUE, COLOR_DEFAULT); init_pair(6, COLOR_GREEN, COLOR_DEFAULT); init_pair(7, COLOR_RED, COLOR_DEFAULT); init_pair(8, COLOR_CYAN, COLOR_DEFAULT); init_pair(9, COLOR_MAGENTA, COLOR_DEFAULT); init_pair(10, COLOR_YELLOW, COLOR_DEFAULT); init_pair(11, COLOR_BLACK, COLOR_DEFAULT); init_pair(12, COLOR_WHITE, COLOR_DEFAULT); /* definícia menovky restart, sem sa presunieme pomocou goto pre reštart hry */ restart: /* Zistí rozmery terminálu */ getmaxyx(stdscr, row, col); /* Priradenie hodnôt premenným */ min = miny_config.miny; width = 30; height = 16; w_height = height + 2; w_width = width + 2; oznacil = 0; poloha_x = 1; poloha_y = 1; zacal = 0; //start_time = time(NULL); //end_time = 0; /* Pridelenie pamate podľa konfigurácie */ pridel_pamet(width, height); /* Vynulovanie hodnôt v poliach... */ for (i = 0; i < width; i++) { for (j = 0; j < height; j++) { min_pole[i][j] = 0; uhadol[i][j] = 0; pole_hodnot[i][j] = 0; } } /* vycentruje hru na obrazovke */ if (miny_config.vycentruj == 1) { starty = (row - w_height) / 2; startx = (col - (w_width * 2 + 2)) / 2; } else { /* položí na ľavú stranu a mierne odsadí od okrajov */ starty = 1; startx = 2; } /* Vypísať na reálnu obrazovku (Print to real screen) */ refresh(); printw("Copyright © 2013 Juraj Oravec\n"); /* Vytvorenie curses "okien" */ my_win = create_newwin(w_height, w_width, starty, startx); info_win = create_newwin(w_height, w_width, starty, startx + 34); smyle_win = create_newwin(6, 10, starty + 11, startx + 34 + 12); /* "odstránenie" rámiku okolo okna so smajlíkom */ wborder(smyle_win, ' ', ' ', ' ',' ',' ',' ',' ',' '); wrefresh(smyle_win); /* Výpis do informačného okna */ mvwprintw(info_win, 1, (w_width - strlen(NAZOV)) / 2, NAZOV); mvwprintw(info_win, 3, 2, "Pocet min: %d", min); wattron(info_win, A_BOLD); mvwprintw(info_win, 3, 25, " 0/%d", min); wattroff(info_win, A_BOLD); mvwprintw(info_win, 4, 2, "Minove pole: %d x %d", width, height); /* vypísať polohu kurzoru len ak je to povolené v konfigurácii */ if (miny_config.info_poloha == 1) mvwprintw(info_win, 5, 2, "Poloha kurzoru: X: %d, Y: %d", poloha_x, poloha_y); /* Refresh/Obnova informačného okna, aby sa zobrazilo čo sme vypoísali */ wrefresh(info_win); /* Zobrazenie smajlíka */ smajlik_init(smyle_win); /* * vyber_min -> Základná poloha kurzoru v ľavom hornom rohu * mini_rozhadz -> Náhodne rozmiestni míny po hracom poli */ vyber_min(my_win, width, height, poloha_x, poloha_y, 0, 0); mini_rozhadz(0, width, height, min); /* * Nekonečný cyklus pre zisťovanie stlačenia kláves * Program sa ukonćí funkciou exit() po stlačení 'q' */ while ( ( ch = getch() ) ) { /* Uloženie starej polohy kurzoru pre ďalśie spracovanie */ old_x = poloha_x; old_y = poloha_y; /* * switch/prepínač pre "kontrolu" stlačených kláves * a podľa toho vykoná nejakú akciu... */ switch (ch) { /* * Stlačenie šípky vľavo, * nasleduje posun kurzoru vľavo, ak je to možné */ case KEY_LEFT: if (hra == 1) { if (poloha_x > 1) poloha_x--; } break; /* * Stlačenie šípky vpravo, * nasleduje posun kurzoru vpravo, ak je to možné */ case KEY_RIGHT: if (hra == 1) { if (poloha_x < width) poloha_x++; } break; /* * Stlačenie šípky hore, * nasleduje posun kurzoru hore, ak je to možné */ case KEY_UP: if (hra == 1) { if (poloha_y > 1) poloha_y--; } break; /* * Stlačenie šípky dole, * nasleduje posun kurzoru dole, ak je to možné */ case KEY_DOWN: if (hra == 1) { if (poloha_y < height) poloha_y++; } break; case 'a': /* * Nástroj pre programátora, testera... * označí všetky prázdne polia v hre */ if (miny_config.vyvojar == 1) { for (u = 0; u < width; u++) for (z = 0; z < height; z++) { if (min_pole[u][z] == 0) vyber_dopln((u + 1), (z + 1), width, height, my_win); } wrefresh(my_win); } break; /* Označenie míny */ case 'm': if (hra == 1) { /* Kontrola neoznaćeného políčka */ if (uhadol[(poloha_x - 1)][(poloha_y - 1)] != 1 && uhadol[(poloha_x - 1)][(poloha_y - 1)] != 2) { /* Vypísanie označenia míny, refresh hracieho poľa, uloženie označenia */ mvwprintw(my_win, poloha_y, poloha_x, "*"); wrefresh(my_win); uhadol[(poloha_x - 1)][(poloha_y - 1)] = 2; oznacil++; vypis_oznacene(info_win, oznacil, min); } else if (uhadol[(poloha_x - 1)][(poloha_y - 1)] == 2) { /* Ak je mína už označená tak bude označenie zrušené */ mvwprintw(my_win, poloha_y, poloha_x, " "); wrefresh(my_win); uhadol[(poloha_x - 1)][(poloha_y - 1)] = 0; oznacil--; vypis_oznacene(info_win, oznacil, min); } } break; /* Ukončenie programu s kódom 0 - správne ukončenie */ case 'q': endwin(); exit(0); break; /* reštartovanie hry */ case 'r': if (miny_config.vyvojar == 1) { /* príprava na reštart... */ restart_prepare (my_win, info_win, smyle_win, width, height); /* prestavenie identifikátoru stavu hry na play/hrať/1/OK... */ hra = 1; /* preskočenie na menovku restart */ goto restart; } break; /* Medzera - Výber políčka na hracom poli */ case ' ': if (hra == 1) { /* * Pokiaľ je aktívna voľba cisty_start tak sa bude mínové pole generovař pokiaľ * na daných súradniciach bude mína, keď nebude, tak prestane. */ if (miny_config.cisty_start == 1 && zacal == 0) { if (miny_config.nulovy_start == 1) { while (TRUE) { for (u = 0; u < width; u++) { for (z = 0; z < height; z++) { /* Vymazanie mín z hracieho poľa */ min_pole[u][z] = 0; } } mini_rozhadz(0, width, height, min); if (min_okolo(poloha_x, poloha_y, width, height) == 0 && min_pole[(poloha_x - 1)][(poloha_y - 1)] == 0) break; } } else if (min_pole[(poloha_x - 1)][(poloha_y - 1)] == 1) { while (TRUE) { for (u = 0; u < width; u++) { for (z = 0; z < height; z++) { /* Vymazanie mín z hracieho poľa */ min_pole[u][z] = 0; } } mini_rozhadz(0, width, height, min); if (min_pole[(poloha_x - 1)][(poloha_y - 1)] == 0) break; } } zacal = 1; } /* Ak trafil na mínu */ if (min_pole[(poloha_x - 1)][(poloha_y - 1)] == 1) { if (uhadol[(poloha_x - 1)][(poloha_y - 1)] == 0) { /* zobrazí všetky míny, vypíše zásah */ mini_zobraz(my_win, width, height); /* Zobrazí smutného smajlíka */ smajlik (smyle_win, 2); /* zastaví hru, teda zmení stav na koniec/stop/KO/... */ hra = 0; } } else { /* * Ak trafil na prázdne pole * vypíše koľko mín sa nachádza v okolí toho poľa */ vyber_dopln(poloha_x, poloha_y, width, height, my_win); /* Refresh okien */ /*wrefresh(info_win);*/ wrefresh(my_win); /* kontrola dokončenia hry */ if (dokoncil(width, height) == 1) { /* ak boli označené všetky "prázdne polia" vypíše všetky míny na zeleno, správne vyplnenie.. */ mini_zobraz(my_win, width, height); oznacil = min; vypis_oznacene(info_win, oznacil, min); //end_time = time(NULL); hra = 0; } } } else if (hra == 0) { /* príprava na reštart... */ restart_prepare (my_win, info_win, smyle_win, width, height); /* prestavenie identifikátoru stavu hry na play/hrať/1/OK... */ hra = 1; zacal = 0; /* preskočenie na menovku restart */ goto restart; } break; } /* Posunutie kurzora, ak sa zmenila jeho poloha */ if (poloha_x != old_x || poloha_y != old_y) vyber_min(my_win, width, height, poloha_x, poloha_y, old_x, old_y); /* pokiaľ je aktívne vypisovanie polohy... */ if (miny_config.info_poloha == 1) { /* Doplnenie prázdneho miesta za súradnice kurzoru */ if (poloha_x < 10 && poloha_y < 10) dopln = " "; else if (poloha_x < 10 || poloha_y < 10) dopln = " "; /* Výpis polohy kurzoru */ mvwprintw(info_win, 5, 2, "Poloha kurzoru: X: %d, Y: %d%s", poloha_x, poloha_y, dopln); } /* refreš info okna */ wrefresh(info_win); } /* Ukončenie curses modu */ endwin(); /* Ukončenie programu */ return 0; }
int main(int argc, char *argv[]) { WINDOW *send_win, *people_win; win_s send, people; int ch; int port, i = 0; char *host, *name; pthread_t read_pid; pt_s pt; if (argc != 4) { fprintf(stderr, "usage: %s <host> <port> <nickname>\n", argv[0]); return 0; } host = argv[1]; port = atoi(argv[2]); for (i = 0; i < strlen(argv[3]); i++) { pt.wbuf[i] = argv[3][i]; } fprintf(stdout, "OK in 46\n"); // setlocale(LC_ALL, "zh_CN.UTF-8"); initscr(); raw(); echo(); keypad(stdscr, TRUE); if(has_colors() == FALSE) { endwin(); printf("Your terminal does not support color\n"); return 1; } start_color(); init_pair(1, COLOR_GREEN, COLOR_BLACK); init_pair(2, COLOR_YELLOW, COLOR_BLACK); init_pair(3, COLOR_BLUE, COLOR_BLACK); init_pair(4, COLOR_CYAN, COLOR_BLACK); send.height = 5; send.width = COLS - 20; send.startx = 0; send.starty = LINES - 5; refresh(); send_win = create_newwin(send, "SEND"); refresh(); pt.clientfd = open_clientfd(host, port); Rio_readinitb(&(pt.rio), pt.clientfd); pt.wbuf[strlen(argv[3])] = '\n'; Rio_writen(pt.clientfd, pt.wbuf, strlen(pt.wbuf)); pt.wbuf[strlen(argv[3])] = ':'; pthread_create(&read_pid, NULL, read_thread, &pt); int name_len = strlen(argv[3]) + 1; while (mvwgetnstr(send_win, 0, 0, pt.wbuf + name_len, MAXLINE - name_len) != ERR) { pt.wbuf[strlen(pt.wbuf)] = '\n'; Rio_writen(pt.clientfd, pt.wbuf, strlen(pt.wbuf)); bzero(pt.wbuf + name_len, MAXLINE - name_len); werase(send_win); } endwin(); return 0; }
int main(int argc, char *argv[]) { struct sockaddr_in serv_addr; struct hostent *server; char outputBuffer[BUFFER_SIZE]; char outputBufferErr[BUFFER_SIZE]; strcpy(outputBufferErr, "ERROR: Message is too big"); //outputBufferErr[strlen(outputBufferErr)]='\n'; if (argc < 2) { fprintf(stderr,"usage %s hostname\n", argv[0]); exit(0); } server = gethostbyname(argv[1]); if (server == NULL) { fprintf(stderr,"ERROR, no such host\n"); exit(0); } // TCP: CREATE SOCKET if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { printf("ERROR opening socket\n"); } serv_addr.sin_family = AF_INET; serv_addr.sin_port = htons(PORT); serv_addr.sin_addr = *((struct in_addr *)server->h_addr); bzero(&(serv_addr.sin_zero), 8); // TCP: CONNECT if (connect(sockfd,(struct sockaddr *) &serv_addr,sizeof(serv_addr)) < 0) { printf("ERROR connecting\n"); close(sockfd); exit(1); } // Create windows initscr(); //Init nCurses if(has_colors() == FALSE) { endwin(); printf("Your terminal does not support color\n"); exit(1); } wInput = create_newwin(4, COLS, LINES-5, 0); wOutput = create_newwin(LINES-5,COLS,0,0); start_color(); init_pair(3, COLOR_BLUE, COLOR_BLACK); init_pair(2, COLOR_RED, COLOR_WHITE); init_pair(1, COLOR_YELLOW, COLOR_BLACK); scrollok(wOutput,TRUE); lineIndex = 0; mvwprintw(wInput,2,1,msg); wrefresh(wInput); mvwprintw(wInput,2,1,msg); wrefresh(wInput); // TCP: READ initial messages from the server if(read(sockfd,inputBuffer,BUFFER_SIZE) > 0) // Welcome message { wattron(wOutput,COLOR_PAIR(2)); mvwprintw(wOutput,lineIndex+1,1,"My ID is %s",inputBuffer); wattroff(wOutput,COLOR_PAIR(2)); lineIndex++; UUID = atoi(inputBuffer); if(read(sockfd,inputBuffer,BUFFER_SIZE) >0) //Welcome message { wattron(wOutput,COLOR_PAIR(2)); mvwprintw(wOutput,lineIndex+1,1,"%s",inputBuffer); wattroff(wOutput,COLOR_PAIR(2)); lineIndex++; wrefresh(wOutput); pthread_create(&readerHandler,NULL,reader,NULL); } } while(TRUE) { bzero(outputBuffer,BUFFER_SIZE); wgetstr(wInput,outputBuffer); mvwprintw(wInput,2,1,msg); wclrtoeol(wInput); wrefresh(wInput); // New Message if(strlen(outputBuffer) > 1) { outputBuffer[strlen(outputBuffer)]='\n'; // TCP: WRITE message if (strlen(outputBuffer) > COLS-strlen(msg)-4) { if(lineIndex < LINES-7) { wattron(wOutput,COLOR_PAIR(1)); mvwprintw(wOutput,lineIndex+1,1,"SERVER > %s",outputBufferErr); wattroff(wOutput,COLOR_PAIR(1)); lineIndex++; } else // Scroll { wattron(wOutput,COLOR_PAIR(1)); mvwprintw(wOutput,LINES-7,1,"SERVER > %s",outputBufferErr); wattroff(wOutput,COLOR_PAIR(1)); wclrtoeol(wOutput); scroll(wOutput); box(wOutput, 0 , 0); } wrefresh(wOutput); } else { write(sockfd,outputBuffer,BUFFER_SIZE); pthread_mutex_lock(&mutexLock); if(lineIndex < LINES-7) { wattron(wOutput,COLOR_PAIR(1)); mvwprintw(wOutput,lineIndex+1,1,"Me > %s",outputBuffer); wattroff(wOutput,COLOR_PAIR(1)); lineIndex++; } else // Scroll { wattron(wOutput,COLOR_PAIR(1)); mvwprintw(wOutput,LINES-7,1,"Me > %s",outputBuffer); wattroff(wOutput,COLOR_PAIR(1)); wclrtoeol(wOutput); scroll(wOutput); box(wOutput, 0 , 0); } wrefresh(wOutput); pthread_mutex_unlock(&mutexLock); } } if(outputBuffer[0] == '/' && outputBuffer[1] == 'q') { break; } } endwin(); // TCP: CLOSE SOCKET close(sockfd); return 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); }
/* trafvol_section_init This function creates the trafvol section window and the fields inside it. Returncodes: 0: ok -1: error */ static int trafvol_section_init(const int debuglvl, int height, int width, int startx, int starty, unsigned int ifac_num) { size_t i = 0; int rows = 0, cols = 0; int max_height = 0, max_width = 0, toprow = 0, num_rows = (int)ifac_num; unsigned int ifacs = 0, ifac_fields = 0, ifac_start = 4; /* get and check the screen dimentions */ getmaxyx(stdscr, max_height, max_width); if(width > max_width) return(-1); /* set the number of fields: interfacename, today in, today out, yesterday in, yesterday out, 7 days in, 7 days out, this month in, this month out, last month in, last month out */ TrafVolSection.n_fields = 11 * (size_t)ifac_num; /* alloc the needed memory */ if(!(TrafVolSection.fields = (FIELD **)calloc(TrafVolSection.n_fields + 1, sizeof(FIELD *)))) { (void)vrprint.error(-1, VR_ERR, gettext("calloc failed: %s (in: %s:%d)."), strerror(errno), __FUNC__, __LINE__); return(-1); } /* create iface stats fields */ for(ifacs = 0, ifac_fields = 0; ifacs < ifac_num; ifacs++) { toprow = (int)(ifac_start+ifacs); /* interface name */ TrafVolSection.fields[ifac_fields] = new_field(1, 15, toprow, 0, 0, 1); set_field_buffer_wrap(debuglvl, TrafVolSection.fields[ifac_fields], 1, "ifacname"); ifac_fields++; TrafVolSection.fields[ifac_fields] = new_field(1, 5, toprow, 16, 0, 1); set_field_buffer_wrap(debuglvl, TrafVolSection.fields[ifac_fields], 1, "t-in"); ifac_fields++; TrafVolSection.fields[ifac_fields] = new_field(1, 5, toprow, 22, 0, 1); set_field_buffer_wrap(debuglvl, TrafVolSection.fields[ifac_fields], 1, "t-ou"); ifac_fields++; TrafVolSection.fields[ifac_fields] = new_field(1, 5, toprow, 28, 0, 1); set_field_buffer_wrap(debuglvl, TrafVolSection.fields[ifac_fields], 1, "y-in"); ifac_fields++; TrafVolSection.fields[ifac_fields] = new_field(1, 5, toprow, 34, 0, 1); set_field_buffer_wrap(debuglvl, TrafVolSection.fields[ifac_fields], 1, "y-ou"); ifac_fields++; TrafVolSection.fields[ifac_fields] = new_field(1, 5, toprow, 40, 0, 1); set_field_buffer_wrap(debuglvl, TrafVolSection.fields[ifac_fields], 1, "7-in"); ifac_fields++; TrafVolSection.fields[ifac_fields] = new_field(1, 5, toprow, 46, 0, 1); set_field_buffer_wrap(debuglvl, TrafVolSection.fields[ifac_fields], 1, "7-ou"); ifac_fields++; TrafVolSection.fields[ifac_fields] = new_field(1, 5, toprow, 52, 0, 1); set_field_buffer_wrap(debuglvl, TrafVolSection.fields[ifac_fields], 1, "t-in"); ifac_fields++; TrafVolSection.fields[ifac_fields] = new_field(1, 5, toprow, 58, 0, 1); set_field_buffer_wrap(debuglvl, TrafVolSection.fields[ifac_fields], 1, "t-ou"); ifac_fields++; TrafVolSection.fields[ifac_fields] = new_field(1, 5, toprow, 64, 0, 1); set_field_buffer_wrap(debuglvl, TrafVolSection.fields[ifac_fields], 1, "l-in"); ifac_fields++; TrafVolSection.fields[ifac_fields] = new_field(1, 5, toprow, 70, 0, 1); set_field_buffer_wrap(debuglvl, TrafVolSection.fields[ifac_fields], 1, "l-ou"); ifac_fields++; } /* terminate the field array */ TrafVolSection.fields[TrafVolSection.n_fields] = NULL; /* create the window and the panel */ if(!(TrafVolSection.win = create_newwin(height, width, startx, starty, gettext("Traffic Volume Section"), vccnf.color_win))) { (void)vrprint.error(-1, VR_ERR, gettext("creating window failed.")); return(-1); } if(!(TrafVolSection.panel[0] = new_panel(TrafVolSection.win))) { (void)vrprint.error(-1, VR_ERR, gettext("creating panel failed.")); return(-1); } /* field options */ for(i = 0; i < TrafVolSection.n_fields; i++) { if(debuglvl >= LOW) set_field_back(TrafVolSection.fields[i], vccnf.color_win); else set_field_back(TrafVolSection.fields[i], vccnf.color_win); field_opts_off(TrafVolSection.fields[i], O_AUTOSKIP); /* set status to false */ set_field_status(TrafVolSection.fields[i], FALSE); } /* Create the form and post it */ if(!(TrafVolSection.form = new_form(TrafVolSection.fields))) { (void)vrprint.error(-1, VR_ERR, gettext("creating form failed.")); return(-1); } /* Calculate the area required for the form */ scale_form(TrafVolSection.form, &rows, &cols); keypad(TrafVolSection.win, TRUE); /* Set main window and sub window */ set_form_win(TrafVolSection.form, TrafVolSection.win); set_form_sub(TrafVolSection.form, derwin(TrafVolSection.win, rows, cols, 1, 2)); if(post_form(TrafVolSection.form) != E_OK) { (void)vrprint.error(-1, VR_ERR, gettext("posting the form failed.")); return(-1); } mvwprintw(TrafVolSection.win, 3, 2, gettext("Interface")); mvwprintw(TrafVolSection.win, 2, 18, gettext("Today")); mvwprintw(TrafVolSection.win, 3, 18, gettext("In")); mvwprintw(TrafVolSection.win, 3, 24, gettext("Out")); mvwprintw(TrafVolSection.win, 2, 30, gettext("Yesterday")); mvwprintw(TrafVolSection.win, 3, 30, gettext("In")); mvwprintw(TrafVolSection.win, 3, 36, gettext("Out")); mvwprintw(TrafVolSection.win, 2, 42, gettext("7-days")); mvwprintw(TrafVolSection.win, 3, 42, gettext("In")); mvwprintw(TrafVolSection.win, 3, 48, gettext("Out")); mvwprintw(TrafVolSection.win, 2, 54, gettext("This month")); mvwprintw(TrafVolSection.win, 3, 54, gettext("In")); mvwprintw(TrafVolSection.win, 3, 60, gettext("Out")); mvwprintw(TrafVolSection.win, 2, 66, gettext("Last month")); mvwprintw(TrafVolSection.win, 3, 66, gettext("In")); mvwprintw(TrafVolSection.win, 3, 72, gettext("Out")); mvwhline(TrafVolSection.win, 4, 1, ACS_HLINE, 76); mvwaddch(TrafVolSection.win, 4, 0, ACS_LTEE); mvwaddch(TrafVolSection.win, 4, 77, ACS_RTEE); mvwvline(TrafVolSection.win, 5, 17, ACS_VLINE, num_rows); mvwaddch(TrafVolSection.win, 4, 17, ACS_TTEE); mvwvline(TrafVolSection.win, 5, 23, ACS_VLINE, num_rows); mvwaddch(TrafVolSection.win, 4, 23, ACS_TTEE); mvwvline(TrafVolSection.win, 5, 29, ACS_VLINE, num_rows); mvwaddch(TrafVolSection.win, 4, 29, ACS_TTEE); mvwvline(TrafVolSection.win, 5, 35, ACS_VLINE, num_rows); mvwaddch(TrafVolSection.win, 4, 35, ACS_TTEE); mvwvline(TrafVolSection.win, 5, 41, ACS_VLINE, num_rows); mvwaddch(TrafVolSection.win, 4, 41, ACS_TTEE); mvwvline(TrafVolSection.win, 5, 47, ACS_VLINE, num_rows); mvwaddch(TrafVolSection.win, 4, 47, ACS_TTEE); mvwvline(TrafVolSection.win, 5, 53, ACS_VLINE, num_rows); mvwaddch(TrafVolSection.win, 4, 53, ACS_TTEE); mvwvline(TrafVolSection.win, 5, 59, ACS_VLINE, num_rows); mvwaddch(TrafVolSection.win, 4, 59, ACS_TTEE); mvwvline(TrafVolSection.win, 5, 65, ACS_VLINE, num_rows); mvwaddch(TrafVolSection.win, 4, 65, ACS_TTEE); mvwvline(TrafVolSection.win, 5, 71, ACS_VLINE, num_rows); mvwaddch(TrafVolSection.win, 4, 71, ACS_TTEE); /* don't print this line if it overlaps with the window border */ if(5 + num_rows + 1 < height) { mvwhline(TrafVolSection.win, 5 + num_rows, 1, ACS_HLINE, 76); mvwaddch(TrafVolSection.win, 5 + num_rows, 0, ACS_LTEE); mvwaddch(TrafVolSection.win, 5 + num_rows, 77, ACS_RTEE); } mvwaddch(TrafVolSection.win, 5 + num_rows, 17, ACS_BTEE); mvwaddch(TrafVolSection.win, 5 + num_rows, 23, ACS_BTEE); mvwaddch(TrafVolSection.win, 5 + num_rows, 29, ACS_BTEE); mvwaddch(TrafVolSection.win, 5 + num_rows, 35, ACS_BTEE); mvwaddch(TrafVolSection.win, 5 + num_rows, 41, ACS_BTEE); mvwaddch(TrafVolSection.win, 5 + num_rows, 47, ACS_BTEE); mvwaddch(TrafVolSection.win, 5 + num_rows, 53, ACS_BTEE); mvwaddch(TrafVolSection.win, 5 + num_rows, 59, ACS_BTEE); mvwaddch(TrafVolSection.win, 5 + num_rows, 65, ACS_BTEE); mvwaddch(TrafVolSection.win, 5 + num_rows, 71, ACS_BTEE); return(0); }
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 main(void) { char expr[1000] = " "; char *postfix; char *err; int ln = -2, cnt = 2; int width, height; char *title = "Expression Evaluator"; WINDOW *title_win, *work_win; char *e; char *num = NULL; char curr[2] = {'\0', '\0'}; char *prev; int r; // stacks for operands and operators. strstack *operands = createStrstack(); strstack *operators = createStrstack(); initscr(); refresh(); getmaxyx(stdscr, height, width); // create the title and working windows. title_win = create_newwin(3, width, 0, 0, true); work_win = create_newwin(height-2, width, 3, 0, false); // print title. mvwprintw(title_win, 1, (width - (int)strlen(title))/2, "%s", title); wrefresh(title_win); // REPL loop scrollok(work_win, TRUE); while(strcmp(expr, "exit") != 0) { if (ln > height/2) { wscrl(work_win, 2); refresh(); } else { ln += cnt; cnt = 0; } mvwprintw(work_win, ln+cnt++, 1, ">> ", ln); wrefresh(work_win); wgetstr(work_win, expr); // check to make sure the expression is not empty. if (strlen(expr) == 0) { cnt--; continue; } // clean INFIX expression err = cleanInfixExpression(expr); if (strlen(err) != 0) { mvwprintw(work_win, ln+cnt++, 4, "Could not clean expression. [%s]", err); continue; } else { mvwprintw(work_win, ln+cnt, 4, "INFIX: "); // Print expression and go through character by character. wattron(work_win, A_BOLD); wattron(work_win, A_STANDOUT); mvwprintw(work_win, ln+cnt++, 11, "%s", expr); wattroff(work_win, A_STANDOUT); wattroff(work_win, A_BOLD); } // check INFIX expression err = checkInfixExpression(expr); if (strlen(err) != 0) { mvwprintw(work_win, ln+cnt++, 4, "%s", err); continue; } emptyStrstack(operators); free(operators); operators = createStrstack(); emptyStrstack(operands); free(operands); operands = createStrstack(); e = malloc(sizeof(char) * (strlen(expr) + 1)); strcpy(e, expr); num = e; for(r = 0; r < strlen(expr); r++) { printStacks(work_win, operands, operators, ln+cnt+3, 4); // check if the current character is an operator. wattron(work_win, A_DIM); if (isOperator(expr[r])) { mvwprintw(work_win, ln+cnt+1, 4, "This is an operator."); // save current operator. curr[0] = e[r]; e[r] = 0; // push the current operand. if (strlen(num) != 0) { mvwprintw(work_win, ln+cnt+2, 4, "Push the number."); pushStrstack(operands, num); printStacks(work_win, operands, operators, ln+cnt+3, 4); } // check for operator precedence. for (prev = peekStrstack(operators); prev != NULL && prev[0] != '(' && operateNow(prev[0], curr[0]); prev = peekStrstack(operators)) { reducePushPostfix(operands, operators); printStacks(work_win, operands, operators, ln+cnt+3, 4); } // push the current opeator pushStrstack(operators, curr); printStacks(work_win, operands, operators, ln+cnt+3, 4); num = e + r + 1; } else if (e[r] == '(') { // (, then just push the opening bracket and move the number // pointer. curr[0] = e[r]; pushStrstack(operators, curr); printStacks(work_win, operands, operators, ln+cnt+3, 4); num = e + r + 1; } else if (e[r] == ')') { e[r] = 0; // push the last number. if (strlen(num) != 0) { pushStrstack(operands, num); printStacks(work_win, operands, operators, ln+cnt+3, 4); } for (prev = peekStrstack(operators); prev != NULL && prev[0] != '('; prev = peekStrstack(operators)) { reducePushPostfix(operands, operators); printStacks(work_win, operands, operators, ln+cnt+3, 4); } // pop the '(' out. popStrstack(operators, &num); printStacks(work_win, operands, operators, ln+cnt+3, 4); num = e + r + 1; } else { mvwprintw(work_win, ln+cnt+1, 4, " "); mvwprintw(work_win, ln+cnt+2, 4, " "); } // Print the two stacks. wattroff(work_win, A_DIM); wattron(work_win, A_BOLD); mvwprintw(work_win, ln+cnt, 11+r, "^"); wattroff(work_win, A_BOLD); wrefresh(work_win); usleep(1000000); mvwprintw(work_win, ln+cnt, 11+r, " "); } // push the last number. if (strlen(num) != 0) { pushStrstack(operands, num); printStacks(work_win, operands, operators, ln+cnt+3, 4); } while(!isEmptyStrstack(operators)) { reducePushPostfix(operands, operators); printStacks(work_win, operands, operators, ln+cnt+3, 4); } // get the POSTFIX expression. popStrstack(operands, &num); mvwprintw(work_win, ln+cnt++, 4, "POSTFIX: %s", num); // clear the stack display. printStacks(work_win, NULL, NULL, ln+cnt+3, 0); wrefresh(work_win); } endwin(); return; }
int main(int argc, char** argv){ int port,sd,row,col,crow,ccol,ctcol; char buffer[BUFFSIZE],tmp[BUFFSIZE]; char username[MAXUSERSIZE],*user;//samething temp holder variable if(argc!=4){ fprintf(stderr,"Usage: %s takes 3 arguments a server, a portname, and a username", argv[0]); exit(EXIT_FAILURE); } port= atoi(argv[2]); bzero(username,MAXUSERSIZE); memcpy(username,argv[3],strlen(argv[3])); user=username; // their_addr.sin_family=AF_INET; // their_addr.sin_port = htons(port); //if(!inet_aton(argv[1], &their_addr.sin_addr.s_addr)){ // fprintf(stderr,"%s requires a valid server address", argv[0]); // exit(EXIT_FAILURE); //} struct addrinfo* ai,*ac; struct addrinfo hints; hints.ai_family = AF_INET; hints.ai_socktype = SOCK_DGRAM; hints.ai_flags = 0; hints.ai_protocol = port; hints.ai_canonname = NULL; hints.ai_addr = NULL; hints.ai_next = NULL; if(getaddrinfo(argv[1],argv[2],NULL,&ai)<0){ close(sd); fprintf(stderr,"please input a vaild server!\n",argv[1]); exit(EXIT_FAILURE); } for (ac = ai; ac != NULL; ac = ac->ai_next) { sd = socket(AF_INET, SOCK_DGRAM,0); fcntl(sd, F_SETFL, O_NONBLOCK); if (sd == -1) continue; if (connect(sd, ac->ai_addr, ac->ai_addrlen) != -1) break; /* Success */ close(sd); } // their_addr.sin_addr.s_addr=ai.ai_addr; // memset(&(their_addr.sin_zero),'\0',8); //char host[NI_MAXHOST],service[NI_MAXSERV]; WINDOW *chat_win,*text_win,*user_win; // if(connect(sd,ai->ai_addr,ai->ai_addrlen)){ // close(sd); // fprintf(stderr,"Failed to connect to %s!\n",argv[1]); // exit(EXIT_FAILURE); // }else{ initscr(); crow=1; ccol=2; ctcol=2; getmaxyx(stdscr,row,col); chat_win=create_newwin(row-3,col-30,0,0); user_win=create_newwin(row-2,col,0,col-30); text_win=create_newwin(3,col,row-3,0); scrollok(chat_win, TRUE); idlok(chat_win,TRUE); scrollok(text_win, TRUE); noecho(); if(sd!=-1){ mvwprintw(chat_win,crow++,ccol,"connected to server %s",argv[1]); wrefresh(chat_win); }else{ mvwprintw(chat_win,crow++,ccol,"couldn't connect to server %s ... exiting",argv[1]); wrefresh(chat_win); sleep(1); delwin(text_win); delwin(chat_win); delwin(user_win); endwin(); return 0; } // } int bsize=BUFFSIZE; int nread; //send user name to server bzero(buffer,BUFFSIZE); bzero(tmp,BUFFSIZE); memcpy(buffer,username,strlen(username)); send(sd,buffer,strlen(username),0); int i=0; int j; char c; int getusers=1; wmove(text_win,1,ctcol); wrefresh(text_win); while(1){ bzero(buffer,BUFFSIZE); if(kbhit()){ c=getchar(); if(c=='\r') continue; tmp[i]=c; i++; mvwaddch(text_win,1,ctcol,c); wrefresh(text_win); ctcol++; while(1){ if(kbhit()){ c=getchar(); if(c=='\r') break; if(c==(char)127||c==(char)8){ if(i>0){ ctcol--; wmove(text_win,1,ctcol); wdelch(text_win); wrefresh(text_win); tmp[i]='\0'; i--; } continue; } if(i>BUFFSIZE) continue; tmp[i]=c; i++; mvwaddch(text_win,1,ctcol,c); wrefresh(text_win); ctcol++; } if((nread=recvp(chat_win,&crow,ccol,col-28,user_win,user,sd,buffer,BUFFSIZE,0))!=-1){ wmove(text_win,1,ctcol); wrefresh(text_win); } } } if(i>0){ if(memcmp(tmp,"clear\0",6)==0){ wmove(chat_win,1,ccol); wclrtobot(chat_win); box(chat_win, 0 , 0); wrefresh(chat_win); box(text_win,0,0); wrefresh(text_win); crow=1; ccol=1; }else{ send(sd,tmp,i,0); } wmove(text_win,1,0); wclrtoeol(text_win); wrefresh(text_win); ctcol=1; i=0; bzero(tmp,BUFFSIZE); } if((nread=recvp(chat_win,&crow,ccol,col-28,user_win,user,sd,buffer,BUFFSIZE,0))!=-1){ wmove(text_win,1,ctcol); wrefresh(text_win); if(memcmp(buffer,"close\0",6)==0){ sleep(1); break; } //onetime thing if(getusers){ getusers=0; memcpy(tmp,":users:",7); send(sd,tmp,7,0); bzero(tmp,BUFFSIZE); } } } close(sd); delwin(text_win); delwin(chat_win); delwin(user_win); endwin(); return 0; }
WINDOW *affichage_init_Chat (void){ winChat = create_newwin((LINES/2)-15, COLS-92, (LINES/2)+14 , 47); wnoutrefresh(winChat); return winChat; }
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; }