Skip to content

Commit fb318e5

Browse files
committed
kconfig: menuconfig: reorder functions to remove forward declarations
Define helper functions before the callers so that forward declarations can go away. Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
1 parent b84e368 commit fb318e5

2 files changed

Lines changed: 277 additions & 295 deletions

File tree

scripts/kconfig/lxdialog/textbox.c

Lines changed: 125 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,136 @@
88

99
#include "dialog.h"
1010

11-
static void back_lines(int n);
12-
static void print_page(WINDOW *win, int height, int width, update_text_fn
13-
update_text, void *data);
14-
static void print_line(WINDOW *win, int row, int width);
15-
static char *get_line(void);
16-
static void print_position(WINDOW * win);
17-
1811
static int hscroll;
1912
static int begin_reached, end_reached, page_length;
2013
static char *buf;
2114
static char *page;
2215

16+
/*
17+
* Go back 'n' lines in text. Called by dialog_textbox().
18+
* 'page' will be updated to point to the desired line in 'buf'.
19+
*/
20+
static void back_lines(int n)
21+
{
22+
int i;
23+
24+
begin_reached = 0;
25+
/* Go back 'n' lines */
26+
for (i = 0; i < n; i++) {
27+
if (*page == '\0') {
28+
if (end_reached) {
29+
end_reached = 0;
30+
continue;
31+
}
32+
}
33+
if (page == buf) {
34+
begin_reached = 1;
35+
return;
36+
}
37+
page--;
38+
do {
39+
if (page == buf) {
40+
begin_reached = 1;
41+
return;
42+
}
43+
page--;
44+
} while (*page != '\n');
45+
page++;
46+
}
47+
}
48+
49+
/*
50+
* Return current line of text. Called by dialog_textbox() and print_line().
51+
* 'page' should point to start of current line before calling, and will be
52+
* updated to point to start of next line.
53+
*/
54+
static char *get_line(void)
55+
{
56+
int i = 0;
57+
static char line[MAX_LEN + 1];
58+
59+
end_reached = 0;
60+
while (*page != '\n') {
61+
if (*page == '\0') {
62+
end_reached = 1;
63+
break;
64+
} else if (i < MAX_LEN)
65+
line[i++] = *(page++);
66+
else {
67+
/* Truncate lines longer than MAX_LEN characters */
68+
if (i == MAX_LEN)
69+
line[i++] = '\0';
70+
page++;
71+
}
72+
}
73+
if (i <= MAX_LEN)
74+
line[i] = '\0';
75+
if (!end_reached)
76+
page++; /* move past '\n' */
77+
78+
return line;
79+
}
80+
81+
/*
82+
* Print a new line of text.
83+
*/
84+
static void print_line(WINDOW *win, int row, int width)
85+
{
86+
char *line;
87+
88+
line = get_line();
89+
line += MIN(strlen(line), hscroll); /* Scroll horizontally */
90+
wmove(win, row, 0); /* move cursor to correct line */
91+
waddch(win, ' ');
92+
waddnstr(win, line, MIN(strlen(line), width - 2));
93+
94+
/* Clear 'residue' of previous line */
95+
wclrtoeol(win);
96+
}
97+
98+
/*
99+
* Print a new page of text.
100+
*/
101+
static void print_page(WINDOW *win, int height, int width, update_text_fn
102+
update_text, void *data)
103+
{
104+
int i, passed_end = 0;
105+
106+
if (update_text) {
107+
char *end;
108+
109+
for (i = 0; i < height; i++)
110+
get_line();
111+
end = page;
112+
back_lines(height);
113+
update_text(buf, page - buf, end - buf, data);
114+
}
115+
116+
page_length = 0;
117+
for (i = 0; i < height; i++) {
118+
print_line(win, i, width);
119+
if (!passed_end)
120+
page_length++;
121+
if (end_reached && !passed_end)
122+
passed_end = 1;
123+
}
124+
wnoutrefresh(win);
125+
}
126+
127+
/*
128+
* Print current position
129+
*/
130+
static void print_position(WINDOW *win)
131+
{
132+
int percent;
133+
134+
wattrset(win, dlg.position_indicator.atr);
135+
wbkgdset(win, dlg.position_indicator.atr & A_COLOR);
136+
percent = (page - buf) * 100 / strlen(buf);
137+
wmove(win, getmaxy(win) - 3, getmaxx(win) - 9);
138+
wprintw(win, "(%3d%%)", percent);
139+
}
140+
23141
/*
24142
* refresh window content
25143
*/
@@ -33,7 +151,6 @@ static void refresh_text_box(WINDOW *dialog, WINDOW *box, int boxh, int boxw,
33151
wrefresh(dialog);
34152
}
35153

