1 ;;; sinfo.el --- sinfo to Texinfo converter
3 ;; Copyright (C) 1996,1997,1998 MORIOKA Tomohiko
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Keywords: SGML, Texinfo
8 ;; This file is part of sinfo (SGML based info system).
10 ;; This program is free software; you can redistribute it and/or
11 ;; modify it under the terms of the GNU General Public License as
12 ;; published by the Free Software Foundation; either version 2, or (at
13 ;; your option) any later version.
15 ;; This program is distributed in the hope that it will be useful, but
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ;; General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
27 ;; This program is for Emacs/mule (mule-19.33-delta) and requires
36 (defun-maybe file-name-non-extension (filename)
37 (if (string-match "\\.[^.]+$" filename)
38 (substring filename 0 (match-beginning 0))
41 (defvar sinfo-texi-mapping-file
42 "/usr/local/share/sgml/rep/sinfo/texi-mapping"
43 "*SGML mapping file to convert into Texinfo.")
45 (defvar sinfo-html-mapping-file
46 "/usr/local/share/sgml/rep/sinfo/html-mapping"
47 "*SGML mapping file to convert into HTML.")
49 (defun sinfo-texi-swap-node ()
51 (goto-char (point-min))
52 (while (re-search-forward
53 "^\\(@\\(chapter\\|\\(sub\\)*section\\) .*\\)
54 \\(@node .*\\)\n" nil t)
55 (let* ((md (match-data))
60 (replace-match (format "%s\n%s"
61 (buffer-substring nb ne)
62 (buffer-substring (match-beginning 0) nb)
66 (defun sinfo-filter-for-standard ()
67 (goto-char (point-min))
68 (while (re-search-forward
69 "@noindent\n\\[\\([^][]*\\)\\]\n@quotation\n\\([^,]*\\)," nil t)
70 (let ((name (buffer-substring (match-beginning 1)(match-end 1)))
71 (org (buffer-substring (match-beginning 2)(match-end 2)))
73 (b (match-beginning 0))
76 (and (eq (aref name 0) ?:)
77 (eq (aref name 1) ?\ )
78 (setq name (substring name 2))
81 (setq dest (concat "@noindent\n[" name "]\n" dest))
84 (setq dest (concat dest org ","))
87 (search-forward "@end quotation")
88 (narrow-to-region b (match-beginning 0))
90 (if (search-forward " (obsolete RFC )" nil t)
94 (while (search-forward "
\e$B!X!Y
\e(B" nil t)
98 (while (search-forward "``''" nil t)
102 (while (re-search-forward ",[ \t\n]*," nil t)
106 (and (re-search-forward "^,[ \t\n]*" nil t)
109 (if (search-forward ", ." nil t)
112 (goto-char (point-max))
116 (defun sinfo-to-texi ()
118 (let* ((the-buf (current-buffer))
119 (src-name (buffer-file-name))
120 (name (file-name-non-extension src-name))
121 (dst-name (concat name ".texi"))
122 (fname (concat (file-name-nondirectory name) ".info"))
123 (cs buffer-file-coding-system)
127 (insert-buffer the-buf)
128 (goto-char (point-min))
129 (while (re-search-forward "[@{}]" nil t)
130 (replace-match (concat "@" (buffer-substring (match-beginning 0)
133 (let ((sinfo-path (getenv "SINFO_PATH"))
134 (coding-system-for-read 'emacs-mule)
135 (coding-system-for-write 'emacs-mule))
137 (format "%s/dtd/%%N.dtd:%s/dtd/%%P.dtd:%s/rep/texi/%%N"
138 sinfo-path sinfo-path sinfo-path))
140 (call-process-region (point-min)(point-max)
143 (format "sgmls|sgmlsasp %s"
145 sinfo-texi-mapping-file)
150 (goto-char (point-min))
151 (if (and (search-forward "sgmls:" nil t)
152 (re-search-forward "line \\([0-9]+\\)" nil t)
154 (let ((line (string-to-number
155 (buffer-substring (match-beginning 1)
159 (pop-to-buffer the-buf)
162 (set-buffer-file-coding-system cs)
163 (sinfo-texi-swap-node)
166 (goto-char (point-min))
167 (and (re-search-forward "@title \\(.*\\)\n" nil t)
168 (buffer-substring (match-beginning 1)(match-end 1))
171 (goto-char (point-min))
172 (and (re-search-forward "@setfilename$" nil t)
175 "@c Generated automatically from %s by sinfo 3.7.
176 @setfilename %s" (file-name-nondirectory src-name) fname)
178 (and (re-search-forward "@settitle{}" nil t)
180 (format "@settitle{%s}" title)
182 (and (re-search-forward "@top$" nil t)
184 (format "@top %s" title)
187 (goto-char (point-min))
188 (while (re-search-forward
189 "@DREF{\\(([^{}()]*)\\)\\([^{}]+\\)}"
191 (let ((file (buffer-substring (match-beginning 1)(match-end 1)))
192 (word (buffer-substring (match-beginning 2)(match-end 2)))
195 (re-search-forward "@end DREF")
197 (concat word " (@ref{"
198 (if (string= file "()")
203 (goto-char (point-min))
204 (while (re-search-forward
205 "@AREF{\\([^{}]*\\)}{<URL:\\([^<>()]*\\)>}\n*"
207 (let ((node (buffer-substring (match-beginning 1)(match-end 1)))
208 (url (buffer-substring (match-beginning 2)(match-end 2)))
211 (re-search-forward "@end AREF")
213 (if (string= node "()")
215 (concat "(@ref{" node "})")
218 (sinfo-filter-for-standard)
219 (goto-char (point-min))
220 (while (re-search-forward "@CONCEPT{\\([^{}]+\\)}" nil t)
221 (let ((name (buffer-substring (match-beginning 1) (match-end 1))))
222 (replace-match (format "@cindex{%s}@strong{%s}" name name)
225 (goto-char (point-min))
226 (while (search-forward "{<URL:>}" nil t)
229 (goto-char (point-min))
230 (while (search-forward "@ref{()" nil t)
231 (replace-match "@ref{")
233 (goto-char (point-min))
234 (while (re-search-forward "@cindex{\\([^}]*\\)}" nil t)
235 (let ((str (buffer-substring (match-beginning 1)(match-end 1))))
240 (if (re-search-backward
241 "@\\(chapter\\|\\(sub\\)*section\\)[ \t][^\n]*\n" nil t)
243 (goto-char (match-end 0))
246 (mapconcat (function (lambda (chr)
254 (goto-char (point-min))
255 (while (re-search-forward "{@refill}" nil t)
257 (if (= (current-column) 0)
259 ;;(fill-paragraph nil)
260 (if (looking-at "\n\n")
265 (goto-char (point-min))
266 (while (re-search-forward "@ref{\\([^}]*\\)}" nil t)
267 (let ((str (buffer-substring (match-beginning 1)(match-end 1))))
272 (mapconcat (function (lambda (chr)
280 (goto-char (point-min))
281 (while (re-search-forward "@strong{\\([^}]*\\)}" nil t)
282 (let ((str (buffer-substring (match-beginning 1)(match-end 1))))
287 (mapconcat (function (lambda (chr)
295 (texinfo-every-node-update)
296 (texinfo-all-menus-update)
297 (texinfo-all-menu-titles-update)
298 (goto-char (point-min))
301 (defun sinfo-to-html ()
303 (let* ((the-buf (current-buffer))
304 (src-name (buffer-file-name))
305 (name (file-name-non-extension src-name))
306 (dst-name (concat name ".html"))
307 (cs buffer-file-coding-system)
311 (insert-buffer the-buf)
312 (let ((sinfo-path (getenv "SINFO_PATH"))
313 (coding-system-for-read 'emacs-mule)
314 (coding-system-for-write 'emacs-mule))
316 (format "%s/dtd/%%N.dtd:%s/dtd/%%P.dtd:%s/rep/html/%%N"
317 sinfo-path sinfo-path sinfo-path))
319 (call-process-region (point-min)(point-max)
322 (format "sgmls|sgmlsasp %s"
324 sinfo-html-mapping-file)
329 (goto-char (point-min))
330 (if (and (search-forward "sgmls:" nil t)
331 (re-search-forward "line \\([0-9]+\\)" nil t)
333 (let ((line (string-to-number
334 (buffer-substring (match-beginning 1)
338 (pop-to-buffer the-buf)
341 (set-buffer-file-coding-system cs)
342 (goto-char (point-min))
344 (goto-char (point-min))
345 (if (re-search-forward "<title>" nil t)
346 (let ((p0 (match-end 0)))
347 (if (re-search-forward "</title>" nil t)
348 (let ((title (buffer-substring p0 (match-beginning 0))))
349 (when (re-search-forward "<body>" nil t)
354 (goto-char (point-min))
355 (while (re-search-forward
356 "<h[1-6]>\\([^<]+\\)\\(<a name=\"[^\"]+\">\\)</a>"
358 (let* ((p0 (match-beginning 0))
359 (p1 (match-beginning 1))
363 (h (buffer-substring (1+ (match-beginning 0)) p1))
364 (desc (buffer-substring p1 p2)))
366 (insert (concat "</" h))
369 (delete-region p1 p2)
373 (goto-char (point-min))
382 ;;; sinfo.el ends here