annotate lisp/net/netrc.el @ 54126:8d0f80667054

(w32_draw_fringe_bitmap): Draw overlaid bitmaps correctly over other bitmaps.
author Jason Rumney <jasonr@gnu.org>
date Sun, 22 Feb 2004 22:41:52 +0000
parents 695cf19ef79e
children 18a818a2ee7c 375f2633d815
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
44810
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 ;;; netrc.el --- .netrc parsing functionality
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3 ;; Free Software Foundation, Inc.
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 ;; Keywords: news
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 ;; Modularized by Ted Zlatanov <tzz@lifelogs.com>
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 ;; when it was part of Gnus.
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10 ;; This file is part of GNU Emacs.
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; it under the terms of the GNU General Public License as published by
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; the Free Software Foundation; either version 2, or (at your option)
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 ;; any later version.
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; GNU Emacs is distributed in the hope that it will be useful,
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 ;; GNU General Public License for more details.
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25 ;; Boston, MA 02111-1307, USA.
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 ;;; Commentary:
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 ;; Just the .netrc parsing functionality, abstracted so other packages
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 ;; besides Gnus can use it.
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 ;;; Code:
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 ;;;
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 ;;; .netrc and .authinforc parsing
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 ;;;
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 (defalias 'netrc-point-at-eol
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 (if (fboundp 'point-at-eol)
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 'point-at-eol
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 'line-end-position))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 (defun netrc-parse (file)
47927
7089f332a708 (netrc-parse): Fix typo.
Juanma Barranquero <lekktu@gmail.com>
parents: 44810
diff changeset
44 "Parse FILE and return a list of all entries in the file."
44810
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 (when (file-exists-p file)
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 (with-temp-buffer
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 (let ((tokens '("machine" "default" "login"
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 "password" "account" "macdef" "force"
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 "port"))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 alist elem result pair)
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 (insert-file-contents file)
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 (goto-char (point-min))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 ;; Go through the file, line by line.
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 (while (not (eobp))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 (narrow-to-region (point) (netrc-point-at-eol))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 ;; For each line, get the tokens and values.
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 (while (not (eobp))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 (skip-chars-forward "\t ")
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 ;; Skip lines that begin with a "#".
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 (if (eq (char-after) ?#)
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 (goto-char (point-max))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 (unless (eobp)
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 (setq elem
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 (if (= (following-char) ?\")
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 (read (current-buffer))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 (buffer-substring
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 (point) (progn (skip-chars-forward "^\t ")
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 (point)))))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 (cond
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 ((equal elem "macdef")
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 ;; We skip past the macro definition.
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 (widen)
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 (while (and (zerop (forward-line 1))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 (looking-at "$")))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 (narrow-to-region (point) (point)))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 ((member elem tokens)
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 ;; Tokens that don't have a following value are ignored,
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 ;; except "default".
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 (when (and pair (or (cdr pair)
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 (equal (car pair) "default")))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 (push pair alist))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 (setq pair (list elem)))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 (t
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 ;; Values that haven't got a preceding token are ignored.
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 (when pair
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 (setcdr pair elem)
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 (push pair alist)
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 (setq pair nil)))))))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 (when alist
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 (push (nreverse alist) result))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 (setq alist nil
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 pair nil)
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 (widen)
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 (forward-line 1))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 (nreverse result)))))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 (defun netrc-machine (list machine &optional port defaultport)
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 "Return the netrc values from LIST for MACHINE or for the default entry.
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 If PORT specified, only return entries with matching port tokens.
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 Entries without port tokens default to DEFAULTPORT."
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 (let ((rest list)
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 result)
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 (while list
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 (when (equal (cdr (assoc "machine" (car list))) machine)
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 (push (car list) result))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 (pop list))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 (unless result
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 ;; No machine name matches, so we look for default entries.
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 (while rest
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110 (when (assoc "default" (car rest))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 (push (car rest) result))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 (pop rest)))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 (when result
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 (setq result (nreverse result))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 (while (and result
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 (not (equal (or port defaultport "nntp")
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 (or (netrc-get (car result) "port")
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 defaultport "nntp"))))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 (pop result))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 (car result))))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 (defun netrc-get (alist type)
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 "Return the value of token TYPE from ALIST."
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 (cdr (assoc type alist)))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 (provide 'netrc)
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 47927
diff changeset
128 ;;; arch-tag: af9929cc-2d12-482f-936e-eb4366f9fa55
44810
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 ;;; netrc.el ends here