| 1 | /* asael1.c - extrai termos de arquivo log |
|---|
| 2 | |
|---|
| 3 | Autor: AOT, 25/03/2003 |
|---|
| 4 | |
|---|
| 5 | --------------------------------------------------------------------- */ |
|---|
| 6 | |
|---|
| 7 | #include <stdio.h> |
|---|
| 8 | #include <string.h> |
|---|
| 9 | |
|---|
| 10 | #include "cisis.h" /* CISIS Interface header file */ |
|---|
| 11 | #include "cirun.h" /* CISIS Interface runtime declarations */ |
|---|
| 12 | |
|---|
| 13 | #include "cib70.h" |
|---|
| 14 | |
|---|
| 15 | void main(argc,argv) |
|---|
| 16 | int argc; |
|---|
| 17 | char *argv[]; |
|---|
| 18 | { |
|---|
| 19 | RECSTRU *recp; |
|---|
| 20 | LONGX irec,mfn; |
|---|
| 21 | |
|---|
| 22 | LONGX upcrec,upirec; |
|---|
| 23 | |
|---|
| 24 | char *p; |
|---|
| 25 | |
|---|
| 26 | char *dbnp; |
|---|
| 27 | char *dbnoutp; |
|---|
| 28 | UWORD parmtag; |
|---|
| 29 | LONGX parmfrom,parmto,parmloop,parmcount,parmtell; |
|---|
| 30 | int parmtrace=0; |
|---|
| 31 | |
|---|
| 32 | LONGX xtag; |
|---|
| 33 | LONGX count=0; |
|---|
| 34 | |
|---|
| 35 | int argnext; |
|---|
| 36 | |
|---|
| 37 | char *boolqryp=NULL; |
|---|
| 38 | LONGX boolridx=0; |
|---|
| 39 | char *booldbnp = NULL; /* b4x query dbn */ |
|---|
| 40 | b7_CIB7 *cib7p=NULL; |
|---|
| 41 | void *ciapip = NULL; |
|---|
| 42 | LONGX crec=0L; /* b5_exp usa crec condicionado a booldbnp */ |
|---|
| 43 | int errno; |
|---|
| 44 | |
|---|
| 45 | int xdir; |
|---|
| 46 | |
|---|
| 47 | char *buffup=NULL; /* outfreq/fldupdat, now allocated - AOT, 28/01/2002 */ |
|---|
| 48 | LONGX buffuplen=MAXMFRL+BUFSIZ; /* ALLOMAXV? */ |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | if (argc < 4) { |
|---|
| 52 | printf("%s",cicopyr("Utility ASAEL1")); |
|---|
| 53 | printf(" \n"); |
|---|
| 54 | printf("asael1 <dbn> <tag> [create=]<dbnout> [<option> [...]] \n"); |
|---|
| 55 | printf(" \n"); |
|---|
| 56 | printf("options: {from|to|loop|count|tell}=<n> \n"); |
|---|
| 57 | printf(" \n"); |
|---|
| 58 | exit(1); |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | |
|---|
| 62 | /* init processing |
|---|
| 63 | */ |
|---|
| 64 | parmfrom=1; parmto=999999999L; parmloop=1; parmcount=0; parmtell=0; |
|---|
| 65 | |
|---|
| 66 | argnext=1; |
|---|
| 67 | RECORD(irec=nrecs,dbnp=argv[argnext++],0L); |
|---|
| 68 | |
|---|
| 69 | p=argv[argnext++]; |
|---|
| 70 | if (sscanf(p,"%"_LD_,&xtag) != 1) fatal(p); |
|---|
| 71 | parmtag=(UWORD)xtag; |
|---|
| 72 | |
|---|
| 73 | dbnoutp=argv[argnext++]; |
|---|
| 74 | |
|---|
| 75 | /* get optional parms |
|---|
| 76 | */ |
|---|
| 77 | for (; argnext < argc; argnext++) { |
|---|
| 78 | p=argv[argnext]; |
|---|
| 79 | if (strncmp(p,"from?",5) == 0 || strncmp(p,"from=",5) == 0) { |
|---|
| 80 | if (sscanf(p+5,"%"_LD_,&parmfrom) != 1) |
|---|
| 81 | fatal(p); |
|---|
| 82 | continue; |
|---|
| 83 | } |
|---|
| 84 | if (strncmp(p,"to?",3) == 0 || strncmp(p,"to=",3) == 0) { |
|---|
| 85 | if (sscanf(p+3,"%"_LD_,&parmto) != 1) |
|---|
| 86 | fatal(p); |
|---|
| 87 | continue; |
|---|
| 88 | } |
|---|
| 89 | if (strncmp(p,"loop?",5) == 0 || strncmp(p,"loop=",5) == 0) { |
|---|
| 90 | if (sscanf(p+5,"%"_LD_,&parmloop) != 1) |
|---|
| 91 | fatal(p); |
|---|
| 92 | continue; |
|---|
| 93 | } |
|---|
| 94 | if (strncmp(p,"count?",6) == 0 || strncmp(p,"count=",6) == 0) { |
|---|
| 95 | if (sscanf(p+6,"%"_LD_,&parmcount) != 1) |
|---|
| 96 | fatal(p); |
|---|
| 97 | continue; |
|---|
| 98 | } |
|---|
| 99 | if (strncmp(p,"tell?",5) == 0 || strncmp(p,"tell=",5) == 0) { |
|---|
| 100 | if (sscanf(p+5,"%"_LD_,&parmtell) != 1) |
|---|
| 101 | fatal(p); |
|---|
| 102 | continue; |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | if (strcmp(p,"trace") == 0) { |
|---|
| 106 | parmtrace=1; |
|---|
| 107 | dbxtrace=rectrace=trmtrace=b70trace=1; |
|---|
| 108 | continue; |
|---|
| 109 | } |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | |
|---|
| 113 | /* allocate buffup |
|---|
| 114 | */ |
|---|
| 115 | buffup=loadfile(NULL,'@',"",NULL,buffuplen,'\0'); |
|---|
| 116 | |
|---|
| 117 | |
|---|
| 118 | /* initialize ridx and b4_xxx() parameters |
|---|
| 119 | */ |
|---|
| 120 | #if CIAPI |
|---|
| 121 | ciapip = cisisApplication( MAXNREC,MAXNTRM );/* mandatory for CIAPI definitions */ |
|---|
| 122 | #endif /* CIAPI */ |
|---|
| 123 | |
|---|
| 124 | cib7p=b7_cib7(cib7p,ciapip); |
|---|
| 125 | |
|---|
| 126 | for (boolridx=nrecs, mfn=1; ; mfn++) { /* get actual maxmfn */ |
|---|
| 127 | record(boolridx,dbnp,mfn); |
|---|
| 128 | if (VRECrc(boolridx) == RCEOF) fatal(dbnp); |
|---|
| 129 | if (VRECrc(boolridx) == RCNORMAL) break; |
|---|
| 130 | } |
|---|
| 131 | VRECdbxp(boolridx)=NULL; /* nao usa base de log */ |
|---|
| 132 | VMFRmfn(boolridx)=0L; |
|---|
| 133 | |
|---|
| 134 | /* create output |
|---|
| 135 | */ |
|---|
| 136 | if (!strncmp(dbnoutp,"create=",7)) { |
|---|
| 137 | dbnoutp+=7; |
|---|
| 138 | recisis0(dbnoutp); |
|---|
| 139 | } |
|---|
| 140 | |
|---|
| 141 | /* init recupdat() |
|---|
| 142 | */ |
|---|
| 143 | record(upcrec=nrecs,dbnoutp,0L); |
|---|
| 144 | record(upirec=nrecs,dbnoutp,1L); |
|---|
| 145 | |
|---|
| 146 | |
|---|
| 147 | /* |
|---|
| 148 | loop principal |
|---|
| 149 | */ |
|---|
| 150 | |
|---|
| 151 | for (mfn=parmfrom; mfn <= parmto ; mfn+=parmloop) { |
|---|
| 152 | |
|---|
| 153 | RECORD(irec,dbnp,mfn); |
|---|
| 154 | if (RECrc == RCEOF) break; |
|---|
| 155 | if (RECrc != RCNORMAL) continue; |
|---|
| 156 | if (parmcount) if (count >= parmcount) break; |
|---|
| 157 | |
|---|
| 158 | xdir=fieldx(irec,parmtag,1); |
|---|
| 159 | |
|---|
| 160 | if (xdir >= 0) { |
|---|
| 161 | |
|---|
| 162 | char *batchp=buffup; |
|---|
| 163 | |
|---|
| 164 | boolqryp=FIELDP(xdir); |
|---|
| 165 | boolqryp[DIRlen(xdir)]='\0'; |
|---|
| 166 | |
|---|
| 167 | p=b7_exp(cib7p,boolridx,dbnp,boolqryp,buffup,booldbnp,crec,&errno); |
|---|
| 168 | if (p || errno) { |
|---|
| 169 | sprintf(buffup,"<1 0>Expression syntax error %d: '%s'</1>",errno,p); |
|---|
| 170 | } |
|---|
| 171 | else { |
|---|
| 172 | char *p; |
|---|
| 173 | int xdir; |
|---|
| 174 | xdir=fieldx(boolridx,MFQTOBJ0,1); |
|---|
| 175 | if (xdir < 0) fatal("asael1/MFQTOBJ0"); |
|---|
| 176 | p=VFIELDP(boolridx,xdir); |
|---|
| 177 | sprintf(batchp,"<1 0>%d</1>",errno); batchp+=strlen(batchp); |
|---|
| 178 | while (*p != OPRXEND) { |
|---|
| 179 | if (*p != ZLDV) { p++; continue; } |
|---|
| 180 | p++; |
|---|
| 181 | p++; /* skip PSTLEVEL */ |
|---|
| 182 | sprintf(batchp,"<2 0>"); batchp+=strlen(batchp); |
|---|
| 183 | while (*p != OPRNULL) *batchp++ = *p++; |
|---|
| 184 | sprintf(batchp,"</2>"); batchp+=strlen(batchp); |
|---|
| 185 | } |
|---|
| 186 | } |
|---|
| 187 | RECORD(upirec,dbnoutp,mfn); |
|---|
| 188 | MFRstatus=ACTIVE; MFRmfrl=MFRbase=LEADER; |
|---|
| 189 | if (fldupdat(upirec,buffup)) fatal("asael1/fldupdat"); |
|---|
| 190 | recupdat(upcrec,upirec); |
|---|
| 191 | if (parmtrace) { printf(".."); getchar(); } |
|---|
| 192 | } |
|---|
| 193 | |
|---|
| 194 | count++; |
|---|
| 195 | if (parmtell) if ((count % parmtell) == 0) fprintf(stderr,"+++ %"_LD_"\n",count); |
|---|
| 196 | } |
|---|
| 197 | |
|---|
| 198 | if (parmtell) fprintf(stdout,"asael1: %"_LD_" recs in\n",count); |
|---|
| 199 | |
|---|
| 200 | if (cib7p) cib7p=b7_cib7_delete(cib7p); |
|---|
| 201 | #if CIAPI |
|---|
| 202 | cisisApplicationDelete(ciapip); |
|---|
| 203 | ciapip=NULL; |
|---|
| 204 | #endif /* CIAPI */ |
|---|
| 205 | |
|---|
| 206 | exit(0); |
|---|
| 207 | } |
|---|
| 208 | |
|---|
| 209 | |
|---|
| 210 | #if 0 |
|---|
| 211 | |
|---|
| 212 | void outfreq(n) |
|---|
| 213 | UINT n; |
|---|
| 214 | { |
|---|
| 215 | int widx,wlen; |
|---|
| 216 | char *wptr; |
|---|
| 217 | char *batchp,*p; |
|---|
| 218 | |
|---|
| 219 | widx=0; |
|---|
| 220 | wptr=tabkey; |
|---|
| 221 | do { |
|---|
| 222 | if (widx == maxhash) |
|---|
| 223 | fatal("asael1/outfreq/widx == maxhash"); |
|---|
| 224 | if (*wptr) { |
|---|
| 225 | batchp=buffup; |
|---|
| 226 | for (itabx=0;itabx<ntabx;itabx++) { |
|---|
| 227 | for (wlen=0, p=wptr; *p; p++) |
|---|
| 228 | if (wlen < lentabx[itabx]) wlen++; |
|---|
| 229 | else break; |
|---|
| 230 | sprintf(batchp,"H%d %d ",itabx+1,wlen); batchp+=strlen(batchp); |
|---|
| 231 | memcpy(batchp,wptr,wlen); |
|---|
| 232 | batchp+=wlen; |
|---|
| 233 | wptr+=lentabx[itabx]; |
|---|
| 234 | |
|---|
| 235 | } |
|---|
| 236 | wptr++; /* NULL */ |
|---|
| 237 | sprintf(batchp,"A998/%09"_LD_"/A999/%"_LD_"/", |
|---|
| 238 | 999999999L-tabcnt[widx],tabcnt[widx]); |
|---|
| 239 | batchp+=strlen(batchp); |
|---|
| 240 | *batchp='\0'; |
|---|
| 241 | record(upirec,dbnoutp,VMF0nxtmfn(upcrec)); |
|---|
| 242 | VMFRstatus(upirec)=ACTIVE; |
|---|
| 243 | if (fldupdat(upirec,buffup)) fatal(fldupdat(upirec,buffup)); |
|---|
| 244 | recupdat(upcrec,upirec); |
|---|
| 245 | n--; |
|---|
| 246 | } |
|---|
| 247 | else |
|---|
| 248 | wptr+=tabwidth; |
|---|
| 249 | widx++; |
|---|
| 250 | } while (n); |
|---|
| 251 | |
|---|
| 252 | } |
|---|
| 253 | #endif |
|---|