emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Patch for invalid chars in file names on Cygwin


From: Ehud Karni
Subject: Patch for invalid chars in file names on Cygwin
Date: Sat, 20 Aug 2005 18:54:07 +0300

On 2005-08-11 I sent the following patch for Cygwin handling of file
names. I did not get any response. Please check this and comment.

[Repeat of that email, with new diffs against the newer versions]

I discovered today that `convert-standard-filename' on Cygwin does
nothing and as result `make-temp-file' fails for name like "*mail*".
The change in `make-auto-save-file-name' in 22.0.50 to call
`make-temp-file' (it was `make-temp-name' before) made `compose-mail'
fails on Cygwin.

I created a new file `cygwin.el' to have Cygwin specific functions
(for now just one). Below is a patch that fix this problem.

Note. I don't have CVS write permission, so pleas check my patch
and if you find it appropriate, please install it.

Ehud.



2005-08-11  Ehud Karni  <address@hidden>

        * files.el (convert-standard-filename): change documentation.
        (abbreviate-file-name): replace or by memq.
        (make-auto-save-file-name): call `convert-standard-filename'
        when OS is Cygwin too.

        * loadup.el load cygwin when OS is Cygwin. Dump on Cygwin
        with 2 names (as on UNIX).

        * cygwin.el - new file. (convert-standard-filename): new function
        to ensure valid file name on Cygwin.


diff -c lisp/files.el.\~1.784.\~ lisp/files.el
*** lisp/files.el.~1.784.~      Mon Aug 15 05:05:01 2005
--- lisp/files.el               Mon Aug 15 23:35:10 2005
***************
*** 517,526 ****
  This function's standard definition is trivial; it just returns
  the argument.  However, on Windows and DOS, replace invalid
  characters.  On DOS, make sure to obey the 8.3 limitations.  On
! Windows, turn Cygwin names into native names, and also turn
! slashes into backslashes if the shell requires it (see
  `w32-shell-dos-semantics').

  See Info node `(elisp)Standard File Names' for more details."
    filename)

--- 517,528 ----
  This function's standard definition is trivial; it just returns
  the argument.  However, on Windows and DOS, replace invalid
  characters.  On DOS, make sure to obey the 8.3 limitations.  On
! Windows (native), turn Cygwin names into native names, and also
! turn slashes into backslashes if the shell requires it (see
  `w32-shell-dos-semantics').

+ On Cygwin, replace invalid Windows characters.
+
  See Info node `(elisp)Standard File Names' for more details."
    filename)

***************
*** 1232,1240 ****
                       (= (aref filename 0) ?/)))
             ;; MS-DOS root directories can come with a drive letter;
             ;; Novell Netware allows drive letters beyond `Z:'.
!            (not (and (or (eq system-type 'ms-dos)
!                          (eq system-type 'cygwin)
!                          (eq system-type 'windows-nt))
                       (save-match-data
                         (string-match "^[a-zA-`]:/$" filename)))))
        (setq filename
--- 1234,1240 ----
                       (= (aref filename 0) ?/)))
             ;; MS-DOS root directories can come with a drive letter;
             ;; Novell Netware allows drive letters beyond `Z:'.
!            (not (and (memq system-type '(ms-dos windows-nt cygwin))
                       (save-match-data
                         (string-match "^[a-zA-`]:/$" filename)))))
        (setq filename
***************
*** 4098,4104 ****
                        "#")))
        ;; Make sure auto-save file names don't contain characters
        ;; invalid for the underlying filesystem.
!       (if (and (memq system-type '(ms-dos windows-nt))
                 ;; Don't modify remote (ange-ftp) filenames
                 (not (string-match "^/address@hidden:" result)))
            (convert-standard-filename result)
--- 4098,4104 ----
                        "#")))
        ;; Make sure auto-save file names don't contain characters
        ;; invalid for the underlying filesystem.
!       (if (and (memq system-type '(ms-dos windows-nt cygwin))
                 ;; Don't modify remote (ange-ftp) filenames
                 (not (string-match "^/address@hidden:" result)))
            (convert-standard-filename result)
***************
*** 4133,4139 ****
                      ((file-writable-p default-directory) default-directory)
                      ((file-writable-p "/var/tmp/") "/var/tmp/")
                      ("~/")))))
!              (if (and (memq system-type '(ms-dos windows-nt))
                        ;; Don't modify remote (ange-ftp) filenames
                        (not (string-match "^/address@hidden:" fname)))
                   ;; The call to convert-standard-filename is in case
--- 4133,4139 ----
                      ((file-writable-p default-directory) default-directory)
                      ((file-writable-p "/var/tmp/") "/var/tmp/")
                      ("~/")))))
