Category : C Source Code
Archive   : WKERMSRC.ZIP
Filename : LCKPROT.C

 
Output of file : LCKPROT.C contained in archive : WKERMSRC.ZIP
##################################################################
## LCKPROT.C

/* WARNING -- This C source program generated by Wart preprocessor. */
/* Do not edit this file; edit the Wart-format source file instead, */
/* and then run it through Wart to produce a new C source file. */

/* Wart Version Info: */
char *wartv = "Wart Version 1A(003) 27 May 85";

char *protv = "C-Kermit Protocol Module 4C(026), 12 Jun 85"; /* -*-C-*- */

/* C K C P R O -- C-Kermit Protocol Module, in Wart preprocessor notation. */
/*
Author: Frank da Cruz (SY.FDC@CU20B),
Columbia University Center for Computing Activities, January 1985.
Copyright (C) 1985, Trustees of Columbia University in the City of New York.
Permission is granted to any individual or institution to use, copy, or
redistribute this software so long as it is not sold for profit, provided this
copyright notice is retained.
*/
/* Modified for sliding windows impl. by: Jan A. van der Eijk */

#include "lckdeb.h"
#include "lckerm.h"
/*
Note -- This file may also be preprocessed by the Unix Lex program, but
you must indent the above #include statement before using Lex, and then
restore it to the left margin in the resulting C program before compilation.
Also, the invocation of the "wart()" function below must be replaced by an
invocation of the "yylex()" function. It might also be necessary to remove
comments in the %%...%% section.
*/

/* State definitions for Wart (or Lex) */
#define rfile 1
#define rdata 2
#define ssinit 3
#define ssdata 4
#define sseof 5
#define sseot 6
#define get 7
#define rattr 8
#define ssattr 9
#define swdata 10
#define rwdata 11
#define sweof 12

/* External C-Kermit variable declarations */
extern char sstate, *versio, *cmarg, *cmarg2;
extern char data[], filnam[], ttname[];
extern int pktnum, timint, nfils, image, hcflg, xflg, speed, flow, mdmtyp;
extern int prvpkt, cxseen, czseen, local, displa, bctu, bctr, quiet;
extern int putfil(), errpkt();
extern int filatr,nxtcas, rpktno, window;

/* Local variables */
static char vstate = 0; /* Saved State */
static char vcmd = 0; /* Saved Command */
static int x; /* General-purpose integer */

/* Macros - Note, BEGIN is predefined by Wart (and Lex) */
#define RESUME return


#define BEGIN state =

int state = 0;

wart()
{
int c,actno;
extern int tbl[];
while (1) {
c = input();
if ((actno = tbl[c + state*128]) != -1)
switch(actno) {
case 1:
{ tinit(); /* Do Send command */
if (sinit()) BEGIN ssinit;
else RESUME; }
break;
case 2:
{ tinit(); sleep(1); nack(); BEGIN get; }
break;
case 3:
{ errpkt("User cancelled transaction"); /* Tell other side what's going on */
clsif(); clsof();
return(0); }
break;
case 4:
{ rinit(data); bctu = bctr; BEGIN rfile; }
break;
case 5:
{ if (rcvfil()) { /* A file is coming */
ack();
if (filatr) BEGIN rattr; /* Both want attributes */
else if ( wdinit() ) BEGIN rwdata; /* Both want windows */
else BEGIN rdata; }
else { errpkt("Can't open file"); RESUME; } }
break;
case 6:
{ ack(); reot(); sleep(2); RESUME; }
break;
case 7:
{ if ( rdattr(data)) ack(); /* Got file Attributes */
else { errpkt("Not enough disk space"); clsof(); RESUME; } }
break;
case 8:
{ ack(); decode(data,putfil); /* First data packet */
if ( wdinit() ) BEGIN rwdata;
else BEGIN rdata; }
break;
case 9:
{ ack(); reof(); BEGIN rfile; }
break;
case 10:
{ if ( !(cxseen || czseen) ) { /* Not aborted by me */
rweof(); } /* write data to disk */
pktnum = rpktno; /* make sure we have the right packet number */
ack(); reof();
BEGIN rfile; }
break;
case 11:
{ if (cxseen) ack1("X"); /* Got data. */
else if (czseen) ack1("Z");
else ack();
decode(data,putfil); }
break;
case 12:
{ if (cxseen || czseen) { /* Got data, in window */
pktnum = rpktno; /* Resynch. packet numbers */
if (czseen) ack1("Z");
else ack1("X");
ttflui(); sleep(3);
ttflui(); } /* Flush input buffer */
else if ( !gwdata()) {
wnderr("Protocol Error");
RESUME; } }
break;
case 13:
{ if ( ! nackdp() ) { /* Got bad data, NACK it */
wnderr("Timed out."); /* Timed out, issue message and */
RESUME; } }
break;
case 14:
{ resend(); }
break;
case 15:
{ spar(data); /* Got ACK to Send-Init */

bctu = bctr;
if (sfile()) {
if (filatr) { BEGIN ssattr; nxtcas = 1;}
else BEGIN ssdata;
} else { errpkt("Can't open file"); RESUME; } }
break;
case 16:
{ if (canned(data)) { seof(); clsif(); BEGIN sseof; }
else if (!sattr()) { /* Send Attr packet(s) */
BEGIN ssdata; } }
break;
case 17:
{ if (canned(data) || !sdata()) { /* Got ACK to data */
seof(); clsif();
BEGIN sseof; }
else if (wdinit()) BEGIN swdata; }
break;
case 18:
{ if (canned(data) || !sdataw() ) { /* Got ACK, with Abort data */
if (!cxseen && !czseen && window ) { /* or abort by me or EOF */
BEGIN sweof; /* EOF but window not empty */
} else {
pktnum = rpktno; /* Get the right number */
ttfluo(); sleep(2);
ttflui(); /* Wait and flush buffer */
seof();clsif(); /* Send the Z packet */
BEGIN sseof; } } }
break;
case 19:
{ if ( !wresnd() ) { /* Not an ACK, try resend */
wnderr("Timed out."); /* Timed out, issue message */
RESUME; } }
break;
case 20:
{ if ( weof() ) { /* If all the packets are ACKEd */
seof(); clsif(); /* End Of File state */
BEGIN sseof; } }
break;
case 21:
{ if (gnfile() > 0) { /* Got ACK to EOF, get next file */
if (sfile()) {
if (filatr) { BEGIN ssattr; nxtcas = 1;}
else BEGIN ssdata;
} else { errpkt("Can't open file") ; RESUME; }
} else { /* If no next file, EOT */
seot();
BEGIN sseot; } }
break;
case 22:
{ RESUME; }
break;
case 23:
{ ermsg(data); /* Error packet, issue message */
x = quiet, quiet = 1; /* close files silently */
clsif(); clsof();
quiet = x;
RESUME; }
break;
case 24:
{ nack(); }
break;

}
}
}

