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> 6*40849Sbostic # include "pathnames.h" 72147Seric 8*40849Sbostic static char Sccsid[] = "@(#)get.c 4.10 04/08/90"; 92147Seric 1030498Slepreau int Debug = 0; 112147Seric struct packet gpkt; 122147Seric struct sid sid; 132147Seric unsigned Ser; 142147Seric int num_files; 152147Seric char had[26]; 162147Seric char *ilist, *elist, *lfile; 1730498Slepreau long cutoff = 0X7FFFFFFFL; /* max positive long */ 182147Seric int verbosity; 198341Ssam char Gfile[MAXNAMLEN + 3]; 2016514Smckusick char Mod[MAXNAMLEN + 3]; /* should be as large as Gfile? */ 212147Seric char *Type; 222147Seric int Did_id; 232147Seric 242147Seric main(argc,argv) 252147Seric int argc; 262147Seric register char *argv[]; 272147Seric { 282147Seric register int i; 292147Seric register char *p; 302147Seric char c; 312147Seric int testmore; 322147Seric extern int Fcnt; 332147Seric extern get(); 342147Seric 352147Seric Fflags = FTLEXIT | FTLMSG | FTLCLN; 362147Seric for(i=1; i<argc; i++) 372147Seric if(argv[i][0] == '-' && (c=argv[i][1])) { 382147Seric p = &argv[i][2]; 392147Seric testmore = 0; 402147Seric switch (c) { 412147Seric 422147Seric case 'a': 432147Seric if (!p[0]) { 442147Seric argv[i] = 0; 452147Seric continue; 462147Seric } 472147Seric Ser = patoi(p); 482147Seric break; 492147Seric case 'r': 502147Seric if (!p[0]) { 512147Seric argv[i] = 0; 522147Seric continue; 532147Seric } 542147Seric chksid(sid_ab(p,&sid),&sid); 552147Seric break; 562147Seric case 'c': 572147Seric if (!p[0]) { 582147Seric argv[i] = 0; 592147Seric continue; 602147Seric } 612147Seric if (date_ab(p,&cutoff)) 622147Seric fatal("bad date/time (cm5)"); 632147Seric break; 642147Seric case 'l': 652147Seric lfile = p; 662147Seric break; 672147Seric case 'i': 682147Seric if (!p[0]) { 692147Seric argv[i] = 0; 702147Seric continue; 712147Seric } 722147Seric ilist = p; 732147Seric break; 742147Seric case 'x': 752147Seric if (!p[0]) { 762147Seric argv[i] = 0; 772147Seric continue; 782147Seric } 792147Seric elist = p; 802147Seric break; 812147Seric case 'b': 822147Seric case 'g': 832147Seric case 'e': 842147Seric case 'p': 852147Seric case 'k': 862147Seric case 'm': 872147Seric case 'n': 882147Seric case 's': 892147Seric case 't': 902147Seric testmore++; 912147Seric break; 922147Seric default: 932147Seric fatal("unknown key letter (cm1)"); 942147Seric } 952147Seric 962147Seric if (testmore) { 972147Seric testmore = 0; 9833423Sbostic if (*p) { 9933423Sbostic sprintf(Error,"value after %c arg (cm8)",c); 10033423Sbostic fatal(Error); 10133423Sbostic } 1022147Seric } 1032147Seric if (had[c - 'a']++) 1042147Seric fatal("key letter twice (cm2)"); 1052147Seric argv[i] = 0; 1062147Seric } 1072147Seric else num_files++; 1082147Seric 1092147Seric if(num_files == 0) 1102147Seric fatal("missing file arg (cm3)"); 1112147Seric if (HADE && HADM) 1122147Seric fatal("e not allowed with m (ge3)"); 1132147Seric if (HADE || HADI || HADX) 1142147Seric HADK = 1; 1152147Seric if (!HADS) 1162147Seric verbosity = -1; 1172147Seric setsig(); 11830498Slepreau Fflags &= ~FTLEXIT; 11930498Slepreau Fflags |= FTLJMP; 1202147Seric for (i=1; i<argc; i++) 1212147Seric if (p=argv[i]) 1222147Seric do_file(p,get); 1232147Seric exit(Fcnt ? 1 : 0); 1242147Seric } 1252147Seric 1262147Seric 1272147Seric get(file) 1282147Seric { 1292147Seric register char *p; 1302147Seric register unsigned ser; 1312147Seric extern char had_dir, had_standinp; 1322147Seric extern char *Sflags[]; 1332147Seric struct stats stats; 1342147Seric char str[32]; 1352147Seric 1362147Seric if (setjmp(Fjmp)) 1372147Seric return; 1382147Seric sinit(&gpkt,file,1); 1392147Seric gpkt.p_ixuser = (HADI | HADX); 1402147Seric gpkt.p_reqsid.s_rel = sid.s_rel; 1412147Seric gpkt.p_reqsid.s_lev = sid.s_lev; 1422147Seric gpkt.p_reqsid.s_br = sid.s_br; 1432147Seric gpkt.p_reqsid.s_seq = sid.s_seq; 1442147Seric gpkt.p_verbose = verbosity; 1452147Seric gpkt.p_stdout = (HADP ? stderr : stdout); 1462147Seric gpkt.p_cutoff = cutoff; 1472147Seric gpkt.p_lfile = lfile; 1482147Seric copy(auxf(gpkt.p_file,'g'),Gfile); 1492147Seric 1502147Seric if (gpkt.p_verbose && (num_files > 1 || had_dir || had_standinp)) 1512147Seric fprintf(gpkt.p_stdout,"\n%s:\n",gpkt.p_file); 1522147Seric if (dodelt(&gpkt,&stats,0,0) == 0) 1532147Seric fmterr(&gpkt); 1542147Seric finduser(&gpkt); 1552147Seric doflags(&gpkt); 1562147Seric if (!HADA) 1572147Seric ser = getser(&gpkt); 1582147Seric else { 1592147Seric if ((ser = Ser) > maxser(&gpkt)) 1602147Seric fatal("serial number too large (ge19)"); 16119942Ssam bcopy(&gpkt.p_idel[ser].i_sid, &gpkt.p_gotsid, sizeof(sid)); 1622147Seric if (HADR && sid.s_rel != gpkt.p_gotsid.s_rel) { 16319942Ssam bzero(&gpkt.p_reqsid, sizeof(gpkt.p_reqsid)); 1642147Seric gpkt.p_reqsid.s_rel = sid.s_rel; 1652147Seric } 1662147Seric else 16719942Ssam bcopy(&gpkt.p_gotsid, &gpkt.p_reqsid, sizeof(sid)); 1682147Seric } 1692147Seric doie(&gpkt,ilist,elist,0); 1702147Seric setup(&gpkt,ser); 1712147Seric if (!(Type = Sflags[TYPEFLAG - 'a'])) 1722147Seric Type = Null; 17333423Sbostic if (!(HADP || HADG) && writable(Gfile)) { 17433423Sbostic sprintf(Error,"writable `%s' exists (ge4)",Gfile); 17533423Sbostic fatal(Error); 17633423Sbostic } 1772147Seric if (gpkt.p_verbose) { 1782147Seric sid_ba(&gpkt.p_gotsid,str); 1792147Seric fprintf(gpkt.p_stdout,"%s\n",str); 1802147Seric } 1812147Seric if (HADE) { 1822147Seric if (!HADR) 18319942Ssam bcopy(&gpkt.p_gotsid,&gpkt.p_reqsid, 1842147Seric sizeof(gpkt.p_reqsid)); 1852147Seric newsid(&gpkt,Sflags[BRCHFLAG - 'a'] && HADB); 1862147Seric permiss(&gpkt); 1872147Seric wrtpfile(&gpkt,ilist,elist); 1882147Seric } 1892147Seric setuid(getuid()); 1902147Seric if (HADL) 1912147Seric gen_lfile(&gpkt); 1922147Seric if (HADG) { 1932147Seric fclose(gpkt.p_iop); 1942147Seric xfreeall(); 1952147Seric return; 1962147Seric } 1972147Seric flushto(&gpkt,EUSERTXT,1); 1982147Seric idsetup(&gpkt); 1992147Seric gpkt.p_chkeof = 1; 2002147Seric Did_id = 0; 2012147Seric while(readmod(&gpkt)) { 2022147Seric if (gpkt.p_gout == 0) { 2032147Seric if (HADP) 2042147Seric gpkt.p_gout = stdout; 2052147Seric else 2062539Seric gpkt.p_gout = xfcreat(Gfile,HADK ? 0666 : 0444); 2072147Seric } 20816514Smckusick if (HADN) 20916514Smckusick fprintf(gpkt.p_gout,"%s\t",Mod); 21016514Smckusick if (HADM) { 21116514Smckusick sid_ba(&gpkt.p_inssid,str); 21216514Smckusick fprintf(gpkt.p_gout,"%s\t",str); 21316514Smckusick } 21416514Smckusick p = gpkt.p_line; 21516514Smckusick if (!HADK && any('%',p)) 21616514Smckusick p = idsubst(&gpkt,p); 2172147Seric fputs(p,gpkt.p_gout); 2182147Seric } 2192147Seric fflush(gpkt.p_gout); 2202147Seric if (gpkt.p_gout && gpkt.p_gout != stdout) 2212147Seric fclose(gpkt.p_gout); 2222147Seric if (gpkt.p_verbose) 2232147Seric fprintf(gpkt.p_stdout,"%u lines\n",gpkt.p_glnno); 2242147Seric if (!Did_id && !HADK) 2252147Seric if (Sflags[IDFLAG - 'a']) 2262147Seric fatal("no id keywords (cm6)"); 2272147Seric else if (gpkt.p_verbose) 2282147Seric fprintf(stderr,"No id keywords (cm7)\n"); 2292147Seric xfreeall(); 2302147Seric } 2312147Seric 2322448Seric writable(fn) 2332448Seric char *fn; 2342448Seric { 2352448Seric struct stat s; 2362147Seric 2372448Seric return (stat(fn, &s) >= 0 && (s.st_mode & 0222) != 0); 2382448Seric } 2392448Seric 2402448Seric 2412147Seric newsid(pkt,branch) 2422147Seric register struct packet *pkt; 2432147Seric int branch; 2442147Seric { 2452147Seric int chkbr; 2462147Seric 2472147Seric chkbr = 0; 2482147Seric if (pkt->p_reqsid.s_br == 0) { 24930498Slepreau pkt->p_reqsid.s_lev += 1; 2502147Seric if (sidtoser(&pkt->p_reqsid,pkt) || 2512147Seric pkt->p_maxr > pkt->p_reqsid.s_rel || branch) { 2522147Seric pkt->p_reqsid.s_rel = pkt->p_gotsid.s_rel; 2532147Seric pkt->p_reqsid.s_lev = pkt->p_gotsid.s_lev; 2542147Seric pkt->p_reqsid.s_br = pkt->p_gotsid.s_br + 1; 2552147Seric pkt->p_reqsid.s_seq = 1; 2562147Seric chkbr++; 2572147Seric } 2582147Seric } 2592147Seric else if (pkt->p_reqsid.s_seq == 0 && !branch) 2602147Seric pkt->p_reqsid.s_seq = pkt->p_gotsid.s_seq + 1; 2612147Seric else { 26230498Slepreau pkt->p_reqsid.s_seq += 1; 2632147Seric if (branch || sidtoser(&pkt->p_reqsid,pkt)) { 26430498Slepreau pkt->p_reqsid.s_br += 1; 2652147Seric pkt->p_reqsid.s_seq = 1; 2662147Seric chkbr++; 2672147Seric } 2682147Seric } 2692147Seric if (chkbr) 2702147Seric while (sidtoser(&pkt->p_reqsid,pkt)) 27130498Slepreau pkt->p_reqsid.s_br += 1; 2722147Seric if (sidtoser(&pkt->p_reqsid,pkt)) 2732147Seric fatal("internal error in newsid()"); 2742147Seric } 2752147Seric 2762147Seric 2772147Seric enter(pkt,ch,n,sidp) 2782147Seric struct packet *pkt; 2792147Seric char ch; 2802147Seric int n; 2812147Seric struct sid *sidp; 2822147Seric { 2832147Seric char str[32]; 2842147Seric register struct apply *ap; 2852147Seric 2862147Seric sid_ba(sidp,str); 2872147Seric if (pkt->p_verbose) 2882147Seric fprintf(pkt->p_stdout,"%s\n",str); 2892147Seric ap = &pkt->p_apply[n]; 2902147Seric switch(ap->a_code) { 2912147Seric 2922147Seric case EMPTY: 2932147Seric if (ch == INCLUDE) 2942147Seric condset(ap,APPLY,INCLUSER); 2952147Seric else 2962147Seric condset(ap,NOAPPLY,EXCLUSER); 2972147Seric break; 2982147Seric case APPLY: 2992147Seric sid_ba(sidp,str); 30033423Sbostic sprintf(Error,"%s already included (ge9)",str); 30133423Sbostic fatal(Error); 3022147Seric break; 3032147Seric case NOAPPLY: 3042147Seric sid_ba(sidp,str); 30533423Sbostic sprintf(Error,"%s already excluded (ge10)",str); 30633423Sbostic fatal(Error); 3072147Seric break; 3082147Seric default: 3092147Seric fatal("internal error in get/enter() (ge11)"); 3102147Seric break; 3112147Seric } 3122147Seric } 3132147Seric 3142147Seric 3152147Seric gen_lfile(pkt) 3162147Seric register struct packet *pkt; 3172147Seric { 3182147Seric int n; 3192147Seric int reason; 3202147Seric char str[32]; 3212147Seric char line[BUFSIZ]; 3222147Seric struct deltab dt; 3232147Seric FILE *in; 3242147Seric FILE *out; 3252147Seric 3262147Seric in = xfopen(pkt->p_file,0); 3272147Seric if (*pkt->p_lfile) 3282147Seric out = stdout; 3292147Seric else 3302147Seric out = xfcreat(auxf(pkt->p_file,'l'),0444); 3312147Seric fgets(line,sizeof(line),in); 3322147Seric while (fgets(line,sizeof(line),in) != NULL && line[0] == CTLCHAR && line[1] == STATS) { 3332147Seric fgets(line,sizeof(line),in); 3342147Seric del_ab(line,&dt); 3352147Seric if (dt.d_type == 'D') { 3362147Seric reason = pkt->p_apply[dt.d_serial].a_reason; 3372147Seric if (pkt->p_apply[dt.d_serial].a_code == APPLY) { 3382147Seric putc(' ',out); 3392147Seric putc(' ',out); 3402147Seric } 3412147Seric else { 3422147Seric putc('*',out); 3432147Seric if (reason & IGNR) 3442147Seric putc(' ',out); 3452147Seric else 3462147Seric putc('*',out); 3472147Seric } 3482147Seric switch (reason & (INCL | EXCL | CUTOFF)) { 3492147Seric 3502147Seric case INCL: 3512147Seric putc('I',out); 3522147Seric break; 3532147Seric case EXCL: 3542147Seric putc('X',out); 3552147Seric break; 3562147Seric case CUTOFF: 3572147Seric putc('C',out); 3582147Seric break; 3592147Seric default: 3602147Seric putc(' ',out); 3612147Seric break; 3622147Seric } 3632147Seric putc(' ',out); 3642147Seric sid_ba(&dt.d_sid,str); 3652147Seric fprintf(out,"%s\t",str); 3662147Seric date_ba(&dt.d_datetime,str); 3672147Seric fprintf(out,"%s %s\n",str,dt.d_pgmr); 3682147Seric } 3692147Seric while ((n = fgets(line,sizeof(line),in)) != NULL) 3702147Seric if (line[0] != CTLCHAR) 3712147Seric break; 3722147Seric else { 3732147Seric switch (line[1]) { 3742147Seric 3752147Seric case EDELTAB: 3762147Seric break; 3772147Seric default: 3782147Seric continue; 3792147Seric case MRNUM: 3802147Seric case COMMENTS: 3812147Seric if (dt.d_type == 'D') 3822147Seric fprintf(out,"\t%s",&line[3]); 3832147Seric continue; 3842147Seric } 3852147Seric break; 3862147Seric } 3872147Seric if (n == NULL || line[0] != CTLCHAR) 3882147Seric break; 3892147Seric putc('\n',out); 3902147Seric } 3912147Seric fclose(in); 3922147Seric if (out != stdout) 3932147Seric fclose(out); 3942147Seric } 3952147Seric 3962147Seric char Curdate[18]; 3972147Seric char *Curtime; 3982147Seric char Gdate[9]; 3992147Seric char Chgdate[18]; 4002147Seric char *Chgtime; 4012147Seric char Gchgdate[9]; 40219942Ssam char Qchgdate[30]; 4032147Seric char Sid[32]; 40419942Ssam char Olddir[MAXPATHLEN+1]; 40519942Ssam char Pname[MAXPATHLEN+1]; 40619942Ssam char Dir[MAXPATHLEN+1]; 4072147Seric 4082147Seric idsetup(pkt) 4092147Seric register struct packet *pkt; 4102147Seric { 4112147Seric extern long Timenow; 4122147Seric register int n; 4132147Seric register char *p; 4142147Seric 4152147Seric date_ba(&Timenow,Curdate); 4162147Seric Curtime = &Curdate[9]; 4172147Seric Curdate[8] = 0; 4182147Seric copy(pkt->p_file,Dir); 4192147Seric dname(Dir); 42019942Ssam if(getwd(Olddir) == 0) 42119942Ssam fatal("getwd failed (ge20)"); 4222147Seric if(chdir(Dir) != 0) 4232147Seric fatal("cannot change directory (ge22)"); 42419942Ssam if(getwd(Pname) == 0) 42519942Ssam fatal("getwd failed (ge21)"); 4262147Seric if(chdir(Olddir) != 0) 4272147Seric fatal("cannot change directory (ge23)"); 4282147Seric makgdate(Curdate,Gdate); 4292147Seric for (n = maxser(pkt); n; n--) 4302147Seric if (pkt->p_apply[n].a_code == APPLY) 4312147Seric break; 4322147Seric if (n) 4332147Seric date_ba(&pkt->p_idel[n].i_datetime,Chgdate); 4342147Seric Chgtime = &Chgdate[9]; 4352147Seric Chgdate[8] = 0; 4362147Seric makgdate(Chgdate,Gchgdate); 43719942Ssam makqdate(Gchgdate,Qchgdate); 4382147Seric sid_ba(&pkt->p_gotsid,Sid); 4392147Seric if (p = Sflags[MODFLAG - 'a']) 4402147Seric copy(p,Mod); 4412147Seric else 4422147Seric copy(Gfile,Mod); 4432147Seric } 4442147Seric 4452147Seric 4462147Seric makgdate(old,new) 4472147Seric register char *old, *new; 4482147Seric { 4492147Seric if ((*new = old[3]) != '0') 4502147Seric new++; 4512147Seric *new++ = old[4]; 4522147Seric *new++ = '/'; 4532147Seric if ((*new = old[6]) != '0') 4542147Seric new++; 4552147Seric *new++ = old[7]; 4562147Seric *new++ = '/'; 4572147Seric *new++ = old[0]; 4582147Seric *new++ = old[1]; 4592147Seric *new = 0; 4602147Seric } 4612147Seric 46219942Ssam makqdate(old,new) 46319942Ssam register char *old, *new; 46419942Ssam { 46519942Ssam static char *months[12] = 46619942Ssam { "January", "February", "March", "April", "May", "June", "July", 46719942Ssam "August", "September", "October", "November", "December" }; 4682147Seric 46919942Ssam strcpy(new, months[atoi(old)-1]); 47019942Ssam while (*new != '\0') 47119942Ssam new++; 47219942Ssam while (*old++ != '/') 47319942Ssam ; 47419942Ssam *new++ = ' '; 47519942Ssam *new++ = *old++; 47619942Ssam if (*old != '/') 47719942Ssam *new++ = *old++; 47819942Ssam *new++ = ','; 47919942Ssam *new++ = ' '; 48019942Ssam *new++ = '1'; *new++ = '9'; /* works for this century at least */ 48119942Ssam *new++ = *++old; 48219942Ssam *new++ = *++old; 48319942Ssam *new = '\0'; 48419942Ssam } 48519942Ssam 48630498Slepreau static char Zkeywd[5] = "@(#)"; 4872147Seric 48819942Ssam 4892147Seric idsubst(pkt,line) 4902147Seric register struct packet *pkt; 4912147Seric char line[]; 4922147Seric { 4932147Seric static char tline[BUFSIZ]; 4942147Seric static char str[32]; 495*40849Sbostic register char *lp, *tp, *p; 4962147Seric extern char *Type; 4972147Seric extern char *Sflags[]; 4982147Seric 4992147Seric tp = tline; 5002147Seric for(lp=line; *lp != 0; lp++) { 501*40849Sbostic if (lp[0] != '%' || !lp[1] || !lp[2]) { 502*40849Sbostic *tp++ = *lp; 503*40849Sbostic continue; 504*40849Sbostic } 505*40849Sbostic if (lp[2] == '%') { 5062147Seric switch(*++lp) { 5072147Seric case 'M': 5082147Seric tp = trans(tp,Mod); 5092147Seric break; 5102147Seric case 'R': 5112147Seric sprintf(str,"%u",pkt->p_gotsid.s_rel); 5122147Seric tp = trans(tp,str); 5132147Seric break; 5142147Seric case 'L': 5152147Seric sprintf(str,"%u",pkt->p_gotsid.s_lev); 5162147Seric tp = trans(tp,str); 5172147Seric break; 5182147Seric case 'B': 5192147Seric sprintf(str,"%u",pkt->p_gotsid.s_br); 5202147Seric tp = trans(tp,str); 5212147Seric break; 5222147Seric case 'S': 5232147Seric sprintf(str,"%u",pkt->p_gotsid.s_seq); 5242147Seric tp = trans(tp,str); 5252147Seric break; 5262147Seric case 'D': 5272147Seric tp = trans(tp,Curdate); 5282147Seric break; 5292147Seric case 'H': 5302147Seric tp = trans(tp,Gdate); 5312147Seric break; 5322147Seric case 'T': 5332147Seric tp = trans(tp,Curtime); 5342147Seric break; 5352147Seric case 'E': 5362147Seric tp = trans(tp,Chgdate); 5372147Seric break; 5382147Seric case 'G': 5392147Seric tp = trans(tp,Gchgdate); 5402147Seric break; 54119942Ssam case 'Q': 54219942Ssam tp = trans(tp,Qchgdate); 54319942Ssam break; 5442147Seric case 'U': 5452147Seric tp = trans(tp,Chgtime); 5462147Seric break; 5472147Seric case 'Z': 5482147Seric tp = trans(tp,Zkeywd); 5492147Seric break; 5502147Seric case 'Y': 5512147Seric tp = trans(tp,Type); 5522147Seric break; 5532147Seric case 'W': 5542147Seric tp = trans(tp,Zkeywd); 5552147Seric tp = trans(tp,Mod); 5562147Seric *tp++ = '\t'; 5572147Seric case 'I': 5582147Seric tp = trans(tp,Sid); 5592147Seric break; 5602147Seric case 'P': 5612147Seric tp = trans(tp,Pname); 5622147Seric *tp++ = '/'; 5632147Seric tp = trans(tp,(sname(pkt->p_file))); 5642147Seric break; 5652147Seric case 'F': 5662147Seric tp = trans(tp,pkt->p_file); 5672147Seric break; 5682147Seric case 'C': 5692147Seric sprintf(str,"%u",pkt->p_glnno); 5702147Seric tp = trans(tp,str); 5712147Seric break; 5722147Seric case 'A': 5732147Seric tp = trans(tp,Zkeywd); 5742147Seric tp = trans(tp,Type); 5752147Seric *tp++ = ' '; 5762147Seric tp = trans(tp,Mod); 5772147Seric *tp++ = ' '; 5782147Seric tp = trans(tp,Sid); 5792147Seric tp = trans(tp,Zkeywd); 5802147Seric break; 5812147Seric default: 5822147Seric *tp++ = '%'; 5832147Seric *tp++ = *lp; 5842147Seric continue; 5852147Seric } 5862147Seric lp++; 587*40849Sbostic continue; 5882147Seric } 589*40849Sbostic if (!strncmp(lp, "%sccs.include.", 14)) { 590*40849Sbostic for (p = lp + 14; *p && *p != '%'; ++p); 591*40849Sbostic if (*p != '%') 592*40849Sbostic *tp++ = '%'; 593*40849Sbostic else { 594*40849Sbostic *p = '\0'; 595*40849Sbostic tp = readcopy(lp + 14, tp); 596*40849Sbostic lp = p + 1; 597*40849Sbostic } 598*40849Sbostic } 5992147Seric } 6002147Seric 6012147Seric *tp = 0; 6022147Seric return(tline); 6032147Seric } 6042147Seric 6052147Seric 6062147Seric trans(tp,str) 6072147Seric register char *tp, *str; 6082147Seric { 6092147Seric Did_id = 1; 6102147Seric while(*tp++ = *str++) 6112147Seric ; 6122147Seric return(tp-1); 6132147Seric } 6142147Seric 615*40849Sbostic readcopy(name, tp) 616*40849Sbostic register char *name; 617*40849Sbostic register char *tp; 618*40849Sbostic { 619*40849Sbostic register FILE *fp; 620*40849Sbostic register int ch; 621*40849Sbostic char path[MAXPATHLEN]; 6222147Seric 623*40849Sbostic (void)sprintf(path, "%s/%s", _PATH_SCCSINCLUDE, name); 624*40849Sbostic if (!(fp = fopen(path, "r"))) { 625*40849Sbostic (void)sprintf(Error,"can't read %s", path); 626*40849Sbostic fatal(Error); 627*40849Sbostic } 628*40849Sbostic while ((ch = getc(fp)) != EOF) 629*40849Sbostic *tp++ = ch; 630*40849Sbostic (void)fclose(fp); 631*40849Sbostic return(tp); 632*40849Sbostic } 633*40849Sbostic 6342147Seric clean_up(n) 6352147Seric { 6362147Seric if (gpkt.p_file[0]) 6372147Seric unlockit(auxf(gpkt.p_file,'z'),getpid()); 6382147Seric if (gpkt.p_iop) 6392147Seric fclose(gpkt.p_iop); 6402147Seric xfreeall(); 6412147Seric } 6422147Seric 6432147Seric 6442147Seric wrtpfile(pkt,inc,exc) 6452147Seric register struct packet *pkt; 6462147Seric char *inc, *exc; 6472147Seric { 6482147Seric char line[64], str1[32], str2[32]; 6492147Seric char *user; 6502147Seric FILE *in, *out; 6512147Seric struct pfile pf; 6522147Seric register char *p; 6532147Seric int fd; 6542147Seric int i; 6552147Seric extern long Timenow; 6562147Seric 6572147Seric user = logname(); 6582147Seric if (lockit(auxf(pkt->p_file,'z'),2,getpid())) 6592147Seric fatal("cannot create lock file (cm4)"); 6602147Seric if (exists(p = auxf(pkt->p_file,'p'))) { 6612147Seric fd = xopen(p,2); 66219942Ssam in = fdopen(fd,"r"); 6632147Seric while (fgets(line,sizeof(line),in) != NULL) { 6642147Seric p = line; 6652147Seric p[length(p) - 1] = 0; 6662147Seric pf_ab(p,&pf,0); 6672147Seric if ((pf.pf_gsid.s_rel == pkt->p_gotsid.s_rel && 6682147Seric pf.pf_gsid.s_lev == pkt->p_gotsid.s_lev && 6692147Seric pf.pf_gsid.s_br == pkt->p_gotsid.s_br && 6702147Seric pf.pf_gsid.s_seq == pkt->p_gotsid.s_seq) || 6712147Seric (pf.pf_nsid.s_rel == pkt->p_reqsid.s_rel && 6722147Seric pf.pf_nsid.s_lev == pkt->p_reqsid.s_lev && 6732147Seric pf.pf_nsid.s_br == pkt->p_reqsid.s_br && 6742147Seric pf.pf_nsid.s_seq == pkt->p_reqsid.s_seq)) { 6752147Seric fclose(in); 67633423Sbostic sprintf(Error,"being edited: `%s' (ge17)",line); 67733423Sbostic fatal(Error); 6782147Seric } 6792147Seric if (!equal(pf.pf_user,user)) 6802147Seric fprintf(stderr,"WARNING: being edited: `%s' (ge18)\n",line); 6812147Seric } 68219942Ssam out = fdopen(dup(fd),"w"); 6832147Seric fclose(in); 6842147Seric } 6852147Seric else 6862539Seric out = xfcreat(p,0666); 6872147Seric fseek(out,0L,2); 6882147Seric sid_ba(&pkt->p_gotsid,str1); 6892147Seric sid_ba(&pkt->p_reqsid,str2); 6902147Seric date_ba(&Timenow,line); 6912147Seric fprintf(out,"%s %s %s %s",str1,str2,user,line); 6922147Seric if (inc) 6932147Seric fprintf(out," -i%s",inc); 6942147Seric if (exc) 6952147Seric fprintf(out," -x%s",exc); 6962147Seric fprintf(out,"\n"); 6972147Seric fclose(out); 6982147Seric if (pkt->p_verbose) 6992147Seric fprintf(pkt->p_stdout,"new delta %s\n",str2); 7002147Seric unlockit(auxf(pkt->p_file,'z'),getpid()); 7012147Seric } 7022147Seric 7032147Seric 7042147Seric getser(pkt) 7052147Seric register struct packet *pkt; 7062147Seric { 7072147Seric register struct idel *rdp; 7082147Seric int n, ser, def; 7092147Seric char *p; 7102147Seric extern char *Sflags[]; 7112147Seric 7122147Seric def = 0; 7132147Seric if (pkt->p_reqsid.s_rel == 0) { 7142147Seric if (p = Sflags[DEFTFLAG - 'a']) 7152147Seric chksid(sid_ab(p, &pkt->p_reqsid), &pkt->p_reqsid); 7162147Seric else { 7172147Seric pkt->p_reqsid.s_rel = MAX; 7182147Seric def = 1; 7192147Seric } 7202147Seric } 7212147Seric ser = 0; 7222147Seric if (pkt->p_reqsid.s_lev == 0) { 7232147Seric for (n = maxser(pkt); n; n--) { 7242147Seric rdp = &pkt->p_idel[n]; 7252147Seric if ((rdp->i_sid.s_br == 0 || HADT) && 7262147Seric pkt->p_reqsid.s_rel >= rdp->i_sid.s_rel && 7272147Seric rdp->i_sid.s_rel > pkt->p_gotsid.s_rel) { 7282147Seric ser = n; 7292147Seric pkt->p_gotsid.s_rel = rdp->i_sid.s_rel; 7302147Seric } 7312147Seric } 7322147Seric } 7332147Seric else if (pkt->p_reqsid.s_br && pkt->p_reqsid.s_seq == 0) { 7342147Seric for (n = maxser(pkt); n; n--) { 7352147Seric rdp = &pkt->p_idel[n]; 7362147Seric if (rdp->i_sid.s_rel == pkt->p_reqsid.s_rel && 7372147Seric rdp->i_sid.s_lev == pkt->p_reqsid.s_lev && 7382147Seric rdp->i_sid.s_br == pkt->p_reqsid.s_br) 7392147Seric break; 7402147Seric } 7412147Seric ser = n; 7422147Seric } 7432147Seric else { 7442147Seric ser = sidtoser(&pkt->p_reqsid,pkt); 7452147Seric } 7462147Seric if (ser == 0) 7472147Seric fatal("nonexistent sid (ge5)"); 7482147Seric rdp = &pkt->p_idel[ser]; 74919942Ssam bcopy(&rdp->i_sid, &pkt->p_gotsid, sizeof(pkt->p_gotsid)); 7502147Seric if (def || (pkt->p_reqsid.s_lev == 0 && pkt->p_reqsid.s_rel == pkt->p_gotsid.s_rel)) 75119942Ssam bcopy(&pkt->p_gotsid, &pkt->p_reqsid, sizeof(pkt->p_gotsid)); 7522147Seric return(ser); 7532147Seric } 7542147Seric 7552147Seric 7562147Seric /* Null routine to satisfy external reference from dodelt() */ 7572147Seric 7582147Seric escdodelt() 7592147Seric { 7602147Seric } 761