1 # include "../hdr/defines.h" 2 3 SCCSID(@(#)putline 2.1.1.1); 4 /* 5 Routine to write out either the current line in the packet 6 (if newline is zero) or the line specified by newline. 7 A line is actually written (and the x-file is only 8 opened) if pkt->p_upd is non-zero. When the current line from 9 the packet is written, pkt->p_wrttn is set non-zero, and 10 further attempts to write it are ignored. When a line is 11 read into the packet, pkt->p_wrttn must be turned off. 12 */ 13 14 int Xcreate; 15 FILE *Xiop; 16 17 18 putline(pkt,newline) 19 register struct packet *pkt; 20 char *newline; 21 { 22 static char obf[BUFSIZ]; 23 char *xf; 24 register char *p; 25 26 if(pkt->p_upd == 0) return; 27 28 if(!Xcreate) { 29 stat(pkt->p_file,&Statbuf); 30 xf = auxf(pkt->p_file,'x'); 31 Xiop = xfcreat(xf,Statbuf.st_mode); 32 setbuf(Xiop,obf); 33 chown(xf,Statbuf.st_uid,Statbuf.st_gid); 34 } 35 if (newline) 36 p = newline; 37 else { 38 if(!pkt->p_wrttn++) 39 p = pkt->p_line; 40 else 41 p = 0; 42 } 43 if (p) { 44 fputs(p,Xiop); 45 if (Xcreate) 46 while (*p) 47 pkt->p_nhash =+ *p++; 48 } 49 Xcreate = 1; 50 } 51 52 53 flushline(pkt,stats) 54 register struct packet *pkt; 55 register struct stats *stats; 56 { 57 register char *p; 58 char ins[6], del[6], unc[6], hash[6]; 59 60 if (pkt->p_upd == 0) 61 return; 62 putline(pkt,0); 63 rewind(Xiop); 64 65 if (stats) { 66 sprintf(ins,"%05u",stats->s_ins); 67 sprintf(del,"%05u",stats->s_del); 68 sprintf(unc,"%05u",stats->s_unc); 69 for (p = ins; *p; p++) 70 pkt->p_nhash =+ (*p - '0'); 71 for (p = del; *p; p++) 72 pkt->p_nhash =+ (*p - '0'); 73 for (p = unc; *p; p++) 74 pkt->p_nhash =+ (*p - '0'); 75 } 76 77 sprintf(hash,"%5u",pkt->p_nhash&0xFFFF); 78 zeropad(hash); 79 fprintf(Xiop,"%c%c%s\n",CTLCHAR,HEAD,hash); 80 if (stats) 81 fprintf(Xiop,"%c%c %s/%s/%s\n",CTLCHAR,STATS,ins,del,unc); 82 fclose(Xiop); 83 } 84 85 86 xrm(pkt) 87 struct packet *pkt; 88 { 89 if (Xiop) 90 fclose(Xiop); 91 Xiop = Xcreate = 0; 92 } 93