DataMuseum.dk

Presents historical artifacts from the history of:

CP/M

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

See our Wiki for more about CP/M

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - download

⟦485f3a6d7⟧ TextFile

    Length: 23680 (0x5c80)
    Types: TextFile
    Names: »TELED.C«

Derivation

└─⟦b35f94715⟧ Bits:30003295 BDS C version 1.50 arbejdsdiskette til RC703 Piccolo
└─⟦b35f94715⟧ Bits:30005324 BDS C version 1.50 arbejdsdiskette til RC703 Piccolo
    └─ ⟦this⟧ »TELED.C« 

TextFile

/*
	TELEDIT.C	v1.3		(see TELEDIT.DOC)

	Modified for BDS C v1.50 by Leor Zolman, 10/82, 2/83

	A telecommunications program using Ward Christensen's
	"MODEM" File Transfer Protocol.

 	Modified by Nigel Harrison and Leor Zolman from XMODEM.C,
	which was written by:  Jack M. Wierda,
               modified by Roderick W. Hart and William D. Earnest

	Note that the Modem port interfaces are defined in BDSCIO.H,
	which must be configured with the correct values for your system.

	TELED now knows distinguishes between several different modes of
	operation: "terminal" mode (full duplex), "host" mode, and 
	"half-duplex" mode, as follows (designed by Stephen Stuvner):
	----------------------------------------------------------------
	TERMINAL MODE:		keyboard(char) ---> MoDem

				MoDem(char)    ---> CRT
	----------------------------------------------------------------
	ECHO (HOST) MODE:	keyboard(char) ---> MoDem
						`---> CRT
			If (char == CR).... LF ---> MoDem
						`---> CRT

				MoDem(char)    ---> CRT
						`---> MoDem
			If (char == CR).... LF ---> CRT
						`---> MoDem
	----------------------------------------------------------------
	1/2 DUPLEX MODE:	keyboard(char) ---> MoDem
						`---> CRT
			If (char == CR).... LF ---> CRT

				MoDem(char)    ---> CRT
	----------------------------------------------------------------
*/

#include <bdscio.h>
#include <hardware.h>

/*
	The following three defines must be customized by the user:
*/
#define HC	"Ø33H*"			/* Home cursor and print a "*"	*/
#define	SPECIAL	'^'-0x40		/* Gets out of terminal mode	*/
#define	CPUCLK 4			/* CPU clock rate, in MHz 	*/
#define BELL 7				/* ASCII bell 			*/

/*
	The rest of the defines need not be modified
*/

#define	SOH 1
#define	EOT 4
#define	ACK 6
#define	ERRORMAX 10
#define	RETRYMAX 10
#define	LF 10
#define	CR 13
#define	SPS 1500           		/*loops per second */
#define	NAK 21
#define	TIMEOUT -1
#define	TBFSIZ NSECTS*SECSIZ
#define	ML 1000				/* maximum source lines */
#define SEARCH_FIRST	17		/* BDOS calls */
#define SEARCH_NEXT	18

char linebufÆMAXLINEÅ;			/* string buffer */
char fnambufÆ50Å;			/* name of file for text collection */
int nlines, nl;				/* number of lines	*/
int linect;				/* current line	*/
char fflg;				/* text collection file flag */
char halfdup;				/* half-duplex mode	*/
char hostflg;				/* true in host mode	*/
char sflg;				/* transmit flag	*/


int kbhit()	/* test for console character available: */
æ
	return bios(2);
å

int getch()	/* get char from console raw, no echo */
æ
	while (!kbhit());
	return bios(3) & 0x7f;
å

int getchar()	/* get console char with echo, expand CR to CRLF locally: */
æ
	char c;

	putchar(c = getch());
	if (c == 'Ør')
		putchar('Øn');	
	return c;
å

putchar(c)	/* write char to console, expand LF to CRLF: */
æ
	if (c == 'Øn') putchar('Ør'); 
	bios(4,c);
å

send(data)	/* send char to modem */
char data;
æ
	while(!MOD_TBE)
		;
	MOD_TDATA(data);
å

