1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
;;; cedet-files.el --- Common routines dealing with file names.
;; Copyright (C) 2007 Eric M. Ludlam
;; Author: Eric M. Ludlam <eric@siege-engine.com>
;; X-RCS: $Id: cedet-files.el,v 1.1 2007-11-26 15:06:39 michaels Exp $
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 2, or (at
;; your option) any later version.
;; This program is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
;;; Commentary:
;;
;; Various useful routines for dealing with file names in the tools
;; which are a part of CEDET.
;;; Code:
(defvar cedet-dir-sep-char (if (boundp 'directory-sep-char)
(symbol-value 'directory-sep-char)
?/)
"Character used for directory separation.
Obsoleted in some versions of Emacs. Needed in others.")
(defun cedet-directory-name-to-file-name (referencedir)
"Convert the REFERENCEDIR (a full path name) into a filename.
Converts directory seperation characters into ! characters."
(let ((file referencedir)
dir-sep-string)
;; Expand to full file name
(or (file-name-absolute-p file)
(setq file (expand-file-name file)))
;; If FILE is a directory, then force it to end in /.
(when (file-directory-p file)
(setq file (file-name-as-directory file)))
;; Handle Windows Special cases
(when (memq system-type '(windows-nt ms-dos))
;; Replace any invalid file-name characters (for the
;; case of backing up remote files).
(setq file (expand-file-name (convert-standard-filename file)))
(setq dir-sep-string (char-to-string cedet-dir-sep-char))
;; Normalize DOSish file names: convert all slashes to
;; directory-sep-char, downcase the drive letter, if any,
;; and replace the leading "x:" with "/drive_x".
(if (eq (aref file 1) ?:)
(setq file (concat dir-sep-string
"drive_"
(char-to-string (downcase (aref file 0)))
(if (eq (aref file 2) cedet-dir-sep-char)
""
dir-sep-string)
(substring file 2)))))
;; Make the name unique by substituting directory
;; separators. It may not really be worth bothering about
;; doubling `!'s in the original name...
(setq file (subst-char-in-string
cedet-dir-sep-char ?!
(replace-regexp-in-string "!" "!!" file)))
file))
(provide 'cedet-files)
;;; cedet-files.el ends here
|