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