Check-in [2e7a0cd380]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Initial commit
Timelines: family | ancestors | trunk
Files: files | file ages | folders
SHA1: 2e7a0cd380c76b2d364cb9debd07da9c9f4e6449
User & Date: bapt 2012-06-18 22:49:56
Context
2012-06-18
22:49
Initial commit Leaf check-in: 2e7a0cd380 user: bapt tags: trunk
19:34
initial empty check-in check-in: 11a2ceb630 user: bapt tags: trunk
Changes

Added Makefile.









>
>
>
>
1
2
3
4
PROG=	portdlg
LDADD=	-ldialog -lcursesw

.include <bsd.prog.mk>

Added portdlg.c.































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#include <sys/types.h>
#include <sys/queue.h>

#include <stdio.h>
#include <dialog.h>
#include <dlg_keys.h>

static TAILQ_HEAD(opt_list, opt) opt_head = TAILQ_HEAD_INITIALIZER(opt_head);
struct opt {
	char *opt;
	TAILQ_ENTRY(opt) next;
};

static void
print_options_item(WINDOW *options, struct opt *o, int item, int nscroll, int selected)
{
	chtype attr = A_NORMAL;
	char sizetext[16];
	int y = item - nscroll + 1;
	char optdesc[256];

	wattrset(options, selected ? item_selected_attr : item_attr);
	wmove(options, y, MARGIN + 2);
	if (selected) {
		dlg_print_text(options, "[*]", 5, &attr);
	} else {
		dlg_print_text(options, "[ ]", 5, &attr);
	}
	wmove(options, y, 7);
	dlg_print_text(options, o->opt, 10, &attr);
	snprintf(optdesc, sizeof(optdesc), "%s_DESC", o->opt);
	wmove(options, y, 10);
	if (getenv(optdesc) != NULL)
		dlg_print_text(options, getenv(optdesc), 50, &attr);
}

int
main(void)
{
	WINDOW *dialog, *options;
	int height, width, min_width;
	static DLG_KEYS_BINDING binding[] = {
		ENTERKEY_BINDINGS,
		DLG_KEYS_DATA( DLGK_ENTER,      ' ' ),
		DLG_KEYS_DATA( DLGK_ITEM_NEXT, KEY_DOWN ),
		DLG_KEYS_DATA( DLGK_ITEM_PREV, KEY_UP ),
		DLG_KEYS_DATA( DLGK_FIELD_NEXT, KEY_RIGHT ),
		DLG_KEYS_DATA( DLGK_FIELD_NEXT, TAB ),
		DLG_KEYS_DATA( DLGK_FIELD_PREV, KEY_BTAB ),
		DLG_KEYS_DATA( DLGK_FIELD_PREV, KEY_LEFT ),
		SCROLLKEY_BINDINGS,
		END_KEYS_BINDING
	};
	int cur_button = 0;
	int *selected = NULL;
	int cur_part = 0;
	int *nscroll = NULL;
	int cur_scroll = 0;
	const char *buttons[] =
	    { "Ok", "Cancel", NULL };

	char *options_define = strdup(getenv("OPTIONS_DEFINE"));
	int nitems = 0;
	char *next;
	char *buf = options_define;
	struct opt *o;


	while ((next = strchr(buf, ' ')) != NULL) {
		nitems++;
		o = malloc(sizeof(struct opt));
		o->opt = buf;
		TAILQ_INSERT_TAIL(&opt_head, o, next);
		buf = next;
		buf[0] = '\0';
		buf++;
	}

	min_width = 70;
	height = width = 0;
	init_dialog(stdin, stdout);
	dialog_vars.backtitle = __DECONST(char *, "Options for bla");
	dlg_put_backtitle();

	int options_list_height = 10;
	dlg_tab_correct_str("Options");
	dlg_button_layout(buttons, &min_width);
	dlg_auto_size("Options dialog", "kikoo", &height, &width, 2, min_width);
	height += options_list_height;
	int options_list_width = width - 2*MARGIN;
	dlg_print_size(height, width);
	dlg_ctl_size(height, width);

	int x = dlg_box_x_ordinate(width);
	int y = dlg_box_y_ordinate(height);

	dialog = dlg_new_window(height, width, y, x);
	dlg_register_window(dialog, "optionsbox", binding);
	dlg_register_buttons(dialog, "optionsbox", buttons);

	dlg_draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr);
	dlg_draw_bottom_box(dialog);
/*	dlg_draw_title(dialog, "title");*/
	wattrset(dialog, dialog_attr);

	options = dlg_sub_window(dialog, options_list_height, options_list_width,
	    y + 3, x + 1);
	dlg_register_window(options, "optionslist", binding);
	dlg_register_buttons(options, "optionsist", buttons);
	wattrset(options, menubox_attr);

	dlg_draw_buttons(dialog, height - 2*MARGIN, 0, buttons,
	    cur_button, FALSE, width);
	dlg_print_autowrap(dialog, "Options", height, width);

	if (selected != NULL)
		cur_part = *selected;
	if (nscroll != NULL)
		cur_scroll = *nscroll;
	if (cur_part - cur_scroll >= options_list_height - 2 ||
	    cur_part - cur_scroll < 0)
		cur_scroll = cur_part;

repaint:
	dlg_draw_box(dialog, 3, 1,  options_list_height, options_list_width,
	    menubox_border_attr, menubox_attr);
	int i = 0;
	TAILQ_FOREACH(o, &opt_head, next) {
		if (i < cur_scroll) {
			i++;
			continue;
		}
		if (i >= MIN(cur_scroll + options_list_height - 2, nitems))
				break;
		i++;
		print_options_item(options, o, i, cur_scroll, i == cur_part);
		wrefresh(options);
	}

	sleep(3);
	end_dialog();

}