DELAY.REX: Difference between revisions

2,977 bytes removed ,  3 years ago
m
added a comment concerning fractional seconds.
m (→‎{{header|REXX}}: added/changed verbiage in some notes.)
m (added a comment concerning fractional seconds.)
 
(4 intermediate revisions 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,│
│ even though some operating systems (or REXX) 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. */
when !regina then do /*Is this Regina? */
if nFrac=n then call sleep n /*whole seconds? */
else call beep 3200032767, nFrac * 1000 /*uses fraction. */
/* [↑] sound MAY be heard, faint tic.*/
end
when !dos then @ping @pingArgs /*Is this DOS? Use PING cmscommand. */
otherwise nop /*don't know what this environment is.*/
end /*select*/
 
return 0 /*return a zero value (if a fuction).*/
 
tracereturn 0 off /*suppressreturn anya REXX error messages.zero value (if a function).*/
 
 
parse arg !halt: return 1 /*obtainreturn alla thezero argumentsvalue from(if thea CLfunction).*/
 
/*══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════*/
Line 87 ⟶ 54:
Coding note: &nbsp; the &nbsp; '''!<small>xxx</small>''' &nbsp; subroutines (above) deal mostly with determining what version of REXX is being invoked and what operating system is being used; &nbsp; and based on that information, appropriate flags (variables) are set. &nbsp; This is an example of a robust boilerplate code checking for various versions of REXX and operating systems, and it also defines additional flags not used within this particular program.
 
Programming note: &nbsp; The subroutine &nbsp; '''$ERR''' &nbsp; isn't included here; &nbsp; so here is the gist of the error messages:
::* &nbsp; '''er 59''' &nbsp; &nbsp; &nbsp; too many arguments specified for the ─── DELAY ─── command.
::* &nbsp; '''er 53''' &nbsp; &nbsp; &nbsp; argument ─── xxx ─── isn't numeric for the option ─── delay-seconds ─── for the ─── DELAY ─── command.