tf5-5.0beta8/.git/
tf5-5.0beta8/.git/info/
tf5-5.0beta8/.git/logs/
tf5-5.0beta8/.git/logs/refs/heads/
tf5-5.0beta8/.git/objects/00/
tf5-5.0beta8/.git/objects/01/
tf5-5.0beta8/.git/objects/04/
tf5-5.0beta8/.git/objects/05/
tf5-5.0beta8/.git/objects/07/
tf5-5.0beta8/.git/objects/09/
tf5-5.0beta8/.git/objects/0a/
tf5-5.0beta8/.git/objects/0c/
tf5-5.0beta8/.git/objects/0e/
tf5-5.0beta8/.git/objects/12/
tf5-5.0beta8/.git/objects/13/
tf5-5.0beta8/.git/objects/14/
tf5-5.0beta8/.git/objects/16/
tf5-5.0beta8/.git/objects/17/
tf5-5.0beta8/.git/objects/19/
tf5-5.0beta8/.git/objects/1c/
tf5-5.0beta8/.git/objects/1d/
tf5-5.0beta8/.git/objects/1e/
tf5-5.0beta8/.git/objects/1f/
tf5-5.0beta8/.git/objects/20/
tf5-5.0beta8/.git/objects/21/
tf5-5.0beta8/.git/objects/23/
tf5-5.0beta8/.git/objects/27/
tf5-5.0beta8/.git/objects/29/
tf5-5.0beta8/.git/objects/2a/
tf5-5.0beta8/.git/objects/2b/
tf5-5.0beta8/.git/objects/2f/
tf5-5.0beta8/.git/objects/30/
tf5-5.0beta8/.git/objects/33/
tf5-5.0beta8/.git/objects/34/
tf5-5.0beta8/.git/objects/35/
tf5-5.0beta8/.git/objects/39/
tf5-5.0beta8/.git/objects/3c/
tf5-5.0beta8/.git/objects/3d/
tf5-5.0beta8/.git/objects/3f/
tf5-5.0beta8/.git/objects/40/
tf5-5.0beta8/.git/objects/41/
tf5-5.0beta8/.git/objects/42/
tf5-5.0beta8/.git/objects/44/
tf5-5.0beta8/.git/objects/46/
tf5-5.0beta8/.git/objects/47/
tf5-5.0beta8/.git/objects/48/
tf5-5.0beta8/.git/objects/4a/
tf5-5.0beta8/.git/objects/4d/
tf5-5.0beta8/.git/objects/4f/
tf5-5.0beta8/.git/objects/53/
tf5-5.0beta8/.git/objects/54/
tf5-5.0beta8/.git/objects/58/
tf5-5.0beta8/.git/objects/5b/
tf5-5.0beta8/.git/objects/5c/
tf5-5.0beta8/.git/objects/5e/
tf5-5.0beta8/.git/objects/5f/
tf5-5.0beta8/.git/objects/60/
tf5-5.0beta8/.git/objects/61/
tf5-5.0beta8/.git/objects/62/
tf5-5.0beta8/.git/objects/63/
tf5-5.0beta8/.git/objects/66/
tf5-5.0beta8/.git/objects/67/
tf5-5.0beta8/.git/objects/6c/
tf5-5.0beta8/.git/objects/6e/
tf5-5.0beta8/.git/objects/72/
tf5-5.0beta8/.git/objects/73/
tf5-5.0beta8/.git/objects/75/
tf5-5.0beta8/.git/objects/77/
tf5-5.0beta8/.git/objects/7a/
tf5-5.0beta8/.git/objects/7b/
tf5-5.0beta8/.git/objects/7c/
tf5-5.0beta8/.git/objects/7e/
tf5-5.0beta8/.git/objects/7f/
tf5-5.0beta8/.git/objects/81/
tf5-5.0beta8/.git/objects/84/
tf5-5.0beta8/.git/objects/86/
tf5-5.0beta8/.git/objects/87/
tf5-5.0beta8/.git/objects/88/
tf5-5.0beta8/.git/objects/8b/
tf5-5.0beta8/.git/objects/8c/
tf5-5.0beta8/.git/objects/8f/
tf5-5.0beta8/.git/objects/91/
tf5-5.0beta8/.git/objects/93/
tf5-5.0beta8/.git/objects/96/
tf5-5.0beta8/.git/objects/97/
tf5-5.0beta8/.git/objects/99/
tf5-5.0beta8/.git/objects/9a/
tf5-5.0beta8/.git/objects/9b/
tf5-5.0beta8/.git/objects/9c/
tf5-5.0beta8/.git/objects/9d/
tf5-5.0beta8/.git/objects/9e/
tf5-5.0beta8/.git/objects/a1/
tf5-5.0beta8/.git/objects/a3/
tf5-5.0beta8/.git/objects/a4/
tf5-5.0beta8/.git/objects/a6/
tf5-5.0beta8/.git/objects/a7/
tf5-5.0beta8/.git/objects/a8/
tf5-5.0beta8/.git/objects/a9/
tf5-5.0beta8/.git/objects/ab/
tf5-5.0beta8/.git/objects/ac/
tf5-5.0beta8/.git/objects/ae/
tf5-5.0beta8/.git/objects/b1/
tf5-5.0beta8/.git/objects/b2/
tf5-5.0beta8/.git/objects/b3/
tf5-5.0beta8/.git/objects/b7/
tf5-5.0beta8/.git/objects/b9/
tf5-5.0beta8/.git/objects/bb/
tf5-5.0beta8/.git/objects/bc/
tf5-5.0beta8/.git/objects/bd/
tf5-5.0beta8/.git/objects/bf/
tf5-5.0beta8/.git/objects/c0/
tf5-5.0beta8/.git/objects/c1/
tf5-5.0beta8/.git/objects/c2/
tf5-5.0beta8/.git/objects/c3/
tf5-5.0beta8/.git/objects/c5/
tf5-5.0beta8/.git/objects/c7/
tf5-5.0beta8/.git/objects/ca/
tf5-5.0beta8/.git/objects/ce/
tf5-5.0beta8/.git/objects/d1/
tf5-5.0beta8/.git/objects/d3/
tf5-5.0beta8/.git/objects/d4/
tf5-5.0beta8/.git/objects/d5/
tf5-5.0beta8/.git/objects/d8/
tf5-5.0beta8/.git/objects/d9/
tf5-5.0beta8/.git/objects/dc/
tf5-5.0beta8/.git/objects/dd/
tf5-5.0beta8/.git/objects/e1/
tf5-5.0beta8/.git/objects/e4/
tf5-5.0beta8/.git/objects/e5/
tf5-5.0beta8/.git/objects/e6/
tf5-5.0beta8/.git/objects/e7/
tf5-5.0beta8/.git/objects/e8/
tf5-5.0beta8/.git/objects/ea/
tf5-5.0beta8/.git/objects/eb/
tf5-5.0beta8/.git/objects/ed/
tf5-5.0beta8/.git/objects/ee/
tf5-5.0beta8/.git/objects/ef/
tf5-5.0beta8/.git/objects/f0/
tf5-5.0beta8/.git/objects/f4/
tf5-5.0beta8/.git/objects/f5/
tf5-5.0beta8/.git/objects/f6/
tf5-5.0beta8/.git/objects/f8/
tf5-5.0beta8/.git/objects/f9/
tf5-5.0beta8/.git/objects/fa/
tf5-5.0beta8/.git/objects/fb/
tf5-5.0beta8/.git/objects/fc/
tf5-5.0beta8/.git/objects/fd/
tf5-5.0beta8/.git/refs/heads/
tf5-5.0beta8/.git/refs/tags/
tf5-5.0beta8/autom4te.cache/
tf5-5.0beta8/macos/
tf5-5.0beta8/unix/
tf5-5.0beta8/win32/
;;; textutil.tf
;;; unix-like text utilities