int tbl[] = {
-1,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 3, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 1, 24, 24, 2, 24, 24,
24, 24, 24, 24, 24, 24, 24, -1, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 6, 24, 24, 23, 5, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 3, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 1, 24, 24, 2, 24, 24, 24, 24, 24, 24, 24, 24, 24, -1, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 11, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 9, 24, 24, 24, 24, 24, 24, 3, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 1, 24, 24, 2, 24, 24, 24, 24, 24, 24,
24, 24, 24, -1, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 23, 24, 24, 24, 24, 24, 24, 24,
24, 14, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 15, 24, 24, 24, 24, 24, 24, 24,
3, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 1, 24,
24, 2, 24, 24, 24, 24, 24, 24, 24, 24, 24, -1, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
23, 24, 24, 24, 24, 24, 24, 24, 24, 14, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
17, 24, 24, 24, 24, 24, 24, 24, 3, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 1, 24, 24, 2, 24, 24, 24, 24, 24, 24, 24, 24, 24, -1,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 23, 24, 24, 24, 24, 24, 24, 24, 24, 14, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 21, 24, 24, 24, 24, 24, 24, 24, 3, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 1, 24, 24, 2, 24, 24,
24, 24, 24, 24, 24, 24, 24, -1, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 23, 24, 24, 24,
24, 24, 24, 24, 24, 14, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 22, 24, 24, 24,
24, 24, 24, 24, 3, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 1, 24, 24, 2, 24, 24, 24, 24, 24, 24, 24, 24, 24, -1, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 4, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 3, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 1, 24, 24, 2, 24, 24, 24, 24, 24, 24,
24, 24, 24, -1, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 7, 24, 24, 8, 23, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 9, 24, 24, 24, 24, 24, 24,
3, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 1, 24,
24, 2, 24, 24, 24, 24, 24, 24, 24, 24, 24, -1, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
16, 24, 24, 24, 24, 24, 24, 24, 3, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 1, 24, 24, 2, 24, 24, 24, 24, 24, 24, 24, 24, 24, -1,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 23, 24, 24, 24, 24, 24, 24, 24, 24, 19, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 18, 24, 24, 24, 24, 24, 24, 24, 3, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 1, 24, 24, 2, 24, 24,
24, 24, 24, 24, 24, 24, 24, -1, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 12, 23, 24, 24, 24,
24, 24, 24, 24, 24, 13, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 10, 24, 24,
24, 24, 24, 24, 3, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 1, 24, 24, 2, 24, 24, 24, 24, 24, 24, 24, 24, 24, 0, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 23, 24, 24, 24, 24, 24, 24, 24, 24, 19, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 20, 24, 24, 24, 24, 24, 24, 24, 3, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 1, 24, 24, 2, 24, 24, 24, 24, 24, 24,
24, 24, 24, };


/* P R O T O -- Protocol entry function */

proto() {

int x;

/* Set up the communication line for file transfer. */

if (local && (speed < 0)) {
screen(SCR_EM,0,0l,"Sorry, you must 'set speed' first");
return;
}

x = -1;
if (ttopen(ttname,&x,mdmtyp) < 0) {
debug(F111,"proto ttopen local",ttname,local);
screen(SCR_EM,0,0l,"Can't open line");
return;
}
if (x > -1) local = x;
debug(F111,"proto ttopen local",ttname,local);

x = (local) ? speed : -1;
if (ttpkt(x,flow) < 0) { /* Put line in packet mode, */
screen(SCR_EM,0,0l,"Can't condition line");
return;
}
sleep(1);

/*
The 'wart()' function is generated by the wart program. It gets a
character from the input() routine and then based on that character and
the current state, selects the appropriate action, according to the state
table above, which is transformed by the wart program into a big case
statement. The function is active for one transaction.
*/

wart(); /* Enter the state table switcher. */
screen(SCR_TC,0,0l,""); /* Transaction complete */
}


  3 Responses to “Category : C Source Code
Archive   : WKERMSRC.ZIP
Filename : LCKPROT.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/