| 1 | /* ifload.c - Load an inverted file from sorted link files |
|---|
| 2 | */ |
|---|
| 3 | #include <stdio.h> |
|---|
| 4 | #include <string.h> |
|---|
| 5 | #include <ctype.h> |
|---|
| 6 | |
|---|
| 7 | #if CIAPI |
|---|
| 8 | #include "ciapi.h" |
|---|
| 9 | #else /* CIAPI */ |
|---|
| 10 | #include "cisis.h" |
|---|
| 11 | #endif /* CIAPI */ |
|---|
| 12 | |
|---|
| 13 | #if IFLOADFUN |
|---|
| 14 | int cisis_ifload(stringp) |
|---|
| 15 | char *stringp; |
|---|
| 16 | { |
|---|
| 17 | #define MAXARGS1 512 |
|---|
| 18 | int argc=0; |
|---|
| 19 | char *argv[MAXARGS1+1]; |
|---|
| 20 | char *p,*q,c1,c2; |
|---|
| 21 | int strip; |
|---|
| 22 | int rc; |
|---|
| 23 | #if LIND |
|---|
| 24 | for (argv[argc++]="iflind", p=stringp; *p; ) { |
|---|
| 25 | #else /* LIND */ |
|---|
| 26 | for (argv[argc++]="ifload", p=stringp; *p; ) { |
|---|
| 27 | #endif /* LIND */ |
|---|
| 28 | while (isspace(*p)) p++; |
|---|
| 29 | c1='\r'; c2='\n'; if (*p == '"') { p++; c1=c2='"'; } |
|---|
| 30 | argv[argc++]=p; |
|---|
| 31 | for (strip=0, q=p; *p; ) { |
|---|
| 32 | if (*p == c1) { *p++='\0'; if (*p == c2) p++; break; } |
|---|
| 33 | if (*p == c2) { *p++='\0'; if (*p == c1) p++; break; } |
|---|
| 34 | if (*p) { *q++ = *p++; strip++; } |
|---|
| 35 | } |
|---|
| 36 | #if BEFORE401R2 /* because must keep trailing space in "seq=x " */ |
|---|
| 37 | if (c1 != '"') while (strip--) if (isspace(*(q-1))) q--; else break; |
|---|
| 38 | #endif |
|---|
| 39 | *q='\0'; |
|---|
| 40 | } |
|---|
| 41 | argv[argc]=NULL; |
|---|
| 42 | rc=ifloadexec(argc,argv); |
|---|
| 43 | return(rc); |
|---|
| 44 | } |
|---|
| 45 | #endif /* IFLOADFUN */ |
|---|
| 46 | |
|---|
| 47 | #if !CICPP && !CIAPI |
|---|
| 48 | extern int ifl_balan; /* cisis.h */ |
|---|
| 49 | #endif /* !CICPP */ |
|---|
| 50 | |
|---|
| 51 | /* function ifloadexec(argc,argv) derived from the original ifload.c source code |
|---|
| 52 | |
|---|
| 53 | AOT, 21/02/2001 |
|---|
| 54 | |
|---|
| 55 | update ifloadexec(argc,argv) included code from the original iflind.c source |
|---|
| 56 | |
|---|
| 57 | AOT, 18/05/2001 |
|---|
| 58 | */ |
|---|
| 59 | |
|---|
| 60 | int ifloadexec(argc,argv) |
|---|
| 61 | int argc; |
|---|
| 62 | char *argv[]; |
|---|
| 63 | { |
|---|
| 64 | char *dbnp,*fillk1p,*fillk2p,*rdbnp; |
|---|
| 65 | int pstflag=IFUPISIS; |
|---|
| 66 | LONGX parmtell=0L; |
|---|
| 67 | int parmtrace=0; |
|---|
| 68 | #if LIND |
|---|
| 69 | LONGX parmxmfn=0L; |
|---|
| 70 | char *parmxmfp=NULL; |
|---|
| 71 | char *parmlogp=NULL; |
|---|
| 72 | int parmreset=0; |
|---|
| 73 | #else /* LIND */ |
|---|
| 74 | int parmreset=1; |
|---|
| 75 | #endif /* LIND */ |
|---|
| 76 | int argnext=1; |
|---|
| 77 | char *p; |
|---|
| 78 | LONGX nlinks; |
|---|
| 79 | #if CIAPI |
|---|
| 80 | void *ciapip; |
|---|
| 81 | #endif /* CIAPI */ |
|---|
| 82 | |
|---|
| 83 | #if LIND |
|---|
| 84 | if (argc < 4) { |
|---|
| 85 | printf("%s",cicopyr("Utility IFLIND")); |
|---|
| 86 | printf("\n"); |
|---|
| 87 | printf("iflind <dbname> {<file_lk1>|void} {<file_lk2>|void} [<option> [...]] \n"); |
|---|
| 88 | printf("\n"); |
|---|
| 89 | printf(" <dbname> -> output inverted file \n"); |
|---|
| 90 | printf(" <file_lk1> -> sorted %2d-byte link file\n",LE1); |
|---|
| 91 | printf(" <file_lk2> -> sorted %2d-byte link file\n",LE2); |
|---|
| 92 | printf("\n"); |
|---|
| 93 | printf("options: \n"); |
|---|
| 94 | printf("\n"); |
|---|
| 95 | printf(" -posts -> do not load .iyp \n"); |
|---|
| 96 | printf(" -balan -> do not rebalance the dict \n"); |
|---|
| 97 | printf(" maxmfn=<n> -> max master file number \n"); |
|---|
| 98 | printf(" master=<dbn> -> master file to get maxmfn \n"); |
|---|
| 99 | printf(" log=<file> -> log file name \n"); |
|---|
| 100 | printf(" tell=<n> -> tell <n> links has been loaded \n"); |
|---|
| 101 | #if !LINK_7544KEY |
|---|
| 102 | #if CIIFLFIX |
|---|
| 103 | printf(" +fix[/m] -> read fixed length link records \n"); |
|---|
| 104 | #endif |
|---|
| 105 | #endif |
|---|
| 106 | printf(" +reset[=<dbn>] -> reset IF update is pending \n"); |
|---|
| 107 | printf(" \n"); |
|---|
| 108 | return(1); /* error */ |
|---|
| 109 | } |
|---|
| 110 | #else /* LIND */ |
|---|
| 111 | if (argc < 4) { |
|---|
| 112 | printf("%s",cicopyr("Utility IFLOAD")); |
|---|
| 113 | printf("\n"); |
|---|
| 114 | printf("ifload <dbname> {<file_lk1>|void} {<file_lk2>|void} [<option> [...]] \n"); |
|---|
| 115 | printf("\n"); |
|---|
| 116 | printf(" <dbname> -> output inverted file \n"); |
|---|
| 117 | printf(" <file_lk1> -> sorted %2d-byte link file\n",LE1); |
|---|
| 118 | printf(" <file_lk2> -> sorted %2d-byte link file\n",LE2); |
|---|
| 119 | printf("\n"); |
|---|
| 120 | printf("options: \n"); |
|---|
| 121 | printf("\n"); |
|---|
| 122 | printf(" master=<name> -> alternate master file \n"); |
|---|
| 123 | printf(" -reset -> keep IF update is pending \n"); |
|---|
| 124 | printf(" -posts -> do not load .ifp \n"); |
|---|
| 125 | printf(" -balan -> do not rebalance the dict \n"); |
|---|
| 126 | printf(" tell=<n> -> tell <n> links has been loaded \n"); |
|---|
| 127 | #if !LINK_7544KEY |
|---|
| 128 | #if CIIFLFIX |
|---|
| 129 | printf(" +fix[/m] -> read fixed link records \n"); |
|---|
| 130 | #endif |
|---|
| 131 | #endif |
|---|
| 132 | printf(" \n"); |
|---|
| 133 | return(1); /* error */ |
|---|
| 134 | } |
|---|
| 135 | #endif /* LIND */ |
|---|
| 136 | |
|---|
| 137 | |
|---|
| 138 | #if CIAPI |
|---|
| 139 | ciapip = cisisApplication( MAXNREC,MAXNTRM );/* mandatory for CIAPI definitions */ |
|---|
| 140 | #endif /* CIAPI */ |
|---|
| 141 | |
|---|
| 142 | /* get positional parms */ |
|---|
| 143 | dbnp=rdbnp=argv[argnext++]; |
|---|
| 144 | fillk1p=argv[argnext++]; |
|---|
| 145 | fillk2p=argv[argnext++]; |
|---|
| 146 | |
|---|
| 147 | /* get optional parms */ |
|---|
| 148 | for (; argnext < argc; argnext++) { |
|---|
| 149 | p=argv[argnext]; |
|---|
| 150 | if (strncmp(p,"tell?",5) == 0 || strncmp(p,"tell=",5) == 0) { |
|---|
| 151 | if (sscanf(p+5,"%"_LD_,&parmtell) != 1) fatal(p); |
|---|
| 152 | if (parmtell < 0) fatal(p); |
|---|
| 153 | continue; |
|---|
| 154 | } |
|---|
| 155 | if (strcmp(p,"-balan") == 0) { |
|---|
| 156 | ifl_balan=0; |
|---|
| 157 | continue; |
|---|
| 158 | } |
|---|
| 159 | if (strcmp(p,"-posts") == 0) { |
|---|
| 160 | pstflag=IFUPDICT; |
|---|
| 161 | continue; |
|---|
| 162 | } |
|---|
| 163 | #if LIND |
|---|
| 164 | if (strncmp(p,"maxmfn?",7) == 0 || strncmp(p,"maxmfn=",7) == 0) { |
|---|
| 165 | if (sscanf(p+7,"%"_LD_,&parmxmfn) != 1) fatal(p); |
|---|
| 166 | if (parmxmfn < 1) fatal(p); |
|---|
| 167 | continue; |
|---|
| 168 | } |
|---|
| 169 | if (strncmp(p,"master?",7) == 0 || strncmp(p,"master=",7) == 0) { |
|---|
| 170 | parmxmfp=p+7; |
|---|
| 171 | if (!*parmxmfp) fatal(p); |
|---|
| 172 | continue; |
|---|
| 173 | } |
|---|
| 174 | if (strncmp(p,"log?",4) == 0 || strncmp(p,"log=",4) == 0) { |
|---|
| 175 | parmlogp=p+4; |
|---|
| 176 | if (!*parmlogp) fatal(p); |
|---|
| 177 | continue; |
|---|
| 178 | } |
|---|
| 179 | if (strncmp(p,"+reset?",7) == 0 || strncmp(p,"+reset=",7) == 0) { |
|---|
| 180 | rdbnp=p+7; |
|---|
| 181 | if (!*rdbnp) fatal(p); |
|---|
| 182 | continue; |
|---|
| 183 | } |
|---|
| 184 | if (strcmp(p,"+reset") == 0) { |
|---|
| 185 | parmreset=1; |
|---|
| 186 | continue; |
|---|
| 187 | } |
|---|
| 188 | #else /* LIND */ |
|---|
| 189 | if (strncmp(p,"master?",7) == 0 || strncmp(p,"master=",7) == 0) { |
|---|
| 190 | rdbnp=p+7; |
|---|
| 191 | if (!*rdbnp) fatal(p); |
|---|
| 192 | continue; |
|---|
| 193 | } |
|---|
| 194 | if (strcmp(p,"-reset") == 0) { |
|---|
| 195 | parmreset=0; |
|---|
| 196 | continue; |
|---|
| 197 | } |
|---|
| 198 | #endif /* LIND */ |
|---|
| 199 | |
|---|
| 200 | #if !LINK_7544KEY |
|---|
| 201 | #if CIIFLFIX |
|---|
| 202 | if (strcmp(p,"+fix") == 0) { |
|---|
| 203 | ciiflfix=1; |
|---|
| 204 | continue; |
|---|
| 205 | } |
|---|
| 206 | if (strcmp(p,"+fix/m") == 0) { |
|---|
| 207 | ciiflfix=ciiflfim=1; |
|---|
| 208 | continue; |
|---|
| 209 | } |
|---|
| 210 | #endif |
|---|
| 211 | #endif |
|---|
| 212 | if (strcmp(p,"trace") == 0) { |
|---|
| 213 | parmtrace=1; |
|---|
| 214 | dbxtrace=1; trmtrace=1; |
|---|
| 215 | continue; |
|---|
| 216 | } |
|---|
| 217 | fatal(p); |
|---|
| 218 | } |
|---|
| 219 | |
|---|
| 220 | #if LIND |
|---|
| 221 | /* get maxmfn */ |
|---|
| 222 | if (!parmxmfn) { |
|---|
| 223 | LONGX irecx; |
|---|
| 224 | if (!parmxmfp) parmxmfp=dbnp; |
|---|
| 225 | parmxmfn=VMF0nxtmfn(record(irecx=nrecs,parmxmfp,0L))-1; |
|---|
| 226 | FREE(vrecp[irecx]); vrecp[irecx]=NULL; nrecs-=1; |
|---|
| 227 | dbxflush(parmxmfp); |
|---|
| 228 | } |
|---|
| 229 | /* should pause */ |
|---|
| 230 | if (parmtrace || parmtell) { |
|---|
| 231 | printf("+++ create=%s \n",dbnp); |
|---|
| 232 | printf("+++ maxmfn=%"_LD_"\n",parmxmfn); |
|---|
| 233 | } |
|---|
| 234 | /* initialize IF and load link files */ |
|---|
| 235 | nlinks=svdiflind (dbnp, fillk1p ,fillk2p, parmxmfn, parmlogp, pstflag, parmtell); |
|---|
| 236 | #else /* LIND */ |
|---|
| 237 | /* should pause */ |
|---|
| 238 | if (parmtrace || parmtell) { |
|---|
| 239 | printf("+++ data base: %s\n",dbnp); |
|---|
| 240 | printf("+++ .lk1 file: %s\n",fillk1p); |
|---|
| 241 | printf("+++ .lk2 file: %s\n",fillk2p); |
|---|
| 242 | } |
|---|
| 243 | /* initialize IF and load link files */ |
|---|
| 244 | nlinks=svdifload (dbnp, fillk1p ,fillk2p, pstflag, parmtell); |
|---|
| 245 | #endif /* LIND */ |
|---|
| 246 | dbxflush(dbnp); |
|---|
| 247 | |
|---|
| 248 | /* reset "I/F update is pending" */ |
|---|
| 249 | if (parmreset) { |
|---|
| 250 | recreset(rdbnp,1L,MAXUPDMFN,0L,parmtell); |
|---|
| 251 | } |
|---|
| 252 | |
|---|
| 253 | #if CIAPI |
|---|
| 254 | cisisApplicationDelete( ciapip ); |
|---|
| 255 | #endif /* CIAPI */ |
|---|
| 256 | |
|---|
| 257 | return( (nlinks < 0) ? /* error */ 1 + (int)(-nlinks) : 0); |
|---|
| 258 | } |
|---|