/* This is an example ARexx program for communicating with CygnusEd */

/*
	This  program  is  a  demonstration  of  the  ARexx  <--> CygnusEd
interface.  To run this program you must own ARexx.  ARexx is a commercial
product  that  is  not  included  with  CygnusEd  Professional.  To see an
example of another programming controlling CygnusEd Professional if you do
not own ARexx, please look in the OtherPrograms drawer.

	This program does nothing useful, but it is neat to watch.
	*/



/* Let's use a shortcut for the "cr" string... */
cr = '0A'X

first_text_line = 6

options results		/* want this enabled for okay2 testing and other */
			/* commands that return results. */



/* Set the default port name so that commands go to CygnusEd. */
ADDRESS 'rexx_ced'



/* Use the 'open new' menu command to open up a new project. */
'Open new'



/* Expand the new view out to full size. */

expand view



/* Insert some blank lines. */

text cr
text cr
text cr



/* Print out the title line in a fancy way. */

textline = '               ****** Arexx <-- --> CED Demonstration ******'

do i = length(textline) to 1 by -1
   'beg of line'
   text substr(textline,i,1)
end

'end of line'

text cr
'end of file'
text cr



text OKAY1 COMMAND cr cr
text 'Command line = okay1 "The OKAY1 Command"' cr cr
text 'This command brings up a requester containing the message you specify' cr
text 'and returns when the user clicks on the okay gadget.' cr 
okay1 "The OKAY1 Command"
call clear



text 'OKAY2 COMMAND'cr cr
text 'Command line = okay2 "The OKAY2 Command"'cr cr
text 'This command brings up a requester containing the message you specify'cr
text 'with "Yes" and "No Way!" gadgets.  It returns when the user clicks on'cr
text 'one of the gadgets and, if you have set results on in Arexx,  returns'cr
text 'a 1 or 0 depending on whether the user clicked on "Yes" or "No Way!".'cr cr
call time 'r'
okay2 "The OKAY2 Command"
hold = result		/* save the result */
text 'You took' time('E') 'seconds to respond by selecting the '
if hold = 1
   then text '"Yes"'
   else text '"No Way!"'
text ' gadget'cr
call wait(2)
call clear



text 'The TEXT Command'cr cr
text 'The text command is used to enter a string of ascii text into the current'cr
text 'file in CygnusEd.  To stop ARexx from uppercasing the text,  it should be'cr
text 'enclosed  in  quotes.   Non-ascii  or  control  characters  can either be'cr
text 'entered as  hex  data in ARexx by putting an X after a string of hex data'cr
text 'or by using the "Enter ascii" command of CygnusEd. A carriage return must'cr
text 'be entered at the end of each text line.'cr cr
text 'Example command:'cr
text '  text "this is a line." "0a"x"'cr
text '        would enter...'cr
text '  this is a line.'cr 
okay1 'Paused...'
call clear



text 'The JUMPTO Command'cr cr
text 'Command line = "jumpto 10 i"'cr cr
text 'This command lets you jump the CygnusEd cursor to a specified line'cr
text 'and column number position.'cr
do i = 10 to 30
   jumpto 10 i
end
call wait(2)
call clear



text 'The GETFILENAME Command'cr cr
text 'Command line = "getfilename "default/file/name""'cr cr
text 'This command brings up the CygnusEd file requester (written by Colin Fox)'cr
text 'containing  whatever  default  file  name  you  specify.  If you have set'cr
text 'results on in ARexx it returns the file name the user selects,  or a null'cr
text 'string if the user selects nothing.'cr cr
'getfilename default/file/name'
if result = 'RESULT'
   then text 'A null string was returned'cr
   else text 'The returned string was "'result'"'cr
call wait(2.5)
call clear



text 'The GETNUMBER Command'cr cr
text 'Command line = "getnumber 100"'cr cr
text 'This  command  brings up the CygnusEd get_a_number requester.  The default'cr
text 'number  you  specify on the  commandline will be in the requester.  If you'cr
text 'have set results on in ARexx this  will  return  whatever  number the user'cr
text 'enters.  If the user cancels the requester it will return a null string.'cr
getnumber 100
hold = result
text cr
if hold = ''
   then text 'A null was returned'cr
   else text 'The number returned was' hold cr
call wait(2)
call clear



text 'The ENTER ASCII Command'cr cr
text 'Command line = "enter ascii..."'cr
text 'CygnusEd will bring up a requester asking you to specify the'cr
text 'numeric value for the ASCII character you want to enter.'cr cr
text 'Note where the cursor is located before the command is executed'cr
text '(10 is the numeric value for a Carrige Return)'
jumpto 9 1
okay1 'Waiting...'
'Enter ascii...'
call wait(2)
call clear



text "Let's play with the replace command."cr cr cr cr
text "I'll just put in a bit of sample text.  There we are."cr
text "I'll just put in a bit of sample text.  There we are."cr
text "I'll just put in a bit of sample text.  There we are."cr
call wait(1)
jumpto first_text_line + 2
text "I'm going to replace the string 'sample' with the string 'Replacement'"
call wait(3)
counter = 0
do i = 1 to 3
   'replace... sample Replacement'
   call wait(1)
end
'End of file'
call wait(2)
call clear



string1 = 'This is '
string2 = 'the end'
string3 = ' of the demo.'
string4 = '   Is this really '
text '                       '
do i = 1 to length(string1)
   text substr(string1,i,1)
end
do i = 1 to length(string2)
   text substr(string2,i,1)
end
do i = 1 to length(string3)
   text substr(string3,i,1)
end
call wait(2)
do i = 1 to length(string1) + length(string2) + length(string3)
   left
end
do i = 1 to length(string1)
   delete
end
do i = 1 to length(string4)
   text substr(string4,i,1)
end
do i = 1 to length(string2)
   right
end
do i = 1 to length(string3)
   delete
end
text '?'cr

exit 0



/* This routine clears from first_text_line to the end of the file - as */
/* as this isn't more than twenty lines.  A better version would check */
/* to find out when it had reached the end of the file. */

clear:
   jumpto first_text_line 1
   do i = 1 to 20
       delete line
   end
return 0



/* This is a function to delay a specified number of seconds. */

wait:
   arg delay
   call time 'R'
   do while time('E') < delay
      nop
   end
return 0
