home / infca / rexx (navigation links) Rexx became reality on March 20th, 1979. That day is considered Rexx's birthday.

Stem | Open Window | Install | My Code Links | End

Cosetes de Rexx

Mike!

Defs Summary Expr Keyw Built Misc Registre MQ
CalcR System Dubtes NetRexx Instalacio My Code Other (Perl, Ant) Links

Definició i característiques Amunt! Top Amunt!

REXX is a procedural language that allows programs and algorithms to be written in a clear and structured way
  • llenguatge sense definicions
  • totes les variables son "string"
  • pas de parametres per valor


Amunt! Top Amunt!
Summary of expression syntax
Strings: "String constants" 'enclosed in quotes' Hex strings: '616263 64'x Numbers: 123.4e-56 Constant symbols: .abc 1d4 7! Simple symbols: foo bar xyz3 Stems: array. Compound symbols: c.3 element.bar.45 Operators: arithmetic: + - * / ** (to-power) % (div) // (mod) string: [abuttal] [space] || (concatenation) logical: \ (not) & (and) | (or) && (xor) comparison: = > < <> <= >= \> \< \= == >> << <<= >>= \>> \<< \== (strong comparison) Function calls: fn(1,2,3) bar(,5) 'DATE'()
Summary of instructions
/* this is a comment */ expression - execute a host command symbol=value - assignment ADDRESS [VALUE] [environment] - change the current environment ADDRESS environment command - execute a command in an environment CALL name [arg][,[arg],...]] - call a function or subroutine CALL ON condition [NAME symbol]- turn on condition handling CALL OFF condition - turn off condition handling condition = ERROR | FAILURE | NOTREADY | HALT DO [ symbol=start [TO finish] ] [WHILE expression_w] [ [BY step ] ] [ [FOR count ] ] [UNTIL expression_u] [ expression_c ] [FOREVER ] - block or repetitive block instruction DROP symbol [symbol...] - de-assignment END [symbol] - end block or repetitive block instruction EXIT [expression] - exit program or external function IF expression [;] THEN [;] statement [ ; ELSE [;] statement] - conditional instruction INTERPRET expression - dynamically execute a string ITERATE [symbol] - continue repetitive block LEAVE [symbol] - leave repetitive block NOP - do nothing NUMERIC DIGITS n - set parameters for numeric formatting NUMERIC FUZZ n NUMERIC FORM SCIENTIFIC | ENGINEERING | "string constant" | [VALUE] expression OPTIONS expression - Control system-dependent things [PARSE [UPPER]] ARG template [PARSE [UPPER]] PULL [template] PARSE [UPPER] LINEIN [template] PARSE [UPPER] SOURCE template PARSE [UPPER] VERSION template PARSE [UPPER] NUMERIC template PARSE [UPPER] VAR symbol template PARSE [UPPER] VALUE expression WITH template template -> [firstPosition] assignments [assignments] assignments -> [nextPosition] varlist [stopPosition] varlist -> varname ' ' [varlist] varname -> "non-constant symbol" | '.' firstPosition -> position nextPosition -> position [nextPosition] stopPosition -> position position -> searchPosition | absPosition | relPosition | '(' "expression" ')' searchPosition -> "string constant" absPosition -> "integer" | '=' numexpr relPosition -> '+' numexpr | '-' numexpr numexpr -> "integer" | '(' "integer expression" ')' PROCEDURE - hide the caller's symbols PROCEDURE EXPOSE var1 [var2...] PROCEDURE HIDE var1 [var2...] PUSH expression - stack a value in LIFO order QUEUE expression - stack a value in FIFO order RETURN [value] - return from a function or subroutine SAY [expression] - echo data SAYN expression - echo data without newline SELECT [expression] WHEN expression THEN statements WHEN expression THEN statements ... [OTHERWISE statements] END [SELECT] - switch on a list of conditions SIGNAL [VALUE] name - jump to a label SIGNAL ON condition [NAME symbol] - turn on condition handling SIGNAL OFF condition - turn off condition handling condition = ERROR | FAILURE | NOTREADY | HALT | SYNTAX | NOVALUE TRACE [symbol] - control program tracing. Values are: TRACE "string" A (all clauses) C (commands) E (error) TRACE VALUE expression F (failure) I (intermediate values) L (labels) N (normal, =F) O (off) R (results)
Summary of builtin functions
Standard functions ABBREV(information,info[,length]) - check for valid abbreviations ABS(number) - return the absolute value ADDRESS() - return the current environment ARG([n][,opt]) - return or test an argument BITAND(string1,string2[,pad]) BITOR (string1,string2[,pad]) - combine two strings with bit operations BITXOR(string1,string2[,pad]) B2D(binary) B2X(binary) D2B(decimal) C2X(string) C2D(string[,n]) D2C(decimal[,n]) - convert between data formats D2X(decimal[,n]) X2B(hex) X2C(hex) X2D(hex) CENTER(s,n[,pad]) - centre a string in a field CENTRE(s,n[,pad]) COMPARE(s1,s2[,pad]) - compare two strings CONDITION([option]) - return information about trapped condition Option can be (default I): C (condition name) D (description) I (instruction) S (status) COPIES(s,n) - replicate a string DATATYPE(string[,type]) - test datatype. Type can be: A (alphanumeric) B (bits) L (lowercase) M (mixed case) N (number) S (symbol chars) U (upper case) W (whole number) X (hex) DATE([format]) - get date. Format can be: B (base date - days since 1/1/1 AD) C (days in century) D (days in year) E (European) J (Julian) M (month name) N (normal: dd Mon yyyy) O (ordered) S (sorted) U (USA) W (day of week) DELSTR(string,n[,length]) - delete substring DELWORD(string,n[,length]) - delete words DIGITS() - NUMERIC DIGITS setting ERRORTEXT(i) - Rexx error message FORM() - NUMERIC FORM setting FORMAT(number [,[before] [,[after] [,[expp] [,expt]]]] ) - format a number as specified FUZZ() - NUMERIC FUZZ setting INSERT(new,target[,[n][,[length][,pad]]]) - insert new string into target JUSTIFY(s,n[,pad]) - justify text to given width LASTPOS(needle,haystack[,start]) - find last occurrence of a string LEFT(string,num[,pad]) - return an initial substring LENGTH(string) - find the length of a string LINESIZE() - find the terminal width MAX(number[,number...]) - find the maximum of a set MIN(number[,number...]) - find the minimum of a set OVERLAY(new,target[,[n][,[length][,pad]]]) - overlay new string on to target POS(needle,haystack[,start]) - find the first occurance of a string QUEUED() - return the number of items on the stack RANDOM([min][,[max][,seed]]) - return a random number REVERSE(string) - find the reverse of a string RIGHT(string,num[,pad]) - return a final substring SOURCELINE([i]) - return a line of the source program SPACE(s[,[n][,pad]]) - evenly space words in a sentence STRIP(string[,[opt][,char]]) - remove leading/trailing spaces SUBSTR(string,n[,length[,pad]]) - return a substring SUBWORD(string,n[,k]) - return a substring of words SYMBOL(name) - test to see if a symbol is defined TIME([format]) - get the time. Format can be: C (civil time) N (normal) L (long) H (hours since midnight) M (minutes since midnight) S (seconds since midnight) E (elapsed time) R (elapsed time then reset) TRACE([setting]) - get and/or set trace mode (see trace instruction) TRANSLATE(string[,[tableo][,[tablei][,pad]]]) - translate characters using given tables TRUNC(number[,n]) - truncate floating point number VALUE(s[,[newvalue][,selector]]) - get or set value of a symbol VERIFY(string,reference[,[option][,start]]) - verify string for valid characters WORD(string,n) - return a word from a string WORDINDEX(string,n) - return the position of a word in a string WORDLENGTH(string,n) - return the length of a word in a string WORDPOS(phrase,string[,start]) - find a phrase in a string WORDS(string) - return the number of words in a string XRANGE([a[,b]]) - return a range of characters I/O functions (some of which are UNIX-specific) CHARIN([stream] [,[position] [,count]]) - read characters CHAROUT([stream] [,[string] [,position] ]- write characters CHARS([stream]) - number of characters available CLOSE(stream) - close a stream FDOPEN(fd [,[mode] [,stream]]) - open an fd number FILENO(stream) - find an fd number FTELL(stream) - return the current file pointer LINEIN([stream] [,[line] [,count]]) - read a line LINEOUT([stream] [,[string] [,line]]) - write a line LINES([stream]) - determine whether lines may be read OPEN(file [,[mode] [,stream]]) - open a file PCLOSE(stream) - close a pipe POPEN(command [,[mode] [,stream]]) - open a pipe to a shell command STREAM(stream [,[option] [,command]]) - miscellaneous stream operations UNIX-specific functions CHDIR(directory) - change to new directory GETCWD() - return current working directory GETENV(name) - get an environment variable PUTENV(string) - set an environment variable SYSTEM(s) - return the output of a shell command USERID() - return the process owner's login name Mathematical functions (implemented as separate package) ACOS(x) the arc-cosine of x in radians (0<=acs(x)<=pi) ASIN(x) the arc-sine of x in radians (-pi/2<=asn(x)<=pi/2) ATAN(x) the arc-tangent of x in radians (-pi/2<=atn(x)<=pi/2) COS(x) the cosine of x radians EXP(x) the exponential of x (2.718281... to the power x) LN(x) the natural logarithm of x (x>0) SIN(x) the sine of x radians SQRT(x) the square root of x (x>=0) [arbitrary precision possible] TAN(x) the tangent of x radians (x <> pi/2) TOPOWER(x,y) x to the power y

Amunt! Top Amunt!
Expressions and Operators
Logical (Boolean)
A character string is taken to have the value "false" if it is '0', and "true" if it is '1'.
  &  = And          Returns 1 if both terms are true.
  |  = Inclusive Or Returns 1 if either term is true.
  && = Exclusive Or Returns 1 if either, but not both, is true.
  \  = Logical Not  Negates; 1 becomes 0 and vice versa.

From "The Rexx language. A practical approach to programming.", by M.F. Cowlishaw, section 3.

Test

What do you think the contents of B would in after the following instructions?

A = 45 B = A || 1 + 3

url


Amunt! Top Amunt!
File I/O
rc = stream( myFile, "c", "open" ); /* Explicitly opening a file */ record = linein(myFile, start, count); count = lineout(myFile, text, start); rc = stream(myFile, "c", "close");

Rexx Inside and Out - File I/O


Keyword Instructions Amunt! Top Amunt!

PARSE [UPPER] { ARG / LINEIN / PULL / SOURCE / VALUE [expression] WITH / VAR name / VERSION } [template]
used to assign data (from various sources) to one or more variables according to the rules and templates described
  PARSE ARG     = string(s) passed to the program are parsed.
  PARSE LINEIN  = shorter form of PARSE VALUE LINEIN() WITH [template] ;
  PARSE SOURCE  = describes the source of the program being executed (how it was called)
  PARSE VERSION = information describing the language level and the date of the language processor
PULL [template]
used to read a string from an external data queue.
It is a shorter form of the instruction PARSE UPPER PULL [template] ;

Sample :

say "Do you want to erase the file ?" pull answer . if answer = 'YES' then Erase oldfile

From "The Rexx language. A practical approach to programming.", by M.F. Cowlishaw, section 7.


Built-in Functions Amunt! Top Amunt!

date([option])
returns the local date in various formats
date('E') == '27/08/89'
date('S') == '19890827' [ISO/R 2014-1971]
DATE argument must be one of BDEFLMNOSTUW
length(string)
returns the length of string
cnt = length( LineaEntrada )
linein([name][,[line][,count]])
returns count (0 or 1)
lineout([name][,[line]])
returns rc
rc = lineout( StreamName, LineOut ) ; // no Lineout ? close input/output stream
overlay(new,target[,[n],[length][,pad]]])
overlays the string new onto the string target
LineaNova = overlay( " ", LiniaVella )
pos(needle,haystack[,start])
returns the position of one string , needle in another, haystack
Inici = pos( "<A HREF=", LiniaFitxer )
right(string,length[,pad])
returns a string of length length containing the right-most characters of string
Num2 = right( Num1, 4, '0' ) /* Num1 = 6 => Num2 = '0006' */
strip(string[,[option][,char]])
removes Leading, Trailing or Both leading and trailing characters from string
Str2 = strip( Str1, 'L' ) /* Str1 = " ABC " => Str2 = "ABC " */
substr(string,n[,[length][,pad]])
returns a sub-string of string that begins at the nth character and is of length length.
Str2 = substr( Str1, 2, 4, '.' ) /* Str1 = "abc" => Str2 = "bc.." */
time([option])
returns the local time in various formats
time('') == '13:26:27'
time('S') == '48377'
TIME argument must be one of CEFHLMNORST (WXP says CEHLMNRS)

