home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 6 File / 06-File.zip / dfsee510.zip / dfscript.txt < prev    next >
Text File  |  2003-01-14  |  14KB  |  351 lines

  1.   Display File Systems; version 5.08 01-01-2003  (c) 1994-2003; Jan van Wijk
  2.  ----------------------------[ www.dfsee.com ]-------------------------------
  3.  
  4.  
  5. C O N T E N T S:
  6. ================
  7.  
  8.   Summary of scripting  = how to use scripting with DFSee
  9.   Native scripts
  10.   Batch scripts
  11.   REXX scripts (OS/2 only)
  12.  
  13.  
  14. S U M M A R Y   O F   S C R I P T I N G:
  15. ========================================
  16.  
  17. Scripting is a way to automate functions, in this case DFSee actions.
  18.  
  19. For DFSee there are now three ways to use scripting:
  20.  
  21.  
  22. 1) New in version 4.16: DFSee NATIVE scripting
  23.  
  24.    Here DFSee commands can be placed in a simple text-file and will be
  25.    executed one by one.  This is the first implementation of the native
  26.    script-engine that only supports a simple list of commands.
  27.    The intention is to expand the capabilities of this script-engine
  28.    with conditional constructs like IF and WHILE and more ...
  29.  
  30.    A NATIVE script for DFSee is executed from the DFSee commandline using
  31.    the RUN command with the scriptname as a parameter. DFSee will select
  32.    the NATIVE engine automatically based on the contents of the script.
  33.  
  34.    Native scripting can be very usefull for recovery scenario's where
  35.    multiple partitions need to be recreated and for other repetive tasks
  36.    like analysing an HPFS partition.
  37.  
  38.  
  39.  
  40. 2) The classic way, using batch-files (.BAT or .CMD)
  41.  
  42.    In this case DFSee commands are executed by calling a DFSee executable
  43.    for every DFSee (multi) command.
  44.  
  45.    Normal batch-logic like "if errorlevel ..." can be used to control the
  46.    flow in the script.
  47.  
  48.    One disadvantage to this method is that there is just the returncode from
  49.    a DFSee call to be used in subsequent operations.
  50.    All DFSee commands that depend on each other need to be in a single
  51.    multi-command to work as expected. This could be a problem as a result of
  52.    the limited length of the (DOS) commandline.
  53.  
  54.    Another point is that the DFSee executable will be reloaded for each
  55.    command executed, this can be real slow when working from diskettes.
  56.  
  57.    An example of such a script is the DFSUNFD.BAT and DFSUNFD.CMD that
  58.    collects information needed for partition recovery.
  59.  
  60.  
  61.  
  62. 3) For OS/2 only: the more comfortable way, using REXX as a script engine.
  63.  
  64.    Here the DFSee commands are executed by REXX using a 'subcommand-handler'
  65.    in the DFSee executable. All commands are automatically routed there.
  66.    Commands can also be sent to the shell (cmd.exe) by using 'ADDRESS CMD'.
  67.  
  68.    The REXX subcommand-handler in DFSee makes the most important internal
  69.    DFSee variables available as REXX variables too, so it is much easier
  70.    to interact with DFSee and use results from previous commands.
  71.  
  72.    A NATIVE script for DFSee is executed from the DFSee commandline using
  73.    the RUN command with the scriptname as a parameter. DFSee will select
  74.    either REXX or the NATIVE engine by checking the contents of the script,
  75.    all REXX scripts need to start with the '/*' symbol in the first line.
  76.    This is consistent with the behaviour of CMD.EXE on OS/2 platforms.
  77.  
  78.    An example of a DFSee REXX script is DFSINFO.CMD that collects
  79.    information on all your disks and partitions in a (large) logfile.
  80.  
  81.  
  82. N A T I V E   S C R I P T S:
  83. ============================
  84.  
  85.  RUN macro [args] = Run a DFSee macro in native format (list of commands)
  86.  
  87.  Purpose:       Execute a NATIVE DFSee script with multiple commands
  88.  
  89.  Parameters:    macro       The name of the macro-file, when no extention is
  90.                             given a '.DFS' extention will be appended.
  91.  
  92.                 args        Arguments to be passed as parameters to the macro
  93.                             upto 9 arguments can be specified and can be used
  94.                             anywhere in the script as '$1' to '$9' while $0
  95.                             is the scriptname (without file extension)
  96.                             Arguments can be enclosed in single- or double-quotes
  97.                             to allow embedded spaces or special characters
  98.  
  99.  Options:       -v          verbose, show details about running the script
  100.                 -p-         no prompting and command-echo by the command handler
  101.                 -p:1        echo command by handler, but no prompting afterwards
  102.                 -p:2        no echo by handler, but prompting afterwards
  103.                 -p:3        echo before, and prompt after executing (default)
  104.                 -E:i        ignore errors, continue execution when RC is not 0
  105.                 -E:q        quit on any errors, exit  (default when in batch mode)
  106.                 -E:c        confirm by user on errors (default when interactive)
  107.                 -s          single-step, confirm each line before executing it
  108.                 -q          quit DFSee after executing the script
  109.  
  110.  
  111.  Output:        SCRIPT progress when running in verbose mode, confirmation
  112.                 dialogs on errors, and regular output from executed commands
  113.  
  114.  Remarks:       All lines in the script that do NOT start with a ';' in the
  115.                 first column, are sent to the command-handler inside DFSee
  116.                 to be executed as a command. These commands can be multiple
  117.                 commands as usual (using '#' separators) and can also contain
  118.                 additional comment at the end of the command using ';' as a
  119.                 start-comment symbol.
  120.  
  121.                 When using the -E:confirm or E:quit types of error handling,
  122.                 every returncode from a command that is not 0 will cause
  123.                 either the confirmation dialog, or terminate the script.
  124.  
  125.                 The return-code (RC) for the whole script will be that of the
  126.                 last command that is executed in the script itself.
  127.  
  128.                 Native scripts can RUN other scripts (nesting) but are limited
  129.                 to about 10 levels of nesting.
  130.  
  131.  
  132. Native Pragmas:
  133. ---------------
  134. The initial behaviour of the native script interpreter can be set with some
  135. options of the run command. However, some of them can be changed by the
  136. script itself using 'pragma' statements.
  137.  
  138. A pragma always starts with the ';;' sequence at the beginning of a line.
  139.  
  140.  
  141.  
  142. ;;defaultparam  p  value
  143.  
  144. This will give a default 'value' to the parameter 'p' where p is 0..9
  145. The default value is only effective if no value has been passed as
  146. an argument to the macro.
  147.  
  148. One example of usage is to supply a default disk-number or partition
  149. while allowing to specify a different value when needed.
  150.  
  151.  
  152.  
  153. The following pragmas alter the behaviour of the script interpreter
  154. from within the script as initialy set by the corresponding options
  155. on the RUN statement or from the builtin defaults.
  156.  
  157. ;;verbose         [off]    set verbose mode on or off         (see -v)
  158. ;;prompt      [0|1|2|3]    set prompting and command-echo     (see -p)
  159. ;;error         [i|c|q]    set error handling for RC not 0    (see -e)
  160. ;;singlestep      [off]    single-step, confirm each line     (see -s)
  161.  
  162.  
  163.  
  164.  
  165. Special Commands:
  166. -----------------
  167. Some commands have been added to DFSee to allow better scripting, they
  168. are also available from the normal commandline.
  169.  
  170.  
  171.  REM [anything]   = Do not do anything (but echo the command :-)
  172.  
  173.  Purpose:       Allow REMark lines in a script, like in batch-files
  174.  
  175.  Parameters:    any     optional   Anything you like
  176.  
  177.  Output:        None
  178.  
  179.  Remarks:       Yes please! That is the whole purpose of the thing.
  180.  
  181.  
  182.  
  183.  SAY    [text]    = Display text to the DFSee display and logfile
  184.  
  185.  Purpose:       Give messages to user and logfile from the script
  186.  
  187.  Parameters:    text    optional   A line of text to display and log
  188.  
  189.  Output:        The specfied text or an empty line when not specified.
  190.  
  191.  Remarks:
  192.  
  193.  
  194.  
  195.  SLEEP  [secs]    = Sleep for the specified number of seconds
  196.  
  197.  Purpose:       Hold processing for the specified time, for instance to
  198.                 allow a user to read some output
  199.  
  200.  Options:       -q                 Do not give a status message
  201.  
  202.  Parameters:    secs    optional   Number of seconds, default is 1 second
  203.  
  204.  Output:        A message indicating DFSee is sleeping (if no '-q' option)
  205.  
  206.  Remarks:       On OS/2 and Win-NT this is a non-blocking wait, so the system
  207.                 keeps responding normally :-)  On DOS it is a busy-wait.
  208.  
  209.  
  210.  
  211. Example native script
  212. ---------------------
  213.  
  214. This is a simple script that uses some specific DFSee HPFS commands
  215. to analyse the current or a specified partition.
  216. (script is included in the distribution as 'dohpfs.dfs')
  217.  
  218. ;------------------ start script
  219. ;basic analysis for a HPFS partition
  220. ;;defaultparam 1 .
  221. say Start analysis for partition $1
  222. part $1
  223. fs  hpfs                        ;force HPFS mode
  224. d
  225. d                               ;display next default sector
  226. d
  227. 11                              ;display spareblock
  228. d
  229. d
  230. alloc                           ;display allocation map
  231. check
  232. slt                             ;perform check and show SLT
  233. findroot 12                     ;find the root directory
  234. ;----------------- end script
  235.  
  236. The next is a simple script to play with, and get used to the RUN options.
  237. With the script in a file 'say.dfs', run it in a few different ways:
  238.  
  239.  run say
  240.  run -s  say
  241.  run -v  say "parameter one"
  242.  run -p- say "parameter one"
  243.  run -p- say one two three
  244.  run -p- -v  say
  245.  run -p- -v  say 1 2 3 "sleep 5"
  246.  
  247. ;------------------ start script
  248. ;;defaultparam 2 THIS IS PARAMETER TWO
  249. say line 1
  250. say line 2
  251. say $1 $2 $3
  252. $4
  253. say last line
  254. ;----------------- end script
  255.  
  256. Note: The run commands above are available as another script: 'runsay.dfs'
  257.       which is part of the distribution together with 'say.dfs' itself.
  258.  
  259.  
  260. B A T C H    S C R I P T S:
  261. ===========================
  262.  
  263. There is really nothing special about batch scripts using DFSee.
  264. One thing to be aware of is that the renage of return-codes is
  265. limited to 65535 (16 bits numbers) on the DOS platform.
  266.  
  267. This could lead to problems if the DFSee 'query' command is
  268. not used carefully for instance to check disk sizes ...
  269.  
  270. Also the length of the commandline on DOS is limited to just
  271. over a 100 characters on DOS. (OS/2 and NT more than 2000)
  272.  
  273.  
  274.  
  275. R E X X   S C R I P T S:
  276. ========================
  277.  
  278. scripts for OS/2 only:
  279.  
  280.  RUN macro [args] = Run a DFSee macro in a REXX file
  281.  
  282.  Purpose:       Execute a REXX script using the 'DFS' environment
  283.  
  284.  Parameters:    mf      mandatory  Macro file specification
  285.  
  286.                 arg     optional   Arguments to the REXX macro
  287.  
  288.  Output:        Any output from the REXX macro including (OS/2) commands
  289.                 executed from the macro.
  290.  
  291.  Remarks:       The RUN command recognizes REXX scripts by contents, the
  292.                 first two characters must be '/*' which is a REXX comment.
  293.                 Other files will be handled as NATIVE DFSee script files.
  294.  
  295.                 DFS commands can be issued from within the macro, this
  296.                 is the default environment (Address DFS).
  297.                 Commands for CMD.EXE must be addressed using 'Address Cmd'
  298.  
  299.                 The following REXX variables will be available after
  300.                 each executed DFS command from a macro:
  301.  
  302.                 rc            The returncode from the DFS command
  303.  
  304.                 dfs_disknr    Physical disk number currently open
  305.                 dfs_partid    Partition-id for selection with "part"
  306.                 dfs_drive     The opened drive letter, including a colon.
  307.                 dfs_afsys     The attached filesystem, like "HPFS" or "FAT"
  308.                 dfs_sect      The last retrieved sector(s), binary buffer
  309.                 dfs_type      Type of last retrieved sector, this is a string
  310.                               starting with the type-character (see 'F' cmd)
  311.                               followed by a textual description.
  312.  
  313.                 dfs_this      SN of the last retrieved sector
  314.                 dfs_down      SN of most likely sector to retrieve now
  315.                 dfs_up        SN of sector up in hierarchy
  316.                 dfs_next      SN of next in sequence
  317.                 dfs_prev      SN of previous in sequence
  318.                 dfs_down      SN of up in hierarchy
  319.  
  320.                 dfs_number    The number of disks or partitions resolved,
  321.                               from the commands "disk" and "part 0" or
  322.                               "part" respectively.
  323.  
  324.                 dfs_sn.0      Number of sector-numbers in the SN stem variable
  325.                 dfs_sn.n      nth sector-number in the SN stem variable, coming
  326.                               from DFS output for directories and allocation.
  327.                               They correspond to the '.NNNNN' command
  328.  
  329.                               Note: SN's are in an 8-digit Hexadecimal format
  330.  
  331.  
  332.                 REXX is dynamically loaded, when the run-command is executed
  333.                 It requires REXX.DLL and REXXAPI.DLL in the libpath.
  334.  
  335.  
  336.  
  337.  COPYOUTPUT [stem-name]      Copy output from last-command to REXX stem-var
  338.  
  339.  Purpose:       Allow output to be captured and processed from REXX
  340.  
  341.  Parameters:    stem    optional   name of stem variable, ending in a '.'
  342.                         default:   "dfs_output."
  343.  
  344.  Output:        none
  345.  
  346.  Remarks:       The <stem>.0 will hold the number of lines
  347.                 <stem>.1 through <stem>.n the actual cmd-output
  348.  
  349.                 ==> This command is temporarily disabled to avoid a trap
  350.  
  351.