| 1 | /* ifmerge.c - Load an inverted file from existing inverted files |
|---|
| 2 | */ |
|---|
| 3 | #include <stdio.h> |
|---|
| 4 | #include <string.h> |
|---|
| 5 | #include "cisis.h" |
|---|
| 6 | #include "ciupi.h" |
|---|
| 7 | #include "cirun.h" |
|---|
| 8 | extern int ifl_balan; /* cisis.h */ |
|---|
| 9 | |
|---|
| 10 | void main(argc,argv) |
|---|
| 11 | int argc; |
|---|
| 12 | char *argv[]; |
|---|
| 13 | { |
|---|
| 14 | char *dbnp=NULL; |
|---|
| 15 | char *vifnamp[MAXIFMRG+1]; |
|---|
| 16 | LONGX vifmfns[MAXIFMRG]; |
|---|
| 17 | int vifxmst[MAXIFMRG]; |
|---|
| 18 | int nifs=0; |
|---|
| 19 | LONGX totmfns=0L; |
|---|
| 20 | int mstxrftag=0; |
|---|
| 21 | int pstflag=IFUPISIS; |
|---|
| 22 | LONGX parmxmfn=0L; |
|---|
| 23 | char *parmlogp=NULL; |
|---|
| 24 | LONGX parmtell=0L; |
|---|
| 25 | int parmtrace=0; |
|---|
| 26 | int argnext=1; |
|---|
| 27 | char *p,*q,*namp; |
|---|
| 28 | |
|---|
| 29 | if (argc < 3) { |
|---|
| 30 | printf("%s",cicopyr("Utility IFMERGE")); |
|---|
| 31 | printf("\n"); |
|---|
| 32 | #if LIND |
|---|
| 33 | printf("ifmerge <out>[,n] <if1>[,n1] <if2>[,n2] [...] [<option> [...]] \n"); |
|---|
| 34 | printf("\n"); |
|---|
| 35 | printf(" <out>[,n] -> output inverted file, maxmfn \n"); |
|---|
| 36 | #else |
|---|
| 37 | printf("ifmerge <out> <if1>[,n1] <if2>[,n2] [...] [<option> [...]] \n"); |
|---|
| 38 | printf("\n"); |
|---|
| 39 | printf(" <out> -> output inverted file \n"); |
|---|
| 40 | #endif |
|---|
| 41 | printf(" <if1>[,n1] -> input inverted file #1, maxmfn#1 \n"); |
|---|
| 42 | printf(" <if2>[,n2] -> input inverted file #2, maxmfn#2 \n"); |
|---|
| 43 | printf(" ... \n"); |
|---|
| 44 | printf("\n"); |
|---|
| 45 | printf("options: \n"); |
|---|
| 46 | printf("\n"); |
|---|
| 47 | printf(" +mstxrf -> create <out> M/F and its mstxrf <out>.pft \n"); |
|---|
| 48 | printf(" -posts -> do not load %s \n",ix1extp); |
|---|
| 49 | printf(" -balan -> do not rebalance the dict \n"); |
|---|
| 50 | #if LIND |
|---|
| 51 | printf(" log=<file> -> log file name \n"); |
|---|
| 52 | #endif |
|---|
| 53 | printf(" tell=<n> -> tell <n> keys has been loaded \n"); |
|---|
| 54 | printf(" \n"); |
|---|
| 55 | exit(1); |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | |
|---|
| 59 | /* get parms */ |
|---|
| 60 | for (; argnext < argc; argnext++) { |
|---|
| 61 | p=argv[argnext]; |
|---|
| 62 | #if LIND |
|---|
| 63 | if (strncmp(p,"log?",4) == 0 || strncmp(p,"log=",4) == 0) { |
|---|
| 64 | parmlogp=p+4; |
|---|
| 65 | if (!*parmlogp) fatal(p); |
|---|
| 66 | continue; |
|---|
| 67 | } |
|---|
| 68 | #endif |
|---|
| 69 | if (strncmp(p,"tell?",5) == 0 || strncmp(p,"tell=",5) == 0) { |
|---|
| 70 | if (sscanf(p+5,"%"_LD_,&parmtell) != 1) fatal(p); |
|---|
| 71 | if (parmtell < 0) fatal(p); |
|---|
| 72 | continue; |
|---|
| 73 | } |
|---|
| 74 | if (strcmp(p,"+mstxrf") == 0) { |
|---|
| 75 | mstxrftag=32701; |
|---|
| 76 | continue; |
|---|
| 77 | } |
|---|
| 78 | if (strcmp(p,"-balan") == 0) { |
|---|
| 79 | ifl_balan=0; |
|---|
| 80 | continue; |
|---|
| 81 | } |
|---|
| 82 | if (strcmp(p,"-posts") == 0) { |
|---|
| 83 | pstflag=IFUPDICT; |
|---|
| 84 | continue; |
|---|
| 85 | } |
|---|
| 86 | if (strcmp(p,"trace") == 0) { |
|---|
| 87 | parmtrace=1; |
|---|
| 88 | continue; |
|---|
| 89 | } |
|---|
| 90 | if (strcmp(p,"trace=all") == 0) { |
|---|
| 91 | parmtrace=1; |
|---|
| 92 | dbxtrace=1; trmtrace=1; |
|---|
| 93 | continue; |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | if (nifs >= MAXIFMRG) fatal("MAXIFMRG overflow"); |
|---|
| 97 | |
|---|
| 98 | q=strchr((namp=p),','); vifxmst[nifs]=0; |
|---|
| 99 | if (q) { |
|---|
| 100 | *q='\0'; |
|---|
| 101 | if (sscanf(q+1,"%"_LD_,&vifmfns[nifs]) != 1) fatal(p); |
|---|
| 102 | if (vifmfns[nifs] < 0) fatal(p); |
|---|
| 103 | } |
|---|
| 104 | else if (dbnp) { |
|---|
| 105 | RECSTRU *recp; |
|---|
| 106 | LONGX irec=nrecs; |
|---|
| 107 | RECORD(irec,namp,0L); |
|---|
| 108 | vifmfns[nifs]=MF0nxtmfn-1; |
|---|
| 109 | vifxmst[nifs]=1; |
|---|
| 110 | FREE(vrecp[irec]); vrecp[irec]=NULL; nrecs--; |
|---|
| 111 | dbxflush(namp); |
|---|
| 112 | } else vifmfns[0]=0; |
|---|
| 113 | |
|---|
| 114 | if (parmtrace || parmtell) |
|---|
| 115 | printf("+++ #%d: %s mfns=%"_LD_"\n",nifs,namp,vifmfns[nifs]); |
|---|
| 116 | |
|---|
| 117 | if (!dbnp) { |
|---|
| 118 | dbnp=namp; |
|---|
| 119 | parmxmfn=vifmfns[0]; |
|---|
| 120 | } |
|---|
| 121 | else { |
|---|
| 122 | totmfns+=vifmfns[nifs]; |
|---|
| 123 | vifnamp[nifs]=namp; |
|---|
| 124 | nifs++; |
|---|
| 125 | } |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| 128 | if (nifs < 1) fatal("no I/F to merge"); |
|---|
| 129 | vifnamp[nifs]=NULL; /* end of list */ |
|---|
| 130 | |
|---|
| 131 | /* setup maxmfn */ |
|---|
| 132 | if (!parmxmfn) parmxmfn=totmfns; |
|---|
| 133 | |
|---|
| 134 | /* should pause */ |
|---|
| 135 | if (parmtrace || parmtell) { |
|---|
| 136 | printf("+++ create=%s \n",dbnp); |
|---|
| 137 | printf("+++ maxmfn=%"_LD_"\n",parmxmfn); |
|---|
| 138 | } |
|---|
| 139 | |
|---|
| 140 | /* create mstxrf M/F and reading .pft */ |
|---|
| 141 | if (mstxrftag) { |
|---|
| 142 | char buffup[BUFSIZ]; |
|---|
| 143 | FILE *fp; |
|---|
| 144 | int xif; |
|---|
| 145 | recisis0(dbnp); |
|---|
| 146 | sprintf(buffup,"%s.pft",dbnp); |
|---|
| 147 | strcpy(buffup,dbxcipar(dbnp,buffup,'=')); |
|---|
| 148 | if ((fp=fopen(buffup,"w")) == NULL) fatal(buffup); |
|---|
| 149 | fprintf(fp,"proc('='f(val(v32701^m),1,0)), \n"); |
|---|
| 150 | fprintf(fp,"proc('R'v32701^*,',',v32701^m), \n"); |
|---|
| 151 | for (xif=0; xif < nifs; xif++) { |
|---|
| 152 | fprintf(fp,"if v32701^*='%s' then @%s.pft, fi, \n",vifnamp[xif],vifnamp[xif]); |
|---|
| 153 | } |
|---|
| 154 | fclose(fp); |
|---|
| 155 | if (totmfns) { |
|---|
| 156 | LONGX outmfn=1; |
|---|
| 157 | LONGX crec,irec; |
|---|
| 158 | record(crec=nrecs,dbnp,0L); |
|---|
| 159 | record(irec=nrecs,dbnp,1L); |
|---|
| 160 | for (xif=0; xif < nifs; xif++) { |
|---|
| 161 | LONGX xmfn=1,xloop; |
|---|
| 162 | LONGX xrec; |
|---|
| 163 | RECSTRU *recp,*xrecp=NULL; |
|---|
| 164 | if (vifxmst[xif]) { |
|---|
| 165 | RECORD(xrec=nrecs,vifnamp[xif],0L); xrecp=recp; |
|---|
| 166 | } |
|---|
| 167 | for (xloop=vifmfns[xif]; xloop--; outmfn++, xmfn++) { |
|---|
| 168 | int xrc=RCNORMAL; |
|---|
| 169 | LONGX xcomb; |
|---|
| 170 | int xcomp; |
|---|
| 171 | if (vifxmst[xif]) xrc=recxref(xrecp,xmfn,&xcomb,&xcomp); |
|---|
| 172 | if (xrc == RCNORMAL) { |
|---|
| 173 | RECORD(irec,dbnp,outmfn); |
|---|
| 174 | RECrc=RCNORMAL; |
|---|
| 175 | MFRstatus=ACTIVE; |
|---|
| 176 | sprintf(buffup,"A%"_LD_"~%s^m%"_LD_"~",(LONGX)mstxrftag,vifnamp[xif],xmfn); |
|---|
| 177 | if (fldupdat(irec,buffup)) fatal("ifmerge/fldupdat"); |
|---|
| 178 | recupdat(crec,irec); |
|---|
| 179 | } |
|---|
| 180 | } |
|---|
| 181 | if (xrecp) { |
|---|
| 182 | FREE(vrecp[xrec]); vrecp[xrec]=NULL; nrecs--; |
|---|
| 183 | dbxflush(vifnamp[xif]); |
|---|
| 184 | } |
|---|
| 185 | } /* end for nifs */ |
|---|
| 186 | FREE(vrecp[irec]); vrecp[irec]=NULL; nrecs--; |
|---|
| 187 | FREE(vrecp[crec]); vrecp[crec]=NULL; nrecs--; |
|---|
| 188 | mstflush(dbnp); |
|---|
| 189 | } |
|---|
| 190 | } |
|---|
| 191 | |
|---|
| 192 | |
|---|
| 193 | /* initialize IF and load link files */ |
|---|
| 194 | svdifmerg (dbnp, vifnamp, vifmfns, parmxmfn, parmlogp, pstflag, parmtell); |
|---|
| 195 | |
|---|
| 196 | exit(0); |
|---|
| 197 | } |
|---|