Contributed by: Wayne Swanson
A quick way to add plugin support to your VisPro/Rexx application is to setup a condition where you can make control and window ID's available to the user and he can write a script that would work just like a subroutine written into the code of your program. Your program would read his cmd file and "interpret" it. This makes a lot of power available to your user within the confines of your program.
You can read the cmd file with "Linein" (maybe to a stem variable) and interpret one line at a time but that has a couple of gotcha's. One minor problem is that using "Linein" is always slower than reading a file with "Charin". The other problem is that interpreting a line at a time will disallow things like loops or signal calls to another part of the code.
To get around some of these limitations you can "Charin" the file and interpret the whole thing at once. There are a couple of "gotcha's" here too but we can deal with at least one of them pretty easily.
When you "Charin" a cmd file, you get the line feed/carraige return pairs (crlf) with it also. Here, we'll replace the crlf with a semicolon which is a line separator for rexx cmd files anyways.
The other "gotcha" is that in rexx, you can tell it to keep going onto the next line with a comma. The way we are replacing the crlf with the semicolon I am not sure that rexx will still combine the two lines separated by the semicolon. Although I've never tested it I have just been sure to not use the comma extender. Perhaps one of you has the time to try this. :-)
Here is the explanation of the important lines followed by the snippet.
Arg PLGFileName
IF LENGTH(PLGfilename) > 0 THEN DO
In the application this came from I had already tested for the existing file before I got to this point and only check if the argument has a value. You may want to check for the existance of the file here with SysFileTree or the Stream function.
PLG_value = CHARIN(PLGfilename,1,CHARS(PLGfilename))
rc=stream(PLGfilename,'c','close')
This reads the whole file into the PLG_value variable and closes the file when done.
PLG_value = TRANSLATE(PLG_value,';','0d0a'x)
This is where we are replacing the crlf's ('0d0a'x) with the semicolon (';') This effectively makes your cmd file one long string (held in the PLG_value variable) instead of many lines.
Target=1100
This is a control variable for the writer of the plugin to access a control in the program we are allowing him to work with. In this case it is the control ID of 'EDITWINDOW' which is our MLE.
/* Interpret the Plugin */
interpret PLG_value
I hear many people talk with upturned noses over the "interpret" instruction but it has it's place in the language. What can be easier than this? A very powerful instruction indeed.
We follow all of this with any other commands we need to send to our program. In the following snippet we only reset the undo flag for the mle. You may want to turn off repainting, STDIO etc. Here is the routine as we currently use it in one fell swoop.
/* PlugIn */
Arg PLGFileName
/* Load Plugin */
IF LENGTH(PLGfilename) > 0 THEN DO
PLG_value = CHARIN(PLGfilename,1,CHARS(PLGfilename))
rc = stream(PLGfilename,'c','close')
PLG_value = TRANSLATE(PLG_value,';','0d0a'x)
Target=1100
/* Interpret the Plugin */
interpret PLG_value
/* Reset undo flag MLE */
CALL VpItem window,'EDITWINDOW','SENDMSG','0x01cf'
END
return