From "The Rexx language. A practical approach to programming.", by M.F. Cowlishaw, section 9.
ISBN 0-13-780651-5, also ZB35-5100-01.


Amunt! Top Amunt!
CASE in Rexx ...
select when ( Q == 1 ) then do end /* Q = 1 */ when ( Q == 2 ) then do end /* Q = 2 */ otherwise do say "Dont know what to do ... Q =" Q leave ; end ; end /* select */

Rexx miscelani Amunt! Top Amunt!

Un llibre de Algoritmes i tècniques
Album of Algorithms and Techniques for Standard Rexx - Vladimir Zabrodsky url.

Ejemple interessant : llegir tot un fitxer i mostrar la linia 9.

/* Rexx */ say "Hi. Actual time is" Time() F2 = "FILE2.TXT" /* set input file name */ NL = 0 /* init line count */ do while ( lines( F2 ) ) /* verify there is data */ L2 = linein( F2 ) /* get one line from file */ NL = NL + 1 if ( NL == 9 ) then do echo "La linia" NL "es {" || L2 || "}." end end Rc = lineout( F2 ) /* close input file */ say "Llegides (" NL ") linies del fitxer (" F2 ")." return 0 /* always return a code */

Implementació WHILE, REPEAT, etc

do forever ... if ... then leave ... end /* forever loop */

