1;;; sb-texfaq.el --- shimbun backend for TeX Q&A Bullettein Board.
2
3;; Copyright (C) 2002, 2004 Hidetaka Iwai <tyuyu@mb6.seikyou.ne.jp>
4
5;; Author: Hidetaka Iwai <tyuyu@mb6.seikyou.ne.jp>,
6;;         TSUCHIYA Masatoshi <tsuchiya@namazu.org>
7;; Keywords: news
8
9;; This file is a part of shimbun.
10
11;; This program is free software; you can redistribute it and/or modify
12;; it under the terms of the GNU General Public License as published by
13;; the Free Software Foundation; either version 2, or (at your option)
14;; any later version.
15
16;; This program is distributed in the hope that it will be useful,
17;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19;; GNU General Public License for more details.
20
21;; You should have received a copy of the GNU General Public License
22;; along with this program; see the file COPYING.  If not, write to
23;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24;; Boston, MA 02110-1301, USA.
25
26;;; Code:
27
28(require 'shimbun)
29
30(luna-define-class shimbun-texfaq (shimbun) ())
31
32(defvar shimbun-texfaq-url "http://oku.edu.mie-u.ac.jp/~okumura/texfaq/qa/")
33(defvar shimbun-texfaq-groups '("qanda"))
34(defvar shimbun-texfaq-content-start "</h2>\n")
35(defvar shimbun-texfaq-content-end  "\n<hr>\n<p>")
36
37(defun shimbun-texfaq-make-id (shimbun string)
38  (concat "<"
39	  string
40	  "."
41	  (shimbun-current-group-internal shimbun)
42	  "@"
43	  (save-match-data
44	    (let ((url (shimbun-index-url shimbun)))
45	      (if (string-match "\\`[^:/]+://\\([^/]+\\)/" url)
46		  (match-string 1 url)
47		(error "Cannot extract host name from %s" url))))
48	  ">"))
49
50(luna-define-method shimbun-get-headers ((shimbun shimbun-texfaq)
51					 &optional range)
52  (let ((case-fold-search t) headers)
53    (catch 'found
54      (goto-char (point-min))
55      (while (re-search-forward "[0-9]+: \
56\\([0-9][0-9][0-9][0-9]\\)-\\([0-1][0-9]\\)-\\([0-3][0-9]\\) \
57\\([0-2][0-9]:[0-5][0-9]:[0-5][0-9]\\) \
58<a href=\"\\(\\([0-9]+\\)\\.html\\)\">\\([^<]+\\)</a>\\([^<]+\\)<br>" nil t)
59	(let ((date (shimbun-make-date-string
60		     (string-to-number (match-string 1))
61		     (string-to-number (match-string 2))
62		     (string-to-number (match-string 3))
63		     (match-string 4)))
64	      (subject (match-string 7))
65	      (author (match-string 8))
66	      (url (shimbun-expand-url (match-string 5)
67				       (shimbun-index-url shimbun)))
68	      (id (shimbun-texfaq-make-id shimbun (match-string 6))))
69	  (when (shimbun-search-id shimbun id)
70	    (throw 'found headers))
71	  (push (shimbun-create-header 0 subject author date id "" 0 0 url)
72		headers)))
73      headers)))
74
75(luna-define-method shimbun-make-contents :before ((shimbun shimbun-texfaq)
76						   header)
77  (save-excursion
78    (goto-char (point-min))
79    (when (re-search-forward
80	   "<hr>\n<a href=\"\\([0-9]+\\)\\.html\">&gt;&gt;[0-9]+</a>" nil t)
81      (shimbun-header-set-references
82       header
83       (shimbun-texfaq-make-id shimbun (match-string 1))))))
84
85(provide 'sb-texfaq)
86
87;;; sb-texfaq.el ends here
88