Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b1c5f1c6 authored by Sam Ravnborg's avatar Sam Ravnborg
Browse files

kconfig: Lindent scripts/lxdialog



The lxdialog code was not easy to read. So as first step the code
was run through Lindent.
Fix-ups will come in next patchset.

Signed-off-by: default avatarSam Ravnborg <sam@ravnborg.org>
parent b286e392
Loading
Loading
Loading
Loading
+344 −312
Original line number Original line Diff line number Diff line
@@ -29,8 +29,7 @@ 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,
print_item(WINDOW * win, const char *item, int status, int choice, int selected)
	    int choice, int selected)
{
{
	int i;
	int i;


@@ -70,8 +69,7 @@ print_arrows (WINDOW * win, int choice, int item_no, int scroll,
		wattrset(win, uarrow_attr);
		wattrset(win, uarrow_attr);
		waddch(win, ACS_UARROW);
		waddch(win, ACS_UARROW);
		waddstr(win, "(-)");
		waddstr(win, "(-)");
    }
	} else {
    else {
		wattrset(win, menubox_attr);
		wattrset(win, menubox_attr);
		waddch(win, ACS_HLINE);
		waddch(win, ACS_HLINE);
		waddch(win, ACS_HLINE);
		waddch(win, ACS_HLINE);
@@ -86,8 +84,7 @@ print_arrows (WINDOW * win, int choice, int item_no, int scroll,
		wattrset(win, darrow_attr);
		wattrset(win, darrow_attr);
		waddch(win, ACS_DARROW);
		waddch(win, ACS_DARROW);
		waddstr(win, "(+)");
		waddstr(win, "(+)");
    }
	} else {
    else {
		wattrset(win, menubox_border_attr);
		wattrset(win, menubox_border_attr);
		waddch(win, ACS_HLINE);
		waddch(win, ACS_HLINE);
		waddch(win, ACS_HLINE);
		waddch(win, ACS_HLINE);
@@ -99,8 +96,7 @@ print_arrows (WINDOW * win, int choice, int item_no, int scroll,
/*
/*
 *  Display the termination buttons
 *  Display the termination buttons
 */
 */
static void
static void print_buttons(WINDOW * dialog, int height, int width, int selected)
print_buttons( WINDOW *dialog, int height, int width, int selected)
{
{
	int x = width / 2 - 11;
	int x = width / 2 - 11;
	int y = height - 2;
	int y = height - 2;
@@ -118,8 +114,8 @@ print_buttons( WINDOW *dialog, int height, int width, int selected)
 */
 */
int
int
dialog_checklist(const char *title, const char *prompt, int height, int width,
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 list_height, int item_no, const char *const *items,
	
		 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;
@@ -138,7 +134,8 @@ dialog_checklist (const char *title, const char *prompt, int height, int width,
	/* Initializes status */
	/* Initializes status */
	for (i = 0; i < item_no; i++) {
	for (i = 0; i < item_no; i++) {
		status[i] = !strcasecmp(items[i * 3 + 2], "on");
		status[i] = !strcasecmp(items[i * 3 + 2], "on");
	if ((!choice && status[i]) || !strcasecmp (items[i * 3 + 2], "selected"))
		if ((!choice && status[i])
		    || !strcasecmp(items[i * 3 + 2], "selected"))
			choice = i + 1;
			choice = i + 1;
	}
	}
	if (choice)
	if (choice)
@@ -186,7 +183,9 @@ 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 = 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);
	keypad(list, TRUE);


@@ -226,10 +225,10 @@ dialog_checklist (const char *title, const char *prompt, int height, int width,
		key = wgetch(dialog);
		key = wgetch(dialog);


		for (i = 0; i < max_choice; i++)
		for (i = 0; i < max_choice; i++)
            if (toupper(key) == toupper(items[(scroll+i)*3+1][0]))
			if (toupper(key) ==
			    toupper(items[(scroll + i) * 3 + 1][0]))
				break;
				break;



		if (i < max_choice || key == KEY_UP || key == KEY_DOWN ||
		if (i < max_choice || key == KEY_UP || key == KEY_DOWN ||
		    key == '+' || key == '-') {
		    key == '+' || key == '-') {
			if (key == KEY_UP || key == '-') {
			if (key == KEY_UP || key == '-') {
@@ -239,8 +238,11 @@ 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, items[scroll * 3 + 1],
						print_item(list,
					status[scroll], 0, FALSE);
							   items[scroll * 3 +
								 1],
							   status[scroll], 0,
							   FALSE);
						scrollok(list, TRUE);
						scrollok(list, TRUE);
						wscrl(list, -1);
						wscrl(list, -1);
						scrollok(list, FALSE);
						scrollok(list, FALSE);
@@ -250,8 +252,10 @@ dialog_checklist (const char *title, const char *prompt, int height, int width,
						   status[scroll], 0, TRUE);
						   status[scroll], 0, TRUE);
					wnoutrefresh(list);
					wnoutrefresh(list);


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


					wrefresh(dialog);
					wrefresh(dialog);


@@ -265,21 +269,32 @@ 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, items[(scroll + max_choice - 1) * 3 + 1],
						print_item(list,
				    status[scroll + max_choice - 1],
							   items[(scroll +
				    max_choice - 1, FALSE);
								  max_choice -
								  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, items[(scroll + max_choice - 1) * 3 + 1],
					print_item(list,
				status[scroll + max_choice - 1],
						   items[(scroll + max_choice -
				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, scroll,
					print_arrows(dialog, choice, item_no,
				box_y, box_x + check_x + 5, list_height);
						     scroll, box_y,
						     box_x + check_x + 5,
						     list_height);


					wrefresh(dialog);
					wrefresh(dialog);


@@ -289,12 +304,16 @@ 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, items[(scroll + choice) * 3 + 1],
				print_item(list,
			    status[scroll + choice], choice, FALSE);
					   items[(scroll + choice) * 3 + 1],
					   status[scroll + choice], choice,
					   FALSE);
				/* Highlight new item */
				/* Highlight new item */
				choice = i;
				choice = i;
		print_item (list, items[(scroll + choice) * 3 + 1],
				print_item(list,
			    status[scroll + choice], choice, TRUE);
					   items[(scroll + choice) * 3 + 1],
					   status[scroll + choice], choice,
					   TRUE);
				wnoutrefresh(list);
				wnoutrefresh(list);
				wrefresh(dialog);
				wrefresh(dialog);
			}
			}
@@ -323,18 +342,28 @@ 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]", status[scroll + choice] ? 'X' : ' ');
					wprintw(list, "[%c]",
						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, items[(scroll + i) * 3 + 1],
							print_item(list,
					status[scroll + i], i, i == choice);
								   items[(scroll
									  +
									  i) *
									 3 + 1],
								   status[scroll
									  + i],
								   i,
								   i == choice);
					}
					}
				}
				}
				wnoutrefresh(list);
				wnoutrefresh(list);
@@ -343,15 +372,19 @@ 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, "\"%s\" ", items[i * 3]);
							fprintf(stderr,
								"\"%s\" ",
								items[i * 3]);
						} else {
						} else {
			    fprintf (stderr, "%s", items[i * 3]);
							fprintf(stderr, "%s",
								items[i * 3]);
						}
						}


					}
					}
				}
				}
			} else
			} else
		fprintf (stderr, "%s", items[(scroll + choice) * 3]);
				fprintf(stderr, "%s",
					items[(scroll + choice) * 3]);
			delwin(dialog);
			delwin(dialog);
			free(status);
			free(status);
			return button;
			return button;
