| 1 | /* Copyright (c) 1990, 1991 Adalberto Otranto Tardelli. All rights reserved. |
|---|
| 2 | * Written by A.O.Tardelli 7/90 |
|---|
| 3 | * Redistribution and use in source and binary forms are freely permitted |
|---|
| 4 | * provided that the above copyright notice and attribution and date of work |
|---|
| 5 | * and this paragraph are duplicated in all such forms. |
|---|
| 6 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR |
|---|
| 7 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED |
|---|
| 8 | * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
|---|
| 9 | * This program gets the number of records, status, tag and chars frequencies |
|---|
| 10 | * of a MicroISIS master file and writes the results in a record that is |
|---|
| 11 | * appended in another master file. |
|---|
| 12 | * Note that the resulting master file should not be exported as an ISO-2709 |
|---|
| 13 | * file, because fields with tags greater than 1000 are used. |
|---|
| 14 | * Currently works with CISIS Interface 1.1 and TurboC 2.0 (Huge model) |
|---|
| 15 | */ |
|---|
| 16 | |
|---|
| 17 | /* ------------------------------ mxf0.c ----------------------------------- */ |
|---|
| 18 | |
|---|
| 19 | #include <stdio.h> |
|---|
| 20 | #include <time.h> |
|---|
| 21 | #include <ctype.h> |
|---|
| 22 | #include <string.h> |
|---|
| 23 | |
|---|
| 24 | #if 1 |
|---|
| 25 | #include "cisis.h" /* CISIS Interface header file */ |
|---|
| 26 | #include "cirun.h" /* CISIS Interface runtime declarations */ |
|---|
| 27 | #else |
|---|
| 28 | #include "\cisis\include\cisis.h" /* CISIS Interface header file */ |
|---|
| 29 | #include "\cisis\include\cirun.h" /* CISIS Interface runtime declarations */ |
|---|
| 30 | #endif |
|---|
| 31 | |
|---|
| 32 | /* program parameters */ |
|---|
| 33 | UBYTE dbname[CIMPL+1],line[CIMPL+1],dbnout[CIMPL+1]; |
|---|
| 34 | UBYTE *dbnamep,*dbnoutp; |
|---|
| 35 | LONGX parmtnrecs=0L; |
|---|
| 36 | int parmedit; |
|---|
| 37 | LONGX parmtell; |
|---|
| 38 | LONGX parmfrom,parmto,parmloop,parmcount; |
|---|
| 39 | int parmtbytes; |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | /* cisis/update working area */ |
|---|
| 43 | UBYTE buffup[MAXMFRL+MAXMFRL+BUFSIZ]; |
|---|
| 44 | UBYTE buffid[BUFSIZ]; |
|---|
| 45 | #define FLDUPDLM 0x01 |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | typedef struct freqstru { |
|---|
| 49 | int tag; |
|---|
| 50 | LONGX freqtag; |
|---|
| 51 | LONGX freqocc; |
|---|
| 52 | int minsize; |
|---|
| 53 | int maxsize; |
|---|
| 54 | LONGX totbytes; |
|---|
| 55 | char newdoc; |
|---|
| 56 | struct freqstru *nextp; |
|---|
| 57 | } FREQSTRU; |
|---|
| 58 | |
|---|
| 59 | FREQSTRU *freqhp,*freqtagp,*freqp,*freqlp; |
|---|
| 60 | |
|---|
| 61 | LONGX freqch[256]; |
|---|
| 62 | LONGX freqrc[RCPDEL+1]; |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | /* prototypes */ |
|---|
| 66 | #if ANSI |
|---|
| 67 | int getparms(int argc, char *argv[]); |
|---|
| 68 | FREQSTRU *freqalloc(void); |
|---|
| 69 | #else |
|---|
| 70 | int getparms(); |
|---|
| 71 | FREQSTRU *freqalloc(); |
|---|
| 72 | #endif |
|---|
| 73 | |
|---|
| 74 | |
|---|
| 75 | void main(argc,argv) |
|---|
| 76 | int argc; |
|---|
| 77 | char *argv[]; |
|---|
| 78 | { |
|---|
| 79 | RECSTRU *recp; /* mandatory for defines REC RDB MF0 MFR DIR, FIELDP */ |
|---|
| 80 | LONGX irec; |
|---|
| 81 | LONGX upcrec,upirec; |
|---|
| 82 | int loopdir,xdir,tag,len; |
|---|
| 83 | UBYTE *batchp; |
|---|
| 84 | |
|---|
| 85 | int rc,xfd; |
|---|
| 86 | LONGX mfn; |
|---|
| 87 | LONGX wtime; |
|---|
| 88 | struct tm *t; |
|---|
| 89 | unsigned char c,*p; |
|---|
| 90 | int loop; |
|---|
| 91 | |
|---|
| 92 | LONGX count=0L; |
|---|
| 93 | |
|---|
| 94 | getparms(argc,argv); |
|---|
| 95 | if (parmtell) fprintf(stderr,"+++ input data base: %s\n",dbnamep); |
|---|
| 96 | if (parmtell) fprintf(stderr,"+++ output data base: %s\n",dbnoutp); |
|---|
| 97 | |
|---|
| 98 | |
|---|
| 99 | /* |
|---|
| 100 | create output data base |
|---|
| 101 | */ |
|---|
| 102 | if (strncmp(dbnoutp,"create=",7) == 0) { |
|---|
| 103 | rc=recisis0((dbnoutp+=7)); |
|---|
| 104 | /* if (parmtell) fprintf(stderr,"+++ recisis0=%d\n",rc); */ |
|---|
| 105 | } |
|---|
| 106 | else { |
|---|
| 107 | if (strncmp(dbnoutp,"append=",7) == 0) dbnoutp+=7; |
|---|
| 108 | dbxopt_fatal=0; |
|---|
| 109 | if ((xfd=dbxopen("",dbnoutp,mx1extp)) <= 0) { |
|---|
| 110 | rc=recisis0(dbnoutp); |
|---|
| 111 | /* fprintf(stderr,"+++ recisis0=%d\n",rc); */ |
|---|
| 112 | } |
|---|
| 113 | else |
|---|
| 114 | CLOSE(xfd); |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | /* |
|---|
| 118 | get output data base control record and write this execution |
|---|
| 119 | */ |
|---|
| 120 | |
|---|
| 121 | RECORD((upcrec=nrecs),dbnoutp,0L); |
|---|
| 122 | |
|---|
| 123 | time(&wtime); |
|---|
| 124 | #if MPE |
|---|
| 125 | system("setvar TZ 'TMZ1XXX'"); |
|---|
| 126 | #endif |
|---|
| 127 | |
|---|
| 128 | sprintf(batchp=buffid,"A1001\n%s\n",dbnamep); |
|---|
| 129 | batchp+=strlen(batchp); |
|---|
| 130 | |
|---|
| 131 | t=localtime(&wtime); |
|---|
| 132 | sprintf(batchp,"A1003\n%04d%02d%02d %02d:%02d:%02d %.3s\n", |
|---|
| 133 | t->tm_year+1900,t->tm_mon+1,t->tm_mday, |
|---|
| 134 | t->tm_hour,t->tm_min,t->tm_sec, |
|---|
| 135 | ctime(&wtime)); |
|---|
| 136 | |
|---|
| 137 | strcpy(buffup,buffid); |
|---|
| 138 | |
|---|
| 139 | |
|---|
| 140 | /* |
|---|
| 141 | choose the next output master file record "shelf" |
|---|
| 142 | (it's a good programming pratice !!!) |
|---|
| 143 | */ |
|---|
| 144 | upirec=nrecs; |
|---|
| 145 | recallok(upirec,MAXMFRL+MAXMFRL); |
|---|
| 146 | |
|---|
| 147 | /* |
|---|
| 148 | get the next output master file record and make it active |
|---|
| 149 | (at this point, defines MF0 are still valid !!!) |
|---|
| 150 | |
|---|
| 151 | */ |
|---|
| 152 | RECORD(upirec,dbnoutp,MF0nxtmfn); RECrc=RCNORMAL; MFRstatus=ACTIVE; |
|---|
| 153 | |
|---|
| 154 | |
|---|
| 155 | /* |
|---|
| 156 | call the field update routine and create master file record |
|---|
| 157 | */ |
|---|
| 158 | if ((p=fldupdat(upirec,buffup)) != NULL) |
|---|
| 159 | fatal(p); |
|---|
| 160 | recupdat(upcrec,upirec); |
|---|
| 161 | |
|---|
| 162 | |
|---|
| 163 | /* |
|---|
| 164 | inicializa frequencias |
|---|
| 165 | */ |
|---|
| 166 | freqhp=NULL; |
|---|
| 167 | for (loop=256; loop--; ) |
|---|
| 168 | freqch[loop]=0; |
|---|
| 169 | freqrc[RCNORMAL]=freqrc[RCLDEL]=freqrc[RCPDEL]=0; |
|---|
| 170 | |
|---|
| 171 | |
|---|
| 172 | /* |
|---|
| 173 | choose next record "shelf" for processing and tabulate the data |
|---|
| 174 | */ |
|---|
| 175 | for (irec=nrecs, mfn=parmfrom; ; mfn+=parmloop) { |
|---|
| 176 | |
|---|
| 177 | if (parmto) if (mfn > parmto) break; |
|---|
| 178 | if (parmcount) if (count > parmcount) break; |
|---|
| 179 | |
|---|
| 180 | RECORD(irec,dbnamep,mfn); |
|---|
| 181 | if (RECrc == RCEOF) |
|---|
| 182 | break; |
|---|
| 183 | |
|---|
| 184 | count++; |
|---|
| 185 | freqrc[RECrc]++; |
|---|
| 186 | |
|---|
| 187 | if (RECrc != RCNORMAL) |
|---|
| 188 | continue; |
|---|
| 189 | |
|---|
| 190 | for (freqp=freqhp; freqp; freqp=freqp->nextp) |
|---|
| 191 | freqp->newdoc=1; |
|---|
| 192 | |
|---|
| 193 | for (loopdir=MFRnvf, xdir=0; loopdir--; xdir++) { |
|---|
| 194 | |
|---|
| 195 | tag=DIRtag(xdir); len=DIRlen(xdir); |
|---|
| 196 | |
|---|
| 197 | for (freqtagp=NULL, freqp=freqhp; freqp; freqp=freqp->nextp) |
|---|
| 198 | if (freqp->tag == tag) { |
|---|
| 199 | freqtagp=freqp; |
|---|
| 200 | break; |
|---|
| 201 | } |
|---|
| 202 | |
|---|
| 203 | if (!freqtagp) { |
|---|
| 204 | freqtagp=freqalloc(); |
|---|
| 205 | if (!freqhp) { |
|---|
| 206 | freqhp=freqtagp; |
|---|
| 207 | freqtagp->nextp=NULL; |
|---|
| 208 | } |
|---|
| 209 | else { |
|---|
| 210 | for (freqlp=freqp=freqhp; freqp; freqp=freqp->nextp) |
|---|
| 211 | if (freqp->tag > tag) |
|---|
| 212 | break; |
|---|
| 213 | else |
|---|
| 214 | freqlp=freqp; |
|---|
| 215 | freqtagp->nextp=freqp; |
|---|
| 216 | if (freqhp == freqp) |
|---|
| 217 | freqhp=freqtagp; |
|---|
| 218 | else |
|---|
| 219 | freqlp->nextp=freqtagp; |
|---|
| 220 | } |
|---|
| 221 | freqtagp->tag=tag; |
|---|
| 222 | freqtagp->newdoc=1; |
|---|
| 223 | } |
|---|
| 224 | |
|---|
| 225 | if (freqtagp->newdoc == 1) { |
|---|
| 226 | freqtagp->freqtag++; |
|---|
| 227 | freqtagp->newdoc=0; |
|---|
| 228 | } |
|---|
| 229 | freqtagp->freqocc++; |
|---|
| 230 | |
|---|
| 231 | if (len < freqtagp->minsize) |
|---|
| 232 | freqtagp->minsize=len; |
|---|
| 233 | if (len > freqtagp->maxsize) |
|---|
| 234 | freqtagp->maxsize=len; |
|---|
| 235 | |
|---|
| 236 | freqtagp->totbytes+=len; |
|---|
| 237 | |
|---|
| 238 | for (p=FIELDP(xdir), loop=len; loop--; p++) { |
|---|
| 239 | c= *p; |
|---|
| 240 | freqch[c]++; |
|---|
| 241 | } |
|---|
| 242 | } |
|---|
| 243 | |
|---|
| 244 | if (parmtell) |
|---|
| 245 | if (!(count % parmtell)) |
|---|
| 246 | fprintf(stderr,"+++ %"_LD_" recs\n",count); |
|---|
| 247 | |
|---|
| 248 | } |
|---|
| 249 | |
|---|
| 250 | |
|---|
| 251 | /* |
|---|
| 252 | setup frequencies results via 'A' commands for fldupdat |
|---|
| 253 | */ |
|---|
| 254 | if (parmedit) |
|---|
| 255 | sprintf(batchp=buffup, |
|---|
| 256 | "A1009\n%9"_LD_"\n A1010\n%9"_LD_"\n A1011\n%9"_LD_"\n A1012\n%9"_LD_"\n A1013\n%9"_LD_"\n", |
|---|
| 257 | count,freqrc[RCNORMAL],freqrc[RCLDEL],freqrc[RCPDEL],mfn); |
|---|
| 258 | else |
|---|
| 259 | sprintf(batchp=buffup, |
|---|
| 260 | "A1009\n%"_LD_"\n A1010\n%"_LD_"\n A1011\n%"_LD_"\n A1012\n%"_LD_"\n A1013\n%"_LD_"\n", |
|---|
| 261 | count,freqrc[RCNORMAL],freqrc[RCLDEL],freqrc[RCPDEL],mfn); |
|---|
| 262 | batchp+=strlen(batchp); |
|---|
| 263 | |
|---|
| 264 | if (parmtbytes) { |
|---|
| 265 | LONGX tbytes=0; |
|---|
| 266 | for (freqp=freqhp; freqp; freqp=freqp->nextp) tbytes+=freqp->totbytes; |
|---|
| 267 | if (parmedit) |
|---|
| 268 | sprintf(batchp,"A1014\n^tall^n%10"_LD_"\n",tbytes); |
|---|
| 269 | else |
|---|
| 270 | sprintf(batchp,"A1014\n^tall^n%"_LD_"\n",tbytes); |
|---|
| 271 | batchp+=strlen(batchp); |
|---|
| 272 | } |
|---|
| 273 | |
|---|
| 274 | for (freqp=freqhp; freqp; freqp=freqp->nextp) { |
|---|
| 275 | if (parmedit) |
|---|
| 276 | sprintf(batchp,"A1020\n^t%03d^d%9"_LD_"^o%9"_LD_"^l%5d^u%5d^n%10"_LD_"\n", |
|---|
| 277 | freqp->tag, |
|---|
| 278 | freqp->freqtag,freqp->freqocc, |
|---|
| 279 | freqp->minsize,freqp->maxsize, |
|---|
| 280 | freqp->totbytes); |
|---|
| 281 | else |
|---|
| 282 | sprintf(batchp,"A1020\n^t%03d^d%"_LD_"^o%"_LD_"^l%d^u%d^n%"_LD_"\n", |
|---|
| 283 | freqp->tag, |
|---|
| 284 | freqp->freqtag,freqp->freqocc, |
|---|
| 285 | freqp->minsize,freqp->maxsize, |
|---|
| 286 | freqp->totbytes); |
|---|
| 287 | batchp+=strlen(batchp); |
|---|
| 288 | } |
|---|
| 289 | |
|---|
| 290 | for (loop=0; loop<256; loop++) |
|---|
| 291 | if (freqch[loop]) { |
|---|
| 292 | if (parmedit) |
|---|
| 293 | sprintf(batchp,"A1030\n^tall^x%02x^n%10"_LD_"\n", |
|---|
| 294 | loop,freqch[loop]); |
|---|
| 295 | else |
|---|
| 296 | sprintf(batchp,"A1030\n^tall^x%02x^n%"_LD_"\n", |
|---|
| 297 | loop,freqch[loop]); |
|---|
| 298 | batchp+=strlen(batchp); |
|---|
| 299 | } |
|---|
| 300 | |
|---|
| 301 | |
|---|
| 302 | /* |
|---|
| 303 | call the field update routine and update master file record |
|---|
| 304 | */ |
|---|
| 305 | if ((p=fldupdat(upirec,buffup)) != NULL) |
|---|
| 306 | fatal(p); |
|---|
| 307 | |
|---|
| 308 | recupdat(upcrec,upirec); |
|---|
| 309 | |
|---|
| 310 | |
|---|
| 311 | if (parmtell) fprintf(stderr, |
|---|
| 312 | "mxf0: %"_LD_" recs\n",count); |
|---|
| 313 | |
|---|
| 314 | if (count == parmtnrecs) |
|---|
| 315 | exit(0); |
|---|
| 316 | else |
|---|
| 317 | exit(1); |
|---|
| 318 | |
|---|
| 319 | } |
|---|
| 320 | |
|---|
| 321 | |
|---|
| 322 | |
|---|
| 323 | |
|---|
| 324 | FREQSTRU *freqalloc() |
|---|
| 325 | { |
|---|
| 326 | FREQSTRU *freqp; |
|---|
| 327 | unsigned char *p; |
|---|
| 328 | int loop; |
|---|
| 329 | |
|---|
| 330 | freqp=(FREQSTRU *)malloc(sizeof(FREQSTRU)); |
|---|
| 331 | if (freqp == NULL) |
|---|
| 332 | fatal("erro ao alocar FREQSTRU"); |
|---|
| 333 | |
|---|
| 334 | for (p=(unsigned char *)freqp, loop=sizeof(FREQSTRU); loop--; ) |
|---|
| 335 | *p++ = NULL; |
|---|
| 336 | |
|---|
| 337 | freqp->minsize=INT_MAX; |
|---|
| 338 | freqp->maxsize=INT_MIN; |
|---|
| 339 | |
|---|
| 340 | return(freqp); |
|---|
| 341 | } |
|---|
| 342 | |
|---|
| 343 | |
|---|
| 344 | |
|---|
| 345 | int getparms(argc,argv) /* |
|---|
| 346 | -------- */ |
|---|
| 347 | int argc; |
|---|
| 348 | char *argv[]; |
|---|
| 349 | { |
|---|
| 350 | int argnext=1; |
|---|
| 351 | UBYTE *p; |
|---|
| 352 | |
|---|
| 353 | if (argc < 3) { |
|---|
| 354 | printf("%s",cicopyr("Utility MXF0")); |
|---|
| 355 | printf("\n"); |
|---|
| 356 | printf("mxf0 <dbname> [create=]<dbnout> [<tnrecs>]"); |
|---|
| 357 | printf(" [noedit] [tell=<n>] [total] \n"); |
|---|
| 358 | printf("\n"); |
|---|
| 359 | printf(" <dbname> input master file \n"); |
|---|
| 360 | printf(" <dbnout> output master file for results \n"); |
|---|
| 361 | printf(" <tnrecs> expected number of input records (default=%"_LD_") \n",parmtnrecs); |
|---|
| 362 | printf(" \n"); |
|---|
| 363 | printf(" noedit suppress all leading spaces in the output"); |
|---|
| 364 | printf(" data fields\n"); |
|---|
| 365 | printf(" tell=<n> produce a message to the stderr every each <n>"); |
|---|
| 366 | printf(" input records\n"); |
|---|
| 367 | printf(" \n"); |
|---|
| 368 | printf(" The following tags are output to <dbnout>:\n"); |
|---|
| 369 | printf(" \n"); |
|---|
| 370 | printf(" 1001: input master file name\n"); |
|---|
| 371 | printf(" 1003: date & time stamp\n"); |
|---|
| 372 | printf(" 1009: total number of records\n"); |
|---|
| 373 | printf(" 1010: number of active records\n"); |
|---|
| 374 | printf(" 1011: number of logically deleted records\n"); |
|---|
| 375 | printf(" 1012: number of physically deleted records\n"); |
|---|
| 376 | printf(" 1013: next MFN to be assigned\n"); |
|---|
| 377 | printf(" 1020: ^tTAG ^dDOCS ^oOCCS ^lMINLEN ^uMAXLEN ^nDATA BYTES\n"); |
|---|
| 378 | printf(" 1030: ^tall ^xCHRCODE ^nCHRFREQ \n"); |
|---|
| 379 | printf("\n"); |
|---|
| 380 | printf(" Exit code is 0 if the total number of records is"); |
|---|
| 381 | printf(" equal to <tnrecs> \n"); |
|---|
| 382 | printf("\n"); |
|---|
| 383 | exit(1); |
|---|
| 384 | } |
|---|
| 385 | |
|---|
| 386 | dbnamep=argv[argnext++]; |
|---|
| 387 | dbnoutp=argv[argnext++]; |
|---|
| 388 | p=argv[argnext++]; |
|---|
| 389 | if (p) if (sscanf(p,"%"_LD_,&parmtnrecs) != 1) fatal(p); |
|---|
| 390 | |
|---|
| 391 | parmedit=1; |
|---|
| 392 | parmtell=0; |
|---|
| 393 | |
|---|
| 394 | parmfrom=1; parmto=0; parmloop=1; parmcount=LONGX_MAX; |
|---|
| 395 | parmtbytes=0; |
|---|
| 396 | |
|---|
| 397 | for (; argnext < argc; argnext++) { |
|---|
| 398 | p=argv[argnext]; |
|---|
| 399 | |
|---|
| 400 | if (strcmp(p,"noedit") == 0) { |
|---|
| 401 | parmedit=0; |
|---|
| 402 | continue; |
|---|
| 403 | } |
|---|
| 404 | |
|---|
| 405 | if (strncmp(p,"tell=",5) == 0) { |
|---|
| 406 | if (sscanf(p+5,"%"_LD_,&parmtell) != 1) |
|---|
| 407 | fatal(p); |
|---|
| 408 | continue; |
|---|
| 409 | } |
|---|
| 410 | |
|---|
| 411 | if (strncmp(p,"from=",5) == 0) { |
|---|
| 412 | if (sscanf(p+5,"%"_LD_,&parmfrom) != 1) |
|---|
| 413 | fatal(p); |
|---|
| 414 | continue; |
|---|
| 415 | } |
|---|
| 416 | if (strncmp(p,"to=",3) == 0) { |
|---|
| 417 | if (sscanf(p+3,"%"_LD_,&parmto) != 1) |
|---|
| 418 | fatal(p); |
|---|
| 419 | continue; |
|---|
| 420 | } |
|---|
| 421 | if (strncmp(p,"loop=",5) == 0) { |
|---|
| 422 | if (sscanf(p+5,"%"_LD_,&parmloop) != 1) |
|---|
| 423 | fatal(p); |
|---|
| 424 | continue; |
|---|
| 425 | } |
|---|
| 426 | if (strncmp(p,"count=",6) == 0) { |
|---|
| 427 | if (sscanf(p+6,"%"_LD_,&parmcount) != 1) |
|---|
| 428 | fatal(p); |
|---|
| 429 | continue; |
|---|
| 430 | } |
|---|
| 431 | |
|---|
| 432 | if (strcmp(p,"total") == 0) { |
|---|
| 433 | parmtbytes=1; |
|---|
| 434 | continue; |
|---|
| 435 | } |
|---|
| 436 | |
|---|
| 437 | fatal(p); |
|---|
| 438 | } |
|---|
| 439 | |
|---|
| 440 | return(0); |
|---|
| 441 | } |
|---|