/*
** SortBlock.ced
**
** $VER: SortBlock.ced 1.0.0 (2.6.93)
**
** This script is designed to execute from a window within CED to
** sort the highlighted area (in a block) alphabetically.  It works similar
** to the built-in functions Rot Marked and Change Case Marked.  You specify
** an area, then call this function.
**
** Note:
** 1. The 'Sort' command must be present in your command path in order for
**       this program to run.
** 2. This program works with temporary files in T:, so you might want to
**       modify it to store instead on a more appropriate device.
**
** This script requires CygnusEd Professional v3.5 (or later) to run.
**
** Copyright © 1990-1993 ASDG, Incorporated  All Rights Reserved
*/


TempUnsortedBlock = "T:TempUnsortedBlock"
TempSortedBlock = "T:TempSortedBlock"


ADDRESS "rexx_ced"
OPTIONS RESULTS


CUT						/* Cut the original block out */
IF (RESULT ~= 0) THEN DO			/* If the user did in fact have a block specified, then... */
	/*
	** Store block in a temporary file.
	*/
	SAVE CLIP AS TempUnsortedBlock

	/*
	** Tell the CLI to sort the newly created file
	*/
	ADDRESS COMMAND "Sort" TempUnsortedBlock TempSortedBlock

	/*
	** Tell CygnusEd to include the newly sorted file
	*/
	ADDRESS "rexx_ced" INCLUDE FILE TempSortedBlock

	/*
	** This STATUS command will ensure that CED finishes loading the
	** sorted file before ARexx sends off the command to delete the
	** file.
	*/
	STATUS RESTNAME

	/*
	** Delete the temporary files.
	*/
	ADDRESS COMMAND "Delete" TempUnsortedBlock
	ADDRESS COMMAND "Delete" TempSortedBlock
END
ELSE DO
	/*
	** No block was marked.
	*/
	CEDTOFRONT
	OKAY1 "Can't sort block.  No block was marked."
END

EXIT 0
