1 ;; Rewrite DEFVAR_LISP variables.
2 ;; Each variable is renamed to start with impl_.
3 ;; Compatibility defines are added to globals.h.
4 ;; Invoke as: emacs --script rewrite-globals.el
6 (defvar defvar-list
'())
8 (defun extract-defvars ()
9 (let ((case-fold-search nil
))
10 (while (re-search-forward "^[^#*]*\\(DEFVAR_[A-Z_]*\\)" nil
'move
)
11 (let ((kind (match-string 1)))
12 (unless (member kind
'("DEFVAR_KBOARD" "DEFVAR_PER_BUFFER"))
13 ;; Skip the paren and the first argument.
14 (skip-chars-forward " (")
16 (skip-chars-forward ", \t\n&")
17 (if (looking-at "\\_<\\(\\sw\\|\\s_\\)+\\_>")
18 (let ((var-name (match-string 0)))
19 (if (equal kind
"DEFVAR_LISP")
20 (push var-name defvar-list
)))))))))
24 (while (re-search-forward "^\\(extern \\|static \\)?Lisp_Object " nil
'move
)
25 ;; skip function decls.
26 (if (not (looking-at ".*("))
27 (while (looking-at "[a-z0-9A-Z_]+")
28 (if (member (match-string 0) defvar-list
)
30 ;; Rename them all to impl_
31 (goto-char (match-beginning 0))
34 (skip-chars-forward ", \t\n")))))
38 (defun munge-V-directory ()
39 ;; First extract all defvars.
40 (dolist (file (directory-files V-dir t
"[ch]$"))
42 (message "Scanning %s" file
)
46 (setq defvar-list
(delete-dups (sort defvar-list
#'string
<)))
48 (dolist (file (directory-files V-dir t
"[ch]$"))
50 (message "Processing %s" file
)
52 (goto-char (point-min))
56 (find-file "globals.h")
58 (dolist (v defvar-list
)
59 (insert "#define " v
" *find_variable_location (&impl_" v
")\n"))
61 ;; A few special cases for globals.h.
63 (dolist (v '("do_mouse_tracking" "Vmark_even_if_inactive" "Vprint_level"))
64 (insert "extern Lisp_Object impl_" v
";\n"))