main(argc,argv)
char **argv;
æ
	int i, j, k, l;			/* scratch integers */
	char *lineptrÆMLÅ;		/* allow ML source lines */
	char *inlÆMLÅ;			/* inserted line pointers */
	char *p;			/* scratch pointer */
	char bufÆBUFSIZÅ;		/* i/o buffer	*/
	int  in;			/* collect characters at in */
	char *alloc();			/* storage allocator */
	char *getm();			/* memory procuror */
	int baudrate;

	_allocp = NULL;			/* initialize alligator */

	linect = nlines = i = 0;
	fflg = hostflg = halfdup = FALSE;
	lineptrÆiÅ = NULL;

	baudrate = 0;			/* unknown baud rate */

   while(1)
   æ
	puts(CLEARS);
	printf("Teledit ver 1.3 ØnØn");

	printf("T: Terminal mode - no text collectionØn");
	printf("X: terminal mode with teXt collectionØn");
	printf("       In terminal mode:Øn");
	printf("   	SPECIAL (control-^): return to menuØn");
	printf("   	control-E: enter editorØn");
	printf("H: toggle Host mode (for user-user typing) (currently: %s)Øn",
					hostflg ? "ENABLED" : "disabled");
	printf("G: toGgle half-duplex system mode (currently: %s duplex)Øn",
					halfdup ? "HALF" : "full");
	printf("E: Edit collected textØn");
	printf("F: Flush text buffer to text collection fileØn");
	printf("C: flush and Close text collection fileØn");
	printf("U: select cp/m User areaØn");
	printf("V: select cp/m driVeØn");
	printf("D: print Directory for current drive and user areaØn");
	printf("S: Send a file, MODEM protocolØn");
	printf("R: Receive a file, MODEM protocolØn");   
	printf("B: select Baud rate (currently ");
		if (baudrate)
			printf("running at %d baud",baudrate);
		else
			printf("unchanged from last usage");
		puts(")Øn");

	printf("Q: quitØn");
	printf("SPECIAL: send SPECIAL char to modemØn");
	printf("ØnCommand: ");

	in = toupper(getchar());
	putchar('Øn');

     switch(in)
     æ
	case 'U':
		printf("Switch to user area: ");
		bdos(32,atoi(gets(linebuf)));
		break;

	case 'V':
		printf("Switch to drive: ");
		bdos(14,toupper(getchar()) - 'A');
		break;

	case 'D':
		dodir();
		goto wait;

	case SPECIAL:
		send(SPECIAL);
		break;

	case 'T':
	   terminal();
	   break;

	case 'X':
     if (fflg)
	printf("Text collection already in effect (filename '%s')Øn", fnambuf);
     else
     æ
	puts("Collection text filename = ");
	getname(fnambuf);

	puts("Wait...");
	if (fopen(fnambuf,buf) == ERROR)	/* if it already exists, */
		goto newfile;			/* go create it 	 */
	else					/* else query further	 */
	æ
		printf("ØnFile already exists; do you want to ");
		if(ask("overwrite it"))
		æ
	 newfile:  if (fcreat(fnambuf, buf) == ERROR)   /* Make new version */
		   æ
			printf("ØnCan't create %s", fnambuf);
			goto wait;
		   å
		å
		else if (ask("Do you want to append to it")) /* append to it */
		æ
		   if (fappend(fnambuf,buf) == ERROR)
		   æ
			printf("ØnCan't append for some reasonØn");
			goto wait;
		   å
		å
		else
		æ
			printf("File operations aborted.Øn");
			goto wait;
		å
	å
	
	fflg = TRUE;
     å
	printf("ØnReadyØn");

	while(1)
	æ	if(MOD_RDA)
		æ	putchar (in = MOD_RDATA & 0x7F);
			if (hostflg)
			æ
				send(in);
				if (in == 'Ør')
				æ
					send('Øn');
					putchar('Øn');
				å
			å

			if(in >= ' ')
				linebufÆi++Å = in;
			else
			æ	if(in == 'Øn') continue;
				if(in == CR)
				æ	linebufÆi++Å = 'Øn';
					linebufÆiÅ = NULL;
					p = getm(linebuf);
					if(p == NULL) continue;
					lineptrÆnlines++Å = p;
					lineptrÆnlinesÅ = NULL;
					if(nlines > 500) putchar(BELL);
					i = 0;
				å
				else if(in == 'Øt' øø in == 'Øf')
					linebufÆi++Å = in;
				else
					continue;
			å
		å
		if(kbhit())
		æ
			in = getch();
			if(in == SPECIAL)
				break;
			else if (in == ('E' & 037))
			æ
				ed(lineptr);
				printf("Terminal mode:ØnØn");
			å
			else
				send(in);
			if (hostflg øø halfdup)
			æ
				putchar(in);
				if (in == 'Ør')
				æ
					putchar('Øn');
					if (hostflg)
						send('Øn');
				å
			å	
		å
	å
	break;

     case 'S':
     case 'R':
	printf("File to %s = ", (in == 'S') ? "send" : "receive");
	getname(linebuf);

	if(in == 'R')
		readfile(linebuf);
	else
	æ
		if(fopen(linebuf, buf) == ERROR)
		æ	printf("Can't open %sØn", linebuf);
			goto wait;
		å
		sendfile(linebuf);
	å
	putchar(BELL);			/* beep when done */
	goto wait;

     case 'E':
	ed(lineptr);
	break;

     case 'D':
	dump(lineptr, buf);
	goto wait;

     case 'G':
	if (halfdup = !halfdup)
	æ
		puts("Going into half duplex modeØn");
		if (hostflg) æ
			puts("(HOST mode is being automatically disabled)Øn");
			hostflg = FALSE;
		å
		goto wait;
	å
	goto Hterm;

     case 'H':
	if (hostflg = !hostflg)
	æ
		puts("Going into HOST (user-user communication) modeØn");
		if (halfdup)
		æ
		  puts("(HALF DUPLEX mode is being automatically disabled)Øn");
			halfdup = FALSE;
		å
		goto wait;
	å

	Hterm:	puts("Going back to normal terminal modeØn");
		goto wait;

     case 'B':	/**** This section is left for the user to configure ****
		* 1) ask the user what baudrate to switch to,		*
		* 2) make the "baudrate" variable equal the new rate    *
		* 3) actually set the baudrate in whichever way is	*
		*    appropriate to your hardware.			*
		* Note that the "baudrate" variable comes up equal to	*
		* 0 to indicate that no explicit baud rate has been	*
		* selected by the user (i.e., the baudrate is in what-	*
		* ever state it was in before TELED was invoked)	*
		*********************************************************/

	puts("Baudrate selection is left for the user to configure.Øn");
	goto wait;

     case 'Q':
	if (fflg)
	æ
		printf("ØnSave file Ø"%sØ" to ",fnambuf);
		if (ask("disk"))
		æ	dump(lineptr, buf);
			putc(CPMEOF, buf);
			fclose(buf);
		å
	å
	exit(0);

     case 'C':
	if (fflg)
	æ
		printf("Closing %s...",fnambuf);
		dump(lineptr, buf);
		putc(CPMEOF, buf);
		fclose(buf);
		fflg = FALSE;
	å
	else puts("No currently active text collection fileØn");

 wait: 	puts("ØnØnHit any key to return to menu: ");
	getchar();
     å
   å
