Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 15 additions & 22 deletions cobj/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -4012,13 +4012,20 @@ static void joutput_file_initialization(struct cb_file *f) {
joutput_line (" byte_%s%s[i] = '0;'");
joutput_line ("}");
}*/
if (f->external) {
joutput_line("%s%s = CobolFile.getExternalFile(\"%s\");", CB_PREFIX_FILE,
f->cname, f->cname);
joutput_line("if(%s%s == null) {", CB_PREFIX_FILE, f->cname);
joutput_indent_level += 2;
}

joutput_line("%s%s = CobolFileFactory.makeCobolFileInstance(", CB_PREFIX_FILE,
f->cname);
joutput_line("/* select_name = */ \"%s\",", f->name);
if (f->external && !f->file_status) {
joutput_line("/* file_status = */ cob_external_addr (\"%s%s_status\", 4),",
CB_PREFIX_FILE, f->cname);
joutput_line("/* file_status = */ CobolFile.getExternalFileStatus "
"(\"%s\"),",
f->cname);
} else {
joutput_line("/* file_status = */ %s%s_status,", CB_PREFIX_FILE, f->cname);
}
Expand Down Expand Up @@ -4076,26 +4083,15 @@ static void joutput_file_initialization(struct cb_file *f) {
joutput_line(");");

if (f->external) {
// joutput_line ("%s%s = CobolExternal.getFileAddress (\"%s\");",
// CB_PREFIX_FILE, f->cname, f->cname);
joutput_line("if (CobolExternal.initialExternal)");
joutput_indent("{");
if (f->linage) {
joutput_line("%s%s.setLinorkeyptr(new Linage());", CB_PREFIX_FILE,
f->cname);
}
} else {
// joutput_line ("if (%s%s == null)", CB_PREFIX_FILE, f->cname);
// joutput_indent ("{");
// joutput_line ("%s%s = new CobolFile();", CB_PREFIX_FILE, f->cname);
if (f->linage) {
joutput_line("%s%s.setLinorkeyptr(new Linage());", CB_PREFIX_FILE,
f->cname);
}
// joutput_indent ("}");
joutput_line("CobolFile.putExternalFile(\"%s\", %s%s);", f->cname,
CB_PREFIX_FILE, f->cname);
joutput_indent_level -= 2;
joutput_line("}");
}

if (f->linage) {
joutput_line("%s%s.setLinorkeyptr(new Linage());", CB_PREFIX_FILE,
f->cname);
joutput_line("lingptr = (Linage)(%s%s.getLinorkeyptr());", CB_PREFIX_FILE,
f->cname);
joutput_prefix();
Expand Down Expand Up @@ -4135,9 +4131,6 @@ static void joutput_file_initialization(struct cb_file *f) {
joutput_line("lingptr.setLinTop(0);");
joutput_line("lingptr.setLinBot(0);");
}
if (f->external) {
joutput_indent("}");
}
}

/*
Expand Down
86 changes: 54 additions & 32 deletions libcobj/src/jp/osscons/opensourcecobol/libcobj/file/CobolFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
import java.nio.file.StandardOpenOption;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import jp.osscons.opensourcecobol.libcobj.common.CobolModule;
import jp.osscons.opensourcecobol.libcobj.common.CobolUtil;
import jp.osscons.opensourcecobol.libcobj.data.AbstractCobolField;
Expand Down Expand Up @@ -164,7 +166,7 @@ public class CobolFile {
protected static String file_open_name;
protected static byte[] file_open_buff = new byte[1024];

protected static final String[] prefix = {"DD_", "dd_", ""};
protected static final String[] prefix = { "DD_", "dd_", "" };
protected static final int NUM_PREFIX = prefix.length;

protected static int eop_status = 0;
Expand All @@ -173,16 +175,16 @@ public class CobolFile {
private static List<CobolFile> file_cache = new ArrayList<CobolFile>();

protected static int[] status_exception = {
0,
CobolExceptionId.COB_EC_I_O_AT_END,
CobolExceptionId.COB_EC_I_O_INVALID_KEY,
CobolExceptionId.COB_EC_I_O_PERMANENT_ERROR,
CobolExceptionId.COB_EC_I_O_LOGIC_ERROR,
CobolExceptionId.COB_EC_I_O_RECORD_OPERATION,
CobolExceptionId.COB_EC_I_O_FILE_SHARING,
CobolExceptionId.COB_EC_I_O,
CobolExceptionId.COB_EC_I_O,
CobolExceptionId.COB_EC_I_O_IMP
0,
CobolExceptionId.COB_EC_I_O_AT_END,
CobolExceptionId.COB_EC_I_O_INVALID_KEY,
CobolExceptionId.COB_EC_I_O_PERMANENT_ERROR,
CobolExceptionId.COB_EC_I_O_LOGIC_ERROR,
CobolExceptionId.COB_EC_I_O_RECORD_OPERATION,
CobolExceptionId.COB_EC_I_O_FILE_SHARING,
CobolExceptionId.COB_EC_I_O,
CobolExceptionId.COB_EC_I_O,
CobolExceptionId.COB_EC_I_O_IMP
};
public String select_name;
public byte[] file_status;
Expand Down Expand Up @@ -230,7 +232,8 @@ public void setLinorkeyptr(Linage ptr) {
this.linorkeyptr = ptr;
}

public CobolFile() {}
public CobolFile() {
}

public CobolFile(
String selectName,
Expand Down Expand Up @@ -287,7 +290,8 @@ public CobolFile(
}

/**
* libcob/fileio.cのsave_statusの実装 RETURN_STATUSマクロは実装できないため,本メソッドの呼び出し後の次の文はreturn;を書くこと.
* libcob/fileio.cのsave_statusの実装
* RETURN_STATUSマクロは実装できないため,本メソッドの呼び出し後の次の文はreturn;を書くこと.
*
* @param status
* @param fnstatus
Expand Down Expand Up @@ -351,8 +355,7 @@ protected boolean file_linage_check() {
Linage lingptr = getLinorkeyptr();
lingptr.setLinLines(lingptr.getLinage().getInt());

outer:
{
outer: {
if (lingptr.getLinLines() < 1) {
break outer;
}
Expand Down Expand Up @@ -765,25 +768,22 @@ public int open_(String filename, int mode, int sharing) throws IOException {
fp = FileChannel.open(Paths.get(filename), StandardOpenOption.READ);
break;
case COB_OPEN_OUTPUT:
fp =
FileChannel.open(
Paths.get(filename),
StandardOpenOption.WRITE,
StandardOpenOption.CREATE,
StandardOpenOption.TRUNCATE_EXISTING);
fp = FileChannel.open(
Paths.get(filename),
StandardOpenOption.WRITE,
StandardOpenOption.CREATE,
StandardOpenOption.TRUNCATE_EXISTING);
break;
case COB_OPEN_I_O:
fp =
FileChannel.open(
Paths.get(filename),
StandardOpenOption.READ,
StandardOpenOption.WRITE,
StandardOpenOption.CREATE);
fp = FileChannel.open(
Paths.get(filename),
StandardOpenOption.READ,
StandardOpenOption.WRITE,
StandardOpenOption.CREATE);
break;
case COB_OPEN_EXTEND:
fp =
FileChannel.open(
Paths.get(filename), StandardOpenOption.APPEND, StandardOpenOption.CREATE);
fp = FileChannel.open(
Paths.get(filename), StandardOpenOption.APPEND, StandardOpenOption.CREATE);
break;
default:
break;
Expand Down Expand Up @@ -1073,8 +1073,7 @@ public void write(AbstractCobolField rec, int opt, AbstractCobolField fnstatus)
}

String openMode = openModeToString(this.last_open_mode);
if (invokeFun(COB_IO_WRITE, this, null, rec.getDataStorage(), fnstatus, openMode, null, null)
!= 0) {
if (invokeFun(COB_IO_WRITE, this, null, rec.getDataStorage(), fnstatus, openMode, null, null) != 0) {
return;
}

Expand Down Expand Up @@ -1532,4 +1531,27 @@ public byte[] getFileStatus() {
// CobolFile cobolFile = new CobolFile();
return this.file_status;
}

private static Map<String, byte[]> externalFileStatusTable = new HashMap<String, byte[]>();

public static byte[] getExternalFileStatus(String key) {
byte[] bytes = externalFileStatusTable.get(key);
if (bytes == null) {
bytes = new byte[2];
bytes[0] = 0;
bytes[1] = 0;
externalFileStatusTable.put(key, bytes);
}
return bytes;
}

private static Map<String, CobolFile> externalFileTable = new HashMap<String, CobolFile>();

public static CobolFile getExternalFile(String key) {
return externalFileTable.get(key);
}

public static CobolFile putExternalFile(String key, CobolFile value) {
return externalFileTable.put(key, value);
}
}
3 changes: 2 additions & 1 deletion tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ misc_DEPENDENCIES = \
misc.src/version-string-in-java.at \
misc.src/comp3-compute.at \
misc.src/index-file-status.at \
misc.src/comp-n.at
misc.src/comp-n.at \
misc.src/fd-external.at


EXTRA_DIST = $(srcdir)/package.m4 \
Expand Down
3 changes: 2 additions & 1 deletion tests/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,8 @@ misc_DEPENDENCIES = \
misc.src/version-string-in-java.at \
misc.src/comp3-compute.at \
misc.src/index-file-status.at \
misc.src/comp-n.at
misc.src/comp-n.at \
misc.src/fd-external.at

EXTRA_DIST = $(srcdir)/package.m4 \
$(TESTS) \
Expand Down
3 changes: 2 additions & 1 deletion tests/misc.at
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ m4_include([exit-perform-cycle.at])
m4_include([version-string-in-java.at])
m4_include([comp3-compute.at])
m4_include([index-file-status.at])
m4_include([comp-n.at])
m4_include([comp-n.at])
m4_include([fd-external.at])
68 changes: 68 additions & 0 deletions tests/misc.src/fd-external.at
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
AT_SETUP([FD EXTERNAL])

AT_DATA([prog.cbl], [
identification division.
program-id. prog.
environment division.
input-output section.
file-control.
select sequential-file assign to "sequential.txt"
organization is sequential
file status is sequential-file-status.
data division.
file section.
fd sequential-file is external.
01 sequential-file-rec pic x(20).
working-storage section.
01 sequential-file-status pic 99.
01 command pic x(20).
procedure division.
main-rtn.
open output sequential-file.
move "seq-data" to sequential-file-rec.
move "write-sequential" to command.
call "sub" using command.
close sequential-file.

open input sequential-file.
move space to sequential-file-rec.
move "read-sequential" to command.
call "sub" using command.
display "sequential-file-rec:" sequential-file-rec.
close sequential-file.

])

AT_DATA([sub.cbl], [
identification division.
program-id. sub.
environment division.
input-output section.
file-control.
select sequential-file assign to "sequential.txt"
organization is sequential
file status is sequential-file-status.
data division.
file section.
fd sequential-file is external.
01 sequential-file-rec pic x(20).
working-storage section.
01 sequential-file-status pic 99.
linkage section.
01 command pic x(20).
procedure division using command.
main-rtn.
evaluate command
when "read-sequential"
read sequential-file
when "write-sequential"
write sequential-file-rec
end-evaluate.
])

AT_CHECK([${COBJ} prog.cbl sub.cbl])
AT_CHECK([java prog], [0],
[sequential-file-rec:seq-data @&t@
])

AT_CLEANUP