1*2147Seric # include "../hdr/defines.h" 2*2147Seric # include "../hdr/had.h" 3*2147Seric 4*2147Seric SCCSID(@(#)get.c 4.1); 5*2147Seric USXALLOC(); 6*2147Seric 7*2147Seric int Debug 0; 8*2147Seric struct packet gpkt; 9*2147Seric struct sid sid; 10*2147Seric unsigned Ser; 11*2147Seric int num_files; 12*2147Seric char had[26]; 13*2147Seric char *ilist, *elist, *lfile; 14*2147Seric long cutoff 0X7FFFFFFFL; /* max positive long */ 15*2147Seric int verbosity; 16*2147Seric char Gfile[16]; 17*2147Seric char *Type; 18*2147Seric int Did_id; 19*2147Seric 20*2147Seric main(argc,argv) 21*2147Seric int argc; 22*2147Seric register char *argv[]; 23*2147Seric { 24*2147Seric register int i; 25*2147Seric register char *p; 26*2147Seric char c; 27*2147Seric int testmore; 28*2147Seric extern int Fcnt; 29*2147Seric extern get(); 30*2147Seric 31*2147Seric Fflags = FTLEXIT | FTLMSG | FTLCLN; 32*2147Seric for(i=1; i<argc; i++) 33*2147Seric if(argv[i][0] == '-' && (c=argv[i][1])) { 34*2147Seric p = &argv[i][2]; 35*2147Seric testmore = 0; 36*2147Seric switch (c) { 37*2147Seric 38*2147Seric case 'a': 39*2147Seric if (!p[0]) { 40*2147Seric argv[i] = 0; 41*2147Seric continue; 42*2147Seric } 43*2147Seric Ser = patoi(p); 44*2147Seric break; 45*2147Seric case 'r': 46*2147Seric if (!p[0]) { 47*2147Seric argv[i] = 0; 48*2147Seric continue; 49*2147Seric } 50*2147Seric chksid(sid_ab(p,&sid),&sid); 51*2147Seric break; 52*2147Seric case 'c': 53*2147Seric if (!p[0]) { 54*2147Seric argv[i] = 0; 55*2147Seric continue; 56*2147Seric } 57*2147Seric if (date_ab(p,&cutoff)) 58*2147Seric fatal("bad date/time (cm5)"); 59*2147Seric break; 60*2147Seric case 'l': 61*2147Seric lfile = p; 62*2147Seric break; 63*2147Seric case 'i': 64*2147Seric if (!p[0]) { 65*2147Seric argv[i] = 0; 66*2147Seric continue; 67*2147Seric } 68*2147Seric ilist = p; 69*2147Seric break; 70*2147Seric case 'x': 71*2147Seric if (!p[0]) { 72*2147Seric argv[i] = 0; 73*2147Seric continue; 74*2147Seric } 75*2147Seric elist = p; 76*2147Seric break; 77*2147Seric case 'b': 78*2147Seric case 'g': 79*2147Seric case 'e': 80*2147Seric case 'p': 81*2147Seric case 'k': 82*2147Seric case 'm': 83*2147Seric case 'n': 84*2147Seric case 's': 85*2147Seric case 't': 86*2147Seric testmore++; 87*2147Seric break; 88*2147Seric default: 89*2147Seric fatal("unknown key letter (cm1)"); 90*2147Seric } 91*2147Seric 92*2147Seric if (testmore) { 93*2147Seric testmore = 0; 94*2147Seric if (*p) 95*2147Seric fatal(sprintf(Error, 96*2147Seric "value after %c arg (cm8)",c)); 97*2147Seric } 98*2147Seric if (had[c - 'a']++) 99*2147Seric fatal("key letter twice (cm2)"); 100*2147Seric argv[i] = 0; 101*2147Seric } 102*2147Seric else num_files++; 103*2147Seric 104*2147Seric if(num_files == 0) 105*2147Seric fatal("missing file arg (cm3)"); 106*2147Seric if (HADE && HADM) 107*2147Seric fatal("e not allowed with m (ge3)"); 108*2147Seric if (HADE || HADI || HADX) 109*2147Seric HADK = 1; 110*2147Seric if (!HADS) 111*2147Seric verbosity = -1; 112*2147Seric setsig(); 113*2147Seric Fflags =& ~FTLEXIT; 114*2147Seric Fflags =| FTLJMP; 115*2147Seric for (i=1; i<argc; i++) 116*2147Seric if (p=argv[i]) 117*2147Seric do_file(p,get); 118*2147Seric exit(Fcnt ? 1 : 0); 119*2147Seric } 120*2147Seric 121*2147Seric 122*2147Seric get(file) 123*2147Seric { 124*2147Seric register char *p; 125*2147Seric register unsigned ser; 126*2147Seric extern char had_dir, had_standinp; 127*2147Seric extern char *Sflags[]; 128*2147Seric struct stats stats; 129*2147Seric char str[32]; 130*2147Seric 131*2147Seric if (setjmp(Fjmp)) 132*2147Seric return; 133*2147Seric sinit(&gpkt,file,1); 134*2147Seric gpkt.p_ixuser = (HADI | HADX); 135*2147Seric gpkt.p_reqsid.s_rel = sid.s_rel; 136*2147Seric gpkt.p_reqsid.s_lev = sid.s_lev; 137*2147Seric gpkt.p_reqsid.s_br = sid.s_br; 138*2147Seric gpkt.p_reqsid.s_seq = sid.s_seq; 139*2147Seric gpkt.p_verbose = verbosity; 140*2147Seric gpkt.p_stdout = (HADP ? stderr : stdout); 141*2147Seric gpkt.p_cutoff = cutoff; 142*2147Seric gpkt.p_lfile = lfile; 143*2147Seric copy(auxf(gpkt.p_file,'g'),Gfile); 144*2147Seric 145*2147Seric if (gpkt.p_verbose && (num_files > 1 || had_dir || had_standinp)) 146*2147Seric fprintf(gpkt.p_stdout,"\n%s:\n",gpkt.p_file); 147*2147Seric if (dodelt(&gpkt,&stats,0,0) == 0) 148*2147Seric fmterr(&gpkt); 149*2147Seric finduser(&gpkt); 150*2147Seric doflags(&gpkt); 151*2147Seric if (!HADA) 152*2147Seric ser = getser(&gpkt); 153*2147Seric else { 154*2147Seric if ((ser = Ser) > maxser(&gpkt)) 155*2147Seric fatal("serial number too large (ge19)"); 156*2147Seric move(&gpkt.p_idel[ser].i_sid, &gpkt.p_gotsid, sizeof(sid)); 157*2147Seric if (HADR && sid.s_rel != gpkt.p_gotsid.s_rel) { 158*2147Seric zero(&gpkt.p_reqsid, sizeof(gpkt.p_reqsid)); 159*2147Seric gpkt.p_reqsid.s_rel = sid.s_rel; 160*2147Seric } 161*2147Seric else 162*2147Seric move(&gpkt.p_gotsid, &gpkt.p_reqsid, sizeof(sid)); 163*2147Seric } 164*2147Seric doie(&gpkt,ilist,elist,0); 165*2147Seric setup(&gpkt,ser); 166*2147Seric if (!(Type = Sflags[TYPEFLAG - 'a'])) 167*2147Seric Type = Null; 168*2147Seric if (!(HADP || HADG) && access(Gfile,2) == 0) 169*2147Seric fatal(sprintf(Error,"writable `%s' exists (ge4)",Gfile)); 170*2147Seric if (gpkt.p_verbose) { 171*2147Seric sid_ba(&gpkt.p_gotsid,str); 172*2147Seric fprintf(gpkt.p_stdout,"%s\n",str); 173*2147Seric } 174*2147Seric if (HADE) { 175*2147Seric if (!HADR) 176*2147Seric move(&gpkt.p_gotsid,&gpkt.p_reqsid, 177*2147Seric sizeof(gpkt.p_reqsid)); 178*2147Seric newsid(&gpkt,Sflags[BRCHFLAG - 'a'] && HADB); 179*2147Seric permiss(&gpkt); 180*2147Seric wrtpfile(&gpkt,ilist,elist); 181*2147Seric } 182*2147Seric setuid(getuid()); 183*2147Seric if (HADL) 184*2147Seric gen_lfile(&gpkt); 185*2147Seric if (HADG) { 186*2147Seric fclose(gpkt.p_iop); 187*2147Seric xfreeall(); 188*2147Seric return; 189*2147Seric } 190*2147Seric flushto(&gpkt,EUSERTXT,1); 191*2147Seric idsetup(&gpkt); 192*2147Seric gpkt.p_chkeof = 1; 193*2147Seric Did_id = 0; 194*2147Seric while(readmod(&gpkt)) { 195*2147Seric if (gpkt.p_gout == 0) { 196*2147Seric if (HADP) 197*2147Seric gpkt.p_gout = stdout; 198*2147Seric else 199*2147Seric gpkt.p_gout = xfcreat(Gfile,HADK ? 0644 : 0444); 200*2147Seric } 201*2147Seric prfx(&gpkt); 202*2147Seric p = idsubst(&gpkt,gpkt.p_line); 203*2147Seric fputs(p,gpkt.p_gout); 204*2147Seric } 205*2147Seric fflush(gpkt.p_gout); 206*2147Seric if (gpkt.p_gout && gpkt.p_gout != stdout) 207*2147Seric fclose(gpkt.p_gout); 208*2147Seric if (gpkt.p_verbose) 209*2147Seric fprintf(gpkt.p_stdout,"%u lines\n",gpkt.p_glnno); 210*2147Seric if (!Did_id && !HADK) 211*2147Seric if (Sflags[IDFLAG - 'a']) 212*2147Seric fatal("no id keywords (cm6)"); 213*2147Seric else if (gpkt.p_verbose) 214*2147Seric fprintf(stderr,"No id keywords (cm7)\n"); 215*2147Seric xfreeall(); 216*2147Seric } 217*2147Seric 218*2147Seric 219*2147Seric newsid(pkt,branch) 220*2147Seric register struct packet *pkt; 221*2147Seric int branch; 222*2147Seric { 223*2147Seric int chkbr; 224*2147Seric 225*2147Seric chkbr = 0; 226*2147Seric if (pkt->p_reqsid.s_br == 0) { 227*2147Seric pkt->p_reqsid.s_lev =+ 1; 228*2147Seric if (sidtoser(&pkt->p_reqsid,pkt) || 229*2147Seric pkt->p_maxr > pkt->p_reqsid.s_rel || branch) { 230*2147Seric pkt->p_reqsid.s_rel = pkt->p_gotsid.s_rel; 231*2147Seric pkt->p_reqsid.s_lev = pkt->p_gotsid.s_lev; 232*2147Seric pkt->p_reqsid.s_br = pkt->p_gotsid.s_br + 1; 233*2147Seric pkt->p_reqsid.s_seq = 1; 234*2147Seric chkbr++; 235*2147Seric } 236*2147Seric } 237*2147Seric else if (pkt->p_reqsid.s_seq == 0 && !branch) 238*2147Seric pkt->p_reqsid.s_seq = pkt->p_gotsid.s_seq + 1; 239*2147Seric else { 240*2147Seric pkt->p_reqsid.s_seq =+ 1; 241*2147Seric if (branch || sidtoser(&pkt->p_reqsid,pkt)) { 242*2147Seric pkt->p_reqsid.s_br =+ 1; 243*2147Seric pkt->p_reqsid.s_seq = 1; 244*2147Seric chkbr++; 245*2147Seric } 246*2147Seric } 247*2147Seric if (chkbr) 248*2147Seric while (sidtoser(&pkt->p_reqsid,pkt)) 249*2147Seric pkt->p_reqsid.s_br =+ 1; 250*2147Seric if (sidtoser(&pkt->p_reqsid,pkt)) 251*2147Seric fatal("internal error in newsid()"); 252*2147Seric } 253*2147Seric 254*2147Seric 255*2147Seric enter(pkt,ch,n,sidp) 256*2147Seric struct packet *pkt; 257*2147Seric char ch; 258*2147Seric int n; 259*2147Seric struct sid *sidp; 260*2147Seric { 261*2147Seric char str[32]; 262*2147Seric register struct apply *ap; 263*2147Seric 264*2147Seric sid_ba(sidp,str); 265*2147Seric if (pkt->p_verbose) 266*2147Seric fprintf(pkt->p_stdout,"%s\n",str); 267*2147Seric ap = &pkt->p_apply[n]; 268*2147Seric switch(ap->a_code) { 269*2147Seric 270*2147Seric case EMPTY: 271*2147Seric if (ch == INCLUDE) 272*2147Seric condset(ap,APPLY,INCLUSER); 273*2147Seric else 274*2147Seric condset(ap,NOAPPLY,EXCLUSER); 275*2147Seric break; 276*2147Seric case APPLY: 277*2147Seric sid_ba(sidp,str); 278*2147Seric fatal(sprintf(Error,"%s already included (ge9)",str)); 279*2147Seric break; 280*2147Seric case NOAPPLY: 281*2147Seric sid_ba(sidp,str); 282*2147Seric fatal(sprintf(Error,"%s already excluded (ge10)",str)); 283*2147Seric break; 284*2147Seric default: 285*2147Seric fatal("internal error in get/enter() (ge11)"); 286*2147Seric break; 287*2147Seric } 288*2147Seric } 289*2147Seric 290*2147Seric 291*2147Seric gen_lfile(pkt) 292*2147Seric register struct packet *pkt; 293*2147Seric { 294*2147Seric int n; 295*2147Seric int reason; 296*2147Seric char str[32]; 297*2147Seric char line[BUFSIZ]; 298*2147Seric struct deltab dt; 299*2147Seric FILE *in; 300*2147Seric FILE *out; 301*2147Seric 302*2147Seric in = xfopen(pkt->p_file,0); 303*2147Seric if (*pkt->p_lfile) 304*2147Seric out = stdout; 305*2147Seric else 306*2147Seric out = xfcreat(auxf(pkt->p_file,'l'),0444); 307*2147Seric fgets(line,sizeof(line),in); 308*2147Seric while (fgets(line,sizeof(line),in) != NULL && line[0] == CTLCHAR && line[1] == STATS) { 309*2147Seric fgets(line,sizeof(line),in); 310*2147Seric del_ab(line,&dt); 311*2147Seric if (dt.d_type == 'D') { 312*2147Seric reason = pkt->p_apply[dt.d_serial].a_reason; 313*2147Seric if (pkt->p_apply[dt.d_serial].a_code == APPLY) { 314*2147Seric putc(' ',out); 315*2147Seric putc(' ',out); 316*2147Seric } 317*2147Seric else { 318*2147Seric putc('*',out); 319*2147Seric if (reason & IGNR) 320*2147Seric putc(' ',out); 321*2147Seric else 322*2147Seric putc('*',out); 323*2147Seric } 324*2147Seric switch (reason & (INCL | EXCL | CUTOFF)) { 325*2147Seric 326*2147Seric case INCL: 327*2147Seric putc('I',out); 328*2147Seric break; 329*2147Seric case EXCL: 330*2147Seric putc('X',out); 331*2147Seric break; 332*2147Seric case CUTOFF: 333*2147Seric putc('C',out); 334*2147Seric break; 335*2147Seric default: 336*2147Seric putc(' ',out); 337*2147Seric break; 338*2147Seric } 339*2147Seric putc(' ',out); 340*2147Seric sid_ba(&dt.d_sid,str); 341*2147Seric fprintf(out,"%s\t",str); 342*2147Seric date_ba(&dt.d_datetime,str); 343*2147Seric fprintf(out,"%s %s\n",str,dt.d_pgmr); 344*2147Seric } 345*2147Seric while ((n = fgets(line,sizeof(line),in)) != NULL) 346*2147Seric if (line[0] != CTLCHAR) 347*2147Seric break; 348*2147Seric else { 349*2147Seric switch (line[1]) { 350*2147Seric 351*2147Seric case EDELTAB: 352*2147Seric break; 353*2147Seric default: 354*2147Seric continue; 355*2147Seric case MRNUM: 356*2147Seric case COMMENTS: 357*2147Seric if (dt.d_type == 'D') 358*2147Seric fprintf(out,"\t%s",&line[3]); 359*2147Seric continue; 360*2147Seric } 361*2147Seric break; 362*2147Seric } 363*2147Seric if (n == NULL || line[0] != CTLCHAR) 364*2147Seric break; 365*2147Seric putc('\n',out); 366*2147Seric } 367*2147Seric fclose(in); 368*2147Seric if (out != stdout) 369*2147Seric fclose(out); 370*2147Seric } 371*2147Seric 372*2147Seric 373*2147Seric char Curdate[18]; 374*2147Seric char *Curtime; 375*2147Seric char Gdate[9]; 376*2147Seric char Chgdate[18]; 377*2147Seric char *Chgtime; 378*2147Seric char Gchgdate[9]; 379*2147Seric char Sid[32]; 380*2147Seric char Mod[16]; 381*2147Seric char Olddir[BUFSIZ]; 382*2147Seric char Pname[BUFSIZ]; 383*2147Seric char Dir[BUFSIZ]; 384*2147Seric 385*2147Seric idsetup(pkt) 386*2147Seric register struct packet *pkt; 387*2147Seric { 388*2147Seric extern long Timenow; 389*2147Seric register int n; 390*2147Seric register char *p; 391*2147Seric 392*2147Seric date_ba(&Timenow,Curdate); 393*2147Seric Curtime = &Curdate[9]; 394*2147Seric Curdate[8] = 0; 395*2147Seric copy(pkt->p_file,Dir); 396*2147Seric dname(Dir); 397*2147Seric if(curdir(Olddir) != 0) 398*2147Seric fatal("curdir failed (ge20)"); 399*2147Seric if(chdir(Dir) != 0) 400*2147Seric fatal("cannot change directory (ge22)"); 401*2147Seric if(curdir(Pname) != 0) 402*2147Seric fatal("curdir failed (ge21)"); 403*2147Seric if(chdir(Olddir) != 0) 404*2147Seric fatal("cannot change directory (ge23)"); 405*2147Seric makgdate(Curdate,Gdate); 406*2147Seric for (n = maxser(pkt); n; n--) 407*2147Seric if (pkt->p_apply[n].a_code == APPLY) 408*2147Seric break; 409*2147Seric if (n) 410*2147Seric date_ba(&pkt->p_idel[n].i_datetime,Chgdate); 411*2147Seric Chgtime = &Chgdate[9]; 412*2147Seric Chgdate[8] = 0; 413*2147Seric makgdate(Chgdate,Gchgdate); 414*2147Seric sid_ba(&pkt->p_gotsid,Sid); 415*2147Seric if (p = Sflags[MODFLAG - 'a']) 416*2147Seric copy(p,Mod); 417*2147Seric else 418*2147Seric copy(Gfile,Mod); 419*2147Seric } 420*2147Seric 421*2147Seric 422*2147Seric makgdate(old,new) 423*2147Seric register char *old, *new; 424*2147Seric { 425*2147Seric if ((*new = old[3]) != '0') 426*2147Seric new++; 427*2147Seric *new++ = old[4]; 428*2147Seric *new++ = '/'; 429*2147Seric if ((*new = old[6]) != '0') 430*2147Seric new++; 431*2147Seric *new++ = old[7]; 432*2147Seric *new++ = '/'; 433*2147Seric *new++ = old[0]; 434*2147Seric *new++ = old[1]; 435*2147Seric *new = 0; 436*2147Seric } 437*2147Seric 438*2147Seric 439*2147Seric static char Zkeywd[5] "@(#)"; 440*2147Seric 441*2147Seric idsubst(pkt,line) 442*2147Seric register struct packet *pkt; 443*2147Seric char line[]; 444*2147Seric { 445*2147Seric static char tline[BUFSIZ]; 446*2147Seric static char str[32]; 447*2147Seric register char *lp, *tp; 448*2147Seric extern char *Type; 449*2147Seric extern char *Sflags[]; 450*2147Seric 451*2147Seric if (HADK || !any('%',line)) 452*2147Seric return(line); 453*2147Seric 454*2147Seric tp = tline; 455*2147Seric for(lp=line; *lp != 0; lp++) { 456*2147Seric if(lp[0] == '%' && lp[1] != 0 && lp[2] == '%') { 457*2147Seric switch(*++lp) { 458*2147Seric 459*2147Seric case 'M': 460*2147Seric tp = trans(tp,Mod); 461*2147Seric break; 462*2147Seric case 'R': 463*2147Seric sprintf(str,"%u",pkt->p_gotsid.s_rel); 464*2147Seric tp = trans(tp,str); 465*2147Seric break; 466*2147Seric case 'L': 467*2147Seric sprintf(str,"%u",pkt->p_gotsid.s_lev); 468*2147Seric tp = trans(tp,str); 469*2147Seric break; 470*2147Seric case 'B': 471*2147Seric sprintf(str,"%u",pkt->p_gotsid.s_br); 472*2147Seric tp = trans(tp,str); 473*2147Seric break; 474*2147Seric case 'S': 475*2147Seric sprintf(str,"%u",pkt->p_gotsid.s_seq); 476*2147Seric tp = trans(tp,str); 477*2147Seric break; 478*2147Seric case 'D': 479*2147Seric tp = trans(tp,Curdate); 480*2147Seric break; 481*2147Seric case 'H': 482*2147Seric tp = trans(tp,Gdate); 483*2147Seric break; 484*2147Seric case 'T': 485*2147Seric tp = trans(tp,Curtime); 486*2147Seric break; 487*2147Seric case 'E': 488*2147Seric tp = trans(tp,Chgdate); 489*2147Seric break; 490*2147Seric case 'G': 491*2147Seric tp = trans(tp,Gchgdate); 492*2147Seric break; 493*2147Seric case 'U': 494*2147Seric tp = trans(tp,Chgtime); 495*2147Seric break; 496*2147Seric case 'Z': 497*2147Seric tp = trans(tp,Zkeywd); 498*2147Seric break; 499*2147Seric case 'Y': 500*2147Seric tp = trans(tp,Type); 501*2147Seric break; 502*2147Seric case 'W': 503*2147Seric tp = trans(tp,Zkeywd); 504*2147Seric tp = trans(tp,Mod); 505*2147Seric *tp++ = '\t'; 506*2147Seric case 'I': 507*2147Seric tp = trans(tp,Sid); 508*2147Seric break; 509*2147Seric case 'P': 510*2147Seric tp = trans(tp,Pname); 511*2147Seric *tp++ = '/'; 512*2147Seric tp = trans(tp,(sname(pkt->p_file))); 513*2147Seric break; 514*2147Seric case 'F': 515*2147Seric tp = trans(tp,pkt->p_file); 516*2147Seric break; 517*2147Seric case 'C': 518*2147Seric sprintf(str,"%u",pkt->p_glnno); 519*2147Seric tp = trans(tp,str); 520*2147Seric break; 521*2147Seric case 'A': 522*2147Seric tp = trans(tp,Zkeywd); 523*2147Seric tp = trans(tp,Type); 524*2147Seric *tp++ = ' '; 525*2147Seric tp = trans(tp,Mod); 526*2147Seric *tp++ = ' '; 527*2147Seric tp = trans(tp,Sid); 528*2147Seric tp = trans(tp,Zkeywd); 529*2147Seric break; 530*2147Seric default: 531*2147Seric *tp++ = '%'; 532*2147Seric *tp++ = *lp; 533*2147Seric continue; 534*2147Seric } 535*2147Seric lp++; 536*2147Seric } 537*2147Seric else 538*2147Seric *tp++ = *lp; 539*2147Seric } 540*2147Seric 541*2147Seric *tp = 0; 542*2147Seric return(tline); 543*2147Seric } 544*2147Seric 545*2147Seric 546*2147Seric trans(tp,str) 547*2147Seric register char *tp, *str; 548*2147Seric { 549*2147Seric Did_id = 1; 550*2147Seric while(*tp++ = *str++) 551*2147Seric ; 552*2147Seric return(tp-1); 553*2147Seric } 554*2147Seric 555*2147Seric 556*2147Seric prfx(pkt) 557*2147Seric register struct packet *pkt; 558*2147Seric { 559*2147Seric char str[32]; 560*2147Seric 561*2147Seric if (HADN) 562*2147Seric fprintf(pkt->p_gout,"%s\t",Mod); 563*2147Seric if (HADM) { 564*2147Seric sid_ba(&pkt->p_inssid,str); 565*2147Seric fprintf(pkt->p_gout,"%s\t",str); 566*2147Seric } 567*2147Seric } 568*2147Seric 569*2147Seric 570*2147Seric clean_up(n) 571*2147Seric { 572*2147Seric if (gpkt.p_file[0]) 573*2147Seric unlockit(auxf(gpkt.p_file,'z'),getpid()); 574*2147Seric if (gpkt.p_iop) 575*2147Seric fclose(gpkt.p_iop); 576*2147Seric xfreeall(); 577*2147Seric } 578*2147Seric 579*2147Seric 580*2147Seric wrtpfile(pkt,inc,exc) 581*2147Seric register struct packet *pkt; 582*2147Seric char *inc, *exc; 583*2147Seric { 584*2147Seric char line[64], str1[32], str2[32]; 585*2147Seric char *user; 586*2147Seric FILE *in, *out; 587*2147Seric struct pfile pf; 588*2147Seric register char *p; 589*2147Seric int fd; 590*2147Seric int i; 591*2147Seric extern long Timenow; 592*2147Seric 593*2147Seric user = logname(); 594*2147Seric if (lockit(auxf(pkt->p_file,'z'),2,getpid())) 595*2147Seric fatal("cannot create lock file (cm4)"); 596*2147Seric if (exists(p = auxf(pkt->p_file,'p'))) { 597*2147Seric fd = xopen(p,2); 598*2147Seric in = fdfopen(fd,0); 599*2147Seric while (fgets(line,sizeof(line),in) != NULL) { 600*2147Seric p = line; 601*2147Seric p[length(p) - 1] = 0; 602*2147Seric pf_ab(p,&pf,0); 603*2147Seric if ((pf.pf_gsid.s_rel == pkt->p_gotsid.s_rel && 604*2147Seric pf.pf_gsid.s_lev == pkt->p_gotsid.s_lev && 605*2147Seric pf.pf_gsid.s_br == pkt->p_gotsid.s_br && 606*2147Seric pf.pf_gsid.s_seq == pkt->p_gotsid.s_seq) || 607*2147Seric (pf.pf_nsid.s_rel == pkt->p_reqsid.s_rel && 608*2147Seric pf.pf_nsid.s_lev == pkt->p_reqsid.s_lev && 609*2147Seric pf.pf_nsid.s_br == pkt->p_reqsid.s_br && 610*2147Seric pf.pf_nsid.s_seq == pkt->p_reqsid.s_seq)) { 611*2147Seric fclose(in); 612*2147Seric fatal(sprintf(Error,"being edited: `%s' (ge17)", 613*2147Seric line)); 614*2147Seric } 615*2147Seric if (!equal(pf.pf_user,user)) 616*2147Seric fprintf(stderr,"WARNING: being edited: `%s' (ge18)\n",line); 617*2147Seric } 618*2147Seric out = fdfopen(dup(fd),1); 619*2147Seric fclose(in); 620*2147Seric } 621*2147Seric else 622*2147Seric out = xfcreat(p,0644); 623*2147Seric fseek(out,0L,2); 624*2147Seric sid_ba(&pkt->p_gotsid,str1); 625*2147Seric sid_ba(&pkt->p_reqsid,str2); 626*2147Seric date_ba(&Timenow,line); 627*2147Seric fprintf(out,"%s %s %s %s",str1,str2,user,line); 628*2147Seric if (inc) 629*2147Seric fprintf(out," -i%s",inc); 630*2147Seric if (exc) 631*2147Seric fprintf(out," -x%s",exc); 632*2147Seric fprintf(out,"\n"); 633*2147Seric fclose(out); 634*2147Seric if (pkt->p_verbose) 635*2147Seric fprintf(pkt->p_stdout,"new delta %s\n",str2); 636*2147Seric unlockit(auxf(pkt->p_file,'z'),getpid()); 637*2147Seric } 638*2147Seric 639*2147Seric 640*2147Seric getser(pkt) 641*2147Seric register struct packet *pkt; 642*2147Seric { 643*2147Seric register struct idel *rdp; 644*2147Seric int n, ser, def; 645*2147Seric char *p; 646*2147Seric extern char *Sflags[]; 647*2147Seric 648*2147Seric def = 0; 649*2147Seric if (pkt->p_reqsid.s_rel == 0) { 650*2147Seric if (p = Sflags[DEFTFLAG - 'a']) 651*2147Seric chksid(sid_ab(p, &pkt->p_reqsid), &pkt->p_reqsid); 652*2147Seric else { 653*2147Seric pkt->p_reqsid.s_rel = MAX; 654*2147Seric def = 1; 655*2147Seric } 656*2147Seric } 657*2147Seric ser = 0; 658*2147Seric if (pkt->p_reqsid.s_lev == 0) { 659*2147Seric for (n = maxser(pkt); n; n--) { 660*2147Seric rdp = &pkt->p_idel[n]; 661*2147Seric if ((rdp->i_sid.s_br == 0 || HADT) && 662*2147Seric pkt->p_reqsid.s_rel >= rdp->i_sid.s_rel && 663*2147Seric rdp->i_sid.s_rel > pkt->p_gotsid.s_rel) { 664*2147Seric ser = n; 665*2147Seric pkt->p_gotsid.s_rel = rdp->i_sid.s_rel; 666*2147Seric } 667*2147Seric } 668*2147Seric } 669*2147Seric else if (pkt->p_reqsid.s_br && pkt->p_reqsid.s_seq == 0) { 670*2147Seric for (n = maxser(pkt); n; n--) { 671*2147Seric rdp = &pkt->p_idel[n]; 672*2147Seric if (rdp->i_sid.s_rel == pkt->p_reqsid.s_rel && 673*2147Seric rdp->i_sid.s_lev == pkt->p_reqsid.s_lev && 674*2147Seric rdp->i_sid.s_br == pkt->p_reqsid.s_br) 675*2147Seric break; 676*2147Seric } 677*2147Seric ser = n; 678*2147Seric } 679*2147Seric else { 680*2147Seric ser = sidtoser(&pkt->p_reqsid,pkt); 681*2147Seric } 682*2147Seric if (ser == 0) 683*2147Seric fatal("nonexistent sid (ge5)"); 684*2147Seric rdp = &pkt->p_idel[ser]; 685*2147Seric move(&rdp->i_sid, &pkt->p_gotsid, sizeof(pkt->p_gotsid)); 686*2147Seric if (def || (pkt->p_reqsid.s_lev == 0 && pkt->p_reqsid.s_rel == pkt->p_gotsid.s_rel)) 687*2147Seric move(&pkt->p_gotsid, &pkt->p_reqsid, sizeof(pkt->p_gotsid)); 688*2147Seric return(ser); 689*2147Seric } 690*2147Seric 691*2147Seric 692*2147Seric /* Null routine to satisfy external reference from dodelt() */ 693*2147Seric 694*2147Seric escdodelt() 695*2147Seric { 696*2147Seric } 697