/loaded __TFLIB__/textutil.tf

; Note: users should not rely on %_loaded_libs like this.  I can get away
; with this here only because this and /loaded are both internal to TF.
/if (_loaded_libs =/ "*{__TFLIB__/grep.tf}*") \
    /echo -e %% Warning: textutil.tf and grep.tf have conflicting defintions.%;\
/endif

/require lisp.tf


/def -i _grep = \
    /let _line=%; \
    /let _count=0%; \
    /while (tfread(_line) >= 0) \
        /test (%{*}) & (++_count, opt_c | tfwrite(_line))%; \
    /done%; \
    /test opt_c & echo(_count)%; \
    /return _count

; ... %| /fgrep [-cvi] <string>
/def -i fgrep = \
    /if (!getopts("cvi", 0)) /return 0%; /endif%; \
    /if (opt_i) \
        /let _pattern=$[tolower({*})]%; \
        /_grep (strstr(tolower(_line), _pattern) < 0) == opt_v%; \
    /else \
        /let _pattern=%*%; \
        /_grep (strstr(_line, _pattern) < 0) == opt_v%; \
    /endif

; ... %| /grep [-cvi] <glob>
/def -i grep = \
    /if (!getopts("cvi", 0)) /return 0%; /endif%; \
    /let _pattern=%*%; \
    /_grep (_line !/ _pattern) == opt_v