@@ -366,7 +399,6 @@ dialog_checklist (const char *title, const char *prompt, int height, int width,
		doupdate();
		doupdate();
	}
	}



	delwin(dialog);
	delwin(dialog);
	free(status);
	free(status);
	return -1;		/* ESC pressed */
	return -1;		/* ESC pressed */
+0 −1
Original line number Original line Diff line number Diff line
@@ -18,7 +18,6 @@
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 */



/*
/*
 *   Default color definitions
 *   Default color definitions
 *
 *
+28 −31
Original line number Original line Diff line number Diff line
@@ -56,7 +56,6 @@
#define MIN(x,y) (x < y ? x : y)
#define MIN(x,y) (x < y ? x : y)
#define MAX(x,y) (x > y ? x : y)
#define MAX(x,y) (x > y ? x : y)



#ifndef ACS_ULCORNER
#ifndef ACS_ULCORNER
#define ACS_ULCORNER '+'
#define ACS_ULCORNER '+'
#endif
#endif
@@ -140,7 +139,6 @@ extern const char *backtitle;
extern void create_rc(const char *filename);
extern void create_rc(const char *filename);
extern int parse_rc(void);
extern int parse_rc(void);



void init_dialog(void);
void init_dialog(void);
void end_dialog(void);
void end_dialog(void);
void attr_clear(WINDOW * win, int height, int width, chtype attr);
void attr_clear(WINDOW * win, int height, int width, chtype attr);
@@ -178,7 +176,6 @@ int dialog_inputbox (const char *title, const char *prompt, int height,
 */
 */
