Mercurial > emacs
comparison vms/make-mms-derivative.el @ 60854:6c3c9561257e
Rewrite.
author | Thien-Thi Nguyen <ttn@gnuvola.org> |
---|---|
date | Wed, 23 Mar 2005 14:33:57 +0000 |
parents | a9ece659b645 |
children | 23a17af379b1 13796b0653c7 |
comparison
equal
deleted
inserted
replaced
60853:53a24edea9ee | 60854:6c3c9561257e |
---|---|
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
23 ;; Boston, MA 02111-1307, USA. | 23 ;; Boston, MA 02111-1307, USA. |
24 | 24 |
25 ;;; Commentary: | 25 ;;; Commentary: |
26 | 26 |
27 ;; Under OpenVMS the standard make-like program is called MMS, which | 27 ;; Under VMS the standard make-like program is called MMS, which looks |
28 ;; looks for an input file in the default directory named DESCRIP.MMS | 28 ;; for an input file in the default directory named DESCRIP.MMS and runs |
29 ;; and runs the DCL command rules therein. As of 2005, the build | 29 ;; the DCL command rules therein. As of 2005, the build process |
30 ;; process requires a hand translation of the Makefile.in and related | 30 ;; requires a hand translation of the Makefile.in and Emacs-specific |
31 ;; Emacs-specific methodology to DCL and TPU commands, so to alleviate | 31 ;; methodology to DCL and TPU commands, so to alleviate this pain, we |
32 ;; this pain, we provide `make-mms-derivative', which given a source | 32 ;; provide `make-mms-derivative', which given a source FILENAME, inserts |
33 ;; FILENAME (under `make-mms-derivative-root-dir'), inserts the file | 33 ;; the file contents in a new buffer and loads FILENAME-2mms. The lisp |
34 ;; contents in a new buffer and loads FILENAME-2mms. The elisp in the | 34 ;; code in the -2mms file can (do whatever -- it's emacs -- and), as |
35 ;; -2mms file can (do whatever -- it's emacs -- and) arrange to write | 35 ;; long as it arranges to write out the modified buffer after loading by |
36 ;; out the modified buffer after FILENAME-2mms loading by using: | 36 ;; specifying, on a line of its own, the directive: |
37 ;; | 37 ;; |
38 ;; (make-mms-derivative-data 'write-under-root RELATIVE-FILENAME) | 38 ;; :output RELATIVE-OUTPUT |
39 ;; | 39 ;; |
40 ;; where RELATIVE-FILENAME is something like "src/descrip.mms_in_in". | 40 ;; where RELATIVE-OUTPUT is a filename (a string) relative to FILENAME's |
41 ;; Over the long run, the convenience procedures provided (see source) | 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) | |
42 ;; will be augmented by factoring maximally the -2mms files, squeezing | 61 ;; will be augmented by factoring maximally the -2mms files, squeezing |
43 ;; as much algorithm out of those nasty heuristics as possible. What | 62 ;; as much algorithm out of those nasty heuristics as possible. What |
44 ;; makes them nasty is not that they rely on the conventions of the | 63 ;; makes them nasty is not that they rely on the conventions of the |
45 ;; Emacs makefiles; that's no big deal. What makes them nasty is that | 64 ;; Emacs makefiles; that's no big deal. What makes them nasty is that |
46 ;; they rely on the conventions of separately maintained tools (namely | 65 ;; they rely on the conventions of separately maintained tools (namely |
47 ;; Autoconf 1.11 under OpenVMS and the rest of GNU), and the separation | 66 ;; Autoconf for VMS and GNU Autoconf), and the separation of conventions |
48 ;; of conventions is how people drift apart, dragging their software | 67 ;; is how people drift apart, dragging their software behind |
49 ;; behind mercilessly. | 68 ;; mercilessly. |
50 ;; | 69 ;; |
51 ;; In general, codified thought w/o self-synchronization is doomed. | 70 ;; In general, codified thought w/o self-synchronization is doomed. |
52 ;; That a generation would eat its young (most discriminatingly, even) | 71 ;; That a generation would eat its young (most discriminatingly, even) |
53 ;; is no reason GNU cannot build around such woe. | 72 ;; is no reason GNU cannot build around such woe. |
54 | 73 |
55 ;;; Code: | 74 ;;; Code: |
56 | 75 |
57 (defvar make-mms-derivative-root-dir "AXPA:[TTN.EMACS.EMACS212_3]" | |
58 "Source tree root directory.") | |
59 | |
60 (defvar make-mms-derivative-data nil | 76 (defvar make-mms-derivative-data nil |
61 "Alist of data specific to `make-mms-derivative'.") | 77 "Plist of data specific to `make-mms-derivative'.") |
62 | 78 |
63 (defun make-mms-derivative-data (key &optional newval) | 79 (defun make-mms-derivative-data (key &optional newval) |
64 (if newval | 80 (if newval (setq make-mms-derivative-data |
65 (setq make-mms-derivative-data | 81 (plist-put make-mms-derivative-data key newval)) |
66 (cons (cons key newval) make-mms-derivative-data)) | 82 (plist-get make-mms-derivative-data key))) |
67 (cdr (assq key make-mms-derivative-data)))) | |
68 | 83 |
69 (defmacro make-mms-derivative-progn (msg &rest body) | 84 (defun make-mms-derivative-gigo (name) |
70 `(progn | 85 "Insert the text associated with :gigo NAME." |
71 (message "(%s) %s" (point) ,msg) | 86 (insert (cdr (assq name (make-mms-derivative-data :gigo))))) |
72 ,@body)) | |
73 | 87 |
74 (put 'make-mms-derivative-progn 'lisp-indent-function 1) | 88 (defun make-mms-derivative (filename) |
75 | 89 "Take FILENAME contents, load FILENAME-2mms, and write out the result. |
76 (defun make-mms-derivative-load-edits-file (name) | 90 The output file is specified by the :output directive in FILENAME-2mms. |
77 (make-mms-derivative-data 'edits-filename name) | 91 See commentary of make-mms-derivative.el for full documentation." |
78 (let (raw-data | |
79 (cur (current-buffer)) | |
80 (wbuf (get-buffer-create "*make-mms-derivative-load-edits-file work"))) | |
81 (set-buffer wbuf) | |
82 (insert-file-contents name) | |
83 (keep-lines "^;;;[0-9]+;;") | |
84 (goto-char (point-max)) | |
85 (while (re-search-backward "^;;;\\([0-9]+\\);;\\(.*\\)$" (point-min) t) | |
86 (let* ((i (string-to-number (match-string 1))) | |
87 (line (match-string 2)) | |
88 (look (assq i raw-data))) | |
89 (if look | |
90 (setcdr look (cons line (cdr look))) | |
91 (setq raw-data (cons (list i line) raw-data))))) | |
92 (kill-buffer wbuf) | |
93 (set-buffer cur) | |
94 (mapcar (lambda (ent) | |
95 (setcdr ent (mapconcat (lambda (line) | |
96 (concat line "\n")) | |
97 (cdr ent) | |
98 ""))) | |
99 raw-data) | |
100 (make-mms-derivative-data 'raw-data raw-data)) | |
101 (load name)) | |
102 | |
103 (defun make-mms-derivative-insert-raw-data (n) | |
104 (insert (cdr (assq n (make-mms-derivative-data 'raw-data))))) | |
105 | |
106 (defun make-mms-derivative (file) | |
107 (interactive "fSource File: ") | 92 (interactive "fSource File: ") |
108 (let ((root (expand-file-name make-mms-derivative-root-dir)) | 93 (let* ((todo (let ((fn (concat filename "-2mms"))) |
109 (file (expand-file-name file))) | 94 (unless (file-exists-p fn) |
110 (when (file-name-absolute-p (file-relative-name file root)) | 95 (error "Could not find %s" fn)) |
111 (error "Not under root (%s)" root)) | 96 (set-buffer (get-buffer-create " *make-mms-derivative todo*")) |
112 (let ((edits-filename (concat file "-2mms"))) | 97 (insert-file-contents fn) |
113 (unless (file-exists-p edits-filename) | 98 (current-buffer))) |
114 (error "Could not find %s" edits-filename)) | 99 (deriv (get-buffer-create (format "*mms-derivative: %s" |
115 (let ((buf (get-buffer-create | 100 (file-relative-name filename)))) |
116 (format "*mms-derivative: %s" | 101 output gigo form) |
117 (file-relative-name file root))))) | 102 (set-buffer todo) |
118 (message "Munging ...") | 103 (re-search-forward "^:output") |
119 (switch-to-buffer buf) | 104 (setq output (expand-file-name (read (current-buffer)) |
120 (erase-buffer) | 105 (file-name-directory filename))) |
121 (make-variable-buffer-local 'make-mms-derivative-data) | 106 (goto-char (point-min)) |
122 (insert-file file) | 107 (while (re-search-forward "^:gigo" (point-max) t) |
123 (make-mms-derivative-load-edits-file edits-filename) | 108 (let ((name (read (current-buffer))) |
124 (let ((out (make-mms-derivative-data 'write-under-root))) | 109 (p (progn (forward-line 1) (point)))) |
125 (when out | 110 (while (looking-at ";;") |
126 (write-file | 111 (delete-char 2) |
127 (expand-file-name rel-filename make-mms-derivative-root-dir))) | 112 (forward-line 1)) |
128 (kill-buffer buf) | 113 (setq gigo (cons (cons name (buffer-substring p (point))) gigo)) |
129 (unless out (message "Munging ... done"))))))) | 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))) | |
130 | 136 |
131 (provide 'make-mms-derivative) | 137 (provide 'make-mms-derivative) |
132 | 138 |
133 ;;; arch-tag: a5b08625-3952-4053-be16-296220e27bb0 | 139 ;;; arch-tag: a5b08625-3952-4053-be16-296220e27bb0 |
134 ;;; make-mms-derivative.el ends here | 140 ;;; make-mms-derivative.el ends here |