Guidance
指路人
g.yi.org
Guidance Forums / Reginald Rexx / Debugging an RPC Macro

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. Debugging an RPC Macro
#5759
Posted by: misi01 2005-01-28 21:40:29 Last edited by: Jeff Glatt 2007-06-25 03:47:15 (Total edited 1 time)
I'm having trouble with my first RPC macro. I want to be able to highlight the name of some external script being called, and then run a macro to load that script into the editor.

How do I debug such a macro?
Michael
Message2. Re: Macro problem
#5766
Posted by: Jeff Glatt 2005-01-29 05:55:10 Last edited by: Jeff Glatt 2007-06-26 14:58:24 (Total edited 1 time)
Don't "Add the macro" until it is completely finished and debugged.

To test/debug a macro while you're creating it, simply do what you do with all other scripts. Make it the current editor window and select "Debug -> Start debugger" or "Debug -> Run". Of course, you'll also need some other editor window open for your macro script to operate upon it. RPC will automatically choose that other script/window as the target to operate upon.




You need to first call EditGetDoc() at the beginning of your macro. This does some bookkeeping to determine what document (ie, editor window) the rest of the functions operate upon. If you just want whatever is the current document, then call EditGetDoc() without any arg. If you want a specific file loaded and operated upon, pass the full pathname of that file. Here's a version of your script that will do what you want:
/* Get whatever is the current document. All
 * subsequent calls will operate upon this
 * editor window until we do another editgetdoc
 * or editopendoc.
 */
err = editgetdoc()
IF err == "" THEN DO
   guisay("No document is loaded!")
   RETURN
END

/* Get the currently selected lines. */
err = editgettext('scriptname.')
IF err \== "" THEN DO
   guisay(err)
   RETURN
END

/* Is there no text selected? */
IF scriptname.1 = "" THEN DO
   guisay("Mark a script name for loading first!")
   RETURN
END

/* Check that script name ends in .rex */
scriptname = STRIP(scriptname.1)
IF TRANSLATE(FILESPEC('E', scriptname)) \== ".rex" THEN 
scriptname = scriptname || '.rex'

/* Load that script. EditOpenDoc will fail with
 * an error message if the script can't be found.
 */
err = editopendoc(scriptname)
IF err \== "" THEN guisay(err)
Message3. Re: Macro problem
#5787
Posted by: kjactive 2005-02-03 03:24:09
Your code is not very efficient. Why use all these err = since you use err only for testing?
/* Get whatever is the current document. All
 * subsequent calls will operate upon this
 * editor window until we do another editgetdoc
 * or editopendoc.
 */
IF editgetdoc() \== '' THEN DO
   RETURN guisay("No document is loaded!")
END

/* Get the currently selected lines. */
IF editgettext('scriptname.') \== '' THEN DO
   RETURN guisay(err)
END

/* Is there no text selected? */
IF scriptname.0 = 0 THEN DO( zero is stem counter )
   RETURN guisay("THERE WAS NO LINES AVAILBLE IN CURRENT DOCUMENT")
END

/* Check that script name ends in .rex */
scriptname = STRIP(scriptname.1)
IF TRANSLATE(FILESPEC('E', scriptname)) \== ".rex" THEN 
scriptname = scriptname || '.rex'

/* Load that script. EditOpenDoc will fail with
 * an error message if the script can't be found.
 */
err = editopendoc(scriptname)
IF err \== "" THEN guisay(err)
Message4. Re: Macro problem
#5789
Posted by: Jeff Glatt 2005-02-03 03:49:39
If efficiency is what you're going after (which is not really what I do if I'm showing example code), then it would be more efficient to code:
IF editgetdoc() \== '' THEN
   RETURN guisay("No document is loaded!")
Eliminating the DO/END makes a difference. (Of course, the above assumes that the program running your script doesn't expect your script to return anything. That is true of both Script Launcher and Programmer Center. Otherwise, the program may do something weird with the return of RXSAY).

But, the most efficient thing to do is to set Programmer Center to raise a condition for an error, and utilize CATCH. Then you eliminate all of the error checking after each call:
/* Raise USER 1 if a macro function fails */
rexxedheading = 1
rexxederr = 1

editgetdoc()
editgettext('scriptname.')
scriptname = STRIP(scriptname.1)
IF TRANSLATE(FILESPEC('E', scriptname)) \== ".rex" THEN 
scriptname = scriptname || '.rex'
editopendoc(scriptname)

CATCH user 1
   CONDITION('M')
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Wed 2024-2-21  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0