; ... %| /egrep [-cvi] <regexp>
/def -i egrep = \
    /if (!getopts("cvi", 0)) /return 0%; /endif%; \
    /if (opt_i) \
        /let _pattern=$[tolower({*})]%; \
        /_grep !regmatch(_pattern, tolower(_line)) == opt_v%; \
    /else \
        /let _pattern=%*%; \
        /_grep !regmatch(_pattern, _line) == opt_v%; \
    /endif


; /copyio <in_handle> <out_handle>
; copies lines from <in_handle> to <out_handle>.
/def -i copyio = \
    /let _in=%{1-i}%; \
    /let _out=%{2-o}%; \
    /let _line=%; \
    /while (tfread(_in, _line) >= 0) \
        /test tfwrite(_out, _line)%; \
    /done

; /readfile <file> %| ...
/def -i readfile = \
    /let _handle=%; \
    /test ((_handle := tfopen({1}, "r")) >= 0) & \
        (copyio(_handle, "o"), tfclose(_handle))

; ... %| /writefile <file>
/def -i writefile = \
    /let _handle=%; \
    /if (!getopts("a", 0)) /return 0%; /endif%; \
    /test ((_handle := tfopen({1}, opt_a ? "a" : "w")) >= 0) & \
        (copyio("i", _handle), tfclose(_handle))


; ... %| /head [-n<count>] [<handle>]
; outputs first <count> lines of <handle> or tfin.
/def -i head = \
    /if (!getopts("n#", 10)) /return 0%; /endif%; \
    /let _handle=%{1-i}%; \
    /let _line=%; \
    /while (tfread(_handle, _line) >= 0) \
        /if (--opt_n < 0) /break%; /endif%; \
        /test echo(_line)%; \
    /done


; ... %| /wc [-lwc] [<handle>]
; counts lines, words, and/or characters of text from <handle> or tfin.
/def -i wc = \
    /if (!getopts("lwc", 0)) /return 0%; /endif%; \
    /let _handle=%{1-i}%; \
    /let _lines=0%; \
    /let _words=0%; \
    /let _chars=0%; \
    /let _line=%; \
    /let _body=0%; \
    /if (!opt_l & !opt_w & !opt_c) /test opt_l:= opt_w:= opt_c:= 1%; /endif%; \
    /if (opt_l) /let _body=%_body, ++_lines%; /endif%; \
    /if (opt_w) /let _body=%_body, _words+=$$(/length %%_line)%; /endif%; \
    /if (opt_c) /let _body=%_body, _chars+=strlen(_line)%; /endif%; \
    /eval \
        /while (tfread(_handle, _line) >= 0) \
            /test %_body%%; \
        /done%; \
    /echo $[opt_l ? _lines : ""] $[opt_w ? _words : ""] $[opt_c ? _chars : ""]

; ... %| /tee <handle> %| ...
; copies tfin to <handle> AND tfout.
/def -i tee = \
    /let _line=%; \
    /while (tfread(_line) >= 0) \
        /test tfwrite({*}, _line), tfwrite(_line)%; \
    /done

; ... %| /fmt 
; copies input to output, with adjacent non-blank lines joined
/def -i fmt = \
    /let _line=%; \
    /let _text=%; \
    /while (tfread(_line) >= 0) \
        /if (_line =~ "" & _text !~ "") \
            /echo - %{_text}%; \
            /echo%; \
            /let _text=%; \
        /else \
            /let _text=%{_text} %{_line}%; \
        /endif%; \
    /done%; \
    /echo - %{_text}

; ... %| /uniq
; copies input to output, with adjacent duplicate lines removed
/def -i uniq = \
    /let _prev=%; \
    /let _line=%; \
    /while (tfread(_line) >= 0) \
        /if (_line !~ _prev) \
            /test echo(_line), _prev:=_line%; \
        /endif%; \
    /done

; ... %| /randline [<handle>]
; reads lines from <handle> or tfin, and copies one at random to tfout.
/def -i randline = \
    /let _in=%{1-i}%; \
    /let _line=%; \
    /let _selection=%; \
    /let _lines=0%; \
    /while (tfread(_in, _line) >= 0) \
        /test rand(++_lines) | (_selection := {*})%; \
    /done%; \
    /result _selection