/* REXX FACTORS Determine factors of a supplied number. */ arg argline /* pro-forma quick-start */ address TSO arg parms "((" opts opts = Strip( opts,'T','5d'x ) parse var opts "TRACE" tv . parse value tv "N" with tv . rc = Trace("O"); rc = Trace(tv) parse value '' with helpmsg parse source sys_id how_invokt exec_name DD_nm DS_nm, as_invokt cmd_env addr_spc usr_tokn if WordPos( '?',parms ) > 0 then call HELP /* -*/ "CLEAR" numlist = parms do forever parse var numlist num numlist if num = '' then do /* get more ? */ "NEWSTACK" say "Enter a number or numbers to process, or" say "enter '?' for HELP, or null to exit." pull numlist "DELSTACK" if numlist = '?' then call HELP /* ...and don't come back */ if numlist = '' then exit parse var numlist num numlist end /* num */ call D_DEVELOP_FACTORS /* -*/ call P_PUMP /* -*/ end /* forever */ exit /*@ FACTORS */ /* . ----------------------------------------------------------------- */ D_DEVELOP_FACTORS: /*@ */ address TSO parse value "0" with sum faclist if DataType( num,'W' ) = 0 then do say "FACTORS needs a number as its one and only parm." exit end do fac = 2 to num if fac**2 > num then leave if num // fac = 0 then do hifac = num / fac if hifac = fac then do hifac = '' sum = sum + fac end else , sum = sum + fac + hifac faclist = faclist fac hifac end /* evenly divisible */ end /* fac */ if faclist = '' then do queue num "is prime." return end rc = Trace("O"); rc = Trace(tv) "NEWSTACK" "SQRT" num pull sqroot "DELSTACK" faclist = STRSORT( faclist ) queue "Factors of" num "are" faclist queue "and their sum is" sum queue "The square root of" num "is" sqroot return /*@ D_DEVELOP_FACTORS */ /* . ----------------------------------------------------------------- */ P_PUMP: /*@ */ address TSO "CLEAR" msglim = SYSVAR( "SYSWTERM" ) - 12 do queued() parse pull line do while Length(line) > msglim pt = LastPos(" ",line,msglim) slug = Left(line,pt) say slug line = " "Substr( line,pt ) end /* while msglim */ say line end /* queued */ "NEWSTACK"; pull; "CLEAR"; "DELSTACK" return /*@ P_PUMP */ /* . ----------------------------------------------------------------- */ HELP: /*@ */ address TSO;"CLEAR" if helpmsg <> "" then say helpmsg ex_nam = Left(exec_name,8) /* predictable size */ say " " say " "ex_nam" shows the integer factors of any number. " say " " say " Syntax: "ex_nam" numlist " say " " say " numlist is a list of blank-delimited integers to be " say " processed. If is empty, you will be " say " prompted to enter one or more numbers to process. " say " " "NEWSTACK"; pull ; "CLEAR" ; "DELSTACK" say " Debugging tools provided include: " say " " say " TRACE tv: will use value following TRACE to place the execution " say " into REXX TRACE Mode. " say " " say " " say " Debugging tools can be accessed in the following manner: " say " " say " TSO "ex_nam" parameters (( debug-options " say " " say " For example: " say " " say " TSO "ex_nam" (( TRACE ?R " if sysvar("SYSISPF") = "ACTIVE" then, address ISPEXEC "CONTROL DISPLAY REFRESH" exit /*@ HELP */