staging: comedi: usbdux: tidy up usbdux_ao_insn_write()
[linux-2.6.git] / scripts / config
blob567120a87c39c0152643fba45f5487979b305afc
1 #!/bin/bash
2 # Manipulate options in a .config file from the command line
4 myname=${0##*/}
6 # If no prefix forced, use the default CONFIG_
7 CONFIG_="${CONFIG_-CONFIG_}"
9 usage() {
10 cat >&2 <<EOL
11 Manipulate options in a .config file from the command line.
12 Usage:
13 $myname options command ...
14 commands:
15 --enable|-e option Enable option
16 --disable|-d option Disable option
17 --module|-m option Turn option into a module
18 --set-str option string
19 Set option to "string"
20 --set-val option value
21 Set option to value
22 --undefine|-u option Undefine option
23 --state|-s option Print state of option (n,y,m,undef)
25 --enable-after|-E beforeopt option
26 Enable option directly after other option
27 --disable-after|-D beforeopt option
28 Disable option directly after other option
29 --module-after|-M beforeopt option
30 Turn option into module directly after other option
32 commands can be repeated multiple times
34 options:
35 --file config-file .config file to change (default .config)
36 --keep-case|-k Keep next symbols' case (dont' upper-case it)
38 $myname doesn't check the validity of the .config file. This is done at next
39 make time.
41 By default, $myname will upper-case the given symbol. Use --keep-case to keep
42 the case of all following symbols unchanged.
44 $myname uses 'CONFIG_' as the default symbol prefix. Set the environment
45 variable CONFIG_ to the prefix to use. Eg.: CONFIG_="FOO_" $myname ...
46 EOL
47 exit 1
50 checkarg() {
51 ARG="$1"
52 if [ "$ARG" = "" ] ; then
53 usage
55 case "$ARG" in
56 ${CONFIG_}*)
57 ARG="${ARG/${CONFIG_}/}"
59 esac
60 if [ "$MUNGE_CASE" = "yes" ] ; then
61 ARG="`echo $ARG | tr a-z A-Z`"
65 set_var() {
66 local name=$1 new=$2 before=$3
68 name_re="^($name=|# $name is not set)"
69 before_re="^($before=|# $before is not set)"
70 if test -n "$before" && grep -Eq "$before_re" "$FN"; then
71 sed -ri "/$before_re/a $new" "$FN"
72 elif grep -Eq "$name_re" "$FN"; then
73 sed -ri "s:$name_re.*:$new:" "$FN"
74 else
75 echo "$new" >>"$FN"
79 undef_var() {
80 local name=$1
82 sed -ri "/^($name=|# $name is not set)/d" "$FN"
85 if [ "$1" = "--file" ]; then
86 FN="$2"
87 if [ "$FN" = "" ] ; then
88 usage
90 shift 2
91 else
92 FN=.config
95 if [ "$1" = "" ] ; then
96 usage
99 MUNGE_CASE=yes
100 while [ "$1" != "" ] ; do
101 CMD="$1"
102 shift
103 case "$CMD" in
104 --keep-case|-k)
105 MUNGE_CASE=no
106 continue
108 --refresh)
110 --*-after|-E|-D|-M)
111 checkarg "$1"
112 A=$ARG
113 checkarg "$2"
114 B=$ARG
115 shift 2
118 checkarg "$1"
119 shift
121 esac
122 case "$CMD" in
123 --enable|-e)
124 set_var "${CONFIG_}$ARG" "${CONFIG_}$ARG=y"
127 --disable|-d)
128 set_var "${CONFIG_}$ARG" "# ${CONFIG_}$ARG is not set"
131 --module|-m)
132 set_var "${CONFIG_}$ARG" "${CONFIG_}$ARG=m"
135 --set-str)
136 # sed swallows one level of escaping, so we need double-escaping
137 set_var "${CONFIG_}$ARG" "${CONFIG_}$ARG=\"${1//\"/\\\\\"}\""
138 shift
141 --set-val)
142 set_var "${CONFIG_}$ARG" "${CONFIG_}$ARG=$1"
143 shift
145 --undefine|-u)
146 undef_var "${CONFIG_}$ARG"
149 --state|-s)
150 if grep -q "# ${CONFIG_}$ARG is not set" $FN ; then
151 echo n
152 else
153 V="$(grep "^${CONFIG_}$ARG=" $FN)"
154 if [ $? != 0 ] ; then
155 echo undef
156 else
157 V="${V/#${CONFIG_}$ARG=/}"
158 V="${V/#\"/}"
159 V="${V/%\"/}"
160 V="${V//\\\"/\"}"
161 echo "${V}"
166 --enable-after|-E)
167 set_var "${CONFIG_}$B" "${CONFIG_}$B=y" "${CONFIG_}$A"
170 --disable-after|-D)
171 set_var "${CONFIG_}$B" "# ${CONFIG_}$B is not set" "${CONFIG_}$A"
174 --module-after|-M)
175 set_var "${CONFIG_}$B" "${CONFIG_}$B=m" "${CONFIG_}$A"
178 # undocumented because it ignores --file (fixme)
179 --refresh)
180 yes "" | make oldconfig
184 usage
186 esac
187 done