2 # Copyright (C) 2007 Alejandro Mery <amery@geeks.cl>
4 # More information can be found in the files COPYING and README.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; version 3 of the License. A copy of the
9 # GNU General Public License can be found in the file COPYING.
24 usage: $progname [-V|--version]
25 $progname -m <mode> [-o <format>] [OPTIONS] [locations...]
29 -q|--quiet not verbose
30 -R|--root directory to use as root
33 query mode to use (default:list)
35 output format to use (default:plain)
39 * formats: plain, html
41 * formats: plain, html
48 -B|--base relative path to this location (/)
49 -h|--home name to give to the base (home)
53 adtree_echo
() { [ -z "$verbose" ] ||
echo -e $
* >&2 ; }
54 adtree_warn
() { echo -e "WARN: $@" >&2 ; }
55 adtree_error
() { echo -e "ERROR: $@" >&2 ; }
57 # analyse the given options
58 shortopts
='Vvqnldm:o:R:b:h:'
59 longopts
='version,verbose,quiet,mode:,output:,root:,base:,home:'
61 options
=$
( getopt
-o "$shortopts" -l "$longopts" -- "$@" )
67 # load new arguments list
68 eval set -- "$options"
70 while [ $# -gt 0 ]; do
75 Copyright (C) 2007 Alejandro Mery <amery@geeks.cl>
87 navigation|list|deps|makefile
)
89 *) adtree_error
"unknown mode '$1'"
108 *) adtree_error
"unknown output format '$1'"
116 *) adtree_error
"unknown output format '$1'"
134 if [ -z "$mode" ]; then
135 adtree_error
"no mode choosen"
140 # if not folder was given, use .
141 [ $# -gt 0 ] ||
set -- .
143 if [ -n "$root" ]; then
144 if [ -d "$root" ]; then
145 adtree_echo
"root: $root"
147 adtree_error
"$root: invalid root"
154 root
=$
( cd "$root"; pwd -P )
157 trap 'echo "Got SIGINT (Crtl-C). Aborting." >&2 ; rm -rf '$tmpfile'; exit 1' INT
160 local source="$1" target
= name
=
161 local filename
= folder
= path
=
163 name
="${source#$root/}"
164 if ! grep -q "^$name\$" $tmpfile; then
165 echo "$name" >> $tmpfile
167 filename
="${source##*/}"; name
="${filename%.txt}"
168 path
="${source%/*}"; folder
="${path##*/}"
172 if [ "$name" == "$folder" ]; then
173 target
="$path/index.html"
175 target
="$path/$name.html"
182 echo "${target#$root/}"
187 local source="$1" path
= name
= dep
=
189 name
="${source#$root/}"
190 if ! grep -q "^$name\$" $tmpfile; then
191 echo "$name" >> $tmpfile
193 if [ -r "$source" ]; then
195 adtree_echo
"$name: list of dependencies"
197 sed -n -e "s,^\(include\|include1\)::\(.*\)\[\(.*\)\].*$,\2,p" "$source" |
while read dep
; do
204 adtree_warn
"$name: include file not found"
210 local source="$1" html
=
211 local filename
= name
= path
=
214 filename
="${source##*/}"; name
="${filename%.txt}"
215 if [ "$filename" != "$source" ]; then
219 if [ "$name" == "${path##*/}" ]; then
220 html
="${path:+$path/}index.html"
222 html
="${path:+$path/}$name.html"
225 if [ -s "$path/style.css" ]; then
226 style
="${path:+$path/}style.css"
230 ${html#$root/}: ${source#$root/} ${style#$root/} $( $0 -dR "$root" -- "$source" | tr '\n' ' ' )
236 list|deps|navigation
)
237 for x
; do if [ -e "$x" ]; then
238 if [ -d "$x/" ]; then
239 x
=$
( cd "$x"; pwd -P )
242 [ "$x" != "$f" ] || x
="$PWD/$f"
244 x
="$( cd ${x%/*}; pwd -P )/$f"
248 list
) $0 -dR "$root" -- "$x" >> "$tmpfile"
249 find "$x" -type f
-name '*.txt' |
while read f
; do
253 find "$x" -type f
-name '*.txt' |
while read f
; do
261 "$0" -lR "$root" -- "$@" |
while read x
; do