36-
37154
/*
38155
* Display text from a file in a dialog box.
39156
*
@@ -259,128 +376,3 @@ int dialog_textbox(const char *title, char *tbuf, int initial_height,
259376
*_hscroll = hscroll;
260377
return key;
261378
}
262-
263-
/*
264-
* Go back 'n' lines in text. Called by dialog_textbox().
265-
* 'page' will be updated to point to the desired line in 'buf'.
266-
*/
267-
static void back_lines(int n)
268-
{
269-
int i;
270-
271-
begin_reached = 0;
272-
/* Go back 'n' lines */
273-
for (i = 0; i < n; i++) {
274-
if (*page == '\0') {
275-
if (end_reached) {
276-
end_reached = 0;
277-
continue;
278-
}
279-
}
280-
if (page == buf) {
281-
begin_reached = 1;
282-
return;
283-
}
284-
page--;
285-
do {
286-
if (page == buf) {
287-
begin_reached = 1;
288-
return;
289-
}
290-
page--;
291-
} while (*page != '\n');
292-
page++;
293-
}
294-
}
295-
296-
/*
297-
* Print a new page of text.
298-
*/
299-
static void print_page(WINDOW *win, int height, int width, update_text_fn
300-
update_text, void *data)
301-
{
302-
int i, passed_end = 0;
303-
304-
if (update_text) {
305-
char *end;
306-
307-
for (i = 0; i < height; i++)
308-
get_line();
309-
end = page;
310-
back_lines(height);
311-
update_text(buf, page - buf, end - buf, data);
312-
}
313-
314-
page_length = 0;
315-
for (i = 0; i < height; i++) {
316-
print_line(win, i, width);
317-
if (!passed_end)
318-
page_length++;
319-
if (end_reached && !passed_end)
320-
passed_end = 1;
321-
}
322-
wnoutrefresh(win);
323-
}
324-
325-
/*
326-
* Print a new line of text.
327-
*/
328-
static void print_line(WINDOW * win, int row, int width)
329-
{
330-
char *line;
331-
332-
line = get_line();
333-
line += MIN(strlen(line), hscroll); /* Scroll horizontally */
334-
wmove(win, row, 0); /* move cursor to correct line */
335-
waddch(win, ' ');
336-
waddnstr(win, line, MIN(strlen(line), width - 2));
337-
338-
/* Clear 'residue' of previous line */
339-
wclrtoeol(win);
340-
}
341-
342-
/*
343-
* Return current line of text. Called by dialog_textbox() and print_line().
344-
* 'page' should point to start of current line before calling, and will be
345-
* updated to point to start of next line.
346-
*/
347-
static char *get_line(void)
348-
{
349-
int i = 0;
350-
static char line[MAX_LEN + 1];
351-
352-
end_reached = 0;
353-
while (*page != '\n') {
354-
if (*page == '\0') {
355-
end_reached = 1;
356-
break;
357-
} else if (i < MAX_LEN)
358-
line[i++] = *(page++);
359-
else {
360-
/* Truncate lines longer than MAX_LEN characters */
361-
if (i == MAX_LEN)
362-
line[i++] = '\0';
363-
page++;
364-
}
365-
}
366-
if (i <= MAX_LEN)
367-
line[i] = '\0';
368-
if (!end_reached)
369-
page++; /* move past '\n' */
370-
371-
return line;
372-
}
373-
374-
/*
375-
* Print current position
376-
*/
377-
static void print_position(WINDOW * win)
378-
{
379-
int percent;
380-
381-
wattrset(win, dlg.position_indicator.atr);
382-
wbkgdset(win, dlg.position_indicator.atr & A_COLOR);
383-
percent = (page - buf) * 100 / strlen(buf);
384-
wmove(win, getmaxy(win) - 3, getmaxx(win) - 9);
385-
wprintw(win, "(%3d%%)", percent);
386-
}

0 commit comments

Comments
 (0)