]> git.plutz.net Git - serve0/blobdiff - list.sh
Merge commit 'b931bbd0c30907b9cc956d3707b26b449bf41f76'
[serve0] / list.sh
diff --git a/list.sh b/list.sh
index 2384da842185b41cc40d2aa6029055de801ad0ae..94a926465f40f161474b4ef364ab7f1744065c3e 100755 (executable)
--- a/list.sh
+++ b/list.sh
@@ -6,12 +6,6 @@
 
 list_item() {
   local meta file link name
-  eval "$LOCAL_META"
-  meta="${1}";
-
-  read_meta <<-EOF
-       $meta
-       EOF
 
   if [ "${META_NAME%/}" != "${META_NAME}" ]; then
     printf '[a .list .dir href="%s?%s" . %s]' \
@@ -61,7 +55,7 @@ list_item() {
 )"
 
 list_fullname(){
-  local short="$(UNSTRING "${1%${CR}}")" file
+  local short="$1" file
   file="$(printf %s\\n "$_DATA/$ITEM/$short".*)"
   file="${file%%${BR}*}"
   [ -e "$file" ] && printf %s\\n "${file#${_DATA}/${ITEM}/}"
@@ -87,20 +81,14 @@ list_filter(){
 }
 
 list_order(){
-  local fm fn fn al length ln h w t c name buffer l
+  local fm fn fn al length ln h w t c name group o buffer l
 
   if [ $ORDER = Name ]; then
     sort -k6
   elif [ $ORDER = Group ]; then
-    sed -E '
-      :X
-      s;^([^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^ 0-9]*)-([0-9a-zA-Z_-]{11}\r|ph[0-9a-f]{13}\r|[0-9]{8}\r)(.*)$;\1-\r\3 \2\n;;
-      t;
-      s;^([^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^ 0-9]*)([0-9]+)(.*)$;\1\r\3 \2;;
-      tX;' \
-    | { sort -n -k7 -k8 -k9 -k10 -k11 |sort -s -k6,6 ; echo '0 0 0 tags= comment= _'; } \
-    | while read -r length w h t c name; do
-      if [ "${ln%% *}" = "${name%% *}" ]; then
+    { sort -n -k8 -k6,6 |sort -s -k7,7 ; echo '0 0 0 tags= comment= _'; } \
+    | while read -r length w h t c name group o; do
+      if [ "${ln%% *}" = "${group}" ]; then
         al=$((al + length))
         buffer="${buffer}${BR}$length  $w      $h      $t      $c      $name"
       else
@@ -110,15 +98,15 @@ list_order(){
         al="$length"
         buffer="$length        $w      $h      $t      $c      $name"
       fi
-      ln="$name"
+      ln="$group"
     done \
-    | sort -s -n -k1,1 |sed -E 's;^[0-9]+\t;;;' \
-    | sed -E ':X s;^([^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\r]*)\r([^ ]*) ([^ ]+)( .*)?$;\1\3\2\4;; tX'
+    | sort -s -n -k1,1 |sed -E 's;^[0-9]+\t;;;'
   elif [ $ORDER = Length ]; then
     sort -sn -k1
   elif [ $ORDER = Date ]; then
     while read -r fm; do
-      fn="$(list_fullname "${fm##*     }")"
+      fn="${fm%${CR}   *}"
+      fn="$(list_fullname "${fn##*     }")"
       printf '%i       %s\n' \
              "$(stat -c %Y "$fn")" "${fm}"
     done \
@@ -168,12 +156,20 @@ list_paginate() {
   local page i c n end qry
   page="$(GET p |grep -axE '[0-9]+' || printf 1)"; c=1
   end=$((page + LISTSIZE))
-  qry="${w_refuri#*\?}"; qry="${qry#&#112;&#61;*&#38;}"
+  eval "$LOCAL_META"  # localize vars from db_meta
 
   printf '[div .itemlist '
-  while read -r i; do
+  while :; do
+    if [ $c -lt $page ]; then
+      read -r discard || break
+    elif [ $c -ge $end ]; then
+      c=$((c + $(wc -l) ))
+      break
+    else
+      read_meta || break
+      list_item
+    fi
     c=$((c + 1))
-    [ $c -gt $page -a $c -le $end  ] && list_item "$i"
   done
   printf ']'
 
@@ -185,8 +181,8 @@ list_paginate() {
   for n in $( seq 1 $end ); do
     c=$(( (n - 1) * LISTSIZE + 1 ))
     [ $c = $page ] \
-    && printf '[a .page .current href="%s" %s]' "?p=${c}&${qry}" "$n" \
-    || printf '[a .page href="%s" %s]' "?p=${c}&${qry}" "$n"
+    && printf '[a .page .current href="?p=%i&%s" %i]' "${c}" "${QUERY_STRING#p=*&}" "$n" \
+    || printf '[a .page          href="?p=%i&%s" %i]' "${c}" "${QUERY_STRING#p=*&}" "$n"
   done
   printf ']'
 }