🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.unix.programmer
1 messages
1 total messages Started by Rick Hohensee Tue, 19 Feb 2002 04:12
simple text outline processor script
#3351
Author: Rick Hohensee
Date: Tue, 19 Feb 2002 04:12
92 lines
4886 bytes
# 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.

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.

cLIeNUX also has the more general \"walk\" directory recurser script.
"
else
        TOLrecurse () {
        local f
        for f in $*                                     ;do
                if test ! -L $f -a ! -d $f ; then
                        if  file $f | grep text > /dev/null ;then
                                echo "$indent$f FILE " >> $user/outline
                                ed $f <<!
                                ,s/^/$indent    /
                                ,W $user/outline
                                q
!
                        fi
                fi
                if test -d $f -a ! -L $f; then
                        echo "$indent$f ### DIRECTORY " >> $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.

# LAAETTR...
#  write-a-book version
#  brief outline version, N lines limit per file (3 more characters
#       in the ed part... 1,10W )
#  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
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads