\ This file compiles Specific TEXTRA interface words.  Author: Mike Haas
\
\ This program is placed into the public domain.
\
\                         IMPORTANT
\                         =========
\
\ SEE THE NOTE BELOW ABOUT THE AREXX BUG FIX FOR JFORTH 3.0 & 3.1
\
\    NOTE: This program includes a workaround for a bug
\          in the JForth ARexx code.  You can compile
\          this file and it will work, but to really do this
\          right, you should fix jrx:ARexxTools.f as follows:
\          
\          1. Open jrx:ARexxTools.f and locate the definition
\             for RX.GET.MSG.  Add the following lines to it:
\             
\                 rx-result1 off
\                 rx-result2 off
\
\    THE USE OF THIS PROGRAM REQUIRES TEXTRA 1.12 OR LATER.
\
\ ---------------------------------------------------------------
\
\ $TxOpen  ( filename -- , opens in textra )
\
\ TxOpen   ( -- , <filename> , opens in textra )
\
\ TxView   ( -- , <wordname> , found & displayed )
\                 - works like FILE?
\
\ View     ( -- , <wordname , same as TxView )
\
\ 00000 08-jun-93 mdh     Initial version

include? task-Rexxclude.f  JRX:Rexxclude.f

ANEW TASK-Textra.F

decimal

: WorkAround  ( -- , this should be done by RX.GET.MSG )
  rx-result1 off
  rx-result2 off
;

0 .if
: rx.put.textra.launch  ( 0$ -- , will try to launch if nec )
;
.then


\ --------------------- OPEN SPECIFIED FILE

: |TxOpen$|  ( $filename -- 0 = error )
  " OPENFILE "  pad $move
  count pad $append
  pad count >dos  dos0 rx.put.textra 0=
  WorkAround
;

: TxOpen$  ( $filename -- )  |TxOpen$|  drop ;

: TxOpen  ( <command_line> -- , "string" )
  eol word TxOpen$
;


\ --------------------- DISPLAY JFORTH WORD  (FILE? to TEXTRA)

: NFA>FILE ( nfa -- addr cnt , file? with this NFA )
	1 #nested !
	\   >newline  dup id. 
	BEGIN  dup nextname? ( thisnfa prevnfa/0 -- ) -dup
		 IF   swap drop dup nested?
			  IF    1 #nested +!
			  THEN
			  dup fileheader?  dup
			  IF   -1  #nested +!
			  THEN #nested @ 0= and
		 ELSE cr ." NFA>FILE$ : fileheaders not found!" quit
		 THEN
	UNTIL
	( ."  was compiled from "  )
	( nfa -- )  dup c@ $ 1f and    ( nfa cnt -- )
	4 -  ( nfa cnt-4 -- ) ( adjust out the locater text )
	swap 5 + swap  ( adr cnt -- , of filename )
;

create &here  40 allot
create &name  40 allot

: |TxView|  { fname fnamelen wordname -- }   \ 36 here$ &here  36 name$ &name -- }
  \
  &name off    fname fnamelen &name $append
  &name |TxOpen$|
  IF
     " FIND "  pad $move
     &here count pad $append
     pad count >dos  dos0 rx.put.textra drop
     WorkAround
  THEN
;

: TxView$  ( $name -- )
  dup &here $move  find
  IF   ( pfa -- )  >name nfa>file   &here   |TxView|
  ELSE $type ."  isn't in the selected vocabularies."
  THEN
;

: TxView   ( -- )   ( eats: name )
  bl word TxView$
;

: view TxView ;

\ THIS WORD TO BE USED BY TEXTRA ONLY!!!

: RETURNFILENAME  ( $name -- )
	find
	IF
		( -- pfa )  dup >name nfa>file CreateArgstring() ?dup
		IF
			rx-result2 !
		THEN
	THEN
	drop  rx-result2 @ 0=
	IF
		0" NOTIFY NOT FOUND" rx.put.textra drop
		Workaround
	THEN
;