CRLF string :

CRLF = D2C(13) || D2C(10) or CRLF = "0D0A0D0A"x msg.msg = msg.msg || CRLF

TAB char :

tab = '09'x /* en hexadecimal */ SAY key || tab || value

Rexx trace :

/* trace ?r */ trace ?Errors say "RC val =" RC

Rexx input parameters :

parse UPPER Arg fIn fOut fTz Resto fileIn = fileInDefault ; if ( fIn \== '' ) then fileIn = fIn ;
Directory management

curdir = directory()

FirstDir = directory() /* remember where we are */ say "El directori original es" FirstDir < move on the tree > call directory FirstDir /* back to where we were */

FILESPEC

thisfile = "C:\WINDOWS\UTIL\SYSTEM.INI" say "Tenim com a nom sencer :" thisdir say "Amb FILESPEC, la darrera part es :" FILESPEC("name",thisdir)

REVERSE

path2 = "C:\WINDOWS\UTIL\SYSTEM.INI" htap = reverse( path2 ) parse var htap last '\' . say "Javier's version says :" reverse( last )
Compte !
c:\proves> type anar.cmd /* REXX */ trace ?Errors fn1 = "c:\Program Files\" fn2 = "AT&T Network Client" "cd " fn1 "cd " fn2 say "RC es {" RC "}."
Data conversion functions CDX

Conversions Character, Decimal i heXadecimal :

  • C2D - char to decimal
    c2d('81'x) -> 129 ; c2d('81') -> 14385 ;
  • C2X - char to hex
    c2x("REXX") returns the value 52455858 (the ASCII values for the characters)
Per operar string hexadecimals ...
5 *-* sH = 'AB' ; >>> "AB" 6 *-* dV = X2D( sH ) ; >>> "171" 7 *-* dV = dV + 6 >>> "177" 8 *-* sH = D2X( dV ) ; >>> "B1"
Funcions interessants
  • parse source HowWasCalled
  • parse version VersionRexx
    Also rexx -v
SysCls and other functions
if RxFuncQuery('SysLoadFuncs') then do call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs' call SysLoadFuncs end

Write the complete list of the funcions available ...
How can I know ? Read this Reference Handbook (OS/2), that comes from here

SysAddFileHandle SysFileTree SysRegisterObjectClass SysAddRexxMacro SysGetCollate SysReleaseMutexSem SysBootDrive SysGetEA SysReorderRexxMacro SysClearRexxMacroSpace SysGetKey SysRequestMutexSem SysCloseEventSem SysGetMessage SysResetEventSem SysCloseMutexSem SysIni SysRmDir SysCls SysLoadFuncs SysSaveObject SysCopyObject SysLoadLibrary SysSaveRexxMacroSpace SysCreateEventSem SysLoadRexxMacroSpace SysSearchPath SysCreateMutexSem SysMapCase SysSetFileHandle SysCreateObject SysMkDir SysSetIcon SysCreateShadow SysMoveObject SysSetObjectData SysCurPos SysNationalLanguageCompare SysSetPriority SysCurState SysOpenEventSem SysSetProcessCodePage SysDeregisterObjectClass SysOpenMutexSem SysShutDownSystem SysDestroyObject SysOpenObject SysSleep SysDriveInfo SysOS2Ver SysSwitchSession SysDriveMap SysPostEventSem SysTempFileName SysDropFuncs SysProcessType SysTextScreenRead SysDropLibrary SysPutEA SysTextScreenSize SysDropRexxMacro SysQueryClassList SysWaitEventSem SysElapsedTime SysQueryEAList SysWaitForShell SysFileDelete SysQueryProcessCodePage SysWaitNamedPipe SysFileSearch SysQueryRexxMacro SysWildCard SysFileSystemType SysQuerySwitchList
Visibilitat de variables en la crida a funcions + Pas de parametres

