X-Git-Url: http://git.plutz.net/?p=cgilite;a=blobdiff_plain;f=misc.sh;h=43edfcf70fc88dfc96dfece9036e52ef6851d69b;hp=54c3dc67f68c83ed21ab45907bf295f6d0a4f2eb;hb=d849a531488425d7f86afad48eaa98e14956958f;hpb=203fb52bb5b1462dc65678208a9a0eb5f97a0180 diff --git a/misc.sh b/misc.sh index 54c3dc6..43edfcf 100755 --- a/misc.sh +++ b/misc.sh @@ -17,6 +17,9 @@ # You should have received a copy of the GNU Affero General Public License # along with shcgi. If not, see . +BR=' +' + data_dirs(){ # set up directories for object storage @@ -30,25 +33,25 @@ data_dirs(){ validate(){ # print value if value matches regex; otherwise print default value="$1" - regex="$(printf %s\\n "$2" \ - | sed -r 's;(^|[^\\]+)((\\\\)+)/;\1\2\\/;g; s;(^|[^\\])/;\1\\/;g; s;(^|[^\\]+)((\\\\)+)/;\1\2\\/;g; s;(^|[^\\])/;\1\\/;g;' - )" # ^^ escape only unescaped slash characters for later insertion + regex="$(printf %s\\n "$2" | sed -r ':X;s;(^|[^\\])((\\\\)*)/;\1\2\\/;g;tX')" + # ^^ escape only unescaped slash characters for later insertion default="$3" printf %s\\n "${value}" \ - | sed -rn "2q; /^(${regex})\$/{p;q}; a${default}" + | sed -rn "2q; /^(${regex})\$/{p;q}; a${default} + " } invalidate(){ # print default if value matches regex; otherwise print value value="$1" - regex="$(printf %s\\n "$2" \ - | sed -r 's;(^|[^\\]+)((\\\\)+)/;\1\2\\/;g; s;(^|[^\\])/;\1\\/;g; s;(^|[^\\]+)((\\\\)+)/;\1\2\\/;g; s;(^|[^\\])/;\1\\/;g;' - )" # ^^ escape only unescaped slash characters for later insertion + regex="$(printf %s\\n "$2" | sed -r ':X;s;(^|[^\\])((\\\\)*)/;\1\2\\/;g;tX')" + # ^^ escape only unescaped slash characters for later insertion default="$3" printf %s\\n "${value}" \ - | sed -rn "2q; /^(${regex})\$/{bd}; p;q; :d;a${default}" + | sed -rn "2q; /^(${regex})\$/{bX}; p;q; :X;a${default} + " } declare -A item_name