'set novalue on' /* force KEXX and its way of SIGNAL ON NOVALUE */ /* Usage: [MACRO] HREF [optional undelimited target] */ /* Example: define A-HOME 'macro href' */ /* HREF focus word to href-link */ /* HREF https: dito after Loc /https:/ */ /* Purpose: Convert focusword.2() to dummy hypertext link. */ /* If style use href in link and text. */ /* If new style use href in link and text. */ /* If A012345 use http://purl.net/net/eisa/A012345 */ /* All & in URL converted to & (if necessary). */ /* Bugs: May not convert more than one occurence of the */ /* same focus word in one line sometimes - affects */ /* only and optional undelimited target */ /* See also: KHELP FOCUSWORD */ /* Requires: Kedit 5.0 (Frank Ellermann, 2004) */ 'extract /STREAM/ALT/' ; 'stream off' if arg( 1 ) <> '' then do URL = delimit( arg( 1 )) 'Locate' URL 'CL 1' ; if rc <> 0 then exit OOPS( rc ) 'CL -' || URL ; if rc <> 0 then exit OOPS( rc ) end if focusword.2() = '' then do 'emsg cannot convert missing focus word' ; exit OOPS( 1 ) end URL = focusword.2() ; REF = URL ; 'CL 1' 'CL -' || delimit( URL ) ; if rc <> 0 then exit OOPS( rc ) if abbrev( URL, 'A') & datatype( substr( URL,2,6 ), 'w' ) then do URL = left( URL, 7 ) /* special for Neil Sloane's EIS */ REF = 'http://purl.net/net/eisa/' || URL end else if abbrev( translate( URL ), '', URL )) REF = length( URL ) /* 24 : */ if REF <= 6 then do /* 18 : 123456..456789012345678 */ 'emsg strange in' focusword.2() ; exit OOPS( 1 ) end REF = substr( URL, 6, REF - 6 ) 'c' delimit( URL, REF ) ; if rc <> 0 then exit OOPS( rc ) URL = REF end else if abbrev( URL, '<' ) then do URL = left( URL, pos( '>', URL )) REF = length( URL ) /* same trick as above for links */ if REF <= 2 then do /* in angle brackets (new style) */ 'emsg strange <> in' focusword.2() ; exit OOPS( 1 ) end REF = substr( URL, 2, REF - 2 ) 'c' delimit( URL, REF ) ; if rc <> 0 then exit OOPS( rc ) URL = REF end N = pos( '&', REF ) if N <> 0 then do do until N = 0 if substr( REF, N + 1, 4 ) <> 'amp;' then REF = insert( 'amp;', REF, N ) N = pos( '&', REF, N + 4 ) end 'c' delimit( URL, REF ) ; if rc <> 0 then exit OOPS( rc ) URL = REF end 'CL 1' ; 'refresh' 'CL -' || delimit( URL ) ; 'CL' length( URL ) ; 'Ci ' 'CL -' || length( URL ) ; 'Ci ' 'CL' length( REF ) + 11 ; say 'href="' || REF || '"' URL 'set alt' min( ALT.1 + 1, alt.1()) ALT.2 + 1 ; exit OOPS( rc ) OOPS: 'stream' STREAM.1 ; return arg( 1 ) /* reset 'STREAM on' */