home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / fileutil / dhrgcd / dhrgcd.tut < prev    next >
Encoding:
Text File  |  1992-07-01  |  16.0 KB  |  309 lines

  1.  
  2.         DHRGCD.CMD Version 1.01 Detailed Description
  3.         DHRGCD.CMD Version 1.01 Detailed Description
  4.         DHRGCD.CMD Version 1.01 Detailed Description
  5.         06/22/92
  6.            
  7.            
  8.         This document will attempt to explain some of the how and why of
  9.         the programming logic in DHRGCD.CMD. REXX was chosen as the
  10.         programming language because it is easy to use and is included
  11.         free with OS/2 2.0. The version supplied with OS/2 is highly
  12.         integrated with OS/2 and supports all features of the DOS style
  13.         batch language including the essential ability to permanently
  14.         change disks and directories from within a REXX command file
  15.           
  16.           
  17.         The DHRGCD program was written to provide a way to jump from
  18.         directory to directory without requiring the full path name. This
  19.         functionality is provided in DOS by the Norton Utilities' program
  20.         NCD. The additional ability to jump between disks was included
  21.         because the size of OS/2 and developmental software had required
  22.         me to purchase multiple disk drives. When the new configuration
  23.         was complete, I was left with 7 logical disks on 2 physical
  24.         drives to manage. For program development (and most other tasks),
  25.         I prefer to use multiple full screen command line sessions rather
  26.         than have multiple small windows open on the work place shell.
  27.         Since I do mainframe programming (IBM VM and MVS) as well as DOS
  28.         and OS/2 programming, my general editor of choice is Mansfield
  29.         Software's KEDIT (for OS/2 and DOS) which is very similar to
  30.         XEDIT on VM (which I prefer over SPF on MVS).
  31.           
  32.           
  33.         Throughout the file are comments labeled /* Reference #x */. I
  34.         will refer to those in the following explanation. The exec begins
  35.         with the required REXX comment line, the content of which re-
  36.         flects the operating system where I first learned REXX - IBM's
  37.         VM/CMS where REXX files were required to have a file type of
  38.         'EXEC' (where in OS/2 the file type is 'CMD'). The first execut-
  39.         able instruction is 'trace'. This is used primarily during devel-
  40.         opment by adding the option 'r' to display what is happening
  41.         within the REXX program during execution. It is left here to
  42.         maintain the same line number count during normal operations and
  43.         testing.
  44.         The OS/2 environment variable RXTRACE may also be used to display
  45.         program flow.
  46.           
  47.           
  48.         The PARSE source extracts the full name of the CMD including path
  49.         information. The filespec function and following PARSE is used to
  50.         extract just the name. The name will be used in displays from the
  51.         program. The command '@ECHO OFF' turns off displays of commands
  52.         sent to OS/2 exactly the same as in a BAT file.
  53.           
  54.           
  55.         The signal statement here identifies the name of a REXX subrou-
  56.         tine that will be executed if control break or control C is
  57.         entered. The routine at Reference #13 will first delete the index
  58.         file if the program is in the process of building it then display
  59.         a termination message and exit.
  60.  
  61.  
  62.  
  63.  
  64.                                         1
  65.  
  66.  
  67.         DHRGCD.CMD Version 1.01 Detailed Description
  68.         DHRGCD.CMD Version 1.01 Detailed Description
  69.         DHRGCD.CMD Version 1.01 Detailed Description
  70.         06/22/92
  71.            
  72.            
  73.         Following Reference #2 are options to control how the REXX pro-
  74.         gram will operate. They were placed here in a group to allow easy
  75.         modification. The variable use_current_disk_index when set to 'Y'
  76.         will place the index on the disk where the command is executed.
  77.         If not set to 'Y', the variable use_boot_disk_index when set to
  78.         'Y' will place the index on the boot disk. If
  79.         use_current_disk_index is not 'Y' and use_boot_disk_index is also
  80.         not 'Y', the index will be placed on the first local hard disk.
  81.         The REXX variable use_ansi_colors determines if ANSI control
  82.         strings will be used to change colors when displaying messages
  83.         from the program. The variable use_all_disks controls if only
  84.         local drives or all drives known to OS/2 will be used when creat-
  85.         ing an index file.
  86.           
  87.           
  88.         The first task is to extract information from the command line.
  89.         The PARSE instruction is used to separate the command line into
  90.         sections - destination subdirectory name and execution option.
  91.         Options in DOS and OS/2 follow the UNIX tradition of a '/' or '-'
  92.         followed by a sometimes cryptic letter or combination of letters
  93.         that means something to the executing program. The options may
  94.         precede or follow a parameter such as a file name. Options in the
  95.         IBM VM/CMS world are generally meaningful names that always
  96.         follow a '(' that may follow a parameter such as a file name.
  97.              OS/2    ->  GCD /l sub1
  98.              OS/2    ->  GCD sub1 /l
  99.              VM/CMS  ->  GCD sub1 (l
  100.           
  101.           
  102.         The OS/2 High Performance File System allows a dash ('-') to be a
  103.         leading character in a file or subdirectory name so the use of
  104.         the '-' as an option flag will not be supported in this REXX
  105.         program. (This is not to say it cannot be done, it can be done in
  106.         this program due to the limited number of options but could not
  107.         be done if more options were available.)
  108.  
  109.              GCD -h -l  - which is the directory and which is the option?
  110.           
  111.           
  112.         The lines following Reference #3 extracts two items from the
  113.         command line that have been entered in either the DOS-OS/2 format
  114.         or the VM/CMS format. There are three PARSE instructions all
  115.         extracting from the same command string but using different
  116.         patterns to match different types of input. Much of the logic
  117.         here is to handle either format of parameters. The PARSE option
  118.         'upper' will convert both subdirectory name and option to upper-
  119.         case. If a question mark was entered, it will be placed in the
  120.         option field even though a slash was not entered. The HPFS allows
  121.         directory and file names to contain spaces. The REXX PARSE gener-
  122.         ally uses spaces as a delimiter. The first PARSE statement speci-
  123.         fies a delimiter of '/' which prevents the removal of spaces from
  124.         the directory name, although the primary purpose is to identify
  125.         the option string. The STRIP function without options removes
  126.         beginning and trailing spaces. To allow entry of a directory name
  127.  
  128.  
  129.                                         2
  130.  
  131.  
  132.         DHRGCD.CMD Version 1.01 Detailed Description
  133.         DHRGCD.CMD Version 1.01 Detailed Description
  134.         DHRGCD.CMD Version 1.01 Detailed Description
  135.         06/22/92
  136.            
  137.            
  138.         that contains a leading space, the program provides for entry of
  139.         a directory surrounded by double quotes with another PARSE state-
  140.         ment. Note that quotes are only required if the directory name
  141.         begins with a space. Trailing spaces are never stored by the
  142.         HPFS. Any trailing spaces are removed by a STRIP call with the
  143.         'T' option.
  144.           
  145.           
  146.         Lines following Reference #4 check for options that can be han-
  147.         dled immediately and combinations of entries that are invalid.
  148.         This is placed here to minimize the amount of processing for
  149.         these types of entries. If help was not requested and the options
  150.         appear valid, lines following Reference #5 initialize variables
  151.         that are used later. Based on a variable set following Reference
  152.         #2, the ansi_ variables are set to ANSI escape sequences to
  153.         control display color or to null. The REXXUTIL DLL will be used
  154.         in multiple places, so here it is tested to see if it was pre-
  155.         viously loaded by another CMD file. If not, it is loaded here.
  156.           
  157.           
  158.         If the variable use_boot_disk_index was set to 'Y', lines follow-
  159.         ing Reference #6 determine the boot disk. The custom DHRRU100 DLL
  160.         will be used to extract the boot drive number. The RxFuncAdd call
  161.         will load the custom DLL that contains the REXX function DHRSys-
  162.         Info that will be used to determine the logical disk that was
  163.         used to boot the system.
  164.           
  165.           
  166.         As I described before, having 7 logical disks is a perfect oppor-
  167.         tunity for the OS/2 Boot Manager. Drive C is a bootable primary
  168.         dual boot DOS 5 and OS/2 1.3 FAT partition. Drive D is a bootable
  169.         logical OS/2 2.0 PM FAT partition. Drive E is a bootable logical
  170.         OS/2 2.0 non PM FAT partition (to do corrective CHKDSK on the D
  171.         drive when required). Drive F, G, and H are FAT logical parti-
  172.         tions. Drive I is a bootable logical OS/2 2.0 PM HPFS partition.
  173.         The desire to segregate system files to a specific boot disk led
  174.         to the development of a simple REXX callable DLL written in C
  175.         which would return the contents of the OS/2 control program
  176.         function QuerySysInfo which contains, among other things, the
  177.         boot disk number.
  178.           
  179.           
  180.         After the call to DHRSysInfo the REXX variable OS2info.5 contains
  181.         the boot disk number. The DLL will normally only be used by this
  182.         REXX program, so it is released by the RxFuncDrop.
  183.           
  184.           
  185.         Lines following Reference #7 determine if the index is present
  186.         based on a variable set at the top of the program. If the
  187.         use_boot_disk_index is set to 'Y' and the boot_disk variable
  188.         contains a value, the index_disk will be set to the boot_disk.
  189.         The following lines may be uncommented to test the boot disk for
  190.         the presence of the index and force all disks to be searched if
  191.         the index is not found on the boot disk. The next IF-END will
  192.         search for the index disk on any local disk if it has not been
  193.  
  194.                                         3
  195.  
  196.  
  197.         DHRGCD.CMD Version 1.01 Detailed Description
  198.         DHRGCD.CMD Version 1.01 Detailed Description
  199.         DHRGCD.CMD Version 1.01 Detailed Description
  200.         06/22/92
  201.            
  202.            
  203.         identified.
  204.           
  205.           
  206.         Lines following Reference #8 are executed if the disk containing
  207.         the index file has not been determined which means it does not
  208.         currently exist.
  209.           
  210.           
  211.         By the time we get to Reference #9, there are four possible
  212.         options - 'R', 'RQ', 'L', or NULL. The option 'RQ' is an exten-
  213.         sion of the 'R' option so they are handled together. The 'L'
  214.         option is a modification of the normal look up so is handled in
  215.         the second half of the IF statement.
  216.           
  217.           
  218.         The 'R' or 'RQ' option builds or rebuilds the directory index.
  219.         With these options the target string may become a string of disks
  220.         to be searched for indexing. The '@ECHO OFF' at the beginning of
  221.         the program turned off the normal echoing of command execution to
  222.         the console, but the 'DEL' command will produce an error message
  223.         when a file to be deleted is not found. The redirection ' 2> NUL'
  224.         discards information written to file handle 2 (STDERR) which is
  225.         where the 'not found' error message is displayed.
  226.  
  227.         The DO WHILE sequence takes an entered string of disks to be
  228.         indexed and expands the string by adding a colon and space to the
  229.         end of each letter. The PARSE instruction in the next DO WHILE
  230.         loop will separate each disk delimited by a space. The call to
  231.         the REXXUTIL entry SysFileTree should work but there is a problem
  232.         in the internal code of OS/2 (to be fixed in the future) so
  233.         SysFileTree does not return subdirectories that begin with a
  234.         space. The DIR command does so the next line calls a REXX subrou-
  235.         tine to return the same information but in more lines of code.
  236.  
  237.  
  238.         The code following Reference #14 redirects the output of the DIR
  239.         command to the default REXX queue with the OS/2 RXQUEUE program.
  240.         The DO loop places the queued information into a REXX stem vari-
  241.         able called 'dirstem' which is exactly where the information
  242.         would have appeared had the SysFileTree function been executed.
  243.         The subdirectory names are output to the index file with a call
  244.         to a REXX subroutine write_dir.
  245.  
  246.  
  247.         The second half of the IF ELSE test implements the subdirectory
  248.         look up. The REXXUTIL function SysFileSearch following Reference
  249.         #10 is used to search the directory index for all names that
  250.         contain the target string. An error is displayed if no matches
  251.         are returned. The returned values are further reviewed in the
  252.         following DO loop. If the /l option was included, all returned
  253.         values that do not exist on the current disk are skipped. If the
  254.         returned value does not include the target directory as part of
  255.         the last qualifier, it is also rejected. The REXX stem variable
  256.         match_val. will contain all valid matches. An attempt is made to
  257.  
  258.  
  259.                                         4
  260.  
  261.  
  262.         DHRGCD.CMD Version 1.01 Detailed Description
  263.         DHRGCD.CMD Version 1.01 Detailed Description
  264.         DHRGCD.CMD Version 1.01 Detailed Description
  265.         06/22/92
  266.            
  267.            
  268.         provide a best match hint for later display.
  269.           
  270.           
  271.         If there was only one match, the directory is switched by the
  272.         call to the REXX function directory. If there was more than one
  273.         choice, they are displayed and the user is prompted for a selec-
  274.         tion in the lines following Reference #11. The REXXUTIL function
  275.         SysTextScreenSize is used to determine how many lines are avail-
  276.         able for the display. If there are more choices then there are
  277.         display lines, the list will be divided into two columns. If
  278.         there is a best match, item number will be displayed along with
  279.         the prompt. A best match value allows the use of just the enter
  280.         key for acceptance. The local function get_ans, located following
  281.         Reference #15, reads one or more keys based on the expected maxi-
  282.         mum length of the reply. The call to CHROUT is used to prevent
  283.         the automatic CR/LF output of the SAY instruction. Non-numeric
  284.         keys are rejected, the ESC key may be used to return without a
  285.         value, and the enter key will return with whatever has been
  286.         entered. The string entered is returned to the caller.
  287.  
  288.         If a valid value was entered, the call to the directory function
  289.         will switch to the new directory. The common exit code following
  290.         Reference #12 is required to restore the screen colors to a white
  291.         on black display. The label exit_gcd: is used by the signal
  292.         following the call to get_ans to immediately exit if either the
  293.         ESC key was pressed or 0 was entered. If the default screen color
  294.         is not white on black, the variable ansi_white should be changed
  295.         to the correct color defined at the start of the program.
  296.           
  297.           
  298.         The subroutine write_dir at Reference #16 was included here
  299.         rather than placed inline at the single calling location to allow
  300.         future expansion. Two help displays are available, caused by a ?
  301.         or /h. The /h provides the OS/2 full screen VIEW display of the
  302.         DHRGCD.INF file. Unfortunately, the return code is always zero.
  303.         The enter of a ? will produce the short text display of help
  304.         information.
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.                                         5
  324.  
  325.  
  326.