diff --git a/cobj/system.def b/cobj/system.def index fc6c1646..298c9e1c 100644 --- a/cobj/system.def +++ b/cobj/system.def @@ -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) diff --git a/cobj/typeck.c b/cobj/typeck.c index 333769d8..bcc17371 100644 --- a/cobj/typeck.c +++ b/cobj/typeck.c @@ -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; diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/call/CobolSystemRoutine.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/call/CobolSystemRoutine.java index e8a9a773..4e0865a2 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/call/CobolSystemRoutine.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/call/CobolSystemRoutine.java @@ -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 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); } diff --git a/tests/Makefile.am b/tests/Makefile.am index 3f4306c0..5cb9f5a2 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 \ diff --git a/tests/Makefile.in b/tests/Makefile.in index 3e13f2b5..50e8d69b 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -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 \ diff --git a/tests/run.at b/tests/run.at index 1b63ecfa..76ec8cd1 100644 --- a/tests/run.at +++ b/tests/run.at @@ -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]) diff --git a/tests/run.src/system-routines.at b/tests/run.src/system-routines.at new file mode 100644 index 00000000..25e7ca65 --- /dev/null +++ b/tests/run.src/system-routines.at @@ -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 \ No newline at end of file