1162Sroot # include "../hdr/defines.h"
2162Sroot # include "../hdr/had.h"
3162Sroot
4*33423Sbostic static char Sccsid[] = "@(#)delta.c 4.10 02/02/88";
5162Sroot USXALLOC();
6162Sroot
715766Sralph # ifdef LOGDELTA
815766Sralph char LogFile[] = "/usr/adm/sccs-log";
915766Sralph FILE *Logf;
1015766Sralph # endif
1115766Sralph
1215766Sralph char Diffpgm[] = "/usr/local/bdiff";
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;
74*33423Sbostic if (*p) {
75*33423Sbostic sprintf(Error, "value after %c arg (cm7)",c);
76*33423Sbostic fatal(Error);
77*33423Sbostic }
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 */
220*33423Sbostic if (((status >> 8) & 0377) == 32) { /* 'execl' failed */
221*33423Sbostic sprintf(Error, "cannot execute '%s' (de12)", Diffpgm);
222*33423Sbostic fatal(Error);
223*33423Sbostic }
224162Sroot /*
225162Sroot Re-try.
226162Sroot */
22732771Sbostic if (difflim -= 500) { /* reduce segmentation */
228162Sroot fprintf(stderr,
229162Sroot "'%s' failed, re-trying, segmentation = %d (de13)\n",
230162Sroot Diffpgm,difflim);
231162Sroot fclose(Xiop); /* set up */
232162Sroot Xiop = 0; /* for new x-file */
233162Sroot Xcreate = 0;
234162Sroot /*
235162Sroot Re-open s-file.
236162Sroot */
237162Sroot gpkt.p_iop = xfopen(gpkt.p_file,0);
238162Sroot setbuf(gpkt.p_iop,gpkt.p_buf);
239162Sroot /*
240162Sroot Reset counters.
241162Sroot */
242162Sroot gpkt.p_slnno = 0;
243162Sroot gpkt.p_ihash = 0;
244162Sroot gpkt.p_chash = 0;
245162Sroot gpkt.p_nhash = 0;
246162Sroot gpkt.p_keep = 0;
247162Sroot }
248162Sroot else
249162Sroot /* tried up to 500 lines, can't go on */
250162Sroot fatal("diff failed (de4)");
251162Sroot }
252162Sroot else { /* no need to try again, worked */
253162Sroot break; /* exit while loop */
254162Sroot }
255162Sroot }
256162Sroot unlink(dfilename);
257162Sroot stats.s_ins = inserted;
258162Sroot stats.s_del = deleted;
259162Sroot stats.s_unc = orig - deleted;
260162Sroot if (gpkt.p_verbose) {
261162Sroot fprintf(gpkt.p_stdout,"%u inserted\n",stats.s_ins);
262162Sroot fprintf(gpkt.p_stdout,"%u deleted\n",stats.s_del);
263162Sroot fprintf(gpkt.p_stdout,"%u unchanged\n",stats.s_unc);
264162Sroot }
265162Sroot flushline(&gpkt,&stats);
266162Sroot rename(auxf(gpkt.p_file,'x'),gpkt.p_file);
267162Sroot if (Szqfile)
268162Sroot rename(auxf(&gpkt.p_file,'q'),Pfilename);
269162Sroot else {
270162Sroot xunlink(Pfilename);
271162Sroot xunlink(auxf(&gpkt.p_file,'q'));
272162Sroot }
273162Sroot clean_up(0);
274162Sroot if (!HADN) {
275162Sroot setuid(getuid());
276162Sroot unlink(gfilename);
277162Sroot }
278162Sroot }
279162Sroot
280162Sroot
281162Sroot mkdelt(pkt,sp,osp,diffloop,orig_nlines)
282162Sroot struct packet *pkt;
283162Sroot struct sid *sp, *osp;
284162Sroot int diffloop;
285162Sroot int orig_nlines;
286162Sroot {
287162Sroot extern long Timenow;
288162Sroot struct deltab dt;
289162Sroot char str[128];
290162Sroot int newser;
291162Sroot extern char *Sflags[];
292162Sroot register char *p;
293162Sroot int ser_inc, opred, nulldel;
294162Sroot
295162Sroot if (!diffloop && pkt->p_verbose) {
296162Sroot sid_ba(sp,str);
297162Sroot fprintf(pkt->p_stdout,"%s\n",str);
298162Sroot }
299*33423Sbostic sprintf(str,"%c%c00000\n",CTLCHAR,HEAD);
300*33423Sbostic putline(pkt,str);
301162Sroot newstats(pkt,str,"0");
30219941Ssam bcopy(sp,&dt.d_sid,sizeof(dt.d_sid));
303162Sroot
304162Sroot /*
305162Sroot Check if 'null' deltas should be inserted
306162Sroot (only if 'null' flag is in file and
307162Sroot releases are being skipped) and set
308162Sroot 'nulldel' indicator appropriately.
309162Sroot */
310162Sroot if (Sflags[NULLFLAG - 'a'] && (sp->s_rel > osp->s_rel + 1) &&
311162Sroot !sp->s_br && !sp->s_seq &&
312162Sroot !osp->s_br && !osp->s_seq)
313162Sroot nulldel = 1;
314162Sroot else
315162Sroot nulldel = 0;
316162Sroot /*
317162Sroot Calculate how many serial numbers are needed.
318162Sroot */
319162Sroot if (nulldel)
320162Sroot ser_inc = sp->s_rel - osp->s_rel;
321162Sroot else
322162Sroot ser_inc = 1;
323162Sroot /*
324162Sroot Find serial number of the new delta.
325162Sroot */
326162Sroot newser = dt.d_serial = maxser(pkt) + ser_inc;
327162Sroot /*
328162Sroot Find old predecessor's serial number.
329162Sroot */
330162Sroot opred = sidtoser(osp,pkt);
331162Sroot if (nulldel)
332162Sroot dt.d_pred = newser - 1; /* set predecessor to 'null' delta */
333162Sroot else
334162Sroot dt.d_pred = opred;
335162Sroot dt.d_datetime = Timenow;
3366173Seric substr(logname(),dt.d_pgmr,0,LNLNAM);
337162Sroot dt.d_type = 'D';
338162Sroot del_ba(&dt,str);
339162Sroot putline(pkt,str);
34015766Sralph # ifdef LOGDELTA
34115815Sralph if (Logf != NULL) {
34215815Sralph if (pkt->p_file[0] != '/') {
34315815Sralph char buf[1024];
34415766Sralph
34515815Sralph if (getwd(buf) != NULL)
34615815Sralph fprintf(Logf, "%s/", buf);
34715815Sralph }
34815815Sralph fprintf(Logf, "%s:\n%s%s\n", pkt->p_file, str + 5, Comments);
34915766Sralph }
35015766Sralph # endif
351162Sroot if (ilist)
352162Sroot mkixg(pkt,INCLUSER,INCLUDE);
353162Sroot if (elist)
354162Sroot mkixg(pkt,EXCLUSER,EXCLUDE);
355162Sroot if (glist)
356162Sroot mkixg(pkt,IGNRUSER,IGNORE);
357162Sroot if (Mrs) {
358162Sroot if (!(p = Sflags[VALFLAG - 'a']))
359162Sroot fatal("MRs not allowed (de8)");
360162Sroot if (*p && !diffloop && valmrs(pkt,p))
361162Sroot fatal("invalid MRs (de9)");
362162Sroot putmrs(pkt);
363162Sroot }
364162Sroot else if (Sflags[VALFLAG - 'a'])
365162Sroot fatal("MRs required (de10)");
366*33423Sbostic sprintf(str,"%c%c ",CTLCHAR,COMMENTS);
367*33423Sbostic putline(pkt,str);
368162Sroot putline(pkt,Comments);
369162Sroot putline(pkt,"\n");
370*33423Sbostic sprintf(str,CTLSTR,CTLCHAR,EDELTAB);
371*33423Sbostic putline(pkt,str);
372162Sroot if (nulldel) /* insert 'null' deltas */
373162Sroot while (--ser_inc) {
374*33423Sbostic sprintf(str,"%c%c %s/%s/%05u\n", CTLCHAR, STATS, "00000", "00000", orig_nlines);
375*33423Sbostic putline(pkt,str);
37632771Sbostic dt.d_sid.s_rel -= 1;
37732771Sbostic dt.d_serial -= 1;
378162Sroot if (ser_inc != 1)
37932771Sbostic dt.d_pred -= 1;
380162Sroot else
381162Sroot dt.d_pred = opred; /* point to old pred */
382162Sroot del_ba(&dt,str);
383162Sroot putline(pkt,str);
384*33423Sbostic sprintf(str,"%c%c ",CTLCHAR,COMMENTS);
385*33423Sbostic putline(pkt,str);
386162Sroot putline(pkt,"AUTO NULL DELTA\n");
387*33423Sbostic sprintf(str,CTLSTR,CTLCHAR,EDELTAB);
388*33423Sbostic putline(pkt,str);
389162Sroot }
390162Sroot return(newser);
391162Sroot }
392162Sroot
393162Sroot
394162Sroot mkixg(pkt,reason,ch)
395162Sroot struct packet *pkt;
396162Sroot int reason;
397162Sroot char ch;
398162Sroot {
399162Sroot int n;
400162Sroot char str[512];
401162Sroot
402*33423Sbostic sprintf(str,"%c%c",CTLCHAR,ch);
403*33423Sbostic putline(pkt,str);
404162Sroot for (n = maxser(pkt); n; n--) {
405*33423Sbostic if (pkt->p_apply[n].a_reason == reason) {
406*33423Sbostic sprintf(str," %u",n);
407*33423Sbostic putline(pkt,str);
408*33423Sbostic }
409162Sroot }
410162Sroot putline(pkt,"\n");
411162Sroot }
412162Sroot
413162Sroot
414162Sroot putmrs(pkt)
415162Sroot struct packet *pkt;
416162Sroot {
417162Sroot register char **argv;
418162Sroot char str[64];
419162Sroot extern char *Varg[];
420162Sroot
421*33423Sbostic for (argv = &Varg[VSTART]; *argv; argv++) {
422*33423Sbostic sprintf(str,"%c%c %s\n",CTLCHAR,MRNUM,*argv);
423*33423Sbostic putline(pkt,str);
424*33423Sbostic }
425162Sroot }
426162Sroot
427162Sroot
rdpfile(pkt,sp)428162Sroot rdpfile(pkt,sp)
429162Sroot register struct packet *pkt;
430162Sroot struct sid *sp;
431162Sroot {
432162Sroot char *user;
433162Sroot struct pfile pf;
434162Sroot static struct pfile goodpf;
435162Sroot char line[512];
4366636Ssam int cnt, root;
437162Sroot FILE *in, *out;
438162Sroot
439162Sroot cnt = -1;
440162Sroot user = logname();
44119941Ssam bzero(&goodpf,sizeof(goodpf));
442162Sroot in = xfopen(auxf(pkt->p_file,'p'),0);
443162Sroot out = xfcreat(auxf(pkt->p_file,'q'),0644);
4446636Ssam root = getuid() == 0;
445162Sroot while (fgets(line,sizeof(line),in) != NULL) {
446162Sroot pf_ab(line,&pf,1);
4476636Ssam if (root || equal(pf.pf_user,user)) {
448162Sroot if (sp->s_rel == 0) {
449162Sroot if (++cnt) {
450162Sroot fclose(out);
451162Sroot fclose(in);
452162Sroot fatal("missing -r argument (de1)");
453162Sroot }
45419941Ssam bcopy(&pf,&goodpf,sizeof(pf));
455162Sroot continue;
456162Sroot }
457162Sroot else if (sp->s_rel == pf.pf_gsid.s_rel &&
458162Sroot sp->s_lev == pf.pf_gsid.s_lev &&
459162Sroot sp->s_br == pf.pf_gsid.s_br &&
460162Sroot sp->s_seq == pf.pf_gsid.s_seq) {
46119941Ssam bcopy(&pf,&goodpf,sizeof(pf));
462162Sroot continue;
463162Sroot }
464162Sroot }
465162Sroot fputs(line,out);
466162Sroot }
467162Sroot fflush(out);
468162Sroot fstat(fileno(out),&Statbuf);
469162Sroot Szqfile = Statbuf.st_size;
470162Sroot copy(auxf(pkt->p_file,'p'),Pfilename);
471162Sroot fclose(out);
472162Sroot fclose(in);
473162Sroot if (!goodpf.pf_user[0])
474162Sroot fatal("not in p-file (de2)");
475162Sroot return(&goodpf);
476162Sroot }
477162Sroot
478162Sroot
dodiff(newf,oldf,difflim)479162Sroot dodiff(newf,oldf,difflim)
480162Sroot char *newf, *oldf;
481162Sroot int difflim;
482162Sroot {
483162Sroot register int i;
484162Sroot int pfd[2];
485162Sroot FILE *iop;
486162Sroot extern char Diffpgm[];
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);
503162Sroot execl(Diffpgm,Diffpgm,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);
574*33423Sbostic sprintf(str,"%c%c %u\n",CTLCHAR,INS,ser);
575*33423Sbostic putline(pkt,str);
576162Sroot for (++n; --n; ) {
577162Sroot rddiff(str,sizeof(str));
578162Sroot putline(pkt,&str[2]);
579162Sroot }
580*33423Sbostic sprintf(str,"%c%c %u\n",CTLCHAR,END,ser);
581*33423Sbostic 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);
594*33423Sbostic sprintf(str,"%c%c %u\n",CTLCHAR,DEL,ser);
595*33423Sbostic putline(pkt,str);
596162Sroot after(pkt,linenum + n - 1);
597*33423Sbostic sprintf(str,"%c%c %u\n",CTLCHAR,END,ser);
598*33423Sbostic 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