home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 545a.lha / PowerVisor_v1.0 / docs.LZH / docs / Scripts < prev    next >
Encoding:
Text File  |  1991-09-01  |  11.2 KB  |  292 lines

  1. *-----------------*
  2. * Tutor : Scripts * Sun Sep  1 15:00:47 1991
  3. *-----------------*
  4.  
  5. ===================== Commands used in this tutorial =========================
  6.  
  7.    assign      Assign to a variable for use in ARexx
  8.    attach      Attach a command to a key
  9.    awin        Open/close 'Rexx' logical window
  10.    cleanup     Free all memory allocated with 'alloc'
  11.    front       Bring PowerVisor to the front
  12.    go          Jump to memory
  13.    hide        Hide output from ARexx script
  14.    list        List a list
  15.    load        Load a file in memory
  16.    pvcall      Call PowerVisor internal variable
  17.    remattach   Remove a keyattachement
  18.    remvar      Remove a variable
  19.    rx          Start an ARexx script
  20.    script      Start a script
  21.    sync        Synchronize ARexx with PowerVisor
  22.    unhide      Unhide output from ARexx script
  23.    unsync      Undo synchronization of ARexx with PowerVisor
  24.    vars        Show all variables
  25.    void        Evaluate expressions
  26.  
  27. ===================== Functions used in this tutorial ========================
  28.  
  29.    alloc       Allocate memory
  30.    eval        Evaluate string
  31.    free        Free memory
  32.    if          Conditional evaluation
  33.  
  34. ============================== Introduction ==================================
  35.  
  36. This tutor file explains everything (or almost everything at least) that
  37. there is to know about ³scripts for PowerVisor. This is already quiet a lot.
  38. ²ARexx scripts, ²PowerVisor scripts and ²machinelanguage scripts are all
  39. explained here.
  40.  
  41. =========================== PowerVisor scripts ===============================
  42.  
  43. ²²PowerVisor scripts are the simplest. A PowerVisor script is simply a bunch
  44. of PowerVisor commands put after each other. You can't do special things
  45. in scripts. There are a few things that must be noted though :
  46.  
  47.    - You can put ¹comments in your script files by putting a ';' in front
  48.      of the line (you may put spaces in front of the ';')
  49.    - The 'quit' command works different in scripts. The 'quit' command
  50.      stops the script. (PowerVisor will not quit)
  51.    - The 'script' command does not work in scripts. You can't recursively
  52.      execute scripts
  53.  
  54. You can start a script with the 'script' command.
  55.  
  56. The recommended place for scripts is the ¹s:pv subdirectory but PowerVisor
  57. will first try the ²current directory. When a script is located in the
  58. current directory or in the s:pv directory you need not specify the full
  59. pathname.
  60.  
  61. There is one exception. The ¹Startup-PowerVisor script always resides
  62. in the s: directory.
  63.  
  64. There are some commands in functions present in PowerVisor that can
  65. be used from the PowerVisor commandline but are more useful in scripts.
  66. Two of these functions are 'if' and 'eval'. They are explained more fully
  67. in the 'Expressions' tutorial file.
  68.  
  69. Of course, commands like 'print' and 'locate' are also more useful in
  70. scripts.
  71.  
  72. For a fully documented script example, look at ¹s:pv/mkeys.explained.
  73. This script installs a memory viewer. Don't be alarmed at the apparent
  74. complexity of this script (well, you may alarm yourselves a bit, because
  75. it is a complex example :-), once you got the feeling you will find it
  76. rather easy to use scripts in general.
  77.  
  78. If you use ¹variables in your script it is recomended that you put
  79. an ¹underscore ('_') in front of your variable. That way you minimize
  80. the chances for variable collision with user variables. If you are
  81. ready with the variable use 'remvar' to remove it.
  82.  
  83. ============================== ARexx scripts =================================
  84.  
  85. For more complex scripts you can use ¹¹ARexx. With ARexx you can interface
  86. PowerVisor to all other programs that use ARexx. If you want you could even
  87. write an ARexx script to debug programs from within your favorite editor,
  88. or edit files from within PowerVisor :-)
  89.  
  90. The ³PowerVisor ARexx port is called ¹'REXX_POWERVISOR'. This port is
  91. the default ARexx port if your script is started from PowerVisor. But
  92. if you want to make global scripts (scripts that can be started from
  93. anywhere, like the Shell or an editor) you must use :
  94.  
  95. ARexx< address rexx_powervisor
  96.  
  97. before you issue any PowerVisor command.
  98.  
  99. You can of course also use :
  100.  
  101. ARexx< address rexx_powervisor 'some powervisor command'
  102.  
  103. (Note that an ARexx script always starts with a comment /* ... */)
  104.  
  105.  
  106. Almost all PowerVisor commands can be used from within an ARexx script.
  107. There are some differences compared with the commandline :
  108.  
  109.    - You can't use ¹abbreviations for commands, you must always type the
  110.      full commandname
  111.    - You can't use ¹prefixes like '-' and '~' before a command. ('~' is
  112.      not useful). If you want to ²hide output ('-'), you must use 'hide'
  113.    - The 'quit' command is ignored
  114.    - You get some new commands ('assign', 'hide', 'unhide', 'sync',
  115.      'async' and 'front') (explained below)
  116.    - ¹Functions are called the same way as commands. The result is put
  117.      in the ²'result' variable (if you use ²'options results' in
  118.      the ARexx script)
  119.  
  120. You can use the 'rx' command to start an ARexx script. This command
  121. starts the script ¹asynchronous. This means that while the script is
  122. running you can still use PowerVisor commands. If you want to disable
  123. this feature you can use the 'sync' command from within the ARexx
  124. script. This command ²synchronizes PowerVisor with the ARexx script.
  125. You will not be able to use the PowerVisor commandline. When the
  126. ARexx script is ready, it should call 'async'. If the ARexx script
  127. forgets the 'async' command, you will not be able to use PowerVisor
  128. anymore. You can solve this by sending the command 'async' from
  129. the Shell (with the 'rx' shell command).
  130.  
  131. Note that the ³default file extension for PowerVisor ARexx scripts
  132. is ¹'.pv'. You do not need to type this extension when you use the
  133. 'rx' command.
  134.  
  135. When you execute a PowerVisor command or function from within ARexx
  136. and there is an error (or the command is interrupted) you can
  137. examine the returncode (the 'rc' variable). 'rc' will contain
  138. 0 if there was no error or the PowerVisor error code if there was
  139. an error.
  140.  
  141. Because you can't use the '-' prefix to ²hide output for a command there
  142. is another way to hide output. The 'hide' and 'unhide' commands are
  143. provided for this. After 'hide' all output from the ARexx commands is
  144. hidden (as if there was a '-' in front of the commandline).
  145. 'unhide' restores this situation. Note that you must use 'unhide' otherwise
  146. you might confuse yourselves when you use other ARexx scripts.
  147.  
  148. Normally the output for the ARexx scripts goes to the ³current logical window
  149. ('Main' or 'Extra'). If you open the ³'Rexx' logical window with 'awin',
  150. all the ARexx output will go to that logical window.
  151.  
  152. The 'front' command brings the ²PowerVisor screen to the front.
  153.  
  154. Normally you would use 'rx' to start ARexx scripts. But you can also
  155. use this command to start ARexx commands from within PowerVisor :
  156.  
  157. < rx 'disp 3+4' <enter>
  158. > 00000007 , 7
  159.  
  160. or something more useful :
  161.  
  162. < rx 'address command dir' <enter>
  163. CLI> ...
  164.  
  165. And the directory appears on the shell output window. You can thus use
  166. the 'rx' command to start ²cli commands from within PowerVisor.
  167.  
  168. The last extra command for ARexx is 'assign'. With this command you
  169. can assign something to a ²PowerVisor variable.
  170. For example, the following ARexx script :
  171.  
  172.       file< /* */
  173.       file< address rexx_powervisor
  174.       file< a=1
  175.       file< assign 'a=2'
  176.       file< disp a
  177.       file< disp 'a'
  178.  
  179. Will have as output :
  180.  
  181.       < rx file <enter>
  182.       > 00000001 , 1
  183.       > 00000002 , 2
  184.  
  185. You should understand why
  186.    a=1
  187. is not the same as
  188.    assign 'a=1'
  189.  
  190. The first command assigns 1 to the ²ARexx variable 'a'. This variable
  191. is not directly accessable from within PowerVisor.
  192.  
  193. The second command assign 1 to the PowerVisor variable 'a'. This variable
  194. is not directly accesable from within the ARexx script. You can ask the value
  195. of PowerVisor variables with 'void' :
  196.  
  197.    ARexx< options results
  198.    ARexx< a=1
  199.    ARexx< assign 'a=2'
  200.    ARexx< 'void a'
  201.    ARexx< var1=result
  202.    ARexx< 'void' a
  203.    ARexx< var2=result
  204.  
  205. Note ! var1 will be equal to 2, but var2 will be equal to 1. Can you explain
  206. why ?
  207.  
  208. ¹s:pv/ShowAscii.pv, ¹s:pv/PrintMode.pv and ¹s:pv/PrintHist.pv are three ARexx
  209. script examples that you can examine.
  210.  
  211. ========================= Machinelanguage scripts ============================
  212.  
  213. The following explanation is rather technical. Most PowerVisor users will
  214. probably never write ²²machinelanguage scripts.
  215.  
  216. Machinelanguage scripts or ML scripts are normal AmigaDOS executable files.
  217. In practice these can be programmed in several languages (like C), but
  218. for naming conventions we call them ML scripts.
  219.  
  220. You can execute ML scripts the same way as normal PowerVisor scripts :
  221. with the 'script' command. PowerVisor will automatically check if the
  222. script is a machinelanguage script by reading the first four bytes.
  223. AmigaDOS executable files always begin with the same four bytes.
  224.  
  225.  
  226. Example :
  227.  
  228. < script execfile 10 <enter>
  229.  
  230. will execute the file 'execfile' and give 10 as the first argument
  231. to the machinelanguage script.
  232.  
  233. When a ml-script gets executed some registers contain predefined
  234. information :
  235.  
  236.    a0       A pointer to the rest of the commandline
  237.    a1       Is the pointer to the ²'rc' variable. You can use this pointer
  238.             to store results or to get some value. The 'rc' variable is a
  239.             longword
  240.    a2       Is the pointer to the ¹PVCallTable. This is a table with routines
  241.             for you to use. See the 'TheWizardCorner' file for more
  242.             information about the PVCallTable and the 'pvcall' command
  243.  
  244. You can put the returnvalue in d0. This returnvalue will be the result of
  245. the 'script' command.
  246.  
  247. This is really all there is to machinelanguage scripts. But you should
  248. read the 'TheWizardCorner' file if you really want to make more advanced
  249. ML scripts. ¹s:pv/SearchHist.asm is an example ML script. This script can
  250. be installed on a key to provide a history search utility.
  251.  
  252. ======================= Making ML-scripts resident ===========================
  253.  
  254. If you want you can make ²ml scripts ³resident in memory. This is certainly
  255. a lot faster if you use diskdrives and if the script is big.
  256.  
  257. You can use the 'resident' command to make ML scripts resident. Here
  258. follows an example :
  259.  
  260. < _a={-resident s:pv/SearchHist} <enter>
  261. < attach 'go \(_a)' 04c 2 e <enter>
  262. < attach 'go \(_a)' 04c 1 e <enter>
  263. < remvar _a <enter>
  264.  
  265. These four commands install the 'SearchHist' ML script on the shift-arrow
  266. up key. When these four commands are executed you can search in the
  267. PowerVisor history buffer with this key.
  268.  
  269. The first command ('resident') loads the ML script into memory and assigns
  270. the pointer to the code to the '_a' variable.
  271.  
  272. Using the 'attach' command we attach the 'go' command to the shift-arrow
  273. up key. Note that when 'attach' parses the command string it will replace
  274. \(_a) with the contents of the variable '_a'. This is the pointer to the
  275. code of the ML script.
  276.  
  277. The last command removes the variable.
  278.  
  279. This is actually not very difficult once you get used to it.
  280.  
  281. The 'go' command works very analogous to the 'script' command. The only
  282. difference is that the script must be located in memory instead of a
  283. file. The register conventions are the same.
  284.  
  285. Now you can use <shift>+<up> to search in the ²history buffer. The text
  286. at the left of the cursor in the stringgagdet will remain unchanged. The
  287. script will search all lines beginning with this text.
  288.  
  289. You can use 'unresident' to remove a loaded file. All resident files
  290. are also automatically removed when PowerVisor quits.
  291.  
  292.