I was trying to open multiple files using same but when I loop to second file, old FCD structure is returned.
I made changes to find_fcd function:
static FCD3 *
find_fcd (cob_file *f, int free_fcd)
{
FCD3 *fcd;
struct fcd_file *ff;
/* Change Start */
int fileNameLen=0;
while(((cob_field *)f->assign)->data[fileNameLen] != 32){
if(fileNameLen >= ((cob_field *)f->assign)->size) break;
fileNameLen++;
}
for (ff = fcd_file_list; ff; ff=ff->next) {
if (memcmp(((cob_field *)f->assign)->data,ff->fcd->fnamePtr,fileNameLen)==0) {
/* Change End */
if (free_fcd == -1) {
ff->free_fcd = -1;
}
return ff->fcd;
}
}
fcd = cob_cache_malloc (sizeof (FCD3));
copy_file_to_fcd (f, fcd);
ff = cob_cache_malloc (sizeof (struct fcd_file));
ff->next = fcd_file_list;
ff->fcd = fcd;
ff->f = f;
ff->free_fcd = free_fcd;
fcd_file_list = ff;
return fcd;
}
Also cob_file structure should be initialized in the cob_extfh functions but for now I only added one initialization statement:
void
cob_extfh_open (
int (*callfh)(unsigned char *opcode, FCD3 *fcd),
cob_file *f, const int mode, const int sharing, cob_field *fnstatus)
{
unsigned char opcode[2];
FCD3 *fcd;
int sts;
COB_UNUSED (sharing);
f->open_mode = 0; /* Change 01 */
fcd = find_fcd (f, 1);
f->last_open_mode = (unsigned char)mode;
if (mode == COB_OPEN_OUTPUT)
STCOMPX2(OP_OPEN_OUTPUT, opcode);
else if (mode == COB_OPEN_I_O)
STCOMPX2(OP_OPEN_IO, opcode);
else if (mode == COB_OPEN_EXTEND)
STCOMPX2(OP_OPEN_EXTEND, opcode);
else
STCOMPX2(OP_OPEN_INPUT, opcode);
/* Keep table of 'fcd' created */
sts = callfh (opcode, fcd);
if (f->file_status) {
if (memcmp(f->file_status,"00",2) == 0
|| memcmp(f->file_status,"05",2) == 0) {
fcd->openMode &= ~OPEN_NOT_OPEN;
}
} else {
fcd->openMode &= ~OPEN_NOT_OPEN;
}
update_fcd_to_file (fcd, f, fnstatus, 1);
save_fcd_status (fcd, sts);
}
I added the above changes in GnuCobol compiler code and is running fine.