summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKatolaZ <[email protected]>2020-01-11 07:09:30 +0000
committerKatolaZ <[email protected]>2020-01-11 07:09:30 +0000
commit7acd17b36e16815a1a4f0e304e1ed979b2bdded0 (patch)
tree50d7c91c4699b83f65bc637f2145558cccfead21
parent5546d8dd8efb00d05dc463ae01d011c591fd11ea (diff)
search_cgi: move results printout to a function
-rwxr-xr-xsearch_cgi33
1 files changed, 22 insertions, 11 deletions
diff --git a/search_cgi b/search_cgi
index b6dccfe..5302e3a 100755
--- a/search_cgi
+++ b/search_cgi
@@ -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