Blame view

scripts/kconfig/mconf.c 27.3 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
5
6
  /*
   * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
   * Released under the terms of the GNU GPL v2.0.
   *
   * Introduced single menu mode (show all sub-menus in one large tree).
   * 2002-11-06 Petr Baudis <pasky@ucw.cz>
3b9fa0931   Arnaldo Carvalho de Melo   [PATCH] Kconfig i...
7
8
   *
   * i18n, 2005, Arnaldo Carvalho de Melo <acme@conectiva.com.br>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
9
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
10
11
12
13
  #include <ctype.h>
  #include <errno.h>
  #include <fcntl.h>
  #include <limits.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
14
15
16
  #include <stdarg.h>
  #include <stdlib.h>
  #include <string.h>
564899f9f   Davidlohr Bueso   kconfig: handle S...
17
  #include <signal.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
18
  #include <unistd.h>
442ff7022   Jean-Christophe Dubois   [PATCH] mconf.c n...
19
  #include <locale.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
20

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
21
  #include "lkc.h"
2982de699   Sam Ravnborg   kconfig/menuconfi...
22
  #include "lxdialog/dialog.h"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
23

3b9fa0931   Arnaldo Carvalho de Melo   [PATCH] Kconfig i...
24
  static const char mconf_readme[] = N_(
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
25
26
27
28
  "Overview
  "
  "--------
  "
652cf9821   Arnaud Lacombe   kconfig: rephrase...
29
30
31
32
33
34
  "This interface let you select features and parameters for the build.
  "
  "Features can either be built-in, modularized, or ignored. Parameters
  "
  "must be entered in as decimal or hexadecimal numbers or text.
  "
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
35
36
  "
  "
b5d609dbf   Matej Laitl   kconfig/menuconfi...
37
38
39
40
41
42
43
44
45
46
47
48
49
50
  "Menu items beginning with following braces represent features that
  "
  "  [ ] can be built in or removed
  "
  "  < > can be built in, modularized or removed
  "
  "  { } can be built in or modularized (selected by other feature)
  "
  "  - - are selected by other feature,
  "
  "while *, M or whitespace inside braces means to build in, build as
  "
  "a module or to exclude the feature respectively.
  "
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
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
  "
  "
  "To change any of these features, highlight it with the cursor
  "
  "keys and press <Y> to build it in, <M> to make it a module or
  "
  "<N> to removed it.  You may also press the <Space Bar> to cycle
  "
  "through the available options (ie. Y->N->M->Y).
  "
  "
  "
  "Some additional keyboard hints:
  "
  "
  "
  "Menus
  "
  "----------
  "
  "o  Use the Up/Down arrow keys (cursor keys) to highlight the item
  "
  "   you wish to change or submenu wish to select and press <Enter>.
  "
  "   Submenus are designated by \"--->\".
  "
  "
  "
  "   Shortcut: Press the option's highlighted letter (hotkey).
  "
  "             Pressing a hotkey more than once will sequence
  "
  "             through all visible items which use that hotkey.
  "
  "
  "
  "   You may also use the <PAGE UP> and <PAGE DOWN> keys to scroll
  "
  "   unseen options into view.
  "
  "
  "
  "o  To exit a menu use the cursor keys to highlight the <Exit> button
  "
  "   and press <ENTER>.
  "
  "
  "
  "   Shortcut: Press <ESC><ESC> or <E> or <X> if there is no hotkey
  "
  "             using those letters.  You may press a single <ESC>, but
  "
  "             there is a delayed response which you may find annoying.
  "
  "
  "
  "   Also, the <TAB> and cursor keys will cycle between <Select>,
  "
22c7eca61   Li Zefan   menuconfig: add s...
109
110
  "   <Exit> and <Help>.
  "
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
111
112
113
114
  "
  "
  "o  To get help with an item, use the cursor keys to highlight <Help>
  "
22c7eca61   Li Zefan   menuconfig: add s...
115
116
  "   and press <ENTER>.
  "
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
117
118
119
120
121
122
  "
  "
  "   Shortcut: Press <H> or <?>.
  "
  "
  "
f9447c493   Li Zefan   menuconfig: impro...
123
124
  "o  To toggle the display of hidden options, press <Z>.
  "
22c7eca61   Li Zefan   menuconfig: add s...
125
126
  "
  "
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
  "
  "
  "Radiolists  (Choice lists)
  "
  "-----------
  "
  "o  Use the cursor keys to select the option you wish to set and press
  "
  "   <S> or the <SPACE BAR>.
  "
  "
  "
  "   Shortcut: Press the first letter of the option you wish to set then
  "
  "             press <S> or <SPACE BAR>.
  "
  "
  "
  "o  To see available help for the item, use the cursor keys to highlight
  "
  "   <Help> and Press <ENTER>.
  "
  "
  "
  "   Shortcut: Press <H> or <?>.
  "
  "
  "
  "   Also, the <TAB> and cursor keys will cycle between <Select> and
  "
  "   <Help>
  "
  "
  "
  "
  "
  "Data Entry
  "
  "-----------
  "
  "o  Enter the requested information and press <ENTER>
  "
  "   If you are entering hexadecimal values, it is not necessary to
  "
  "   add the '0x' prefix to the entry.
  "
  "
  "
  "o  For help, use the <TAB> or cursor keys to highlight the help option
  "
  "   and press <ENTER>.  You can try <TAB><H> as well.
  "
  "
  "
  "
  "
  "Text Box    (Help Window)
  "
  "--------
  "
  "o  Use the cursor keys to scroll up/down/left/right.  The VI editor
  "
9d4792c9b   Benjamin Poirier   menuconfig: add u...
189
190
191
192
  "   keys h,j,k,l function here as do <u>, <d>, <SPACE BAR> and <B> for 
  "
  "   those who are familiar with less and lynx.
  "
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
193
194
  "
  "
9d4792c9b   Benjamin Poirier   menuconfig: add u...
195
196
  "o  Press <E>, <X>, <q>, <Enter> or <Esc><Esc> to exit.
  "
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
197
198
199
200
201
202
203
204
205
206
207
208
  "
  "
  "
  "
  "Alternate Configuration Files
  "
  "-----------------------------
  "
  "Menuconfig supports the use of alternate configuration files for
  "
  "those who, for various reasons, find it necessary to switch
  "
652cf9821   Arnaud Lacombe   kconfig: rephrase...
209
210
  "between different configurations.
  "
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
  "
  "
  "At the end of the main menu you will find two options.  One is
  "
  "for saving the current configuration to a file of your choosing.
  "
  "The other option is for loading a previously saved alternate
  "
  "configuration.
  "
  "
  "
  "Even if you don't use alternate configuration files, but you
  "
  "find during a Menuconfig session that you have completely messed
  "
  "up your settings, you may use the \"Load Alternate...\" option to
  "
  "restore your previously saved settings from \".config\" without
  "
  "restarting Menuconfig.
  "
  "
  "
  "Other information
  "
  "-----------------
  "
  "If you use Menuconfig in an XTERM window make sure you have your
  "
  "$TERM variable set to point to a xterm definition which supports color.
  "
  "Otherwise, Menuconfig will look rather bad.  Menuconfig will not
  "
  "display correctly in a RXVT window because rxvt displays only one
  "
  "intensity of color, bright.
  "
  "
  "
  "Menuconfig will display larger menus on screens or xterms which are
  "
  "set to display more than the standard 25 row by 80 column geometry.
  "
  "In order for this to work, the \"stty size\" command must be able to
  "
  "display the screen's current row and column geometry.  I STRONGLY
  "
  "RECOMMEND that you make sure you do NOT have the shell variables
  "
  "LINES and COLUMNS exported into your environment.  Some distributions
  "
  "export those variables via /etc/profile.  Some ncurses programs can
  "
  "become confused when those variables (LINES & COLUMNS) don't reflect
  "
  "the true screen size.
  "
  "
  "
  "Optional personality available
  "
  "------------------------------
  "
652cf9821   Arnaud Lacombe   kconfig: rephrase...
275
276
277
278
279
280
  "If you prefer to have all of the options listed in a single menu, rather
  "
  "than the default multimenu hierarchy, run the menuconfig with
  "
  "MENUCONFIG_MODE environment variable set to single_menu. Example:
  "
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
  "
  "
  "make MENUCONFIG_MODE=single_menu menuconfig
  "
  "
  "
  "<Enter> will then unroll the appropriate category, or enfold it if it
  "
  "is already unrolled.
  "
  "
  "
  "Note that this mode can eventually be a little more CPU expensive
  "
  "(especially with a larger number of unrolled categories) than the
  "
458972132   Sam Ravnborg   kconfig/lxdialog:...
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
  "default mode.
  "
  "
  "
  "Different color themes available
  "
  "--------------------------------
  "
  "It is possible to select different color themes using the variable
  "
  "MENUCONFIG_COLOR. To select a theme use:
  "
  "
  "
  "make MENUCONFIG_COLOR=<theme> menuconfig
  "
  "
  "
  "Available themes are
  "
  " mono       => selects colors suitable for monochrome displays
  "
  " blackbg    => selects a color scheme with black background
  "
350b5b763   Sam Ravnborg   kconfig/lxdialog:...
321
322
323
324
  " classic    => theme with blue background. The classic look
  "
  " bluetitle  => a LCD friendly version of classic. (default)
  "
458972132   Sam Ravnborg   kconfig/lxdialog:...
325
326
  "
  "),
3b9fa0931   Arnaldo Carvalho de Melo   [PATCH] Kconfig i...
327
  menu_instructions[] = N_(
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
328
329
330
331
332
  	"Arrow keys navigate the menu.  "
  	"<Enter> selects submenus --->.  "
  	"Highlighted letters are hotkeys.  "
  	"Pressing <Y> includes, <N> excludes, <M> modularizes features.  "
  	"Press <Esc><Esc> to exit, <?> for Help, </> for Search.  "
3b9fa0931   Arnaldo Carvalho de Melo   [PATCH] Kconfig i...
333
334
  	"Legend: [*] built-in  [ ] excluded  <M> module  < > module capable"),
  radiolist_instructions[] = N_(
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
335
336
337
  	"Use the arrow keys to navigate this window or "
  	"press the hotkey of the item you wish to select "
  	"followed by the <SPACE BAR>. "
3b9fa0931   Arnaldo Carvalho de Melo   [PATCH] Kconfig i...
338
339
  	"Press <?> for additional information about this option."),
  inputbox_instructions_int[] = N_(
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
340
341
  	"Please enter a decimal value. "
  	"Fractions will not be accepted.  "
3b9fa0931   Arnaldo Carvalho de Melo   [PATCH] Kconfig i...
342
343
  	"Use the <TAB> key to move from the input field to the buttons below it."),
  inputbox_instructions_hex[] = N_(
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
344
  	"Please enter a hexadecimal value. "
3b9fa0931   Arnaldo Carvalho de Melo   [PATCH] Kconfig i...
345
346
  	"Use the <TAB> key to move from the input field to the buttons below it."),
  inputbox_instructions_string[] = N_(
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
347
  	"Please enter a string value. "
3b9fa0931   Arnaldo Carvalho de Melo   [PATCH] Kconfig i...
348
349
  	"Use the <TAB> key to move from the input field to the buttons below it."),
  setmod_text[] = N_(
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
350
351
  	"This feature depends on another which has been configured as a module.
  "
3b9fa0931   Arnaldo Carvalho de Melo   [PATCH] Kconfig i...
352
  	"As a result, this feature will be built as a module."),
3b9fa0931   Arnaldo Carvalho de Melo   [PATCH] Kconfig i...
353
  load_config_text[] = N_(
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
354
355
  	"Enter the name of the configuration file you wish to load.  "
  	"Accept the name shown to restore the configuration you "
3b9fa0931   Arnaldo Carvalho de Melo   [PATCH] Kconfig i...
356
357
  	"last retrieved.  Leave blank to abort."),
  load_config_help[] = N_(
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
358
359
  	"
  "
652cf9821   Arnaud Lacombe   kconfig: rephrase...
360
361
  	"For various reasons, one may wish to keep several different
  "
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
362
363
364
365
366
367
  	"configurations available on a single machine.
  "
  	"
  "
  	"If you have saved a previous configuration in a file other than the
  "
652cf9821   Arnaud Lacombe   kconfig: rephrase...
368
369
370
371
  	"default one, entering its name here will allow you to modify that
  "
  	"configuration.
  "
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
372
373
374
375
  	"
  "
  	"If you are uncertain, then you have probably never used alternate
  "
af901ca18   AndrĂ© Goddard Rosa   tree-wide: fix as...
376
377
  	"configuration files. You should therefore leave this blank to abort.
  "),
3b9fa0931   Arnaldo Carvalho de Melo   [PATCH] Kconfig i...
378
  save_config_text[] = N_(
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
379
  	"Enter a filename to which this configuration should be saved "
3b9fa0931   Arnaldo Carvalho de Melo   [PATCH] Kconfig i...
380
381
  	"as an alternate.  Leave blank to abort."),
  save_config_help[] = N_(
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
382
383
  	"
  "
652cf9821   Arnaud Lacombe   kconfig: rephrase...
384
385
386
387
  	"For various reasons, one may wish to keep different configurations
  "
  	"available on a single machine.
  "
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
388
389
390
391
392
393
394
395
396
397
398
399
  	"
  "
  	"Entering a file name here will allow you to later retrieve, modify
  "
  	"and use the current configuration as an alternate to whatever
  "
  	"configuration options you have selected at that time.
  "
  	"
  "
  	"If you are uncertain what all this means then you should probably
  "
3b9fa0931   Arnaldo Carvalho de Melo   [PATCH] Kconfig i...
400
401
402
  	"leave this blank.
  "),
  search_help[] = N_(
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
403
404
  	"
  "
59dfa24da   Arnaud Lacombe   kconfig: rephrase...
405
406
  	"Search for symbols and display their relations.
  "
503af334e   Randy Dunlap   [PATCH] clarify m...
407
408
  	"Regular expressions are allowed.
  "
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
409
410
411
412
413
414
415
416
  	"Example: search for \"^FOO\"
  "
  	"Result:
  "
  	"-----------------------------------------------------------------
  "
  	"Symbol: FOO [=m]
  "
5e609addb   Benjamin Poirier   menuconfig: Add j...
417
418
  	"Type  : tristate
  "
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
419
420
  	"Prompt: Foo bus is used to drive the bar HW
  "
5e609addb   Benjamin Poirier   menuconfig: Add j...
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
  	"  Defined at drivers/pci/Kconfig:47
  "
  	"  Depends on: X86_LOCAL_APIC && X86_IO_APIC || IA64
  "
  	"  Location:
  "
  	"    -> Bus options (PCI, PCMCIA, EISA, ISA)
  "
  	"      -> PCI support (PCI [=y])
  "
  	"(1)     -> PCI access mode (<choice> [=y])
  "
  	"  Selects: LIBCRC32
  "
  	"  Selected by: BAR
  "
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
437
438
  	"-----------------------------------------------------------------
  "
5e609addb   Benjamin Poirier   menuconfig: Add j...
439
440
441
442
  	"o The line 'Type:' shows the type of the configuration option for
  "
  	"  this symbol (boolean, tristate, string, ...)
  "
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
443
444
  	"o The line 'Prompt:' shows the text used in the menu structure for
  "
59dfa24da   Arnaud Lacombe   kconfig: rephrase...
445
446
  	"  this symbol
  "
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
447
448
449
450
451
452
453
454
455
456
457
458
  	"o The 'Defined at' line tell at what file / line number the symbol
  "
  	"  is defined
  "
  	"o The 'Depends on:' line tell what symbols needs to be defined for
  "
  	"  this symbol to be visible in the menu (selectable)
  "
  	"o The 'Location:' lines tell where in the menu structure this symbol
  "
  	"  is located
  "
5e609addb   Benjamin Poirier   menuconfig: Add j...
459
460
461
462
463
464
465
466
467
468
469
470
  	"    A location followed by a [=y] indicates that this is a
  "
  	"    selectable menu item - and the current value is displayed inside
  "
  	"    brackets.
  "
  	"    Press the key in the (#) prefix to jump directly to that
  "
  	"    location. You will be returned to the current search results
  "
  	"    after exiting this new menu.
  "
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
  	"o The 'Selects:' line tell what symbol will be automatically
  "
  	"  selected if this symbol is selected (y or m)
  "
  	"o The 'Selected by' line tell what symbol has selected this symbol
  "
  	"
  "
  	"Only relevant lines are shown.
  "
  	"
  
  "
  	"Search examples:
  "
59dfa24da   Arnaud Lacombe   kconfig: rephrase...
486
487
488
489
490
491
  	"Examples: USB	=> find all symbols containing USB
  "
  	"          ^USB => find all symbols starting with USB
  "
  	"          USB$ => find all symbols ending with USB
  "
3b9fa0931   Arnaldo Carvalho de Melo   [PATCH] Kconfig i...
492
493
  	"
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
494

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
495
  static int indent;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
496
497
  static struct menu *current_menu;
  static int child_count;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
498
  static int single_menu_mode;
22c7eca61   Li Zefan   menuconfig: add s...
499
  static int show_all_options;
6364fd0cb   Wang YanQing   menuconfig: Add S...
500
  static int save_and_exit;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
501

5e609addb   Benjamin Poirier   menuconfig: Add j...
502
  static void conf(struct menu *menu, struct menu *active_menu);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
503
504
505
506
  static void conf_choice(struct menu *menu);
  static void conf_string(struct menu *menu);
  static void conf_load(void);
  static void conf_save(void);
95ac9b3b5   Benjamin Poirier   menuconfig: Assig...
507
508
509
  static int show_textbox_ext(const char *title, char *text, int r, int c,
  			    int *keys, int *vscroll, int *hscroll,
  			    update_text_fn update_text, void *data);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
510
511
512
  static void show_textbox(const char *title, const char *text, int r, int c);
  static void show_helptext(const char *title, const char *text);
  static void show_help(struct menu *menu);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
513

95e30f959   Sam Ravnborg   menuconfig: remem...
514
515
516
517
518
  static char filename[PATH_MAX+1];
  static void set_config_filename(const char *config_filename)
  {
  	static char menu_backtitle[PATH_MAX+128];
  	int size;
95e30f959   Sam Ravnborg   menuconfig: remem...
519

95e30f959   Sam Ravnborg   menuconfig: remem...
520
  	size = snprintf(menu_backtitle, sizeof(menu_backtitle),
0954828fc   Arnaud Lacombe   kconfig: replace ...
521
  	                "%s - %s", config_filename, rootmenu.prompt->text);
95e30f959   Sam Ravnborg   menuconfig: remem...
522
523
524
525
526
527
528
529
  	if (size >= sizeof(menu_backtitle))
  		menu_backtitle[sizeof(menu_backtitle)-1] = '\0';
  	set_dialog_backtitle(menu_backtitle);
  
  	size = snprintf(filename, sizeof(filename), "%s", config_filename);
  	if (size >= sizeof(filename))
  		filename[sizeof(filename)-1] = '\0';
  }
9a69abf80   Benjamin Poirier   menuconfig: Add "...
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
  struct subtitle_part {
  	struct list_head entries;
  	const char *text;
  };
  static LIST_HEAD(trail);
  
  static struct subtitle_list *subtitles;
  static void set_subtitle(void)
  {
  	struct subtitle_part *sp;
  	struct subtitle_list *pos, *tmp;
  
  	for (pos = subtitles; pos != NULL; pos = tmp) {
  		tmp = pos->next;
  		free(pos);
  	}
  
  	subtitles = NULL;
  	list_for_each_entry(sp, &trail, entries) {
  		if (sp->text) {
  			if (pos) {
  				pos->next = xcalloc(sizeof(*pos), 1);
  				pos = pos->next;
  			} else {
  				subtitles = pos = xcalloc(sizeof(*pos), 1);
  			}
  			pos->text = sp->text;
  		}
  	}
  
  	set_dialog_subtitles(subtitles);
  }
  
  static void reset_subtitle(void)
  {
  	struct subtitle_list *pos, *tmp;
  
  	for (pos = subtitles; pos != NULL; pos = tmp) {
  		tmp = pos->next;
  		free(pos);
  	}
  	subtitles = NULL;
  	set_dialog_subtitles(subtitles);
  }
95e30f959   Sam Ravnborg   menuconfig: remem...
574

95ac9b3b5   Benjamin Poirier   menuconfig: Assig...
575
  struct search_data {
bad9955db   Benjamin Poirier   menuconfig: Repla...
576
  	struct list_head *head;
95ac9b3b5   Benjamin Poirier   menuconfig: Assig...
577
578
579
580
581
582
583
584
585
  	struct menu **targets;
  	int *keys;
  };
  
  static void update_text(char *buf, size_t start, size_t end, void *_data)
  {
  	struct search_data *data = _data;
  	struct jump_key *pos;
  	int k = 0;
bad9955db   Benjamin Poirier   menuconfig: Repla...
586
  	list_for_each_entry(pos, data->head, entries) {
95ac9b3b5   Benjamin Poirier   menuconfig: Assig...
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
  		if (pos->offset >= start && pos->offset < end) {
  			char header[4];
  
  			if (k < JUMP_NB) {
  				int key = '0' + (pos->index % JUMP_NB) + 1;
  
  				sprintf(header, "(%c)", key);
  				data->keys[k] = key;
  				data->targets[k] = pos->target;
  				k++;
  			} else {
  				sprintf(header, "   ");
  			}
  
  			memcpy(buf + pos->offset, header, sizeof(header) - 1);
  		}
  	}
  	data->keys[k] = 0;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
606
607
608
  static void search_conf(void)
  {
  	struct symbol **sym_arr;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
609
  	struct gstr res;
337a275d0   Yann E. MORIN   kconfig: remove C...
610
  	struct gstr title;
0584f9f9c   Bernhard Walle   kconfig: strip 'C...
611
  	char *dialog_input;
5e609addb   Benjamin Poirier   menuconfig: Add j...
612
613
  	int dres, vscroll = 0, hscroll = 0;
  	bool again;
9a69abf80   Benjamin Poirier   menuconfig: Add "...
614
615
  	struct gstr sttext;
  	struct subtitle_part stpart;
5e609addb   Benjamin Poirier   menuconfig: Add j...
616

337a275d0   Yann E. MORIN   kconfig: remove C...
617
618
619
  	title = str_new();
  	str_printf( &title, _("Enter %s (sub)string to search for "
  			      "(with or without \"%s\")"), CONFIG_, CONFIG_);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
620
  again:
e94c5bde7   Sam Ravnborg   kconfig/menuconfi...
621
  	dialog_clear();
2982de699   Sam Ravnborg   kconfig/menuconfi...
622
  	dres = dialog_inputbox(_("Search Configuration Parameter"),
337a275d0   Yann E. MORIN   kconfig: remove C...
623
  			      str_get(&title),
2982de699   Sam Ravnborg   kconfig/menuconfi...
624
625
  			      10, 75, "");
  	switch (dres) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
626
627
628
  	case 0:
  		break;
  	case 1:
3b9fa0931   Arnaldo Carvalho de Melo   [PATCH] Kconfig i...
629
  		show_helptext(_("Search Configuration"), search_help);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
630
631
  		goto again;
  	default:
337a275d0   Yann E. MORIN   kconfig: remove C...
632
  		str_free(&title);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
633
634
  		return;
  	}
ffb5957bc   Arnaud Lacombe   kconfig: allow bu...
635
  	/* strip the prefix if necessary */