Hem de diferenciar :

  • funcions escrites en Rexx o funcions escrites en algun altre llenguatge, pero cridades des Rexx
  • si son escrites en Rexx, poden ser internes o externes
  • si son internes, poden començar amb procedure o no

Has access to all of your variables :

  • internal Rexx function without a PROCEDURE statement,
  • external function not written in Rexx

Has acces to none of your variables :

  • internal Rexx function with a PROCEDURE statement ( can use EXPOSE )
  • external function written in Rexx

Atenció : si cridem una funcio així : "rc = EnviarFichero( clientSocket, Fn, Ftz )" haurem de rebre els arguments així : "parse arg SendToSocket, FileName, FileTrace"
Atencio a les comes !

Exemple de EXPOSE : Trabajo: procedure expose Cnt_Input Cnt_Output

BigTrace = 1 lout = "JaJa." rc = MyTrace( fTz, lout, BigTrace ) /* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ MyTrace: procedure /* no vars visible */ parse arg filetrace, texto, ToFile Say texto if ( ToFile == 1 ) then do rc = lineout( filetrace, texto ) end return 0 /* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
Amunt! Top Amunt!
TCPIP & RxSock

The RxSock package is contained in the file rxsock.dll. This file must be placed in a directory listed in your LIBPATH. To get access to the functions in the RxSock package, execute the following Rexx code:

If RxFuncQuery("SockDropFuncs") then do rc = RxFuncAdd("SockLoadFuncs","rxsock","SockLoadFuncs") rc = SockLoadFuncs() vers = SockVersion() say( "Rexx Socket Support package version :" vers ) end

To unload the DLL, call the SockDropFuncs() function and then exit all CMD.EXE shells.

Get PDF "Rexx TCP/IP Socket Library Functions" at wu-wien, ooRexx, 2012. Browse OnLine (v 4, Aug 2009)

Connect() return codes
99 EADDRNOTAVAIL The calling host cannot reach the specified destination. 97 EAFNOSUPPORT The address family is not supported. 114 EALREADY The socket is in nonblocking mode. A previous connection attempt has not completed. 88 ENOTSOCK The socket is not a valid socket descriptor. 111 ECONNREFUSED The destination host rejected the connection request. 115 EINPROGRESS socket is in nonblocking mode, and the connection cannot be completed immediately. EINPROGRESS does not indicate an error. 4 EINTR Interrupted system call. 106 EISCONN Socket is already connected. 101 ENETUNREACH The network cannot be reached from this host. 110 ETIMEDOUT Establishing the connection timed out. 105 ENOBUFS There is no buffer space available. 95 EOPNOTSUPP The operation is not supported on socket.

Use this errno tool on your system !

### EXAMPLES: ### ### 1. To look up errno 22 on a system: ### ### errno 22 ### ### ### 2. To look up errno ECONNRESET: ### ### errno ECONNRESET
Amunt! Top Amunt!
Stem

DogBreeds. = '' DogBreeds.0 = 0 CALL addBreed peke "expensive rug rat" CALL addBreed huskie "eats your cat" if DogBreeds.0 > 0 then do i = 1 to DogBreeds.0 key = DogBreeds.i value = DogBreeds.key SAY key value end return 0 /* Add indexable key-value pair to stem */ addBreed: Procedure expose DogBreeds. Parse arg breed characteristics index = DogBreeds.0 index = index+1 DogBreeds.0 = index DogBreeds.index = breed DogBreeds.breed = characteristics return

Do it in two steps: ProcessStem: parse arg _ProcessStem_stem call ProcessStem_sub _ProcessStem_stem return result ProcessStem_sub: procedure expose (_ProcessStem_stem) stem = _ProcessStem_stem /* write your code here */ return
File data entry into a Stem (complete)
/* Rexx */ /* trace ?r */ Producte = "Conversor de texte a HTM" ; Versio = "v 1.0, 20050914" ; Autor = "Sebastia Altemir Gubankov" ; signal on Halt /* allow Ctrl-C end */ FileInDefault = "TXT2HTM.TXT" FileOutDefault = "TXT2HTM.OUT" parse UPPER Arg fIn fOut fTz Resto Mostrar_Dades_Llegides = 1 FileIn = FileInDefault FileOut = FileOutDefault if ( ( fIn \= '' ) & ( fIn \= '-') ) then FileIn = fIn /* input : data */ say "Anem a tractar el fitxer d'entrada" FileIn Nl = 0 DadesIn. = "" DadesIn.0 = 0 do while ( lines( FileIn ) ) Nl = Nl + 1 DadesIn.Nl = linein( FileIn ) end /* while loop */ rc = lineout( FileIn ) /* close input file */ DadesIn.0 = Nl say "Llegides" DadesIn.0 "linies del fitxer d'entrada" FileIn if ( Mostrar_Dades_Llegides == 1 ) then do i = 0 do while ( i < DadesIn.0 ) i = i + 1 l = length( DadesIn.i ) say "Linia" i "[" l "] =" DadesIn.i end end Halt : /* cerrar ordenadamente */ return 0 /* always return a value */
Amunt! Top Amunt!
Com obrir finestres amb Texte pregunta, botons "Yes/No", etc
/* Rexx */ iRC = RxMessageBox( "Continue or Not", "Mon Titol", "YesNo", "Question" ) say "RxMB rc =" iRC /* iRC = 6 on "yes", iRC = 7 on "no */ call RxFuncAdd InstMMFuncs, "OODialog", InstMMFuncs call InstMMFuncs message = "Hello, world !" rc = InfoMessage(message) say 'Im rc =' rc rc = ErrorMessage(message) say 'Em rc =' rc rc = YesNoMessage(message) say 'YNm rc =' rc say "Adeu." time() "-" date() return 0 ::requires "OODPLAIN.CLS"
Com posar icones al escritori ...

