DELAY.REX: Difference between revisions

3,177 bytes removed ,  3 years ago
m
added a comment concerning fractional seconds.
m (→‎{{header|REXX}}: updated code to use a return code of 1 if HALTed.)
m (added a comment concerning fractional seconds.)
 
(One intermediate revision by the same user not shown)
Line 16:
<br>Note: &nbsp; when PC/REXX or Personal REXX are used, those REXXes already have a built-in function (BIF), so the &nbsp; '''delay''' &nbsp; subroutine (below) will never be executed, but the REXX &nbsp; '''DELAY''' &nbsp; BIF will be used instead.
 
ThisFor non-Regina REXXes, &nbsp; this REXX program only uses whole seconds &nbsp; (fractional seconds are ignored).
 
=={{header|REXX}}==
<lang rexx> select
<lang rexx>/*REXX program delays (or SLEEPS) a number of whole number of seconds. */
trace off /*suppress any REXX error messages. */
parse arg ! /*obtain all the arguments from the CL.*/
if !all( arg() ) then exit /*Any kind of documentation requested? */
if !cms then address '' /*Is this CMS? Then use fast cmd path.*/
signal on halt /*handle (user) HALT gracefully. */
signal on noValue /*handle REXX noValue error/mishap. */
signal on syntax /*handle REXX syntax errors. */
 
/*┌────────────────────────────────────────────────────────────────────┐
┌─┘ The DELAY function is used to delay (wait) a specific amount of └─┐
│ (wall─clock) time specified in seconds. Any fraction part is ignored │
│ for most REXX interpreters, but it is supported for Regina REXX, │
│ even though some operating systems (or REXXes) support that option. │
│ │
│ If the REXX program invoking DELAY function is running under PC/REXX │
│ or Personal REXX, this REXX program should never be invoked as those │
└─┐ REXXes have their own built─in function (BIF) named "DELAY". ┌─┘
└────────────────────────────────────────────────────────────────────┘*/
 
parse var ! n _ . /*parse args from command line or parms*/
if _\=='' | arg()>1 then call er 59 /*are there too many arguments? Err msg*/
if n=='' | n=="," then n= 1 /*Mo arguments? Then assume one sec.*/
if \isNum(n) then call er 53,n 'delay-seconds' /*Is n not numeric? Say error msg.*/
nFrac= n /*retain the original delay time. */
n= n % 1 /*elide any fractional part of the time*/
if nFrac<=0 then return 0 /*Negative or zero time? No sleep then*/
 
@cpsleep = 'CP SLEEP' /*point to the (CP) SLEEP command. */
@ping = 'PING' /*point to the DOS PING command. */
@pingArgs = '-n' n "127.0.0.1 > NUL" /*arguments used with the DOS PING cmd.*/
 
 
/* ┌────────────────────┐ */
/* │ delay n seconds. │ */
/* │ or fractional secs.│ */
/* └────────────────────┘ */
select
when !cms then @cpsleep n "SEC" /*Is this CMS? Use CP SLEEP. */
when !tso then call sleep n /*Is this TSO? Use SLEEP cmd. */
Line 73 ⟶ 36:
 
halt: return 1 /*return a zero value (if a function).*/
 
 
/*══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════*/