1 #include "../hdr/defines.h" 2 3 static char Sccsid[] = "@(#)getline.c 1.2 02/15/87"; 4 /* 5 Routine to read a line into the packet. The main reason for 6 it is to make sure that pkt->p_wrttn gets turned off, 7 and to increment pkt->p_slnno. 8 */ 9 10 getline(pkt) 11 register struct packet *pkt; 12 { 13 register int n; 14 register char *p; 15 16 if(pkt->p_wrttn==0) 17 putline(pkt,0); 18 if ((n = fgets(pkt->p_line,sizeof(pkt->p_line),pkt->p_iop)) != NULL) { 19 pkt->p_slnno++; 20 pkt->p_wrttn = 0; 21 for (p = pkt->p_line; *p; ) 22 pkt->p_chash += *p++; 23 } 24 else { 25 if (!pkt->p_reopen) { 26 fclose(pkt->p_iop); 27 pkt->p_iop = 0; 28 } 29 if (!pkt->p_chkeof) 30 fatal("premature eof (co5)"); 31 if (pkt->do_chksum && (pkt->p_chash ^ pkt->p_ihash)&0xFFFF) 32 fatal("corrupted file (co6)"); 33 if (pkt->p_reopen) { 34 fseek(pkt->p_iop,0L,0); 35 pkt->p_reopen = 0; 36 pkt->p_slnno = 0; 37 pkt->p_ihash = 0; 38 pkt->p_chash = 0; 39 pkt->p_nhash = 0; 40 pkt->p_keep = 0; 41 pkt->do_chksum = 0; 42 } 43 } 44 return(n); 45 } 46