home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / lifeos2.zip / LIFE-1.02 / LIB / FILES.LF < prev    next >
Text File  |  1996-06-04  |  2KB  |  103 lines

  1. %    $Id: files.lf,v 1.2 1994/12/08 23:57:59 duchier Exp $    
  2. module("files") ?
  3.  
  4. public(set_extension)?
  5. add_man(set_extension,
  6.     " NewName = set_extension(FileName,Extension)?
  7.  
  8.   input: Filename:string, Extension:string
  9.  
  10.   output: NewName:string
  11.  
  12.   Changes the extension of a UNIX filename to 'Extension'.
  13.  
  14.   Examples:
  15.  
  16.   set_extension(""charley.pl"",""lf"")  -> ""charley.lf""
  17.   set_extension(""long"",""hair"") -> ""long.hair""
  18.   set_extension(""~/a.b/c"",""d"") -> ""~/a.b/c.d""
  19.   ")?
  20.  
  21. %
  22. % Change a file's extension
  23. %
  24.  
  25. set_extension(Name,Ext) -> change_ext(Name,Ext,strlen(Name)).
  26.  
  27. change_ext(N,E,L) ->
  28.  
  29.     cond(    C:substr(N,L,1) $== ".",
  30.         strcon(substr(N,1,L),E),
  31.         cond(    C $== "/" or L=<1,
  32.             strcon(N,strcon(".",E)),
  33.             change_ext(N,E,L-1)
  34.         )
  35.     ).
  36.  
  37. public(remove_extension)?
  38. add_man(remove_extension,
  39.     " NewName = remove_extension(FileName)?
  40.  
  41.   input: Filename:string
  42.  
  43.   output: NewName:string
  44.  
  45.   removes the extension of a UNIX filename.
  46.  
  47.   Examples:
  48.  
  49.     remove_extension(""charley.pl"")  -> ""charley""
  50.     remove_extension(""long"") -> ""long""
  51.     remove_extension(""~/a.b/c"") -> ""~/a.b/c""
  52.   ")?
  53.  
  54. %
  55. % Change a file's extension
  56. %
  57.  
  58. remove_extension(Name) -> remove_ext(Name,strlen(Name)).
  59.  
  60. remove_ext(N,L) ->
  61.  
  62.     cond(    C:substr(N,L,1) $== ".",
  63.         substr(N,1,L-1),
  64.         cond(    C $== "/" or L=<1,
  65.             N,
  66.             remove_ext(N,L-1)
  67.         )
  68.     ).
  69.  
  70.  
  71.  
  72.  
  73. public(remove_path)?
  74. add_man(remove_path,
  75.     " File = remove_path(CompleteName)?
  76.  
  77.   input: CompleteName:string
  78.  
  79.   output: File:string
  80.  
  81.   Removes the UNIX path from a file name.
  82.  
  83.   Examples:
  84.  
  85.   remove_path(""/user/loud_mouth/noises/hello.au"") -> ""hello.au"".
  86.   remove_path(""clap.au"") -> ""clap.au"".
  87.   ")?
  88.  
  89.  
  90.  
  91. %
  92. % Remove the path from a file name.
  93. %
  94.  
  95. remove_path(File) -> remove_path_loop(File,strlen(File)).
  96.  
  97. remove_path_loop(File,0) -> File.
  98. remove_path_loop(File,L) -> cond(L<1,
  99.                  File,
  100.                  cond(substr(File,L,1) $== "/",
  101.                       substr(File,L+1,strlen(File)-L),
  102.                       remove_path_loop(File,L-1))).
  103.