/**/ signal on novalue /* force REXX and its way of 'NOVALUE ON' */ /* Usage: [MACRO] RXLYNX [url|.|:] */ /* Example: RXLYNX http://example.com = show specified URL */ /* RXLYNX = show this file:/// */ /* RXLYNX . = show directory */ /* RXLYNX : = show focusword.2() */ /* Option: define A-HOME 'macro RXLYNX :' */ /* Purpose: Locate FOCUSWORD.2() or a specified argument as */ /* URL using RXLYNX.cmd - the trick is to extract */ /* an URL from the various forms found in href= or */ /* contructs. Character references aren't */ /* resolved, only & is replaced by &. */ /* See also: KHELP FOCUSWORD */ /* */ /* */ /* Requires: Kedit 5.0, OS/2 REXX, RXLYNX.cmd */ /* (Frank Ellermann, 2004) */ URL = arg( 1 ) ; rc = 0 if URL = ':' then URL = focusword.2() USE = translate( URL ) ; LOC = 'file://localhost/' if URL = '' & dir() = 0 then do URL = LOC || translate( fileid.1(), '/', '\' ) if alt() then 'save' ; if rc <> 0 then exit rc end else if URL = '' then URL = LOC || translate( dirfileid.1(), '/', '\' ) else if URL = '.' then URL = LOC || translate( directory(), '/', '\' ) else if abbrev( USE , '' /* (in text) */ else if abbrev( USE , '<' ) then parse var URL '<' URL '>' /* (in news) */ else if abbrev( USE , 'HREF="' ) then parse var URL =7 URL '"' /* href="any:url" (X)HTML */ else if abbrev( USE , 'HREF=' ) then parse var URL =6 URL '>' /* href=any:url> (in HTML) */ else if abbrev( USE , '"' ) then parse var URL '"' URL '"' /* "any:url" (strings) */ else if abbrev( USE , "'" ) then parse var URL "'" URL "'" /* 'any:url' (strings) */ else if sign( pos( '="HTTP://', USE )) then parse var URL '="' URL '"' /* any="http://url" (XML) */ else if abbrev( USE , 'HTTP://' ) then if verify( right( USE, 1 ), ':;,.', 'Match' ) then do URL = left( URL, length( URL ) - 1 ) end /* kludge for text URL with trailing comma or similar */ /* maybe add special handling of implicit file: and news: URLs */ /* maybe add special handling of explicit mailto:, dict:, etc. */ address CMD '@RXLYNX' QUOT( URL ) ; if rc = 0 then exit 0 'emsg RXLYNX' URL '(' || rc || ')' ; exit 1 QUOT: procedure /* quote URL using "...": */ parse arg SRC ; DST = '' ; POS = pos( '"' , SRC ) do while POS > 0 DST = DST || left( SRC, POS -1 ) || '%22' SRC = substr( SRC, POS +1 ) ; POS = pos( '"' , SRC ) end SRC = DST || SRC ; DST = '' ; POS = pos( ' ' , SRC ) do while POS > 0 DST = DST || left( SRC, POS -1 ) || '%20' SRC = substr( SRC, POS +1 ) ; POS = pos( ' ' , SRC ) end SRC = DST || SRC ; DST = '' ; POS = pos( ',' , SRC ) do while POS > 0 DST = DST || left( SRC, POS -1 ) || '%2C' SRC = substr( SRC, POS +1 ) ; POS = pos( ',' , SRC ) end SRC = DST || SRC ; DST = '' ; POS = pos( '&', SRC ) do while POS > 0 DST = DST || left( SRC, POS -1 ) || '&' SRC = substr( SRC, POS +5 ) ; POS = pos( '&', SRC ) end DST = '"' || DST || SRC || '"' ; say 'href=' || DST return DST