Initial Commit
[packages] / xemacs-packages / bbdb / misc / bbdb-unmigrate-stuff.el
1 ;;; -*- Mode:Emacs-Lisp -*-
2
3 ;;; This file is part of the Insidious Big Brother Database (aka BBDB),
4 ;;; Copyright (c) 2000 Alex Schroeder
5 ;;;
6 ;;; The Insidious Big Brother Database is free software; you can redistribute
7 ;;; it and/or modify it under the terms of the GNU General Public License as
8 ;;; published by the Free Software Foundation; either version 2, or (at your
9 ;;; option) any later version.
10 ;;;
11 ;;; BBDB is distributed in the hope that it will be useful, but WITHOUT ANY
12 ;;; WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 ;;; FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
14 ;;; details.
15 ;;;
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with GNU Emacs; see the file COPYING.  If not, write to
18 ;;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
19
20 (defun bbdb-unmigrate-stuff (&optional new-version)
21   "Create a buffer with unmigrated BBDB data.
22 Usefull if you fooled around with BBDB file format 4 by Alex and want to
23 start using the official BBDB 2.00.06 again.  In order to do that, you
24 have to save your .bbdb in BBDB file format 3 instead of the file format 4
25 introduced by Alex.  This function will create a *BBDB Version 3* buffer
26 for you, which you can examine and save as your new .bbdb.  The unmigration
27 will strip the country fields of all entries in your BBDB as such a field
28 did not exist in the BBDB file format 3 used in BBDB 2.00.06."
29   (interactive "nUnmigrate to version (I recommend version 3): ")
30   (if (null new-version)
31       (setq new-version 3))
32   (if (>= new-version bbdb-file-format)
33       (error "Current BBDB file format is version %d" bbdb-file-format)
34     (let* ((records (bbdb-records))
35            (propnames (bbdb-with-db-buffer bbdb-propnames))
36            (rec)
37            (bbdb-file-format-migration (cons bbdb-file-format new-version))
38            (buf (get-buffer-create (format "*BBDB Version %d*" (cdr bbdb-file-format-migration)))))
39       (message "Unconverting the BBDB database...")
40       (set-buffer buf)
41       (erase-buffer)
42       (insert (format (concat ";;; file-version: %d\n"
43                               ";;; user-fields: %S\n")
44                       new-version (mapcar (function (lambda (x) (intern (car x))))
45                                           propnames)))
46       (while records
47         (setq rec (copy-sequence (car records)))
48         (bbdb-unmigrate-record rec)
49         (aset rec 8 nil)
50         (insert (format "%S\n" rec))
51         (setq records (cdr records)))
52       (pop-to-buffer buf)
53       (message "Unconverting the BBDB database...done"))))