12147Seric # include "../hdr/defines.h" 22147Seric # include "../hdr/had.h" 32147Seric 4*2539Seric SCCSID(@(#)get.c 4.3); 52147Seric USXALLOC(); 62147Seric 72147Seric int Debug 0; 82147Seric struct packet gpkt; 92147Seric struct sid sid; 102147Seric unsigned Ser; 112147Seric int num_files; 122147Seric char had[26]; 132147Seric char *ilist, *elist, *lfile; 142147Seric long cutoff 0X7FFFFFFFL; /* max positive long */ 152147Seric int verbosity; 162147Seric char Gfile[16]; 172147Seric char *Type; 182147Seric int Did_id; 192147Seric 202147Seric main(argc,argv) 212147Seric int argc; 222147Seric register char *argv[]; 232147Seric { 242147Seric register int i; 252147Seric register char *p; 262147Seric char c; 272147Seric int testmore; 282147Seric extern int Fcnt; 292147Seric extern get(); 302147Seric 312147Seric Fflags = FTLEXIT | FTLMSG | FTLCLN; 322147Seric for(i=1; i<argc; i++) 332147Seric if(argv[i][0] == '-' && (c=argv[i][1])) { 342147Seric p = &argv[i][2]; 352147Seric testmore = 0; 362147Seric switch (c) { 372147Seric 382147Seric case 'a': 392147Seric if (!p[0]) { 402147Seric argv[i] = 0; 412147Seric continue; 422147Seric } 432147Seric Ser = patoi(p); 442147Seric break; 452147Seric case 'r': 462147Seric if (!p[0]) { 472147Seric argv[i] = 0; 482147Seric continue; 492147Seric } 502147Seric chksid(sid_ab(p,&sid),&sid); 512147Seric break; 522147Seric case 'c': 532147Seric if (!p[0]) { 542147Seric argv[i] = 0; 552147Seric continue; 562147Seric } 572147Seric if (date_ab(p,&cutoff)) 582147Seric fatal("bad date/time (cm5)"); 592147Seric break; 602147Seric case 'l': 612147Seric lfile = p; 622147Seric break; 632147Seric case 'i': 642147Seric if (!p[0]) { 652147Seric argv[i] = 0; 662147Seric continue; 672147Seric } 682147Seric ilist = p; 692147Seric break; 702147Seric case 'x': 712147Seric if (!p[0]) { 722147Seric argv[i] = 0; 732147Seric continue; 742147Seric } 752147Seric elist = p; 762147Seric break; 772147Seric case 'b': 782147Seric case 'g': 792147Seric case 'e': 802147Seric case 'p': 812147Seric case 'k': 822147Seric case 'm': 832147Seric case 'n': 842147Seric case 's': 852147Seric case 't': 862147Seric testmore++; 872147Seric break; 882147Seric default: 892147Seric fatal("unknown key letter (cm1)"); 902147Seric } 912147Seric 922147Seric if (testmore) { 932147Seric testmore = 0; 942147Seric if (*p) 952147Seric fatal(sprintf(Error, 962147Seric "value after %c arg (cm8)",c)); 972147Seric } 982147Seric if (had[c - 'a']++) 992147Seric fatal("key letter twice (cm2)"); 1002147Seric argv[i] = 0; 1012147Seric } 1022147Seric else num_files++; 1032147Seric 1042147Seric if(num_files == 0) 1052147Seric fatal("missing file arg (cm3)"); 1062147Seric if (HADE && HADM) 1072147Seric fatal("e not allowed with m (ge3)"); 1082147Seric if (HADE || HADI || HADX) 1092147Seric HADK = 1; 1102147Seric if (!HADS) 1112147Seric verbosity = -1; 1122147Seric setsig(); 1132147Seric Fflags =& ~FTLEXIT; 1142147Seric Fflags =| FTLJMP; 1152147Seric for (i=1; i<argc; i++) 1162147Seric if (p=argv[i]) 1172147Seric do_file(p,get); 1182147Seric exit(Fcnt ? 1 : 0); 1192147Seric } 1202147Seric 1212147Seric 1222147Seric get(file) 1232147Seric { 1242147Seric register char *p; 1252147Seric register unsigned ser; 1262147Seric extern char had_dir, had_standinp; 1272147Seric extern char *Sflags[]; 1282147Seric struct stats stats; 1292147Seric char str[32]; 1302147Seric 1312147Seric if (setjmp(Fjmp)) 1322147Seric return; 1332147Seric sinit(&gpkt,file,1); 1342147Seric gpkt.p_ixuser = (HADI | HADX); 1352147Seric gpkt.p_reqsid.s_rel = sid.s_rel; 1362147Seric gpkt.p_reqsid.s_lev = sid.s_lev; 1372147Seric gpkt.p_reqsid.s_br = sid.s_br; 1382147Seric gpkt.p_reqsid.s_seq = sid.s_seq; 1392147Seric gpkt.p_verbose = verbosity; 1402147Seric gpkt.p_stdout = (HADP ? stderr : stdout); 1412147Seric gpkt.p_cutoff = cutoff; 1422147Seric gpkt.p_lfile = lfile; 1432147Seric copy(auxf(gpkt.p_file,'g'),Gfile); 1442147Seric 1452147Seric if (gpkt.p_verbose && (num_files > 1 || had_dir || had_standinp)) 1462147Seric fprintf(gpkt.p_stdout,"\n%s:\n",gpkt.p_file); 1472147Seric if (dodelt(&gpkt,&stats,0,0) == 0) 1482147Seric fmterr(&gpkt); 1492147Seric finduser(&gpkt); 1502147Seric doflags(&gpkt); 1512147Seric if (!HADA) 1522147Seric ser = getser(&gpkt); 1532147Seric else { 1542147Seric if ((ser = Ser) > maxser(&gpkt)) 1552147Seric fatal("serial number too large (ge19)"); 1562147Seric move(&gpkt.p_idel[ser].i_sid, &gpkt.p_gotsid, sizeof(sid)); 1572147Seric if (HADR && sid.s_rel != gpkt.p_gotsid.s_rel) { 1582147Seric zero(&gpkt.p_reqsid, sizeof(gpkt.p_reqsid)); 1592147Seric gpkt.p_reqsid.s_rel = sid.s_rel; 1602147Seric } 1612147Seric else 1622147Seric move(&gpkt.p_gotsid, &gpkt.p_reqsid, sizeof(sid)); 1632147Seric } 1642147Seric doie(&gpkt,ilist,elist,0); 1652147Seric setup(&gpkt,ser); 1662147Seric if (!(Type = Sflags[TYPEFLAG - 'a'])) 1672147Seric Type = Null; 1682448Seric if (!(HADP || HADG) && writable(Gfile)) 1692147Seric fatal(sprintf(Error,"writable `%s' exists (ge4)",Gfile)); 1702147Seric if (gpkt.p_verbose) { 1712147Seric sid_ba(&gpkt.p_gotsid,str); 1722147Seric fprintf(gpkt.p_stdout,"%s\n",str); 1732147Seric } 1742147Seric if (HADE) { 1752147Seric if (!HADR) 1762147Seric move(&gpkt.p_gotsid,&gpkt.p_reqsid, 1772147Seric sizeof(gpkt.p_reqsid)); 1782147Seric newsid(&gpkt,Sflags[BRCHFLAG - 'a'] && HADB); 1792147Seric permiss(&gpkt); 1802147Seric wrtpfile(&gpkt,ilist,elist); 1812147Seric } 1822147Seric setuid(getuid()); 1832147Seric if (HADL) 1842147Seric gen_lfile(&gpkt); 1852147Seric if (HADG) { 1862147Seric fclose(gpkt.p_iop); 1872147Seric xfreeall(); 1882147Seric return; 1892147Seric } 1902147Seric flushto(&gpkt,EUSERTXT,1); 1912147Seric idsetup(&gpkt); 1922147Seric gpkt.p_chkeof = 1; 1932147Seric Did_id = 0; 1942147Seric while(readmod(&gpkt)) { 1952147Seric if (gpkt.p_gout == 0) { 1962147Seric if (HADP) 1972147Seric gpkt.p_gout = stdout; 1982147Seric else 199*2539Seric gpkt.p_gout = xfcreat(Gfile,HADK ? 0666 : 0444); 2002147Seric } 2012147Seric prfx(&gpkt); 2022147Seric p = idsubst(&gpkt,gpkt.p_line); 2032147Seric fputs(p,gpkt.p_gout); 2042147Seric } 2052147Seric fflush(gpkt.p_gout); 2062147Seric if (gpkt.p_gout && gpkt.p_gout != stdout) 2072147Seric fclose(gpkt.p_gout); 2082147Seric if (gpkt.p_verbose) 2092147Seric fprintf(gpkt.p_stdout,"%u lines\n",gpkt.p_glnno); 2102147Seric if (!Did_id && !HADK) 2112147Seric if (Sflags[IDFLAG - 'a']) 2122147Seric fatal("no id keywords (cm6)"); 2132147Seric else if (gpkt.p_verbose) 2142147Seric fprintf(stderr,"No id keywords (cm7)\n"); 2152147Seric xfreeall(); 2162147Seric } 2172147Seric 2182448Seric writable(fn) 2192448Seric char *fn; 2202448Seric { 2212448Seric struct stat s; 2222147Seric 2232448Seric return (stat(fn, &s) >= 0 && (s.st_mode & 0222) != 0); 2242448Seric } 2252448Seric 2262448Seric 2272147Seric newsid(pkt,branch) 2282147Seric register struct packet *pkt; 2292147Seric int branch; 2302147Seric { 2312147Seric int chkbr; 2322147Seric 2332147Seric chkbr = 0; 2342147Seric if (pkt->p_reqsid.s_br == 0) { 2352147Seric pkt->p_reqsid.s_lev =+ 1; 2362147Seric if (sidtoser(&pkt->p_reqsid,pkt) || 2372147Seric pkt->p_maxr > pkt->p_reqsid.s_rel || branch) { 2382147Seric pkt->p_reqsid.s_rel = pkt->p_gotsid.s_rel; 2392147Seric pkt->p_reqsid.s_lev = pkt->p_gotsid.s_lev; 2402147Seric pkt->p_reqsid.s_br = pkt->p_gotsid.s_br + 1; 2412147Seric pkt->p_reqsid.s_seq = 1; 2422147Seric chkbr++; 2432147Seric } 2442147Seric } 2452147Seric else if (pkt->p_reqsid.s_seq == 0 && !branch) 2462147Seric pkt->p_reqsid.s_seq = pkt->p_gotsid.s_seq + 1; 2472147Seric else { 2482147Seric pkt->p_reqsid.s_seq =+ 1; 2492147Seric if (branch || sidtoser(&pkt->p_reqsid,pkt)) { 2502147Seric pkt->p_reqsid.s_br =+ 1; 2512147Seric pkt->p_reqsid.s_seq = 1; 2522147Seric chkbr++; 2532147Seric } 2542147Seric } 2552147Seric if (chkbr) 2562147Seric while (sidtoser(&pkt->p_reqsid,pkt)) 2572147Seric pkt->p_reqsid.s_br =+ 1; 2582147Seric if (sidtoser(&pkt->p_reqsid,pkt)) 2592147Seric fatal("internal error in newsid()"); 2602147Seric } 2612147Seric 2622147Seric 2632147Seric enter(pkt,ch,n,sidp) 2642147Seric struct packet *pkt; 2652147Seric char ch; 2662147Seric int n; 2672147Seric struct sid *sidp; 2682147Seric { 2692147Seric char str[32]; 2702147Seric register struct apply *ap; 2712147Seric 2722147Seric sid_ba(sidp,str); 2732147Seric if (pkt->p_verbose) 2742147Seric fprintf(pkt->p_stdout,"%s\n",str); 2752147Seric ap = &pkt->p_apply[n]; 2762147Seric switch(ap->a_code) { 2772147Seric 2782147Seric case EMPTY: 2792147Seric if (ch == INCLUDE) 2802147Seric condset(ap,APPLY,INCLUSER); 2812147Seric else 2822147Seric condset(ap,NOAPPLY,EXCLUSER); 2832147Seric break; 2842147Seric case APPLY: 2852147Seric sid_ba(sidp,str); 2862147Seric fatal(sprintf(Error,"%s already included (ge9)",str)); 2872147Seric break; 2882147Seric case NOAPPLY: 2892147Seric sid_ba(sidp,str); 2902147Seric fatal(sprintf(Error,"%s already excluded (ge10)",str)); 2912147Seric break; 2922147Seric default: 2932147Seric fatal("internal error in get/enter() (ge11)"); 2942147Seric break; 2952147Seric } 2962147Seric } 2972147Seric 2982147Seric 2992147Seric gen_lfile(pkt) 3002147Seric register struct packet *pkt; 3012147Seric { 3022147Seric int n; 3032147Seric int reason; 3042147Seric char str[32]; 3052147Seric char line[BUFSIZ]; 3062147Seric struct deltab dt; 3072147Seric FILE *in; 3082147Seric FILE *out; 3092147Seric 3102147Seric in = xfopen(pkt->p_file,0); 3112147Seric if (*pkt->p_lfile) 3122147Seric out = stdout; 3132147Seric else 3142147Seric out = xfcreat(auxf(pkt->p_file,'l'),0444); 3152147Seric fgets(line,sizeof(line),in); 3162147Seric while (fgets(line,sizeof(line),in) != NULL && line[0] == CTLCHAR && line[1] == STATS) { 3172147Seric fgets(line,sizeof(line),in); 3182147Seric del_ab(line,&dt); 3192147Seric if (dt.d_type == 'D') { 3202147Seric reason = pkt->p_apply[dt.d_serial].a_reason; 3212147Seric if (pkt->p_apply[dt.d_serial].a_code == APPLY) { 3222147Seric putc(' ',out); 3232147Seric putc(' ',out); 3242147Seric } 3252147Seric else { 3262147Seric putc('*',out); 3272147Seric if (reason & IGNR) 3282147Seric putc(' ',out); 3292147Seric else 3302147Seric putc('*',out); 3312147Seric } 3322147Seric switch (reason & (INCL | EXCL | CUTOFF)) { 3332147Seric 3342147Seric case INCL: 3352147Seric putc('I',out); 3362147Seric break; 3372147Seric case EXCL: 3382147Seric putc('X',out); 3392147Seric break; 3402147Seric case CUTOFF: 3412147Seric putc('C',out); 3422147Seric break; 3432147Seric default: 3442147Seric putc(' ',out); 3452147Seric break; 3462147Seric } 3472147Seric putc(' ',out); 3482147Seric sid_ba(&dt.d_sid,str); 3492147Seric fprintf(out,"%s\t",str); 3502147Seric date_ba(&dt.d_datetime,str); 3512147Seric fprintf(out,"%s %s\n",str,dt.d_pgmr); 3522147Seric } 3532147Seric while ((n = fgets(line,sizeof(line),in)) != NULL) 3542147Seric if (line[0] != CTLCHAR) 3552147Seric break; 3562147Seric else { 3572147Seric switch (line[1]) { 3582147Seric 3592147Seric case EDELTAB: 3602147Seric break; 3612147Seric default: 3622147Seric continue; 3632147Seric case MRNUM: 3642147Seric case COMMENTS: 3652147Seric if (dt.d_type == 'D') 3662147Seric fprintf(out,"\t%s",&line[3]); 3672147Seric continue; 3682147Seric } 3692147Seric break; 3702147Seric } 3712147Seric if (n == NULL || line[0] != CTLCHAR) 3722147Seric break; 3732147Seric putc('\n',out); 3742147Seric } 3752147Seric fclose(in); 3762147Seric if (out != stdout) 3772147Seric fclose(out); 3782147Seric } 3792147Seric 3802147Seric 3812147Seric char Curdate[18]; 3822147Seric char *Curtime; 3832147Seric char Gdate[9]; 3842147Seric char Chgdate[18]; 3852147Seric char *Chgtime; 3862147Seric char Gchgdate[9]; 3872147Seric char Sid[32]; 3882147Seric char Mod[16]; 3892147Seric char Olddir[BUFSIZ]; 3902147Seric char Pname[BUFSIZ]; 3912147Seric char Dir[BUFSIZ]; 3922147Seric 3932147Seric idsetup(pkt) 3942147Seric register struct packet *pkt; 3952147Seric { 3962147Seric extern long Timenow; 3972147Seric register int n; 3982147Seric register char *p; 3992147Seric 4002147Seric date_ba(&Timenow,Curdate); 4012147Seric Curtime = &Curdate[9]; 4022147Seric Curdate[8] = 0; 4032147Seric copy(pkt->p_file,Dir); 4042147Seric dname(Dir); 4052147Seric if(curdir(Olddir) != 0) 4062147Seric fatal("curdir failed (ge20)"); 4072147Seric if(chdir(Dir) != 0) 4082147Seric fatal("cannot change directory (ge22)"); 4092147Seric if(curdir(Pname) != 0) 4102147Seric fatal("curdir failed (ge21)"); 4112147Seric if(chdir(Olddir) != 0) 4122147Seric fatal("cannot change directory (ge23)"); 4132147Seric makgdate(Curdate,Gdate); 4142147Seric for (n = maxser(pkt); n; n--) 4152147Seric if (pkt->p_apply[n].a_code == APPLY) 4162147Seric break; 4172147Seric if (n) 4182147Seric date_ba(&pkt->p_idel[n].i_datetime,Chgdate); 4192147Seric Chgtime = &Chgdate[9]; 4202147Seric Chgdate[8] = 0; 4212147Seric makgdate(Chgdate,Gchgdate); 4222147Seric sid_ba(&pkt->p_gotsid,Sid); 4232147Seric if (p = Sflags[MODFLAG - 'a']) 4242147Seric copy(p,Mod); 4252147Seric else 4262147Seric copy(Gfile,Mod); 4272147Seric } 4282147Seric 4292147Seric 4302147Seric makgdate(old,new) 4312147Seric register char *old, *new; 4322147Seric { 4332147Seric if ((*new = old[3]) != '0') 4342147Seric new++; 4352147Seric *new++ = old[4]; 4362147Seric *new++ = '/'; 4372147Seric if ((*new = old[6]) != '0') 4382147Seric new++; 4392147Seric *new++ = old[7]; 4402147Seric *new++ = '/'; 4412147Seric *new++ = old[0]; 4422147Seric *new++ = old[1]; 4432147Seric *new = 0; 4442147Seric } 4452147Seric 4462147Seric 4472147Seric static char Zkeywd[5] "@(#)"; 4482147Seric 4492147Seric idsubst(pkt,line) 4502147Seric register struct packet *pkt; 4512147Seric char line[]; 4522147Seric { 4532147Seric static char tline[BUFSIZ]; 4542147Seric static char str[32]; 4552147Seric register char *lp, *tp; 4562147Seric extern char *Type; 4572147Seric extern char *Sflags[]; 4582147Seric 4592147Seric if (HADK || !any('%',line)) 4602147Seric return(line); 4612147Seric 4622147Seric tp = tline; 4632147Seric for(lp=line; *lp != 0; lp++) { 4642147Seric if(lp[0] == '%' && lp[1] != 0 && lp[2] == '%') { 4652147Seric switch(*++lp) { 4662147Seric 4672147Seric case 'M': 4682147Seric tp = trans(tp,Mod); 4692147Seric break; 4702147Seric case 'R': 4712147Seric sprintf(str,"%u",pkt->p_gotsid.s_rel); 4722147Seric tp = trans(tp,str); 4732147Seric break; 4742147Seric case 'L': 4752147Seric sprintf(str,"%u",pkt->p_gotsid.s_lev); 4762147Seric tp = trans(tp,str); 4772147Seric break; 4782147Seric case 'B': 4792147Seric sprintf(str,"%u",pkt->p_gotsid.s_br); 4802147Seric tp = trans(tp,str); 4812147Seric break; 4822147Seric case 'S': 4832147Seric sprintf(str,"%u",pkt->p_gotsid.s_seq); 4842147Seric tp = trans(tp,str); 4852147Seric break; 4862147Seric case 'D': 4872147Seric tp = trans(tp,Curdate); 4882147Seric break; 4892147Seric case 'H': 4902147Seric tp = trans(tp,Gdate); 4912147Seric break; 4922147Seric case 'T': 4932147Seric tp = trans(tp,Curtime); 4942147Seric break; 4952147Seric case 'E': 4962147Seric tp = trans(tp,Chgdate); 4972147Seric break; 4982147Seric case 'G': 4992147Seric tp = trans(tp,Gchgdate); 5002147Seric break; 5012147Seric case 'U': 5022147Seric tp = trans(tp,Chgtime); 5032147Seric break; 5042147Seric case 'Z': 5052147Seric tp = trans(tp,Zkeywd); 5062147Seric break; 5072147Seric case 'Y': 5082147Seric tp = trans(tp,Type); 5092147Seric break; 5102147Seric case 'W': 5112147Seric tp = trans(tp,Zkeywd); 5122147Seric tp = trans(tp,Mod); 5132147Seric *tp++ = '\t'; 5142147Seric case 'I': 5152147Seric tp = trans(tp,Sid); 5162147Seric break; 5172147Seric case 'P': 5182147Seric tp = trans(tp,Pname); 5192147Seric *tp++ = '/'; 5202147Seric tp = trans(tp,(sname(pkt->p_file))); 5212147Seric break; 5222147Seric case 'F': 5232147Seric tp = trans(tp,pkt->p_file); 5242147Seric break; 5252147Seric case 'C': 5262147Seric sprintf(str,"%u",pkt->p_glnno); 5272147Seric tp = trans(tp,str); 5282147Seric break; 5292147Seric case 'A': 5302147Seric tp = trans(tp,Zkeywd); 5312147Seric tp = trans(tp,Type); 5322147Seric *tp++ = ' '; 5332147Seric tp = trans(tp,Mod); 5342147Seric *tp++ = ' '; 5352147Seric tp = trans(tp,Sid); 5362147Seric tp = trans(tp,Zkeywd); 5372147Seric break; 5382147Seric default: 5392147Seric *tp++ = '%'; 5402147Seric *tp++ = *lp; 5412147Seric continue; 5422147Seric } 5432147Seric lp++; 5442147Seric } 5452147Seric else 5462147Seric *tp++ = *lp; 5472147Seric } 5482147Seric 5492147Seric *tp = 0; 5502147Seric return(tline); 5512147Seric } 5522147Seric 5532147Seric 5542147Seric trans(tp,str) 5552147Seric register char *tp, *str; 5562147Seric { 5572147Seric Did_id = 1; 5582147Seric while(*tp++ = *str++) 5592147Seric ; 5602147Seric return(tp-1); 5612147Seric } 5622147Seric 5632147Seric 5642147Seric prfx(pkt) 5652147Seric register struct packet *pkt; 5662147Seric { 5672147Seric char str[32]; 5682147Seric 5692147Seric if (HADN) 5702147Seric fprintf(pkt->p_gout,"%s\t",Mod); 5712147Seric if (HADM) { 5722147Seric sid_ba(&pkt->p_inssid,str); 5732147Seric fprintf(pkt->p_gout,"%s\t",str); 5742147Seric } 5752147Seric } 5762147Seric 5772147Seric 5782147Seric clean_up(n) 5792147Seric { 5802147Seric if (gpkt.p_file[0]) 5812147Seric unlockit(auxf(gpkt.p_file,'z'),getpid()); 5822147Seric if (gpkt.p_iop) 5832147Seric fclose(gpkt.p_iop); 5842147Seric xfreeall(); 5852147Seric } 5862147Seric 5872147Seric 5882147Seric wrtpfile(pkt,inc,exc) 5892147Seric register struct packet *pkt; 5902147Seric char *inc, *exc; 5912147Seric { 5922147Seric char line[64], str1[32], str2[32]; 5932147Seric char *user; 5942147Seric FILE *in, *out; 5952147Seric struct pfile pf; 5962147Seric register char *p; 5972147Seric int fd; 5982147Seric int i; 5992147Seric extern long Timenow; 6002147Seric 6012147Seric user = logname(); 6022147Seric if (lockit(auxf(pkt->p_file,'z'),2,getpid())) 6032147Seric fatal("cannot create lock file (cm4)"); 6042147Seric if (exists(p = auxf(pkt->p_file,'p'))) { 6052147Seric fd = xopen(p,2); 6062147Seric in = fdfopen(fd,0); 6072147Seric while (fgets(line,sizeof(line),in) != NULL) { 6082147Seric p = line; 6092147Seric p[length(p) - 1] = 0; 6102147Seric pf_ab(p,&pf,0); 6112147Seric if ((pf.pf_gsid.s_rel == pkt->p_gotsid.s_rel && 6122147Seric pf.pf_gsid.s_lev == pkt->p_gotsid.s_lev && 6132147Seric pf.pf_gsid.s_br == pkt->p_gotsid.s_br && 6142147Seric pf.pf_gsid.s_seq == pkt->p_gotsid.s_seq) || 6152147Seric (pf.pf_nsid.s_rel == pkt->p_reqsid.s_rel && 6162147Seric pf.pf_nsid.s_lev == pkt->p_reqsid.s_lev && 6172147Seric pf.pf_nsid.s_br == pkt->p_reqsid.s_br && 6182147Seric pf.pf_nsid.s_seq == pkt->p_reqsid.s_seq)) { 6192147Seric fclose(in); 6202147Seric fatal(sprintf(Error,"being edited: `%s' (ge17)", 6212147Seric line)); 6222147Seric } 6232147Seric if (!equal(pf.pf_user,user)) 6242147Seric fprintf(stderr,"WARNING: being edited: `%s' (ge18)\n",line); 6252147Seric } 6262147Seric out = fdfopen(dup(fd),1); 6272147Seric fclose(in); 6282147Seric } 6292147Seric else 630*2539Seric out = xfcreat(p,0666); 6312147Seric fseek(out,0L,2); 6322147Seric sid_ba(&pkt->p_gotsid,str1); 6332147Seric sid_ba(&pkt->p_reqsid,str2); 6342147Seric date_ba(&Timenow,line); 6352147Seric fprintf(out,"%s %s %s %s",str1,str2,user,line); 6362147Seric if (inc) 6372147Seric fprintf(out," -i%s",inc); 6382147Seric if (exc) 6392147Seric fprintf(out," -x%s",exc); 6402147Seric fprintf(out,"\n"); 6412147Seric fclose(out); 6422147Seric if (pkt->p_verbose) 6432147Seric fprintf(pkt->p_stdout,"new delta %s\n",str2); 6442147Seric unlockit(auxf(pkt->p_file,'z'),getpid()); 6452147Seric } 6462147Seric 6472147Seric 6482147Seric getser(pkt) 6492147Seric register struct packet *pkt; 6502147Seric { 6512147Seric register struct idel *rdp; 6522147Seric int n, ser, def; 6532147Seric char *p; 6542147Seric extern char *Sflags[]; 6552147Seric 6562147Seric def = 0; 6572147Seric if (pkt->p_reqsid.s_rel == 0) { 6582147Seric if (p = Sflags[DEFTFLAG - 'a']) 6592147Seric chksid(sid_ab(p, &pkt->p_reqsid), &pkt->p_reqsid); 6602147Seric else { 6612147Seric pkt->p_reqsid.s_rel = MAX; 6622147Seric def = 1; 6632147Seric } 6642147Seric } 6652147Seric ser = 0; 6662147Seric if (pkt->p_reqsid.s_lev == 0) { 6672147Seric for (n = maxser(pkt); n; n--) { 6682147Seric rdp = &pkt->p_idel[n]; 6692147Seric if ((rdp->i_sid.s_br == 0 || HADT) && 6702147Seric pkt->p_reqsid.s_rel >= rdp->i_sid.s_rel && 6712147Seric rdp->i_sid.s_rel > pkt->p_gotsid.s_rel) { 6722147Seric ser = n; 6732147Seric pkt->p_gotsid.s_rel = rdp->i_sid.s_rel; 6742147Seric } 6752147Seric } 6762147Seric } 6772147Seric else if (pkt->p_reqsid.s_br && pkt->p_reqsid.s_seq == 0) { 6782147Seric for (n = maxser(pkt); n; n--) { 6792147Seric rdp = &pkt->p_idel[n]; 6802147Seric if (rdp->i_sid.s_rel == pkt->p_reqsid.s_rel && 6812147Seric rdp->i_sid.s_lev == pkt->p_reqsid.s_lev && 6822147Seric rdp->i_sid.s_br == pkt->p_reqsid.s_br) 6832147Seric break; 6842147Seric } 6852147Seric ser = n; 6862147Seric } 6872147Seric else { 6882147Seric ser = sidtoser(&pkt->p_reqsid,pkt); 6892147Seric } 6902147Seric if (ser == 0) 6912147Seric fatal("nonexistent sid (ge5)"); 6922147Seric rdp = &pkt->p_idel[ser]; 6932147Seric move(&rdp->i_sid, &pkt->p_gotsid, sizeof(pkt->p_gotsid)); 6942147Seric if (def || (pkt->p_reqsid.s_lev == 0 && pkt->p_reqsid.s_rel == pkt->p_gotsid.s_rel)) 6952147Seric move(&pkt->p_gotsid, &pkt->p_reqsid, sizeof(pkt->p_gotsid)); 6962147Seric return(ser); 6972147Seric } 6982147Seric 6992147Seric 7002147Seric /* Null routine to satisfy external reference from dodelt() */ 7012147Seric 7022147Seric escdodelt() 7032147Seric { 7042147Seric } 705