/*
** $VER: FetchRefs.bed 1.0 (18.04.96)
**
** FetchRefs - By Gerbert Nuijen
**
** An ARexx script to invoke FetchRefs from BED. It will get the current word
** under the cursor and will send an request to FetchRefs to get all possible
** references. It will automatically open an window with possible refs on the
** BED screen.
**
*/

/* Set some options of ARexx */
OPTIONS RESULTS
OPTIONS FAILAT 21

/* Get the current word under the cursor */
GetWord
function = RESULT

IF word="" THEN DO
	BeepScreen
	SetStatusBar "Cursor not on a word!"
	RETURN
END

/* Define a temporary filename to put the reference into */
cutat = VERIFY(function, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890_")
filename = 'T:FR_' || LEFT(function, MAX(0, cutat - 1))

/* It doesn't matter whether we want a taglist, varargs or whatever function */
IF RIGHT(function, 7) = "TagList" THEN
	 function = LEFT(function, LENGTH(function) - 7)
ELSE IF RIGHT(function, 4) = "Tags" THEN
	 function = LEFT(function, LENGTH(function) - 4)
ELSE IF RIGHT(function, 1) = "A" THEN
	 function = LEFT(function, LENGTH(function) - 1)

/* Get the reference */
address 'FETCHREFS' FR_GET function || '(%|Tags|TagList|A)' filename FILEREF

/* Load the file */
IF rc ~= 0 THEN DO
	/*
		Maybe search with FindSymbol.bed for more references ??
	*/

	BeepScreen
	SetStatusBar RC2

	/* Return */
	EXIT 0
END
ELSE DO

	/* Print the reference */
	'OpenDoc SETTINGS=BED:Support/SAS_C.prf DEFINITIONS=BED:Support/SAS_C.dfn'	filename

	ADDRESS VALUE RESULT
	Move RC2
	ScrollView 2

	/* Delete the temporary file */
	ADDRESS COMMAND 'C:Delete >NIL:' filename

	/* Return */
	EXIT 0
END