N.I.Y.

Folder :

Call SysCreateObject "WPFolder", "INF Files", "<WP_DESKTOP>",, "OBJECTID=<INF_FILES>"

INF icon :

Call SysCreateObject "WPProgram", title' ['path']', "<INF_FILES>",, "EXENAME=VIEW.EXE;PARAMETERS="name";STARTUPDIR="path";",, "UPDATE"

PROG icon :

Call SysCreateObject "WPProgram", title' ['path']', "<INF_FILES>",, "EXENAME=VIEW.EXE;PARAMETERS="name";STARTUPDIR="path";",, "UPDATE"
Com llegir / escriure del / al Registre

See: C:\Program Files\ObjREXX\SAMPLES\registry.rex
Object Rexx Reference, Other Classes, WindowsRegistry Class

MAC change
/* trace ?r */ parse UPPER Arg newMACparam Verbose Resto newMACparam = strip( newMACparam ) ; myKey2 = "CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\0007" /* Get system and version */ ret = syswinver() parse var ret winsys winver /* The registry editor name is different on NT 3.5 */ if winver \= 4 then regeditor = "REGEDT32" else regeditor = "REGEDIT" FileControl = "\control" FileNewKey = "\testuser" /* do not use file extension on 95 */ if winsys = "WindowsNT" then do FileControl = FileControl || ".reg" FileNewKey = FileNewKey || ".reg" end r = .WindowsRegistry~new /* create a new registry object */ if r~InitCode \= 0 then exit /* leave if init failed */ /* r~Current_Key is initially set to HKEY_LOCAL_MACHINE */ /* Open the "HKEY_LOCAL_MACHINE\System" key */ myKey = "SYSTEM" if r~open(,myKey,"QUERY WRITE") \= 0 then do syskey = r~Current_Key /* save to close it */ if r~List(,keys.) = 0 then do /* Get a list of System's subkeys */ bk = r~open(,myKey2) /* open System's first subkey's Control key */ if bk \= 0 then do r~setvalue(,"NetworkAddress",newMACparam) /* REG_SZ */ end r~Close(bk) /* close Control key */ lout = "+++(1) End Close CONTROL key." ; rc = mySay( lout, Verbose ) ; end r~Close(syskey) /* close System key */ end return 0 /* winsystm.cls contains the WindowsRegistry class definition */ ::requires "winsystm.cls"
WINFUNCS.DLL
Sample : counting given words
cnt = 0 keep. = 0 do while text <> '' parse var text nextword text if keep.nextword = 0 then do cnt = cnt + 1 list.cnt = nextword end keep.nextword = keep.nextword + 1 end do i = 1 to cnt nextword = list.i say nextword keep.nextword end
RANDOM
NUMERIC DIGITS 10 vIM=139968 vIA=3877 vIC=29573 LAST=42 parse arg n If n < 1 Then Do n = 1 End Do i = 1 TO N result = gen_random(100) End SAY result EXIT gen_random: PROCEDURE EXPOSE LAST vIM vIA vIC PARSE ARG n LAST = (LAST * vIA + vIC) // vIM return n * LAST / vIM
Escaping "&"

Com fer anar un String que conté un "&" ? El DOS l'agafa com a operador "AND" ...

A basic rule in Rexx is: Quote all commands to the underlying system. The command is ECHO, so you start with:

'echo'

then, so that Rexx won't do substitution, you quote any string you don't want Rexx to see, as you did:

lout='John & Mary'

The result in your program should read:

'echo' lout

and you've followed all the Rexx rules. Rexx will pass the command with the substituted string for the variable LOUT to the underlying OS, which may have it's own rules for examining and substituting!

Generally speaking, and I'm no expert, you tell Windows to handle a string as a literal (without any substitution) by putting it in double-quotes. But to do that in Rexx, you either have to double the double-quotes OR put them in single quotes ! I'll use single quotes here, since that seems to be your style (MVS users tend to favor double-quotes), so look closely:

/* rexx */ lout = "ramon & pere" ; 'echo' '"'lout'"' /* return 0
Error traps
signal on failure name ExitProc signal on halt name ExitProc signal on syntax name ExitProc


Amunt! Top Amunt!
Rexx access to DOS
envir vars
/* rexx */ myhn = value( 'COMPUTERNAME',, 'ENVIRONMENT' ) ; // get Hostname say "This host's HOSTNAME is" myhn mypth = value( 'PATH',, 'ENVIRONMENT' ) ; // get Path envir value say mypth return 0
IP
/* rexx */ fn = ".\f1.txt" myipcmd = 'ipconfig | find "IP A" > ' fn myipcmd ; // execute command line = linein(fn) say "linea = " line parse var line inici ':' myip resto /* remove trailing CR */ lng = length( myip ) myip = delstr( myip, lng ,1 ) /* display IP and correct length */ lng=length( myip ) say "myip = ["lng"]{" || myip || "}." return myip

Amunt! Top Amunt!
Rexx access to MQ

OS/2 had MA31; w/NT had MA77.

Entorn
c:\> rexx -v IBM Object REXX Interpreter Version 2.1.3 Build date: Mar 31 2004 Copyright (c) IBM Corporation 1996, 2004. All Rights Reserved. c:\>dspmqver Name: WebSphere MQ Version: 6.0.1.1 CMVC level: p600-101-060504 BuildType: IKAP - (Production)
Instalació

