ehl@Navajo.ARPA (08/11/85)
I've written a shell script (xmac) that will take a list of files, check whether they're BinHex files, and then macput them. If a file is a BinHex file, it will be xbin'd before the transfer -- this eliminates the need to use BinHex on your Macintosh. All temporary files (including the .info, .data, and .rsrc files produced by xbin) are removed automatically. If a file is not a BinHex file, it is assumed to be a text file and is transferred via macput -u. An initial -n switch is passed on to macput to set the Macintosh filename. Unfortunately, macput does not seem to pay any attention to this switch when transferring the .info, .data, and .rsrc files, so it is currently only useful in transferring text files. One very nice feature is that if no files are given to it, it will take input from stdin. This allows you to transfer files without leaving your news reader. The invocation is "| xmac" from rn and "s |xmac" from readnews/vnews. One caveat, though. If your version of SH does not redirect stdin to the terminal after the pipe is closed, you will need to change macput.c to use /dev/tty for i/o rather than stdin/stdout. Elgin Lee UUCP: ..decvax!decwrl!glacier!navajo!ehl ARPA: ehl@su-navajo.arpa ---------- Diff of the changes required to macput.c: ----------------Cut Here------------ *** macput.c.old Tue Nov 27 01:30:47 1984 --- macput.c Sat Aug 10 13:28:26 1985 *************** *** 24,29 #include <sys/types.h> #include <sys/stat.h> #include <sys/timeb.h> /* Mac time of 00:00:00 GMT, Jan 1, 1970 */ #define TIMEDIFF 0x7c25b080 --- 24,30 ----- #include <sys/types.h> #include <sys/stat.h> #include <sys/timeb.h> + #include <sys/file.h> /* Mac time of 00:00:00 GMT, Jan 1, 1970 */ #define TIMEDIFF 0x7c25b080 *************** *** 438,445 int cleanup(); int timedout(); ! ttyf = stdin; ! ttyfd = fileno(stdout); ioctl(ttyfd, TIOCGETP, &otty); signal(SIGHUP, cleanup); signal(SIGINT, cleanup); --- 439,448 ----- int cleanup(); int timedout(); ! /* ttyf = stdin; */ ! ttyf = fopen("/dev/tty", "r"); ! /* ttyfd = fileno(stdout); */ ! ttyfd = open("/dev/tty", O_WRONLY, 0600); ioctl(ttyfd, TIOCGETP, &otty); signal(SIGHUP, cleanup); signal(SIGINT, cleanup); ---------------- ... and here's xmac itself: ---------------Cut Here-------------- : This is a SH script. The first line should not begin with a '#'. # # Yet another shell script for transmitting groups of files to a Macintosh # via macput and xbin. # # Usage: xmac [-n macname] [file] ... # # xmac transfers the indicated files to a Macintosh via macput. Each such # file is checked to see whether it is a BinHex (.hex, .hcx, or .hqx format) # file; if so, the file is xbin'd before the transfer. Files that are not # BinHex format will be sent as text files via macput -u. # # If no file is specified, the standard input is used. This allows you # to transfer files from net.sources.mac without leaving your news reader. # Use "| xmac" from rn or "s |xmac" from readnews/vnews. # # If the -n switch is specified, it (and the following argument) is passed # on to macput to set the Mac filename. Macput does not appear to use # the switch when transfering the .info, .data, and .rsrc files, however. # # To install, you will need to change the values of XBIN and MACPUT (below) # to reflect the locations of xbin and macput on your system. # # For the piping feature to work, you either need a version of the SH that # redirects stdin to the terminal after the pipe closes (at Stanford, the # version at Shasta seems to do this, but the version on Navajo doesn't), # or you need to change macput to use /dev/tty for i/o rather than stdin and # stdout. # # Written August 9, 1985 by # # Elgin Lee # Stanford University # ..decvax!decwrl!glacier!navajo!ehl # ehl@su-navajo.arpa # XBIN=/user/ehl/bin/xbin MACPUT=/user/ehl/bin/newmacput hexfile=#xmac$$ mesg n # cleanup if interrupted trap 'rm -f $hexfile; if test $f; then rm -f $f.info $f.rsrc $f.data; mesg y; \ exit' 1 2 3 15 if test $# -ge 2; then case $1 in -n) transfername=$2; shift; shift ;; esac fi if test $# -eq 0; then if cat > $hexfile; then if macname=`$XBIN -l $hexfile 2> /dev/null \ | sed -n -e 's/^macname: //p' | sed -e 's/ /_/g'` test $macname then if $XBIN $hexfile; then if test $transfername; then $MACPUT $macname -n $transfername else $MACPUT $macname fi else $MACPUT -u $hexfile -n ${transfername-stdin} fi rm -f $macname.info $macname.data $macname.rsrc else $MACPUT -u $hexfile -n ${transfername-stdin} fi rm -f $hexfile else echo Can\'t create temporary file $hexfile fi else for f in $*; do if test -r $f -a ! -d $f; then if macname=`$XBIN -l $f 2> /dev/null \ | sed -n -e 's/^macname: //p' | sed -e 's/ /_/g'` test $macname then if $XBIN $f; then if test $transfername; then $MACPUT $macname -n $transfername else $MACPUT $macname fi elif test $transfername; then $MACPUT -u $f -n $transfername else $MACPUT -u $f fi rm -f $macname.info $macname.data $macname.rsrc elif test $transfername; then $MACPUT -u $f -n $transfername else $MACPUT -u $f fi else echo "$f: does not exist or is a directory." fi done fi echo -n " " echo "Downloads done!" echo -n echo -n echo -n mesg y -- Elgin Lee UUCP: ..decvax!decwrl!glacier!navajo!ehl ARPA: ehl@su-navajo.ARPA, ehl@su-score.ARPA