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.
Showing the changes to scripts (8 of 8 files). Show all
Unified · Split
| @@ -28,8 +28,8 @@ static int list_width, check_x, item_x, checkflag; · 27 unmodified lines | |||
| 28 | /* | 28 | /* |
| 29 | * Print list item | 29 | * Print list item |
| 30 | */ | 30 | */ |
| 31 | static void | 31 | static void print_item(WINDOW * win, const char *item, int status, int choice, |
| 32 | print_item(WINDOW * win, const char *item, int status, int choice, int selected) | 32 | int selected) |
| 33 | { | 33 | { |
| 34 | int i; | 34 | int i; |
| 35 | 35 | ||
| @@ -59,8 +59,7 @@ print_item(WINDOW * win, const char *item, int status, int choice, int selected) · 23 unmodified lines | |||
| 59 | /* | 59 | /* |
| 60 | * Print the scroll indicators. | 60 | * Print the scroll indicators. |
| 61 | */ | 61 | */ |
| 62 | static void | 62 | static void print_arrows(WINDOW * win, int choice, int item_no, int scroll, |
| 63 | print_arrows(WINDOW * win, int choice, int item_no, int scroll, | ||
| 64 | int y, int x, int height) | 63 | int y, int x, int height) |
| 65 | { | 64 | { |
| 66 | wmove(win, y, x); | 65 | wmove(win, y, x); |
| @@ -112,10 +111,9 @@ static void print_buttons(WINDOW * dialog, int height, int width, int selected) · 45 unmodified lines | |||
| 112 | * Display a dialog box with a list of options that can be turned on or off | 111 | * Display a dialog box with a list of options that can be turned on or off |
| 113 | * The `flag' parameter is used to select between radiolist and checklist. | 112 | * The `flag' parameter is used to select between radiolist and checklist. |
| 114 | */ | 113 | */ |
| 115 | int | 114 | int dialog_checklist(const char *title, const char *prompt, int height, |
| 116 | dialog_checklist(const char *title, const char *prompt, int height, int width, | 115 | int width, int list_height, int item_no, |
| 117 | int list_height, int item_no, const char *const *items, | 116 | const char *const *items, int flag) |
| 118 | int flag) | ||
| 119 | { | 117 | { |
| 120 | int i, x, y, box_x, box_y; | 118 | int i, x, y, box_x, box_y; |
| 121 | int key = 0, button = 0, choice = 0, scroll = 0, max_choice, *status; | 119 | int key = 0, button = 0, choice = 0, scroll = 0, max_choice, *status; |
| @@ -183,15 +181,14 @@ dialog_checklist(const char *title, const char *prompt, int height, int width, · 61 unmodified lines | |||
| 183 | box_x = (width - list_width) / 2 - 1; | 181 | box_x = (width - list_width) / 2 - 1; |
| 184 | 182 | ||
| 185 | /* create new window for the list */ | 183 | /* create new window for the list */ |
| 186 | list = | 184 | list = subwin(dialog, list_height, list_width, y + box_y + 1, |
| 187 | subwin(dialog, list_height, list_width, y + box_y + 1, | 185 | x + box_x + 1); |
| 188 | x + box_x + 1); | ||
| 189 | 186 | ||
| 190 | keypad(list, TRUE); | 187 | keypad(list, TRUE); |
| 191 | 188 | ||
| 192 | /* draw a box around the list items */ | 189 | /* draw a box around the list items */ |
| 193 | draw_box(dialog, box_y, box_x, list_height + 2, list_width + 2, | 190 | draw_box(dialog, box_y, box_x, list_height + 2, list_width + 2, |
| 194 | menubox_border_attr, menubox_attr); | 191 | menubox_border_attr, menubox_attr); |
| 195 | 192 | ||
| 196 | /* Find length of longest item in order to center checklist */ | 193 | /* Find length of longest item in order to center checklist */ |
| 197 | check_x = 0; | 194 | check_x = 0; |
| @@ -238,24 +235,18 @@ dialog_checklist(const char *title, const char *prompt, int height, int width, · 40 unmodified lines | |||
| 238 | /* Scroll list down */ | 235 | /* Scroll list down */ |
| 239 | if (list_height > 1) { | 236 | if (list_height > 1) { |
| 240 | /* De-highlight current first item */ | 237 | /* De-highlight current first item */ |
| 241 | print_item(list, | 238 | print_item(list, items[scroll * 3 + 1], |
| 242 | items[scroll * 3 + | 239 | status[scroll], 0, FALSE); |
| 243 | 1], | ||
| 244 | status[scroll], 0, | ||
| 245 | FALSE); | ||
| 246 | scrollok(list, TRUE); | 240 | scrollok(list, TRUE); |
| 247 | wscrl(list, -1); | 241 | wscrl(list, -1); |
| 248 | scrollok(list, FALSE); | 242 | scrollok(list, FALSE); |
| 249 | } | 243 | } |
| 250 | scroll--; | 244 | scroll--; |
| 251 | print_item(list, items[scroll * 3 + 1], | 245 | print_item(list, items[scroll * 3 + 1], status[scroll], 0, TRUE); |
| 252 | status[scroll], 0, TRUE); | ||
| 253 | wnoutrefresh(list); | 246 | wnoutrefresh(list); |
| 254 | 247 | ||
| 255 | print_arrows(dialog, choice, item_no, | 248 | print_arrows(dialog, choice, item_no, |
| 256 | scroll, box_y, | 249 | scroll, box_y, box_x + check_x + 5, list_height); |
| 257 | box_x + check_x + 5, | ||
| 258 | list_height); | ||
| 259 | 250 | ||
| 260 | wrefresh(dialog); | 251 | wrefresh(dialog); |
| 261 | 252 | ||
| @@ -269,32 +260,20 @@ dialog_checklist(const char *title, const char *prompt, int height, int width, · 7 unmodified lines | |||
| 269 | /* Scroll list up */ | 260 | /* Scroll list up */ |
| 270 | if (list_height > 1) { | 261 | if (list_height > 1) { |
| 271 | /* De-highlight current last item before scrolling up */ | 262 | /* De-highlight current last item before scrolling up */ |
| 272 | print_item(list, | 263 | print_item(list, items[(scroll + max_choice - 1) * 3 + 1], |
| 273 | items[(scroll + | 264 | status[scroll + max_choice - 1], |
| 274 | max_choice - | 265 | max_choice - 1, FALSE); |
| 275 | 1) * 3 + 1], | ||
| 276 | status[scroll + | ||
| 277 | max_choice - | ||
| 278 | 1], | ||
| 279 | max_choice - 1, | ||
| 280 | FALSE); | ||
| 281 | scrollok(list, TRUE); | 266 | scrollok(list, TRUE); |
| 282 | wscrl(list, 1); | 267 | wscrl(list, 1); |
| 283 | scrollok(list, FALSE); | 268 | scrollok(list, FALSE); |
| 284 | } | 269 | } |
| 285 | scroll++; | 270 | scroll++; |
| 286 | print_item(list, | 271 | print_item(list, items[(scroll + max_choice - 1) * 3 + 1], |
| 287 | items[(scroll + max_choice - | 272 | status[scroll + max_choice - 1], max_choice - 1, TRUE); |
| 288 | 1) * 3 + 1], | ||
| 289 | status[scroll + max_choice - | ||
| 290 | 1], max_choice - 1, | ||
| 291 | TRUE); | ||
| 292 | wnoutrefresh(list); | 273 | wnoutrefresh(list); |
| 293 | 274 | ||
| 294 | print_arrows(dialog, choice, item_no, | 275 | print_arrows(dialog, choice, item_no, |
| 295 | scroll, box_y, | 276 | scroll, box_y, box_x + check_x + 5, list_height); |
| 296 | box_x + check_x + 5, | ||
| 297 | list_height); | ||
| 298 | 277 | ||
| 299 | wrefresh(dialog); | 278 | wrefresh(dialog); |
| 300 | 279 | ||
| @@ -304,16 +283,12 @@ dialog_checklist(const char *title, const char *prompt, int height, int width, · 3 unmodified lines | |||
| 304 | } | 283 | } |
| 305 | if (i != choice) { | 284 | if (i != choice) { |
| 306 | /* De-highlight current item */ | 285 | /* De-highlight current item */ |
| 307 | print_item(list, | 286 | print_item(list, items[(scroll + choice) * 3 + 1], |
| 308 | items[(scroll + choice) * 3 + 1], | 287 | status[scroll + choice], choice, FALSE); |
| 309 | status[scroll + choice], choice, | ||
| 310 | FALSE); | ||
| 311 | /* Highlight new item */ | 288 | /* Highlight new item */ |
| 312 | choice = i; | 289 | choice = i; |
| 313 | print_item(list, | 290 | print_item(list, items[(scroll + choice) * 3 + 1], |
| 314 | items[(scroll + choice) * 3 + 1], | 291 | status[scroll + choice], choice, TRUE); |
| 315 | status[scroll + choice], choice, | ||
| 316 | TRUE); | ||
| 317 | wnoutrefresh(list); | 292 | wnoutrefresh(list); |
| 318 | wrefresh(dialog); | 293 | wrefresh(dialog); |
| 319 | } | 294 | } |
| @@ -342,28 +317,18 @@ dialog_checklist(const char *title, const char *prompt, int height, int width, · 22 unmodified lines | |||
| 342 | case '\n': | 317 | case '\n': |
| 343 | if (!button) { | 318 | if (!button) { |
| 344 | if (flag == FLAG_CHECK) { | 319 | if (flag == FLAG_CHECK) { |
| 345 | status[scroll + choice] = | 320 | status[scroll + choice] = !status[scroll + choice]; |
| 346 | !status[scroll + choice]; | ||
| 347 | wmove(list, choice, check_x); | 321 | wmove(list, choice, check_x); |
| 348 | wattrset(list, check_selected_attr); | 322 | wattrset(list, check_selected_attr); |
| 349 | wprintw(list, "[%c]", | 323 | wprintw(list, "[%c]", status[scroll + choice] ? 'X' : ' '); |
| 350 | status[scroll + | ||
| 351 | choice] ? 'X' : ' '); | ||
| 352 | } else { | 324 | } else { |
| 353 | if (!status[scroll + choice]) { | 325 | if (!status[scroll + choice]) { |
| 354 | for (i = 0; i < item_no; i++) | 326 | for (i = 0; i < item_no; i++) |
| 355 | status[i] = 0; | 327 | status[i] = 0; |
| 356 | status[scroll + choice] = 1; | 328 | status[scroll + choice] = 1; |
| 357 | for (i = 0; i < max_choice; i++) | 329 | for (i = 0; i < max_choice; i++) |
| 358 | print_item(list, | 330 | print_item(list, items[(scroll + i) * 3 + 1], |
| 359 | items[(scroll | 331 | status[scroll + i], i, i == choice); |
| 360 | + | ||
| 361 | i) * | ||
| 362 | 3 + 1], | ||
| 363 | status[scroll | ||
| 364 | + i], | ||
| 365 | i, | ||
| 366 | i == choice); | ||
| 367 | } | 332 | } |
| 368 | } | 333 | } |
| 369 | wnoutrefresh(list); | 334 | wnoutrefresh(list); |
| @@ -372,19 +337,15 @@ dialog_checklist(const char *title, const char *prompt, int height, int width, · 2 unmodified lines | |||
| 372 | for (i = 0; i < item_no; i++) { | 337 | for (i = 0; i < item_no; i++) { |
| 373 | if (status[i]) { | 338 | if (status[i]) { |
| 374 | if (flag == FLAG_CHECK) { | 339 | if (flag == FLAG_CHECK) { |
| 375 | fprintf(stderr, | 340 | fprintf(stderr, "\"%s\" ", items[i * 3]); |
| 376 | "\"%s\" ", | ||
| 377 | items[i * 3]); | ||
| 378 | } else { | 341 | } else { |
| 379 | fprintf(stderr, "%s", | 342 | fprintf(stderr, "%s", items[i * 3]); |
| 380 | items[i * 3]); | ||
| 381 | } | 343 | } |
| 382 | 344 | ||
| 383 | } | 345 | } |
| 384 | } | 346 | } |
| 385 | } else | 347 | } else |
| 386 | fprintf(stderr, "%s", | 348 | fprintf(stderr, "%s", items[(scroll + choice) * 3]); |
| 387 | items[(scroll + choice) * 3]); | ||
| 388 | delwin(dialog); | 349 | delwin(dialog); |
| 389 | free(status); | 350 | free(status); |
| 390 | return button; | 351 | return button; |
| @@ -1,4 +1,3 @@ | |||
| 1 | |||
| 2 | /* | 1 | /* |
| 3 | * dialog.h -- common declarations for all dialog modules | 2 | * dialog.h -- common declarations for all dialog modules |
| 4 | * | 3 | * |
| @@ -87,7 +86,7 @@ · 82 unmodified lines | |||
| 87 | #define ACS_DARROW 'v' | 86 | #define ACS_DARROW 'v' |
| 88 | #endif | 87 | #endif |
| 89 | 88 | ||
| 90 | /* | 89 | /* |
| 91 | * Attribute names | 90 | * Attribute names |
| 92 | */ | 91 | */ |
| 93 | #define screen_attr attributes[0] | 92 | #define screen_attr attributes[0] |
| @@ -41,9 +41,8 @@ static void print_buttons(WINDOW * dialog, int height, int width, int selected) · 40 unmodified lines | |||
| 41 | /* | 41 | /* |
| 42 | * Display a dialog box for inputing a string | 42 | * Display a dialog box for inputing a string |
| 43 | */ | 43 | */ |
| 44 | int | 44 | int dialog_inputbox(const char *title, const char *prompt, int height, int width, |
| 45 | dialog_inputbox(const char *title, const char *prompt, int height, int width, | 45 | const char *init) |
| 46 | const char *init) | ||
| 47 | { | 46 | { |
| 48 | int i, x, y, box_y, box_x, box_width; | 47 | int i, x, y, box_y, box_x, box_width; |
| 49 | int input_x = 0, scroll = 0, key = 0, button = -1; | 48 | int input_x = 0, scroll = 0, key = 0, button = -1; |
| @@ -90,8 +89,7 @@ dialog_inputbox(const char *title, const char *prompt, int height, int width, · 40 unmodified lines | |||
| 90 | getyx(dialog, y, x); | 89 | getyx(dialog, y, x); |
| 91 | box_y = y + 2; | 90 | box_y = y + 2; |
| 92 | box_x = (width - box_width) / 2; | 91 | box_x = (width - box_width) / 2; |
| 93 | draw_box(dialog, y + 1, box_x - 1, 3, box_width + 2, | 92 | draw_box(dialog, y + 1, box_x - 1, 3, box_width + 2, border_attr, dialog_attr); |
| 94 | border_attr, dialog_attr); | ||
| 95 | 93 | ||
| 96 | print_buttons(dialog, height, width, 0); | 94 | print_buttons(dialog, height, width, 0); |
| 97 | 95 | ||
| @@ -111,8 +109,9 @@ dialog_inputbox(const char *title, const char *prompt, int height, int width, · 13 unmodified lines | |||
| 111 | input_x = box_width - 1; | 109 | input_x = box_width - 1; |
| 112 | for (i = 0; i < box_width - 1; i++) | 110 | for (i = 0; i < box_width - 1; i++) |
| 113 | waddch(dialog, instr[scroll + i]); | 111 | waddch(dialog, instr[scroll + i]); |
| 114 | } else | 112 | } else { |
| 115 | waddstr(dialog, instr); | 113 | waddstr(dialog, instr); |
| 114 | } | ||
| 116 | 115 | ||
| 117 | wmove(dialog, box_y, box_x + input_x); | 116 | wmove(dialog, box_y, box_x + input_x); |
| 118 | 117 | ||
| @@ -136,26 +135,17 @@ dialog_inputbox(const char *title, const char *prompt, int height, int width, · 17 unmodified lines | |||
| 136 | if (input_x || scroll) { | 135 | if (input_x || scroll) { |
| 137 | wattrset(dialog, inputbox_attr); | 136 | wattrset(dialog, inputbox_attr); |
| 138 | if (!input_x) { | 137 | if (!input_x) { |
| 139 | scroll = | 138 | scroll = scroll < box_width - 1 ? 0 : scroll - (box_width - 1); |
| 140 | scroll < | ||
| 141 | box_width - 1 ? 0 : scroll - | ||
| 142 | (box_width - 1); | ||
| 143 | wmove(dialog, box_y, box_x); | 139 | wmove(dialog, box_y, box_x); |
| 144 | for (i = 0; i < box_width; i++) | 140 | for (i = 0; i < box_width; i++) |
| 145 | waddch(dialog, | 141 | waddch(dialog, |
| 146 | instr[scroll + | 142 | instr[scroll + input_x + i] ? |
| 147 | input_x + | 143 | instr[scroll + input_x + i] : ' '); |
| 148 | i] ? | 144 | input_x = strlen(instr) - scroll; |
| 149 | instr[scroll + | ||
| 150 | input_x + | ||
| 151 | i] : ' '); | ||
| 152 | input_x = | ||
| 153 | strlen(instr) - scroll; | ||
| 154 | } else | 145 | } else |
| 155 | input_x--; | 146 | input_x--; |
| 156 | instr[scroll + input_x] = '\0'; | 147 | instr[scroll + input_x] = '\0'; |
| 157 | mvwaddch(dialog, box_y, input_x + box_x, | 148 | mvwaddch(dialog, box_y, input_x + box_x, ' '); |
| 158 | ' '); | ||
| 159 | wmove(dialog, box_y, input_x + box_x); | 149 | wmove(dialog, box_y, input_x + box_x); |
| 160 | wrefresh(dialog); | 150 | wrefresh(dialog); |
| 161 | } | 151 | } |
| @@ -165,23 +155,14 @@ dialog_inputbox(const char *title, const char *prompt, int height, int width, · 3 unmodified lines | |||
| 165 | if (scroll + input_x < MAX_LEN) { | 155 | if (scroll + input_x < MAX_LEN) { |
| 166 | wattrset(dialog, inputbox_attr); | 156 | wattrset(dialog, inputbox_attr); |
| 167 | instr[scroll + input_x] = key; | 157 | instr[scroll + input_x] = key; |
| 168 | instr[scroll + input_x + 1] = | 158 | instr[scroll + input_x + 1] = '\0'; |
| 169 | '\0'; | ||
| 170 | if (input_x == box_width - 1) { | 159 | if (input_x == box_width - 1) { |
| 171 | scroll++; | 160 | scroll++; |
| 172 | wmove(dialog, box_y, | 161 | wmove(dialog, box_y, box_x); |
| 173 | box_x); | 162 | for (i = 0; i < box_width - 1; i++) |
| 174 | for (i = 0; | 163 | waddch(dialog, instr [scroll + i]); |
| 175 | i < box_width - 1; | ||
| 176 | i++) | ||
| 177 | waddch(dialog, | ||
| 178 | instr | ||
| 179 | [scroll + | ||
| 180 | i]); | ||
| 181 | } else { | 164 | } else { |
| 182 | wmove(dialog, box_y, | 165 | wmove(dialog, box_y, input_x++ + box_x); |
| 183 | input_x++ + | ||
| 184 | box_x); | ||
| 185 | waddch(dialog, key); | 166 | waddch(dialog, key); |
| 186 | } | 167 | } |
| 187 | wrefresh(dialog); | 168 | wrefresh(dialog); |
| @@ -63,8 +63,8 @@ static int menu_width, item_x; · 62 unmodified lines | |||
| 63 | /* | 63 | /* |
| 64 | * Print menu item | 64 | * Print menu item |
| 65 | */ | 65 | */ |
| 66 | static void | 66 | static void print_item(WINDOW * win, const char *item, int choice, |
| 67 | print_item(WINDOW * win, const char *item, int choice, int selected, int hotkey) | 67 | int selected, int hotkey) |
| 68 | { | 68 | { |
| 69 | int j; | 69 | int j; |
| 70 | char menu_item[menu_width + 1]; | 70 | char menu_item[menu_width + 1]; |
| @@ -100,8 +100,8 @@ print_item(WINDOW * win, const char *item, int choice, int selected, int hotkey) · 29 unmodified lines | |||
| 100 | /* | 100 | /* |
| 101 | * Print the scroll indicators. | 101 | * Print the scroll indicators. |
| 102 | */ | 102 | */ |
| 103 | static void | 103 | static void print_arrows(WINDOW * win, int item_no, int scroll, int y, int x, |
| 104 | print_arrows(WINDOW * win, int item_no, int scroll, int y, int x, int height) | 104 | int height) |
| 105 | { | 105 | { |
| 106 | int cur_y, cur_x; | 106 | int cur_y, cur_x; |
| 107 | 107 | ||
| @@ -158,10 +158,9 @@ static void print_buttons(WINDOW * win, int height, int width, int selected) · 50 unmodified lines | |||
| 158 | /* | 158 | /* |
| 159 | * Display a menu for choosing among a number of options | 159 | * Display a menu for choosing among a number of options |
| 160 | */ | 160 | */ |
| 161 | int | 161 | int dialog_menu(const char *title, const char *prompt, int height, int width, |
| 162 | dialog_menu(const char *title, const char *prompt, int height, int width, | 162 | int menu_height, const char *current, int item_no, |
| 163 | int menu_height, const char *current, int item_no, | 163 | const char *const *items) |
| 164 | const char *const *items) | ||
| 165 | { | 164 | { |
| 166 | int i, j, x, y, box_x, box_y; | 165 | int i, j, x, y, box_x, box_y; |
| 167 | int key = 0, button = 0, scroll = 0, choice = 0, first_item = | 166 | int key = 0, button = 0, scroll = 0, choice = 0, first_item = |
| @@ -283,20 +282,14 @@ dialog_menu(const char *title, const char *prompt, int height, int width, · 115 unmodified lines | |||
| 283 | i = max_choice; | 282 | i = max_choice; |
| 284 | else { | 283 | else { |
| 285 | for (i = choice + 1; i < max_choice; i++) { | 284 | for (i = choice + 1; i < max_choice; i++) { |
| 286 | j = first_alpha(items[(scroll + i) * 2 + 1], | 285 | j = first_alpha(items[(scroll + i) * 2 + 1], "YyNnMmHh"); |
| 287 | "YyNnMmHh"); | 286 | if (key == tolower(items[(scroll + i) * 2 + 1][j])) |
| 288 | if (key == | ||
| 289 | tolower(items[(scroll + i) * 2 + 1][j])) | ||
| 290 | break; | 287 | break; |
| 291 | } | 288 | } |
| 292 | if (i == max_choice) | 289 | if (i == max_choice) |
| 293 | for (i = 0; i < max_choice; i++) { | 290 | for (i = 0; i < max_choice; i++) { |
| 294 | j = first_alpha(items | 291 | j = first_alpha(items [(scroll + i) * 2 + 1], "YyNnMmHh"); |
| 295 | [(scroll + i) * 2 + 1], | 292 | if (key == tolower(items[(scroll + i) * 2 + 1][j])) |
| 296 | "YyNnMmHh"); | ||
| 297 | if (key == | ||
| 298 | tolower(items[(scroll + i) * 2 + 1] | ||
| 299 | [j])) | ||
| 300 | break; | 293 | break; |
| 301 | } | 294 | } |
| 302 | } | 295 | } |
| @@ -319,24 +312,19 @@ dialog_menu(const char *title, const char *prompt, int height, int width, · 16 unmodified lines | |||
| 319 | 312 | ||
| 320 | scroll--; | 313 | scroll--; |
| 321 | 314 | ||
| 322 | print_item(menu, items[scroll * 2 + 1], | 315 | print_item(menu, items[scroll * 2 + 1], 0, FALSE, |
| 323 | 0, FALSE, | 316 | (items[scroll * 2][0] != ':')); |
| 324 | (items[scroll * 2][0] != | ||
| 325 | ':')); | ||
| 326 | } else | 317 | } else |
| 327 | choice = MAX(choice - 1, 0); | 318 | choice = MAX(choice - 1, 0); |
| 328 | 319 | ||
| 329 | } else if (key == KEY_DOWN || key == '+') { | 320 | } else if (key == KEY_DOWN || key == '+') { |
| 330 | 321 | ||
| 331 | print_item(menu, | 322 | print_item(menu, |
| 332 | items[(scroll + choice) * 2 + 1], | 323 | items[(scroll + choice) * 2 + 1], choice, FALSE, |
| 333 | choice, FALSE, | 324 | (items[(scroll + choice) * 2][0] != ':')); |
| 334 | (items[(scroll + choice) * 2][0] != | ||
| 335 | ':')); | ||
| 336 | 325 | ||
| 337 | if ((choice > max_choice - 3) && | 326 | if ((choice > max_choice - 3) && |
| 338 | (scroll + max_choice < item_no) | 327 | (scroll + max_choice < item_no)) { |
| 339 | ) { | ||
| 340 | /* Scroll menu up */ | 328 | /* Scroll menu up */ |
| 341 | scrollok(menu, TRUE); | 329 | scrollok(menu, TRUE); |
| 342 | wscrl(menu, 1); | 330 | wscrl(menu, 1); |
| @@ -344,16 +332,11 @@ dialog_menu(const char *title, const char *prompt, int height, int width, · 1 unmodified line | |||
| 344 | 332 | ||
| 345 | scroll++; | 333 | scroll++; |
| 346 | 334 | ||
| 347 | print_item(menu, | 335 | print_item(menu, items[(scroll + max_choice - 1) * 2 + 1], |
| 348 | items[(scroll + max_choice - | ||
| 349 | 1) * 2 + 1], | ||
| 350 | max_choice - 1, FALSE, | 336 | max_choice - 1, FALSE, |
| 351 | (items | 337 | (items [(scroll + max_choice - 1) * 2][0] != ':')); |
| 352 | [(scroll + max_choice - | ||
| 353 | 1) * 2][0] != ':')); | ||
| 354 | } else | 338 | } else |
| 355 | choice = | 339 | choice = MIN(choice + 1, max_choice - 1); |
| 356 | MIN(choice + 1, max_choice - 1); | ||
| 357 | 340 | ||
| 358 | } else if (key == KEY_PPAGE) { | 341 | } else if (key == KEY_PPAGE) { |
| 359 | scrollok(menu, TRUE); | 342 | scrollok(menu, TRUE); |
| @@ -361,11 +344,8 @@ dialog_menu(const char *title, const char *prompt, int height, int width, · 1 unmodified line | |||
| 361 | if (scroll > 0) { | 344 | if (scroll > 0) { |
| 362 | wscrl(menu, -1); | 345 | wscrl(menu, -1); |
| 363 | scroll--; | 346 | scroll--; |
| 364 | print_item(menu, | 347 | print_item(menu, items[scroll * 2 + 1], 0, FALSE, |
| 365 | items[scroll * 2 + | 348 | (items[scroll * 2][0] != ':')); |
| 366 | 1], 0, FALSE, | ||
| 367 | (items[scroll * 2][0] | ||
| 368 | != ':')); | ||
| 369 | } else { | 349 | } else { |
| 370 | if (choice > 0) | 350 | if (choice > 0) |
| 371 | choice--; | 351 | choice--; |
| @@ -380,17 +360,9 @@ dialog_menu(const char *title, const char *prompt, int height, int width, · 8 unmodified lines | |||
| 380 | wscrl(menu, 1); | 360 | wscrl(menu, 1); |
| 381 | scrollok(menu, FALSE); | 361 | scrollok(menu, FALSE); |
| 382 | scroll++; | 362 | scroll++; |
| 383 | print_item(menu, | 363 | print_item(menu, items[(scroll + max_choice - 1) * 2 + 1], |
| 384 | items[(scroll + | 364 | max_choice - 1, FALSE, |
| 385 | max_choice - | 365 | (items [(scroll + max_choice - 1) * 2][0] != ':')); |
| 386 | 1) * 2 + 1], | ||
| 387 | max_choice - 1, | ||
| 388 | FALSE, | ||
| 389 | (items | ||
| 390 | [(scroll + | ||
| 391 | max_choice - | ||
| 392 | 1) * 2][0] != | ||
| 393 | ':')); | ||
| 394 | } else { | 366 | } else { |
| 395 | if (choice + 1 < max_choice) | 367 | if (choice + 1 < max_choice) |
| 396 | choice++; | 368 | choice++; |
| @@ -401,8 +373,7 @@ dialog_menu(const char *title, const char *prompt, int height, int width, · 4 unmodified lines | |||
| 401 | choice = i; | 373 | choice = i; |
| 402 | 374 | ||
| 403 | print_item(menu, items[(scroll + choice) * 2 + 1], | 375 | print_item(menu, items[(scroll + choice) * 2 + 1], |
| 404 | choice, TRUE, | 376 | choice, TRUE, (items[(scroll + choice) * 2][0] != ':')); |
| 405 | (items[(scroll + choice) * 2][0] != ':')); | ||
| 406 | 377 | ||
| 407 | print_arrows(dialog, item_no, scroll, | 378 | print_arrows(dialog, item_no, scroll, |
| 408 | box_y, box_x + item_x + 1, menu_height); | 379 | 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, · 51 unmodified lines | |||
| 460 | fprintf(stderr, "%s \"%s\"\n", | 431 | fprintf(stderr, "%s \"%s\"\n", |
| 461 | items[(scroll + choice) * 2], | 432 | items[(scroll + choice) * 2], |
| 462 | items[(scroll + choice) * 2 + 1] + | 433 | items[(scroll + choice) * 2 + 1] + |
| 463 | first_alpha(items | 434 | first_alpha(items [(scroll + choice) * 2 + 1], "")); |
| 464 | [(scroll + choice) * 2 + 1], | ||
| 465 | "")); | ||
| 466 | else | 435 | else |
| 467 | fprintf(stderr, "%s\n", | 436 | fprintf(stderr, "%s\n", |
| 468 | items[(scroll + choice) * 2]); | 437 | items[(scroll + choice) * 2]); |
| @@ -25,9 +25,8 @@ · 24 unmodified lines | |||
| 25 | * Display a message box. Program will pause and display an "OK" button | 25 | * Display a message box. Program will pause and display an "OK" button |
| 26 | * if the parameter 'pause' is non-zero. | 26 | * if the parameter 'pause' is non-zero. |
| 27 | */ | 27 | */ |
| 28 | int | 28 | int dialog_msgbox(const char *title, const char *prompt, int height, int width, |
| 29 | dialog_msgbox(const char *title, const char *prompt, int height, int width, | 29 | int pause) |
| 30 | int pause) | ||
| 31 | { | 30 | { |
| 32 | int i, x, y, key = 0; | 31 | int i, x, y, key = 0; |
| 33 | WINDOW *dialog; | 32 | WINDOW *dialog; |
| @@ -46,30 +46,26 @@ int dialog_textbox(const char *title, const char *file, int height, int width) · 45 unmodified lines | |||
| 46 | /* Open input file for reading */ | 46 | /* Open input file for reading */ |
| 47 | if ((fd = open(file, O_RDONLY)) == -1) { | 47 | if ((fd = open(file, O_RDONLY)) == -1) { |
| 48 | endwin(); | 48 | endwin(); |
| 49 | fprintf(stderr, | 49 | fprintf(stderr, "\nCan't open input file in dialog_textbox().\n"); |
| 50 | "\nCan't open input file in dialog_textbox().\n"); | ||
| 51 | exit(-1); | 50 | exit(-1); |
| 52 | } | 51 | } |
| 53 | /* Get file size. Actually, 'file_size' is the real file size - 1, | 52 | /* Get file size. Actually, 'file_size' is the real file size - 1, |
| 54 | since it's only the last byte offset from the beginning */ | 53 | since it's only the last byte offset from the beginning */ |
| 55 | if ((file_size = lseek(fd, 0, SEEK_END)) == -1) { | 54 | if ((file_size = lseek(fd, 0, SEEK_END)) == -1) { |
| 56 | endwin(); | 55 | endwin(); |
| 57 | fprintf(stderr, | 56 | fprintf(stderr, "\nError getting file size in dialog_textbox().\n"); |
| 58 | "\nError getting file size in dialog_textbox().\n"); | ||
| 59 | exit(-1); | 57 | exit(-1); |
| 60 | } | 58 | } |
| 61 | /* Restore file pointer to beginning of file after getting file size */ | 59 | /* Restore file pointer to beginning of file after getting file size */ |
| 62 | if (lseek(fd, 0, SEEK_SET) == -1) { | 60 | if (lseek(fd, 0, SEEK_SET) == -1) { |
| 63 | endwin(); | 61 | endwin(); |
| 64 | fprintf(stderr, | 62 | fprintf(stderr, "\nError moving file pointer in dialog_textbox().\n"); |
| 65 | "\nError moving file pointer in dialog_textbox().\n"); | ||
| 66 | exit(-1); | 63 | exit(-1); |
| 67 | } | 64 | } |
| 68 | /* Allocate space for read buffer */ | 65 | /* Allocate space for read buffer */ |
| 69 | if ((buf = malloc(BUF_SIZE + 1)) == NULL) { | 66 | if ((buf = malloc(BUF_SIZE + 1)) == NULL) { |
| 70 | endwin(); | 67 | endwin(); |
| 71 | fprintf(stderr, | 68 | fprintf(stderr, "\nCan't allocate memory in dialog_textbox().\n"); |
| 72 | "\nCan't allocate memory in dialog_textbox().\n"); | ||
| 73 | exit(-1); | 69 | exit(-1); |
| 74 | } | 70 | } |
| 75 | if ((bytes_read = read(fd, buf, BUF_SIZE)) == -1) { | 71 | 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) · 74 unmodified lines | |||
| 150 | /* First page not in buffer? */ | 146 | /* First page not in buffer? */ |
| 151 | if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) { | 147 | if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) { |
| 152 | endwin(); | 148 | endwin(); |
| 153 | fprintf(stderr, | 149 | fprintf(stderr, "\nError moving file pointer in dialog_textbox().\n"); |
| 154 | "\nError moving file pointer in dialog_textbox().\n"); | ||
| 155 | exit(-1); | 150 | exit(-1); |
| 156 | } | 151 | } |
| 157 | if (fpos > bytes_read) { /* Yes, we have to read it in */ | 152 | if (fpos > bytes_read) { /* Yes, we have to read it in */ |
| 158 | if (lseek(fd, 0, SEEK_SET) == -1) { | 153 | if (lseek(fd, 0, SEEK_SET) == -1) { |
| 159 | endwin(); | 154 | endwin(); |
| 160 | fprintf(stderr, | 155 | fprintf(stderr, "\nError moving file pointer in " |
| 161 | "\nError moving file pointer in " | 156 | "dialog_textbox().\n"); |
| 162 | "dialog_textbox().\n"); | ||
| 163 | exit(-1); | 157 | exit(-1); |
| 164 | } | 158 | } |
| 165 | if ((bytes_read = | 159 | if ((bytes_read = |
| 166 | read(fd, buf, BUF_SIZE)) == -1) { | 160 | read(fd, buf, BUF_SIZE)) == -1) { |
| 167 | endwin(); | 161 | endwin(); |
| 168 | fprintf(stderr, | 162 | fprintf(stderr, "\nError reading file in dialog_textbox().\n"); |
| 169 | "\nError reading file in dialog_textbox().\n"); | ||
| 170 | exit(-1); | 163 | exit(-1); |
| 171 | } | 164 | } |
| 172 | buf[bytes_read] = '\0'; | 165 | buf[bytes_read] = '\0'; |
| @@ -185,22 +178,19 @@ int dialog_textbox(const char *title, const char *file, int height, int width) · 12 unmodified lines | |||
| 185 | /* Last page not in buffer? */ | 178 | /* Last page not in buffer? */ |
| 186 | if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) { | 179 | if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) { |
| 187 | endwin(); | 180 | endwin(); |
| 188 | fprintf(stderr, | 181 | fprintf(stderr, "\nError moving file pointer in dialog_textbox().\n"); |
| 189 | "\nError moving file pointer in dialog_textbox().\n"); | ||
| 190 | exit(-1); | 182 | exit(-1); |
| 191 | } | 183 | } |
| 192 | if (fpos < file_size) { /* Yes, we have to read it in */ | 184 | if (fpos < file_size) { /* Yes, we have to read it in */ |
| 193 | if (lseek(fd, -BUF_SIZE, SEEK_END) == -1) { | 185 | if (lseek(fd, -BUF_SIZE, SEEK_END) == -1) { |
| 194 | endwin(); | 186 | endwin(); |
| 195 | fprintf(stderr, | 187 | fprintf(stderr, "\nError moving file pointer in dialog_textbox().\n"); |
| 196 | "\nError moving file pointer in dialog_textbox().\n"); | ||
| 197 | exit(-1); | 188 | exit(-1); |
| 198 | } | 189 | } |
| 199 | if ((bytes_read = | 190 | if ((bytes_read = |
| 200 | read(fd, buf, BUF_SIZE)) == -1) { | 191 | read(fd, buf, BUF_SIZE)) == -1) { |
| 201 | endwin(); | 192 | endwin(); |
| 202 | fprintf(stderr, | 193 | fprintf(stderr, "\nError reading file in dialog_textbox().\n"); |
| 203 | "\nError reading file in dialog_textbox().\n"); | ||
| 204 | exit(-1); | 194 | exit(-1); |
| 205 | } | 195 | } |
| 206 | buf[bytes_read] = '\0'; | 196 | buf[bytes_read] = '\0'; |
| @@ -342,9 +332,8 @@ static void back_lines(int n) · 135 unmodified lines | |||
| 342 | if (page == buf) { | 332 | if (page == buf) { |
| 343 | if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) { | 333 | if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) { |
| 344 | endwin(); | 334 | endwin(); |
| 345 | fprintf(stderr, | 335 | fprintf(stderr, "\nError moving file pointer in " |
| 346 | "\nError moving file pointer in " | 336 | "back_lines().\n"); |
| 347 | "back_lines().\n"); | ||
| 348 | exit(-1); | 337 | exit(-1); |
| 349 | } | 338 | } |
| 350 | if (fpos > bytes_read) { /* Not beginning of file yet */ | 339 | if (fpos > bytes_read) { /* Not beginning of file yet */ |
| @@ -358,21 +347,16 @@ static void back_lines(int n) · 7 unmodified lines | |||
| 358 | /* No, move less then */ | 347 | /* No, move less then */ |
| 359 | if (lseek(fd, 0, SEEK_SET) == -1) { | 348 | if (lseek(fd, 0, SEEK_SET) == -1) { |
| 360 | endwin(); | 349 | endwin(); |
| 361 | fprintf(stderr, | 350 | fprintf(stderr, "\nError moving file pointer in " |
| 362 | "\nError moving file pointer in " | 351 | "back_lines().\n"); |
| 363 | "back_lines().\n"); | ||
| 364 | exit(-1); | 352 | exit(-1); |
| 365 | } | 353 | } |
| 366 | page = buf + fpos - bytes_read; | 354 | page = buf + fpos - bytes_read; |
| 367 | } else { /* Move backward BUF_SIZE/2 bytes */ | 355 | } else { /* Move backward BUF_SIZE/2 bytes */ |
| 368 | if (lseek | 356 | if (lseek (fd, -(BUF_SIZE / 2 + bytes_read), SEEK_CUR) == -1) { |
| 369 | (fd, -(BUF_SIZE / 2 + bytes_read), | ||
| 370 | SEEK_CUR) | ||
| 371 | == -1) { | ||
| 372 | endwin(); | 357 | endwin(); |
| 373 | fprintf(stderr, | 358 | fprintf(stderr, "\nError moving file pointer " |
| 374 | "\nError moving file pointer " | 359 | "in back_lines().\n"); |
| 375 | "in back_lines().\n"); | ||
| 376 | exit(-1); | 360 | exit(-1); |
| 377 | } | 361 | } |
| 378 | page = buf + BUF_SIZE / 2; | 362 | page = buf + BUF_SIZE / 2; |
| @@ -380,8 +364,7 @@ static void back_lines(int n) · 1 unmodified line | |||
| 380 | if ((bytes_read = | 364 | if ((bytes_read = |
| 381 | read(fd, buf, BUF_SIZE)) == -1) { | 365 | read(fd, buf, BUF_SIZE)) == -1) { |
| 382 | endwin(); | 366 | endwin(); |
| 383 | fprintf(stderr, | 367 | fprintf(stderr, "\nError reading file in back_lines().\n"); |
| 384 | "\nError reading file in back_lines().\n"); | ||
| 385 | exit(-1); | 368 | exit(-1); |
| 386 | } | 369 | } |
| 387 | buf[bytes_read] = '\0'; | 370 | buf[bytes_read] = '\0'; |
| @@ -403,33 +386,25 @@ static void back_lines(int n) · 15 unmodified lines | |||
| 403 | if (page == buf) { | 386 | if (page == buf) { |
| 404 | if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) { | 387 | if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) { |
| 405 | endwin(); | 388 | endwin(); |
| 406 | fprintf(stderr, | 389 | fprintf(stderr, "\nError moving file pointer in back_lines().\n"); |
| 407 | "\nError moving file pointer in back_lines().\n"); | ||
| 408 | exit(-1); | 390 | exit(-1); |
| 409 | } | 391 | } |
| 410 | if (fpos > bytes_read) { | 392 | if (fpos > bytes_read) { |
| 411 | /* Really possible to move backward BUF_SIZE/2 bytes? */ | 393 | /* Really possible to move backward BUF_SIZE/2 bytes? */ |
| 412 | if (fpos < BUF_SIZE / 2 + bytes_read) { | 394 | if (fpos < BUF_SIZE / 2 + bytes_read) { |
| 413 | /* No, move less then */ | 395 | /* No, move less then */ |
| 414 | if (lseek(fd, 0, SEEK_SET) == | 396 | if (lseek(fd, 0, SEEK_SET) == -1) { |
| 415 | -1) { | ||
| 416 | endwin(); | 397 | endwin(); |
| 417 | fprintf(stderr, | 398 | fprintf(stderr, "\nError moving file pointer " |
| 418 | "\nError moving file pointer " | 399 | "in back_lines().\n"); |
| 419 | "in back_lines().\n"); | ||
| 420 | exit(-1); | 400 | exit(-1); |
| 421 | } | 401 | } |
| 422 | page = buf + fpos - bytes_read; | 402 | page = buf + fpos - bytes_read; |
| 423 | } else { /* Move backward BUF_SIZE/2 bytes */ | 403 | } else { /* Move backward BUF_SIZE/2 bytes */ |
| 424 | if (lseek | 404 | if (lseek (fd, -(BUF_SIZE / 2 + bytes_read), SEEK_CUR) == -1) { |
| 425 | (fd, | ||
| 426 | -(BUF_SIZE / 2 + | ||
| 427 | bytes_read), | ||
| 428 | SEEK_CUR) == -1) { | ||
| 429 | endwin(); | 405 | endwin(); |
| 430 | fprintf(stderr, | 406 | fprintf(stderr, "\nError moving file pointer" |
| 431 | "\nError moving file pointer" | 407 | " in back_lines().\n"); |
| 432 | " in back_lines().\n"); | ||
| 433 | exit(-1); | 408 | exit(-1); |
| 434 | } | 409 | } |
| 435 | page = buf + BUF_SIZE / 2; | 410 | page = buf + BUF_SIZE / 2; |
| @@ -437,9 +412,8 @@ static void back_lines(int n) · 1 unmodified line | |||
| 437 | if ((bytes_read = | 412 | if ((bytes_read = |
| 438 | read(fd, buf, BUF_SIZE)) == -1) { | 413 | read(fd, buf, BUF_SIZE)) == -1) { |
| 439 | endwin(); | 414 | endwin(); |
| 440 | fprintf(stderr, | 415 | fprintf(stderr, "\nError reading file in " |
| 441 | "\nError reading file in " | 416 | "back_lines().\n"); |
| 442 | "back_lines().\n"); | ||
| 443 | exit(-1); | 417 | exit(-1); |
| 444 | } | 418 | } |
| 445 | buf[bytes_read] = '\0'; | 419 | buf[bytes_read] = '\0'; |
| @@ -513,9 +487,8 @@ static char *get_line(void) · 67 unmodified lines | |||
| 513 | /* Either end of file or end of buffer reached */ | 487 | /* Either end of file or end of buffer reached */ |
| 514 | if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) { | 488 | if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) { |
| 515 | endwin(); | 489 | endwin(); |
| 516 | fprintf(stderr, | 490 | fprintf(stderr, "\nError moving file pointer in " |
| 517 | "\nError moving file pointer in " | 491 | "get_line().\n"); |
| 518 | "get_line().\n"); | ||
| 519 | exit(-1); | 492 | exit(-1); |
| 520 | } | 493 | } |
| 521 | if (fpos < file_size) { /* Not end of file yet */ | 494 | if (fpos < file_size) { /* Not end of file yet */ |
| @@ -524,8 +497,7 @@ static char *get_line(void) · 2 unmodified lines | |||
| 524 | if ((bytes_read = | 497 | if ((bytes_read = |
| 525 | read(fd, buf, BUF_SIZE)) == -1) { | 498 | read(fd, buf, BUF_SIZE)) == -1) { |
| 526 | endwin(); | 499 | endwin(); |
| 527 | fprintf(stderr, | 500 | fprintf(stderr, "\nError reading file in get_line().\n"); |
| 528 | "\nError reading file in get_line().\n"); | ||
| 529 | exit(-1); | 501 | exit(-1); |
| 530 | } | 502 | } |
| 531 | buf[bytes_read] = '\0'; | 503 | buf[bytes_read] = '\0'; |
| @@ -561,8 +533,7 @@ static void print_position(WINDOW * win, int height, int width) · 29 unmodified lines | |||
| 561 | 533 | ||
| 562 | if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) { | 534 | if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) { |
| 563 | endwin(); | 535 | endwin(); |
| 564 | fprintf(stderr, | 536 | fprintf(stderr, "\nError moving file pointer in print_position().\n"); |
| 565 | "\nError moving file pointer in print_position().\n"); | ||
| 566 | exit(-1); | 537 | exit(-1); |
| 567 | } | 538 | } |
| 568 | wattrset(win, position_indicator_attr); | 539 | wattrset(win, position_indicator_attr); |
| @@ -28,7 +28,7 @@ const char *backtitle = NULL; · 27 unmodified lines | |||
| 28 | 28 | ||
| 29 | const char *dialog_result; | 29 | const char *dialog_result; |
| 30 | 30 | ||
| 31 | /* | 31 | /* |
| 32 | * Attribute values, default is for mono display | 32 | * Attribute values, default is for mono display |
| 33 | */ | 33 | */ |
| 34 | chtype attributes[] = { | 34 | chtype attributes[] = { |
| @@ -96,8 +96,7 @@ int dialog_yesno(const char *title, const char *prompt, int height, int width) · 95 unmodified lines | |||
| 96 | case TAB: | 96 | case TAB: |
| 97 | case KEY_LEFT: | 97 | case KEY_LEFT: |
| 98 | case KEY_RIGHT: | 98 | case KEY_RIGHT: |
| 99 | button = ((key == KEY_LEFT ? --button : ++button) < 0) | 99 | button = ((key == KEY_LEFT ? --button : ++button) < 0) ? 1 : (button > 1 ? 0 : button); |
| 100 | ? 1 : (button > 1 ? 0 : button); | ||
| 101 | 100 | ||
| 102 | print_buttons(dialog, height, width, button); | 101 | print_buttons(dialog, height, width, button); |
| 103 | wrefresh(dialog); | 102 | wrefresh(dialog); |