From 5be586046b14c2f10b323c66a03a2d6e5c6679aa Mon Sep 17 00:00:00 2001 From: Paul Selkirk Date: Fri, 17 Jun 2016 18:00:14 -0400 Subject: gcc -Wall cleanup --- kermit.c | 91 ++++++++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 63 insertions(+), 28 deletions(-) (limited to 'kermit.c') diff --git a/kermit.c b/kermit.c index e041c71..d8d5644 100644 --- a/kermit.c +++ b/kermit.c @@ -57,8 +57,12 @@ /* See cdefs.h for meaning of STATIC, ULONG, and UCHAR */ +#ifdef F_AT STATIC ULONG stringnum(UCHAR *, struct k_data *); +#endif +#ifndef RECVONLY STATIC UCHAR * numstring(ULONG, UCHAR *, int, struct k_data *); +#endif int STATIC spkt(char, short, int, UCHAR *, struct k_data *); int STATIC ack(struct k_data *, short, UCHAR * text); int STATIC nak(struct k_data *, short, short); @@ -72,21 +76,29 @@ int STATIC rpar(struct k_data *, char); int STATIC decode(struct k_data *, struct k_response *, short, UCHAR *); #ifdef F_AT int STATIC gattr(struct k_data *, UCHAR *, struct k_response *); +#ifndef RECVONLY int STATIC sattr(struct k_data *, struct k_response *); +#endif #endif /* F_AT */ #ifndef RECVONLY int STATIC sdata(struct k_data *, struct k_response *); #endif /* RECVONLY */ void STATIC epkt(char *, struct k_data *); +#ifndef RECVONLY int STATIC getpkt(struct k_data *, struct k_response *); int STATIC encstr(UCHAR *, struct k_data *, struct k_response *); +#endif +#if 0 void STATIC decstr(UCHAR *, struct k_data *, struct k_response *); +#endif +#ifndef RECVONLY void STATIC encode(int, int, struct k_data *); int STATIC nxtpkt(struct k_data *); +#endif int STATIC resend(struct k_data *); -#ifdef DEBUG +#ifdef SIMULATED_ERROR int xerror(void); -#endif /* DEBUG */ +#endif /* SIMULATED_ERROR */ int /* The kermit() function */ kermit(short f, /* Function code */ @@ -96,16 +108,19 @@ kermit(short f, /* Function code */ char *msg, /* Message for error packet */ struct k_response *r) { /* Response struct */ - int i, j, rc; /* Workers */ + int i, rc; /* Workers */ int datalen; /* Length of packet data field */ UCHAR *p; /* Pointer to packet data field */ UCHAR *q; /* Pointer to data to be checked */ - UCHAR *s; /* Worker string pointer */ - UCHAR c, t; /* Worker chars */ + UCHAR *s=0; /* Worker string pointer */ +#ifdef F_LP + UCHAR c; /* Worker chars */ +#endif + UCHAR t; /* Worker chars */ UCHAR pbc[4]; /* Copy of packet block check */ short seq, prev; /* Copies of sequence numbers */ - short chklen; /* Length of packet block check */ #ifdef F_CRC + short chklen; /* Length of packet block check */ unsigned int crc; /* 16-bit CRC */ #endif /* F_CRC */ int ok; @@ -338,12 +353,13 @@ kermit(short f, /* Function code */ } } #else - chklen = 1; /* Block check is always type 1 */ datalen = k->ipktinfo[r_slot].len - 3; /* Data length */ #endif /* F_CRC */ debug(DB_LOG,"bct",0,(k->bct)); debug(DB_LOG,"datalen",0,datalen); - debug(DB_LOG,"chkalen",0,chklen); +#ifdef F_CRC + debug(DB_LOG,"chklen",0,chklen); +#endif #ifdef F_CRC for (i = 0; i < chklen; i++) /* Copy the block check */ @@ -359,9 +375,9 @@ kermit(short f, /* Function code */ case 1: /* Type 1, 6-bit checksum */ #endif /* F_CRC */ ok = (xunchar(*pbc) == chk1(q,k)); -#ifdef DEBUG +#ifdef SIMULATED_ERROR if (ok && xerror()) ok = 0; -#endif /* DEBUG */ +#endif /* SIMULATED_ERROR */ if (!ok) { freerslot(k,r_slot); #ifdef RECVONLY @@ -380,9 +396,9 @@ kermit(short f, /* Function code */ case 2: /* Type 2, 12-bit checksum */ i = xunchar(*pbc) << 6 | xunchar(pbc[1]); ok = (i == chk2(q,k)); -#ifdef DEBUG +#ifdef SIMULATED_ERROR if (ok && xerror()) ok = 0; -#endif /* DEBUG */ +#endif /* SIMULATED_ERROR */ if (!ok) { /* No match */ if (t == 'E') { /* Allow E packets to have type 1 */ int j; @@ -412,12 +428,12 @@ kermit(short f, /* Function code */ | (xunchar(pbc[1]) << 6) | (xunchar(pbc[2])); ok = (crc == chk3(q,k)); -#ifdef DEBUG +#ifdef SIMULATED_ERROR if (ok && xerror()) { ok = 0; debug(DB_MSG,"CRC ERROR INJECTED",0,0); } -#endif /* DEBUG */ +#endif /* SIMULATED_ERROR */ if (!ok) { debug(DB_LOG,"CRC ERROR t",0,t); if (t == 'E') { /* Allow E packets to have type 1 */ @@ -863,17 +879,19 @@ chk3(UCHAR *pkt, struct k_data * k) { STATIC int spkt(char typ, short seq, int len, UCHAR * data, struct k_data * k) { +#ifdef F_CRC unsigned int crc; /* For building CRC */ - int i, j, lenpos, m, n, x; /* Workers */ +#endif + int i, j, lenpos; /* Workers */ UCHAR * s, * buf; - debug(DB_LOG,"spkt len 1",0,len); + debug(DB_LOG,"spkt len",0,len); if (len < 0) { /* Calculate data length ourselves? */ len = 0; s = data; while (*s++) len++; + debug(DB_LOG,"spkt len 2",0,len); } - debug(DB_LOG,"spkt len 2",0,len); buf = k->opktbuf; /* Where to put packet (FOR NOW) */ i = 0; /* Packet buffer position */ @@ -950,7 +968,7 @@ spkt(char typ, short seq, int len, UCHAR * data, struct k_data * k) { k->opktlen = i; /* Remember length for retransmit */ -#ifdef DEBUG +#ifdef SIMULATED_ERROR /* CORRUPT THE PACKET SENT BUT NOT THE ONE WE SAVE */ if (xerror()) { UCHAR p[P_PKTLEN+8]; @@ -963,8 +981,9 @@ spkt(char typ, short seq, int len, UCHAR * data, struct k_data * k) { return((*(k->txd))(k,p,k->opktlen)); /* Send it. */ } debug(DB_PKT,"SPKT",(char *)&buf[1],0); -#endif /* DEBUG */ +#endif /* SIMULATED_ERROR */ + debug(DB_PKT,"SPKT",&buf[1],k->opktlen); return((*(k->txd))(k,buf,k->opktlen)); /* Send it. */ } @@ -974,6 +993,7 @@ STATIC int nak(struct k_data * k, short seq, short slot) { int rc; rc = spkt('N', seq, 0, (UCHAR *)0, k); + debug(DB_LOG,"nak spkt rc",0,rc); if (k->ipktinfo[slot].rtr++ > k->retry) rc = X_ERROR; return(rc); @@ -1001,8 +1021,10 @@ ack(struct k_data * k, short seq, UCHAR * text) { STATIC void spar(struct k_data * k, UCHAR *s, int datalen) { - int x, y; - UCHAR c; + #if defined(F_LP) || defined(F_SW) || defined(F_AT) || defined(F_RS) || defined(F_LS) + int x; +#endif + int y=0; s--; /* Line up with field numbers. */ @@ -1048,7 +1070,9 @@ spar(struct k_data * k, UCHAR *s, int datalen) { } } if (datalen >= 10) { /* Capability bits */ +#if defined(F_LP) || defined(F_SW) || defined(F_AT) || defined(F_RS) || defined(F_LS) x = xunchar(s[10]); +#endif #ifdef F_LP /* Long packets */ if (!(x & CAP_LP)) @@ -1115,7 +1139,7 @@ rpar(struct k_data * k, char type) { UCHAR *d; int rc, len; #ifdef F_CRC - short b; + short b=0; #endif /* F_CRC */ d = k->ack_s; /* Where to put it */ @@ -1191,7 +1215,7 @@ decode(struct k_data * k, struct k_response * r, short f, UCHAR *inbuf) { unsigned int b8; /* 8th bit */ int rpt; /* Repeat count */ int rc; /* Return code */ - UCHAR *p; + UCHAR *p=0; rc = X_OK; rpt = 0; /* Initialize repeat count. */ @@ -1237,6 +1261,7 @@ decode(struct k_data * k, struct k_response * r, short f, UCHAR *inbuf) { return(rc); } +#ifdef F_AT STATIC ULONG /* Convert decimal string to number */ stringnum(UCHAR *s, struct k_data * k) { long n; @@ -1247,7 +1272,9 @@ stringnum(UCHAR *s, struct k_data * k) { n = n * 10 + (*s++ - '0'); return(n); } +#endif +#ifndef RECVONLY STATIC UCHAR * /* Convert number to string */ numstring(ULONG n, UCHAR * buf, int buflen, struct k_data * k) { int i, x; @@ -1271,6 +1298,7 @@ numstring(ULONG n, UCHAR * buf, int buflen, struct k_data * k) { } return((UCHAR *)buf); } +#endif #ifdef F_AT @@ -1287,7 +1315,7 @@ numstring(ULONG n, UCHAR * buf, int buflen, struct k_data * k) { STATIC int gattr(struct k_data * k, UCHAR * s, struct k_response * r) { - long fsize, fsizek; /* File size */ + long fsize=-1L, fsizek=-1L; /* File size */ UCHAR c; /* Workers */ int aln, i, rc; @@ -1345,11 +1373,12 @@ gattr(struct k_data * k, UCHAR * s, struct k_response * r) { return(rc); } +#ifndef RECVONLY #define ATTRLEN 48 STATIC int sattr(struct k_data *k, struct k_response *r) { /* Build and send A packet */ - int i, x, aln; + int i, x; short tmp; long filelength; UCHAR datebuf[DATE_MAX], * p; @@ -1418,11 +1447,13 @@ sattr(struct k_data *k, struct k_response *r) { /* Build and send A packet */ debug(DB_LOG,"sattr k->xdata: ",k->xdata,0); return(spkt('A',k->s_seq,-1,k->xdata,k)); } +#endif #endif /* F_AT */ +#ifndef RECVONLY STATIC int getpkt(struct k_data *k, struct k_response *r) { /* Fill a packet from file */ - int i, next, rpt, maxlen; + int i, next, maxlen; static int c; /* PUT THIS IN STRUCT */ debug(DB_LOG,"getpkt k->s_first",0,(k->s_first)); @@ -1464,7 +1495,6 @@ getpkt(struct k_data *k, struct k_response *r) { /* Fill a packet from file */ if (k->s_first == -1) return(k->size); - rpt = 0; /* Initialize repeat counter. */ while (k->s_first > -1) { /* Until end of file or string... */ if (k->istring) { next = *(k->istring)++; @@ -1504,7 +1534,6 @@ getpkt(struct k_data *k, struct k_response *r) { /* Fill a packet from file */ return(k->size); /* EOF, return size. */ } -#ifndef RECVONLY STATIC int sdata(struct k_data *k,struct k_response *r) { /* Send a data packet */ int len, rc; @@ -1532,6 +1561,7 @@ epkt(char * msg, struct k_data * k) { (void) spkt('E', 0, -1, (UCHAR *) msg, k); } +#ifndef RECVONLY STATIC int /* Fill a packet from string s. */ encstr(UCHAR * s, struct k_data * k, struct k_response *r) { k->s_first = 1; /* Start lookahead. */ @@ -1541,7 +1571,9 @@ encstr(UCHAR * s, struct k_data * k, struct k_response *r) { k->s_first = 1; /* "Rewind" */ return(k->size); /* Return data field length */ } +#endif +#if 0 /* Decode packet data into a string */ STATIC void @@ -1551,7 +1583,9 @@ decstr(UCHAR * s, struct k_data * k, struct k_response * r) { *(k->ostring) = '\0'; /* Terminate with null */ k->ostring = (UCHAR *)0; /* Reset output string pointer */ } +#endif +#ifndef RECVONLY STATIC void encode(int a, int next, struct k_data * k) { /* Encode character into packet */ int a7, b8, maxlen; @@ -1607,6 +1641,7 @@ nxtpkt(struct k_data * k) { /* Get next packet to send */ k->xdata = k->xdatabuf; return(0); } +#endif STATIC int resend(struct k_data * k) { -- cgit v1.2.3