1 # include "../hdr/defines.h" 2 # include "../hdr/had.h" 3 4 static char Sccsid[] = "@(#)comb.c 4.4 02/02/88"; 5 USXALLOC(); 6 7 struct packet gpkt; 8 struct sid sid; 9 int num_files; 10 char had[26]; 11 char *clist; 12 int *Cvec; 13 int Cnt; 14 FILE *iop; 15 16 main(argc,argv) 17 int argc; 18 register char *argv[]; 19 { 20 register int i; 21 register char *p; 22 char c; 23 int testmore; 24 extern comb(); 25 extern int Fcnt; 26 27 Fflags = FTLEXIT | FTLMSG | FTLCLN; 28 for(i = 1; i < argc; i++) 29 if(argv[i][0] == '-' && (c=argv[i][1])) { 30 p = &argv[i][2]; 31 testmore = 0; 32 switch (c) { 33 34 case 'p': 35 if (!p[0]) { 36 argv[i] = 0; 37 continue; 38 } 39 chksid(sid_ab(p,&sid),&sid); 40 break; 41 case 'c': 42 clist = p; 43 break; 44 case 'o': 45 testmore++; 46 break; 47 case 's': 48 testmore++; 49 break; 50 default: 51 fatal("unknown key letter (cm1)"); 52 } 53 54 if (testmore) { 55 testmore = 0; 56 if (*p) { 57 sprintf(Error, "value after %c arg (cm7)",c); 58 fatal(Error); 59 } 60 } 61 if (had[c - 'a']++) 62 fatal("key letter twice (cm2)"); 63 argv[i] = 0; 64 } 65 else num_files++; 66 67 if(num_files == 0) 68 fatal("missing file arg (cm3)"); 69 if (HADP && HADC) 70 fatal("can't have both -p and -c (cb2)"); 71 setsig(); 72 Fflags &= ~FTLEXIT; 73 Fflags |= FTLJMP; 74 iop = stdout; 75 for (i = 1; i < argc; i++) 76 if (p=argv[i]) 77 do_file(p,comb); 78 fclose(iop); 79 exit(Fcnt ? 1 : 0); 80 } 81 82 83 comb(file) 84 { 85 register int i, n; 86 register struct idel *rdp; 87 char *p; 88 int succnt; 89 struct sid *sp; 90 extern char had_dir, had_standinp; 91 extern char *Sflags[]; 92 struct stats stats; 93 94 if (setjmp(Fjmp)) 95 return; 96 sinit(&gpkt, file, 1); 97 gpkt.p_verbose = -1; 98 gpkt.p_stdout = stderr; 99 if (gpkt.p_verbose && (num_files > 1 || had_dir || had_standinp)) 100 fprintf(gpkt.p_stdout,"\n%s:\n",gpkt.p_file); 101 if (exists(auxf(gpkt.p_file, 'p'))) 102 fatal("p-file exists (cb1)"); 103 104 if (dodelt(&gpkt,&stats,0,0) == 0) 105 fmterr(&gpkt); 106 107 Cvec = alloc(n = ((maxser(&gpkt) + 1) * sizeof(*Cvec))); 108 bzero(Cvec, n); 109 Cnt = 0; 110 111 if (HADP) { 112 if (!(n = sidtoser(&sid, &gpkt))) 113 fatal("sid doesn't exist (cb3)"); 114 while (n <= maxser(&gpkt)) 115 Cvec[Cnt++] = n++; 116 } 117 else if (HADC) { 118 dolist(&gpkt, clist, 0); 119 } 120 else { 121 rdp = gpkt.p_idel; 122 for (i = 1; i <= maxser(&gpkt); i++) { 123 succnt = 0; 124 for (n = i + 1; n <= maxser(&gpkt); n++) 125 if (rdp[n].i_pred == i) 126 succnt++; 127 if (succnt != 1) 128 Cvec[Cnt++] = i; 129 } 130 } 131 finduser(&gpkt); 132 doflags(&gpkt); 133 fclose(gpkt.p_iop); 134 gpkt.p_iop = 0; 135 if (!Cnt) 136 fatal("nothing to do (cb4)"); 137 rdp = gpkt.p_idel; 138 sp = prtget(rdp, Cvec[0], iop, gpkt.p_file); 139 fprintf(iop, "admin -iCOMB -r%d s.COMB\n", sp->s_rel); 140 fprintf(iop, "rm -f COMB\n"); 141 for (i = 1; i < Cnt; i++) { 142 n = getpred(rdp, Cvec, i); 143 if (HADO) 144 fprintf(iop, "get -s -r%d -g -e -t s.COMB\n", 145 rdp[Cvec[i]].i_sid.s_rel); 146 else 147 fprintf(iop, "get -s -a%d -r%d -g -e s.COMB\n", 148 n + 1, rdp[Cvec[i]].i_sid.s_rel); 149 prtget(rdp, Cvec[i], iop, gpkt.p_file); 150 fprintf(iop, "delta -s '-yThis was COMBined' s.COMB\n"); 151 } 152 fprintf(iop, "sed -n '/^%c%c$/,/^%c%c$/p' %s >comb${pid}\n", 153 CTLCHAR, BUSERTXT, CTLCHAR, EUSERTXT, gpkt.p_file); 154 fprintf(iop, "ed - comb${pid} <<\\!\n"); 155 fprintf(iop, "1d\n"); 156 fprintf(iop, "$c\n"); 157 fprintf(iop, " *** DELTA TABLE PRIOR TO COMBINE ***\n"); 158 fprintf(iop, ".\n"); 159 fprintf(iop, "w\n"); 160 fprintf(iop, "q\n"); 161 fprintf(iop, "!\n"); 162 fprintf(iop, "prt -a %s >>comb${pid}\n", gpkt.p_file); 163 fprintf(iop, "admin -tcomb${pid} s.COMB\\\n"); 164 for (i = 0; i < NFLAGS; i++) 165 if (p = Sflags[i]) 166 fprintf(iop, " -f%c%s\\\n", i + 'a', p); 167 fprintf(iop, "\n"); 168 fprintf(iop, "sed -n '/^%c%c$/,/^%c%c$/p' %s >comb${pid}\n", 169 CTLCHAR, BUSERNAM, CTLCHAR, EUSERNAM, gpkt.p_file); 170 fprintf(iop, "ed - comb${pid} <<\\!\n"); 171 fprintf(iop, "v/^%c/s/.*/-a& \\\\/\n", CTLCHAR); 172 fprintf(iop, "1c\n"); 173 fprintf(iop, "admin s.COMB\\\n"); 174 fprintf(iop, ".\n"); 175 fprintf(iop, "$c\n"); 176 fprintf(iop, "\n"); 177 fprintf(iop, ".\n"); 178 fprintf(iop, "w\n"); 179 fprintf(iop, "q\n"); 180 fprintf(iop, "!\n"); 181 fprintf(iop, "sh comb${pid}\n"); 182 fprintf(iop, "rm comb${pid}\n"); 183 if (!HADS) { 184 fprintf(iop, "rm -f %s\n", gpkt.p_file); 185 fprintf(iop, "mv s.COMB %s\n", gpkt.p_file); 186 } 187 else { 188 fprintf(iop, "set a=`echo \\`ls -s s.COMB\\``\n"); 189 fprintf(iop, "set b=`echo \\`ls -s %s\\``\n",gpkt.p_file); 190 fprintf(iop, "set c=`expr 100 - 100 '*' ${a} / ${b}`\n"); 191 fprintf(iop, "echo '%s\t' ${c}'%%\t' ${a}/${b}\n", gpkt.p_file); 192 fprintf(iop, "rm -f s.COMB\n"); 193 } 194 } 195 196 197 enter(pkt,ch,n,sidp) 198 struct packet *pkt; 199 char ch; 200 int n; 201 struct sid *sidp; 202 { 203 Cvec[Cnt++] = n; 204 } 205 206 207 prtget(idp, ser, iop, file) 208 struct idel *idp; 209 int ser; 210 FILE *iop; 211 char *file; 212 { 213 char buf[32]; 214 struct sid *sp; 215 216 sid_ba(sp = &idp[ser].i_sid, buf); 217 fprintf(iop, ":\t/bin/bsh\n"); 218 fprintf(iop, "get -s -k -r%s -p %s > COMB\n", buf, file); 219 return(sp); 220 } 221 222 223 getpred(idp, vec, i) 224 struct idel *idp; 225 int *vec; 226 int i; 227 { 228 int ser, pred, acpred; 229 230 ser = vec[i]; 231 while (--i) { 232 pred = vec[i]; 233 for (acpred = idp[ser].i_pred; acpred; acpred = idp[acpred].i_pred) 234 if (pred == acpred) 235 break; 236 if (pred == acpred) 237 break; 238 } 239 return(i); 240 } 241 242 243 clean_up(n) 244 { 245 xfreeall(); 246 } 247 248 249 escdodelt() /* dummy for dodelt() */ 250 { 251 } 252