1 ;;; sinfo.el --- sinfo to Texinfo converter
3 ;; Copyright (C) 1996,1997,1998 MORIOKA Tomohiko
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Version: $Id: sinfo.el,v 3.7 1997/01/31 13:46:10 morioka Exp $
7 ;; Keywords: SGML, Texinfo
9 ;; This file is part of sinfo (SGML based info system).
11 ;; This program is free software; you can redistribute it and/or
12 ;; modify it under the terms of the GNU General Public License as
13 ;; published by the Free Software Foundation; either version 2, or (at
14 ;; your option) any later version.
16 ;; This program is distributed in the hope that it will be useful, but
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ;; General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
28 ;; This program is for Emacs/mule (mule-19.33-delta) and requires
37 (defun-maybe file-name-non-extension (filename)
38 (if (string-match "\\.[^.]+$" filename)
39 (substring filename 0 (match-beginning 0))
42 (defvar sinfo-texi-mapping-file
43 "/usr/local/share/sgml/rep/sinfo/texi-mapping"
44 "*SGML mapping file to convert into Texinfo.")
46 (defvar sinfo-html-mapping-file
47 "/usr/local/share/sgml/rep/sinfo/html-mapping"
48 "*SGML mapping file to convert into HTML.")
50 (defun sinfo-texi-swap-node ()
52 (goto-char (point-min))
53 (while (re-search-forward
54 "^\\(@\\(chapter\\|\\(sub\\)*section\\) .*\\)
55 \\(@node .*\\)\n" nil t)
56 (let* ((md (match-data))
61 (replace-match (format "%s\n%s"
62 (buffer-substring nb ne)
63 (buffer-substring (match-beginning 0) nb)
67 (defun sinfo-filter-for-standard ()
68 (goto-char (point-min))
69 (while (re-search-forward
70 "@noindent\n\\[\\([^][]*\\)\\]\n@quotation\n\\([^,]*\\)," nil t)
71 (let ((name (buffer-substring (match-beginning 1)(match-end 1)))
72 (org (buffer-substring (match-beginning 2)(match-end 2)))
74 (b (match-beginning 0))
77 (and (eq (aref name 0) ?:)
78 (eq (aref name 1) ?\ )
79 (setq name (substring name 2))
82 (setq dest (concat "@noindent\n[" name "]\n" dest))
85 (setq dest (concat dest org ","))
88 (search-forward "@end quotation")
89 (narrow-to-region b (match-beginning 0))
91 (if (search-forward " (obsolete RFC )" nil t)
95 (while (search-forward "
\e$B!X!Y
\e(B" nil t)
99 (while (search-forward "``''" nil t)
103 (while (re-search-forward ",[ \t\n]*," nil t)
107 (and (re-search-forward "^,[ \t\n]*" nil t)
110 (if (search-forward ", ." nil t)
113 (goto-char (point-max))
117 (defun sinfo-to-texi ()
119 (let* ((the-buf (current-buffer))
120 (src-name (buffer-file-name))
121 (name (file-name-non-extension src-name))
122 (dst-name (concat name ".texi"))
123 (fname (concat (file-name-nondirectory name) ".info"))
124 (cs buffer-file-coding-system)
128 (insert-buffer the-buf)
129 (goto-char (point-min))
130 (while (re-search-forward "[@{}]" nil t)
131 (replace-match (concat "@" (buffer-substring (match-beginning 0)
134 (let ((sinfo-path (getenv "SINFO_PATH"))
135 (coding-system-for-read 'emacs-mule)
136 (coding-system-for-write 'emacs-mule))
138 (format "%s/dtd/%%N.dtd:%s/dtd/%%P.dtd:%s/rep/texi/%%N"
139 sinfo-path sinfo-path sinfo-path))
141 (call-process-region (point-min)(point-max)
144 (format "sgmls|sgmlsasp %s"
146 sinfo-texi-mapping-file)
151 (goto-char (point-min))
152 (if (and (search-forward "sgmls:" nil t)
153 (re-search-forward "line \\([0-9]+\\)" nil t)
155 (let ((line (string-to-number
156 (buffer-substring (match-beginning 1)
160 (pop-to-buffer the-buf)
163 (set-buffer-file-coding-system cs)
164 (sinfo-texi-swap-node)
167 (goto-char (point-min))
168 (and (re-search-forward "@title \\(.*\\)\n" nil t)
169 (buffer-substring (match-beginning 1)(match-end 1))
172 (goto-char (point-min))
173 (and (re-search-forward "@setfilename$" nil t)
176 "@c Generated automatically from %s by sinfo .
177 @setfilename %s" (file-name-nondirectory src-name) fname)
179 (and (re-search-forward "@settitle{}" nil t)
181 (format "@settitle{%s}" title)
183 (and (re-search-forward "@top$" nil t)
185 (format "@top %s" title)
188 (goto-char (point-min))
189 (while (re-search-forward
190 "@DREF{\\(([^{}()]*)\\)\\([^{}]+\\)}"
192 (let ((file (buffer-substring (match-beginning 1)(match-end 1)))
193 (word (buffer-substring (match-beginning 2)(match-end 2)))
196 (re-search-forward "@end DREF")
198 (concat word " (@ref{"
199 (if (string= file "()")
204 (goto-char (point-min))
205 (while (re-search-forward
206 "@AREF{\\([^{}]*\\)}{<URL:\\([^<>()]*\\)>}\n*"
208 (let ((node (buffer-substring (match-beginning 1)(match-end 1)))
209 (url (buffer-substring (match-beginning 2)(match-end 2)))
212 (re-search-forward "@end AREF")
214 (if (string= node "()")
216 (concat "(@ref{" node "})")
219 (sinfo-filter-for-standard)
220 (goto-char (point-min))
221 (while (re-search-forward "@CONCEPT{\\([^{}]+\\)}" nil t)
222 (let ((name (buffer-substring (match-beginning 1) (match-end 1))))
223 (replace-match (format "@cindex{%s}@strong{%s}" name name)
226 (goto-char (point-min))
227 (while (search-forward "{<URL:>}" nil t)
230 (goto-char (point-min))
231 (while (search-forward "@ref{()" nil t)
232 (replace-match "@ref{")
234 (goto-char (point-min))
235 (while (re-search-forward "@cindex{\\([^}]*\\)}" nil t)
236 (let ((str (buffer-substring (match-beginning 1)(match-end 1))))
241 (if (re-search-backward
242 "@\\(chapter\\|\\(sub\\)*section\\)[ \t][^\n]*\n" nil t)
244 (goto-char (match-end 0))
247 (mapconcat (function (lambda (chr)
255 (goto-char (point-min))
256 (while (re-search-forward "{@refill}" nil t)
258 (if (= (current-column) 0)
260 ;;(fill-paragraph nil)
261 (if (looking-at "\n\n")
266 (goto-char (point-min))
267 (while (re-search-forward "@ref{\\([^}]*\\)}" nil t)
268 (let ((str (buffer-substring (match-beginning 1)(match-end 1))))
273 (mapconcat (function (lambda (chr)
281 (goto-char (point-min))
282 (while (re-search-forward "@strong{\\([^}]*\\)}" nil t)
283 (let ((str (buffer-substring (match-beginning 1)(match-end 1))))
288 (mapconcat (function (lambda (chr)
296 (texinfo-every-node-update)
297 (texinfo-all-menus-update)
298 (texinfo-all-menu-titles-update)
299 (goto-char (point-min))
302 (defun sinfo-to-html ()
304 (let* ((the-buf (current-buffer))
305 (src-name (buffer-file-name))
306 (name (file-name-non-extension src-name))
307 (dst-name (concat name ".html"))
308 (cs buffer-file-coding-system)
312 (insert-buffer the-buf)
313 (let ((sinfo-path (getenv "SINFO_PATH"))
314 (coding-system-for-read 'emacs-mule)
315 (coding-system-for-write 'emacs-mule))
317 (format "%s/dtd/%%N.dtd:%s/dtd/%%P.dtd:%s/rep/html/%%N"
318 sinfo-path sinfo-path sinfo-path))
320 (call-process-region (point-min)(point-max)
323 (format "sgmls|sgmlsasp %s"
325 sinfo-html-mapping-file)
330 (goto-char (point-min))
331 (if (and (search-forward "sgmls:" nil t)
332 (re-search-forward "line \\([0-9]+\\)" nil t)
334 (let ((line (string-to-number
335 (buffer-substring (match-beginning 1)
339 (pop-to-buffer the-buf)
342 (set-buffer-file-coding-system cs)
343 (goto-char (point-min))
345 (goto-char (point-min))
346 (if (re-search-forward "<title>" nil t)
347 (let ((p0 (match-end 0)))
348 (if (re-search-forward "</title>" nil t)
349 (let ((title (buffer-substring p0 (match-beginning 0))))
350 (when (re-search-forward "<body>" nil t)
355 (goto-char (point-min))
356 (while (re-search-forward
357 "<h[1-6]>\\([^<]+\\)\\(<a name=\"[^\"]+\">\\)</a>"
359 (let* ((p0 (match-beginning 0))
360 (p1 (match-beginning 1))
364 (h (buffer-substring (1+ (match-beginning 0)) p1))
365 (desc (buffer-substring p1 p2)))
367 (insert (concat "</" h))
370 (delete-region p1 p2)
374 (goto-char (point-min))
383 ;;; sinfo.el ends here