]> git.sesse.net Git - vlc/blob - menuconfig
2af7d6e1c4fedbb27c6add57f5de59e68edec55e
[vlc] / menuconfig
1 #! /bin/sh
2 #
3 # VLC media player configuration script, borrowed from linux menuconfig
4 # Cyril Deguet <asmax@videolan.org>
5
6 # Currently out of date
7
8 echo "'./menuconfig' is currently not maintained and out-of-date. Use './configure' instead."
9
10 exit 1
11
12 #
13 #-----------------------------------------------------------------
14 # William Roadcap was the original author of Menuconfig.
15 # Michael Elizabeth Chastain (mec@shout.net) is the current maintainer.
16 #
17 # 070497 Bernhard Kaindl (bkaindl@netway.at) - get default values for
18 # new bool, tristate and dep_tristate parameters from the defconfig file.
19 # new configuration parameters are marked with '(NEW)' as in make config.
20 #
21 # 180697 Bernhard Kaindl (bkaindl@netway.at) - added the needed support
22 # for string options. They are handled like the int and hex options.
23 #
24 # 081297 Pavel Machek (pavel@atrey.karlin.mff.cuni.cz) - better error 
25 # handling
26 #
27 # 131197 Michael Chastain (mec@shout.net) - output all lines for a
28 # choice list, not just the selected one.  This makes the output
29 # the same as Configure output, which is important for smart config
30 # dependencies.
31 #
32 # 101297 Michael Chastain (mec@shout.net) - remove sound driver cruft.
33 #
34 # 221297 Michael Chastain (mec@shout.net) - make define_bool actually
35 # define its arguments so that later tests on them work right.
36 #
37 # 160198 Michael Chastain (mec@shout.net) - fix bug with 'c' command
38 # (complement existing value) when used on virgin uninitialized variables.
39 #
40 # 090398 Axel Boldt (boldt@math.ucsb.edu) - allow for empty lines in help
41 # texts.
42 #
43 # 12 Dec 1998, Michael Elizabeth Chastain (mec@shout.net)
44 # Remove a /tmp security hole in get_def (also makes it faster).
45 # Give uninitialized variables canonical values rather than null value.
46 # Change a lot of places to call set_x_info uniformly.
47 # Take out message about preparing version (old sound driver cruft).
48 #
49 # 13 Dec 1998, Riley H Williams <Riley@Williams.Name>
50 # When an error occurs, actually display the error message as well as
51 # our comments thereon.
52 #
53 # 31 Dec 1998, Michael Elizabeth Chastain (mec@shout.net)
54 # Fix mod_bool to honor $CONFIG_MODULES.
55 # Fix dep_tristate to call define_bool when dependency is "n".
56 #
57 # 02 January 1999, Michael Elizabeth Chastain (mec@shout.net)
58 # Blow away lxdialog.scrltmp on entry to activate_menu.  This protects
59 # against people who use commands like ' ' to select menus.
60 #
61 # 24 January 1999, Michael Elizabeth Chastain, <mec@shout.net>
62 # - Improve the exit message (Jeff Ronne).
63 #
64 # 06 July 1999, Andrzej M. Krzysztofowicz, <ankry@mif.pg.gda.pl>
65 # - Support for multiple conditions in dep_tristate().
66 # - Implemented new functions: define_tristate(), define_int(), define_hex(),
67 #   define_string(), dep_bool().
68 #
69 # 12 November 2001, Keith Owens <kaos@ocs.com.au>
70 # Escape double quotes on eval so the quotes are still there on the second
71 # evaluation, required to handle strings with special characters.
72
73
74
75 #
76 # Change this to TRUE if you prefer all kernel options listed
77 # in a single menu rather than the standard menu hierarchy.
78 #
79 single_menu_mode=
80
81 #
82 # Make sure we're really running bash.
83 #
84 [ -z "$BASH" ] && { echo "Menuconfig requires bash" 1>&2; exit 1; }
85
86 #
87 # Cache function definitions, turn off posix compliance
88 #
89 set -h +o posix
90
91
92
93 # Given a configuration variable, set the global variable $x to its value,
94 # and the global variable $info to the string " (NEW)" if this is a new
95 # variable.
96 #
97 # This function looks for: (1) the current value, or (2) the default value
98 # from the arch-dependent defconfig file, or (3) a default passed by the caller.
99
100 function set_x_info () {
101     eval x=\$$1
102     if [ -z "$x" ]; then
103         eval `sed -n -e 's/# \(.*\) is not set.*/\1=n/' -e "/^$1=/p" arch/$ARCH/defconfig`
104         eval x=\${$1:-\"$2\"}
105         eval $1=$x
106         eval INFO_$1="' (NEW)'"
107     fi
108     eval info=\"\$INFO_$1\"
109 }
110
111 #
112 # Load the functions used by the config.in files.
113 #
114 # I do this because these functions must be redefined depending
115 # on whether they are being called for interactive use or for
116 # saving a configuration to a file.
117 #
118 # Thank the heavens bash supports nesting function definitions.
119 #
120 load_functions () {
121
122 #
123 # Additional comments
124 #
125 function comment () {
126         comment_ctr=$[ comment_ctr + 1 ]
127         echo -ne "': $comment_ctr' '--- $1' " >>MCmenu
128 }
129
130 #
131 # Define a boolean to a specific value.
132 #
133 function define_bool () {
134         eval $1=$2
135 }
136
137 function define_tristate () {
138         eval $1=$2
139 }
140
141 function define_hex () {
142         eval $1=$2
143 }
144
145 function define_int () {
146         eval $1=$2
147 }
148
149 function define_string () {
150         eval $1=\"$2\"
151 }
152
153 #
154 # Create a boolean (Yes/No) function for our current menu
155 # which calls our local bool function.
156 #
157 function bool () {
158         set_x_info "$2" "n"
159
160         case $x in
161         y|m)    flag="*" ;;
162         n)      flag=" " ;;
163         esac
164
165         echo -ne "'$2' '[$flag] $1$info' " >>MCmenu
166
167         echo -e "function $2 () { l_bool '$2' \"\$1\" ;}\n" >>MCradiolists
168 }
169
170 #
171 # Create a tristate (Yes/No/Module) radiolist function
172 # which calls our local tristate function.
173 #
174 # Collapses to a boolean (Yes/No) if module support is disabled.
175 #
176 function tristate () {
177         if [ "$CONFIG_MODULES" != "y" ]
178         then
179                 bool "$1" "$2"
180         else
181                 set_x_info "$2" "n"
182         
183                 case $x in
184                 y) flag="*" ;;
185                 m) flag="M" ;;
186                 *) flag=" " ;;
187                 esac
188         
189                 echo -ne "'$2' '<$flag> $1$info' " >>MCmenu
190         
191                 echo -e "
192                 function $2 () { l_tristate '$2' \"\$1\" ;}" >>MCradiolists
193         fi
194 }
195
196 #
197 # Create a tristate radiolist function which is dependent on
198 # another vlc configuration option.
199 #
200 # Quote from the original configure script:
201 #
202 #       If the option we depend upon is a module,
203 #       then the only allowable options are M or N.  If Y, then
204 #       this is a normal tristate.  This is used in cases where modules
205 #       are nested, and one module requires the presence of something
206 #       else in the kernel.
207 #
208 function dep_tristate () {
209         ques="$1"
210         var="$2"
211         dep=y
212         shift 2
213         while [ $# -gt 0 ]; do
214                 if   [ "$1" = y ]; then
215                         shift
216                 elif [ "$1" = m ]; then
217                         dep=m
218                         shift
219                 else
220                         dep=n
221                         shift $#
222                 fi
223         done
224         if [ "$dep" = y ]; then
225             tristate "$ques" "$var"
226         elif [ "$dep" = m ]; then
227             mod_bool "$ques" "$var"
228         else 
229             define_tristate "$var" n
230         fi
231 }
232
233 #
234 #   Same as above, but now only Y and N are allowed as dependency
235 #   (i.e. third and next arguments).
236 #
237 function dep_bool () {
238         ques="$1"
239         var="$2"
240         dep=y
241         shift 2
242         while [ $# -gt 0 ]; do
243                 if [ "$1" = y ]; then
244                         shift
245                 else
246                         dep=n
247                         shift $#
248                 fi
249         done
250         if [ "$dep" = y ]; then
251             bool "$ques" "$var"
252         else 
253             define_bool "$var" n
254         fi
255 }
256
257 function dep_mbool () {
258         ques="$1"
259         var="$2"
260         dep=y
261         shift 2
262         while [ $# -gt 0 ]; do
263                 if [ "$1" = y -o "$1" = m ]; then
264                         shift
265                 else
266                         dep=n
267                         shift $#
268                 fi
269         done
270         if [ "$dep" = y ]; then
271             bool "$ques" "$var"
272         else 
273             define_bool "$var" n
274         fi
275 }
276
277 #
278 # Add a menu item which will call our local int function.
279
280 function int () {
281         set_x_info "$2" "$3"
282
283         echo -ne "'$2' '($x) $1$info' " >>MCmenu
284
285         echo -e "function $2 () { l_int '$1' '$2' '$3' '$x' ;}" >>MCradiolists
286 }
287
288 #
289 # Add a menu item which will call our local hex function.
290
291 function hex () {
292         set_x_info "$2" "$3"
293         x=${x##*[x,X]}
294
295         echo -ne "'$2' '($x) $1$info' " >>MCmenu
296
297         echo -e "function $2 () { l_hex '$1' '$2' '$3' '$x' ;}" >>MCradiolists
298 }
299
300 #
301 # Add a menu item which will call our local string function.
302
303 function string () {
304         set_x_info "$2" "$3"
305
306         echo -ne "'$2' '     $1: \"$x\"$info' " >>MCmenu
307
308         echo -e "function $2 () { l_string '$1' '$2' '$3' '$x' ;}" >>MCradiolists
309 }
310
311 #
312 # Add a menu item which will call our local One-of-Many choice list.
313 #
314 function choice () {
315         #
316         # Need to remember params cause they're gonna get reset.
317         #
318         title=$1
319         choices=$2
320         default=$3
321         current=
322
323         #
324         # Find out if one of the choices is already set.
325         # If it's not then make it the default.
326         #
327         set -- $choices
328         firstchoice=$2
329
330         while [ -n "$2" ]
331         do
332                 if eval [ \"_\$$2\" = \"_y\" ]
333                 then
334                         current=$1
335                         break
336                 fi
337                 shift ; shift
338         done
339
340         : ${current:=$default}
341
342         echo -ne "'$firstchoice' '($current) $title' " >>MCmenu
343
344         echo -e "
345         function $firstchoice () \
346                 { l_choice '$title' \"$choices\" \"$current\" ;}" >>MCradiolists
347 }
348
349 } # END load_functions()
350
351
352
353
354
355 #
356 # Extract available help for an option from Configure.help
357 # and send it to standard output.
358 #
359 # Most of this function was borrowed from the original kernel
360 # Configure script.
361 #
362 function extract_help () {
363   if [ -f doc/Configure.help ]
364   then
365      #first escape regexp special characters in the argument:
366      var=$(echo "$1"|sed 's/[][\/.^$*]/\\&/g')
367      #now pick out the right help text:
368      text=$(sed -n "/^$var[     ]*\$/,\${
369                         /^$var[         ]*\$/c\\
370 ${var}:\\
371
372                         /^#/b
373                         /^[^    ]/q
374                         s/^  //
375                         /<file:\\([^>]*\\)>/s//\\1/g
376                         p
377                     }" doc/Configure.help)
378
379      if [ -z "$text" ]
380      then
381           echo "There is no help available for this option."
382           return 1
383      else
384           echo "$text"
385      fi
386   else
387          echo "There is no help available for this option."
388          return 1
389   fi
390 }
391
392 #
393 # Activate a help dialog.
394 #
395 function help () {
396         if extract_help $1 >help.out
397         then
398                 $DIALOG --backtitle "$backtitle" --title "$2"\
399                         --textbox help.out $ROWS $COLS
400         else
401                 $DIALOG --backtitle "$backtitle" \
402                         --textbox help.out $ROWS $COLS
403         fi
404         rm -f help.out
405 }
406
407 #
408 # Show the README file.
409 #
410 function show_readme () {
411         $DIALOG --backtitle "$backtitle" \
412                 --textbox scripts/README.Menuconfig $ROWS $COLS
413 }
414
415 #
416 # Begin building the dialog menu command and Initialize the 
417 # Radiolist function file.
418 #
419 function menu_name () {
420         echo -ne "$DIALOG --title '$1'\
421                         --backtitle '$backtitle' \
422                         --menu '$menu_instructions' \
423                         $ROWS $COLS $((ROWS-10)) \
424                         '$default' " >MCmenu
425         >MCradiolists
426 }
427
428 #
429 # Add a submenu option to the menu currently under construction.
430 #
431 function submenu () {
432         echo -ne "'activate_menu $2' '$1  --->' " >>MCmenu
433 }
434
435 #
436 # Handle a boolean (Yes/No) option.
437 #
438 function l_bool () {
439         if [ -n "$2" ]
440         then
441                 case "$2" in
442                 y|m)    eval $1=y ;;
443                 c)      eval x=\$$1
444                         case $x in
445                         y) eval $1=n ;;
446                         n) eval $1=y ;;
447                         *) eval $1=y ;;
448                         esac ;;
449                 *)      eval $1=n ;;
450                 esac
451         else
452                 echo -ne "\007"
453         fi
454 }
455
456 #
457 # Same as bool() except options are (Module/No)
458 #
459 function mod_bool () {
460         if [ "$CONFIG_MODULES" != "y" ]; then
461             define_bool "$2" "n"
462         else
463             set_x_info "$2" "n"
464  
465             case $x in
466             y|m) flag='M' ;;
467             *)   flag=' ' ;;
468             esac
469  
470             echo -ne "'$2' '<$flag> $1$info' " >>MCmenu
471  
472             echo -e "function $2 () { l_mod_bool '$2' \"\$1\" ;}" >>MCradiolists
473         fi
474 }
475
476 #
477 # Same as l_bool() except options are (Module/No)
478 #
479 function l_mod_bool() {
480         if [ -n "$2" ]
481         then
482                 case "$2" in
483                 y)      echo -en "\007"
484                         ${DIALOG} --backtitle "$backtitle" \
485                                   --infobox "\
486 This feature depends on another which has been configured as a module.  \
487 As a result, this feature will be built as a module." 4 70
488                         sleep 5
489                         eval $1=m ;;
490                 m)      eval $1=m ;;
491                 c)      eval x=\$$1
492                         case $x in
493                         m) eval $1=n ;;
494                         n) eval $1=m ;;
495                         *) eval $1=m ;;
496                         esac ;;
497                 *)      eval $1=n ;;
498                 esac
499         else
500                 echo -ne "\007"
501         fi
502 }
503
504 #
505 # Handle a tristate (Yes/No/Module) option.
506 #
507 function l_tristate () {
508         if [ -n "$2" ]
509         then
510                 eval x=\$$1
511
512                 case "$2" in
513                 y) eval $1=y ;;
514                 m) eval $1=m ;;
515                 c) eval x=\$$1
516                    case $x in
517                    y) eval $1=n ;;
518                    n) eval $1=m ;;
519                    m) eval $1=y ;;
520                    *) eval $1=y ;;
521                    esac ;;
522                 *) eval $1=n ;;
523                 esac
524         else
525                 echo -ne "\007"
526         fi
527 }
528
529 #
530 # Create a dialog for entering an integer into a kernel option.
531 #
532 function l_int () {
533         while true
534         do
535                 if $DIALOG --title "$1" \
536                         --backtitle "$backtitle" \
537                         --inputbox "$inputbox_instructions_int" \
538                         10 75 "$4" 2>MCdialog.out
539                 then
540                         answer="`cat MCdialog.out`"
541                         answer="${answer:-$3}"
542
543                         # Semantics of + and ? in GNU expr changed, so
544                         # we avoid them:
545                         if expr "$answer" : '0$' '|' "$answer" : '[1-9][0-9]*$' '|' "$answer" : '-[1-9][0-9]*$' >/dev/null
546                         then
547                                 eval $2=\"$answer\"
548                         else
549                                 eval $2=\"$3\"
550                                 echo -en "\007"
551                                 ${DIALOG} --backtitle "$backtitle" \
552                                         --infobox "You have made an invalid entry." 3 43
553                                 sleep 2
554                         fi
555
556                         break
557                 fi
558
559                 help "$2" "$1"
560         done
561 }
562
563 #
564 # Create a dialog for entering a hexadecimal into a kernel option.
565 #
566 function l_hex () {
567         while true
568         do
569                 if $DIALOG --title "$1" \
570                         --backtitle "$backtitle" \
571                         --inputbox "$inputbox_instructions_hex" \
572                         10 75 "$4" 2>MCdialog.out
573                 then
574                         answer="`cat MCdialog.out`"
575                         answer="${answer:-$3}"
576                         answer="${answer##*[x,X]}"
577
578                         if expr "$answer" : '[0-9a-fA-F][0-9a-fA-F]*$' >/dev/null
579                         then
580                                 eval $2=\"$answer\"
581                         else
582                                 eval $2=\"$3\"
583                                 echo -en "\007"
584                                 ${DIALOG} --backtitle "$backtitle" \
585                                         --infobox "You have made an invalid entry." 3 43
586                                 sleep 2
587                         fi
588
589                         break
590                 fi
591
592                 help "$2" "$1"
593         done
594 }
595
596 #
597 # Create a dialog for entering a string into a kernel option.
598 #
599 function l_string () {
600         while true
601         do
602                 if $DIALOG --title "$1" \
603                         --backtitle "$backtitle" \
604                         --inputbox "$inputbox_instructions_string" \
605                         10 75 "$4" 2>MCdialog.out
606                 then
607                         answer="`cat MCdialog.out`"
608                         answer="${answer:-$3}"
609
610                         #
611                         # Someone may add a nice check for the entered
612                         # string here...
613                         #
614                         eval $2=\"$answer\"
615
616                         break
617                 fi
618
619                 help "$2" "$1"
620         done
621 }
622
623
624 #
625 # Handle a one-of-many choice list.
626 #
627 function l_choice () {
628         #
629         # Need to remember params cause they're gonna get reset.
630         #
631         title="$1"
632         choices="$2"
633         current="$3"
634         chosen=
635
636         #
637         # Scan current value of choices and set radiolist switches.
638         #
639         list=
640         set -- $choices
641         firstchoice=$2
642         while [ -n "$2" ]
643         do
644                 case "$1" in
645                 "$current"*)    if [ -z "$chosen" ]; then
646                                         list="$list $2 $1 ON "
647                                         chosen=1
648                                 else
649                                         list="$list $2 $1 OFF "
650                                 fi  ;;
651                 *)              list="$list $2 $1 OFF " ;;
652                 esac
653                         
654                 shift ; shift
655         done
656
657         while true
658         do
659                 if $DIALOG --title "$title" \
660                         --backtitle "$backtitle" \
661                         --radiolist "$radiolist_instructions" \
662                         15 70 6 $list 2>MCdialog.out
663                 then
664                         choice=`cat MCdialog.out`
665                         break
666                 fi
667
668                 help "$firstchoice" "$title"
669         done
670
671         #
672         # Now set the boolean value of each option based on
673         # the selection made from the radiolist.
674         #
675         set -- $choices
676         while [ -n "$2" ]
677         do
678                 if [ "$2" = "$choice" ]
679                 then
680                         eval $2=\"y\"
681                 else
682                         eval $2=\"n\"
683                 fi
684                 
685                 shift ; shift
686         done
687 }
688
689 #
690 # Call awk, and watch for error codes, etc.
691 #
692 function callawk () {
693 awk "$1" || { echo "Awk died with error code $?. Giving up."; exit 1; }
694 }
695
696 #
697 # A faster awk based recursive parser. (I hope)
698 #
699 function parser1 () {
700 callawk '
701 BEGIN {
702         menu_no = 0
703         comment_is_option = 0
704         parser("'$CONFIG_IN'","MCmenu0")
705 }
706
707 function parser(ifile,menu) {
708
709         while (getline <ifile) {
710                 if ($1 == "mainmenu_option") {
711                         comment_is_option = "1"
712                 }
713                 else if ($1 == "comment" && comment_is_option == "1") {
714                         comment_is_option= "0"
715                         sub($1,"",$0)
716                         ++menu_no
717
718                         printf("submenu %s MCmenu%s\n", $0, menu_no) >>menu
719
720                         newmenu = sprintf("MCmenu%d", menu_no);
721                         printf( "function MCmenu%s () {\n"\
722                                 "default=$1\n"\
723                                 "menu_name %s\n",\
724                                  menu_no, $0) >newmenu
725
726                         parser(ifile, newmenu)
727                 }
728                 else if ($0 ~ /^#|\$MAKE|mainmenu_name/) {
729                         printf("") >>menu
730                 }
731                 else if ($1 ~ "endmenu") {
732                         printf("}\n") >>menu
733                         return
734                 } 
735                 else if ($1 == "source") {
736                         parser($2,menu)
737                 }
738                 else {
739                         print >>menu
740                 }
741         }
742 }'
743 }
744
745 #
746 # Secondary parser for single menu mode.
747 #
748 function parser2 () {
749 callawk '
750 BEGIN {
751         parser("'$CONFIG_IN'","MCmenu0")
752 }
753
754 function parser(ifile,menu) {
755
756         while (getline <ifile) {
757                 if ($0 ~ /^#|$MAKE|mainmenu_name/) {
758                         printf("") >>menu
759                 }
760                 else if ($1 ~ /mainmenu_option|endmenu/) {
761                         printf("") >>menu
762                 } 
763                 else if ($1 == "source") {
764                         parser($2,menu)
765                 }
766                 else {
767                         print >>menu
768                 }
769         }
770 }'
771 }
772
773 #
774 # Parse all the config.in files into mini scripts.
775 #
776 function parse_config_files () {
777         rm -f MCmenu*
778
779         echo "function MCmenu0 () {" >MCmenu0
780         echo 'default=$1' >>MCmenu0
781         echo "menu_name 'Main Menu'" >>MCmenu0
782
783         if [ "_$single_menu_mode" = "_TRUE" ]
784         then
785                 parser2
786         else
787                 parser1
788         fi
789
790         echo "comment ''"       >>MCmenu0
791         echo "g_alt_config"     >>MCmenu0
792         echo "s_alt_config"     >>MCmenu0
793
794         echo "}" >>MCmenu0
795
796         #
797         # These mini scripts must be sourced into the current
798         # environment in order for all of this to work.  Leaving
799         # them on the disk as executables screws up the recursion
800         # in activate_menu(), among other things.  Once they are
801         # sourced we can discard them.
802         #
803         for i in MCmenu*
804         do
805                 echo -n "."
806                 source ./$i
807         done
808         rm -f MCmenu*
809 }
810
811 #
812 # This is the menu tree's bootstrap.
813 #
814 # Executes the parsed menus on demand and creates a set of functions,
815 # one per configuration option.  These functions will in turn execute
816 # dialog commands or recursively call other menus.
817 #
818 function activate_menu () {
819         rm -f lxdialog.scrltmp
820         while true
821         do
822                 comment_ctr=0           #So comment lines get unique tags
823
824                 $1 "$default" 2> MCerror #Create the lxdialog menu & functions
825
826                 if [ "$?" != "0" ]
827                 then
828                         clear
829                         cat <<EOM
830
831 Menuconfig has encountered a possible error in one of the vlc's
832 configuration files and is unable to continue.  Here is the error
833 report:
834
835 EOM
836                         sed 's/^/ Q> /' MCerror
837                         cat <<EOM
838
839 Please report this to the maintainer <asmax@videolan.org>.
840
841 Please indicate the vlc version you are trying to configure and
842 which menu you were trying to enter when this error occurred.
843
844 EOM
845                         cleanup
846                         exit 1
847                 fi
848                 rm -f MCerror
849
850                 . ./MCradiolists                #Source the menu's functions
851
852                 . ./MCmenu 2>MCdialog.out       #Activate the lxdialog menu
853                 ret=$?
854
855                 read selection <MCdialog.out
856
857                 case "$ret" in
858                 0|3|4|5|6)
859                         defaults="$selection\12$defaults"  #pseudo stack
860                         case "$ret" in
861                         0) eval $selection   ;;
862                         3) eval $selection y ;;
863                         4) eval $selection n ;;
864                         5) eval $selection m ;;
865                         6) eval $selection c ;;
866                         esac
867                         default="${defaults%%\12*}" defaults="${defaults#*\12}"
868                         ;;
869                 2)      
870                         default="${selection%%\ *}"
871
872                         case "$selection" in
873                         *"-->"*|*"alt_config"*)
874                                 show_readme ;;
875                         *)
876                                 eval help $selection ;;
877                         esac
878                         ;;
879                 255|1)
880                         break
881                         ;;
882                 139)
883                         stty sane
884                         clear
885                         cat <<EOM
886
887 There seems to be a problem with the lxdialog companion utility which is
888 built prior to running Menuconfig.  Usually this is an indicator that you
889 have upgraded/downgraded your ncurses libraries and did not remove the 
890 old ncurses header file(s) in /usr/include or /usr/include/ncurses.
891
892 It is VERY important that you have only one set of ncurses header files
893 and that those files are properly version matched to the ncurses libraries 
894 installed on your machine.
895
896 You may also need to rebuild lxdialog.  This can be done by moving to
897 the /usr/src/linux/scripts/lxdialog directory and issuing the 
898 "make clean all" command.
899
900 If you have verified that your ncurses install is correct, you may email
901 the maintainer <asmax@videolan.org>.
902
903 EOM
904                         cleanup
905                         exit 139
906                         ;;
907                 esac
908         done
909 }
910
911 #
912 # Create a menu item to load an alternate configuration file.
913 #
914 g_alt_config () {
915         echo -n "get_alt_config 'Load an Alternate Configuration File' "\
916                 >>MCmenu
917 }
918
919 #
920 # Get alternate config file name and load the 
921 # configuration from it.
922 #
923 get_alt_config () {
924         set -f ## Switch file expansion OFF
925
926         while true
927         do
928                 ALT_CONFIG="${ALT_CONFIG:-$DEFAULTS}"
929
930                 $DIALOG --backtitle "$backtitle" \
931                         --inputbox "\
932 Enter the name of the configuration file you wish to load.  \
933 Accept the name shown to restore the configuration you \
934 last retrieved.  Leave blank to abort."\
935                         11 55 "$ALT_CONFIG" 2>MCdialog.out
936
937                 if [ "$?" = "0" ]
938                 then
939                         ALT_CONFIG=`cat MCdialog.out`
940
941                         [ "_" = "_$ALT_CONFIG" ] && break
942
943                         if eval [ -r \"$ALT_CONFIG\" ]
944                         then
945                                 eval load_config_file \"$ALT_CONFIG\"
946                                 break
947                         else
948                                 echo -ne "\007"
949                                 $DIALOG --backtitle "$backtitle" \
950                                         --infobox "File does not exist!"  3 38
951                                 sleep 2
952                         fi
953                 else
954                         cat <<EOM >help.out
955
956 For various reasons, one may wish to keep several different vlc
957 configurations available on a single machine.  
958
959 If you have saved a previous configuration in a file other than the
960 vlc's default, entering the name of the file here will allow you
961 to modify that configuration.
962
963 If you are uncertain, then you have probably never used alternate 
964 configuration files.  You should therefor leave this blank to abort.
965
966 EOM
967                         $DIALOG --backtitle "$backtitle"\
968                                 --title "Load Alternate Configuration"\
969                                 --textbox help.out $ROWS $COLS
970                 fi
971         done
972
973         set +f ## Switch file expansion ON
974         rm -f help.out MCdialog.out
975 }
976
977 #
978 # Create a menu item to store an alternate config file.
979 #
980 s_alt_config () {
981         echo -n "save_alt_config 'Save Configuration to an Alternate File' "\
982                  >>MCmenu
983 }
984
985 #
986 # Get an alternate config file name and save the current
987 # configuration to it.
988 #
989 save_alt_config () {
990         set -f  ## Switch file expansion OFF
991                         
992         while true
993         do
994                 $DIALOG --backtitle "$backtitle" \
995                         --inputbox "\
996 Enter a filename to which this configuration should be saved \
997 as an alternate.  Leave blank to abort."\
998                         10 55 "$ALT_CONFIG" 2>MCdialog.out
999
1000                 if [ "$?" = "0" ]
1001                 then
1002                         ALT_CONFIG=`cat MCdialog.out`
1003
1004                         [ "_" = "_$ALT_CONFIG" ] && break
1005
1006                         if eval touch $ALT_CONFIG 2>/dev/null
1007                         then
1008                                 eval save_configuration $ALT_CONFIG
1009                                 load_functions  ## RELOAD
1010                                 break
1011                         else
1012                                 echo -ne "\007"
1013                                 $DIALOG --backtitle "$backtitle" \
1014                                         --infobox "Can't create file!  Probably a nonexistent directory." 3 60
1015                                 sleep 2
1016                         fi
1017                 else
1018                         cat <<EOM >help.out
1019
1020 For various reasons, one may wish to keep different vlc
1021 configurations available on a single machine.  
1022
1023 Entering a file name here will allow you to later retrieve, modify
1024 and use the current configuration as an alternate to whatever 
1025 configuration options you have selected at that time.
1026
1027 If you are uncertain what all this means then you should probably
1028 leave this blank.
1029 EOM
1030                         $DIALOG --backtitle "$backtitle"\
1031                                 --title "Save Alternate Configuration"\
1032                                 --textbox help.out $ROWS $COLS
1033                 fi
1034         done
1035
1036         set +f  ## Switch file expansion ON
1037         rm -f help.out MCdialog.out
1038 }
1039
1040 #
1041 # Load config options from a file.
1042 # Converts all "# OPTION is not set" lines to "OPTION=n" lines
1043 #
1044 function load_config_file () {
1045         awk '
1046           /# .* is not set.*/ { printf("%s=n\n", $2) }
1047         ! /# .* is not set.*/ { print }
1048         ' $1 >.tmpconfig
1049
1050         source ./.tmpconfig
1051         rm -f .tmpconfig
1052 }
1053
1054 #
1055 # Just what it says.
1056 #
1057 save_configuration () {
1058         echo
1059         echo -n "Saving your vlc configuration."
1060
1061         #
1062         # Now, let's redefine the configuration functions for final
1063         # output to the config files.
1064         #
1065         # Nested function definitions, YIPEE!
1066         #
1067         function bool () {
1068                 set_x_info "$2" "n"
1069                 eval define_bool \"$2\" \"$x\"
1070         }
1071
1072         function tristate () {
1073                 set_x_info "$2" "n"
1074                 eval define_tristate \"$2\" \"$x\"
1075         }
1076
1077         function dep_tristate () {
1078                 set_x_info "$2" "n"
1079                 var="$2"
1080                 shift 2
1081                 while [ $# -gt 0 ]; do
1082                         if   [ "$1" = y ]; then
1083                                 shift
1084                         elif [ "$1" = m -a "$x" != n ]; then
1085                                 x=m; shift
1086                         else 
1087                                 x=n; shift $#
1088                         fi
1089                 done
1090                 define_tristate "$var" "$x"
1091         }
1092
1093         function dep_bool () {
1094                 set_x_info "$2" "n"
1095                 var="$2"
1096                 shift 2
1097                 while [ $# -gt 0 ]; do
1098                         if   [ "$1" = y ]; then
1099                                 shift
1100                         else 
1101                                 x=n; shift $#
1102                         fi
1103                 done
1104                 define_bool "$var" "$x"
1105         }
1106
1107         function dep_mbool () {
1108                 set_x_info "$2" "n"
1109                 var="$2"
1110                 shift 2
1111                 while [ $# -gt 0 ]; do
1112                         if   [ "$1" = y -o "$1" = m ]; then
1113                                 shift
1114                         else 
1115                                 x=n; shift $#
1116                         fi
1117                 done
1118                 define_bool "$var" "$x"
1119         }
1120
1121         function int () {
1122                 set_x_info "$2" "$3"
1123                 echo "$2=$x"            >>$CONFIG
1124         }
1125
1126         function hex () {
1127                 set_x_info "$2" "$3"
1128                 echo "$2=$x"                     >>$CONFIG
1129         }
1130
1131         function string () {
1132                 set_x_info "$2" "$3"
1133                 echo "$2=\"$x\""                         >>$CONFIG
1134         }
1135
1136         function define_hex () {
1137                 eval $1=\"$2\"
1138                 echo "$1=$2"                    >>$CONFIG
1139         }
1140
1141         function define_int () {
1142                 eval $1=\"$2\"
1143                 echo "$1=$2"                    >>$CONFIG
1144         }
1145
1146         function define_string () {
1147                 eval $1=\"$2\"
1148                 echo "$1=\"$2\""                >>$CONFIG
1149         }
1150
1151         function define_bool () {
1152                 define_tristate "$1" "$2"
1153         }
1154
1155         function define_tristate () {
1156                 eval $1=\"$2\"
1157
1158                 case "$2" in
1159                 y)
1160                         echo "$1=y"             >>$CONFIG
1161                         ;;
1162
1163                 m)
1164                         if [ "$CONFIG_MODULES" = "y" ]
1165                         then
1166                                 echo "$1=m"                >>$CONFIG
1167                         else
1168                                 echo "$1=y"             >>$CONFIG
1169                         fi
1170                         ;;
1171
1172                 n)
1173                         echo "# $1 is not set"  >>$CONFIG
1174                         ;;
1175                 esac
1176         }
1177
1178         function choice () {
1179                 #
1180                 # Find the first choice that's already set to 'y'
1181                 #
1182                 choices="$2"
1183                 default="$3"
1184                 current=
1185                 chosen=
1186
1187                 set -- $choices
1188                 while [ -n "$2" ]
1189                 do
1190                         if eval [ \"_\$$2\" = \"_y\" ]
1191                         then
1192                                 current=$1
1193                                 break
1194                         fi
1195                         shift ; shift
1196                 done
1197
1198                 #
1199                 # Use the default if none were set.  
1200                 #
1201                 : ${current:=$default}
1202
1203                 #
1204                 # Output all choices (to be compatible with other configs).
1205                 #
1206                 set -- $choices
1207                 while [ -n "$2" ]
1208                 do
1209                         case "$1" in
1210                         "$current"*)    if [ -z "$chosen" ]; then
1211                                                 define_bool "$2" "y"
1212                                                 chosen=1
1213                                         else
1214                                                 define_bool "$2" "n"
1215                                         fi ;;
1216                         *)              define_bool "$2" "n" ;;
1217                         esac
1218                         shift ; shift
1219                 done
1220         }
1221
1222         function mainmenu_name () {
1223                 :
1224         }
1225
1226         function mainmenu_option () {
1227                 comment_is_option=TRUE
1228         }
1229
1230         function endmenu () {
1231                 :
1232         }
1233
1234         function comment () {
1235                 if [ "$comment_is_option" ]
1236                 then
1237                         comment_is_option=
1238                         echo        >>$CONFIG
1239                         echo "#"    >>$CONFIG
1240                         echo "# $1" >>$CONFIG
1241                         echo "#"    >>$CONFIG
1242                 fi
1243         }
1244
1245         echo -n "."
1246
1247         DEF_CONFIG="${1:-.config}"
1248
1249         CONFIG=.tmpconfig
1250
1251         echo "#" >$CONFIG
1252         echo "# Automatically generated by make menuconfig: don't edit" >>$CONFIG
1253         echo "#" >>$CONFIG
1254
1255         echo -n "."
1256         if . $CONFIG_IN >>.menuconfig.log 2>&1
1257         then
1258                 if [ -f "$DEF_CONFIG" ]
1259                 then
1260                         rm -f ${DEF_CONFIG}.old
1261                         mv $DEF_CONFIG ${DEF_CONFIG}.old
1262                 fi
1263
1264                 mv $CONFIG $DEF_CONFIG
1265                         
1266                 return 0
1267         else
1268                 return 1
1269         fi
1270 }
1271
1272 #
1273 # Remove temporary files
1274 #
1275 cleanup () {
1276         cleanup1
1277         cleanup2
1278 }
1279
1280 cleanup1 () {
1281         rm -f MCmenu* MCradiolists MCdialog.out help.out
1282 }
1283
1284 cleanup2 () {
1285         rm -f .tmpconfig
1286 }
1287
1288 set_geometry () {
1289         # Some distributions export these with incorrect values
1290         # which can really screw up some ncurses programs.
1291         LINES=  COLUMNS=
1292
1293         ROWS=${1:-24}  COLS=${2:-80} 
1294
1295         # Just in case the nasty rlogin bug returns.
1296         #
1297         [ $ROWS = 0 ] && ROWS=24
1298         [ $COLS = 0 ] && COLS=80
1299
1300         if [ $ROWS -lt 19 -o $COLS -lt 80 ]
1301         then
1302                 echo -e "\n\007Your display is too small to run Menuconfig!"
1303                 echo "It must be at least 19 lines by 80 columns."
1304                 exit 1
1305         fi 
1306
1307         ROWS=$((ROWS-4))  COLS=$((COLS-5))
1308 }
1309
1310
1311 set_geometry `stty size 2>/dev/null`
1312
1313 menu_instructions="\
1314 Arrow keys navigate the menu.  \
1315 <Enter> selects submenus --->.  \
1316 Highlighted letters are hotkeys.  \
1317 Pressing <Y> includes, <N> excludes, <M> modularizes features.  \
1318 Press <Esc><Esc> to exit, <?> for Help.  \
1319 Legend: [*] built-in  [ ] excluded  <M> module  < > module capable"
1320
1321 radiolist_instructions="\
1322 Use the arrow keys to navigate this window or \
1323 press the hotkey of the item you wish to select \
1324 followed by the <SPACE BAR>.
1325 Press <?> for additional information about this option."
1326
1327 inputbox_instructions_int="\
1328 Please enter a decimal value. \
1329 Fractions will not be accepted.  \
1330 Use the <TAB> key to move from the input field to the buttons below it."
1331
1332 inputbox_instructions_hex="\
1333 Please enter a hexadecimal value. \
1334 Use the <TAB> key to move from the input field to the buttons below it."
1335
1336 inputbox_instructions_string="\
1337 Please enter a string value. \
1338 Use the <TAB> key to move from the input field to the buttons below it."
1339
1340 DIALOG="./lxdialog/lxdialog"
1341
1342 backtitle="VLC media player configuration"
1343
1344 trap "cleanup ; exit 1" 1 2 15
1345
1346
1347 #
1348 # Locate default files.
1349 #
1350 CONFIG_IN=./config.in
1351 if [ "$1" != "" ] ; then
1352         CONFIG_IN=$1
1353 fi
1354
1355 DEFAULTS=defconfig
1356 if [ -f .config ]; then
1357   DEFAULTS=.config
1358 fi
1359
1360 if [ -f $DEFAULTS ]
1361 then
1362   echo "Using defaults found in" $DEFAULTS
1363   load_config_file $DEFAULTS
1364 else
1365   echo "No defaults found"
1366 fi
1367
1368
1369 # Fresh new log.
1370 >.menuconfig.log
1371
1372 # Load the functions used by the config.in files.
1373 echo -n "Preparing scripts: functions" 
1374 load_functions
1375
1376 if [ ! -e $CONFIG_IN ]
1377 then
1378         echo "Your main config.in file ($CONFIG_IN) does not exist"
1379         exit 1
1380 fi
1381
1382 if [ ! -x $DIALOG ]
1383 then
1384         echo "Building lxdialog"
1385         cd lxdialog
1386         make
1387         cd ..
1388 fi
1389 if [ ! -x $DIALOG ]
1390 then
1391         echo "Your lxdialog utility does not exist"
1392         exit 1
1393 fi
1394
1395
1396 #
1397 # Read config.in files and parse them into one shell function per menu.
1398 #
1399 echo -n ", parsing"
1400 parse_config_files $CONFIG_IN
1401
1402 echo "done."
1403 #
1404 # Start the ball rolling from the top.
1405 #
1406 activate_menu MCmenu0
1407
1408 #
1409 # All done!
1410 #
1411 cleanup1
1412
1413 #
1414 # Confirm and Save
1415 #
1416 if $DIALOG --backtitle "$backtitle" \
1417            --yesno "Do you wish to save your new vlc configuration?" 5 60
1418 then
1419         save_configuration
1420         echo
1421         echo "*** End of VideoLAN client configuration. ***"
1422         echo "Run ./build-vlc to launch the build process"
1423         echo
1424 else
1425         echo
1426         echo 
1427         echo Your vlc configuration changes were NOT saved.
1428         echo
1429 fi
1430
1431 # Remove log if empty.
1432 if [ ! -s .menuconfig.log ] ; then
1433         rm -f .menuconfig.log
1434 fi
1435
1436 exit 0