0584f9f9c   Bernhard Walle   kconfig: strip 'C...
636
  	dialog_input = dialog_input_result;
ffb5957bc   Arnaud Lacombe   kconfig: allow bu...
637
638
  	if (strncasecmp(dialog_input_result, CONFIG_, strlen(CONFIG_)) == 0)
  		dialog_input += strlen(CONFIG_);
0584f9f9c   Bernhard Walle   kconfig: strip 'C...
639

9a69abf80   Benjamin Poirier   menuconfig: Add "...
640
641
642
643
  	sttext = str_new();
  	str_printf(&sttext, "Search (%s)", dialog_input_result);
  	stpart.text = str_get(&sttext);
  	list_add_tail(&stpart.entries, &trail);
0584f9f9c   Bernhard Walle   kconfig: strip 'C...
644
  	sym_arr = sym_re_search(dialog_input);
5e609addb   Benjamin Poirier   menuconfig: Add j...
645
  	do {
bad9955db   Benjamin Poirier   menuconfig: Repla...
646
  		LIST_HEAD(head);
95ac9b3b5   Benjamin Poirier   menuconfig: Assig...
647
648
649
650
651
652
653
  		struct menu *targets[JUMP_NB];
  		int keys[JUMP_NB + 1], i;
  		struct search_data data = {
  			.head = &head,
  			.targets = targets,
  			.keys = keys,
  		};
edb749f43   Benjamin Poirier   menuconfig: Fix m...
654
  		struct jump_key *pos, *tmp;
95ac9b3b5   Benjamin Poirier   menuconfig: Assig...
655
656
  
  		res = get_relations_str(sym_arr, &head);
9a69abf80   Benjamin Poirier   menuconfig: Add "...
657
  		set_subtitle();
95ac9b3b5   Benjamin Poirier   menuconfig: Assig...
658
659
660
661
  		dres = show_textbox_ext(_("Search Results"), (char *)
  					str_get(&res), 0, 0, keys, &vscroll,
  					&hscroll, &update_text, (void *)
  					&data);
5e609addb   Benjamin Poirier   menuconfig: Add j...
662
  		again = false;
95ac9b3b5   Benjamin Poirier   menuconfig: Assig...
663
  		for (i = 0; i < JUMP_NB && keys[i]; i++)
5e609addb   Benjamin Poirier   menuconfig: Add j...
664
  			if (dres == keys[i]) {
95ac9b3b5   Benjamin Poirier   menuconfig: Assig...
665
  				conf(targets[i]->parent, targets[i]);
5e609addb   Benjamin Poirier   menuconfig: Add j...
666
667
668
  				again = true;
  			}
  		str_free(&res);
edb749f43   Benjamin Poirier   menuconfig: Fix m...
669
670
  		list_for_each_entry_safe(pos, tmp, &head, entries)
  			free(pos);
5e609addb   Benjamin Poirier   menuconfig: Add j...
671
  	} while (again);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
672
  	free(sym_arr);
337a275d0   Yann E. MORIN   kconfig: remove C...
673
  	str_free(&title);
9a69abf80   Benjamin Poirier   menuconfig: Add "...
674
675
  	list_del(trail.prev);
  	str_free(&sttext);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
676
677
678
679
680
681
682
683
684
685
  }
  
  static void build_conf(struct menu *menu)
  {
  	struct symbol *sym;
  	struct property *prop;
  	struct menu *child;
  	int type, tmp, doint = 2;
  	tristate val;
  	char ch;
22c7eca61   Li Zefan   menuconfig: add s...
686
687
688
689
690
691
692
693
694
695
  	bool visible;
  
  	/*
  	 * note: menu_is_visible() has side effect that it will
  	 * recalc the value of the symbol.
  	 */
  	visible = menu_is_visible(menu);
  	if (show_all_options && !menu_has_prompt(menu))
  		return;
  	else if (!show_all_options && !visible)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
696
697
698
699
700
701
702
703
704
705
  		return;
  
  	sym = menu->sym;
  	prop = menu->prompt;
  	if (!sym) {
  		if (prop && menu != current_menu) {
  			const char *prompt = menu_get_prompt(menu);
  			switch (prop->type) {
  			case P_MENU:
  				child_count++;
413f006ba   EGRY Gabor   kconfig: gettext ...
706
  				prompt = _(prompt);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
707
  				if (single_menu_mode) {
2982de699   Sam Ravnborg   kconfig/menuconfi...
708
709
710
  					item_make("%s%*c%s",
  						  menu->data ? "-->" : "++>",
  						  indent + 1, ' ', prompt);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
711
  				} else
2982de699   Sam Ravnborg   kconfig/menuconfi...
712
  					item_make("   %*c%s  --->", indent + 1, ' ', prompt);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
713

2982de699   Sam Ravnborg   kconfig/menuconfi...
714
715
  				item_set_tag('m');
  				item_set_data(menu);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
716
717
718
  				if (single_menu_mode && menu->data)
  					goto conf_childs;
  				return;
48874077d   Sam Ravnborg   kconfig: make com...
719
720
721
  			case P_COMMENT:
  				if (prompt) {
  					child_count++;
413f006ba   EGRY Gabor   kconfig: gettext ...
722
  					item_make("   %*c*** %s ***", indent + 1, ' ', _(prompt));
48874077d   Sam Ravnborg   kconfig: make com...
723
724
725
726
  					item_set_tag(':');
  					item_set_data(menu);
  				}
  				break;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
727
728
729
  			default:
  				if (prompt) {
  					child_count++;
413f006ba   EGRY Gabor   kconfig: gettext ...
730
  					item_make("---%*c%s", indent + 1, ' ', _(prompt));
2982de699   Sam Ravnborg   kconfig/menuconfi...
731
732
  					item_set_tag(':');
  					item_set_data(menu);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
  				}
  			}
  		} else
  			doint = 0;
  		goto conf_childs;
  	}
  
  	type = sym_get_type(sym);
  	if (sym_is_choice(sym)) {
  		struct symbol *def_sym = sym_get_choice_value(sym);
  		struct menu *def_menu = NULL;
  
  		child_count++;
  		for (child = menu->list; child; child = child->next) {
  			if (menu_is_visible(child) && child->sym == def_sym)
  				def_menu = child;
  		}
  
  		val = sym_get_tristate_value(sym);
  		if (sym_is_changable(sym)) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
753
754
  			switch (type) {
  			case S_BOOLEAN:
2982de699   Sam Ravnborg   kconfig/menuconfi...
755
  				item_make("[%c]", val == no ? ' ' : '*');
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
756
757
758
759
760
761
762
  				break;
  			case S_TRISTATE:
  				switch (val) {
  				case yes: ch = '*'; break;
  				case mod: ch = 'M'; break;
  				default:  ch = ' '; break;
  				}
2982de699   Sam Ravnborg   kconfig/menuconfi...
763
  				item_make("<%c>", ch);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
764
765
  				break;
  			}
2982de699   Sam Ravnborg   kconfig/menuconfi...
766
767
  			item_set_tag('t');
  			item_set_data(menu);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
768
  		} else {
2982de699   Sam Ravnborg   kconfig/menuconfi...
769
770
771
  			item_make("   ");
  			item_set_tag(def_menu ? 't' : ':');
  			item_set_data(menu);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
772
  		}
413f006ba   EGRY Gabor   kconfig: gettext ...
773
  		item_add_str("%*c%s", indent + 1, ' ', _(menu_get_prompt(menu)));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
774
775
  		if (val == yes) {
  			if (def_menu) {
413f006ba   EGRY Gabor   kconfig: gettext ...
776
  				item_add_str(" (%s)", _(menu_get_prompt(def_menu)));
2982de699   Sam Ravnborg   kconfig/menuconfi...
777
  				item_add_str("  --->");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
778
779
780
781
782
  				if (def_menu->list) {
  					indent += 2;
  					build_conf(def_menu);
  					indent -= 2;
  				}
2982de699   Sam Ravnborg   kconfig/menuconfi...
783
  			}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
784
785
  			return;
  		}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
786
787
  	} else {
  		if (menu == current_menu) {
413f006ba   EGRY Gabor   kconfig: gettext ...
788
  			item_make("---%*c%s", indent + 1, ' ', _(menu_get_prompt(menu)));
2982de699   Sam Ravnborg   kconfig/menuconfi...
789
790
  			item_set_tag(':');
  			item_set_data(menu);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
791
792
793
794
795
  			goto conf_childs;
  		}
  		child_count++;
  		val = sym_get_tristate_value(sym);
  		if (sym_is_choice_value(sym) && val == yes) {
2982de699   Sam Ravnborg   kconfig/menuconfi...
796
797
798
  			item_make("   ");
  			item_set_tag(':');
  			item_set_data(menu);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
799
800
801
  		} else {
  			switch (type) {
  			case S_BOOLEAN:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
802
  				if (sym_is_changable(sym))
2982de699   Sam Ravnborg   kconfig/menuconfi...
803
  					item_make("[%c]", val == no ? ' ' : '*');
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
804
  				else
b5d609dbf   Matej Laitl   kconfig/menuconfi...
805
  					item_make("-%c-", val == no ? ' ' : '*');
2982de699   Sam Ravnborg   kconfig/menuconfi...
806
807
  				item_set_tag('t');
  				item_set_data(menu);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
808
809
  				break;
  			case S_TRISTATE:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
810
811
812
813
814
  				switch (val) {
  				case yes: ch = '*'; break;
  				case mod: ch = 'M'; break;
  				default:  ch = ' '; break;
  				}
b5d609dbf   Matej Laitl   kconfig/menuconfi...
815
816
817
818
819
820
821
  				if (sym_is_changable(sym)) {
  					if (sym->rev_dep.tri == mod)
  						item_make("{%c}", ch);
  					else
  						item_make("<%c>", ch);
  				} else
  					item_make("-%c-", ch);
2982de699   Sam Ravnborg   kconfig/menuconfi...
822
823
  				item_set_tag('t');
  				item_set_data(menu);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
824
825
  				break;
  			default:
2982de699   Sam Ravnborg   kconfig/menuconfi...
826
827
  				tmp = 2 + strlen(sym_get_string_value(sym)); /* () = 2 */
  				item_make("(%s)", sym_get_string_value(sym));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
828
829
830
  				tmp = indent - tmp + 4;
  				if (tmp < 0)
  					tmp = 0;
413f006ba   EGRY Gabor   kconfig: gettext ...
831
  				item_add_str("%*c%s%s", tmp, ' ', _(menu_get_prompt(menu)),
2982de699   Sam Ravnborg   kconfig/menuconfi...
832
  					     (sym_has_value(sym) || !sym_is_changable(sym)) ?
413f006ba   EGRY Gabor   kconfig: gettext ...
833
  					     "" : _(" (NEW)"));
2982de699   Sam Ravnborg   kconfig/menuconfi...
834
835
  				item_set_tag('s');
  				item_set_data(menu);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
836
837
838
  				goto conf_childs;
  			}
  		}
413f006ba   EGRY Gabor   kconfig: gettext ...
839
  		item_add_str("%*c%s%s", indent + 1, ' ', _(menu_get_prompt(menu)),
2982de699   Sam Ravnborg   kconfig/menuconfi...
840
  			  (sym_has_value(sym) || !sym_is_changable(sym)) ?
413f006ba   EGRY Gabor   kconfig: gettext ...
841
  			  "" : _(" (NEW)"));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
842
  		if (menu->prompt->type == P_MENU) {
2982de699   Sam Ravnborg   kconfig/menuconfi...
843
  			item_add_str("  --->");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
844
845
  			return;
  		}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
846
847
848
849
850
851
852
853
  	}
  
  conf_childs:
  	indent += doint;
  	for (child = menu->list; child; child = child->next)
  		build_conf(child);
  	indent -= doint;
  }
5e609addb   Benjamin Poirier   menuconfig: Add j...
854
  static void conf(struct menu *menu, struct menu *active_menu)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
855
856
857
  {
  	struct menu *submenu;
  	const char *prompt = menu_get_prompt(menu);
9a69abf80   Benjamin Poirier   menuconfig: Add "...
858
  	struct subtitle_part stpart;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
859
  	struct symbol *sym;
2982de699   Sam Ravnborg   kconfig/menuconfi...
860
861
  	int res;
  	int s_scroll = 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
862

9a69abf80   Benjamin Poirier   menuconfig: Add "...
863
864
865
866
867
  	if (menu != &rootmenu)
  		stpart.text = menu_get_prompt(menu);
  	else
  		stpart.text = NULL;
  	list_add_tail(&stpart.entries, &trail);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
868
  	while (1) {
2982de699   Sam Ravnborg   kconfig/menuconfi...
869
  		item_reset();
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
870
871
872
873
  		current_menu = menu;
  		build_conf(menu);
  		if (!child_count)
  			break;
9a69abf80   Benjamin Poirier   menuconfig: Add "...
874
  		set_subtitle();
e94c5bde7   Sam Ravnborg   kconfig/menuconfi...
875
  		dialog_clear();
413f006ba   EGRY Gabor   kconfig: gettext ...
876
  		res = dialog_menu(prompt ? _(prompt) : _("Main Menu"),
2982de699   Sam Ravnborg   kconfig/menuconfi...
877
  				  _(menu_instructions),
2982de699   Sam Ravnborg   kconfig/menuconfi...
878
  				  active_menu, &s_scroll);
c8dc68ad0   Sam Ravnborg   kconfig/lxdialog:...
879
  		if (res == 1 || res == KEY_ESC || res == -ERRDISPLAYTOOSMALL)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
880
  			break;
063f4661f   Dirk Gouders   mconf: handle key...
881
882
883
884
885
886
  		if (item_count() != 0) {
  			if (!item_activate_selected())
  				continue;
  			if (!item_tag())
  				continue;
  		}
2982de699   Sam Ravnborg   kconfig/menuconfi...
887
888
  		submenu = item_data();
  		active_menu = item_data();
c8dc68ad0   Sam Ravnborg   kconfig/lxdialog:...
889
890
891
892
  		if (submenu)
  			sym = submenu->sym;
  		else
  			sym = NULL;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
893

2982de699   Sam Ravnborg   kconfig/menuconfi...
894
  		switch (res) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
895
  		case 0:
2982de699   Sam Ravnborg   kconfig/menuconfi...
896
  			switch (item_tag()) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
897
898
899
900
  			case 'm':
  				if (single_menu_mode)
  					submenu->data = (void *) (long) !submenu->data;
  				else
5e609addb   Benjamin Poirier   menuconfig: Add j...
901
  					conf(submenu, NULL);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
902
903
904
905
906
  				break;
  			case 't':
  				if (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)
  					conf_choice(submenu);
  				else if (submenu->prompt->type == P_MENU)
5e609addb   Benjamin Poirier   menuconfig: Add j...
907
  					conf(submenu, NULL);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
908
909
910
911
  				break;
  			case 's':
  				conf_string(submenu);
  				break;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
912
913
914
915
916
  			}
  			break;
  		case 2:
  			if (sym)
  				show_help(submenu);
9a69abf80   Benjamin Poirier   menuconfig: Add "...
917
918
  			else {
  				reset_subtitle();
413f006ba   EGRY Gabor   kconfig: gettext ...
919
  				show_helptext(_("README"), _(mconf_readme));
9a69abf80   Benjamin Poirier   menuconfig: Add "...
920
  			}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
921
922
  			break;
  		case 3:
9a69abf80   Benjamin Poirier   menuconfig: Add "...
923
  			reset_subtitle();
6364fd0cb   Wang YanQing   menuconfig: Add S...
924
925
926
  			conf_save();
  			break;
  		case 4:
9a69abf80   Benjamin Poirier   menuconfig: Add "...
927
  			reset_subtitle();
6364fd0cb   Wang YanQing   menuconfig: Add S...
928
929
930
  			conf_load();
  			break;
  		case 5:
2982de699   Sam Ravnborg   kconfig/menuconfi...
931
  			if (item_is_tag('t')) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
932
933
934
935
936
937
  				if (sym_set_tristate_value(sym, yes))
  					break;
  				if (sym_set_tristate_value(sym, mod))
  					show_textbox(NULL, setmod_text, 6, 74);
  			}
  			break;
