Skip to content

Commit

Permalink
kconfig: fixup after Lindent
Browse files Browse the repository at this point in the history
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: Sam Ravnborg <sam@ravnborg.org>
  • Loading branch information
Sam Ravnborg committed Nov 19, 2005
1 parent b1c5f1c commit dec69da
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 229 deletions.
99 changes: 30 additions & 69 deletions scripts/lxdialog/checklist.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ static int list_width, check_x, item_x, checkflag;
/*
* Print list item
*/
static void
print_item(WINDOW * win, const char *item, int status, int choice, int selected)
static void print_item(WINDOW * win, const char *item, int status, int choice,
int selected)
{
int i;

Expand Down Expand Up @@ -59,8 +59,7 @@ print_item(WINDOW * win, const char *item, int status, int choice, int selected)
/*
* Print the scroll indicators.
*/
static void
print_arrows(WINDOW * win, int choice, int item_no, int scroll,
static void print_arrows(WINDOW * win, int choice, int item_no, int scroll,
int y, int x, int height)
{
wmove(win, y, x);
Expand Down Expand Up @@ -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
* The `flag' parameter is used to select between radiolist and checklist.
*/
int
dialog_checklist(const char *title, const char *prompt, int height, int width,
int list_height, int item_no, const char *const *items,
int flag)
int dialog_checklist(const char *title, const char *prompt, int height,
int width, int list_height, int item_no,
const char *const *items, int flag)
{
int i, x, y, box_x, box_y;
int key = 0, button = 0, choice = 0, scroll = 0, max_choice, *status;
Expand Down Expand Up @@ -183,15 +181,14 @@ dialog_checklist(const char *title, const char *prompt, int height, int width,
box_x = (width - list_width) / 2 - 1;

/* create new window for the list */
list =
subwin(dialog, list_height, list_width, y + box_y + 1,
x + box_x + 1);
list = subwin(dialog, list_height, list_width, y + box_y + 1,
x + box_x + 1);

keypad(list, TRUE);

/* draw a box around the list items */
draw_box(dialog, box_y, box_x, list_height + 2, list_width + 2,
menubox_border_attr, menubox_attr);
menubox_border_attr, menubox_attr);

/* Find length of longest item in order to center checklist */
check_x = 0;
Expand Down Expand Up @@ -238,24 +235,18 @@ dialog_checklist(const char *title, const char *prompt, int height, int width,
/* Scroll list down */
if (list_height > 1) {
/* De-highlight current first item */
print_item(list,
items[scroll * 3 +
1],
status[scroll], 0,
FALSE);
print_item(list, items[scroll * 3 + 1],
status[scroll], 0, FALSE);
scrollok(list, TRUE);
wscrl(list, -1);
scrollok(list, FALSE);
}
scroll--;
print_item(list, items[scroll * 3 + 1],
status[scroll], 0, TRUE);
print_item(list, items[scroll * 3 + 1], status[scroll], 0, TRUE);
wnoutrefresh(list);

print_arrows(dialog, choice, item_no,
scroll, box_y,
box_x + check_x + 5,
list_height);
scroll, box_y, box_x + check_x + 5, list_height);

wrefresh(dialog);

Expand All @@ -269,32 +260,20 @@ dialog_checklist(const char *title, const char *prompt, int height, int width,
/* Scroll list up */
if (list_height > 1) {
/* De-highlight current last item before scrolling up */
print_item(list,
items[(scroll +
max_choice -
1) * 3 + 1],
status[scroll +
max_choice -
1],
max_choice - 1,
FALSE);
print_item(list, items[(scroll + max_choice - 1) * 3 + 1],
status[scroll + max_choice - 1],
max_choice - 1, FALSE);
scrollok(list, TRUE);
wscrl(list, 1);
scrollok(list, FALSE);
}
scroll++;
print_item(list,
items[(scroll + max_choice -
1) * 3 + 1],
status[scroll + max_choice -
1], max_choice - 1,
TRUE);
print_item(list, items[(scroll + max_choice - 1) * 3 + 1],
status[scroll + max_choice - 1], max_choice - 1, TRUE);
wnoutrefresh(list);

print_arrows(dialog, choice, item_no,
scroll, box_y,
box_x + check_x + 5,
list_height);
scroll, box_y, box_x + check_x + 5, list_height);

wrefresh(dialog);

Expand All @@ -304,16 +283,12 @@ dialog_checklist(const char *title, const char *prompt, int height, int width,
}
if (i != choice) {
/* De-highlight current item */
print_item(list,
items[(scroll + choice) * 3 + 1],
status[scroll + choice], choice,
FALSE);
print_item(list, items[(scroll + choice) * 3 + 1],
status[scroll + choice], choice, FALSE);
/* Highlight new item */
choice = i;
print_item(list,
items[(scroll + choice) * 3 + 1],
status[scroll + choice], choice,
TRUE);
print_item(list, items[(scroll + choice) * 3 + 1],
status[scroll + choice], choice, TRUE);
wnoutrefresh(list);
wrefresh(dialog);
}
Expand Down Expand Up @@ -342,28 +317,18 @@ dialog_checklist(const char *title, const char *prompt, int height, int width,
case '\n':
if (!button) {
if (flag == FLAG_CHECK) {
status[scroll + choice] =
!status[scroll + choice];
status[scroll + choice] = !status[scroll + choice];
wmove(list, choice, check_x);
wattrset(list, check_selected_attr);
wprintw(list, "[%c]",
status[scroll +
choice] ? 'X' : ' ');
wprintw(list, "[%c]", status[scroll + choice] ? 'X' : ' ');
} else {
if (!status[scroll + choice]) {
for (i = 0; i < item_no; i++)
status[i] = 0;
status[scroll + choice] = 1;
for (i = 0; i < max_choice; i++)
print_item(list,
items[(scroll
+
i) *
3 + 1],
status[scroll
+ i],
i,
i == choice);
print_item(list, items[(scroll + i) * 3 + 1],
status[scroll + i], i, i == choice);
}
}
wnoutrefresh(list);
Expand All @@ -372,19 +337,15 @@ dialog_checklist(const char *title, const char *prompt, int height, int width,
for (i = 0; i < item_no; i++) {
if (status[i]) {
if (flag == FLAG_CHECK) {
fprintf(stderr,
"\"%s\" ",
items[i * 3]);
fprintf(stderr, "\"%s\" ", items[i * 3]);
} else {
fprintf(stderr, "%s",
items[i * 3]);
fprintf(stderr, "%s", items[i * 3]);
}

}
}
} else
fprintf(stderr, "%s",
items[(scroll + choice) * 3]);
fprintf(stderr, "%s", items[(scroll + choice) * 3]);
delwin(dialog);
free(status);
return button;
Expand Down
3 changes: 1 addition & 2 deletions scripts/lxdialog/dialog.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/*
* dialog.h -- common declarations for all dialog modules
*
Expand Down Expand Up @@ -87,7 +86,7 @@
#define ACS_DARROW 'v'
#endif

/*
/*
* Attribute names
*/
#define screen_attr attributes[0]
Expand Down
49 changes: 15 additions & 34 deletions scripts/lxdialog/inputbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ static void print_buttons(WINDOW * dialog, int height, int width, int selected)
/*
* Display a dialog box for inputing a string
*/
int
dialog_inputbox(const char *title, const char *prompt, int height, int width,
const char *init)
int dialog_inputbox(const char *title, const char *prompt, int height, int width,
const char *init)
{
int i, x, y, box_y, box_x, box_width;
int input_x = 0, scroll = 0, key = 0, button = -1;
Expand Down Expand Up @@ -90,8 +89,7 @@ dialog_inputbox(const char *title, const char *prompt, int height, int width,
getyx(dialog, y, x);
box_y = y + 2;
box_x = (width - box_width) / 2;
draw_box(dialog, y + 1, box_x - 1, 3, box_width + 2,
border_attr, dialog_attr);
draw_box(dialog, y + 1, box_x - 1, 3, box_width + 2, border_attr, dialog_attr);

print_buttons(dialog, height, width, 0);

Expand All @@ -111,8 +109,9 @@ dialog_inputbox(const char *title, const char *prompt, int height, int width,
input_x = box_width - 1;
for (i = 0; i < box_width - 1; i++)
waddch(dialog, instr[scroll + i]);
} else
} else {
waddstr(dialog, instr);
}

wmove(dialog, box_y, box_x + input_x);

Expand All @@ -136,26 +135,17 @@ dialog_inputbox(const char *title, const char *prompt, int height, int width,
if (input_x || scroll) {
wattrset(dialog, inputbox_attr);
if (!input_x) {
scroll =
scroll <
box_width - 1 ? 0 : scroll -
(box_width - 1);
scroll = scroll < box_width - 1 ? 0 : scroll - (box_width - 1);
wmove(dialog, box_y, box_x);
for (i = 0; i < box_width; i++)
waddch(dialog,
instr[scroll +
input_x +
i] ?
instr[scroll +
input_x +
i] : ' ');
input_x =
strlen(instr) - scroll;
instr[scroll + input_x + i] ?
instr[scroll + input_x + i] : ' ');
input_x = strlen(instr) - scroll;
} else
input_x--;
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);
wrefresh(dialog);
}
Expand All @@ -165,23 +155,14 @@ dialog_inputbox(const char *title, const char *prompt, int height, int width,
if (scroll + input_x < MAX_LEN) {
wattrset(dialog, inputbox_attr);
instr[scroll + input_x] = key;
instr[scroll + input_x + 1] =
'\0';
instr[scroll + input_x + 1] = '\0';
if (input_x == box_width - 1) {
scroll++;
wmove(dialog, box_y,
box_x);
for (i = 0;
i < box_width - 1;
i++)
waddch(dialog,
instr
[scroll +
i]);
wmove(dialog, box_y, box_x);
for (i = 0; i < box_width - 1; i++)
waddch(dialog, instr [scroll + i]);
} else {
wmove(dialog, box_y,
input_x++ +
box_x);
wmove(dialog, box_y, input_x++ + box_x);
waddch(dialog, key);
}
wrefresh(dialog);
Expand Down
Loading

0 comments on commit dec69da

Please sign in to comment.