Commit dec69da8 authored by Sam Ravnborg's avatar Sam Ravnborg

kconfig: fixup after Lindent

Readability are more important then the 80 coloumn limit, so fold
several lines to greatly improve readability.
Also keep return type on same line as function definition.
Signed-off-by: default avatarSam Ravnborg <sam@ravnborg.org>
parent b1c5f1c6
...@@ -28,8 +28,8 @@ static int list_width, check_x, item_x, checkflag; ...@@ -28,8 +28,8 @@ static int list_width, check_x, item_x, checkflag;
/* /*
* Print list item * Print list item
*/ */
static void static void print_item(WINDOW * win, const char *item, int status, int choice,
print_item(WINDOW * win, const char *item, int status, int choice, int selected) int selected)
{ {
int i; int i;
...@@ -59,8 +59,7 @@ print_item(WINDOW * win, const char *item, int status, int choice, int selected) ...@@ -59,8 +59,7 @@ print_item(WINDOW * win, const char *item, int status, int choice, int selected)
/* /*
* Print the scroll indicators. * Print the scroll indicators.
*/ */
static void static void print_arrows(WINDOW * win, int choice, int item_no, int scroll,
print_arrows(WINDOW * win, int choice, int item_no, int scroll,
int y, int x, int height) int y, int x, int height)
{ {
wmove(win, y, x); wmove(win, y, x);
...@@ -112,10 +111,9 @@ static void print_buttons(WINDOW * dialog, int height, int width, int selected) ...@@ -112,10 +111,9 @@ static void print_buttons(WINDOW * dialog, int height, int width, int selected)
* Display a dialog box with a list of options that can be turned on or off * Display a dialog box with a list of options that can be turned on or off
* The `flag' parameter is used to select between radiolist and checklist. * The `flag' parameter is used to select between radiolist and checklist.
*/ */
int int dialog_checklist(const char *title, const char *prompt, int height,
dialog_checklist(const char *title, const char *prompt, int height, int width, int width, int list_height, int item_no,
int list_height, int item_no, const char *const *items, const char *const *items, int flag)
int flag)
{ {
int i, x, y, box_x, box_y; int i, x, y, box_x, box_y;
int key = 0, button = 0, choice = 0, scroll = 0, max_choice, *status; int key = 0, button = 0, choice = 0, scroll = 0, max_choice, *status;
...@@ -183,8 +181,7 @@ dialog_checklist(const char *title, const char *prompt, int height, int width, ...@@ -183,8 +181,7 @@ dialog_checklist(const char *title, const char *prompt, int height, int width,
box_x = (width - list_width) / 2 - 1; box_x = (width - list_width) / 2 - 1;
/* create new window for the list */ /* create new window for the list */
list = list = subwin(dialog, list_height, list_width, y + box_y + 1,
subwin(dialog, list_height, list_width, y + box_y + 1,
x + box_x + 1); x + box_x + 1);
keypad(list, TRUE); keypad(list, TRUE);
...@@ -238,24 +235,18 @@ dialog_checklist(const char *title, const char *prompt, int height, int width, ...@@ -238,24 +235,18 @@ dialog_checklist(const char *title, const char *prompt, int height, int width,
/* Scroll list down */ /* Scroll list down */
if (list_height > 1) { if (list_height > 1) {
/* De-highlight current first item */ /* De-highlight current first item */
print_item(list, print_item(list, items[scroll * 3 + 1],
items[scroll * 3 + status[scroll], 0, FALSE);
1],
status[scroll], 0,
FALSE);
scrollok(list, TRUE); scrollok(list, TRUE);
wscrl(list, -1); wscrl(list, -1);
scrollok(list, FALSE); scrollok(list, FALSE);
} }
scroll--; scroll--;
print_item(list, items[scroll * 3 + 1], print_item(list, items[scroll * 3 + 1], status[scroll], 0, TRUE);
status[scroll], 0, TRUE);
wnoutrefresh(list); wnoutrefresh(list);
print_arrows(dialog, choice, item_no, print_arrows(dialog, choice, item_no,
scroll, box_y, scroll, box_y, box_x + check_x + 5, list_height);
box_x + check_x + 5,
list_height);
wrefresh(dialog); wrefresh(dialog);
...@@ -269,32 +260,20 @@ dialog_checklist(const char *title, const char *prompt, int height, int width, ...@@ -269,32 +260,20 @@ dialog_checklist(const char *title, const char *prompt, int height, int width,
/* Scroll list up */ /* Scroll list up */
if (list_height > 1) { if (list_height > 1) {
/* De-highlight current last item before scrolling up */ /* De-highlight current last item before scrolling up */
print_item(list, print_item(list, items[(scroll + max_choice - 1) * 3 + 1],
items[(scroll + status[scroll + max_choice - 1],
max_choice - max_choice - 1, FALSE);
1) * 3 + 1],
status[scroll +
max_choice -
1],
max_choice - 1,
FALSE);
scrollok(list, TRUE); scrollok(list, TRUE);
wscrl(list, 1); wscrl(list, 1);
scrollok(list, FALSE); scrollok(list, FALSE);
} }
scroll++; scroll++;
print_item(list, print_item(list, items[(scroll + max_choice - 1) * 3 + 1],
items[(scroll + max_choice - status[scroll + max_choice - 1], max_choice - 1, TRUE);
1) * 3 + 1],
status[scroll + max_choice -
1], max_choice - 1,
TRUE);
wnoutrefresh(list); wnoutrefresh(list);
print_arrows(dialog, choice, item_no, print_arrows(dialog, choice, item_no,
scroll, box_y, scroll, box_y, box_x + check_x + 5, list_height);
box_x + check_x + 5,
list_height);
wrefresh(dialog); wrefresh(dialog);
...@@ -304,16 +283,12 @@ dialog_checklist(const char *title, const char *prompt, int height, int width, ...@@ -304,16 +283,12 @@ dialog_checklist(const char *title, const char *prompt, int height, int width,
} }
if (i != choice) { if (i != choice) {
/* De-highlight current item */ /* De-highlight current item */
print_item(list, print_item(list, items[(scroll + choice) * 3 + 1],
items[(scroll + choice) * 3 + 1], status[scroll + choice], choice, FALSE);
status[scroll + choice], choice,
FALSE);
/* Highlight new item */ /* Highlight new item */
choice = i; choice = i;
print_item(list, print_item(list, items[(scroll + choice) * 3 + 1],
items[(scroll + choice) * 3 + 1], status[scroll + choice], choice, TRUE);
status[scroll + choice], choice,
TRUE);
wnoutrefresh(list); wnoutrefresh(list);
wrefresh(dialog); wrefresh(dialog);
} }
...@@ -342,28 +317,18 @@ dialog_checklist(const char *title, const char *prompt, int height, int width, ...@@ -342,28 +317,18 @@ dialog_checklist(const char *title, const char *prompt, int height, int width,
case '\n': case '\n':
if (!button) { if (!button) {
if (flag == FLAG_CHECK) { if (flag == FLAG_CHECK) {
status[scroll + choice] = status[scroll + choice] = !status[scroll + choice];
!status[scroll + choice];
wmove(list, choice, check_x); wmove(list, choice, check_x);
wattrset(list, check_selected_attr); wattrset(list, check_selected_attr);
wprintw(list, "[%c]", wprintw(list, "[%c]", status[scroll + choice] ? 'X' : ' ');
status[scroll +
choice] ? 'X' : ' ');
} else { } else {
if (!status[scroll + choice]) { if (!status[scroll + choice]) {
for (i = 0; i < item_no; i++) for (i = 0; i < item_no; i++)
status[i] = 0; status[i] = 0;
status[scroll + choice] = 1; status[scroll + choice] = 1;
for (i = 0; i < max_choice; i++) for (i = 0; i < max_choice; i++)
print_item(list, print_item(list, items[(scroll + i) * 3 + 1],
items[(scroll status[scroll + i], i, i == choice);
+
i) *
3 + 1],
status[scroll
+ i],
i,
i == choice);
} }
} }
wnoutrefresh(list); wnoutrefresh(list);
...@@ -372,19 +337,15 @@ dialog_checklist(const char *title, const char *prompt, int height, int width, ...@@ -372,19 +337,15 @@ dialog_checklist(const char *title, const char *prompt, int height, int width,
for (i = 0; i < item_no; i++) { for (i = 0; i < item_no; i++) {
if (status[i]) { if (status[i]) {
if (flag == FLAG_CHECK) { if (flag == FLAG_CHECK) {
fprintf(stderr, fprintf(stderr, "\"%s\" ", items[i * 3]);
"\"%s\" ",
items[i * 3]);
} else { } else {
fprintf(stderr, "%s", fprintf(stderr, "%s", items[i * 3]);
items[i * 3]);
} }
} }
} }
} else } else
fprintf(stderr, "%s", fprintf(stderr, "%s", items[(scroll + choice) * 3]);
items[(scroll + choice) * 3]);
delwin(dialog); delwin(dialog);
free(status); free(status);
return button; return button;
......
/* /*
* dialog.h -- common declarations for all dialog modules * dialog.h -- common declarations for all dialog modules
* *
......
...@@ -41,8 +41,7 @@ static void print_buttons(WINDOW * dialog, int height, int width, int selected) ...@@ -41,8 +41,7 @@ static void print_buttons(WINDOW * dialog, int height, int width, int selected)
/* /*
* Display a dialog box for inputing a string * Display a dialog box for inputing a string
*/ */
int int dialog_inputbox(const char *title, const char *prompt, int height, int width,
dialog_inputbox(const char *title, const char *prompt, int height, int width,
const char *init) const char *init)
{ {
int i, x, y, box_y, box_x, box_width; int i, x, y, box_y, box_x, box_width;
...@@ -90,8 +89,7 @@ dialog_inputbox(const char *title, const char *prompt, int height, int width, ...@@ -90,8 +89,7 @@ dialog_inputbox(const char *title, const char *prompt, int height, int width,
getyx(dialog, y, x); getyx(dialog, y, x);
box_y = y + 2; box_y = y + 2;
box_x = (width - box_width) / 2; box_x = (width - box_width) / 2;
draw_box(dialog, y + 1, box_x - 1, 3, box_width + 2, draw_box(dialog, y + 1, box_x - 1, 3, box_width + 2, border_attr, dialog_attr);
border_attr, dialog_attr);
print_buttons(dialog, height, width, 0); print_buttons(dialog, height, width, 0);
...@@ -111,8 +109,9 @@ dialog_inputbox(const char *title, const char *prompt, int height, int width, ...@@ -111,8 +109,9 @@ dialog_inputbox(const char *title, const char *prompt, int height, int width,
input_x = box_width - 1; input_x = box_width - 1;
for (i = 0; i < box_width - 1; i++) for (i = 0; i < box_width - 1; i++)
waddch(dialog, instr[scroll + i]); waddch(dialog, instr[scroll + i]);
} else } else {
waddstr(dialog, instr); waddstr(dialog, instr);
}
wmove(dialog, box_y, box_x + input_x); wmove(dialog, box_y, box_x + input_x);
...@@ -136,26 +135,17 @@ dialog_inputbox(const char *title, const char *prompt, int height, int width, ...@@ -136,26 +135,17 @@ dialog_inputbox(const char *title, const char *prompt, int height, int width,
if (input_x || scroll) { if (input_x || scroll) {
wattrset(dialog, inputbox_attr); wattrset(dialog, inputbox_attr);
if (!input_x) { if (!input_x) {
scroll = scroll = scroll < box_width - 1 ? 0 : scroll - (box_width - 1);
scroll <
box_width - 1 ? 0 : scroll -
(box_width - 1);
wmove(dialog, box_y, box_x); wmove(dialog, box_y, box_x);
for (i = 0; i < box_width; i++) for (i = 0; i < box_width; i++)
waddch(dialog, waddch(dialog,
instr[scroll + instr[scroll + input_x + i] ?
input_x + instr[scroll + input_x + i] : ' ');
i] ? input_x = strlen(instr) - scroll;
instr[scroll +
input_x +
i] : ' ');
input_x =
strlen(instr) - scroll;
} else } else
input_x--; input_x--;
instr[scroll + input_x] = '\0'; instr[scroll + input_x] = '\0';
mvwaddch(dialog, box_y, input_x + box_x, mvwaddch(dialog, box_y, input_x + box_x, ' ');
' ');
wmove(dialog, box_y, input_x + box_x); wmove(dialog, box_y, input_x + box_x);
wrefresh(dialog); wrefresh(dialog);
} }
...@@ -165,23 +155,14 @@ dialog_inputbox(const char *title, const char *prompt, int height, int width, ...@@ -165,23 +155,14 @@ dialog_inputbox(const char *title, const char *prompt, int height, int width,
if (scroll + input_x < MAX_LEN) { if (scroll + input_x < MAX_LEN) {
wattrset(dialog, inputbox_attr); wattrset(dialog, inputbox_attr);
instr[scroll + input_x] = key; instr[scroll + input_x] = key;
instr[scroll + input_x + 1] = instr[scroll + input_x + 1] = '\0';
'\0';
if (input_x == box_width - 1) { if (input_x == box_width - 1) {
scroll++; scroll++;
wmove(dialog, box_y, wmove(dialog, box_y, box_x);
box_x); for (i = 0; i < box_width - 1; i++)
for (i = 0; waddch(dialog, instr [scroll + i]);
i < box_width - 1;
i++)
waddch(dialog,
instr
[scroll +
i]);
} else { } else {
wmove(dialog, box_y, wmove(dialog, box_y, input_x++ + box_x);
input_x++ +
box_x);
waddch(dialog, key); waddch(dialog, key);
} }
wrefresh(dialog); wrefresh(dialog);
......
...@@ -63,8 +63,8 @@ static int menu_width, item_x; ...@@ -63,8 +63,8 @@ static int menu_width, item_x;
/* /*
* Print menu item * Print menu item
*/ */
static void static void print_item(WINDOW * win, const char *item, int choice,
print_item(WINDOW * win, const char *item, int choice, int selected, int hotkey) int selected, int hotkey)
{ {
int j; int j;
char menu_item[menu_width + 1]; char menu_item[menu_width + 1];
...@@ -100,8 +100,8 @@ print_item(WINDOW * win, const char *item, int choice, int selected, int hotkey) ...@@ -100,8 +100,8 @@ print_item(WINDOW * win, const char *item, int choice, int selected, int hotkey)
/* /*
* Print the scroll indicators. * Print the scroll indicators.
*/ */
static void static void print_arrows(WINDOW * win, int item_no, int scroll, int y, int x,
print_arrows(WINDOW * win, int item_no, int scroll, int y, int x, int height) int height)
{ {
int cur_y, cur_x; int cur_y, cur_x;
...@@ -158,8 +158,7 @@ static void print_buttons(WINDOW * win, int height, int width, int selected) ...@@ -158,8 +158,7 @@ static void print_buttons(WINDOW * win, int height, int width, int selected)
/* /*
* Display a menu for choosing among a number of options * Display a menu for choosing among a number of options
*/ */
int int dialog_menu(const char *title, const char *prompt, int height, int width,
dialog_menu(const char *title, const char *prompt, int height, int width,
int menu_height, const char *current, int item_no, int menu_height, const char *current, int item_no,
const char *const *items) const char *const *items)
{ {
...@@ -283,20 +282,14 @@ dialog_menu(const char *title, const char *prompt, int height, int width, ...@@ -283,20 +282,14 @@ dialog_menu(const char *title, const char *prompt, int height, int width,
i = max_choice; i = max_choice;
else { else {
for (i = choice + 1; i < max_choice; i++) { for (i = choice + 1; i < max_choice; i++) {
j = first_alpha(items[(scroll + i) * 2 + 1], j = first_alpha(items[(scroll + i) * 2 + 1], "YyNnMmHh");
"YyNnMmHh"); if (key == tolower(items[(scroll + i) * 2 + 1][j]))
if (key ==
tolower(items[(scroll + i) * 2 + 1][j]))
break; break;
} }
if (i == max_choice) if (i == max_choice)
for (i = 0; i < max_choice; i++) { for (i = 0; i < max_choice; i++) {
j = first_alpha(items j = first_alpha(items [(scroll + i) * 2 + 1], "YyNnMmHh");
[(scroll + i) * 2 + 1], if (key == tolower(items[(scroll + i) * 2 + 1][j]))
"YyNnMmHh");
if (key ==
tolower(items[(scroll + i) * 2 + 1]
[j]))
break; break;
} }
} }
...@@ -319,24 +312,19 @@ dialog_menu(const char *title, const char *prompt, int height, int width, ...@@ -319,24 +312,19 @@ dialog_menu(const char *title, const char *prompt, int height, int width,
scroll--; scroll--;
print_item(menu, items[scroll * 2 + 1], print_item(menu, items[scroll * 2 + 1], 0, FALSE,
0, FALSE, (items[scroll * 2][0] != ':'));
(items[scroll * 2][0] !=
':'));
} else } else
choice = MAX(choice - 1, 0); choice = MAX(choice - 1, 0);
} else if (key == KEY_DOWN || key == '+') { } else if (key == KEY_DOWN || key == '+') {
print_item(menu, print_item(menu,
items[(scroll + choice) * 2 + 1], items[(scroll + choice) * 2 + 1], choice, FALSE,
choice, FALSE, (items[(scroll + choice) * 2][0] != ':'));
(items[(scroll + choice) * 2][0] !=
':'));
if ((choice > max_choice - 3) && if ((choice > max_choice - 3) &&
(scroll + max_choice < item_no) (scroll + max_choice < item_no)) {
) {
/* Scroll menu up */ /* Scroll menu up */
scrollok(menu, TRUE); scrollok(menu, TRUE);
wscrl(menu, 1); wscrl(menu, 1);
...@@ -344,16 +332,11 @@ dialog_menu(const char *title, const char *prompt, int height, int width, ...@@ -344,16 +332,11 @@ dialog_menu(const char *title, const char *prompt, int height, int width,
scroll++; scroll++;
print_item(menu, print_item(menu, items[(scroll + max_choice - 1) * 2 + 1],
items[(scroll + max_choice -
1) * 2 + 1],
max_choice - 1, FALSE, max_choice - 1, FALSE,
(items (items [(scroll + max_choice - 1) * 2][0] != ':'));
[(scroll + max_choice -
1) * 2][0] != ':'));
} else } else
choice = choice = MIN(choice + 1, max_choice - 1);
MIN(choice + 1, max_choice - 1);
} else if (key == KEY_PPAGE) { } else if (key == KEY_PPAGE) {
scrollok(menu, TRUE); scrollok(menu, TRUE);
...@@ -361,11 +344,8 @@ dialog_menu(const char *title, const char *prompt, int height, int width, ...@@ -361,11 +344,8 @@ dialog_menu(const char *title, const char *prompt, int height, int width,
if (scroll > 0) { if (scroll > 0) {
wscrl(menu, -1); wscrl(menu, -1);
scroll--; scroll--;
print_item(menu, print_item(menu, items[scroll * 2 + 1], 0, FALSE,
items[scroll * 2 + (items[scroll * 2][0] != ':'));
1], 0, FALSE,
(items[scroll * 2][0]
!= ':'));
} else { } else {
if (choice > 0) if (choice > 0)
choice--; choice--;
...@@ -380,17 +360,9 @@ dialog_menu(const char *title, const char *prompt, int height, int width, ...@@ -380,17 +360,9 @@ dialog_menu(const char *title, const char *prompt, int height, int width,
wscrl(menu, 1); wscrl(menu, 1);
scrollok(menu, FALSE); scrollok(menu, FALSE);
scroll++; scroll++;
print_item(menu, print_item(menu, items[(scroll + max_choice - 1) * 2 + 1],
items[(scroll + max_choice - 1, FALSE,
max_choice - (items [(scroll + max_choice - 1) * 2][0] != ':'));
1) * 2 + 1],
max_choice - 1,
FALSE,
(items
[(scroll +
max_choice -
1) * 2][0] !=
':'));
} else { } else {
if (choice + 1 < max_choice) if (choice + 1 < max_choice)
choice++; choice++;
...@@ -401,8 +373,7 @@ dialog_menu(const char *title, const char *prompt, int height, int width, ...@@ -401,8 +373,7 @@ dialog_menu(const char *title, const char *prompt, int height, int width,
choice = i; choice = i;
print_item(menu, items[(scroll + choice) * 2 + 1], print_item(menu, items[(scroll + choice) * 2 + 1],
choice, TRUE, choice, TRUE, (items[(scroll + choice) * 2][0] != ':'));
(items[(scroll + choice) * 2][0] != ':'));
print_arrows(dialog, item_no, scroll, print_arrows(dialog, item_no, scroll,
box_y, box_x + item_x + 1, menu_height); box_y, box_x + item_x + 1, menu_height);
...@@ -460,9 +431,7 @@ dialog_menu(const char *title, const char *prompt, int height, int width, ...@@ -460,9 +431,7 @@ dialog_menu(const char *title, const char *prompt, int height, int width,
fprintf(stderr, "%s \"%s\"\n", fprintf(stderr, "%s \"%s\"\n",
items[(scroll + choice) * 2], items[(scroll + choice) * 2],
items[(scroll + choice) * 2 + 1] + items[(scroll + choice) * 2 + 1] +
first_alpha(items first_alpha(items [(scroll + choice) * 2 + 1], ""));
[(scroll + choice) * 2 + 1],
""));
else else
fprintf(stderr, "%s\n", fprintf(stderr, "%s\n",
items[(scroll + choice) * 2]); items[(scroll + choice) * 2]);
......
...@@ -25,8 +25,7 @@ ...@@ -25,8 +25,7 @@
* Display a message box. Program will pause and display an "OK" button * Display a message box. Program will pause and display an "OK" button
* if the parameter 'pause' is non-zero. * if the parameter 'pause' is non-zero.
*/ */
int int dialog_msgbox(const char *title, const char *prompt, int height, int width,
dialog_msgbox(const char *title, const char *prompt, int height, int width,
int pause) int pause)
{ {
int i, x, y, key = 0; int i, x, y, key = 0;
......
...@@ -46,30 +46,26 @@ int dialog_textbox(const char *title, const char *file, int height, int width) ...@@ -46,30 +46,26 @@ int dialog_textbox(const char *title, const char *file, int height, int width)
/* Open input file for reading */ /* Open input file for reading */
if ((fd = open(file, O_RDONLY)) == -1) { if ((fd = open(file, O_RDONLY)) == -1) {
endwin(); endwin();
fprintf(stderr, fprintf(stderr, "\nCan't open input file in dialog_textbox().\n");
"\nCan't open input file in dialog_textbox().\n");
exit(-1); exit(-1);
} }
/* Get file size. Actually, 'file_size' is the real file size - 1, /* Get file size. Actually, 'file_size' is the real file size - 1,
since it's only the last byte offset from the beginning */ since it's only the last byte offset from the beginning */
if ((file_size = lseek(fd, 0, SEEK_END)) == -1) { if ((file_size = lseek(fd, 0, SEEK_END)) == -1) {
endwin(); endwin();
fprintf(stderr, fprintf(stderr, "\nError getting file size in dialog_textbox().\n");
"\nError getting file size in dialog_textbox().\n");
exit(-1); exit(-1);
} }
/* Restore file pointer to beginning of file after getting file size */ /* Restore file pointer to beginning of file after getting file size */
if (lseek(fd, 0, SEEK_SET) == -1) { if (lseek(fd, 0, SEEK_SET) == -1) {
endwin(); endwin();
fprintf(stderr, fprintf(stderr, "\nError moving file pointer in dialog_textbox().\n");
"\nError moving file pointer in dialog_textbox().\n");
exit(-1); exit(-1);
} }
/* Allocate space for read buffer */ /* Allocate space for read buffer */
if ((buf = malloc(BUF_SIZE + 1)) == NULL) { if ((buf = malloc(BUF_SIZE + 1)) == NULL) {
endwin(); endwin();
fprintf(stderr, fprintf(stderr, "\nCan't allocate memory in dialog_textbox().\n");
"\nCan't allocate memory in dialog_textbox().\n");
exit(-1); exit(-1);
} }
if ((bytes_read = read(fd, buf, BUF_SIZE)) == -1) { if ((bytes_read = read(fd, buf, BUF_SIZE)) == -1) {
...@@ -150,23 +146,20 @@ int dialog_textbox(const char *title, const char *file, int height, int width) ...@@ -150,23 +146,20 @@ int dialog_textbox(const char *title, const char *file, int height, int width)
/* First page not in buffer? */ /* First page not in buffer? */
if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) { if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) {
endwin(); endwin();
fprintf(stderr, fprintf(stderr, "\nError moving file pointer in dialog_textbox().\n");
"\nError moving file pointer in dialog_textbox().\n");
exit(-1); exit(-1);
} }
if (fpos > bytes_read) { /* Yes, we have to read it in */ if (fpos > bytes_read) { /* Yes, we have to read it in */
if (lseek(fd, 0, SEEK_SET) == -1) { if (lseek(fd, 0, SEEK_SET) == -1) {
endwin(); endwin();
fprintf(stderr, fprintf(stderr, "\nError moving file pointer in "
"\nError moving file pointer in "
"dialog_textbox().\n"); "dialog_textbox().\n");
exit(-1); exit(-1);
} }
if ((bytes_read = if ((bytes_read =
read(fd, buf, BUF_SIZE)) == -1) { read(fd, buf, BUF_SIZE)) == -1) {
endwin(); endwin();
fprintf(stderr, fprintf(stderr, "\nError reading file in dialog_textbox().\n");
"\nError reading file in dialog_textbox().\n");
exit(-1); exit(-1);
} }
buf[bytes_read] = '\0'; buf[bytes_read] = '\0';
...@@ -185,22 +178,19 @@ int dialog_textbox(const char *title, const char *file, int height, int width) ...@@ -185,22 +178,19 @@ int dialog_textbox(const char *title, const char *file, int height, int width)
/* Last page not in buffer? */ /* Last page not in buffer? */
if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) { if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) {
endwin(); endwin();
fprintf(stderr, fprintf(stderr, "\nError moving file pointer in dialog_textbox().\n");
"\nError moving file pointer in dialog_textbox().\n");
exit(-1); exit(-1);
} }
if (fpos < file_size) { /* Yes, we have to read it in */ if (fpos < file_size) { /* Yes, we have to read it in */
if (lseek(fd, -BUF_SIZE, SEEK_END) == -1) { if (lseek(fd, -BUF_SIZE, SEEK_END) == -1) {
endwin(); endwin();
fprintf(stderr, fprintf(stderr, "\nError moving file pointer in dialog_textbox().\n");
"\nError moving file pointer in dialog_textbox().\n");
exit(-1); exit(-1);
} }
if ((bytes_read = if ((bytes_read =
read(fd, buf, BUF_SIZE)) == -1) { read(fd, buf, BUF_SIZE)) == -1) {
endwin(); endwin();
fprintf(stderr, fprintf(stderr, "\nError reading file in dialog_textbox().\n");
"\nError reading file in dialog_textbox().\n");
exit(-1); exit(-1);
} }
buf[bytes_read] = '\0'; buf[bytes_read] = '\0';
...@@ -342,8 +332,7 @@ static void back_lines(int n) ...@@ -342,8 +332,7 @@ static void back_lines(int n)
if (page == buf) { if (page == buf) {
if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) { if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) {
endwin(); endwin();
fprintf(stderr, fprintf(stderr, "\nError moving file pointer in "
"\nError moving file pointer in "
"back_lines().\n"); "back_lines().\n");
exit(-1); exit(-1);
} }
...@@ -358,20 +347,15 @@ static void back_lines(int n) ...@@ -358,20 +347,15 @@ static void back_lines(int n)
/* No, move less then */ /* No, move less then */
if (lseek(fd, 0, SEEK_SET) == -1) { if (lseek(fd, 0, SEEK_SET) == -1) {
endwin(); endwin();
fprintf(stderr, fprintf(stderr, "\nError moving file pointer in "
"\nError moving file pointer in "
"back_lines().\n"); "back_lines().\n");
exit(-1); exit(-1);
} }
page = buf + fpos - bytes_read; page = buf + fpos - bytes_read;
} else { /* Move backward BUF_SIZE/2 bytes */ } else { /* Move backward BUF_SIZE/2 bytes */
if (lseek if (lseek (fd, -(BUF_SIZE / 2 + bytes_read), SEEK_CUR) == -1) {
(fd, -(BUF_SIZE / 2 + bytes_read),
SEEK_CUR)
== -1) {
endwin(); endwin();
fprintf(stderr, fprintf(stderr, "\nError moving file pointer "
"\nError moving file pointer "
"in back_lines().\n"); "in back_lines().\n");
exit(-1); exit(-1);
} }
...@@ -380,8 +364,7 @@ static void back_lines(int n) ...@@ -380,8 +364,7 @@ static void back_lines(int n)
if ((bytes_read = if ((bytes_read =
read(fd, buf, BUF_SIZE)) == -1) { read(fd, buf, BUF_SIZE)) == -1) {
endwin(); endwin();
fprintf(stderr, fprintf(stderr, "\nError reading file in back_lines().\n");
"\nError reading file in back_lines().\n");
exit(-1); exit(-1);
} }
buf[bytes_read] = '\0'; buf[bytes_read] = '\0';
...@@ -403,32 +386,24 @@ static void back_lines(int n) ...@@ -403,32 +386,24 @@ static void back_lines(int n)
if (page == buf) { if (page == buf) {
if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) { if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) {
endwin(); endwin();
fprintf(stderr, fprintf(stderr, "\nError moving file pointer in back_lines().\n");
"\nError moving file pointer in back_lines().\n");
exit(-1); exit(-1);
} }
if (fpos > bytes_read) { if (fpos > bytes_read) {
/* Really possible to move backward BUF_SIZE/2 bytes? */ /* Really possible to move backward BUF_SIZE/2 bytes? */
if (fpos < BUF_SIZE / 2 + bytes_read) { if (fpos < BUF_SIZE / 2 + bytes_read) {
/* No, move less then */ /* No, move less then */
if (lseek(fd, 0, SEEK_SET) == if (lseek(fd, 0, SEEK_SET) == -1) {
-1) {
endwin(); endwin();
fprintf(stderr, fprintf(stderr, "\nError moving file pointer "
"\nError moving file pointer "
"in back_lines().\n"); "in back_lines().\n");
exit(-1); exit(-1);
} }
page = buf + fpos - bytes_read; page = buf + fpos - bytes_read;
} else { /* Move backward BUF_SIZE/2 bytes */ } else { /* Move backward BUF_SIZE/2 bytes */
if (lseek if (lseek (fd, -(BUF_SIZE / 2 + bytes_read), SEEK_CUR) == -1) {
(fd,
-(BUF_SIZE / 2 +
bytes_read),
SEEK_CUR) == -1) {
endwin(); endwin();
fprintf(stderr, fprintf(stderr, "\nError moving file pointer"
"\nError moving file pointer"
" in back_lines().\n"); " in back_lines().\n");
exit(-1); exit(-1);
} }
...@@ -437,8 +412,7 @@ static void back_lines(int n) ...@@ -437,8 +412,7 @@ static void back_lines(int n)
if ((bytes_read = if ((bytes_read =
read(fd, buf, BUF_SIZE)) == -1) { read(fd, buf, BUF_SIZE)) == -1) {
endwin(); endwin();
fprintf(stderr, fprintf(stderr, "\nError reading file in "
"\nError reading file in "
"back_lines().\n"); "back_lines().\n");
exit(-1); exit(-1);
} }
...@@ -513,8 +487,7 @@ static char *get_line(void) ...@@ -513,8 +487,7 @@ static char *get_line(void)
/* Either end of file or end of buffer reached */ /* Either end of file or end of buffer reached */
if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) { if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) {
endwin(); endwin();
fprintf(stderr, fprintf(stderr, "\nError moving file pointer in "
"\nError moving file pointer in "
"get_line().\n"); "get_line().\n");
exit(-1); exit(-1);
} }
...@@ -524,8 +497,7 @@ static char *get_line(void) ...@@ -524,8 +497,7 @@ static char *get_line(void)
if ((bytes_read = if ((bytes_read =
read(fd, buf, BUF_SIZE)) == -1) { read(fd, buf, BUF_SIZE)) == -1) {
endwin(); endwin();
fprintf(stderr, fprintf(stderr, "\nError reading file in get_line().\n");
"\nError reading file in get_line().\n");
exit(-1); exit(-1);
} }
buf[bytes_read] = '\0'; buf[bytes_read] = '\0';
...@@ -561,8 +533,7 @@ static void print_position(WINDOW * win, int height, int width) ...@@ -561,8 +533,7 @@ static void print_position(WINDOW * win, int height, int width)
if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) { if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) {
endwin(); endwin();
fprintf(stderr, fprintf(stderr, "\nError moving file pointer in print_position().\n");
"\nError moving file pointer in print_position().\n");
exit(-1); exit(-1);
} }
wattrset(win, position_indicator_attr); wattrset(win, position_indicator_attr);
......
...@@ -96,8 +96,7 @@ int dialog_yesno(const char *title, const char *prompt, int height, int width) ...@@ -96,8 +96,7 @@ int dialog_yesno(const char *title, const char *prompt, int height, int width)
case TAB: case TAB:
case KEY_LEFT: case KEY_LEFT:
case KEY_RIGHT: case KEY_RIGHT:
button = ((key == KEY_LEFT ? --button : ++button) < 0) button = ((key == KEY_LEFT ? --button : ++button) < 0) ? 1 : (button > 1 ? 0 : button);
? 1 : (button > 1 ? 0 : button);
print_buttons(dialog, height, width, button); print_buttons(dialog, height, width, button);
wrefresh(dialog); wrefresh(dialog);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment