/* ÔÅÌÅÄÉÔ.Ã V1.2 (SEE ÔÅÌÅÄÉÔ.ÄÏÃ) ÍODIFIED FOR ÂÄÓ Ã V1.50 BY ÌEOR ÚOLMAN, 10/21/82 Á TELECOMMUNICATIONS PROGRAM USING ×ARD ÃHRISTENSEN'S "ÍÏÄÅÍ" ÆILE ÔRANSFER ÐROTOCOL. ÍODIFIED BY ÎIGEL ÈARRISON AND ÌEOR ÚOLMAN FROM ØÍÏÄÅÍ.Ã, WHICH WAS WRITTEN BY: ÊACK Í. ×IERDA, MODIFIED BY ÒODERICK ×. ÈART AND ×ILLIAM Ä. ÅARNEST ÎOTE THAT ÍODEM PORT NUMBERS, MASKS, ETC., ARE TAKEN FROM ÂÄÓÃÉÏ.È, WHICH MUST HAVE THE CORRECT VALUES FOR YOUR SYSTEM. */ #INCLUDE #INCLUDE /* ÔHE FOLLOWING THREE DEFINES MUST BE CUSTOMIZED BY THE USER: */ #DEFINE ÈÃ "\33È*" /* ÈOME CURSOR AND PRINT A "*" */ #DEFINE ÓÐÅÃÉÁÌ '^'-0X40 /* ÇETS OUT OF TERMINAL MODE */ #DEFINE ÃÐÕÃÌË 4 /* ÃÐÕ CLOCK RATE, IN ÍÈZ */ /* ÔHE REST OF THE DEFINES NEED NOT BE MODIFIED */ #DEFINE ÓÏÈ 1 #DEFINE ÅÏÔ 4 #DEFINE ÁÃË 6 #DEFINE ÅÒÒÏÒÍÁØ 10 #DEFINE ÒÅÔÒÙÍÁØ 10 #DEFINE ÌÆ 10 #DEFINE ÃÒ 13 #DEFINE ÓÐÓ 1500 /*LOOPS PER SECOND */ #DEFINE ÎÁË 21 #DEFINE ÔÉÍÅÏÕÔ -1 #DEFINE ÔÂÆÓÉÚ ÎÓÅÃÔÓ*ÓÅÃÓÉÚ #DEFINE ÍÌ 1000 /* MAXIMUM SOURCE LINES */ #DEFINE ÓÅÁÒÃÈ_ÆÉÒÓÔ 17 /* ÂÄÏÓ CALLS */ #DEFINE ÓÅÁÒÃÈ_ÎÅØÔ 18 CHAR LINEBUF[ÍÁØÌÉÎÅ]; /* 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 ECHOFLG; /* WHETHER TO ECHO */ 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 CHAR FROM CONSOLE WITH ECHO, EXPAND ÃÒ TO ÃÒÌÆ: */ { CHAR C; IF ((C = GETCH()) == '\R') C = '\N'; PUTCHAR(C); RETURN C; } PUTCHAR(C) /* WRITE CHAR TO CONSOLE, EXPAND ÌÆ TO ÃÒÌÆ: */ { IF (C == '\N') PUTCHAR('\R'); BIOS(4,C); } INT MOREADY() /* RETURN ÔÒÕÅ IF THE MODEM IS READY FOR OUTPUT */ { RETURN ÍÏÄ_ÔÂÅ; } INT MIREADY() /* RETURN ÔÒÕÅ IF INPUT IS PRESENT ON THE MODEM */ { RETURN ÍÏÄ_ÒÄÁ; } SEND(DATA) /* SEND CHAR TO MODEM */ CHAR DATA; { WHILE(!MOREADY()) ; ÍÏÄ_ÔÄÁÔÁ(DATA); } MAIN(ARGC,ARGV) CHAR **ARGV; { INT I, J, K, L; /* SCRATCH INTEGERS */ CHAR *LINEPTR[ÍÌ]; /* ALLOW ÍÌ SOURCE LINES */ CHAR *INL[ÍÌ]; /* INSERTED LINE POINTERS */ CHAR *P; /* SCRATCH POINTER */ CHAR BUF[ÂÕÆÓÉÚ]; /* I/O BUFFER */ INT IN; /* COLLECT CHARACTERS AT IN */ CHAR *ALLOC(); /* STORAGE ALLOCATOR */ CHAR *GETM(); /* MEMORY PROCUROR */ _ALLOCP = ÎÕÌÌ; /* INITIALIZE ALLIGATOR */ LINECT = NLINES = I = 0; FFLG = ECHOFLG = ÆÁÌÓÅ; LINEPTR[I] = ÎÕÌÌ; WHILE(1) { PUTS(ÃÌÅÁÒÓ); PRINTF("ÔELEDIT VER 1.1\N\N"); PRINTF("Ô: ÔERMINAL MODE - NO TEXT COLLECTION\N"); PRINTF("Ø: TERMINAL MODE WITH TEØT COLLECTION\N"); PRINTF(" ÉN TERMINAL MODE:\N"); PRINTF(" ÓÐÅÃÉÁÌ (CONTROL-^): RETURN TO MENU\N"); PRINTF(" CONTROL-Å: ENTER EDITOR\N"); PRINTF("Ç: TOÇGLE ECHO MODE (CURRENTLY SET TO: %SECHO)\N", ECHOFLG ? "" : "NO "); PRINTF("Å: ÅDIT COLLECTED TEXT\N"); PRINTF("Æ: ÆLUSH TEXT BUFFER TO TEXT COLLECTION FILE\N"); PRINTF("Õ: SELECT CP/M ÕSER AREA\N"); PRINTF("Ö: SELECT CP/M DRIÖE\N"); PRINTF("Ä: PRINT ÄIRECTORY FOR CURRENT DRIVE AND USER AREA\N"); PRINTF("Ó: ÓEND A FILE, ÍÏÄÅÍ PROTOCOL\N"); PRINTF("Ò: ÒECEIVE A FILE, ÍÏÄÅÍ PROTOCOL\N"); PRINTF("Ñ: QUIT\N"); PRINTF("ÓÐÅÃÉÁÌ: SEND ÓÐÅÃÉÁÌ CHAR TO MODEM\N"); PRINTF("\NÃOMMAND: "); IN = TOUPPER(GETCHAR()); PUTCHAR('\N'); SWITCH(IN) { CASE 'Õ': PRINTF("ÓWITCH TO USER AREA: "); BDOS(32,ATOI(GETS(LINEBUF))); BREAK; CASE 'Ö': PRINTF("ÓWITCH TO DRIVE: "); BDOS(14,TOUPPER(GETCHAR()) - 'Á'); BREAK; CASE 'Ä': DODIR(); BREAK; CASE ÓÐÅÃÉÁÌ: SEND(ÓÐÅÃÉÁÌ); BREAK; CASE 'Ô': TERMINAL(); BREAK; CASE 'Ø': IF (FFLG) PRINTF("ÔEXT COLLECTION ALREADY IN EFFECT (FILENAME '%S')\N", FNAMBUF); ELSE { PUTS("ÃOLLECTION TEXT FILENAME = "); GETS(FNAMBUF); PUTS("×AIT..."); IF(FOPEN(FNAMBUF,BUF) != ÅÒÒÏÒ) { PRINTF("\NÆILE ALREADY EXISTS; DO YOU WANT TO "); IF(!ASK("OVERWRITE IT")) BREAK; } IF(FCREAT(FNAMBUF, BUF) == ÅÒÒÏÒ) { PRINTF("\NÃAN'T CREATE %S", FNAMBUF); BREAK; } FFLG = ÔÒÕÅ; } PRINTF("\NÒEADY\N"); WHILE(1) { IF(MIREADY()) { PUTCHAR (IN = ÍÏÄ_ÒÄÁÔÁ); IF(IN >= ' ') LINEBUF[I++] = IN; ELSE { IF(IN == '\N') CONTINUE; IF(IN == ÃÒ) { LINEBUF[I++] = '\N'; LINEBUF[I] = ÎÕÌÌ; P = GETM(LINEBUF); IF(P == ÎÕÌÌ) CONTINUE; LINEPTR[NLINES++] = P; LINEPTR[NLINES] = ÎÕÌÌ; IF(NLINES > 500) PUTCHAR('\7'); I = 0; } ELSE IF(IN == '\T' || IN == '\F') LINEBUF[I++] = IN; ELSE CONTINUE; } } IF(KBHIT()) { IF(ECHOFLG) IN = GETCHAR(); *1Í5 IN = GETCH(); IF(IN == ÓÐÅÃÉÁÌ) BREAK; ELSE IF(IN == ('Å' & 037)) { ED(LINEPTR); PRINTF("ÔERMINAL MODE:\N\N"); } ELSE SEND(IN); } } BREAK; CASE 'Ó': CASE 'Ò': PRINTF("ÆILE TO %S =ÂÊ9== 'Ó') ? "SEND" : "RECEIVE"); GETS(LINEBUF); IF(IN == 'Ò') READFILE(LINEBUF); ELSE { IF(FOPEN(LINEBUF, BUF) == ÅÒÒÏÒ) { PRINTF("\7ÔELEDIT: CAN'T OPEN %S\N", LINEBUF); SLEEP(15); BREAK; } SENDFILE(LINEBUF); } PUTCHAR(7); /* BEEP WHEN DONE */ BREAK; CASE 'Å': ED(LINEPTR); BREAK; CASE 'Ä': DUMP(LINEPTR, BUF); BREAK; CASE 'Ç': ECHOFLG = !ECHOFLG; BREAK; CASE 'Ñ': IF (FFLG) { PRINTF("\NÓAVE FILE \"%S\" TO ",FNAMBUF); IF (ASK("DISK")) { DUMP(LINEPTR, BUF); PUTC(ÃÐÍÅÏÆ, BUF); FFLUSH(BUF); FCLOSE(BUF); } } EXIT(0); } } } 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,ÂÁÓÅ+0X80); /* ENSURE DEFAULT ÄÍÁ AFTER READ/WRITE */ PRINTF("\NÆILES = "); IF (GETLINE(NAME,15) < 2) SETFCB(FCB,"*.*"); ELSE SETFCB(FCB,NAME); DRIVE= (FCB[0]==0 ? BDOS(25) : FCB[0]-1 ) ; PUTS(ÃÌÅÁÒÓ); PRINTF("ÄIRECTORY FOR ÄRIVE %C, USER AREA %D:\N\N", DRIVE+'Á', BDOS(32,0XFF)); COLNO = 1; FIRST_TIME = ÔÒÕÅ; WHILE (1) { DMAPOS = BDOS(FIRST_TIME ? ÓÅÁÒÃÈ_ÆÉÒÓÔ : ÓÅÁÒÃÈ_ÎÅØÔ,FCB); IF (DMAPOS == 255) BREAK; FIRST_TIME = ÆÁÌÓÅ; HACKNAME(TMPFN,(ÂÁÓÅ + 0X80 + DMAPOS * 32)); PUTS(TMPFN); FOR (I = STRLEN(TMPFN); I < 15; I++) PUTCHAR(' '); IF ((COLNO += 15) > 65) { PUTCHAR('\N'); COLNO =1; } } PUTS("\N\NÈIT ANY KEY TO RETURN TO MENU: "); GETCHAR(); } 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 **LINEP%,ÖJ { INT I; FOR(I = 0; LINEPTR[I] != ÎÕÌÌ; I++) IF(FPUTS(LINEPTR[I], BUF) == ÅÒÒÏÒ) PRINTF("\N\7ÅRROR WRITING TXT, DISK FULL?\N"); LINEPTR[0] = LINECT = NLINES = _ALLOCP = 0; } ED(LINEPTR) /* EDITOR */ CHAR **LINEPTR; { CHAR IN, *INL[ÍÌ], *P, BUF[ÂÕÆÓÉÚ]; INT I, J, K, L; CHAR *GETM(), *ALLOC(); IF(!FFLG) { PRINTF("\N\7ÎO TEXT BUFFER TO EDIT.\N"); RETURN; J5 PRINTF("\NEDIT\N*"); NL = 22; WHILE (IN = GETCHAR()) SWITCH (TOLOWER(IN)) { CASE 'A': PUTS("ÆILENAME TO YANK = "); GETS(LINEBUF); IF(FOPEN(LINEBUF, BUF) == ÅÒÒÏÒ) { PRINTF ("\R ÃANNOT OPEN %S.\R*", LINEBUF); CONTINUE; } FOR(I = 0; FGETS(LINEBUF, BUF); I++) { INL[I] = GETM(LINEBUF); IF(INL[I] == ÎÕÌÌ) BREAK; } INL[I] = ÎÕÌÌ; IBLOCK(LINEPTR, INL, LINECT); SHOW (LINEPTR, LINECT, NL); CONTINUE; CASE 'B': LINECT = 0; SHOW (LINEPTR, LINECT, NL); CONTINUE; CASE 'Q': PRINTF(ÃÌÅÁÒÓ); 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(ÈÃ); PRINTF(" NOT FOUND\R*"); } CONTINUE; CASE 'I': J = MIN(LINECT, 5); IF(J == 0) PRINTF(ÃÌÅÁÒÓ); ELSE { SHOW(LINEPTR, (LINECT - J), J); J++; PRINTF("\B "); FOR(; J; J--) PUTCHAR('\N'); } WHILE(1) { GETS(LINEBUF); FOR(I = 0; LINEBUF[I]; I++) Ê!LINEBUF[I] == ÃÐÍÅÏÆ) BREAK; IF(LINEBUF[I] == ÃÐÍÅÏÆ) BREAK; LINEBUF[I++] = '\N'; LINEBUF[I] = ÎÕÌÌ; INL[J++] = GETM(LINEBUF); } INL[J] = ÎÕÌÌ; 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(ÈÃ); PRINTF(" NOT FOUND\R*"); } CONTINUE; CASE 'O': PUTCHAR('\N'); I = LINECT; WHILE(GETS(LINEBUF)) { FOR(J = 0; LINEBUF[J]; J++) IF(LINEBUF[J] == ÃÐÍÅÏÆ) BREAK; IF(LINEBUF[J] == ÃÐÍÅÏÆ) BREAK; LINEBUF[J++] = '\N'; LINEBUF[J] = ÎÕÌÌ; IF(LINEPTR[I]) FREE(LINEPTR[I]); LINEPTR[I++] = GETM(LINEBUF); IF(I > NLINES) LINEPTR[++NLINES] = ÎÕÌÌ; } SHOW (LINEPTR, LINECT, NL); CONTINUE; CASE 'P': LINECT = MIN((LINECT + NL), NLINES); SHOW (LINEPTR, LINECT, NL); C7+M 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] = ÎÕÌÌ; 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] != ÎÕÌÌ) { SHOW1(LINEPTR, LINECT); LINECT++; } ELSE PRINTF (ÈÃ); CONTINUE; CASE ' ': IF(LINECT) LINECT--; SHOW(LINEPTR, LINECT, NL); CONTINUE; CASE ('Å'&037): SEND(IN); PRINTF("\N^Å SENT\N"); RETURN; DEFAULT: PRINTF(" ?\R*"); } } SHOCRT(SEC,TRY,TOT) INT SEC,TRY,TOT; { IF(SFLG) PRINTF("ÓENDING #%D (ÔRY=%D ÅRRS=%D) \R", SEC, TRY, TOT); ELSE PRINTF("ÁWAITING %EU%D, ÅRRS=%D) \R", SEC, TRY, TOT); IF(TRY && TOT) PUTCHAR('\N'); } RECEIVE(SECONDS) INT SECONDS; { CHAR DATA; INT LPC,SECCNT; FOR (LPC = 0; LPC < ÃÐÕÃÌË; LPC++) { SECCNT = SECONDS * ÓÐÓ; WHILE (!MIREADY() && SECCNT--); IF(SECCNT >= 0) { DATA = ÍÏÄ_ÒÄÁÔÁ; RETURN(DATA); } } RETURN(ÔÉÍÅÏÕÔ); } PURGELINE() { WHILE (MIREADY()) ÍÏÄ_ÒÄÁÔÁ; /* 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[ÂÕÆÓÉÚ]; SFLG = ÆÁÌÓÅ; FD = CREAT(FILE); IF(FD == -1) { PRINTF("ÔELEDIT: CANNOT CREATE %S\N", FILE); EXIT(1); } PRINTF("\NÒEADY TO RECEIVE %S\N", FILE); SECTNUM = 0; ERRORS = 0; TOTERR = 0; BUFCTR = 0; PURGELINE(); SHOCRT(0,0,0); DO { ERRORFLAG = ÆÁÌÓÅ; DO FIRSTCHAR = RECEIVE (10); WHILE(FIRSTCHAR != ÓÏÈ && FIRSTCHAR != ÅÏÔ && FIRSTCHAR != ÔÉÍÅÏÕÔ); IF(FIRSTCHAR == ÔÉÍÅÏÕÔ) ERRORFLAG = ÔÒÕÅ; IF(FIRSTCHAR == ÓÏÈ) { SECTCURR = RECEIVE (1); SECTCOMP = RECEIVE (1); IF((SECTCURR + SECTCOMP) == 255) { IF(SECTCURR == ((SECTNUM + 1) & 0XÆÆ)) { CHECKSUM = 0; 2=É!J = BUFCTR;J < (BUFCTR + ÓÅÃÓÉÚ);J++) { BUFFER[J] = RECEIVE (1); CHECKSUM = (CHECKSUM + BUFFER[J]) & 0XFF; } IF(CHECKSUM == RECEIVE (1)) { ERRORS = 0; SECTNUM = SECTCURR; BUFCTR = BUFCTR + ÓÅÃÓÉÚ; IF(BUFCTR == ÔÂÆÓÉÚ) { BUFCTR = 0; WRITE(FD, BUFFER, ÎÓÅÃÔÓ); } SHOCRT(SECTNUM,ERRORS,TOTERR); SEND(ÁÃË); } ELSE ERRORFLAG = ÔÒÕÅ; J5 ELSE IF(SECTCURR == SECTNUM) { DO; WHILE(RECEIVE (1) != ÔÉÍÅÏÕÔ) ; SEND(ÁÃË); } *1Í5 ERRORFLAG = ÔÒÕÅ; } ELSE ERRORFLAG = ÔÒÕÅ; } IF(ERRORFLAG == ÔÒÕÅ) { ERRORS++; IF(SECTNUM) TOTERR++; WHILE(RECEIVE (1) != ÔÉÍÅÏÕÔ); SHOCRT(SECTNUM,ERRORS,TOTERR); SEND(ÎÁË); } } WHILE(FIRSTCHAR != ÅÏÔ && ERRORS != ÅÒÒÏÒÍÁØ); IF((FIRSTCHAR == ÅÏÔ) && (ERRORS < ÅÒÒÏÒÍÁØ)) { SEND(ÁÃË); BUFCTR = (BUFCTR + ÓÅÃÓÉÚ - 1) / ÓÅÃÓÉÚ; WRITE(FD, BUFFER, BUFCTR); CLOSE(FD); PRINTF("\NÄONE -- RETURNING TO MENU:\N"); } ELSE PRINTF("\N\7ÁBORTING\N\N"); } SENDFILE(FILE) CHAR *FILE; { CHAR *NPNT; INT J, SECTNUM, SECTORS, ATTEMPTS; INT TOTERR,CHECKSUM; INT BUFCTR, FD; CHAR BUFFER[ÂÕÆÓÉÚ]; SFLG = ÔÒÕÅ; FD = OPEN(FILE,0); IF(FD == -1) { PRINTF("\NÔELEDIT: %S NOT FOUND\N", FILE); RETURN; } ELSE PRINTF("\NÆILE IS %D SECTORS LONG.\N",CFSIZE(FD)); PURGELINE(); ATTEMPTS=0; TOTERR = 0; SHOCRT(0,0,0); WHILE((RECEIVE (10) != ÎÁË) && (ATTEMPTS != 8)) { ATTEMPTS++; SHOCRT(0,ATTEMPTS,0); } IF (ATTEMPTS == 8) { PRINTF("\NÔIMED OUT AWAITING INITIAL ÎÁË\N"); EXIT(); } ATTEMPTS = 0; SECTNUM = 1; WHILE((SECTORS = READ(FD, BUFFER, ÎÓÅÃÔÓ)) && (ATTEMPTS != ÒÅÔÒÙÍÁØ)) { IF(SECTORS == -1) { PRINTF("\NÆILE READ ERROR.\N"); BREAK; } ELSE { BUFCTR = 0; DO { ATTEMPTS =Ã!"=5 { SHOCRT(SECTNUM,ATTEMPTS,TOTERR); SEND(ÓÏÈ); SEND(SECTNUM); SEND(-SECTNUM-1); CHECKSUM = 0; FOR(J = BUFCTR;J < (BUFCTR + ÓÅÃÓÉÚ);J++) { SEND(BUFFER[J]); CHECKSUM = (CHECKSUM + BUFFER[J]) & 0XFF; } SEND(CHECKSUM); PURGELINE(); ATTEMPTS++; TOTERR++; } WHILE((RECEIVE (10) != ÁÃË) && (ATTEMPTS != ÒÅÔÒÙÍÁØ)); BUFCTR = BUFCTR + ÓÅÃÓÉÚ; SECTNUM++; SECTORS--; TOTERR--; } WHILE((SECTORS != 0) && (ATTEMPTS != ÒÅÔÒÙÍÁØ)); } } IF(ATTEMPTS == ÒÅÔÒÙÍÁØ) PRINTF("\NÎO ÁÃË ON SECTOR, ABORTING\N"); ELSE { ATTEMPTS = 0; DO { SEND(ÅÏÔ); PURGELINE(); ATTEMPTS++; } WHILE((RECEIVE (10) != ÁÃË) && (ATTEMPTS != ÒÅÔÒÙÍÁØ)); IF(ATTEMPTS == ÒÅÔÒÙÍÁØ) PRINTF("\NÎO ÁÃË ON ÅÏÔ, ABORTING\N"); } CLOSE(FD); PRINTF("\NÄONE -- ÒETURNING 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(" \7ÙES OR NO, PLEASE...\N"); GOTO AGAIN; } RETURN 0; } FIND(LINEB%9 Ñ% /*ÆIND A LINE HAVING THE PATTERN IN LINEBUF */ CHAR *LINEPTR[]; INT LINECT; { INT I; FOR(I = LINECT; LINEPTR[I] != ÎÕÌÌ; 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] != ÎÕÌÌ && NL > 0; I++, NL--) { FREE(LINEPTR[I]); NLINES--; } LINEPTR[LINECT] = ÎÕÌÌ; IF(LINEPTR[I] != ÎÕÌÌ) { J = (N2.JB%9 Ñ% * 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[ÍÁØÌÉÎÅ]; J = STRLEN(LINEBUF); FOR (I = LINECT; LINEPTR[I] != ÎÕÌÌ; I++) { STRCPY(LINE, LINEPTR[I]); LINE[J] = ÎÕÌÌ; 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 (ÃÌÅÁÒÓ); PUTCHAR('\N'); FOR (I = LINECT; I < (LINECT+NL) && LINEPTR[I] != ÎÕÌÌ; I++) PRINTF("%S", LINEPTR[I]); PRINTF (ÈÃ); 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(ÈÃ); FOR(I = 0; I < 78; I++) PUTCHAR(' '); PRINTF("\R*"); } TERMINAL() /* TERMINAL MODE, NO TEXT */ { INT IN; WHILE(1) { IF(MIREADY()) PUTCHAR(ÍÏÄ_ÒÄÁÔÁ); IF(KBHIT()) { IF(ECHOFLG) IN = GETCHAR(); ELSE IN = GETCH(); IF(IN == ÓÐÅÃÉÁÌ) RETURN; ELSE SEND(IN); } } } CHAR *GETM(LINE) /* GET MEMORY FOR LINE, STORE IT, RETURN POINTER */ CHAR LINE[]; { CHAR *P, *ALLOC(); IF ((P = ALLOC(STRLEN(LINE) + 1)) != ÎÕÌÌ) 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] = ÎÕÌÌ; NLINES += I; RETURN CL; /* RETURN NEW CURRENT LINE */ } Â>IB[I]; IF(!J) RB[CL] = ÎÕÌÌ; NLINES += I; RETUR