#define M_EVENT (KEY_MAX+1)
#define M_EVENT (KEY_MAX+1)



/*
/*
 * The `flag' parameter in checklist is used to select between
 * The `flag' parameter in checklist is used to select between
 * radiolist and checklist
 * radiolist and checklist
+212 −196
Original line number Original line Diff line number Diff line
@@ -26,8 +26,7 @@ char dialog_input_result[MAX_LEN + 1];
/*
/*
 *  Print the termination buttons
 *  Print the termination buttons
 */
 */
static void
static void print_buttons(WINDOW * dialog, int height, int width, int selected)
print_buttons(WINDOW *dialog, int height, int width, int selected)
{
{
	int x = width / 2 - 11;
	int x = width / 2 - 11;
	int y = height - 2;
	int y = height - 2;
@@ -55,7 +54,6 @@ dialog_inputbox (const char *title, const char *prompt, int height, int width,
	x = (COLS - width) / 2;
	x = (COLS - width) / 2;
	y = (LINES - height) / 2;
	y = (LINES - height) / 2;



	draw_shadow(stdscr, y, x, height, width);
	draw_shadow(stdscr, y, x, height, width);


	dialog = newwin(height, width, y, x);
	dialog = newwin(height, width, y, x);
@@ -138,17 +136,26 @@ 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 < box_width - 1 ?
						scroll =
			    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, instr[scroll + input_x + i] ?
							waddch(dialog,
				    instr[scroll + input_x + i] : ' ');
							       instr[scroll +
			input_x = strlen (instr) - scroll;
								     input_x +
								     i] ?
							       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);
				}
				}
@@ -158,14 +165,23 @@ 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] = '\0';
						instr[scroll + input_x + 1] =
						    '\0';
						if (input_x == box_width - 1) {
						if (input_x == box_width - 1) {
							scroll++;
							scroll++;
			    wmove (dialog, box_y, box_x);
							wmove(dialog, box_y,
			    for (i = 0; i < box_width - 1; i++)
							      box_x);
				waddch (dialog, instr[scroll + i]);
							for (i = 0;
							     i < box_width - 1;
							     i++)
								waddch(dialog,
								       instr
								       [scroll +
									i]);
						} else {
						} else {
			    wmove (dialog, box_y, input_x++ + box_x);
							wmove(dialog, box_y,
							      input_x++ +
							      box_x);
							waddch(dialog, key);
							waddch(dialog, key);
						}
						}
						wrefresh(dialog);
						wrefresh(dialog);
