aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorGravatar Paweł Zuzelski <pawelz@pld-linux.org>2010-03-29 08:25:17 +0200
committerGravatar Paweł Zuzelski <pawelz@pld-linux.org>2010-03-29 08:25:17 +0200
commitb9b1422173211d50edb273f93fe3fcc025646dc6 (patch)
treec62e5a6cb2d1a03b2b83de47654dda3da6dda070 /examples
parentd65308d54619c41f7c72266a549ccd42ce826f11 (diff)
Make it more portable (now it works also with ksh)
echo behaviour differs across POSIX shells. Some shells expands strings like '\\n' in echo built-in command (ksh), some does not (bash). According to [1] both behaviours are correct. That means "echo" is not portable for strings containing backslashes. [1] advises to use printf instead. [1] http://www.opengroup.org/onlinepubs/009695399/utilities/echo.html
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/data/scripts/formfiller.sh70
1 files changed, 35 insertions, 35 deletions
diff --git a/examples/data/scripts/formfiller.sh b/examples/data/scripts/formfiller.sh
index b977235..9bac495 100755
--- a/examples/data/scripts/formfiller.sh
+++ b/examples/data/scripts/formfiller.sh
@@ -95,35 +95,35 @@ then
action="new"
fi
-dumpFunction='function dump() {
- var rv="";
- var allFrames = new Array(window);
- for(f=0;f<window.frames.length;f=f+1) {
- allFrames.push(window.frames[f]);
- }
- for(j=0;j<allFrames.length;j=j+1) {
- try {
- var xp_res=allFrames[j].document.evaluate("//input", allFrames[j].document.documentElement, null, XPathResult.ANY_TYPE,null);
- var input;
- while(input=xp_res.iterateNext()) {
- var type=(input.type?input.type:text);
- if(type == "text" || type == "password") {
- rv += input.name + "(" + type + "):" + input.value + "\\n";
- }
- else if(type == "checkbox" || type == "radio") {
- rv += input.name + "{" + input.value + "}(" + type + "):" + (input.checked?"ON":"OFF") + "\\n";
- }
- }
- xp_res=allFrames[j].document.evaluate("//textarea", allFrames[j].document.documentElement, null, XPathResult.ANY_TYPE,null);
- var input;
- while(input=xp_res.iterateNext()) {
- rv += input.name + "(textarea):" + input.value + "\\n";
- }
- }
- catch(err) { }
- }
- return rv;
-}; '
+dumpFunction="function dump() { \
+ var rv=''; \
+ var allFrames = new Array(window); \
+ for(f=0;f<window.frames.length;f=f+1) { \
+ allFrames.push(window.frames[f]); \
+ } \
+ for(j=0;j<allFrames.length;j=j+1) { \
+ try { \
+ var xp_res=allFrames[j].document.evaluate('//input', allFrames[j].document.documentElement, null, XPathResult.ANY_TYPE,null); \
+ var input; \
+ while(input=xp_res.iterateNext()) { \
+ var type=(input.type?input.type:text); \
+ if(type == 'text' || type == 'password') { \
+ rv += input.name + '(' + type + '):' + input.value + '\\\\n'; \
+ } \
+ else if(type == 'checkbox' || type == 'radio') { \
+ rv += input.name + '{' + input.value + '}(' + type + '):' + (input.checked?'ON':'OFF') + '\\\\n'; \
+ } \
+ } \
+ xp_res=allFrames[j].document.evaluate('//textarea', allFrames[j].document.documentElement, null, XPathResult.ANY_TYPE,null); \
+ var input; \
+ while(input=xp_res.iterateNext()) { \
+ rv += input.name + '(textarea):' + input.value + '\\\\n'; \
+ } \
+ } \
+ catch(err) { } \
+ } \
+ return rv; \
+}; "
insertFunction="function insert(fname, ftype, fvalue, fchecked) { \
var allFrames = new Array(window); \
@@ -169,16 +169,16 @@ then
sed 's/^\(.\+\)$/<{br}>\1/' | \
tr -d '\n' | \
sed 's/<{br}>%{>\([^(]\+(\)\(radio\|checkbox\|text\|textarea\|password\)):<}%/\\n\1\2):/g'`
- echo "${fields}" | \
+ printf '%s\n' "${fields}" | \
sed -n -e "s/\([^(]\+\)(\(password\|text\|textarea\)\+):[ ]*\(.\+\)/js $insertFunction; insert('\1', '\2', '\3', 0);/p" | \
sed -e 's/@/\\@/g;s/<{br}>/\\\\n/g' > $fifo
- echo "${fields}" | \
+ printf '%s\n' "${fields}" | \
sed -n -e "s/\([^{]\+\){\([^}]*\)}(\(radio\|checkbox\)):[ ]*\(.\+\)/js $insertFunction; insert('\1', '\3', '\2', \4);/p" | \
sed -e 's/@/\\@/g' > $fifo
elif [ "$action" = "once" ]
then
tmpfile=`mktemp`
- echo "js "$dumpFunction" dump(); " | \
+ printf 'js %s dump(); \n' "$dumpFunction" | \
socat - unix-connect:$socket | \
sed -n '/^[^(]\+([^)]\+):/p' > $tmpfile
${editor} $tmpfile
@@ -191,10 +191,10 @@ then
sed 's/^\(.\+\)$/<{br}>\1/' | \
tr -d '\n' | \
sed 's/<{br}>%{>\([^(]\+(\)\(radio\|checkbox\|text\|textarea\|password\)):<}%/\\n\1\2):/g'`
- echo "${fields}" | \
+ printf '%s\n' "${fields}" | \
sed -n -e "s/\([^(]\+\)(\(password\|text\|textarea\)\+):[ ]*\(.\+\)/js $insertFunction; insert('\1', '\2', '\3', 0);/p" | \
sed -e 's/@/\\@/g;s/<{br}>/\\\\n/g' > $fifo
- echo "${fields}" | \
+ printf '%s\n' "${fields}" | \
sed -n -e "s/\([^{]\+\){\([^}]*\)}(\(radio\|checkbox\)):[ ]*\(.\+\)/js $insertFunction; insert('\1', '\3', '\2', \4);/p" | \
sed -e 's/@/\\@/g' > $fifo
rm -f $tmpfile
@@ -223,7 +223,7 @@ else
# login(text):
# passwd(password):
#
- echo "js "$dumpFunction" dump(); " | \
+ printf 'js %s dump(); \n' "$dumpFunction" | \
socat - unix-connect:$socket | \
sed -n '/^[^(]\+([^)]\+):/p' >> $keydir/$domain
fi