/**
 **  VER$: GetXRef.te version 1.0 (13.7.94)
 **  By Timothy J. Aston, modified by Osma Ahvenlampi
 **  Based on GetXRef.ttx by David N. Junod
 **
 **  Display the AmigaGuide format Autodoc page for the word currently under
 **  the cursor from within Quill.
 **
 **  Create a keystroke and/or menuitem and/or button macro with the following
 **  command:
 **    RX GetXRef.quill
 **
 **/
          
/* CONFIGURATION SECTION.
 *
 * The xref_file MUST be changed to reflect your set.
 */
xref_file = "Dev:Doc/AutoDoc.xref"

/**********************************************************
 * Code section.  You should not have to modify any of this.
 */
options results
options failat 255

main:
	/* Add the library if its not already there.
	 */
	IF ~show('L', 'amigaguide.library') then
	   call addlib('amigaguide.library', 0, -30)

	mode = 'SYNC'

	/* Get the name of the screen that TextEdit is being run on.
	 */
	'GETATTR APPLICATION SCREEN VAR' screen

	/* Get the word currently under the cursor from TextEdit.
	 */
	'GETWORD'
	word = result

	/* See if the Autodoc cross-reference table is loaded, and if not, load it.
	 */
	line = GetXRef("OpenWindow()")
	if line = 10 then do
		/* Show that we're doing something in the TextEdit status bar.
		 */
		'SETSTATUSBAR' 'Loading cross-reference file...'

		/* The Autodoc table wasn't loaded, so load it.
		 */
		LoadXRef(xref_file)
	end

	/* See if the word is in the cross-reference table, and if not, we assume that
	 * the word we've been asked to look up is the name of a database.
	 */
	function = word
	xref = 0
	line = GetXRef(function)
	if line = 10 then do
		/* Add the brackets to the name and try again.
		 */
		function = word||"()"

		line = GetXRef(function)
		if line = 10 then do
			function = word
		end
		else do
			xref = 1
		end
	end
	else do
		xref = 1
	end

	/* Show that we're doing something in the TextEdit status bar.
	 */
	'SETSTATUSBAR' 'Loading '||function||'...'

	/* See if we are trying to load a database or a document.
	 */
	if xref = 0 then
		ShowNode(screen, function'.guide', 'main', 1, 0)
	else do
		parse var line '"'doc'"' '"'database'"' linenum type
		ShowNode(screen, database, doc, 1, 0)
	end

	'SETSTATUSBAR' 'Done'

	exit
