🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.vms
Article #15623

DCL procedure to clean up Unixy filenames on OpenVMS systems

#15623
From: mathog
Date: Fri, 08 Dec 1995 00:00
203 lines
6840 bytes
Hi all,

Are you tired of having to suffer along with files left on your OpenVMS
machines by the Mac Fetch program (and others) that reveal the hideous
underpinnings of Unix filenames?  I'm referring to files with fun names like:

   $CS_1.M13FOR$5NS$EQ$5NTXT;1

or

   $CS_1.M13FOR$5N$BIN


Well I sure am, so I wrote a little DCL procedure "FIX_UNIXNAME.COM", that
converts these silly names into something more manageable.  The procedure
follows my signature. 

Here is an example of how to use it:


 $ fix_unixname :== @wherever:fix_unixname
 $ fix_unixname disk:[directory...]*.*  "" ".seq.txt,.seq,.bin^,.abi^"
                ----------------------  -- ---------------------------
                      P1                 P2             P3

P1 is either a single filename or a wildcarded search for filenames as
   in the example shown.

P2 is either FIRST or LAST, defaulting to LAST.  This is the one "."
   in the name that gets to stay a ".", the rest become "_".

P3 replaces (.seq.txt) -> (.seq) and (.bin) -> (.abi).  The "^" indicates
   beginning or ending of the file.  Replacements are each done ONCE in
   the order shown (left to right).  

P4 (not shown here), if present, shuts off logging of file name changes.

Ok, that command is a bit verbose.  So you can always put the special case
into a simpler format.  For instance, to clean up ABI DNA sequencer files
that have been FTP'd with the Mac Fetch program onto your system, you could
put this in your login.com: 

 $ clean_here :== "''fix_unixname' []*.* LAST "".seq.txt,.seq,.bin^,.abi^"""

Then go to any directory and issue the command

 $ clean_here

to convert all of the file names.

WARNING - I do NOT suggest that you use this to clean up an NFS directory
exported by Multinet to a Unix machine.  At the very least it would mangle
all of the ".whatever" and ".Whatever" files, which would break things left
and right on the Unix end.  Nor should you *EVER* run this in places like
SYS$SYSTEM!!!!!!!

Regards,

David Mathog
mathog@seqaxp.bio.caltech.edu
Manager, sequence analysis facility, biology division, Caltech 
**********************************************************************
$!FIX_UNIXNAME.COM
$! 7-DEC-1995, David Mathog, Biology Division, Caltech
$!
$! This routine converts hideous Unixy filenames, such as:
$!     $RC_100A.T7$5NS$EQ$5NTXT
$! to a more civilized form, such as:
$!     rc_100a_t7.seq
$!
$! In the first pass all $5N are converted to "."
$! In the second pass all single $ are removed.
$! In the third pass all replacements are done
$! In the fourth pass, reduce to a single "."
$!
$! Here is an example use, which cleans up ABI sequence files transferred 
$! with the Mac program fetch.  All ".seq.txt" files become ".seq", and 
$! all ".bin" files become ".abi"
$!
$!  $ @fix_unixname disk:[directory.subdirectory...]*.*  "" ".seq.txt,.seq,.bin^,.abi^"
$!
$! Parameters are:
$! P1  Name of file or wildcarded search string
$! P2  "Period priority".  Options are FIRST and LAST, default being
$!     LAST.  These take effect after the string is converted to the
$!     unix form, ie RC_100A.T7.Seq.txt
$! P3  Replacement pairs.  Not case sensitive.  A string like:
$!     "seq.txt,.txt,.bin,.abi"  These consist of a pattern to find,
$!     and a string to replace it with.  Most useful for removing the
$!     drivel that Mac's FETCH sticks on the end. "^" matches begin and
$!     end of a filename, ie ".bin^" will only pick up a final ".bin"
$!     Each replacement is only performed ONCE per name.
$! P4  Anything but a "" silences logging of changes
$!
$ if(P1 .nes. "")
$ then
$   searchfor = P1
$ else
$   inquire searchfor "Enter a Unixy filename or wildcarded search string"
$ endif
$!
$ if(P2 .nes. "")
$ then
$   PerPri = F$EDIT(P2,"TRIM,UPCASE")
$   if(PerPri .nes. "FIRST")then PerPri = "LAST"
$ else
$   PerPri = "LAST"
$ endif
$!
$ reppairs="foo"
$ if(P3 .nes. "")then reppairs = P3
$ reppairs = f$edit(reppairs,"UPCASE,TRIM")
$!
$ silent = P4
$!
$!  Top of search string
$!
$TOP:
$  file = f$search(searchfor)
$  if(file .eqs. "")then goto done
$  target   = f$parse(file,,,"NAME") + f$parse(file,,,"TYPE")
$  yuckname = "^" + target + "^"
$!
$! pass1, convert all $5N to "."
$!
$TOP1:
$  site = f$locate("$5N",yuckname)
$  len  = f$length(yuckname)
$  if(site .ne. len)
$    then
$       yuckname=   f$extract(0,site,yuckname) -
                  + "." -
                  + f$extract(site+3,len-site-3,yuckname)