Set PATH to reach for RXMQN.DLL (acces to a local QMgr) and/or RXMQT.DLL (client access to a server QMgr).

Codi
/* Define the Rexx/MQ interface to Rexx */ rcc = RXFuncadd('RXMQNINIT','RXMQN','RXMQNINIT') say '>>> FuncAdd() rc=' rcc /* Initialise the interface */ RXMQNTRACE = '' rcc= RXMQNINIT() say '>>> Init() rc=' rcc /* Connect to Queue Manager - RAHN */ qMgrName = "QMANAGER.AS400" RXMQNTRACE = '' rcc = RXMQNCONN( qMgrName ) say '>>> Conn() rc=' rcc /* Open Queue N1 for Inquire Access Only, tracing Object Descriptor accesses */ queueName = "ALBERTQ" iod.on = queueName iod.ot = MQOT_Q RXMQNTRACE = '' rcc = RXMQNOPEN('iod.', mqoo_inquire, 'h1', 'ood.') say '>>> Open() rc=' rcc 'H=' h1 /* Show the name of the Queue which is using handle 1 */ RXMQNTRACE = '' atrin = mqca_q_name atrou = '' rcc = RXMQNINQ(h1, atrin, 'atrou' ) say 'Inq() rc=' rcc 'Atr' atrin 'Setting <'atrou'>' ... /* Stop access to the Queue */ RXMQNTRACE = '' rcc = RXMQNCLOSE(h3, mqco_none) say 'Close() rc=' rcc /* Disconnect from the QM (Closing h1 in the process) */ RXMQNTRACE = '' rcc = RXMQNDISC() say 'Disc() rc=' rcc /* Remove the Interface functions from the Rexx Workspace ... */ RXMQNTRACE = 'TERM' rcc = RXMQNTERM() say 'Term() rc=' rcc

Call SAG.DLL from SAG.CMD

How to code a DLL

N.I.Y.

How to call a (own) DLL from Rexx

N.I.Y.


Amunt! Top Amunt!
Calculator
c:\\Rexx\CalcR> type calc.rex /* rexx */ X = 'input BYE to quit' do until X = 'BYE' ; interpret 'say' X ; pull X ; end

Amunt! Top Amunt!
Rexx on a pipe

When you put the REXX interpreter into a pipeline, it connects STDIN, STDOUT and STDERR so that they become available to the rexx programs run by this interpreter.

Example (myprog is a rexx script):

ps -eF | grep amq | rexx myprog

Other example:

ps -eF | grep amq | rexx -e "signal on notready;do forever;parse pull . pid .; say 'pid=' pid; end; notready:return"

Gives as output:

pid= 4797

System functions Amunt! Top Amunt!

See ftp://sdfrxs02.boeblingen.de.ibm.com/rexx/OREXXLinux/i386/readme.txt (11/02/03)

12.0 LIST OF REXX UTILITY FUNCTIONS

=================================================================
 Function                 | Exists on platforms:  |
  Name:                   | OS/2 | Windows | UNIX | Remarks