6364fd0cb   Wang YanQing   menuconfig: Add S...
938
  		case 6:
2982de699   Sam Ravnborg   kconfig/menuconfi...
939
  			if (item_is_tag('t'))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
940
941
  				sym_set_tristate_value(sym, no);
  			break;
6364fd0cb   Wang YanQing   menuconfig: Add S...
942
  		case 7:
2982de699   Sam Ravnborg   kconfig/menuconfi...
943
  			if (item_is_tag('t'))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
944
945
  				sym_set_tristate_value(sym, mod);
  			break;
6364fd0cb   Wang YanQing   menuconfig: Add S...
946
  		case 8:
2982de699   Sam Ravnborg   kconfig/menuconfi...
947
  			if (item_is_tag('t'))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
948
  				sym_toggle_tristate_value(sym);
2982de699   Sam Ravnborg   kconfig/menuconfi...
949
  			else if (item_is_tag('m'))
5e609addb   Benjamin Poirier   menuconfig: Add j...
950
  				conf(submenu, NULL);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
951
  			break;
6364fd0cb   Wang YanQing   menuconfig: Add S...
952
  		case 9:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
953
954
  			search_conf();
  			break;
6364fd0cb   Wang YanQing   menuconfig: Add S...
955
  		case 10:
22c7eca61   Li Zefan   menuconfig: add s...
956
957
  			show_all_options = !show_all_options;
  			break;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
