| 1 | /* Program R1: dumps the field contents of all active records |
|---|
| 2 | of a given data base |
|---|
| 3 | */ |
|---|
| 4 | #include <stdio.h> |
|---|
| 5 | #include <string.h> |
|---|
| 6 | #include "cisis.h" /* CISIS Interface header file */ |
|---|
| 7 | #include "cirun.h" /* CISIS Interface runtime declarations */ |
|---|
| 8 | |
|---|
| 9 | LONGX count1=0; |
|---|
| 10 | LONGX count2=0; |
|---|
| 11 | |
|---|
| 12 | void main(argc,argv) |
|---|
| 13 | int argc; |
|---|
| 14 | char *argv[]; |
|---|
| 15 | { |
|---|
| 16 | RECSTRU *recp; /* mandatory for defines REC,MFR,DIR,FIELDP */ |
|---|
| 17 | LONGX mfn; |
|---|
| 18 | int diridx,dirloop,chrloop; |
|---|
| 19 | char *p; |
|---|
| 20 | int parmtrace; |
|---|
| 21 | LONGX parmfrom,parmto,parmloop,parmcount; |
|---|
| 22 | LONGX parmoffset,parmtell; |
|---|
| 23 | char *dbnp; |
|---|
| 24 | int argnext; |
|---|
| 25 | int tag1rec=0; |
|---|
| 26 | char val1rec[200]; |
|---|
| 27 | int has1recprev=0,has1rec; |
|---|
| 28 | |
|---|
| 29 | if (argc < 2) { |
|---|
| 30 | printf("%s",cicopyr("Utility I2ID")); |
|---|
| 31 | printf("\n"); |
|---|
| 32 | printf("i2id <dbn> [option [option] ... ] \n"); |
|---|
| 33 | printf("\n"); |
|---|
| 34 | /**/ |
|---|
| 35 | printf("options: {from/to/loop/count/offset/tell}=<n> \n"); |
|---|
| 36 | printf(" 1record=<tag>=<value> \n"); |
|---|
| 37 | printf("\n"); |
|---|
| 38 | /**/ |
|---|
| 39 | printf("\n"); |
|---|
| 40 | printf("The following output is produced on stdout:\n"); |
|---|
| 41 | printf("\n"); |
|---|
| 42 | printf("!ID mmmmmmm \n"); |
|---|
| 43 | printf("!vXXX!...contents of tag XXX............. \n"); |
|---|
| 44 | printf("!vYYY!...contents of tag YYY............. \n"); |
|---|
| 45 | printf("... \n"); |
|---|
| 46 | printf("\n"); |
|---|
| 47 | printf("where mmmmmmm is the MFN \n"); |
|---|
| 48 | printf("\n"); |
|---|
| 49 | exit(1); |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | parmtrace=0; |
|---|
| 53 | parmfrom=1; parmto=0; parmloop=1; parmcount=LONGX_MAX; |
|---|
| 54 | parmoffset=0; parmtell=0; |
|---|
| 55 | |
|---|
| 56 | dbnp=argv[argnext=1]; argnext++; |
|---|
| 57 | |
|---|
| 58 | /* |
|---|
| 59 | get optional parameters |
|---|
| 60 | */ |
|---|
| 61 | for ( ; argnext < argc; argnext++) { |
|---|
| 62 | p=argv[argnext]; |
|---|
| 63 | |
|---|
| 64 | if (strncmp(p,"from=",5) == 0) { |
|---|
| 65 | if (sscanf(p+5,"%ld",&parmfrom) != 1) |
|---|
| 66 | fatal(p); |
|---|
| 67 | continue; |
|---|
| 68 | } |
|---|
| 69 | if (strncmp(p,"to=",3) == 0) { |
|---|
| 70 | if (sscanf(p+3,"%ld",&parmto) != 1) |
|---|
| 71 | fatal(p); |
|---|
| 72 | continue; |
|---|
| 73 | } |
|---|
| 74 | if (strncmp(p,"count=",6) == 0) { |
|---|
| 75 | if (sscanf(p+6,"%ld",&parmcount) != 1) |
|---|
| 76 | fatal(p); |
|---|
| 77 | continue; |
|---|
| 78 | } |
|---|
| 79 | if (strncmp(p,"loop=",5) == 0) { |
|---|
| 80 | if (sscanf(p+5,"%ld",&parmloop) != 1) |
|---|
| 81 | fatal(p); |
|---|
| 82 | continue; |
|---|
| 83 | } |
|---|
| 84 | if (strncmp(p,"offset=",7) == 0) { |
|---|
| 85 | if (sscanf(p+7,"%ld",&parmoffset) != 1) |
|---|
| 86 | fatal(p); |
|---|
| 87 | continue; |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 90 | if (strncmp(p,"tell=",5) == 0) { |
|---|
| 91 | if (sscanf(p+5,"%ld",&parmtell) != 1) |
|---|
| 92 | fatal(p); |
|---|
| 93 | continue; |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | if (strncmp(p,"1record=",8) == 0) { |
|---|
| 97 | if (sscanf(p+8,"%d=%s",&tag1rec,val1rec) != 2) |
|---|
| 98 | fatal(p); |
|---|
| 99 | continue; |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | if (strcmp(p,"trace") == 0) { |
|---|
| 103 | parmtrace=1; |
|---|
| 104 | continue; |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | fatal(p); |
|---|
| 108 | } |
|---|
| 109 | |
|---|
| 110 | if (!parmto) parmto=LONGX_MAX; |
|---|
| 111 | if (parmtrace) parmtell=1; |
|---|
| 112 | |
|---|
| 113 | if (parmtrace) { |
|---|
| 114 | printf("+++ input data base: %s\n",dbnp); |
|---|
| 115 | printf("+++ 1record: tag %d=%s\n",tag1rec,val1rec); |
|---|
| 116 | } |
|---|
| 117 | |
|---|
| 118 | for (mfn=parmfrom; mfn <= parmto; mfn+=parmloop) { |
|---|
| 119 | RECORD(0L,dbnp,mfn); |
|---|
| 120 | if (RECrc == RCEOF) break; |
|---|
| 121 | count1++; if (count1 > parmcount) break; |
|---|
| 122 | if (parmtell) if (!(count1 % parmtell)) fprintf(stderr,"+++ %ld/%ld recs\n",count1,count2); |
|---|
| 123 | if (RECrc != RCNORMAL) continue; |
|---|
| 124 | |
|---|
| 125 | has1rec=0; |
|---|
| 126 | if (tag1rec) { |
|---|
| 127 | for (diridx=0, dirloop=MFRnvf; dirloop--; diridx++) { |
|---|
| 128 | if (DIRtag(diridx) == tag1rec) { |
|---|
| 129 | p=FIELDP(diridx); |
|---|
| 130 | if (DIRlen(diridx) == strlen(val1rec)) |
|---|
| 131 | if (memcmp(p,val1rec,DIRlen(diridx)) == 0) { |
|---|
| 132 | has1rec=1; |
|---|
| 133 | } |
|---|
| 134 | break; |
|---|
| 135 | } |
|---|
| 136 | } |
|---|
| 137 | } |
|---|
| 138 | |
|---|
| 139 | if (has1recprev == 0 || has1rec == 0) { |
|---|
| 140 | count2++; |
|---|
| 141 | printf("!ID %07ld\n",mfn+parmoffset); |
|---|
| 142 | } |
|---|
| 143 | has1recprev=has1rec; |
|---|
| 144 | |
|---|
| 145 | for (diridx=0, dirloop=MFRnvf; dirloop--; diridx++) { |
|---|
| 146 | /* |
|---|
| 147 | if (DIRtag(diridx) > 999) continue; |
|---|
| 148 | */ |
|---|
| 149 | printf("!v%03d!",DIRtag(diridx)); |
|---|
| 150 | p=FIELDP(diridx); |
|---|
| 151 | for (chrloop=DIRlen(diridx); chrloop--; p++) |
|---|
| 152 | printf("%c",*p); |
|---|
| 153 | printf("\n"); |
|---|
| 154 | } |
|---|
| 155 | } |
|---|
| 156 | if (parmtell) fprintf(stderr,"+++ %ld/%ld recs\n",count1,count2); |
|---|
| 157 | } /* end of main */ |
|---|