--------------------------+------+---------+------+--------------
SysAddFileHandle          | YES  |   YES   | NO   |
SysAddRexxMacro           | YES  |   YES   | YES  |
SysBootDrive              | YES  |   YES   | NO   |
SysClearRexxMacroSpace    | YES  |   YES   | YES  |
SysCloseEventSem          | YES  |   YES   | YES  |
SysCloseMutexSem          | YES  |   YES   | YES  |
SysCls                    | YES  |   YES   | YES  |
SysCopyObject             | YES  |   NO    | NO   |
SysCreateEventSem         | YES  |   YES   | YES  |
SysCreateMutexSem         | YES  |   YES   | YES  |
SysCreateObject           | YES  |   NO    | NO   |
SysCreatePipe             | NO   |   NO    | YES  |
SysCreateShadow           | YES  |   NO    | NO   |
SysCurPos                 | YES  |   YES   | NO   |
SysCurState               | YES  |   YES   | NO   |
SysDeregisterObjectClass  | YES  |   NO    | NO   |
SysDestroyObject          | YES  |   NO    | NO   |
SysDriveInfo              | YES  |   YES   | NO   |
SysDriveMap               | YES  |   YES   | NO   |
SysDropFuncs              | YES  |   YES   | YES  |
SysDropLibrary            | YES  |   YES   | NO   |
SysDropRexxMacro          | YES  |   YES   | YES  |
SysDumpVariables          | YES  |   YES   | YES  |
SysElapsedTime            | YES  |   NO    | NO   |
SysFileDelete             | YES  |   YES   | YES  |
SysFileSearch             | YES  |   YES   | YES  |
SysFileSystemType         | YES  |   YES   | NO   |
SysFileTree               | YES  |   YES   | YES* |
SysFromUnicode            | NO   |   YES   | NO   |
SysToUnicode              | NO   |   YES   | NO   |
SysGetErrortext           | NO   |   YES   | YES**|
SysFork                   | NO   |   NO    | YES  |
SysGetCollate             | YES  |   YES   | NO   |
SysGetEA                  | YES  |   NO    | NO   |
SysGetFileDateTime        | YES  |   YES   | YES  |
SysGetKey                 | YES  |   YES   | YES  |
SysGetMessage             | NO   |   YES   | YES  |
SysGetMessageX            | NO   |   NO    | YES  |
SysGetpid                 | NO   |   NO    | YES+ | use SysQueryProcess instead;
SysIni                    | YES  |   YES   | NO   |
SysLoadFuncs              | YES  |   YES   | YES  |
SysLoadLibrary            | YES  |   YES   | NO   |
SysLoadRexxMacroSpace     | YES  |   YES   | YES  |
SysMapCase                | YES  |   YES   | NO   |
SysMkDir                  | YES  |   YES   | YES  |
SysMoveObject             | YES  |   NO    | NO   |
SysNationalLanguageCompare| YES  |   YES   | NO   |
SysOpenEventSem           | YES  |   YES   | YES  |
SysOpenMutexSem           | YES  |   YES   | YES  |
SysOpenObject             | YES  |   NO    | NO   |
SysPostEventSem           | YES  |   YES   | YES  |
SysProzessType            | YES  |   YES   | NO   |
SysPulseEventSem          | YES  |   YES   | NO   |
SysPutEA                  | YES  |   NO    | NO   |
SysQueryClassList         | YES  |   NO    | NO   |
SysQueryEAList            | YES  |   NO    | NO   |
SysQueryExtLIBPATH        | YES  |   NO    | NO   |
SysQueryProcess           | YES  |   YES   | YES* |
SysQueryProcessCodePage   | YES  |   YES   | NO   |
SysQueryRexxMacro         | YES  |   YES   | YES  |
SysQuerySwitchList        | YES  |   NO    | NO   |
SysRegisterObjectClass    | YES  |   NO    | NO   |
SysReleaseMutexSem        | YES  |   YES   | YES  |
SysReorderRexxMacro       | YES  |   YES   | YES  |
SysRequestMutexSem        | YES  |   YES   | YES  |
SysResetEventSem          | YES  |   YES   | YES  |
SysRmDir                  | YES  |   YES   | YES  |
SysSaveObject             | YES  |   NO    | NO   |
SysSaveRexxMacroSpace     | YES  |   YES   | YES  |
SysSearchPath             | YES  |   YES   | YES  |
SysSetExtLIBPATH          | YES  |   NO    | NO   |
SysSetFileDateTime        | YES  |   YES   | YES  |
SysSetFileHandle          | YES  |   NO    | NO   |
SysSetIcon                | YES  |   NO    | NO   |
SysSetObjectData          | YES  |   NO    | NO   |
SysSetPriority            | YES  |   YES   | NO   |
SysSetProcessCodePage     | YES  |   YES   | NO   |
SysShutDownSystem         | YES  |   YES   | NO   |
SysSleep                  | YES  |   YES   | YES  |
SysStemCopy               | YES  |   YES   | YES  |
SysStemDelete             | YES  |   YES   | YES  |
SysStemInsert             | YES  |   YES   | YES  |
SysStemSort               | YES  |   YES   | YES  |
SysSwitchSession          | YES  |   YES   | NO   |
SysSystemDirectory        | YES  |   NO    | NO   |
SysTempFileName           | YES  |   YES   | YES  |
SysTextScreenRead         | YES  |   YES   | NO   |
SysTextScreenSize         | YES  |   YES   | NO   |
SysUtilVersion            | YES  |   YES   | YES  |
SysVersion                | YES  |   YES   | YES  |
SysVolumeLabel            | YES  |   YES   | NO   |
SysWait                   | NO   |   NO    | YES  |
SysWaitEventSem           | YES  |   YES   | YES  |
SysWaitForShell           | YES  |   NO    | NO   |
SysWaitNamedPipe          | YES  |   YES   | NO   |
SysWinDecryptFile         | NO   |   YES   | NO   |
SysWinEncryptFile         | NO   |   YES   | NO   |
SysWildCard               | YES  |   YES   | NO   |
==========================+======+=========+======+==============
SysOS2Ver                 | YES  |   NO    | NO   | use SysVersion instead;
SysWinVer                 | NO   |   YES   | NO   | use SysVersion instead;
SysLinVer                 | NO   |   NO    | YES++| use SysVersion instead;
=================================================================
     Legend: *  <=> works differently;
             ** <=> new function;
             +  <=> AIX only.
             ++ <=> Linux only.
=================================================================


El REXX i el rus

Problema típic de encoding. Ha de quadrar el encoding del file system, el del shell, i el del texte del rexx. T'aconsello que tot sigui utf8 sempre i per a tot. Allò que no ho sigui que ho modifiquis. El texte del rexx ho pots canviar amb el notepad++ El shell el pots canviar amb chcp. Jo timc tots els shells en utf8 per defecte. El file system o millor dit els filenames és més laboriós - renames

Shell

Chcp 65001


Amunt! Top Amunt!
interface to other languages ...

This chapter describes how to interface applications to Rexx or extend the Rexx language by using Rexx C++ application programming interfaces (APIs). As used here, the term application refers to programs written in C++.

url


Amunt! Top Amunt!
Pending

Dubtes Amunt! Top Amunt!

NetRexx Amunt! Top Amunt!

Amunt! Top Amunt!
Instalació Rexx

Get ooRexx 4.1.2 & RxSock() v1.4

CD Eines-2 - OjbRexx - or T42:\Fonts\Rexx - or gSpace(ruta66).

D:\ObjRexx\Win_V2.1.3\setup.exe = 16.507.617 = Developer Edition 2.1.3.0 PARSE version says "OBJREXX 6.00 31 Mar 2004" c:\> rexx -v IBM Object REXX Interpreter Version 2.1.3 Build date: Mar 31 2004
labss2 (RH v4, 32-bit)

Comencem amb

3576601 Nov 15 14:09 oorexx-3.1.1-1.el4.rf.i386.rpm 124168 Apr 1 2004 RxSock-1.4.tar.gz

Instalem

[root@labss2 rexx]# cat /etc/issue Red Hat Enterprise Linux AS release 4 (Nahant Update 4) [root@labss2 rexx]# rpm -ivh oorexx-3.1.1-1.el4.rf.i386.rpm warning: oorexx-3.1.1-1.el4.rf.i386.rpm: V3 DSA signature: NOKEY, key ID 6b8d79e6 Preparing... ########################################### [100%] 1:oorexx ########################################### [100%] [root@labss2 rexx]# rexx -v Open Object Rexx Interpreter Version 3.1.1 for LINUX Build date: Jan 15 2007 [root@labss2 rexx]#

Per RxSock:

