diff options
| author | Thien-Thi Nguyen | 2005-03-23 14:33:57 +0000 |
|---|---|---|
| committer | Thien-Thi Nguyen | 2005-03-23 14:33:57 +0000 |
| commit | 256249731ed8d41e9caf24d453b0c7c78da75dc2 (patch) | |
| tree | 4c42f7ebd5eeb82c3f8387a696e70b7926859416 | |
| parent | c22e3cd40712d40742d945721b455e7d7271fa4f (diff) | |
| download | emacs-256249731ed8d41e9caf24d453b0c7c78da75dc2.tar.gz emacs-256249731ed8d41e9caf24d453b0c7c78da75dc2.zip | |
Rewrite.
| -rw-r--r-- | vms/make-mms-derivative.el | 176 |
1 files changed, 91 insertions, 85 deletions
diff --git a/vms/make-mms-derivative.el b/vms/make-mms-derivative.el index 700822c29bd..643fe91dfda 100644 --- a/vms/make-mms-derivative.el +++ b/vms/make-mms-derivative.el | |||
| @@ -24,29 +24,48 @@ | |||
| 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) |
| @@ -54,79 +73,66 @@ | |||
| 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)))) | 83 | |
| 68 | 84 | (defun make-mms-derivative-gigo (name) | |
| 69 | (defmacro make-mms-derivative-progn (msg &rest body) | 85 | "Insert the text associated with :gigo NAME." |
| 70 | `(progn | 86 | (insert (cdr (assq name (make-mms-derivative-data :gigo))))) |
| 71 | (message "(%s) %s" (point) ,msg) | 87 | |
| 72 | ,@body)) | 88 | (defun make-mms-derivative (filename) |
| 73 | 89 | "Take FILENAME contents, load FILENAME-2mms, and write out the result. | |
| 74 | (put 'make-mms-derivative-progn 'lisp-indent-function 1) | 90 | The output file is specified by the :output directive in FILENAME-2mms. |
| 75 | 91 | See commentary of make-mms-derivative.el for full documentation." | |
| 76 | (defun make-mms-derivative-load-edits-file (name) | ||
| 77 | (make-mms-derivative-data 'edits-filename name) | ||
| 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 | ||