-(defun Info-suffixed-file (name &optional name2)
- "Look for NAME with each of the `Info-suffix-list' extensions in
-turn. Optional NAME2 is the name of a fallback info file to check
-for; usually a downcased version of NAME."
- (let ((suff Info-suffix-list)
- (found nil)
- file file2)
- (while (and suff (not found))
- (setq file (concat name (caar suff))
- file2 (and name2 (concat name2 (caar suff))))
- (cond
- ((file-regular-p file)
- (setq found file))
- ((and file2 (file-regular-p file2))
- (setq found file2))
- (t
- (setq suff (cdr suff)))))
- (or found
- (and name (when (file-regular-p name)
- name))
- (and name2 (when (file-regular-p name2)
- name2)))))
+(defun Info-all-case-regexp (str)
+ (let ((regexp "")
+ (len (length str))
+ (i 0)
+ c)
+ (while (< i len)
+ (setq c (aref str i))
+ (cond ((or (and (>= c ?A) (<= c ?Z))
+ (and (>= c ?a) (<= c ?z)))
+ (setq regexp (concat regexp
+ "["
+ (char-to-string (downcase c))
+ "\\|"
+ (char-to-string (upcase c))
+ "]")))
+ (t
+ (setq regexp (concat regexp (char-to-string c)))))
+ (setq i (1+ i)))
+ regexp))
+
+(defun Info-suffixed-file (name &optional exact)
+ "Look for an info file named NAME. This function tries to be smart in
+finding the file corresponding to NAME: if it doesn't exist, several
+variants are looked for, notably by appending suffixes from
+`Info-suffix-list' and by trying to change the characters case in NAME.
+
+The optional argument EXACT prevents this function from trying different case
+versions of NAME. Only the suffixes are tried."
+ (catch 'found
+ ;; First, try NAME alone:
+ (and (file-regular-p name) (throw 'found name))
+ ;; Then, try different variants
+ (let ((suff-match (concat "\\("
+ (let ((suff-list Info-suffix-list)
+ suff regexp)
+ (while (setq suff (pop suff-list))
+ (setq regexp
+ (concat regexp
+ (regexp-quote (car suff))
+ (and suff-list "\\|"))))
+ regexp)
+ "\\)?$"))
+ (dir (file-name-directory name))
+ file files)
+ (setq name (file-name-nondirectory name))
+ (setq files
+ (condition-case data ;; protect against invalid directory
+ ;; First, try NAME[.<suffix>]
+ (append
+ (directory-files dir 'fullname
+ (concat "^" (regexp-quote name) suff-match)
+ nil t)
+ (if exact
+ nil
+ ;; Then, try to match the name independantly of the
+ ;; characters case.
+ (directory-files dir 'fullname
+ (Info-all-case-regexp
+ (concat "^"
+ (regexp-quote name)
+ suff-match))
+ nil t)))
+ (t
+ (display-warning 'info
+ (format "directory `%s' error: %s" dir data))
+ nil)))
+ (while (setq file (pop files))
+ (and (file-regular-p file)
+ (throw 'found file)))
+ )))