å

dodir()
æ
	char dmapos;		/* value returned by search calls */
	char first_time;	/* used in search routine */
	char tmpfnÆ20Å;		/* temp filename buffer */
	char fcbÆ36Å;
	int colno;		/* column count */
	int i;

	char nameÆ15Å;
	int drive;
		
	bdos(26,BASE+0x80);	/* ensure default DMA after read/write */
	printf("ØnFiles = ");
	if (getline(name,15) < 2)
		setfcb(fcb,"*.*");
	else 
		setfcb(fcb,name);

	drive= (fcbÆ0Å==0 ? bdos(25) : fcbÆ0Å-1 ) ;

	puts(CLEARS);
	printf("Directory for Drive %c, user area %d:ØnØn",
			drive+'A', bdos(32,0xff));

	colno = 1;
	first_time = TRUE;
	while (1) æ
		dmapos = bdos(first_time ? SEARCH_FIRST : SEARCH_NEXT,fcb);
		if (dmapos == 255) break;
		first_time = FALSE;
		hackname(tmpfn,(BASE + 0x80 + dmapos * 32));
		puts(tmpfn);
		for (i = strlen(tmpfn); i < 15; i++) putchar(' ');
		if ((colno += 15) > 65)
		æ
			putchar('Øn');
			colno =1;
		å
	å
