1162Sroot # include "../hdr/defines.h" 2162Sroot # include "../hdr/had.h" 3162Sroot 4*15766Sralph SCCSID(@(#)delta.c 4.5); 5162Sroot USXALLOC(); 6162Sroot 7*15766Sralph # ifdef LOGDELTA 8*15766Sralph char LogFile[] = "/usr/adm/sccs-log"; 9*15766Sralph FILE *Logf; 10*15766Sralph # endif 11*15766Sralph 12*15766Sralph char Diffpgm[] = "/usr/local/bdiff"; 13162Sroot FILE *Diffin; 14162Sroot 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; 22*15766Sralph int verbosity; 23162Sroot int Did_id; 24162Sroot long Szqfile; 25162Sroot char Pfilename[FILESIZE]; 26162Sroot FILE *Xiop; 27162Sroot int Xcreate; 28162Sroot 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; 74162Sroot if (*p) 75162Sroot fatal(sprintf(Error, 76162Sroot "value after %c arg (cm7)",c)); 77162Sroot } 78162Sroot if (had[c - 'a']++) 79162Sroot fatal("key letter twice (cm2)"); 80162Sroot argv[i] = 0; 81162Sroot } 82162Sroot else num_files++; 83162Sroot 84*15766Sralph if (num_files == 0) 85162Sroot fatal("missing file arg (cm3)"); 86162Sroot if (!HADS) 87162Sroot verbosity = -1; 88*15766Sralph # ifdef LOGDELTA 89*15766Sralph if ((Logf = fopen(LogFile, "a")) == NULL) 90*15766Sralph fatal("cannot open logfile"); 91*15766Sralph # endif 92162Sroot setsig(); 93162Sroot Fflags =& ~FTLEXIT; 94162Sroot Fflags =| FTLJMP; 95162Sroot for (i=1; i<argc; i++) 96162Sroot if (p=argv[i]) 97162Sroot do_file(p,delta); 98*15766Sralph # ifdef LOGDELTA 99*15766Sralph fclose(Logf); 100*15766Sralph # endif 101162Sroot exit(Fcnt ? 1 : 0); 102162Sroot } 103162Sroot 104162Sroot 105162Sroot delta(file) 106*15766Sralph char *file; 107162Sroot { 108162Sroot static int first 1; 109162Sroot register char *p; 110162Sroot int n, linenum; 111162Sroot char type; 112162Sroot register int ser; 113162Sroot extern char had_dir, had_standinp; 114162Sroot extern char *Sflags[]; 115162Sroot char dfilename[FILESIZE]; 116162Sroot char gfilename[FILESIZE]; 117162Sroot char line[512]; 118162Sroot FILE *gin; 119162Sroot struct stats stats; 120162Sroot struct pfile *pp; 121162Sroot int inserted, deleted, orig; 122162Sroot int newser; 123162Sroot int status; 124162Sroot int diffloop; 125162Sroot int difflim; 126162Sroot 127162Sroot if (setjmp(Fjmp)) 128162Sroot return; 129162Sroot if (first) { 130162Sroot first = 0; 131162Sroot dohist(file); 132162Sroot } 133162Sroot sinit(&gpkt,file,1); 134162Sroot if (lockit(auxf(gpkt.p_file,'z'),2,getpid())) 135162Sroot fatal("cannot create lock file (cm4)"); 136162Sroot gpkt.p_reopen = 1; 137162Sroot gpkt.p_stdout = stdout; 138162Sroot copy(auxf(gpkt.p_file,'g'),gfilename); 139162Sroot gin = xfopen(gfilename,0); 140162Sroot pp = rdpfile(&gpkt,&sid); 141162Sroot gpkt.p_cutoff = pp->pf_date; 142162Sroot ilist = pp->pf_ilist; 143162Sroot elist = pp->pf_elist; 144162Sroot 145162Sroot if (dodelt(&gpkt,&stats,0,0) == 0) 146162Sroot fmterr(&gpkt); 147162Sroot if ((ser = sidtoser(&pp->pf_gsid,&gpkt)) == 0 || 148162Sroot sidtoser(&pp->pf_nsid,&gpkt)) 149162Sroot fatal("invalid sid in p-file (de3)"); 150162Sroot doie(&gpkt,ilist,elist,glist); 151162Sroot setup(&gpkt,ser); 152162Sroot finduser(&gpkt); 153162Sroot doflags(&gpkt); 154162Sroot move(&pp->pf_nsid,&gpkt.p_reqsid,sizeof(gpkt.p_reqsid)); 155162Sroot permiss(&gpkt); 156162Sroot flushto(&gpkt,EUSERTXT,1); 157162Sroot gpkt.p_chkeof = 1; 158162Sroot copy(auxf(gpkt.p_file,'d'),dfilename); 159162Sroot gpkt.p_gout = xfcreat(dfilename,0444); 160162Sroot while(readmod(&gpkt)) { 161162Sroot chkid(gpkt.p_line); 162162Sroot fputs(gpkt.p_line,gpkt.p_gout); 163162Sroot } 164162Sroot fclose(gpkt.p_gout); 165162Sroot orig = gpkt.p_glnno; 166162Sroot gpkt.p_glnno = 0; 167162Sroot gpkt.p_verbose = verbosity; 168162Sroot Did_id = 0; 169162Sroot while (fgets(line,sizeof(line),gin) != NULL && !chkid(line)) 170162Sroot ; 171162Sroot fclose(gin); 172162Sroot if (gpkt.p_verbose && (num_files > 1 || had_dir || had_standinp)) 173162Sroot fprintf(gpkt.p_stdout,"\n%s:\n",gpkt.p_file); 174162Sroot if (!Did_id) 175162Sroot if (Sflags[IDFLAG - 'a']) 176162Sroot fatal("no id keywords (cm6)"); 177162Sroot else if (gpkt.p_verbose) 178162Sroot fprintf(stderr,"No id keywords (cm7)\n"); 179162Sroot 180162Sroot /* 181162Sroot The following while loop executes 'bdiff' on g-file and 182162Sroot d-file. If 'bdiff' fails (usually because segmentation 183162Sroot limit it is using is too large for 'diff'), it is 184162Sroot invoked again, with a lower segmentation limit. 185162Sroot */ 186162Sroot difflim = 3500; 187162Sroot diffloop = 0; 188162Sroot while (1) { 189162Sroot inserted = deleted = 0; 190162Sroot gpkt.p_glnno = 0; 191162Sroot gpkt.p_upd = 1; 192162Sroot gpkt.p_wrttn = 1; 193162Sroot getline(&gpkt); 194162Sroot gpkt.p_wrttn = 1; 195162Sroot newser = mkdelt(&gpkt,&pp->pf_nsid,&pp->pf_gsid, 196162Sroot diffloop,orig); 197162Sroot diffloop = 1; 198162Sroot flushto(&gpkt,EUSERTXT,0); 199162Sroot Diffin = dodiff(auxf(gpkt.p_file,'g'),dfilename,difflim); 200162Sroot while (n = getdiff(&type,&linenum)) { 201162Sroot if (type == INS) { 202162Sroot inserted =+ n; 203162Sroot insert(&gpkt,linenum,n,newser); 204162Sroot } 205162Sroot else { 206162Sroot deleted =+ n; 207162Sroot delete(&gpkt,linenum,n,newser); 208162Sroot } 209162Sroot } 210162Sroot fclose(Diffin); 211162Sroot if (gpkt.p_iop) 212162Sroot while (readmod(&gpkt)) 213162Sroot ; 214162Sroot wait(&status); 215162Sroot if (status) { /* diff failed */ 216162Sroot /* 217162Sroot Check top byte (exit code of child). 218162Sroot */ 219162Sroot if (((status >> 8) & 0377) == 32) /* 'execl' failed */ 220162Sroot fatal(sprintf(Error, 221162Sroot "cannot execute '%s' (de12)", 222162Sroot Diffpgm)); 223162Sroot /* 224162Sroot Re-try. 225162Sroot */ 226162Sroot if (difflim =- 500) { /* reduce segmentation */ 227162Sroot fprintf(stderr, 228162Sroot "'%s' failed, re-trying, segmentation = %d (de13)\n", 229162Sroot Diffpgm,difflim); 230162Sroot fclose(Xiop); /* set up */ 231162Sroot Xiop = 0; /* for new x-file */ 232162Sroot Xcreate = 0; 233162Sroot /* 234162Sroot Re-open s-file. 235162Sroot */ 236162Sroot gpkt.p_iop = xfopen(gpkt.p_file,0); 237162Sroot setbuf(gpkt.p_iop,gpkt.p_buf); 238162Sroot /* 239162Sroot Reset counters. 240162Sroot */ 241162Sroot gpkt.p_slnno = 0; 242162Sroot gpkt.p_ihash = 0; 243162Sroot gpkt.p_chash = 0; 244162Sroot gpkt.p_nhash = 0; 245162Sroot gpkt.p_keep = 0; 246162Sroot } 247162Sroot else 248162Sroot /* tried up to 500 lines, can't go on */ 249162Sroot fatal("diff failed (de4)"); 250162Sroot } 251162Sroot else { /* no need to try again, worked */ 252162Sroot break; /* exit while loop */ 253162Sroot } 254162Sroot } 255162Sroot unlink(dfilename); 256162Sroot stats.s_ins = inserted; 257162Sroot stats.s_del = deleted; 258162Sroot stats.s_unc = orig - deleted; 259162Sroot if (gpkt.p_verbose) { 260162Sroot fprintf(gpkt.p_stdout,"%u inserted\n",stats.s_ins); 261162Sroot fprintf(gpkt.p_stdout,"%u deleted\n",stats.s_del); 262162Sroot fprintf(gpkt.p_stdout,"%u unchanged\n",stats.s_unc); 263162Sroot } 264162Sroot flushline(&gpkt,&stats); 265162Sroot rename(auxf(gpkt.p_file,'x'),gpkt.p_file); 266162Sroot if (Szqfile) 267162Sroot rename(auxf(&gpkt.p_file,'q'),Pfilename); 268162Sroot else { 269162Sroot xunlink(Pfilename); 270162Sroot xunlink(auxf(&gpkt.p_file,'q')); 271162Sroot } 272162Sroot clean_up(0); 273162Sroot if (!HADN) { 274162Sroot setuid(getuid()); 275162Sroot unlink(gfilename); 276162Sroot } 277162Sroot } 278162Sroot 279162Sroot 280162Sroot mkdelt(pkt,sp,osp,diffloop,orig_nlines) 281162Sroot struct packet *pkt; 282162Sroot struct sid *sp, *osp; 283162Sroot int diffloop; 284162Sroot int orig_nlines; 285162Sroot { 286162Sroot extern long Timenow; 287162Sroot struct deltab dt; 288162Sroot char str[128]; 289162Sroot int newser; 290162Sroot extern char *Sflags[]; 291162Sroot register char *p; 292162Sroot int ser_inc, opred, nulldel; 293162Sroot 294162Sroot if (!diffloop && pkt->p_verbose) { 295162Sroot sid_ba(sp,str); 296162Sroot fprintf(pkt->p_stdout,"%s\n",str); 297162Sroot } 298162Sroot putline(pkt,sprintf(str,"%c%c00000\n",CTLCHAR,HEAD)); 299162Sroot newstats(pkt,str,"0"); 300162Sroot move(sp,&dt.d_sid,sizeof(dt.d_sid)); 301162Sroot 302162Sroot /* 303162Sroot Check if 'null' deltas should be inserted 304162Sroot (only if 'null' flag is in file and 305162Sroot releases are being skipped) and set 306162Sroot 'nulldel' indicator appropriately. 307162Sroot */ 308162Sroot if (Sflags[NULLFLAG - 'a'] && (sp->s_rel > osp->s_rel + 1) && 309162Sroot !sp->s_br && !sp->s_seq && 310162Sroot !osp->s_br && !osp->s_seq) 311162Sroot nulldel = 1; 312162Sroot else 313162Sroot nulldel = 0; 314162Sroot /* 315162Sroot Calculate how many serial numbers are needed. 316162Sroot */ 317162Sroot if (nulldel) 318162Sroot ser_inc = sp->s_rel - osp->s_rel; 319162Sroot else 320162Sroot ser_inc = 1; 321162Sroot /* 322162Sroot Find serial number of the new delta. 323162Sroot */ 324162Sroot newser = dt.d_serial = maxser(pkt) + ser_inc; 325162Sroot /* 326162Sroot Find old predecessor's serial number. 327162Sroot */ 328162Sroot opred = sidtoser(osp,pkt); 329162Sroot if (nulldel) 330162Sroot dt.d_pred = newser - 1; /* set predecessor to 'null' delta */ 331162Sroot else 332162Sroot dt.d_pred = opred; 333162Sroot dt.d_datetime = Timenow; 3346173Seric substr(logname(),dt.d_pgmr,0,LNLNAM); 335162Sroot dt.d_type = 'D'; 336162Sroot del_ba(&dt,str); 337162Sroot putline(pkt,str); 338*15766Sralph # ifdef LOGDELTA 339*15766Sralph if (pkt->p_file[0] != '/') { 340*15766Sralph char buf[1024]; 341*15766Sralph 342*15766Sralph if (getwd(buf) != NULL) 343*15766Sralph fprintf(Logf, "%s/", buf); 344*15766Sralph } 345*15766Sralph fprintf(Logf, "%s:\n%s%s\n", pkt->p_file, str + 5, Comments); 346*15766Sralph # endif 347162Sroot if (ilist) 348162Sroot mkixg(pkt,INCLUSER,INCLUDE); 349162Sroot if (elist) 350162Sroot mkixg(pkt,EXCLUSER,EXCLUDE); 351162Sroot if (glist) 352162Sroot mkixg(pkt,IGNRUSER,IGNORE); 353162Sroot if (Mrs) { 354162Sroot if (!(p = Sflags[VALFLAG - 'a'])) 355162Sroot fatal("MRs not allowed (de8)"); 356162Sroot if (*p && !diffloop && valmrs(pkt,p)) 357162Sroot fatal("invalid MRs (de9)"); 358162Sroot putmrs(pkt); 359162Sroot } 360162Sroot else if (Sflags[VALFLAG - 'a']) 361162Sroot fatal("MRs required (de10)"); 362162Sroot putline(pkt,sprintf(str,"%c%c ",CTLCHAR,COMMENTS)); 363162Sroot putline(pkt,Comments); 364162Sroot putline(pkt,"\n"); 365162Sroot putline(pkt,sprintf(str,CTLSTR,CTLCHAR,EDELTAB)); 366162Sroot if (nulldel) /* insert 'null' deltas */ 367162Sroot while (--ser_inc) { 368162Sroot putline(pkt,sprintf(str,"%c%c %s/%s/%05u\n", 369162Sroot CTLCHAR, STATS, 370162Sroot "00000", "00000", orig_nlines)); 371162Sroot dt.d_sid.s_rel =- 1; 372162Sroot dt.d_serial =- 1; 373162Sroot if (ser_inc != 1) 374162Sroot dt.d_pred =- 1; 375162Sroot else 376162Sroot dt.d_pred = opred; /* point to old pred */ 377162Sroot del_ba(&dt,str); 378162Sroot putline(pkt,str); 379162Sroot putline(pkt,sprintf(str,"%c%c ",CTLCHAR,COMMENTS)); 380162Sroot putline(pkt,"AUTO NULL DELTA\n"); 381162Sroot putline(pkt,sprintf(str,CTLSTR,CTLCHAR,EDELTAB)); 382162Sroot } 383162Sroot return(newser); 384162Sroot } 385162Sroot 386162Sroot 387162Sroot mkixg(pkt,reason,ch) 388162Sroot struct packet *pkt; 389162Sroot int reason; 390162Sroot char ch; 391162Sroot { 392162Sroot int n; 393162Sroot char str[512]; 394162Sroot 395162Sroot putline(pkt,sprintf(str,"%c%c",CTLCHAR,ch)); 396162Sroot for (n = maxser(pkt); n; n--) { 397162Sroot if (pkt->p_apply[n].a_reason == reason) 398162Sroot putline(pkt,sprintf(str," %u",n)); 399162Sroot } 400162Sroot putline(pkt,"\n"); 401162Sroot } 402162Sroot 403162Sroot 404162Sroot putmrs(pkt) 405162Sroot struct packet *pkt; 406162Sroot { 407162Sroot register char **argv; 408162Sroot char str[64]; 409162Sroot extern char *Varg[]; 410162Sroot 411162Sroot for (argv = &Varg[VSTART]; *argv; argv++) 412162Sroot putline(pkt,sprintf(str,"%c%c %s\n",CTLCHAR,MRNUM,*argv)); 413162Sroot } 414162Sroot 415162Sroot 416162Sroot rdpfile(pkt,sp) 417162Sroot register struct packet *pkt; 418162Sroot struct sid *sp; 419162Sroot { 420162Sroot char *user; 421162Sroot struct pfile pf; 422162Sroot static struct pfile goodpf; 423162Sroot char line[512]; 4246636Ssam int cnt, root; 425162Sroot FILE *in, *out; 426162Sroot 427162Sroot cnt = -1; 428162Sroot user = logname(); 429162Sroot zero(&goodpf,sizeof(goodpf)); 430162Sroot in = xfopen(auxf(pkt->p_file,'p'),0); 431162Sroot out = xfcreat(auxf(pkt->p_file,'q'),0644); 4326636Ssam root = getuid() == 0; 433162Sroot while (fgets(line,sizeof(line),in) != NULL) { 434162Sroot pf_ab(line,&pf,1); 4356636Ssam if (root || equal(pf.pf_user,user)) { 436162Sroot if (sp->s_rel == 0) { 437162Sroot if (++cnt) { 438162Sroot fclose(out); 439162Sroot fclose(in); 440162Sroot fatal("missing -r argument (de1)"); 441162Sroot } 442162Sroot move(&pf,&goodpf,sizeof(pf)); 443162Sroot continue; 444162Sroot } 445162Sroot else if (sp->s_rel == pf.pf_gsid.s_rel && 446162Sroot sp->s_lev == pf.pf_gsid.s_lev && 447162Sroot sp->s_br == pf.pf_gsid.s_br && 448162Sroot sp->s_seq == pf.pf_gsid.s_seq) { 449162Sroot move(&pf,&goodpf,sizeof(pf)); 450162Sroot continue; 451162Sroot } 452162Sroot } 453162Sroot fputs(line,out); 454162Sroot } 455162Sroot fflush(out); 456162Sroot fstat(fileno(out),&Statbuf); 457162Sroot Szqfile = Statbuf.st_size; 458162Sroot copy(auxf(pkt->p_file,'p'),Pfilename); 459162Sroot fclose(out); 460162Sroot fclose(in); 461162Sroot if (!goodpf.pf_user[0]) 462162Sroot fatal("not in p-file (de2)"); 463162Sroot return(&goodpf); 464162Sroot } 465162Sroot 466162Sroot 467162Sroot dodiff(newf,oldf,difflim) 468162Sroot char *newf, *oldf; 469162Sroot int difflim; 470162Sroot { 471162Sroot register int i; 472162Sroot int pfd[2]; 473162Sroot FILE *iop; 474162Sroot extern char Diffpgm[]; 475162Sroot char num[10]; 476162Sroot 477162Sroot xpipe(pfd); 478162Sroot if ((i = fork()) < 0) { 479162Sroot close(pfd[0]); 480162Sroot close(pfd[1]); 481162Sroot fatal("cannot fork, try again (de11)"); 482162Sroot } 483162Sroot else if (i == 0) { 484162Sroot close(pfd[0]); 485162Sroot close(1); 486162Sroot dup(pfd[1]); 487162Sroot close(pfd[1]); 488162Sroot for (i = 5; i < 15; i++) 489162Sroot close(i); 490162Sroot sprintf(num,"%d",difflim); 491162Sroot execl(Diffpgm,Diffpgm,oldf,newf,num,"-s",0); 492162Sroot close(1); 493162Sroot exit(32); /* tell parent that 'execl' failed */ 494162Sroot } 495162Sroot else { 496162Sroot close(pfd[1]); 497162Sroot iop = fdfopen(pfd[0],0); 498162Sroot return(iop); 499162Sroot } 500162Sroot } 501162Sroot 502162Sroot 503162Sroot getdiff(type,plinenum) 504162Sroot register char *type; 505162Sroot register int *plinenum; 506162Sroot { 507162Sroot char line[512]; 508162Sroot register char *p; 509162Sroot int num_lines; 510162Sroot static int chg_num, chg_ln; 511162Sroot int lowline, highline; 512162Sroot 513162Sroot if ((p = rddiff(line,512)) == NULL) 514162Sroot return(0); 515162Sroot 516162Sroot if (*p == '-') { 517162Sroot *type = INS; 518162Sroot *plinenum = chg_ln; 519162Sroot num_lines = chg_num; 520162Sroot } 521162Sroot else { 522162Sroot p = linerange(p,&lowline,&highline); 523162Sroot *plinenum = lowline; 524162Sroot 525162Sroot switch(*p++) { 526162Sroot case 'd': 527162Sroot num_lines = highline - lowline + 1; 528162Sroot *type = DEL; 5292167Seric skiplines(line,num_lines); 530162Sroot break; 531162Sroot 532162Sroot case 'a': 533162Sroot linerange(p,&lowline,&highline); 534162Sroot num_lines = highline - lowline + 1; 535162Sroot *type = INS; 536162Sroot break; 537162Sroot 538162Sroot case 'c': 539162Sroot chg_ln = lowline; 540162Sroot num_lines = highline - lowline + 1; 541162Sroot linerange(p,&lowline,&highline); 542162Sroot chg_num = highline - lowline + 1; 543162Sroot *type = DEL; 5442167Seric skiplines(line,num_lines); 545162Sroot break; 546162Sroot } 547162Sroot } 548162Sroot 549162Sroot return(num_lines); 550162Sroot } 551162Sroot 552162Sroot 553162Sroot insert(pkt,linenum,n,ser) 554162Sroot register struct packet *pkt; 555162Sroot register int linenum; 556162Sroot register int n; 557162Sroot int ser; 558162Sroot { 559162Sroot char str[512]; 560162Sroot 561162Sroot after(pkt,linenum); 562162Sroot putline(pkt,sprintf(str,"%c%c %u\n",CTLCHAR,INS,ser)); 563162Sroot for (++n; --n; ) { 564162Sroot rddiff(str,sizeof(str)); 565162Sroot putline(pkt,&str[2]); 566162Sroot } 567162Sroot putline(pkt,sprintf(str,"%c%c %u\n",CTLCHAR,END,ser)); 568162Sroot } 569162Sroot 570162Sroot 571162Sroot delete(pkt,linenum,n,ser) 572162Sroot register struct packet *pkt; 573162Sroot register int linenum; 574162Sroot int n; 575162Sroot register int ser; 576162Sroot { 577162Sroot char str[512]; 578162Sroot 579162Sroot before(pkt,linenum); 580162Sroot putline(pkt,sprintf(str,"%c%c %u\n",CTLCHAR,DEL,ser)); 581162Sroot after(pkt,linenum + n - 1); 582162Sroot putline(pkt,sprintf(str,"%c%c %u\n",CTLCHAR,END,ser)); 583162Sroot } 584162Sroot 585162Sroot 586162Sroot after(pkt,n) 587162Sroot register struct packet *pkt; 588162Sroot register int n; 589162Sroot { 590162Sroot before(pkt,n); 591162Sroot if (pkt->p_glnno == n) 592162Sroot putline(pkt,0); 593162Sroot } 594162Sroot 595162Sroot 596162Sroot before(pkt,n) 597162Sroot register struct packet *pkt; 598162Sroot register int n; 599162Sroot { 600162Sroot while (pkt->p_glnno < n) { 601162Sroot if (!readmod(pkt)) 602162Sroot break; 603162Sroot } 604162Sroot } 605162Sroot 606162Sroot 607162Sroot linerange(cp,low,high) 608162Sroot register char *cp; 609162Sroot register int *low, *high; 610162Sroot { 611162Sroot cp = satoi(cp,low); 612162Sroot if (*cp == ',') 613162Sroot cp = satoi(++cp,high); 614162Sroot else 615162Sroot *high = *low; 616162Sroot 617162Sroot return(cp); 618162Sroot } 619162Sroot 620162Sroot 621162Sroot skiplines(lp,num) 622162Sroot register char *lp; 623162Sroot register int num; 624162Sroot { 625162Sroot for (++num;--num;) 626162Sroot rddiff(lp,512); 627162Sroot } 628162Sroot 629162Sroot 630162Sroot rddiff(s,n) 631162Sroot register char *s; 632162Sroot register int n; 633162Sroot { 634162Sroot register int r; 635162Sroot 636162Sroot if ((r = fgets(s,n,Diffin)) != NULL && HADP) 637162Sroot fputs(s,gpkt.p_stdout); 638162Sroot return(r); 639162Sroot } 640162Sroot 641162Sroot 642162Sroot enter(pkt,ch,n,sidp) 643162Sroot struct packet *pkt; 644162Sroot char ch; 645162Sroot int n; 646162Sroot struct sid *sidp; 647162Sroot { 648162Sroot char str[32]; 649162Sroot register struct apply *ap; 650162Sroot 651162Sroot sid_ba(sidp,str); 652162Sroot ap = &pkt->p_apply[n]; 653162Sroot if (pkt->p_cutoff > pkt->p_idel[n].i_datetime) 654162Sroot switch(ap->a_code) { 655162Sroot 656162Sroot case EMPTY: 657162Sroot switch (ch) { 658162Sroot case INCLUDE: 659162Sroot condset(ap,APPLY,INCLUSER); 660162Sroot break; 661162Sroot case EXCLUDE: 662162Sroot condset(ap,NOAPPLY,EXCLUSER); 663162Sroot break; 664162Sroot case IGNORE: 665162Sroot condset(ap,EMPTY,IGNRUSER); 666162Sroot break; 667162Sroot } 668162Sroot break; 669162Sroot case APPLY: 670162Sroot fatal("internal error in delta/enter() (de5)"); 671162Sroot break; 672162Sroot case NOAPPLY: 673162Sroot fatal("internal error in delta/enter() (de6)"); 674162Sroot break; 675162Sroot default: 676162Sroot fatal("internal error in delta/enter() (de7)"); 677162Sroot break; 678162Sroot } 679162Sroot } 680162Sroot 681162Sroot 682162Sroot escdodelt() /* dummy routine for dodelt() */ 683162Sroot { 684162Sroot } 685162Sroot 686162Sroot 687162Sroot clean_up(n) 688162Sroot { 689162Sroot if (gpkt.p_file[0]) 690162Sroot unlockit(auxf(gpkt.p_file,'z'),getpid()); 691162Sroot xrm(&gpkt); 692162Sroot xfreeall(); 693162Sroot } 694