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
Original file line number Diff line number Diff line change
Expand Up @@ -2028,4 +2028,25 @@ public static AbstractCobolField funcExceptionStatus() {
}
return currField;
}

/**
* cob_intr_fraction_partの実装
*
* @param srcfield
* @return
*/
public static AbstractCobolField funcFractionPart(AbstractCobolField srcfield) {
CobolFieldAttribute attr =
new CobolFieldAttribute(
CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY,
18,
18,
CobolFieldAttribute.COB_FLAG_HAVE_SIGN,
null);
AbstractCobolField field = CobolFieldFactory.makeCobolField(8, (CobolDataStorage) null, attr);
makeFieldEntry(field);

currField.moveFrom(srcfield);
return currField;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,7 @@ public byte[] getBytes() {

@Override
public String getString() {
CobolFieldAttribute thisAttr = this.getAttribute();
int flag = thisAttr.isFlagHaveSign() ? CobolFieldAttribute.COB_FLAG_HAVE_SIGN : 0;
CobolFieldAttribute attr =
new CobolFieldAttribute(
CobolFieldAttribute.COB_TYPE_NUMERIC,
thisAttr.getDigits(),
thisAttr.getScale(),
flag,
thisAttr.getPic());
CobolDataStorage storage = new CobolDataStorage(thisAttr.getDigits());
CobolNumericField numericField = new CobolNumericField(thisAttr.getDigits(), storage, attr);
numericField.moveFrom(this);
return numericField.getString();
return String.format("%.18f", this.getDouble());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,17 +382,15 @@ private void moveBinaryToDisplay(AbstractCobolField field) {

private void moveDoubleToDisplay(AbstractCobolField field) {
CobolFieldAttribute thisAttr = this.getAttribute();
double val = Math.abs(field.getDouble() * thisAttr.getScale());
String formatter = "%0" + thisAttr.getDigits() + "." + thisAttr.getScale() + "f";
String valString = String.format(formatter, val).replace(".", "");
double val = Math.abs(field.getDouble());
int startIndex = 0;
if (thisAttr.isFlagHaveSign()
&& thisAttr.isFlagSignLeading()
&& thisAttr.isFlagSignSeparate()) {
startIndex = 1;
}
CobolDataStorage dstStorage = this.getDataStorage().getSubDataStorage(startIndex);
dstStorage.memcpy(valString, thisAttr.getDigits());
dstStorage.memcpy(String.valueOf(val), thisAttr.getDigits());
this.putSign(field.getSign() >= 0 ? 1 : -1);
}

Expand Down
61 changes: 32 additions & 29 deletions libcobj/src/jp/osscons/opensourcecobol/libcobj/file/CobolFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,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 @@ -175,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 @@ -232,8 +232,7 @@ public void setLinorkeyptr(Linage ptr) {
this.linorkeyptr = ptr;
}

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

public CobolFile(
String selectName,
Expand Down Expand Up @@ -290,8 +289,7 @@ 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 @@ -355,7 +353,8 @@ 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 @@ -768,22 +767,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;
default:
break;
Expand Down Expand Up @@ -1073,7 +1075,8 @@ 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
44 changes: 41 additions & 3 deletions tests/run.src/functions.at
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,6 @@ AT_CHECK([java prog], [0],
AT_CLEANUP

AT_SETUP([FUNCTION FRACTION-PART])
AT_CHECK([${SKIP_TEST}])

AT_DATA([prog.cob], [
IDENTIFICATION DIVISION.
Expand Down Expand Up @@ -1035,8 +1034,7 @@ AT_CHECK([java prog], [0],

AT_CLEANUP

AT_SETUP([FUNCTION MIDRANGE])
AT_CHECK([${SKIP_TEST}])
AT_SETUP([FUNCTION MIDRANGE(calculation result is negative)])

AT_DATA([prog.cob], [
IDENTIFICATION DIVISION.
Expand All @@ -1056,6 +1054,46 @@ AT_CHECK([java prog], [0],

AT_CLEANUP

AT_SETUP([FUNCTION MIDRANGE(calculation result is positive)])

AT_DATA([prog.cob], [
IDENTIFICATION DIVISION.
PROGRAM-ID. prog.
DATA DIVISION.
WORKING-STORAGE SECTION.
PROCEDURE DIVISION.
DISPLAY FUNCTION MIDRANGE ( 3 14 0 8 3 )
END-DISPLAY.
STOP RUN.
])

AT_CHECK([${COMPILE} prog.cob])
AT_CHECK([java prog], [0],
[7.000000000000000000
])

AT_CLEANUP

AT_SETUP([FUNCTION MIDRANGE(calculation result is decimal)])

AT_DATA([prog.cob], [
IDENTIFICATION DIVISION.
PROGRAM-ID. prog.
DATA DIVISION.
WORKING-STORAGE SECTION.
PROCEDURE DIVISION.
DISPLAY FUNCTION MIDRANGE ( 2 2 3 9 )
END-DISPLAY.
STOP RUN.
])

AT_CHECK([${COMPILE} prog.cob])
AT_CHECK([java prog], [0],
[5.500000000000000000
])

AT_CLEANUP

AT_SETUP([FUNCTION MIN])

AT_DATA([prog.cob], [
Expand Down