1 ;;; sinfo.el --- sinfo to Texinfo converter
3 ;; Copyright (C) 1996,1997 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)
175 (format "@setfilename %s" fname)
177 (and (re-search-forward "@settitle{}" nil t)
179 (format "@settitle{%s}" title)
181 (and (re-search-forward "@top$" nil t)
183 (format "@top %s" title)
186 (goto-char (point-min))
187 (while (re-search-forward
188 "@DREF{\\(([^{}()]*)\\)\\([^{}]+\\)}"
190 (let ((file (buffer-substring (match-beginning 1)(match-end 1)))
191 (word (buffer-substring (match-beginning 2)(match-end 2)))
194 (re-search-forward "@end DREF")
196 (concat word " (@ref{"
197 (if (string= file "()")
202 (goto-char (point-min))
203 (while (re-search-forward
204 "@AREF{\\([^{}]*\\)}{<URL:\\([^<>()]*\\)>}\n*"
206 (let ((node (buffer-substring (match-beginning 1)(match-end 1)))
207 (url (buffer-substring (match-beginning 2)(match-end 2)))
210 (re-search-forward "@end AREF")
212 (if (string= node "()")
214 (concat "(@ref{" node "})")
217 (sinfo-filter-for-standard)
218 (goto-char (point-min))
219 (while (re-search-forward "@CONCEPT{\\([^{}]+\\)}" nil t)
220 (let ((name (buffer-substring (match-beginning 1) (match-end 1))))
221 (replace-match (format "@cindex{%s}@strong{%s}" name name)
224 (goto-char (point-min))
225 (while (search-forward "{<URL:>}" nil t)
228 (goto-char (point-min))
229 (while (search-forward "@ref{()" nil t)
230 (replace-match "@ref{")
232 (goto-char (point-min))
233 (while (re-search-forward "@cindex{\\([^}]*\\)}" nil t)
234 (let ((str (buffer-substring (match-beginning 1)(match-end 1))))
239 (if (re-search-backward
240 "@\\(chapter\\|\\(sub\\)*section\\)[ \t][^\n]*\n" nil t)
242 (goto-char (match-end 0))
245 (mapconcat (function (lambda (chr)
253 (goto-char (point-min))
254 (while (re-search-forward "{@refill}" nil t)
256 (if (= (current-column) 0)
258 ;;(fill-paragraph nil)
259 (if (looking-at "\n\n")
264 (goto-char (point-min))
265 (while (re-search-forward "@ref{\\([^}]*\\)}" nil t)
266 (let ((str (buffer-substring (match-beginning 1)(match-end 1))))
271 (mapconcat (function (lambda (chr)
279 (goto-char (point-min))
280 (while (re-search-forward "@strong{\\([^}]*\\)}" nil t)
281 (let ((str (buffer-substring (match-beginning 1)(match-end 1))))
286 (mapconcat (function (lambda (chr)
294 (texinfo-every-node-update)
295 (texinfo-all-menus-update)
296 (texinfo-all-menu-titles-update)
297 (goto-char (point-min))
300 (defun sinfo-to-html ()
302 (let* ((the-buf (current-buffer))
303 (src-name (buffer-file-name))
304 (name (file-name-non-extension src-name))
305 (dst-name (concat name ".html"))
306 (cs buffer-file-coding-system)
310 (insert-buffer the-buf)
311 (let ((sinfo-path (getenv "SINFO_PATH"))
312 (coding-system-for-read 'emacs-mule)
313 (coding-system-for-write 'emacs-mule))
315 (format "%s/dtd/%%N.dtd:%s/dtd/%%P.dtd:%s/rep/html/%%N"
316 sinfo-path sinfo-path sinfo-path))
318 (call-process-region (point-min)(point-max)
321 (format "sgmls|sgmlsasp %s"
323 sinfo-html-mapping-file)
328 (goto-char (point-min))
329 (if (and (search-forward "sgmls:" nil t)
330 (re-search-forward "line \\([0-9]+\\)" nil t)
332 (let ((line (string-to-number
333 (buffer-substring (match-beginning 1)
337 (pop-to-buffer the-buf)
340 (set-buffer-file-coding-system cs)
341 (goto-char (point-min))
343 (goto-char (point-min))
344 (if (re-search-forward "<title>" nil t)
345 (let ((p0 (match-end 0)))
346 (if (re-search-forward "</title>" nil t)
347 (let ((title (buffer-substring p0 (match-beginning 0))))
348 (when (re-search-forward "<body>" nil t)
353 (goto-char (point-min))
354 (while (re-search-forward
355 "<h[1-6]>\\([^<]+\\)\\(<a name=\"[^\"]+\">\\)</a>"
357 (let* ((p0 (match-beginning 0))
358 (p1 (match-beginning 1))
362 (h (buffer-substring (1+ (match-beginning 0)) p1))
363 (desc (buffer-substring p1 p2)))
365 (insert (concat "</" h))
368 (delete-region p1 p2)
372 (goto-char (point-min))
381 ;;; sinfo.el ends here