Submitted-by: michaeli@stout.atd.ucar.edu Archive-name: xmodem/part02 #!/bin/sh # this is xmodem.02 (part 2 of xmodem) # do not concatenate these parts, unpack them in order with /bin/sh # file xmodem/Makefile continued # touch -am 1231235999 $$.touch >/dev/null 2>&1 if test ! -f 1231235999 && test -f $$.touch; then shar_touch=touch else shar_touch=: echo 'WARNING: not restoring timestamps' fi rm -f 1231235999 $$.touch # if test ! -r _sharseq.tmp; then echo 'Please unpack part 1 first!' exit 1 fi shar_sequence=`cat _sharseq.tmp` if test "$shar_sequence" != 2; then echo "Please unpack part $shar_sequence next!" exit 1 fi if test ! -f _sharnew.tmp; then echo 'x - still skipping xmodem/Makefile' else echo 'x - continuing file xmodem/Makefile' sed 's/^X//' << 'SHAR_EOF' >> 'xmodem/Makefile' && # X # modification history # -------------------- # 01b,21apr94,mcm Changed for vxWorks ver 5.1 # 01a,26feb93,mcm Merged original Makefile with vxWorks stuff for this X TOOl = gnu CPU = MC68000 CC=cc68k -mc68000 -msoft-float LD=ld68k X CFLAGS = -O -fstrength-reduce \ X -I$(VX_BSP_BASE)/h/ -ansi -pipe -nostdinc -DCPU=$(CPU) X RM = rm -f CP = cp SHELL = /bin/sh X X X.SUFFIXES : .lint .s .c .g X X.s.o : X @ $(RM) $@ X cat $< > $*.S X $(CC) $(CFLAGS) -c $*.S X @ $(RM) $*.S X X.c.o : X @ $(RM) $@ X $(CC) $(CFLAGS) -c $< X X.c.g : X @ $(RM) $@ X $(CC) $(CFLAGS) -g -c $< X X X X ####################### object modules ################################ X X SRCS = xmodem.c getput.c misc.c send.c receive.c batch.c OBJECTS = xmodem.o getput.o misc.o send.o receive.o batch.o # CFLAGS = -O # MAN = /usr/man/manl/xmodem.l X XXmodem.o: $(OBJECTS) X $(LD) -o Xmodem.o -r $(OBJECTS) X $(OBJECTS): xmodem.h X clean: X rm -f *.o errs a.out X lint: X lint xmodem.c getput.c receive.c send.c batch.c misc.c X shar: X shar README Makefile xmodem.1 xmodem.h version.h > xmodem.shar.1 X shar update.doc xmodem.c receive.c > xmodem.shar.2 X shar getput.c README.vxWorks rtcTime.fixme.c > xmodem.shar.3 X shar misc.c batch.c send.c > xmodem.shar.4 X shar ymodem.doc > xmodem.shar.5 X dist: X tar cvf vxXmodem.tar README update.doc Makefile xmodem.1 xmodem.h \ X version.h xmodem.c getput.c receive.c misc.c batch.c \ X send.c ymodem.doc README.vxWorks rtcTime.fixme.c X compress vxXmodem.tar X xmodem.o: xmodem.c xmodem.h version.h getput.o: getput.c xmodem.h misc.o: misc.c xmodem.h send.o: send.c xmodem.h receive.o: receive.c xmodem.h batch.o: batch.c xmodem.h X # end of MakeSkel X SHAR_EOF echo 'File xmodem/Makefile is complete' && $shar_touch -am 0815105694 'xmodem/Makefile' && chmod 0644 'xmodem/Makefile' || echo 'restore of xmodem/Makefile failed' shar_count="`wc -c < 'xmodem/Makefile'`" test 1680 -eq "$shar_count" || echo "xmodem/Makefile: original size 1680, current size $shar_count" rm -f _sharnew.tmp fi # ============= xmodem/xmodem.1 ============== if test -f 'xmodem/xmodem.1' && test X"$1" != X"-c"; then echo 'x - skipping xmodem/xmodem.1 (File already exists)' rm -f _sharnew.tmp else > _sharnew.tmp echo 'x - extracting xmodem/xmodem.1 (Text)' sed 's/^X//' << 'SHAR_EOF' > 'xmodem/xmodem.1' && X.TH XMODEM LOCAL "December 14, 1990" X.UC 4.2 X.SH NAME xmodem \- Christensen protocol file transfer utility \- Version 3.10, December 1990 X.SH SYNOPSIS X.B xmodem [\fBst|sb|sa|rt|rb|ra\fR][\fBygmkctdlxpwen\fR] [file...] X.br X.SH DESCRIPTION The X.I xmodem program implements the Christensen (XMODEM) file transfer protocol for moving files between 4.2/4.3BSD Unix systems (and successors, including Suns) and microcomputers. The XMODEM/CRC protocol, the MODEM7 batch protocol, the XMODEM-1K block protocol, the YMODEM batch protocol and the YMODEM-G streaming protocol are all supported by X.IR xmodem . The ZMODEM protocol is not supported. For details of the XMODEM/YMODEM protocols, see the document edited by Chuck Forsberg titled X.I XXMODEM/YMODEM Protocol Reference. X.sp Option Flags are case insensitive; the cluster of flags may be preceded by an optional "-" character. X.PP X.SH PARAMETERS Exactly one of the following must be selected: X.TP X.B rb Receive Binary - files are placed on the Unix disk without conversion. X.I Xmodem will silently destroy existing files of the same name. X.TP X.B rt Receive Text - files are converted from the CP/M and MS-DOS format of CR-LF pairs to the Unix convention of newline characters only between lines. Null bytes are ignored and bit 8 of each character is stripped (which makes Wordstar files much more readable). A CTRL-Z character is deemed to indicate the EOF location in the incoming file. The resulting file is acceptable to the Unix editors and compilers, and is usually slightly smaller than the original file. X.I Xmodem will silently destroy existing files of the same name. X.TP X.B ra Receive Apple - same as rt save CR characters in the incoming file are translated into Unix newline characters. X.TP X.B sb Send Binary - files are sent without conversion as they exist on the Unix disk. X.TP X.B st Send Text - newline characters in the file are converted to CR-LF pairs in accord with the CP/M and MS-DOS conventions for text files. The file "grows" in this process. X.TP X.B sa Send Apple - same as st save newline characters are converted into CR characters in accord with Apple Macintosh conventions for text files. X.PP X.SH OPTIONS X.TP X.B y Select the YMODEM batch protocol for sending files; a list of files specified on the command line will be sent in sequence. The YMODEM batch protocol is used automatically for file reception if the sending program requests it. If this flag is specified for a batch receive, (\fIxmodem rty\fR, for example), the transfer will never attempt to switch from CRC to checksum mode. X.TP X.B g Select the YMODEM-G variant of YMODEM when receiving files. YMODEM-G is automatically invoked on transmit if the receiving program requests it. YMODEM-G is designed for "error-free" connections with proper flow control; the transmitting program blasts packets to the receiver as fast as it can without waiting for acknowledgements. Any errors cause the entire file transfer to be aborted. X.TP X.B m Select the MODEM7 batch protocol for sending files; a list of files specified on the command line will be sent in sequence. The MODEM7 batch protocol is used automatically for file reception if the sending program requests it. If this flag is specified for a batch receive, (\fIxmodem rbm\fR, for example), the transfer starts in checksum mode rather than CRC mode. If both "m" and "c" are specified on a receive command, the initial "file-name" negotiations are done using checksums while the file transfers are done using CRC-16. X.TP X.B k Select the XMODEM-1K file transfer mode for sending files. Use of 1K packets on low-error lines increases throughput. However, over direct connections at 9600 bps to a busy host, 1K packets may cause data overflows generating excessive retries. 1K packets are automatically used for file reception if the sending program requests it. If this flag is specified with the YMODEM flag in a batch receive (\fIxmodem rbyk\fR, for example), the program will attempt to use the "KMD/IMP" convention to invoke 1K file transfers. X.TP X.B c Select the CRC-16 error-checking protocol on receive. CRC mode is better at catching transmission errors that occur than the alternative checksum protocol. CRC mode is automatically selected for file transmission if the receiving modem program requests it. X.TP X.B t Indicates the Unix system is Too Busy and X.I xmodem should fall back to a simpler I/O strategy than normal. X.TP X.B d Delete the X.I xmodem.log file before file transfer is begun. X.TP X.B l Do NOT write to the log file. If logging is selected, a file X.I xmodem.log will be created (or appended to), with entries for significant events, errors and retries. This can be useful to see why things went wrong when they do. X.TP X.B x Toggle on debug mode. If debug mode is selected, copious and possibly useful debugging information will be placed in X.IR xmodem.log . A second "x" will place even more information in the log. X.TP X.B p Assume that X.I xmodem is being invoked through SunOS tip (via the ~C command). Status and error messages will be sent to stderr, and hence to your screen, while the transfer is in progress. X.B Do X.B not use this option unless you are using tip! X.TP X.B w Wait 15 seconds before initiating the startup handshake. Useful if handshake characters are trashing things you need to type. X.TP X.B e Suppress EOT verification. Normally, X.I xmodem tries to verify an EOT character (used to signify the end of file) by NAKing it and waiting for the EOT to be resent. This reliability feature can generate harmless error messages in some microcomputer file transfer programs; other programs refuse to work at all. To accomodate the latter brain-damaged programs, use the "e" option. X.TP X.B n Allow CAN-CAN aborts during mid-transfer. Normally, as a reliability feature, CAN-CAN aborts are only allowed at the beginning of a file transfer. If you don't like this feature, use the "n" flag. X.SH "FILE NAMES" Files transmitted using one of the batch modes will be stored on the remote machine under a CP/M-ified name (path names stripped, limited to eight characters plus a three character extension; ":" characters will be turned into "/" characters; all characters will be in monocase). Files received using one of the batch modes will be stored under their transmitted names (except that any "/" characters in the file name will be converted into ":" characters, all upper-case characters will be translated into lower case and trailing dots will be expunged). X.PP When a batch receive is requested, X.I xmodem takes a wait and see attitude and can adapt to either batch protocol or even a classic XMODEM transfer (note that CRC-16 mode is automatically set under these circumstances unless the b flag is specified). If a classic, "non-batch" XMODEM file reception takes place, the received file is stored as X.IR xmodem.in . File names present on the command line for a batch receive are ignored. X.SH NOTES Remember, CRC-16 error detection and YMODEM-G streaming must be invoked by the X.B receiving program while 1K blocksize must be invoked by the X.B sending program. X.PP While waiting for the beginning of a file transfer, X.I xmodem treats two CAN (CTRL-X) characters that are received within 3 seconds as a request to abort. CAN characters will not cause an abort if received in the midst of a file transfer (unless the "n" option was invoked). X.PP If 10 or more errors are detected during the transmission or reception of any one packet, the transfer is aborted. X.PP Squeezed, compressed, ZIPed or ARCed files must be transferred in binary mode, even if they contain text. X.PP If you use X.I xmodem over a X.I rlogin link, you may have to use the form X.IR "rlogin machine -8" . This insures a full 8-bit wide datapath. X.PP If there is any "magic box" between your Unix box and PC (such as a terminal server or a telnet box), make sure that the magic box provides a fully transparent 8-bit path and does not intercept ^S characters or listen for an "escape" sequence to get the magic box's attention. X.PP MIPS's RISC/os version of Unix handles ^S characters and strips the high-order bit on input even in raw mode. Try the command X.IR "/bin/stty -istrip -ixon" before running X.I xmodem on MIPS machines if you are having trouble uploading. X.PP If an unexpected error occurs before a file is completely received, the incomplete file is deleted. X.PP Files received using both binary and text mode in a YMODEM batch transfer will be truncated to the file size specified in the YMODEM header (extra CR characters in the incoming file are correctly handled). File sizes are included in the YMODEM header when sending both binary and text files. Thus files transferred via YMODEM should preserve their exact length. File modification times are set for received files if present in the YMODEM header; they are included in the headers for transmitted files (watch for timezone problems, however). X.PP The "KMD/IMP" record count field in the YMODEM header is both set and read. X.PP X.I xmodem can be used through the SunOS X.I tip program to transfer files. Use X.I tip to establish a session on a remote computer. Enter the file transfer command on the remote computer to send or receive files, then use the ~C command which causes X.I tip to request a local command string and enter the appropriate X.I xmodem command. Use the "p" option on the local X.I xmodem command so you will see status reports on your screen. If the X.I xmodem is running on the remote machine, use the "w" option there to halt the initiation of file-transfer handshaking for a bit to allow you to enter the ~C command line without interference. X.PP The MODEM7 batch protocol is archaic and should only be used if YMODEM batch protocols are not available in your PC's communication program. If you must use MODEM7, you may have to specify the "m" option or, preferably, "cm" when receiving files with X.IR xmodem . X.SH EXAMPLES X.PP To receive a text file transmitted from a micro (using CRC-16 error-checking) and store it under the name X.IR file.name , use the command line X.RS X.B "xmodem rtc file.name" X.RE Note that if the transmitting program on the micro uses the 1K packet protocol and/or the YMODEM batch protocol, X.I xmodem detects this automatically and takes appropriate action. Further note that if one of the batch protocols is used, the received file(s) will be stored under their own names and the name on the command line (if any) will be ignored. Finally, note that CRC-16 error checking is the default. Thus, a generic command to receive files would be X.RS X.B "xmodem rt" X.RE X.PP To send a set of text files to a microcomputer using 1K packets and the YMODEM batch protocol, use the command line X.RS X.B "xmodem styk *.txt" X.RE X.SH FILES xmodem.log (if logging is enabled) X.SH BUGS Batch mode could be smarter about bad file-names in the midst of a batch transmit/receive. X.PP Batch mode could allow a mixture of binary and text files. X.PP Bare Carriage Return characters (i.e., those not immediately followed by a Line Feed character) are mishandled in a received file when using text mode. A file with "overstruck" lines will thus come out looking funny. X.SH SEE ALSO kermit(1), rz(1), sz(1) X.SH AUTHOR Steve Grandi, National Optical Astronomy Observatories (grandi@noao.edu). Based on X.I xmodem by Brian Kantor, University of California at San Diego. This, in turn, was based on X.I umodem by Lauren Weinstein, Richard Conn and others. SHAR_EOF $shar_touch -am 0812084894 'xmodem/xmodem.1' && chmod 0644 'xmodem/xmodem.1' || echo 'restore of xmodem/xmodem.1 failed' shar_count="`wc -c < 'xmodem/xmodem.1'`" test 11512 -eq "$shar_count" || echo "xmodem/xmodem.1: original size 11512, current size $shar_count" rm -f _sharnew.tmp fi # ============= xmodem/xmodem.h ============== if test -f 'xmodem/xmodem.h' && test X"$1" != X"-c"; then echo 'x - skipping xmodem/xmodem.h (File already exists)' rm -f _sharnew.tmp else > _sharnew.tmp echo 'x - extracting xmodem/xmodem.h (Text)' sed 's/^X//' << 'SHAR_EOF' > 'xmodem/xmodem.h' && #include "vxWorks.h" /* Added for vxWorks */ #include "sysLib.h" #include "setjmp.h" /* Also added for vxWorks */ #include "ctype.h" #include "stdioLib.h" /* Changed for vxWorks */ #include "types.h" #include "stat.h" #include "string.h" #include "systime.h" /* Changed for vxWorks */ #include "time.h" #include "ioLib.h" #include "fioLib.h" #include "sigLib.h" /* Changed for vxWorks */ #include "taskLib.h" /* Added for vxWorks */ #include "selectLib.h" /* Added for vxWorks */ X X /* Routines from rtcTime.stub.c */ IMPORT time_t rtcUnixTime(time_t *tloc); IMPORT char *rtcConvUnixTime(time_t tloc); /* Not needed with vx 5.1 */ X X /* define macros to print messages in log file */ #define logit(string) if(LOGFLAG)fprintf(LOGFP,string) #define logitarg(string,argument) if(LOGFLAG)fprintf(LOGFP,string,argument) #define tlogit(string) if(TIPFLAG)fprintf(stderr,string) #define tlogitarg(string,argument) if(TIPFLAG)fprintf(stderr,string,argument) /* sleep definition added for vxWorks */ #define sleep(sec) taskDelay(sysClkRateGet() * (sec)) /* vxWorks addition. Created this command to give number of seconds since X 1/1/70 */ #define time(location) rtcUnixTime((location)) /* #define ctime(seconds) rtcConvUnixTime((seconds)) -- don't need with vx5.1*/ #define FALSE 0 #define TRUE 1 X X /* ASCII Constants */ #define SOH 001 #define STX 002 #define ETX 003 #define EOT 004 #define ENQ 005 #define ACK 006 #define LF 012 /* Unix LF/NL */ #define CR 015 #define NAK 025 #define SYN 026 #define CAN 030 #define ESC 033 X /* XMODEM Constants */ #define TIMEOUT -1 #define ERRORMAX 10 /* maximum errors tolerated while transferring a packet */ #define WAITFIRST 1 /* seconds between startup characters in read */ #define PACKWAIT 5 /* seconds to wait for start of packet */ #define STERRORMAX 60 /* maximum "errors" tolerated in read startup */ #define CRCSWMAX 30 /* maximum time to try CRC mode before switching */ #define NAKMAX 120 /* maximum times to wait for initial NAK when sending */ #define RETRYMAX 5 /* maximum retries to be made certain handshaking routines */ #define KSWMAX 5 /* maximum errors before switching to 128 byte packets */ #define EOTMAX 10 /* maximum times sender will send an EOT to end transfer */ #define SLEEPNUM 100 /* target number of characters to collect during sleepy time */ #define BBUFSIZ 1024 /* buffer size */ #define NAMSIZ 11 /* length of a CP/M file name string */ #define CTRLZ 032 /* CP/M EOF for text (usually!) */ #define CRCCHR 'C' /* CRC request character */ #define KCHR 'K' /* 1K block request character */ #define GCHR 'G' /* Ymodem-G request character */ #define BAD_NAME 'u' /* Bad filename indicator */ #define TIPDELAY 15 /* seconds to delay handshake startup when -w */ X #define CREATMODE 0644 /* mode for created files */ X /* GLOBAL VARIABLES */ X int ttyspeed; /* tty speed (bits per second) */ unsigned char buff[BBUFSIZ]; /* buffer for data */ int nbchr; /* number of chars read so far for buffered read */ long filelength; /* length specified in YMODEM header */ long fileread; /* characters actually read so far in file */ char filename[256]; /* place to construct filenames */ int yfilesleft; /* # of files left for YMODEM header */ long ytotleft; /* # of bytes left for YMODEM header */ X FILE *LOGFP; /* descriptor for LOG file */ X /* option flags and state variables */ char XMITTYPE; /* text or binary? */ int DEBUG; /* keep debugging info in log? */ int MOREDEBUG; /* keep even more debugging info in log? */ int RECVFLAG; /* receive? */ int SENDFLAG; /* send? */ int BATCH; /* batch? (Now used as a state variable) */ int CRCMODE; /* CRC or checksums? */ int DELFLAG; /* don't delete old log file? */ int LOGFLAG; /* keep log? */ int LONGPACK; /* do not use long packets on transmit? */ int MDM7BAT; /* MODEM7 batch protocol */ int YMDMBAT; /* YMODEM batch protocol */ int TOOBUSY; /* turn off sleeping in packet read routine */ int TIPFLAG; /* for tip ~C command */ int DELAYFLAG; /* for startup delay */ int NOEOT; /* suppress EOT verification */ int CANCAN; /* allow CAN-CAN aborts anytime */ int YMODEMG; /* YMODEM-G variant of YMODEM */ X int CHECKLENGTH; /* Are we truncating a file to a YMODEM length? */ X X /* CRC-16 constants. From Usenet contribution by Mark G. Mendel, X Network Systems Corp. (ihnp4!umn-cs!hyper!mark) */ X X /* the CRC polynomial. */ #define P 0x1021 X X /* number of bits in CRC */ #define W 16 X X /* the number of bits per char */ #define B 8 SHAR_EOF $shar_touch -am 0812105794 'xmodem/xmodem.h' && chmod 0644 'xmodem/xmodem.h' || echo 'restore of xmodem/xmodem.h failed' shar_count="`wc -c < 'xmodem/xmodem.h'`" test 4750 -eq "$shar_count" || echo "xmodem/xmodem.h: original size 4750, current size $shar_count" rm -f _sharnew.tmp fi # ============= xmodem/version.h ============== if test -f 'xmodem/version.h' && test X"$1" != X"-c"; then echo 'x - skipping xmodem/version.h (File already exists)' rm -f _sharnew.tmp else > _sharnew.tmp echo 'x - extracting xmodem/version.h (Text)' sed 's/^X//' << 'SHAR_EOF' > 'xmodem/version.h' && #define VERSION "3.10.vxW.02 (20 Apr. 1994)" SHAR_EOF $shar_touch -am 0815110794 'xmodem/version.h' && chmod 0644 'xmodem/version.h' || echo 'restore of xmodem/version.h failed' shar_count="`wc -c < 'xmodem/version.h'`" test 50 -eq "$shar_count" || echo "xmodem/version.h: original size 50, current size $shar_count" rm -f _sharnew.tmp fi # ============= xmodem/xmodem.c ============== if test -f 'xmodem/xmodem.c' && test X"$1" != X"-c"; then echo 'x - skipping xmodem/xmodem.c (File already exists)' rm -f _sharnew.tmp else > _sharnew.tmp echo 'x - extracting xmodem/xmodem.c (Text)' sed 's/^X//' << 'SHAR_EOF' > 'xmodem/xmodem.c' && /* X * XMODEM -- Implements the Christensen XMODEM protocol, X * for packetized file up/downloading. X * X * See the README file for some notes on SYS V adaptations. X * The program has been successfully run on VAXes (4.3BSD) and SUN-3/4s X * (SunOS 3.x) against MEX-PC and ZCOMM/DSZ. X * X * See the README and update.doc files for history and change notes. X * X * Please send bug fixes, additions and comments to: X * grandi@noao.edu X */ X #include "xmodem.h" #include "version.h" X /* External and forward routine references */ extern void xmhelp(void); extern void stopsig(void); extern int gettype(char); extern void error(char *, int); extern void getspeed(void); extern void setmodes(void); extern int rfile(char *); extern void flushin(void); extern void restoremodes(int); extern long countnl(int); extern void sfile(char *); extern int projtime(long, FILE *); X jmp_buf xmEnv; X int Xmodem(char *option1) /* , ...) */ X /* option1 The first option, the final one MUST be a 0 */ { X int argc; /* Changed for vxWorks */ X char **argv; X X FILE *fopen(); X char *unix_cpm(); X char *strcpy(); X char *strcat(); X char *prtype(); X X char *fname = filename; /* convenient place to stash file names */ X char *logfile = "xmodem.log"; /* Name of LOG File */ X X char *stamptime(); /* for timestamp */ X X char *defname = "xmodem.in"; /* default file name if none given */ X X struct stat filestatbuf; /* file status info */ X X int index; X char flag; X long expsect; X int fd; X X /* vxWorks fix. Since we have not argc and argv, we create them. X * Note that the options list MUST be null terminated. X */ X argv = &option1; X --argv; /* FAKE in argv[0], it should not be used */ X argc = 1; X while (argv[argc] != NULL) X argc++; X X /* initialize option flags */ X X XMITTYPE = 't'; /* assume text transfer */ X DEBUG = FALSE; /* don't keep debugging info in log */ X MOREDEBUG = FALSE; /* don't keep even more debugging info in log */ X RECVFLAG = FALSE; /* not receive */ X SENDFLAG = FALSE; /* not send either */ X BATCH = FALSE; /* nor batch */ X CRCMODE = FALSE; /* use checksums for now */ X DELFLAG = FALSE; /* don't delete old log file */ X LOGFLAG = TRUE; /* keep log */ X LONGPACK = FALSE; /* do not use long packets on transmit */ X MDM7BAT = FALSE; /* no MODEM7 batch mode */ X YMDMBAT = FALSE; /* no YMODEM batch mode */ X TOOBUSY = FALSE; /* not too busy for sleeping in packet read */ X TIPFLAG = FALSE; /* no special logging on stderr */ X DELAYFLAG = FALSE; /* don't delay startup for a while */ X NOEOT = FALSE; /* don't suppress EOT verification */ X CANCAN = FALSE; /* don't allow CAN-CAN aborts in mid-transfer */ X YMODEMG = FALSE; /* no YMODEM-G */ X X fprintf(stderr, "XMODEM Version %s", VERSION); X fprintf(stderr, " -- vxWorks File Transfer Facility\n"); X X /* Exit from inner loops with longjmp (namely in error() in misc.c) */ X if (setjmp(xmEnv) != 0) X return -1; X X if (argc == 1) X { X xmhelp(); X return -1; X /* exit(-1); Note, all exits converted to return for vxWorks */ X } X X index = 0; /* set index for flag loop */ X X stopsig(); /* suppress keyboard stop signal */ X X while ((flag = argv[1][index++]) != '\0') X switch (flag) { X case '-' : break; X case 'X' : X case 'x' : if (DEBUG) { X MOREDEBUG = TRUE; X } X else { X DEBUG = TRUE; /* turn on debugging log */ X } X break; X case 'C' : X case 'c' : CRCMODE = TRUE; /* enable CRC on receive */ X break; X case 'D' : X case 'd' : DELFLAG = TRUE; /* delete log file */ X break; X case 'L' : X case 'l' : LOGFLAG = FALSE; /* turn off log */ X break; X case 'm' : X case 'M' : MDM7BAT = TRUE; /* turn on MODEM7 batch protocol */ X BATCH = TRUE; X break; X case 'y' : X case 'Y' : YMDMBAT = TRUE; /* turn on YMODEM batch protocol */ X BATCH = TRUE; X break; X case 'k' : X case 'K' : LONGPACK = TRUE; /* use 1K packets on transmit */ X break; X case 't' : X case 'T' : TOOBUSY = TRUE; /* turn off sleeping */ X break; X /* Don't need this for vxWorks, but what the hell */ X case 'p' : X case 'P' : TIPFLAG = TRUE; /* turn on special handling for SunOS tip */ X break; X case 'w' : X case 'W' : DELAYFLAG = TRUE; /* delay startup */ X break; X case 'e' : X case 'E' : NOEOT = TRUE; /* turn off EOT verification */ X break; X case 'n' : X case 'N' : CANCAN = TRUE; /* allow mid-transfer CAN-CAN */ X break; X case 'g' : X case 'G' : YMODEMG = TRUE; /* YMODEM-G mode */ X CANCAN = TRUE; X CRCMODE = TRUE; X YMDMBAT = TRUE; X break; X case 'R' : X case 'r' : RECVFLAG = TRUE; /* receive file */ X XMITTYPE = gettype(argv[1][index++]); /* get t/b */ X break; X case 'S' : X case 's' : SENDFLAG = TRUE; /* send file */ X XMITTYPE = gettype(argv[1][index++]); X break; X default : fprintf(stderr, "Invalid Flag %c ignored\n", flag); X break; X } X X if (DEBUG) X LOGFLAG = TRUE; X X if (LOGFLAG) X { X /* fname = strcat(fname, "/"); */ X fname = strcpy(fname, "/"); X fname = strcat(fname, logfile); X if (!DELFLAG) X LOGFP = fopen(fname, "a"); /* append to LOG file */ X else X LOGFP = fopen(fname, "w"); /* new LOG file */ X if (!LOGFP) X error("XMODEM Fatal Error- Can't Open Log File", TRUE); /* was false */ X X fprintf(LOGFP,"\n++++++++ %s", stamptime()); X fprintf(LOGFP,"XMODEM Version %s\n", VERSION); X /* argv[0] removed from next line for vxWorks */ X fprintf(LOGFP,"Command line: %s %s", "Xmodem", argv[1]); X for (index=2; index2) X { X if(open(argv[2], 0,0) != -1) /* check for overwriting */ X { X logit("Warning -- Target File Exists and is Being Overwritten\n"); X fprintf(stderr, "Warning -- Target File Exists and is Being Overwritten\n"); X } X fprintf(stderr, "Ready to RECEIVE File %s", argv[2]); X fprintf(stderr, " in %s mode\n", prtype(XMITTYPE)); X if (!TIPFLAG) X fprintf(stderr, "Send several Control-X characters to cancel\n"); X logitarg("Receiving in %s mode\n", prtype(XMITTYPE)); X strcpy(fname,argv[2]); X } X X if (RECVFLAG) X { X if (DELAYFLAG) /* delay if -w requested */ X sleep(TIPDELAY); X setmodes(); /* set tty modes for transfer */ X X while(rfile(fname) != FALSE); /* receive files */ X X flushin(); X restoremodes(FALSE); /* restore normal tty modes */ X X sleep(2); /* give other side time to return to terminal mode */ X return 0; X } X X if (SENDFLAG && BATCH) X { X if (YMDMBAT) X { X ytotleft = 0l; X yfilesleft = 0; X for (index=2; index= 0) { X ytotleft += countnl(fd); X close(fd); X } X } X } X } X if (DEBUG) X fprintf(LOGFP, "DEBUG YMODEM file count: %d, %ld bytes\n", yfilesleft, ytotleft); X X fprintf(stderr, "Ready to YMODEM BATCH SEND"); X fprintf(stderr, " in %s mode\n", prtype(XMITTYPE)); X logit("YMODEM Batch Send Started"); X logitarg(" in %s mode\n", prtype(XMITTYPE)); X } X else if (MDM7BAT) X { X fprintf(stderr, "Ready to MODEM7 BATCH SEND"); X fprintf(stderr, " in %s mode\n", prtype(XMITTYPE)); X logit("MODEM7 Batch Send Started"); X logitarg(" in %s mode\n", prtype(XMITTYPE)); X } X if (!TIPFLAG) X fprintf(stderr, "Send several Control-X characters to cancel\n"); X X if (DELAYFLAG) /* delay if -w requested */ X sleep(TIPDELAY); X setmodes(); X for (index=2; index _sharnew.tmp echo 'x - extracting xmodem/getput.c (Text)' sed 's/^X//' << 'SHAR_EOF' > 'xmodem/getput.c' && /* X * Contains system routines to get and put bytes, change tty modes, etc X * Most of the routines are VERY 4.2BSD Specific!!! X * X * Changed these routines to be VERY vxWorks specific. X */ X #include "xmodem.h" X /* external and forward references */ X extern void error(char *, int); void napms(int); X /* X * X * Get a byte from the specified file. Buffer the read so we don't X * have to use a system call for each character. X * X */ int getbyte(int fildes, char *ch) /* Buffered disk read */ X X { X static char buf[BUFSIZ]; /* Remember buffer */ X static char *bufp = buf; /* Remember where we are in buffer */ X X if (nbchr == 0) /* Buffer exausted; read some more */ X { X if ((nbchr = read(fildes, buf, BUFSIZ)) < 0) X error("File Read Error", TRUE); X bufp = buf; /* Set pointer to start of array */ X } X if (--nbchr >= 0) X { X *ch = *bufp++; X return(0); X } X else X { X return(EOF); X } X } X /* Count the number of newlines in a file so we know the REAL file size */ X long countnl(int fd) { X char buf[BUFSIZ]; X char *bufp; X long nltot = 0; X int numchar; X X while (numchar = read(fd, buf, BUFSIZ)) /* cycle through file */ X for (bufp=buf; numchar--; bufp++) X if (*bufp == '\n') X nltot++; X X (void) lseek (fd, 0l, 0); /* rewind file */ X if (DEBUG) X fprintf(LOGFP, "DEBUG: countnl--%ld newlines counted\n", nltot); X return (nltot); } X /* CRC-16 constant array... X from Usenet contribution by Mark G. Mendel, Network Systems Corp. X (ihnp4!umn-cs!hyper!mark) */ X /* crctab as calculated by initcrctab() */ unsigned short crctab[1< 0;) { X X /* read however many chars are waiting */ X X if ((select(1, (fd_set *) &readfd, (fd_set *)0, (fd_set *)0, &tmout)) == 0) X return(TIMEOUT); X X numread = read(0, inbuf, left); X left -= numread; X X if (DEBUG) X fprintf(LOGFP, "DEBUG: readbuf--read %d characters\n", numread); X X /* now process part of packet we just read */ X X for (j = 0; j < numread; j++) X { X buff[bfctr] = c = inbuf[j] & 0xff; X fileread++; X X if (MOREDEBUG) X fprintf(LOGFP, "DEBUG: character read %02xh\n", c & 0xff); X X if (CRCMODE) /* CRC */ X chksm = (chksm<>(W-B)) ^ c]; X X else /* checksum */ X chksm = ((chksm+c) & 0xff); X X if (CHECKLENGTH && fileread > filelength) /* past EOF ? */ X continue; X X if (tmode) /* text mode processing */ X { X buff[bfctr] &= 0x7f; /* nuke bit 8 */ X if (c == CR || c == 0) /* skip CRs and nulls */ X continue; X else if (c == CTRLZ) /* CP/M EOF char */ X { X recfin = TRUE; X continue; X } X else if (!recfin) /* don't increment if past EOF */ X bfctr++; X } X else if (amode) /* Apple macintosh text mode processing */ X { X buff[bfctr] &= 0x7f; /* nuke bit 8 */ X if (c == 0) /* skip nulls */ X continue; X else if (c == CR) /* translate CR to LF */ X buff[bfctr] = LF; X else if (c == CTRLZ) /* CP/M EOF char */ X { X recfin = TRUE; X continue; X } X if (!recfin) /* don't increment if past EOF */ X bfctr++; X } X else /* binary */ X bfctr++; X X } X X /* go to sleep to save uneeded system calls while kernel X is reading data from serial line; X fudge constant from 10000 to 9000 to avoid sleeping too long. X */ X if (left && !TOOBUSY) X napms( (left _sharseq.tmp exit 0