From 8f4241380815a6fc553e6a5e7fd71b56c89971b6 Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Sat, 25 Oct 2014 19:05:42 -0400 Subject: parse_dep(): Rewrite parsing code to use sed's ERE --- 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\]] [] - - 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 -- cgit v0.9.1