root/tags/5.4.pre05/ciiso.c @ 1

Revision 1, 21.4 kB (checked in by heitor.barbieri, 2 years ago)

Criação do svn para Cisis.

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