# cLIeNUX outline       Public Domain 

# Due to the way I've probably pasted this into my mailer,    
# if you got this off the net as text you may need to convert some
# spaces to tabs.  ,s/^/$indent    /    and    indent=$indent" "
# below each have one tab...   ^^^^\tab                   tab/^     

user=~

if test $# -eq 0 ; then
echo "
You didn't give outline any directory arguments. That's not so awful, 
but it's a handy case to stick this help response on.

cLIeNUX outline allows a hierarchical filesystem to be used as a
rudimentry outline processor. outline doesn't generate nested section
tags, like A.3.c or what have you. It does indenting and
directory-names-as-headings. You can have a dedicated outline, or extract
one from something with some larger purpose. outline makes a single
outline-indented textfile from all the textfiles in the directory tree(s)
given to it as a(n) argument(s). As initially implemented, a text file is
any file that the unix utility \"file\"  describes with words including
the string \"text\". This includes html, C sourcecode and so on. For
example, cLIeNUX's version of \"file\" reports
			
	HTML document text
				when it thinks it found html, so the
outline generated will include such html files. The outline file will be
found as ~/outline when outline is done. Due to the hackness of that
little expedient, one user can only sensibly generate one outline on a
machine at a time, which I don't expect to be terribly problematic.
If outline's first argument is \"brief\", ala

	outline brief sourcedir docdir otherdir	
							then only the
first four lines of each directory will be outlined. Run outline on a
directory tree with a lot of commands in it, and you should get an outline
containing all the scripts and docs but none of the binaries.

cLIeNUX also has the more general \"walk\" directory recurser script. 

"
else

	if test $1 == "brief" ;then
		BRIEF=true
	else
		BRIEF=
	fi

	TOLrecurse () {
	local f
	for f in $*					;do
		if test ! -L $f -a ! -d $f ; then
			if  file $f | grep text > /dev/null ;then
				if test $BRIEF  ;then
					echo "$indent$f " >> $user/outline
					ed $f <<!
					,s/^/$indent	/
					1,4W $user/outline
					Q
!
				else
					echo "$indent$f " >> $user/outline
					ed $f <<!
					,s/^/$indent	/
					,W $user/outline
					q
!
				fi
			fi
		fi
		if test -d $f -a ! -L $f; then
			echo "$indent$f	>>>>> "	>> $user/outline
			indent=$indent"	"
			cd $f
				TOLrecurse *
			cd ..
			indent=${indent:0:${#indent}-1}	
	        fi
	done
	}


	rm $user/outline
	TOLrecurse $*


fi

#As far as a sh besides Bash, the tricky stuff outline needs from a shell is
#parameter expansions capable of an action like Perl's chomp, which is
# a variously skinnable cat, and recursive instantiation of locals, which 
# latter I think even ash does. As to chomp, you can keep the indent
# with a case and a nesting count, thus not needing chomp, for example.

#outline is dependant on GNU Bash, ed, file, and grep, and /dev/null.
#outline is a small script and lends itself to specialized mods, except
#that it's recursive, and thus is tricky code flow-control-wise, but if you
#just change test cases and stuff it should be fun and quite handy for the
#non-theoretically-inclined. I use it a lot. It gives a big-picture-ness
#to things that is quite helpful.

# LAAETTR...
#  write-a-book version
#  brief outline version, N lines limit per file (3 more characters 
#	in the ed part... 1,10W, DONE, "brief" argument. )
#  suffix-based for C, include .c and .s but not .i or .o
#  webtangler version
#  Linux help version
#  nested section tags generation/propagation 
#  do something cute with symlinks
#  yadda yadda

# Copyright 2002 Rick Hohensee
