From 1a660e3e4c72af665e8c76f6abe240493c942e9b Mon Sep 17 00:00:00 2001 From: kio-watatanabe Date: Wed, 11 Jan 2023 09:25:13 +0900 Subject: [PATCH 1/3] Fix CobolFile.java --- .../opensourcecobol/libcobj/file/CobolFile.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/libcobj/src/jp/osscons/opensourcecobol/libcobj/file/CobolFile.java b/libcobj/src/jp/osscons/opensourcecobol/libcobj/file/CobolFile.java index 236a7ac1..b96c4ab1 100644 --- a/libcobj/src/jp/osscons/opensourcecobol/libcobj/file/CobolFile.java +++ b/libcobj/src/jp/osscons/opensourcecobol/libcobj/file/CobolFile.java @@ -688,8 +688,8 @@ public void open(int mode, int sharing, AbstractCobolField fnstatus) { was_not_exist = true; if (mode != COB_OPEN_OUTPUT && !this.flag_optional - && (mode != COB_OPEN_I_O || System.getenv(COB_IO_CREATES).equals("yes")) - && (mode != COB_OPEN_EXTEND || System.getenv(COB_EXTEND_CREATES).equals("yes"))) { + && (mode != COB_OPEN_I_O || !System.getenv(COB_IO_CREATES).equals("yes")) + && (mode != COB_OPEN_EXTEND || !System.getenv(COB_EXTEND_CREATES).equals("yes"))) { saveStatus(COB_STATUS_35_NOT_EXISTS, fnstatus); return; } @@ -707,6 +707,13 @@ public void open(int mode, int sharing, AbstractCobolField fnstatus) { cacheFile(this); try { + + if (this.organization == COB_ORG_INDEXED) { + int status = this.open_(file_open_name, mode, sharing); + saveStatus(status, fnstatus); + return; + } + switch (this.open_(file_open_name, mode, sharing)) { case 0: this.open_mode = (char) mode; From b878a5f334ef2ee4fbea72f15cd8802a9cf6bbc9 Mon Sep 17 00:00:00 2001 From: kio-watatanabe Date: Wed, 11 Jan 2023 10:38:56 +0900 Subject: [PATCH 2/3] Fix CobolFile.java --- .../libcobj/file/CobolFile.java | 68 ++++++++----------- 1 file changed, 30 insertions(+), 38 deletions(-) diff --git a/libcobj/src/jp/osscons/opensourcecobol/libcobj/file/CobolFile.java b/libcobj/src/jp/osscons/opensourcecobol/libcobj/file/CobolFile.java index b96c4ab1..a6d6bc19 100644 --- a/libcobj/src/jp/osscons/opensourcecobol/libcobj/file/CobolFile.java +++ b/libcobj/src/jp/osscons/opensourcecobol/libcobj/file/CobolFile.java @@ -165,7 +165,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; @@ -174,16 +174,16 @@ public class CobolFile { private static List file_cache = new ArrayList(); 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 }; protected String select_name; public byte[] file_status; @@ -229,7 +229,8 @@ public void setLinorkeyptr(Linage ptr) { this.linorkeyptr = ptr; } - public CobolFile() {} + public CobolFile() { + } public CobolFile( String select_name, @@ -286,7 +287,8 @@ public CobolFile( } /** - * libcob/fileio.cのsave_statusの実装 RETURN_STATUSマクロは実装できないため,本メソッドの呼び出し後の次の文はreturn;を書くこと. + * libcob/fileio.cのsave_statusの実装 + * RETURN_STATUSマクロは実装できないため,本メソッドの呼び出し後の次の文はreturn;を書くこと. * * @param status * @param fnstatus @@ -707,13 +709,6 @@ public void open(int mode, int sharing, AbstractCobolField fnstatus) { cacheFile(this); try { - - if (this.organization == COB_ORG_INDEXED) { - int status = this.open_(file_open_name, mode, sharing); - saveStatus(status, fnstatus); - return; - } - switch (this.open_(file_open_name, mode, sharing)) { case 0: this.open_mode = (char) mode; @@ -778,25 +773,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; } } catch (IOException e) { @@ -1100,8 +1092,7 @@ public void write(AbstractCobolField rec, int opt, AbstractCobolField fnstatus) } String openMode = String.format("%02d", (int) 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; } @@ -1275,7 +1266,8 @@ public void unlock(AbstractCobolField fnstatus) { public void unlock_() { if (this.open_mode != COB_OPEN_CLOSED && this.open_mode != COB_OPEN_LOCKED) { this.file.flush(); - if ((this.lock_mode & COB_LOCK_EXCLUSIVE) == 0) {} + if ((this.lock_mode & COB_LOCK_EXCLUSIVE) == 0) { + } } } From 8f509cd9e928fd0d5104e4489bf114162ef48c67 Mon Sep 17 00:00:00 2001 From: kio-watatanabe Date: Wed, 11 Jan 2023 10:40:33 +0900 Subject: [PATCH 3/3] Fix CobolFile.java --- .../libcobj/file/CobolFile.java | 61 ++++++++++--------- 1 file changed, 31 insertions(+), 30 deletions(-) diff --git a/libcobj/src/jp/osscons/opensourcecobol/libcobj/file/CobolFile.java b/libcobj/src/jp/osscons/opensourcecobol/libcobj/file/CobolFile.java index a6d6bc19..b78ef712 100644 --- a/libcobj/src/jp/osscons/opensourcecobol/libcobj/file/CobolFile.java +++ b/libcobj/src/jp/osscons/opensourcecobol/libcobj/file/CobolFile.java @@ -165,7 +165,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; @@ -174,16 +174,16 @@ public class CobolFile { private static List file_cache = new ArrayList(); 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 }; protected String select_name; public byte[] file_status; @@ -229,8 +229,7 @@ public void setLinorkeyptr(Linage ptr) { this.linorkeyptr = ptr; } - public CobolFile() { - } + public CobolFile() {} public CobolFile( String select_name, @@ -287,8 +286,7 @@ public CobolFile( } /** - * libcob/fileio.cのsave_statusの実装 - * RETURN_STATUSマクロは実装できないため,本メソッドの呼び出し後の次の文はreturn;を書くこと. + * libcob/fileio.cのsave_statusの実装 RETURN_STATUSマクロは実装できないため,本メソッドの呼び出し後の次の文はreturn;を書くこと. * * @param status * @param fnstatus @@ -773,22 +771,25 @@ 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; } } catch (IOException e) { @@ -1092,7 +1093,8 @@ public void write(AbstractCobolField rec, int opt, AbstractCobolField fnstatus) } String openMode = String.format("%02d", (int) 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; } @@ -1266,8 +1268,7 @@ public void unlock(AbstractCobolField fnstatus) { public void unlock_() { if (this.open_mode != COB_OPEN_CLOSED && this.open_mode != COB_OPEN_LOCKED) { this.file.flush(); - if ((this.lock_mode & COB_LOCK_EXCLUSIVE) == 0) { - } + if ((this.lock_mode & COB_LOCK_EXCLUSIVE) == 0) {} } }