å


hackname(dest,source)
char *dest, *source;
æ
	int i,j;

	j = 0;

	for (i = 1; i < 9; i++)
	æ
		if (sourceÆiÅ == ' ') break;
		destÆj++Å = sourceÆiÅ;
	å
	if (sourceÆ9Å != ' ')
		destÆj++Å = '.';

	for (i = 9; i < 12; i++)
	æ
		if (sourceÆiÅ == ' ') break;
		destÆj++Å = sourceÆiÅ;
	å
	destÆjÅ = 'Ø0';
	return dest;
å

dump(lineptr, buf)	/* dump text buffer	*/
char **lineptr, *buf;
æ
	int i;

	for(i = 0; lineptrÆiÅ != NULL; i++)
		if(fputs(lineptrÆiÅ, buf) == ERROR)
			printf("ØnØ7Error writing txt, disk full?Øn");

	lineptrÆ0Å = linect = nlines = _allocp = 0;
å

ed(lineptr)	/* editor */
char **lineptr;
æ
	char in, *inlÆMLÅ, *p, bufÆBUFSIZÅ;
	int i, j, k, l;
	char *getm(), *alloc();

	if(!fflg)
	æ	printf("ØnØ7No text buffer to edit.Øn");
		return;
	å

	printf("ØneditØn*");
	nl = 22;

	while (in = getchar())
	   switch (tolower(in)) æ
		case 'a':
			puts("Filename to yank = ");
			if(fopen(getname(linebuf), buf) == ERROR) æ
				printf ("Ør  Cannot open %s.Ør*", linebuf);
				continue;
			å

			for(i = 0; fgets(linebuf, buf); i++) æ
				inlÆiÅ = getm(linebuf);
				if(inlÆiÅ == NULL) break;
			å

			inlÆiÅ = NULL;
			iblock(lineptr, inl, linect);
			show (lineptr, linect, nl);
			continue;
		case 'b':
			linect = 0;
			show (lineptr, linect, nl);
			continue;
		case 'q':
			printf(CLEARS);
			return;
		case 'f':
			gets(linebuf);
			if((i = find(lineptr, linect)) >= 0) æ
				linect = i;
				show (lineptr, linect, nl);
			å
			else if((i = find(lineptr, 0)) >= 0) æ
				linect = i;
				show (lineptr, linect, nl);
			å
			else
			æ
				printf(HC);
				printf("  not foundØr*");
			å
			continue;
		case 'i':
			j = min(linect, 5);
			if(j == 0)
				printf(CLEARS);
			else æ
				show(lineptr, (linect - j), j);
				j++;
				printf("Øb ");
				for(; j; j--)
					putchar('Øn');
			å
			while(1) æ
				gets(linebuf);
				for(i = 0; linebufÆiÅ; i++)  
					if(linebufÆiÅ == CPMEOF)  
						break;
				if(linebufÆiÅ == CPMEOF) break;
				linebufÆi++Å = 'Øn';
				linebufÆiÅ = NULL;
				inlÆj++Å = getm(linebuf);
			å
			inlÆjÅ = NULL;
			iblock(lineptr, inl, linect);
			show (lineptr, linect, nl);
			continue;
		case 'k':
			putchar('Øn');
			show1(lineptr, linect);
			kill(lineptr, linect, 1);
			continue;
		case 'l':
			gets(linebuf);
			if((i = lfind(lineptr, linect)) >= 0) æ
				linect = i;
				show(lineptr, linect, nl);
			å
			else if((i = lfind(lineptr, 0)) >= 0) æ
				linect = i;
				show(lineptr, linect, nl);
			å
			else æ
				printf(HC);
				printf("  not foundØr*");
			å
			continue;
		case 'o':
			putchar('Øn');
			i = linect;
			while(gets(linebuf)) æ
				for(j = 0; linebufÆjÅ; j++)
					if(linebufÆjÅ == CPMEOF) break;
				if(linebufÆjÅ == CPMEOF) break;
				linebufÆj++Å = 'Øn';
				linebufÆjÅ = NULL;
				if(lineptrÆiÅ)
					free(lineptrÆiÅ);
				lineptrÆi++Å = getm(linebuf);
				if(i > nlines) lineptrÆ++nlinesÅ = NULL;
			å
			show (lineptr, linect, nl);
			continue;
		case 'p':
			linect = min((linect + nl), nlines);
			show (lineptr, linect, nl);
			continue;
		case 's':
			gets(linebuf);
			nl = max((atoi(linebuf)), 1);
			show (lineptr, linect, nl);
			continue;
		case 'z':
			linect = nlines;
			show(lineptr, linect, nl);
			continue;
		case '1': case '2': case '3': case '4': case '5':
		case '6': case '7': case '8': case '9': case '-':
			linebufÆ0Å = in;
			for (i = 1; (isdigit(in = getchar())); i++)
				linebufÆiÅ = in;
			linebufÆiÅ = NULL;
			i = atoi(linebuf);
			if (i < 0)
				j = max((linect + i), 0);
			else
				j = min((linect + i), nlines);
			in = tolower(in);
			if(j > linect && in == 'k')
				kill(lineptr, linect, (j - linect));
			else
				linect = j;
			if (in == 'p') linect = max((linect-nl), 0);
			show (lineptr, linect, nl);
			continue;
		case '#':
			printf (" of lines: %dØr*", nlines);
			continue;
		case 'Øn':
			if (lineptrÆlinectÅ != NULL) æ
				show1(lineptr, linect);
				linect++;
			å
			else
				printf (HC);
			continue;
		case ' ':
			if(linect)
				linect--;
			show(lineptr, linect, nl);
			continue;
		case ('E'&037):
			send(in);
			printf("Øn^E sentØn");
			return;
		default:
			printf(" ?Ør*");
		å
