diff options
-rw-r--r-- | lib/deps.sh | 70 |
1 files changed, 25 insertions, 45 deletions
diff --git a/lib/deps.sh b/lib/deps.sh index 27e1b77..c9b065f 100644 --- a/lib/deps.sh +++ b/lib/deps.sh @@ -34,10 +34,9 @@ ob_parse_dep() local host_arch= local host_plat= local dep= - local pkgarchqual= + local dep_re= local pkg= local archqual= - local relver= local rel= local ver= local arches= @@ -97,54 +96,35 @@ ob_parse_dep() shift $(($OPTIND - 1)) if [ ${#} -eq 1 ]; then - dep="$(printf '%s\n' "${1}" | sed -n ' - H; # Store each input line in the hold space. - ${ - g; # Restore everything to the pattern space. - s/[\t\n]/ /g; # Replace tabs and newlines with spaces. - s/ *\([(\[<]\) */ \1/g; # One space before "(", "[", and "<". - s/ *\([)\]>]\) */\1 /g; # One space after "(", "[", and "<". - s/ *\(<[<=]\) */\1 /g; # One space after "<<" and "<=". - s/ *\(>[>=]\) */\1 /g; # One space after ">>" and ">=". - s/ *\(=\) */\1 /g; # One space after "=". - s/^ *//; # Remove leading spaces. - s/ *$//; # Remove trailing spaces. - s/ */ /g; # Remove duplicate spaces. - p; # Print the pattern space. - }; - ')" + dep="${1}" else return 125 fi # pkg[:archqual] [(rel ver)] [\[arches\]] [<plats>] - - pkgarchqual="${dep%% *}" - dep=" ${dep#* }" - pkg="${pkgarchqual%:*}" - if [ "${pkg}" != "${pkgarchqual}" ]; then - archqual="${pkgarchqual##*:}" - fi - - if [ "${dep# (*)}" != "${dep}" ]; then - relver="${dep# (}" - relver="${relver%%)*}" - dep="${dep# (*)}" - rel="${relver% *}" - ver="${relver##* }" - fi - - if [ "${dep# \[*\]}" != "${dep}" ]; then - arches="${dep# \[}" - arches="${arches%%\]*}" - dep="${dep# \[*\]}" - fi - - if [ "${dep# <*>}" != "${dep}" ]; then - plats="${dep# <}" - plats="${plats%%>*}" - dep="${dep# <*>}" - fi + dep_re='s/^ *([^ \(\[<]+) *(\((<<|<=|=|>=|>>) *(.+)\))?' + dep_re="${dep_re}"' *(\[(.+)\])? *(<(.+)>)? *$/\1\n\3\n\4\n\6\n\8/;' + + # BusyBox sed supports -r and (as of version 1.22.0) -E. + dep="$(printf '%s\n' "${dep}" | sed -nr ' + H; + ${ + g; + s/[\t\n]/ /g; + '"${dep_re}"' + p; + }; + ')" + + { + IFS=':' read pkg archqual + read rel + read ver + read arches + read plats + } <<-EOF + ${dep} + EOF # Set the specified variables. for comp in pkg archqual rel ver arches plats; do |