| 1 | /* |
|---|
| 2 | * <R> |
|---|
| 3 | * cib71, b7_exp() |
|---|
| 4 | * basado en b6 usando algo de b4 |
|---|
| 5 | * b4 - proximidad |
|---|
| 6 | * b6 - prefix, multiples I/F, log format |
|---|
| 7 | * </R> |
|---|
| 8 | */ |
|---|
| 9 | #include <stdio.h> |
|---|
| 10 | #include <string.h> |
|---|
| 11 | #include <ctype.h> |
|---|
| 12 | #include <time.h> |
|---|
| 13 | |
|---|
| 14 | /* ----------------------------- b60.c ------------------------------ */ |
|---|
| 15 | /* ----------------------------- b61.c ------------------------------ */ |
|---|
| 16 | |
|---|
| 17 | #if CIAPI |
|---|
| 18 | #include "ciapi.h" |
|---|
| 19 | #if !TLS |
|---|
| 20 | #define ciapip cib7p->ciapip |
|---|
| 21 | #else |
|---|
| 22 | DWORD extern ciapiTlsIndex; |
|---|
| 23 | #endif |
|---|
| 24 | #else /* CIAPI */ |
|---|
| 25 | #include "cisis.h" |
|---|
| 26 | #endif /* CIAPI */ |
|---|
| 27 | |
|---|
| 28 | #if !CICPP |
|---|
| 29 | #include "cib70.h" |
|---|
| 30 | #endif /* CICPP */ |
|---|
| 31 | |
|---|
| 32 | #if CICPP |
|---|
| 33 | char * CIB7::b7_exp(RECSTRU *recp, |
|---|
| 34 | char *dbnamp, /* ptr nome base de dados a ler */ |
|---|
| 35 | char *qryp, /* ptr formulacao */ |
|---|
| 36 | char *buffup, /* area addr for fldupdat */ |
|---|
| 37 | char *qrydbnp, /* query data base */ |
|---|
| 38 | RECSTRU *crecp, /* registro de controle qrydbnp */ |
|---|
| 39 | int *errnop) /* addr para codigo de erro */ |
|---|
| 40 | |
|---|
| 41 | #else /* CICPP */ |
|---|
| 42 | char *b7_exp(cib7p,irec,dbnamp,qryp,buffup,qrydbnp,crec,errnop) /* |
|---|
| 43 | |
|---|
| 44 | ------------ |
|---|
| 45 | ... |
|---|
| 46 | retorna NULL ou ptr erro |
|---|
| 47 | |
|---|
| 48 | */ |
|---|
| 49 | b7_CIB7 *cib7p; /* variables globales */ |
|---|
| 50 | LONGX irec; /* vrecp para store */ |
|---|
| 51 | char *dbnamp; /* ptr nome base de dados a ler */ |
|---|
| 52 | char *qryp; /* ptr formulacao */ |
|---|
| 53 | char *buffup; /* area addr for fldupdat */ |
|---|
| 54 | char *qrydbnp; /* query data base */ |
|---|
| 55 | LONGX crec; /* registro de controle qrydbnp */ |
|---|
| 56 | int *errnop; /* addr para codigo de erro */ |
|---|
| 57 | #endif /* CICPP */ |
|---|
| 58 | { |
|---|
| 59 | #if !CICPP |
|---|
| 60 | RECSTRU *recp; |
|---|
| 61 | #endif /* CICPP */ |
|---|
| 62 | |
|---|
| 63 | LONGX answer; |
|---|
| 64 | char *b7buffup = NULL; |
|---|
| 65 | char *trim; |
|---|
| 66 | |
|---|
| 67 | #if DISTRACE |
|---|
| 68 | printf("b7_exp - irec,dbnamp,qryp: %"_LD_",%s,'%s' [%s]\n", |
|---|
| 69 | irec,dbnamp,qryp,qrydbnp); |
|---|
| 70 | #endif |
|---|
| 71 | #if BEFORE20010117 |
|---|
| 72 | #if SHOWCORE |
|---|
| 73 | if (b70trace) showcore("b7_exp"); |
|---|
| 74 | #endif |
|---|
| 75 | #endif /* BEFORE */ |
|---|
| 76 | |
|---|
| 77 | strcpy(b7errxy,"b7_exp"); |
|---|
| 78 | #if FATRAP |
|---|
| 79 | b71error = setjmp(b71jumper); |
|---|
| 80 | #else |
|---|
| 81 | b7error = b71error = 0; |
|---|
| 82 | #endif /* FATRAP */ |
|---|
| 83 | B7_EXPERROR: |
|---|
| 84 | if (b71error != 0) { |
|---|
| 85 | #if ERRTRACE |
|---|
| 86 | printf("setjmp - error=%d (%s)\n",b71error,b7errxy); |
|---|
| 87 | #endif |
|---|
| 88 | *errnop=b71error; |
|---|
| 89 | #if CICPP |
|---|
| 90 | if (b7buffup) delete[] b7buffup; |
|---|
| 91 | #else /* CICPP */ |
|---|
| 92 | if (b7buffup) FREE(b7buffup); |
|---|
| 93 | #endif /* CICPP */ |
|---|
| 94 | return(b7errxy); |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | #if CICPP |
|---|
| 98 | try { b7buffup = new char[((ALLOPARM)MAXMFRL+1)]; } |
|---|
| 99 | catch (BAD_ALLOC) { b7buffup = (char *)ALLONULL; } |
|---|
| 100 | if (b7buffup == (char *)ALLONULL){ b7_experr(B7_THISP -8,"buffup/ALLOC",0); |
|---|
| 101 | goto B7_EXPERROR; |
|---|
| 102 | } |
|---|
| 103 | #else /* CICPP */ |
|---|
| 104 | b7buffup = (char *)ALLOC((ALLOPARM)MAXMFRL+1); |
|---|
| 105 | if (b7buffup == (char *)ALLONULL){ b7_experr(B7_THISP -8,"buffup/ALLOC",0); |
|---|
| 106 | goto B7_EXPERROR; |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | if (!ndbxs) dbxinit(); /* init vdbxp/vrecp/vtrmp if not yet init - AOT, 28/10/2005 */ |
|---|
| 110 | |
|---|
| 111 | recp=vrecp[irec]; |
|---|
| 112 | #endif /* CICPP */ |
|---|
| 113 | |
|---|
| 114 | if (!recp){ |
|---|
| 115 | b7_experr(B7_THISP B7EE_X2,"b7_exp/recallok/recp",0); |
|---|
| 116 | goto B7_EXPERROR; |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | #if CICPP |
|---|
| 120 | if (!recp->recmfp){ |
|---|
| 121 | b7_experr(B7_THISP B7EE_X2,"b7_exp/recallok/recmfp",0); |
|---|
| 122 | goto B7_EXPERROR; |
|---|
| 123 | } |
|---|
| 124 | #endif /* CICPP */ |
|---|
| 125 | |
|---|
| 126 | trim = qryp + ( strlen( qryp ) - 1 ); |
|---|
| 127 | for( ;isspace( *trim ); trim-- ) |
|---|
| 128 | *trim='\0'; |
|---|
| 129 | |
|---|
| 130 | b7recp=recp; |
|---|
| 131 | |
|---|
| 132 | RECtype = TYPEMFR; |
|---|
| 133 | if (qrydbnp) { |
|---|
| 134 | RECdbxp = dbxstorp(qrydbnp); |
|---|
| 135 | if (RDBmsmfn <= 0L) { |
|---|
| 136 | recisis0(qrydbnp); |
|---|
| 137 | RDBmsmfn = 1L; |
|---|
| 138 | } |
|---|
| 139 | MFRmfn=RDBmsmfn; |
|---|
| 140 | #if CICPP |
|---|
| 141 | crecp->xrecord(dbnamp,0); |
|---|
| 142 | crecp->xrecord(qrydbnp,0); |
|---|
| 143 | #else /* CICPP */ |
|---|
| 144 | record(crec,qrydbnp,0); |
|---|
| 145 | #endif /* CICPP */ |
|---|
| 146 | } |
|---|
| 147 | else { |
|---|
| 148 | RECdbxp = NULL; |
|---|
| 149 | if (MFRmfn == 0) MFRmfn=1; else MFRmfn=MFRmfn+1; |
|---|
| 150 | } |
|---|
| 151 | |
|---|
| 152 | RECrc=RCNORMAL; |
|---|
| 153 | |
|---|
| 154 | MFRmfrl=LEADER; |
|---|
| 155 | MFRmfbwb=MFRmfbwp=0; |
|---|
| 156 | |
|---|
| 157 | MFRbase=MFRmfrl; |
|---|
| 158 | MFRnvf=0; |
|---|
| 159 | MFRstatus=ACTIVE; |
|---|
| 160 | |
|---|
| 161 | |
|---|
| 162 | /* store MFQTDBN0 */ |
|---|
| 163 | sprintf(b7buffup,"A%d|%s|",MFQTDBN0,dbnamp); |
|---|
| 164 | #if CICPP |
|---|
| 165 | if (recp->xfldupdat(b7buffup)) |
|---|
| 166 | #else /* CICPP */ |
|---|
| 167 | if (fldupdat(irec,b7buffup)) |
|---|
| 168 | #endif /* CICPP */ |
|---|
| 169 | { |
|---|
| 170 | b7_experr(B7_THISP -3,"b7_exp/MFQTDBN0",0); |
|---|
| 171 | goto B7_EXPERROR; |
|---|
| 172 | } |
|---|
| 173 | |
|---|
| 174 | |
|---|
| 175 | /* store MFQTQRY0 */ |
|---|
| 176 | sprintf(b7buffup,"A%d|%s|",MFQTQRY0,qryp); |
|---|
| 177 | #if CICPP |
|---|
| 178 | if (recp->xfldupdat(b7buffup)) |
|---|
| 179 | #else /* CICPP */ |
|---|
| 180 | if (fldupdat(irec,b7buffup)) |
|---|
| 181 | #endif /* CICPP */ |
|---|
| 182 | { |
|---|
| 183 | b7_experr(B7_THISP -4,"b7_exp/MFQTQRY0",0); |
|---|
| 184 | goto B7_EXPERROR; |
|---|
| 185 | } |
|---|
| 186 | |
|---|
| 187 | |
|---|
| 188 | /* setup MFQTOBJ0 fldupdat */ |
|---|
| 189 | #if BOLTRACE |
|---|
| 190 | b7objp=b7buffup; |
|---|
| 191 | #endif |
|---|
| 192 | b7batchp=b7buffup; |
|---|
| 193 | sprintf(b7batchp,"A%d\n",MFQTOBJ0); b7batchp+=strlen(b7batchp); /* | AOT, 27/05/2004 */ |
|---|
| 194 | |
|---|
| 195 | |
|---|
| 196 | /* aponta expressao para gettoken */ |
|---|
| 197 | toknextp=qryp; |
|---|
| 198 | |
|---|
| 199 | /* analisa primeiro comando */ |
|---|
| 200 | nb7oprs=0; |
|---|
| 201 | statement(B7_THISP &answer); |
|---|
| 202 | |
|---|
| 203 | /* analisa demais */ |
|---|
| 204 | do { |
|---|
| 205 | if (*token) { |
|---|
| 206 | statement(B7_THISP &answer); |
|---|
| 207 | } |
|---|
| 208 | else |
|---|
| 209 | break; |
|---|
| 210 | } while (1); |
|---|
| 211 | |
|---|
| 212 | if( b7error ) { |
|---|
| 213 | b7_experr(B7_THISP b7error,"b7_exp/statement",0); |
|---|
| 214 | goto B7_EXPERROR; |
|---|
| 215 | } |
|---|
| 216 | |
|---|
| 217 | *b7batchp++ = OPRXEND; |
|---|
| 218 | #if TESTNotNULL |
|---|
| 219 | strcpy(b7batchp,"Not NULL"); b7batchp+=strlen(b7batchp); |
|---|
| 220 | #endif |
|---|
| 221 | *b7batchp++ = '\n'; /* '|'; AOT, 27/05/2004 */ |
|---|
| 222 | *b7batchp='\0'; |
|---|
| 223 | #if CICPP |
|---|
| 224 | if (recp->xfldupdat(b7buffup)) |
|---|
| 225 | #else /* CICPP */ |
|---|
| 226 | if (fldupdat(irec,b7buffup)) |
|---|
| 227 | #endif /* CICPP */ |
|---|
| 228 | { |
|---|
| 229 | b7_experr(B7_THISP -5,"b7_exp/fldupdat",0); |
|---|
| 230 | goto B7_EXPERROR; |
|---|
| 231 | } |
|---|
| 232 | |
|---|
| 233 | if (qrydbnp) { |
|---|
| 234 | #if CICPP |
|---|
| 235 | recp->xrecupdat(); |
|---|
| 236 | #else /* CICPP */ |
|---|
| 237 | recupdat(crec,irec); |
|---|
| 238 | #endif /* CICPP */ |
|---|
| 239 | } |
|---|
| 240 | |
|---|
| 241 | |
|---|
| 242 | #if BOLTRACE |
|---|
| 243 | display("end"); |
|---|
| 244 | #endif |
|---|
| 245 | |
|---|
| 246 | |
|---|
| 247 | RECtype = TYPEMFQ; |
|---|
| 248 | |
|---|
| 249 | #if BEFORE20010117 |
|---|
| 250 | #if SHOWCORE |
|---|
| 251 | if (b70trace) showcore("b7_exp - exit"); |
|---|
| 252 | #endif |
|---|
| 253 | #endif /* BEFORE20010117 */ |
|---|
| 254 | |
|---|
| 255 | *errnop=0; |
|---|
| 256 | sprintf( buffup, "%s", b7buffup); |
|---|
| 257 | #if CICPP |
|---|
| 258 | delete[] b7buffup; |
|---|
| 259 | #else /* CICPP */ |
|---|
| 260 | FREE(b7buffup); |
|---|
| 261 | #endif /* CICPP */ |
|---|
| 262 | return(NULL); |
|---|
| 263 | } |
|---|
| 264 | |
|---|
| 265 | |
|---|
| 266 | |
|---|
| 267 | #if CICPP |
|---|
| 268 | void CIB7::statement(LONGX *result) |
|---|
| 269 | #else /*CICPP*/ |
|---|
| 270 | void statement(cib7p,result) |
|---|
| 271 | b7_CIB7 *cib7p; |
|---|
| 272 | LONGX *result; |
|---|
| 273 | #endif /*CICPP*/ |
|---|
| 274 | { |
|---|
| 275 | |
|---|
| 276 | #if BOLTRACE |
|---|
| 277 | display("statement"); |
|---|
| 278 | #endif |
|---|
| 279 | |
|---|
| 280 | get_token(B7_THIS ); |
|---|
| 281 | |
|---|
| 282 | if (!*token){ |
|---|
| 283 | b7_experr(B7_THISP 1,"",0); |
|---|
| 284 | return; |
|---|
| 285 | } |
|---|
| 286 | |
|---|
| 287 | astatement(B7_THISP result); |
|---|
| 288 | |
|---|
| 289 | if (*token && *token != ';'){ |
|---|
| 290 | b7_experr(B7_THISP 2,token,toklen); |
|---|
| 291 | return; |
|---|
| 292 | } |
|---|
| 293 | |
|---|
| 294 | /*** nao gera fim de execucao */ |
|---|
| 295 | ; |
|---|
| 296 | |
|---|
| 297 | #if BOLTRACE |
|---|
| 298 | printf("statement - fim:'%s'\n",b7objp); |
|---|
| 299 | #endif |
|---|
| 300 | |
|---|
| 301 | } |
|---|
| 302 | |
|---|
| 303 | |
|---|
| 304 | |
|---|
| 305 | #if CICPP |
|---|
| 306 | void CIB7::astatement(LONGX *result) |
|---|
| 307 | #else /*CICPP*/ |
|---|
| 308 | void astatement(cib7p,result) |
|---|
| 309 | b7_CIB7* cib7p; |
|---|
| 310 | LONGX *result; |
|---|
| 311 | #endif /*CICPP*/ |
|---|
| 312 | { |
|---|
| 313 | char *p,*slotp; |
|---|
| 314 | int n,slotl; |
|---|
| 315 | char *acclevp; |
|---|
| 316 | |
|---|
| 317 | #if BOLTRACE |
|---|
| 318 | display("astatement"); |
|---|
| 319 | #endif |
|---|
| 320 | |
|---|
| 321 | acclevp=b7batchp; |
|---|
| 322 | |
|---|
| 323 | if (toktyp == TOKTERM && *token == '#') { /* #{idx/filn} */ |
|---|
| 324 | |
|---|
| 325 | slotp=token; slotl=toklen; |
|---|
| 326 | |
|---|
| 327 | p=tokbackp; get_token(B7_THIS ); |
|---|
| 328 | |
|---|
| 329 | if (toktyp == TOKDELIM && *token == '=') { |
|---|
| 330 | |
|---|
| 331 | #if BOLTRACE |
|---|
| 332 | printf("\n+++ %s",slotp); |
|---|
| 333 | #endif |
|---|
| 334 | get_token(B7_THIS ); |
|---|
| 335 | expression(B7_THISP result); |
|---|
| 336 | |
|---|
| 337 | /*** gera assign para o slot */ |
|---|
| 338 | |
|---|
| 339 | nb7oprs++; |
|---|
| 340 | |
|---|
| 341 | *b7batchp++ = ZASS; |
|---|
| 342 | for (p=slotp, n=slotl; n--; ) |
|---|
| 343 | *b7batchp++ = *p++; |
|---|
| 344 | *b7batchp++ = OPRNULL; |
|---|
| 345 | |
|---|
| 346 | *b7batchp = '\0'; /* tmp end */ |
|---|
| 347 | } |
|---|
| 348 | |
|---|
| 349 | else { |
|---|
| 350 | |
|---|
| 351 | #if BOLTRACE |
|---|
| 352 | printf("putback - tokbackp=%s\n",tokbackp); |
|---|
| 353 | #endif |
|---|
| 354 | toknextp=p; get_token(B7_THIS ); |
|---|
| 355 | |
|---|
| 356 | expression(B7_THISP result); |
|---|
| 357 | } |
|---|
| 358 | } |
|---|
| 359 | |
|---|
| 360 | else { |
|---|
| 361 | |
|---|
| 362 | expression(B7_THISP result); |
|---|
| 363 | } |
|---|
| 364 | |
|---|
| 365 | |
|---|
| 366 | for (p=acclevp; p != b7batchp; p++) |
|---|
| 367 | #if FIXTRACE |
|---|
| 368 | putchar(*p); |
|---|
| 369 | putchar('\n'); |
|---|
| 370 | #else |
|---|
| 371 | ; /* next p */ |
|---|
| 372 | #endif |
|---|
| 373 | if( b7error ) |
|---|
| 374 | return; |
|---|
| 375 | |
|---|
| 376 | fixup( B7_THISP acclevp,p-1); |
|---|
| 377 | #if FIXTRACE |
|---|
| 378 | puts(acclevp); |
|---|
| 379 | #endif |
|---|
| 380 | |
|---|
| 381 | #if BOLTRACE |
|---|
| 382 | printf("astatement - fim:'%s'\n",b7objp); |
|---|
| 383 | #endif |
|---|
| 384 | |
|---|
| 385 | } |
|---|
| 386 | |
|---|
| 387 | #if CICPP |
|---|
| 388 | char CIB7::expression(LONGX *result) |
|---|
| 389 | #else /*CICPP*/ |
|---|
| 390 | char expression(cib7p,result) |
|---|
| 391 | b7_CIB7 *cib7p; |
|---|
| 392 | LONGX *result; |
|---|
| 393 | #endif /*CICPP*/ |
|---|
| 394 | { |
|---|
| 395 | char op; |
|---|
| 396 | int opl; |
|---|
| 397 | LONGX hold; |
|---|
| 398 | |
|---|
| 399 | #if BOLTRACE |
|---|
| 400 | display("expression"); |
|---|
| 401 | #endif |
|---|
| 402 | |
|---|
| 403 | conjunction(B7_THISP result); |
|---|
| 404 | op=tokopr; opl=tokqty; |
|---|
| 405 | while (op == ZORX) { |
|---|
| 406 | get_token(B7_THIS ); |
|---|
| 407 | conjunction(B7_THISP &hold); |
|---|
| 408 | semaction(B7_THISP TBOOL,op,opl,result,&hold); |
|---|
| 409 | op=tokopr; opl=tokqty; |
|---|
| 410 | } |
|---|
| 411 | |
|---|
| 412 | #if BOLTRACE |
|---|
| 413 | printf("expression - fim - '%s'\n",b7objp); |
|---|
| 414 | #endif |
|---|
| 415 | |
|---|
| 416 | return(PSTLEVEL); |
|---|
| 417 | |
|---|
| 418 | } |
|---|
| 419 | |
|---|
| 420 | #if CICPP |
|---|
| 421 | char CIB7::conjunction(LONGX *result) |
|---|
| 422 | #else /*CICPP*/ |
|---|
| 423 | char conjunction(cib7p,result) |
|---|
| 424 | b7_CIB7 *cib7p; |
|---|
| 425 | LONGX *result; |
|---|
| 426 | #endif /*CICPP*/ |
|---|
| 427 | { |
|---|
| 428 | char op; |
|---|
| 429 | int opl; |
|---|
| 430 | LONGX hold; |
|---|
| 431 | |
|---|
| 432 | #if BOLTRACE |
|---|
| 433 | display("conjunction"); |
|---|
| 434 | #endif |
|---|
| 435 | |
|---|
| 436 | #if !LIND |
|---|
| 437 | conjgop(B7_THISP &hold); |
|---|
| 438 | #else |
|---|
| 439 | primitive(B7_THISP &hold); |
|---|
| 440 | #endif |
|---|
| 441 | op=tokopr; opl=tokqty; |
|---|
| 442 | while (op == ZAND || op == ZANN) { |
|---|
| 443 | get_token(B7_THIS ); |
|---|
| 444 | #if !LIND |
|---|
| 445 | conjgop(B7_THISP &hold); |
|---|
| 446 | #else |
|---|
| 447 | primitive(B7_THISP &hold); |
|---|
| 448 | #endif |
|---|
| 449 | semaction(B7_THISP TBOOL,op,opl,result,&hold); |
|---|
| 450 | op=tokopr; opl=tokqty; |
|---|
| 451 | } |
|---|
| 452 | |
|---|
| 453 | #if BOLTRACE |
|---|
| 454 | printf("conjunction - fim - '%s'\n",b7objp); |
|---|
| 455 | #endif |
|---|
| 456 | |
|---|
| 457 | return(PSTLEVEL); |
|---|
| 458 | } |
|---|
| 459 | |
|---|
| 460 | |
|---|
| 461 | |
|---|
| 462 | #if !LIND |
|---|
| 463 | #if CICPP |
|---|
| 464 | char CIB7::conjgop(LONGX *result) |
|---|
| 465 | #else /*CICPP*/ |
|---|
| 466 | char conjgop(cib7p,result) |
|---|
| 467 | b7_CIB7 *cib7p; |
|---|
| 468 | LONGX *result; |
|---|
| 469 | #endif /*CICPP*/ |
|---|
| 470 | { |
|---|
| 471 | char op; |
|---|
| 472 | int opl; |
|---|
| 473 | LONGX hold; |
|---|
| 474 | |
|---|
| 475 | #if BOLTRACE |
|---|
| 476 | display("conjgop"); |
|---|
| 477 | #endif |
|---|
| 478 | |
|---|
| 479 | conjfop(B7_THISP result); |
|---|
| 480 | op=tokopr; opl=tokqty; |
|---|
| 481 | while (op == ZANG) { |
|---|
| 482 | get_token(B7_THIS ); |
|---|
| 483 | conjfop(B7_THISP &hold); |
|---|
| 484 | semaction(B7_THISP TBOOL,op,opl,result,&hold); |
|---|
| 485 | op=tokopr; opl=tokqty; |
|---|
| 486 | } |
|---|
| 487 | |
|---|
| 488 | #if BOLTRACE |
|---|
| 489 | printf("conjgop - fim - '%s'\n",b7objp); |
|---|
| 490 | #endif |
|---|
| 491 | |
|---|
| 492 | return(PSTLEVEL); |
|---|
| 493 | } |
|---|
| 494 | |
|---|
| 495 | |
|---|
| 496 | #if CICPP |
|---|
| 497 | char CIB7::conjfop(LONGX *result) |
|---|
| 498 | #else /*CICPP*/ |
|---|
| 499 | char conjfop(cib7p,result) |
|---|
| 500 | b7_CIB7 *cib7p; |
|---|
| 501 | LONGX *result; |
|---|
| 502 | #endif /*CICPP*/ |
|---|
| 503 | { |
|---|
| 504 | char op; |
|---|
| 505 | int opl; |
|---|
| 506 | LONGX hold; |
|---|
| 507 | |
|---|
| 508 | #if BOLTRACE |
|---|
| 509 | display("conjfop"); |
|---|
| 510 | #endif |
|---|
| 511 | |
|---|
| 512 | conjpop(B7_THISP result); |
|---|
| 513 | op=tokopr; opl=tokqty; |
|---|
| 514 | while (op == ZANF) { |
|---|
| 515 | get_token(B7_THIS ); |
|---|
| 516 | conjpop(B7_THISP &hold); |
|---|
| 517 | semaction(B7_THISP TBOOL,op,opl,result,&hold); |
|---|
| 518 | op=tokopr; opl=tokqty; |
|---|
| 519 | } |
|---|
| 520 | |
|---|
| 521 | #if BOLTRACE |
|---|
| 522 | printf("conjfop - fim - '%s'\n",b7objp); |
|---|
| 523 | #endif |
|---|
| 524 | |
|---|
| 525 | return(PSTLEVEL); |
|---|
| 526 | } |
|---|
| 527 | |
|---|
| 528 | #if CICPP |
|---|
| 529 | char CIB7::conjpop(LONGX *result) |
|---|
| 530 | #else /*CICPP*/ |
|---|
| 531 | char conjpop(cib7p,result) |
|---|
| 532 | b7_CIB7 *cib7p; |
|---|
| 533 | LONGX *result; |
|---|
| 534 | #endif /*CICPP*/ |
|---|
| 535 | { |
|---|
| 536 | char op; |
|---|
| 537 | int opl; |
|---|
| 538 | LONGX hold; |
|---|
| 539 | |
|---|
| 540 | #if BOLTRACE |
|---|
| 541 | display("conjpop"); |
|---|
| 542 | #endif |
|---|
| 543 | |
|---|
| 544 | conjeop(B7_THISP result); |
|---|
| 545 | op=tokopr; opl=tokqty; |
|---|
| 546 | while (op == ZANP) { |
|---|
| 547 | get_token(B7_THIS ); |
|---|
| 548 | conjeop(B7_THISP &hold); |
|---|
| 549 | semaction(B7_THISP TBOOL,op,opl,result,&hold); |
|---|
| 550 | op=tokopr; opl=tokqty; |
|---|
| 551 | } |
|---|
| 552 | |
|---|
| 553 | #if BOLTRACE |
|---|
| 554 | printf("conjpop - fim - '%s'\n",b7objp); |
|---|
| 555 | #endif |
|---|
| 556 | |
|---|
| 557 | return(PSTLEVEL); |
|---|
| 558 | } |
|---|
| 559 | |
|---|
| 560 | |
|---|
| 561 | #if CICPP |
|---|
| 562 | char CIB7::conjeop(LONGX *result) |
|---|
| 563 | #else /*CICPP*/ |
|---|
| 564 | char conjeop(cib7p,result) |
|---|
| 565 | b7_CIB7 *cib7p; |
|---|
| 566 | LONGX *result; |
|---|
| 567 | #endif /*CICPP*/ |
|---|
| 568 | { |
|---|
| 569 | char op; |
|---|
| 570 | int opl; |
|---|
| 571 | LONGX hold; |
|---|
| 572 | |
|---|
| 573 | #if BOLTRACE |
|---|
| 574 | display("conjeop"); |
|---|
| 575 | #endif |
|---|
| 576 | |
|---|
| 577 | primitive(B7_THISP result); |
|---|
| 578 | op=tokopr; opl=tokqty; |
|---|
| 579 | while (op == ZANE) { |
|---|
| 580 | get_token(B7_THIS ); |
|---|
| 581 | primitive(B7_THISP &hold); |
|---|
| 582 | semaction(B7_THISP TBOOL,op,opl,result,&hold); |
|---|
| 583 | op=tokopr; opl=tokqty; |
|---|
| 584 | } |
|---|
| 585 | |
|---|
| 586 | #if BOLTRACE |
|---|
| 587 | printf("conjeop - fim - '%s'\n",b7objp); |
|---|
| 588 | #endif |
|---|
| 589 | |
|---|
| 590 | return(PSTLEVEL); |
|---|
| 591 | } |
|---|
| 592 | #endif /* LIND */ |
|---|
| 593 | |
|---|
| 594 | |
|---|
| 595 | #if CICPP |
|---|
| 596 | char CIB7::primitive(LONGX *result) |
|---|
| 597 | #else /*CICPP*/ |
|---|
| 598 | char primitive(cib7p,result) |
|---|
| 599 | b7_CIB7 *cib7p; |
|---|
| 600 | LONGX *result; |
|---|
| 601 | #endif /*CICPP*/ |
|---|
| 602 | { |
|---|
| 603 | char *p; |
|---|
| 604 | int n; |
|---|
| 605 | int aspc; |
|---|
| 606 | |
|---|
| 607 | #if BOLTRACE |
|---|
| 608 | printf /* display() */ ("primitive - '%s'\n",b7objp); |
|---|
| 609 | #endif |
|---|
| 610 | |
|---|
| 611 | switch (toktyp) { |
|---|
| 612 | |
|---|
| 613 | case TOKNULL: |
|---|
| 614 | b7_experr(B7_THISP 3,"",0); |
|---|
| 615 | return ' '; |
|---|
| 616 | |
|---|
| 617 | case TOKDELIM: |
|---|
| 618 | |
|---|
| 619 | if (tokopr == '(') { |
|---|
| 620 | get_token(B7_THIS ); |
|---|
| 621 | expression(B7_THISP result); |
|---|
| 622 | if (tokopr != ')'){ |
|---|
| 623 | b7_experr(B7_THISP 4,token,toklen); |
|---|
| 624 | return ' '; |
|---|
| 625 | } |
|---|
| 626 | } |
|---|
| 627 | else{ |
|---|
| 628 | b7_experr(B7_THISP 5,token,toklen); |
|---|
| 629 | return ' '; |
|---|
| 630 | } |
|---|
| 631 | |
|---|
| 632 | #if BOLTRACE |
|---|
| 633 | display("primitive.D"); |
|---|
| 634 | #endif |
|---|
| 635 | break; |
|---|
| 636 | |
|---|
| 637 | |
|---|
| 638 | case TOKTERM: |
|---|
| 639 | |
|---|
| 640 | /*** gera carga do termo */ |
|---|
| 641 | |
|---|
| 642 | nb7oprs++; |
|---|
| 643 | |
|---|
| 644 | if (tokqualp) { |
|---|
| 645 | if (tokqualn <= 0) |
|---|
| 646 | fatal("b7_primitive/tokqualn"); |
|---|
| 647 | *b7batchp++ = ZQUA; |
|---|
| 648 | for (p=tokqualp, n=tokquall; n--; ) |
|---|
| 649 | *b7batchp++ = *p++; |
|---|
| 650 | *b7batchp++ = OPRNULL; |
|---|
| 651 | nb7oprs++; |
|---|
| 652 | } |
|---|
| 653 | |
|---|
| 654 | *b7batchp++ = ZLDV; |
|---|
| 655 | *b7batchp++ = PSTLEVEL; /* room for pstlevel */ |
|---|
| 656 | for (aspc=0,p=token, n=toklen; n--; ){ |
|---|
| 657 | /* |
|---|
| 658 | <R> |
|---|
| 659 | Eliminar los carascteres de escape. |
|---|
| 660 | */ |
|---|
| 661 | if( *p == '\\' ){ |
|---|
| 662 | memmove( p, p+1, strlen(p) ); |
|---|
| 663 | *b7batchp++ = *p++; |
|---|
| 664 | continue; |
|---|
| 665 | } |
|---|
| 666 | |
|---|
| 667 | /* ASPAS */ |
|---|
| 668 | if( *p == '"' ) |
|---|
| 669 | aspc++; |
|---|
| 670 | *b7batchp++ = *p++; |
|---|
| 671 | } |
|---|
| 672 | if( aspc ) |
|---|
| 673 | if( aspc%2 ){ |
|---|
| 674 | b7_experr( B7_THISP 10, token, toklen ); |
|---|
| 675 | return ' '; |
|---|
| 676 | } |
|---|
| 677 | |
|---|
| 678 | /* </R> */ |
|---|
| 679 | *b7batchp++ = OPRNULL; |
|---|
| 680 | |
|---|
| 681 | *b7batchp = '\0'; /* tmp end */ |
|---|
| 682 | |
|---|
| 683 | |
|---|
| 684 | #if BOLTRACE |
|---|
| 685 | display("primitive.T"); |
|---|
| 686 | #endif |
|---|
| 687 | break; |
|---|
| 688 | |
|---|
| 689 | |
|---|
| 690 | default: |
|---|
| 691 | |
|---|
| 692 | b7_experr(B7_THISP 6,token,toklen); |
|---|
| 693 | return ' '; |
|---|
| 694 | } |
|---|
| 695 | |
|---|
| 696 | |
|---|
| 697 | get_token(B7_THIS ); |
|---|
| 698 | |
|---|
| 699 | #if BOLTRACE |
|---|
| 700 | printf("primitive - fim - '%s'\n",b7objp); |
|---|
| 701 | #endif |
|---|
| 702 | |
|---|
| 703 | return(PSTLEVEL); |
|---|
| 704 | } |
|---|
| 705 | |
|---|
| 706 | |
|---|
| 707 | #if CICPP |
|---|
| 708 | void CIB7::semaction(int type, |
|---|
| 709 | char op, |
|---|
| 710 | int opl, |
|---|
| 711 | LONGX *r, |
|---|
| 712 | LONGX *h) |
|---|
| 713 | #else /*CICPP*/ |
|---|
| 714 | void semaction(cib7p,type,op,opl,r,h) |
|---|
| 715 | b7_CIB7* cib7p; |
|---|
| 716 | int type; |
|---|
| 717 | char op; |
|---|
| 718 | int opl; |
|---|
| 719 | LONGX *r,*h; |
|---|
| 720 | #endif /*CICPP*/ |
|---|
| 721 | { |
|---|
| 722 | #if BOLTRACE |
|---|
| 723 | printf("semaction - op=%c\n",op); |
|---|
| 724 | #endif |
|---|
| 725 | |
|---|
| 726 | |
|---|
| 727 | /*** gera operacao com o topo-1 e topo */ |
|---|
| 728 | |
|---|
| 729 | |
|---|
| 730 | nb7oprs++; |
|---|
| 731 | |
|---|
| 732 | *b7batchp++ = op; |
|---|
| 733 | *b7batchp++ = opl + '0'; |
|---|
| 734 | *b7batchp++ = ACCLEVEL; /* room for acclevel */ |
|---|
| 735 | *b7batchp++ = OPRNULL; |
|---|
| 736 | |
|---|
| 737 | *b7batchp = '\0'; /* tmp end */ |
|---|
| 738 | |
|---|
| 739 | op=type+(*r)+(*h); /* no wrn */ |
|---|
| 740 | } |
|---|
| 741 | |
|---|
| 742 | |
|---|
| 743 | |
|---|
| 744 | #if CICPP |
|---|
| 745 | void CIB7::fixup(char *p1, char* p2) |
|---|
| 746 | #else /* CICPP */ |
|---|
| 747 | void fixup(cib7p,p1,p2) |
|---|
| 748 | b7_CIB7 *cib7p; |
|---|
| 749 | char *p1; |
|---|
| 750 | char *p2; |
|---|
| 751 | #endif /* CICPP */ |
|---|
| 752 | { |
|---|
| 753 | char *p,c; |
|---|
| 754 | int x; |
|---|
| 755 | |
|---|
| 756 | #if FIXTRACE |
|---|
| 757 | printf("fixup "); for (p=p1; p!=p2; p++) putchar(*p); |
|---|
| 758 | getchar(); |
|---|
| 759 | #endif |
|---|
| 760 | |
|---|
| 761 | if (*p2 != OPRNULL) fatal("*p2 != OPRNULL"); |
|---|
| 762 | |
|---|
| 763 | for (nop=0, p=p1; p != p2; p++) { |
|---|
| 764 | x=0; |
|---|
| 765 | switch (*p) { |
|---|
| 766 | case PSTLEVEL: c= *(p-1); |
|---|
| 767 | switch (c) { |
|---|
| 768 | case ZLDV: x='0'; break; |
|---|
| 769 | default: fatal("b7_exp/PSTLEVEL"); |
|---|
| 770 | } |
|---|
| 771 | break; |
|---|
| 772 | case ACCLEVEL: c= *(p-2); |
|---|
| 773 | switch (c) { |
|---|
| 774 | case ZORX: |
|---|
| 775 | case ZAND: |
|---|
| 776 | case ZANN: x='1'; break; |
|---|
| 777 | #if !LIND |
|---|
| 778 | case ZANG: x='2'; break; |
|---|
| 779 | case ZANF: x='3'; break; |
|---|
| 780 | case ZANP: |
|---|
| 781 | case ZANE: x='4'; break; |
|---|
| 782 | #endif /* !LIND */ |
|---|
| 783 | default: fatal("b7_exp/ACCLEVEL"); |
|---|
| 784 | } |
|---|
| 785 | break; |
|---|
| 786 | } |
|---|
| 787 | if (x) { |
|---|
| 788 | if (nop >= MAXVOPR){ |
|---|
| 789 | b7_experr(B7_THISP -7,"fixup/MAXVOPR",0); |
|---|
| 790 | return; |
|---|
| 791 | } |
|---|
| 792 | vetopr[nop]=c; vetcas[nop]=x; vetopp[nop]=p; |
|---|
| 793 | #if FIXTRACE |
|---|
| 794 | printf("#%2d opr=%c cas=%c opp=%.3s\n", |
|---|
| 795 | nop,vetopr[nop],vetcas[nop],vetopp[nop]); |
|---|
| 796 | #endif |
|---|
| 797 | nop++; |
|---|
| 798 | } |
|---|
| 799 | } |
|---|
| 800 | if (nop == 0) |
|---|
| 801 | fatal("fixup/nop"); |
|---|
| 802 | #if FIXTRACE |
|---|
| 803 | xtrac=0; |
|---|
| 804 | #endif |
|---|
| 805 | fixlev(B7_THISP nop-1,'1'); |
|---|
| 806 | |
|---|
| 807 | /* check '#' */ |
|---|
| 808 | for (p=p1; p != p2; p++) { |
|---|
| 809 | if (*p == ZLDV) |
|---|
| 810 | if (*(p+1) >= '1' && *(p+1) <= '4') |
|---|
| 811 | if (*(p+2) == '#') |
|---|
| 812 | if (*(p+1) != '1'){ |
|---|
| 813 | b7_experr(B7_THISP 22,"#",1); |
|---|
| 814 | return; |
|---|
| 815 | } |
|---|
| 816 | } |
|---|
| 817 | } |
|---|
| 818 | |
|---|
| 819 | |
|---|
| 820 | #if CICPP |
|---|
| 821 | int CIB7::fixlev(int i2, char level) |
|---|
| 822 | #else |
|---|
| 823 | int fixlev(cib7p,i2,level) |
|---|
| 824 | b7_CIB7 *cib7p; |
|---|
| 825 | int i2; |
|---|
| 826 | char level; |
|---|
| 827 | #endif |
|---|
| 828 | { |
|---|
| 829 | #if FIXTRACE |
|---|
| 830 | int n; |
|---|
| 831 | for (n=xtrac; n--; ) printf(" "); |
|---|
| 832 | printf("[%d] i2=%d level=%c ",xtrac,i2,level); |
|---|
| 833 | #endif |
|---|
| 834 | |
|---|
| 835 | if (i2 < 0) return(i2); |
|---|
| 836 | |
|---|
| 837 | #if FIXTRACE |
|---|
| 838 | printf("%.9s\n",vetopp[i2]); |
|---|
| 839 | #endif |
|---|
| 840 | |
|---|
| 841 | *vetopp[i2]=level; |
|---|
| 842 | |
|---|
| 843 | if (vetopr[i2] != ZLDV) { /* operation */ |
|---|
| 844 | #if FIXTRACE |
|---|
| 845 | xtrac++; |
|---|
| 846 | #endif |
|---|
| 847 | if (vetcas[i2] > level) |
|---|
| 848 | level=vetcas[i2]; |
|---|
| 849 | |
|---|
| 850 | if (i2 < 2) |
|---|
| 851 | fatal("fixlev/i2<2"); |
|---|
| 852 | i2=fixlev(B7_THISP i2-1,level); |
|---|
| 853 | |
|---|
| 854 | if (i2 < 0) |
|---|
| 855 | fatal("fixlev/i2<0"); |
|---|
| 856 | i2=fixlev(B7_THISP i2-1,level); |
|---|
| 857 | #if FIXTRACE |
|---|
| 858 | xtrac--; |
|---|
| 859 | #endif |
|---|
| 860 | } |
|---|
| 861 | |
|---|
| 862 | return(i2); |
|---|
| 863 | } |
|---|
| 864 | |
|---|
| 865 | #define iswhite(c) isspace(c) |
|---|
| 866 | #if CICPP |
|---|
| 867 | void CIB7::get_token() |
|---|
| 868 | #else |
|---|
| 869 | void get_token(cib7p) |
|---|
| 870 | b7_CIB7 *cib7p; |
|---|
| 871 | #endif |
|---|
| 872 | { |
|---|
| 873 | char *toknp,*toknxp,toknx; |
|---|
| 874 | |
|---|
| 875 | char *tkkbackp; |
|---|
| 876 | char *tkknextp; |
|---|
| 877 | char *tkken; |
|---|
| 878 | char tkktyp; |
|---|
| 879 | char tkkopr; |
|---|
| 880 | int tkkqty; |
|---|
| 881 | int tkklen; |
|---|
| 882 | |
|---|
| 883 | char *p; |
|---|
| 884 | int loop; |
|---|
| 885 | |
|---|
| 886 | |
|---|
| 887 | NEWTOKEN: |
|---|
| 888 | tokmassp=NULL; |
|---|
| 889 | gettoken(B7_THIS); |
|---|
| 890 | tokqualp=NULL; |
|---|
| 891 | tokquall=tokqualn=0; |
|---|
| 892 | |
|---|
| 893 | switch (toktyp) { |
|---|
| 894 | |
|---|
| 895 | case TOKDELIM: |
|---|
| 896 | break; |
|---|
| 897 | |
|---|
| 898 | case TOKTERM: |
|---|
| 899 | if (!*token) { |
|---|
| 900 | toktyp=TOKNULL; |
|---|
| 901 | break; |
|---|
| 902 | } |
|---|
| 903 | |
|---|
| 904 | for (toknxp=toknextp; iswhite(*toknxp); toknxp++); |
|---|
| 905 | toknx = (*toknxp == '/') ? '/' : '\0'; |
|---|
| 906 | |
|---|
| 907 | while (toklen && iswhite(*(toknextp-1))) { |
|---|
| 908 | toklen--; |
|---|
| 909 | toknextp--; |
|---|
| 910 | } |
|---|
| 911 | |
|---|
| 912 | toknp=token+toklen; |
|---|
| 913 | while (toklen && iswhite(*(toknp-1))) { |
|---|
| 914 | toklen--; |
|---|
| 915 | toknp--; |
|---|
| 916 | } |
|---|
| 917 | |
|---|
| 918 | if (b7batchp) /* intbrm - 06/01/93 */ |
|---|
| 919 | tokmassp=b7_massp(B7_THISP token,toklen,B7EE_PFX); |
|---|
| 920 | |
|---|
| 921 | |
|---|
| 922 | if (*(toknp-1) == '/' || toknx == '/') { |
|---|
| 923 | tkkbackp=tokbackp; |
|---|
| 924 | tkknextp=toknextp; |
|---|
| 925 | tkken=token; |
|---|
| 926 | tkktyp=toktyp; |
|---|
| 927 | tkkopr=tokopr; |
|---|
| 928 | tkkqty=tokqty; |
|---|
| 929 | tkklen=toklen; |
|---|
| 930 | |
|---|
| 931 | if (toknx == '/') |
|---|
| 932 | toknextp=toknxp+1; |
|---|
| 933 | gettoken(B7_THIS); /* '(' */ |
|---|
| 934 | if (tokopr == '(') { |
|---|
| 935 | tokqualp=toknextp; |
|---|
| 936 | gettoken(B7_THIS); /* 10,20,30,...,qualifier_n */ |
|---|
| 937 | tokquall=toklen; |
|---|
| 938 | gettoken(B7_THIS); /* ')' */ |
|---|
| 939 | if (tokopr == ')') { |
|---|
| 940 | tokqualn=1; |
|---|
| 941 | for (p=tokqualp, loop=tokquall; loop--; p++) { |
|---|
| 942 | if (iswhite(*p)) |
|---|
| 943 | continue; |
|---|
| 944 | if (*p == ',') |
|---|
| 945 | tokqualn++; |
|---|
| 946 | if (tokqualn >= MAXQUAL){ |
|---|
| 947 | b7_experr(B7_THISP 7,tokqualp,tokquall); |
|---|
| 948 | return; |
|---|
| 949 | } |
|---|
| 950 | } |
|---|
| 951 | } |
|---|
| 952 | else{ |
|---|
| 953 | b7_experr(B7_THISP 8,tokqualp,tokquall); |
|---|
| 954 | return; |
|---|
| 955 | } |
|---|
| 956 | token=tkken; |
|---|
| 957 | toktyp=tkktyp; |
|---|
| 958 | tokopr=tkkopr; |
|---|
| 959 | tokqty=tkkqty; |
|---|
| 960 | toklen=tkklen; |
|---|
| 961 | |
|---|
| 962 | if (toknx != '/') |
|---|
| 963 | do { |
|---|
| 964 | toklen--; |
|---|
| 965 | toknp--; |
|---|
| 966 | } while (toklen && iswhite(*(toknp-1))); |
|---|
| 967 | } |
|---|
| 968 | else { |
|---|
| 969 | tokbackp=tkkbackp; |
|---|
| 970 | toknextp=tkknextp; |
|---|
| 971 | token=tkken; |
|---|
| 972 | toktyp=tkktyp; |
|---|
| 973 | tokopr=tkkopr; |
|---|
| 974 | tokqty=tkkqty; |
|---|
| 975 | toklen=tkklen; |
|---|
| 976 | } |
|---|
| 977 | } |
|---|
| 978 | ; |
|---|
| 979 | #if MASSAGE |
|---|
| 980 | tokmassp=b7_massp(token,toklen,tokqualp,tokquall,toknextp); |
|---|
| 981 | #endif |
|---|
| 982 | ; |
|---|
| 983 | break; |
|---|
| 984 | |
|---|
| 985 | default: |
|---|
| 986 | fatal("b7_expr/get_token"); |
|---|
| 987 | } |
|---|
| 988 | |
|---|
| 989 | #if TOKTRACE |
|---|
| 990 | #if !BOLTRACE |
|---|
| 991 | display("get_token"); |
|---|
| 992 | #endif |
|---|
| 993 | #endif |
|---|
| 994 | |
|---|
| 995 | if (tokmassp) { |
|---|
| 996 | toknextp=tokmassp; |
|---|
| 997 | goto NEWTOKEN; |
|---|
| 998 | } |
|---|
| 999 | } |
|---|
| 1000 | |
|---|
| 1001 | |
|---|
| 1002 | #if CICPP |
|---|
| 1003 | void CIB7::gettoken() |
|---|
| 1004 | #else |
|---|
| 1005 | void gettoken(cib7p) |
|---|
| 1006 | b7_CIB7 *cib7p; |
|---|
| 1007 | #endif |
|---|
| 1008 | /* |
|---|
| 1009 | ------------- */ |
|---|
| 1010 | { |
|---|
| 1011 | int n; |
|---|
| 1012 | char c,*p; |
|---|
| 1013 | #if !LIND |
|---|
| 1014 | char uc; |
|---|
| 1015 | #endif /* !LIND */ |
|---|
| 1016 | int checkpos; /* RP 29/05/98 */ |
|---|
| 1017 | int aspc; |
|---|
| 1018 | |
|---|
| 1019 | aspc = 0; |
|---|
| 1020 | |
|---|
| 1021 | |
|---|
| 1022 | tokbackp=toknextp; /* para putback */ |
|---|
| 1023 | |
|---|
| 1024 | |
|---|
| 1025 | |
|---|
| 1026 | /* space and proximity operators */ |
|---|
| 1027 | |
|---|
| 1028 | if (iswhite(*toknextp)) { |
|---|
| 1029 | |
|---|
| 1030 | while (iswhite(*toknextp)) { |
|---|
| 1031 | toknextp++; |
|---|
| 1032 | } |
|---|
| 1033 | |
|---|
| 1034 | p=token=toknextp; c= *p; |
|---|
| 1035 | |
|---|
| 1036 | switch (c) { |
|---|
| 1037 | |
|---|
| 1038 | case '.': |
|---|
| 1039 | case '$': |
|---|
| 1040 | if (iswhite(*(p+1))) { |
|---|
| 1041 | n=0; |
|---|
| 1042 | do { |
|---|
| 1043 | n++; p+=2; |
|---|
| 1044 | } while (*p == c && iswhite(*(p+1))); |
|---|
| 1045 | toktyp=TOKDELIM; |
|---|
| 1046 | tokopr = c; |
|---|
| 1047 | tokqty=n; |
|---|
| 1048 | toklen=n+n-1; |
|---|
| 1049 | toknextp=p; |
|---|
| 1050 | return; |
|---|
| 1051 | } |
|---|
| 1052 | break; |
|---|
| 1053 | } |
|---|
| 1054 | } |
|---|
| 1055 | |
|---|
| 1056 | |
|---|
| 1057 | p=token=toknextp; c= *p; |
|---|
| 1058 | |
|---|
| 1059 | |
|---|
| 1060 | /* others delimiters */ |
|---|
| 1061 | |
|---|
| 1062 | tokqty=1; toktyp=TOKDELIM; |
|---|
| 1063 | |
|---|
| 1064 | switch (c) { |
|---|
| 1065 | |
|---|
| 1066 | case 'a': |
|---|
| 1067 | case 'A': |
|---|
| 1068 | if (iswhite(*(p-1))) |
|---|
| 1069 | if (toupper(*(p+1)) == 'N') |
|---|
| 1070 | if (toupper(*(p+2)) == 'D') |
|---|
| 1071 | if (iswhite(*(p+3))) |
|---|
| 1072 | if (toupper(*(p+4)) == 'N') |
|---|
| 1073 | if (toupper(*(p+5)) == 'O') |
|---|
| 1074 | if (toupper(*(p+6)) == 'T') |
|---|
| 1075 | if (iswhite(*(p+7))) { |
|---|
| 1076 | toknextp+=7; toklen=7; |
|---|
| 1077 | c = '^'; |
|---|
| 1078 | tokopr=c; return; |
|---|
| 1079 | } |
|---|
| 1080 | if (iswhite(*(p-1))) |
|---|
| 1081 | if (toupper(*(p+1)) == 'N') |
|---|
| 1082 | if (toupper(*(p+2)) == 'D') |
|---|
| 1083 | if (iswhite(*(p+3))) { |
|---|
| 1084 | toknextp+=3; toklen=3; |
|---|
| 1085 | c = '*'; |
|---|
| 1086 | tokopr=c; |
|---|
| 1087 | #if !LIND |
|---|
| 1088 | if (and2gf == 1) tokopr=ZANG; /* AOT&RP 28/05/98 */ |
|---|
| 1089 | if (and2gf == 2) tokopr=ZANF; /* AOT&RP 28/05/98 */ |
|---|
| 1090 | #endif /* !LIND */ |
|---|
| 1091 | return; |
|---|
| 1092 | } |
|---|
| 1093 | break; |
|---|
| 1094 | case 'o': |
|---|
| 1095 | case 'O': |
|---|
| 1096 | if (iswhite(*(p-1))) |
|---|
| 1097 | if (toupper(*(p+1)) == 'R') |
|---|
| 1098 | if (iswhite(*(p+2))) { |
|---|
| 1099 | toknextp+=2; toklen=2; |
|---|
| 1100 | c = '+'; |
|---|
| 1101 | tokopr=c; return; |
|---|
| 1102 | } |
|---|
| 1103 | break; |
|---|
| 1104 | #if !LIND |
|---|
| 1105 | case 'w': |
|---|
| 1106 | case 'W': |
|---|
| 1107 | if (iswhite(*(p-1))) |
|---|
| 1108 | if (toupper(*(p+1)) == 'I') |
|---|
| 1109 | if (toupper(*(p+2)) == 'T') |
|---|
| 1110 | if (toupper(*(p+3)) == 'H') |
|---|
| 1111 | if (iswhite(*(p+4))) { |
|---|
| 1112 | toknextp+=4; toklen=4; |
|---|
| 1113 | c = ZANF; |
|---|
| 1114 | tokopr=c; return; |
|---|
| 1115 | } |
|---|
| 1116 | break; |
|---|
| 1117 | #endif |
|---|
| 1118 | |
|---|
| 1119 | case '=': |
|---|
| 1120 | case '+': |
|---|
| 1121 | case '*': |
|---|
| 1122 | case '^': |
|---|
| 1123 | tokopr = c; |
|---|
| 1124 | toklen=1; |
|---|
| 1125 | toknextp+=1; |
|---|
| 1126 | #if !LIND |
|---|
| 1127 | if (tokopr == '*') { /* AOT&RP 28/05/98 */ |
|---|
| 1128 | if (and2gf == 1) tokopr=ZANG; /* AOT&RP 28/05/98 */ |
|---|
| 1129 | if (and2gf == 2) tokopr=ZANF; /* AOT&RP 28/05/98 */ |
|---|
| 1130 | } |
|---|
| 1131 | #endif /* !LIND */ |
|---|
| 1132 | return; |
|---|
| 1133 | |
|---|
| 1134 | case '(': |
|---|
| 1135 | case ')': |
|---|
| 1136 | #if !LIND |
|---|
| 1137 | if (c == '(') |
|---|
| 1138 | if ((uc = toupper(*(p+1))) == ZANG || uc == ZANF) |
|---|
| 1139 | if (*(p+2) == ')') { |
|---|
| 1140 | tokopr = uc; |
|---|
| 1141 | toklen=3; |
|---|
| 1142 | toknextp+=3; |
|---|
| 1143 | return; |
|---|
| 1144 | } |
|---|
| 1145 | #endif |
|---|
| 1146 | tokopr = c; |
|---|
| 1147 | toklen=1; |
|---|
| 1148 | toknextp+=1; |
|---|
| 1149 | return; |
|---|
| 1150 | |
|---|
| 1151 | case '"': |
|---|
| 1152 | tokopr='\0'; |
|---|
| 1153 | toktyp=TOKTERM; |
|---|
| 1154 | toklen=tokqty=0; |
|---|
| 1155 | toknextp++; |
|---|
| 1156 | toklen++; |
|---|
| 1157 | /* |
|---|
| 1158 | <R> |
|---|
| 1159 | ASPAS |
|---|
| 1160 | */ |
|---|
| 1161 | for (; *toknextp; toknextp++, toklen++) |
|---|
| 1162 | if (*toknextp == c) { |
|---|
| 1163 | toknextp++; |
|---|
| 1164 | toklen++; |
|---|
| 1165 | return; |
|---|
| 1166 | } |
|---|
| 1167 | b7_experr(B7_THISP 2,token,toklen); |
|---|
| 1168 | return; |
|---|
| 1169 | /* |
|---|
| 1170 | </R> |
|---|
| 1171 | */ |
|---|
| 1172 | |
|---|
| 1173 | break; |
|---|
| 1174 | default : /* RP 29/05/98 begin */ |
|---|
| 1175 | if (!subst_and) break; |
|---|
| 1176 | if (!iswhite(*(p-1))) break; |
|---|
| 1177 | for (checkpos = 0; *(subst_and+checkpos); checkpos++) |
|---|
| 1178 | if (toupper(*(p+checkpos)) != toupper(*(subst_and+checkpos))) { |
|---|
| 1179 | checkpos = 0; |
|---|
| 1180 | break; |
|---|
| 1181 | } |
|---|
| 1182 | if (!checkpos) break; |
|---|
| 1183 | if (!iswhite(*(p+checkpos))) break; |
|---|
| 1184 | toknextp+=checkpos; toklen=checkpos; |
|---|
| 1185 | c = '*'; |
|---|
| 1186 | tokopr=c; |
|---|
| 1187 | return; /* RP 29/05/98 end */ |
|---|
| 1188 | |
|---|
| 1189 | } |
|---|
| 1190 | |
|---|
| 1191 | |
|---|
| 1192 | /* default */ |
|---|
| 1193 | |
|---|
| 1194 | tokopr='\0'; toklen=tokqty=0; toktyp=TOKTERM; |
|---|
| 1195 | |
|---|
| 1196 | while (*p) { |
|---|
| 1197 | toklen++; |
|---|
| 1198 | toknextp++; |
|---|
| 1199 | |
|---|
| 1200 | switch (*toknextp) { |
|---|
| 1201 | |
|---|
| 1202 | case '.': |
|---|
| 1203 | case '$': |
|---|
| 1204 | if (iswhite(*(toknextp-1))) |
|---|
| 1205 | if (iswhite(*(toknextp+1))) |
|---|
| 1206 | return; |
|---|
| 1207 | break; |
|---|
| 1208 | case '\\': |
|---|
| 1209 | toknextp+=2; |
|---|
| 1210 | toklen++; |
|---|
| 1211 | break; |
|---|
| 1212 | case '\0': |
|---|
| 1213 | case '+': |
|---|
| 1214 | case '*': |
|---|
| 1215 | case '^': |
|---|
| 1216 | case '(': |
|---|
| 1217 | case ')': |
|---|
| 1218 | /* |
|---|
| 1219 | <R> ASPAS |
|---|
| 1220 | */ |
|---|
| 1221 | if( !aspc ) |
|---|
| 1222 | return; |
|---|
| 1223 | /* </R> */ |
|---|
| 1224 | case 'a': |
|---|
| 1225 | case 'A': |
|---|
| 1226 | if (iswhite(*(toknextp-1))) |
|---|
| 1227 | if (toupper(*(toknextp+1)) == 'N') |
|---|
| 1228 | if (toupper(*(toknextp+2)) == 'D') |
|---|
| 1229 | if (iswhite(*(toknextp+3))) |
|---|
| 1230 | return; |
|---|
| 1231 | break; |
|---|
| 1232 | case 'o': |
|---|
| 1233 | case 'O': |
|---|
| 1234 | if (iswhite(*(toknextp-1))) |
|---|
| 1235 | if (toupper(*(toknextp+1)) == 'R') |
|---|
| 1236 | if (iswhite(*(toknextp+2))) |
|---|
| 1237 | return; |
|---|
| 1238 | break; |
|---|
| 1239 | #if !LIND |
|---|
| 1240 | case 'w': |
|---|
| 1241 | case 'W': |
|---|
| 1242 | if (iswhite(*(toknextp-1))) |
|---|
| 1243 | if (toupper(*(toknextp+1)) == 'I') |
|---|
| 1244 | if (toupper(*(toknextp+2)) == 'T') |
|---|
| 1245 | if (toupper(*(toknextp+3)) == 'H') |
|---|
| 1246 | if (iswhite(*(toknextp+4))) |
|---|
| 1247 | return; |
|---|
| 1248 | break; |
|---|
| 1249 | #endif |
|---|
| 1250 | default : /* RP 29/05/98 begin */ |
|---|
| 1251 | if (!subst_and) break; |
|---|
| 1252 | if (!iswhite(*(toknextp-1))) break; |
|---|
| 1253 | for (checkpos = 0; *(subst_and+checkpos); checkpos++) |
|---|
| 1254 | if (toupper(*(toknextp+checkpos)) != toupper(*(subst_and+checkpos))) { |
|---|
| 1255 | checkpos = 0; |
|---|
| 1256 | break; |
|---|
| 1257 | } |
|---|
| 1258 | if (!checkpos) break; |
|---|
| 1259 | if (!iswhite(*(toknextp+checkpos))) break; |
|---|
| 1260 | return; /* RP 29/05/98 end */ |
|---|
| 1261 | } |
|---|
| 1262 | } |
|---|
| 1263 | |
|---|
| 1264 | if (*p) |
|---|
| 1265 | fatal("gettoken"); |
|---|
| 1266 | } |
|---|
| 1267 | |
|---|
| 1268 | |
|---|
| 1269 | |
|---|
| 1270 | |
|---|
| 1271 | |
|---|
| 1272 | |
|---|
| 1273 | #if CICPP |
|---|
| 1274 | void CIB7::b7_experr(int error, |
|---|
| 1275 | char *errp, |
|---|
| 1276 | int errl) |
|---|
| 1277 | #else /*CICPP*/ |
|---|
| 1278 | void b7_experr(cib7p,error,errp,errl) |
|---|
| 1279 | b7_CIB7 *cib7p; |
|---|
| 1280 | int error; |
|---|
| 1281 | char *errp; |
|---|
| 1282 | int errl; |
|---|
| 1283 | #endif /*CICPP*/ |
|---|
| 1284 | { |
|---|
| 1285 | #if ERRTRACE |
|---|
| 1286 | char *p; |
|---|
| 1287 | int loop; |
|---|
| 1288 | #endif |
|---|
| 1289 | |
|---|
| 1290 | if (errl <= 0) errl=strlen(errp); |
|---|
| 1291 | if (errl >= MAXERRL) errl=MAXERRL; |
|---|
| 1292 | |
|---|
| 1293 | #if ERRTRACE |
|---|
| 1294 | printf("b7_experr - error=%d (",error); |
|---|
| 1295 | for (p=errp,loop=errl;loop--;p++) |
|---|
| 1296 | putchar(*p); |
|---|
| 1297 | printf(")\n"); |
|---|
| 1298 | #endif |
|---|
| 1299 | |
|---|
| 1300 | strncpy(b7errxy,errp,errl); b7errxy[errl]='\0'; |
|---|
| 1301 | |
|---|
| 1302 | #if FATRAP |
|---|
| 1303 | longjmp(b71jumper,error); |
|---|
| 1304 | #endif /* FATRAP */ |
|---|
| 1305 | |
|---|
| 1306 | b7error=error?error:1; |
|---|
| 1307 | b71error=b7error; |
|---|
| 1308 | |
|---|
| 1309 | } |
|---|
| 1310 | |
|---|
| 1311 | |
|---|
| 1312 | |
|---|
| 1313 | #if DISTRACE |
|---|
| 1314 | #if CICPP |
|---|
| 1315 | void display(char *s) |
|---|
| 1316 | #else /*CICPP*/ |
|---|
| 1317 | void display(s) |
|---|
| 1318 | char *s; |
|---|
| 1319 | #endif /*CICPP*/ |
|---|
| 1320 | { |
|---|
| 1321 | #if RECTRACE |
|---|
| 1322 | RECSTRU *recp; |
|---|
| 1323 | char c; |
|---|
| 1324 | #endif |
|---|
| 1325 | int i,n; |
|---|
| 1326 | char *p; |
|---|
| 1327 | |
|---|
| 1328 | #if BOLTRACE |
|---|
| 1329 | printf("%s - token=",s); |
|---|
| 1330 | for (p=token, n=toklen; n--; p++) putchar(*p); |
|---|
| 1331 | printf(",len=%d,typ=%d",toklen,toktyp); |
|---|
| 1332 | printf(",opr=%c,qty=%d",tokopr,tokqty); |
|---|
| 1333 | printf(",next=%c",*toknextp); |
|---|
| 1334 | if (tokqualp) { |
|---|
| 1335 | for (p=s; *p; p++) putchar(' '); |
|---|
| 1336 | printf(" - qualp="); |
|---|
| 1337 | for (p=tokqualp, n=tokquall; n--; p++) putchar(*p); |
|---|
| 1338 | printf(",l=%d,n=%d",tokqualp,tokquall,tokqualn); |
|---|
| 1339 | } |
|---|
| 1340 | putchar('\n'); |
|---|
| 1341 | } |
|---|
| 1342 | #endif |
|---|
| 1343 | |
|---|
| 1344 | #if RECTRACE |
|---|
| 1345 | recp=b7recp; |
|---|
| 1346 | printf("mfn,mfrl,mfbwb,mfbwp,base,nvf,status: %"_LD_,%d,%"_LD_,%d,%d,%d,%d\n", |
|---|
| 1347 | MFRmfn,MFRmfrl,MFRmfbwb,MFRmfbwp,MFRbase,MFRnvf,MFRstatus); |
|---|
| 1348 | for (i=0; i<MFRnvf; i++) { |
|---|
| 1349 | printf("b7 - i,tag,pos,len=%d,%d,%d,%d (", |
|---|
| 1350 | i,DIRtag(i),DIRpos(i),DIRlen(i)); |
|---|
| 1351 | for (p=FIELDP(i), n=DIRlen(i); n--; ) |
|---|
| 1352 | putchar(((c = *p++) == NULL) ? '0' : c); |
|---|
| 1353 | printf(")\n"); |
|---|
| 1354 | } |
|---|
| 1355 | #endif |
|---|
| 1356 | |
|---|
| 1357 | #if RECTRACE |
|---|
| 1358 | recp=b7recp; |
|---|
| 1359 | printf("mfn,mfrl,mfbwb,mfbwp,base,nvf,status: %"_LD_,%d,%"_LD_,%d,%d,%d,%d\n", |
|---|
| 1360 | MFRmfn,MFRmfrl,MFRmfbwb,MFRmfbwp,MFRbase,MFRnvf,MFRstatus); |
|---|
| 1361 | for (i=0; i<MFRnvf; i++) { |
|---|
| 1362 | printf("b7 - i,tag,pos,len=%d,%d,%d,%d (", |
|---|
| 1363 | i,DIRtag(i),DIRpos(i),DIRlen(i)); |
|---|
| 1364 | for (p=FIELDP(i), n=DIRlen(i); n--; ) |
|---|
| 1365 | putchar(((c = *p++) == NULL) ? '0' : c); |
|---|
| 1366 | printf(")\n"); |
|---|
| 1367 | } |
|---|
| 1368 | #endif |
|---|
| 1369 | |
|---|
| 1370 | } |
|---|
| 1371 | #endif |
|---|
| 1372 | |
|---|
| 1373 | #if CICPP |
|---|
| 1374 | char *CIB7::b7_massp(char *tokenmassp, |
|---|
| 1375 | int tokenmassplen, |
|---|
| 1376 | int b7ee_pfx) |
|---|
| 1377 | #else /*CICPP*/ |
|---|
| 1378 | char *b7_massp(cib7p,tokenmassp, tokenmassplen, b7ee_pfx) |
|---|
| 1379 | b7_CIB7 *cib7p; |
|---|
| 1380 | char *tokenmassp; |
|---|
| 1381 | int tokenmassplen; |
|---|
| 1382 | int b7ee_pfx; |
|---|
| 1383 | #endif /*CICPP*/ |
|---|
| 1384 | { |
|---|
| 1385 | char *p; |
|---|
| 1386 | int deflen,found; |
|---|
| 1387 | |
|---|
| 1388 | if (*tokenmassp == '[') { |
|---|
| 1389 | found=0; |
|---|
| 1390 | for (p=tokenmassp+1, deflen=0; deflen+1 < tokenmassplen ; p++, deflen++) { |
|---|
| 1391 | if (*p == ']') { |
|---|
| 1392 | found=1; |
|---|
| 1393 | break; |
|---|
| 1394 | } |
|---|
| 1395 | } |
|---|
| 1396 | |
|---|
| 1397 | |
|---|
| 1398 | if (!found) b7_experr(B7_THISP b7ee_pfx,tokenmassp,tokenmassplen); |
|---|
| 1399 | |
|---|
| 1400 | /*** gera [XX] */ |
|---|
| 1401 | nb7oprs++; |
|---|
| 1402 | *b7batchp++ = ZPFX; |
|---|
| 1403 | #if 0 |
|---|
| 1404 | if (deflen > 9) deflen=9; |
|---|
| 1405 | *b7batchp++ = deflen + '0'; |
|---|
| 1406 | #endif |
|---|
| 1407 | memcpy(b7batchp,tokenmassp+1,deflen); b7batchp+=deflen; |
|---|
| 1408 | *b7batchp++ = OPRNULL; |
|---|
| 1409 | |
|---|
| 1410 | return(p+1); |
|---|
| 1411 | } |
|---|
| 1412 | |
|---|
| 1413 | return(NULL); |
|---|
| 1414 | } |
|---|
| 1415 | |
|---|
| 1416 | |
|---|
| 1417 | #if !CICPP |
|---|
| 1418 | /* |
|---|
| 1419 | cib7.c - estrutura com o environment de compilacao, execucao e recuperacao dos hits |
|---|
| 1420 | */ |
|---|
| 1421 | |
|---|
| 1422 | /* |
|---|
| 1423 | Constructor y destructor :-) |
|---|
| 1424 | */ |
|---|
| 1425 | |
|---|
| 1426 | b7_CIB7 *b7_cib7(b7_CIB7 *cib7p, void *xciapip) { |
|---|
| 1427 | |
|---|
| 1428 | if (!cib7p) { |
|---|
| 1429 | #if CICPP |
|---|
| 1430 | cib7p=(b7_CIB7*)new char[sizeof(b7_CIB7)]; |
|---|
| 1431 | #else |
|---|
| 1432 | cib7p=(b7_CIB7*)ALLOC((ALLOPARM)sizeof(b7_CIB7)); |
|---|
| 1433 | #endif |
|---|
| 1434 | if (!cib7p) fatal("b7_cib7/ALLOC"); |
|---|
| 1435 | memset(cib7p,0x00,sizeof(b7_CIB7)); /* AOT, 24/02/2002, |
|---|
| 1436 | despues de mucho trabajo en debugar la aplicacion, porque jamais podria |
|---|
| 1437 | creer que el projecto B7 podiera haber sido "liberado" con un bug tan |
|---|
| 1438 | primitivo: llamar a b7_exp para una expression con error de sintaxis, |
|---|
| 1439 | atrapar el error code y obviamente *no llamar a b7_run* y |
|---|
| 1440 | llamar a b7_cib7_delete() |
|---|
| 1441 | que ocurre? b7_free sera' llamada al azar, porque, npdls no |
|---|
| 1442 | esta' inicializado y solo es setado en b7_run, |
|---|
| 1443 | aunque b7_cib7_delete() obviamente sea llamada si hubo o |
|---|
| 1444 | no hubo error de sintaxis en la expression de busqueda |
|---|
| 1445 | |
|---|
| 1446 | peor: el bug fue introduzido durante el desarrollo del zserver |
|---|
| 1447 | |
|---|
| 1448 | BTW: Rosnier, que significa su comentario "gress!!! "en el fuente cib72.c? |
|---|
| 1449 | */ |
|---|
| 1450 | } |
|---|
| 1451 | |
|---|
| 1452 | #if CIAPI |
|---|
| 1453 | #if !TLS |
|---|
| 1454 | ciapip = xciapip; |
|---|
| 1455 | #endif |
|---|
| 1456 | #endif |
|---|
| 1457 | |
|---|
| 1458 | b70trace=0; |
|---|
| 1459 | and2gf=0; /* AOT&RP 28/05/98 */ |
|---|
| 1460 | subst_and=NULL; /* RP 29/05/98 */ |
|---|
| 1461 | b7_gidbnp=NULL; /* dbn.par */ |
|---|
| 1462 | b7fd=0; /* open() - 06/03/95 */ |
|---|
| 1463 | b7bufferp = NULL; /* b7_run() processing buffer */ |
|---|
| 1464 | b7_pfxmdl=0; |
|---|
| 1465 | b7error=0; |
|---|
| 1466 | b7rootmsg=OFF; |
|---|
| 1467 | return (cib7p); |
|---|
| 1468 | } |
|---|
| 1469 | |
|---|
| 1470 | b7_CIB7 *b7_cib7_delete(b7_CIB7 *cib7p ) { |
|---|
| 1471 | |
|---|
| 1472 | if (!cib7p) return((b7_CIB7 *)NULL); |
|---|
| 1473 | |
|---|
| 1474 | for (; npdls; npdls--) |
|---|
| 1475 | #if CICPP |
|---|
| 1476 | b7_free(npdls-1); |
|---|
| 1477 | #else |
|---|
| 1478 | b7_free(cib7p,npdls-1); |
|---|
| 1479 | #endif |
|---|
| 1480 | |
|---|
| 1481 | if (b7bufferp) |
|---|
| 1482 | #if CICPP |
|---|
| 1483 | delete [] b7bufferp; |
|---|
| 1484 | #else |
|---|
| 1485 | FREE(b7bufferp); |
|---|
| 1486 | #endif |
|---|
| 1487 | |
|---|
| 1488 | #if CICPP |
|---|
| 1489 | delete [] (char *)cib7p; |
|---|
| 1490 | #else |
|---|
| 1491 | FREE((char *)cib7p); |
|---|
| 1492 | #endif |
|---|
| 1493 | |
|---|
| 1494 | return((b7_CIB7 *)NULL); |
|---|
| 1495 | } |
|---|
| 1496 | #endif /* CICPP */ |
|---|