Google
 

Trailing-Edge - PDP-10 Archives - LCG_Integration_Tools_Clearinghouse_T20_v7_30Apr86 - tools/com/chdir.com
There are 3 other files named chdir.com in the archive. Click here to see a list.
$ v := 'F$VERIFY(0)
$!\\
$!\\  CHDIR - change current directory
$!\\
$!\\  There are several forms, most of which are not like UNIX.
$!\\ 
$!\\ 	SYNTAX			SEMANTICS
$!\\ 	------			---------
$!\\ 
$!\\ 	CHDIR 			=> "default".  Go home, where home is defined
$!\\ 				   by two global symbols presumably from your
$!\\ 				   LOGIN.COM file.  The usual case is:
$!\\ 				   $ CHDIR$DISK :== "DBB1:"
$!\\ 				   $ CHDIR$HOME :== "PAMMETT"
$!\\ 				   CHDIR with no parameters, then, gets you
$!\\ 				   the directory "dbb1:[pammett]".
$!\\ 
$!\\ 	CHDIR ..		=> "up".  go to the directory immediately
$!\\ 				   above the current one.  However, if you 
$!\\ 				   are already at [PAMMETT], for example,
$!\\ 				   you don't go anywhere, without warning.
$!\\ 				   If a second parameter is given, it is
$!\\ 				   ignored without warning.
$!\\ 
$!\\ 	CHDIR name		=> "sub directory".  This is the usual case.
$!\\ 				   If you are already at the 'top' of your
$!\\ 				   directory string, (e.g. DB:[USER]), then
$!\\ 				   "CHDIR sub" gets you to DB:[USER.sub].
$!\\ 				   If you are in DB:[USER.sub], for example,
$!\\ 				   "CHDIR new" gets you to DB:[USER.new], i.e.
$!\\ 				   you remain at the current directory depth.
$!\\ 
$!\\ 	CHDIR .name		=> "down directory".  If the given directory
$!\\ 				   name starts with ".", then the new string
$!\\ 				   is the current one suffixed by ".name".
$!\\ 				   This is the usual way of "going down" one
$!\\ 				   or more directory levels.
$!\\ 
$!\\ 	CHDIR string:		=> "escape".  The given parameter is assumed
$!\\          [string]             to be the complete and correct directory
$!\\ 	      <string>             specification if it contains a colon,
$!\\ 	      xxx,xxx		   comma, left-angle, or left-square char.
$!\\ 				   This makes CHDIR just like SET DEFAULT.
$!\\ 				   If a second parameter is given, it is
$!\\ 				   ignored without warning.
$!\\ 
$!\\ 	CHDIR .T		=> "top".  Go to the 'top' level directory
$!\\ 	CHDIR .T sub		   of where you currently are.  If a second
$!\\ 				   parameter is given, it is equivalent to
$!\\ 				   "CHDIR .T" followed by "CHDIR sub".
$!\\ 
$!\\ 	CHDIR .M 		=> "my".  This version first gets you HOME
$!\\ 	CHDIR .M xxx		   (CHDIR with no arg), and then gets you 
$!\\ 				   to the sub-directory XXX.  With no XXX
$!\\ 				   this version is identical to CHDIR with
$!\\ 				   no parameter.
$!\\
$!\\ 	CHDIR .S		=> "save".  The current directory name
$!\\ 				   is 'remembered' in the global symbol 
$!\\ 				   called CHDIR$SAVE.  See "CHDIR .R".
$!\\ 				   This only works when you .S and then .R
$!\\ 				   within the current log-in session.
$!\\				   CHDIR$TELL => whether or not a message is
$!\\				   produced to record what .R or .S does.
$!\\				   No 2nd or subsequent parameter is allowed.
$!\\ 
$!\\ 	CHDIR .R		=> "restore" or "return".  A SET DEFAULT
$!\\ 				   to the last-stored directory name is done.
$!\\				   CHDIR$TELL => whether or not a message is
$!\\				   produced to record what .R or .S does.
$!\\				   No 2nd or subsequent parameter is allowed.
$!\\ 
$!\\   For most versions of CHDIR, if a third (or subsequent) parameter is
$!\\   given, it is ignored without warning.  Also, like SET DEFAULT, only
$!\\   limited syntax and existence checks are made on the final directory
$!\\   specification.
$!\\ 
$
$!  This command file turns off VERIFY, but then puts it back to
$!  what the user had it set to.
$!
$!   Pick up the given parameter and see if it is null.
$
$ file := 'P1  
$
$ ! A parameterless call => my 'home' directory.
$
$ if file.EQS."" then goto home
$ !
$ ! Check for the special case, "..", which is stolen from the UNIX
$ ! notion of "going up" to the directory above the current one.
$
$ if file.EQS.".." then goto upone
$
$ ! Then check for a .S, .M, .T, or .R case; they are simple.
$
$ if file.EQS.".S" then goto save
$ if file.EQS.".R" then goto restore
$ if file.EQS.".M" then goto mysubdir
$ if file.EQS.".T" then goto dotop
$
$ ! If there is a '<', ':', ',' or '[', then the parameter is 
$ ! the entire target directory so we take it "as is".
$ 
$ IF 'F$LOCATE("[",file).NE.'F$LENGTH(FILE) THEN GOTO asis
$ IF 'F$LOCATE(",",file).NE.'F$LENGTH(FILE) THEN GOTO asis
$ IF 'F$LOCATE(":",file).NE.'F$LENGTH(FILE) THEN GOTO asis
$ IF 'F$LOCATE("<",file).EQ.'F$LENGTH(FILE) THEN GOTO subname
$ 
$ asis:
$
$ ! Believe that the given parameter is the entire and proper
$ ! directory specification and simply set the current directory
$ ! to it as given.
$
$ set default 'file
$ goto done
$
$ save:
$
$ ! Make sure that only the .S parameter is given.
$
$ optn := "S"
$ if P2.nes."" then goto how_r_s
$
$ ! This code saves away the current directory name so that
$ ! a later "CHDIR .R" (restore) command can be implemented.
$ ! We save away the whole directory name, including the disk.
$ 
$ chdir$save :== 'f$logical("SYS$DISK")''F$directory()'
$ out := "CHDIR: saved current directory name"
$ if chdir$tell then write sys$output "''out' ''chdir$save'"
$ goto done
$
$ restore:
$
$ ! Make sure that only the .R parameter is given.
$
$ optn := "R"
$ if P2.nes."" then goto how_r_s
$
$ ! This code simply gets you back to a place previously
$ ! 'saved' by a "CHDIR .S" command.
$
$ set default 'chdir$save
$ out := "CHDIR: restored current directory to"
$ if chdir$tell then write sys$output "''out' ''chdir$save'"
$ goto done
$ 
$ how_r_s:
$ write sys$output "Usage: CHDIR .''optn'"
$ goto done
$
$ mysubdir:
$
$ ! This code gets one to "my" directory where MY is defined on a
$ ! per user basis via two global symbols.  See also CHDIR with no
$ ! parameter, or the code labeled by "home:", below.
$
$ if P2.nes."" then P2 := .'P2
$ top := 'chdir$disk'['chdir$home''P2']
$ set def 'top
$ goto done
$
$ dotop:
$ 
$ ! The 'top' case is that we assume the given parameter
$ ! is a sub directory of the top current directory.  There are
$ ! two cases which we handle:
$ !
$ !     1) we are already in a sub directory
$ !        e.g. PWD
$ !             [top.middle.subname]
$ !             CHDIR .T new
$ !             PWD
$ !             [top.new]
$ !	   i.e. you go up to 1 below the top level.
$ !
$ !     2) we are in a top-level directory
$ !        e.g. PWD
$ !             [top]
$ !             CHDIR .T new
$ !             PWD
$ !             [top.new]
$ !	   i.e. you go down 1 level from the top.
$ ! 
$ ! Handle these two cases by first picking up the current directory
$ ! name.  Then see if a period can be found somewhere in the string.
$
$ d := 'F$DIRECTORY() "" 
$ IF 'F$LOCATE(".",d).EQ.'F$LENGTH(d) THEN GOTO nosub
$
$ ! There IS a sub directory.  The 'top' portion of what we set
$ ! the new default to is the current directory string minus the
$ ! sub directory.
$
$ pos := 'F$LOCATE(".",d)
$
$ setdef:
$
$ pos = pos-1
$ top := 'F$EXTRACT(1,pos,d)
$
$ ! When there is no 2nd parameter for ".T", the user simply wants
$ ! to go to the 'top' of his directory structure.  Otherwise
$ ! he wants to go to ['top'.sub]
$
$ file := 'top'
$ if P2.nes."" then file := 'top'.'P2'
$ set default ['file']
$ goto done
$
$ nosub:
$
$ ! There is no sub directory so the one specified is assumed to
$ ! be immediately subordinate to the current one.  The current
$ ! directory, as a symbol name, may be enclosed in '<...>' or '[...]'.
$ ! Pick up the name of the 'top' directory, without the enclosing
$ ! angle or square brackets.
$ 
$ IF 'F$LOCATE("[",d).NE.'F$LENGTH(d) THEN pos := 'F$LOCATE("]",d)
$ IF 'F$LOCATE("<",d).NE.'F$LENGTH(d) THEN pos := 'F$LOCATE(">",d)
$ goto setdef
$
$ subname:
$
$ ! There are two cases here: "CHDIR name" and "CHDIR .name".
$ ! The former is handled by common code with "..", below.
$
$ if 'f$locate(".",P1).ne.0 then goto upone
$
$ ! To implement "CHDIR .name", we simply remove the "." from the
$ ! parameter and go do what "CHDIR name" would do if there were
$ ! no sub directory in the current one.
$
$ d := 'f$directory()
$ P2 := 'f$extract(1,200,P1)
$ goto nosub
$
$ upone:
$
$ ! At this point we are implementing "CHDIR ..", or "CHDIR name".
$ ! Both of these require first picking up the current directory
$ ! name and then finding the last "." in the string.
$
$ d := 'F$directory() ""
$ IF 'F$locate(".",d).eq.'f$length(d) then goto attop
$ pos = 'f$locate(".",d)
$
$ ! There is atleast one "." in the current directory name,
$ ! and 'pos' is the character position of the dot after it.  
$ ! To get to the last dot in the string we have to loop,
$ ! extracting the rest of the string, locating another dot,
$ ! and updating POS (which still referrs to the original
$ ! string) by the character position in the REST string, each
$ ! time another dot is located.
$
$ nextdir:
$
$ newp = pos +1
$ rest := 'f$extract(newp,200,d)
$ IF 'f$locate(".",rest).eq.'f$length(rest) then goto nomore
$ p = 'f$locate(".",rest)
$ pos = pos + p +1
$ goto nextdir
$
$ attop:
$
$ ! At this point we are done if it was "CHDIR ..".  On the other
$ ! hand, we implement "CHDIR name" in a standard way since there
$ ! are no sub directories.
$
$ if file.eqs.".." then goto done
$ P2 := 'P1
$ goto nosub
$
$ nomore:
$
$ ! Back over the last ".", and extract the entire UPPER portion of
$ ! the initial directory name.  For the ".." case, this becomes the
$ ! new current directory and we're done.  For the "CHDIR name" case
$ ! we tack on "name" before doing the same thing.
$
$ pos = pos -1
$ upper := 'f$extract(1,pos,d)
$ if P1.nes.".." then upper := 'upper'.'P1'
$ set def ['upper']
$ goto done
$
$ home:
$
$ ! CHDIR with no parameters means that we go to a directory defined
$ ! by symbols from your LOGIN.COM file via, for example:
$ !
$ ! 	$ chdir$disk :== "dbb1:"
$ !	$ chdir$home :== "pammett"
$
$ set def 'CHDIR$DISK'['chdir$HOME']
$
$ done:
$ 
$ ! Final clean up.  For now, we only have to put the user-defined
$ ! value for VERIFY back to what it was.
$
$ show def
$ if v then set verify