1162Sroot # include "../hdr/defines.h"
2162Sroot # include "../hdr/had.h"
344892Sbostic # include "pathnames.h"
4162Sroot
5*45561Sbostic static char Sccsid[] = "@(#)delta.c 4.12 11/11/90";
6162Sroot USXALLOC();
7162Sroot
815766Sralph # ifdef LOGDELTA
944892Sbostic char *LogFile = _PATH_SCCSLOG;
1015766Sralph FILE *Logf;
1115766Sralph # endif
1215766Sralph
13162Sroot FILE *Diffin;
1430501Slepreau int Debug = 0;
15162Sroot struct packet gpkt;
16162Sroot struct sid sid;
17162Sroot int num_files;
18162Sroot char had[26];
19162Sroot char *ilist, *elist, *glist;
20162Sroot char *Comments, *Mrs;
21162Sroot int Domrs;
2215766Sralph int verbosity;
23162Sroot int Did_id;
24162Sroot long Szqfile;
25162Sroot char Pfilename[FILESIZE];
26162Sroot FILE *Xiop;
27162Sroot int Xcreate;
28162Sroot
main(argc,argv)29162Sroot main(argc,argv)
30162Sroot int argc;
31162Sroot register char *argv[];
32162Sroot {
33162Sroot register int i;
34162Sroot register char *p;
35162Sroot char c;
36162Sroot int testmore;
37162Sroot extern delta();
38162Sroot extern int Fcnt;
39162Sroot
40162Sroot Fflags = FTLEXIT | FTLMSG | FTLCLN;
41162Sroot for(i=1; i<argc; i++)
42162Sroot if(argv[i][0] == '-' && (c=argv[i][1])) {
43162Sroot p = &argv[i][2];
44162Sroot testmore = 0;
45162Sroot switch (c) {
46162Sroot
47162Sroot case 'r':
48162Sroot if (!p[0]) {
49162Sroot argv[i] = 0;
50162Sroot continue;
51162Sroot }
52162Sroot chksid(sid_ab(p,&sid),&sid);
53162Sroot break;
54162Sroot case 'g':
55162Sroot glist = p;
56162Sroot break;
57162Sroot case 'y':
58162Sroot Comments = p;
59162Sroot break;
60162Sroot case 'm':
61162Sroot Mrs = p;
62162Sroot break;
63162Sroot case 'p':
64162Sroot case 'n':
65162Sroot case 's':
66162Sroot testmore++;
67162Sroot break;
68162Sroot default:
69162Sroot fatal("unknown key letter (cm1)");
70162Sroot }
71162Sroot
72162Sroot if (testmore) {
73162Sroot testmore = 0;
7433423Sbostic if (*p) {
7533423Sbostic sprintf(Error, "value after %c arg (cm7)",c);
7633423Sbostic fatal(Error);
7733423Sbostic }
78162Sroot }
79162Sroot if (had[c - 'a']++)
80162Sroot fatal("key letter twice (cm2)");
81162Sroot argv[i] = 0;
82162Sroot }
83162Sroot else num_files++;
84162Sroot
8515766Sralph if (num_files == 0)
86162Sroot fatal("missing file arg (cm3)");
87162Sroot if (!HADS)
88162Sroot verbosity = -1;
8915766Sralph # ifdef LOGDELTA
9015815Sralph Logf = fopen(LogFile, "a");
9115766Sralph # endif
92162Sroot setsig();
9330501Slepreau Fflags &= ~FTLEXIT;
9430501Slepreau Fflags |= FTLJMP;
95162Sroot for (i=1; i<argc; i++)
96162Sroot if (p=argv[i])
97162Sroot do_file(p,delta);
9815766Sralph # ifdef LOGDELTA
9915815Sralph if (Logf != NULL)
10015815Sralph fclose(Logf);
10115766Sralph # endif
102162Sroot exit(Fcnt ? 1 : 0);
103162Sroot }
104162Sroot
105162Sroot
delta(file)106162Sroot delta(file)
10715766Sralph char *file;
108162Sroot {
10930501Slepreau static int first = 1;
110162Sroot register char *p;
111162Sroot int n, linenum;
112162Sroot char type;
113162Sroot register int ser;
114162Sroot extern char had_dir, had_standinp;
115162Sroot extern char *Sflags[];
116162Sroot char dfilename[FILESIZE];
117162Sroot char gfilename[FILESIZE];
118162Sroot char line[512];
119162Sroot FILE *gin;
120162Sroot struct stats stats;
121162Sroot struct pfile *pp;
122162Sroot int inserted, deleted, orig;
123162Sroot int newser;
124162Sroot int status;
125162Sroot int diffloop;
126162Sroot int difflim;
127162Sroot
128162Sroot if (setjmp(Fjmp))
129162Sroot return;
130162Sroot if (first) {
131162Sroot first = 0;
132162Sroot dohist(file);
133162Sroot }
134162Sroot sinit(&gpkt,file,1);
135162Sroot if (lockit(auxf(gpkt.p_file,'z'),2,getpid()))
136162Sroot fatal("cannot create lock file (cm4)");
137162Sroot gpkt.p_reopen = 1;
138162Sroot gpkt.p_stdout = stdout;
139162Sroot copy(auxf(gpkt.p_file,'g'),gfilename);
140162Sroot gin = xfopen(gfilename,0);
141162Sroot pp = rdpfile(&gpkt,&sid);
142162Sroot gpkt.p_cutoff = pp->pf_date;
143162Sroot ilist = pp->pf_ilist;
144162Sroot elist = pp->pf_elist;
145162Sroot
146162Sroot if (dodelt(&gpkt,&stats,0,0) == 0)
147162Sroot fmterr(&gpkt);
148162Sroot if ((ser = sidtoser(&pp->pf_gsid,&gpkt)) == 0 ||
149162Sroot sidtoser(&pp->pf_nsid,&gpkt))
150162Sroot fatal("invalid sid in p-file (de3)");
151162Sroot doie(&gpkt,ilist,elist,glist);
152162Sroot setup(&gpkt,ser);
153162Sroot finduser(&gpkt);
154162Sroot doflags(&gpkt);
15519941Ssam bcopy(&pp->pf_nsid,&gpkt.p_reqsid,sizeof(gpkt.p_reqsid));
156162Sroot permiss(&gpkt);
157162Sroot flushto(&gpkt,EUSERTXT,1);
158162Sroot gpkt.p_chkeof = 1;
159162Sroot copy(auxf(gpkt.p_file,'d'),dfilename);
160162Sroot gpkt.p_gout = xfcreat(dfilename,0444);
161162Sroot while(readmod(&gpkt)) {
162162Sroot chkid(gpkt.p_line);
163162Sroot fputs(gpkt.p_line,gpkt.p_gout);
164162Sroot }
165162Sroot fclose(gpkt.p_gout);
166162Sroot orig = gpkt.p_glnno;
167162Sroot gpkt.p_glnno = 0;
168162Sroot gpkt.p_verbose = verbosity;
169162Sroot Did_id = 0;
170162Sroot while (fgets(line,sizeof(line),gin) != NULL && !chkid(line))
171162Sroot ;
172162Sroot fclose(gin);
173162Sroot if (gpkt.p_verbose && (num_files > 1 || had_dir || had_standinp))
174162Sroot fprintf(gpkt.p_stdout,"\n%s:\n",gpkt.p_file);
175162Sroot if (!Did_id)
176162Sroot if (Sflags[IDFLAG - 'a'])
177162Sroot fatal("no id keywords (cm6)");
178162Sroot else if (gpkt.p_verbose)
179162Sroot fprintf(stderr,"No id keywords (cm7)\n");
180162Sroot
181162Sroot /*
182162Sroot The following while loop executes 'bdiff' on g-file and
183162Sroot d-file. If 'bdiff' fails (usually because segmentation
184162Sroot limit it is using is too large for 'diff'), it is
185162Sroot invoked again, with a lower segmentation limit.
186162Sroot */
187162Sroot difflim = 3500;
188162Sroot diffloop = 0;
189162Sroot while (1) {
190162Sroot inserted = deleted = 0;
191162Sroot gpkt.p_glnno = 0;
192162Sroot gpkt.p_upd = 1;
193162Sroot gpkt.p_wrttn = 1;
194162Sroot getline(&gpkt);
195162Sroot gpkt.p_wrttn = 1;
196162Sroot newser = mkdelt(&gpkt,&pp->pf_nsid,&pp->pf_gsid,
197162Sroot diffloop,orig);
198162Sroot diffloop = 1;
199162Sroot flushto(&gpkt,EUSERTXT,0);
200162Sroot Diffin = dodiff(auxf(gpkt.p_file,'g'),dfilename,difflim);
201162Sroot while (n = getdiff(&type,&linenum)) {
202162Sroot if (type == INS) {
20330501Slepreau inserted += n;
204162Sroot insert(&gpkt,linenum,n,newser);
205162Sroot }
206162Sroot else {
20730501Slepreau deleted += n;
208162Sroot delete(&gpkt,linenum,n,newser);
209162Sroot }
210162Sroot }
211162Sroot fclose(Diffin);
212162Sroot if (gpkt.p_iop)
213162Sroot while (readmod(&gpkt))
214162Sroot ;
215162Sroot wait(&status);
216162Sroot if (status) { /* diff failed */
217162Sroot /*
218162Sroot Check top byte (exit code of child).
219162Sroot */
22033423Sbostic if (((status >> 8) & 0377) == 32) { /* 'execl' failed */
221*45561Sbostic sprintf(Error, "cannot execute '%s' (de12)",
222*45561Sbostic _PATH_BDIFF);
22333423Sbostic fatal(Error);
22433423Sbostic }
225162Sroot /*
226162Sroot Re-try.
227162Sroot */
22832771Sbostic if (difflim -= 500) { /* reduce segmentation */
229162Sroot fprintf(stderr,
230162Sroot "'%s' failed, re-trying, segmentation = %d (de13)\n",
231*45561Sbostic _PATH_BDIFF,difflim);
232162Sroot fclose(Xiop); /* set up */
233162Sroot Xiop = 0; /* for new x-file */
234162Sroot Xcreate = 0;
235162Sroot /*
236162Sroot Re-open s-file.
237162Sroot */
238162Sroot gpkt.p_iop = xfopen(gpkt.p_file,0);
239162Sroot setbuf(gpkt.p_iop,gpkt.p_buf);
240162Sroot /*
241162Sroot Reset counters.
242162Sroot */
243162Sroot gpkt.p_slnno = 0;
244162Sroot gpkt.p_ihash = 0;
245162Sroot gpkt.p_chash = 0;
246162Sroot gpkt.p_nhash = 0;
247162Sroot gpkt.p_keep = 0;
248162Sroot }
249162Sroot else
250162Sroot /* tried up to 500 lines, can't go on */
251162Sroot fatal("diff failed (de4)");
252162Sroot }
253162Sroot else { /* no need to try again, worked */
254162Sroot break; /* exit while loop */
255162Sroot }
256162Sroot }
257162Sroot unlink(dfilename);
258162Sroot stats.s_ins = inserted;
259162Sroot stats.s_del = deleted;
260162Sroot stats.s_unc = orig - deleted;
261162Sroot if (gpkt.p_verbose) {
262162Sroot fprintf(gpkt.p_stdout,"%u inserted\n",stats.s_ins);
263162Sroot fprintf(gpkt.p_stdout,"%u deleted\n",stats.s_del);
264162Sroot fprintf(gpkt.p_stdout,"%u unchanged\n",stats.s_unc);
265162Sroot }
266162Sroot flushline(&gpkt,&stats);
267162Sroot rename(auxf(gpkt.p_file,'x'),gpkt.p_file);
268162Sroot if (Szqfile)
269162Sroot rename(auxf(&gpkt.p_file,'q'),Pfilename);
270162Sroot else {
271162Sroot xunlink(Pfilename);
272162Sroot xunlink(auxf(&gpkt.p_file,'q'));
273162Sroot }
274162Sroot clean_up(0);
275162Sroot if (!HADN) {
276162Sroot setuid(getuid());
277162Sroot unlink(gfilename);
278162Sroot }
279162Sroot }
280162Sroot
281162Sroot
282162Sroot mkdelt(pkt,sp,osp,diffloop,orig_nlines)
283162Sroot struct packet *pkt;
284162Sroot struct sid *sp, *osp;
285162Sroot int diffloop;
286162Sroot int orig_nlines;
287162Sroot {
288162Sroot extern long Timenow;
289162Sroot struct deltab dt;
290162Sroot char str[128];
291162Sroot int newser;
292162Sroot extern char *Sflags[];
293162Sroot register char *p;
294162Sroot int ser_inc, opred, nulldel;
295162Sroot
296162Sroot if (!diffloop && pkt->p_verbose) {
297162Sroot sid_ba(sp,str);
298162Sroot fprintf(pkt->p_stdout,"%s\n",str);
299162Sroot }
30033423Sbostic sprintf(str,"%c%c00000\n",CTLCHAR,HEAD);
30133423Sbostic putline(pkt,str);
302162Sroot newstats(pkt,str,"0");
30319941Ssam bcopy(sp,&dt.d_sid,sizeof(dt.d_sid));
304162Sroot
305162Sroot /*
306162Sroot Check if 'null' deltas should be inserted
307162Sroot (only if 'null' flag is in file and
308162Sroot releases are being skipped) and set
309162Sroot 'nulldel' indicator appropriately.
310162Sroot */
311162Sroot if (Sflags[NULLFLAG - 'a'] && (sp->s_rel > osp->s_rel + 1) &&
312162Sroot !sp->s_br && !sp->s_seq &&
313162Sroot !osp->s_br && !osp->s_seq)
314162Sroot nulldel = 1;
315162Sroot else
316162Sroot nulldel = 0;
317162Sroot /*
318162Sroot Calculate how many serial numbers are needed.
319162Sroot */
320162Sroot if (nulldel)
321162Sroot ser_inc = sp->s_rel - osp->s_rel;
322162Sroot else
323162Sroot ser_inc = 1;
324162Sroot /*
325162Sroot Find serial number of the new delta.
326162Sroot */
327162Sroot newser = dt.d_serial = maxser(pkt) + ser_inc;
328162Sroot /*
329162Sroot Find old predecessor's serial number.
330162Sroot */
331162Sroot opred = sidtoser(osp,pkt);
332162Sroot if (nulldel)
333162Sroot dt.d_pred = newser - 1; /* set predecessor to 'null' delta */
334162Sroot else
335162Sroot dt.d_pred = opred;
336162Sroot dt.d_datetime = Timenow;
3376173Seric substr(logname(),dt.d_pgmr,0,LNLNAM);
338162Sroot dt.d_type = 'D';
339162Sroot del_ba(&dt,str);
340162Sroot putline(pkt,str);
34115766Sralph # ifdef LOGDELTA
34215815Sralph if (Logf != NULL) {
34315815Sralph if (pkt->p_file[0] != '/') {
34415815Sralph char buf[1024];
34515766Sralph
34615815Sralph if (getwd(buf) != NULL)
34715815Sralph fprintf(Logf, "%s/", buf);
34815815Sralph }
34915815Sralph fprintf(Logf, "%s:\n%s%s\n", pkt->p_file, str + 5, Comments);
35015766Sralph }
35115766Sralph # endif
352162Sroot if (ilist)
353162Sroot mkixg(pkt,INCLUSER,INCLUDE);
354162Sroot if (elist)
355162Sroot mkixg(pkt,EXCLUSER,EXCLUDE);
356162Sroot if (glist)
357162Sroot mkixg(pkt,IGNRUSER,IGNORE);
358162Sroot if (Mrs) {
359162Sroot if (!(p = Sflags[VALFLAG - 'a']))
360162Sroot fatal("MRs not allowed (de8)");
361162Sroot if (*p && !diffloop && valmrs(pkt,p))
362162Sroot fatal("invalid MRs (de9)");
363162Sroot putmrs(pkt);
364162Sroot }
365162Sroot else if (Sflags[VALFLAG - 'a'])
366162Sroot fatal("MRs required (de10)");
36733423Sbostic sprintf(str,"%c%c ",CTLCHAR,COMMENTS);
36833423Sbostic putline(pkt,str);
369162Sroot putline(pkt,Comments);
370162Sroot putline(pkt,"\n");
37133423Sbostic sprintf(str,CTLSTR,CTLCHAR,EDELTAB);
37233423Sbostic putline(pkt,str);
373162Sroot if (nulldel) /* insert 'null' deltas */
374162Sroot while (--ser_inc) {
37533423Sbostic sprintf(str,"%c%c %s/%s/%05u\n", CTLCHAR, STATS, "00000", "00000", orig_nlines);
37633423Sbostic putline(pkt,str);
37732771Sbostic dt.d_sid.s_rel -= 1;
37832771Sbostic dt.d_serial -= 1;
379162Sroot if (ser_inc != 1)
38032771Sbostic dt.d_pred -= 1;
381162Sroot else
382162Sroot dt.d_pred = opred; /* point to old pred */
383162Sroot del_ba(&dt,str);
384162Sroot putline(pkt,str);
38533423Sbostic sprintf(str,"%c%c ",CTLCHAR,COMMENTS);
38633423Sbostic putline(pkt,str);
387162Sroot putline(pkt,"AUTO NULL DELTA\n");
38833423Sbostic sprintf(str,CTLSTR,CTLCHAR,EDELTAB);
38933423Sbostic putline(pkt,str);
390162Sroot }
391162Sroot return(newser);
392162Sroot }
393162Sroot
394162Sroot
395162Sroot mkixg(pkt,reason,ch)
396162Sroot struct packet *pkt;
397162Sroot int reason;
398162Sroot char ch;
399162Sroot {
400162Sroot int n;
401162Sroot char str[512];
402162Sroot
40333423Sbostic sprintf(str,"%c%c",CTLCHAR,ch);
40433423Sbostic putline(pkt,str);
405162Sroot for (n = maxser(pkt); n; n--) {
40633423Sbostic if (pkt->p_apply[n].a_reason == reason) {
40733423Sbostic sprintf(str," %u",n);
40833423Sbostic putline(pkt,str);
40933423Sbostic }
410162Sroot }
411162Sroot putline(pkt,"\n");
412162Sroot }
413162Sroot
414162Sroot
415162Sroot putmrs(pkt)
416162Sroot struct packet *pkt;
417162Sroot {
418162Sroot register char **argv;
419162Sroot char str[64];
420162Sroot extern char *Varg[];
421162Sroot
42233423Sbostic for (argv = &Varg[VSTART]; *argv; argv++) {
42333423Sbostic sprintf(str,"%c%c %s\n",CTLCHAR,MRNUM,*argv);
42433423Sbostic putline(pkt,str);
42533423Sbostic }
426162Sroot }
427162Sroot
428162Sroot
rdpfile(pkt,sp)429162Sroot rdpfile(pkt,sp)
430162Sroot register struct packet *pkt;
431162Sroot struct sid *sp;
432162Sroot {
433162Sroot char *user;
434162Sroot struct pfile pf;
435162Sroot static struct pfile goodpf;
436162Sroot char line[512];
4376636Ssam int cnt, root;
438162Sroot FILE *in, *out;
439162Sroot
440162Sroot cnt = -1;
441162Sroot user = logname();
44219941Ssam bzero(&goodpf,sizeof(goodpf));
443162Sroot in = xfopen(auxf(pkt->p_file,'p'),0);
444162Sroot out = xfcreat(auxf(pkt->p_file,'q'),0644);
4456636Ssam root = getuid() == 0;
446162Sroot while (fgets(line,sizeof(line),in) != NULL) {
447162Sroot pf_ab(line,&pf,1);
4486636Ssam if (root || equal(pf.pf_user,user)) {
449162Sroot if (sp->s_rel == 0) {
450162Sroot if (++cnt) {
451162Sroot fclose(out);
452162Sroot fclose(in);
453162Sroot fatal("missing -r argument (de1)");
454162Sroot }
45519941Ssam bcopy(&pf,&goodpf,sizeof(pf));
456162Sroot continue;
457162Sroot }
458162Sroot else if (sp->s_rel == pf.pf_gsid.s_rel &&
459162Sroot sp->s_lev == pf.pf_gsid.s_lev &&
460162Sroot sp->s_br == pf.pf_gsid.s_br &&
461162Sroot sp->s_seq == pf.pf_gsid.s_seq) {
46219941Ssam bcopy(&pf,&goodpf,sizeof(pf));
463162Sroot continue;
464162Sroot }
465162Sroot }
466162Sroot fputs(line,out);
467162Sroot }
468162Sroot fflush(out);
469162Sroot fstat(fileno(out),&Statbuf);
470162Sroot Szqfile = Statbuf.st_size;
471162Sroot copy(auxf(pkt->p_file,'p'),Pfilename);
472162Sroot fclose(out);
473162Sroot fclose(in);
474162Sroot if (!goodpf.pf_user[0])
475162Sroot fatal("not in p-file (de2)");
476162Sroot return(&goodpf);
477162Sroot }
478162Sroot
479162Sroot
dodiff(newf,oldf,difflim)480162Sroot dodiff(newf,oldf,difflim)
481162Sroot char *newf, *oldf;
482162Sroot int difflim;
483162Sroot {
484162Sroot register int i;
485162Sroot int pfd[2];
486162Sroot FILE *iop;
487162Sroot char num[10];
488162Sroot
489162Sroot xpipe(pfd);
490162Sroot if ((i = fork()) < 0) {
491162Sroot close(pfd[0]);
492162Sroot close(pfd[1]);
493162Sroot fatal("cannot fork, try again (de11)");
494162Sroot }
495162Sroot else if (i == 0) {
496162Sroot close(pfd[0]);
49719941Ssam dup2(pfd[1], 1);
49819941Ssam if (pfd[1] != 1)
49919941Ssam close(pfd[1]);
50019941Ssam for (i = getdtablesize(); i > 4; i--)
501162Sroot close(i);
502162Sroot sprintf(num,"%d",difflim);
503*45561Sbostic execl(_PATH_BDIFF,"bdiff",oldf,newf,num,"-s",0);
504162Sroot close(1);
505162Sroot exit(32); /* tell parent that 'execl' failed */
506162Sroot }
507162Sroot else {
508162Sroot close(pfd[1]);
50919941Ssam iop = fdopen(pfd[0],"r");
510162Sroot return(iop);
511162Sroot }
512162Sroot }
513162Sroot
514162Sroot
getdiff(type,plinenum)515162Sroot getdiff(type,plinenum)
516162Sroot register char *type;
517162Sroot register int *plinenum;
518162Sroot {
519162Sroot char line[512];
520162Sroot register char *p;
521162Sroot int num_lines;
522162Sroot static int chg_num, chg_ln;
523162Sroot int lowline, highline;
524162Sroot
52519941Ssam if ((p = rddiff(line,sizeof (line))) == NULL)
526162Sroot return(0);
527162Sroot
528162Sroot if (*p == '-') {
529162Sroot *type = INS;
530162Sroot *plinenum = chg_ln;
531162Sroot num_lines = chg_num;
532162Sroot }
533162Sroot else {
534162Sroot p = linerange(p,&lowline,&highline);
535162Sroot *plinenum = lowline;
536162Sroot
537162Sroot switch(*p++) {
538162Sroot case 'd':
539162Sroot num_lines = highline - lowline + 1;
540162Sroot *type = DEL;
5412167Seric skiplines(line,num_lines);
542162Sroot break;
543162Sroot
544162Sroot case 'a':
545162Sroot linerange(p,&lowline,&highline);
546162Sroot num_lines = highline - lowline + 1;
547162Sroot *type = INS;
548162Sroot break;
549162Sroot
550162Sroot case 'c':
551162Sroot chg_ln = lowline;
552162Sroot num_lines = highline - lowline + 1;
553162Sroot linerange(p,&lowline,&highline);
554162Sroot chg_num = highline - lowline + 1;
555162Sroot *type = DEL;
5562167Seric skiplines(line,num_lines);
557162Sroot break;
558162Sroot }
559162Sroot }
560162Sroot
561162Sroot return(num_lines);
562162Sroot }
563162Sroot
564162Sroot
insert(pkt,linenum,n,ser)565162Sroot insert(pkt,linenum,n,ser)
566162Sroot register struct packet *pkt;
567162Sroot register int linenum;
568162Sroot register int n;
569162Sroot int ser;
570162Sroot {
571162Sroot char str[512];
572162Sroot
573162Sroot after(pkt,linenum);
57433423Sbostic sprintf(str,"%c%c %u\n",CTLCHAR,INS,ser);
57533423Sbostic putline(pkt,str);
576162Sroot for (++n; --n; ) {
577162Sroot rddiff(str,sizeof(str));
578162Sroot putline(pkt,&str[2]);
579162Sroot }
58033423Sbostic sprintf(str,"%c%c %u\n",CTLCHAR,END,ser);
58133423Sbostic putline(pkt,str);
582162Sroot }
583162Sroot
584162Sroot
delete(pkt,linenum,n,ser)585162Sroot delete(pkt,linenum,n,ser)
586162Sroot register struct packet *pkt;
587162Sroot register int linenum;
588162Sroot int n;
589162Sroot register int ser;
590162Sroot {
591162Sroot char str[512];
592162Sroot
593162Sroot before(pkt,linenum);
59433423Sbostic sprintf(str,"%c%c %u\n",CTLCHAR,DEL,ser);
59533423Sbostic putline(pkt,str);
596162Sroot after(pkt,linenum + n - 1);
59733423Sbostic sprintf(str,"%c%c %u\n",CTLCHAR,END,ser);
59833423Sbostic putline(pkt,str);
599162Sroot }
600162Sroot
601162Sroot
after(pkt,n)602162Sroot after(pkt,n)
603162Sroot register struct packet *pkt;
604162Sroot register int n;
605162Sroot {
606162Sroot before(pkt,n);
607162Sroot if (pkt->p_glnno == n)
608162Sroot putline(pkt,0);
609162Sroot }
610162Sroot
611162Sroot
before(pkt,n)612162Sroot before(pkt,n)
613162Sroot register struct packet *pkt;
614162Sroot register int n;
615162Sroot {
616162Sroot while (pkt->p_glnno < n) {
617162Sroot if (!readmod(pkt))
618162Sroot break;
619162Sroot }
620162Sroot }
621162Sroot
622162Sroot
linerange(cp,low,high)623162Sroot linerange(cp,low,high)
624162Sroot register char *cp;
625162Sroot register int *low, *high;
626162Sroot {
627162Sroot cp = satoi(cp,low);
628162Sroot if (*cp == ',')
629162Sroot cp = satoi(++cp,high);
630162Sroot else
631162Sroot *high = *low;
632162Sroot
633162Sroot return(cp);
634162Sroot }
635162Sroot
636162Sroot
skiplines(lp,num)637162Sroot skiplines(lp,num)
638162Sroot register char *lp;
639162Sroot register int num;
640162Sroot {
641162Sroot for (++num;--num;)
642162Sroot rddiff(lp,512);
643162Sroot }
644162Sroot
645162Sroot
rddiff(s,n)646162Sroot rddiff(s,n)
647162Sroot register char *s;
648162Sroot register int n;
649162Sroot {
650162Sroot register int r;
651162Sroot
652162Sroot if ((r = fgets(s,n,Diffin)) != NULL && HADP)
653162Sroot fputs(s,gpkt.p_stdout);
654162Sroot return(r);
655162Sroot }
656162Sroot
657162Sroot
658162Sroot enter(pkt,ch,n,sidp)
659162Sroot struct packet *pkt;
660162Sroot char ch;
661162Sroot int n;
662162Sroot struct sid *sidp;
663162Sroot {
664162Sroot char str[32];
665162Sroot register struct apply *ap;
666162Sroot
667162Sroot sid_ba(sidp,str);
668162Sroot ap = &pkt->p_apply[n];
669162Sroot if (pkt->p_cutoff > pkt->p_idel[n].i_datetime)
670162Sroot switch(ap->a_code) {
671162Sroot
672162Sroot case EMPTY:
673162Sroot switch (ch) {
674162Sroot case INCLUDE:
675162Sroot condset(ap,APPLY,INCLUSER);
676162Sroot break;
677162Sroot case EXCLUDE:
678162Sroot condset(ap,NOAPPLY,EXCLUSER);
679162Sroot break;
680162Sroot case IGNORE:
681162Sroot condset(ap,EMPTY,IGNRUSER);
682162Sroot break;
683162Sroot }
684162Sroot break;
685162Sroot case APPLY:
686162Sroot fatal("internal error in delta/enter() (de5)");
687162Sroot break;
688162Sroot case NOAPPLY:
689162Sroot fatal("internal error in delta/enter() (de6)");
690162Sroot break;
691162Sroot default:
692162Sroot fatal("internal error in delta/enter() (de7)");
693162Sroot break;
694162Sroot }
695162Sroot }
696162Sroot
697162Sroot
escdodelt()698162Sroot escdodelt() /* dummy routine for dodelt() */
699162Sroot {
700162Sroot }
701162Sroot
702162Sroot
clean_up(n)703162Sroot clean_up(n)
704162Sroot {
705162Sroot if (gpkt.p_file[0])
706162Sroot unlockit(auxf(gpkt.p_file,'z'),getpid());
707162Sroot xrm(&gpkt);
708162Sroot xfreeall();
709162Sroot }
710