OpenSDE Framework (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

600 lines
15 KiB

  1. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  2. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  3. #
  4. # Filename: lib/sde-config/functions.in
  5. # Copyright (C) 2006 - 2008 The OpenSDE Project
  6. # Copyright (C) 2004 - 2006 The T2 SDE Project
  7. # Copyright (C) 1998 - 2003 Clifford Wolf
  8. #
  9. # More information can be found in the files COPYING and README.
  10. #
  11. # This program is free software; you can redistribute it and/or modify
  12. # it under the terms of the GNU General Public License as published by
  13. # the Free Software Foundation; version 2 of the License. A copy of the
  14. # GNU General Public License can be found in the file COPYING.
  15. # --- SDE-COPYRIGHT-NOTE-END ---
  16. . lib/core-functions.in
  17. # Function to cache config.in and subconfig.in file lists
  18. #
  19. create_configin_list() {
  20. bprof cache_configin_list start
  21. if [ ! -f $cfgtmpdir/noexpert-config.in -o ! -f $cfgtmpdir/expert-config.in ]; then
  22. local file= prio= name=
  23. rm -f $cfgtmpdir/{no,}expert-config.in{,.$$}
  24. rm -f $cfgtmpdir/subconfig-*.in{,.$$}
  25. touch $cfgtmpdir/{no,}expert-config.in{,.$$}
  26. # config.in
  27. # FIXME: this expression may produce duplicated entries!! //mnemoc
  28. ls -1 {package/*,misc,lib}/*/config{,-[a-z]*}{,-[0-9]*}.in 2> /dev/null | while read file; do
  29. prio="$( echo "${file##*/}" | sed -n -e "s,.*-\([0-9]*\).in,\1,p" )"
  30. if [ ${prio:-750} -le 500 ]; then
  31. echo "$prio $file" >> $cfgtmpdir/noexpert-config.in.$$
  32. else
  33. echo "${prio:-750} $file" >> $cfgtmpdir/expert-config.in.$$
  34. fi
  35. done
  36. sort -u $cfgtmpdir/noexpert-config.in.$$ | sed 's,^[^ ]* ,. ,g' > $cfgtmpdir/noexpert-config.in
  37. sort -u $cfgtmpdir/expert-config.in.$$ | sed 's,^[^ ]* ,. ,g' > $cfgtmpdir/expert-config.in
  38. rm -f $cfgtmpdir/{no,}expert-config.in.$$
  39. # subconfig.in
  40. ls -1 package/*/*/subconfig-[a-z]*.in 2> /dev/null | while read file; do
  41. prio="$( echo "${file##*/}" | sed -n -e "s,.*-\([0-9]*\).in,\1,p" )"
  42. name="$( echo "${file##*/}" | sed -e "s,-\([0-9]*\).in,.in," )"
  43. echo "${prio:-750} $file" >> $cfgtmpdir/$name.$$
  44. done
  45. for file in $cfgtmpdir/subconfig-[a-z]*.in.$$; do
  46. sort -n $file | sed 's,^[^ ]* ,. ,g' > ${file%.$$}
  47. rm -f $file
  48. done
  49. fi
  50. bprof cache_configin_list stop
  51. }
  52. # Function to cache config.in and subconfig.in file lists
  53. #
  54. create_dot_in_lists() {
  55. local file= x= y=
  56. # {architecture,misc,lib,target,package/*}/*/{pre,post}config.in
  57. bprof cache_dotin_list start
  58. for x in preconfig.in postconfig.in; do
  59. for y in architecture misc lib target; do
  60. file=$cfgtmpdir/$y-$x
  61. if [ ! -f $file ]; then
  62. ls -1 $y/*/$x 2> /dev/null | sed 's,^,. ,' > $file
  63. fi
  64. done
  65. y=package
  66. file=$cfgtmpdir/$y-$x
  67. if [ ! -f $file ]; then
  68. ls -1 $y/*/*/$x 2> /dev/null | sed 's,^,. ,' > $file
  69. fi
  70. done
  71. bprof cache_dotin_list stop
  72. # and {sub,}config.in, which is more complex
  73. create_configin_list
  74. }
  75. hack_stages() {
  76. local stage="$1----------"; shift
  77. local pkgs="$*"
  78. if [ $# -gt 1 ]; then
  79. pkgs="${pkgs// /\|}"
  80. elif [ $# -eq 1 ]; then
  81. true
  82. fi
  83. if [ "$pkgs" ]; then
  84. pkgfilter sed -e "s,^\(.\) [^ ]* \([^ ]*\) \([^ ]*\) \($pkgs\) ,\1 ${stage:0:10} \2 \3 \4 ,"
  85. fi
  86. }
  87. # Functions for working with config/$config/packages
  88. #
  89. # pkgenable package-list
  90. # pkgdisable package-list
  91. # pkgremove package-list
  92. # pkgcheck pattern X|O|.
  93. # pkgfilter cmd arg1 ...
  94. #
  95. if [ -n "$nobashmod" ]
  96. then
  97. pkgin() { :; }
  98. pkgout() { :; }
  99. __pkgfilter() {
  100. "$@" < $cfgtmpdir/config/packages > $cfgtmpdir/packages.new
  101. mv $cfgtmpdir/packages.new $cfgtmpdir/config/packages
  102. }
  103. pkgfilter() {
  104. bprof pkgfilter start
  105. __pkgfilter "$@"
  106. bprof pkgfilter stop
  107. }
  108. pkgenable() {
  109. bprof pkgenable start
  110. local pattern patterns
  111. for pattern; do
  112. patterns="$patterns -e '/ $pattern / s/^./X/'"
  113. done
  114. if [ "$patterns" ]; then
  115. eval "__pkgfilter sed $patterns"
  116. fi
  117. bprof pkgenable stop
  118. }
  119. pkgdisable() {
  120. bprof pkgdisable start
  121. local pattern patterns
  122. for pattern; do
  123. patterns="$patterns -e '/ $pattern / s/^./O/'"
  124. done
  125. if [ "$patterns" ]; then
  126. eval "__pkgfilter sed $patterns"
  127. fi
  128. bprof pkgdisable stop
  129. }
  130. pkgremove() {
  131. bprof pkgremove start
  132. local pattern patterns
  133. if [ "$1" ]; then
  134. patterns=" $1 "; shift
  135. for pattern; do
  136. patterns="$patterns| $pattern "
  137. done
  138. __pkgfilter egrep -v "$patterns"
  139. fi
  140. bprof pkgremove stop
  141. }
  142. pkgcheck() {
  143. bprof pkgcheck start
  144. local pattern="$1"; pattern="${pattern//+/\\+}"
  145. egrep -q "^$2.*[ =]($pattern) " $cfgtmpdir/config/packages; local ret=$?
  146. bprof pkgcheck stop
  147. return $ret
  148. }
  149. else
  150. pkgin() { cfghlp pkg_in $cfgtmpdir/config/packages; }
  151. pkgout() { cfghlp pkg_out $cfgtmpdir/config/packages ; }
  152. pkgfilter() {
  153. bprof pkgfilter start
  154. cfghlp pkg_out $cfgtmpdir/packages.tmp
  155. "$@" < $cfgtmpdir/packages.tmp > $cfgtmpdir/config/packages
  156. cfghlp pkg_in $cfgtmpdir/config/packages
  157. bprof pkgfilter stop
  158. }
  159. pkgenable() {
  160. bprof pkgenable start
  161. cfghlp pkgenable "$@"
  162. bprof pkgenable stop
  163. }
  164. pkgdisable() {
  165. bprof pkgdisable start
  166. cfghlp pkgdisable "$@"
  167. bprof pkgdisable stop
  168. }
  169. pkgremove() {
  170. bprof pkgremove start
  171. cfghlp pkgremove "$@"
  172. bprof pkgremove stop
  173. }
  174. pkgcheck() {
  175. bprof pkgcheck start
  176. cfghlp pkgcheck "$1" "$2"; local ret=$?
  177. bprof pkgcheck stop
  178. return $ret
  179. }
  180. fi
  181. # pkgchecklicense -- checks for files with license issues
  182. pkgchecklicense() {
  183. rm -f $cfgtmpdir/license-issue.*
  184. while read a b c repo pkg dummy; do
  185. if grep -E "\[(L|LICENSE)\][ ]*(Commercial|Restricted)" \
  186. package/$repo/$pkg/$pkg.desc &> /dev/null; then
  187. echo $pkg >> $cfgtmpdir/license-issue.ask
  188. fi
  189. done < <(grep "^X" $cfgtmpdir/config/packages)
  190. }
  191. comment() {
  192. bprof comment start
  193. if [ $SDECFG_EXPERT -eq 1 -o $expert -eq 0 ] && \
  194. [ $menu_current = $menu_this ] ; then
  195. commentnr=$(( $commentnr + 1 ))
  196. echo "COMMENT_$commentnr '$spacer$1'" >> $cfgtmpdir/config.dialog
  197. if [ "$2" != "" ] ; then
  198. set_help "COMMENT_$commentnr" "$2"
  199. fi
  200. fi
  201. bprof comment stop
  202. }
  203. comment_id() {
  204. bprof comment_id start
  205. if [ $SDECFG_EXPERT -eq 1 -o $expert -eq 0 ] &&
  206. [ $menu_current = $menu_this ] ; then
  207. echo "$2 '$spacer$1'" >> $cfgtmpdir/config.dialog
  208. if [ "$3" != "" ] ; then
  209. set_help "$2" "$3"
  210. fi
  211. fi
  212. bprof comment_id stop
  213. }
  214. const() {
  215. bprof const start
  216. local q="'"
  217. local v="${2//$q/$q\\$q$q}"
  218. eval "$1=\"\$2\""
  219. echo "export $1='$v'" >> $cfgtmpdir/config/config
  220. bprof const stop
  221. }
  222. # Usage: set_data NAME DEFAULT
  223. #
  224. set_data() {
  225. bprof set_data start
  226. local q="'" set_name="SDECFGSET_${1#SDECFG_}"
  227. if eval "[ \"\$$set_name\" ]" ; then
  228. eval "data=\"\$$set_name\""
  229. eval "$1=\"\$data\""
  230. if [ $SDECFG_EXPERT -eq 1 -o $expert -eq 0 ]
  231. then menumode=2 ; else menumode=0 ; fi
  232. elif [ $SDECFG_EXPERT -eq 1 -o $expert -eq 0 ] ; then
  233. eval "data=\"\${$1:-$2}\""
  234. eval "$1=\"\$data\""
  235. menumode=1
  236. else
  237. data="$2" ; eval "$1=\"\$data\""
  238. menumode=0
  239. fi
  240. item="$1"
  241. echo "export $1='${data//$q/$q\\$q$q}'" >> $cfgtmpdir/config/config
  242. bprof set_data stop
  243. }
  244. choice() {
  245. bprof choice start
  246. # desired default value
  247. #
  248. local defval="$2"
  249. # reset to default if current value is not in list
  250. # and default to first element if it's not in list
  251. #
  252. eval $(
  253. eval "value=\$$1" ; name=$1 ; dval=$defval; shift ; shift
  254. while [ "$#" != 0 ] ; do
  255. [ "$dval" = "$1" ] && dval=
  256. [ "$value" = "$1" ] && name= ; shift ; shift
  257. done
  258. [ "$dval" ] && echo "unset defval;"
  259. [ "$name" ] && echo "unset $name"
  260. )
  261. set_data "$1" "${defval:-$3}"
  262. if [ "$menumode" -eq 1 -a $menu_current = $menu_this ] ; then
  263. { $ECHO_E -n "$item\tchoice_action '$1' '$data'" ; shift ; shift
  264. for x ; do echo -n " '$x'" ; done ; echo ; } >> $cfgtmpdir/config.data
  265. fi
  266. if [ "$menumode" -gt 0 -a $menu_current = $menu_this ] ; then
  267. if [ "$menumode" -eq 1 ] ; then xdata="($data)"
  268. else xdata="=$data=" ; fi
  269. while [ "$1" -a "$1" != "$data" ] ; do shift ; shift ; done
  270. printf "'$item' '$spacer%-${tabspace}s ${2//_/ }'\n" \
  271. "$xdata" >> $cfgtmpdir/config.dialog
  272. fi
  273. bprof choice stop
  274. }
  275. choice_action() {
  276. command="./tmp/confdialog.bin --title 'Build Config' \
  277. --backtitle '$configtitle' \
  278. --radiolist 'Arrow keys navigate the menu. Press <Enter> to activate menu items. Highlighted letters are hotkeys.' \
  279. $(( $lines - 4 )) $(( $columns - 5 )) $(( $lines - 12 ))"
  280. default=$2 ; item=$1 ; shift ; shift
  281. while [ "$1" ] ; do
  282. if [ "$1" = "$default" ]
  283. then command="$command '$1' '${2//_/ }' ON"
  284. else command="$command '$1' '${2//_/ }' OFF" ; fi
  285. shift ; shift
  286. done
  287. eval "$command" 2> $cfgtmpdir/config.out
  288. case "$?" in
  289. 0|6)
  290. eval "$item='`cat $cfgtmpdir/config.out`'"
  291. ;;
  292. 1|255) return 0 ;;
  293. 2) echo "No help." ; sleep 1 ;;
  294. *) echo "unknown returncode: $?" ; exit 1 ;;
  295. esac
  296. }
  297. text() {
  298. bprof text start
  299. local q="'"
  300. set_data "$2" "$3"
  301. if [ "$menumode" -eq 1 -a $menu_current = $menu_this ] ; then
  302. $ECHO_E "$2\ttext_action '$1' '$2'" \
  303. "'${data//$q/$q\\$q$q}'" >> $cfgtmpdir/config.data
  304. fi
  305. if [ "$menumode" -gt 0 -a $menu_current = $menu_this ] ; then
  306. xdata="$( printf "%-${tabspace}s" \
  307. "$(echo $data | cut -c1-20)")"
  308. if [ "$menumode" -eq 1 ] ; then xdata="($xdata)"
  309. else xdata="=$xdata=" ; fi
  310. printf "'$2' '$spacer%s $1'\n" \
  311. "${xdata//$q/$q\\$q$q}" >> $cfgtmpdir/config.dialog
  312. if [ "$4" != "" ] ; then
  313. set_help "$2" "$4"
  314. fi
  315. fi
  316. bprof text stop
  317. }
  318. text_action() {
  319. ./tmp/confdialog.bin --title 'Build Config' \
  320. --backtitle "$configtitle" \
  321. --inputbox "$1" 9 $(( $columns - 5 )) "$3" 2> $cfgtmpdir/config.out
  322. [ "$?" -eq 0 -o "$?" -eq 1 ] && eval "$2=\"\$(cat $cfgtmpdir/config.out)\""
  323. }
  324. bool() {
  325. bprof bool start
  326. local x
  327. set_data "$2" "$3"
  328. if [ "$menumode" -eq 1 -a $menu_current = $menu_this ] ; then
  329. $ECHO_E "$2\tbool_action '$1' '$2' '$data'" >> $cfgtmpdir/config.data
  330. fi
  331. if [ "$menumode" -gt 0 -a $menu_current = $menu_this ] ; then
  332. if [ "$menumode" -eq 1 ] ; then
  333. if [ $data -eq 0 ] ; then x='[ ]' ; else x='[*]' ; fi
  334. else
  335. if [ $data -eq 0 ] ; then x='= =' ; else x='=*=' ; fi
  336. fi
  337. printf "$2 '$spacer%-${tabspace}s ${1//_/ }'\n" \
  338. "$x" >> $cfgtmpdir/config.dialog
  339. if [ "$4" != "" ] ; then
  340. set_help "$2" "$4"
  341. fi
  342. fi
  343. bprof bool stop
  344. }
  345. bool_action() {
  346. if [ $3 -eq 0 ] ; then eval "$2=1"
  347. else eval "$2=0" ; fi
  348. }
  349. editfile() {
  350. bprof editfile start
  351. if [ $SDECFG_EXPERT -eq 1 -o $expert -eq 0 ] ; then
  352. local x="$spacer" q="'"
  353. comment ",----< $3 >----."
  354. block_begin 0 ; spacer="${spacer%??}| "
  355. touch "$2"
  356. line_nr=1
  357. while read line ; do
  358. line="${line//$q/$q\\$q$q}"
  359. if [ $menu_current = $menu_this ] ; then
  360. printf "$1:${editfilenr} '$spacer%-${tabspace}s %s'\n" \
  361. `printf "%03d:" $line_nr` "$line" >> $cfgtmpdir/config.dialog
  362. $ECHO_E "$1:${editfilenr}\teditfile_action $2" \
  363. "$line_nr '$3'" >> $cfgtmpdir/config.data
  364. fi
  365. editfilenr=$(( $editfilenr + 1 ))
  366. line_nr=$(( $line_nr + 1 ))
  367. done < "$2"
  368. if [ $menu_current = $menu_this ] ; then
  369. printf "$1:${editfilenr} '$spacer%-${tabspace}s %s'\n" \
  370. `printf "%03d:" $line_nr` "<add new rule>" >> $cfgtmpdir/config.dialog
  371. $ECHO_E "$1:${editfilenr}\teditfile_action $2" \
  372. "$line_nr '$3'" >> $cfgtmpdir/config.data
  373. fi
  374. editfilenr=$(( $editfilenr + 1 ))
  375. block_end
  376. comment "\`------${3//?/-}------'\''"
  377. spacer="$x"
  378. else
  379. rm -f "$2"
  380. fi
  381. bprof editfile stop
  382. }
  383. editfile_action() {
  384. line="`tail -n +$2 $1 | head -n 1`"
  385. ./tmp/confdialog.bin --title 'Build Config' \
  386. --backtitle "$configtitle" \
  387. --inputbox "$3 - Line $3" \
  388. 9 $(( $columns - 5 )) "$line" 2> $cfgtmpdir/config.out
  389. head -n $(( $2 - 1 )) $1 > $1.new
  390. [ -s $cfgtmpdir/config.out ] && echo "`cat $cfgtmpdir/config.out`" >> $1.new
  391. tail -n +$(( $2 + 1 )) $1 >> $1.new
  392. mv $1.new $1
  393. }
  394. startprog() {
  395. bprof startprog start
  396. if [ $SDECFG_EXPERT -eq 1 -o $expert -eq 0 ] &&
  397. [ $menu_current = $menu_this ] ; then
  398. printf "$1 '$spacer%-${tabspace}s %s'\n" \
  399. "-->" "$2" >> $cfgtmpdir/config.dialog
  400. $ECHO_E "$1\t$3" >> $cfgtmpdir/config.data
  401. fi
  402. bprof startprog stop
  403. }
  404. block_begin() {
  405. bprof block_begin start
  406. if [ $menu_current = $menu_this ] ; then
  407. [ "$tabspace_list" ] && spacer="$spacer "
  408. tabspace_list="$tabspace $tabspace_list"
  409. tabspace="$(( $tabspace + $1 - 2 ))"
  410. fi
  411. bprof block_begin stop
  412. }
  413. block_end() {
  414. bprof block_end start
  415. if [ $menu_current = $menu_this ] ; then
  416. spacer="${spacer%??}"
  417. tabspace="${tabspace_list%% *}"
  418. tabspace_list="${tabspace_list#* }"
  419. fi
  420. bprof block_end stop
  421. }
  422. expert_begin() {
  423. expert=$(( $exprt + 1 ))
  424. }
  425. expert_end() {
  426. expert=$(( $exprt - 1 ))
  427. }
  428. menu_begin() {
  429. bprof menu_begin start
  430. menu_counter=$(( $menu_counter + 1 ))
  431. if [ $SDECFG_EXPERT -eq 1 -o $expert -eq 0 ] &&
  432. [ $menu_current = $menu_this ] ; then
  433. printf "$1 '$spacer%-${tabspace}s %s'\n" \
  434. "===>" "$2" >> $cfgtmpdir/config.dialog
  435. $ECHO_E "$1\tmenu_current=$menu_counter" >> $cfgtmpdir/config.data
  436. fi
  437. if [ $SDECFG_EXPERT -eq 1 -o $expert -eq 0 ] &&
  438. [ $menu_current = $menu_counter ] ; then
  439. echo "$1 '===> $2'" >> $cfgtmpdir/config.dialog
  440. $ECHO_E "$1\tmenu_current=$menu_this" >> $cfgtmpdir/config.data
  441. fi
  442. if [ $menu_current = $menu_counter ] ; then
  443. menu_back=$menu_this
  444. menu_backpos=$1
  445. fi
  446. menu_stack="$menu_this $menu_stack"
  447. menu_this=$menu_counter
  448. block_begin 3
  449. bprof menu_begin stop
  450. }
  451. menu_end() {
  452. bprof menu_end start
  453. block_end
  454. menu_this="${menu_stack%% *}"
  455. menu_stack="${menu_stack#* }"
  456. bprof menu_end stop
  457. }
  458. set_help() {
  459. bprof set_help start
  460. ($ECHO_E -n "$1 '$1:\n\n$2'" | sed 's,$,\\n,' |
  461. tr -d '\n' | sed 's,\\n$,,'; echo ) >> $cfgtmpdir/config.help
  462. bprof set_help stop
  463. }
  464. get_help() {
  465. bprof get_help start
  466. # Create standard help output ...
  467. default_text="
  468. There is no help on '$1' available.
  469. This is the OpenSDE ($sdever) Configuration Tool.
  470. More information can be found on the OpenSDE Homepage:
  471. http://www.opensde.org/
  472. A Bugtracker, Source Browser and Wiki can be found here:
  473. http://trac.opensde.org/
  474. Subscribe to the mailing list by sending an empty e-mail to:
  475. <list-subscribe@opensde.org>
  476. and confirm the subscription request by replying to the mail
  477. our mailing list manager will send you."
  478. # Ok let us find a help for the current item ...
  479. # First of all mask all special chars in the item name
  480. # Comment: this is sick. You can't get any \n this way !!!
  481. item_name=$( echo "$1" | sed 's/[][\/.^$*]/\\&/g' )
  482. # Now search *.hlp files
  483. hlp_text=$( sed -n "/^$item_name[ ]*\$/,\${
  484. /^$item_name[ ]*\$/c\\
  485. $item_name:\\
  486. /^#/d
  487. /^[^ ]/q
  488. s/^ //
  489. p
  490. }" lib/*/config*.hlp package/*/*/subconfig-*.hlp package/*/*/config*.hlp target/*/config*.hlp 2>/dev/null )
  491. # Get help strings out of the temporary file.
  492. tmp_text=$(grep "^$item_name" $cfgtmpdir/config.help | cut -f2- -d' ' | sed -e "s,^',," -e "s,'$,," )
  493. # Let us see what we have ...
  494. if [ "$hlp_text" -a "$tmp_text" ] ; then
  495. echo "
  496. There are two help text's... one in one of the config.in files and one
  497. in one of the config.hlp files. Please remove one of them to get rid of
  498. this message here.
  499. Here the one out of config.in:
  500. $tmp_text
  501. Here the one out of config.hlp:
  502. $hlp_text"
  503. elif [ "$hlp_text" ] ; then
  504. echo "$hlp_text"
  505. elif [ "$tmp_text" ] ; then
  506. echo "$tmp_text"
  507. else
  508. echo "$default_text"
  509. fi
  510. bprof get_help stop
  511. }