annotate vms/make-mms-derivative.el @ 96250:423373db93ef

(str_to_unibyte): Extern it.
author Kenichi Handa <handa@m17n.org>
date Wed, 25 Jun 2008 02:44:43 +0000
parents 2281719c874d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
53152
a87bb25a4575 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1 ;;; make-mms-derivative.el --- framework to do horrible things for VMS support
a87bb25a4575 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
2
79729
a670de1f8013 Add 2008 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 78241
diff changeset
3 ;; Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008
a670de1f8013 Add 2008 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 78241
diff changeset
4 ;; Free Software Foundation, Inc.
53152
a87bb25a4575 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
5
a87bb25a4575 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
6 ;; Author: Thien-Thi Nguyen <ttn@gnu.org>
a87bb25a4575 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
7 ;; Keywords: maint build vms mms makefile levitte autoconf war-is-a-lose
a87bb25a4575 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
8
a87bb25a4575 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
a87bb25a4575 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
10
94709
2281719c874d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 79729
diff changeset
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
53152
a87bb25a4575 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
94709
2281719c874d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 79729
diff changeset
13 ;; the Free Software Foundation, either version 3 of the License, or
2281719c874d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 79729
diff changeset
14 ;; (at your option) any later version.
53152
a87bb25a4575 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
15
a87bb25a4575 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
a87bb25a4575 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
a87bb25a4575 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a87bb25a4575 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
19 ;; GNU General Public License for more details.
a87bb25a4575 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
20
a87bb25a4575 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
94709
2281719c874d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 79729
diff changeset
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
53152
a87bb25a4575 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
23
a87bb25a4575 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
24 ;;; Commentary:
a87bb25a4575 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
25
60854
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
26 ;; Under VMS the standard make-like program is called MMS, which looks
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
27 ;; for an input file in the default directory named DESCRIP.MMS and runs
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
28 ;; the DCL command rules therein. As of 2005, the build process
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
29 ;; requires a hand translation of the Makefile.in and Emacs-specific
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
30 ;; methodology to DCL and TPU commands, so to alleviate this pain, we
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
31 ;; provide `make-mms-derivative', which given a source FILENAME, inserts
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
32 ;; the file contents in a new buffer and loads FILENAME-2mms. The lisp
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
33 ;; code in the -2mms file can (do whatever -- it's emacs -- and), as
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
34 ;; long as it arranges to write out the modified buffer after loading by
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
35 ;; specifying, on a line of its own, the directive:
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
36 ;;
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
37 ;; :output RELATIVE-OUTPUT
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
38 ;;
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
39 ;; where RELATIVE-OUTPUT is a filename (a string) relative to FILENAME's
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
40 ;; directory, typically something simple like "descrip.mms_in_in". Only
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
41 ;; the first :output directive is recognized.
53152
a87bb25a4575 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
42 ;;
60854
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
43 ;; The only other special directive at this time has the form:
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
44 ;;
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
45 ;; :gigo NAME
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
46 ;; ;;blah blah blah
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
47 ;; ;;(more text here)
53152
a87bb25a4575 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
48 ;;
60854
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
49 ;; NAME is anything distinguishable w/ `eq' (number, symbol or keyword).
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
50 ;; This associates NAME with the block of text starting immediately below
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
51 ;; the :gigo directive and ending at the first line that does not begin
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
52 ;; with two semicolons (which are stripped from each line in the block).
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
53 ;; To insert this block of text, pass NAME to `make-mms-derivative-gigo'.
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
54 ;;
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
55 ;; Directives are scanned before normal evaluation, so their placement
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
56 ;; in the file is not important. During loading, plain strings are
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
57 ;; displayed in the echo area, prefixed with the current line number.
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
58 ;;
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
59 ;; Over the long run, the convenience functions provided (see source)
53153
95cc51c7ff64 (make-mms-derivative): Use suffix "-2mms"
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53152
diff changeset
60 ;; will be augmented by factoring maximally the -2mms files, squeezing
53152
a87bb25a4575 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
61 ;; as much algorithm out of those nasty heuristics as possible. What
a87bb25a4575 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
62 ;; makes them nasty is not that they rely on the conventions of the
a87bb25a4575 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
63 ;; Emacs makefiles; that's no big deal. What makes them nasty is that
a87bb25a4575 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
64 ;; they rely on the conventions of separately maintained tools (namely
60854
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
65 ;; Autoconf for VMS and GNU Autoconf), and the separation of conventions
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
66 ;; is how people drift apart, dragging their software behind
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
67 ;; mercilessly.
53152
a87bb25a4575 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
68 ;;
a87bb25a4575 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
69 ;; In general, codified thought w/o self-synchronization is doomed.
a87bb25a4575 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
70 ;; That a generation would eat its young (most discriminatingly, even)
a87bb25a4575 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
71 ;; is no reason GNU cannot build around such woe.
a87bb25a4575 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
72
a87bb25a4575 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
73 ;;; Code:
a87bb25a4575 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
74
a87bb25a4575 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
75 (defvar make-mms-derivative-data nil
60854
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
76 "Plist of data specific to `make-mms-derivative'.")
53152
a87bb25a4575 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
77
a87bb25a4575 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
78 (defun make-mms-derivative-data (key &optional newval)
60854
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
79 (if newval (setq make-mms-derivative-data
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
80 (plist-put make-mms-derivative-data key newval))
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
81 (plist-get make-mms-derivative-data key)))
53152
a87bb25a4575 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
82
60854
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
83 (defun make-mms-derivative-gigo (name)
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
84 "Insert the text associated with :gigo NAME."
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
85 (insert (cdr (assq name (make-mms-derivative-data :gigo)))))
53152
a87bb25a4575 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
86
60854
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
87 (defun make-mms-derivative (filename)
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
88 "Take FILENAME contents, load FILENAME-2mms, and write out the result.
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
89 The output file is specified by the :output directive in FILENAME-2mms.
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
90 See commentary of make-mms-derivative.el for full documentation."
53152
a87bb25a4575 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
91 (interactive "fSource File: ")
60854
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
92 (let* ((todo (let ((fn (concat filename "-2mms")))
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
93 (unless (file-exists-p fn)
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
94 (error "Could not find %s" fn))
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
95 (set-buffer (get-buffer-create " *make-mms-derivative todo*"))
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
96 (insert-file-contents fn)
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
97 (current-buffer)))
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
98 (deriv (get-buffer-create (format "*mms-derivative: %s"
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
99 (file-relative-name filename))))
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
100 output gigo form)
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
101 (set-buffer todo)
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
102 (re-search-forward "^:output")
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
103 (setq output (expand-file-name (read (current-buffer))
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
104 (file-name-directory filename)))
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
105 (goto-char (point-min))
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
106 (while (re-search-forward "^:gigo" (point-max) t)
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
107 (let ((name (read (current-buffer)))
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
108 (p (progn (forward-line 1) (point))))
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
109 (while (looking-at ";;")
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
110 (delete-char 2)
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
111 (forward-line 1))
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
112 (setq gigo (cons (cons name (buffer-substring p (point))) gigo))
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
113 (delete-region p (point))))
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
114 (message "Munging...")
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
115 (switch-to-buffer deriv)
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
116 (erase-buffer)
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
117 (insert-file-contents filename)
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
118 (set (make-local-variable 'make-mms-derivative-data)
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
119 (list :gigo gigo))
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
120 (set-buffer todo)
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
121 (goto-char (point-min))
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
122 (while (condition-case nil
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
123 (setq form (read (current-buffer)))
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
124 (end-of-file nil))
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
125 (if (stringp form)
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
126 (message "%d: %s" (count-lines (point-min) (point)) form)
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
127 (save-excursion
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
128 (set-buffer deriv)
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
129 (eval form))))
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
130 (set-buffer deriv)
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
131 (message "Munging...done")
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
132 (write-file output)
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
133 (kill-buffer todo)
6c3c9561257e Rewrite.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 60814
diff changeset
134 (kill-buffer deriv)))
53152
a87bb25a4575 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
135
a87bb25a4575 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
136 (provide 'make-mms-derivative)
a87bb25a4575 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
137
94709
2281719c874d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 79729
diff changeset
138 ;; arch-tag: a5b08625-3952-4053-be16-296220e27bb0
53152
a87bb25a4575 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
139 ;;; make-mms-derivative.el ends here