å

shocrt(sec,try,tot)
int sec,try,tot;
æ
	if(sflg)
		printf("Sending #%d (Try=%d Errs=%d)  Ør", sec, try, tot);
	else
		printf("Awaiting #%d (Try=%d, Errs=%d)  Ør", sec, try, tot);

	if(try && tot) putchar('Øn');
å

receive(seconds)
int seconds;
æ char data;
    int lpc,seccnt;
    for (lpc = 0; lpc < CPUCLK; lpc++)
        æ seccnt = seconds * SPS;
          while (!MOD_RDA && seccnt--);
          if(seccnt >= 0)
              æ data = MOD_RDATA;   
                return(data);
              å
        å
    return(TIMEOUT);
å

char *getname(linbuf)		/* get a reasonable filename from user */
char *linbuf;
æ
	int i;
	char c;

	while (1)
	æ
		gets(linbuf);
		if (!*linbuf)		/* reject null filename */
			goto reject;
		for (i = 0; c = linbufÆiÅ; i++)
		æ
			if (c < ' ' øø c > 0x7F)
				goto reject;
		å
		break;
    reject:	puts("ØnFilename = ");
		continue;
	å
	return linbuf;
å

	
purgeline()
æ while (MOD_RDA)
      MOD_RDATA;	/* purge the receive register	*/
å