+112 −126
Original line number Original line Diff line number Diff line
@@ -34,8 +34,7 @@ struct Mode {
jumperFn j_menu, j_checklist, j_radiolist, j_yesno, j_textbox, j_inputbox;
jumperFn j_menu, j_checklist, j_radiolist, j_yesno, j_textbox, j_inputbox;
jumperFn j_msgbox, j_infobox;
jumperFn j_msgbox, j_infobox;


static struct Mode modes[] =
static struct Mode modes[] = {
{
	{"--menu", 9, 0, 3, j_menu},
	{"--menu", 9, 0, 3, j_menu},
	{"--checklist", 9, 0, 3, j_checklist},
	{"--checklist", 9, 0, 3, j_checklist},
	{"--radiolist", 9, 0, 3, j_radiolist},
	{"--radiolist", 9, 0, 3, j_radiolist},
@@ -53,8 +52,7 @@ static struct Mode *modePtr;
#include <locale.h>
#include <locale.h>
#endif
#endif


int
int main(int argc, const char *const *argv)
main (int argc, const char * const * argv)
{
{
	int offset = 0, opt_clear = 0, end_common_opts = 0, retval;
	int offset = 0, opt_clear = 0, end_common_opts = 0, retval;
	const char *title = NULL;
	const char *title = NULL;
@@ -122,8 +120,6 @@ main (int argc, const char * const * argv)
	if (modePtr->argmax && argc - offset > modePtr->argmax)
	if (modePtr->argmax && argc - offset > modePtr->argmax)
		Usage(argv[0]);
		Usage(argv[0]);




	init_dialog();
	init_dialog();
	retval = (*(modePtr->jumper)) (title, argc - offset, argv + offset);
	retval = (*(modePtr->jumper)) (title, argc - offset, argv + offset);


@@ -139,8 +135,7 @@ main (int argc, const char * const * argv)
/*
/*
 * Print program usage
 * Print program usage
 */
 */
static void
static void Usage(const char *name)
Usage (const char *name)
{
{
	fprintf(stderr, "\
	fprintf(stderr, "\
\ndialog, by Savio Lam (lam836@cs.cuhk.hk).\
\ndialog, by Savio Lam (lam836@cs.cuhk.hk).\
@@ -169,41 +164,35 @@ Usage (const char *name)
 * These are the program jumpers
 * These are the program jumpers
 */
 */


int
int j_menu(const char *t, int ac, const char *const *av)
j_menu (const char *t, int ac, const char * const * av)
{
{
	return dialog_menu(t, av[2], atoi(av[3]), atoi(av[4]),
	return dialog_menu(t, av[2], atoi(av[3]), atoi(av[4]),
			   atoi(av[5]), av[6], (ac - 6) / 2, av + 7);
			   atoi(av[5]), av[6], (ac - 6) / 2, av + 7);
}
}


int
int j_checklist(const char *t, int ac, const char *const *av)
j_checklist (const char *t, int ac, const char * const * av)
{
{
	return dialog_checklist(t, av[2], atoi(av[3]), atoi(av[4]),
	return dialog_checklist(t, av[2], atoi(av[3]), atoi(av[4]),
				atoi(av[5]), (ac - 6) / 3, av + 6, FLAG_CHECK);
				atoi(av[5]), (ac - 6) / 3, av + 6, FLAG_CHECK);
}
}


int
int j_radiolist(const char *t, int ac, const char *const *av)
j_radiolist (const char *t, int ac, const char * const * av)
{
{
	return dialog_checklist(t, av[2], atoi(av[3]), atoi(av[4]),
	return dialog_checklist(t, av[2], atoi(av[3]), atoi(av[4]),
				atoi(av[5]), (ac - 6) / 3, av + 6, FLAG_RADIO);
				atoi(av[5]), (ac - 6) / 3, av + 6, FLAG_RADIO);
}
}


int
int j_textbox(const char *t, int ac, const char *const *av)
j_textbox (const char *t, int ac, const char * const * av)
{
{
	return dialog_textbox(t, av[2], atoi(av[3]), atoi(av[4]));
	return dialog_textbox(t, av[2], atoi(av[3]), atoi(av[4]));
}
}


int
int j_yesno(const char *t, int ac, const char *const *av)
j_yesno (const char *t, int ac, const char * const * av)
{
{
	return dialog_yesno(t, av[2], atoi(av[3]), atoi(av[4]));
	return dialog_yesno(t, av[2], atoi(av[3]), atoi(av[4]));
}
}


int
int j_inputbox(const char *t, int ac, const char *const *av)
j_inputbox (const char *t, int ac, const char * const * av)
{
{
	int ret = dialog_inputbox(t, av[2], atoi(av[3]), atoi(av[4]),
	int ret = dialog_inputbox(t, av[2], atoi(av[3]), atoi(av[4]),
				  ac == 6 ? av[5] : (char *)NULL);
				  ac == 6 ? av[5] : (char *)NULL);
@@ -212,15 +201,12 @@ j_inputbox (const char *t, int ac, const char * const * av)
	return ret;
	return ret;
}
}


int
int j_msgbox(const char *t, int ac, const char *const *av)
j_msgbox (const char *t, int ac, const char * const * av)
{
{
	return dialog_msgbox(t, av[2], atoi(av[3]), atoi(av[4]), 1);
	return dialog_msgbox(t, av[2], atoi(av[3]), atoi(av[4]), 1);
}
}


int
int j_infobox(const char *t, int ac, const char *const *av)
j_infobox (const char *t, int ac, const char * const * av)
{
{
	return dialog_msgbox(t, av[2], atoi(av[3]), atoi(av[4]), 0);
	return dialog_msgbox(t, av[2], atoi(av[3]), atoi(av[4]), 0);
}
}
Loading