[comp.mail.mush] Bug warnings and new zfolder

schaefer@ogicse.ogc.edu (Barton E. Schaefer) (02/03/90)

A couple of mush bug warnings, loosely related to "zfolder":

In article <9002021703.AA11461@cse.ogi.edu> schaefer@CSE.OGI.EDU (I) wrote:
} On Feb 2, 10:02am, Renato De Leone wrote:
} } Subject: zfolder
} } 
} } I found some problem using zfolder and folder. It seems to me that the
} } variable compress is not unset when folder command is called (instead
} } of zfolder)
}
} If you really want "folder" to work `between' zfolders, you'll have to do
} two things:
} 
}     1.  cmd folder 'unset compress; \folder'	# note backslash
} 	cmd fo folder


Whatever you do, DON'T DO THIS!  Due to an oversight in the startup code,
mush will expand the "folder" cmd when loading your initial mailbox and
then feed the result directly to the folder() function, producing truly
interesting messages such as

    compress: file not found

which doesn't mean that compress couldn't fine the file, it means mush
tried to load a folder named "compress".  (The message I got, from a
different cmd, when I found this was "z=folder /dev/null: file not found"
which is even more horrifying.)  This will be fixed in patch #5.

Second, the negation logic for pattern-matching expressions is broken.
In other words, "if string =~ pattern" works but "if string !~ pattern"
does not.  This will also be fixed by patch #5.

} But that still doesn't get the compressed version updated.  Hmm, I'm
} getting an idea ... maybe I'll repost a modified .zfolder later ....

And here it is, as a shar this time.  After unpacking, move each file
to a dot-file in your folder directory whose name is otherwise the same
(e.g. "zcmd" --> "$folder/.zcmd") and add the following to your .mushrc:

    cmd zfolder "set z='\!:0 \!*'; source +.zfolder"
    cmd zfo zfolder
    cmd zupdate "source +.zupdate"
    cmd zup zupdate

Note that the zfolder alias has changed to pass the command name to the
"+.zfolder" script.  When you load a folder with "zfolder" or "zfo", the
cmds for "folder" etc. will be installed, so you can change folders or
quit or whatever in normal fashion; the only thing you must remember is
that uncompression will happen only if you use "zfolder", not "folder".

# This is a shell archive.  Remove anything before this line,
# then unpack it by saving it in a file and typing "sh file".
#
# Wrapped by ogicse!schaefer on Fri Feb  2 15:44:04 PST 1990
# Contents:  zcmd zfolder zquit zupdate
 
echo x - zcmd
sed 's/^@//' > "zcmd" <<'@//E*O*F zcmd//'
# Additional cmds for zfolder

cmd folder "set z='!:0 !*'; source +.zfolder"	# make sure "folder" works
cmd fo folder					# and "fo"
cmd update zupdate				# and "update"
cmd quit "set z='!:0'; source +.zquit; \exit"	# and quit
cmd q quit					# and q
cmd exit "set z='!:0'; source +.zquit; \exit"	# and exit
cmd xit exit					# and xit
cmd x xit					# and x

cmd zuncmd "uncmd folder fo update quit q exit xit x"
@//E*O*F zcmd//
chmod u=rw,g=r,o=r zcmd
 
echo x - zfolder
sed 's/^@//' > "zfolder" <<'@//E*O*F zfolder//'
# Mush script to use compressed folders
# Needs $z set to "command [arg1] [arg2] ...", see zfolder cmd
# Bug: can't handle names beginning with + or ~
#  (use file completion: zfo +^[name where ^[ is escape)
# Assumes the following cmds in .mushrc:
#  cmd zfolder "set z='\!:0 \!*'; source +.zfolder"
#  cmd zfo zfolder
#  cmd zupdate "source +.zupdate"
#  cmd zup zupdate

# NO WARRANTIES EXPRESSED OR IMPLIED!  This script is not guaranteed to
# prevent loss of mail when compressing/uncompressing or changing folders.

set zfo = "$z:1"				# identify this script

if "$z:1" =~ zf*				# if the command was zfolder
    source +.zcmd				# install other cmds
    if "X$z:2" != X				# if z:2 is set to something
	if "X$z:2" =~ "*.Z"			# if it has the .Z extension
	    set newfolder = $z:2		# use the name given
	    set had_Z				# and remember that
	else					# otherwise (no .Z)
	    set newfolder = ${z:2}.Z		# put the .Z on
	    if $?had_Z
		unset had_Z			# and forget it
	    endif
	endif
    else					# otherwise (no z:2)
	if $?compress
	    echo -n '"'"${compress:t}"'"'" loaded as "
	endif
	\folder					# act like folder with no args
	exit					# quit reading this file
    endif
else						# otherwise (not zfolder)
    zuncmd					# restore normal foldering
    source +.zupdate				# update compressed folder
    $z						# execute the command
    unset zfo z					# clean up
    exit					# stop reading this file
endif

# this is just flashiness to demonstrate using multiple arguments
if "X$z:3" != X					# if there's a second argument
    set tmpfolder = $z:3			# use it as uncompressed file
else						# otherwise (no second arg)
    set tmpfolder = /usr/tmp/zfo$$		# conjure up a file name
endif

# now find and load the new folder
if -e $newfolder				# if the new folder exists
    source +.zupdate				# update the current folder
    if -e $tmpfolder				# if the temp file exists
	echo "${tmpfolder}: file exists"	# refuse to clobber it
	zuncmd					# restore normal foldering
	unset zfo newfolder tmpfolder z		# clean up
	exit					# stop reading this file
    endif
    echo -n "uncompressing $newfolder ... "
    sh zcat < $newfolder > $tmpfolder		# uncompress the new folder
    echo "loading"
    if $?ok
	unset ok				# remove ok if set
    endif
    \folder $tmpfolder | set ok			# ok set if folder succeeds
    if $?ok					# if folder succeeded
	headers					# display headers
	set compress = $newfolder		# remember name of original
	unset ok				# clean up
    else					# otherwise (folder failed)
	zuncmd					# restore normal foldering
	sh rm -f $tmpfolder			# remove the temp file
    endif
else						# otherwise (no new folder)
    if $?had_Z					# if the arg had .Z
	echo "$newfolder not found"		# complain about it
	unset had_Z
    else					# otherwise (no .Z)
	source +.zupdate			# update the current folder
	\folder "$z:2" "$z:3"			# try an ordinary folder
    endif
    if ! $?compress				# if not compressed
	zuncmd					# restore normal foldering
    endif
endif
unset zfo newfolder tmpfolder z			# clean up
if $?compress					# if compressed
    if "$compress" =~ /*			# check for an absolute path
	# no-op because !~ doesn't work in 7.0.4
    else
	set compress = "$cwd/$compress"		# make the path absolute
    endif
endif
@//E*O*F zfolder//
chmod u=rw,g=r,o=r zfolder
 
echo x - zquit
sed 's/^@//' > "zquit" <<'@//E*O*F zquit//'
# Quitting for use with zfolder

if $?compress					# if compressed
    if $z:1 =~ q*				# and quitting
	set zfo = $thisfolder			# fool zupdate
	source +.zupdate			# do the update
    else					# otherwise (exit, not quit)
	sh rm -f $thisfolder			# remove temp file
    endif
    \exit					# exit the program
else						# otherwise (not compressed)
    $z						# do the command
endif
@//E*O*F zquit//
chmod u=rw,g=r,o=r zquit
 
echo x - zupdate
sed 's/^@//' > "zupdate" <<'@//E*O*F zupdate//'
# Mush script to update a compressed folder

set oldfo=$thisfolder				# save current folder name
if $?compress					# if this folder was compressed
    if $?zfo					# if called from .zfolder
	if $?warning				# warn user if he's paranoid
	    echo "switching to empty folder to force update"
	endif
	\folder /dev/null			# sneaky update without reparse
    else					# otherwise (not from zfolder)
	\update					# normal update
    endif
    echo -n "compressing ... "
    if $?zfo					# if called from .zfolder
	sh compress $oldfo			# compress it again
	echo -n "updating $compress ... "
	sh cp $oldfo.Z $compress		# update the compressed version
	sh rm $oldfo.Z				# get rid of the temp version
	unset compress				# clean up
    else					# otherwise
	sh compress < $oldfo > $compress	# don't alter $oldfo file
    endif
    echo "done"
else						# otherwise (not compressed)
    if ! $?zfo					# if not called from zfolder
	\update					# do the update normally
    endif
endif
unset oldfo					# clean up
@//E*O*F zupdate//
chmod u=rw,g=r,o=r zupdate
 
exit 0
-- 
Bart Schaefer                             "Live and don't learn, that's us."
                                                                   -- Hobbes

schaefer@cse.ogi.edu (used to be cse.ogc.edu)