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
2 changes: 1 addition & 1 deletion cobj/system.def
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ COB_SYSTEM_GEN ("C$JUSTIFY", 1, cob_acuw_justify)
COB_SYSTEM_GEN ("C$CALLEDBY", 1, calledBy)
COB_SYSTEM_GEN ("C$MAKEDIR", 1, cob_acuw_mkdir)
COB_SYSTEM_GEN ("C$NARG", 1, cob_return_args)
COB_SYSTEM_GEN ("C$SLEEP", 1, cob_acuw_sleep)
COB_SYSTEM_GEN ("C$SLEEP", 1, C$SLEEP)
COB_SYSTEM_GEN ("C$PARAMSIZE", 1, cob_parameter_size)
COB_SYSTEM_GEN ("C$TOUPPER", 2, CBL_TOUPPER)
COB_SYSTEM_GEN ("C$TOLOWER", 2, CBL_TOLOWER)
Expand Down
1 change: 0 additions & 1 deletion cobj/typeck.c
Original file line number Diff line number Diff line change
Expand Up @@ -3130,7 +3130,6 @@ void cb_emit_call(cb_tree prog, cb_tree cb_using, cb_tree returning,
case C$JUSTIFY:
case C$MAKEDIR:
case C$NARG:
case C$SLEEP:
case C$PARAMSIZE:
cb_error(_("%s not implemented"), data);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,29 @@ public static int SYSTEM(AbstractCobolField cmd) {
return SYSTEM(cmd.getString());
}

/**
* 組み込み関数すうC$SLEEPの実装
* opensource COBOLのlibcob/common.cのcob_acuw_sleep関数に相当する
*
* @param data C$SLEEPの引数として指定されたCOBOL変数のバイト列。
*/
@SuppressWarnings("PMD.AvoidDollarSigns")
public static int C$SLEEP(CobolDataStorage data) {
CobolUtil.COB_CHK_PARMS("C$SLEEP", 3);
List<AbstractCobolField> params = CobolModule.getCurrentModule().cob_procedure_parameters;
if (!params.isEmpty() && params.get(0) != null) {
int n = params.get(0).getInt();
if (n > 0 && n < 3600 * 24 * 7) {
try {
Thread.sleep(n * 1000L);
} catch (InterruptedException e) {
return 0;
}
}
}
return 0;
}

private interface Calculater {
byte calc(byte b1, byte b2);
}
Expand Down
3 changes: 2 additions & 1 deletion tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ run_DEPENDENCIES = \
run.src/subscripts.at \
run.src/extensions.at \
run.src/return-code.at \
run.src/functions.at
run.src/functions.at \
run.src/system-routines.at

data_rep_DEPENDENCIES = \
data-rep.at \
Expand Down
3 changes: 2 additions & 1 deletion tests/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,8 @@ run_DEPENDENCIES = \
run.src/subscripts.at \
run.src/extensions.at \
run.src/return-code.at \
run.src/functions.at
run.src/functions.at \
run.src/system-routines.at

data_rep_DEPENDENCIES = \
data-rep.at \
Expand Down
1 change: 1 addition & 0 deletions tests/run.at
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ m4_include([miscellaneous.at])
m4_include([extensions.at])
m4_include([return-code.at])
m4_include([functions.at])
m4_include([system-routines.at])
53 changes: 53 additions & 0 deletions tests/run.src/system-routines.at
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
AT_SETUP([C$SLEEP])

AT_DATA([prog1.cbl], [
IDENTIFICATION DIVISION.
PROGRAM-ID. prog1.
PROCEDURE DIVISION.
DISPLAY "Start".
CALL "C$SLEEP" USING 4.
DISPLAY "End".
STOP RUN.
])

AT_CHECK([${COMPILE} prog1.cbl])

# Test that the prog1ram takes at least 2 seconds to execute
AT_CHECK([
start_time=$(date +%s);
java prog1;
end_time=$(date +%s);
duration=$((end_time - start_time));
test $duration -ge 2], [0],
[Start
End
])


AT_DATA([prog2.cbl], [
IDENTIFICATION DIVISION.
PROGRAM-ID. prog2.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-TIMEOUT PIC 9(4) COMP-3 VALUE 4.
PROCEDURE DIVISION.
DISPLAY "Start".
CALL "C$SLEEP" USING WS-TIMEOUT.
DISPLAY "End".
STOP RUN.
])

AT_CHECK([${COMPILE} prog2.cbl])

# Test that the prog2ram takes at least 2 seconds to execute
AT_CHECK([
start_time=$(date +%s);
java prog2;
end_time=$(date +%s);
duration=$((end_time - start_time));
test $duration -ge 2], [0],
[Start
End
])

AT_CLEANUP