[root@labss2 rexx]# tar -zxzf RxSock-1.4.tar.gz
RH64b

Comencem amb

[sebas@rhv6-64b rexx]$ ls -l -rwx------. 1 sebas sebas 2563905 Nov 13 10:55 ooRexx-4.1.2.opensuse1210.x86_64.rpm

Instalem:

[sebas@rhv6-64b rexx]$ rpm -i --test ooRexx-4.1.2.opensuse1210.x86_64.rpm [root@rhv6-64b prod]# rpm -ivh ../ooRexx-4.1.2.opensuse1210.x86_64.rpm Preparing... ########################################### [100%] 1:ooRexx ########################################### [100%] Starting rxapi: /usr/bin/rxapi: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.15' not found (required by /usr/bin/rxapi) /usr/bin/rxapi: /lib64/libc.so.6: version `GLIBC_2.14' not found (required by /usr/bin/rxapi) [FAILED] warning: %post(ooRexx-4.1.2-8330.opensuse1210.x86_64) scriptlet failed, exit status 1 [root@rhv6-64b prod]# rpm -i --test ../ooRexx-4.1.2.opensuse1210.x86_64.rpm package ooRexx-4.1.2-8330.opensuse1210.x86_64 is already installed [root@rhv6-64b prod]# rexx -v rexx: /lib64/libc.so.6: version `GLIBC_2.14' not found (required by /usr/lib64/ooRexx/librexx.so.4) rexx: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.15' not found (required by /usr/lib64/ooRexx/librexxapi.so.4) rexx: /lib64/libc.so.6: version `GLIBC_2.14' not found (required by /usr/lib64/ooRexx/librexxapi.so.4) [root@rhv6-64b lib64]# ls -l /lib64/libc.so.6 lrwxrwxrwx. 1 root root 12 Sep 27 19:25 /lib64/libc.so.6 -> libc-2.12.so [root@rhv6-64b lib64]# ldd /usr/bin/rexx /usr/bin/rexx: /lib64/libc.so.6: version `GLIBC_2.14' not found (required by /usr/lib64/ooRexx/librexx.so.4) /usr/bin/rexx: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.15' not found (required by /usr/lib64/ooRexx/librexxapi.so.4) /usr/bin/rexx: /lib64/libc.so.6: version `GLIBC_2.14' not found (required by /usr/lib64/ooRexx/librexxapi.so.4) linux-vdso.so.1 => (0x00007fff425ff000) librexx.so.4 => /usr/lib64/ooRexx/librexx.so.4 (0x00007f6ffbe25000) librexxapi.so.4 => /usr/lib64/ooRexx/librexxapi.so.4 (0x00007f6ffbc0e000) libdl.so.2 => /lib64/libdl.so.2 (0x0000003df4800000) libpthread.so.0 => /lib64/libpthread.so.0 (0x0000003df4c00000) libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x0000003e00c00000) libm.so.6 => /lib64/libm.so.6 (0x0000003df4400000) libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x0000003dfe400000) libc.so.6 => /lib64/libc.so.6 (0x0000003df4000000) /lib64/ld-linux-x86-64.so.2 (0x0000003df3800000)

My Code Amunt! Top Amunt!

Alguns exemples interessants de codi en Rexx ...

FutCat
DirS -
Codi
Apuntar en el Help on fica el fitxer temporal.
MQ Client
requires MQIC32.DLL
P4:\Delphi\MQ\
T42:\Delphi\MQ_client\

Amunt! Top Amunt!
Other scripting tools

Intentem comparar el rexx amb ...

Rexx is a structured high-level programming language that was designed to be both easy to learn and easy to read. Rexx is widely used as a glue language, macro language, and is often used for processing data and text and generating reports. Rexx is the primary scripting language in some operating systems, and is also used as an internal macro language in some other software.
wiki.

Perl is a high-level, general-purpose, interpreted, dynamic programming language, developed as a general-purpose Unix scripting language to make report processing easier. Perl borrows features from other programming languages including C, shell scripting (sh), AWK, and sed. The language provides powerful text processing facilities without the arbitrary data length limits of many contemporary Unix tools, facilitating easy manipulation of text files.
wiki.

Python is an interpreted, general-purpose high-level programming language whose design philosophy emphasizes code readability. Python aims to combine "remarkable power with very clear syntax", and its standard library is large and comprehensive. Its use of indentation for block delimiters is unique among popular programming languages. Python is often used as a scripting language, but is also used in a wide range of non-scripting contexts.
wiki.

Apache Ant is a software tool for automating software build processes. It is similar to Make but is implemented using the Java language, requires the Java platform, and is best suited to building Java projects. Ant uses XML to describe the build process and its dependencies.
wiki.


Links


Fet en Rexx : ( CALANY.CMD & CALMES.CMD a "\\Rexx\Cal" )

2014
  L M X J V S D L M X J V S D L M X J V S D L M X J V S D L M X J V S D L M X J V S D
Gen     12345 6789101112 13141516171819 20212223242526 2728293031                  
Feb           12 3456789 10111213141516 17181920212223 2425262728                  
Mar           12 3456789 10111213141516 17181920212223 24252627282930 31            
Abr   123456 78910111213 14151617181920 21222324252627 282930                      
May       1234 567891011 12131415161718 19202122232425 262728293031                
Jun             1 2345678 9101112131415 16171819202122 23242526272829 30            
Jul   123456 78910111213 14151617181920 21222324252627 28293031                    
Ago         123 45678910 11121314151617 18192021222324 25262728293031              
Sep 1234567 891011121314 15161718192021 22232425262728 2930                        
Oct     12345 6789101112 13141516171819 20212223242526 2728293031                  
Nov           12 3456789 10111213141516 17181920212223 24252627282930              
Dec 1234567 891011121314 15161718192021 22232425262728 293031                      


Ep ! Site under construction. Escriu-me !
Updated 20170627 (a)  
Uf !