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