summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2014-10-25 19:05:42 (EDT)
committer P. J. McDermott <pj@pehjota.net>2014-10-25 19:05:42 (EDT)
commit8f4241380815a6fc553e6a5e7fd71b56c89971b6 (patch)
treea2cc3f52e6c0da84a93e3afb8ee3463de20ab9d8
parentbefee89010829b36b9fd16bca90b67ff2c42179f (diff)
parse_dep(): Rewrite parsing code to use sed's ERE
-rw-r--r--lib/deps.sh70
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