!              (if (and (memq system-type '(ms-dos windows-nt cygwin))
                        ;; Don't modify remote (ange-ftp) filenames
                        (not (string-match "^/address@hidden:" fname)))
                   ;; The call to convert-standard-filename is in case



diff -c lisp/loadup.el.\~1.141.\~ lisp/loadup.el
*** lisp/loadup.el.~1.141.~     Sun Aug  7 01:13:43 2005
--- lisp/loadup.el              Wed Aug 10 23:30:55 2005
***************
*** 167,172 ****
--- 167,175 ----
  (if (eq system-type 'vax-vms)
      (progn
        (load "vms-patch")))
+ (if (eq system-type 'cygwin)
+     (progn
+       (load "cygwin")))
  (if (eq system-type 'windows-nt)
      (progn
        (load "ls-lisp")
***************
*** 321,347 ****
          (setq name (concat (downcase (substring name 0 (match-beginning 0)))
                             "-"
                             (substring name (match-end 0)))))
!       (if (memq system-type '(ms-dos windows-nt cygwin))
            (message "Dumping under the name emacs")
!         (message "Dumping under names emacs and %s" name)))
!       (condition-case ()
!         (delete-file "emacs")
!       (file-error nil))
!       ;; We used to dump under the name xemacs, but that occasionally
!       ;; confused people installing Emacs (they'd install the file
!       ;; under the name `xemacs'), and it's inconsistent with every
!       ;; other GNU program's build process.
!       (dump-emacs "emacs" "temacs")
!       (message "%d pure bytes used" pure-bytes-used)
!       ;; Recompute NAME now, so that it isn't set when we dump.
!       (if (not (memq system-type '(ms-dos windows-nt cygwin)))
!         (let ((name (concat "emacs-" emacs-version)))
!           (while (string-match "[^-+_.a-zA-Z0-9]+" name)
!             (setq name (concat (downcase (substring name 0 (match-beginning 
0)))
!                                "-"
!                                (substring name (match-end 0)))))
!           (add-name-to-file "emacs" name t)))
!       (kill-emacs)))

  ;; Avoid error if user loads some more libraries now.
  (setq purify-flag nil)
--- 324,347 ----
          (setq name (concat (downcase (substring name 0 (match-beginning 0)))
                             "-"
                             (substring name (match-end 0)))))
!       (if (memq system-type '(ms-dos windows-nt))
            (message "Dumping under the name emacs")
!         (message "Dumping under names emacs and %s" name))
!       (condition-case ()
!           (delete-file "emacs")
!         (file-error nil))
!       ;; We used to dump under the name xemacs, but that occasionally
!       ;; confused people installing Emacs (they'd install the file
!       ;; under the name `xemacs'), and it's inconsistent with every
!       ;; other GNU program's build process.
!       (dump-emacs "emacs" "temacs")
!       (message "%d pure bytes used" pure-bytes-used)
!       ;; Recompute NAME now, so that it isn't set when we dump.
!       (if (not (memq system-type '(ms-dos windows-nt)))
!           (if (eq system-type 'cygwin)
!               (add-name-to-file "emacs.exe" (concat name ".exe") t))
!             (add-name-to-file "emacs" name t)))
!       (kill-emacs)))

  ;; Avoid error if user loads some more libraries now.
  (setq purify-flag nil)


New file  lisp/cygwin.el        Wed Aug 10 23:43:28 2005
********************************************************

;;; cygwin.el --- Lisp routines for Cygwin emulation layer

;; Copyright (C) 2005 Free Software Foundation, Inc.

;; Author: Ehud Karni <address@hidden>
;; Keywords: internal

;; This file is part of GNU Emacs.

;; GNU Emacs 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.

;; GNU Emacs 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 GNU Emacs; see the file COPYING.  If not, write to the
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.

;;; Commentary:

;; (August 10, 2005)
;; Created.


(defun convert-standard-filename (filename)
  "Convert a standard file's name to something suitable for the OS.
This means to guarantee valid names and perhaps to canonicalize
certain patterns.

FILENAME should be an absolute file name since the conversion rules
sometimes vary depending on the position in the file name.  E.g. c:/foo
is a valid DOS file name, but c:/bar/c:/foo is not.

This function's standard definition is trivial; it just returns
the argument.  However, on Windows and DOS, replace invalid
characters.  On DOS, make sure to obey the 8.3 limitations.  On
Windows (native), turn Cygwin names into native names, and also
turn slashes into backslashes if the shell requires it (see
`w32-shell-dos-semantics').

On Cygwin, replace invalid Windows characters.

See Info node `(elisp)Standard File Names' for more details."
  (let ((name filename)
        (start 0))
    ;; destructively replace invalid filename characters with %
    (while (string-match "[?*:<>|\"\000-\037]" name start)
      (aset name (match-beginning 0) ?%)
      (setq start (match-end 0)))
    name))


;;; arch-tag:
;;; cygwin.el ends here



--
 Ehud Karni           Tel: +972-3-7966-561  /"\
 Mivtach - Simon      Fax: +972-3-7966-667  \ /  ASCII Ribbon Campaign
 Insurance agencies   (USA) voice mail and   X   Against   HTML   Mail
 http://www.mvs.co.il  FAX:  1-815-5509341  / \
 GnuPG: 98EA398D <http://www.keyserver.net/>    Better Safe Than Sorry




reply via email to

[Prev in Thread] Current Thread [Next in Thread]