annotate lisp/gnus/hex-util.el @ 82966:28d9e552d178

Merge some changes from Emacs/trunk: 2004-08-22 Reiner Steib <Reiner.Steib@gmx.de> * gnus-mlspl.el (gnus-group-split-update): Fix docstring. 2004-08-22 Stefan Monnier <monnier@iro.umontreal.ca> * gnus-art.el: Use inhibit-read-only instead of buffer-read-only. (gnus-narrow-to-page): Don't assume point-min == 1. (gnus-article-edit-mode): Derive from message-mode. * gnus-score.el (gnus-score-find-bnews): Simplify and don't assume point-min == 1. * imap.el (imap-parse-address-list, imap-parse-body-ext): Disable incorrect use of `assert'. [Emacs/trunk 2004-03-22] * message.el (message-mode): Set comment-start-skip. [Emacs/trunk 2004-03-04] 2004-08-22 Sam Steingold <sds@gnu.org> * pop3.el (pop3-leave-mail-on-server): New user variable. (pop3-movemail): Delete mail only when it is nil. [Emacs/trunk 2003-06-11]
author Reiner Steib <Reiner.Steib@gmx.de>
date Sun, 22 Aug 2004 19:35:29 +0000
parents 0fde48feb604
children 18a818a2ee7c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
82951
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
1 ;;; hex-util.el --- Functions to encode/decode hexadecimal string.
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
2
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
3 ;; Copyright (C) 1999, 2001 Free Software Foundation, Inc.
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
4
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
5 ;; Author: Shuhei KOBAYASHI <shuhei@aqua.ocn.ne.jp>
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
6 ;; Keywords: data
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
7
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
8 ;; This file is part of FLIM (Faithful Library about Internet Message).
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
9
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
10 ;; This program is free software; you can redistribute it and/or
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
11 ;; modify it under the terms of the GNU General Public License as
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
12 ;; published by the Free Software Foundation; either version 2, or
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
13 ;; (at your option) any later version.
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
14
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
15 ;; This program is distributed in the hope that it will be useful,
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
18 ;; GNU General Public License for more details.
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
19
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
21 ;; along with this program; see the file COPYING. If not, write to
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
22 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
23 ;; Boston, MA 02111-1307, USA.
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
24
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
25 ;;; Commentary:
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
26
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
27 ;;; Code:
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
28
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
29 (eval-when-compile
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
30 (defmacro hex-char-to-num (chr)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
31 (` (let ((chr (, chr)))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
32 (cond
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
33 ((and (<= ?a chr)(<= chr ?f)) (+ (- chr ?a) 10))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
34 ((and (<= ?A chr)(<= chr ?F)) (+ (- chr ?A) 10))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
35 ((and (<= ?0 chr)(<= chr ?9)) (- chr ?0))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
36 (t (error "Invalid hexadecimal digit `%c'" chr))))))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
37 (defmacro num-to-hex-char (num)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
38 (` (aref "0123456789abcdef" (, num)))))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
39
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
40 (defun decode-hex-string (string)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
41 "Decode hexadecimal STRING to octet string."
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
42 (let* ((len (length string))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
43 (dst (make-string (/ len 2) 0))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
44 (idx 0)(pos 0))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
45 (while (< pos len)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
46 ;;; logior and lsh are not byte-coded.
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
47 ;;; (aset dst idx (logior (lsh (hex-char-to-num (aref string pos)) 4)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
48 ;;; (hex-char-to-num (aref string (1+ pos)))))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
49 (aset dst idx (+ (* (hex-char-to-num (aref string pos)) 16)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
50 (hex-char-to-num (aref string (1+ pos)))))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
51 (setq idx (1+ idx)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
52 pos (+ 2 pos)))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
53 dst))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
54
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
55 (defun encode-hex-string (string)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
56 "Encode octet STRING to hexadecimal string."
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
57 (let* ((len (length string))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
58 (dst (make-string (* len 2) 0))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
59 (idx 0)(pos 0))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
60 (while (< pos len)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
61 ;;; logand and lsh are not byte-coded.
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
62 ;;; (aset dst idx (num-to-hex-char (logand (lsh (aref string pos) -4) 15)))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
63 (aset dst idx (num-to-hex-char (/ (aref string pos) 16)))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
64 (setq idx (1+ idx))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
65 ;;; (aset dst idx (num-to-hex-char (logand (aref string pos) 15)))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
66 (aset dst idx (num-to-hex-char (% (aref string pos) 16)))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
67 (setq idx (1+ idx)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
68 pos (1+ pos)))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
69 dst))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
70
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
71 (provide 'hex-util)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
72
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
73 ;;; arch-tag: fe8aaa79-6c86-400e-813f-5a8cc4cb3859
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
74 ;;; hex-util.el ends here