958
959
  		}
  	}
9a69abf80   Benjamin Poirier   menuconfig: Add "...
960
961
  
  	list_del(trail.prev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
962
  }
95ac9b3b5   Benjamin Poirier   menuconfig: Assig...
963
964
965
  static int show_textbox_ext(const char *title, char *text, int r, int c, int
  			    *keys, int *vscroll, int *hscroll, update_text_fn
  			    update_text, void *data)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
966
  {
e94c5bde7   Sam Ravnborg   kconfig/menuconfi...
967
  	dialog_clear();
95ac9b3b5   Benjamin Poirier   menuconfig: Assig...
968
969
  	return dialog_textbox(title, text, r, c, keys, vscroll, hscroll,
  			      update_text, data);
537ddae75   Benjamin Poirier   menuconfig: Exten...
970
971
972
973
  }
  
  static void show_textbox(const char *title, const char *text, int r, int c)
  {
95ac9b3b5   Benjamin Poirier   menuconfig: Assig...
974
975
  	show_textbox_ext(title, (char *) text, r, c, (int []) {0}, NULL, NULL,
  			 NULL, NULL);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
976
977
978
979
980
981
  }
  
  static void show_helptext(const char *title, const char *text)
  {
  	show_textbox(title, text, 0, 0);
  }
