DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - download
Index: ┃ T b

⟦347d4dfa6⟧ TextFile

    Length: 4096 (0x1000)
    Types: TextFile
    Names: »batch.c«

Derivation

└─⟦a0efdde77⟧ Bits:30001252 EUUGD11 Tape, 1987 Spring Conference Helsinki
    └─ ⟦this⟧ »EUUGD11/euug-87hel/sec1/xmodem/batch.c« 

TextFile

/*
 *  Various routines for batch tranfer
 */

#include "xmodem.h"

/* make sure filename sent or received in YMODEM batch is canonical */
/* Turn Unix '/' into CP/M ':' and translate to all lower case */

unixify (name)
char *name;
	{
	char *ptr;
	for (ptr=name; *ptr; ++ptr)
		{
		if (*ptr == '/')
			*ptr = ':';
		if (isupper (*ptr))
			*ptr |= 040;
		}
	}

cpmify (name)
char *name;
	{
	char *ptr;
	for (ptr=name; *ptr; ++ptr)
		{
		if (*ptr == ':')
			*ptr = '/';
		if (isupper (*ptr))
			*ptr |= 040;
		}
	}

\f


/* convert a CP/M file name received in a MODEM7 batch transfer
 * into a unix file name mapping '/' into ':', converting to all
 * upper case and adding dot in proper place.  
 * Use "filename" to hold name.
 * Code stolen from D. Thompson's (IRTF) xmodem.c
 */

char *cpm_unix (string)
unsigned char *string;
{
	register int i;
	unsigned char *iptr, temp;
	register char *optr;

	if (*string == '\0')
		error("Null file name in MODEM7 batch receive", TRUE);

	for (iptr=string; (temp = *iptr) ; ) {
		temp &= 0177;			/* strips bit 7 */
		if (isupper(temp))
			temp |= 040;		/* set bit 5 for lower case */
		if (temp == '/') 
			temp=':';		/* map / into : */
		*iptr++ = temp;
	}

	/* put in main part of name */
	iptr=string;
	optr=filename;
	for (i=0; i<8; i++) {
		if (*iptr != ' ')
			*optr++ = *iptr++;
	}

	/* add dot */
	*optr++ = '.';

	/* put in extension */
	iptr = &string[8];
	for (i=0; i<3; i++) {
		if (*iptr != ' ')
			*optr++ = *iptr++;
	}

	*optr++ = '\000';
	return (filename);
}
\f


/* Send 11 character CP/M filename for MODEM7 batch transmission
 * Returns -1 for a protocol error; 0 if successful
 * NOTE: we tromp a little on the argument string!
 * code stolen from D. Thompson's (IRTF) xmodem.c
 */

send_name(name)
char *name;
{
	register int cksum;
	register char *ptr;

	xmdebug("send_name");

	/* append cp/m EOF */
	name[NAMSIZ] = CTRLZ;
	name[NAMSIZ+1] = '\000';

	/* create checksum */
	ptr = name;
	cksum = 0;
	while (*ptr)
		cksum += *ptr++;
	cksum &= 0x00FF;

	/* send filename */

	sendbyte(ACK);
	ptr = name;
	sendbyte(*ptr++);

	while (*ptr) {

checknak:		switch (readbyte(6)) {

			case CAN: {
				if (readbyte(3) == CAN)
					error("Program Canceled by User",TRUE);
				else
					goto checknak;
			}

			case ACK: break;

			case TIMEOUT: {
				logit("Timeout while sending filename\n");
				sendbyte(BAD_NAME);
				return (-1);
			}

			default: {
				logit("Error while sending filename\n");
				sendbyte(BAD_NAME);
				return (-1);
			}
		}	

		sendbyte (*ptr++);
	}

	/* Check checksum returned by other side against my value */
	if (readbyte(10) != cksum) {
		logit("Bad checksum while sending filename\n");
		sendbyte(BAD_NAME);
		return (-1);
	}

	sendbyte(ACK);
	return (0);
}
\f


/* Convert Unix filename to 11 character CP/M file name (8 char name,
 * 3 char extension, dot in between is not included).
 * map ':' into '/'; Use filename to hold name.
 * code stolen from D. Thompson's (IRTF) xmodem.c
 */

char *unix_cpm(string)
char *string;
{
	register char *iptr, *optr, temp;
	int i;

	char *rindex();
	char *strcpy();

	/* blank 11 character name */
	(void) strcpy (filename,"           ");

	/* strip off any path name */
	if ((iptr = rindex(string,'/')))
		iptr++;
	else
		iptr=string;

	/* skip leading '.'s */
	while (*iptr == '.')
		iptr++;

	/* copy main part of name */
	optr = filename;
	i = 8;
	while ((i--) && (*iptr) && (*iptr != '.'))
		*optr++ = *iptr++;

	/* advance to unix extension, or end of unix name */
	while ((*iptr != '.') && (*iptr))
		iptr++;

	/* skip over the  '.' */
	while (*iptr == '.')
		iptr++;

	/* copy extension */
	optr = &filename[8];
	i=3;
	while ((i--) && (*iptr) && (*iptr != '.'))
		*optr++ = *iptr++;

	filename[NAMSIZ] = '\000';

	/* Fuss with name */
	for (iptr=filename; (temp = *iptr) ;) {
		temp &= 0177;			/* strip bit 7 (parity bit) */
		if (islower(temp))
			temp &= ~040;		/* make upper case */
		if (temp == ':')
			temp ='/';		/* map ':' into '/' */
		*iptr++ = temp;
	}

	if (DEBUG)
		fprintf (LOGFP, "DEBUG: File %s sent as %s\n", string, filename);

	return(filename);
}