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