readfile(file)
char *file;
æ int j, firstchar, sectnum, sectcurr, sectcomp, errors;
  int toterr,checksum;
  int errorflag, fd;
  int bufctr;
  char bufferÆBUFSIZÅ;

  sflg = FALSE;
  fd = creat(file);

  if(fd == -1)
  æ	printf("Teledit: cannot create %sØn", file);
	return;
  å

  printf("ØnReady to receive %sØn", file);
  sectnum = 0;
  errors = 0;
  toterr = 0;
  bufctr = 0;
  purgeline();
  shocrt(0,0,0);
  do
      æ errorflag = FALSE;
        do
            firstchar = receive (10);
        while(firstchar != SOH && firstchar != EOT && firstchar != TIMEOUT);

        if(firstchar == TIMEOUT)
            errorflag = TRUE;
        if(firstchar == SOH)
            æ sectcurr = receive (1);
              sectcomp = receive (1);
              if((sectcurr + sectcomp) == 255)
                  æ if(sectcurr == ((sectnum + 1) & 0xFF))
                        æ checksum = 0;
                          for(j = bufctr;j < (bufctr + SECSIZ);j++)
                              æ bufferÆjÅ = receive (1);
                                checksum = (checksum + bufferÆjÅ) & 0xff;
                              å
                          if(checksum == receive (1))
                              æ errors = 0;
                                sectnum = sectcurr;
                                bufctr = bufctr + SECSIZ;
                                if(bufctr == TBFSIZ)
                                    æ bufctr = 0;
				      write(fd, buffer, NSECTS);
                                    å
                                shocrt(sectnum,errors,toterr);
				send(ACK);
                              å
                          else
                              errorflag = TRUE;
                        å
                    else
                        if(sectcurr == sectnum)
                            æ do;
                              while(receive (1) != TIMEOUT) 
					;
			      send(ACK);
                            å
                        else
                            errorflag = TRUE;
                  å
              else
                  errorflag = TRUE;
            å
        if(errorflag == TRUE)
            æ errors++;
              if(sectnum)
                  toterr++;
              while(receive (1) != TIMEOUT);
              shocrt(sectnum,errors,toterr);
	      send(NAK);
            å
      å
  while(firstchar != EOT && errors != ERRORMAX);

  if((firstchar == EOT) && (errors < ERRORMAX))
      æ send(ACK);
	bufctr = (bufctr + SECSIZ - 1) / SECSIZ; 
	write(fd, buffer, bufctr);
        close(fd);
	printf("ØnDone -- returning to menu:Øn");
      å
  else
	printf("ØnØ7AbortingØnØn");
å

sendfile(file)
char *file;
æ char *npnt;
  int j, sectnum, sectors, attempts;
  int toterr,checksum;
  int bufctr, fd;
  char bufferÆBUFSIZÅ;

  sflg = TRUE;
  fd = open(file,0);

  if(fd == -1)
      æ printf("ØnTeledit: %s not foundØn", file);
	return;
      å
  else
	printf("ØnFile is %d sectors long.Øn",cfsize(fd));

  purgeline();
  attempts=0;
  toterr = 0;
  shocrt(0,0,0);

  while((receive (10) != NAK) && (attempts != 8))
      æ attempts++;
        shocrt(0,attempts,0);
      å
  if (attempts == 8)
      æ printf("ØnTimed out awaiting initial NAKØn");
	return;
      å
  attempts = 0;
  sectnum = 1;

  while((sectors = read(fd, buffer, NSECTS)) && (attempts != RETRYMAX))
      æ if(sectors == -1)
            æ printf("ØnFile read error.Øn");
              break;
            å
        else
            æ bufctr = 0;
              do
                  æ attempts = 0;
                    do
                        æ shocrt(sectnum,attempts,toterr);
			  send(SOH);
			  send(sectnum);
			  send(-sectnum-1);
                          checksum = 0;
                          for(j = bufctr;j < (bufctr + SECSIZ);j++)
			      æ send(bufferÆjÅ);
                                checksum = (checksum + bufferÆjÅ) & 0xff;
                              å
			  send(checksum);
                          purgeline();
                          attempts++;
                          toterr++;
                        å
                    while((receive (10) != ACK) && (attempts != RETRYMAX));
                    bufctr = bufctr + SECSIZ;
                    sectnum++;
                    sectors--;
                    toterr--;
                  å
              while((sectors != 0) && (attempts != RETRYMAX));
            å
      å
        if(attempts == RETRYMAX)
            printf("ØnNo ACK on sector, abortingØn");
        else
            æ attempts = 0;
              do
		  æ send(EOT);
                    purgeline();
                    attempts++;
                  å
              while((receive (10) != ACK) && (attempts != RETRYMAX));
              if(attempts == RETRYMAX)
                  printf("ØnNo ACK on EOT, abortingØn");
            å 
  close(fd);
  printf("ØnDone -- Returning to menu:Øn");
å

ask(s)
char *s;
æ

	char c;

again:	printf("%s (y/n)? ", s);
	c = tolower(getchar());
	if(c == 'y') æ
		puts("esØn");
		return 1;
	å

	else if(c == 'n')
		puts("oØn");
	else
	æ
		printf("  Ø7Yes or no, please...Øn");
		goto again;
	å
	return 0;
