[comp.sys.amiga.programmer] Arexx programming help wanted

lindwall@beowulf.ucsd.edu (John Lindwall) (04/24/91)

I'm having a great time learning Arexx -- its a refreshing change from C!
My current (and first) Arexx project is to add some functionality to the
CEDPro editor, and I had some novice-level questions for you Arexx-perts.

1> I have a function which accepts a string as an argument.  The function
   opens and file and searches through the file for the supplied string.
   My problem is that the function is receiving the string in upper-case,
   and I'd like the case preserved.  Its something like this:

	/* */
	call Lookup('UPPERandLowercase')
	exit

	Lookup:
	arg myString
			/* Open file and search for myString */
	say myString
	return

The output from this fragment is UPPERANDLOWERCASE.  How do I preserve case?

2> What kind of modularity can I get out of Arexx?  I plan to implement a
   collection of Arexx scripts which are invoked by various command keys
   from CEDPro.  All of these scripts will be making calls to a set of
   low-level primitives which I have implemented (e.g. Lookup(), above).
   Do I have to copy the entire set of primitive functions into each Arexx
   script file?  Is there a way (aside from writing an External Function
   Library) to maintain a collection of Arexx functions which can be called
   from various scripts?

3> I'm using CEDPro's getstring function to let the user enter a string.
   I'd like to pass a string for the DefaultTitle as well as an _empty_
   DefaultValue.  The syntax is: getstring DefaultValue DefaultTitle.
   I can't seem to successfully pass an empty string for the DefaultTitle
   no matter what horrendous quoting I try.  Currently I pass a string
   consisting of a single space for the DefaultValue, and then strip the
   space off of the return result; which is kind of lame-o.  How can I
   pass an empty string?

Thanks!

John

PS. When I'm done, I plan to distribute my package; in case others may
    find my scripts useful.  
-- 
John Lindwall			lindwall@cs.ucsd.edu
"Oh look at me! I'm all flooby! I'll be a son of a gun!" -- Flaming Carrot

sutela@polaris.utu.fi (Kari Sutela) (04/24/91)

>The output from this fragment is UPPERANDLOWERCASE.  How do I preserve case?

Try:

	Lookup:
	parse arg myString
        ^^^^^

Notice the parse qualifier before ARG.  You should read the chapter on
PARSE-command; it's a really powerful command.

>2> Is there a way (aside from writing an External Function
>   Library) to maintain a collection of Arexx functions which can be called
>   from various scripts?

