AOSC-Archive / autobuild3

AOSC OS package maintenance toolkit (version 3)
https://aosc.io
GNU General Public License v2.0
24 stars 17 forks source link

Current elfstrip enum method can cause syntax errors with specially-formed filenames. #25

Closed Artoria2e5 closed 9 years ago

Artoria2e5 commented 9 years ago

This occurs with R, where the filename breaks the sed syntax. Monkey patching by replacing all sed with bash parameter expansions can fix this, however, it's also possible that something evil will happen with evala, therefore we should rewrite it in a simpler form (TODO).

Note a: If we really want to evil it, we should do printf %q "$var" first so it gets properly escaped.

Foreach methods shouldn't be implemented in bash since functions are not among the first-class data types. If there is a need of such thing, use some function name ref, like this:

# foreach funcname [array-args]
foreach(){
  [ "$1" ] || return 2
  local _fe_fun="$1" _mem
  shift
  for _mem; do "$_fe_fun" "$_mem"; done;
}
# filter funcname simple-array-name
filter(){
  [ "$2" ] || return 2
  # todo typeof check or key array saving
  declare -n _filter_arr="$2"
  declare -a _filter_tmparr=()
  local _fe_funname="_fe_$1"
  eval "${_fe_funname}(){ $(argprint "$1") \"\$1\" && _filter_tmparr+=(\"\$1\"); }"
  foreach "$_fe_funname" "${_filter_arr[@]}"
  _filter_arr=( "${_filter_tmparr[@]}" )
  unset _filter_tmparr $_fe_funname
}
g=(p q r qe)
_lamb_fl_1(){ ((${#1}==1)); }
filter _lamb_fl_1 g
unset _lamb_fl_1
declare -p g
_lamb_fe_l(){ echo "$1" | rev; }
foreach _lamb_fe_l lorem ipsum
unset _lamb_fe_l
Artoria2e5 commented 9 years ago

9f0bfba should be a nice duck taping with argprint.