| 1 | #include <stdio.h> |
|---|
| 2 | #include <string.h> |
|---|
| 3 | #include <ctype.h> |
|---|
| 4 | #include "cisis.h" |
|---|
| 5 | |
|---|
| 6 | #if CICPP |
|---|
| 7 | #include <ciiso.hpp> |
|---|
| 8 | #define CIISO_SOURCE |
|---|
| 9 | #include <cirun.hpp> |
|---|
| 10 | /* ------------------------- CIISO.HPP ---------------------------------- */ |
|---|
| 11 | #ifdef CICPP |
|---|
| 12 | #define iso_openx xiso_openx /* internal use */ |
|---|
| 13 | #endif |
|---|
| 14 | #define iso_creat xiso_creat /* internal use */ |
|---|
| 15 | #define iso_write xiso_write /* internal use */ |
|---|
| 16 | #define iso_bmove xiso_bmove /* internal use */ |
|---|
| 17 | #define iso_break xiso_break /* internal use */ |
|---|
| 18 | #define iso_close xiso_close /* internal use */ |
|---|
| 19 | #define iso_rclos xiso_rclos /* internal use */ |
|---|
| 20 | #if GEN_ISI |
|---|
| 21 | #define iso_open xiso_open /* internal use */ |
|---|
| 22 | /* #define iso_read xiso_read no conversion */ |
|---|
| 23 | #define iso_loadbuff xiso_loadbuff /* internal use */ |
|---|
| 24 | #define iso_getval xiso_getval /* internal use */ |
|---|
| 25 | #endif |
|---|
| 26 | /* ---------------------------------------------------------------------- */ |
|---|
| 27 | #endif /* CICPP */ |
|---|
| 28 | |
|---|
| 29 | /* -------------------------------- iso.c -------------------------------- */ |
|---|
| 30 | #define TRACE 0 |
|---|
| 31 | #define ENABHDR 0 |
|---|
| 32 | #define ENABDIR 0 |
|---|
| 33 | #define ENABFLD 0 |
|---|
| 34 | #define TRACISI 0 |
|---|
| 35 | |
|---|
| 36 | #if !CICPP |
|---|
| 37 | #if !CICPP |
|---|
| 38 | unsigned char *iso_buff = NULL; /* iso_bmove / iso_break */ |
|---|
| 39 | int iso_fd = 0; /* iso_bmove / iso_break */ |
|---|
| 40 | int iso_lrecb; /* iso_bmove / iso_break */ |
|---|
| 41 | int iso_lrfox; /* iso_bmove / iso_break */ |
|---|
| 42 | int iso_isfox; /* iso_bmove / iso_break */ |
|---|
| 43 | unsigned iso_bfree; /* iso_bmove / iso_break */ |
|---|
| 44 | unsigned iso_bidx; /* iso_bmove / iso_break */ |
|---|
| 45 | unsigned iso_bfix; /* iso_bmove / iso_break */ |
|---|
| 46 | unsigned iso_cards; /* iso_bmove / iso_break */ |
|---|
| 47 | unsigned char iso_fmtlef[] = {"%0#d"}; |
|---|
| 48 | unsigned char iso_fmtscp[] = {"%0#d"}; |
|---|
| 49 | int iso_ismarc = 0; |
|---|
| 50 | #endif /* CICPP */ |
|---|
| 51 | #if ANSI |
|---|
| 52 | int iso_bmove(unsigned char *obuf, unsigned obufsize); |
|---|
| 53 | int iso_break(int isfox); |
|---|
| 54 | #else |
|---|
| 55 | int iso_bmove(); |
|---|
| 56 | int iso_break(); |
|---|
| 57 | #endif |
|---|
| 58 | #endif /* !CICPP */ |
|---|
| 59 | |
|---|
| 60 | #define MARC_BEFORE_20090311 0 /* HB - following MARC21 layout*/ |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | #if CICPP |
|---|
| 64 | ISO_2709 :: ISO_2709 (CISISX *cxp) : cisisxp(cxp), |
|---|
| 65 | iso_buff(NULL), iso_fd(0), iso_lrecb(0), |
|---|
| 66 | iso_lrfox(0), iso_isfox(0), iso_bfree(0), |
|---|
| 67 | iso_bidx(0), iso_bfix(0), iso_cards(0), iso_ismarc(0), |
|---|
| 68 | #if GEN_ISI |
|---|
| 69 | isi_buffin(NULL), isi_fd(0), |
|---|
| 70 | isi_lrecb(0), isi_lrfix(0), |
|---|
| 71 | isi_isfix(0), isi_count(0L) |
|---|
| 72 | #endif /* GEN_ISI */ |
|---|
| 73 | { |
|---|
| 74 | iso_fmtlef=(unsigned char *)strdup("%0#d"); // DS 09/95 |
|---|
| 75 | iso_fmtscp=(unsigned char *)strdup("%0#d"); |
|---|
| 76 | |
|---|
| 77 | if (cisisxp == NULL) |
|---|
| 78 | fatal("ISO_2709/NULL"); |
|---|
| 79 | } |
|---|
| 80 | #endif /* CICPP */ |
|---|
| 81 | |
|---|
| 82 | #if CICPP |
|---|
| 83 | ISO_2709 :: ~ISO_2709 (void) |
|---|
| 84 | { |
|---|
| 85 | if (iso_fd > 0) // Existe arquivo iso de exporta� aberto, entao fecha-o. |
|---|
| 86 | { |
|---|
| 87 | xiso_close(); |
|---|
| 88 | iso_fd = 0; |
|---|
| 89 | } |
|---|
| 90 | if (isi_buffin) |
|---|
| 91 | { |
|---|
| 92 | delete[] isi_buffin; |
|---|
| 93 | isi_buffin = NULL; |
|---|
| 94 | } |
|---|
| 95 | if (isi_fd > 0) |
|---|
| 96 | CLOSE(isi_fd); |
|---|
| 97 | isi_fd = 0; |
|---|
| 98 | isi_count = 0L; |
|---|
| 99 | iso_ismarc = 0; |
|---|
| 100 | free(iso_fmtlef); |
|---|
| 101 | free(iso_fmtscp); |
|---|
| 102 | } |
|---|
| 103 | #endif /* CICPP */ |
|---|
| 104 | |
|---|
| 105 | #if CICPP |
|---|
| 106 | int ISO_2709 :: xiso_openx(char *gidbnp, |
|---|
| 107 | unsigned char filnam[], |
|---|
| 108 | int lrecb, |
|---|
| 109 | int lrfox, |
|---|
| 110 | int isfox) |
|---|
| 111 | { |
|---|
| 112 | char *filnamp; |
|---|
| 113 | |
|---|
| 114 | /* open output file */ |
|---|
| 115 | filnamp=dbxcipar(gidbnp,(char *)filnam,'='); |
|---|
| 116 | |
|---|
| 117 | if (iso_fd) |
|---|
| 118 | xiso_close(); |
|---|
| 119 | iso_fd= OPEN(filnamp,O_RDWR|O_BINARY|O_APPEND); /* BINARY */ |
|---|
| 120 | |
|---|
| 121 | if (iso_fd <= 0) |
|---|
| 122 | { |
|---|
| 123 | fatal( filnamp); |
|---|
| 124 | return (iso_fd); /* mffunc.cpp */ |
|---|
| 125 | } |
|---|
| 126 | |
|---|
| 127 | /* allocate output buffer */ |
|---|
| 128 | try {iso_buff = (unsigned char *) new char [ISOBSIZ+800];} |
|---|
| 129 | catch (BAD_ALLOC){ iso_buff = (unsigned char *)ALLONULL;} |
|---|
| 130 | |
|---|
| 131 | if ( iso_buff == (unsigned char *)ALLONULL) |
|---|
| 132 | fatal( "xiso_openx/ALLOC"); |
|---|
| 133 | if (iso_lrecb) |
|---|
| 134 | fatal( "xiso_openx/lrecb"); /* for time being */ |
|---|
| 135 | |
|---|
| 136 | /* keep lrecb/lrfox/isfox */ |
|---|
| 137 | iso_lrecb = lrecb; |
|---|
| 138 | iso_lrfox = lrfox; |
|---|
| 139 | iso_isfox = isfox; |
|---|
| 140 | |
|---|
| 141 | /* setup formats "%0#d" */ |
|---|
| 142 | iso_fmtlef[2]=ISOLLEF+'0'; |
|---|
| 143 | iso_fmtscp[2]=ISOLSCP+'0'; |
|---|
| 144 | return(iso_fd); |
|---|
| 145 | } |
|---|
| 146 | #endif /* CICPP */ |
|---|
| 147 | |
|---|
| 148 | #if CICPP |
|---|
| 149 | int ISO_2709 :: xiso_creat(char *gidbnp, |
|---|
| 150 | unsigned char filnam[], |
|---|
| 151 | int lrecb, |
|---|
| 152 | int lrfox, |
|---|
| 153 | int isfox) |
|---|
| 154 | #else |
|---|
| 155 | int iso_creat(gidbnp,filnam,lrecb,lrfox,isfox) |
|---|
| 156 | char *gidbnp; |
|---|
| 157 | unsigned char filnam[]; |
|---|
| 158 | int lrecb; |
|---|
| 159 | int lrfox; |
|---|
| 160 | int isfox; |
|---|
| 161 | #endif /* CICPP */ |
|---|
| 162 | { |
|---|
| 163 | char *filnamp; |
|---|
| 164 | #if MPE |
|---|
| 165 | char dcb[16]; |
|---|
| 166 | #endif |
|---|
| 167 | /* open output file */ |
|---|
| 168 | filnamp=dbxcipar(gidbnp,(char *)filnam,'='); |
|---|
| 169 | |
|---|
| 170 | #if MPE |
|---|
| 171 | sprintf(dcb,"R%d",lrfox); |
|---|
| 172 | iso_fd=OPEN(filnamp,O_WRONLY|O_CREAT|O_TRUNC|O_MPEOPTS,PERMIS,dcb); |
|---|
| 173 | #else |
|---|
| 174 | #if CICPP |
|---|
| 175 | #if !GCC // na verdade #if PC, pois PC no CISIS.h significa DOS ou Windows |
|---|
| 176 | // em UNIX, fmode e' sempre BINARY (vide #define O_BINARY em CISIS.H) |
|---|
| 177 | unsigned int mode; |
|---|
| 178 | mode=_fmode; _fmode=O_BINARY; |
|---|
| 179 | #endif // !GCC |
|---|
| 180 | iso_fd=CREAT(filnamp,PERMIS); /* BINARY */ |
|---|
| 181 | #if !GCC |
|---|
| 182 | _fmode=mode; |
|---|
| 183 | #endif // !GCC |
|---|
| 184 | #else |
|---|
| 185 | iso_fd=CREAT(filnamp,PERMIS); /* BINARY */ |
|---|
| 186 | #endif /* CICPP */ |
|---|
| 187 | #endif |
|---|
| 188 | if (iso_fd <= 0) { |
|---|
| 189 | fatal( filnamp); |
|---|
| 190 | return (iso_fd); /* mffunc.cpp */ |
|---|
| 191 | } |
|---|
| 192 | |
|---|
| 193 | /* allocate output buffer */ |
|---|
| 194 | #if CICPP |
|---|
| 195 | try {iso_buff = (unsigned char *) new char [ISOBSIZ+800];} |
|---|
| 196 | catch (BAD_ALLOC){ iso_buff = (unsigned char *)ALLONULL;} |
|---|
| 197 | #else |
|---|
| 198 | iso_buff = ALLOC((ALLOPARM)(ISOBSIZ+800)); |
|---|
| 199 | #endif /* CICPP */ |
|---|
| 200 | if ( iso_buff == (unsigned char *)ALLONULL) |
|---|
| 201 | fatal( "iso_creat/ALLOC"); |
|---|
| 202 | if (iso_lrecb) |
|---|
| 203 | fatal( "iso_creat/lrecb"); /* for time being */ |
|---|
| 204 | /* keep lrecb/lrfox/isfox */ |
|---|
| 205 | iso_lrecb = lrecb; |
|---|
| 206 | iso_lrfox = lrfox; |
|---|
| 207 | iso_isfox = isfox; |
|---|
| 208 | /* setup formats "%0#d" */ |
|---|
| 209 | iso_fmtlef[2]=ISOLLEF+'0'; |
|---|
| 210 | iso_fmtscp[2]=ISOLSCP+'0'; |
|---|
| 211 | return(iso_fd); |
|---|
| 212 | } |
|---|
| 213 | |
|---|
| 214 | |
|---|
| 215 | #define LDRTAGN(x) \ |
|---|
| 216 | for (n=0, dirp=MFRdir, loop=MFRnvf; loop--; dirp++) \ |
|---|
| 217 | if (dirp->tag == x) { n=dirp->len; p=(unsigned char *)MFX+(MFRbase+dirp->pos); break; } |
|---|
| 218 | |
|---|
| 219 | |
|---|
| 220 | #if CICPP |
|---|
| 221 | int ISO_2709 :: xiso_write(RECSTRU *recp, |
|---|
| 222 | unsigned char isoxfs, |
|---|
| 223 | unsigned char isoxgs, |
|---|
| 224 | unsigned int ldrtag) |
|---|
| 225 | #else |
|---|
| 226 | int iso_write(recp, isoxfs, isoxgs, ldrtag) |
|---|
| 227 | RECSTRU *recp; |
|---|
| 228 | unsigned char isoxfs; |
|---|
| 229 | unsigned char isoxgs; |
|---|
| 230 | unsigned int ldrtag; |
|---|
| 231 | #endif /* CICPP */ |
|---|
| 232 | { |
|---|
| 233 | ISOHSTRU *isohp; |
|---|
| 234 | ISODSTRU *isodp; |
|---|
| 235 | DIRSTRU *dirp; |
|---|
| 236 | unsigned loop; |
|---|
| 237 | short isolen; |
|---|
| 238 | short isopos; |
|---|
| 239 | int nvfs=0; |
|---|
| 240 | char areah[ISOHSIZE+1],aread[ISODSIZE+1]; /* last byte for str moving */ |
|---|
| 241 | |
|---|
| 242 | /* check previous iso_creat() */ |
|---|
| 243 | if (!iso_buff || iso_fd <= 0) |
|---|
| 244 | fatal( "iso_write/creat"); |
|---|
| 245 | /* initialize iso_bmove() */ |
|---|
| 246 | iso_bfree=ISOBSIZ; |
|---|
| 247 | iso_bidx=0; |
|---|
| 248 | iso_bfix=iso_lrfox; |
|---|
| 249 | iso_cards=0; |
|---|
| 250 | /* leader segment */ |
|---|
| 251 | isohp = (ISOHSTRU *)&areah[0]; /* TC: &areah */ |
|---|
| 252 | isolen=ISOHSIZE; |
|---|
| 253 | |
|---|
| 254 | for (dirp=MFRdir, loop=MFRnvf; loop--; dirp++) { |
|---|
| 255 | /* skip leader data fields for MARC processing - AOT 11/06/2001 */ |
|---|
| 256 | if (ldrtag) if (dirp->tag >= ldrtag) if (dirp->tag <= ldrtag+ISOHSIZE) continue; |
|---|
| 257 | isolen+=(ISODSIZE + dirp->len + 1); nvfs++; |
|---|
| 258 | } |
|---|
| 259 | |
|---|
| 260 | isolen+=2; |
|---|
| 261 | sprintf((char *)isohp->length,"%05d",isolen); |
|---|
| 262 | |
|---|
| 263 | #if MARC_BEFORE_20090311 |
|---|
| 264 | *isohp->status='0'; |
|---|
| 265 | strcpy((char *)isohp->icodes,"0000"); |
|---|
| 266 | *isohp->indlen='0'; |
|---|
| 267 | *isohp->sublen='0'; |
|---|
| 268 | sprintf((char *)isohp->basead,"%05d",ISOHSIZE + nvfs*ISODSIZE + 1); |
|---|
| 269 | strcpy((char *)isohp->forusr,"000"); |
|---|
| 270 | *isohp->lenlef=ISOLLEF+'0'; |
|---|
| 271 | *isohp->lenscp=ISOLSCP+'0'; |
|---|
| 272 | strcpy((char *)isohp->forfut,"00"); |
|---|
| 273 | |
|---|
| 274 | /* store leader data fields for MARC processing - AOT 11/06/2001 */ |
|---|
| 275 | #if 0 |
|---|
| 276 | byte 5 = Estado del registro |
|---|
| 277 | byte 6 = Tipo de registro |
|---|
| 278 | byte 7 = Nivel bibliogr�co |
|---|
| 279 | byte 8 = Tipo de control |
|---|
| 280 | byte 17 = Nivel de codificaci�yte 18 = Forma de catalogaci�yte 19 = Linked requirement |
|---|
| 281 | typedef struct isohstru { |
|---|
| 282 | unsigned char length[5]; |
|---|
| 283 | unsigned char status[1]; /* 5=Estado del registro */ |
|---|
| 284 | unsigned char icodes[4]; /* 6=Tipo de registro; 7=Nivel bibliogr�co; 8=Tipo de control; unused */ |
|---|
| 285 | unsigned char indlen[1]; |
|---|
| 286 | unsigned char sublen[1]; |
|---|
| 287 | unsigned char basead[5]; |
|---|
| 288 | unsigned char forusr[3]; /* 17=Nivel de codificaci�18=Forma de catalogaci�19=Linked requirement */ |
|---|
| 289 | #endif |
|---|
| 290 | if (ldrtag) { |
|---|
| 291 | FFI n; |
|---|
| 292 | unsigned char *p; |
|---|
| 293 | LDRTAGN(ldrtag+5); if (n) isohp->status[0]= *p; |
|---|
| 294 | LDRTAGN(ldrtag+6); if (n) isohp->icodes[0]= *p; |
|---|
| 295 | LDRTAGN(ldrtag+7); if (n) isohp->icodes[1]= *p; |
|---|
| 296 | LDRTAGN(ldrtag+8); if (n) isohp->icodes[2]= *p; |
|---|
| 297 | LDRTAGN(ldrtag+17); if (n) isohp->forusr[0]= *p; |
|---|
| 298 | LDRTAGN(ldrtag+18); if (n) isohp->forusr[1]= *p; |
|---|
| 299 | LDRTAGN(ldrtag+19); if (n) isohp->forusr[2]= *p; |
|---|
| 300 | } |
|---|
| 301 | #else /* MARC_BEFORE_20090311 */ |
|---|
| 302 | /* |
|---|
| 303 | See http://www.itsmarc.com/crs/auth0669.htm |
|---|
| 304 | bytes 00-04 - Logical record length |
|---|
| 305 | byte 05 - Record status |
|---|
| 306 | byte 06 - Type of record |
|---|
| 307 | bytes 07-08 - Undefined |
|---|
| 308 | byte 09 - Character coding scheme |
|---|
| 309 | byte 10 - Indicator count |
|---|
| 310 | byte 11 - Subfield code length |
|---|
| 311 | bytes 12-16 - Base address of data |
|---|
| 312 | byte 17 - Encoding level |
|---|
| 313 | bytes 18-19 - Undefined |
|---|
| 314 | bytes 20-23 - Entry map |
|---|
| 315 | */ |
|---|
| 316 | if (iso_ismarc) { |
|---|
| 317 | *isohp->status='n'; |
|---|
| 318 | isohp->icodes[0]='z'; |
|---|
| 319 | isohp->icodes[1]=' '; |
|---|
| 320 | isohp->icodes[2]=' '; |
|---|
| 321 | isohp->icodes[3]=' '; |
|---|
| 322 | *isohp->indlen='2'; |
|---|
| 323 | *isohp->sublen='2'; |
|---|
| 324 | sprintf((char *)isohp->basead,"%05d",ISOHSIZE + nvfs*ISODSIZE + 1); |
|---|
| 325 | isohp->forusr[0]='n'; |
|---|
| 326 | isohp->forusr[1]=' '; |
|---|
| 327 | isohp->forusr[2]=' '; |
|---|
| 328 | *isohp->lenlef='4'; |
|---|
| 329 | *isohp->lenscp='5'; |
|---|
| 330 | strcpy((char *)isohp->forfut,"00"); |
|---|
| 331 | if (ldrtag) { |
|---|
| 332 | FFI n; |
|---|
| 333 | unsigned char *p; |
|---|
| 334 | LDRTAGN(ldrtag+5); if (n) isohp->status[0]= *p; /* Record status */ |
|---|
| 335 | LDRTAGN(ldrtag+9); if (n) isohp->icodes[3]= *p; /* Character coding scheme */ |
|---|
| 336 | LDRTAGN(ldrtag+17); if (n) isohp->forusr[0]= *p; /* Encoding level */ |
|---|
| 337 | } |
|---|
| 338 | } else { |
|---|
| 339 | *isohp->status='0'; |
|---|
| 340 | strcpy((char *)isohp->icodes,"0000"); |
|---|
| 341 | *isohp->indlen='0'; |
|---|
| 342 | *isohp->sublen='0'; |
|---|
| 343 | sprintf((char *)isohp->basead,"%05d",ISOHSIZE + nvfs*ISODSIZE + 1); |
|---|
| 344 | strcpy((char *)isohp->forusr,"000"); |
|---|
| 345 | *isohp->lenlef=ISOLLEF+'0'; |
|---|
| 346 | *isohp->lenscp=ISOLSCP+'0'; |
|---|
| 347 | strcpy((char *)isohp->forfut,"00"); |
|---|
| 348 | if (ldrtag) { |
|---|
| 349 | FFI n; |
|---|
| 350 | unsigned char *p; |
|---|
| 351 | LDRTAGN(ldrtag+5); if (n) isohp->status[0]= *p; |
|---|
| 352 | LDRTAGN(ldrtag+6); if (n) isohp->icodes[0]= *p; |
|---|
| 353 | LDRTAGN(ldrtag+7); if (n) isohp->icodes[1]= *p; |
|---|
| 354 | LDRTAGN(ldrtag+8); if (n) isohp->icodes[2]= *p; |
|---|
| 355 | LDRTAGN(ldrtag+17); if (n) isohp->forusr[0]= *p; |
|---|
| 356 | LDRTAGN(ldrtag+18); if (n) isohp->forusr[1]= *p; |
|---|
| 357 | LDRTAGN(ldrtag+19); if (n) isohp->forusr[2]= *p; |
|---|
| 358 | } |
|---|
| 359 | } |
|---|
| 360 | #endif /* MARC_BEFORE_20090311 */ |
|---|
| 361 | iso_bmove((unsigned char *)isohp,ISOHSIZE); |
|---|
| 362 | |
|---|
| 363 | /* directory segment */ |
|---|
| 364 | isodp = (ISODSTRU *)&aread[0]; /* TC: &aread */ |
|---|
| 365 | isopos=0; |
|---|
| 366 | for (dirp=MFRdir, loop=MFRnvf; loop--; dirp++) { |
|---|
| 367 | /* skip leader data fields for MARC processing - AOT 11/06/2001 */ |
|---|
| 368 | if (ldrtag) if (dirp->tag >= ldrtag) if (dirp->tag <= ldrtag+ISOHSIZE) continue; |
|---|
| 369 | sprintf((char *)isodp->tagfld,"%03d",dirp->tag); |
|---|
| 370 | sprintf((char *)isodp->lenfld,(CONST char *)iso_fmtlef,dirp->len + 1); |
|---|
| 371 | sprintf((char *)isodp->locfld,(CONST char *)iso_fmtscp,isopos); |
|---|
| 372 | isopos+=(dirp->len + 1); |
|---|
| 373 | iso_bmove((unsigned char *)isodp,ISODSIZE); |
|---|
| 374 | } |
|---|
| 375 | /* variable data fields segment */ |
|---|
| 376 | for (dirp=MFRdir, loop=0; loop < MFRnvf; loop++, dirp++) { |
|---|
| 377 | /* skip leader data fields for MARC processing - AOT 11/06/2001 */ |
|---|
| 378 | if (ldrtag) if (dirp->tag >= ldrtag) if (dirp->tag <= ldrtag+ISOHSIZE) continue; |
|---|
| 379 | iso_bmove(&isoxfs,1); |
|---|
| 380 | iso_bmove((unsigned char*)FIELDP(loop),DIRlen(loop)); |
|---|
| 381 | } |
|---|
| 382 | /* end of iso record */ |
|---|
| 383 | iso_bmove(&isoxfs,1); |
|---|
| 384 | iso_bmove(&isoxgs,1); |
|---|
| 385 | iso_break(iso_isfox); |
|---|
| 386 | return(iso_cards); |
|---|
| 387 | } |
|---|
| 388 | |
|---|
| 389 | #if CICPP |
|---|
| 390 | int ISO_2709 :: xiso_bmove(unsigned char *obuf, |
|---|
| 391 | unsigned obufsize) |
|---|
| 392 | #else |
|---|
| 393 | int iso_bmove(obuf,obufsize) |
|---|
| 394 | unsigned char *obuf; |
|---|
| 395 | unsigned obufsize; |
|---|
| 396 | #endif /* CICPP */ |
|---|
| 397 | { |
|---|
| 398 | unsigned char *p,*q; |
|---|
| 399 | if (obufsize > ISOBSIZ) |
|---|
| 400 | fatal( "iso_bmove/overflow"); |
|---|
| 401 | for (q=obuf; obufsize; ) { |
|---|
| 402 | #if TRAC0 |
|---|
| 403 | printf("iso_bmove - obufsize=%d\n",obufsize); |
|---|
| 404 | #endif |
|---|
| 405 | if (iso_bfree > 2) { |
|---|
| 406 | p = iso_buff + iso_bidx; *p++ = *q++; obufsize--; |
|---|
| 407 | iso_bfree--; iso_bidx++; iso_bfix--; |
|---|
| 408 | if (iso_bfix == 0) { |
|---|
| 409 | #if !MPE |
|---|
| 410 | #if CRLF |
|---|
| 411 | *p++ = '\r'; iso_bfree--; iso_bidx++; |
|---|
| 412 | #endif |
|---|
| 413 | *p = '\n'; iso_bfree--; iso_bidx++; |
|---|
| 414 | #endif |
|---|
| 415 | iso_bfix=iso_lrfox; |
|---|
| 416 | iso_cards++; |
|---|
| 417 | } |
|---|
| 418 | } |
|---|
| 419 | else { |
|---|
| 420 | #if TRACE |
|---|
| 421 | printf("iso_bmove - iso_bidx=%d\n",iso_bidx); |
|---|
| 422 | #endif |
|---|
| 423 | if (CIWRITE(iso_fd,iso_buff,iso_bidx) != iso_bidx) |
|---|
| 424 | fatal( "iso_bmove/write"); |
|---|
| 425 | iso_bfree=ISOBSIZ; |
|---|
| 426 | iso_bidx=0; |
|---|
| 427 | } |
|---|
| 428 | } |
|---|
| 429 | return(iso_cards); |
|---|
| 430 | } |
|---|
| 431 | |
|---|
| 432 | #if CICPP |
|---|
| 433 | int ISO_2709 :: xiso_break(int isfox) |
|---|
| 434 | #else |
|---|
| 435 | int iso_break(isfox) |
|---|
| 436 | int isfox; |
|---|
| 437 | #endif /* CICPP */ |
|---|
| 438 | { |
|---|
| 439 | if (iso_bidx) { |
|---|
| 440 | if (iso_bfix != iso_lrfox) { |
|---|
| 441 | #if TRACE |
|---|
| 442 | printf("iso_break - iso_bidx=%d\n",iso_bidx); |
|---|
| 443 | #endif |
|---|
| 444 | if (isfox >= 0) { /* AOT, 10/06/2005 */ |
|---|
| 445 | if (isfox) |
|---|
| 446 | while (iso_bfix--) |
|---|
| 447 | iso_buff[iso_bidx++]=' '; |
|---|
| 448 | #if !MPE |
|---|
| 449 | #if CRLF |
|---|
| 450 | iso_buff[iso_bidx++] = '\r'; |
|---|
| 451 | #endif |
|---|
| 452 | iso_buff[iso_bidx++] = '\n'; |
|---|
| 453 | #endif |
|---|
| 454 | } |
|---|
| 455 | iso_cards++; |
|---|
| 456 | } |
|---|
| 457 | #if TRACE |
|---|
| 458 | printf("iso_break - iso_bidx=%d\n",iso_bidx); |
|---|
| 459 | #endif |
|---|
| 460 | if (CIWRITE(iso_fd,iso_buff,iso_bidx) != iso_bidx) |
|---|
| 461 | fatal( "iso_break/write"); |
|---|
| 462 | iso_bfree=ISOBSIZ; |
|---|
| 463 | iso_bidx=0; |
|---|
| 464 | iso_bfix=iso_lrfox; |
|---|
| 465 | } |
|---|
| 466 | return(iso_cards); |
|---|
| 467 | } |
|---|
| 468 | |
|---|
| 469 | #if CICPP |
|---|
| 470 | int ISO_2709 :: xiso_close(void) |
|---|
| 471 | #else |
|---|
| 472 | #if ANSI |
|---|
| 473 | int iso_close(void) |
|---|
| 474 | #else |
|---|
| 475 | int iso_close() |
|---|
| 476 | #endif |
|---|
| 477 | #endif /* CICPP */ |
|---|
| 478 | { |
|---|
| 479 | int rc; |
|---|
| 480 | /* check previous iso_creat() */ |
|---|
| 481 | if (!iso_buff || iso_fd <= 0) |
|---|
| 482 | fatal( "iso_close/creat"); |
|---|
| 483 | #if CICPP |
|---|
| 484 | delete[] iso_buff; |
|---|
| 485 | #else |
|---|
| 486 | FREE(iso_buff); |
|---|
| 487 | #endif /* CICPP */ |
|---|
| 488 | iso_buff = NULL; |
|---|
| 489 | rc = CLOSE(iso_fd); iso_fd = 0; |
|---|
| 490 | return(rc); |
|---|
| 491 | } |
|---|
| 492 | |
|---|
| 493 | |
|---|
| 494 | /* -------------------------------- isi.c -------------------------------- */ |
|---|
| 495 | #if GEN_ISI |
|---|
| 496 | #define ISIBSIZ ISOBSIZ /* AOT, 10/06/2005 */ |
|---|
| 497 | |
|---|
| 498 | #if !CICPP |
|---|
| 499 | |
|---|
| 500 | #if !CICPP |
|---|
| 501 | UBYTE *isi_buffin = NULL; /* iso_loadbuff */ |
|---|
| 502 | int isi_fd = 0; /* iso_loadbuff */ |
|---|
| 503 | int isi_lrecb; /* iso_loadbuff */ |
|---|
| 504 | int isi_lrfix; /* iso_loadbuff */ |
|---|
| 505 | int isi_isfix; /* iso_loadbuff */ |
|---|
| 506 | LONGX isi_count; /* iso_loadbuff */ |
|---|
| 507 | #endif /* CICPP */ |
|---|
| 508 | |
|---|
| 509 | #define LENLEN 5 |
|---|
| 510 | #define LENTAG 3 |
|---|
| 511 | #define LENLEF 4 |
|---|
| 512 | #define LENSCP 5 |
|---|
| 513 | /* prototypes */ |
|---|
| 514 | #if ANSI |
|---|
| 515 | int iso_loadbuff(int opt); |
|---|
| 516 | int iso_getval(char *p, int n); |
|---|
| 517 | #else |
|---|
| 518 | int iso_loadbuff(); |
|---|
| 519 | int iso_getval(); |
|---|
| 520 | #endif |
|---|
| 521 | #endif /* !CICPP */ |
|---|
| 522 | |
|---|
| 523 | #if CICPP |
|---|
| 524 | int ISO_2709 :: xiso_open(char *gidbnp, |
|---|
| 525 | unsigned char filnam[], |
|---|
| 526 | int lrecb, |
|---|
| 527 | int lrfix, |
|---|
| 528 | int isfix) |
|---|
| 529 | #else |
|---|
| 530 | int iso_open(gidbnp,filnam,lrecb,lrfix,isfix) |
|---|
| 531 | char *gidbnp; |
|---|
| 532 | unsigned char filnam[]; |
|---|
| 533 | int lrecb; |
|---|
| 534 | int lrfix; |
|---|
| 535 | int isfix; |
|---|
| 536 | #endif /* CICPP */ |
|---|
| 537 | { |
|---|
| 538 | char *filnamp; |
|---|
| 539 | |
|---|
| 540 | /* open input file */ |
|---|
| 541 | filnamp=dbxcipar(gidbnp,(char *)filnam,'='); |
|---|
| 542 | isi_fd=OPEN(filnamp,O_RDONLY|O_BINARY); |
|---|
| 543 | if (isi_fd <= 0) { |
|---|
| 544 | fatal( filnamp); |
|---|
| 545 | return (isi_fd); /* mffunc.cpp */ |
|---|
| 546 | } |
|---|
| 547 | |
|---|
| 548 | /* allocate input buffer */ |
|---|
| 549 | #if CICPP |
|---|
| 550 | try {isi_buffin = (UBYTE *) new char [ISIBSIZ];} |
|---|
| 551 | catch (BAD_ALLOC){isi_buffin = (UBYTE *)ALLONULL;} |
|---|
| 552 | #else |
|---|
| 553 | isi_buffin=ALLOC((ALLOPARM)(ISIBSIZ)); |
|---|
| 554 | #endif /* CICPP */ |
|---|
| 555 | if (isi_buffin == (UBYTE *)ALLONULL) |
|---|
| 556 | fatal( "iso_open/ALLOC"); |
|---|
| 557 | |
|---|
| 558 | /* keep lrecb/lrfix/isfix */ |
|---|
| 559 | isi_lrecb = lrecb; |
|---|
| 560 | isi_lrfix = lrfix; |
|---|
| 561 | isi_isfix = isfix; |
|---|
| 562 | /* reset count */ |
|---|
| 563 | isi_count = 0L; |
|---|
| 564 | return(isi_fd); |
|---|
| 565 | } |
|---|
| 566 | |
|---|
| 567 | #if CICPP |
|---|
| 568 | int ISO_2709 :: xiso_read(RECSTRU * recp, unsigned int ldrtag) |
|---|
| 569 | #else |
|---|
| 570 | int iso_read(crec, irec, ldrtag) |
|---|
| 571 | LONGX crec; |
|---|
| 572 | LONGX irec; |
|---|
| 573 | unsigned int ldrtag; |
|---|
| 574 | #endif /* CICPP */ |
|---|
| 575 | { |
|---|
| 576 | #if !CICPP |
|---|
| 577 | RECSTRU *recp; |
|---|
| 578 | #endif /* CICPP */ |
|---|
| 579 | int n1,n,nvf,fld; |
|---|
| 580 | int tagfld,lenfld,locfld,basead,lenlef,lenscp; |
|---|
| 581 | UBYTE *buffup,*batchp,*p; |
|---|
| 582 | ISOHSTRU *isohp; |
|---|
| 583 | ISODSTRU *isodp; |
|---|
| 584 | #if ENABFLD |
|---|
| 585 | UBYTE c; |
|---|
| 586 | #endif |
|---|
| 587 | /* check previous iso_creat() */ |
|---|
| 588 | if (!isi_buffin || isi_fd <= 0) |
|---|
| 589 | fatal( "iso_read/open"); |
|---|
| 590 | /* set current MFR to irec */ |
|---|
| 591 | #if !CICPP |
|---|
| 592 | recp=vrecp[irec]; |
|---|
| 593 | #endif /* CICPP */ |
|---|
| 594 | /* allocate fldupdat() buffer */ |
|---|
| 595 | #if CICPP |
|---|
| 596 | try {buffup = (UBYTE *) new char [BUFFUPL];} |
|---|
| 597 | catch (BAD_ALLOC){buffup = (UBYTE *)ALLONULL;} |
|---|
| 598 | #else |
|---|
| 599 | buffup=ALLOC((ALLOPARM)(BUFFUPL)); |
|---|
| 600 | #endif /* CICPP */ |
|---|
| 601 | if (buffup == (UBYTE *)ALLONULL) |
|---|
| 602 | fatal( "iso_read/ALLOC"); |
|---|
| 603 | /* initialize iso_loadbuff and/or read next iso record */ |
|---|
| 604 | n1=iso_loadbuff((isi_count) ? LENLEN : 0 ); |
|---|
| 605 | |
|---|
| 606 | /* load it */ |
|---|
| 607 | if (n1 != EOF) { |
|---|
| 608 | isi_count++; |
|---|
| 609 | isohp= (ISOHSTRU *)isi_buffin; |
|---|
| 610 | #if TRACISI |
|---|
| 611 | printf("isi_buffin=%.60s\n",isi_buffin); |
|---|
| 612 | #endif |
|---|
| 613 | if (iso_getval((char *)isohp->length,LENLEN) != n1) |
|---|
| 614 | fatal( "iso2i/length"); |
|---|
| 615 | |
|---|
| 616 | basead=iso_getval((char *)isohp->basead,5); |
|---|
| 617 | lenlef=iso_getval((char *)isohp->lenlef,1); |
|---|
| 618 | |
|---|
| 619 | if (lenlef != LENLEF) fatal( "LENLEF"); |
|---|
| 620 | |
|---|
| 621 | lenscp=iso_getval((char *)isohp->lenscp,1); |
|---|
| 622 | |
|---|
| 623 | if (lenscp != LENSCP) |
|---|
| 624 | fatal( "LENSCP"); |
|---|
| 625 | nvf=(basead-ISOHSIZE-1)/(LENTAG+lenlef+lenscp); |
|---|
| 626 | #if ENABHDR |
|---|
| 627 | printf("iso %ld - isolen=%d base=%d lenlef=%d lenscp=%d nvf=%d\n", |
|---|
| 628 | isi_count,n1,basead,lenlef,lenscp,nvf); |
|---|
| 629 | #endif |
|---|
| 630 | #if BEFORE20000809 |
|---|
| 631 | if (nvf < 1) { |
|---|
| 632 | fprintf(stderr,"*** iso #%ld -> nvf=%d\n",isi_count,nvf); |
|---|
| 633 | fatal( "iso_read/nvf"); |
|---|
| 634 | } |
|---|
| 635 | #endif |
|---|
| 636 | isodp=(ISODSTRU *)(isi_buffin+ISOHSIZE); |
|---|
| 637 | batchp=buffup; |
|---|
| 638 | |
|---|
| 639 | #if MARC_BEFORE_20090311 |
|---|
| 640 | /* load leader data fields for MARC processing - AOT 11/06/2001 */ |
|---|
| 641 | #if 0 |
|---|
| 642 | byte 5 = Estado del registro |
|---|
| 643 | byte 6 = Tipo de registro |
|---|
| 644 | byte 7 = Nivel bibliogr�co |
|---|
| 645 | byte 8 = Tipo de control |
|---|
| 646 | byte 17 = Nivel de codificaci�yte 18 = Forma de catalogaci�yte 19 = Linked requirement |
|---|
| 647 | typedef struct isohstru { |
|---|
| 648 | unsigned char length[5]; |
|---|
| 649 | unsigned char status[1]; /* 5=Estado del registro */ |
|---|
| 650 | unsigned char icodes[4]; /* 6=Tipo de registro; 7=Nivel bibliogr�co; 8=Tipo de control; unused */ |
|---|
| 651 | unsigned char indlen[1]; |
|---|
| 652 | unsigned char sublen[1]; |
|---|
| 653 | unsigned char basead[5]; |
|---|
| 654 | unsigned char forusr[3]; /* 17=Nivel de codificaci�18=Forma de catalogaci�19=Linked requirement */ |
|---|
| 655 | #endif |
|---|
| 656 | if (ldrtag) { |
|---|
| 657 | sprintf((char *)batchp,"H%d 1 %c",ldrtag+5,isohp->status[0]); batchp+=strlen((const char *)batchp); |
|---|
| 658 | sprintf((char *)batchp,"H%d 1 %c",ldrtag+6,isohp->icodes[0]); batchp+=strlen((const char *)batchp); |
|---|
| 659 | sprintf((char *)batchp,"H%d 1 %c",ldrtag+7,isohp->icodes[1]); batchp+=strlen((const char *)batchp); |
|---|
| 660 | sprintf((char *)batchp,"H%d 1 %c",ldrtag+8,isohp->icodes[2]); batchp+=strlen((const char *)batchp); |
|---|
| 661 | sprintf((char *)batchp,"H%d 1 %c",ldrtag+17,isohp->forusr[0]); batchp+=strlen((const char *)batchp); |
|---|
| 662 | sprintf((char *)batchp,"H%d 1 %c",ldrtag+18,isohp->forusr[1]); batchp+=strlen((const char *)batchp); |
|---|
| 663 | sprintf((char *)batchp,"H%d 1 %c",ldrtag+19,isohp->forusr[2]); batchp+=strlen((const char *)batchp); |
|---|
| 664 | } |
|---|
| 665 | #else /* MARC_BEFORE_20090311 */ |
|---|
| 666 | /* |
|---|
| 667 | See http://www.itsmarc.com/crs/auth0669.htm |
|---|
| 668 | bytes 00-04 - Logical record length |
|---|
| 669 | byte 05 - Record status |
|---|
| 670 | byte 06 - Type of record |
|---|
| 671 | bytes 07-08 - Undefined |
|---|
| 672 | byte 09 - Character coding scheme |
|---|
| 673 | byte 10 - Indicator count |
|---|
| 674 | byte 11 - Subfield code length |
|---|
| 675 | bytes 12-16 - Base address of data |
|---|
| 676 | byte 17 - Encoding level |
|---|
| 677 | bytes 18-19 - Undefined |
|---|
| 678 | bytes 20-23 - Entry map |
|---|
| 679 | */ |
|---|
| 680 | if (ldrtag) { |
|---|
| 681 | if (iso_ismarc) { |
|---|
| 682 | sprintf((char *)batchp,"H%d 1 %c",ldrtag+5,isohp->status[0]); batchp+=strlen((const char *)batchp); |
|---|
| 683 | sprintf((char *)batchp,"H%d 1 %c",ldrtag+9,isohp->icodes[3]); batchp+=strlen((const char *)batchp); |
|---|
| 684 | sprintf((char *)batchp,"H%d 1 %c",ldrtag+17,isohp->forusr[0]); batchp+=strlen((const char *)batchp); |
|---|
| 685 | } else { |
|---|
| 686 | sprintf((char *)batchp,"H%d 1 %c",ldrtag+5,isohp->status[0]); batchp+=strlen((const char *)batchp); |
|---|
| 687 | sprintf((char *)batchp,"H%d 1 %c",ldrtag+6,isohp->icodes[0]); batchp+=strlen((const char *)batchp); |
|---|
| 688 | sprintf((char *)batchp,"H%d 1 %c",ldrtag+7,isohp->icodes[1]); batchp+=strlen((const char *)batchp); |
|---|
| 689 | sprintf((char *)batchp,"H%d 1 %c",ldrtag+8,isohp->icodes[2]); batchp+=strlen((const char *)batchp); |
|---|
| 690 | sprintf((char *)batchp,"H%d 1 %c",ldrtag+17,isohp->forusr[0]); batchp+=strlen((const char *)batchp); |
|---|
| 691 | sprintf((char *)batchp,"H%d 1 %c",ldrtag+18,isohp->forusr[1]); batchp+=strlen((const char *)batchp); |
|---|
| 692 | sprintf((char *)batchp,"H%d 1 %c",ldrtag+19,isohp->forusr[2]); batchp+=strlen((const char *)batchp); |
|---|
| 693 | } |
|---|
| 694 | } |
|---|
| 695 | #endif /* MARC_BEFORE_20090311 */ |
|---|
| 696 | |
|---|
| 697 | isodp=(ISODSTRU *)(isi_buffin+ISOHSIZE); |
|---|
| 698 | for (fld=1; fld <= nvf; fld++, isodp++) { |
|---|
| 699 | |
|---|
| 700 | tagfld=iso_getval((char *)isodp->tagfld,LENTAG); |
|---|
| 701 | lenfld=iso_getval((char *)isodp->lenfld,LENLEF); |
|---|
| 702 | locfld=iso_getval((char *)isodp->locfld,LENSCP); |
|---|
| 703 | |
|---|
| 704 | #if ENABDIR |
|---|
| 705 | printf("fld %d - tagfld=%d lenfld=%d locfld=%d '", |
|---|
| 706 | fld,tagfld,lenfld,locfld); |
|---|
| 707 | #if ENABFLD |
|---|
| 708 | for (p=isi_buffin+basead+locfld, n=lenfld; n--; p++) { |
|---|
| 709 | c= *p; |
|---|
| 710 | printf("%c",c); |
|---|
| 711 | } |
|---|
| 712 | #endif |
|---|
| 713 | printf("'\n"); |
|---|
| 714 | #endif |
|---|
| 715 | n=lenfld-1; |
|---|
| 716 | sprintf((char *)batchp,(CONST char *)"H%d %d ",tagfld,n); batchp+=strlen((CONST char *)batchp); |
|---|
| 717 | memcpy(batchp,isi_buffin+basead+locfld,n); batchp+=n; |
|---|
| 718 | } |
|---|
| 719 | *batchp = '\0'; |
|---|
| 720 | |
|---|
| 721 | /* get an empty record and add the fields */ |
|---|
| 722 | #if CICPP |
|---|
| 723 | #if 0 |
|---|
| 724 | recp->xrecord(crecp->recdbxp->dbxname,crecp->recmfp->m0.m0nxtmfn); |
|---|
| 725 | #else |
|---|
| 726 | memset(MFX,0x00,LEADER); |
|---|
| 727 | MFRmfn=1L; MFRmfrl=MFRbase=LEADER; |
|---|
| 728 | RECtype=TYPEMFR; |
|---|
| 729 | #endif /* 0 */ |
|---|
| 730 | #else |
|---|
| 731 | record(irec,VRDBname(crec),VMF0nxtmfn(crec)); |
|---|
| 732 | #endif /* CICPP */ |
|---|
| 733 | RECrc=RCNORMAL; |
|---|
| 734 | MFRstatus=ACTIVE; /* PDEL status is DELETED */ |
|---|
| 735 | #if CICPP |
|---|
| 736 | if ((p=(unsigned char *)recp->xfldupdat((char *)buffup)) != NULL) |
|---|
| 737 | #else |
|---|
| 738 | if ((p=fldupdat(irec,buffup)) != NULL) |
|---|
| 739 | #endif /* CICPP */ |
|---|
| 740 | fatal( (char *)p); |
|---|
| 741 | } |
|---|
| 742 | else iso_rclos(); /* End of File */ |
|---|
| 743 | |
|---|
| 744 | /* deallocate working area */ /* hb/aot 20010606 */ |
|---|
| 745 | #if CICPP |
|---|
| 746 | delete[] buffup; |
|---|
| 747 | #else |
|---|
| 748 | FREE(buffup); |
|---|
| 749 | #endif /* CICPP */ |
|---|
| 750 | |
|---|
| 751 | return (n1); |
|---|
| 752 | } |
|---|
| 753 | |
|---|
| 754 | #if CICPP |
|---|
| 755 | int ISO_2709 :: xiso_loadbuff(int opt) |
|---|
| 756 | #else |
|---|
| 757 | int iso_loadbuff(opt) |
|---|
| 758 | int opt; |
|---|
| 759 | #endif /* CICPP */ |
|---|
| 760 | { |
|---|
| 761 | int n,isolen,k,j,kj; |
|---|
| 762 | #if CRLF /* CRLF */ |
|---|
| 763 | int eorlen = 2; |
|---|
| 764 | #else /* LF */ |
|---|
| 765 | int eorlen = 1; |
|---|
| 766 | #endif |
|---|
| 767 | static char *nextbufp = NULL; |
|---|
| 768 | #if TRACISI |
|---|
| 769 | printf("0. lrecb,lrfix,isfix=%d,%d,%d\n",isi_lrecb,isi_lrfix,isi_isfix); |
|---|
| 770 | #endif |
|---|
| 771 | if (isi_isfix == (-1)) eorlen = 0; /* AOT, 10/06/2005 */ |
|---|
| 772 | if (opt == 0) { |
|---|
| 773 | n=CIREAD(isi_fd,isi_buffin,LENLEN); |
|---|
| 774 | if (n == 0) return(EOF); |
|---|
| 775 | if (n != LENLEN) fatal( "iso_loadbuff/LENLEN"); |
|---|
| 776 | #if TRACISI |
|---|
| 777 | isi_buffin[n]='\0'; |
|---|
| 778 | printf("1. '%s'\n",isi_buffin); |
|---|
| 779 | #endif |
|---|
| 780 | } |
|---|
| 781 | else { |
|---|
| 782 | if (!nextbufp) |
|---|
| 783 | return(EOF); |
|---|
| 784 | #if PC |
|---|
| 785 | if (*nextbufp == 0x1A) return(EOF); |
|---|
| 786 | #endif |
|---|
| 787 | memcpy(isi_buffin,nextbufp,LENLEN); |
|---|
| 788 | #if TRACISI |
|---|
| 789 | isi_buffin[LENLEN]='\0'; |
|---|
| 790 | printf("2. '%s'\n",isi_buffin); |
|---|
| 791 | #endif |
|---|
| 792 | } |
|---|
| 793 | isolen=iso_getval((char *)isi_buffin,LENLEN); |
|---|
| 794 | if (isi_lrecb) /* BINARY */ |
|---|
| 795 | k = (isolen+isi_lrecb-1)/isi_lrecb * isi_lrecb; |
|---|
| 796 | else /* [CR]LF */ |
|---|
| 797 | k = isolen + (isolen+isi_lrfix-1)/isi_lrfix*eorlen; |
|---|
| 798 | kj=k; |
|---|
| 799 | if (isi_isfix > 0) { /* AOT, 10/06/2005 */ |
|---|
| 800 | j = isi_lrfix - (isolen % isi_lrfix); |
|---|
| 801 | if (j == isi_lrfix) j=0; |
|---|
| 802 | kj = k+j; |
|---|
| 803 | #if TRACISI |
|---|
| 804 | printf("isolen,k,j,kj=%d,%d,%d,%d\n",isolen,k,j,kj); |
|---|
| 805 | #endif |
|---|
| 806 | } |
|---|
| 807 | if (isolen < ISOHSIZE) { |
|---|
| 808 | fprintf(stderr,"*** iso #%ld -> len=%d\n",isi_count,isolen); |
|---|
| 809 | fatal( "iso_loadbuff/isolen/ISOHSIZE"); |
|---|
| 810 | } |
|---|
| 811 | if (kj+LENLEN > ISIBSIZ) { |
|---|
| 812 | fprintf(stderr,"*** iso #%ld -> len=%d\n",isi_count,isolen); |
|---|
| 813 | fatal( "iso_loadbuff/isolen/overflow"); |
|---|
| 814 | } |
|---|
| 815 | n=CIREAD(isi_fd,isi_buffin+LENLEN,kj); |
|---|
| 816 | if (n == kj) { |
|---|
| 817 | nextbufp=(char *)isi_buffin+kj; |
|---|
| 818 | } |
|---|
| 819 | else { |
|---|
| 820 | #if CRLF |
|---|
| 821 | if ( LENLEN+n == kj || (LENLEN+n == kj+1 && isi_buffin[kj] == 0x1A) ) |
|---|
| 822 | #else |
|---|
| 823 | if ( LENLEN+n == kj ) |
|---|
| 824 | #endif |
|---|
| 825 | ; |
|---|
| 826 | else { |
|---|
| 827 | fprintf(stderr, |
|---|
| 828 | "*** iso #%ld -> %d n=%d kj=%d \n",isi_count,isolen,n,kj); |
|---|
| 829 | fatal( "iso_loadbuff/kj"); |
|---|
| 830 | } |
|---|
| 831 | nextbufp=NULL; |
|---|
| 832 | n=kj; |
|---|
| 833 | } |
|---|
| 834 | #if TRACISI |
|---|
| 835 | printf("n=%d \n",n); |
|---|
| 836 | #endif |
|---|
| 837 | |
|---|
| 838 | if (!isi_lrecb) { /* Not BINARY */ |
|---|
| 839 | for (k=isi_lrfix; k < n; ) |
|---|
| 840 | #if CRLF |
|---|
| 841 | if (isi_buffin[k] == '\r') { |
|---|
| 842 | if (isi_buffin[k+1] == '\n') { |
|---|
| 843 | j=n-k-2; |
|---|
| 844 | #if TRACISI |
|---|
| 845 | printf("n=%d k=%d moving %d \n",n,k,j); |
|---|
| 846 | #endif |
|---|
| 847 | memcpy(isi_buffin+k,isi_buffin+k+2,j); |
|---|
| 848 | k+=isi_lrfix; n-=2; |
|---|
| 849 | } |
|---|
| 850 | } |
|---|
| 851 | #else |
|---|
| 852 | if (isi_buffin[k] == '\n') { |
|---|
| 853 | j=n-k-1; |
|---|
| 854 | memcpy(isi_buffin+k,isi_buffin+k+1,j); |
|---|
| 855 | k+=isi_lrfix; n-=1; |
|---|
| 856 | } |
|---|
| 857 | #endif |
|---|
| 858 | else |
|---|
| 859 | break; |
|---|
| 860 | } |
|---|
| 861 | return(isolen); |
|---|
| 862 | } |
|---|
| 863 | |
|---|
| 864 | #if CICPP |
|---|
| 865 | int ISO_2709 :: xiso_getval(char *p, |
|---|
| 866 | int n) |
|---|
| 867 | #else |
|---|
| 868 | int iso_getval(p,n) /* |
|---|
| 869 | ----------- */ |
|---|
| 870 | char *p; |
|---|
| 871 | int n; |
|---|
| 872 | #endif /* CICPP */ |
|---|
| 873 | { |
|---|
| 874 | unsigned char *q; |
|---|
| 875 | int loop,result; |
|---|
| 876 | for (result=0, q=(unsigned char *)p, loop=n; loop--; q++) { |
|---|
| 877 | if (!(isdigit(*q))) |
|---|
| 878 | fatal( "iso_getval"); |
|---|
| 879 | result=result*10+(*q-'0'); |
|---|
| 880 | } |
|---|
| 881 | return(result); |
|---|
| 882 | } |
|---|
| 883 | #endif /* GEN_ISI */ |
|---|
| 884 | |
|---|
| 885 | #if CICPP |
|---|
| 886 | int ISO_2709 :: xiso_rclos(void) |
|---|
| 887 | #else |
|---|
| 888 | #if ANSI |
|---|
| 889 | int iso_rclos(void) |
|---|
| 890 | #else |
|---|
| 891 | int iso_rclos() |
|---|
| 892 | #endif |
|---|
| 893 | #endif /* CICPP */ |
|---|
| 894 | { |
|---|
| 895 | int rc; |
|---|
| 896 | /* check previous iso_open() */ |
|---|
| 897 | if (!isi_buffin || isi_fd <= 0) |
|---|
| 898 | fatal("iso_rclos/creat"); |
|---|
| 899 | #if CICPP |
|---|
| 900 | delete[] isi_buffin; |
|---|
| 901 | #else |
|---|
| 902 | FREE(isi_buffin); |
|---|
| 903 | #endif /* CICPP */ |
|---|
| 904 | isi_buffin = NULL; |
|---|
| 905 | rc = CLOSE(isi_fd); isi_fd = 0; |
|---|
| 906 | /* reset count */ |
|---|
| 907 | isi_count = 0L; |
|---|
| 908 | return(rc); |
|---|
| 909 | } |
|---|