home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 6 File / 06-File.zip / DHRGCD.ZIP / DHRGCD.TUT < prev    next >
Text File  |  1992-07-01  |  16KB  |  309 lines

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