| 1 | #include <stdio.h> |
|---|
| 2 | #include <string.h> |
|---|
| 3 | #include <ctype.h> |
|---|
| 4 | |
|---|
| 5 | #include "cisis.h" |
|---|
| 6 | |
|---|
| 7 | #if UNIX || MSC |
|---|
| 8 | #ifndef MAXPATH |
|---|
| 9 | #define MAXPATH 260 |
|---|
| 10 | #endif /* MAXPATH */ |
|---|
| 11 | #endif /* UNIX || MSC */ |
|---|
| 12 | |
|---|
| 13 | #if PC |
|---|
| 14 | #if MSC |
|---|
| 15 | #include <direct.h> |
|---|
| 16 | #else |
|---|
| 17 | #include <dir.h> |
|---|
| 18 | #endif /* MSC */ |
|---|
| 19 | #endif |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | /* ========================== Origem: CIDBX.C ========================== */ |
|---|
| 23 | |
|---|
| 24 | #if CICPP || CIDBX_CISISX_SOURCE |
|---|
| 25 | |
|---|
| 26 | #if MSC |
|---|
| 27 | #include <share.h> |
|---|
| 28 | #include <sys\locking.h> |
|---|
| 29 | #endif |
|---|
| 30 | |
|---|
| 31 | #if CICPP |
|---|
| 32 | #define dbxcinet xdbxcinet /* internal use */ |
|---|
| 33 | #define dbxilock xdbxilock /* internal use */ |
|---|
| 34 | #define dbxinit xdbxinit /* internal use */ |
|---|
| 35 | #define dbxstorp xdbxstorp /* internal use */ |
|---|
| 36 | #define dbxsrchp xdbxsrchp /* internal use */ |
|---|
| 37 | #define dbxopen xdbxopen /* internal use */ |
|---|
| 38 | #define dbxopenw xdbxopenw /* internal use */ |
|---|
| 39 | #define dbxopenc xdbxopenc /* internal use */ |
|---|
| 40 | |
|---|
| 41 | #define fatal xfatal /* internal use */ |
|---|
| 42 | |
|---|
| 43 | #define dbxciset xdbxciset /* internal use */ |
|---|
| 44 | #define dbxcipar xdbxcipar /* internal use */ |
|---|
| 45 | #define dbxgipar xdbxgipar /* internal use */ |
|---|
| 46 | #define gizflush xgizflush /* internal use */ |
|---|
| 47 | #define decflush xdecflush /* internal use */ |
|---|
| 48 | #define loadfile xloadfile /* internal use */ |
|---|
| 49 | #define loadstw xloadstw /* internal use */ |
|---|
| 50 | #define dbxtmpnm xdbxtmpnm /* internal use */ |
|---|
| 51 | #define cntread xcntread /* internal use */ |
|---|
| 52 | #define invsetup xinvsetup /* internal use */ |
|---|
| 53 | #define noderead xnoderead /* internal use */ |
|---|
| 54 | #define leafread xleafread /* internal use */ |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | #endif /* CICPP */ |
|---|
| 58 | |
|---|
| 59 | #define YES "y" /* dxbcipar/xxxtrace=y */ |
|---|
| 60 | |
|---|
| 61 | |
|---|
| 62 | /* ------------------------- cidbx.c/fatal() ---------------------- */ |
|---|
| 63 | #if FATRAP |
|---|
| 64 | #if !CICPP |
|---|
| 65 | /* global */ |
|---|
| 66 | int fatal_errcod = 1; /* cisis fatal() error code */ |
|---|
| 67 | char fatal_iomsg[MAXFATML+1] = { "" }; /* cisis fatal() flag/msg */ |
|---|
| 68 | jmp_buf fatal_jumper; /* cisis fatal() longjmp() */ |
|---|
| 69 | #endif /* !CICPP */ |
|---|
| 70 | #endif /* FATRAP */ |
|---|
| 71 | |
|---|
| 72 | #if WWWISIS |
|---|
| 73 | #if !CICPP |
|---|
| 74 | #if !FATRAP |
|---|
| 75 | char fatal_iomsg[MAXFATML+1] = { "" }; /* cisis fatal() flag/msg */ |
|---|
| 76 | #endif /* !FATRAP */ |
|---|
| 77 | #endif /* CICPP */ |
|---|
| 78 | #if ANSI |
|---|
| 79 | void wwwi_fatal(unsigned char *msgp); |
|---|
| 80 | #else /* ANSI */ |
|---|
| 81 | void wwwi_fatal(); |
|---|
| 82 | #endif /* ANSI */ |
|---|
| 83 | #endif /* WWWISIS */ |
|---|
| 84 | |
|---|
| 85 | #if CIAPI_SOURCE && !BUGciapi_fatal |
|---|
| 86 | extern "C" |
|---|
| 87 | { |
|---|
| 88 | extern void ciapi_fatal(unsigned char *msgp); |
|---|
| 89 | } |
|---|
| 90 | #endif /* CIAPI_SOURCE */ |
|---|
| 91 | |
|---|
| 92 | |
|---|
| 93 | #if CICPP |
|---|
| 94 | void CISISX :: xfatal(char *msgp) |
|---|
| 95 | #else /* CICPP */ |
|---|
| 96 | void fatal(msgp) /* |
|---|
| 97 | ---------- |
|---|
| 98 | fatal: msg; |
|---|
| 99 | abort |
|---|
| 100 | */ |
|---|
| 101 | char *msgp; /* ptr msg */ |
|---|
| 102 | #endif /* CICPP */ |
|---|
| 103 | { |
|---|
| 104 | |
|---|
| 105 | #if CIAPI_SOURCE && !BUGciapi_fatal |
|---|
| 106 | ciapi_fatal((unsigned char*)msgp); |
|---|
| 107 | #else /* CIAPI_SOURCE */ |
|---|
| 108 | #if WWWISIS && !defined(XIS_SERVER) |
|---|
| 109 | wwwi_fatal((unsigned char*)msgp); |
|---|
| 110 | #else /* WWWISIS */ |
|---|
| 111 | |
|---|
| 112 | #if FATRAP |
|---|
| 113 | int msgl; |
|---|
| 114 | |
|---|
| 115 | if (fatal_iomsg[0]) { |
|---|
| 116 | if (msgp != fatal_iomsg) { |
|---|
| 117 | msgl=strlen(msgp); if (msgl >= MAXFATML) msgl=MAXFATML; |
|---|
| 118 | strncpy(fatal_iomsg,msgp,msgl); fatal_iomsg[msgl]='\0'; |
|---|
| 119 | } |
|---|
| 120 | longjmp(fatal_jumper,1 /*fatal_errcod*/); |
|---|
| 121 | } |
|---|
| 122 | #endif /* FATRAP */ |
|---|
| 123 | |
|---|
| 124 | #ifdef USE_ERROR_SYS |
|---|
| 125 | errsys->sys_error(errno,msgp); |
|---|
| 126 | #endif /* !USE_ERROR_SYS */ |
|---|
| 127 | |
|---|
| 128 | #if CICPP && !CIAPI_SOURCE |
|---|
| 129 | Fatal Fat; |
|---|
| 130 | |
|---|
| 131 | Fat.Fa_ECode = -301; |
|---|
| 132 | Fat.Fa_Abort = 1; |
|---|
| 133 | strcpy(Fat.Fa_EMess, msgp); |
|---|
| 134 | throw (Fat); |
|---|
| 135 | #endif /* CICPP && !CIAPI_SOURCE */ |
|---|
| 136 | |
|---|
| 137 | #if BEFORE20000323 /* because some BRM's GCC - ask rpiva */ |
|---|
| 138 | fprintf(cistderr,"\nfatal: %s\n\n",msgp); |
|---|
| 139 | #else |
|---|
| 140 | fprintf(stderr,"\nfatal: %s\n\n",msgp); |
|---|
| 141 | #endif /* BEFORE20000323 */ |
|---|
| 142 | exit(1); /* abort(); */ |
|---|
| 143 | #endif /* WWWISIS */ |
|---|
| 144 | #endif /* CIAPI_SOURCE */ |
|---|
| 145 | } |
|---|
| 146 | /* ------------------------- cidbx.c/fatal() ---------------------- */ |
|---|
| 147 | |
|---|
| 148 | |
|---|
| 149 | #if MULTI |
|---|
| 150 | |
|---|
| 151 | #if CICPP |
|---|
| 152 | int CISISX :: xdbxcinet(char *dbnamp) |
|---|
| 153 | #else /* CICPP */ |
|---|
| 154 | int dbxcinet(dbnamp) /* |
|---|
| 155 | ------------ |
|---|
| 156 | retorna MONONETS, FULLNETS ou MASTNETS |
|---|
| 157 | */ |
|---|
| 158 | char *dbnamp; |
|---|
| 159 | #endif /* CICPP */ |
|---|
| 160 | { |
|---|
| 161 | int multi; |
|---|
| 162 | char *p,parname[CIMPL+1]; |
|---|
| 163 | |
|---|
| 164 | multi=cipnetws; |
|---|
| 165 | |
|---|
| 166 | #if CIPAR |
|---|
| 167 | if (dbnamp) { |
|---|
| 168 | strcpy(parname,dbnamp); |
|---|
| 169 | strcat(parname,".net"); |
|---|
| 170 | p=dbxcipar(NULL,parname,'='); |
|---|
| 171 | } |
|---|
| 172 | else { |
|---|
| 173 | dbnamp="default"; |
|---|
| 174 | p=dbxcipar(NULL,"14",'='); |
|---|
| 175 | if (!dbxcipok) p=dbxcipar(NULL,"netws",'='); |
|---|
| 176 | } |
|---|
| 177 | if (!dbxcipok) multi=cipnetws; else |
|---|
| 178 | if (strcmp(p,"0") == 0 || strcmp(p,"single") == 0) multi=MONONETS; else |
|---|
| 179 | if (strcmp(p,"1") == 0 || strcmp(p,"full" ) == 0) multi=FULLNETS; else |
|---|
| 180 | if (strcmp(p,"2") == 0 || strcmp(p,"master") == 0) multi=MASTNETS; |
|---|
| 181 | |
|---|
| 182 | #endif /* CIPAR */ |
|---|
| 183 | |
|---|
| 184 | #if DBXTRACE |
|---|
| 185 | if (dbxtrace) |
|---|
| 186 | printf("dbxcinet - dbnamp='%s' multi=%d\n",dbnamp,multi); |
|---|
| 187 | #endif |
|---|
| 188 | |
|---|
| 189 | return(multi); |
|---|
| 190 | } |
|---|
| 191 | |
|---|
| 192 | #endif /* MULTI */ |
|---|
| 193 | |
|---|
| 194 | #if CICPP |
|---|
| 195 | int CISISX :: xdbxilock(DBXSTRU *idbxp, |
|---|
| 196 | char *mdbnp, |
|---|
| 197 | char *typ) |
|---|
| 198 | #else /* CICPP */ |
|---|
| 199 | int dbxilock(idbxp,mdbnp,typ) |
|---|
| 200 | DBXSTRU *idbxp; |
|---|
| 201 | char *mdbnp; |
|---|
| 202 | char *typ; |
|---|
| 203 | #endif /* CICPP */ |
|---|
| 204 | { |
|---|
| 205 | DBXSTRU *dbxp; |
|---|
| 206 | char m0area[sizeof(M0STRU)]; |
|---|
| 207 | int count; |
|---|
| 208 | |
|---|
| 209 | if (dbxtrace) printf("+++ dbxilock - %s %d\n",typ,dbxiloop); |
|---|
| 210 | |
|---|
| 211 | if (strcmp(typ,"L") == 0) { |
|---|
| 212 | |
|---|
| 213 | dbxp=idbxp; |
|---|
| 214 | if (!dbxp) fatal("dbxilock/L/dbxp"); |
|---|
| 215 | |
|---|
| 216 | if (dbxtrace) printf("+++ dbxilock - I=%s M=%s \n",DBXname,mdbnp); |
|---|
| 217 | |
|---|
| 218 | dbxinvmp(dbxp); |
|---|
| 219 | dbxopenw(DBXname,DBXname,ix1extp,&DBIifopn,&DBIifopw,"dbxilock/L/ifopn/w"); |
|---|
| 220 | |
|---|
| 221 | dbxp=dbxstorp(mdbnp); |
|---|
| 222 | dbxopenw(mdbnp,mdbnp,mx1extp,&DBXmsopn,&DBXmsopw,"dbxilock/L/msopn/w"); |
|---|
| 223 | |
|---|
| 224 | for (count=dbxiloop; count--; ) { |
|---|
| 225 | |
|---|
| 226 | if (multrace) printf("dbxilock - L %s %d \n",DBXname,count); |
|---|
| 227 | |
|---|
| 228 | #if !CICPP |
|---|
| 229 | if (dbxsleep) if (count+1 < dbxiloop) sleep(dbxsleep); |
|---|
| 230 | #endif /* CICPP */ |
|---|
| 231 | |
|---|
| 232 | /* lock MF */ |
|---|
| 233 | if (dbxflock(dbxp,"M") != 0) continue; |
|---|
| 234 | |
|---|
| 235 | /* "wait" MF/EWL (just once!) */ |
|---|
| 236 | if (dbxwlock(dbxp,m0area,1) != 0) continue; /* unlock MF */ |
|---|
| 237 | |
|---|
| 238 | /* "wait" another's DEL (allow user's DEL) */ |
|---|
| 239 | if (((M0STRU *)m0area)->m0mfcxx2 > 1 || |
|---|
| 240 | (((M0STRU *)m0area)->m0mfcxx2 == 1 && !DBXdelxx)) { |
|---|
| 241 | if (dbxulock(dbxp,"M")) fatal("dbxilock/L/unlock/0"); |
|---|
| 242 | continue; |
|---|
| 243 | } |
|---|
| 244 | |
|---|
| 245 | /* lock IF (2-phase locking!) */ |
|---|
| 246 | if (dbxflock(idbxp,"I") != 0) { |
|---|
| 247 | if (dbxulock(dbxp,"M")) fatal("dbxilock/L/unlock/1"); |
|---|
| 248 | continue; |
|---|
| 249 | } |
|---|
| 250 | |
|---|
| 251 | /* update the control record */ |
|---|
| 252 | DBXewlxx=((M0STRU *)m0area)->m0mfcxx3 = 1; /* LOCK/EWL */ |
|---|
| 253 | if (LSEEK64(DBXmsopn,0L,SEEK_SET) != 0) fatal("dbxilock/L/lseek"); |
|---|
| 254 | #if DBXMSTXL /* AOT/HB 21/08/2002 */ |
|---|
| 255 | if (DBXmstxl) { |
|---|
| 256 | ((M0STRU *)m0area)->m0mftype += DBXmstxl * 256; |
|---|
| 257 | } |
|---|
| 258 | #endif |
|---|
| 259 | #if CNV_PCBINUM |
|---|
| 260 | memcpy(cnv_pcbuff,m0area,sizeof(M0STRU)); |
|---|
| 261 | ConvertMST_CTLSTRUCT(cnv_pcbuff); |
|---|
| 262 | if (CIWRITE(DBXmsopn,cnv_pcbuff,sizeof(M0STRU)) != sizeof(M0STRU)) |
|---|
| 263 | #else |
|---|
| 264 | if (CIWRITE(DBXmsopn,m0area,sizeof(M0STRU)) != sizeof(M0STRU)) |
|---|
| 265 | #endif |
|---|
| 266 | fatal("dbxilock/L/write"); |
|---|
| 267 | |
|---|
| 268 | /* unlock MF */ |
|---|
| 269 | if (dbxulock(dbxp,"M")) fatal("dbxilock/L/unlock/2"); |
|---|
| 270 | |
|---|
| 271 | return(0); /* IF/MF are granted */ |
|---|
| 272 | } |
|---|
| 273 | if (multrace) |
|---|
| 274 | printf("<L> Database %s is locked by another user\n",DBXname); |
|---|
| 275 | #if SHTEST |
|---|
| 276 | printf(".."); if (*gets(shtest)) if (strcmp(shtest,"x")) system(shtest); else fatal("dbxilock/shtest"); |
|---|
| 277 | #endif |
|---|
| 278 | return(RCLOCK); |
|---|
| 279 | } |
|---|
| 280 | |
|---|
| 281 | |
|---|
| 282 | if (strcmp(typ,"UM") == 0) { |
|---|
| 283 | |
|---|
| 284 | if (dbxtrace) printf("+++ dbxilock - M=%s \n",mdbnp); |
|---|
| 285 | dbxp=dbxstorp(mdbnp); |
|---|
| 286 | |
|---|
| 287 | for (count=dbxiloop; count--; ) { |
|---|
| 288 | if (multrace) printf("dbxilock - UM %s %d \n",DBXname,count); |
|---|
| 289 | |
|---|
| 290 | /* lock MF */ |
|---|
| 291 | if (dbxflock(dbxp,"M") != 0) continue; |
|---|
| 292 | |
|---|
| 293 | /* get control record via dbxwlock() */ |
|---|
| 294 | if (dbxwlock(dbxp,m0area,1)) fatal("dbxilock/UM/dbxwlock"); |
|---|
| 295 | |
|---|
| 296 | /* MF/EWL has to be on */ |
|---|
| 297 | if (((M0STRU *)m0area)->m0mfcxx3 == 0 || !DBXewlxx) |
|---|
| 298 | fatal("dbxilock/UM/EWL is off"); |
|---|
| 299 | |
|---|
| 300 | /* update the control record */ |
|---|
| 301 | DBXewlxx=((M0STRU *)m0area)->m0mfcxx3 = 0; /* UNLOCK/EWL */ |
|---|
| 302 | if (LSEEK64(DBXmsopn,0L,SEEK_SET) != 0) fatal("dbxilock/UM/lseek/2"); |
|---|
| 303 | #if DBXMSTXL /* AOT/HB 21/08/2002 */ |
|---|
| 304 | if (DBXmstxl) { |
|---|
| 305 | ((M0STRU *)m0area)->m0mftype += DBXmstxl * 256; |
|---|
| 306 | } |
|---|
| 307 | #endif |
|---|
| 308 | #if CNV_PCBINUM |
|---|
| 309 | memcpy(cnv_pcbuff,m0area,sizeof(M0STRU)); |
|---|
| 310 | ConvertMST_CTLSTRUCT(cnv_pcbuff); |
|---|
| 311 | if (CIWRITE(DBXmsopn,cnv_pcbuff,sizeof(M0STRU)) != sizeof(M0STRU)) |
|---|
| 312 | #else |
|---|
| 313 | if (CIWRITE(DBXmsopn,m0area,sizeof(M0STRU)) != sizeof(M0STRU)) |
|---|
| 314 | #endif |
|---|
| 315 | fatal("dbxilock/UM/write"); |
|---|
| 316 | |
|---|
| 317 | /* unlock MF */ |
|---|
| 318 | if (dbxulock(dbxp,"M")) fatal("dbxilock/UM/unlock"); |
|---|
| 319 | |
|---|
| 320 | return(0); |
|---|
| 321 | } |
|---|
| 322 | if (multrace) |
|---|
| 323 | printf("<U> Database %s is locked by another user\n",DBXname); |
|---|
| 324 | #if SHTEST |
|---|
| 325 | printf(".."); if (*gets(shtest)) if (strcmp(shtest,"x")) system(shtest); else fatal("dbxilock/shtest"); |
|---|
| 326 | #endif |
|---|
| 327 | return(RCLOCK); |
|---|
| 328 | } |
|---|
| 329 | |
|---|
| 330 | if (strcmp(typ,"UI") == 0) { |
|---|
| 331 | dbxp=idbxp; |
|---|
| 332 | if (dbxtrace) printf("+++ dbxilock - I=%s \n",DBXname); |
|---|
| 333 | /* unlock IF */ |
|---|
| 334 | dbxuclos= -dbxuclos; /* do not reopen */ |
|---|
| 335 | if (dbxulock(dbxp,"I")) fatal("dbxilock/UI/unlock"); |
|---|
| 336 | dbxuclos= -dbxuclos; /* reset */ |
|---|
| 337 | return(0); |
|---|
| 338 | } |
|---|
| 339 | |
|---|
| 340 | fatal("dbxilock/type"); |
|---|
| 341 | return(-1); /* no wrn */ |
|---|
| 342 | } |
|---|
| 343 | |
|---|
| 344 | |
|---|
| 345 | #if CICPP |
|---|
| 346 | //void DBXSTRU :: xdbxinit(void) |
|---|
| 347 | void CISISX :: xdbxinit(void) |
|---|
| 348 | #else /* CICPP */ |
|---|
| 349 | void dbxinit() /* |
|---|
| 350 | ------------ |
|---|
| 351 | inicializa vdbxp |
|---|
| 352 | */ |
|---|
| 353 | #endif /* CICPP */ |
|---|
| 354 | { |
|---|
| 355 | char *p; |
|---|
| 356 | #if CICPP |
|---|
| 357 | #else /* CICPP */ |
|---|
| 358 | int callrecinit=1; |
|---|
| 359 | int calltrminit=1; |
|---|
| 360 | #endif /* CICPP */ |
|---|
| 361 | |
|---|
| 362 | #define CIAOTWCT 1 |
|---|
| 363 | #if CIAOTWCT |
|---|
| 364 | if (!isiswctot) { |
|---|
| 365 | memset(isiswctab,0x00,256); |
|---|
| 366 | for (isiswctot=0; isisactab[isiswctot]; isiswctot++) |
|---|
| 367 | isiswctab[isisactab[isiswctot]]=1; |
|---|
| 368 | } |
|---|
| 369 | #endif |
|---|
| 370 | |
|---|
| 371 | for (ndbxs=maxndbx;ndbxs--;) |
|---|
| 372 | vdbxp[ndbxs]=NULL; |
|---|
| 373 | ndbxs=0; |
|---|
| 374 | |
|---|
| 375 | #if CICPP |
|---|
| 376 | #else /* CICPP */ |
|---|
| 377 | /* init vrecp - recinit() - if not init - AOT, 27/10/2005 */ |
|---|
| 378 | if (callrecinit) if (!nrecs) { |
|---|
| 379 | for (nrecs=maxnrec;nrecs--;) vrecp[nrecs]=NULL; |
|---|
| 380 | nrecs=0; |
|---|
| 381 | } |
|---|
| 382 | /* init vtrmp - trminit() - if not init - AOT, 27/10/2005 */ |
|---|
| 383 | if (calltrminit) if (!ntrms) { |
|---|
| 384 | for (ntrms=maxntrm;ntrms--;) vtrmp[ntrms]=NULL; |
|---|
| 385 | ntrms=0; |
|---|
| 386 | } |
|---|
| 387 | #endif /* CICPP */ |
|---|
| 388 | |
|---|
| 389 | |
|---|
| 390 | #if MULTI |
|---|
| 391 | cipnetws=dbxcinet(NULL); |
|---|
| 392 | #endif |
|---|
| 393 | #if CIPAR |
|---|
| 394 | #if MULTI |
|---|
| 395 | p=dbxcipar(NULL,"flock",'='); |
|---|
| 396 | if (dbxcipok) |
|---|
| 397 | if (sscanf(p,"%d",&dbxfloop) != 1) fatal("dbxinit/cipar/flock"); |
|---|
| 398 | p=dbxcipar(NULL,"wlock",'='); |
|---|
| 399 | if (dbxcipok) |
|---|
| 400 | if (sscanf(p,"%d",&dbxwloop) != 1) fatal("dbxinit/cipar/wlock"); |
|---|
| 401 | p=dbxcipar(NULL,"ilock",'='); |
|---|
| 402 | if (dbxcipok) |
|---|
| 403 | if (sscanf(p,"%d",&dbxiloop) != 1) fatal("dbxinit/cipar/ilock"); |
|---|
| 404 | p=dbxcipar(NULL,"uclos",'='); |
|---|
| 405 | if (dbxcipok) |
|---|
| 406 | if (sscanf(p,"%d",&dbxuclos) != 1) fatal("dbxinit/cipar/uclos"); |
|---|
| 407 | p=dbxcipar(NULL,"ewlrc",'='); |
|---|
| 408 | if (dbxcipok) |
|---|
| 409 | if (sscanf(p,"%d",&dbxewlrc) != 1) fatal("dbxinit/cipar/ewlrc"); |
|---|
| 410 | p=dbxcipar(NULL,"sleep",'='); |
|---|
| 411 | if (dbxcipok) |
|---|
| 412 | if (sscanf(p,"%d",&dbxsleep) != 1) fatal("dbxinit/cipar/sleep"); |
|---|
| 413 | #endif |
|---|
| 414 | #if DBXMSTXL |
|---|
| 415 | p=dbxcipar(NULL,"mstxl",'='); |
|---|
| 416 | if (dbxcipok) { |
|---|
| 417 | if (p[strlen(p)-1] == 'G') { |
|---|
| 418 | int num=atoi(p); |
|---|
| 419 | int cap = 1; |
|---|
| 420 | cipmstxl = 1; |
|---|
| 421 | while (num != cap) { |
|---|
| 422 | if (num < cap) { |
|---|
| 423 | fatal("dbxinit/cipar/mstxl/G"); |
|---|
| 424 | } |
|---|
| 425 | cipmstxl++; |
|---|
| 426 | cap *= 2; |
|---|
| 427 | } |
|---|
| 428 | } else { |
|---|
| 429 | if (sscanf(p,"%d",&cipmstxl) != 1) fatal("dbxinit/cipar/mstxl"); |
|---|
| 430 | /*if ((cipmstxl < 0) || (cipmstxl > 4)) fatal("dbxinit/mstxl"); > 4G*/ |
|---|
| 431 | if (cipmstxl < 0) fatal("dbxinit/mstxl"); |
|---|
| 432 | if (cipmstxl == 4) cipmstxl=3; |
|---|
| 433 | } |
|---|
| 434 | } |
|---|
| 435 | #endif |
|---|
| 436 | #ifndef INCLOADX /* AOT, 22/05/2002 */ |
|---|
| 437 | #define INCLOADX 0 |
|---|
| 438 | #endif |
|---|
| 439 | #if INCLOADX |
|---|
| 440 | #define GETACUCTAB 1 |
|---|
| 441 | #endif |
|---|
| 442 | #if GETACUCTAB /* AOT/HB, 15/04/2002 */ |
|---|
| 443 | p=dbxcipar(NULL,"uctab",'='); |
|---|
| 444 | if (dbxcipok) { |
|---|
| 445 | #if GETACUTABANSI |
|---|
| 446 | if (strcmp(p,"ansi") == 0) { |
|---|
| 447 | memcpy(isisuctab,ansiuctab,256/*sizeof(ansiuctab)*/); |
|---|
| 448 | } else { |
|---|
| 449 | #endif |
|---|
| 450 | if (!loaductb(NULL,isisuctab,p)) fatal("dbxinit/uctab"); |
|---|
| 451 | #if GETACUTABANSI |
|---|
| 452 | } |
|---|
| 453 | #endif |
|---|
| 454 | } |
|---|
| 455 | p=dbxcipar(NULL,"actab",'='); |
|---|
| 456 | if (dbxcipok) { |
|---|
| 457 | unsigned char ubuffup[256]; |
|---|
| 458 | memset(isiswctab,0x00,256); |
|---|
| 459 | #if GETACUTABANSI |
|---|
| 460 | if (strcmp(p,"ansi") == 0) { |
|---|
| 461 | for (isiswctot=0; ansiactab[isiswctot]; isiswctot=isiswctot+1) |
|---|
| 462 | isiswctab[ansiactab[isiswctot]]=1; |
|---|
| 463 | } else { |
|---|
| 464 | #endif |
|---|
| 465 | if (!loadactb(NULL,ubuffup,p)) fatal(p); |
|---|
| 466 | for (isiswctot=0; ubuffup[isiswctot]; isiswctot=isiswctot+1) |
|---|
| 467 | isiswctab[ubuffup[isiswctot]]=1; |
|---|
| 468 | #if GETACUTABANSI |
|---|
| 469 | } |
|---|
| 470 | #endif |
|---|
| 471 | } |
|---|
| 472 | #endif /* GETACUCTAB */ |
|---|
| 473 | p=dbxcipar(NULL,"mflush",'='); if (dbxcipok) sscanf(p,"%d",&dbxopt_mflush); |
|---|
| 474 | p=dbxcipar(NULL,"mclose",'='); if (dbxcipok) sscanf(p,"%d",&dbxopt_mclose); |
|---|
| 475 | p=dbxcipar(NULL,"iflush",'='); if (dbxcipok) sscanf(p,"%d",&dbxopt_iflush); |
|---|
| 476 | p=dbxcipar(NULL,"maxmfrl",'='); if (dbxcipok) sscanf(p,"%ld",&rec_maxmfrl); if (rec_maxmfrl < (LONGX)MSNVSPLT || (RECHSIZE+rec_maxmfrl) > ALLOMAXV) rec_maxmfrl=MAXMFRL; |
|---|
| 477 | #if CICPP |
|---|
| 478 | |
|---|
| 479 | #else /* CICPP */ |
|---|
| 480 | fmt_fsiz=rec_maxmfrl; |
|---|
| 481 | #endif /* CICPP */ |
|---|
| 482 | p=dbxcipar(NULL,"mstload",'='); if (dbxcipok) sscanf(p,"%ld",&rec_mstload); |
|---|
| 483 | p=dbxcipar(NULL,"invload",'='); if (dbxcipok) sscanf(p,"%ld",&trm_invload); |
|---|
| 484 | if (strcmp(dbxcipar(NULL,"partrace",'='),YES) == 0) partrace=1; |
|---|
| 485 | if (strcmp(dbxcipar(NULL,"dbxtrace",'='),YES) == 0) dbxtrace=1; |
|---|
| 486 | if (strcmp(dbxcipar(NULL,"rectrace",'='),YES) == 0) rectrace=1; |
|---|
| 487 | if (strcmp(dbxcipar(NULL,"dectrace",'='),YES) == 0) dectrace=1; |
|---|
| 488 | if (strcmp(dbxcipar(NULL,"trmtrace",'='),YES) == 0) trmtrace=1; |
|---|
| 489 | if (strcmp(dbxcipar(NULL,"b40trace",'='),YES) == 0) b40trace=1; |
|---|
| 490 | if (strcmp(dbxcipar(NULL,"b50trace",'='),YES) == 0) b50trace=1; |
|---|
| 491 | if (strcmp(dbxcipar(NULL,"fmttrace",'='),YES) == 0) fmttrace=1; |
|---|
| 492 | if (strcmp(dbxcipar(NULL,"fsttrace",'='),YES) == 0) fsttrace=1; |
|---|
| 493 | if (strcmp(dbxcipar(NULL,"multrace",'='),YES) == 0) multrace=1; |
|---|
| 494 | if (strcmp(dbxcipar(NULL,"cgitrace",'='),YES) == 0) cgitrace=1; |
|---|
| 495 | if (strcmp(dbxcipar(NULL,"adddel" ,'='),YES) == 0) bugadddel=0; |
|---|
| 496 | if (strcmp(dbxcipar(NULL,"what" ,'='),YES) == 0) printf("%s",cicopyr("?")); |
|---|
| 497 | #endif /* CIPAR */ |
|---|
| 498 | } |
|---|
| 499 | |
|---|
| 500 | #if CICPP |
|---|
| 501 | //DBXSTRU * DBXSTRU :: xdbxsrchp(char *dbnamp) |
|---|
| 502 | DBXSTRU * CISISX :: xdbxsrchp(char *dbnamp) |
|---|
| 503 | #else /* CICPP */ |
|---|
| 504 | DBXSTRU *dbxsrchp(dbnamp) /* |
|---|
| 505 | ----------------- |
|---|
| 506 | procura strcmp(dbxp->dbxname,dbnamp) == 0; |
|---|
| 507 | retorna NULL ou dbxp |
|---|
| 508 | */ |
|---|
| 509 | char *dbnamp; /* ptr nome base de dados */ |
|---|
| 510 | #endif /* CICPP */ |
|---|
| 511 | { |
|---|
| 512 | DBXSTRU *dbxp; |
|---|
| 513 | LONGX idbx; |
|---|
| 514 | |
|---|
| 515 | if (!ndbxs) |
|---|
| 516 | return(NULL); |
|---|
| 517 | |
|---|
| 518 | for (idbx=ndbxs; idbx--; ) { |
|---|
| 519 | dbxp=vdbxp[idbx]; |
|---|
| 520 | if (strcmp(DBXname,dbnamp) == 0) return(dbxp); |
|---|
| 521 | } |
|---|
| 522 | |
|---|
| 523 | return(NULL); |
|---|
| 524 | } |
|---|
| 525 | |
|---|
| 526 | #if CICPP |
|---|
| 527 | DBXSTRU * CISISX :: xdbxstorp(char *dbnamp) |
|---|
| 528 | #else /* CICPP */ |
|---|
| 529 | DBXSTRU *dbxstorp(dbnamp) /* |
|---|
| 530 | ----------------- |
|---|
| 531 | procura dbxsrchp(dbnamp); |
|---|
| 532 | se nao achou, aloca e inicializa celula; |
|---|
| 533 | retorna dbxp |
|---|
| 534 | */ |
|---|
| 535 | char *dbnamp; /* ptr nome base de dados */ |
|---|
| 536 | #endif /* CICPP */ |
|---|
| 537 | { |
|---|
| 538 | DBXSTRU *dbxp; |
|---|
| 539 | #if DBXTRAC0 |
|---|
| 540 | LONGX idbx; |
|---|
| 541 | #endif /* DBXTRAC0 */ |
|---|
| 542 | #if !CICPP |
|---|
| 543 | LONGX lval; |
|---|
| 544 | #endif /* CICPP */ |
|---|
| 545 | |
|---|
| 546 | if (!ndbxs) |
|---|
| 547 | dbxinit(); |
|---|
| 548 | |
|---|
| 549 | if (!dbnamp) fatal("dbxstorp/dbnamp"); /* AOT,HB 31/07/2002 */ |
|---|
| 550 | |
|---|
| 551 | if ((dbxp=dbxsrchp(dbnamp)) != NULL) |
|---|
| 552 | return(dbxp); |
|---|
| 553 | |
|---|
| 554 | if (ndbxs >= maxndbx) |
|---|
| 555 | fatal("dbxstorp/overflow"); |
|---|
| 556 | |
|---|
| 557 | #if CICPP |
|---|
| 558 | try { dbxp = new DBXSTRU(this); } |
|---|
| 559 | catch (BAD_ALLOC) { dbxp=(DBXSTRU *)ALLONULL; } |
|---|
| 560 | #else /* CICPP */ |
|---|
| 561 | lval=sizeof(DBXSTRU); |
|---|
| 562 | if (lval > ALLOMAXV) |
|---|
| 563 | fatal("dbxstorp/ALLOMAXV/sizeof(DBXSTRU)"); |
|---|
| 564 | dbxp=(DBXSTRU *)ALLOC((ALLOPARM)(sizeof(DBXSTRU))); |
|---|
| 565 | #endif /* CICPP */ |
|---|
| 566 | if (dbxp == (DBXSTRU *)ALLONULL) |
|---|
| 567 | fatal("dbxstorp/ALLOC"); |
|---|
| 568 | |
|---|
| 569 | #if !CICPP |
|---|
| 570 | memset(dbxp,0x00,sizeof(DBXSTRU)); |
|---|
| 571 | #endif /* CICPP */ |
|---|
| 572 | |
|---|
| 573 | #if USE_VDBXP |
|---|
| 574 | vdbxp[ndbxs++]=dbxp; |
|---|
| 575 | #else |
|---|
| 576 | vdbxp[ndbxs++]=dbxp; |
|---|
| 577 | #endif |
|---|
| 578 | |
|---|
| 579 | if (strlen(dbnamp) > (CIMPL - 4 - 1)) |
|---|
| 580 | fatal("dbxstorp/name"); |
|---|
| 581 | strcpy(DBXname,dbnamp); |
|---|
| 582 | |
|---|
| 583 | #if DBXTRAC0 |
|---|
| 584 | printf("dbxstorp - dbnamp='%s' DBXname='%s' p=%p ndbxs=%ld\n", |
|---|
| 585 | dbnamp,DBXname,vdbxp[ndbxs-1],ndbxs); |
|---|
| 586 | for (idbx=0L; idbx < ndbxs; idbx++) |
|---|
| 587 | printf("+++%ld/%ld %s p=%p \n",idbx,ndbxs,VDBXname(idbx),vdbxp[idbx]); |
|---|
| 588 | #endif |
|---|
| 589 | |
|---|
| 590 | DBXmsmfn=0; /* v3.0 */ |
|---|
| 591 | |
|---|
| 592 | #if MULTI |
|---|
| 593 | DBXnetws=dbxcinet(DBXname); |
|---|
| 594 | #endif |
|---|
| 595 | |
|---|
| 596 | DBXmflush= dbxopt_mflush; |
|---|
| 597 | DBXmclose= dbxopt_mclose; |
|---|
| 598 | DBXiflush= dbxopt_iflush; |
|---|
| 599 | |
|---|
| 600 | return(dbxp); |
|---|
| 601 | } |
|---|
| 602 | |
|---|
| 603 | #if CICPP |
|---|
| 604 | int CISISX :: xdbxopen(char *gidbnp, |
|---|
| 605 | char *dbname, |
|---|
| 606 | char *extp) |
|---|
| 607 | #else /* CICPP */ |
|---|
| 608 | int dbxopen(gidbnp,dbname,extp) /* |
|---|
| 609 | ----------- |
|---|
| 610 | abre dbxname.ext; |
|---|
| 611 | retorna OPEN(dbxname.ext,...); |
|---|
| 612 | */ |
|---|
| 613 | char *gidbnp; /* dbn.par */ |
|---|
| 614 | char *dbname; /* string + 4 + 1 */ |
|---|
| 615 | char *extp; /* .ext */ |
|---|
| 616 | #endif /* CICPP */ |
|---|
| 617 | { |
|---|
| 618 | #if !MSC |
|---|
| 619 | #if BEFORE20000413 |
|---|
| 620 | extern int errno; |
|---|
| 621 | #endif |
|---|
| 622 | #endif |
|---|
| 623 | int fd; |
|---|
| 624 | char filname[CIMPL+1]; |
|---|
| 625 | |
|---|
| 626 | #if DBXTRAC1 |
|---|
| 627 | printf("dbxopen - [%s.par] dbname='%s' len=%d\n",gidbnp,dbname,strlen(dbname)); |
|---|
| 628 | #endif |
|---|
| 629 | |
|---|
| 630 | if (!extp) extp=""; |
|---|
| 631 | |
|---|
| 632 | strcpy(filname,dbname); |
|---|
| 633 | strcat(filname,extp); |
|---|
| 634 | |
|---|
| 635 | strcpy(filname,dbxcipar(gidbnp,filname,'=')); |
|---|
| 636 | #if DBXTRAC1 |
|---|
| 637 | printf("dbxopen - filename='%s' len=%d\n",filname,strlen(filname)); |
|---|
| 638 | #endif |
|---|
| 639 | |
|---|
| 640 | dbxordwr = (dbxopt_ordwr & O_RDWR) ? 1 : 0; /* dbxopt_ordwr & O_RDWR */ |
|---|
| 641 | |
|---|
| 642 | #if MULTI || CDMDL |
|---|
| 643 | #if MSC |
|---|
| 644 | fd=OPEN(filname,O_BINARY|dbxopt_ordwr,SH_DENYNO); |
|---|
| 645 | #else |
|---|
| 646 | fd=OPEN(filname,O_BINARY|dbxopt_ordwr|O_DENYNONE); |
|---|
| 647 | #endif |
|---|
| 648 | #else |
|---|
| 649 | fd=OPEN(filname,O_BINARY|dbxopt_ordwr); |
|---|
| 650 | #endif |
|---|
| 651 | |
|---|
| 652 | if (fd == EOF) { |
|---|
| 653 | if (dbxopt_fatal) { /* v4.2 */ |
|---|
| 654 | #if 0 |
|---|
| 655 | #ifdef USE_ERROR_SYS |
|---|
| 656 | errsys->sys_error(filname); |
|---|
| 657 | #else |
|---|
| 658 | if (dbxopt_errno) |
|---|
| 659 | fprintf(cistderr,"dbxopen: '%s' errno=%d",filname,errno); |
|---|
| 660 | #endif |
|---|
| 661 | #if FATRAP |
|---|
| 662 | if (fatal_iomsg[0]) { |
|---|
| 663 | sprintf(fatal_iomsg,"dbxopen: %s (%d)",filname,errno); |
|---|
| 664 | fatal(fatal_iomsg); |
|---|
| 665 | } |
|---|
| 666 | #endif |
|---|
| 667 | #endif /* 0 */ |
|---|
| 668 | #if !CICPP |
|---|
| 669 | #if WWWISIS |
|---|
| 670 | sprintf(fatal_iomsg,"dbxopen: %s (%d)",filname,errno); |
|---|
| 671 | fatal(fatal_iomsg); |
|---|
| 672 | #else /* !WWWISIS */ |
|---|
| 673 | if (dbxopt_errno) |
|---|
| 674 | fprintf(cistderr,"dbxopen: '%s' errno=%d",filname,errno); |
|---|
| 675 | #if FATRAP |
|---|
| 676 | if (fatal_iomsg[0]) { |
|---|
| 677 | sprintf(fatal_iomsg,"dbxopen: %s (%d)",filname,errno); |
|---|
| 678 | fatal(fatal_iomsg); |
|---|
| 679 | } |
|---|
| 680 | #endif /* FATRAP */ |
|---|
| 681 | #endif /* !WWWISIS */ |
|---|
| 682 | #endif /* !CICPP */ |
|---|
| 683 | #ifdef ISIS_DLL |
|---|
| 684 | char fatal_msg[256]; |
|---|
| 685 | sprintf(fatal_msg,"dbxopen: %s (%d)",filname,errno); |
|---|
| 686 | fatal(fatal_msg); |
|---|
| 687 | #endif /* ISIS_DLL */ |
|---|
| 688 | |
|---|
| 689 | fatal("dbxopen/open"); |
|---|
| 690 | } |
|---|
| 691 | } |
|---|
| 692 | dbxopt_fatal=1; /* set default value */ |
|---|
| 693 | |
|---|
| 694 | if (dbxtrace) |
|---|
| 695 | printf("dbxopen - %s fd=%d [%s]\n",filname,fd,dbxordwr?"RW":"R"); |
|---|
| 696 | |
|---|
| 697 | if (fd == 0) |
|---|
| 698 | fatal("dbxopen/fd=0"); |
|---|
| 699 | |
|---|
| 700 | return(fd); |
|---|
| 701 | } |
|---|
| 702 | |
|---|
| 703 | |
|---|
| 704 | #if CICPP |
|---|
| 705 | int CISISX :: xdbxopenw(char *gidbnp, |
|---|
| 706 | char *dbname, |
|---|
| 707 | char *extp, |
|---|
| 708 | int *opnp, |
|---|
| 709 | int *opwp, |
|---|
| 710 | char *errmsgp) |
|---|
| 711 | #else /* CICPP */ |
|---|
| 712 | int dbxopenw(gidbnp,dbname,extp,opnp,opwp,errmsgp) /* |
|---|
| 713 | ------------ |
|---|
| 714 | abre dbxname.ext para O_RDWR; |
|---|
| 715 | retorna OPEN(dbxname.ext,...); |
|---|
| 716 | */ |
|---|
| 717 | char *gidbnp; /* dbn.par */ |
|---|
| 718 | char *dbname; /* string + 4 + 1 */ |
|---|
| 719 | char *extp; /* .ext */ |
|---|
| 720 | int *opnp; |
|---|
| 721 | int *opwp; |
|---|
| 722 | char *errmsgp; |
|---|
| 723 | #endif /* CICPP */ |
|---|
| 724 | { |
|---|
| 725 | int n,opn=0,opw=0; |
|---|
| 726 | |
|---|
| 727 | if (opnp) opn= *opnp; |
|---|
| 728 | if (opwp) opw= *opwp; |
|---|
| 729 | if (!errmsgp) errmsgp="dbxopenw"; |
|---|
| 730 | |
|---|
| 731 | #if 1 /* DBXTRACw */ |
|---|
| 732 | if (dbxtrace) |
|---|
| 733 | printf("dbxopenw - [%s.par] dbname='%s' extp=%s opn/opw=%d/%d '%s'\n", |
|---|
| 734 | gidbnp,dbname,extp,opn,opw,errmsgp); |
|---|
| 735 | #endif |
|---|
| 736 | |
|---|
| 737 | if (opw) { |
|---|
| 738 | if (opn <= 0) fatal("dbxopenw/opw/opn"); |
|---|
| 739 | return(opn); |
|---|
| 740 | } |
|---|
| 741 | |
|---|
| 742 | if (opn > 0) CLOSE(opn); |
|---|
| 743 | |
|---|
| 744 | n=dbxopt_ordwr; dbxopt_ordwr=O_RDWR; dbxopt_fatal=0; |
|---|
| 745 | #if HASTOBETHESAME |
|---|
| 746 | if (opn > 0) { |
|---|
| 747 | if (dbxopen(gidbnp,dbname,extp) != opn) fatal(errmsgp); |
|---|
| 748 | } else |
|---|
| 749 | #endif |
|---|
| 750 | opn=dbxopen(gidbnp,dbname,extp); dbxopt_ordwr=n; |
|---|
| 751 | if (opn <= 0) if (errmsgp) fatal(errmsgp); |
|---|
| 752 | opw++; |
|---|
| 753 | |
|---|
| 754 | if (opnp) *opnp=opn; |
|---|
| 755 | if (opwp) *opwp=opw; |
|---|
| 756 | |
|---|
| 757 | #if DBXTRACw |
|---|
| 758 | printf("dbxopenw - dbname='%s' extp=%s opn/opw=%d/%d \n", |
|---|
| 759 | dbname,extp,opn,opw); |
|---|
| 760 | #endif |
|---|
| 761 | |
|---|
| 762 | return(opn); |
|---|
| 763 | } |
|---|
| 764 | |
|---|
| 765 | #if CICPP |
|---|
| 766 | char *CISISX :: xdbxopenc(char *gidbnp, |
|---|
| 767 | char *filnamp, |
|---|
| 768 | int *opnp, |
|---|
| 769 | int *opwp, |
|---|
| 770 | char *errmsgp, |
|---|
| 771 | int xcreate, |
|---|
| 772 | int xappend) |
|---|
| 773 | #else /* CICPP */ |
|---|
| 774 | char *dbxopenc(gidbnp,filnamp,opnp,opwp,errmsgp,xcreate,xappend) /* |
|---|
| 775 | ------------ |
|---|
| 776 | create filnamp + abre para O_RDWR; |
|---|
| 777 | retorna filnamp ou filnamp+strlen("create="); |
|---|
| 778 | */ |
|---|
| 779 | char *gidbnp; /* dbn.par */ |
|---|
| 780 | char *filnamp; |
|---|
| 781 | int *opnp; |
|---|
| 782 | int *opwp; |
|---|
| 783 | char *errmsgp; |
|---|
| 784 | int xcreate; |
|---|
| 785 | int xappend; |
|---|
| 786 | #endif /* CICPP */ |
|---|
| 787 | { |
|---|
| 788 | char *p; |
|---|
| 789 | int fd,create=0,append=0,chkc=0; |
|---|
| 790 | |
|---|
| 791 | #if DBXTRACw |
|---|
| 792 | printf("dbxopenc - [%s.par] '%s' \n",gidbnp,filnamp); |
|---|
| 793 | #endif |
|---|
| 794 | |
|---|
| 795 | p=filnamp; |
|---|
| 796 | while (strncmp(p,"append=",7) == 0 || strncmp(p,"create=",7) == 0) { |
|---|
| 797 | if (strncmp(p,"append=",7) == 0) { p+=7; append=1; } |
|---|
| 798 | if (strncmp(p,"create=",7) == 0) { p+=7; create=1; } else chkc=1; |
|---|
| 799 | } |
|---|
| 800 | filnamp=p; |
|---|
| 801 | |
|---|
| 802 | p=dbxcipar(gidbnp,filnamp,'='); |
|---|
| 803 | |
|---|
| 804 | if (chkc || xappend) { |
|---|
| 805 | dbxopt_fatal=0; fd=dbxopen(NULL,p,""); |
|---|
| 806 | if (fd <=0 ) create=1; else CLOSE(fd); |
|---|
| 807 | } |
|---|
| 808 | |
|---|
| 809 | if (create || xcreate) { |
|---|
| 810 | fd=CREAT(p,PERMIS); |
|---|
| 811 | if (fd <= 0) if (errmsgp) fatal(errmsgp); |
|---|
| 812 | CLOSE(fd); |
|---|
| 813 | } |
|---|
| 814 | |
|---|
| 815 | fd=dbxopenw(NULL,p,"",NULL,opwp,errmsgp); |
|---|
| 816 | if (fd > 0) |
|---|
| 817 | if (append || xappend) LSEEK64(fd,0L,SEEK_END); |
|---|
| 818 | else LSEEK64(fd,0L,SEEK_SET); /* rewind */ |
|---|
| 819 | |
|---|
| 820 | *opnp=fd; |
|---|
| 821 | |
|---|
| 822 | #if DBXTRACw |
|---|
| 823 | printf("dbxopenc - '%s' = %d \n",p,fd); |
|---|
| 824 | #endif |
|---|
| 825 | |
|---|
| 826 | return(p); |
|---|
| 827 | } |
|---|
| 828 | |
|---|
| 829 | /* |
|---|
| 830 | gidbnp: db name | "" (to use aknamp.par) | NULL (skip dbn.par) |
|---|
| 831 | argkey: file name | <parmno>= |
|---|
| 832 | *namlenp: file name length |
|---|
| 833 | *extlenp: .extension length |
|---|
| 834 | */ |
|---|
| 835 | |
|---|
| 836 | #if GIPAR |
|---|
| 837 | #if CICPP |
|---|
| 838 | char * CISISX :: xdbxgipar(char *gidbnp, |
|---|
| 839 | char *ginamp, |
|---|
| 840 | int *namlenp, |
|---|
| 841 | int *extlenp) |
|---|
| 842 | #else /* CICPP */ |
|---|
| 843 | char *dbxgipar(gidbnp,ginamp,namlenp,extlenp) |
|---|
| 844 | char *gidbnp; /* dbn / "" / NULL */ |
|---|
| 845 | char *ginamp; /* name.ext / <parmno>= */ |
|---|
| 846 | int *namlenp; /* */ |
|---|
| 847 | int *extlenp; /* */ |
|---|
| 848 | #endif /* CICPP */ |
|---|
| 849 | { |
|---|
| 850 | DBXSTRU *dbxp; |
|---|
| 851 | char *p,*q,*nextlinp,*extp,*fnp; |
|---|
| 852 | int parameter,i,n,naml,fnl; |
|---|
| 853 | int ginnn=0; |
|---|
| 854 | LONGX keepndbx,idbx; |
|---|
| 855 | char tmpgikey[sizeof(dbxgikey)]; /* dbxgipar() tmp */ |
|---|
| 856 | |
|---|
| 857 | if (!ginamp || !*ginamp) return(dbxgikey); |
|---|
| 858 | |
|---|
| 859 | /* setup returning value */ |
|---|
| 860 | naml=strlen(ginamp); |
|---|
| 861 | if (naml >= sizeof(dbxgikey)) naml=sizeof(dbxgikey)-1; |
|---|
| 862 | memcpy(dbxgikey,ginamp,naml); dbxgikey[naml]='\0'; |
|---|
| 863 | |
|---|
| 864 | extp=""; |
|---|
| 865 | for (p=dbxgikey+naml-1, n=naml; n; p--, n--) { |
|---|
| 866 | if (*p == '/') break; |
|---|
| 867 | if (*p == '\\') break; |
|---|
| 868 | if (*p == '.') { |
|---|
| 869 | extp=p; |
|---|
| 870 | break; |
|---|
| 871 | } |
|---|
| 872 | } |
|---|
| 873 | if (namlenp) *namlenp=naml; |
|---|
| 874 | if (extlenp) *extlenp=strlen(extp); |
|---|
| 875 | |
|---|
| 876 | if (!gidbnp) return(dbxgikey); |
|---|
| 877 | |
|---|
| 878 | /* alloc&load dbxgicip */ |
|---|
| 879 | memcpy(tmpgikey,dbxgikey,naml); |
|---|
| 880 | tmpgikey[naml-strlen(extp)]='\0'; |
|---|
| 881 | keepndbx=ndbxs; dbxp=dbxstorp((*gidbnp)?gidbnp:tmpgikey); |
|---|
| 882 | if (dbxp) { |
|---|
| 883 | if (!DBXgicip) { |
|---|
| 884 | strcpy(tmpgikey,DBXname); |
|---|
| 885 | strcat(tmpgikey,".par"); |
|---|
| 886 | DBXgicip=loadfile(NULL,'\0',tmpgikey,NULL,0L,'\n'); |
|---|
| 887 | } |
|---|
| 888 | } |
|---|
| 889 | |
|---|
| 890 | /* flush new vdbxp[] entry */ |
|---|
| 891 | if (!DBXgicip) { |
|---|
| 892 | for (idbx=ndbxs-1; idbx>=keepndbx; idbx--) |
|---|
| 893 | dbxflush(vdbxp[idbx]->dbxname); |
|---|
| 894 | return(dbxgikey); |
|---|
| 895 | } |
|---|
| 896 | |
|---|
| 897 | n=strlen(dbxgikey); extp=""; |
|---|
| 898 | for (p=dbxgikey+n-1; n; p--, n--) { |
|---|
| 899 | if (*p == '/') break; |
|---|
| 900 | if (*p == '\\') break; |
|---|
| 901 | if (*p == '.') { |
|---|
| 902 | extp=p; |
|---|
| 903 | break; |
|---|
| 904 | } |
|---|
| 905 | } |
|---|
| 906 | |
|---|
| 907 | for (i=0; dbxgiext[i]; i++) |
|---|
| 908 | #if !BRME |
|---|
| 909 | if (memicmp(dbxgiext[i],extp,strlen(extp)) == 0) { |
|---|
| 910 | #else |
|---|
| 911 | if (strcmp(dbxgiext[i],extp) == 0) { |
|---|
| 912 | #endif |
|---|
| 913 | ginnn=dbxgiexn[i]; |
|---|
| 914 | break; |
|---|
| 915 | } |
|---|
| 916 | |
|---|
| 917 | if (DBXgicip) for (q=DBXgicip; *q; ) { |
|---|
| 918 | |
|---|
| 919 | for (p=q; *p; nextlinp=p) |
|---|
| 920 | if (*p == '\n' || *p == '\r') { |
|---|
| 921 | while (*p == '\n' || *p == '\r') p++; |
|---|
| 922 | nextlinp=p; |
|---|
| 923 | break; |
|---|
| 924 | } else p++; |
|---|
| 925 | |
|---|
| 926 | while (isspace(*q)) q++; |
|---|
| 927 | |
|---|
| 928 | parameter=atoi(q); |
|---|
| 929 | if (parameter == ginnn) { |
|---|
| 930 | q=strchr(q,'='); |
|---|
| 931 | if (q) { |
|---|
| 932 | q++; /* '=' */ |
|---|
| 933 | while (isspace(*q)) q++; |
|---|
| 934 | for (n=0, p=q; *p; p++, n++) |
|---|
| 935 | if (*p == '\n' || *p == '\r') { |
|---|
| 936 | |
|---|
| 937 | for (p=q+n-1; n; ) |
|---|
| 938 | if (isspace(*p)) { p--; n--;} else break; |
|---|
| 939 | |
|---|
| 940 | fnp=NULL; |
|---|
| 941 | for (fnl=naml-strlen(extp), p=dbxgikey+fnl-1; fnl > 1; p--, fnl--) { |
|---|
| 942 | if (*p == '/' || *p == '\\' || *p == ':') { fnp=p+1; break; } |
|---|
| 943 | } |
|---|
| 944 | if (!fnp) fnp=dbxgikey; |
|---|
| 945 | fnl=strlen(p); |
|---|
| 946 | memcpy(tmpgikey,fnp,fnl); tmpgikey[fnl]='\0'; |
|---|
| 947 | if (fnl+n >= sizeof(dbxgikey)) n=sizeof(dbxgikey)-fnl-1; |
|---|
| 948 | memcpy(dbxgikey,q,n); |
|---|
| 949 | memcpy(dbxgikey+n,tmpgikey,fnl); |
|---|
| 950 | dbxgikey[n+fnl]='\0'; |
|---|
| 951 | |
|---|
| 952 | #if DBGTRACE |
|---|
| 953 | if (dbxtrace) printf("dbxgipar - %s - %s=%s #%d\n", |
|---|
| 954 | gidbnp,ginamp,dbxgikey,ginnn); |
|---|
| 955 | #endif |
|---|
| 956 | break; |
|---|
| 957 | } |
|---|
| 958 | break; |
|---|
| 959 | } |
|---|
| 960 | } |
|---|
| 961 | else q=nextlinp; |
|---|
| 962 | } |
|---|
| 963 | |
|---|
| 964 | return(dbxgikey); |
|---|
| 965 | } |
|---|
| 966 | #endif /* GIPAR */ |
|---|
| 967 | |
|---|
| 968 | #if CICPP |
|---|
| 969 | int CISISX :: xdbxciset(char *cipfile) |
|---|
| 970 | #else /* CICPP */ |
|---|
| 971 | int dbxciset(cipfile) |
|---|
| 972 | char *cipfile; |
|---|
| 973 | #endif /* CICPP */ |
|---|
| 974 | { |
|---|
| 975 | dbxcdcip=NULL; |
|---|
| 976 | if (cipfile) if (*cipfile) { |
|---|
| 977 | dbxcdcip=loadfile(NULL,'\0',cipfile,NULL,EOF,'\n'); // env |
|---|
| 978 | if (!dbxcdcip) return(1); //fatal("dbxciset/cipfile"); |
|---|
| 979 | } |
|---|
| 980 | |
|---|
| 981 | dbxcipfp=NULL; |
|---|
| 982 | memset(dbxcikey,0x00,sizeof(dbxcikey)); |
|---|
| 983 | dbxcipok=0; |
|---|
| 984 | |
|---|
| 985 | #if CIWTF |
|---|
| 986 | /* alloc global AWTFUN - if not alloc - AOT, 19/01/2006 */ |
|---|
| 987 | if (!ciawtfp) { |
|---|
| 988 | ciawtfp=wtfnew(0); // new |
|---|
| 989 | if (!ciawtfp) return(2); //fatal("dbxciset/ciawtfp"); |
|---|
| 990 | } |
|---|
| 991 | #endif /* CIWTF */ |
|---|
| 992 | |
|---|
| 993 | dbxinit(); // par |
|---|
| 994 | |
|---|
| 995 | #if CIWTF |
|---|
| 996 | /* init global AWTFUN - if not init - AOT, 20/01/2006 */ |
|---|
| 997 | if (!/*awtmaxmfrl*/ciawtfp->globalmaxmfrl) { |
|---|
| 998 | wtfset(0,ciawtfp,dbxcdcip); // set |
|---|
| 999 | if (!/*awtmaxmfrl*/ciawtfp->globalmaxmfrl) return(3); //fatal("dbxciset/ciawtfp/set"); |
|---|
| 1000 | } |
|---|
| 1001 | #endif /* CIWTF */ |
|---|
| 1002 | |
|---|
| 1003 | //dbxcipar(NULL,"eval.1",'='); |
|---|
| 1004 | //if (dbxcipok) sss=dbxcikey; // eval |
|---|
| 1005 | |
|---|
| 1006 | return(0); |
|---|
| 1007 | } |
|---|
| 1008 | |
|---|
| 1009 | #if CICPP |
|---|
| 1010 | char * CISISX :: xdbxcipar(char *gidbnp, |
|---|
| 1011 | char *argkey, |
|---|
| 1012 | char argchar) |
|---|
| 1013 | |
|---|
| 1014 | #else /* CICPP */ |
|---|
| 1015 | |
|---|
| 1016 | char *dbxcipar(gidbnp, argkey, argchar) |
|---|
| 1017 | char *gidbnp; |
|---|
| 1018 | char argkey[]; |
|---|
| 1019 | char argchar; |
|---|
| 1020 | |
|---|
| 1021 | #endif /* CICPP */ |
|---|
| 1022 | { |
|---|
| 1023 | int keyl; |
|---|
| 1024 | UBYTE *retp; |
|---|
| 1025 | char *argkp; |
|---|
| 1026 | |
|---|
| 1027 | #if CIPAR |
|---|
| 1028 | UBYTE *p,*p1,*p2; |
|---|
| 1029 | int n,xl; |
|---|
| 1030 | UBYTE line[BUFSIZ]; |
|---|
| 1031 | UBYTE ibuf[BUFSIZ]; |
|---|
| 1032 | UBYTE *cip; |
|---|
| 1033 | #endif |
|---|
| 1034 | |
|---|
| 1035 | dbxcipok=0; |
|---|
| 1036 | argkp=argkey; |
|---|
| 1037 | #if GIPAR |
|---|
| 1038 | if (gidbnp) argkp=dbxgipar(gidbnp,argkey,NULL,NULL); |
|---|
| 1039 | #else |
|---|
| 1040 | gidbnp=gidbnp; /* no wrn */ |
|---|
| 1041 | #endif |
|---|
| 1042 | |
|---|
| 1043 | keyl=strlen(argkp); |
|---|
| 1044 | if (keyl >= sizeof(dbxcikey)) keyl=sizeof(dbxcikey)-1; |
|---|
| 1045 | retp=(UBYTE *)memcpy(dbxcikey,argkp,keyl); retp[keyl]='\0'; |
|---|
| 1046 | |
|---|
| 1047 | #if CIPAR /* CIPAR */ |
|---|
| 1048 | |
|---|
| 1049 | #if PC || UNIX |
|---|
| 1050 | if (!dbxcdcip && !dbxcipfp) { |
|---|
| 1051 | if ((p=(UBYTE *)getenv("CIPAR")) == NULL) p=(UBYTE *)getenv("cipar"); |
|---|
| 1052 | if (p) if ((dbxcipfp=fopen((CONST char *)p,"r")) == NULL) fatal((char *)p); |
|---|
| 1053 | } |
|---|
| 1054 | #endif |
|---|
| 1055 | |
|---|
| 1056 | if (dbxcipfp) |
|---|
| 1057 | rewind(dbxcipfp); /* fseek(dbxcipfp,0L,SEEK_SET); */ |
|---|
| 1058 | |
|---|
| 1059 | *ibuf='\0'; |
|---|
| 1060 | cip = (dbxcdcip) ? (UBYTE *)dbxcdcip : ((dbxcipfp) ? ibuf : NULL); |
|---|
| 1061 | /* |
|---|
| 1062 | if (dbxcdcip) cip=dbxcdcip; |
|---|
| 1063 | else if (dbxcipfp) cip=ibuf; else cip=NULL; |
|---|
| 1064 | */ |
|---|
| 1065 | |
|---|
| 1066 | if (cip) { |
|---|
| 1067 | for (p=cip; ; ) { |
|---|
| 1068 | n=1; |
|---|
| 1069 | if (!*p) { |
|---|
| 1070 | n=0; |
|---|
| 1071 | if (dbxcipfp) |
|---|
| 1072 | if (fgets((char *)(p=cip),BUFSIZ-1,dbxcipfp)) |
|---|
| 1073 | if (*p) |
|---|
| 1074 | n=1; |
|---|
| 1075 | } |
|---|
| 1076 | if (!n) break; |
|---|
| 1077 | #if 0 |
|---|
| 1078 | printf("n=%d *p=%c\n",n,*p); |
|---|
| 1079 | #endif |
|---|
| 1080 | while (isspace(*p) || *p == ';') p++; |
|---|
| 1081 | for (xl=0; *p; p++) { |
|---|
| 1082 | /* if (isspace(*p) || *p == ';') break; RP, 29/03/2001 */ |
|---|
| 1083 | if ((isspace(*p) && *p != ' ') || *p == ';') break; /* RP, 29/03/2001 */ |
|---|
| 1084 | line[xl++] = *p; |
|---|
| 1085 | } |
|---|
| 1086 | if (xl <= keyl) |
|---|
| 1087 | for (n=keyl-xl; n >= 0; n--) line[keyl-n]='"'; |
|---|
| 1088 | #if 0 |
|---|
| 1089 | printf("?%s%c - xl=%d=",argkp,line[keyl],xl); |
|---|
| 1090 | for (n=0; n < keyl; n++) printf("%c(%02x)",line[n],line[n]); |
|---|
| 1091 | getchar(); |
|---|
| 1092 | #endif |
|---|
| 1093 | if (xl == 0) continue; |
|---|
| 1094 | line[xl]='\0'; |
|---|
| 1095 | if (xl == 2) if (line[0] == '/') if (line[1] == '*') break; |
|---|
| 1096 | #if CIPARIC |
|---|
| 1097 | if (memicmp(line,argkp,n=keyl) == 0) { |
|---|
| 1098 | #else |
|---|
| 1099 | if (memcmp(line,argkp,n=keyl) == 0) { |
|---|
| 1100 | #endif |
|---|
| 1101 | if (line[n] == argchar) { |
|---|
| 1102 | retp=(UBYTE *) |
|---|
| 1103 | memcpy(dbxcikey,line+(n+1),strlen((CONST char *)line+n)); /*'\0'*/ |
|---|
| 1104 | dbxcipok=1; |
|---|
| 1105 | break; |
|---|
| 1106 | } |
|---|
| 1107 | } |
|---|
| 1108 | for (p1=line, p2=(UBYTE *)argkp; ; p1++, p2++) { |
|---|
| 1109 | #if CIPARIC |
|---|
| 1110 | if (toupper(*p1) == toupper(*p2)) continue; |
|---|
| 1111 | #else |
|---|
| 1112 | if (*p1 == *p2) continue; |
|---|
| 1113 | #endif |
|---|
| 1114 | if (*p1 == '*') { |
|---|
| 1115 | if (*(p1+1) != argchar) continue; |
|---|
| 1116 | if (line[xl-1] != '*') continue; |
|---|
| 1117 | p1++; p1++; |
|---|
| 1118 | line[xl-1]='\0'; |
|---|
| 1119 | retp=(UBYTE *)memcpy(dbxcikey,p1,n=strlen((CONST char *)p1)); |
|---|
| 1120 | memcpy(dbxcikey+n,p2,strlen((CONST char *)p2)+1); /*'\0'*/ |
|---|
| 1121 | dbxcipok=1; |
|---|
| 1122 | break; |
|---|
| 1123 | } |
|---|
| 1124 | break; |
|---|
| 1125 | } |
|---|
| 1126 | } |
|---|
| 1127 | } |
|---|
| 1128 | |
|---|
| 1129 | #endif /* CIPAR */ |
|---|
| 1130 | |
|---|
| 1131 | #if UC_EXTENSION |
|---|
| 1132 | n=strlen(retp); |
|---|
| 1133 | for (p=retp+n-1; n; p--, n--) { |
|---|
| 1134 | if (*p == '/') break; |
|---|
| 1135 | if (*p == '\\') break; |
|---|
| 1136 | if (*p == '.') { |
|---|
| 1137 | for (p=p+1; *p; p++) if (islower(*p)) *p = toupper(*p); |
|---|
| 1138 | break; |
|---|
| 1139 | } |
|---|
| 1140 | } |
|---|
| 1141 | #endif |
|---|
| 1142 | |
|---|
| 1143 | if (dbxtrace) |
|---|
| 1144 | if (partrace || strcmp(argkey,(CONST char *)retp)) |
|---|
| 1145 | printf("dbxcipar - %s%c%s\n",argkey,argchar,retp); |
|---|
| 1146 | |
|---|
| 1147 | return((char *)retp); |
|---|
| 1148 | } |
|---|
| 1149 | |
|---|
| 1150 | #if RECGIZM |
|---|
| 1151 | #if CICPP |
|---|
| 1152 | void CISISX :: xgizflush(VGIZPSTRU *vgizmap) |
|---|
| 1153 | #else /* CICPP */ |
|---|
| 1154 | void gizflush(vgizmap) /* |
|---|
| 1155 | ------------- |
|---|
| 1156 | seta dbxp; |
|---|
| 1157 | faz close dos arquivos abertos do master file |
|---|
| 1158 | */ |
|---|
| 1159 | VGIZPSTRU *vgizmap; /* gizmo to be flushed */ |
|---|
| 1160 | #endif /* CICPP */ |
|---|
| 1161 | { |
|---|
| 1162 | VGIZPSTRU *nxtp; |
|---|
| 1163 | GIZMSTRU *gizmhp,*gizmp,*gizmnp; |
|---|
| 1164 | int i; |
|---|
| 1165 | |
|---|
| 1166 | if (dbxtrace) printf("gizflush - vgizmap=%p\n",vgizmap); |
|---|
| 1167 | for (; vgizmap; vgizmap=nxtp) { |
|---|
| 1168 | |
|---|
| 1169 | if (dbxtrace) printf("gizflush - %s\n",vgizmap->gdbnp); |
|---|
| 1170 | for (i=0; i <= 255; i++) { |
|---|
| 1171 | gizmhp=vgizmap->ghdrp[i]; |
|---|
| 1172 | for (gizmp=gizmhp; gizmp; gizmp=gizmnp) { |
|---|
| 1173 | #if CICPP |
|---|
| 1174 | delete [] gizmp->ipatt; |
|---|
| 1175 | delete [] gizmp->opatt; |
|---|
| 1176 | #else /* CICPP */ |
|---|
| 1177 | FREE(gizmp->ipatt); |
|---|
| 1178 | FREE(gizmp->opatt); |
|---|
| 1179 | #endif /* CICPP */ |
|---|
| 1180 | gizmnp=gizmp->nextp; |
|---|
| 1181 | #if CICPP |
|---|
| 1182 | delete gizmp; |
|---|
| 1183 | #else /* CICPP */ |
|---|
| 1184 | FREE(gizmp); |
|---|
| 1185 | #endif /* CICPP */ |
|---|
| 1186 | } |
|---|
| 1187 | } |
|---|
| 1188 | #if CICPP |
|---|
| 1189 | delete [] vgizmap->gdbnp; |
|---|
| 1190 | #else /* CICPP */ |
|---|
| 1191 | FREE(vgizmap->gdbnp); |
|---|
| 1192 | #endif /* CICPP */ |
|---|
| 1193 | |
|---|
| 1194 | nxtp=vgizmap->nextp; |
|---|
| 1195 | #if CICPP |
|---|
| 1196 | delete vgizmap; |
|---|
| 1197 | #else /* CICPP */ |
|---|
| 1198 | FREE(vgizmap); |
|---|
| 1199 | #endif /* CICPP */ |
|---|
| 1200 | } |
|---|
| 1201 | } |
|---|
| 1202 | #endif /* RECGIZM */ |
|---|
| 1203 | |
|---|
| 1204 | |
|---|
| 1205 | #if RECDECO |
|---|
| 1206 | #if CICPP |
|---|
| 1207 | void CISISX :: xdecflush(VDECPSTRU *vdecmap) |
|---|
| 1208 | #else /* CICPP */ |
|---|
| 1209 | void decflush(vdecmap) /* |
|---|
| 1210 | ------------- |
|---|
| 1211 | seta dbxp; |
|---|
| 1212 | faz close dos arquivos abertos do master file |
|---|
| 1213 | */ |
|---|
| 1214 | VDECPSTRU *vdecmap; /* decod to be flushed */ |
|---|
| 1215 | #endif /* CICPP */ |
|---|
| 1216 | { |
|---|
| 1217 | VDECPSTRU *nxtp; |
|---|
| 1218 | |
|---|
| 1219 | if (dbxtrace) printf("decflush - vdecmap=%p\n",vdecmap); |
|---|
| 1220 | for (; vdecmap; vdecmap=nxtp) { |
|---|
| 1221 | |
|---|
| 1222 | if (dbxtrace) printf("decflush - %s\n",vdecmap->ddbnp); |
|---|
| 1223 | #if CICPP |
|---|
| 1224 | delete [] vdecmap->ddbnp; |
|---|
| 1225 | #else /* CICPP */ |
|---|
| 1226 | FREE(vdecmap->ddbnp); |
|---|
| 1227 | #endif /* CICPP */ |
|---|
| 1228 | |
|---|
| 1229 | nxtp=vdecmap->nextp; |
|---|
| 1230 | #if CICPP |
|---|
| 1231 | delete vdecmap; |
|---|
| 1232 | #else /* CICPP */ |
|---|
| 1233 | FREE(vdecmap); |
|---|
| 1234 | #endif /* CICPP */ |
|---|
| 1235 | } |
|---|
| 1236 | } |
|---|
| 1237 | #endif /* RECDECO */ |
|---|
| 1238 | |
|---|
| 1239 | #if CICPP |
|---|
| 1240 | char * CISISX :: xloadfile(char *gidbnp, |
|---|
| 1241 | char at, |
|---|
| 1242 | char *atp, |
|---|
| 1243 | char *areap, |
|---|
| 1244 | LONGX asize, |
|---|
| 1245 | char lf2x) |
|---|
| 1246 | #else /*CICPP*/ |
|---|
| 1247 | char *loadfile(gidbnp,at,atp,areap,asize,lf2x) |
|---|
| 1248 | char *gidbnp; /* dbn.par */ |
|---|
| 1249 | char at; |
|---|
| 1250 | char *atp; |
|---|
| 1251 | char *areap; |
|---|
| 1252 | LONGX asize; |
|---|
| 1253 | char lf2x; |
|---|
| 1254 | #endif /*CICPP*/ |
|---|
| 1255 | { |
|---|
| 1256 | LONGX len,alloced=0; |
|---|
| 1257 | unsigned char *p; |
|---|
| 1258 | FILE *fp; |
|---|
| 1259 | int rc; |
|---|
| 1260 | int voidcipar=0; /* AOT, 19/01/2006 */ |
|---|
| 1261 | if (asize==EOF) { voidcipar=1; asize=0L; } /* AOT, 19/01/2006 */ |
|---|
| 1262 | |
|---|
| 1263 | if (areap == NULL) { |
|---|
| 1264 | if (!asize) { |
|---|
| 1265 | if (at && *atp != at) { |
|---|
| 1266 | len=strlen(atp); |
|---|
| 1267 | asize=len+1; |
|---|
| 1268 | } |
|---|
| 1269 | else { |
|---|
| 1270 | p=(unsigned char *)atp; if (at) p++; |
|---|
| 1271 | if (!voidcipar) p=dbxcipar(gidbnp,(char *)p,'='); /* AOT, 19/01/2006 */ |
|---|
| 1272 | if ((fp=fopen(p,"r")) == NULL) { /* AOT, 19/01/2006 */ |
|---|
| 1273 | return(NULL); |
|---|
| 1274 | } |
|---|
| 1275 | fseek(fp,0L,SEEK_END); |
|---|
| 1276 | asize=ftell(fp)+2; |
|---|
| 1277 | fclose(fp); |
|---|
| 1278 | if (asize < 0) {fatal("loadfile/lseek"); return(NULL);} |
|---|
| 1279 | } |
|---|
| 1280 | } |
|---|
| 1281 | #if CICPP |
|---|
| 1282 | areap=new char [asize]; |
|---|
| 1283 | #else |
|---|
| 1284 | areap=(char *)ALLOC((ALLOPARM)(asize)); |
|---|
| 1285 | #endif |
|---|
| 1286 | if (areap == (char *)NULL) {fatal("loadfile/ALLOC"); return(NULL);} |
|---|
| 1287 | alloced=1; |
|---|
| 1288 | } |
|---|
| 1289 | |
|---|
| 1290 | *areap='\0'; |
|---|
| 1291 | |
|---|
| 1292 | if (at && *atp != at) { |
|---|
| 1293 | len=strlen(atp); |
|---|
| 1294 | if (len >= asize) len=asize-1; |
|---|
| 1295 | memcpy(areap,atp,len); areap[len]='\0'; |
|---|
| 1296 | } |
|---|
| 1297 | else { |
|---|
| 1298 | p=(unsigned char *)atp; if (at) p++; |
|---|
| 1299 | if (!voidcipar) p=dbxcipar(gidbnp,(char *)p,'='); /* AOT, 19/01/2006 */ |
|---|
| 1300 | if ((fp=fopen(p,"r")) == NULL) { /* AOT, 19/01/2006 */ |
|---|
| 1301 | #if BEFORE970318 |
|---|
| 1302 | return(areap); /* CICPP */ |
|---|
| 1303 | #else |
|---|
| 1304 | if (alloced) |
|---|
| 1305 | #if CICPP |
|---|
| 1306 | delete [] areap; |
|---|
| 1307 | #else |
|---|
| 1308 | FREE(areap); |
|---|
| 1309 | #endif |
|---|
| 1310 | return(NULL); /* CICPP */ |
|---|
| 1311 | #endif |
|---|
| 1312 | } |
|---|
| 1313 | for (--asize, p=(unsigned char *)areap; ; ) |
|---|
| 1314 | if (asize > 0) { |
|---|
| 1315 | if ((rc=fgetc(fp)) == EOF) break; |
|---|
| 1316 | if (rc) |
|---|
| 1317 | if (rc == '\n') { |
|---|
| 1318 | if (lf2x) { |
|---|
| 1319 | *p++ = lf2x; |
|---|
| 1320 | asize--; |
|---|
| 1321 | } |
|---|
| 1322 | } |
|---|
| 1323 | else { |
|---|
| 1324 | #if MPE |
|---|
| 1325 | if (rc) *p++ = rc; else *p++ = ' '; |
|---|
| 1326 | #else |
|---|
| 1327 | *p++ = rc; |
|---|
| 1328 | #endif |
|---|
| 1329 | asize--; |
|---|
| 1330 | } |
|---|
| 1331 | } |
|---|
| 1332 | else { |
|---|
| 1333 | fatal("loadfile/overflow"); |
|---|
| 1334 | break; /* CICPP */ |
|---|
| 1335 | } |
|---|
| 1336 | |
|---|
| 1337 | #ifdef USE_ERROR_SYS |
|---|
| 1338 | if (p>(unsigned char *)areap && *(p-1)=='\\') /* D.Storti 03/98 */ |
|---|
| 1339 | *p++ = '\n'; |
|---|
| 1340 | #endif |
|---|
| 1341 | *p='\0'; |
|---|
| 1342 | fclose(fp); |
|---|
| 1343 | } |
|---|
| 1344 | return(areap); |
|---|
| 1345 | } |
|---|
| 1346 | |
|---|
| 1347 | #if CICPP |
|---|
| 1348 | char * CISISX :: xloadstw(char *gidbnp, |
|---|
| 1349 | char *atp, |
|---|
| 1350 | char *areap, |
|---|
| 1351 | LONGX asize, |
|---|
| 1352 | int *nstws) |
|---|
| 1353 | #else /*CICPP*/ |
|---|
| 1354 | char *loadstw(gidbnp,atp,areap,asize,nstws) |
|---|
| 1355 | char *gidbnp; /* dbn.par */ |
|---|
| 1356 | char *atp; |
|---|
| 1357 | char *areap; |
|---|
| 1358 | LONGX asize; |
|---|
| 1359 | int *nstws; |
|---|
| 1360 | #endif /*CICPP*/ |
|---|
| 1361 | { |
|---|
| 1362 | FILE *fp; |
|---|
| 1363 | LONGX nbytes; |
|---|
| 1364 | char line[BUFSIZ],*ap,*p; |
|---|
| 1365 | int nlin,len; |
|---|
| 1366 | *nstws=0; |
|---|
| 1367 | if ((fp=fopen(dbxcipar(gidbnp,atp,'='),"r")) == NULL) return(NULL); |
|---|
| 1368 | #ifdef CI_WINISIS |
|---|
| 1369 | for (nlin=1; fgets(line,sizeof(line),fp); ) nlin++; |
|---|
| 1370 | #else |
|---|
| 1371 | for (nlin=0; fgets(line,sizeof(line),fp); ) nlin++; |
|---|
| 1372 | #endif /* CI_WINISIS */ |
|---|
| 1373 | nbytes=nlin*(LE1+1)+1; |
|---|
| 1374 | if (asize) { if (asize < nbytes) {fclose(fp); fatal("loadstw/overflow"); return(NULL);}} |
|---|
| 1375 | else asize=nbytes; |
|---|
| 1376 | if (areap == NULL) { |
|---|
| 1377 | #if CICPP |
|---|
| 1378 | areap=new char [asize]; |
|---|
| 1379 | #else |
|---|
| 1380 | areap=(char *)ALLOC((ALLOPARM)(asize)); |
|---|
| 1381 | #endif |
|---|
| 1382 | if (areap == (char *)NULL) {fclose(fp); fatal("loadstw/ALLOC"); return(NULL);} |
|---|
| 1383 | } |
|---|
| 1384 | memset(areap,0x00,(size_t)asize); |
|---|
| 1385 | fseek(fp,0L,SEEK_SET); |
|---|
| 1386 | for (ap=areap; fgets(line,sizeof(line),fp); ) { |
|---|
| 1387 | len=strlen(line); |
|---|
| 1388 | line[--len]='\0'; /* strip fgets() '\n' */ |
|---|
| 1389 | for (p=line+len-1; len; p--) /* strip trailing spaces */ |
|---|
| 1390 | if (*p == ' ') line[--len]='\0'; else break; |
|---|
| 1391 | if (len < 1) /*fatal("loadstw/blanked line");*/ continue; |
|---|
| 1392 | if (len > LE1) /*fatal(line);*/ line[len=LE1]='\0'; |
|---|
| 1393 | #ifdef CI_WINISIS |
|---|
| 1394 | { |
|---|
| 1395 | char *ai,*apstart=ap; |
|---|
| 1396 | for (ai=line; *ai; ai++, ap++) |
|---|
| 1397 | *ap=isisuctab[(unsigned int)*ai]; |
|---|
| 1398 | *ap=0; |
|---|
| 1399 | ap=apstart+LE1+1; |
|---|
| 1400 | } |
|---|
| 1401 | #else |
|---|
| 1402 | memcpy(ap,line,len); |
|---|
| 1403 | ap+=LE1+1; |
|---|
| 1404 | #endif /* CI_WINISIS */ |
|---|
| 1405 | (*nstws)++; |
|---|
| 1406 | } |
|---|
| 1407 | #ifdef CI_WINISIS |
|---|
| 1408 | if ((*nstws)/2*2!=(*nstws)) // must be pair!! |
|---|
| 1409 | (*nstws)++; |
|---|
| 1410 | #endif /* CI_WINISIS */ |
|---|
| 1411 | fclose(fp); |
|---|
| 1412 | return(areap); |
|---|
| 1413 | } |
|---|
| 1414 | |
|---|
| 1415 | // |
|---|
| 1416 | // dbxtmpnm() original - |
|---|
| 1417 | // copied from 44a/cisisx.c - AOT, 01/12/2006 |
|---|
| 1418 | // |
|---|
| 1419 | #if CICPP |
|---|
| 1420 | char * CISISX :: xdbxtmpnm(char *dirtmp, |
|---|
| 1421 | int strip, |
|---|
| 1422 | char *filnamp) |
|---|
| 1423 | #else /* CICPP */ |
|---|
| 1424 | char *dbxtmpnm(dirtmp, strip, filnamp) |
|---|
| 1425 | char *dirtmp; |
|---|
| 1426 | int strip; |
|---|
| 1427 | char *filnamp; |
|---|
| 1428 | #endif /* CICPP */ |
|---|
| 1429 | /* |
|---|
| 1430 | get a temporary file name in directory dirtmp (if dirtmp) |
|---|
| 1431 | or in directory "CI_TEMPDIR" defined in cipar |
|---|
| 1432 | or env TEMP or TMP |
|---|
| 1433 | strip the .$$$ extension (if strip) |
|---|
| 1434 | store the filename in filnamp (if filnamp) |
|---|
| 1435 | or allocate a new area |
|---|
| 1436 | return the resulting file name or NULL (if error) |
|---|
| 1437 | */ |
|---|
| 1438 | { |
|---|
| 1439 | FILE *fp; |
|---|
| 1440 | char *p,*q; |
|---|
| 1441 | int len; |
|---|
| 1442 | #if PC |
|---|
| 1443 | char cwd[MAXPATH+1]; |
|---|
| 1444 | char *cip; |
|---|
| 1445 | #endif |
|---|
| 1446 | |
|---|
| 1447 | if (!ndbxs) |
|---|
| 1448 | dbxinit(); /* activate CIPAR */ |
|---|
| 1449 | |
|---|
| 1450 | if (filnamp) *filnamp='\0'; |
|---|
| 1451 | |
|---|
| 1452 | #if PC |
|---|
| 1453 | if (dirtmp) if (strcmp(dirtmp,"CI_TEMPDIR") == 0 || strcmp(dirtmp,"ci_tempdir") == 0) { |
|---|
| 1454 | cip=dbxcipar(NULL,"CI_TEMPDIR",'='); |
|---|
| 1455 | if (dbxcipok) dirtmp=cip; else dirtmp=NULL; |
|---|
| 1456 | if (!dirtmp) { |
|---|
| 1457 | cip=dbxcipar(NULL,"ci_tempdir",'='); |
|---|
| 1458 | if (dbxcipok) dirtmp=cip; |
|---|
| 1459 | } |
|---|
| 1460 | if (!dirtmp) if ((dirtmp=getenv("TEMP")) == NULL) dirtmp=getenv("TMP"); |
|---|
| 1461 | } |
|---|
| 1462 | if (dirtmp) { |
|---|
| 1463 | if (!getcwd(cwd,MAXPATH)) return(NULL); |
|---|
| 1464 | if (chdir(dirtmp)) return(NULL); |
|---|
| 1465 | } |
|---|
| 1466 | #endif |
|---|
| 1467 | |
|---|
| 1468 | p=tmpnam(NULL); |
|---|
| 1469 | |
|---|
| 1470 | fp=fopen(p,"w"); if (fp) fclose(fp); else return(NULL); |
|---|
| 1471 | |
|---|
| 1472 | len=strlen(p)+4; /* .ext */ |
|---|
| 1473 | |
|---|
| 1474 | #if PC |
|---|
| 1475 | if (dirtmp) { |
|---|
| 1476 | if (chdir(cwd)) return(NULL); |
|---|
| 1477 | len+=strlen(dirtmp); |
|---|
| 1478 | } |
|---|
| 1479 | #endif |
|---|
| 1480 | |
|---|
| 1481 | #if PC |
|---|
| 1482 | if (strip) if (strcmp((q=p+strlen(p)-4),".$$$") == 0) *q='\0'; |
|---|
| 1483 | #endif |
|---|
| 1484 | |
|---|
| 1485 | if (!filnamp) { |
|---|
| 1486 | #if CICPP |
|---|
| 1487 | try { filnamp= new char [len+1]; } |
|---|
| 1488 | catch (BAD_ALLOC) { filnamp=(char *)NULL; } |
|---|
| 1489 | #else /* CICPP */ |
|---|
| 1490 | filnamp=(char *)ALLOC((ALLOPARM)(len+1)); |
|---|
| 1491 | #endif /* CICPP */ |
|---|
| 1492 | if (filnamp == (char *)ALLONULL) fatal("dbxtmpnm/ALLOC"); |
|---|
| 1493 | *filnamp='\0'; |
|---|
| 1494 | } |
|---|
| 1495 | |
|---|
| 1496 | #if PC |
|---|
| 1497 | if (dirtmp) |
|---|
| 1498 | { |
|---|
| 1499 | char c; |
|---|
| 1500 | strcpy(filnamp,dirtmp); |
|---|
| 1501 | c = *(filnamp+strlen(filnamp)); |
|---|
| 1502 | if (c != '/' && c != '\\') |
|---|
| 1503 | { |
|---|
| 1504 | if (strchr(filnamp,'/')) strcat(filnamp,"/"); |
|---|
| 1505 | else strcat(filnamp,"\\"); |
|---|
| 1506 | } |
|---|
| 1507 | } |
|---|
| 1508 | #endif |
|---|
| 1509 | strcat(filnamp,p); |
|---|
| 1510 | |
|---|
| 1511 | if (dbxtrace && (b40trace||b50trace)) printf("+++dbxtmpnm='%s'\n",filnamp); |
|---|
| 1512 | return(filnamp); |
|---|
| 1513 | } |
|---|
| 1514 | #endif /* CICPP || CIDBX_CISISX_SOURCE */ |
|---|
| 1515 | |
|---|
| 1516 | |
|---|
| 1517 | |
|---|
| 1518 | /* ========================== Origem: CIUPD.C ========================== */ |
|---|
| 1519 | |
|---|
| 1520 | #if CICPP || CIUPD_CISISX_SOURCE |
|---|
| 1521 | |
|---|
| 1522 | #if CICPP |
|---|
| 1523 | int CISISX :: xrecisis0(char *dbnamp) |
|---|
| 1524 | #else /* CICPP */ |
|---|
| 1525 | int recisis0(dbnamp) /* |
|---|
| 1526 | ------------ |
|---|
| 1527 | cria .mst; |
|---|
| 1528 | cria .xrf; |
|---|
| 1529 | retorna CREAT() |
|---|
| 1530 | */ |
|---|
| 1531 | char *dbnamp; /* ptr nome bases de dados */ |
|---|
| 1532 | #endif /* CICPP */ |
|---|
| 1533 | { |
|---|
| 1534 | /* FFI n; */ |
|---|
| 1535 | int n,fd; |
|---|
| 1536 | char *areap; |
|---|
| 1537 | |
|---|
| 1538 | XRSTRU *xrp; |
|---|
| 1539 | M0STRU *ms0p; /* defines MS0 */ |
|---|
| 1540 | XRPTR xrftiv; |
|---|
| 1541 | |
|---|
| 1542 | #if DBXMSTXL |
|---|
| 1543 | int pow, vtot; |
|---|
| 1544 | #endif |
|---|
| 1545 | |
|---|
| 1546 | #if RUITRACE |
|---|
| 1547 | printf("recisis0 - dbnamp=%s\n",dbnamp); |
|---|
| 1548 | #endif |
|---|
| 1549 | |
|---|
| 1550 | #if MULTI |
|---|
| 1551 | if (dbxstorp(dbnamp)->dbxnetws != MONONETS) |
|---|
| 1552 | fatal("recisis0/MONONETS expected"); |
|---|
| 1553 | #endif |
|---|
| 1554 | |
|---|
| 1555 | n = (XRBSIZ > MSBSIZ) ? XRBSIZ : MSBSIZ; |
|---|
| 1556 | #if CICPP |
|---|
| 1557 | try { areap = (char *) new char [n]; } |
|---|
| 1558 | catch (BAD_ALLOC) { areap = (char *)ALLONULL; } |
|---|
| 1559 | #else /* CICPP */ |
|---|
| 1560 | areap=(char *)ALLOC((ALLOPARM)n); |
|---|
| 1561 | #endif /* CICPP */ |
|---|
| 1562 | if (areap == (char *)ALLONULL) |
|---|
| 1563 | fatal("recisis0/ALLOC"); |
|---|
| 1564 | |
|---|
| 1565 | strcpy(areap,dbnamp); |
|---|
| 1566 | strcat(areap,xx1extp); |
|---|
| 1567 | strcpy(areap,dbxcipar(dbnamp,areap,'=')); |
|---|
| 1568 | #if RUITRACE |
|---|
| 1569 | printf("recisis0 - filename='%s'\n",areap); |
|---|
| 1570 | #endif |
|---|
| 1571 | #if MPE |
|---|
| 1572 | if ((fd=OPEN(areap, |
|---|
| 1573 | O_WRONLY|O_CREAT|O_TRUNC|O_MPEOPTS,PERMIS,"b R512")) <= 0) { |
|---|
| 1574 | #else |
|---|
| 1575 | if ((fd=CREAT(areap,PERMIS)) <= 0) { |
|---|
| 1576 | #endif |
|---|
| 1577 | #if CICPP |
|---|
| 1578 | delete[] areap; |
|---|
| 1579 | #else /* CICPP */ |
|---|
| 1580 | FREE(areap); |
|---|
| 1581 | #endif /* CICPP */ |
|---|
| 1582 | fatal("recisis0/xrf"); |
|---|
| 1583 | } |
|---|
| 1584 | if (rectrace) printf("+++ recisis0 - %s=%d\n",areap,fd); |
|---|
| 1585 | |
|---|
| 1586 | xrp=(XRSTRU *)areap; |
|---|
| 1587 | xrp->xrxrpos= -1; /* 1st block = flagged */ |
|---|
| 1588 | |
|---|
| 1589 | xrftiv = (0)*XRXDIVIDE + (0); /* inexistant records */ |
|---|
| 1590 | for (n=0; n < XRMAXTIV; ) { |
|---|
| 1591 | xrp->xrmfptr[n++]=xrftiv; |
|---|
| 1592 | } |
|---|
| 1593 | #if CNV_PCBINUM |
|---|
| 1594 | ConvertXRF_REC(areap); /* local */ |
|---|
| 1595 | #endif |
|---|
| 1596 | |
|---|
| 1597 | if ((n=CIWRITE(fd,areap,XRBSIZ)) != XRBSIZ) { /* CNV_PCBINUM local */ |
|---|
| 1598 | #if RUITRACE |
|---|
| 1599 | printf("recisis0 - write/xrf n=%d\n",n); |
|---|
| 1600 | #endif |
|---|
| 1601 | fatal("recisis0/write/xrf"); |
|---|
| 1602 | } |
|---|
| 1603 | CLOSE(fd); |
|---|
| 1604 | |
|---|
| 1605 | n=recisis0_m; recisis0_m=1; |
|---|
| 1606 | if (!n) { |
|---|
| 1607 | #if CICPP |
|---|
| 1608 | delete[] areap; |
|---|
| 1609 | #else /* CICPP */ |
|---|
| 1610 | FREE(areap); |
|---|
| 1611 | #endif /* CICPP */ |
|---|
| 1612 | return(fd); |
|---|
| 1613 | } |
|---|
| 1614 | |
|---|
| 1615 | strcpy(areap,dbnamp); |
|---|
| 1616 | strcat(areap,mx1extp); |
|---|
| 1617 | strcpy(areap,dbxcipar(dbnamp,areap,'=')); |
|---|
| 1618 | #if RUITRACE |
|---|
| 1619 | printf("recisis0 - filename='%s'\n",areap); |
|---|
| 1620 | #endif |
|---|
| 1621 | |
|---|
| 1622 | #if MPE |
|---|
| 1623 | if ((fd=OPEN(areap, |
|---|
| 1624 | O_WRONLY|O_CREAT|O_TRUNC|O_MPEOPTS,PERMIS,"b R512")) <= 0) { |
|---|
| 1625 | #else |
|---|
| 1626 | if ((fd=CREAT(areap,PERMIS)) <= 0) { |
|---|
| 1627 | #endif |
|---|
| 1628 | #if CICPP |
|---|
| 1629 | delete[] areap; |
|---|
| 1630 | #else /* CICPP */ |
|---|
| 1631 | FREE(areap); |
|---|
| 1632 | #endif /* CICPP */ |
|---|
| 1633 | fatal("recisis0/mst"); |
|---|
| 1634 | } |
|---|
| 1635 | if (rectrace) printf("+++ recisis0 - %s=%d\n",areap,fd); |
|---|
| 1636 | |
|---|
| 1637 | #if DBXMSTXL |
|---|
| 1638 | strcpy(areap,dbnamp); |
|---|
| 1639 | strcat(areap,"/mstxl"); |
|---|
| 1640 | strcpy(areap,dbxcipar(NULL,areap,'=')); |
|---|
| 1641 | if (!dbxcipok) { |
|---|
| 1642 | strcpy(areap, "mstxl"); |
|---|
| 1643 | strcpy(areap,dbxcipar(NULL,areap,'=')); |
|---|
| 1644 | } |
|---|
| 1645 | if (dbxcipok) { |
|---|
| 1646 | char * q = areap + strlen(areap) - 1; |
|---|
| 1647 | while (*q == ' ') *q = 0; |
|---|
| 1648 | |
|---|
| 1649 | if (areap[strlen(areap)-1] == 'G') { |
|---|
| 1650 | int num=atoi(areap); |
|---|
| 1651 | int cap = 1; |
|---|
| 1652 | n = 1; |
|---|
| 1653 | while (num != cap) { |
|---|
| 1654 | if (num < cap) { |
|---|
| 1655 | fatal("recisis0/cipar/mstxl/G"); |
|---|
| 1656 | } |
|---|
| 1657 | n++; |
|---|
| 1658 | cap *= 2; |
|---|
| 1659 | } |
|---|
| 1660 | } else { |
|---|
| 1661 | n=atoi(areap); |
|---|
| 1662 | if (n > 4) fatal("recisis0/mstxl"); |
|---|
| 1663 | if (n == 4) n=3; |
|---|
| 1664 | } |
|---|
| 1665 | } else { |
|---|
| 1666 | n=cipmstxl; |
|---|
| 1667 | if (n) if (n < 0) fatal("recisis0/mstxl"); |
|---|
| 1668 | if (n == 4) n=3; |
|---|
| 1669 | } |
|---|
| 1670 | dbxstorp(dbnamp)->dbxmstxl=n; |
|---|
| 1671 | if (rectrace) printf("+++ recisis0 - mstxl=%d\n",n); |
|---|
| 1672 | #endif |
|---|
| 1673 | |
|---|
| 1674 | ms0p=(M0STRU *)areap; |
|---|
| 1675 | |
|---|
| 1676 | MS0ctlmfn=0; |
|---|
| 1677 | MS0nxtmfn=1; |
|---|
| 1678 | MS0nxtmfb=1; |
|---|
| 1679 | MS0nxtmfp=sizeof(M0STRU)+sizeof(M0STRU)+1; /* gdb */ |
|---|
| 1680 | MS0mftype=MSMFTUSR; |
|---|
| 1681 | #if DBXMSTXL |
|---|
| 1682 | /* MS0mftype += n * 0x00FF; NAO 255! */ |
|---|
| 1683 | MS0mftype += n * 256; /* AOT/AARG 05/01/99 */ |
|---|
| 1684 | |
|---|
| 1685 | /* first rec pos & cipmstxl alignment - |
|---|
| 1686 | see ciupd.c: if (thiscomp & 0x01 || (thiscomp & vtot))*/ |
|---|
| 1687 | vtot = 1; |
|---|
| 1688 | for (pow = 1; pow <= n; pow++) { |
|---|
| 1689 | vtot *= 2; |
|---|
| 1690 | } |
|---|
| 1691 | vtot -= 1; |
|---|
| 1692 | MS0nxtmfp--; |
|---|
| 1693 | while (MS0nxtmfp & vtot) |
|---|
| 1694 | MS0nxtmfp++; |
|---|
| 1695 | MS0nxtmfp++; |
|---|
| 1696 | #endif |
|---|
| 1697 | if (recisis0_s || |
|---|
| 1698 | strcmp(dbnamp+strlen(dbnamp)-3,"msg") == 0 || |
|---|
| 1699 | strcmp(dbnamp+strlen(dbnamp)-3,"MSG") == 0 ) { |
|---|
| 1700 | MS0nxtmfb=2; |
|---|
| 1701 | MS0nxtmfp=1; /* gdb */ |
|---|
| 1702 | MS0mftype=MSMFTMSG; |
|---|
| 1703 | recisis0_s = 0; /* 21/09/94 */ |
|---|
| 1704 | } |
|---|
| 1705 | MS0reccnt=MS0mfcxx1=MS0mfcxx2=MS0mfcxx3=0; |
|---|
| 1706 | |
|---|
| 1707 | #if MST_INFO_FLAG |
|---|
| 1708 | MS0comp = MST_FLAG; |
|---|
| 1709 | #endif /* MST_INFO_FLAG */ |
|---|
| 1710 | |
|---|
| 1711 | #if MST0FILL0XFF |
|---|
| 1712 | memset(areap+sizeof(M0STRU),0xFF,MSBSIZ-sizeof(M0STRU)); |
|---|
| 1713 | #else |
|---|
| 1714 | memset(areap+sizeof(M0STRU),0x00,MSBSIZ-sizeof(M0STRU)); |
|---|
| 1715 | #endif |
|---|
| 1716 | |
|---|
| 1717 | #if CNV_PCBINUM |
|---|
| 1718 | ConvertMST_CTLSTRUCT(areap); /* local */ |
|---|
| 1719 | #endif |
|---|
| 1720 | if ((n=CIWRITE(fd,areap,MSBSIZ)) != MSBSIZ) { /* CNV_PCBINUM local */ |
|---|
| 1721 | #if RUITRACE |
|---|
| 1722 | printf("recisis0 - write/mst n=%d\n",n); |
|---|
| 1723 | #endif |
|---|
| 1724 | fatal("recisis0/write/mst"); |
|---|
| 1725 | } |
|---|
| 1726 | CLOSE(fd); |
|---|
| 1727 | |
|---|
| 1728 | #if CICPP |
|---|
| 1729 | delete[] areap; |
|---|
| 1730 | #else /* CICPP */ |
|---|
| 1731 | FREE(areap); |
|---|
| 1732 | #endif /* CICPP */ |
|---|
| 1733 | |
|---|
| 1734 | return(fd); |
|---|
| 1735 | } |
|---|
| 1736 | |
|---|
| 1737 | |
|---|
| 1738 | /* ----------------------------- recreset ------------------------------ */ |
|---|
| 1739 | #if IFUPDATE |
|---|
| 1740 | #if CICPP |
|---|
| 1741 | void CISISX :: xrecreset(char *dbnp, |
|---|
| 1742 | LONGX mfn1, |
|---|
| 1743 | LONGX mfn2, |
|---|
| 1744 | RECSTRU *xrecp, |
|---|
| 1745 | LONGX parmtell) |
|---|
| 1746 | #else /* CICPP */ |
|---|
| 1747 | void recreset(dbnp,mfn1,mfn2,xrec,parmtell) |
|---|
| 1748 | char *dbnp; |
|---|
| 1749 | LONGX mfn1; |
|---|
| 1750 | LONGX mfn2; |
|---|
| 1751 | LONGX xrec; |
|---|
| 1752 | LONGX parmtell; |
|---|
| 1753 | #endif /* CICPP */ |
|---|
| 1754 | { |
|---|
| 1755 | RECSTRU *recp; |
|---|
| 1756 | DBXSTRU *dbxp; |
|---|
| 1757 | #if !CICPP |
|---|
| 1758 | LONGX irec; |
|---|
| 1759 | #endif /* CICPP */ |
|---|
| 1760 | LONGX mfn; |
|---|
| 1761 | LONGX xrftiv; |
|---|
| 1762 | int flagnew,flagmod; |
|---|
| 1763 | int w,thisidx; |
|---|
| 1764 | LONGX thispos,count=0L,count2=0L; |
|---|
| 1765 | off_t xbyte; |
|---|
| 1766 | #ifdef USE_INFO_SYS |
|---|
| 1767 | char mess_str[64]; |
|---|
| 1768 | // char resettingmess[64]; |
|---|
| 1769 | UIW_STRING *procstr=NULL; |
|---|
| 1770 | UIW_PROGRESSBAR *progbar=NULL; |
|---|
| 1771 | if (wprogress) { |
|---|
| 1772 | UI_EVENT event; |
|---|
| 1773 | procstr=((UIW_STRING*)wprogress->Get("PROCESSING_STRING")); |
|---|
| 1774 | // ((UIW_BUTTON*)wprogress->Get("101"))->woFlags|=WOF_NON_SELECTABLE; |
|---|
| 1775 | // ((UIW_BUTTON*)wprogress->Get("101"))->Information(I_CHANGED_FLAGS,NULL); |
|---|
| 1776 | wprogress->eventManager->Get(event,Q_NO_BLOCK|Q_BEGIN|Q_DESTROY|Q_POLL); |
|---|
| 1777 | wprogress->windowManager->Event(event); |
|---|
| 1778 | progbar=((UIW_PROGRESSBAR*)wprogress->Get("PROG_BAR")); |
|---|
| 1779 | progbar->Assign(0,0); |
|---|
| 1780 | progbar->SetColor(11); |
|---|
| 1781 | // sprintf(resettingmess,"%s",mess->get(453)); |
|---|
| 1782 | } |
|---|
| 1783 | #endif |
|---|
| 1784 | |
|---|
| 1785 | if (rectrace) printf("recreset - %s / %ld / %ld \n",dbnp,mfn1,mfn2); |
|---|
| 1786 | |
|---|
| 1787 | /* allocate irec */ |
|---|
| 1788 | if (mfn1) { |
|---|
| 1789 | #if CICPP |
|---|
| 1790 | try { recp = new RECSTRU(this); } |
|---|
| 1791 | catch (BAD_ALLOC) { fatal("recreset/ALLOC/recp"); } |
|---|
| 1792 | recp->xrecord(dbnp,mfn=mfn1); /* RECdbxp and mstsetup() */ |
|---|
| 1793 | #else /* CICPP */ |
|---|
| 1794 | if (!nrecs) recinit(); |
|---|
| 1795 | for (irec=maxnrec; --irec > 0; ) |
|---|
| 1796 | if (!vrecp[irec]) { |
|---|
| 1797 | recallok(irec,MAXMFRL); |
|---|
| 1798 | recp=vrecp[irec]; |
|---|
| 1799 | break; |
|---|
| 1800 | } |
|---|
| 1801 | if (irec == 0) fatal("recreset/maxnrec"); |
|---|
| 1802 | record(irec,dbnp,mfn=mfn1); /* RECdbxp and mstsetup() */ |
|---|
| 1803 | #endif /* CICPP */ |
|---|
| 1804 | } |
|---|
| 1805 | else { |
|---|
| 1806 | #if CICPP |
|---|
| 1807 | recp=xrecp; // "delete recp" only if (mfn1) is true |
|---|
| 1808 | #else /* CICPP */ |
|---|
| 1809 | irec=xrec; |
|---|
| 1810 | recp=vrecp[irec]; |
|---|
| 1811 | #endif /* CICPP */ |
|---|
| 1812 | mfn=mfn2=MFRmfn; |
|---|
| 1813 | } |
|---|
| 1814 | if (rectrace) printf("recreset : %s / %ld / %ld \n",dbnp,mfn1,mfn2); |
|---|
| 1815 | |
|---|
| 1816 | dbxp=RECdbxp; |
|---|
| 1817 | dbxopenw(DBXname,DBXname,xx1extp,&DBXxropn,&DBXxropw,"recreset/xropn/w"); |
|---|
| 1818 | dbxopenw(DBXname,DBXname,mx1extp,&DBXmsopn,&DBXmsopw,"recreset/msopn/w"); |
|---|
| 1819 | |
|---|
| 1820 | #if MULTI |
|---|
| 1821 | if (DBXnetws != MONONETS) if (!DBXewlxx) fatal("recreset/EWL is off"); |
|---|
| 1822 | #endif |
|---|
| 1823 | |
|---|
| 1824 | if (mfn1) DBXirecs=0; |
|---|
| 1825 | |
|---|
| 1826 | for (; mfn <= mfn2; mfn++) { |
|---|
| 1827 | |
|---|
| 1828 | if (mfn1) { |
|---|
| 1829 | if (rectrace) printf("recreset - reading %s / %ld \n",RDBname,mfn); |
|---|
| 1830 | recreadl=1; /* leader */ |
|---|
| 1831 | |
|---|
| 1832 | recread(recp,mfn); /* leader */ |
|---|
| 1833 | } |
|---|
| 1834 | flagnew=recxrefn; flagmod=recxrefm; |
|---|
| 1835 | |
|---|
| 1836 | if (rectrace) printf("recreset - bw=%ld/%d f=%d/%d\n",MFRmfbwb,MFRmfbwp,flagnew,flagmod); |
|---|
| 1837 | |
|---|
| 1838 | if (RECrc == RCEOF) break; |
|---|
| 1839 | |
|---|
| 1840 | if (parmtell) |
|---|
| 1841 | if (++count % parmtell == 0) |
|---|
| 1842 | #ifdef USE_INFO_SYS |
|---|
| 1843 | { |
|---|
| 1844 | // errsys->sys_info_data(ltoa(count,mfnstr,10)); |
|---|
| 1845 | if (wprogress) { |
|---|
| 1846 | UI_EVENT event; // Resetting MFN |
|---|
| 1847 | // sprintf(mess_str,"%s %ld",resettingmess,mfn); |
|---|
| 1848 | sprintf(mess_str,"MFN: %ld",mfn); |
|---|
| 1849 | procstr->DataSet(mess_str); |
|---|
| 1850 | progbar->Assign(mfn-mfn1,mfn2-mfn1); |
|---|
| 1851 | wprogress->eventManager->Get(event,Q_NO_BLOCK|Q_BEGIN|Q_DESTROY|Q_POLL); |
|---|
| 1852 | if (event.type==10235) { // EXPORT_CANCEL) { |
|---|
| 1853 | int ok=errsys->ErrorMessage(wprogress->windowManager,WOS_INVALID,mess->get(420)); |
|---|
| 1854 | if (ok==WOS_INVALID) { |
|---|
| 1855 | mfn=mfn2+2; // STOP |
|---|
| 1856 | continue; |
|---|
| 1857 | } |
|---|
| 1858 | } |
|---|
| 1859 | wprogress->windowManager->Event(event); |
|---|
| 1860 | wprogress->eventManager->Get(event,Q_NO_BLOCK|Q_BEGIN|Q_DESTROY|Q_POLL); |
|---|
| 1861 | if (event.type==10235) { // EXPORT_CANCEL) { |
|---|
| 1862 | int ok=errsys->ErrorMessage(wprogress->windowManager,WOS_INVALID,mess->get(420)); |
|---|
| 1863 | if (ok==WOS_INVALID) { |
|---|
| 1864 | mfn=mfn2+2; // STOP |
|---|
| 1865 | continue; |
|---|
| 1866 | } |
|---|
| 1867 | } |
|---|
| 1868 | wprogress->windowManager->Event(event); |
|---|
| 1869 | } |
|---|
| 1870 | } |
|---|
| 1871 | #else |
|---|
| 1872 | fprintf(stderr,"+++ %ld/%ld \n",mfn,count2); |
|---|
| 1873 | #endif |
|---|
| 1874 | |
|---|
| 1875 | if (RECrc == RCPDEL) continue; |
|---|
| 1876 | |
|---|
| 1877 | w=0; |
|---|
| 1878 | /* reset .mst bw ptrs */ |
|---|
| 1879 | if (MFRmfbwb || MFRmfbwp) { |
|---|
| 1880 | MFRmfbwb=0; |
|---|
| 1881 | MFRmfbwp=0; |
|---|
| 1882 | #if MULTI |
|---|
| 1883 | /* keep existing RLOCK - AOT/HB 09/11/98*/ |
|---|
| 1884 | if (RECgdbw) MFRmfrl=(FFI)0-MFRmfrl; |
|---|
| 1885 | #endif |
|---|
| 1886 | if (rectrace) printf("recreset - writing mst %s \n",RDBname); |
|---|
| 1887 | |
|---|
| 1888 | recwmast(NULL,recp,recxrefb,recxrefp,0,1); /* leader */ |
|---|
| 1889 | |
|---|
| 1890 | w++; |
|---|
| 1891 | } |
|---|
| 1892 | /* reset .xrf flags */ |
|---|
| 1893 | if (flagnew || flagmod) { |
|---|
| 1894 | #if DBXMSTXL /* AOT 20/09/2001 */ |
|---|
| 1895 | if (rectrace) printf("recreset - writing xrf %s DBXmstxl=%d XRXDIVIDE=%d recxrefb=%ld recxrefp=%d\n",RDBname,DBXmstxl,XRXDIVIDE,recxrefb,recxrefp); |
|---|
| 1896 | xrftiv = recxrefb * (XRXDIVIDE>>DBXmstxl) + (recxrefp>>DBXmstxl); |
|---|
| 1897 | #else /* DBXMSTXL */ |
|---|
| 1898 | xrftiv = recxrefb * XRXDIVIDE + recxrefp; |
|---|
| 1899 | #endif /* DBXMSTXL */ |
|---|
| 1900 | if (MFRstatus == DELETED) xrftiv= -xrftiv; |
|---|
| 1901 | thispos=(MFRmfn+XRMAXTV1)/XRMAXTIV; |
|---|
| 1902 | thisidx=(MFRmfn-1)%XRMAXTIV; |
|---|
| 1903 | xbyte=(off_t)(((off_t)(thispos-1)<<XRSHIFT)+XRPOSSIZ+thisidx*XRPTRSIZ ); |
|---|
| 1904 | if (LSEEK64(DBXxropn,xbyte,SEEK_SET) != xbyte) |
|---|
| 1905 | fatal("recreset/recwxref/seek"); |
|---|
| 1906 | #if CNV_PCBINUM |
|---|
| 1907 | memcpy(cnv_pcbuff,&xrftiv,XRPTRSIZ); |
|---|
| 1908 | ConvertXRF_PTR(cnv_pcbuff); |
|---|
| 1909 | if (CIWRITE(DBXxropn,cnv_pcbuff,XRPTRSIZ) != XRPTRSIZ) |
|---|
| 1910 | #else |
|---|
| 1911 | if (CIWRITE(DBXxropn,(char *)&xrftiv,XRPTRSIZ) != XRPTRSIZ) |
|---|
| 1912 | #endif |
|---|
| 1913 | fatal("recreset/recwxref/write"); |
|---|
| 1914 | if (labs(DBXxribp->xrxrpos) == thispos) /* update buffer */ |
|---|
| 1915 | DBXxribp->xrmfptr[thisidx]=xrftiv; |
|---|
| 1916 | w++; |
|---|
| 1917 | } |
|---|
| 1918 | if (w) {count2++; if (mfn1) DBXirecs++; } |
|---|
| 1919 | } |
|---|
| 1920 | if (parmtell) |
|---|
| 1921 | if (count % parmtell) |
|---|
| 1922 | #ifdef USE_INFO_SYS |
|---|
| 1923 | // errsys->sys_info_data(ltoa(count,mfnstr,10)); |
|---|
| 1924 | { |
|---|
| 1925 | if (wprogress) { |
|---|
| 1926 | UI_EVENT event; |
|---|
| 1927 | sprintf(mess_str,"MFN %ld",mfn); |
|---|
| 1928 | ((UIW_STRING*)wprogress->Get("PROCESSING_STRING"))->DataSet(mess_str); |
|---|
| 1929 | wprogress->eventManager->Get(event,Q_NO_BLOCK|Q_BEGIN|Q_DESTROY|Q_POLL); |
|---|
| 1930 | wprogress->windowManager->Event(event); |
|---|
| 1931 | wprogress->eventManager->Get(event,Q_NO_BLOCK|Q_BEGIN|Q_DESTROY|Q_POLL); |
|---|
| 1932 | wprogress->windowManager->Event(event); |
|---|
| 1933 | } |
|---|
| 1934 | } |
|---|
| 1935 | #else |
|---|
| 1936 | fprintf(stderr,"+++ %ld/%ld \n",mfn,count2); |
|---|
| 1937 | #endif |
|---|
| 1938 | |
|---|
| 1939 | if (mfn1) { |
|---|
| 1940 | #if CICPP |
|---|
| 1941 | delete recp; |
|---|
| 1942 | #else /* CICPP */ |
|---|
| 1943 | if (rectrace) printf("+++ recreset - free %ld \n",irec); |
|---|
| 1944 | FREE(vrecp[irec]); vrecp[irec]=NULL; nrecs--; |
|---|
| 1945 | #endif /* CICPP */ |
|---|
| 1946 | } |
|---|
| 1947 | |
|---|
| 1948 | |
|---|
| 1949 | /* ??? close_ do .mst=dbxulock |
|---|
| 1950 | do .xrf=never!!! |
|---|
| 1951 | */ |
|---|
| 1952 | |
|---|
| 1953 | } |
|---|
| 1954 | |
|---|
| 1955 | #endif /* IFUPDATE */ |
|---|
| 1956 | |
|---|
| 1957 | #endif /* CICPP || CIUPD_CISISX_SOURCE */ |
|---|
| 1958 | |
|---|
| 1959 | |
|---|
| 1960 | |
|---|
| 1961 | /* ========================== Origem: CITRM.C ========================== */ |
|---|
| 1962 | |
|---|
| 1963 | #if CICPP || CITRM_CISISX_SOURCE |
|---|
| 1964 | |
|---|
| 1965 | #if CICPP |
|---|
| 1966 | int CISISX :: xcntread(DBXSTRU *dbxp, |
|---|
| 1967 | int *ifpopen, |
|---|
| 1968 | char *ifpname, |
|---|
| 1969 | int *firstcnli) |
|---|
| 1970 | #else /* CICPP */ |
|---|
| 1971 | int cntread(dbxp,ifpopen,ifpname,firstcnli) |
|---|
| 1972 | DBXSTRU *dbxp; |
|---|
| 1973 | int *ifpopen; |
|---|
| 1974 | char *ifpname; |
|---|
| 1975 | int *firstcnli; |
|---|
| 1976 | #endif /* CICPP */ |
|---|
| 1977 | { |
|---|
| 1978 | INVMAP *invp; |
|---|
| 1979 | int fd,treecase; |
|---|
| 1980 | unsigned char *p; |
|---|
| 1981 | #if TRCTRACE |
|---|
| 1982 | CNSTRU *cp; |
|---|
| 1983 | int n; |
|---|
| 1984 | #endif |
|---|
| 1985 | |
|---|
| 1986 | if (!DBXifmap) dbxinvmp(dbxp); |
|---|
| 1987 | invp=DBXifmap; |
|---|
| 1988 | |
|---|
| 1989 | /* open .cnt */ |
|---|
| 1990 | if (!invp->cnopn || (trmifupd && !invp->cnopw) |
|---|
| 1991 | #if MULTI |
|---|
| 1992 | || DBXnetws != MONONETS |
|---|
| 1993 | #endif |
|---|
| 1994 | ) { |
|---|
| 1995 | |
|---|
| 1996 | if (strcmp(DBXname,"null") == 0) { |
|---|
| 1997 | /* |
|---|
| 1998 | idtype=1 ordn=5 ordf=5 n=15 k=5 liv=-1 posrx=0 nmaxpos=0 fmaxpos=0 abnormal=0 |
|---|
| 1999 | idtype=2 ordn=5 ordf=5 n=15 k=5 liv=-1 posrx=0 nmaxpos=0 fmaxpos=0 abnormal=0 |
|---|
| 2000 | */ |
|---|
| 2001 | for (treecase=0; treecase < 2; treecase++) { |
|---|
| 2002 | invp->cn[treecase].idtype=treecase+1; |
|---|
| 2003 | invp->cn[treecase].ordn=ORDN; |
|---|
| 2004 | invp->cn[treecase].ordf=ORDF; |
|---|
| 2005 | invp->cn[treecase].n=CNTN; |
|---|
| 2006 | invp->cn[treecase].k=CNTK; |
|---|
| 2007 | invp->cn[treecase].liv=NEGLIV; |
|---|
| 2008 | invp->cn[treecase].posrx=0; |
|---|
| 2009 | invp->cn[treecase].nmaxpos=0; |
|---|
| 2010 | invp->cn[treecase].fmaxpos=0; |
|---|
| 2011 | invp->cn[treecase].abnormal=ABNORMAL; |
|---|
| 2012 | } |
|---|
| 2013 | } |
|---|
| 2014 | #if TRSTRACE |
|---|
| 2015 | if (trmtrace && dbxtrace) { |
|---|
| 2016 | printf("cntread - invp=%p DBXname=%s ",DBXifmap,DBXname); |
|---|
| 2017 | printf(" opn=%d opw=%d\n",invp->cnopn,invp->cnopw); |
|---|
| 2018 | } |
|---|
| 2019 | #endif |
|---|
| 2020 | if (strcmp(DBXname,"null") == 0) return(0); |
|---|
| 2021 | |
|---|
| 2022 | p=(UCHR *)invp->cn; |
|---|
| 2023 | invp->cc_offset=0; /* v4.2 */ |
|---|
| 2024 | #if CNLI |
|---|
| 2025 | dbxopt_fatal=0; /* set value for next dbxopen() call */ |
|---|
| 2026 | if ((fd=dbxopen(DBXname,DBXname,iy0extp)) > 0) { |
|---|
| 2027 | if (CIREAD(fd,p,CNBSIZ) != CNBSIZ) fatal("cntread/read/iy0"); |
|---|
| 2028 | invp->cc_offset+=(6*CNBSIZ); |
|---|
| 2029 | if (trmtrace) |
|---|
| 2030 | printf("cntread - cc_offset =%ld\n", |
|---|
| 2031 | invp->cc_offset); |
|---|
| 2032 | invp->cc_offset+=atol((CONST char *)p); |
|---|
| 2033 | if (invp->cc_offset != (6+2)*CNBSIZ) fatal("cntread/cc_offset"); |
|---|
| 2034 | for (treecase=0; treecase < 2; treecase++) { |
|---|
| 2035 | if (CIREAD(fd,p,CNBSIZ) != CNBSIZ) fatal("cntread/read/iy0"); |
|---|
| 2036 | invp->cn_offset[treecase]=invp->cc_offset; |
|---|
| 2037 | if (trmtrace) |
|---|
| 2038 | printf("cntread - cn_offset[%d]=%ld\n",treecase, |
|---|
| 2039 | invp->cn_offset[treecase]); |
|---|
| 2040 | if (treecase) invp->n2opn=fd; else invp->n1opn=fd; |
|---|
| 2041 | if (dbxordwr) if (treecase) invp->n2opw++; else invp->n1opw++; |
|---|
| 2042 | invp->cc_offset+=atol((CONST char *)p); |
|---|
| 2043 | } |
|---|
| 2044 | for (treecase=0; treecase < 2; treecase++) { |
|---|
| 2045 | if (CIREAD(fd,p,CNBSIZ) != CNBSIZ) fatal("cntread/read/iy0"); |
|---|
| 2046 | invp->cl_offset[treecase]=invp->cc_offset; |
|---|
| 2047 | if (trmtrace) |
|---|
| 2048 | printf("cntread - cl_offset[%d]=%ld\n",treecase, |
|---|
| 2049 | invp->cl_offset[treecase]); |
|---|
| 2050 | if (treecase) invp->l2opn=fd; else invp->l1opn=fd; |
|---|
| 2051 | if (dbxordwr) if (treecase) invp->l2opw++; else invp->l1opw++; |
|---|
| 2052 | invp->cc_offset+=atol((CONST char *)p); |
|---|
| 2053 | } |
|---|
| 2054 | if (CIREAD(fd,p,CNBSIZ) != CNBSIZ) fatal("cntread/read/iy0"); |
|---|
| 2055 | invp->ci_offset=0; |
|---|
| 2056 | if (atol((CONST char *)p)) |
|---|
| 2057 | invp->ci_offset=invp->cc_offset; |
|---|
| 2058 | if (trmtrace) |
|---|
| 2059 | printf("cntread - ci_offset =%ld\n",invp->ci_offset); |
|---|
| 2060 | if (invp->ci_offset) { |
|---|
| 2061 | #if SAMEL |
|---|
| 2062 | invp->ifopn[0]=fd; |
|---|
| 2063 | #else |
|---|
| 2064 | invp->ifopn=fd; |
|---|
| 2065 | if (dbxordwr) invp->ifopw++; |
|---|
| 2066 | #endif |
|---|
| 2067 | if (ifpopen) *ifpopen=1; |
|---|
| 2068 | } |
|---|
| 2069 | else { |
|---|
| 2070 | if (ifpname) strcpy(ifpname,DBXname); |
|---|
| 2071 | if (strlen(DBXname) < 2) fatal("cntread/ifpname"); |
|---|
| 2072 | if (ifpname) ifpname[strlen(DBXname)-1]='\0'; /* strip last char */ |
|---|
| 2073 | } |
|---|
| 2074 | invp->cc_offset=6*CNBSIZ; |
|---|
| 2075 | if (firstcnli) *firstcnli=1; |
|---|
| 2076 | } |
|---|
| 2077 | else |
|---|
| 2078 | fd=dbxopen(DBXname,DBXname,cx1extp); |
|---|
| 2079 | #else /* CNLI */ |
|---|
| 2080 | if (ifpopen) {;} /* no wrn */ |
|---|
| 2081 | if (ifpname) {;} /* no wrn */ |
|---|
| 2082 | if (firstcnli) {;} /* no wrn */ |
|---|
| 2083 | #if MULTI |
|---|
| 2084 | if (trmifupd || DBXnetws != MONONETS) |
|---|
| 2085 | fd=dbxopenw(DBXname,DBXname,cx1extp,&DBIcnopn,&DBIcnopw,"cnread/cnopn/w"); |
|---|
| 2086 | else { |
|---|
| 2087 | fd=invp->cnopn=dbxopen(DBXname,DBXname,cx1extp); |
|---|
| 2088 | if (dbxordwr) invp->cnopw++; |
|---|
| 2089 | } |
|---|
| 2090 | #else /* MULTI */ |
|---|
| 2091 | fd=dbxopen(DBXname,DBXname,cx1extp); |
|---|
| 2092 | if (dbxordwr) invp->cnopw++; |
|---|
| 2093 | #endif /* MULTI */ |
|---|
| 2094 | #endif /* CNLI */ |
|---|
| 2095 | if (trmtrace) printf("cntread - %s opn=%d opw=%d\n",DBXname,invp->cnopn,invp->cnopw); |
|---|
| 2096 | } |
|---|
| 2097 | |
|---|
| 2098 | /* read .cnt into DBIcn[] */ |
|---|
| 2099 | #if BEFORE950820 |
|---|
| 2100 | if (LSEEK64(fd,0L,SEEK_SET) != 0) fatal("cntread/seek"); /* see CNLI */ |
|---|
| 2101 | #endif |
|---|
| 2102 | #if CNV_PCFILES |
|---|
| 2103 | if (CIREAD(fd,p,CNBSIZ-CNBUNI) != CNBSIZ-CNBUNI) |
|---|
| 2104 | #else |
|---|
| 2105 | if (CIREAD(fd,p,CNBSIZ) != CNBSIZ) |
|---|
| 2106 | #endif |
|---|
| 2107 | fatal("cntread/read/cnt1"); |
|---|
| 2108 | #if CNV_PCBINUM |
|---|
| 2109 | ConvertCNT_REC(p); |
|---|
| 2110 | #endif |
|---|
| 2111 | #if TRCTRACE |
|---|
| 2112 | printf("+++cnt1:\n"); |
|---|
| 2113 | cp=(CNSTRU *)p; |
|---|
| 2114 | printf("idtype=%d ordn=%d ordf=%d n=%d k=%d ", |
|---|
| 2115 | cp->idtype,cp->ordn,cp->ordf,cp->n,cp->k); |
|---|
| 2116 | printf("liv=%d posrx=%ld\n", |
|---|
| 2117 | cp->liv,cp->posrx); |
|---|
| 2118 | printf("nmaxpos=%ld fmaxpos=%ld abnormal=%d\n", |
|---|
| 2119 | cp->nmaxpos,cp->fmaxpos,cp->abnormal); |
|---|
| 2120 | for (n=0; n<CNBSIZ; n++) printf("%02x ",p[n]); printf("\n"); |
|---|
| 2121 | #endif |
|---|
| 2122 | #if SAMEL |
|---|
| 2123 | if (invp->cn[0].idtype > 1000) { |
|---|
| 2124 | invp->iflxn=invp->cn[0].idtype-1000; |
|---|
| 2125 | if (invp->iflxn > MAXSAMEL) fatal(dbp); |
|---|
| 2126 | invp->cn[0].idtype = 1; |
|---|
| 2127 | } |
|---|
| 2128 | if (lxx > invp->iflxn) fatal(dbp); |
|---|
| 2129 | DBXiflxx=lxx; |
|---|
| 2130 | if (trmtrace) printf("cntread - iflxx=%d iflxn=%d \n", |
|---|
| 2131 | DBXiflxx,invp->iflxn); |
|---|
| 2132 | #endif |
|---|
| 2133 | #if ZTREE |
|---|
| 2134 | invp->iflzx=0; |
|---|
| 2135 | if (invp->cn[0].ordf > ORDF) { |
|---|
| 2136 | invp->iflzx=invp->cn[0].ordf-ORDF; |
|---|
| 2137 | invp->cn[0].ordf=ORDF; |
|---|
| 2138 | if (trmtrace) printf("cntread - iflzx=%d \n",invp->iflzx); |
|---|
| 2139 | } |
|---|
| 2140 | #endif |
|---|
| 2141 | if (invp->cn[0].idtype != 1) fatal("cntread/idtype/1"); |
|---|
| 2142 | if (invp->cn[0].ordf != ORDF) fatal("cntread/ordf/1"); |
|---|
| 2143 | p+=CNBSIZ; |
|---|
| 2144 | #if CNV_PCFILES |
|---|
| 2145 | if (CIREAD(fd,p,CNBSIZ-CNBUNI) != CNBSIZ-CNBUNI) |
|---|
| 2146 | #else |
|---|
| 2147 | if (CIREAD(fd,p,CNBSIZ) != CNBSIZ) |
|---|
| 2148 | #endif |
|---|
| 2149 | fatal("cntread/read/cnt2"); |
|---|
| 2150 | #if CNV_PCBINUM |
|---|
| 2151 | ConvertCNT_REC(p); |
|---|
| 2152 | #endif |
|---|
| 2153 | #if TRCTRACE |
|---|
| 2154 | printf("+++cnt2:\n"); |
|---|
| 2155 | cp=(CNSTRU *)p; |
|---|
| 2156 | printf("idtype=%d ordn=%d ordf=%d n=%d k=%d ", |
|---|
| 2157 | cp->idtype,cp->ordn,cp->ordf,cp->n,cp->k); |
|---|
| 2158 | printf("liv=%d posrx=%ld\n", |
|---|
| 2159 | cp->liv,cp->posrx); |
|---|
| 2160 | printf("nmaxpos=%ld fmaxpos=%ld abnormal=%d\n", |
|---|
| 2161 | cp->nmaxpos,cp->fmaxpos,cp->abnormal); |
|---|
| 2162 | for (n=0; n<CNBSIZ; n++) printf("%02x ",p[n]); printf("\n"); |
|---|
| 2163 | #endif |
|---|
| 2164 | if (invp->cn[1].idtype != 2) fatal("cntread/idtype/2"); |
|---|
| 2165 | if (invp->cn[1].ordf != ORDF) fatal("cntread/ordf/2"); |
|---|
| 2166 | |
|---|
| 2167 | if (!invp->cc_offset) /* v4.2 */ |
|---|
| 2168 | if (!invp->cnopw) { |
|---|
| 2169 | CLOSE(fd); fd=invp->cnopn=0; |
|---|
| 2170 | } |
|---|
| 2171 | |
|---|
| 2172 | return(fd); |
|---|
| 2173 | } |
|---|
| 2174 | |
|---|
| 2175 | #if CICPP |
|---|
| 2176 | void CISISX :: xinvsetup(UCHR *dbnamp, |
|---|
| 2177 | LONGX loadn0x, |
|---|
| 2178 | LONGX loadl0x, |
|---|
| 2179 | LONGX loadpst) |
|---|
| 2180 | #else /* CICPP */ |
|---|
| 2181 | void invsetup(dbnamp,loadn0x,loadl0x,loadpst) /* |
|---|
| 2182 | ------------- |
|---|
| 2183 | seta dbxp; |
|---|
| 2184 | aloca celula INVMAP para o database; |
|---|
| 2185 | abre, carrega registros e fecha .cnt; |
|---|
| 2186 | abre .n01 e .n02; |
|---|
| 2187 | inicializa estrutura de buffers nx; |
|---|
| 2188 | se loadn0x carrega e fecha .n0x |
|---|
| 2189 | abre .l01 e .l02; |
|---|
| 2190 | se loadl0x inicializa estrutura lx e carrega e fecha .l0x; |
|---|
| 2191 | abre .ifp; |
|---|
| 2192 | se loadpst inicializa estrutura px e carrega e fecha .ifp; |
|---|
| 2193 | */ |
|---|
| 2194 | UCHR *dbnamp; /* ptr nome base de dados a ler */ /* v3.3 |
|---|
| 2195 | */ |
|---|
| 2196 | LONGX loadn0x; /* carga total de .n0x */ /* v3.3 |
|---|
| 2197 | */ |
|---|
| 2198 | LONGX loadl0x; /* carga total de .n0x */ /* v3.3 |
|---|
| 2199 | */ |
|---|
| 2200 | LONGX loadpst; /* carga total de .ifp */ /* v3.3 |
|---|
| 2201 | */ |
|---|
| 2202 | #endif /* CICPP */ |
|---|
| 2203 | { |
|---|
| 2204 | #if BEFORE20010221 /* now in cisis.h - AOT, 21/02/2001 */ |
|---|
| 2205 | #if !CICPP |
|---|
| 2206 | extern int NXPAGES[]; |
|---|
| 2207 | #endif /* CICPP */ |
|---|
| 2208 | #endif /* BEFORE20010221 */ |
|---|
| 2209 | DBXSTRU *dbxp; |
|---|
| 2210 | INVMAP *invp; |
|---|
| 2211 | NXSTRU *nxp; |
|---|
| 2212 | #if !LIND |
|---|
| 2213 | IFPCTRL ifpctrl; /* v3.3 */ |
|---|
| 2214 | #endif |
|---|
| 2215 | int fd; |
|---|
| 2216 | UCHR *p; |
|---|
| 2217 | int treecase,liv,level,pagesize; |
|---|
| 2218 | off_t npages,nbytes,loop; |
|---|
| 2219 | int ifpopen; /* v4.2 */ |
|---|
| 2220 | int firstcnli; /* v4.2 */ |
|---|
| 2221 | char ifpname[sizeof(DBXname)]; /* v4.2 */ |
|---|
| 2222 | #if SAMEL |
|---|
| 2223 | char dbxname[sizeof(DBXname)],*dbp; |
|---|
| 2224 | int lxy; |
|---|
| 2225 | int lxx = 0; |
|---|
| 2226 | #endif |
|---|
| 2227 | |
|---|
| 2228 | if (trm_invload) loadn0x=loadl0x=loadpst=trm_invload; /* 28/03/97 */ |
|---|
| 2229 | |
|---|
| 2230 | #if SAMEL |
|---|
| 2231 | if (loadpst) fatal("invsetup/loadpst"); |
|---|
| 2232 | strcpy(dbxname,dbp=dbnamp); |
|---|
| 2233 | for (p=dbnamp=dbxname; *p; p++) |
|---|
| 2234 | if (*p == '#') { |
|---|
| 2235 | *p++ = '\0'; |
|---|
| 2236 | for (; isdigit(*p); p++) lxx=10*lxx+(int)*p-(int)'0'; |
|---|
| 2237 | if (*p) fatal(dbp); |
|---|
| 2238 | if (lxx < 1 || lxx > MAXSAMEL) fatal(dbp); |
|---|
| 2239 | break; |
|---|
| 2240 | } |
|---|
| 2241 | if (trmtrace) printf("invsetup - %s,%s,lxx=%d\n",dbp,dbnamp,lxx); |
|---|
| 2242 | #endif |
|---|
| 2243 | dbxp=dbxstorp((char *)dbnamp); |
|---|
| 2244 | if (trmtrace) printf("invsetup - %s ifmap=%p\n",dbnamp,DBXifmap); |
|---|
| 2245 | firstcnli=0; /* v4.2 */ |
|---|
| 2246 | ifpopen=0; |
|---|
| 2247 | ifpname[0]='\0'; |
|---|
| 2248 | invp=DBXifmap; |
|---|
| 2249 | if (!DBXifmap || trmifupd) { |
|---|
| 2250 | if (!DBXifmap) invp=dbxinvmp(dbxp); |
|---|
| 2251 | if (!invp->cn[0].idtype) fd=cntread(dbxp,&ifpopen,ifpname,&firstcnli); |
|---|
| 2252 | } |
|---|
| 2253 | |
|---|
| 2254 | if (strcmp((CONST char *)dbnamp,"null") == 0) |
|---|
| 2255 | return; |
|---|
| 2256 | |
|---|
| 2257 | /* node's */ |
|---|
| 2258 | if (firstcnli || /* v4.2 */ |
|---|
| 2259 | !invp->n1opn && invp->nybasep[0] == NULL && |
|---|
| 2260 | !invp->n2opn && invp->nybasep[1] == NULL) { |
|---|
| 2261 | if (!firstcnli) { |
|---|
| 2262 | fd=invp->n1opn=dbxopen(DBXname,DBXname,nx12extp[0]); |
|---|
| 2263 | if (dbxordwr) invp->n1opw++; |
|---|
| 2264 | } |
|---|
| 2265 | pagesize=N1BSIZ; |
|---|
| 2266 | for (treecase=0; treecase<2; treecase++) { |
|---|
| 2267 | liv=invp->cn[treecase].liv; |
|---|
| 2268 | if (liv < 0) |
|---|
| 2269 | if (liv != NEGLIV) /* v3.1 */ |
|---|
| 2270 | fatal("invsetup/liv/NEGLIV"); |
|---|
| 2271 | #if TRETRACE |
|---|
| 2272 | else |
|---|
| 2273 | printf("invsetup - liv=%d for treecase %d\n",liv,treecase); |
|---|
| 2274 | #endif |
|---|
| 2275 | if (liv >= MAXLIV) |
|---|
| 2276 | fatal("invsetup/liv/MAXLIV"); |
|---|
| 2277 | invp->nybasep[treecase]=NULL; |
|---|
| 2278 | if ((liv == NEGLIV || loadn0x) && !trmifupd) { /* 08/03/95 */ |
|---|
| 2279 | npages=invp->cn[treecase].nmaxpos; |
|---|
| 2280 | if (npages) { |
|---|
| 2281 | nbytes=pagesize*npages; |
|---|
| 2282 | #if !CICPP |
|---|
| 2283 | if (loadn0x > ALLOMAXV) |
|---|
| 2284 | fatal("invsetup/ALLOMAXV/.n0x"); |
|---|
| 2285 | #endif /* CICPP */ |
|---|
| 2286 | if (nbytes > loadn0x) |
|---|
| 2287 | goto OPENN02; |
|---|
| 2288 | #if CICPP |
|---|
| 2289 | try { invp->nybasep[treecase]= new char [nbytes]; } |
|---|
| 2290 | catch (BAD_ALLOC) { invp->nybasep[treecase] = (char *)ALLONULL; } |
|---|
| 2291 | #else /* CICPP */ |
|---|
| 2292 | invp->nybasep[treecase]=(char *)ALLOC((ALLOPARM)(nbytes)); |
|---|
| 2293 | #endif /* CICPP */ |
|---|
| 2294 | if (invp->nybasep[treecase] == (char *)ALLONULL) |
|---|
| 2295 | fatal("invsetup/ALLOC/nypages"); |
|---|
| 2296 | #if TRSXRACE |
|---|
| 2297 | if (trmtrace) { |
|---|
| 2298 | printf("invsetup - nybasep[%d]=%p %6ld/%6ld=%6ld bytes/pages fd=%d\n", |
|---|
| 2299 | treecase,invp->nybasep[treecase],nbytes,npages,nbytes/npages,fd); |
|---|
| 2300 | } |
|---|
| 2301 | #endif |
|---|
| 2302 | } |
|---|
| 2303 | else { |
|---|
| 2304 | ; |
|---|
| 2305 | #if TRSXRACE |
|---|
| 2306 | if (trmtrace) { |
|---|
| 2307 | printf("invsetup - nybasep[%d]=%p %ld pages\n", |
|---|
| 2308 | treecase,invp->nybasep[treecase],npages); |
|---|
| 2309 | } |
|---|
| 2310 | #endif |
|---|
| 2311 | } |
|---|
| 2312 | #if CNLI |
|---|
| 2313 | /* .... 951208 */ |
|---|
| 2314 | LSEEK64(fd,invp->cn_offset[treecase],SEEK_SET); |
|---|
| 2315 | #endif |
|---|
| 2316 | for (p=(unsigned char *)invp->nybasep[treecase], loop=npages; loop--; |
|---|
| 2317 | p+=pagesize) |
|---|
| 2318 | if (CIREAD(fd,p,pagesize) != pagesize) |
|---|
| 2319 | fatal("invsetup/read/nypages"); |
|---|
| 2320 | if (!invp->cc_offset) { /* v4.2 */ |
|---|
| 2321 | CLOSE(fd); |
|---|
| 2322 | if (treecase) invp->n2opn=0; else invp->n1opn=0; |
|---|
| 2323 | if (treecase) invp->n2opw=0; else invp->n1opw=0; |
|---|
| 2324 | } |
|---|
| 2325 | } |
|---|
| 2326 | OPENN02: |
|---|
| 2327 | if ((invp->nybasep[treecase] == NULL) && !trmifupd) { /* 08/03/95 */ |
|---|
| 2328 | for (level=0; level<=liv; level++) { |
|---|
| 2329 | nxp= &invp->nx[treecase][level]; |
|---|
| 2330 | #if CICPP |
|---|
| 2331 | nxp->pages = 1; |
|---|
| 2332 | #else /* CICPP */ |
|---|
| 2333 | nxp->pages = NXPAGES[level]; |
|---|
| 2334 | #endif /* CICPP */ |
|---|
| 2335 | nxp->left=nxp->pages; |
|---|
| 2336 | nbytes=pagesize*nxp->pages; |
|---|
| 2337 | #if CICPP |
|---|
| 2338 | try { nxp->basep=(char *) new char [nbytes]; } |
|---|
| 2339 | catch (BAD_ALLOC) { nxp->basep = (char *)ALLONULL; } |
|---|
| 2340 | #else /* CICPP */ |
|---|
| 2341 | if ((nbytes) > ALLOMAXV) |
|---|
| 2342 | fatal("invsetup/ALLOMAXV/nbytes)"); |
|---|
| 2343 | nxp->basep=(char *)ALLOC((ALLOPARM)(nbytes)); |
|---|
| 2344 | #endif /* CICPP */ |
|---|
| 2345 | if (nxp->basep == (char *)ALLONULL) |
|---|
| 2346 | fatal("invsetup/ALLOC/nxpages"); |
|---|
| 2347 | #if TRSTRACE |
|---|
| 2348 | if (trmtrace && dbxtrace) { |
|---|
| 2349 | printf("invsetup - nxp[%d][%d]=%p com %ld bytes\n",treecase,level,nxp,nbytes); |
|---|
| 2350 | } |
|---|
| 2351 | #endif |
|---|
| 2352 | } |
|---|
| 2353 | } |
|---|
| 2354 | if (treecase == 0) |
|---|
| 2355 | if (!firstcnli) { |
|---|
| 2356 | fd=invp->n2opn=dbxopen(DBXname,DBXname,nx12extp[1]); |
|---|
| 2357 | if (dbxordwr) invp->n2opw++; |
|---|
| 2358 | } |
|---|
| 2359 | pagesize=N2BSIZ; |
|---|
| 2360 | } |
|---|
| 2361 | } |
|---|
| 2362 | /* leaf's */ |
|---|
| 2363 | if (firstcnli || /* v4.2 */ |
|---|
| 2364 | !invp->l1opn && invp->lybasep[0] == NULL && |
|---|
| 2365 | !invp->l2opn && invp->lybasep[1] == NULL) { |
|---|
| 2366 | if (!firstcnli) { |
|---|
| 2367 | fd=invp->l1opn=dbxopen(DBXname,DBXname,lx12extp[0]); |
|---|
| 2368 | if (dbxordwr) invp->l1opw++; |
|---|
| 2369 | } |
|---|
| 2370 | pagesize=L1BSIZ; |
|---|
| 2371 | for (treecase=0; treecase<2; treecase++) { |
|---|
| 2372 | invp->lybasep[treecase]=NULL; |
|---|
| 2373 | if ((liv == NEGLIV || loadl0x) && !trmifupd) { /* 08/03/95 */ |
|---|
| 2374 | npages=invp->cn[treecase].fmaxpos; |
|---|
| 2375 | if (npages) { |
|---|
| 2376 | nbytes=pagesize*npages; |
|---|
| 2377 | #if !CICPP |
|---|
| 2378 | if (loadl0x > ALLOMAXV) |
|---|
| 2379 | fatal("invsetup/ALLOMAXV/.l0x"); |
|---|
| 2380 | #endif /* CICPP */ |
|---|
| 2381 | if (nbytes > loadl0x) |
|---|
| 2382 | goto OPENL02; |
|---|
| 2383 | #if CICPP |
|---|
| 2384 | try { invp->lybasep[treecase]= (char *) new char [nbytes]; } |
|---|
| 2385 | catch (BAD_ALLOC) {invp->lybasep[treecase] = (char *)ALLONULL; } |
|---|
| 2386 | #else /* CICPP */ |
|---|
| 2387 | invp->lybasep[treecase]=(char *)ALLOC((ALLOPARM)(nbytes)); |
|---|
| 2388 | #endif /* CICPP */ |
|---|
| 2389 | if (invp->lybasep[treecase] == (char *)ALLONULL) |
|---|
| 2390 | fatal("invsetup/ALLOC/lypages"); |
|---|
| 2391 | #if TRSXRACE |
|---|
| 2392 | if (trmtrace) { |
|---|
| 2393 | printf("invsetup - lybasep[%d]=%p %6ld/%6ld=%6ld bytes/pages fd=%d\n", |
|---|
| 2394 | treecase,invp->lybasep[treecase],nbytes,npages,nbytes/npages,fd); |
|---|
| 2395 | } |
|---|
| 2396 | #endif |
|---|
| 2397 | } |
|---|
| 2398 | else { |
|---|
| 2399 | ; |
|---|
| 2400 | #if TRSXRACE |
|---|
| 2401 | if (trmtrace) { |
|---|
| 2402 | printf("invsetup - lybasep[%d]=%p %ld pages\n", |
|---|
| 2403 | treecase,invp->lybasep[treecase],npages); |
|---|
| 2404 | } |
|---|
| 2405 | #endif |
|---|
| 2406 | } |
|---|
| 2407 | #if CNLI |
|---|
| 2408 | /* .... 951208 */ |
|---|
| 2409 | LSEEK64(fd,invp->cl_offset[treecase],SEEK_SET); |
|---|
| 2410 | #endif |
|---|
| 2411 | for (p=(unsigned char *)invp->lybasep[treecase], loop=npages; loop--; |
|---|
| 2412 | p+=pagesize) { |
|---|
| 2413 | if (CIREAD(fd,p,pagesize) != pagesize) |
|---|
| 2414 | fatal("invsetup/read/lypages"); |
|---|
| 2415 | if (loop+((L0STRU *)p)->pos != npages){ |
|---|
| 2416 | printf("*** loop=%"P_OFF_T" pos=%ld", |
|---|
| 2417 | (LONG_LONG)loop,((L0STRU *)p)->pos); |
|---|
| 2418 | fatal("invsetup/check/lypages"); |
|---|
| 2419 | } |
|---|
| 2420 | } |
|---|
| 2421 | if (!invp->cc_offset) { /* v4.2 */ |
|---|
| 2422 | CLOSE(fd); |
|---|
| 2423 | if (treecase) invp->l2opn=0; else invp->l1opn=0; |
|---|
| 2424 | if (treecase) invp->l2opw=0; else invp->l1opw=0; |
|---|
| 2425 | } |
|---|
| 2426 | } |
|---|
| 2427 | OPENL02: |
|---|
| 2428 | if (treecase == 0) |
|---|
| 2429 | if (!firstcnli) { |
|---|
| 2430 | fd=invp->l2opn=dbxopen(DBXname,DBXname,lx12extp[1]); |
|---|
| 2431 | if (dbxordwr) invp->l2opw++; |
|---|
| 2432 | } |
|---|
| 2433 | pagesize=L2BSIZ; |
|---|
| 2434 | } |
|---|
| 2435 | } |
|---|
| 2436 | /* post's */ |
|---|
| 2437 | #if IFPDUMMY |
|---|
| 2438 | if (loadpst >= 0L) { |
|---|
| 2439 | #endif |
|---|
| 2440 | if (ifpopen || /* v4.2 */ |
|---|
| 2441 | #if SAMEL |
|---|
| 2442 | !invp->ifopn[0] && |
|---|
| 2443 | #else |
|---|
| 2444 | !invp->ifopn && |
|---|
| 2445 | #endif |
|---|
| 2446 | invp->iybasep == NULL) { |
|---|
| 2447 | if (!*ifpname) strcpy(ifpname,DBXname); |
|---|
| 2448 | if (!ifpopen) { |
|---|
| 2449 | #if SAMEL |
|---|
| 2450 | if (lxx) sprintf(ifpname,"%s#%d",DBXname,lxx); |
|---|
| 2451 | fd=invp->ifopn[0]=dbxopen(DBXname,ifpname,ix1extp); |
|---|
| 2452 | for (lxy=2; lxy <= invp->iflxn; lxy++) { |
|---|
| 2453 | sprintf(ifpname,"%s#%d",DBXname,lxy); |
|---|
| 2454 | fd=invp->ifopn[lxy-1]=dbxopen(DBXname,ifpname,ix1extp); |
|---|
| 2455 | #if TRSXRACE |
|---|
| 2456 | if (trmtrace) printf("invsetup - ifpname=%s fd=%d\n",ifpname,fd); |
|---|
| 2457 | #endif |
|---|
| 2458 | } |
|---|
| 2459 | #else |
|---|
| 2460 | dbxopt_fatal=0; |
|---|
| 2461 | fd=invp->ifopn =dbxopen(DBXname,ifpname,ix1extp); |
|---|
| 2462 | if (fd <= 0) { |
|---|
| 2463 | fd=invp->ifopn =dbxopen(DBXname,DBXname,ix1extp); |
|---|
| 2464 | } |
|---|
| 2465 | if (dbxordwr) invp->ifopw++; |
|---|
| 2466 | #endif |
|---|
| 2467 | } /* end if (!ifpopen) */ |
|---|
| 2468 | |
|---|
| 2469 | pagesize=IFBSIZ; |
|---|
| 2470 | invp->iybasep=NULL; |
|---|
| 2471 | if ((invp->cn[0].liv == NEGLIV && |
|---|
| 2472 | invp->cn[1].liv == NEGLIV || loadpst) && !trmifupd) { /* 08/03/95 */ |
|---|
| 2473 | #if SAMEL |
|---|
| 2474 | if (lxx) { |
|---|
| 2475 | printf("*** dbname=%s\n",dbp); |
|---|
| 2476 | fatal("invsetup/SAMEL/loadpst"); |
|---|
| 2477 | } |
|---|
| 2478 | #endif |
|---|
| 2479 | #if CNLI |
|---|
| 2480 | /* .... 951208 */ |
|---|
| 2481 | loop=LSEEK64(fd,invp->ci_offset,SEEK_SET); |
|---|
| 2482 | #endif |
|---|
| 2483 | #if !LIND |
|---|
| 2484 | if (CIREAD(fd,(char *)&ifpctrl,sizeof(IFPCTRL)) != sizeof(IFPCTRL)) { |
|---|
| 2485 | fatal("invsetup/read/ifpctrl"); |
|---|
| 2486 | } |
|---|
| 2487 | #if CNV_PCBINUM |
|---|
| 2488 | ConvertIFP_BLKCTL((char *)&ifpctrl,1); |
|---|
| 2489 | #endif |
|---|
| 2490 | LSEEK64(fd,-sizeof(IFPCTRL),SEEK_CUR); |
|---|
| 2491 | npages=ifpctrl.ifprec1; |
|---|
| 2492 | if (ifpctrl.ifprec2 == 0) |
|---|
| 2493 | npages--; |
|---|
| 2494 | nbytes=pagesize*npages; |
|---|
| 2495 | #else /* LIND */ |
|---|
| 2496 | #if BEFORE951208 |
|---|
| 2497 | nbytes=LSEEK64(fd,0L,SEEK_CUR); |
|---|
| 2498 | #else |
|---|
| 2499 | nbytes=LSEEK64(fd,0L,SEEK_END); |
|---|
| 2500 | #if CNLI |
|---|
| 2501 | nbytes-=loop; |
|---|
| 2502 | #endif |
|---|
| 2503 | LSEEK64(fd,loop,SEEK_SET); |
|---|
| 2504 | #endif |
|---|
| 2505 | npages=nbytes/pagesize; |
|---|
| 2506 | #endif |
|---|
| 2507 | #if !CICPP |
|---|
| 2508 | if (loadpst > ALLOMAXV) |
|---|
| 2509 | fatal("invsetup/ALLOMAXV/.ifp"); |
|---|
| 2510 | #endif |
|---|
| 2511 | if (nbytes > loadpst || npages == 0) /* 04/10/91 */ |
|---|
| 2512 | ; |
|---|
| 2513 | else { |
|---|
| 2514 | #if CICPP |
|---|
| 2515 | try { invp->iybasep=(char *) new char [nbytes]; } |
|---|
| 2516 | catch (BAD_ALLOC) {invp->iybasep = (char *)ALLONULL; } |
|---|
| 2517 | #else /* CICPP */ |
|---|
| 2518 | invp->iybasep=(char *)ALLOC((ALLOPARM)(nbytes)); |
|---|
| 2519 | #endif /* CICPP */ |
|---|
| 2520 | #if TRSXRACE |
|---|
| 2521 | if (trmtrace) { |
|---|
| 2522 | printf("invsetup - iybasep =%p %6ld/%6ld=%6ld bytes/pages fd=%d\n", |
|---|
| 2523 | invp->iybasep,nbytes,npages,nbytes/npages,fd); |
|---|
| 2524 | } |
|---|
| 2525 | #endif |
|---|
| 2526 | if (invp->iybasep == (char *)ALLONULL) |
|---|
| 2527 | fatal("invsetup/ALLOC/iypages"); |
|---|
| 2528 | for (p=(unsigned char *)invp->iybasep, loop=npages; loop--; p+=pagesize) |
|---|
| 2529 | if (CIREAD(fd,p,pagesize) != pagesize) |
|---|
| 2530 | fatal("invsetup/read/iypages"); |
|---|
| 2531 | if (!invp->cc_offset) { /* v4.2 */ |
|---|
| 2532 | CLOSE(fd); |
|---|
| 2533 | #if SAMEL |
|---|
| 2534 | invp->ifopn[0]=0; |
|---|
| 2535 | #else |
|---|
| 2536 | invp->ifopn=0; |
|---|
| 2537 | invp->ifopw=0; |
|---|
| 2538 | #endif |
|---|
| 2539 | } |
|---|
| 2540 | } |
|---|
| 2541 | } /* end if (invp->cn[] == NEGLIV || loadpst) */ |
|---|
| 2542 | } /* end if (ifpopen || ! invp->ifopn) */ |
|---|
| 2543 | #if IFPDUMMY |
|---|
| 2544 | } /* end if (loadpst >= 0L) */ |
|---|
| 2545 | #endif |
|---|
| 2546 | } |
|---|
| 2547 | #if CICPP |
|---|
| 2548 | N0STRU * CISISX :: xnoderead(INVMAP *invp, |
|---|
| 2549 | int treecase, |
|---|
| 2550 | int level, |
|---|
| 2551 | PUNT punt) |
|---|
| 2552 | #else /* CICPP */ |
|---|
| 2553 | N0STRU *noderead(invp,treecase,level,punt) /* |
|---|
| 2554 | ---------------- |
|---|
| 2555 | aponta para a area de Nos em memoria; |
|---|
| 2556 | pesquisa o No' desejado; |
|---|
| 2557 | se achou, retorna pointer; |
|---|
| 2558 | determina endereco para leitura; |
|---|
| 2559 | posiciona registro desejado; |
|---|
| 2560 | le registro; |
|---|
| 2561 | retorna pointer N0STRU ou abenda; |
|---|
| 2562 | */ |
|---|
| 2563 | INVMAP *invp; /* ptr descritor do inverted file */ |
|---|
| 2564 | int treecase; /* indice da B*Tree a pesquisar */ |
|---|
| 2565 | int level; /* nivel da arvore a pesquisar */ |
|---|
| 2566 | PUNT punt; /* registro desejado */ |
|---|
| 2567 | #endif /* CICPP */ |
|---|
| 2568 | { |
|---|
| 2569 | N0STRU *np; |
|---|
| 2570 | N1STRU *n1p; /* v3.3 */ |
|---|
| 2571 | N2STRU *n2p; /* v3.3 */ |
|---|
| 2572 | NXSTRU *nxp; |
|---|
| 2573 | int total,left,used; |
|---|
| 2574 | UCHR *basep; |
|---|
| 2575 | int n,nodesize,fd; |
|---|
| 2576 | UCHR *p; |
|---|
| 2577 | off_t xbytes; |
|---|
| 2578 | #if IFUPDATE |
|---|
| 2579 | static UCHR nodearea[N2BSIZ]; /* area para ler pagina de.n01/.n02 */ |
|---|
| 2580 | #endif |
|---|
| 2581 | #if CNV_PCFILES |
|---|
| 2582 | N0STRU *unp; |
|---|
| 2583 | char *up; |
|---|
| 2584 | #endif |
|---|
| 2585 | #if LINDLUX |
|---|
| 2586 | if (invp->ltxpages[treecase]) { |
|---|
| 2587 | if (punt < 1) fatal("noderead/punt"); |
|---|
| 2588 | if (punt > invp->ltxpages[treecase]) fatal("noderead/punt"); |
|---|
| 2589 | if ((np=invp->ltxvpagp[treecase][punt]) == NULL) fatal("noderead/ltx"); |
|---|
| 2590 | return(np); |
|---|
| 2591 | } |
|---|
| 2592 | #endif /* LINDLUX */ |
|---|
| 2593 | if (treecase) { |
|---|
| 2594 | nodesize=N2BSIZ; |
|---|
| 2595 | fd=invp->n2opn; |
|---|
| 2596 | } |
|---|
| 2597 | else { |
|---|
| 2598 | nodesize=N1BSIZ; |
|---|
| 2599 | fd=invp->n1opn; |
|---|
| 2600 | } |
|---|
| 2601 | #if TRNTRACE |
|---|
| 2602 | printf("noderead - invp=%p treecase=%d level=%d punt=%ld\n", |
|---|
| 2603 | invp,treecase,level,(LONGX)punt); |
|---|
| 2604 | #if CNLI |
|---|
| 2605 | printf("noderead - fd=%d offset=%ld\n",fd,invp->cn_offset[treecase]); |
|---|
| 2606 | #endif |
|---|
| 2607 | #endif |
|---|
| 2608 | nxp= &invp->nx[treecase][level]; |
|---|
| 2609 | p=(unsigned char *)invp->nybasep[treecase]; /* v3.3 */ |
|---|
| 2610 | if (fd == 0 && p == NULL) |
|---|
| 2611 | fatal("noderead/fd&p"); |
|---|
| 2612 | if (p != NULL) { |
|---|
| 2613 | #if IFUPDATE |
|---|
| 2614 | if (trmifupd) fatal("noderead/IFUPDATE/p"); |
|---|
| 2615 | #endif |
|---|
| 2616 | if (treecase) { |
|---|
| 2617 | n2p=(N2STRU *)p; n2p+=(punt-1L); |
|---|
| 2618 | #if TRNTRACE |
|---|
| 2619 | printf("noderead - p=%p n2p=%p\n",p,n2p); |
|---|
| 2620 | #endif |
|---|
| 2621 | p=(UCHR *)n2p; |
|---|
| 2622 | } |
|---|
| 2623 | else { |
|---|
| 2624 | n1p=(N1STRU *)p; n1p+=(punt-1L); |
|---|
| 2625 | #if TRNTRACE |
|---|
| 2626 | printf("noderead - p=%p n1p=%p\n",p,n1p); |
|---|
| 2627 | #endif |
|---|
| 2628 | p=(UCHR *)n1p; |
|---|
| 2629 | } |
|---|
| 2630 | } |
|---|
| 2631 | else { /* v3.3 */ |
|---|
| 2632 | total=nxp->pages; |
|---|
| 2633 | left= nxp->left; used=total-left; |
|---|
| 2634 | basep=(unsigned char *)nxp->basep; |
|---|
| 2635 | #if TRNTRACE |
|---|
| 2636 | printf("noderead - nodesize=%d fd=%d total=%d left=%d basep=%p\n", |
|---|
| 2637 | nodesize,fd,total,left,basep); |
|---|
| 2638 | #endif |
|---|
| 2639 | #if IFUPDATE |
|---|
| 2640 | if (trmifupd) /* 15/04/93 */ |
|---|
| 2641 | p=nodearea; |
|---|
| 2642 | else |
|---|
| 2643 | for (n=used, p=basep; n--; p+=nodesize) { |
|---|
| 2644 | np=(N0STRU *)p; |
|---|
| 2645 | #if TRNTRACE |
|---|
| 2646 | printf("noderead - teste com np->pos=%ld\n",(LONGX)np->pos); |
|---|
| 2647 | #endif |
|---|
| 2648 | if (np->pos == punt) |
|---|
| 2649 | return(np); /* CNV_PCBINUM ok */ |
|---|
| 2650 | } |
|---|
| 2651 | #else |
|---|
| 2652 | for (n=used, p=basep; n--; p+=nodesize) { |
|---|
| 2653 | np=(N0STRU *)p; |
|---|
| 2654 | #if TRNTRACE |
|---|
| 2655 | printf("noderead - teste com np->pos=%ld\n",(LONGX)np->pos); |
|---|
| 2656 | #endif |
|---|
| 2657 | if (np->pos == punt) |
|---|
| 2658 | return(np); /* CNV_PCBINUM ok */ |
|---|
| 2659 | } |
|---|
| 2660 | if (left) { |
|---|
| 2661 | p=basep+nodesize*used; /* first unused buffer */ |
|---|
| 2662 | left--; nxp->left=left; |
|---|
| 2663 | } |
|---|
| 2664 | else { |
|---|
| 2665 | p=basep+nodesize*(punt%total); /* any one */ |
|---|
| 2666 | } |
|---|
| 2667 | #endif |
|---|
| 2668 | |
|---|
| 2669 | #if CNV_PCFILES |
|---|
| 2670 | nodesize-=(treecase)?TWORDN*N2BUNI:TWORDN*N1BUNI; |
|---|
| 2671 | #endif |
|---|
| 2672 | xbytes=((off_t)(punt-1L))*nodesize; |
|---|
| 2673 | #if CNLI |
|---|
| 2674 | xbytes+=invp->cn_offset[treecase]; |
|---|
| 2675 | #endif |
|---|
| 2676 | #if TRNTRACE |
|---|
| 2677 | printf("noderead - xbytes=%"P_OFF_T" nodesize=%d \n",(LONG_LONG)xbytes,nodesize); |
|---|
| 2678 | #endif |
|---|
| 2679 | if (LSEEK64(fd,xbytes,SEEK_SET) != xbytes) |
|---|
| 2680 | fatal("noderead/lseek"); |
|---|
| 2681 | #if TRNTRACE |
|---|
| 2682 | printf("noderead - read em %p (punt=%ld)\n",p,punt); |
|---|
| 2683 | #endif |
|---|
| 2684 | #if CNV_PCFILES |
|---|
| 2685 | if (CIREAD(fd,nodeunibuff,nodesize) != nodesize) fatal("noderead/read"); |
|---|
| 2686 | #if CNV_PCBINUM |
|---|
| 2687 | if (treecase) ConvertN02_REC(nodeunibuff); |
|---|
| 2688 | else ConvertN01_REC(nodeunibuff); |
|---|
| 2689 | #endif |
|---|
| 2690 | np=(N0STRU *)p; |
|---|
| 2691 | n1p=(N1STRU *)p; |
|---|
| 2692 | n2p=(N2STRU *)p; |
|---|
| 2693 | unp=(N0STRU *)nodeunibuff; |
|---|
| 2694 | np->pos=unp->pos; |
|---|
| 2695 | np->ock=unp->ock; |
|---|
| 2696 | np->it=unp->it; |
|---|
| 2697 | up=unp->idxchars; |
|---|
| 2698 | for (n=0; n < TWORDN; n++, up+=sizeof(PUNT)) |
|---|
| 2699 | if (treecase) { |
|---|
| 2700 | memcpy(n2p->idx[n].key,up,LE2); up+=LE2; |
|---|
| 2701 | memcpy(&(n2p->idx[n].punt),up,sizeof(PUNT)); |
|---|
| 2702 | } |
|---|
| 2703 | else { |
|---|
| 2704 | memcpy(n1p->idx[n].key,up,LE1); up+=LE1; |
|---|
| 2705 | memcpy(&(n1p->idx[n].punt),up,sizeof(PUNT)); |
|---|
| 2706 | } |
|---|
| 2707 | #else /* CNV_PCFILES */ |
|---|
| 2708 | if (CIREAD(fd,p,nodesize) != nodesize) fatal("noderead/read"); |
|---|
| 2709 | #if CNV_PCBINUM |
|---|
| 2710 | if (treecase) ConvertN02_REC(p); |
|---|
| 2711 | else ConvertN01_REC(p); |
|---|
| 2712 | #endif |
|---|
| 2713 | #endif |
|---|
| 2714 | } /* v3.3 */ |
|---|
| 2715 | np=(N0STRU *)p; |
|---|
| 2716 | #if !SUNBUG_GCC1 |
|---|
| 2717 | if (np->pos != punt) |
|---|
| 2718 | fatal("noderead/pos"); |
|---|
| 2719 | if (np->it != treecase+1) |
|---|
| 2720 | fatal("noderead/it"); |
|---|
| 2721 | if (np->ock < 1 || np->ock > TWORDN) |
|---|
| 2722 | fatal("noderead/ock"); |
|---|
| 2723 | #endif /* !SUNBUG_GCC1 */ |
|---|
| 2724 | return(np); |
|---|
| 2725 | } |
|---|
| 2726 | #if CICPP |
|---|
| 2727 | L0STRU * CISISX :: xleafread(UCHR *fbufp, |
|---|
| 2728 | INVMAP *invp, |
|---|
| 2729 | int treecase, |
|---|
| 2730 | PUNT punt, |
|---|
| 2731 | int lxx) |
|---|
| 2732 | #else /* CICPP */ |
|---|
| 2733 | L0STRU *leafread(fbufp,invp,treecase,punt,lxx) /* |
|---|
| 2734 | ---------------- |
|---|
| 2735 | posiciona registro desejado; |
|---|
| 2736 | le registro; |
|---|
| 2737 | retorna pointer L0STRU ou abenda; |
|---|
| 2738 | */ |
|---|
| 2739 | UCHR *fbufp; /* endereco do buffer de entrada */ |
|---|
| 2740 | INVMAP *invp; /* ptr descriptor do inverted file */ |
|---|
| 2741 | int treecase; /* indece da B*Tree a pesquisar */ |
|---|
| 2742 | PUNT punt; /* registro desejado */ |
|---|
| 2743 | int lxx; /* dbx samel */ |
|---|
| 2744 | #endif /* CICPP */ |
|---|
| 2745 | { |
|---|
| 2746 | L0STRU *lp; |
|---|
| 2747 | int lbufsiz,fd; |
|---|
| 2748 | int lidxesiz; |
|---|
| 2749 | int n; |
|---|
| 2750 | UCHR *p,*lbufp; |
|---|
| 2751 | off_t xbytes; |
|---|
| 2752 | #if ZTREE |
|---|
| 2753 | LZSTRU lzxleaf; |
|---|
| 2754 | int lzxeq,lzxkl,lzxne,iock; |
|---|
| 2755 | unsigned char *lzxkp; |
|---|
| 2756 | unsigned char lzx0k[LE2+1]; |
|---|
| 2757 | L1IDXE *lzx1p; |
|---|
| 2758 | L2IDXE *lzx2p; |
|---|
| 2759 | #endif |
|---|
| 2760 | #if SAMEL |
|---|
| 2761 | UCHR *iflxp; |
|---|
| 2762 | UCHR *lxlbufp; |
|---|
| 2763 | int lxlbufsiz; |
|---|
| 2764 | LONGX lbytes; |
|---|
| 2765 | int klen,loop; |
|---|
| 2766 | L1STRU *l1p; |
|---|
| 2767 | L2STRU *l2p; |
|---|
| 2768 | LXL1STRU *lxl1p; |
|---|
| 2769 | LXL2STRU *lxl2p; |
|---|
| 2770 | L0STRU *lxlp; |
|---|
| 2771 | UWORD lxi; |
|---|
| 2772 | #else |
|---|
| 2773 | #if SAMTRACx |
|---|
| 2774 | int loop; |
|---|
| 2775 | L1STRU *l1p; |
|---|
| 2776 | L2STRU *l2p; |
|---|
| 2777 | #endif |
|---|
| 2778 | #endif |
|---|
| 2779 | #if LEAFCNV_PCFILES |
|---|
| 2780 | L0STRU *unp; |
|---|
| 2781 | char *up; |
|---|
| 2782 | L1STRU *l1p; |
|---|
| 2783 | L2STRU *l2p; |
|---|
| 2784 | #endif |
|---|
| 2785 | |
|---|
| 2786 | lrlrseek=0L; |
|---|
| 2787 | lrlrsize=0L; |
|---|
| 2788 | |
|---|
| 2789 | lbufp=fbufp; |
|---|
| 2790 | #if TRLTRACE |
|---|
| 2791 | printf("leafread - treecase=%d punt=%ld lbufp=%p lxx=%d\n", |
|---|
| 2792 | treecase,(LONGX)punt,lbufp,lxx); |
|---|
| 2793 | #if SAMEL |
|---|
| 2794 | printf("leafread - lxn=%d\n",invp->iflxn); |
|---|
| 2795 | #endif |
|---|
| 2796 | #endif |
|---|
| 2797 | #if LINDLUX |
|---|
| 2798 | if (invp->luxpages[treecase]) { |
|---|
| 2799 | if (punt > invp->luxpages[treecase]) fatal("leafread/punt"); |
|---|
| 2800 | if ((lp=invp->luxvpagp[treecase][punt]) == NULL) fatal("leafread/lux"); |
|---|
| 2801 | if (lbufp) { |
|---|
| 2802 | memcpy(lbufp,lp,(treecase)?L2BSIZ:L1BSIZ); |
|---|
| 2803 | return((L0STRU *)lbufp); |
|---|
| 2804 | } |
|---|
| 2805 | return(lp); |
|---|
| 2806 | } |
|---|
| 2807 | #endif /* LINDLUX */ |
|---|
| 2808 | #if SAMEL |
|---|
| 2809 | if (lxx < ((invp->iflxn) ? 1 : 0) || lxx > invp->iflxn) |
|---|
| 2810 | #else |
|---|
| 2811 | if (lxx) |
|---|
| 2812 | #endif |
|---|
| 2813 | fatal("leafread/lxx"); |
|---|
| 2814 | if (punt < 1) |
|---|
| 2815 | fatal("leafread/punt"); |
|---|
| 2816 | if (treecase) { |
|---|
| 2817 | lbufsiz=L2BSIZ; |
|---|
| 2818 | fd=invp->l2opn; |
|---|
| 2819 | lidxesiz=sizeof(L2IDXE); |
|---|
| 2820 | } |
|---|
| 2821 | else { |
|---|
| 2822 | lbufsiz=L1BSIZ; |
|---|
| 2823 | fd=invp->l1opn; |
|---|
| 2824 | lidxesiz=sizeof(L1IDXE); |
|---|
| 2825 | } |
|---|
| 2826 | #if SAMEL |
|---|
| 2827 | if (invp->iflxn) { |
|---|
| 2828 | if (treecase) { |
|---|
| 2829 | lbytes=sizeof(LXL2STRU); |
|---|
| 2830 | lbytes+=(invp->iflxn-1)*sizeof(lxl2p->idx); |
|---|
| 2831 | if (!invp->ifl2p) { /* ALLOC ok */ |
|---|
| 2832 | #if SAMTRACE |
|---|
| 2833 | printf("leafread - treecase=%d lbytes=%d+%d*%d=%ld\n", |
|---|
| 2834 | treecase,sizeof(LXL2STRU),invp->iflxn-1,sizeof(lxl2p->idx),lbytes); |
|---|
| 2835 | #endif |
|---|
| 2836 | #if CICPP |
|---|
| 2837 | try { invp->ifl2p= new char[lbytes]; } |
|---|
| 2838 | catch (BAD_ALLOC) {invp->ifl2p = (char *)ALLONULL; } |
|---|
| 2839 | #else /* CICPP */ |
|---|
| 2840 | invp->ifl2p=(char *)ALLOC((ALLOPARM)lbytes); |
|---|
| 2841 | #endif /* CICPP */ |
|---|
| 2842 | if (invp->ifl2p == (char *)ALLONULL) fatal("leafread/ALLOC"); |
|---|
| 2843 | memset(invp->ifl2p,0x00,(size_t)lbytes); |
|---|
| 2844 | } |
|---|
| 2845 | iflxp=invp->ifl2p; |
|---|
| 2846 | } |
|---|
| 2847 | else { |
|---|
| 2848 | lbytes=sizeof(LXL1STRU); |
|---|
| 2849 | lbytes+=(invp->iflxn-1)*sizeof(lxl1p->idx); |
|---|
| 2850 | if (!invp->ifl1p) { /* ALLOC ok */ |
|---|
| 2851 | #if SAMTRACE |
|---|
| 2852 | printf("leafread - treecase=%d lbytes=%d+%d*%d=%ld\n", |
|---|
| 2853 | treecase,sizeof(LXL1STRU),invp->iflxn-1,sizeof(lxl1p->idx),lbytes); |
|---|
| 2854 | #endif |
|---|
| 2855 | #if CICPP |
|---|
| 2856 | try { invp->ifl1p= new char[lbytes]; } |
|---|
| 2857 | catch (BAD_ALLOC) {invp->ifl1p = (char *)ALLONULL; } |
|---|
| 2858 | #else /* CICPP */ |
|---|
| 2859 | invp->ifl1p=(char *)ALLOC((ALLOPARM)lbytes); |
|---|
| 2860 | #endif /* CICPP */ |
|---|
| 2861 | if (invp->ifl1p == (char *)ALLONULL) fatal("leafread/ALLOC/2"); |
|---|
| 2862 | memset(invp->ifl1p,0x00,(size_t)lbytes); |
|---|
| 2863 | } |
|---|
| 2864 | iflxp=invp->ifl1p; |
|---|
| 2865 | } |
|---|
| 2866 | lxlbufsiz=lbufsiz; /* save */ |
|---|
| 2867 | lxlbufp=lbufp; /* save */ |
|---|
| 2868 | lxlp=(L0STRU *)lbufp; /* save */ |
|---|
| 2869 | lbufsiz=lbytes; /* set */ |
|---|
| 2870 | lbufp=iflxp; /* set */ |
|---|
| 2871 | #if SAMTRACE |
|---|
| 2872 | printf("leafread - treecase=%d punt=%ld lxx=%d lxn=%d bytes=%ld/%p/%d\n", |
|---|
| 2873 | treecase,(LONGX)punt,lxx,invp->iflxn,lbytes,lbufp,lbufsiz); |
|---|
| 2874 | #endif |
|---|
| 2875 | } |
|---|
| 2876 | #endif /* SAMEL */ |
|---|
| 2877 | lp=(L0STRU *)lbufp; /* use */ |
|---|
| 2878 | #if TRLTRACE |
|---|
| 2879 | printf("leafread - treecase=%d punt=%ld lbufp=%p lp=%p\n", |
|---|
| 2880 | treecase,(LONGX)punt,lbufp,lp); |
|---|
| 2881 | #if CNLI |
|---|
| 2882 | printf("leafread - fd=%d offset=%ld\n",fd,invp->cl_offset[treecase]); |
|---|
| 2883 | #endif |
|---|
| 2884 | #endif |
|---|
| 2885 | /* might ignore possible old leaf's ... */ |
|---|
| 2886 | if (treecase != (lp->it-1) || punt != lp->pos) { |
|---|
| 2887 | #if TRLTRACE |
|---|
| 2888 | printf("leafread - invp=%p treecase=%d punt=%ld\n", |
|---|
| 2889 | invp,treecase,(LONGX)punt); |
|---|
| 2890 | #endif |
|---|
| 2891 | p=(unsigned char *)invp->lybasep[treecase]; /* v3.3 */ |
|---|
| 2892 | if (fd == 0 && p == NULL) |
|---|
| 2893 | fatal("leafread/fd&p"); |
|---|
| 2894 | if (p != NULL) { |
|---|
| 2895 | p+=(lbufsiz*(punt-1L)); |
|---|
| 2896 | #if TRLTRACE |
|---|
| 2897 | printf("leafread - lybasep[%d][%ld]=%p p=%p lp=%p\n", |
|---|
| 2898 | treecase,(punt-1L),invp->lybasep[treecase],p,lp); |
|---|
| 2899 | #endif |
|---|
| 2900 | memcpy(lbufp,p,lbufsiz); /* use */ |
|---|
| 2901 | #if CNV_PCBINUM |
|---|
| 2902 | if (treecase) ConvertL02_REC(lbufp); |
|---|
| 2903 | else ConvertL01_REC(lbufp); |
|---|
| 2904 | #endif |
|---|
| 2905 | #if TRLTRACE |
|---|
| 2906 | printf("leafread - moved pos=%ld ock=%d it=%d ps=%ld\n", |
|---|
| 2907 | lp->pos,lp->ock,lp->it,(LONGX)lp->ps); |
|---|
| 2908 | #endif |
|---|
| 2909 | } |
|---|
| 2910 | else { /* v3.3 */ |
|---|
| 2911 | #if LEAFCNV_PCFILES |
|---|
| 2912 | lbufsiz-=(treecase)?TWORDF*L2BUNI:TWORDF*L1BUNI; |
|---|
| 2913 | xbytes=((off_t)(punt-1L))*lbufsiz; |
|---|
| 2914 | #if TRLTRACE |
|---|
| 2915 | printf("leafread - xbytes=%"P_OFF_T" punt=%ld lbufsiz=%d \n",(LONG_LONG)xbytes,(LONGX)punt, lbufsiz); |
|---|
| 2916 | #endif |
|---|
| 2917 | if (LSEEK64(fd,xbytes,SEEK_SET) != xbytes) { |
|---|
| 2918 | printf("leafread - xbytes=%"P_OFF_T" punt=%ld lbufsiz=%d \n",(LONG_LONG)xbytes,(LONGX)punt, lbufsiz); |
|---|
| 2919 | printf("errno=%ld\n", (long)errno); |
|---|
| 2920 | fatal("leafread/lseek"); |
|---|
| 2921 | } |
|---|
| 2922 | lrlrseek=xbytes; |
|---|
| 2923 | lrlrsize=lbufsiz; |
|---|
| 2924 | if (CIREAD(fd,leafunibuff,lbufsiz) != lbufsiz) /* use */ |
|---|
| 2925 | fatal("leafread/read"); |
|---|
| 2926 | #if CNV_PCBINUM |
|---|
| 2927 | if (treecase) ConvertL02_REC(leafunibuff); |
|---|
| 2928 | else ConvertL01_REC(leafunibuff); |
|---|
| 2929 | #endif |
|---|
| 2930 | lp=(L0STRU *)lbufp; |
|---|
| 2931 | l1p=(L1STRU *)lbufp; |
|---|
| 2932 | l2p=(L2STRU *)lbufp; |
|---|
| 2933 | unp=(L0STRU *)leafunibuff; |
|---|
| 2934 | lp->pos=unp->pos; |
|---|
| 2935 | lp->ock=unp->ock; |
|---|
| 2936 | lp->it=unp->it; |
|---|
| 2937 | lp->ps=unp->ps; |
|---|
| 2938 | up=unp->idxchars; |
|---|
| 2939 | for (n=0; n < TWORDF; n++) |
|---|
| 2940 | if (treecase) { |
|---|
| 2941 | memcpy(l2p->idx[n].key,up,LE2); up+=LE2; |
|---|
| 2942 | memcpy(&(l2p->idx[n].info1),up,sizeof(PUNT)); up+=sizeof(PUNT); |
|---|
| 2943 | memcpy(&(l2p->idx[n].info2),up,sizeof(PUNT)); up+=sizeof(PUNT); |
|---|
| 2944 | } |
|---|
| 2945 | else { |
|---|
| 2946 | memcpy(l1p->idx[n].key,up,LE1); up+=LE1; |
|---|
| 2947 | memcpy(&(l1p->idx[n].info1),up,sizeof(PUNT)); up+=sizeof(PUNT); |
|---|
| 2948 | memcpy(&(l1p->idx[n].info2),up,sizeof(PUNT)); up+=sizeof(PUNT); |
|---|
| 2949 | } |
|---|
| 2950 | #else /* LEAFCNV_PCFILES */ |
|---|
| 2951 | xbytes=((off_t)(punt-1L))*lbufsiz; |
|---|
| 2952 | #if ZTREE |
|---|
| 2953 | if (invp->iflzx) xbytes=punt-1; /* punt < 0 */ |
|---|
| 2954 | #endif |
|---|
| 2955 | #if CNLI |
|---|
| 2956 | xbytes+=invp->cl_offset[treecase]; |
|---|
| 2957 | #endif |
|---|
| 2958 | #if TRLTRACE |
|---|
| 2959 | printf("leafread - xbytes=%"P_OFF_T" punt=%ld lbufsiz=%d \n",(LONG_LONG)xbytes,(LONGX)punt, lbufsiz); |
|---|
| 2960 | #endif |
|---|
| 2961 | if (LSEEK64(fd,xbytes,SEEK_SET) != xbytes) { |
|---|
| 2962 | printf("leafread - xbytes=%"P_OFF_T" punt=%ld lbufsiz=%d \n",(LONG_LONG)xbytes,(LONGX)punt, lbufsiz); |
|---|
| 2963 | printf("errno=%ld\n", (LONGX)errno); |
|---|
| 2964 | fatal("leafread/lseek/2"); |
|---|
| 2965 | } |
|---|
| 2966 | lrlrseek=xbytes; |
|---|
| 2967 | lrlrsize=lbufsiz; |
|---|
| 2968 | #if ZTREE |
|---|
| 2969 | if (invp->iflzx) { |
|---|
| 2970 | /* read max length */ |
|---|
| 2971 | n = (treecase) ? sizeof(LZSTRU) : LZHSIZE + LZKASZ1; |
|---|
| 2972 | lrlrsize=n; |
|---|
| 2973 | if (CIREAD(fd,(char *)&lzxleaf,n) != n) /* use */ |
|---|
| 2974 | fatal("leafread/read"); |
|---|
| 2975 | #if CNV_PCBINUM |
|---|
| 2976 | fatal("leafread/ZTREE"); |
|---|
| 2977 | /* ConvertLZX_REC((char *)&lzxleaf); */ |
|---|
| 2978 | #endif |
|---|
| 2979 | /* move header */ |
|---|
| 2980 | lp->pos = lzxleaf.pos; |
|---|
| 2981 | lp->ock = lzxleaf.ock; |
|---|
| 2982 | lp->it = lzxleaf.it; |
|---|
| 2983 | lp->ps = lzxleaf.ps; |
|---|
| 2984 | #if LIND |
|---|
| 2985 | lp->psb = lzxleaf.psb; |
|---|
| 2986 | #endif |
|---|
| 2987 | if (trmtrace) { |
|---|
| 2988 | printf("leafread - treecase=%d punt=%ld pos=%ld ock=%d it=%d ps=%ld", |
|---|
| 2989 | treecase,punt,(LONGX)lp->pos,lp->ock,lp->it,(LONGX)lp->ps); |
|---|
| 2990 | #if LIND |
|---|
| 2991 | printf("/%ld \n",(LONGX)lp->psb); |
|---|
| 2992 | #else |
|---|
| 2993 | printf(" \n"); |
|---|
| 2994 | #endif |
|---|
| 2995 | } |
|---|
| 2996 | /* setup ptrs */ |
|---|
| 2997 | lzxkp = (unsigned char *)lzxleaf.keys; |
|---|
| 2998 | lzx1p = (L1IDXE *)(L1STRU *)lp->idxchars; |
|---|
| 2999 | lzx2p = (L2IDXE *)(L2STRU *)lp->idxchars; |
|---|
| 3000 | memcpy(lzx0k,lzxkp+1+1,(treecase)?LE2:LE1); |
|---|
| 3001 | /* decompress existing terms */ |
|---|
| 3002 | for (iock=0; iock < lzxleaf.ock; iock++) { |
|---|
| 3003 | lzxeq = (int)*lzxkp++; /* eq */ |
|---|
| 3004 | lzxkl = (int)*lzxkp++; /* keylen */ |
|---|
| 3005 | lzxne = lzxkl-lzxeq; |
|---|
| 3006 | if (treecase) { |
|---|
| 3007 | if (lzxeq+lzxne > LE2) fatal("leafread/ztree/LE2"); |
|---|
| 3008 | memcpy(p=lzx2p->key,lzx0k,lzxeq); p+=lzxeq; |
|---|
| 3009 | memcpy(p,lzxkp,lzxne); p+=lzxne; |
|---|
| 3010 | memset(p,' ',LE2-lzxkl); |
|---|
| 3011 | lzx2p->info1 = lzxleaf.info1[iock]; |
|---|
| 3012 | lzx2p->info2 = lzxleaf.info2[iock]; |
|---|
| 3013 | #if LIND |
|---|
| 3014 | lzx2p->info3info4.info3 = lzxleaf.info3[iock]; |
|---|
| 3015 | #endif |
|---|
| 3016 | memcpy(lzx0k,lzx2p->key,LE2); |
|---|
| 3017 | if (trmtrace) { |
|---|
| 3018 | printf("+++ %2d|%3d|%3d|",iock,lzxeq,lzxne+lzxeq); |
|---|
| 3019 | for (p=lzx2p->key; lzxkl--; p++) printf("%c",*p); |
|---|
| 3020 | printf("|\n"); |
|---|
| 3021 | } |
|---|
| 3022 | lzx2p++; |
|---|
| 3023 | } |
|---|
| 3024 | else { |
|---|
| 3025 | if (lzxeq+lzxne > LE1) fatal("leafread/ztree/LE1"); |
|---|
| 3026 | memcpy(p=lzx1p->key,lzx0k,lzxeq); p+=lzxeq; |
|---|
| 3027 | memcpy(p,lzxkp,lzxne); p+=lzxne; |
|---|
| 3028 | memset(p,' ',LE1-lzxkl); |
|---|
| 3029 | lzx1p->info1 = lzxleaf.info1[iock]; |
|---|
| 3030 | lzx1p->info2 = lzxleaf.info2[iock]; |
|---|
| 3031 | #if LIND |
|---|
| 3032 | lzx1p->info3info4.info3 = lzxleaf.info3[iock]; |
|---|
| 3033 | #endif |
|---|
| 3034 | memcpy(lzx0k,lzx1p->key,LE1); |
|---|
| 3035 | if (trmtrace) { |
|---|
| 3036 | printf("+++ %2d|%3d|%3d|",iock,lzxeq,lzxne+lzxeq); |
|---|
| 3037 | for (p=lzx1p->key; lzxkl--; p++) printf("%c",*p); |
|---|
| 3038 | printf("|\n"); |
|---|
| 3039 | } |
|---|
| 3040 | lzx1p++; |
|---|
| 3041 | } |
|---|
| 3042 | lzxkp+=lzxne; |
|---|
| 3043 | } |
|---|
| 3044 | /* setup inexisting terms */ |
|---|
| 3045 | for (; iock < TWORDF; iock++) { |
|---|
| 3046 | if (treecase) { |
|---|
| 3047 | memset(lzx2p->key,' ',LE2); |
|---|
| 3048 | lzx2p->info1 = 0; |
|---|
| 3049 | lzx2p->info2 = 0; |
|---|
| 3050 | #if LIND |
|---|
| 3051 | lzx2p->info3info4.info3 = 0; |
|---|
| 3052 | #endif |
|---|
| 3053 | lzx2p++; |
|---|
| 3054 | } |
|---|
| 3055 | else { |
|---|
| 3056 | memset(lzx1p->key,' ',LE1); |
|---|
| 3057 | lzx1p->info1 = 0; |
|---|
| 3058 | lzx1p->info2 = 0; |
|---|
| 3059 | #if LIND |
|---|
| 3060 | lzx1p->info3info4.info3 = 0; |
|---|
| 3061 | #endif |
|---|
| 3062 | lzx1p++; |
|---|
| 3063 | } |
|---|
| 3064 | lzxkp+=lzxne; |
|---|
| 3065 | } |
|---|
| 3066 | } |
|---|
| 3067 | else |
|---|
| 3068 | #endif /* ZTREE */ |
|---|
| 3069 | if (CIREAD(fd,lbufp,lbufsiz) != lbufsiz) /* use */ |
|---|
| 3070 | fatal("leafread/read"); |
|---|
| 3071 | #if CNV_PCBINUM |
|---|
| 3072 | if (treecase) ConvertL02_REC(lbufp); |
|---|
| 3073 | else ConvertL01_REC(lbufp); |
|---|
| 3074 | #endif |
|---|
| 3075 | #endif /* LEAFCNV_PCFILES */ |
|---|
| 3076 | } /* v3.3 */ |
|---|
| 3077 | if ((n=lp->ock) < 1 || n >TWORDF) |
|---|
| 3078 | fatal("leafread/ock"); |
|---|
| 3079 | #if SAMEL |
|---|
| 3080 | if (invp->iflxn) { |
|---|
| 3081 | lxi=lxx-1; |
|---|
| 3082 | memcpy(lxlbufp,lbufp,sizeof(L0STRU)); /* move */ |
|---|
| 3083 | if (treecase) { |
|---|
| 3084 | l2p=(L2STRU *)lxlbufp; lxl2p=(LXL2STRU *)lbufp; klen=LE2; |
|---|
| 3085 | for (loop=0; n--; loop++) { |
|---|
| 3086 | memcpy(l2p->idx[loop].key,lxl2p->key[loop],klen); |
|---|
| 3087 | l2p->idx[loop].info1=lxl2p->idx[lxi][loop].info1; |
|---|
| 3088 | l2p->idx[loop].info2=lxl2p->idx[lxi][loop].info2; |
|---|
| 3089 | #if LIND |
|---|
| 3090 | l2p->idx[loop].info3info4.info3= |
|---|
| 3091 | lxl2p->idx[lxi][loop].info3info4.info3; |
|---|
| 3092 | #endif |
|---|
| 3093 | } |
|---|
| 3094 | } |
|---|
| 3095 | else { |
|---|
| 3096 | l1p=(L1STRU *)lxlbufp; lxl1p=(LXL1STRU *)lbufp; klen=LE1; |
|---|
| 3097 | for (loop=0; n--; loop++) { |
|---|
| 3098 | memcpy(l1p->idx[loop].key,lxl1p->key[loop],klen); |
|---|
| 3099 | l1p->idx[loop].info1=lxl1p->idx[lxi][loop].info1; |
|---|
| 3100 | l1p->idx[loop].info2=lxl1p->idx[lxi][loop].info2; |
|---|
| 3101 | #if LIND |
|---|
| 3102 | l1p->idx[loop].info3info4.info3= |
|---|
| 3103 | lxl1p->idx[lxi][loop].info3info4.info3; |
|---|
| 3104 | #endif |
|---|
| 3105 | } |
|---|
| 3106 | } |
|---|
| 3107 | lbufsiz=lxlbufsiz; /* restore */ |
|---|
| 3108 | lbufp=lxlbufp; /* restore */ |
|---|
| 3109 | lp=lxlp; /* restore */ |
|---|
| 3110 | #if SAMTRACE |
|---|
| 3111 | printf("leafread - treecase=%d punt=%ld lxx=%d lxn=%d bytes=%ld/%p/%d\n", |
|---|
| 3112 | treecase,(LONGX)punt,lxx,invp->iflxn,lbytes,lbufp,lbufsiz); |
|---|
| 3113 | #endif |
|---|
| 3114 | } /* end if invp->iflxn */ |
|---|
| 3115 | #endif /* SAMEL */ |
|---|
| 3116 | #if SAMTRACx |
|---|
| 3117 | if (treecase) { |
|---|
| 3118 | l2p=(L2STRU *)lbufp; |
|---|
| 3119 | for (loop=0; loop < l2p->ock; loop++) |
|---|
| 3120 | printf("%d/%d=%.30s=%ld/%ld/%ld\n",loop+1,l2p->ock, |
|---|
| 3121 | l2p->idx[loop].key, |
|---|
| 3122 | l2p->idx[loop].info1, |
|---|
| 3123 | l2p->idx[loop].info2, |
|---|
| 3124 | #if LIND |
|---|
| 3125 | l2p->idx[loop].info3info4.info3); |
|---|
| 3126 | #else |
|---|
| 3127 | 0L); |
|---|
| 3128 | #endif |
|---|
| 3129 | getchar(); |
|---|
| 3130 | } |
|---|
| 3131 | else { |
|---|
| 3132 | l1p=(L1STRU *)lbufp; |
|---|
| 3133 | for (loop=0; loop < l1p->ock; loop++) |
|---|
| 3134 | printf("%d/%d=%.10s=%ld/%ld/%ld\n",loop+1,l1p->ock, |
|---|
| 3135 | l1p->idx[loop].key, |
|---|
| 3136 | l1p->idx[loop].info1, |
|---|
| 3137 | l1p->idx[loop].info2, |
|---|
| 3138 | #if LIND |
|---|
| 3139 | l1p->idx[loop].info3info4.info3); |
|---|
| 3140 | #else |
|---|
| 3141 | 0L); |
|---|
| 3142 | #endif |
|---|
| 3143 | getchar(); |
|---|
| 3144 | } |
|---|
| 3145 | #endif |
|---|
| 3146 | for (p=lbufp+lbufsiz, n=TWORDF - lp->ock; n--; ) { |
|---|
| 3147 | p-=lidxesiz; *p='\0'; /* inactive keys were not cleared */ |
|---|
| 3148 | /* printf("p=%p\n",p); */ |
|---|
| 3149 | } |
|---|
| 3150 | } /* end if punt != lp->pos */ |
|---|
| 3151 | lp=(L0STRU *)fbufp; /* !!! */ /* 15/04/92 */ |
|---|
| 3152 | if (lp->ock < TWORDF) { |
|---|
| 3153 | p=(unsigned char *)lp->idxchars; |
|---|
| 3154 | p+=lidxesiz*lp->ock; |
|---|
| 3155 | if (*p != '\0') { |
|---|
| 3156 | /* printf("p=%p+%d*%d=%p\n",lp->idxchars,lidxesiz,lp->ock,p); */ |
|---|
| 3157 | printf("leafread/check/punt=%ld -> char=%c(%02x)",punt,*p,*p); |
|---|
| 3158 | if (getchar() != '\n') fatal("leafread/getchar"); |
|---|
| 3159 | } |
|---|
| 3160 | } |
|---|
| 3161 | #if TRLTRACE |
|---|
| 3162 | printf("leafread - ock=%d it=%d ps=%ld\n",lp->ock,lp->it,(LONGX)lp->ps); |
|---|
| 3163 | #endif |
|---|
| 3164 | return(lp); |
|---|
| 3165 | } |
|---|
| 3166 | |
|---|
| 3167 | #if CICPP |
|---|
| 3168 | #if !LIND |
|---|
| 3169 | IFPSTRU * CISISX :: xpostread(UCHR *xbufp, |
|---|
| 3170 | INVMAP *invp, |
|---|
| 3171 | PUNT xblk, |
|---|
| 3172 | int lxx) |
|---|
| 3173 | #else |
|---|
| 3174 | IFPSTRU * CISISX :: xpostread(UCHR *xbufp, |
|---|
| 3175 | INVMAP *invp, |
|---|
| 3176 | off_t addr, |
|---|
| 3177 | unsigned int toread, |
|---|
| 3178 | int lxx) |
|---|
| 3179 | #endif |
|---|
| 3180 | #else /* CICPP */ |
|---|
| 3181 | #if !LIND |
|---|
| 3182 | IFPSTRU *postread(xbufp,invp,xblk,lxx) |
|---|
| 3183 | #else |
|---|
| 3184 | IFPSTRU *postread(xbufp,invp,addr,toread,lxx) |
|---|
| 3185 | #endif |
|---|
| 3186 | /* |
|---|
| 3187 | ---------------- |
|---|
| 3188 | posiciona registro desejado; |
|---|
| 3189 | le registro; |
|---|
| 3190 | retorna pointer IFPSTRU ou abenda; |
|---|
| 3191 | */ |
|---|
| 3192 | UCHR *xbufp; /* endereco do buffer de entrada */ |
|---|
| 3193 | INVMAP *invp; /* ptr descritor do inverted file */ |
|---|
| 3194 | #if !LIND |
|---|
| 3195 | PUNT xblk; /* registro desejado */ |
|---|
| 3196 | #else |
|---|
| 3197 | off_t addr; /* byte address */ |
|---|
| 3198 | unsigned int toread;/* bytes to read */ |
|---|
| 3199 | #endif |
|---|
| 3200 | int lxx; /* dbx samel */ |
|---|
| 3201 | #endif /* CICPP */ |
|---|
| 3202 | { |
|---|
| 3203 | IFPSTRU *xp; |
|---|
| 3204 | int fd; |
|---|
| 3205 | unsigned int xbufsiz; |
|---|
| 3206 | #if IFUPDATE |
|---|
| 3207 | LONGX nread; |
|---|
| 3208 | #endif |
|---|
| 3209 | off_t sbyte; |
|---|
| 3210 | UCHR *p; |
|---|
| 3211 | |
|---|
| 3212 | #if SAMEL |
|---|
| 3213 | if (lxx < 0) fatal("postread/lxx"); |
|---|
| 3214 | fd=invp->ifopn[(lxx) ? lxx-1 : 0]; |
|---|
| 3215 | #else |
|---|
| 3216 | fd=invp->ifopn; |
|---|
| 3217 | if (lxx) fatal("postread/lxx"); |
|---|
| 3218 | #endif |
|---|
| 3219 | |
|---|
| 3220 | xp=(IFPSTRU *)xbufp; |
|---|
| 3221 | #if !LIND |
|---|
| 3222 | xbufsiz=sizeof(IFPSTRU); |
|---|
| 3223 | #if TRYTRACE |
|---|
| 3224 | printf("postread - invp=%p xblk=%ld xbufp=%p xp=%p fd=%d \n", |
|---|
| 3225 | invp,(LONGX)xblk,xbufp,xp,fd); |
|---|
| 3226 | #endif |
|---|
| 3227 | #else |
|---|
| 3228 | xbufsiz=toread; |
|---|
| 3229 | #if TRYTRACE |
|---|
| 3230 | printf("postread - invp=%p addr=%"P_OFF_T"/%d xbufp=%p xp=%p fd=%d \n", |
|---|
| 3231 | invp,(LONG_LONG)addr,xbufsiz,xbufp,xp,fd); |
|---|
| 3232 | #endif |
|---|
| 3233 | #endif |
|---|
| 3234 | |
|---|
| 3235 | #if !LIND |
|---|
| 3236 | #if IFUPDATE |
|---|
| 3237 | if (trmifupd || xblk != xp->ifpblk) { /* 15/04/93 */ |
|---|
| 3238 | #else |
|---|
| 3239 | if (xblk != xp->ifpblk) { |
|---|
| 3240 | #endif |
|---|
| 3241 | #endif |
|---|
| 3242 | p=(unsigned char *)invp->iybasep; |
|---|
| 3243 | if (fd == 0 && p == NULL) |
|---|
| 3244 | fatal("postread/fd&p"); |
|---|
| 3245 | if (p != NULL) { |
|---|
| 3246 | #if !LIND |
|---|
| 3247 | p+=(xbufsiz*(xblk-1L)); |
|---|
| 3248 | #else |
|---|
| 3249 | p+=addr; |
|---|
| 3250 | #endif |
|---|
| 3251 | #if TRYTRACE |
|---|
| 3252 | printf("postread - iybasep=%p p=%p\n",invp->iybasep,p); |
|---|
| 3253 | #endif |
|---|
| 3254 | memcpy(xbufp,p,xbufsiz); |
|---|
| 3255 | #if !LIND |
|---|
| 3256 | #if TRYTRACE |
|---|
| 3257 | printf("postread - blk=%ld \n",xp->ifpblk); |
|---|
| 3258 | #endif |
|---|
| 3259 | #endif |
|---|
| 3260 | } |
|---|
| 3261 | else { |
|---|
| 3262 | #if !LIND |
|---|
| 3263 | sbyte=((off_t)(xblk-1L))<<IFSHIFT; |
|---|
| 3264 | #else |
|---|
| 3265 | sbyte=addr; |
|---|
| 3266 | #endif |
|---|
| 3267 | #if CNLI |
|---|
| 3268 | sbyte+=invp->ci_offset; |
|---|
| 3269 | #endif |
|---|
| 3270 | #if TRYTRACE |
|---|
| 3271 | printf("postread - sbyte=%"P_OFF_T" \n",(LONG_LONG)sbyte); |
|---|
| 3272 | #endif |
|---|
| 3273 | if (LSEEK64(fd,sbyte,SEEK_SET) != sbyte) |
|---|
| 3274 | fatal("postread/lseek"); |
|---|
| 3275 | #if IFUPDATE |
|---|
| 3276 | if ((nread=CIREAD(fd,xbufp,xbufsiz)) != xbufsiz) |
|---|
| 3277 | if (trmifupd && !nread) { /* next block */ |
|---|
| 3278 | #if LIND |
|---|
| 3279 | memset(xbufp,0x00,xbufsiz); |
|---|
| 3280 | #else |
|---|
| 3281 | memset(xbufp,0xFF,xbufsiz); |
|---|
| 3282 | ((IFPSTRU *)xbufp)->ifpblk=xblk; |
|---|
| 3283 | #endif |
|---|
| 3284 | } |
|---|
| 3285 | else fatal("postread/read"); |
|---|
| 3286 | #else /* IFUPDATE */ |
|---|
| 3287 | if (CIREAD(fd,xbufp,xbufsiz) != xbufsiz) fatal("postread/read"); |
|---|
| 3288 | #endif /* IFUPDATE */ |
|---|
| 3289 | } |
|---|
| 3290 | #if !LIND |
|---|
| 3291 | #if CNV_PCBINUM |
|---|
| 3292 | ConvertIFP_BLKCTL(xbufp,(xblk == 1) ? 1 : 0); |
|---|
| 3293 | #endif |
|---|
| 3294 | } |
|---|
| 3295 | #endif |
|---|
| 3296 | #if !LIND |
|---|
| 3297 | if (xp->ifpblk != xblk) |
|---|
| 3298 | fatal("postread/check/xblk"); |
|---|
| 3299 | #endif |
|---|
| 3300 | return(xp); |
|---|
| 3301 | } |
|---|
| 3302 | |
|---|
| 3303 | #endif /* CICPP || CITRM_CISISX_SOURCE */ |
|---|
| 3304 | |
|---|