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/
/set savehist_version=$Id: savehist.tf,v 35000.5 2004/08/04 18:31:51 hawkeye Exp $
;;;; Save/restore world histories

;;;; Typical usage in .tfrc:
; /addworld ...
; ...
; /set savehist_dir=~/tf-hist
; /load_histories
; /repeat -0:10 i /save_histories


/loaded __TFLIB__/savehist.tf

/if (systype() !~ "unix") \
    /echo -e %% Warning: savehist.tf may not work on non-unix systems.%; \
/endif

/require textutil.tf
/require textencode.tf
/require lisp.tf

/if (savehist_dir =~ "") /set savehist_dir=~/tf-hist%; /endif

;; /save_histories [-lig]
;; saves all world histories, and optionally local/input/global.  If none of
;; -lig are given, -i is assumed.
/def -i save_histories = \
    /if (!getopts("lig", 0)) /return 0%; /endif%; \
    /if (!opt_l | !opt_i | !opt_g) /let opt_i=1%; /endif%; \
;   %savehist may appear on status bar
    /set savehist=H%; \
    /if (opt_l) /save_history -l%; /endif%; \
    /if (opt_i) /save_history -i%; /endif%; \
    /if (opt_g) /save_history -g%; /endif%; \
;   (unnamedN) worlds won't show up without /listworlds -u
    /quote -S /~save_histories `/listworlds -s%; \
    /unset savehist

/def -i ~save_histories = \
;   /_echo %1%; \
    /save_history -w%1

/def -i load_histories = \
    /echo -e %% Loading all histories...%; \
;   /let old_status_fields=%status_fields%; \
;   /set _savehist=%; \
;   /set status_fields=$[replace("@world", "_savehist", status_fields)]%; \
    /set _loaded_histories=%; \
    /let _histories=$(/quote -S -decho !\
	cd $[filename(savehist_dir)] && echo `ls -1 l i g w* 2>/dev/null`)%; \
    /if (_histories =~ "") \
	/echo -e %% %0: no history files found in "%savehist_dir".%; \
    /else \
	/mapcar /~load_histories %_histories%; \
	/echo -e %% Loaded histories: %_loaded_histories%; \
    /endif%; \
;    /set status_fields=%old_status_fields%; \
    /unset _loaded_histories

/def -i ~load_histories = \
    /let ehist=%1%; \
    /let hist=$[textdecode(ehist)]%; \
;   /set _savehist=%hist%; \
    /let file=%savehist_dir/%ehist%; \
;   Compatibility with optional cchan.tf
    /if (regmatch("w(([^:]+):(.*))$", hist) & ismacro("cchan_addworld") & \
	world_info({P1}, "name") =~ "" & \
	world_info({P2}, "type") =/ "*.cchan.*") \
	    /cchan_addworld $(/listworlds -s %P2):%P3%; \
    /endif%; \
;    /echo -e - Loading history: %hist%; \
    /if /load_history -%hist%; /then \
	/set _loaded_histories=%_loaded_histories %hist%; \
    /endif

;; /set_savehist_last <ehist> <hist>
/def -i set_savehist_last = \
    /set savehist_last_%1=$[regmatch("^[0-9]+", $(/recall -%2 #/1)) & {P0}]

/def -i savehist_args = \
    /if (!regmatch("^-([lig]|w(.+))$", {-1})) \
	/echo -e %% usage: %1 {-l|-i|-g|-w<world>}%; \
	/return 0%; \
    /endif%; \
    /set savehist_hist=%P1%; \
    /let world=%P2%; \
    /if (world !~ "" & world_info(world, "name") =~ "") \
	/echo -e %% %1: no world %world%; \
	/return 0%; \
    /endif%; \
    /return 1

/def -i _hist_write = \
    /let _line=%; \
    /while (tfread('i', _line) >= 0) \
	/test tfwrite({1}, encode_attr(_line))%; \
    /done


; /save_history {-l|-i|-g|-w<world>}
/def -i save_history = \
    /if /!savehist_args %0 %*%; /then /return 0%; /endif%; \
    /let hist=%savehist_hist%; \
    /let ehist=$[textencode(hist)]%; \
    /let dir=$[filename(savehist_dir)]%; \
    /let file=%dir/%ehist%; \
    /let first=%; \
    /test first:=savehist_last_%ehist + 1%; \
    /recall -%hist %{first}- %| /let count=%?%; \
    /if (!count) /return 1%; /endif%; \
    /setenv _file=%file%; \
    /setenv _dir=%dir%; \
;   if appending to file would give it more than 10% extra lines, truncate it
    /let filesize=savehist_filesize_%ehist%; \
    /histsize -%hist %| /let max=%{?}%; \
    /if /test %{filesize}%; /then \
;	The filesize is cached, and we'll assume the directory exists, avoiding
;	potentially expensive shell calls.
	/test %{filesize} := %{filesize} + count%; \
    /else \
;	Filesize is unknown; this must be the first call to save_history for
;	this history.  We must make sure the dir exists and get the filesize.
	/set %{filesize}=0%; \
	/quote -S -decho %% !test -d $$_dir || mkdir $$_dir%; \
	/if ({?} != 0) \
	    /unset _dir%; \
	    /unset _file%; \
	    /return%; \
	/endif%; \
	/quote -S /test %{filesize}:=+"!"wc -l %_file""%; \
    /endif%; \
    /let mode=a%; \
    /if /test %{filesize} + count > max * 1.1%; /then \
	/if (count >= max) \
	    /test count := max%; \
	    /let mode=w%; \
	    /test %{filesize} := 0%; \
	/else \
	    /setenv _tmp=%_dir/tfhist-$[getpid()]%; \
	    /quote -S -decho %% !touch $$_tmp && chmod go-rwx $$_tmp && \
		tail -$[max-count] $$_file > $$_tmp && mv $$_tmp $$_file%; \
	    /if ({?} == 0) \
		/test %{filesize} := max - count%; \
	    /endif%; \
	    /unset _tmp%; \
	/endif%; \
    /endif%; \
;   append the new lines to the file
    /let old_max_iter=%max_iter%; \
    /set max_iter=0%; \
    /let out=%; \
    /if ((out := tfopen(_file, mode)) >= 0) \
	/if /test !%{filesize}%; /then \
	    /quote -S -decho %% !chmod go-rwx $$_file%; \
	/endif%; \
	/test tfflush(out, 0)%; \
;	"i" can't have attributes, so we don't bother encoding them.
	/let opts=-%hist /%count%; \
	/if (savehist_hist =~ "i") \
	    /quote -S -decho #-t'%%@ -' %opts %| /test copyio('i', out)%; \
	/else \
	    /quote -S -decho #-t'%%@ -p -' %opts %| /test _hist_write(out)%; \
	/endif%; \
	/test tfclose(out)%; \
	/set max_iter=%old_max_iter%; \
	/test %{filesize} := %{filesize} + count%; \
	/set_savehist_last %ehist %hist%; \
    /else \
;	Directory may be corrupt.  Forget cached filesize.
	/unset %{filesize}%; \
    /endif%; \
    /unset _dir%; \
    /unset _file

; /load_history {-l|-i|-g|-w<world>}
/def -i load_history = \
    /if /!savehist_args %0 %*%; /then /return 0%; /endif%; \
    /let file=%savehist_dir/$[textencode(savehist_hist)]%; \
    /quote -S /recordline -%savehist_hist -t'%file%; \
    /set_savehist_last %ehist %hist%; \
    /return 1