6364fd0cb   Wang YanQing   menuconfig: Add S...
982
983
984
985
986
987
988
989
990
991
  static void conf_message_callback(const char *fmt, va_list ap)
  {
  	char buf[PATH_MAX+1];
  
  	vsnprintf(buf, sizeof(buf), fmt, ap);
  	if (save_and_exit)
  		printf("%s", buf);
  	else
  		show_textbox(NULL, buf, 6, 60);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
992
993
994
  static void show_help(struct menu *menu)
  {
  	struct gstr help = str_new();
1d525e7c1   Cheng Renquan   kconfig: make use...
995

da60fbbcb   Vadim Bendebury (Đ²Đ±)   menuconfig: wrap ...
996
  	help.max_width = getmaxx(stdscr) - 10;
1d525e7c1   Cheng Renquan   kconfig: make use...
997
  	menu_get_ext_help(menu, &help);
413f006ba   EGRY Gabor   kconfig: gettext ...
998
  	show_helptext(_(menu_get_prompt(menu)), str_get(&help));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
999
1000
  	str_free(&help);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1001
1002
  static void conf_choice(struct menu *menu)
  {
413f006ba   EGRY Gabor   kconfig: gettext ...
1003
  	const char *prompt = _(menu_get_prompt(menu));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1004
1005
  	struct menu *child;
  	struct symbol *active;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1006
1007
1008
  
  	active = sym_get_choice_value(menu->sym);
  	while (1) {
2982de699   Sam Ravnborg   kconfig/menuconfi...
1009
1010
1011
  		int res;
  		int selected;
  		item_reset();
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1012
1013
1014
1015
1016
  
  		current_menu = menu;
  		for (child = menu->list; child; child = child->next) {
  			if (!menu_is_visible(child))
  				continue;
af6c15988   Peter Korsgaard   kconfig: handle c...
1017
1018
1019
1020
1021
1022
  			if (child->sym)
  				item_make("%s", _(menu_get_prompt(child)));
  			else {
  				item_make("*** %s ***", _(menu_get_prompt(child)));
  				item_set_tag(':');
  			}
2982de699   Sam Ravnborg   kconfig/menuconfi...
1023
1024
1025
  			item_set_data(child);
  			if (child->sym == active)
  				item_set_selected(1);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1026
  			if (child->sym == sym_get_choice_value(menu->sym))
2982de699   Sam Ravnborg   kconfig/menuconfi...
1027
  				item_set_tag('X');
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1028
  		}
e94c5bde7   Sam Ravnborg   kconfig/menuconfi...
1029
  		dialog_clear();
413f006ba   EGRY Gabor   kconfig: gettext ...
1030
  		res = dialog_checklist(prompt ? _(prompt) : _("Main Menu"),
2982de699   Sam Ravnborg   kconfig/menuconfi...
1031
1032
1033
1034
  					_(radiolist_instructions),
  					 15, 70, 6);
  		selected = item_activate_selected();
  		switch (res) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1035
  		case 0:
2982de699   Sam Ravnborg   kconfig/menuconfi...
1036
1037
  			if (selected) {
  				child = item_data();
af6c15988   Peter Korsgaard   kconfig: handle c...
1038
1039
  				if (!child->sym)
  					break;
2982de699   Sam Ravnborg   kconfig/menuconfi...
1040
1041
  				sym_set_tristate_value(child->sym, yes);
  			}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1042
1043
  			return;
  		case 1:
2982de699   Sam Ravnborg   kconfig/menuconfi...
1044
1045
  			if (selected) {
  				child = item_data();
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1046
1047
1048
1049
1050
  				show_help(child);
  				active = child->sym;
  			} else
  				show_help(menu);
  			break;
f3cbcdc95   Sam Ravnborg   kconfig/lxdialog:...
1051
  		case KEY_ESC:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1052
  			return;
c8dc68ad0   Sam Ravnborg   kconfig/lxdialog:...
1053
1054
  		case -ERRDISPLAYTOOSMALL:
  			return;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1055
1056
1057
1058
1059
1060
1061
  		}
  	}
  }
  
  static void conf_string(struct menu *menu)
  {
  	const char *prompt = menu_get_prompt(menu);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1062
1063
  
  	while (1) {
2982de699   Sam Ravnborg   kconfig/menuconfi...
1064
  		int res;
c4143a830   Sam Ravnborg   kconfig: fix MAC ...
1065
  		const char *heading;
2982de699   Sam Ravnborg   kconfig/menuconfi...
1066

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1067
1068
  		switch (sym_get_type(menu->sym)) {
  		case S_INT:
2982de699   Sam Ravnborg   kconfig/menuconfi...
1069
  			heading = _(inputbox_instructions_int);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1070
1071
  			break;
  		case S_HEX:
2982de699   Sam Ravnborg   kconfig/menuconfi...
1072
  			heading = _(inputbox_instructions_hex);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1073
1074
  			break;
  		case S_STRING:
2982de699   Sam Ravnborg   kconfig/menuconfi...
1075
  			heading = _(inputbox_instructions_string);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1076
1077
  			break;
  		default:
413f006ba   EGRY Gabor   kconfig: gettext ...
1078
  			heading = _("Internal mconf error!");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1079
  		}
e94c5bde7   Sam Ravnborg   kconfig/menuconfi...
1080
  		dialog_clear();
413f006ba   EGRY Gabor   kconfig: gettext ...
1081
  		res = dialog_inputbox(prompt ? _(prompt) : _("Main Menu"),
2982de699   Sam Ravnborg   kconfig/menuconfi...
1082
1083
1084
  				      heading, 10, 75,
  				      sym_get_string_value(menu->sym));
  		switch (res) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1085
  		case 0:
2982de699   Sam Ravnborg   kconfig/menuconfi...
1086
  			if (sym_set_string_value(menu->sym, dialog_input_result))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1087
  				return;
3b9fa0931   Arnaldo Carvalho de Melo   [PATCH] Kconfig i...
1088
  			show_textbox(NULL, _("You have made an invalid entry."), 5, 43);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1089
1090
1091
1092
  			break;
  		case 1:
  			show_help(menu);
  			break;
f3cbcdc95   Sam Ravnborg   kconfig/lxdialog:...
1093
  		case KEY_ESC:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1094
1095
1096
1097
1098
1099
1100
  			return;
  		}
  	}
  }
  
  static void conf_load(void)
  {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1101
1102
  
  	while (1) {
2982de699   Sam Ravnborg   kconfig/menuconfi...
1103
  		int res;
e94c5bde7   Sam Ravnborg   kconfig/menuconfi...
1104
  		dialog_clear();
2982de699   Sam Ravnborg   kconfig/menuconfi...
1105
1106
1107
  		res = dialog_inputbox(NULL, load_config_text,
  				      11, 55, filename);
  		switch(res) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1108
  		case 0:
2982de699   Sam Ravnborg   kconfig/menuconfi...
1109
  			if (!dialog_input_result[0])
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1110
  				return;
95e30f959   Sam Ravnborg   menuconfig: remem...
1111
1112
  			if (!conf_read(dialog_input_result)) {
  				set_config_filename(dialog_input_result);
36ef805bd   Sam Ravnborg   kconfig: mark con...
1113
  				sym_set_change_count(1);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1114
  				return;
95e30f959   Sam Ravnborg   menuconfig: remem...
1115
  			}
3b9fa0931   Arnaldo Carvalho de Melo   [PATCH] Kconfig i...
1116
  			show_textbox(NULL, _("File does not exist!"), 5, 38);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1117
1118
  			break;
  		case 1:
3b9fa0931   Arnaldo Carvalho de Melo   [PATCH] Kconfig i...
1119
  			show_helptext(_("Load Alternate Configuration"), load_config_help);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1120
  			break;
f3cbcdc95   Sam Ravnborg   kconfig/lxdialog:...
1121
  		case KEY_ESC:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1122
1123
1124
1125
1126
1127
1128
  			return;
  		}
  	}
  }
  
  static void conf_save(void)
  {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1129
  	while (1) {
2982de699   Sam Ravnborg   kconfig/menuconfi...
1130
  		int res;
e94c5bde7   Sam Ravnborg   kconfig/menuconfi...
1131
  		dialog_clear();
2982de699   Sam Ravnborg   kconfig/menuconfi...
1132
1133
1134
  		res = dialog_inputbox(NULL, save_config_text,
  				      11, 55, filename);
  		switch(res) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1135
  		case 0:
2982de699   Sam Ravnborg   kconfig/menuconfi...
1136
  			if (!dialog_input_result[0])
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1137
  				return;
95e30f959   Sam Ravnborg   menuconfig: remem...
1138
1139
  			if (!conf_write(dialog_input_result)) {
  				set_config_filename(dialog_input_result);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1140
  				return;
95e30f959   Sam Ravnborg   menuconfig: remem...
1141
  			}
3b9fa0931   Arnaldo Carvalho de Melo   [PATCH] Kconfig i...
1142
  			show_textbox(NULL, _("Can't create file!  Probably a nonexistent directory."), 5, 60);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1143
1144
  			break;
  		case 1:
3b9fa0931   Arnaldo Carvalho de Melo   [PATCH] Kconfig i...
1145
  			show_helptext(_("Save Alternate Configuration"), save_config_help);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1146
  			break;
f3cbcdc95   Sam Ravnborg   kconfig/lxdialog:...
1147
  		case KEY_ESC:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1148
1149
1150
1151
  			return;
  		}
  	}
  }
