;+
; NAME:
;	TRANSLATE_SETUP_DIRS
; PURPOSE:
;	Translates the UNIX script file "setup_dirs" into the equivalent 
;	command file for VMS 
; CALLING SEQUENCE:  
;	.run translate_setup_dirs
; INPUTS:
;	Reads from file "setup_dirs." on $DIR_GEN_SETUP
; OUTPUTS:
;	Writes file "setup_dirs.com" to current directory
;	Echoes the translations, etc. to the screen
; RESTRICTIONS:
;	Not tested under UNIX, but probably works
; PROCEDURE:
;
; MODIFICATION HISTORY:
;	RDB, 22-Oct-92, Written
;	RDB  18-Feb-94	Do full translation of "disk" name if there is a
;			trailing "/"  (needed for logicals like $dir_gen_tbb)
;       DMZ  15-Mar-95  Removed . from setup_dirs.
;	RDB  27-Mar-94	Some modifications to / trasnlations...
;	RDB  20-May-94  Temp. fix to problem of showpix definition
;
;-

ss=''

;	Open the files
openr,lun,concat_dir('$DIR_GEN_SETUP','setup_dirs'),/get_lun
;openw,lunw,concat_dir('$DIR_GEN_SETUP','setup_dirs.com'),/get_lun
openw,lunw,'setup_dirs.com',/get_lun

;	Add comment to output file as to when translation done
printf,lunw,'$!'
printf,lunw,'$!  This file translated to VMS on: ' + systime()
printf,lunw,'$!'

;	Read through input file line by line. 
;	Write out comments and null lines unchanged.
;	Translate the other lines infor define satements


while not eof(lun) do begin

   readf,lun,ss

   if strlen(strtrim(ss)) gt 0 then begin
;		comment line
      if strmid(ss,0,1) eq '#' then begin
         comment = '$! '+strmid(ss,1,strlen(ss)-1)
         print,comment
         printf,lunw,comment

      endif else begin
;		line of equivalence
         ss2 = str2arr(strcompress(ss),delim=' ')
         ss3 = str2arr(ss2(2),delim='/')

         sdisk = strmid(ss3(0),1,strlen(ss3(0))-1)
         ss4 = sdisk + ':[' + ss3(1)
         trail = 0
;		trailing "/" means full translation of "disk"
         if ss3(n_elements(ss3)-1) eq '' then begin
            sdisk = getenv(strupcase(sdisk))
            sdisk = strlowcase(strmid(sdisk,0,strlen(sdisk)-1))
            ss4 = sdisk + ss3(1)
            trail = 1
         endif
;		assemble rest of equivalence
         for j=2,n_elements(ss3)-1 do ss4= ss4 + '.' + ss3(j)
         ss4 = ss4 + ']'
         if trail then ss4 = ss4 + ' /tran=conc'	;modify definition
         equiv = string('$ define  $'+ss2(1),ss4,format='(a,t35,a)')

;		fix problem to showpix definition !!!!!!!!!
         if strpos(equiv,'showpix') gt 0 then equiv = '$!! ' + equiv

         print,equiv
         printf,lunw,equiv
      endelse

   endif else begin
;		null line
      print,'$!'
      printf,lunw,'$!'

   endelse

endwhile

free_lun,lun
free_lun,lunw

end
