/* OS/2 REXX: format input sequence for EIS using clipbrd.exe, */ /* clipbrd2.exe should also work (shipped with lynx for OS/2), */ /* but I haven't tested it. Replace clibrd by clipbrd2 below. */ /* If you have no clipbrd.exe set STD=1 for standard output - */ /* you'd also set STD=1 in a DOS or UNIX (regina) environment. */ /* The keywords "huge" and "done" are not more used, see FAQ: */ /* http://www.research.att.com/~njas/sequences/FAQ.html#Z21 */ STD = 0 AUT = 'Frank.Ellermann@t-online.de' /* example: STU A9999 1 -2 3 -4 5 -6 7 -8 9 */ /* result: %I A009999 */ /* %S A009999 1,2,3,4,5,6,7,8,9 */ /* %V A009999 1,-2,3,-4,5,-6,7,-8,9 */ /* %N A009999 a(n)=?????????? */ /* %K A009999 sign,more */ /* %O A009999 0,2 */ /* %A A009999 Frank.Ellermann@t-online.de, 11 Jun 2001 */ /* example: STU 1 0 1 1 0 1 1 1 0 1 1 1 1 0 1 1 1 1 1 0 */ /* result: %I A000001 */ /* %S A000001 1.0,1,1,0,1,1,1,0, */ /* %T A000001 1,1,1,1,0,1,1,1,1, */ /* %U A000001 1,0 */ /* %N A000001 a(n)=?????????? */ /* %K A000001 nonn,easy, */ /* %O A000001 0 */ /* %A A000001 Frank.Ellermann@t-online.de, Jun 11 2001 */ /* example: clipbrd | STU A43 */ /* (after copying the terms "[2,3,5,"..."]" to the clipboard) */ /* result: %I A000043 */ /* %S A000043 2,3,5,7,13,17,19,31,61,89,107,127,521, */ /* etc. almost ready for a comment about sequence A000043 with */ /* the 39th Mersenne prime as next term (not yet confirmed). */ signal on novalue name TRAP ; signal on syntax name TRAP signal on error name TRAP ; signal on halt name TRAP MIX = space( translate( translate( arg( 1 ), ' ', '+,' ))) if abbrev( MIX, 'A' ) then do parse var MIX 'A' ID MIX ID = 'A' || right( ID, 6, 0 ) end else ID = 'A000001' if MIX = '' then do while sign( lines()) MIX = space( MIX translate( linein(),, '[+,]' )) end if MIX = '' then do parse source . . SEQ say 'usage:' SEQ '[Anum.] [seq. of integers]' say ' or:' SEQ '[Anum.]' say 'The default Anum. is A000001 for a new sequence.' say 'Sequence can be read from stdin (e.g. in a pipe).' if STD then STD = 'stdout' ; else STD = 'the clipboard' say 'Output in EIS-format is written to' STD || '.' exit 1 end if datatype( MIX, 'n' ) then MIX = FRAC( MIX ) if STD then rc = 0 ; else '@echo %%I' ID '| clipbrd' SEQ = space( translate( MIX, ' ', '-' )) if MIX <> SEQ then do KEY = 'sign' STUB( '%S', '%T', '%U', ID, SEQ ) call STUB '%V', '%W', '%X', ID, MIX end else KEY = 'nonn' STUB( '%S', '%T', '%U', ID, SEQ ) OFF = 0 ; call CLIP '%N' ID, 'a(n)=??????????' do MIX = 1 to words( SEQ ) if OFF = 0 & word( SEQ, MIX ) > 1 then OFF = MIX end MIX call CLIP '%K' ID, KEY if OFF > words( SEQ ) then call CLIP '%O' ID, '0' else call CLIP '%O' ID, '0' OFF parse value date() with U M D call CLIP '%A' ID, AUT translate( '' M U D, d2c( 255 ), ' ' ) exit rc STUB: procedure expose STD rc arg S, T, U, ID, SEQ ; LIM = 69 if length( SEQ ) < LIM then do call CLIP S ID, SEQ ; return 'more' end X = lastpos( ' ', left( SEQ, LIM )) if X = 0 then do call CLIP 'truncated:', word( SEQ, 1 ) ; return 'easy' end call CLIP S ID, space( left( SEQ, X )) || ',' SEQ = space( substr( SEQ, X )) if length( SEQ ) < LIM then do call CLIP T ID, SEQ ; return 'more' end X = lastpos( ' ', left( SEQ, LIM )) if X = 0 then do call CLIP 'truncated:', word( SEQ, 1 ) ; return 'easy' end call CLIP T ID, space( left( SEQ, X )) || ',' SEQ = space( substr( SEQ, X )) if length( SEQ ) < LIM then do call CLIP U ID, SEQ ; return 'easy' end X = lastpos( ' ', left( SEQ, LIM )) if X = 0 then do call CLIP 'truncated:', word( SEQ, 1 ) ; return 'easy' end call CLIP U ID, space( left( SEQ, X )) SEQ = space( substr( SEQ, X )) call CLIP 'truncated:', SEQ return 'easy' CLIP: procedure expose STD rc SEQ = arg( 1 ) translate( arg( 2 ), ', ', ' ' || d2c( 255 )) select when STD then say SEQ when abbrev( SEQ, '%' ) then '@echo %' || SEQ '| clipbrd -a' otherwise '@echo' SEQ '| clipbrd -a' end return rc FRAC: procedure C = arg( 1 ) ; numeric digits 2 * length( C ) S = trunc( C ) ; C = abs( C - S ) do while length( S ) < 204 & C > 0 C = 1 / C ; T = trunc( C ) ; S = S T ; C = C - T end return S /* see , (c) F. Ellermann */ TRAP: /* select REXX exception handler */ call trace 'O' ; trace N /* don't trace interactive */ parse source TRAP /* source on separate line */ TRAP = x2c( 0D ) || right( '+++', 10 ) TRAP || x2c( 0D0A ) TRAP = TRAP || right( '+++', 10 ) /* = standard trace prefix */ TRAP = TRAP strip( condition( 'c' ) 'trap:' condition( 'd' )) select when wordpos( condition( 'c' ), 'ERROR FAILURE' ) > 0 then do if condition( 'd' ) > '' /* need an additional line */ then TRAP = TRAP || x2c( 0D0A ) || right( '+++', 10 ) TRAP = TRAP '(RC' rc || ')' /* any system error codes */ if condition( 'c' ) = 'FAILURE' then rc = -3 end when wordpos( condition( 'c' ), 'HALT SYNTAX' ) > 0 then do if condition( 'c' ) = 'HALT' then rc = 4 if condition( 'd' ) > '' & condition( 'd' ) <> rc then do if condition( 'd' ) <> errortext( rc ) then do TRAP = TRAP || x2c( 0D0A ) || right( '+++', 10 ) TRAP = TRAP errortext( rc ) end /* future condition( 'd' ) */ end /* may use errortext( rc ) */ else TRAP = TRAP errortext( rc ) rc = -rc /* rc < 0: REXX error code */ end when condition( 'c' ) = 'NOVALUE' then rc = -2 /* dubious */ when condition( 'c' ) = 'NOTREADY' then rc = -1 /* dubious */ otherwise /* force non-zero whole rc */ if datatype( value( 'RC' ), 'W' ) = 0 then rc = 1 if rc = 0 then rc = 1 if condition() = '' then TRAP = TRAP arg( 1 ) end /* direct: TRAP( message ) */ TRAP = TRAP || x2c( 0D0A ) || format( sigl, 6 ) signal on syntax name TRAP.SIGL /* throw syntax error 3... */ if 0 < sigl & sigl <= sourceline() /* if no handle for source */ then TRAP = TRAP '*-*' strip( sourceline( sigl )) else TRAP = TRAP '+++ (source line unavailable)' TRAP.SIGL: /* ...catch syntax error 3 */ if abbrev( right( TRAP, 2 + 6 ), x2c( 0D0A )) then do TRAP = TRAP '+++ (source line unreadable)' ; rc = -rc end select when 1 then do /* in pipes STDERR: output */ parse version TRAP.REXX . . /* REXX/Personal: \dev\con */ signal on syntax name TRAP.FAIL if TRAP.REXX = 'REXXSAA' /* fails if no more handle */ then call lineout 'STDERR' , TRAP else call lineout '\dev\con', TRAP end when 0 then do /* OS/2 PM: RxMessageBox() */ signal on syntax name TRAP.FAIL call RxMessageBox , /* fails if not in PMREXX */ translate( TRAP, ' ', x2c( 0D )), , 'CANCEL', 'WARNING' end /* replace any CR by blank */ otherwise say TRAP ; trace ?L /* interactive Label trace */ end if condition() = 'SIGNAL' then signal TRAP.EXIT TRAP.CALL: return rc /* continue after CALL ON */ TRAP.FAIL: say TRAP ; rc = 0 - rc /* force TRAP error output */ TRAP.EXIT: exit rc /* exit for any SIGNAL ON */