diff options
author | KatolaZ <katolaz@freaknet.org> | 2020-01-11 07:09:30 +0000 |
---|---|---|
committer | KatolaZ <katolaz@freaknet.org> | 2020-01-11 07:09:30 +0000 |
commit | 7acd17b36e16815a1a4f0e304e1ed979b2bdded0 (patch) | |
tree | 50d7c91c4699b83f65bc637f2145558cccfead21 | |
parent | 5546d8dd8efb00d05dc463ae01d011c591fd11ea (diff) |
search_cgi: move results printout to a function
-rwxr-xr-x | search_cgi | 33 |
1 files changed, 22 insertions, 11 deletions
@@ -1,5 +1,7 @@ #!/bin/sh +## function definitions ## + ##func printlines (){ printf "<ul>\\n" @@ -12,7 +14,6 @@ printlines (){ -query=$(echo "${QUERY_STRING}" | sed -E 's/["\\$^?<>@;*`|/()]//g') ##func print_head(){ @@ -38,16 +39,9 @@ print_foot(){ echo "</body></html>" } -terms=$(echo "${query}" | tr '&' '\n' | grep -E "^query=" | sed -E 's/^query=//') -qtype=$(echo "${query}" | tr '&' '\n' | grep -E "^type=" | sed -E 's/^type=//') - -print_head - -if [ -n "$terms" ]; then - search=$(echo "$terms" | sed -E 's/\+/ /g') - numres=0 - lines=$(./search_repo ./ "$search" 2>&1 ) - for line in $lines; do +##func +print_results(){ + for line in $@; do case "$line" in "--URL") #echo "$line<br>" @@ -109,6 +103,23 @@ if [ -n "$terms" ]; then printf "<div>No results in readme files </div>\\n" fi fi +} + + +## main loop ## + +query=$(echo "${QUERY_STRING}" | sed -E 's/["\\$^?<>@;*`|/()]//g') + +terms=$(echo "${query}" | tr '&' '\n' | grep -E "^query=" | sed -E 's/^query=//') +qtype=$(echo "${query}" | tr '&' '\n' | grep -E "^type=" | sed -E 's/^type=//') + +print_head + +if [ -n "$terms" ]; then + search=$(echo "$terms" | sed -E 's/\+/ /g') + numres=0 + lines=$(./search_repo ./ "$search" 2>&1 ) + print_results $lines fi print_foot |