564899f9f   Davidlohr Bueso   kconfig: handle S...
1152
1153
1154
  static int handle_exit(void)
  {
  	int res;
6364fd0cb   Wang YanQing   menuconfig: Add S...
1155
  	save_and_exit = 1;
9a69abf80   Benjamin Poirier   menuconfig: Add "...
1156
  	reset_subtitle();
564899f9f   Davidlohr Bueso   kconfig: handle S...
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
  	dialog_clear();
  	if (conf_get_changed())
  		res = dialog_yesno(NULL,
  				   _("Do you wish to save your new configuration ?
  "
  				     "<ESC><ESC> to continue."),
  				   6, 60);
  	else
  		res = -1;
  
  	end_dialog(saved_x, saved_y);
  
  	switch (res) {
  	case 0:
  		if (conf_write(filename)) {
  			fprintf(stderr, _("
  
  "
  					  "Error while writing of the configuration.
  "
  					  "Your configuration changes were NOT saved."
  					  "
  
  "));
  			return 1;
  		}
  		/* fall through */
  	case -1:
  		printf(_("
  
  "
  			 "*** End of the configuration.
  "
  			 "*** Execute 'make' to start the build or try 'make help'."
  			 "
  
  "));
  		res = 0;
  		break;
  	default:
  		fprintf(stderr, _("
  
  "
  				  "Your configuration changes were NOT saved."
  				  "
  
  "));
30c4eaafa   Li Zefan   menuconfig: fix a...
1204
1205
  		if (res != KEY_ESC)
  			res = 0;
564899f9f   Davidlohr Bueso   kconfig: handle S...
1206
1207
1208
1209
1210
1211
1212
1213
1214
  	}
  
  	return res;
  }
  
  static void sig_handler(int signo)
  {
  	exit(handle_exit());
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1215
1216
  int main(int ac, char **av)
  {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1217
  	char *mode;
2982de699   Sam Ravnborg   kconfig/menuconfi...
1218
  	int res;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1219

3b9fa0931   Arnaldo Carvalho de Melo   [PATCH] Kconfig i...
1220
1221
1222
  	setlocale(LC_ALL, "");
  	bindtextdomain(PACKAGE, LOCALEDIR);
  	textdomain(PACKAGE);
564899f9f   Davidlohr Bueso   kconfig: handle S...
1223
  	signal(SIGINT, sig_handler);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1224
1225
  	conf_parse(av[1]);
  	conf_read(NULL);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1226
1227
1228
1229
1230
  	mode = getenv("MENUCONFIG_MODE");
  	if (mode) {
  		if (!strcasecmp(mode, "single_menu"))
  			single_menu_mode = 1;
  	}
09af091f5   Ladislav Michl   kconfig: make kco...
1231
1232
1233
1234
1235
1236
1237
  	if (init_dialog(NULL)) {
  		fprintf(stderr, N_("Your display is too small to run Menuconfig!
  "));
  		fprintf(stderr, N_("It must be at least 19 lines by 80 columns.
  "));
  		return 1;
  	}
d802b50f0   Sam Ravnborg   kconfig/menuconfi...
1238
  	set_config_filename(conf_get_configname());
6364fd0cb   Wang YanQing   menuconfig: Add S...
1239
  	conf_set_message_callback(conf_message_callback);
f3cbcdc95   Sam Ravnborg   kconfig/lxdialog:...
1240
  	do {
5e609addb   Benjamin Poirier   menuconfig: Add j...
1241
  		conf(&rootmenu, NULL);
564899f9f   Davidlohr Bueso   kconfig: handle S...
1242
  		res = handle_exit();
f3cbcdc95   Sam Ravnborg   kconfig/lxdialog:...
1243
  	} while (res == KEY_ESC);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1244

564899f9f   Davidlohr Bueso   kconfig: handle S...
1245
  	return res;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1246
  }
c4143a830   Sam Ravnborg   kconfig: fix MAC ...
1247