å

find(lineptr, linect)	/*Find a line having the pattern in linebuf        */
char *lineptrÆÅ;
int linect;
æ
	int i;

	for(i = linect; lineptrÆiÅ != NULL; i++)
		if(pat(lineptrÆiÅ, linebuf) >= 0)
			return(i);
	return(-1);
å

kill(lineptr, linect, nl)	/* erase lines */
char *lineptrÆÅ;
int linect, nl;
æ
	int i, j;

	for (i = linect; lineptrÆiÅ != NULL && nl > 0; i++, nl--) æ
		free(lineptrÆiÅ);
		nlines--;
	å
	lineptrÆlinectÅ = NULL;
	if(lineptrÆiÅ != NULL) æ
		j = (nlines - linect) * 2;
		movmem(&lineptrÆiÅ, &lineptrÆlinectÅ, j + 2); 
	å
å

lfind(lineptr, linect) 		/* find pattern at beginning of a line */
char *lineptrÆÅ;
int linect;
æ
	int i, j;
	char lineÆMAXLINEÅ;

	j = strlen(linebuf);
	for (i = linect; lineptrÆiÅ != NULL; i++) æ
		strcpy(line, lineptrÆiÅ);
		lineÆjÅ = NULL;
		if(strcmp(line, linebuf) == 0)
			return i;
	å
	return -1;
å
	

pat(s, t)	/* pattern match..*/
char sÆÅ, tÆÅ;
æ
	int i, j, k;

	for(i = 0; sÆiÅ != 'Ø0'; i++)
	   æ
		for(j = i, k=0; tÆkÅ != 'Ø0' && sÆjÅ == tÆkÅ; j++, k++)
			;
		if(tÆkÅ == 'Ø0')
			return(i);
	   å
	return(-1);
å

show (lineptr, linect, nl)	/* screen current frame */
char *lineptrÆÅ;
int linect, nl;
æ
	int i;

	printf (CLEARS);
	putchar('Øn');

	for (i = linect; i < (linect+nl) && lineptrÆiÅ != NULL; i++)
		printf("%s", lineptrÆiÅ);
	printf (HC);
	return(i);
å

show1(lineptr, linect)
char **lineptr;
int linect;
æ
	int i;

	for(i = 0; i < nl; i++)
		putchar('Øn');

	if((linect + nl) >= nlines)
		putchar('Øn');
	else
		printf("%s", lineptrÆlinect+nlÅ);

	printf(HC);

	for(i = 0; i < 78; i++)
		putchar(' ');

	printf("Ør*");
å

terminal()	/* terminal mode, no text */
æ
	int in;

	while(1)
	æ
		if(MOD_RDA)
		æ
			putchar(in = MOD_RDATA);
			if (hostflg)
			æ
				send(in);
				if (in == 'Ør')
				æ
					send('Øn');
					putchar('Øn');
				å
			å
		å			
			
		if(kbhit())
		æ
			in = getch();
			if (in == SPECIAL)
				return;
			else
				send(in);

			if (hostflg øø halfdup)
			æ
				putchar(in);
				if (in == 'Ør')
				æ
					putchar('Øn');
					if (hostflg)
						send('Øn');
				å
			å
		å
	å
å

char *getm(line)	/* get memory for line, store it, return pointer */
char lineÆÅ;
æ
	char *p, *alloc();

	if ((p = alloc(strlen(line) + 1)) != NULL)
		strcpy(p, line);
	return(p);
å

iblock(rb, ib, cl)		/* insert block ib into rb at cl */
char *rbÆÅ, *ibÆÅ;
int cl;
æ
	int i, j;

	j = 0;
	if (rbÆclÅ) æ
		for (i = 0; ibÆiÅ; i++)
			;
		j = (nlines - cl) * 2;
		movmem (&rbÆclÅ, &rbÆcl+iÅ, j + 2);
	å
	for (i = 0; ibÆiÅ; i++, cl++)
		rbÆclÅ = ibÆiÅ;
	if(!j) rbÆclÅ = NULL;
	nlines += i;
	return cl;	/* return new current line */
å
«eof»