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