I have thought about this and it certainly should be possible to write an
ARexx `function server'.  One would call a function somewhat like this:

	result = server( afunctionname [, arguments] )

Server is a separate ARexx script which locates the functions and makes
the real call.  Performance might be quite bad, though.  Of course, every
primitive function could be in its own script, but having a huge amount
of small scripts is not my idea of fun.

I might try writing a function server when I have the time.

-- 
Kari Sutela	sutela@polaris.utu.fi

dac@prolix.pub.uu.oz.au (Andrew Clayton) (04/24/91)

In article <18587@sdcc6.ucsd.edu>, John Lindwall writes:

> I'm having a great time learning Arexx -- its a refreshing change from C!
> My current (and first) Arexx project is to add some functionality to the
> CEDPro editor, and I had some novice-level questions for you Arexx-perts.

Arexx and CEDpro - positively _the_ best combination for the Amiga! :-)

>    My problem is that the function is receiving the string in upper-case,
>    and I'd like the case preserved.  Its something like this:

> 	arg myString

"arg" is short for 'parse arg upper'.  Use 'parse arg myString' and your
problem will disappear.

> 2> What kind of modularity can I get out of Arexx?  I plan to implement a

Arexx can call other scripts from within a script.

> 3> I'm using CEDPro's getstring function to let the user enter a string.
>    I'd like to pass a string for the DefaultTitle as well as an _empty_
>    DefaultValue.  The syntax is: getstring DefaultValue DefaultTitle.
>    I can't seem to successfully pass an empty string for the DefaultTitle
>    no matter what horrendous quoting I try.  Currently I pass a string
>    consisting of a single space for the DefaultValue, and then strip the
>    space off of the return result; which is kind of lame-o.  How can I
>    pass an empty string?

I just spent 5 minutes reading the manual, and creating this:

                              ---cut
/*rexx*/

/*test getstring*/

options results

getstring '" "' "My Test"

IF (result = "") | (result= "RESULT") THEN 
  okay1 "Need input, Stephanie"
ELSE 
  okay1 "you entered:" result
                               ---cut

Which duly said "Need input, Stephanie" if I just pressed return, or sent back
what I typed into the string requester.  [No, I'm not a transvestite, you
fools!  The quote is from Short Circuit.  Sheesh! :-/]

The way I originally read your message, you wanted to pass an empty string to
'DefaultTITLE' which, of course, you can't do :-(.  I guess you made a typo.
What application could call for a null defaulttitle?  :-)

Hope that's of use to you.

Dac
--
David Andrew Clayton. // _l _  _ dac@prolix.pub.uu.oz.au    *or*|I post.I am.
Canberra, Australia.\X/ (_](_l(_ ccadfa.cc.adfa.oz.au!prolix!dac@munnari.oz

yorkw@stable.ecn.purdue.edu (Willis F York) (04/24/91)

lindwall@beowulf.ucsd.edu (John Lindwall) writes:

>1> I have a function which accepts a string as an argument.  The function
>   opens and file and searches through the file for the supplied string.
>   My problem is that the function is receiving the string in upper-case,
>   and I'd like the case preserved.  Its something like this:

>	/* */

>	call Lookup('UPPERandLowercase')
>	exit

>	Lookup:


>	arg myString
>			/* Open file and search for myString */
>	say myString
>	return

>The output from this fragment is UPPERANDLOWERCASE.  How do I preserve case?

I've had stuff do this befor too, i fixed it so it CAN be done.
I THINK ya need to put ANOTHER set of quote marks around the STRING.
Whats happening is that one thing is strippingg off quotes, and then 
another sees no quotes so it uppercases automaticially.
Try the test with somthing like   the below

note ThE SpACe
    ^   ^  

If ya just get the NOTE back ya need to add on quotes somewhere like this.

/**/
getstring foo
/* Foo will have spaces /case ect in tact*/
/* But if ya call a function onto it the  lack of quotes will 
   cause the spaces to get eaten, and upercased */

foo = "'"||foo||"'"
/* NOW ya can work with foo */

msg1 foo 

>2> What kind of modularity can I get out of Arexx?  I plan to implement a
>   collection of Arexx scripts which are invoked by various command keys
>   from CEDPro.  All of these scripts will be making calls to a set of
>   low-level primitives which I have implemented (e.g. Lookup(), above).
>   Do I have to copy the entire set of primitive functions into each Arexx
>   script file?  Is there a way (aside from writing an External Function
>   Library) to maintain a collection of Arexx functions which can be called
>   from various scripts?

Not sure what ya mean, ya can call an arexx script from an arexx script.
I got 1 script that loads all the libraries, so it get's called by other 
rexx scripts all the time.  

>3> I'm using CEDPro's getstring function to let the user enter a string.
>   I'd like to pass a string for the DefaultTitle as well as an _empty_
>   DefaultValue.  The syntax is: getstring DefaultValue DefaultTitle.
>   I can't seem to successfully pass an empty string for the DefaultTitle
>   no matter what horrendous quoting I try.  Currently I pass a string
>   consisting of a single space for the DefaultValue, and then strip the
>   space off of the return result; which is kind of lame-o.  How can I
>   pass an empty string?

Hmm tell it a variable
name with a "null" character in it.
Or give it a null char for thr title.




>PS. When I'm done, I plan to distribute my package; in case others may
>    find my scripts useful.  

Be sure to post those Puppies!
I'm allways looking for New AREXX-CED-Whatever stuff.

--
yorkw@ecn.purdue.edu  aka Willis F York   aka Squid on IRC 
The only thing that Apple invented is the idea to borrow Xerox-invented ideas.  
(Hope THIS sig don't insult anyone!)   :^) 

mwm@pa.dec.com (Mike (My Watch Has Windows) Meyer) (04/25/91)

In article <18587@sdcc6.ucsd.edu> lindwall@beowulf.ucsd.edu (John Lindwall) writes:
   1> I have a function which accepts a string as an argument.  The function
      opens and file and searches through the file for the supplied string.
      My problem is that the function is receiving the string in upper-case,
      and I'd like the case preserved.  Its something like this:

   The output from this fragment is UPPERANDLOWERCASE.  How do I preserve case?

As has been pointed out, use "parse arg" instead of "arg". Also, if
you're going to pass binary variables around, be warned that "arg" is
an invocation of "parse", and can twiddle your strings if you're not
carefull.

   2> What kind of modularity can I get out of Arexx?  I plan to implement a
      collection of Arexx scripts which are invoked by various command keys
      from CEDPro.  All of these scripts will be making calls to a set of
      low-level primitives which I have implemented (e.g. Lookup(), above).


Put those scripts in seperate files with the names you're going to be
calling them from. Don't make it a procedure or bother with a label.
If you're going to be using them from different hosts, don't put an
extension on the function name (of course, this requires that it
doesn't require a specific host for it to run).

   3> I'm using CEDPro's getstring function to let the user enter a string.
      I'd like to pass a string for the DefaultTitle as well as an _empty_
      DefaultValue.  The syntax is: getstring DefaultValue DefaultTitle.
      I can't seem to successfully pass an empty string for the DefaultTitle
      no matter what horrendous quoting I try.  Currently I pass a string
      consisting of a single space for the DefaultValue, and then strip the
      space off of the return result; which is kind of lame-o.  How can I
      pass an empty string?

Depends on how CedPro parses that input. If it were sane, then
something like:

	'getstring "" Title'

would work. Of course, CedPro may not be sane...

	<mike
--
Can't buy happiness no matter what you do		Mike Meyer
Can't get to heaven on roller skates			mwm@pa.dec.com
Can't take a taxicab to Timbuktu			decwrl!mwm
Life is hard.

lindwall@beowulf.ucsd.edu (John Lindwall) (04/26/91)

In article <1909c9ad.ARN1b30@prolix.pub.uu.oz.au> dac@prolix.pub.uu.oz.au writes:
>In article <18587@sdcc6.ucsd.edu>, John Lindwall writes:
>> 3> I'm using CEDPro's getstring function to let the user enter a string.
>>    I'd like to pass a string for the DefaultTitle as well as an _empty_
>>    DefaultValue.  The syntax is: getstring DefaultValue DefaultTitle.
>
>I just spent 5 minutes reading the manual, and creating this:
>/*rexx*/
>/*test getstring*/
>options results
>getstring '" "' "My Test"
>IF (result = "") | (result= "RESULT") THEN 
>  okay1 "Need input, Stephanie"
>ELSE 
>  okay1 "you entered:" result

Thanks for the excellent help for my first two questions (I must have been
sleeping when I read the description of ARG!).  The sample code you show
above is something I also tried, as it is given in an example in the CEDPro
manual; unfortunately is doesn't do what I want.

The example passes a space character as the DefaultValue.  If the user types
a string, the space is appended to their input.  To see this effect replace
the last okay1 call with:

okay 1 "you didn't really enter: [" || result || "]"

My application needs the input string without any bogus appended space char.
As I mentioned I currently strip the trailing blank off, which is good enough
I suppose.  But I was hoping I could pass an empty as the DefaultValue so
that I would get the user's input string returned without any bogus tailing
blank.

PS. Thanks to everyone else who has replied to my query as well!
-- 
John Lindwall			lindwall@cs.ucsd.edu
"Oh look at me! I'm all flooby! I'll be a son of a gun!" -- Flaming Carrot

dac@prolix.pub.uu.oz.au (Andrew Clayton) (04/26/91)

In article <18659@sdcc6.ucsd.edu>, John Lindwall writes:

> Thanks for the excellent help for my first two questions

I think it's great when I _can_ answer a question. :-).

> The example passes a space character as the DefaultValue.  If the user types
> a string, the space is appended to their input.  To see this effect replace
> the last okay1 call with:
>
> okay 1 "you didn't really enter: [" || result || "]"

You're right too.  That's a bit of a shame.  You can strip the trailing blank
of in a number of ways though, as you said, it's just a little kludgy.

Dac
--
David Andrew Clayton. // _l _  _ dac@prolix.pub.uu.oz.au    *or*|I post.I am.
Canberra, Australia.\X/ (_](_l(_ ccadfa.cc.adfa.oz.au!prolix!dac@munnari.oz