DELAY.REX: Difference between revisions

From Rosetta Code
Content added Content deleted
(added the subroutine (program) DELAY.REX (REXX) which emulates the DELAY bif for those REXXes that don't have the DELAY bif. -- ~~~~)
 
(adjusted SLEEP time for specific systems. -- ~~~~)
Line 28: Line 28:


select
select
when !cms then @cpsleep n "SEC" /*CMS? Use CP SLEEP*/
when !cms then @cpsleep n%1 "SEC" /*CMS? Use CP SLEEP*/
when !tso then call sleep n /*TSO? Use SLEEP*/
when !tso then call sleep n%1 /*TSO? Use SLEEP*/
when !regina then call sleep n /*Regina? Use SLEEP*/
when !regina then call sleep n%1 /*Regina? Use SLEEP*/
when !dos then @ping '-n' n "127.0.0.1 > NUL" /*DOS? use PING */
when !dos then @ping '-n' n "127.0.0.1 > NUL" /*DOS? use PING */
otherwise nop
otherwise nop

Revision as of 07:49, 25 February 2013

This the   DELAY.REX   REXX program which emulates the delay bif function for some REXX programs. <lang rexx>/**/trace o;parse arg !;if !all(arg()) then exit;if !cms then address ;signal on halt;signal on novalue;signal on syntax

/*┌────────────────────────────────────────────────────────────────────┐ ┌─┘ └─┐ │ The DELAY function to delay a specific amount of (wall-clock) time │ │ (specified in whole seconds). │ │ │ │ If the REXX program invoking DELAY function is running under PC/REXX,│ │ this REXX routine should never be invoked as PC/REXX has its own built-│ │ in function (BIF). │ └─┐ ┌─┘

 └────────────────────────────────────────────────────────────────────┘*/

@cpsleep = 'CP SLEEP' /*point to (CP) SLEEP cmd*/ @ping = 'PING' /*point to the dos PING cmd*/

parse var ! n _ /*parse argument from parms*/ if _\== | arg()>1 then call er 59 /*are there too many args? */ if n== then n=1 /*no arg? Then assume 1 sec*/ if \isnum(n) then call er 53,dsec 'delay-seconds' /*is n numeric?*/ n=n/1 /*remove any decimal point.*/ if n<=0 then return 0

               /*┌─────────────────────────────┐
                 │   delay    nn    seconds.   │
                 └─────────────────────────────┘*/
 select
 when !cms     then @cpsleep n%1 "SEC"              /*CMS? Use CP SLEEP*/
 when !tso     then call sleep n%1                  /*TSO?    Use SLEEP*/
 when !regina  then call sleep n%1                  /*Regina? Use SLEEP*/
 when !dos     then @ping '-n' n "127.0.0.1 > NUL"  /*DOS?    use PING */
 otherwise          nop
 end   /*select*/

return 0 /*return a zero value. */


/*═════════════════════════════general 1-line subs════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════*/ !all:!!=!;!=space(!);upper !;call !fid;!nt=right(!var('OS'),2)=='NT';!cls=word('CLS VMFCLEAR CLRSCREEN',1+!cms+!tso*2);if arg(1)\==1 then return 0;if wordpos(!,'? ?SAMPLES ?AUTHOR ?FLOW')==0 then return 0;!call=']$H';call '$H' !fn !;!call=;return 1 !cal: if symbol('!CALL')\=="VAR" then !call=;return !call !env: !env='ENVIRONMENT';if !sys=='MSDOS'|!brexx|!r4|!roo then !env='SYSTEM';if !os2 then !env='OS2'!env;!ebcdic=1=='f0'x;return !fid: parse upper source !sys !fun !fid . 1 . . !fn !ft !fm .;call !sys;if !dos then do;_=lastpos('\',!fn);!fm=left(!fn,_);!fn=substr(!fn,_+1);parse var !fn !fn '.' !ft;end;return word(0 !fn !ft !fm,1+('0'arg(1))) !rex: parse upper version !ver !vernum !verdate .;!brexx='BY'==!vernum;!kexx='KEXX'==!ver;!pcrexx='REXX/PERSONAL'==!ver|'REXX/PC'==!ver;!r4='REXX-R4'==!ver;!regina='REXX-REGINA'==left(!ver,11);!roo='REXX-ROO'==!ver;call !env;return !sys: !cms=!sys=='CMS';!os2=!sys=='OS2';!tso=!sys=='TSO'|!sys=='MVS';!vse=!sys=='VSE';!dos=pos('DOS',!sys)\==0|pos('WIN',!sys)\==0|!sys=='CMD';call !rex;return !var: call !fid;if !kexx then return space(dosenv(arg(1)));return space(value(arg(1),,!env)) er: parse arg _1,_2;call '$ERR' "14"p(_1) p(word(_1,2) !fid(1)) _2;if _1<0 then return _1;exit result p: return word(arg(1),1) halt: call er .1 isint: return datatype(arg(1),'W') isnum: return datatype(arg(1),'N') novalue:!sigl=sigl;call er 17,!fid(2) !fid(3) !sigl condition('D') sourceline(!sigl) syntax: !sigl=sigl;call er 13,!fid(2) !fid(3) !sigl !cal() condition('D') sourceline(!sigl)</lang>