From:	CRDGW2::CRDGW2::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX"  2-APR-1991 15:40:08.37
To:	ARISIA::EVERHART
CC:	
Subj:	unix-like cd, ls, push(d), pop(d), cp, mkdir, rmdir

From:	RELAY-INFO-VAX@CRVAX.SRI.COM@SMTP@CRDGW2
To:	Everhart@Arisia@MRGATE

Received:  by crdgw1.ge.com (5.57/GE 1.92)
	 id AA13471; Sun, 31 Mar 91 21:44:43 EST
Received: From UCBVAX.BERKELEY.EDU by CRVAX.SRI.COM with TCP; Sun, 31 MAR 91 18:10:35 PST
Received: by ucbvax.Berkeley.EDU (5.63/1.42)
	id AA26138; Sun, 31 Mar 91 18:02:58 -0800
Received: from USENET by ucbvax.Berkeley.EDU with netnews
	for info-vax@kl.sri.com (info-vax@kl.sri.com)
	(contact usenet@ucbvax.Berkeley.EDU if you have questions)
Date: 1 Apr 91 02:01:16 GMT
From: pacific.mps.ohio-state.edu!davis@tut.cis.ohio-state.edu  ("John E. Davis")
Organization: "Dept. of Physics, The Ohio State University"
Subject: unix-like cd, ls, push(d), pop(d), cp, mkdir, rmdir
Message-Id: <DAVIS.91Mar31210116@pacific.mps.ohio-state.edu>
Sender: info-vax-request@kl.sri.com
To: info-vax@kl.sri.com

Hi,

   There have been several requests fo rme to post my dcl code so here it is:

