XMODEM program for VAXes
brown at nicmad.UUCP
brown at nicmad.UUCP
Fri Jun 21 04:55:47 AEST 1985
The following is in response to the request for a XMODEM program for the VAX.
We have written one for our 11/750 using 4.2BSD. We use it to transfer files
between the Vax and our PCs. Because of that, the program has been designed
the add/remove the CRs. The Vax doesn't really want them and the PC needs
them. It also will remove the ^Z that is at the end of PC text files and will
also remove the extra characters that may be after the ^Z.
Be sure to remove the .signature stuff at the end of this posting.
If you have any questions or problems let me know.
Mike Brown
---------- cut here --------
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
# Makefile
# README
# add.c
# addcr.c
# addlf.c
# cr.c
# cr2lf.c
# del.c
# delcr.c
# lf.c
# lf2cr.c
# receive.c
# transmit.c
# xmodrec.1
# xmodtran.1
# This archive created: Thu Jun 20 13:46:20 1985
# By: Mr. Video ()
export PATH; PATH=/bin:$PATH
echo shar: extracting "'Makefile'" '(1312 characters)'
if test -f 'Makefile'
then
echo shar: will not over-write existing file "'Makefile'"
else
sed 's/^ X//' << \SHAR_EOF > 'Makefile'
XFILES = receive.c transmit.c addcr.c delcr.c add.c del.c\
X lf2cr.c cr.c lf.c cr2lf.c
XOBJS = receive.o transmit.o addcr.o delcr.o add.o del.o\
X lf2cr.o cr.o lf.o cr2lf.o
XLIBS = -lcurses -ltermlib
XFLAGS = -O -c -I/sys/h
XDIR = /usr/local
Xmake: receive transmit addcr delcr cr2lf lf2cr
Xclean:
X rm $(OBJS)
Xpr:
X lpr -Plp $(FILES)
Xreceive.o: receive.c
X cc $(FLAGS) receive.c
Xreceive: receive.o del.o lf.o
X cc -O -o receive del.o lf.o receive.o $(LIBS)
X strip receive
X mv receive $(DIR)/xmodrec
Xtransmit.o: transmit.c
X cc $(FLAGS) transmit.c
Xtransmit: transmit.o add.o cr.o
X cc -O -o transmit add.o cr.o transmit.o $(LIBS)
X strip transmit
X mv transmit $(DIR)/xmodtran
Xaddcr.o: addcr.c
X cc $(FLAGS) addcr.c
Xaddcr: addcr.o add.o
X cc -O -o addcr add.o addcr.o
X strip addcr
X mv addcr $(DIR)
Xdelcr.o: delcr.c
X cc $(FLAGS) delcr.c
Xdelcr: delcr.o del.o
X cc -O -o delcr del.o delcr.o
X strip delcr
X mv delcr $(DIR)
Xadd.o: add.c
X cc $(FLAGS) add.c
Xdel.o: del.c
X cc $(FLAGS) del.c
Xcr.o: cr.c
X cc $(FLAGS) cr.c
Xlf2cr.o: lf2cr.c
X cc $(FLAGS) lf2cr.c
Xlf2cr: lf2cr.o cr.o
X cc -O -o lf2cr lf2cr.o cr.o
X strip lf2cr
X mv lf2cr $(DIR)
Xlf.o: lf.c
X cc $(FLAGS) lf.c
Xcr2lf.o: cr2lf.c
X cc $(FLAGS) cr2lf.c
Xcr2lf: cr2lf.o lf.o
X cc -O -o cr2lf cr2lf.o lf.o
X strip cr2lf
X mv cr2lf $(DIR)
SHAR_EOF
if test 1312 -ne "`wc -c < 'Makefile'`"
then
echo shar: error transmitting "'Makefile'" '(should have been 1312 characters)'
fi
chmod +x 'Makefile'
fi # end of overwriting check
echo shar: extracting "'README'" '(431 characters)'
if test -f 'README'
then
echo shar: will not over-write existing file "'README'"
else
sed 's/^ X//' << \SHAR_EOF > 'README'
X
X
XThe two compiled programs, xmodrec and xmodtran, will be moved to the
X/usr/local directory. If this is not where you want them, change the
XMakefile DIR variable to what you want for your system.
X
XThe programs are being used on a VAX 750 with BSD 4.2. They are used
Xto transfer data between IBM PCs and the VAX.
X
XIf you have any questions or comments, send UUCP mail to:
X
X {ihnp4,seismo}!uwvax!astroatc!nicmad!brown
X
XMike Brown
SHAR_EOF
if test 431 -ne "`wc -c < 'README'`"
then
echo shar: error transmitting "'README'" '(should have been 431 characters)'
fi
chmod +x 'README'
fi # end of overwriting check
echo shar: extracting "'add.c'" '(985 characters)'
if test -f 'add.c'
then
echo shar: will not over-write existing file "'add.c'"
else
sed 's/^ X//' << \SHAR_EOF > 'add.c'
X/* Version 1.0 6/12/85
X Jim Hein
X Nicolet Instrument Corp
X 5225 Verona Rd
X Madison, WI 53611-0288
X*/
X#
X# include <file.h>
X
X# define CR 13
X# define NL 10
X# define CTRL_Z 26
X
Xchar *
XADDCR(file)
Xchar *file; {
X int id, oid;
X char buf[512], *index();
X static char temp[11];
X char *end = "\r\n";
X int ln, cnt;
X register char *ptr = buf, *od;
X register i, count;
X
X strcpy(temp,"tempXXXXXX");
X mktemp(temp);
X if ((oid = open(temp,O_CREAT | O_WRONLY,0644)) < 0) {
X perror(temp);
X unlink(temp);
X exit(-1);
X }
X if ((id = open(file,O_RDONLY,0644)) < 0) {
X perror(file);
X unlink(temp);
X exit(-1);
X }
X
X while (ln = read(id,ptr,512)) {
X count = 0;
X while ( od = index(ptr,NL) ) {
X if (od > &buf[ln]) break;
X *od = '\0';
X cnt = strlen(ptr);
X count += cnt;
X write(oid, ptr, cnt);
X write(oid, end, 2);
X ptr = ++od;
X count++;
X }
X if (count = ln - count)
X write(oid,ptr,count);
X ptr = buf;
X }
X *ptr = CTRL_Z;
X write(oid,ptr,1);
X
X close(oid); close(id);
X return(temp);
X}
SHAR_EOF
if test 985 -ne "`wc -c < 'add.c'`"
then
echo shar: error transmitting "'add.c'" '(should have been 985 characters)'
fi
chmod +x 'add.c'
fi # end of overwriting check
echo shar: extracting "'addcr.c'" '(323 characters)'
if test -f 'addcr.c'
then
echo shar: will not over-write existing file "'addcr.c'"
else
sed 's/^ X//' << \SHAR_EOF > 'addcr.c'
X/* Version 1.0 6/12/85
X Jim Hein
X Nicolet Instrument Corp
X 5225 Verona Rd
X Madison, WI 53611-0288
X*/
Xmain(argc,argv)
Xint argc;
Xchar *argv[]; {
X char buf[512];
X register int i;
X
X for (i = 1; i < argc; i++) {
X strcpy(buf,"mv ");
X strcat(buf,ADDCR(argv[i]));
X strcat(buf," ");
X strcat(buf,argv[i]);
X system(buf);
X }
X}
SHAR_EOF
if test 323 -ne "`wc -c < 'addcr.c'`"
then
echo shar: error transmitting "'addcr.c'" '(should have been 323 characters)'
fi
chmod +x 'addcr.c'
fi # end of overwriting check
echo shar: extracting "'addlf.c'" '(1039 characters)'
if test -f 'addlf.c'
then
echo shar: will not over-write existing file "'addlf.c'"
else
sed 's/^ X//' << \SHAR_EOF > 'addlf.c'
X/* Version 1.0 6/12/85
X Jim Hein
X Nicolet Instrument Corp
X 5225 Verona Rd
X Madison, WI 53611-0288
X*/
X#
X# define CR 13
X# define NL 10
X
Xmain(argc,argv)
Xint argc;
Xchar *argv[]; {
X int id, oid;
X char buf[512];
X char *temp, *index();
X char *end = "\r\n";
X int ln, cnt;
X register char *ptr, *od;
X register i, count;
X
X for (i = 1; i < argc; i++) {
X if ((id = open(argv[i],0)) < 0) {
X printf("CAN NOT OPEN FILE `%s'. . . . .\n",argv[i]);
X break;
X } else {
X temp = "tempXXXXXX";
X mktemp(temp);
X oid = creat(temp,0644);
X
X ptr = buf;
X while (ln = read(id,ptr,512)) {
X count = 0;
X while ( od = index(ptr,CR) ) {
X if (od > &buf[ln]) break;
X *od = '\0';
X cnt = strlen(ptr);
X count += cnt;
X write(oid, ptr, cnt);
X write(oid, end, 2);
X ptr = ++od;
X count++;
X }
X if (count = ln - count)
X write(oid,ptr,count);
X ptr = buf;
X }
X
X close(oid); close(id);
X strcpy(buf,"mv ");
X strcat(buf,temp);
X strcat(buf," ");
X strcat(buf,argv[i]);
X system(buf);
X unlink(temp);
X }
X }
X}
SHAR_EOF
if test 1039 -ne "`wc -c < 'addlf.c'`"
then
echo shar: error transmitting "'addlf.c'" '(should have been 1039 characters)'
fi
chmod +x 'addlf.c'
fi # end of overwriting check
echo shar: extracting "'cr.c'" '(882 characters)'
if test -f 'cr.c'
then
echo shar: will not over-write existing file "'cr.c'"
else
sed 's/^ X//' << \SHAR_EOF > 'cr.c'
X/* Version 1.0 6/12/85
X Jim Hein
X Nicolet Instrument Corp
X 5225 Verona Rd
X Madison, WI 53611-0288
X*/
X#
X#include <file.h>
X
X#define CR 13
X#define NL 10
X
Xchar *
XLF2CR(file)
Xchar *file; {
X int id, oid;
X char buf[512], *index();
X static char temp[11];
X register char *ptr = buf;
X register ln, count;
X
X strcpy(temp,"tempXXXXXX");
X mktemp(temp);
X if ((oid = open(temp,O_CREAT | O_WRONLY,0644)) < 0) {
X perror(temp);
X unlink(temp);
X exit(-1);
X }
X if ((id = open(file,O_RDONLY,0644)) < 0) {
X perror(file);
X unlink(temp);
X exit(-1);
X }
X
X count = 0;
X while (ln = read(id,ptr,512)) {
X while ( ptr = index(ptr,NL) ) {
X if (ptr > &buf[ln]) break;
X *ptr = CR;
X }
X write(oid,ptr = buf,ln);
X count += ln;
X }
X if (ln = count % 128) {
X count = 128 - ln;
X for (ln = 0, ptr = buf; ln < count ; ln++, *ptr++ = ' ');
X write(oid,buf,ln);
X }
X
X close(oid); close(id);
X return(temp);
X}
SHAR_EOF
if test 882 -ne "`wc -c < 'cr.c'`"
then
echo shar: error transmitting "'cr.c'" '(should have been 882 characters)'
fi
chmod +x 'cr.c'
fi # end of overwriting check
echo shar: extracting "'cr2lf.c'" '(233 characters)'
if test -f 'cr2lf.c'
then
echo shar: will not over-write existing file "'cr2lf.c'"
else
sed 's/^ X//' << \SHAR_EOF > 'cr2lf.c'
X/* Version 1.0 6/12/85
X Jim Hein
X Nicolet Instrument Corp
X 5225 Verona Rd
X Madison, WI 53611-0288
X*/
Xmain(argc,argv)
Xint argc;
Xchar *argv[]; {
X char buf[512];
X register int i;
X
X for (i = 1; i < argc; i++) {
X CR2LF(argv[i]);
X }
X}
SHAR_EOF
if test 233 -ne "`wc -c < 'cr2lf.c'`"
then
echo shar: error transmitting "'cr2lf.c'" '(should have been 233 characters)'
fi
chmod +x 'cr2lf.c'
fi # end of overwriting check
echo shar: extracting "'del.c'" '(1134 characters)'
if test -f 'del.c'
then
echo shar: will not over-write existing file "'del.c'"
else
sed 's/^ X//' << \SHAR_EOF > 'del.c'
X/* Version 1.0 6/12/85
X Jim Hein
X Nicolet Instrument Corp
X 5225 Verona Rd
X Madison, WI 53611-0288
X*/
X#
X# include <file.h>
X
X# define CR 13
X# define NL 10
X# define CTRL_Z 26
X# define BLOCK 512
X
XDELCR(file)
Xchar *file; {
X int id, oid;
X char buf[BLOCK+10], *index();
X static char temp[11];
X register char *ptr = buf, *od, *cz;
X register int len;
X
X strcpy(temp,"tempXXXXXX");
X mktemp(temp);
X if ((oid = open(temp,O_CREAT | O_WRONLY,0644)) < 0) {
X perror(temp);
X unlink(temp);
X exit(-1);
X }
X
X if ((id = open(file,O_RDONLY,0644)) < 0) {
X perror(file);
X unlink(temp);
X exit(-1);
X }
X
X while ((len = read(id,ptr,BLOCK)) > 0) {
X *(ptr + len) = 0;
X while ( od = index(ptr,CR) ) {
X *od = '\0';
X if (cz = index(ptr,CTRL_Z)) {
X *cz = '\0';
X write(oid, ptr, strlen(ptr));
X goto OUT;
X }
X write(oid, ptr, strlen(ptr));
X ptr = ++od;
X }
X if (cz = index(ptr,CTRL_Z)) {
X *cz = '\0';
X write(oid, ptr, strlen(ptr));
X goto OUT;
X }
X if (len = strlen(ptr))
X write(oid, ptr, len);
X ptr = buf;
X }
X
XOUT:
X close(oid); close(id);
X strcpy(buf,"mv ");
X strcat(buf,temp);
X strcat(buf," ");
X strcat(buf,file);
X system(buf);
X}
SHAR_EOF
if test 1134 -ne "`wc -c < 'del.c'`"
then
echo shar: error transmitting "'del.c'" '(should have been 1134 characters)'
fi
chmod +x 'del.c'
fi # end of overwriting check
echo shar: extracting "'delcr.c'" '(233 characters)'
if test -f 'delcr.c'
then
echo shar: will not over-write existing file "'delcr.c'"
else
sed 's/^ X//' << \SHAR_EOF > 'delcr.c'
X/* Version 1.0 6/12/85
X Jim Hein
X Nicolet Instrument Corp
X 5225 Verona Rd
X Madison, WI 53611-0288
X*/
Xmain(argc,argv)
Xint argc;
Xchar *argv[]; {
X char buf[512];
X register int i;
X
X for (i = 1; i < argc; i++) {
X DELCR(argv[i]);
X }
X}
SHAR_EOF
if test 233 -ne "`wc -c < 'delcr.c'`"
then
echo shar: error transmitting "'delcr.c'" '(should have been 233 characters)'
fi
chmod +x 'delcr.c'
fi # end of overwriting check
echo shar: extracting "'lf.c'" '(1356 characters)'
if test -f 'lf.c'
then
echo shar: will not over-write existing file "'lf.c'"
else
sed 's/^ X//' << \SHAR_EOF > 'lf.c'
X/* Version 1.0 6/12/85
X Jim Hein
X Nicolet Instrument Corp
X 5225 Verona Rd
X Madison, WI 53611-0288
X*/
X#
X#include <file.h>
X
X#define CR 13
X#define NL 10
X#define BLOCK 512
X#define STOP 0xff
X
XCR2LF(file)
Xchar *file; {
X int id, oid;
X char buf[BLOCK+1], *index();
X char temp[11], temp1[11];
X register char *ptr = buf;
X register int len;
X
X strcpy(temp,"tempXXXXXX");
X mktemp(temp);
X if ((oid = open(temp,O_CREAT | O_RDWR,0644)) < 0) {
X perror(temp);
X unlink(temp);
X exit(-1);
X }
X
X if ((id = open(file,O_RDONLY,0644)) < 0) {
X perror(file);
X unlink(temp);
X exit(-1);
X }
X
X buf[BLOCK] = 0;
X while ((len = read(id,ptr,BLOCK)) > 0) {
X while ( ptr = index(ptr,CR) ) {
X *ptr = NL;
X }
X write(oid, ptr = buf, len);
X }
X
X close(id);
X lseek(oid,1,L_XTND);
X do {
X lseek(oid,-2,L_INCR);
X read(oid,ptr,1);
X } while ( *ptr != NL );
X *ptr = STOP;
X write(oid,ptr,1);
X lseek(oid,0,L_SET);
X
X strcpy(temp1,"tempXXXXXX");
X mktemp(temp1);
X if ((id = open(temp1,O_CREAT | O_WRONLY,0644)) < 0) {
X perror(temp1);
X unlink(temp1);
X unlink(temp);
X exit(-1);
X }
X
X ptr = buf;
X while ((len = read(oid,ptr,BLOCK)) > 0) {
X if (ptr = index(ptr,STOP)) {
X *ptr = 0;
X write(id, buf, strlen(buf));
X break;
X }
X write(id, ptr = buf, len);
X }
X
X close(oid); close(id);
X strcpy(buf,"mv ");
X strcat(buf,temp1);
X strcat(buf," ");
X strcat(buf,file);
X system(buf);
X unlink(temp);
X}
SHAR_EOF
if test 1356 -ne "`wc -c < 'lf.c'`"
then
echo shar: error transmitting "'lf.c'" '(should have been 1356 characters)'
fi
chmod +x 'lf.c'
fi # end of overwriting check
echo shar: extracting "'lf2cr.c'" '(323 characters)'
if test -f 'lf2cr.c'
then
echo shar: will not over-write existing file "'lf2cr.c'"
else
sed 's/^ X//' << \SHAR_EOF > 'lf2cr.c'
X/* Version 1.0 6/12/85
X Jim Hein
X Nicolet Instrument Corp
X 5225 Verona Rd
X Madison, WI 53611-0288
X*/
Xmain(argc,argv)
Xint argc;
Xchar *argv[]; {
X char buf[512];
X register int i;
X
X for (i = 1; i < argc; i++) {
X strcpy(buf,"mv ");
X strcat(buf,LF2CR(argv[i]));
X strcat(buf," ");
X strcat(buf,argv[i]);
X system(buf);
X }
X}
SHAR_EOF
if test 323 -ne "`wc -c < 'lf2cr.c'`"
then
echo shar: error transmitting "'lf2cr.c'" '(should have been 323 characters)'
fi
chmod +x 'lf2cr.c'
fi # end of overwriting check
echo shar: extracting "'receive.c'" '(4439 characters)'
if test -f 'receive.c'
then
echo shar: will not over-write existing file "'receive.c'"
else
sed 's/^ X//' << \SHAR_EOF > 'receive.c'
X/* Version 1.0 6/12/85
X Jim Hein
X Nicolet Instrument Corp
X 5225 Verona Rd
X Madison, WI 53611-0288
X*/
X/*
X** receive filename
X*/
X#
X# include <file.h>
X# include <curses.h>
X# include <signal.h>
X# include <time.h>
X
X# define SOH 0x1
X# define NAK 0x15
X# define ACK 0x6
X# define EOT 0x4
X# define CANCEL 0x18
X
Xchar filename[64];
Xint retries;
Xint seq_num;
Xmain(argc,argv)
Xint argc;
Xchar *argv[]; {
X
X int fd;
X register i;
X char c;
X char block[131];
X int length, pid;
X struct sigvec vec;
X int caught();
X
X if (!((argc == 2) || (argc == 3))) {
X printf("ILLEGAL NUMBER OF ARGUMENTS.\n");
X printf("SYNOPSIS: xmodrec [-t] filename\n");
X exit(-1);
X }
X
X if (argc == 3) {
X if (strcmp(argv[1],"-t") && strcmp(argv[1],"-m")) {
X printf("bad argument `%s'\n",argv[1]);
X printf("SYNOPSIS: xmodrec [-t] filename\n");
X exit(-1);
X }
X }
X
X strcpy(filename,argv[argc-1]);
X if ((fd = open(filename,O_WRONLY|O_CREAT|O_TRUNC,0644)) < 0) {
X perror(filename);
X exit(-1);
X }
X
X initscr();
X raw(); /* set terminal to 8-bit I/O */
X noecho();
X
X/*
X** Ignore interrupts from the user.
X** If the user could delete this program the terminal
X** would be left in a undiserable state of mind.
X*/
X
X vec.sv_handler = caught;
X vec.sv_mask = vec.sv_onstack = 0;
X sigvec(SIGALRM,&vec,(struct sigvec *)0);
X
X sigsetmask(-1 ^ (1 << (SIGALRM-1)));
X
X if ((pid = fork()) == 0) { /* child sends ready prompt */
X c = NAK;
X for ( i = 0; i < 10; i++) {
X write(1,&c,1);
X sleep(10);
X }
X reset(); /* restore terminal to normal state */
X kill(0,SIGKILL); /* kill all processes */
X }
X
X read(0,&c,1);
X kill(pid,SIGKILL); /* received SOH response, so kill child */
X wait(0);
X
X seq_num = 1; retries = 0;
X for(;;) {
X
X if (retries == 10) {
X c = CANCEL;
X write(1,&c,1);
X RESET("Terminate after 10 retries",retries);
X }
X
X switch( c & 0x7f ) {
X case SOH:
X BLOCK(fd);
X break;
X case CANCEL:
X RESET("main: CANCEL IN switch",0);
X case EOT:
X c = ACK;
X write(1,&c,1);
X noraw();
X echo();
X endwin();
X goto END;
X default:
X SET_TIMER();
X for ( i = 0; i < 131; i++) read(0,&c,1);
X DISABLE_TIMER();
X c = NAK;
X write(1,&c,1);
X retries++;
X break;
X }
X SET_TIMER();
X read(0,&c,1);
X DISABLE_TIMER();
X }
XEND:
X DISABLE_TIMER();
X sigsetmask(0);
X vec.sv_handler = SIG_DFL;
X vec.sv_mask = vec.sv_onstack = 0;
X sigvec(SIGALRM,&vec,(struct sigvec *)0);
X
X close(fd);
X if (argc == 3) {
X switch( argv[1][1] ) {
X case 't':
X printf("Deleting carriage returns\n");
X DELCR(filename);
X break;
X case 'm':
X printf("Changing cr's to lf's\n");
X CR2LF(filename);
X }
X }
X}
X
XBLOCK(fd)
Xint fd; {
X
X register i;
X register char *p;
X char block[131];
X char c;
X int length, pid;
X int xsum;
X
X SET_TIMER();
X length = 0;
X for( i = 0, p = block; i < 131; i++) length += read(0,p++,1);
X DISABLE_TIMER();
X
X if (length != 131) {
X c = NAK;
X write(1,&c,1);
X retries++;
X return;
X }
X
X if ( (block[0] & 0xff) != seq_num ) {
X i = (seq_num ? seq_num - 1 : 255);
X if ((block[0] & 0xff) != i ) {
X if ( (block[1] & 0xff) != (255 - seq_num) ) {
X i = 255 - i;
X if ((block[1] & 0xff) == i ) {
X c = NAK;
X write(1,&c,1);
X retries++;
X return;
X }
X c = CANCEL; /* loss of synchronization */
X write(1,&c,1);
X RESET("loss of syn: block = %d, seq_num = %d",block[0]);
X }
X }
X retries++;
X goto leave;
X }
X
X if ( (block[1] & 0xff) != (255 - seq_num) ) {
X c = NAK;
X write(1,&c,1);
X retries++;
X return;
X }
X
X xsum = 0;
X for (i = 2; i < 130; i++) xsum += block[i];
X xsum &= 0xff;
X if ( (block[130] & 0xff) != xsum ) {
X c = NAK;
X write(1,&c,1);
X retries++;
X return;
X }
X
X write(fd,&block[2],128);
X retries = 0;
X seq_num = ++seq_num % 256;
Xleave:
X c = ACK;
X write(1,&c,1);
X}
X
Xreset() {
X
X noraw();
X endwin();
X unlink(filename);
X}
X
X
XRESET(s,b)
Xchar *s;
Xint b; {
X
X FILE *debug;
X
X reset();
X if ((debug = fopen("debug","w")) == NULL ) {
X perror("debug");
X exit(1);
X }
X fprintf(debug,s,b&0xff,seq_num);
X exit(-1);
X}
X
X/*
XDEBUG(b,bl,dat,s)
Xchar *b;
Xint bl, dat;
Xchar *s; {
X
X char buf[128];
X write(debug,b,131);
X sprintf(buf,s,bl,dat);
X write(debug,buf,strlen(buf));
X}
X*/
X
Xcaught() {
X char c;
X
X c = CANCEL;
X write(1,&c,1);
X reset();
X kill(0,SIGKILL);
X}
X
XSET_TIMER() {
X struct itimerval val;
X
X val.it_value.tv_sec = 60;
X val.it_value.tv_usec = 60 * 1000;
X timerclear(&val.it_interval);
X setitimer(ITIMER_REAL,&val,(struct itimerval *)0);
X}
X
XDISABLE_TIMER() {
X struct itimerval val;
X
X timerclear(&val.it_value);
X}
SHAR_EOF
if test 4439 -ne "`wc -c < 'receive.c'`"
then
echo shar: error transmitting "'receive.c'" '(should have been 4439 characters)'
fi
chmod +x 'receive.c'
fi # end of overwriting check
echo shar: extracting "'transmit.c'" '(2953 characters)'
if test -f 'transmit.c'
then
echo shar: will not over-write existing file "'transmit.c'"
else
sed 's/^ X//' << \SHAR_EOF > 'transmit.c'
X/* Version 1.0 6/12/85
X Jim Hein
X Nicolet Instrument Corp
X 5225 Verona Rd
X Madison, WI 53611-0288
X*/
X/*
X** transmit filename
X*/
X# include <curses.h>
X# include <file.h>
X# include <signal.h>
X# include <time.h>
X
X# define SOH 0x1
X# define NAK 0x15
X# define ACK 0x6
X# define EOT 0x4
X# define CANCEL 0x18
X
Xint flags;
Xchar filename[64];
X
Xmain(argc,argv)
Xint argc;
Xchar *argv[]; {
X
X int fd;
X register i;
X register char *p;
X char block[132];
X char c;
X int length, pid;
X int seq_num, xsum;
X int retries;
X struct sigvec vec;
X int caught();
X
X flags = argc;
X if (!((argc == 2) || (argc == 3))) {
X printf("ILLEGAL NUMBER OF ARGUMENTS.\n");
X printf("SYNOPSIS: xmodtran [-t] filename\n");
X exit(-1);
X }
X
X if (argc == 2) strcpy(filename,argv[1]); /* don't put in CR's */
X else {
X switch (argv[1][1]) {
X case 't':
X printf("Adding carriage returns, wait .......\n");
X strcpy(filename,ADDCR(argv[2]));
X printf("DONE\n");
X break;
X case 'm':
X printf("Changing lf's to cr's, wait .......\n");
X strcpy(filename,LF2CR(argv[2]));
X printf("DONE\n");
X break;
X default:
X printf("bad argument `%s'\n",argv[1]);
X printf("SYNOPSIS: xmodtran [-t] filename\n");
X exit(-1);
X }
X }
X
X if ((fd = open(filename,O_RDONLY,0644)) < 0) {
X perror(filename);
X exit(-1);
X }
X
X initscr();
X raw(); /* set terminal to 8-bit I/O */
X noecho();
X
X/*
X** Ignore interrupts from the user.
X** If the user could delete this program the terminal
X** would be left in a undiserable state of mind.
X*/
X vec.sv_handler = caught;
X vec.sv_mask = vec.sv_onstack = 0;
X sigvec(SIGALRM,&vec,(struct sigvec *)0);
X
X sigsetmask(-1 ^ (1 << (SIGALRM-1)));
X
X SET_TIMER();
X
X for(;;) { /* wait for NAK */
X read(0,&c,1); /* if not received in 60 sec's, program terminates */
X if ((c&0x7f) == NAK) break;
X }
X
X DISABLE_TIMER();
X
X seq_num = 1;
X p = &block[3];
X while ( (length = read(fd,p,128)) > 0 ) {
X
X p = block;
X *p++ = SOH;
X *p++ = seq_num;
X *p++ = 255 - seq_num;
X
X p += length;
X for( i = length; i < 128; i++) *p++ = 0;
X xsum = 0;
X for (i = 3; i < 131; i++) xsum += block[i];
X *p = xsum & 0xff;
X
X retries = 0;
X do {
X if (retries) sleep(10);
X
X write(1,block,132);
X SET_TIMER();
X read(0,&c,1);
X DISABLE_TIMER();
X
X if ( (c&0x7f) == CANCEL ) {RESET(); exit(-1);}
X if (++retries == 10 ) {
X c = CANCEL;
X write(1,&c,1);
X RESET(); exit(-1);
X }
X } while ( (c&0x7f) != ACK );
X
X seq_num = ++seq_num % 256;
X p = &block[3];
X
X }
X
X SET_TIMER();
X do {
X c = EOT;
X write(1,&c,1);
X read(0,&c,1);
X } while ( (c&0x7f) != ACK );
X DISABLE_TIMER();
X
X RESET();
X}
X
XRESET() {
X
X noraw();
X echo();
X endwin();
X if (flags == 3) unlink(filename);
X} /* END */
X
Xcaught() {
X RESET();
X kill(0,SIGKILL);
X}
X
XSET_TIMER() {
X struct itimerval val;
X
X val.it_value.tv_sec = 60;
X val.it_value.tv_usec = 60 * 1000;
X timerclear(&val.it_interval);
X setitimer(ITIMER_REAL,&val,(struct itimerval *)0);
X}
X
XDISABLE_TIMER() {
X struct itimerval val;
X
X timerclear(&val.it_value);
X}
SHAR_EOF
if test 2953 -ne "`wc -c < 'transmit.c'`"
then
echo shar: error transmitting "'transmit.c'" '(should have been 2953 characters)'
fi
chmod +x 'transmit.c'
fi # end of overwriting check
echo shar: extracting "'xmodrec.1'" '(579 characters)'
if test -f 'xmodrec.1'
then
echo shar: will not over-write existing file "'xmodrec.1'"
else
sed 's/^ X//' << \SHAR_EOF > 'xmodrec.1'
X.TH XMODREC 1
X.SH NAME
Xxmodrec \- receive file using XMODEM protocol
X.SH SYNOPSIS
X.B xmodrec
X[
X.B \-t
X] filename
X.SH DESCRIPTION
X.I Xmodrec
Xis used to receive a file from another computer, ie, IBM PC or look-alike.
XThe computer from which the file is to be received must also have the
XXMODEM protocol.
X.PP
XThis version of XMODEM uses the checksum method of error detection.
X.PP
XOptions:
X.TP 6
X.B \-t
XRemove the carriage returns from the incoming data. Also removes the ^Z
Xend-of-file marker and any data after it.
X.SH AUTHOR
XJim Hein {ihnp4,seismo}!uwvax!astroatc!nicmad!jhein
SHAR_EOF
if test 579 -ne "`wc -c < 'xmodrec.1'`"
then
echo shar: error transmitting "'xmodrec.1'" '(should have been 579 characters)'
fi
chmod +x 'xmodrec.1'
fi # end of overwriting check
echo shar: extracting "'xmodtran.1'" '(614 characters)'
if test -f 'xmodtran.1'
then
echo shar: will not over-write existing file "'xmodtran.1'"
else
sed 's/^ X//' << \SHAR_EOF > 'xmodtran.1'
X.TH XMODTRAN 1
X.SH NAME
Xxmodtran \- transmit a file using XMODEM protocol
X.SH SYNOPSIS
X.B xmodtran
X[
X.B \-t
X] filename
X.SH DESCRIPTION
X.I Xmodtran
Xis used to transmit a file to another computer, ie, IBM PC or look-alike.
XThe computer to which the file is to be transmitted must also have the
XXMODEM protocol.
X.PP
XThis version of XMODEM uses the checksum method of error detection.
X.PP
XOptions:
X.TP 6
X.B \-t
XAdds carriage returns to each line of data being transmitted. Some computers
Xrequire that the text file have a CR/LF at the end of each line.
X.SH AUTHOR
XJim Hein {ihnp4,seismo}!uwvax!astroatc!nicmad!jhein
SHAR_EOF
if test 614 -ne "`wc -c < 'xmodtran.1'`"
then
echo shar: error transmitting "'xmodtran.1'" '(should have been 614 characters)'
fi
chmod +x 'xmodtran.1'
fi # end of overwriting check
# End of shell archive
exit 0
-------- cut here --------
--
|------------|
| |-------| o| JVC HRD725U
Mr. Video | | | o| |--------------|
| | | | | |----| o o o |
| |-------| O| |--------------|
|------------| VHS Hi-Fi (the only way to go)
{seismo,ihnp4}!uwvax!astroatc!nicmad!brown
More information about the Comp.sources.unix
mailing list