diff options
author | Christophe Grenier <[email protected]> | 2012-01-01 18:44:44 +0100 |
---|---|---|
committer | Christophe Grenier <[email protected]> | 2012-01-01 18:44:44 +0100 |
commit | 7b769570102a1ef5323145123df86f22d2b97b13 (patch) | |
tree | 3fd7b0751ba95db9cbf58e8319a2c3d618bd5bc0 /src | |
parent | e4429ca8c24234160bd28c05ad00d89633879640 (diff) |
Add WINDOW *window argument to get_string()
Diffstat (limited to 'src')
-rw-r--r-- | src/chgtypen.c | 3 | ||||
-rw-r--r-- | src/edit.c | 6 | ||||
-rw-r--r-- | src/geometry.c | 12 | ||||
-rw-r--r-- | src/intrfn.c | 121 | ||||
-rw-r--r-- | src/intrfn.h | 2 |
5 files changed, 75 insertions, 69 deletions
diff --git a/src/chgtypen.c b/src/chgtypen.c index 95bdece9..2e81a205 100644 --- a/src/chgtypen.c +++ b/src/chgtypen.c @@ -112,8 +112,9 @@ static void change_part_type_ncurses(const disk_t *disk_car,partition_t *partiti aff_part(stdscr,AFF_PART_ORDER|AFF_PART_STATUS,disk_car,partition); screen_buffer_display(stdscr,"",menuType); wmove(stdscr,LINES-2,0); + wclrtoeol(stdscr); wprintw(stdscr,"New partition type [current %02x] ? ",partition->arch->get_part_type(partition)); - if (get_string(response, sizeof(response), NULL) > 0) { + if (get_string(stdscr, response, sizeof(response), NULL) > 0) { int tmp_val = strtol(response, NULL, 16); partition->arch->set_part_type(partition,tmp_val); } @@ -152,7 +152,7 @@ static void interface_editor_position(const disk_t *disk_car,uint64_t *lba) case 'C': sprintf(def, "%lu", position.cylinder); mvwaddstr(stdscr,INTER_GEOM_Y, INTER_GEOM_X, "Enter the number of cylinders: "); - if (get_string(response, sizeof(response), def) > 0) { + if (get_string(stdscr, response, sizeof(response), def) > 0) { tmp_val = atol(response); if (tmp_val < disk_car->geom.cylinders) { position.cylinder = tmp_val; @@ -164,7 +164,7 @@ static void interface_editor_position(const disk_t *disk_car,uint64_t *lba) case 'H': sprintf(def, "%u", position.head); mvwaddstr(stdscr,INTER_GEOM_Y, INTER_GEOM_X, "Enter the number of heads: "); - if (get_string(response, sizeof(response), def) > 0) { + if (get_string(stdscr, response, sizeof(response), def) > 0) { tmp_val = atoi(response); if (tmp_val < disk_car->geom.heads_per_cylinder) { position.head = tmp_val; @@ -176,7 +176,7 @@ static void interface_editor_position(const disk_t *disk_car,uint64_t *lba) case 'S': sprintf(def, "%u", position.sector); mvwaddstr(stdscr,INTER_GEOM_Y, INTER_GEOM_X, "Enter the number of sectors per track: "); - if (get_string(response, sizeof(response), def) > 0) { + if (get_string(stdscr, response, sizeof(response), def) > 0) { tmp_val = atoi(response); if (tmp_val > 0 && tmp_val <= disk_car->geom.sectors_per_head ) { position.sector = tmp_val; diff --git a/src/geometry.c b/src/geometry.c index 16f36f82..8f382453 100644 --- a/src/geometry.c +++ b/src/geometry.c @@ -211,7 +211,8 @@ static int change_geometry_ncurses(disk_t *disk_car) { sprintf(def, "%lu", disk_car->geom.cylinders); mvwaddstr(stdscr,INTER_GEOM_Y, INTER_GEOM_X, "Enter the number of cylinders: "); - if (get_string(response, sizeof(response), def) > 0) { + wclrtoeol(stdscr); + if (get_string(stdscr, response, sizeof(response), def) > 0) { tmp_val = atol(response); if (tmp_val > 0) { disk_car->geom.cylinders = tmp_val; @@ -229,7 +230,8 @@ static int change_geometry_ncurses(disk_t *disk_car) { sprintf(def, "%u", disk_car->geom.heads_per_cylinder); mvwaddstr(stdscr,INTER_GEOM_Y, INTER_GEOM_X, "Enter the number of heads: "); - if (get_string(response, sizeof(response), def) > 0) { + wclrtoeol(stdscr); + if (get_string(stdscr, response, sizeof(response), def) > 0) { tmp_val = atoi(response); if (tmp_val > 0 && tmp_val <= MAX_HEADS) { disk_car->geom.heads_per_cylinder = tmp_val; @@ -249,7 +251,8 @@ static int change_geometry_ncurses(disk_t *disk_car) sprintf(def, "%u", disk_car->geom.sectors_per_head); /* FIXME SUN partition can have more than 63 sectors */ mvwaddstr(stdscr,INTER_GEOM_Y, INTER_GEOM_X, "Enter the number of sectors per track (1-63): "); - if (get_string(response, sizeof(response), def) > 0) + wclrtoeol(stdscr); + if (get_string(stdscr, response, sizeof(response), def) > 0) { tmp_val = atoi(response); /* TODO Check for the maximum value */ @@ -270,7 +273,8 @@ static int change_geometry_ncurses(disk_t *disk_car) { sprintf(def, "%u", disk_car->sector_size); mvwaddstr(stdscr,INTER_GEOM_Y, INTER_GEOM_X, "Enter the sector size (512, 1024, 2048, 4096, 8192): "); - if (get_string(response, sizeof(response), def) > 0) { + wclrtoeol(stdscr); + if (get_string(stdscr, response, sizeof(response), def) > 0) { tmp_val = atoi(response); if(change_sector_size(disk_car, cyl_modified, tmp_val)) wprintw(stdscr,"Illegal sector size"); diff --git a/src/intrfn.c b/src/intrfn.c index a3a32bad..8df69a70 100644 --- a/src/intrfn.c +++ b/src/intrfn.c @@ -86,70 +86,69 @@ extern int intr_nbr_line; static int wmenuUpdate(WINDOW *window, const int yinfo, int y, int x, const struct MenuItem *menuItems, const unsigned int itemLength, const char *available, const int menuType, unsigned int current); static int wgetch_nodelay(WINDOW *window); -int get_string(char *str, const int len, const char *def) +int get_string(WINDOW *window, char *str, const int len, const char *def) { - int c; - int i = 0; - int x, y; - int use_def = FALSE; - curs_set(1); - getyx(stdscr, y, x); - wclrtoeol(stdscr); - str[0] = 0; + int c; + int i = 0; + int x, y; + int use_def = FALSE; + curs_set(1); + getyx(window, y, x); + str[0] = 0; - if (def != NULL) { - mvwaddstr(stdscr,y, x, def); - wmove(stdscr,y, x); - use_def = TRUE; - } + if (def != NULL) { + mvwaddstr(window,y, x, def); + wmove(window,y, x); + use_def = TRUE; + } - wrefresh(stdscr); - while ((c = wgetch(stdscr)) != '\n' && c != key_CR + wrefresh(window); + while ((c = wgetch(window)) != '\n' && c != key_CR #ifdef PADENTER - && c!= PADENTER + && c!= PADENTER #endif - ) - { - switch (c) { - /* escape is generated by enter from keypad */ - /* - case key_ESC: - wmove(stdscr,y, x); - wclrtoeol(stdscr); - curs_set(0); - wrefresh(stdscr); - return GS_key_ESCAPE; - */ - case KEY_DC: - case KEY_BACKSPACE: - if (i > 0) { - str[--i] = 0; - mvaddch(y, x+i, ' '); - wmove(stdscr,y, x+i); - } else if (use_def) { - wclrtoeol(stdscr); - use_def = FALSE; - } - break; - default: - if (i < len && isprint(c)) { - mvaddch(y, x+i, c); - if (use_def) { - wclrtoeol(stdscr); - use_def = FALSE; - } - str[i++] = c; - str[i] = 0; - } - } - wrefresh(stdscr); + ) + { + switch (c) { + /* escape is generated by enter from keypad */ + /* + case key_ESC: + wmove(window,y, x); + wclrtoeol(window); + curs_set(0); + wrefresh(window); + return GS_key_ESCAPE; + */ + case KEY_DC: + case KEY_BACKSPACE: + if (i > 0) { + str[--i] = 0; + mvwaddch(window, y, x+i, ' '); + wmove(window,y, x+i); + } else if (use_def) { + wclrtoeol(window); + use_def = FALSE; + } + break; + default: + if (i < len && isprint(c)) { + mvwaddch(window, y, x+i, c); + if (use_def) { + wclrtoeol(window); + use_def = FALSE; + } + str[i++] = c; + str[i] = 0; + } } - curs_set(0); - wrefresh(stdscr); - if (use_def) - return GS_DEFAULT; - else - return i; + wrefresh(window); + } + curs_set(0); + wrefresh(window); + if (use_def) + return GS_DEFAULT; + else + return i; } static int wgetch_nodelay(WINDOW *window) @@ -555,8 +554,9 @@ unsigned long long int ask_number(const unsigned long long int val_cur, const un va_end(ap); waddstr(stdscr, res); waddstr(stdscr, res2); + wclrtoeol(stdscr); sprintf(def, "%llu", val_cur); - if (get_string(response, sizeof(response), def) > 0) + if (get_string(stdscr, response, sizeof(response), def) > 0) { unsigned long int tmp_val; #ifdef HAVE_ATOLL @@ -1224,7 +1224,8 @@ char *ask_log_location(const char*filename) wbkgdset(stdscr,' ' | COLOR_PAIR(0)); wmove(stdscr,9,0); wprintw(stdscr,"to abort log file creation.\n"); - if (get_string(response, sizeof(response), NULL) > 0) + wclrtoeol(stdscr); + if (get_string(stdscr, response, sizeof(response), NULL) > 0) return response; return NULL; } diff --git a/src/intrfn.h b/src/intrfn.h index 253988cb..161d2611 100644 --- a/src/intrfn.h +++ b/src/intrfn.h @@ -57,7 +57,7 @@ int end_ncurses(void); int interface_partition_type_ncurses(disk_t *disk_car); int vaff_txt(int line, WINDOW *window, const char *_format, va_list ap) __attribute__((format(printf, 3, 0))); char *ask_log_location(const char*filename); -int get_string(char *str, const int len, const char *def); +int get_string(WINDOW *window, char *str, const int len, const char *def); #endif void display_message(const char*msg); |