Advertisement
Guest User

ajdiaz

a guest
Feb 16th, 2010
999
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.87 KB | None | 0 0
  1. cfg.parser ()
  2. {
  3.     IFS=$'\n' && ini=( $(<$1) ) # convert to line-array
  4.     ini=( ${ini[*]//;*/} )      # remove comments ‘;’
  5.     ini=( ${ini[*]//\#*/} )     # remove comments ‘#’
  6.     ini=( ${ini[*]/\    =/=} )  # remove tabs before =
  7.     ini=( ${ini[*]/=\   /=} )   # remove tabs be =
  8.     ini=( ${ini[*]/\ =\ /=} )   # remove anything with a space around ‘ = ‘
  9.     ini=( ${ini[*]/#[/\}$'\n'cfg.section.} ) # set section prefix
  10.     ini=( ${ini[*]/%]/ \(} )    # convert text2function (1)
  11.     ini=( ${ini[*]/=/=\( } )    # convert item to array
  12.     ini=( ${ini[*]/%/ \)} )     # close array parenthesis
  13.     ini=( ${ini[*]/%\\ \)/ \\} ) # the multiline trick
  14.     ini=( ${ini[*]/%\( \)/\(\) \{} ) # convert text2function (2)
  15.     ini=( ${ini[*]/%\} \)/\}} ) # remove extra parenthesis
  16.     ini[0]="" # remove first element
  17.     ini[${#ini[*]} + 1]='}'    # add the last brace
  18.     eval "$(echo "${ini[*]}")" # eval the result
  19. }
  20.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement