[hackers] diri: new tip (= 54)

From: Anselm R. Garbe <arg_AT_suckless.org>
Date: Tue, 06 Feb 2007 10:40:01 +0100

changeset: 54:f53076de4387
tag: tip
parent: 53:df6ec99477fc
parent: 52:42a72feef5a3
user: arg_AT_suckless.org
date: Tue Feb 06 10:39:09 2007 +0100
description:
merged new version

changeset: 53:df6ec99477fc
parent: 51:8e0c72a652de
user: arg_AT_suckless.org
date: Tue Feb 06 10:38:42 2007 +0100
files: show.rc
description:
applied Kris' awk menu version (thanks to Kris) - this increased the speed drastically

diff -r 42a72feef5a3 -r f53076de4387 show.rc
--- a/show.rc Tue Feb 06 10:27:48 2007 +0100
+++ b/show.rc Tue Feb 06 10:39:09 2007 +0100
@@ -2,30 +2,28 @@
 . /var/www/dirirc
 
 fn menu {
- level=`{expr $1 + 1}
- if(test $level -le $#paths)
- sub=$paths($level)
- if not
- sub=()
- echo '<ul>'
- for(file in $2/*) {
- file=`{cleanname $file}
- base=`{basename $file}
- if(echo $base | grep -s '^[a-zA-Z0-9_]+$') {
- bname=`{echo $base | sed 's/^[0-9]+_//; s/_/ /g'}
- if(test -d $file)
- bname=$"bname/
- if(test $sub && ~ $base $sub) {
- echo '<li>'^$"bname^''
- if(test -d $file)
- @{menu $level $file}
- echo '</li>'
- }
- if not
- echo '<li>'^$"bname^'</li>'
- }
- }
- echo '</ul>'
+ ls -F $1 | sed 's,^\./,,' | awk -v urlbase'='$ADDRESS/$SHOW/ '
+ BEGIN { print "<ul>" }
+ END { print "</ul>" }
+
+ /^([a-zA-Z0-9_]+[\/*]?)+$/ {
+ isdir = match($0, "/$");
+ sub("[*/]$", "");
+ bname = $0;
+ sub("^(.*/)?([0-9]+_)?", "", bname);
+ gsub("_", " ", bname);
+ if(isdir)
+ bname = bname "/"
+ sub("[^/]+$", "")
+ path = $0 bname
+
+ if(isdir && match(ENVIRON["PATH_INFO"]"/", "^"path)) {
+ print "<li><a href=\"" urlbase path "\" class=\"current\">" bname "</a>"
+ system("rc -c ''menu " path "''");
+ }else
+ print "<li><a href=\"" urlbase path "\">" bname "</a>"
+ print "</li>"
+ }' | awk '{ print "\t" $0 }'
 }
 
 if(test $PATH_INFO && echo $PATH_INFO | grep -v -s '^[a-zA-Z0-9_/]+$') {
@@ -36,7 +34,7 @@ if(! test $PATH_INFO)
 if(! test $PATH_INFO)
         PATH_INFO=''
 if not
- PATH_INFO=`{cleanname $PATH_INFO | sed 's/^.//'}
+ PATH_INFO=`{cleanname $PATH_INFO | sed 's,^/,,'}
 if(test -d $DIRIDIR/$PATH_INFO) {
         file=`{find $DIRIDIR/$PATH_INFO -type f | grep '/[a-zA-Z0-9_]+$' | sort | sed 1q}
         if(test $file && test -f $file) {
@@ -45,11 +43,6 @@ if(test -d $DIRIDIR/$PATH_INFO) {
                 PATH_INFO=`{echo $file | sed $arg}
         }
 }
-tmp=$ifs
-ifs='/
-'
-paths=`{echo $PATH_INFO}
-ifs=$tmp
 title=`{basename $PATH_INFO | sed 's/^[0-9]+_//; s/_/ /g'}
 cat <<END
 Cache-Control: no-cache
@@ -105,7 +98,7 @@ Content-Type: text/html
                 <div id="menu">
 END
 cd $DIRIDIR
-menu 0 .
+menu .
 cat <<END
                 </div>
                 <div id="page">
Received on Tue Feb 06 2007 - 10:40:02 UTC

This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 15:54:55 UTC