$       goto top1
$    endif  
$!
$! pass2, get rid of all loose "$"
$!
$TOP2:
$  back  = f$element(1,"$",yuckname)
$  if(back .nes. "$")
$  then
$       yuckname = yuckname - "$"
$       goto top2
$  endif
$!
$! pass3, Do all substitutions
$!
$count = 0
$TOP3:
$  was    = f$element(count,",",reppairs)
$  willbe = f$element(count+1,",",reppairs)
$  count  = count + 2
$  if(was .eqs. "," .or. willbe .eqs.",")then goto bottom3
$  site   = f$locate(was,yuckname)
$  len    = f$length(yuckname)
$  lenw   = f$length(was)
$  if(site .ne. len)
$  then
$       yuckname=   f$extract(0,site,yuckname) -
                  + willbe -
                  + f$extract(site+lenw,len-site-lenw,yuckname)
$  endif  
$  goto top3
$bottom3:
$!
$!  Pass4, reduce to one period, all others become "_".
$!
$ onedot = -1
$ len  = f$length(yuckname)
$ top4:
$ site = f$locate(".",yuckname)
$ if(site .ne. len)
$ then
$    yuckname=   f$extract(0,site,yuckname) -
                 + "_" -
                 + f$extract(site+1,len-site-1,yuckname)
$    if(PerPri .eqs. "FIRST")
$    then
$       if(onedot .eq. -1)then onedot = site
$    else
$       onedot = site
$    endif
$    goto top4
$ endif  
$    yuckname=   f$extract(0,onedot,yuckname) -
                 + "." -
                 + f$extract(onedot+1,len-onedot-1,yuckname)
$!
$! strip off the beginning and ending "^" and put the directory stuff back on
$!
$ yuckname = yuckname - "^" - "^"
$ if(target .nes. yuckname)
$ then
$   if(silent .eqs. "")
$   then
$     write sys$output "was: ''target'"
$     write sys$output "is:  ''yuckname'"
$   endif
$ rename 'file' 'yuckname'
$ endif
$ goto top
$done:
Technical Details
Message-ID: <4a83fs$gdo@gap.cco.caltech.edu>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f7344,5c8f5de4a057cd2,start
X-Google-Attributes: gidf7344,public
X-Google-Thread: fa6b6,5c8f5de4a057cd2,start
X-Google-Attributes: gidfa6b6,public
From: mathog@seqaxp.bio.caltech.edu
Subject: DCL procedure to clean up Unixy filenames on OpenVMS systems
Date: 1995/12/08
Message-ID: <4a83fs$gdo@gap.cco.caltech.edu>
X-Deja-AN: 121244016
organization: Biology Division, Caltech, Pasadena CA 91125
reply-to: mathog@seqaxp.bio.caltech.edu
newsgroups: comp.os.vms,bionet.software