| 1 | #include <stdio.h> |
|---|
| 2 | #include <string.h> |
|---|
| 3 | #include <ctype.h> |
|---|
| 4 | #include "cisis.h" |
|---|
| 5 | |
|---|
| 6 | #if CICPP |
|---|
| 7 | #include <cifst.hpp> |
|---|
| 8 | #include <cirun.hpp> |
|---|
| 9 | |
|---|
| 10 | //#include <ciutl.hpp> |
|---|
| 11 | #if USE_GDBFMT |
|---|
| 12 | #include <format.hpp> |
|---|
| 13 | #else |
|---|
| 14 | #include <cifmt.hpp> |
|---|
| 15 | #endif |
|---|
| 16 | #endif /* CICPP */ |
|---|
| 17 | |
|---|
| 18 | #if CICPP |
|---|
| 19 | #define FST351 0 |
|---|
| 20 | #else |
|---|
| 21 | #define FST351 1 |
|---|
| 22 | #endif |
|---|
| 23 | |
|---|
| 24 | #define FSTBSIZ 0x7FFF |
|---|
| 25 | |
|---|
| 26 | #if BEFORE20010604 |
|---|
| 27 | #ifdef CI_WINISIS |
|---|
| 28 | #define ENTRY_DLM 0x01 /* no Ctrl C may be entered and therefore... */ |
|---|
| 29 | #else |
|---|
| 30 | #define ENTRY_DLM ';' /* for inline fst's */ |
|---|
| 31 | #endif |
|---|
| 32 | #endif |
|---|
| 33 | #define FST_EDLM 0x01 /* no Ctrl C may be entered and therefore... */ |
|---|
| 34 | |
|---|
| 35 | /* ------------------------- CIFST.HPP --------------------------------- */ |
|---|
| 36 | #if CICPP |
|---|
| 37 | #define fst_gener xfst_gener /* internal use */ |
|---|
| 38 | #define fst_free xfst_free /* internal use */ |
|---|
| 39 | /* #define fst_inter xfst_inter no conversion */ |
|---|
| 40 | #define fst_link xfst_link /* internal use */ |
|---|
| 41 | #define fst_writ xfst_writ /* internal use */ |
|---|
| 42 | #define fst_open xfst_open /* internal use */ |
|---|
| 43 | #define fst_clos xfst_clos /* internal use */ |
|---|
| 44 | #define pstdecod xpstdecod /* internal use */ |
|---|
| 45 | #define prtlink xprtlink /* internal use */ |
|---|
| 46 | #endif /* CICPP */ |
|---|
| 47 | /* --------------------------------------------------------------------- */ |
|---|
| 48 | |
|---|
| 49 | #if !CICPP |
|---|
| 50 | int cifstfix=0; /* key %8ld %5d %4d %4d */ |
|---|
| 51 | int cifstfim=0; /* key %8ld w/ cifstfix */ |
|---|
| 52 | #endif /* CICPP */ |
|---|
| 53 | |
|---|
| 54 | /* ----------------------------- fst.c ------------------------------ */ |
|---|
| 55 | #define FSTTRACE 0 |
|---|
| 56 | #if !CICPP |
|---|
| 57 | #define FSSTRACE 1 |
|---|
| 58 | #endif |
|---|
| 59 | |
|---|
| 60 | #if !CICPP |
|---|
| 61 | |
|---|
| 62 | LONGX fst_error; /* gener - fst spec error */ |
|---|
| 63 | LONGX fst_errl; /* gener - fst spec line where error occured */ |
|---|
| 64 | char *fst_errp; /* gener - fst spec ptr where error occured */ |
|---|
| 65 | char *fst_fmtap=NULL; /* inter - default: no static format area */ |
|---|
| 66 | LONGX fst_fmtby=MAXMFRL; /* inter - bytes for dynamic format area */ |
|---|
| 67 | char fst_rdlm='%'; /* inter - new occ delimiter */ |
|---|
| 68 | char *fst_batchup=NULL; /* inter - batchp for fldupdat() area */ |
|---|
| 69 | char *fst_batchp=NULL; /* inter - batchp for fldupdat() commands */ |
|---|
| 70 | int fst_batch0=1; /* inter - batchp ^mmfn^oocc^ccnt^l1/2 option */ |
|---|
| 71 | char fst_a351='\0'; /* inter - 351 */ |
|---|
| 72 | UCHR *fst_fbuff[2]={NULL,NULL}; /* writbsiz*/ |
|---|
| 73 | UWORD fst_fbsiz=FSTBSIZ/*0x7FFF*/; |
|---|
| 74 | UWORD fst_fleft[2]; |
|---|
| 75 | UWORD fst_ffree[2]={0,0}; |
|---|
| 76 | int fst_fd[2]={0,0}; /* inter - file descriptor for .ln1/.ln2 */ |
|---|
| 77 | LONGX fst_fx[2]={0,0}; /* inter - output records to .ln1/.ln2 */ |
|---|
| 78 | char *fst_hdrp=NULL; /* inter - hit file headers - area */ |
|---|
| 79 | int fst_hdrx=0; /* inter - hit file headers - #bytes allocated */ |
|---|
| 80 | int fst_hdru=0; /* inter - hit file headers - #bytes stored */ |
|---|
| 81 | int fst_hdrt=0; /* inter - hit file headers - for area+^m^t^o^c */ |
|---|
| 82 | char *fst_wlupifnp=NULL; /* inter - word lookup I/F for TW processing */ |
|---|
| 83 | TRMSTRU *fst_wluptrmp=NULL; /* inter - word lookup I/F for TW processing */ |
|---|
| 84 | LONGX fst_wlupitrm=0L; /* inter - word lookup I/F for TW processing */ |
|---|
| 85 | #endif /* CICPP */ |
|---|
| 86 | |
|---|
| 87 | #if CICPP |
|---|
| 88 | #define NO_IREC -1L |
|---|
| 89 | #endif /* CICPP */ |
|---|
| 90 | |
|---|
| 91 | #if CICPP |
|---|
| 92 | FSTSTRU :: FSTSTRU (CISISX *parm_cisisxp, char *gidbnp, char *fstfile, char *stwfile, |
|---|
| 93 | #if USE_GDBFMT |
|---|
| 94 | MST_FILE *mst, BTREE *btree, |
|---|
| 95 | #endif |
|---|
| 96 | /* LONGX maxlk1, LONGX maxlk2, int instream):*/ |
|---|
| 97 | LONGX maxlk1, LONGX maxlk2, int instream, int stw_instream): |
|---|
| 98 | cisisxp(parm_cisisxp), cifstfix(0), cifstfim(0), fst_error(0L), fst_errl(0L), |
|---|
| 99 | fst_errp(NULL), fst_fmtap (NULL), fst_fmtby(MAXMFRL), |
|---|
| 100 | fst_rdlm('%') , |
|---|
| 101 | fst_batchup(NULL), fst_batchp(NULL), fst_batch0(1), |
|---|
| 102 | fst_a351('\0'), fst_fbsiz(FSTBSIZ/*0x7FFF*/) |
|---|
| 103 | { |
|---|
| 104 | fst_fbuff[0] = NULL; |
|---|
| 105 | fst_fbuff[1] = NULL; |
|---|
| 106 | fst_fleft[0] = 0; |
|---|
| 107 | fst_fleft[1] = 0; |
|---|
| 108 | fst_ffree[0] = 0; |
|---|
| 109 | fst_ffree[1] = 0; |
|---|
| 110 | fst_fd[0] = 0; |
|---|
| 111 | fst_fd[1] = 0; |
|---|
| 112 | fst_fx[0] = 0; |
|---|
| 113 | fst_fx[1] = 0; |
|---|
| 114 | |
|---|
| 115 | fst_pgmp=NULL; |
|---|
| 116 | fst_stwp=NULL; |
|---|
| 117 | fst_nstws=0; |
|---|
| 118 | fst_area1p=NULL; |
|---|
| 119 | fst_maxlk1=maxlk1; |
|---|
| 120 | fst_area2p=NULL; |
|---|
| 121 | fst_maxlk2=maxlk2; |
|---|
| 122 | fst_qtylk1=0; |
|---|
| 123 | fst_qtylk2=0; |
|---|
| 124 | |
|---|
| 125 | fst_oarea1p=NULL; |
|---|
| 126 | fst_oarea2p=NULL; |
|---|
| 127 | fst_oqtylk1=0; |
|---|
| 128 | fst_oqtylk2=0; |
|---|
| 129 | |
|---|
| 130 | fst_hdrp=NULL; |
|---|
| 131 | fst_hdrx=0; |
|---|
| 132 | fst_hdru=0; |
|---|
| 133 | fst_hdrt=0; |
|---|
| 134 | |
|---|
| 135 | fst_wlupifnp=NULL; /* inter - word lookup I/F for TW processing */ |
|---|
| 136 | fst_wluptrmp=NULL; /* inter - word lookup I/F for TW processing */ |
|---|
| 137 | fst_wlupitrm=0L; /* inter - word lookup I/F for TW processing */ |
|---|
| 138 | |
|---|
| 139 | #if USE_GDBFMT |
|---|
| 140 | fst_mst=mst; |
|---|
| 141 | fst_btree=btree; |
|---|
| 142 | #endif |
|---|
| 143 | fst_recp=NULL; |
|---|
| 144 | |
|---|
| 145 | int nlins = 0; |
|---|
| 146 | |
|---|
| 147 | #if !CIAPI_SOURCE |
|---|
| 148 | |
|---|
| 149 | char *specp=xfst_loadfst(gidbnp,fstfile,instream); |
|---|
| 150 | #ifdef CI_WINISIS |
|---|
| 151 | // ---- DS 03/98 |
|---|
| 152 | if (!specp) specp=xfst_loadfst(NULL,fstfile,instream); |
|---|
| 153 | // ---- DS 03/98 (end) |
|---|
| 154 | #endif |
|---|
| 155 | if (!specp) fst_error+=1; |
|---|
| 156 | |
|---|
| 157 | /* fst_stwp=xfst_loadstw(gidbnp,stwfile,&fst_nstws); */ |
|---|
| 158 | fst_stwp=xfst_loadstw(gidbnp,stwfile,&fst_nstws, stw_instream); |
|---|
| 159 | //if (!fst_stwp) fst_error+=2; |
|---|
| 160 | |
|---|
| 161 | if (specp) nlins=xfst_gener(specp); |
|---|
| 162 | |
|---|
| 163 | delete [] specp; |
|---|
| 164 | if (nlins <= 0) fst_error+=4; |
|---|
| 165 | #endif /* CIAPI_SOURCE */ |
|---|
| 166 | } |
|---|
| 167 | |
|---|
| 168 | FSTSTRU :: ~FSTSTRU (void) |
|---|
| 169 | { |
|---|
| 170 | fst_clos(0); fst_clos(1); |
|---|
| 171 | xfst_free(); // delete each entry pointed to by fst_pgmp, including fmtp |
|---|
| 172 | } |
|---|
| 173 | |
|---|
| 174 | |
|---|
| 175 | char * FSTSTRU :: xfst_batch(LONGX nbytes, int option) |
|---|
| 176 | { |
|---|
| 177 | delete [] fst_batchup; |
|---|
| 178 | try {fst_batchup=new char [nbytes];} |
|---|
| 179 | catch(BAD_ALLOC) {fst_batchup=(char *)NULL;} |
|---|
| 180 | fst_batch0 = option; |
|---|
| 181 | return(fst_batchup); |
|---|
| 182 | } |
|---|
| 183 | |
|---|
| 184 | |
|---|
| 185 | RECSTRU * FSTSTRU :: xfst_getrecp(void) |
|---|
| 186 | { |
|---|
| 187 | if (!fst_recp) fst_recp = new RECSTRU(cisisxp); |
|---|
| 188 | return(fst_recp); |
|---|
| 189 | } |
|---|
| 190 | |
|---|
| 191 | void FSTSTRU :: xfst_setrecp(RECSTRU *recp) |
|---|
| 192 | { |
|---|
| 193 | fst_recp=recp; |
|---|
| 194 | } |
|---|
| 195 | |
|---|
| 196 | #endif /* CICPP */ |
|---|
| 197 | |
|---|
| 198 | #if CICPP |
|---|
| 199 | char * FSTSTRU::xfst_loadfst(char *gidbnp, char *file, int instream) |
|---|
| 200 | { |
|---|
| 201 | char *fstspecp = NULL; // = "24 4 v24\n 70 0 (v70/)\n 69 2 v69"; |
|---|
| 202 | if (instream) { |
|---|
| 203 | try {fstspecp=new char [strlen(file)+1];} |
|---|
| 204 | catch(BAD_ALLOC) {fstspecp=(char *)NULL;} |
|---|
| 205 | if (fstspecp == (char *)NULL) return(NULL); |
|---|
| 206 | strcpy(fstspecp,file); |
|---|
| 207 | } |
|---|
| 208 | else fstspecp=loadfile(gidbnp,'\0',file,NULL,0L,'\n'); /* ok */ |
|---|
| 209 | return fstspecp; |
|---|
| 210 | } |
|---|
| 211 | |
|---|
| 212 | char * FSTSTRU::xfst_loadstw(char *gidbnp, char *file, int *nstwsp, int stw_instream) |
|---|
| 213 | { |
|---|
| 214 | char *stwp=NULL; |
|---|
| 215 | int nstws=0; |
|---|
| 216 | //if (file) if (file[0]) stwp=loadstw(gidbnp, file,NULL,0L,&nstws); |
|---|
| 217 | if (file) |
|---|
| 218 | if (file[0]) |
|---|
| 219 | if (stw_instream) { |
|---|
| 220 | stwp=xloadmemstw(file,&nstws); |
|---|
| 221 | } else { |
|---|
| 222 | stwp=loadstw(gidbnp, file,NULL,0L,&nstws); |
|---|
| 223 | } |
|---|
| 224 | if (nstwsp) *nstwsp = nstws; |
|---|
| 225 | return stwp; |
|---|
| 226 | } |
|---|
| 227 | |
|---|
| 228 | LONGX FSTSTRU :: xfst_gener(char *fstspecp) |
|---|
| 229 | #else |
|---|
| 230 | LONGX fst_gener(pgmpp,fstspecp) /* |
|---|
| 231 | -------------- |
|---|
| 232 | aloca e compila uma fst |
|---|
| 233 | */ |
|---|
| 234 | FST_CODE **pgmpp; |
|---|
| 235 | char *fstspecp; |
|---|
| 236 | #endif /* CICPP */ |
|---|
| 237 | { |
|---|
| 238 | #if CICPP |
|---|
| 239 | FST_CODE **pgmpp = &fst_pgmp; |
|---|
| 240 | #endif |
|---|
| 241 | FST_CODE *pgmp,*lastp=NULL; |
|---|
| 242 | LONGX nfsts=0L; |
|---|
| 243 | UWORD tag; |
|---|
| 244 | int itx; |
|---|
| 245 | FMT_CODX *fmtp; |
|---|
| 246 | char *p,*q,c; |
|---|
| 247 | int n; |
|---|
| 248 | LONGX fmtrc; |
|---|
| 249 | char cifstdlm=FST_EDLM; /* multiple fst delimiter */ /* 20010604 */ |
|---|
| 250 | #if FSTTRACE |
|---|
| 251 | printf("fst_gener - '%s'\n",fstspecp); |
|---|
| 252 | #endif |
|---|
| 253 | if (rectrace) fsttrace=1; |
|---|
| 254 | /* init pgmpp */ |
|---|
| 255 | *pgmpp=NULL; |
|---|
| 256 | nfsts=0; |
|---|
| 257 | /* point to fst specification and do it */ |
|---|
| 258 | p=fstspecp; |
|---|
| 259 | fst_errl=1; |
|---|
| 260 | fst_errp=p; |
|---|
| 261 | if (*p) if (!isdigit(*p)) cifstdlm = *p++; |
|---|
| 262 | for (fst_error=0; *p; ) { |
|---|
| 263 | /* ignore leading spaces ( /ht/cr/lf/vt/ff) */ |
|---|
| 264 | while (isspace(*p) || *p == cifstdlm) p++; |
|---|
| 265 | if (!*p) break; |
|---|
| 266 | /* new fst entry */ |
|---|
| 267 | #if CICPP |
|---|
| 268 | try { pgmp=(FST_CODE *)new char[sizeof(FST_CODE)];} |
|---|
| 269 | catch (BAD_ALLOC){pgmp=(FST_CODE *)ALLONULL;} |
|---|
| 270 | #else |
|---|
| 271 | pgmp=(FST_CODE *)ALLOC((ALLOPARM)sizeof(FST_CODE)); |
|---|
| 272 | #endif /* CICPP */ |
|---|
| 273 | if (pgmp == (FST_CODE *)ALLONULL) fatal("fst_gener/ALLOC"); |
|---|
| 274 | memset(pgmp,0x00,sizeof(FST_CODE)); |
|---|
| 275 | if (lastp) lastp->nextp=pgmp; else *pgmpp=pgmp; |
|---|
| 276 | lastp=pgmp; |
|---|
| 277 | /* parse */ |
|---|
| 278 | fst_errp=p; |
|---|
| 279 | if (!isdigit(*p)) {fst_error=FSTERR1; break;} |
|---|
| 280 | for (tag=0; isdigit(*p); p++) tag=tag*10+((int)(*p)-(int)'0'); |
|---|
| 281 | while (*p == ' ' || *p == '\t') p++; |
|---|
| 282 | if (!isdigit(*p)) {fst_error=FSTERR2; break;} |
|---|
| 283 | for (itx=0; isdigit(*p); p++) itx=itx*10+((int)(*p)-(int)'0'); |
|---|
| 284 | while (*p == ' ' || *p == '\t') p++; |
|---|
| 285 | if (itx != 351) |
|---|
| 286 | if (itx < 0 || itx > 8) |
|---|
| 287 | if (itx < 1000 || itx > 1008) |
|---|
| 288 | if (itx < 2000 || itx > 2008) |
|---|
| 289 | {fst_error=FSTERR2; break;} |
|---|
| 290 | #if BEFORE20010604 |
|---|
| 291 | if (isspace(*p) || *p == ENTRY_DLM) {fst_error=FSTERR3; break;} |
|---|
| 292 | #else |
|---|
| 293 | if (isspace(*p) || *p == cifstdlm) {fst_error=FSTERR3; break;} |
|---|
| 294 | #endif |
|---|
| 295 | for (n=0, q=p; ; q++, n++) |
|---|
| 296 | #if BEFORE20010604 |
|---|
| 297 | if (*q == '\n' || *q == ENTRY_DLM || !*q) {c= *q; break;} |
|---|
| 298 | #else |
|---|
| 299 | if (*q == '\n' || *q == cifstdlm || !*q) {c= *q; break;} |
|---|
| 300 | #endif |
|---|
| 301 | if (!n) {fst_error=FSTERR3; break;} |
|---|
| 302 | *q='\0'; |
|---|
| 303 | if (fsttrace) printf("fst_gener - tag=%d it=%d pft='%s'\n",tag,itx,p); |
|---|
| 304 | #if CICPP |
|---|
| 305 | #if USE_GDBFMT |
|---|
| 306 | fmtrc=0; |
|---|
| 307 | fmtp=strdup(p); // RELEASE |
|---|
| 308 | #else |
|---|
| 309 | fmtp=(char *)new FMTSTRU(cisisxp); |
|---|
| 310 | fmtrc = ((FMTSTRU *)fmtp)->xfmt_gener(p); |
|---|
| 311 | #endif /* USE_GDBFMT */ |
|---|
| 312 | #else |
|---|
| 313 | fmtrc=fmt_gener(&fmtp,p); |
|---|
| 314 | #endif /* CICPP */ |
|---|
| 315 | if (fmtrc) {fst_error=FSTERRF; break;} |
|---|
| 316 | pgmp->tag=tag; |
|---|
| 317 | pgmp->it=itx; |
|---|
| 318 | pgmp->fmtp=fmtp; |
|---|
| 319 | /* restore last chr */ |
|---|
| 320 | *q=c; |
|---|
| 321 | /* next line */ |
|---|
| 322 | p=q; |
|---|
| 323 | fst_errl++; |
|---|
| 324 | nfsts++; |
|---|
| 325 | /* next line */ |
|---|
| 326 | fst_errl++; |
|---|
| 327 | } |
|---|
| 328 | if (fst_error) { |
|---|
| 329 | pgmp= *pgmpp; |
|---|
| 330 | #if CICPP |
|---|
| 331 | xfst_free(); |
|---|
| 332 | #else /* CICPP */ |
|---|
| 333 | fst_free(pgmp); |
|---|
| 334 | #endif /* CICPP */ |
|---|
| 335 | *pgmpp=NULL; |
|---|
| 336 | return(fst_error); |
|---|
| 337 | } |
|---|
| 338 | else { |
|---|
| 339 | fst_errl=0; |
|---|
| 340 | fst_errp=NULL; |
|---|
| 341 | return(nfsts); |
|---|
| 342 | } |
|---|
| 343 | } |
|---|
| 344 | |
|---|
| 345 | #if CICPP |
|---|
| 346 | void FSTSTRU :: xfst_free(void) |
|---|
| 347 | #else |
|---|
| 348 | void fst_free(pgmp) /* |
|---|
| 349 | -------------- |
|---|
| 350 | libera area de uma fst |
|---|
| 351 | inclui delete's de FSTSTRU |
|---|
| 352 | */ |
|---|
| 353 | FST_CODE *pgmp; |
|---|
| 354 | #endif /* CICPP */ |
|---|
| 355 | { |
|---|
| 356 | #if CICPP |
|---|
| 357 | FST_CODE *pgmp = fst_pgmp; |
|---|
| 358 | #endif |
|---|
| 359 | FST_CODE *nextp; |
|---|
| 360 | for (; pgmp; pgmp=nextp) { |
|---|
| 361 | if (pgmp->fmtp) |
|---|
| 362 | #if USE_GDBFMT |
|---|
| 363 | free (pgmp->fmtp); // because has been allocated via strdup() |
|---|
| 364 | // delete [] pgmp->fmtp; // RELEASE |
|---|
| 365 | #else |
|---|
| 366 | #if CICPP |
|---|
| 367 | //((FMTSTRU *)pgmp->fmtp)->xfmt_free(); |
|---|
| 368 | delete (FMTSTRU *)pgmp->fmtp; |
|---|
| 369 | #else |
|---|
| 370 | fmt_free(pgmp->fmtp); /* fmt_free nao testava */ |
|---|
| 371 | #endif /* CICPP */ |
|---|
| 372 | #endif |
|---|
| 373 | nextp=pgmp->nextp; |
|---|
| 374 | |
|---|
| 375 | #if CICPP |
|---|
| 376 | delete [] (char *)pgmp; |
|---|
| 377 | #else |
|---|
| 378 | FREE(pgmp); |
|---|
| 379 | #endif /* CICPP */ |
|---|
| 380 | } |
|---|
| 381 | #if CICPP |
|---|
| 382 | delete [] fst_stwp; fst_stwp = NULL; |
|---|
| 383 | delete [] fst_area1p; fst_area1p = NULL; |
|---|
| 384 | delete [] fst_area2p; fst_area2p = NULL; |
|---|
| 385 | delete [] fst_oarea1p; fst_oarea1p = NULL; |
|---|
| 386 | delete [] fst_oarea2p; fst_oarea2p = NULL; |
|---|
| 387 | delete fst_recp; fst_recp = NULL; |
|---|
| 388 | delete [] fst_batchup; fst_batchup = NULL; |
|---|
| 389 | delete fst_wluptrmp; fst_wluptrmp = NULL; |
|---|
| 390 | #else |
|---|
| 391 | /* |
|---|
| 392 | if (fst_stwp) FREE(fst_stwp); |
|---|
| 393 | if (fst_area1p) FREE(fst_area1p); |
|---|
| 394 | if (fst_area2p) FREE(fst_area2p); |
|---|
| 395 | if (fst_oarea1p) FREE(fst_oarea1p); |
|---|
| 396 | if (fst_oarea2p) FREE(fst_oarea2p); |
|---|
| 397 | if (fst_recp) FREE(fst_recp); |
|---|
| 398 | if (fst_batchup) FREE(fst_batchup); |
|---|
| 399 | */ |
|---|
| 400 | if (fst_wluptrmp) if (fst_wlupitrm) { |
|---|
| 401 | FREE(vtrmp[fst_wlupitrm]); vtrmp[fst_wlupitrm]=NULL; ntrms--; |
|---|
| 402 | fst_wlupitrm=0L; |
|---|
| 403 | } |
|---|
| 404 | #endif /* CICPP */ |
|---|
| 405 | |
|---|
| 406 | /* |
|---|
| 407 | fst_stwp=NULL; |
|---|
| 408 | fst_area1p=NULL; |
|---|
| 409 | fst_area2p=NULL; |
|---|
| 410 | fst_oarea1p=NULL; |
|---|
| 411 | fst_oarea2p=NULL; |
|---|
| 412 | fst_recp=NULL; |
|---|
| 413 | fst_batchup=NULL; |
|---|
| 414 | */ |
|---|
| 415 | fst_wluptrmp=NULL; |
|---|
| 416 | } |
|---|
| 417 | |
|---|
| 418 | #if CICPP |
|---|
| 419 | LONGX FSTSTRU :: xfst_inter(int bwcase) |
|---|
| 420 | #else |
|---|
| 421 | LONGX fst_inter(pgmp,irec,stwp,area1pp,max1,area2pp,max2,qty1p,qty2p) /* |
|---|
| 422 | -------------- |
|---|
| 423 | se area1p = NULL entao aloca max1 x LINK1; |
|---|
| 424 | se area2p = NULL entao aloca max2 x LINK2; |
|---|
| 425 | executa pgmp; |
|---|
| 426 | retorna qty1+qty2 |
|---|
| 427 | */ |
|---|
| 428 | FST_CODE *pgmp; |
|---|
| 429 | LONGX irec; |
|---|
| 430 | char *stwp; |
|---|
| 431 | char **area1pp; |
|---|
| 432 | LONGX max1; |
|---|
| 433 | char **area2pp; |
|---|
| 434 | LONGX max2; |
|---|
| 435 | LONGX *qty1p; |
|---|
| 436 | LONGX *qty2p; |
|---|
| 437 | #endif /* CICPP */ |
|---|
| 438 | { |
|---|
| 439 | #if CICPP |
|---|
| 440 | #if USE_GDBFMT |
|---|
| 441 | MST_FILE *mst=fst_mst; |
|---|
| 442 | BTREE *btree=fst_btree; |
|---|
| 443 | #endif |
|---|
| 444 | FST_CODE *pgmp = fst_pgmp; |
|---|
| 445 | char *stwp = fst_stwp; |
|---|
| 446 | char **area1pp = (!bwcase) ? &fst_area1p : &fst_oarea1p; |
|---|
| 447 | LONGX max1 = fst_maxlk1; |
|---|
| 448 | char **area2pp = (!bwcase) ? &fst_area2p : &fst_oarea2p; |
|---|
| 449 | LONGX max2 = fst_maxlk2; |
|---|
| 450 | LONGX *qty1p = (!bwcase) ? &fst_qtylk1 : &fst_oqtylk1; |
|---|
| 451 | LONGX *qty2p = (!bwcase) ? &fst_qtylk2 : &fst_oqtylk2; |
|---|
| 452 | LONGX irec = NO_IREC; |
|---|
| 453 | #else |
|---|
| 454 | LONGX xqty1,xqty2; |
|---|
| 455 | #endif /* CICPP */ |
|---|
| 456 | |
|---|
| 457 | RECSTRU *recp; |
|---|
| 458 | LONGX mfn; |
|---|
| 459 | UWORD tag,occ,cnt; |
|---|
| 460 | int itx,ity,itz,nwo,nwc; |
|---|
| 461 | FMT_CODX *fmtp; |
|---|
| 462 | UCHR word[LE2+LE2+LE2+1],*p,*q,*wp,*sp,c1,c2; |
|---|
| 463 | LINK1 *link1p; |
|---|
| 464 | LINK2 *link2p; |
|---|
| 465 | LONGX x1,x2; |
|---|
| 466 | char *fmtareap,*fmtap; |
|---|
| 467 | char *pfxp,*keyp,*hdrp; |
|---|
| 468 | int pfxl,n,wlen,isstw,ifst; |
|---|
| 469 | #if FST351 |
|---|
| 470 | int n351; |
|---|
| 471 | #endif |
|---|
| 472 | int error=0,hlen; |
|---|
| 473 | LONGX fmtrc,nbytes; |
|---|
| 474 | |
|---|
| 475 | #define ITMARKUP 1 |
|---|
| 476 | #if ITMARKUP |
|---|
| 477 | int itm; |
|---|
| 478 | char *itmp; |
|---|
| 479 | int itmn,itmx; |
|---|
| 480 | int itmalen,itmyplen,itmelen,itmstriplen,itmyok,itmymatch; |
|---|
| 481 | int itmfldleft,itmfldqleft; |
|---|
| 482 | char *itmyp,*itmfldp,*itmfldq; |
|---|
| 483 | #define MAXITMARKUPLEN 100 |
|---|
| 484 | char itmend[MAXITMARKUPLEN+1]; |
|---|
| 485 | char itmuc[MAXITMARKUPLEN+1]; |
|---|
| 486 | char *itmxp,*itmxq; |
|---|
| 487 | int itmxx; |
|---|
| 488 | #endif /* ITMARKUP */ |
|---|
| 489 | |
|---|
| 490 | #define STRIPMARKUP 1 |
|---|
| 491 | #if STRIPMARKUP /* STRIPMARKUP */ |
|---|
| 492 | char *smuenvp=NULL; |
|---|
| 493 | int smumaxlen=0; |
|---|
| 494 | int fldleft,qleft,striplen; |
|---|
| 495 | int xdir,erased,match; |
|---|
| 496 | char *fldp,*fldq; |
|---|
| 497 | #define STRIPMAXTAGS 16 |
|---|
| 498 | UWORD striptags[STRIPMAXTAGS+1]; |
|---|
| 499 | int nstrips=0; |
|---|
| 500 | LONGX ltag; |
|---|
| 501 | UWORD xtag; |
|---|
| 502 | int xloop,xxtag; |
|---|
| 503 | #endif |
|---|
| 504 | |
|---|
| 505 | #if FSTTRACE |
|---|
| 506 | printf("fst_inter - pgmp=%p irec=%ld area1=%p/%ld area2=%p/%ld\n", |
|---|
| 507 | pgmp,irec,*area1pp,max1,*area2pp,max2); |
|---|
| 508 | #endif |
|---|
| 509 | /* check fst */ |
|---|
| 510 | #if !CICPP |
|---|
| 511 | if (!qty1p) qty1p= &xqty1; |
|---|
| 512 | if (!qty2p) qty2p= &xqty2; |
|---|
| 513 | #endif /* CICPP */ |
|---|
| 514 | *qty1p=0L; |
|---|
| 515 | *qty2p=0L; |
|---|
| 516 | if (!pgmp) return(-1L); |
|---|
| 517 | #if CICPP |
|---|
| 518 | //recp must be set via setrecp (or mst is provided) |
|---|
| 519 | recp=fst_recp; |
|---|
| 520 | #else /* CICPP */ |
|---|
| 521 | /* check irec */ |
|---|
| 522 | if (!nrecs) fatal("fst_inter/nrecs"); |
|---|
| 523 | if (irec < 0 || irec >= maxnrec) fatal("fst_inter/irec"); |
|---|
| 524 | if ((recp=vrecp[irec]) == NULL) fatal("fst_inter/recp"); |
|---|
| 525 | #endif /* CICPP */ |
|---|
| 526 | #if USE_GDBFMT |
|---|
| 527 | if (recp) mfn=MFRmfn; /* recp is provided */ |
|---|
| 528 | else mfn=mst->getmfn(); |
|---|
| 529 | #else |
|---|
| 530 | if (RECtype != TYPEMFR) fatal("fst_inter/TYPEMFR"); |
|---|
| 531 | mfn=MFRmfn; |
|---|
| 532 | #endif |
|---|
| 533 | |
|---|
| 534 | #if STRIPMARKUP /* STRIPMARKUP */ |
|---|
| 535 | p=(unsigned char *)dbxcipar(NULL,"ci_fststrip",'='); |
|---|
| 536 | if (dbxcipok) smuenvp=(char *)p; |
|---|
| 537 | #if PC || UNIX |
|---|
| 538 | if (!smuenvp) |
|---|
| 539 | if ((smuenvp=getenv("CI_FSTSTRIP")) == NULL) |
|---|
| 540 | smuenvp=getenv("ci_fststrip"); |
|---|
| 541 | #endif |
|---|
| 542 | if (smuenvp) if (sscanf(smuenvp,"%d",&smumaxlen) != 1) fatal("fst_inter/CI_FSTSTRIP/maxlen"); |
|---|
| 543 | if (smumaxlen > 0) { /* strip <.smumaxlen> from data segment */ |
|---|
| 544 | /*... |
|---|
| 545 | UWORD striptags[STRIPMAXTAGS+1]; |
|---|
| 546 | ...*/ |
|---|
| 547 | nstrips=0; p=(unsigned char *)smuenvp; |
|---|
| 548 | while (isspace(*p)) p++; while (isdigit(*p)) p++; /* smumaxlen */ |
|---|
| 549 | while (isspace(*p)) p++; |
|---|
| 550 | while (*p++ == ',') { |
|---|
| 551 | while (isspace(*p)) p++; |
|---|
| 552 | for (ltag=0; isdigit(*p); ) { ltag=ltag*10+(*p-'0'); p++; } |
|---|
| 553 | if (ltag <= 0) fatal("fst_inter/CI_FSTSTRIP/tag"); |
|---|
| 554 | striptags[nstrips++]=(UWORD)ltag; |
|---|
| 555 | if (nstrips >= STRIPMAXTAGS) fatal("fst_inter/CI_FSTSTRIP/MAXTAGS"); |
|---|
| 556 | } |
|---|
| 557 | striptags[nstrips]=(UWORD)0; |
|---|
| 558 | /*...*/ |
|---|
| 559 | for (xdir=0; xdir < MFRnvf; xdir++) { |
|---|
| 560 | if (nstrips) { |
|---|
| 561 | xtag=DIRtag(xdir); |
|---|
| 562 | for (xxtag=0, xloop=0; striptags[xloop]; xloop++) |
|---|
| 563 | if (xtag == striptags[xloop]) { xxtag=1; break; } |
|---|
| 564 | if (!xxtag) continue; |
|---|
| 565 | } |
|---|
| 566 | fldp=FIELDP(xdir); |
|---|
| 567 | fldleft=DIRlen(xdir); |
|---|
| 568 | for (erased=0, p=(UCHR *)fldp; fldleft > 0; ) { |
|---|
| 569 | if (*fldp != '<') { |
|---|
| 570 | if (erased) *p = *fldp; p++; fldp++; fldleft--; continue; |
|---|
| 571 | } |
|---|
| 572 | for (striplen=1, match=0, fldq=fldp, qleft=fldleft; qleft > 0; ) { |
|---|
| 573 | if (striplen > smumaxlen) break; |
|---|
| 574 | if (*fldq == '>') { match=1; break; } |
|---|
| 575 | fldq++; qleft--; striplen++; continue; |
|---|
| 576 | } |
|---|
| 577 | if (!match) { |
|---|
| 578 | if (erased) *p = *fldp; p++; fldp++; fldleft--; continue; |
|---|
| 579 | } |
|---|
| 580 | /*...*/ |
|---|
| 581 | fldp+=striplen; fldleft-=striplen; erased+=striplen; |
|---|
| 582 | } |
|---|
| 583 | if (erased) memset(p,' ',erased); |
|---|
| 584 | } |
|---|
| 585 | } |
|---|
| 586 | #endif /* STRIPMARKUP */ |
|---|
| 587 | |
|---|
| 588 | |
|---|
| 589 | |
|---|
| 590 | |
|---|
| 591 | /* setup fst_batchp for links in fldupdat() format */ |
|---|
| 592 | if (fst_batchup) { |
|---|
| 593 | *fst_batchup='\0'; |
|---|
| 594 | fst_batchp=fst_batchup; |
|---|
| 595 | } |
|---|
| 596 | |
|---|
| 597 | /* alloc area for links */ |
|---|
| 598 | if (!fst_fd[0]) /* 21/11/94 */ |
|---|
| 599 | if (!*area1pp) { |
|---|
| 600 | nbytes=sizeof(LINK1)*max1; |
|---|
| 601 | if (nbytes > ALLOMAXV) fatal("fst_inter/max1"); |
|---|
| 602 | #if CICPP |
|---|
| 603 | try {*area1pp=new char [nbytes];} |
|---|
| 604 | catch(BAD_ALLOC) {*area1pp=(char *)ALLONULL;} |
|---|
| 605 | #else |
|---|
| 606 | *area1pp=(char *)ALLOC((ALLOPARM)nbytes); |
|---|
| 607 | #endif /* CICPP */ |
|---|
| 608 | if (*area1pp == (char *)ALLONULL) fatal("fst_inter/ALLOC/area1"); |
|---|
| 609 | } |
|---|
| 610 | if (!fst_fd[1]) /* 21/11/94 */ |
|---|
| 611 | if (!*area2pp) { |
|---|
| 612 | nbytes=sizeof(LINK2)*max2; |
|---|
| 613 | if (nbytes > ALLOMAXV) fatal("fst_inter/max2"); |
|---|
| 614 | #if CICPP |
|---|
| 615 | try { *area2pp=new char[nbytes];} |
|---|
| 616 | catch (BAD_ALLOC){ *area2pp=(char *)ALLONULL;} |
|---|
| 617 | #else |
|---|
| 618 | *area2pp=(char *)ALLOC((ALLOPARM)nbytes); |
|---|
| 619 | #endif /* CICPP */ |
|---|
| 620 | |
|---|
| 621 | if (*area2pp == (char *)ALLONULL) fatal("fst_inter/ALLOC/area2"); |
|---|
| 622 | } |
|---|
| 623 | /* alloc format area */ |
|---|
| 624 | if (fst_fmtby < MAXMFRL) |
|---|
| 625 | if (fsttrace) printf("+++ fst_fmtby=%ld\n",fst_fmtby); |
|---|
| 626 | fmtareap=fst_fmtap; |
|---|
| 627 | if (!fst_fmtap) { |
|---|
| 628 | nbytes=fst_fmtby; |
|---|
| 629 | if (nbytes > ALLOMAXV) fatal("fst_inter/fst_fmtby"); |
|---|
| 630 | #if SHOW |
|---|
| 631 | if (fsttrace) showcore("+++ fstareap"); |
|---|
| 632 | #endif |
|---|
| 633 | #if CICPP |
|---|
| 634 | try {fmtareap=new char [nbytes];} |
|---|
| 635 | catch (BAD_ALLOC){ fmtareap=(char *)ALLONULL;} |
|---|
| 636 | #else |
|---|
| 637 | fmtareap=(char *)ALLOC((ALLOPARM)nbytes); |
|---|
| 638 | #endif /* CICPP */ |
|---|
| 639 | if (fmtareap == (char *)ALLONULL) fatal("fst_inter/ALLOC/fmtarea"); |
|---|
| 640 | } |
|---|
| 641 | /* setup link1/link2 */ |
|---|
| 642 | if (!fst_fd[0]) /* 21/11/94 */ |
|---|
| 643 | link1p=(LINK1 *)*area1pp; |
|---|
| 644 | x1=max1; |
|---|
| 645 | if (!fst_fd[1]) /* 21/11/94 */ |
|---|
| 646 | link2p=(LINK2 *)*area2pp; |
|---|
| 647 | x2=max2; |
|---|
| 648 | /* check stwp */ |
|---|
| 649 | if (!stwp) stwp=""; |
|---|
| 650 | |
|---|
| 651 | fst_hdru=0; /* 05/10/95 */ |
|---|
| 652 | if (fst_hdrp) *fst_hdrp='\0'; |
|---|
| 653 | |
|---|
| 654 | /* format and process each fst entry */ |
|---|
| 655 | /* new */ |
|---|
| 656 | for (ifst=1; pgmp; pgmp=pgmp->nextp, ifst++) { |
|---|
| 657 | tag=pgmp->tag; |
|---|
| 658 | itx=pgmp->it; |
|---|
| 659 | ity=itz=0; |
|---|
| 660 | #if ITMARKUP |
|---|
| 661 | itm=0; |
|---|
| 662 | if (itx >= 2000) {itx-=2000; itm=1;} |
|---|
| 663 | #endif /* ITMARKUP */ |
|---|
| 664 | if (itx >= 1000) {itx-=1000; itz=1;} |
|---|
| 665 | if (itx == 351) itx=351; |
|---|
| 666 | else { |
|---|
| 667 | if (itx < 0 || itx > 8) /*fatal("fst_inter/it");*/ {error=1; break;} |
|---|
| 668 | if (itx > 4) {itx-=4; ity=1;} |
|---|
| 669 | } |
|---|
| 670 | /* format */ |
|---|
| 671 | fmtp=pgmp->fmtp; |
|---|
| 672 | *fmtareap='\0'; |
|---|
| 673 | #if USE_GDBFMT |
|---|
| 674 | //#if BEFORE950113 |
|---|
| 675 | // char * recbuf=mst->getrecbuf(); |
|---|
| 676 | //#else |
|---|
| 677 | // char * recbuf=recp->recmfp->mx; // MFX |
|---|
| 678 | //#endif |
|---|
| 679 | char *recbuf; |
|---|
| 680 | if (recp) recbuf=MFX; |
|---|
| 681 | else recbuf=mst->getrecbuf(); |
|---|
| 682 | |
|---|
| 683 | // .. if (mst->getrec(mfn,&recbuf)!=0) |
|---|
| 684 | FORMAT *f = new FORMAT(cisisxp, mst,btree,1); // ascii_output |
|---|
| 685 | fmtrc = - f->Format(fmtp, /* format */ /* HB 06/10/99 */ |
|---|
| 686 | recbuf, // char *rec, /* MF record */ |
|---|
| 687 | fmtareap, // char *wka, /* format work area */ |
|---|
| 688 | fst_fmtby); // LONGX la, /* length of work area */ |
|---|
| 689 | delete f; |
|---|
| 690 | /* fmtrc=0;*/ /* HB 06/10/99 */ |
|---|
| 691 | #else /* USE_GDBFMT */ |
|---|
| 692 | #if CICPP |
|---|
| 693 | fmtrc=((FMTSTRU *)fmtp)->xfmt_inter(recp,fst_fmtby,fmtareap,fst_fmtby); |
|---|
| 694 | #else |
|---|
| 695 | fmtrc=fmt_inter(fmtp,irec,fst_fmtby,fmtareap,fst_fmtby); |
|---|
| 696 | #endif /* CICPP */ |
|---|
| 697 | #endif /* USE_GDBFMT */ |
|---|
| 698 | |
|---|
| 699 | if (fsttrace) |
|---|
| 700 | printf("+++ fst %d = %ld %d+%d\n+++ fmt=%ld\n%s.\n", |
|---|
| 701 | ifst,(LONGX)tag,itx,ity,fmtrc,fmtareap); |
|---|
| 702 | if (fmtrc < 0) /*fatal("fst_inter/fmtrc");*/ {error=2; break;} |
|---|
| 703 | |
|---|
| 704 | #if BEFORE20000831 |
|---|
| 705 | #else |
|---|
| 706 | #if USE_GDBFMT |
|---|
| 707 | #else |
|---|
| 708 | mfn=MFRmfn; |
|---|
| 709 | #endif |
|---|
| 710 | #endif |
|---|
| 711 | |
|---|
| 712 | fmtap=fmtareap; pfxp=""; pfxl=0; |
|---|
| 713 | #if ITMARKUP |
|---|
| 714 | itmp=""; itmn=0; |
|---|
| 715 | #endif /* ITMARKUP */ |
|---|
| 716 | if (itm) |
|---|
| 717 | if (*(p=(UCHR *)fmtap) != '\0') |
|---|
| 718 | if (*(p+1)) |
|---|
| 719 | for (c1= *p++; *p; p++) |
|---|
| 720 | if (*p == c1) { |
|---|
| 721 | fmtap++; *p='\0'; |
|---|
| 722 | for (itmn=1, itmp=fmtap; *fmtap++; ) |
|---|
| 723 | if (*fmtap == ',') { fmtap='\0'; itmn++; } |
|---|
| 724 | else *fmtap=isisuctab[*fmtap]; |
|---|
| 725 | fmtap=(char *)(p+1); |
|---|
| 726 | break; |
|---|
| 727 | } |
|---|
| 728 | if (*itmp) { |
|---|
| 729 | itmfldp=fmtap; itmfldleft=strlen(fmtap); itmalen=0; |
|---|
| 730 | for (; itmfldleft > 0; ) { |
|---|
| 731 | if (*itmfldp != '<') { itmfldp++; itmfldleft--; continue; } |
|---|
| 732 | for (itmyok=0, itmyp=itmp, itmx=itmn; itmx--; itmyp+=(itmyplen+1)) { |
|---|
| 733 | itmyplen=strlen(itmyp); |
|---|
| 734 | if (itmyplen >= MAXITMARKUPLEN) { itmfldp++; itmfldleft--; continue; } /* return fatal error */ |
|---|
| 735 | for (itmxq=itmuc, itmxp=itmfldp, itmxx=itmyplen; itmxx--; ) |
|---|
| 736 | *itmxq++=isisuctab[*itmxp++]; |
|---|
| 737 | *itmxq='\0'; |
|---|
| 738 | if (strncmp(itmuc,itmyp,itmyplen) == 0) { itmyok=1; break; } |
|---|
| 739 | } |
|---|
| 740 | if (!itmyok) { itmfldp++; itmfldleft--; continue; } |
|---|
| 741 | if (itmyplen+1 >= MAXITMARKUPLEN) { itmfldp++; itmfldleft--; continue; } /* return fatal error */ |
|---|
| 742 | itmend[0]='<'; itmend[1]='/'; memcpy(itmend+2,itmyp+1,itmyplen-1); |
|---|
| 743 | itmend[itmelen=itmyplen+1]='\0'; |
|---|
| 744 | if (itmend[itmelen-1] == ' ') { |
|---|
| 745 | itmend[itmelen-1]='>'; /* permite <XX> ou <XXb - AOT, 25/09/2002 */ |
|---|
| 746 | /* .. falta saltar os atributos */ |
|---|
| 747 | } |
|---|
| 748 | itmymatch=0, itmstriplen=0; |
|---|
| 749 | for (itmfldq=itmfldp+itmyplen, itmfldqleft=itmfldleft-itmyplen; itmfldqleft > 0; ) { |
|---|
| 750 | if (*itmfldq != '>') { itmfldq++; itmfldqleft--; continue; } |
|---|
| 751 | if (itmelen >= MAXITMARKUPLEN) { itmfldq++; itmfldqleft--; continue; } /* return fatal error */ |
|---|
| 752 | if (itmfldleft-itmfldqleft >= itmelen) { |
|---|
| 753 | for (itmxq=itmuc, itmxp=itmfldq-itmelen+1, itmxx=itmelen; itmxx--; ) |
|---|
| 754 | *itmxq++=isisuctab[*itmxp++]; |
|---|
| 755 | if (strncmp(itmuc,itmend,itmelen) == 0) |
|---|
| 756 | { itmymatch=1; break; } |
|---|
| 757 | } |
|---|
| 758 | itmfldq++; itmfldqleft--; |
|---|
| 759 | } |
|---|
| 760 | if (itmymatch) { |
|---|
| 761 | itmfldq++; itmfldqleft--; |
|---|
| 762 | itmstriplen=itmfldleft-itmfldqleft-itmyplen-itmelen; |
|---|
| 763 | memcpy(fmtap+itmalen,itmfldp+itmyplen,itmstriplen); /* for */ |
|---|
| 764 | itmalen+=itmstriplen; |
|---|
| 765 | itmfldp=itmfldq+1; itmfldleft-=(itmyplen+itmstriplen+itmelen); |
|---|
| 766 | } |
|---|
| 767 | else { itmfldp++; itmfldleft--; } |
|---|
| 768 | } |
|---|
| 769 | fmtap[itmalen]='\0'; |
|---|
| 770 | } |
|---|
| 771 | if (itz) |
|---|
| 772 | if (*(p=(UCHR *)fmtap) != '\0') |
|---|
| 773 | if (*(p+1)) |
|---|
| 774 | for (c1= *p++; *p; p++) |
|---|
| 775 | if (*p == c1) { |
|---|
| 776 | fmtap++; *p='\0'; |
|---|
| 777 | sscanf(fmtap,"%ld",&mfn); |
|---|
| 778 | fmtap=(char *)(p+1); |
|---|
| 779 | break; |
|---|
| 780 | } |
|---|
| 781 | if (ity) |
|---|
| 782 | if (*(p=(UCHR *)fmtap) != '\0') |
|---|
| 783 | if (*(p+1)) |
|---|
| 784 | for (c1= *p++; *p; p++) |
|---|
| 785 | if (*p == c1) { |
|---|
| 786 | pfxp=fmtap+1; *p='\0'; |
|---|
| 787 | fmtap=(char *)(p+1); |
|---|
| 788 | for (p=(UCHR *)pfxp; *p; p++, pfxl++) |
|---|
| 789 | if (*p == '\r' || *p == '\n') { |
|---|
| 790 | *p='\0'; break; |
|---|
| 791 | } |
|---|
| 792 | if (!pfxl) pfxp=""; |
|---|
| 793 | break; |
|---|
| 794 | } |
|---|
| 795 | for (nwo=nwc=0, occ=cnt=1, p=(UCHR *)(keyp=fmtap); *keyp; ) { |
|---|
| 796 | if (*p == fst_rdlm) {nwo=1; *p='\n';} |
|---|
| 797 | if (itx == 351) if (*p == ';') {nwo=1; *p='\n';} /* ENTRY_DLM ? */ |
|---|
| 798 | if (*p != '\r') if (*p != '\n') if (*p) {p++; continue;} |
|---|
| 799 | while (*p == '\r' || *p == '\n') *p++='\0'; |
|---|
| 800 | #if FSSTRACE |
|---|
| 801 | if (fsttrace) printf("+++ keyp=%s\n",keyp); |
|---|
| 802 | #endif |
|---|
| 803 | switch (itx) { |
|---|
| 804 | |
|---|
| 805 | case 0: |
|---|
| 806 | if (*keyp) { |
|---|
| 807 | n=fst_link(pfxp,pfxl,keyp,strlen(keyp),mfn,tag,occ,cnt, |
|---|
| 808 | (char *)link1p,(char *)link2p,&x1,&x2); |
|---|
| 809 | if (n < 0) return(n); |
|---|
| 810 | if (n) if (n <= LE1) link1p++; else link2p++; |
|---|
| 811 | cnt++; |
|---|
| 812 | } |
|---|
| 813 | break; |
|---|
| 814 | |
|---|
| 815 | case 1: |
|---|
| 816 | if (*keyp == SFLDCHR) if (*++keyp) keyp++; |
|---|
| 817 | for (q=(UCHR *)keyp; ; ) { |
|---|
| 818 | nwc=0; |
|---|
| 819 | hlen=0; hdrp=(char *)q; |
|---|
| 820 | while (*q) { |
|---|
| 821 | if (*q == SFLDCHR) {nwc=1; if (*++q) q++; break;} |
|---|
| 822 | hlen++; q++; |
|---|
| 823 | } |
|---|
| 824 | if (hlen == 0) { |
|---|
| 825 | if (nwc) cnt++; |
|---|
| 826 | if (*q) continue; else break; |
|---|
| 827 | } |
|---|
| 828 | #if FSSTRACE |
|---|
| 829 | if (fsttrace) { |
|---|
| 830 | printf("+++ %d:%d,%d=",itx,occ,cnt); |
|---|
| 831 | for (n=0; n < hlen; n++) printf("%c",hdrp[n]); |
|---|
| 832 | printf("\n"); |
|---|
| 833 | } |
|---|
| 834 | #endif |
|---|
| 835 | n=fst_link(pfxp,pfxl,hdrp,hlen,mfn,tag,occ,cnt, |
|---|
| 836 | (char *)link1p,(char *)link2p,&x1,&x2); |
|---|
| 837 | if (n < 0) return(n); |
|---|
| 838 | if (n) if (n <= LE1) link1p++; else link2p++; |
|---|
| 839 | cnt++; if (!*q) break; |
|---|
| 840 | } |
|---|
| 841 | break; |
|---|
| 842 | |
|---|
| 843 | case 2: |
|---|
| 844 | c1='<'; c2='>'; |
|---|
| 845 | case 3: |
|---|
| 846 | if (itx == 3) c1=c2='/'; |
|---|
| 847 | for (q=(UCHR *)keyp; ; ) { |
|---|
| 848 | nwc=0; |
|---|
| 849 | hlen=0; |
|---|
| 850 | while (*q != c1) if (*q) q++; else break; |
|---|
| 851 | if (*q == c1) { |
|---|
| 852 | #if FST2TAGS |
|---|
| 853 | tagop=strstr(q,"<I>"); |
|---|
| 854 | if (tagop) { |
|---|
| 855 | |
|---|
| 856 | } |
|---|
| 857 | #endif /* FST2TAGS */ |
|---|
| 858 | hdrp=(char *)(q+1); |
|---|
| 859 | for (nwc=1; *++q; ) |
|---|
| 860 | if (*q == c2) { |
|---|
| 861 | #if FST2TAGS |
|---|
| 862 | . |
|---|
| 863 | #endif /* FST2TAGS */ |
|---|
| 864 | q++; break; |
|---|
| 865 | } |
|---|
| 866 | else hlen++; |
|---|
| 867 | } |
|---|
| 868 | if (hlen == 0) { |
|---|
| 869 | if (nwc) cnt++; |
|---|
| 870 | if (*q) continue; else break; |
|---|
| 871 | } |
|---|
| 872 | #if FSSTRACE |
|---|
| 873 | if (fsttrace) { |
|---|
| 874 | printf("+++ %d:%d,%d=",itx,occ,cnt); |
|---|
| 875 | for (n=0; n < hlen; n++) printf("%c",hdrp[n]); |
|---|
| 876 | printf("\n"); |
|---|
| 877 | } |
|---|
| 878 | #endif |
|---|
| 879 | n=fst_link(pfxp,pfxl,hdrp,hlen,mfn,tag,occ,cnt, |
|---|
| 880 | (char *)link1p,(char *)link2p,&x1,&x2); |
|---|
| 881 | if (n < 0) return(n); |
|---|
| 882 | if (n) if (n <= LE1) link1p++; else link2p++; |
|---|
| 883 | cnt++; if (!*q) break; |
|---|
| 884 | } |
|---|
| 885 | break; |
|---|
| 886 | |
|---|
| 887 | case 4: |
|---|
| 888 | for (q=(UCHR *)keyp, wlen=0; ; ) { |
|---|
| 889 | hdrp=(char *)q; hlen=0; |
|---|
| 890 | while (isiswctab[*q]) { |
|---|
| 891 | if (wlen < sizeof(word)) word[wlen++] = *q; |
|---|
| 892 | hlen++; |
|---|
| 893 | if (!*++q) break; |
|---|
| 894 | } |
|---|
| 895 | while (!isiswctab[*q]) if (*q) q++; else break; |
|---|
| 896 | if (wlen == 0) if (*q) continue; else break; |
|---|
| 897 | word[wlen] = '\0'; |
|---|
| 898 | #if FSSTRACE |
|---|
| 899 | if (fsttrace) { |
|---|
| 900 | printf("+++ %d:%d,%d=%s=",itx,occ,cnt,word); |
|---|
| 901 | for (n=0; n < hlen; n++) printf("%c",hdrp[n]); |
|---|
| 902 | printf("\n"); |
|---|
| 903 | } |
|---|
| 904 | #endif |
|---|
| 905 | for (wp=word; *wp; wp++) *wp = isisuctab[*wp]; |
|---|
| 906 | isstw=0; |
|---|
| 907 | if (wlen <= LE1) { |
|---|
| 908 | #ifdef CI_WINISIS |
|---|
| 909 | for (sp=stwp; *sp; sp+=(LE1+1)*2) { |
|---|
| 910 | n=memcmp(sp,word,wlen+1); |
|---|
| 911 | if (n > 0) { |
|---|
| 912 | if (memcmp(sp-(LE1+1),word,wlen+1)==0) |
|---|
| 913 | isstw=1; |
|---|
| 914 | break; |
|---|
| 915 | } |
|---|
| 916 | if (n < 0) continue; |
|---|
| 917 | isstw=1; break; |
|---|
| 918 | } |
|---|
| 919 | #else |
|---|
| 920 | for (sp=(UCHR *)stwp; *sp; sp+=LE1+1) { |
|---|
| 921 | n=memcmp(sp,word,wlen+1); |
|---|
| 922 | if (n > 0) break; |
|---|
| 923 | if (n < 0) continue; |
|---|
| 924 | isstw=1; break; |
|---|
| 925 | } |
|---|
| 926 | #endif /* CI_WINISIS */ |
|---|
| 927 | } |
|---|
| 928 | |
|---|
| 929 | #if BEFORE20030113 |
|---|
| 930 | #else |
|---|
| 931 | if (fst_wlupifnp) { |
|---|
| 932 | if (!fst_wluptrmp) { |
|---|
| 933 | #if CICPP |
|---|
| 934 | try { fst_wluptrmp=new TRMSTRU(cisisxp); } |
|---|
| 935 | catch (BAD_ALLOC) { fatal("cifst/lup_trm/next"); } |
|---|
| 936 | fst_wluptrmp->xtrmalloc(0L); |
|---|
| 937 | fst_wluptrmp->xterm((unsigned char *)fst_wlupifnp,(unsigned char *)"!"); |
|---|
| 938 | #else /* CICPP */ |
|---|
| 939 | for (fst_wlupitrm=maxntrm; fst_wlupitrm--; ){ |
|---|
| 940 | if (!vtrmp[fst_wlupitrm]) /* ja' decrementado */ |
|---|
| 941 | break; |
|---|
| 942 | } |
|---|
| 943 | if (!fst_wlupitrm) fatal("cifst/lup_trm/next"); |
|---|
| 944 | trmalloc(fst_wlupitrm,0L); |
|---|
| 945 | term(fst_wlupitrm,fst_wlupifnp,"!"); |
|---|
| 946 | fst_wluptrmp=vtrmp[fst_wlupitrm]; |
|---|
| 947 | #endif /* CICPP */ |
|---|
| 948 | } |
|---|
| 949 | #if CICPP |
|---|
| 950 | fst_wluptrmp->xterm((unsigned char *)fst_wlupifnp,word); |
|---|
| 951 | #else /* CICPP */ |
|---|
| 952 | term(fst_wlupitrm,fst_wlupifnp,word); |
|---|
| 953 | #endif /* CICPP */ |
|---|
| 954 | if (fst_wluptrmp->trmrc == RCNORMAL) isstw=1; /* force */ |
|---|
| 955 | } |
|---|
| 956 | #endif |
|---|
| 957 | if (!isstw) { |
|---|
| 958 | n=fst_link(pfxp,pfxl,hdrp,hlen,mfn,tag,occ,cnt, |
|---|
| 959 | (char *)link1p,(char *)link2p,&x1,&x2); |
|---|
| 960 | if (n < 0) return(n); |
|---|
| 961 | if (n) if (n <= LE1) link1p++; else link2p++; |
|---|
| 962 | } |
|---|
| 963 | cnt++; wlen=0; if (!*q) break; |
|---|
| 964 | } |
|---|
| 965 | break; |
|---|
| 966 | |
|---|
| 967 | #if FST351 |
|---|
| 968 | case 351: |
|---|
| 969 | for (; *keyp == ' '; ) keyp++; |
|---|
| 970 | q=keyp; |
|---|
| 971 | pfxp=q; pfxl=0; |
|---|
| 972 | for (; *q && *q != '/'; q++) { |
|---|
| 973 | *q=isisuctab[(UCHR)*q]; if (pfxl < LE2) pfxl++; |
|---|
| 974 | } |
|---|
| 975 | for (; pfxl; ) { |
|---|
| 976 | n351=nwc=wlen=0; fst_a351='\0'; |
|---|
| 977 | if (*q == '/') { |
|---|
| 978 | word[wlen++]='/'; |
|---|
| 979 | if (*++q == '*') { |
|---|
| 980 | fst_a351='.'; q++; if (*q == '/') n351=1; |
|---|
| 981 | /* printf("+++ n351=%d\n",n351); */ |
|---|
| 982 | } |
|---|
| 983 | } |
|---|
| 984 | for (; *q && *q != '/'; q++) |
|---|
| 985 | if (wlen < sizeof(word)) word[wlen++] = *q; |
|---|
| 986 | if (wlen == 1) wlen=0; |
|---|
| 987 | if (!wlen) if (!pfxl) break; |
|---|
| 988 | word[wlen] = '\0'; |
|---|
| 989 | pfxp[pfxl] = '\0'; |
|---|
| 990 | #if FSSTRACE |
|---|
| 991 | if (fsttrace) printf("+++ %d:%d,%d=%c,%s(%d),%s(%d)\n", |
|---|
| 992 | itx,occ,cnt,fst_a351,pfxp,pfxl,word,wlen); |
|---|
| 993 | #endif |
|---|
| 994 | n=fst_link(pfxp,-pfxl,"",0,mfn,tag,occ,cnt, |
|---|
| 995 | (char *)link1p,(char *)link2p,&x1,&x2); |
|---|
| 996 | if (n < 0) return(n); |
|---|
| 997 | if (n) if (n <= LE1) link1p++; else link2p++; |
|---|
| 998 | n=fst_link(pfxp,-pfxl,(wlen)?(char *)word:"/", |
|---|
| 999 | 0,mfn,tag,occ,cnt, |
|---|
| 1000 | (char *)link1p,(char *)link2p,&x1,&x2); |
|---|
| 1001 | if (n < 0) return(n); |
|---|
| 1002 | if (n) if (n <= LE1) link1p++; else link2p++; |
|---|
| 1003 | if (wlen) { |
|---|
| 1004 | n=fst_link("",0,word,0,mfn,tag,occ,cnt, |
|---|
| 1005 | (char *)link1p,(char *)link2p,&x1,&x2); |
|---|
| 1006 | if (n < 0) return(n); |
|---|
| 1007 | if (n) if (n <= LE1) link1p++; else link2p++; |
|---|
| 1008 | } |
|---|
| 1009 | if (fst_a351) { |
|---|
| 1010 | fst_a351='\0'; |
|---|
| 1011 | n=fst_link(pfxp,-pfxl,"",0,mfn,tag,occ,cnt, |
|---|
| 1012 | (char *)link1p,(char *)link2p,&x1,&x2); |
|---|
| 1013 | if (n < 0) return(n); |
|---|
| 1014 | if (n) if (n <= LE1) link1p++; else link2p++; |
|---|
| 1015 | n=fst_link(pfxp,-pfxl,(wlen)?(char *)word:"/", |
|---|
| 1016 | 0,mfn,tag,occ,cnt, |
|---|
| 1017 | (char *)link1p,(char *)link2p,&x1,&x2); |
|---|
| 1018 | if (n < 0) return(n); |
|---|
| 1019 | if (n) if (n <= LE1) link1p++; else link2p++; |
|---|
| 1020 | if (wlen) { |
|---|
| 1021 | n=fst_link("",0,word,0,mfn,tag,occ,cnt, |
|---|
| 1022 | (char *)link1p,(char *)link2p,&x1,&x2); |
|---|
| 1023 | if (n < 0) return(n); |
|---|
| 1024 | if (n) if (n <= LE1) link1p++; else link2p++; |
|---|
| 1025 | } |
|---|
| 1026 | fst_a351='.'; |
|---|
| 1027 | } |
|---|
| 1028 | if (n351) continue; |
|---|
| 1029 | cnt++; if (!*q) break; |
|---|
| 1030 | if (wlen == 0) { |
|---|
| 1031 | if (nwc) cnt++; |
|---|
| 1032 | if (*q) continue; else break; |
|---|
| 1033 | } |
|---|
| 1034 | } /* end for pfxl */ |
|---|
| 1035 | break; |
|---|
| 1036 | #endif /* FST351 */ |
|---|
| 1037 | |
|---|
| 1038 | } /* end of switch itx */ |
|---|
| 1039 | |
|---|
| 1040 | if (nwo) {occ++; cnt=1;} |
|---|
| 1041 | nwo=0; |
|---|
| 1042 | keyp=(char *)p; |
|---|
| 1043 | |
|---|
| 1044 | } /* end of for fmtap */ |
|---|
| 1045 | |
|---|
| 1046 | } /* end of for pgmp */ |
|---|
| 1047 | |
|---|
| 1048 | /* release local format area */ |
|---|
| 1049 | if (!fst_fmtap) |
|---|
| 1050 | #if CICPP |
|---|
| 1051 | delete [] fmtareap; |
|---|
| 1052 | #else |
|---|
| 1053 | FREE(fmtareap); |
|---|
| 1054 | #endif /* CICPP */ |
|---|
| 1055 | |
|---|
| 1056 | /* update qty1/qty2 and return to caller */ |
|---|
| 1057 | *qty1p = max1 - x1; |
|---|
| 1058 | *qty2p = max2 - x2; |
|---|
| 1059 | |
|---|
| 1060 | if (error) return(-2); |
|---|
| 1061 | |
|---|
| 1062 | return( *qty1p + *qty2p ); |
|---|
| 1063 | } |
|---|
| 1064 | |
|---|
| 1065 | |
|---|
| 1066 | #if CICPP |
|---|
| 1067 | int FSTSTRU :: xfst_link(char *pfxp, |
|---|
| 1068 | int plen, |
|---|
| 1069 | char *keyp, |
|---|
| 1070 | int klen, |
|---|
| 1071 | LONGX mfn, |
|---|
| 1072 | UWORD tag, |
|---|
| 1073 | UWORD occ, |
|---|
| 1074 | UWORD cnt, |
|---|
| 1075 | char *lk1p, |
|---|
| 1076 | char *lk2p, |
|---|
| 1077 | LONGX *lft1, |
|---|
| 1078 | LONGX *lft2) |
|---|
| 1079 | #else |
|---|
| 1080 | int fst_link(pfxp,plen,keyp,klen,mfn,tag,occ,cnt,lk1p,lk2p,lft1,lft2) /* |
|---|
| 1081 | ------------ |
|---|
| 1082 | monta chave (em upper case se len > 0); |
|---|
| 1083 | monta posting; |
|---|
| 1084 | mantem left (lft1/lft2); |
|---|
| 1085 | se fst_fdx, chama fst_writ e retorna; |
|---|
| 1086 | move posting (para link1/link2); |
|---|
| 1087 | retorna 0 ou tamanho da chave |
|---|
| 1088 | */ |
|---|
| 1089 | char *pfxp; |
|---|
| 1090 | int plen; |
|---|
| 1091 | char *keyp; |
|---|
| 1092 | int klen; |
|---|
| 1093 | LONGX mfn; |
|---|
| 1094 | UWORD tag; |
|---|
| 1095 | UWORD occ; |
|---|
| 1096 | UWORD cnt; |
|---|
| 1097 | char *lk1p; |
|---|
| 1098 | char *lk2p; |
|---|
| 1099 | LONGX *lft1; |
|---|
| 1100 | LONGX *lft2; |
|---|
| 1101 | #endif /* CICPP */ |
|---|
| 1102 | { |
|---|
| 1103 | LINK1 *link1p; |
|---|
| 1104 | LINK2 *link2p; |
|---|
| 1105 | #ifdef CI_WINISIS |
|---|
| 1106 | UCHR *p,*line,*a351,*bpfx,*bkey; |
|---|
| 1107 | #else |
|---|
| 1108 | UCHR line[LE2+1],a351[LE2+1],*p,bpfx[LE2+1],bkey[LE2+1]; |
|---|
| 1109 | #endif |
|---|
| 1110 | int len,n,bplen,bklen,left,plen0,klen0; |
|---|
| 1111 | int xrc; |
|---|
| 1112 | |
|---|
| 1113 | #ifdef CI_WINISIS |
|---|
| 1114 | #define LE2X (LE2*(*lft2)) |
|---|
| 1115 | try { line=(UCHR *)new UCHR[LE2X];} |
|---|
| 1116 | catch (BAD_ALLOC){line=(UCHR *)ALLONULL;} |
|---|
| 1117 | try { a351=(UCHR *)new UCHR[LE2X];} |
|---|
| 1118 | catch (BAD_ALLOC){a351=(UCHR *)ALLONULL;} |
|---|
| 1119 | try { bpfx=(UCHR *)new UCHR[LE2X];} |
|---|
| 1120 | catch (BAD_ALLOC){bpfx=(UCHR *)ALLONULL;} |
|---|
| 1121 | try { bkey=(UCHR *)new UCHR[LE2X];} |
|---|
| 1122 | catch (BAD_ALLOC){bkey=(UCHR *)ALLONULL;} |
|---|
| 1123 | #else |
|---|
| 1124 | #define LE2X LE2 |
|---|
| 1125 | #endif |
|---|
| 1126 | |
|---|
| 1127 | plen0=plen; plen=abs(plen); |
|---|
| 1128 | klen0=klen; klen=abs(klen); |
|---|
| 1129 | |
|---|
| 1130 | /* store as heading */ |
|---|
| 1131 | if (fst_hdrp) { /* 05/10/95 */ |
|---|
| 1132 | p=(unsigned char *)fst_hdrp+fst_hdru; |
|---|
| 1133 | left=fst_hdrx-fst_hdru; if (left < 2) return(-1); |
|---|
| 1134 | bplen=bobkey(pfxp,plen,(char *)p,left-2,1,1,0); |
|---|
| 1135 | fst_hdru+=bplen; |
|---|
| 1136 | left-=bplen; if (left < 2) { *p='\0'; return(-2); } |
|---|
| 1137 | p+=bplen; |
|---|
| 1138 | bklen=bobkey((char *)keyp,klen,(char *)p,left-2,1,1,1); |
|---|
| 1139 | fst_hdru+=bklen; |
|---|
| 1140 | left-=bklen; |
|---|
| 1141 | p+=bklen; |
|---|
| 1142 | if (fst_hdrt) { |
|---|
| 1143 | sprintf((char *)line,"^m%ld^t%u^o%u^c%u",mfn,tag,occ,cnt); |
|---|
| 1144 | if (left > (len=strlen((char *)line))) { |
|---|
| 1145 | memcpy(p,line,len); p+=len; fst_hdru+=len; |
|---|
| 1146 | } |
|---|
| 1147 | } |
|---|
| 1148 | *p++='\n'; *p='\0'; |
|---|
| 1149 | fst_hdru+=1; |
|---|
| 1150 | #ifdef CI_WINISIS |
|---|
| 1151 | if (line) delete [] line; |
|---|
| 1152 | if (a351) delete [] a351; |
|---|
| 1153 | if (bpfx) delete [] bpfx; |
|---|
| 1154 | if (bkey) delete [] bkey; |
|---|
| 1155 | #endif |
|---|
| 1156 | return(0); |
|---|
| 1157 | } |
|---|
| 1158 | |
|---|
| 1159 | /* setup pfx+key for regular fst */ |
|---|
| 1160 | bklen=bobkey((char *)keyp,klen,(char *)bkey,LE2X,1,1,1); |
|---|
| 1161 | |
|---|
| 1162 | if (fst_a351) { |
|---|
| 1163 | a351[0]=fst_a351; |
|---|
| 1164 | memcpy(a351+1,pfxp,(plen+1 > LE2X) ? LE2X-1 : plen); |
|---|
| 1165 | pfxp=(char *)a351; plen++; |
|---|
| 1166 | } |
|---|
| 1167 | |
|---|
| 1168 | bplen=bobkey((char *)pfxp,plen,(char *)bpfx,LE2X,1,1,0); |
|---|
| 1169 | |
|---|
| 1170 | #ifdef CI_WINISIS |
|---|
| 1171 | if (plen0 <= 0 || LE2X > LE2) { |
|---|
| 1172 | #else |
|---|
| 1173 | if (plen0 <= 0) { |
|---|
| 1174 | #endif |
|---|
| 1175 | len=bplen; |
|---|
| 1176 | memcpy(line,bpfx,len); p=line+len; |
|---|
| 1177 | } |
|---|
| 1178 | else |
|---|
| 1179 | for (p=line, len=bplen, n=0; n < bplen; n++) |
|---|
| 1180 | *p++ = isisuctab[bpfx[n]]; |
|---|
| 1181 | |
|---|
| 1182 | #ifdef CI_WINISIS |
|---|
| 1183 | if (klen0 <= 0 || *lft2==(MAXMFRL/LE2)) { // poor solution |
|---|
| 1184 | #else |
|---|
| 1185 | if (klen0 <= 0) { |
|---|
| 1186 | #endif |
|---|
| 1187 | n=(len+bklen > LE2X) ? LE2X-len : bklen; |
|---|
| 1188 | memcpy(p,bkey,n); p+=n; len+=n; |
|---|
| 1189 | } |
|---|
| 1190 | else |
|---|
| 1191 | for (n=0; n < bklen; n++, len++) |
|---|
| 1192 | if (len < LE2X) *p++ = isisuctab[bkey[n]]; else break; |
|---|
| 1193 | |
|---|
| 1194 | line[len]='\0'; |
|---|
| 1195 | |
|---|
| 1196 | #if FSSTRACE |
|---|
| 1197 | if (fsttrace) printf("+++ %s=%s[%d]%s[%d]\n",line,bpfx,bplen,bkey,bklen); |
|---|
| 1198 | #endif |
|---|
| 1199 | |
|---|
| 1200 | if (!len) { |
|---|
| 1201 | #if FSTTRACE |
|---|
| 1202 | #ifndef USE_ERROR_SYS |
|---|
| 1203 | printf("REJECTED LINK: %ld/%d/%d/%d %c%s%c\n", |
|---|
| 1204 | mfn,tag,occ,cnt,OPENFCHR,line,CLOSFCHR); |
|---|
| 1205 | #endif |
|---|
| 1206 | #endif /* FSTTRACE */ |
|---|
| 1207 | #ifdef CI_WINISIS |
|---|
| 1208 | if (line) delete [] line; |
|---|
| 1209 | if (a351) delete [] a351; |
|---|
| 1210 | if (bpfx) delete [] bpfx; |
|---|
| 1211 | if (bkey) delete [] bkey; |
|---|
| 1212 | #endif |
|---|
| 1213 | return(0); |
|---|
| 1214 | } |
|---|
| 1215 | |
|---|
| 1216 | /* write a link record */ |
|---|
| 1217 | if (len <= LE1) { |
|---|
| 1218 | if (fst_fd[0] > 0) { |
|---|
| 1219 | if ((xrc=fst_writ(0,mfn,tag,occ,cnt,(char *)line,len,NULL)) < 0) |
|---|
| 1220 | return(10+xrc); |
|---|
| 1221 | #ifdef CI_WINISIS |
|---|
| 1222 | if (line) delete [] line; |
|---|
| 1223 | if (a351) delete [] a351; |
|---|
| 1224 | if (bpfx) delete [] bpfx; |
|---|
| 1225 | if (bkey) delete [] bkey; |
|---|
| 1226 | #endif |
|---|
| 1227 | return(0); |
|---|
| 1228 | } |
|---|
| 1229 | } |
|---|
| 1230 | else { |
|---|
| 1231 | if (fst_fd[1] > 0) { |
|---|
| 1232 | if ((xrc=fst_writ(1,mfn,tag,occ,cnt,(char *)line,len,NULL)) < 0) |
|---|
| 1233 | return(20+xrc); |
|---|
| 1234 | #ifdef CI_WINISIS |
|---|
| 1235 | if (line) delete [] line; |
|---|
| 1236 | if (a351) delete [] a351; |
|---|
| 1237 | if (bpfx) delete [] bpfx; |
|---|
| 1238 | if (bkey) delete [] bkey; |
|---|
| 1239 | #endif |
|---|
| 1240 | return(0); |
|---|
| 1241 | } |
|---|
| 1242 | } |
|---|
| 1243 | |
|---|
| 1244 | /* store as fldupdat() command */ |
|---|
| 1245 | if (fst_batchp) { /* see mx.c */ |
|---|
| 1246 | sprintf(fst_batchp,"A%u",tag); fst_batchp+=strlen(fst_batchp); |
|---|
| 1247 | *fst_batchp++ = '\n'; |
|---|
| 1248 | memcpy(fst_batchp,line,len); fst_batchp+=len; |
|---|
| 1249 | if (fst_batch0) { |
|---|
| 1250 | sprintf(fst_batchp,"^m%ld^o%u^c%u^l%d",mfn,occ,cnt,(len <= LE1)?1:2); |
|---|
| 1251 | fst_batchp+=strlen(fst_batchp); |
|---|
| 1252 | } |
|---|
| 1253 | *fst_batchp++ = '\n'; |
|---|
| 1254 | *fst_batchp = '\0'; |
|---|
| 1255 | #ifdef CI_WINISIS |
|---|
| 1256 | if (line) delete [] line; |
|---|
| 1257 | if (a351) delete [] a351; |
|---|
| 1258 | if (bpfx) delete [] bpfx; |
|---|
| 1259 | if (bkey) delete [] bkey; |
|---|
| 1260 | #endif |
|---|
| 1261 | return(0); |
|---|
| 1262 | } |
|---|
| 1263 | |
|---|
| 1264 | /* store as LINK1/LINK2 */ |
|---|
| 1265 | |
|---|
| 1266 | if (len <= LE1) { |
|---|
| 1267 | if (*lft1 <= 0) /*fatal("fst_link/left/link1");*/ { |
|---|
| 1268 | #ifdef CI_WINISIS |
|---|
| 1269 | if (line) delete [] line; |
|---|
| 1270 | if (a351) delete [] a351; |
|---|
| 1271 | if (bpfx) delete [] bpfx; |
|---|
| 1272 | if (bkey) delete [] bkey; |
|---|
| 1273 | #endif |
|---|
| 1274 | return(-31); |
|---|
| 1275 | } |
|---|
| 1276 | link1p=(LINK1 *)lk1p; |
|---|
| 1277 | memcpy(link1p->key,line,len); |
|---|
| 1278 | if (len < LE1) memset(link1p->key+len,' ',LE1-len); |
|---|
| 1279 | encodepst(&link1p->post,mfn,tag,occ,cnt); |
|---|
| 1280 | (*lft1)--; |
|---|
| 1281 | } |
|---|
| 1282 | else { |
|---|
| 1283 | if (*lft2 <= 0) /*fatal("fst_link/left/link2");*/ { |
|---|
| 1284 | #ifdef CI_WINISIS |
|---|
| 1285 | if (line) delete [] line; |
|---|
| 1286 | if (a351) delete [] a351; |
|---|
| 1287 | if (bpfx) delete [] bpfx; |
|---|
| 1288 | if (bkey) delete [] bkey; |
|---|
| 1289 | #endif |
|---|
| 1290 | return(-41); |
|---|
| 1291 | } |
|---|
| 1292 | link2p=(LINK2 *)lk2p; |
|---|
| 1293 | memcpy(link2p->key,line,len); |
|---|
| 1294 | if (len < LE2) memset(link2p->key+len,' ',LE2-len); |
|---|
| 1295 | encodepst(&link2p->post,mfn,tag,occ,cnt); |
|---|
| 1296 | (*lft2)--; |
|---|
| 1297 | } |
|---|
| 1298 | |
|---|
| 1299 | #ifdef CI_WINISIS |
|---|
| 1300 | if (line) delete [] line; |
|---|
| 1301 | if (a351) delete [] a351; |
|---|
| 1302 | if (bpfx) delete [] bpfx; |
|---|
| 1303 | if (bkey) delete [] bkey; |
|---|
| 1304 | #endif |
|---|
| 1305 | return(len); |
|---|
| 1306 | } |
|---|
| 1307 | |
|---|
| 1308 | |
|---|
| 1309 | #if CICPP |
|---|
| 1310 | int FSTSTRU :: xfst_writ(int treecase, |
|---|
| 1311 | LONGX mfn, |
|---|
| 1312 | UWORD tag, |
|---|
| 1313 | UWORD occ, |
|---|
| 1314 | UWORD cnt, |
|---|
| 1315 | char *keyp, |
|---|
| 1316 | int keylen, |
|---|
| 1317 | UCHR *uctabp) |
|---|
| 1318 | #else |
|---|
| 1319 | int fst_writ(treecase,mfn,tag,occ,cnt,keyp,keylen,uctabp) |
|---|
| 1320 | int treecase; |
|---|
| 1321 | LONGX mfn; |
|---|
| 1322 | UWORD tag; |
|---|
| 1323 | UWORD occ; |
|---|
| 1324 | UWORD cnt; |
|---|
| 1325 | char *keyp; |
|---|
| 1326 | int keylen; |
|---|
| 1327 | UCHR *uctabp; |
|---|
| 1328 | #endif /* CICPP */ |
|---|
| 1329 | { |
|---|
| 1330 | UCHR line[1+25+LE2+1],*p,*q; |
|---|
| 1331 | int x,lrecl,loop; |
|---|
| 1332 | x=treecase; |
|---|
| 1333 | #if FSSTRACE |
|---|
| 1334 | if (fsttrace) { |
|---|
| 1335 | printf("fst_writ - [%d] %8ld/%5d/%4d/%4d ",x+1,mfn,tag,occ,cnt); |
|---|
| 1336 | for (q=keyp, loop=keylen; loop--; q++) printf("%c",*q); |
|---|
| 1337 | printf("\n"); |
|---|
| 1338 | } |
|---|
| 1339 | #endif |
|---|
| 1340 | /* setup link record */ |
|---|
| 1341 | if (keylen < 1 || keylen > LE2) fatal("fst_writ/keylen"); |
|---|
| 1342 | p=line; lrecl=0; |
|---|
| 1343 | #if MPE |
|---|
| 1344 | *p++='\0'; lrecl++; |
|---|
| 1345 | sprintf(p,"%8ld %5d %4d %4d ",mfn,tag,occ,cnt); p+=25; lrecl+=25; |
|---|
| 1346 | if (uctabp) for (q=keyp, loop=keylen; loop--; ) *p++ = uctabp[*q++]; |
|---|
| 1347 | else {memcpy(p,keyp,keylen); p+=keylen;} |
|---|
| 1348 | lrecl+=keylen; |
|---|
| 1349 | loop = ((keylen <= LE1) ? LE1 : LE2) - keylen; |
|---|
| 1350 | memset(p,' ',loop); p+=loop; lrecl+=loop; |
|---|
| 1351 | #else |
|---|
| 1352 | if (cifstfix) { |
|---|
| 1353 | if (uctabp) for (q=(UCHR *)keyp, loop=keylen; loop--; ) *p++ = uctabp[*q++]; |
|---|
| 1354 | else {memcpy(p,keyp,keylen); p+=keylen;} |
|---|
| 1355 | lrecl+=keylen; |
|---|
| 1356 | loop = ((keylen <= LE1) ? LE1 : LE2) - keylen; |
|---|
| 1357 | memset(p,' ',loop); p+=loop; lrecl+=loop; |
|---|
| 1358 | if (cifstfim) { |
|---|
| 1359 | sprintf((char *)p," %8ld",mfn); p+=9; lrecl+=9; |
|---|
| 1360 | } else { |
|---|
| 1361 | sprintf((char *)p," %8ld %5d %4d %4d",mfn,tag,occ,cnt); p+=25; lrecl+=25; |
|---|
| 1362 | } |
|---|
| 1363 | } |
|---|
| 1364 | else { |
|---|
| 1365 | #if LINK_7544KEY |
|---|
| 1366 | sprintf(p,"%8ld %5d %4d %4d ",mfn,tag,occ,cnt); p+=25; lrecl+=25; |
|---|
| 1367 | #else |
|---|
| 1368 | sprintf((char *)p,"%1ld %1d %1d %1d ",mfn,tag,occ,cnt); |
|---|
| 1369 | lrecl+=strlen((CONST char *)p); p= &line[lrecl]; |
|---|
| 1370 | #endif |
|---|
| 1371 | if (uctabp) for (q=(UCHR *)keyp, loop=keylen; loop--; ) *p++ = uctabp[*q++]; |
|---|
| 1372 | else {memcpy(p,keyp,keylen); p+=keylen;} |
|---|
| 1373 | lrecl+=keylen; |
|---|
| 1374 | #if LINK_7544KEY |
|---|
| 1375 | loop = ((keylen <= LE1) ? LE1 : LE2) - keylen; |
|---|
| 1376 | memset(p,' ',loop); p+=loop; lrecl+=loop; |
|---|
| 1377 | #endif |
|---|
| 1378 | } |
|---|
| 1379 | #if PC |
|---|
| 1380 | *p++='\r'; /* CIWRITE */ |
|---|
| 1381 | lrecl++; |
|---|
| 1382 | #endif |
|---|
| 1383 | #endif /* !MPE */ |
|---|
| 1384 | *p='\n'; |
|---|
| 1385 | lrecl++; |
|---|
| 1386 | /* write it */ |
|---|
| 1387 | if (!fst_fd[treecase]) /*fatal("fst_writ/fst_open");*/ return(-1); |
|---|
| 1388 | if (fst_fleft[x] >= lrecl) { |
|---|
| 1389 | memcpy(&fst_fbuff[x][fst_ffree[x]],line,lrecl); |
|---|
| 1390 | fst_fleft[x]-=lrecl; |
|---|
| 1391 | fst_ffree[x]+=lrecl; |
|---|
| 1392 | } |
|---|
| 1393 | else { |
|---|
| 1394 | memcpy(&fst_fbuff[x][fst_ffree[x]],line,fst_fleft[x]); |
|---|
| 1395 | if (CIWRITE(fst_fd[x],fst_fbuff[x],fst_fbsiz) != fst_fbsiz) { |
|---|
| 1396 | #ifndef USE_ERROR_SYS |
|---|
| 1397 | printf("mfn/tag/occ/cnt: %ld/%d/%d/%d \n",mfn,tag,occ,cnt); |
|---|
| 1398 | fatal("writbsiz/write"); |
|---|
| 1399 | #endif |
|---|
| 1400 | return(-2); |
|---|
| 1401 | } |
|---|
| 1402 | fst_ffree[x]=lrecl-fst_fleft[x]; |
|---|
| 1403 | memcpy(fst_fbuff[x],&line[fst_fleft[x]],fst_ffree[x]); |
|---|
| 1404 | fst_fleft[x]=fst_fbsiz-fst_ffree[x]; |
|---|
| 1405 | } |
|---|
| 1406 | fst_fx[x]++; |
|---|
| 1407 | return(keylen); |
|---|
| 1408 | } |
|---|
| 1409 | |
|---|
| 1410 | #if CICPP |
|---|
| 1411 | int FSTSTRU :: xfst_open(char *gidbnp, |
|---|
| 1412 | char *filnamp, |
|---|
| 1413 | int treecase) |
|---|
| 1414 | #else |
|---|
| 1415 | int fst_open(gidbnp,filnamp,treecase) |
|---|
| 1416 | char *gidbnp; |
|---|
| 1417 | char *filnamp; |
|---|
| 1418 | int treecase; |
|---|
| 1419 | #endif /* CICPP */ |
|---|
| 1420 | { |
|---|
| 1421 | int fd; |
|---|
| 1422 | #if MPE |
|---|
| 1423 | int lrecl; |
|---|
| 1424 | char dcb[32]; |
|---|
| 1425 | #endif |
|---|
| 1426 | if (treecase != 0 && treecase != 1) fatal("fst_open/treecase"); |
|---|
| 1427 | |
|---|
| 1428 | /* create link file */ |
|---|
| 1429 | filnamp=dbxcipar(gidbnp,filnamp,'='); |
|---|
| 1430 | #if MPE |
|---|
| 1431 | lrecl=25+((treecase)?LE2:LE1); /* ccxl ! */ |
|---|
| 1432 | sprintf(dcb,"R%d Bl%d",lrecl,8192/lrecl); |
|---|
| 1433 | fd=OPEN(filnamp,O_WRONLY|O_CREAT|O_TRUNC|O_MPEOPTS,PERMIS,dcb); |
|---|
| 1434 | #else |
|---|
| 1435 | #if CICPP |
|---|
| 1436 | #if !GCC // na verdade #if PC, pois PC no CISIS.h significa DOS ou Windows |
|---|
| 1437 | // em UNIX, fmode e' sempre BINARY (vide #define O_BINARY em CISIS.H) |
|---|
| 1438 | unsigned int mode; |
|---|
| 1439 | mode=_fmode; _fmode=O_BINARY; |
|---|
| 1440 | #endif // !GCC |
|---|
| 1441 | fd=CREAT(filnamp,PERMIS); /* BINARY */ |
|---|
| 1442 | #if !GCC |
|---|
| 1443 | _fmode=mode; |
|---|
| 1444 | #endif // !GCC |
|---|
| 1445 | #else |
|---|
| 1446 | fd=CREAT(filnamp,PERMIS); /* BINARY */ |
|---|
| 1447 | #endif /* CICPP */ |
|---|
| 1448 | #endif |
|---|
| 1449 | if (fd == EOF) /*fatal(filnamp);*/ return(EOF); |
|---|
| 1450 | if (!fst_fbuff[treecase]) { |
|---|
| 1451 | /*if (fst_fbsiz > (UWORD)ALLOMAXV) fatal("fst_open/ALLOMAXV"); HB 28/03/2003 -> FFI */ |
|---|
| 1452 | if (fst_fbsiz > ALLOMAXV) fatal("fst_open/ALLOMAXV"); |
|---|
| 1453 | #if CICPP |
|---|
| 1454 | try {fst_fbuff[treecase]=new unsigned char [fst_fbsiz];} |
|---|
| 1455 | catch (BAD_ALLOC) {fst_fbuff[treecase]=(unsigned char *)ALLONULL;} |
|---|
| 1456 | #else |
|---|
| 1457 | fst_fbuff[treecase]=(char *)ALLOC((ALLOPARM)fst_fbsiz); |
|---|
| 1458 | #endif /* CICPP */ |
|---|
| 1459 | if (fst_fbuff[treecase] == (unsigned char *)ALLONULL) { |
|---|
| 1460 | CLOSE(fd); fatal("fst_open/ALLOC"); |
|---|
| 1461 | return(EOF); |
|---|
| 1462 | } |
|---|
| 1463 | } |
|---|
| 1464 | |
|---|
| 1465 | fst_fleft[treecase]=fst_fbsiz; |
|---|
| 1466 | fst_ffree[treecase]=0; |
|---|
| 1467 | fst_fx[treecase]=0; |
|---|
| 1468 | |
|---|
| 1469 | return(fst_fd[treecase]=fd); |
|---|
| 1470 | } |
|---|
| 1471 | |
|---|
| 1472 | #if CICPP |
|---|
| 1473 | int FSTSTRU :: fst_clos(int treecase) |
|---|
| 1474 | #else |
|---|
| 1475 | int fst_clos(treecase) /* |
|---|
| 1476 | ------------- */ |
|---|
| 1477 | int treecase; |
|---|
| 1478 | #endif /* CICPP */ |
|---|
| 1479 | { |
|---|
| 1480 | int x; |
|---|
| 1481 | if (fst_fd[x=treecase] > 0) { |
|---|
| 1482 | if (fst_ffree[x]) |
|---|
| 1483 | if (CIWRITE(fst_fd[x],fst_fbuff[x],fst_ffree[x]) != fst_ffree[x]) |
|---|
| 1484 | /*fatal("fst_clos/write");*/ return(EOF); |
|---|
| 1485 | #if CICPP |
|---|
| 1486 | delete [] fst_fbuff[x]; |
|---|
| 1487 | #else |
|---|
| 1488 | FREE(fst_fbuff[x]); |
|---|
| 1489 | #endif /* CICPP */ |
|---|
| 1490 | CLOSE(fst_fd[x]); |
|---|
| 1491 | } |
|---|
| 1492 | return(0); |
|---|
| 1493 | } |
|---|
| 1494 | |
|---|
| 1495 | /* *************************** pstdecod ******************************** */ |
|---|
| 1496 | #if CICPP |
|---|
| 1497 | void FSTSTRU :: xpstdecod(POSTSTRU *pst, |
|---|
| 1498 | LONGX *mfn, |
|---|
| 1499 | UWORD *tag, |
|---|
| 1500 | UWORD *occ, |
|---|
| 1501 | UWORD *cnt) |
|---|
| 1502 | #else |
|---|
| 1503 | void pstdecod(pst,mfn,tag,occ,cnt) |
|---|
| 1504 | POSTSTRU *pst; |
|---|
| 1505 | LONGX *mfn; |
|---|
| 1506 | UWORD *tag; |
|---|
| 1507 | UWORD *occ; |
|---|
| 1508 | UWORD *cnt; |
|---|
| 1509 | #endif /* CICPP */ |
|---|
| 1510 | { |
|---|
| 1511 | LONGX xmfn; |
|---|
| 1512 | UCHR *p,byt1,byt2,byt3; |
|---|
| 1513 | |
|---|
| 1514 | p=(UCHR *)pst; |
|---|
| 1515 | byt1= *p++; byt2= *p++; byt3= *p++; |
|---|
| 1516 | xmfn = (unsigned LONGX )byt1; |
|---|
| 1517 | xmfn=(unsigned LONGX )(xmfn << 16)+ |
|---|
| 1518 | (unsigned LONGX)(byt2<<8)+ |
|---|
| 1519 | (unsigned LONGX)byt3; |
|---|
| 1520 | *mfn=xmfn; |
|---|
| 1521 | byt1= *p++; byt2= *p++; |
|---|
| 1522 | *tag=(byt1<<8)+byt2; |
|---|
| 1523 | byt1= *p++; |
|---|
| 1524 | *occ=byt1; |
|---|
| 1525 | byt1= *p++; byt2= *p++; |
|---|
| 1526 | *cnt=(byt1<<8)+byt2; |
|---|
| 1527 | } |
|---|
| 1528 | /* *************************** prtlink ******************************** */ |
|---|
| 1529 | #if CICPP |
|---|
| 1530 | void FSTSTRU :: xprtlink(char *stubp, |
|---|
| 1531 | LONGX pmfn, |
|---|
| 1532 | UWORD ptag, |
|---|
| 1533 | UWORD pocc, |
|---|
| 1534 | UWORD pcnt, |
|---|
| 1535 | UCHR *keyp, |
|---|
| 1536 | int len) |
|---|
| 1537 | #else |
|---|
| 1538 | void prtlink(stubp,pmfn,ptag,pocc,pcnt,keyp,len) |
|---|
| 1539 | char *stubp; |
|---|
| 1540 | LONGX pmfn; |
|---|
| 1541 | UWORD ptag,pocc,pcnt; |
|---|
| 1542 | UCHR *keyp; |
|---|
| 1543 | int len; |
|---|
| 1544 | #endif /* CICPP */ |
|---|
| 1545 | { |
|---|
| 1546 | int loop; |
|---|
| 1547 | char *p; |
|---|
| 1548 | |
|---|
| 1549 | if (stubp) printf("%s",stubp); |
|---|
| 1550 | printf("%8ld %5u %4u %4u ",pmfn,ptag,pocc,pcnt); |
|---|
| 1551 | for (p=(char *)keyp, loop=len; loop--; p++) printf("%c",*p); |
|---|
| 1552 | printf("\n"); |
|---|
| 1553 | } |
|---|
| 1554 | |
|---|
| 1555 | |
|---|
| 1556 | #if CICPP |
|---|
| 1557 | char * FSTSTRU :: xloadmemstw(char *memp, |
|---|
| 1558 | int *nstws) { |
|---|
| 1559 | char* areap = NULL; |
|---|
| 1560 | char* aposp = NULL; |
|---|
| 1561 | char* mposp = memp; |
|---|
| 1562 | int asize = 0; |
|---|
| 1563 | int mlen = 0; |
|---|
| 1564 | int klen = 0; |
|---|
| 1565 | int num = 0; |
|---|
| 1566 | bool added = false; |
|---|
| 1567 | |
|---|
| 1568 | if (memp != NULL) { |
|---|
| 1569 | mlen = strlen(memp); |
|---|
| 1570 | |
|---|
| 1571 | for (int counter = 0; counter < mlen; counter++) { |
|---|
| 1572 | if (isspace(*mposp)) { |
|---|
| 1573 | added = false; |
|---|
| 1574 | } else { |
|---|
| 1575 | if (!added) { |
|---|
| 1576 | num++; |
|---|
| 1577 | added = true; |
|---|
| 1578 | } |
|---|
| 1579 | } |
|---|
| 1580 | mposp++; |
|---|
| 1581 | } |
|---|
| 1582 | |
|---|
| 1583 | asize = (num * (LE1 + 1)) + 1; |
|---|
| 1584 | |
|---|
| 1585 | try { |
|---|
| 1586 | aposp = areap = new char[asize]; |
|---|
| 1587 | } catch (BAD_ALLOC) { |
|---|
| 1588 | fatal("xloadmemstw/ALLOC"); |
|---|
| 1589 | } |
|---|
| 1590 | |
|---|
| 1591 | memset(areap, 0x00, asize); |
|---|
| 1592 | mposp = memp; |
|---|
| 1593 | |
|---|
| 1594 | for (int pos = 0; pos < mlen; pos++) { |
|---|
| 1595 | if (isspace(*mposp) == 0) { |
|---|
| 1596 | if (klen <= LE1) { |
|---|
| 1597 | *aposp = *mposp; |
|---|
| 1598 | if (klen == LE1) { |
|---|
| 1599 | aposp++; |
|---|
| 1600 | } |
|---|
| 1601 | } |
|---|
| 1602 | klen++; |
|---|
| 1603 | aposp++; |
|---|
| 1604 | } else { |
|---|
| 1605 | if (klen > 0) { |
|---|
| 1606 | aposp += (LE1 - klen + 1); |
|---|
| 1607 | klen = 0; |
|---|
| 1608 | } |
|---|
| 1609 | } |
|---|
| 1610 | mposp++; |
|---|
| 1611 | } |
|---|
| 1612 | } |
|---|
| 1613 | *nstws = num; |
|---|
| 1614 | |
|---|
| 1615 | return areap; |
|---|
| 1616 | } |
|---|
| 1617 | #endif /* CICPP */ |
|---|