[comp.os.vms] Prompt representing default directory..

SEENGS1@MACALSTR.BITNET (01/28/88)

Hello all.  I remember seeing a message that came accros the net from someone
who wanted a way to set the prompt to represent the current default directory.
I wrote such a thing not too long ago for a friend of mine. It's not to great
or fast, but then again, it does what it is supposed to.

If anyone has any comments or suggestions, feel free to send them to me.

Eric Engstrom  -  Bitnet:  SEENGS1@Macalstr
1600 Grand Avenue
Macalester College
St. Paul, Minnesota  55105-1899,  U.S.A.

------------------------------ <<- Cut Here ->> --------------------------------
$ !+
$ ! DEF_PROMPT.COM - Written by Eric Engstrom   10-Jan-1988
$ !                  Class of 1990  --  Bitnet: SEENGS1@Macalstr
$ !                  Macalester College, 1600 Grand Avenue
$ !                  St. Paul, Minnesota  55105-1899  U.S.A.
$ ! Written under VMS 4.6 on a VAX 11/780
$ !
$ ! Will allow a user to change the default directory and then set the prompt
$ ! to a rendition of the default.  (See end of file for description how.)
$ !
$ ! Input default if none passed as the first parameter.
$ !-
$       if p1 .eqs. "" then $ inquire/nopunct p1 "_Directory: "
$       if p1 .eqs. "" then $ EXIT
$ !+
$ ! Change default.
$ !-
$!      On WARNING then $ EXIT
$!      On ERROR then $ EXIT
$!      On SEVERE_ERROR then $ EXIT
$       Set Default 'p1'
$!      @Studnet:[4eengstro.comfiles]logcomuse.com "Def_Prompt"
$ !+
$ ! Create a prompt string that resembles the current default.
$ !-
$       MinMaxLen = 5           ! Maximum Minimum Length of the MaxElem
$                               !       See Chk_Len3
$       ExtraCharLen = 5        ! '[' at the front and ']-> ' at the back.
$       MaxPromptLen = 32       ! Maximum length of a prompt in V4.6
$       ShortElemLen = 4        ! Length of shortened element including period.
$                       ! e.g.  [4eengstro.comfiles.data] = [4een.com.data]
$       Device = f$Parse("*.*;*",,,"DEVICE")
$       DevLen = f$length(Device)
$       Direct = f$extract(1,f$length(f$directory())-2,f$directory())
$       DirLen = f$length(Direct)
$       if DirLen + ExtraCharLen + DevLen .le. MaxPromptLen -
                then $ goto Set_Prompt
$ !+
$ ! Find Maximum number of directory levels there are.
$ !-
$       Max = -1
$Find_Max_Levels:
$       Max = Max + 1
$       if f$element(max+1,".",Direct) .nes. "." then $ goto Find_Max_Levels
$ !+
$ ! Phase 1:  Shorten intermediate directories.
$ !-
$       if Max .eq. 0 then $ goto Chk_Len3      ! Cannot shorten only one.
$       i = Max
$Chk_Len1: i = i - 1
$       if f$length(Direct) + ExtraCharLen + DevLen .le. MaxPromptLen -
                then $ goto Set_Prompt
$       TempElement = f$extract(0,i,".") + f$element(i,".",Direct)
$       TempElementLoc = f$locate(TempElement,Direct)
$       TempElementLen = f$length(TempElement)
$       Direct = f$extract(0,TempElementLoc,Direct) + -
                 f$extract(0,ShortElemLen,TempElement) + -
                 f$extract(TempElementLoc + TempElementLen,DirLen,Direct)
$       if i .gt. 0 then $ goto Chk_Len1
$ !+
$ ! Phase 2: Remove intermediate directories.
$ !-
$       if Max .le. 1 then $ goto Chk_Len3      ! Cannot remove top level.
$       i = Max
$Chk_Len2: i = i - 1
$       if f$length(Direct) + ExtraCharLen + DevLen .le. MaxPromptLen -
                then $ goto Set_Prompt
$       TempElementLoc = f$locate("." + f$element(i,".",Direct),Direct)
$       Direct = f$extract(0,TempElementLoc,Direct) + "." + -
                 f$extract(TempElementLoc + ShortElemLen,DirLen,Direct)
$       if i .gt. 1 then $ goto Chk_Len2        ! Stop at top level.
$ !+
$ ! Phase3: Shorten Maximum Element to fit.
$ !-
$Chk_Len3:
$       if f$length(Direct) + ExtraCharLen + DevLen .le. MaxPromptLen -
                then $ goto Set_Prompt
$       MaxElemLen = f$length(f$element(Max,".",Direct))
$       DirLen = f$length(Direct)
$       OldDirLen = DirLen
$Shorten_Max:
$       DirLen = DirLen - 1
$       Direct = f$extract(0,DirLen,Direct) + "+"    ! Add the 'plus' each time.
$       if DirLen + ExtraCharLen + 1 + DevLen .le. MaxPromptLen -
                then $ goto Set_Prompt          ! Plus one more for '+'.
$       if MaxElemLen - (OldDirLen - DirLen) .gt. MinMaxLen then -
                $ goto Shorten_Max
$ !+
$ ! Should never get here.  Print error message and set prompt to a default.
$ ! More shortening of other things could go here.  e.g. Device name.
$ !-
$Chk_Len4:
$       Type Sys$input

The default you have selected cannot be shortened enough to make a prompt.
Perhaps you could shorten your device/logical name if it is long.

The default prompt will be enterd.

$       Set Prompt
$ EXIT
$
$ !+
$ ! Put the last of the prompt together and set prompt.
$ !-
$Set_Prompt:
$       Prompt = Device + "[" + Direct + "]-> "    ! Change ExtraCharLen.
$       Set Prompt="''Prompt'"
$ EXIT
$ !+
$ ! DEF_PROMPT.COM
$ !
$ ! Description of the shortening algorithm:
$ !   This program currently shortens the default to fit as a prompt in three
$ !   phases.   Given that the default is: 'Device:[d1.d2.d3.d4.d5.d6.d7.d8]'
$ !
$ !   Phase 1:  This will shorten the default string by physically shortening
$ !     the length of d7 thru d1 to 4 (ShortElemLen) characters, each time
$ !     testing to see if the new string is short enough to be used as a prompt.
$ !   Phase 2:  If Phase 1 does not create a string short enough to be used
$ !     as a prompt, this will remove the intermediate directories (d7 thru d2)
$ !     leaving just a period to indicate the levels down one is.  This phase
$ !     also attemps to leave the user with as much information as possible by
$ !     only removing what is neccessary.
$ !   Phase 3:  This takes what Phase 2 leaves and shortens d8 until d8 is 5
$ !     (MinMaxLen) characters long.  It will stop sooner if it can of course.
$ !   Phase 4:  This is left for expansion of the shortening routine.  It
$ !     currently prints an error message and sets the prompt to the default.
$ !
$ !   Examples:
$ !     DUA1:[STUDENT.4EENGSTRO.COMFILES]  --->  DUA1:[STUDENT.4EE.COMFILES]
$ !     STUDENT$:[4EENGSTRO.COMFILES]      --->  STUDENT$:[4EENGSTRO.COMFILES]
$ !     STUDENT$:[4EENGSTRO.PUBLIC.GAMES.HIGHSCORES] --->
$ !                                             STUDENT$:[4EEN...HIGHSCORES]
$ !
$ !   Please send me any comments.   Eric Engstom - Bitnet SEENGS1@MACALSTR
$ !-
------------------------------ <<- Cut Here ->> --------------------------------

-------