------------------(cut here)-------------------------------------------   
$! Unix like commands for VMS
$!
$!  1. Name this file UNIX.COM
$!  2. Put the foillowing lines in your login.com file:
$!         
$!         $ cd       :== @unix.com cd
$!         $ ls       :== @unix.com ls
$!         $ cp       :== @unix.com cp
$!         $ mkdir    :== @unix.com mkdir
$!         $ rmdir    :== @unix.com rmdir
$!         $ push     :== @unix.com push
$!         $ pop      :== @unix.com pop
$!         $ dcl_debug == 0
$!
$!  3. Example usage:
$!
$!               cd ../test
$!               cd ,            !cd to previous dir
$!               cd .            !cd to home dir
$!               ls -l ..
$!               mkdir dev$scratch:/davis/tmp
$!               rmdir dev$scratch:/davis/tmp
$!               cp ../dcl/*.com ./ 
$!               push /davis/edit/emacs  
$!               pop
$!
$!    Any questions or comments should be directed to:
$!
$!       John E. Davis  davis@pacific.mps.ohio-state.edu
$!
$ this_verify = f$verify (0)
$ if dcl_debug .eqs. 1 then set verify
$ goto 'p1'_label
$ cd_ls_exit:
$    if dcl_debug then set noverify
$    if this_verify then set verify
$    exit
$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$!
$!               ls [-a] [directory]
$!
$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$ ls_label: 
$ directory := directory
$ if ("''p2'" .eqs. "")
$ then
$   directory
$   goto cd_ls_exit
$ endif
$ if (f$extract(0,1,"''p2'") .eqs. "-")
$ then
$    if ("''p3'" .eqs. "")
$    then
$       dir = ""
$    else
$       UNIX_NAME = p3
$       gosub unix_2_vms
$       dir = VMS_NAME
$    endif
$    directory/date/size=all/protection 'dir'
$ else
$    UNIX_NAME = p2
$    gosub unix_2_vms
$    dir = VMS_NAME
$    directory 'VMS_NAME'
$ endif
$ goto cd_ls_exit
$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$!
$!       cd {[,] | [directory]}
$!
$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$ cd_label:
$  esc[0,8] = %X1B
$  current_dir = f$environment("DEFAULT")
$  new_dir = f$parse(f$environment("DEFAULT"))
$  if (p2 .eqs. ",") then p2 = "''f$trnlgn("cd_old_dir")'"
$  if ("''p2'" .nes. "")
$  then
$     UNIX_NAME = p2
$     gosub unix_2_vms
$     dir = VMS_NAME
$     current_dir = f$environment("DEFAULT")
$     set def 'dir'
$     new_dir = f$parse(f$environment("DEFAULT"))
$     if ((new_dir .eqs. "") .and. ( dir .nes. "[]")) then goto cd_dir_error
$  endif
$  define/nolog cd_old_dir 'current_dir'
$  device = f$element(0,":",new_dir) + ":"
$  VMS_NAME = f$directory()
$  gosub make_unix
$  set prompt= "''UNIX_NAME'> "
$  write sys$output esc + "[1m"
$  show time
$  write sys$output "''esc'[0m"
$  write sys$output "''device'"
$  goto cd_ls_exit
$!
$  cd_dir_error:
$  set default 'current_dir'
$  bell[0,8] = 7
$  write sys$output "''bell'" + "''esc'[1mDirectory " + "''save' --> ''dir' does not exist!''esc'[0m"
$  goto cd_ls_exit
$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$!
$!     mkdir, rmdir
$!
$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$ rmdir_label:
$    UNIX_NAME = p2
$    gosub unix_2_vms
$    the_dir = VMS_NAME
$    set protection=(o:rwed) 'the_dir'
$    delete/confirm 'the_dir';*
$    goto cd_ls_exit
$ mkdir_label:
$    UNIX_NAME = p2
$    gosub unix_2_vms
$    the_dir = VMS_NAME
$    create/directory 'the_dir'
$    goto cd_ls_exit
$ cp_label:                                   ! cp file1 file2  
$    copy := copy/confirm
$    if ("''p2'" .nes. "")
$    then
$       UNIX_NAME = p2
$       gosub unix_2_vms
$       file1 = VMS_NAME
$       if ("''p3'" .nes. "")
$       then
$          UNIX_NAME = p3
$          gosub unix_2_vms
$          copy 'file1' 'VMS_NAME'
$       else
$          copy 'file1' []
$      endif
$   endif
$   goto cd_ls_exit
$ most_label:
$   UNIX_NAME = p2
$   gosub unix_2_vms
$   pager 'VMS_NAME'
$   goto cd_ls_exit
$!
$!
$!                           subroutine unix_2_vms
$!                       converts UNIX_NAME to VMS_NAME  
$!
$ unix_2_vms:
$ u2v_dir = UNIX_NAME
$ u2v_length = f$length(UNIX_NAME)
$ u2v_device = ""
$ u2v_its_root = 0
$ u2v_work = UNIX_NAME
$ if (f$locate("[",u2v_dir) .lt. u2v_length) then goto u2v_finish   !vms syntax
$ if (f$locate("/",u2v_dir) .lt. u2v_length) then goto u2v_start    !unix syntax
$ if ("''u2v_work'" .eqs. ".")
$ then
$    u2v_dir = f$trnlgn("sys$login")
$    goto u2v_finish
$ endif
$ if ("''u2v_work'" .eqs. "..")
$ then
$    u2v_dir = "[.-]"
$    goto u2v_finish
$ endif
$ if (f$extract(0,1,u2v_work) .eqs. ".")
$ then
$    u2v_dir = "''u2v_work'"
$    goto u2v_finish
$ endif
$ u2v_start:
$ u2v_new_name= "["
$ u2v_save = UNIX_NAME
$ if f$locate(":",u2v_work) .lt. u2v_length
$ then
$    u2v_device = f$element(0,":",u2v_work) + ":"
$    u2v_work = (u2v_work - u2v_device) - ":"
$    u2v_dir = ""
$ endif
$ if ("''u2v_work'" .eqs. "") then goto u2v_finish
$ if ("''u2v_work'" .eqs. "/")
$ then
$    u2v_dir = "[000000]"
$    goto u2v_finish
$ endif
$ if (f$extract(0,2,u2v_work) .eqs. "..")
$ then
$    u2v_new_name = u2v_new_name + "-"
$    u2v_work = u2v_work - ".."
$    if (f$extract(0,1,u2v_work) .eqs. "/") then u2v_work = u2v_work - "/"
$ else
$    if (f$extract(0,1,u2v_work) .eqs. ".")
$    then
$       u2v_work = u2v_work - "."
$    else
$       if (f$extract(0,1,u2v_work) .eqs. "/")
$       then
$          u2v_work = u2v_work - "/"
$          u2v_its_root = 1
$       endif
$    endif
$ endif
$! I need to add code here to take "." ---> "/"
$ u2v_count = 0
$ u2v_loop:
$    u2v_elem = f$element(u2v_count,"/",u2v_work)
$    u2v_count = u2v_count + 1
$    if ((u2v_elem .nes. "/") .and. (u2v_elem .nes. ""))
$    then
$       if (f$locate(".",u2v_elem) .lt. f$length(u2v_elem))
$       then
$          u2v_dir = u2v_new_name + "]" + u2v_elem
$          goto u2v_finish
$       else
$          u2v_new_name = u2v_new_name + "."  + u2v_elem
$          goto u2v_loop
$       endif
$    endif
$!
$ u2v_dir = u2v_new_name + "]"
$!
$ u2v_finish:
$!
$ if (u2v_its_root .eqs. 1) then u2v_dir = "[" + (u2v_dir -  "[.")
$ u2v_dir = u2v_device + u2v_dir
$ VMS_NAME = u2v_dir
$ return
$!
$!                           subroutine make_unix
$!                     converts VMS_NAME to UNIX_NAME
$!     
$ make_unix:
$   mu_count = 0
$   UNIX_NAME = ""
$   VMS_NAME = f$element(1,"[",f$element(0,"]",VMS_NAME)) - "000000."
$   mu_loop:
$    mu_elem = f$element(mu_count,".",VMS_NAME)
$    mu_count = mu_count + 1
$    if ((mu_elem .nes. ".") .and. (mu_elem .nes. ""))
$    then
$       UNIX_NAME = UNIX_NAME + "/"  + mu_elem
$       goto mu_loop
$    endif
$ UNIX_NAME = f$edit(UNIX_NAME,"lowercase")
$ UNIX_NAME = UNIX_NAME - "000000"
$ return
$! 
$! less frequently used commands go here
$!
$ push_label:                                         !push 'directory'
$    if ("''p2'".eqs. "") then goto push_usage
$    dir_stack == dir_stack+1
$    current_dir = f$environment("DEFAULT")
$    if dir_stack .eqs. 1 then goto push_one
$    if dir_stack .eqs. 2 then goto push_two
$    if dir_stack .eqs. 3 then goto push_three
$    bell[0,8] = %X07
$    esc[0,8] = %X1B
$    write sys$output "''bell'" + "''esc'[1m"+"Stack Overflow!"+"''esc'[0m"
$    dir_stack == dir_stack - 1
$    goto cd_ls_exit
$!
$    push_one:
$       define/nolog old_dir_1 'current_dir'
$       write sys$output "stack: " + "''f$trnlgn("old_dir_1")'"
$       goto push_finish
$    push_two:
$       define/nolog old_dir_2 'current_dir'
$       write sys$output "stack: " + "''f$trnlgn("old_dir_1")'" +"; "   -
                               + "''f$trnlgn("old_dir_2")'"
$       goto push_finish
$    push_three:
$       define/nolog old_dir_3 'current_dir'
$       write sys$output "stack: " + "''f$trnlgn("old_dir_1")'"  + "; "  -
                              + "''f$trnlgn("old_dir_2")'"  + "; "  -
                              + "''f$trnlgn("old_dir_3")'"
$       goto push_finish
$!
$    push_finish:
$       cd 'p2'
$       pp2 = f$environment("DEFAULT")
$       if (pp2 .nes. current_dir) then goto cd_ls_exit
$!
$    mistake:
$       if ("''p2'" .eqs. "") then goto cd_ls_exit
$       dir_stack==dir_stack-1
$       goto cd_ls_exit
$!
$    push_usage:
$       write sys$output "Usage: push directory"
$       goto cd_ls_exit
$!
$ pop_label:
$       if dir_stack .eqs. 1 then goto pop_one
$       if dir_stack .eqs. 2 then goto pop_two
$       if dir_stack .eqs. 3 then goto pop_three
$       write sys$output "''bell'" + "''esc'[1m"+"Directory Stack is empty"+"''esc'[0m"
$       goto cd_ls_exit
$   pop_one:
$       cd "''f$trnlgn("old_dir_1")'"
$       goto pop_finish
$   pop_two:
$       cd "''f$trnlgn("old_dir_2")'"
$       write sys$output "stack: " + "''f$trnlgn("old_dir_1")'"
$       goto pop_finish
$   pop_three:
$       cd "''f$trnlgn("old_dir_3")'"
$       write sys$output "stack: " + "''f$trnlgn("old_dir_1")'"  + "; "  -
                              + "''f$trnlgn("old_dir_2")'"
$       goto pop_finish
$!
$   pop_finish:
$!
$       dir_stack == dir_stack-1
$       goto cd_ls_exit
   
--
John

  bitnet: davis@ohstpy
internet: davis@pacific.mps.ohio-state.edu

