aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--etc/NEWS34
-rw-r--r--lib-src/ChangeLog10
-rwxr-xr-xlib-src/rcs2log26
-rw-r--r--lisp/ChangeLog48
-rw-r--r--lisp/cus-edit.el3
-rw-r--r--lisp/ffap.el2
-rw-r--r--lisp/ido.el119
-rw-r--r--lisp/jka-compr.el9
-rw-r--r--lisp/ls-lisp.el21
-rw-r--r--lisp/textmodes/texnfo-upd.el39
-rw-r--r--lisp/wid-edit.el110
-rw-r--r--lispref/ChangeLog50
-rw-r--r--lispref/commands.texi10
-rw-r--r--lispref/customize.texi73
-rw-r--r--lispref/display.texi7
-rw-r--r--lispref/eval.texi58
-rw-r--r--lispref/help.texi1
-rw-r--r--lispref/internals.texi30
-rw-r--r--lispref/loading.texi3
-rw-r--r--lispref/nonascii.texi228
-rw-r--r--lispref/objects.texi4
-rw-r--r--lispref/processes.texi1
-rw-r--r--lispref/tips.texi1
-rw-r--r--lispref/variables.texi47
-rw-r--r--src/ChangeLog91
-rw-r--r--src/Makefile.in2
-rw-r--r--src/composite.c7
-rw-r--r--src/dired.c27
-rw-r--r--src/dispextern.h9
-rw-r--r--src/dispnew.c51
-rw-r--r--src/keyboard.c30
-rw-r--r--src/lisp.h5
-rw-r--r--src/macfns.c9
-rw-r--r--src/macterm.c2
-rw-r--r--src/minibuf.c24
-rw-r--r--src/regex.c6335
-rw-r--r--src/regex.h576
-rw-r--r--src/termcap.c46
-rw-r--r--src/w32fns.c9
-rw-r--r--src/w32menu.c1
-rw-r--r--src/w32term.c2
-rw-r--r--src/xdisp.c449
-rw-r--r--src/xfaces.c19
-rw-r--r--src/xfns.c10
-rw-r--r--src/xmenu.c4
-rw-r--r--src/xterm.c22
46 files changed, 8291 insertions, 373 deletions
diff --git a/etc/NEWS b/etc/NEWS
index c4e9291c5ae..13a8b93dc0f 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1740,6 +1740,40 @@ return value of `get-char-property' called with those arguments and
1740whose cdr is the overlay in which the property was found, or nil if 1740whose cdr is the overlay in which the property was found, or nil if
1741it was found as a text property or not found at all. 1741it was found as a text property or not found at all.
1742 1742
1743** The mouse pointer shape in void text areas (i.e. after the end of a
1744line or below the last line in the buffer) of the text window is now
1745controlled by the new variable `void-text-area-pointer'. The default
1746is to use the `arrow' (non-text) pointer. Other choices are `text'
1747(or nil), `hand', `vdrag', `hdrag', `modeline', and `hourglass'.
1748
1749** The mouse pointer shape over an image can now be controlled by the
1750:pointer image property.
1751
1752** The mouse pointer shape over ordinary text or images may now be
1753controlled/overriden via the `pointer' text property.
1754
1755** Images may now have an associated image map via the :map property.
1756
1757An image map is an alist where each element has the format (AREA ID PLIST).
1758An AREA is specified as either a rectangle, a circle, or a polygon:
1759A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
1760pixel coordinates of the upper left and bottom right corners.
1761A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
1762and the radius of the circle; r may be a float or integer.
1763A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
1764vector describes one corner in the polygon.
1765
1766When the mouse pointer is above a hot-spot area of an image, the
1767PLIST of that hot-spot is consulted; if it contains a `help-echo'
1768property it defines a tool-tip for the hot-spot, and if it contains
1769a `pointer' property, it defines the shape of the mouse cursor when
1770it is over the hot-spot. See the variable 'void-area-text-pointer'
1771for possible pointer shapes.
1772
1773When you click the mouse when the mouse pointer is over a hot-spot,
1774an event is composed by combining the ID of the hot-spot with the
1775mouse event, e.g. [area4 mouse-1] if the hot-spot's ID is `area4'.
1776
1743** Mouse event enhancements: 1777** Mouse event enhancements:
1744 1778
1745*** Mouse clicks on fringes now generates left-fringe or right-fringes 1779*** Mouse clicks on fringes now generates left-fringe or right-fringes
diff --git a/lib-src/ChangeLog b/lib-src/ChangeLog
index 1a0774e7e57..542761fda2f 100644
--- a/lib-src/ChangeLog
+++ b/lib-src/ChangeLog
@@ -1,3 +1,11 @@
12003-12-27 Paul Eggert <eggert@twinsun.com>
2
3 * rcs2log (rlog_options): Append -rbranchtag if CVS/Tag indicates
4 a tag, and if the user has not specified an rlog option.
5 Adapted from a suggestion by Martin Stjernholm in
6 <http://mail.gnu.org/archive/html/bug-gnu-emacs/2003-07/msg00066.html>.
7 (Copyright): Update to 2003.
8
12003-12-24 Thien-Thi Nguyen <ttn@gnu.org> 92003-12-24 Thien-Thi Nguyen <ttn@gnu.org>
2 10
3 * make-docfile.c (main): For return code, no longer special-case VMS. 11 * make-docfile.c (main): For return code, no longer special-case VMS.
@@ -5461,7 +5469,7 @@ Tue Jul 1 01:09:07 1997 Geoff Voelker <voelker@cs.washington.edu>
5461;; coding: iso-2022-7bit 5469;; coding: iso-2022-7bit
5462;; End: 5470;; End:
5463 5471
5464 Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2001, 2002 5472 Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2001, 2002, 2003
5465 Free Software Foundation, Inc. 5473 Free Software Foundation, Inc.
5466 Copying and distribution of this file, with or without modification, 5474 Copying and distribution of this file, with or without modification,
5467 are permitted provided the copyright notice and this notice are preserved. 5475 are permitted provided the copyright notice and this notice are preserved.
diff --git a/lib-src/rcs2log b/lib-src/rcs2log
index f3773e48766..4400fb72578 100755
--- a/lib-src/rcs2log
+++ b/lib-src/rcs2log
@@ -29,9 +29,9 @@ Options:
29 29
30Report bugs to <bug-gnu-emacs@gnu.org>.' 30Report bugs to <bug-gnu-emacs@gnu.org>.'
31 31
32Id='$Id: rcs2log,v 1.51 2003/09/01 15:45:03 miles Exp $' 32Id='$Id: rcs2log,v 1.52 2003/12/27 08:18:08 uid65632 Exp $'
33 33
34# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2001, 2002 34# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2001, 2002, 2003
35# Free Software Foundation, Inc. 35# Free Software Foundation, Inc.
36 36
37# This program is free software; you can redistribute it and/or modify 37# This program is free software; you can redistribute it and/or modify
@@ -49,7 +49,7 @@ Id='$Id: rcs2log,v 1.51 2003/09/01 15:45:03 miles Exp $'
49# Free Software Foundation, Inc., 59 Temple Place - Suite 330, 49# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
50# Boston, MA 02111-1307, USA. 50# Boston, MA 02111-1307, USA.
51 51
52Copyright='Copyright (C) 2002 Free Software Foundation, Inc. 52Copyright='Copyright (C) 2003 Free Software Foundation, Inc.
53This program comes with NO WARRANTY, to the extent permitted by law. 53This program comes with NO WARRANTY, to the extent permitted by law.
54You may redistribute copies of this program 54You may redistribute copies of this program
55under the terms of the GNU General Public License. 55under the terms of the GNU General Public License.
@@ -195,8 +195,9 @@ case $rlogfile in
195 195
196 # If no rlog options are given, 196 # If no rlog options are given,
197 # log the revisions checked in since the first ChangeLog entry. 197 # log the revisions checked in since the first ChangeLog entry.
198 # Since ChangeLog is only by date, some of these revisions may be duplicates of 198 # Since ChangeLog is only by date, some of these revisions may be
199 # what's already in ChangeLog; it's the user's responsibility to remove them. 199 # duplicates of what's already in ChangeLog; it's the user's
200 # responsibility to remove them.
200 case $rlog_options in 201 case $rlog_options in
201 '') 202 '')
202 if test -s "$changelog" 203 if test -s "$changelog"
@@ -281,6 +282,21 @@ case $rlogfile in
281 esac 282 esac
282 done 283 done
283 284
285 # If no rlog options are given, and if we are in a tagged CVS branch,
286 # log only the changes in that branch.
287 case $rlog_options in
288 '')
289 if test -f CVS/Tag
290 then
291 CVSTAG=`cat <CVS/Tag` || exit
292 case $CVSTAG in
293 T?*)
294 rlog_options=-r`expr "$CVSTAG" : 'T\(.*\)'`;;
295 *)
296 echo >&2 "$0: invalid CVS/Tag"; exit 1;;
297 esac
298 fi;;
299 esac
284 fi 300 fi
285 301
286 # Use $rlog's -zLT option, if $rlog supports it. 302 # Use $rlog's -zLT option, if $rlog supports it.
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 5c667e0b353..c737c003eb9 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,34 @@
12003-12-27 Kim F. Storm <storm@cua.dk>
2
3 * ido.el: Handle non-readable directories.
4 (ido-decorations): Add 9th element for non-readable directory.
5 (ido-directory-nonreadable): New dynamic var.
6 (ido-set-current-directory): Set it.
7 (ido-read-buffer, ido-file-internal):
8 (ido-read-file-name, ido-read-directory-name): Let-bind it.
9 (ido-file-name-all-completions1): Return empty list for
10 non-readable directory.
11 (ido-exhibit): Print [Not readable] if directory is not readable.
12 (ido-expand-directory): New defun (based on tiny fix from Karl Chen).
13 (ido-read-file-name, ido-file-internal, ido-read-directory-name):
14 Use it.
15
162003-12-27 Lars Hansen <larsh@math.ku.dk>
17
18 * ls-lisp.el (ls-lisp-insert-directory): Add parameter 'string in
19 calls to directory-files-and-attributes and file-attributes.
20 (ls-lisp-format): Remove system dependent handling of user and
21 group id's.
22
232003-12-25 Luc Teirlinck <teirllm@auburn.edu>
24
25 * ffap.el (ffap-read-file-or-url): Revert previous change.
26
272003-12-25 Andreas Schwab <schwab@suse.de>
28
29 * jka-compr.el (jka-compr-insert-file-contents): Avoid error when
30 file not found.
31
12003-12-08 Miles Bader <miles@gnu.org> 322003-12-08 Miles Bader <miles@gnu.org>
2 33
3 * dired.el (dired-between-files): Always use dired-move-to-filename, 34 * dired.el (dired-between-files): Always use dired-move-to-filename,
@@ -67,6 +98,23 @@
67 * info.el (Info-unescape-quotes, Info-split-parameter-string) 98 * info.el (Info-unescape-quotes, Info-split-parameter-string)
68 (Info-goto-emacs-command-node): Doc fixes. 99 (Info-goto-emacs-command-node): Doc fixes.
69 100
1012003-12-12 Jesper Harder <harder@ifa.au.dk>
102
103 * cus-edit.el (custom-add-parent-links): Define "many".
104
1052003-12-08 Per Abrahamsen <abraham@dina.kvl.dk>
106
107 * wid-edit.el (widget-child-value-get, widget-child-value-inline)
108 (widget-child-validate, widget-type-value-create)
109 (widget-type-default-get, widget-type-match): New functions.
110 (lazy): New widget.
111 (menu-choice, checklist, radio-button-choice, editable-list)
112 (group, documentation-string): Removed redundant (per 2003-10-25
113 change) calls to `widget-children-value-delete'.
114 (widget-choice-value-get, widget-choice-value-inline): Removed
115 functions.
116 (menu-choice): Updated widget.
117
702003-12-03 Kenichi Handa <handa@m17n.org> 1182003-12-03 Kenichi Handa <handa@m17n.org>
71 119
72 * language/cyrillic.el: Register "microsoft-cp1251" in 120 * language/cyrillic.el: Register "microsoft-cp1251" in
diff --git a/lisp/cus-edit.el b/lisp/cus-edit.el
index bf92e8df9cf..fc5e7ecb8af 100644
--- a/lisp/cus-edit.el
+++ b/lisp/cus-edit.el
@@ -1970,7 +1970,8 @@ If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
1970 (setq parents (cons symbol parents)))))) 1970 (setq parents (cons symbol parents))))))
1971 (and (null (get symbol 'custom-links)) ;No links of its own. 1971 (and (null (get symbol 'custom-links)) ;No links of its own.
1972 (= (length parents) 1) ;A single parent. 1972 (= (length parents) 1) ;A single parent.
1973 (let ((links (get (car parents) 'custom-links))) 1973 (let* ((links (get (car parents) 'custom-links))
1974 (many (> (length links) 2)))
1974 (when links 1975 (when links
1975 (insert "\nParent documentation: ") 1976 (insert "\nParent documentation: ")
1976 (while links 1977 (while links
diff --git a/lisp/ffap.el b/lisp/ffap.el
index b249ce8daa0..668700a5c1f 100644
--- a/lisp/ffap.el
+++ b/lisp/ffap.el
@@ -1216,7 +1216,7 @@ which may actually result in an url rather than a filename."
1216 'ffap-read-file-or-url-internal 1216 'ffap-read-file-or-url-internal
1217 dir 1217 dir
1218 nil 1218 nil
1219 (if dir (cons guess (1+ (length dir))) guess) 1219 (if dir (cons guess (length dir)) guess)
1220 (list 'file-name-history)))) 1220 (list 'file-name-history))))
1221 ;; Do file substitution like (interactive "F"), suggested by MCOOK. 1221 ;; Do file substitution like (interactive "F"), suggested by MCOOK.
1222 (or (ffap-url-p guess) (setq guess (substitute-in-file-name guess))) 1222 (or (ffap-url-p guess) (setq guess (substitute-in-file-name guess)))
diff --git a/lisp/ido.el b/lisp/ido.el
index 57736ae7d26..165142ea222 100644
--- a/lisp/ido.el
+++ b/lisp/ido.el
@@ -685,16 +685,17 @@ Obsolete. Set 3rd element of `ido-decorations' instead."
685 :type '(choice string (const nil)) 685 :type '(choice string (const nil))
686 :group 'ido) 686 :group 'ido)
687 687
688(defcustom ido-decorations '( "{" "}" " | " " | ..." "[" "]" " [No match]" " [Matched]") 688(defcustom ido-decorations '( "{" "}" " | " " | ..." "[" "]" " [No match]" " [Matched]" " [Not readable]")
689 "*List of strings used by ido to display the alternatives in the minibuffer. 689 "*List of strings used by ido to display the alternatives in the minibuffer.
690There are 8 elements in this list, each is a pair of strings: 690There are 9 elements in this list:
6911st and 2nd elements are used as brackets around the prospect list, 6911st and 2nd elements are used as brackets around the prospect list,
6923rd element is the separator between prospects (ignored if ido-separator is set), 6923rd element is the separator between prospects (ignored if ido-separator is set),
6934th element is the string inserted at the end of a truncated list of prospects, 6934th element is the string inserted at the end of a truncated list of prospects,
6945th and 6th elements are used as brackets around the common match string which 6945th and 6th elements are used as brackets around the common match string which
695can be completed using TAB, 695can be completed using TAB,
6967th element is the string displayed when there are a no matches, and 6967th element is the string displayed when there are a no matches, and
6978th element displayed if there is a single match (and faces are not used)." 6978th element is displayed if there is a single match (and faces are not used).
6989th element is displayed when the current directory is non-readable."
698 :type '(repeat string) 699 :type '(repeat string)
699 :group 'ido) 700 :group 'ido)
700 701
@@ -931,6 +932,9 @@ it doesn't interfere with other minibuffer usage.")
931;; `ido-cur-list'. It is in no specific order. 932;; `ido-cur-list'. It is in no specific order.
932(defvar ido-ignored-list) 933(defvar ido-ignored-list)
933 934
935;; Remember if current directory is non-readable (so we cannot do completion).
936(defvar ido-directory-nonreadable)
937
934;; Keep current item list if non-nil. 938;; Keep current item list if non-nil.
935(defvar ido-keep-item-list) 939(defvar ido-keep-item-list)
936 940
@@ -1406,6 +1410,7 @@ This function also adds a hook to the minibuffer."
1406 (setq ido-current-directory dir) 1410 (setq ido-current-directory dir)
1407 (if (get-buffer ido-completion-buffer) 1411 (if (get-buffer ido-completion-buffer)
1408 (kill-buffer ido-completion-buffer)) 1412 (kill-buffer ido-completion-buffer))
1413 (setq ido-directory-nonreadable (not (file-readable-p dir)))
1409 t)) 1414 t))
1410 1415
1411(defun ido-set-current-home (&optional dir) 1416(defun ido-set-current-home (&optional dir)
@@ -1812,7 +1817,8 @@ PROMPT is the prompt to give to the user. DEFAULT if given is the default
1812buffer to be selected, which will go to the front of the list. 1817buffer to be selected, which will go to the front of the list.
1813If REQUIRE-MATCH is non-nil, an existing-buffer must be selected. 1818If REQUIRE-MATCH is non-nil, an existing-buffer must be selected.
1814If INITIAL is non-nil, it specifies the initial input string." 1819If INITIAL is non-nil, it specifies the initial input string."
1815 (let ((ido-current-directory nil)) 1820 (let ((ido-current-directory nil)
1821 (ido-directory-nonreadable nil))
1816 (ido-read-internal 'buffer prompt 'ido-buffer-history default require-match initial))) 1822 (ido-read-internal 'buffer prompt 'ido-buffer-history default require-match initial)))
1817 1823
1818(defun ido-record-work-directory (&optional dir) 1824(defun ido-record-work-directory (&optional dir)
@@ -1851,12 +1857,18 @@ If INITIAL is non-nil, it specifies the initial input string."
1851 (if (> (length ido-work-file-list) ido-max-work-file-list) 1857 (if (> (length ido-work-file-list) ido-max-work-file-list)
1852 (setcdr (nthcdr (1- ido-max-work-file-list) ido-work-file-list) nil)))) 1858 (setcdr (nthcdr (1- ido-max-work-file-list) ido-work-file-list) nil))))
1853 1859
1860(defun ido-expand-directory (dir)
1861 ;; Expand DIR or use DEFAULT-DIRECTORY if nil.
1862 ;; Add final slash to result in case it was missing from DEFAULT-DIRECTORY.
1863 (ido-final-slash (expand-file-name (or dir default-directory)) t))
1864
1854(defun ido-file-internal (method &optional fallback default prompt item initial) 1865(defun ido-file-internal (method &optional fallback default prompt item initial)
1855 ;; Internal function for ido-find-file and friends 1866 ;; Internal function for ido-find-file and friends
1856 (unless item 1867 (unless item
1857 (setq item 'file)) 1868 (setq item 'file))
1858 (let ((ido-current-directory (expand-file-name (or default default-directory))) 1869 (let* ((ido-current-directory (ido-expand-directory default))
1859 filename) 1870 (ido-directory-nonreadable (not (file-readable-p ido-current-directory)))
1871 filename)
1860 1872
1861 (cond 1873 (cond
1862 ((or (not ido-mode) (ido-is-slow-ftp-host)) 1874 ((or (not ido-mode) (ido-is-slow-ftp-host))
@@ -2693,30 +2705,33 @@ for first matching file."
2693 (setq ido-temp-list items))) 2705 (setq ido-temp-list items)))
2694 2706
2695(defun ido-file-name-all-completions1 (dir) 2707(defun ido-file-name-all-completions1 (dir)
2696 (if (and ido-enable-tramp-completion 2708 (cond
2697 (string-match "\\`/\\([^/:]+:\\([^/:@]+@\\)?\\)\\'" dir)) 2709 ((not (file-readable-p dir)) '())
2698 2710 ((and ido-enable-tramp-completion
2699 ;; Trick tramp's file-name-all-completions handler to DTRT, as it 2711 (string-match "\\`/\\([^/:]+:\\([^/:@]+@\\)?\\)\\'" dir))
2700 ;; has some pretty obscure requirements. This seems to work... 2712
2701 ;; /ftp: => (f-n-a-c "/ftp:" "") 2713 ;; Trick tramp's file-name-all-completions handler to DTRT, as it
2702 ;; /ftp:kfs: => (f-n-a-c "" "/ftp:kfs:") 2714 ;; has some pretty obscure requirements. This seems to work...
2703 ;; /ftp:kfs@ => (f-n-a-c "ftp:kfs@" "/") 2715 ;; /ftp: => (f-n-a-c "/ftp:" "")
2704 ;; /ftp:kfs@kfs: => (f-n-a-c "" "/ftp:kfs@kfs:") 2716 ;; /ftp:kfs: => (f-n-a-c "" "/ftp:kfs:")
2705 ;; Currently no attempt is made to handle multi: stuff. 2717 ;; /ftp:kfs@ => (f-n-a-c "ftp:kfs@" "/")
2706 2718 ;; /ftp:kfs@kfs: => (f-n-a-c "" "/ftp:kfs@kfs:")
2707 (let* ((prefix (match-string 1 dir)) 2719 ;; Currently no attempt is made to handle multi: stuff.
2708 (user-flag (match-beginning 2)) 2720
2709 (len (and prefix (length prefix))) 2721 (let* ((prefix (match-string 1 dir))
2710 compl) 2722 (user-flag (match-beginning 2))
2711 (if user-flag 2723 (len (and prefix (length prefix)))
2712 (setq dir (substring dir 1))) 2724 compl)
2713 (require 'tramp nil t) 2725 (if user-flag
2714 (ido-trace "tramp complete" dir) 2726 (setq dir (substring dir 1)))
2715 (setq compl (file-name-all-completions dir (if user-flag "/" ""))) 2727 (require 'tramp nil t)
2716 (if (> len 0) 2728 (ido-trace "tramp complete" dir)
2717 (mapcar (lambda (c) (substring c len)) compl) 2729 (setq compl (file-name-all-completions dir (if user-flag "/" "")))
2718 compl)) 2730 (if (> len 0)
2719 (file-name-all-completions "" dir))) 2731 (mapcar (lambda (c) (substring c len)) compl)
2732 compl)))
2733 (t
2734 (file-name-all-completions "" dir))))
2720 2735
2721(defun ido-file-name-all-completions (dir) 2736(defun ido-file-name-all-completions (dir)
2722 ;; Return name of all files in DIR 2737 ;; Return name of all files in DIR
@@ -3518,6 +3533,11 @@ For details of keybindings, do `\\[describe-function] ido-find-file'."
3518 (expand-file-name "/" ido-current-directory) 3533 (expand-file-name "/" ido-current-directory)
3519 "/")) 3534 "/"))
3520 (setq refresh t)) 3535 (setq refresh t))
3536 ((and ido-directory-nonreadable
3537 (file-directory-p (concat ido-current-directory (file-name-directory contents))))
3538 (ido-set-current-directory
3539 (concat ido-current-directory (file-name-directory contents)))
3540 (setq refresh t))
3521 (t 3541 (t
3522 (ido-trace "try single dir") 3542 (ido-trace "try single dir")
3523 (setq try-single-dir-match t)))) 3543 (setq try-single-dir-match t))))
@@ -3574,6 +3594,7 @@ For details of keybindings, do `\\[describe-function] ido-find-file'."
3574 (exit-minibuffer)) 3594 (exit-minibuffer))
3575 3595
3576 (when (and (not ido-matches) 3596 (when (and (not ido-matches)
3597 (not ido-directory-nonreadable)
3577 ;; ido-rescan ? 3598 ;; ido-rescan ?
3578 ido-process-ignore-lists 3599 ido-process-ignore-lists
3579 ido-ignored-list) 3600 ido-ignored-list)
@@ -3596,7 +3617,8 @@ For details of keybindings, do `\\[describe-function] ido-find-file'."
3596 (memq ido-cur-item '(file dir)) 3617 (memq ido-cur-item '(file dir))
3597 (not (ido-is-root-directory)) 3618 (not (ido-is-root-directory))
3598 (> (length contents) 1) 3619 (> (length contents) 1)
3599 (not (string-match "[$]" contents))) 3620 (not (string-match "[$]" contents))
3621 (not ido-directory-nonreadable))
3600 (ido-trace "merge?") 3622 (ido-trace "merge?")
3601 (if ido-use-merged-list 3623 (if ido-use-merged-list
3602 (ido-undo-merge-work-directory contents nil) 3624 (ido-undo-merge-work-directory contents nil)
@@ -3658,9 +3680,12 @@ For details of keybindings, do `\\[describe-function] ido-find-file'."
3658 (setq comps (cons first (cdr comps))))) 3680 (setq comps (cons first (cdr comps)))))
3659 3681
3660 (cond ((null comps) 3682 (cond ((null comps)
3661 (if ido-report-no-match 3683 (cond
3662 (nth 6 ido-decorations) ;; [No Match] 3684 (ido-directory-nonreadable
3663 "")) 3685 (or (nth 8 ido-decorations) " [Not readable]"))
3686 (ido-report-no-match
3687 (nth 6 ido-decorations)) ;; [No match]
3688 (t "")))
3664 3689
3665 ((null (cdr comps)) ;one match 3690 ((null (cdr comps)) ;one match
3666 (concat (if (> (length (ido-name (car comps))) (length name)) 3691 (concat (if (> (length (ido-name (car comps))) (length name))
@@ -3771,13 +3796,14 @@ See `read-file-name' for additional parameters."
3771 (ido-read-directory-name prompt dir default-filename mustmatch initial)) 3796 (ido-read-directory-name prompt dir default-filename mustmatch initial))
3772 ((and (not (memq this-command ido-read-file-name-non-ido)) 3797 ((and (not (memq this-command ido-read-file-name-non-ido))
3773 (or (null predicate) (eq predicate 'file-exists-p))) 3798 (or (null predicate) (eq predicate 'file-exists-p)))
3774 (let (filename 3799 (let* (filename
3775 ido-saved-vc-hb 3800 ido-saved-vc-hb
3776 (vc-handled-backends (and (boundp 'vc-handled-backends) vc-handled-backends)) 3801 (vc-handled-backends (and (boundp 'vc-handled-backends) vc-handled-backends))
3777 (ido-current-directory (expand-file-name (or dir default-directory))) 3802 (ido-current-directory (ido-expand-directory dir))
3778 (ido-work-directory-index -1) 3803 (ido-directory-nonreadable (not (file-readable-p ido-current-directory)))
3779 (ido-work-file-index -1) 3804 (ido-work-directory-index -1)
3780 (ido-find-literal nil)) 3805 (ido-work-file-index -1)
3806 (ido-find-literal nil))
3781 (setq filename 3807 (setq filename
3782 (ido-read-internal 'file prompt 'ido-file-history default-filename mustmatch initial)) 3808 (ido-read-internal 'file prompt 'ido-file-history default-filename mustmatch initial))
3783 (if filename 3809 (if filename
@@ -3790,11 +3816,12 @@ See `read-file-name' for additional parameters."
3790(defun ido-read-directory-name (prompt &optional dir default-dirname mustmatch initial) 3816(defun ido-read-directory-name (prompt &optional dir default-dirname mustmatch initial)
3791 "Read directory name, prompting with PROMPT and completing in directory DIR. 3817 "Read directory name, prompting with PROMPT and completing in directory DIR.
3792See `read-file-name' for additional parameters." 3818See `read-file-name' for additional parameters."
3793 (let (filename 3819 (let* (filename
3794 ido-saved-vc-hb 3820 ido-saved-vc-hb
3795 (ido-current-directory (expand-file-name (or dir default-directory))) 3821 (ido-current-directory (ido-expand-directory dir))
3796 (ido-work-directory-index -1) 3822 (ido-directory-nonreadable (not (file-readable-p ido-current-directory)))
3797 (ido-work-file-index -1)) 3823 (ido-work-directory-index -1)
3824 (ido-work-file-index -1))
3798 (setq filename 3825 (setq filename
3799 (ido-read-internal 'dir prompt 'ido-file-history default-dirname mustmatch initial)) 3826 (ido-read-internal 'dir prompt 'ido-file-history default-dirname mustmatch initial))
3800 (if filename 3827 (if filename
diff --git a/lisp/jka-compr.el b/lisp/jka-compr.el
index dd56c9c0f31..aae0f0f85c1 100644
--- a/lisp/jka-compr.el
+++ b/lisp/jka-compr.el
@@ -590,10 +590,11 @@ There should be no more than seven characters after the final `/'."
590 (file-exists-p local-copy) 590 (file-exists-p local-copy)
591 (delete-file local-copy))) 591 (delete-file local-copy)))
592 592
593 (decode-coding-inserted-region 593 (unless notfound
594 (point) (+ (point) size) 594 (decode-coding-inserted-region
595 (jka-compr-byte-compiler-base-file-name file) 595 (point) (+ (point) size)
596 visit beg end replace) 596 (jka-compr-byte-compiler-base-file-name file)
597 visit beg end replace))
597 598
598 (and 599 (and
599 visit 600 visit
diff --git a/lisp/ls-lisp.el b/lisp/ls-lisp.el
index 7554bce0a3b..521729b764f 100644
--- a/lisp/ls-lisp.el
+++ b/lisp/ls-lisp.el
@@ -267,7 +267,7 @@ not contain `d', so that a full listing is expected."
267 (let* ((dir (file-name-as-directory file)) 267 (let* ((dir (file-name-as-directory file))
268 (default-directory dir) ; so that file-attributes works 268 (default-directory dir) ; so that file-attributes works
269 (file-alist 269 (file-alist
270 (directory-files-and-attributes dir nil wildcard-regexp t)) 270 (directory-files-and-attributes dir nil wildcard-regexp t 'string))
271 (now (current-time)) 271 (now (current-time))
272 (sum 0) 272 (sum 0)
273 ;; do all bindings here for speed 273 ;; do all bindings here for speed
@@ -329,7 +329,7 @@ not contain `d', so that a full listing is expected."
329 ;; so must make it a relative filename as ls does: 329 ;; so must make it a relative filename as ls does:
330 (if (eq (aref file (1- (length file))) ?/) 330 (if (eq (aref file (1- (length file))) ?/)
331 (setq file (substring file 0 -1))) 331 (setq file (substring file 0 -1)))
332 (let ((fattr (file-attributes file))) 332 (let ((fattr (file-attributes file 'string)))
333 (if fattr 333 (if fattr
334 (insert (ls-lisp-format file fattr (nth 7 fattr) 334 (insert (ls-lisp-format file fattr (nth 7 fattr)
335 switches time-index (current-time))) 335 switches time-index (current-time)))
@@ -522,23 +522,14 @@ SWITCHES, TIME-INDEX and NOW give the full switch list and time data."
522 ;; They tend to be bogus on non-UNIX platforms anyway so 522 ;; They tend to be bogus on non-UNIX platforms anyway so
523 ;; optionally hide them. 523 ;; optionally hide them.
524 (if (memq 'uid ls-lisp-verbosity) 524 (if (memq 'uid ls-lisp-verbosity)
525 ;; (user-login-name uid) works on Windows NT but not 525 ;; uid can be a sting or an integer
526 ;; on 9x and maybe not on some other platforms, so...
527 (let ((uid (nth 2 file-attr))) 526 (let ((uid (nth 2 file-attr)))
528 (if (= uid (user-uid)) 527 (format (if (stringp uid) " %-8s" " %-8d") uid)))
529 (format " %-8s" (user-login-name))
530 (format " %-8d" uid))))
531 (if (not (memq ?G switches)) ; GNU ls -- shows group by default 528 (if (not (memq ?G switches)) ; GNU ls -- shows group by default
532 (if (or (memq ?g switches) ; UNIX ls -- no group by default 529 (if (or (memq ?g switches) ; UNIX ls -- no group by default
533 (memq 'gid ls-lisp-verbosity)) 530 (memq 'gid ls-lisp-verbosity))
534 (if (memq system-type '(macos windows-nt ms-dos)) 531 (let ((gid (nth 3 file-attr)))
535 ;; No useful concept of group... 532 (format (if (stringp gid) " %-8s" " %-8d") gid))))
536 " root"
537 (let* ((gid (nth 3 file-attr))
538 (group (user-login-name gid)))
539 (if group
540 (format " %-8s" group)
541 (format " %-8d" gid))))))
542 (ls-lisp-format-file-size file-size (memq ?h switches)) 533 (ls-lisp-format-file-size file-size (memq ?h switches))
543 " " 534 " "
544 (ls-lisp-format-time file-attr time-index now) 535 (ls-lisp-format-time file-attr time-index now)
diff --git a/lisp/textmodes/texnfo-upd.el b/lisp/textmodes/texnfo-upd.el
index fb44acbff4f..17b0affac92 100644
--- a/lisp/textmodes/texnfo-upd.el
+++ b/lisp/textmodes/texnfo-upd.el
@@ -1,6 +1,6 @@
1;;; texnfo-upd.el --- utilities for updating nodes and menus in Texinfo files 1;;; texnfo-upd.el --- utilities for updating nodes and menus in Texinfo files
2 2
3;; Copyright (C) 1989, 1990, 1991, 1992, 2001, 2002 Free Software Foundation, Inc. 3;; Copyright (C) 1989, 1990, 1991, 1992, 2001, 2002, 2003 Free Software Foundation, Inc.
4 4
5;; Author: Robert J. Chassell 5;; Author: Robert J. Chassell
6;; Maintainer: bug-texinfo@gnu.org 6;; Maintainer: bug-texinfo@gnu.org
@@ -1795,25 +1795,34 @@ Thus, normally, each included file contains one, and only one, chapter."
1795;; description slot of a menu as a description. 1795;; description slot of a menu as a description.
1796 1796
1797 (let ((case-fold-search t) 1797 (let ((case-fold-search t)
1798 menu-list next-node-name previous-node-name) 1798 menu-list next-node-name previous-node-name files-with-node-lines)
1799 1799
1800 ;; Find the name of the first node of the first included file. 1800 ;; Create a new list of included files that only have node lines
1801 (set-buffer (find-file-noselect (car (cdr files)))) 1801 (while files
1802 (set-buffer (find-file-noselect (car files)))
1803 (widen)
1804 (goto-char (point-min))
1805 (when (re-search-forward "^@node" nil t)
1806 (setq files-with-node-lines (cons (car files) files-with-node-lines)))
1807 (setq files (cdr files)))
1808 (setq files-with-node-lines (nreverse files-with-node-lines))
1809
1810 ;; Find the name of the first node in a subsequent file
1811 ;; and copy it into the variable next-node-name
1812 (set-buffer (find-file-noselect (car (cdr files-with-node-lines))))
1802 (widen) 1813 (widen)
1803 (goto-char (point-min)) 1814 (goto-char (point-min))
1804 (if (not (re-search-forward "^@node" nil t))
1805 (error "No `@node' line found in %s" (buffer-name)))
1806 (beginning-of-line) 1815 (beginning-of-line)
1807 (texinfo-check-for-node-name) 1816 (texinfo-check-for-node-name)
1808 (setq next-node-name (texinfo-copy-node-name)) 1817 (setq next-node-name (texinfo-copy-node-name))
1809
1810 (push (cons next-node-name (prog1 "" (forward-line 1))) 1818 (push (cons next-node-name (prog1 "" (forward-line 1)))
1811 ;; Use following to insert section titles automatically. 1819 ;; Use following to insert section titles automatically.
1812 ;; (texinfo-copy-next-section-title) 1820 ;; (texinfo-copy-next-section-title)
1813 menu-list) 1821 menu-list)
1814 1822
1815 ;; Go to outer file 1823 ;; Go to outer file
1816 (set-buffer (find-file-noselect (pop files))) 1824 ;; `pop' is analogous to (prog1 (car PLACE) (setf PLACE (cdr PLACE)))
1825 (set-buffer (find-file-noselect (pop files-with-node-lines)))
1817 (goto-char (point-min)) 1826 (goto-char (point-min))
1818 (if (not (re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)" nil t)) 1827 (if (not (re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)" nil t))
1819 (error "This buffer needs a Top node")) 1828 (error "This buffer needs a Top node"))
@@ -1824,18 +1833,16 @@ Thus, normally, each included file contains one, and only one, chapter."
1824 (beginning-of-line) 1833 (beginning-of-line)
1825 (setq previous-node-name "Top") 1834 (setq previous-node-name "Top")
1826 1835
1827 (while files 1836 (while files-with-node-lines
1828 1837
1829 (if (not (cdr files)) 1838 (if (not (cdr files-with-node-lines))
1830 ;; No next file 1839 ;; No next file
1831 (setq next-node-name "") 1840 (setq next-node-name "")
1832 ;; Else, 1841 ;; Else,
1833 ;; find the name of the first node in the next file. 1842 ;; find the name of the first node in the next file.
1834 (set-buffer (find-file-noselect (car (cdr files)))) 1843 (set-buffer (find-file-noselect (car (cdr files-with-node-lines))))
1835 (widen) 1844 (widen)
1836 (goto-char (point-min)) 1845 (goto-char (point-min))
1837 (if (not (re-search-forward "^@node" nil t))
1838 (error "No `@node' line found in %s" (buffer-name)))
1839 (beginning-of-line) 1846 (beginning-of-line)
1840 (texinfo-check-for-node-name) 1847 (texinfo-check-for-node-name)
1841 (setq next-node-name (texinfo-copy-node-name)) 1848 (setq next-node-name (texinfo-copy-node-name))
@@ -1845,10 +1852,8 @@ Thus, normally, each included file contains one, and only one, chapter."
1845 menu-list)) 1852 menu-list))
1846 1853
1847 ;; Go to node to be updated. 1854 ;; Go to node to be updated.
1848 (set-buffer (find-file-noselect (car files))) 1855 (set-buffer (find-file-noselect (car files-with-node-lines)))
1849 (goto-char (point-min)) 1856 (goto-char (point-min))
1850 (if (not (re-search-forward "^@node" nil t))
1851 (error "No `@node' line found in %s" (buffer-name)))
1852 (beginning-of-line) 1857 (beginning-of-line)
1853 1858
1854 ;; Update other menus and nodes if requested. 1859 ;; Update other menus and nodes if requested.
@@ -1862,7 +1867,7 @@ Thus, normally, each included file contains one, and only one, chapter."
1862 (beginning-of-line) 1867 (beginning-of-line)
1863 (setq previous-node-name (texinfo-copy-node-name)) 1868 (setq previous-node-name (texinfo-copy-node-name))
1864 1869
1865 (setq files (cdr files))) 1870 (setq files-with-node-lines (cdr files-with-node-lines)))
1866 (nreverse menu-list))) 1871 (nreverse menu-list)))
1867 1872
1868(defun texinfo-multi-files-insert-main-menu (menu-list) 1873(defun texinfo-multi-files-insert-main-menu (menu-list)
diff --git a/lisp/wid-edit.el b/lisp/wid-edit.el
index 4c70334e908..63a254d1d67 100644
--- a/lisp/wid-edit.el
+++ b/lisp/wid-edit.el
@@ -1267,6 +1267,42 @@ Optional EVENT is the event that triggered the action."
1267 found (widget-apply child :validate))) 1267 found (widget-apply child :validate)))
1268 found)) 1268 found))
1269 1269
1270(defun widget-child-value-get (widget)
1271 "Get the value of the first member of :children in WIDGET."
1272 (widget-value (car (widget-get widget :children))))
1273
1274(defun widget-child-value-inline (widget)
1275 "Get the inline value of the first member of :children in WIDGET."
1276 (widget-apply (car (widget-get widget :children)) :value-inline))
1277
1278(defun widget-child-validate (widget)
1279 "The result of validating the first member of :children in WIDGET."
1280 (widget-apply (car (widget-get widget :children)) :validate))
1281
1282(defun widget-type-value-create (widget)
1283 "Convert and instantiate the value of the :type attribute of WIDGET.
1284Store the newly created widget in the :children attribute.
1285
1286The value of the :type attribute should be an unconverted widget type."
1287 (let ((value (widget-get widget :value))
1288 (type (widget-get widget :type)))
1289 (widget-put widget :children
1290 (list (widget-create-child-value widget
1291 (widget-convert type)
1292 value)))))
1293
1294(defun widget-type-default-get (widget)
1295 "Get default value from the :type attribute of WIDGET.
1296
1297The value of the :type attribute should be an unconverted widget type."
1298 (widget-default-get (widget-convert (widget-get widget :type))))
1299
1300(defun widget-type-match (widget value)
1301 "Non-nil if the :type value of WIDGET matches VALUE.
1302
1303The value of the :type attribute should be an unconverted widget type."
1304 (widget-apply (widget-convert (widget-get widget :type)) :match value))
1305
1270(defun widget-types-copy (widget) 1306(defun widget-types-copy (widget)
1271 "Copy :args as widget types in WIDGET." 1307 "Copy :args as widget types in WIDGET."
1272 (widget-put widget :args (mapcar 'widget-copy (widget-get widget :args))) 1308 (widget-put widget :args (mapcar 'widget-copy (widget-get widget :args)))
@@ -1862,9 +1898,8 @@ the earlier input."
1862 :tag "choice" 1898 :tag "choice"
1863 :void '(item :format "invalid (%t)\n") 1899 :void '(item :format "invalid (%t)\n")
1864 :value-create 'widget-choice-value-create 1900 :value-create 'widget-choice-value-create
1865 :value-delete 'widget-children-value-delete 1901 :value-get 'widget-child-value-get
1866 :value-get 'widget-choice-value-get 1902 :value-inline 'widget-child-value-inline
1867 :value-inline 'widget-choice-value-inline
1868 :default-get 'widget-choice-default-get 1903 :default-get 'widget-choice-default-get
1869 :mouse-down-action 'widget-choice-mouse-down-action 1904 :mouse-down-action 'widget-choice-mouse-down-action
1870 :action 'widget-choice-action 1905 :action 'widget-choice-action
@@ -1901,14 +1936,6 @@ the earlier input."
1901 widget void :value value))) 1936 widget void :value value)))
1902 (widget-put widget :choice void)))))) 1937 (widget-put widget :choice void))))))
1903 1938
1904(defun widget-choice-value-get (widget)
1905 ;; Get value of the child widget.
1906 (widget-value (car (widget-get widget :children))))
1907
1908(defun widget-choice-value-inline (widget)
1909 ;; Get value of the child widget.
1910 (widget-apply (car (widget-get widget :children)) :value-inline))
1911
1912(defun widget-choice-default-get (widget) 1939(defun widget-choice-default-get (widget)
1913 ;; Get default for the first choice. 1940 ;; Get default for the first choice.
1914 (widget-default-get (car (widget-get widget :args)))) 1941 (widget-default-get (car (widget-get widget :args))))
@@ -2099,7 +2126,6 @@ when he invoked the menu."
2099 :entry-format "%b %v" 2126 :entry-format "%b %v"
2100 :greedy nil 2127 :greedy nil
2101 :value-create 'widget-checklist-value-create 2128 :value-create 'widget-checklist-value-create
2102 :value-delete 'widget-children-value-delete
2103 :value-get 'widget-checklist-value-get 2129 :value-get 'widget-checklist-value-get
2104 :validate 'widget-checklist-validate 2130 :validate 'widget-checklist-validate
2105 :match 'widget-checklist-match 2131 :match 'widget-checklist-match
@@ -2276,7 +2302,6 @@ Return an alist of (TYPE MATCH)."
2276 :format "%v" 2302 :format "%v"
2277 :entry-format "%b %v" 2303 :entry-format "%b %v"
2278 :value-create 'widget-radio-value-create 2304 :value-create 'widget-radio-value-create
2279 :value-delete 'widget-children-value-delete
2280 :value-get 'widget-radio-value-get 2305 :value-get 'widget-radio-value-get
2281 :value-inline 'widget-radio-value-inline 2306 :value-inline 'widget-radio-value-inline
2282 :value-set 'widget-radio-value-set 2307 :value-set 'widget-radio-value-set
@@ -2466,7 +2491,6 @@ Return an alist of (TYPE MATCH)."
2466 :format-handler 'widget-editable-list-format-handler 2491 :format-handler 'widget-editable-list-format-handler
2467 :entry-format "%i %d %v" 2492 :entry-format "%i %d %v"
2468 :value-create 'widget-editable-list-value-create 2493 :value-create 'widget-editable-list-value-create
2469 :value-delete 'widget-children-value-delete
2470 :value-get 'widget-editable-list-value-get 2494 :value-get 'widget-editable-list-value-get
2471 :validate 'widget-children-validate 2495 :validate 'widget-children-validate
2472 :match 'widget-editable-list-match 2496 :match 'widget-editable-list-match
@@ -2637,7 +2661,6 @@ Return an alist of (TYPE MATCH)."
2637 :copy 'widget-types-copy 2661 :copy 'widget-types-copy
2638 :format "%v" 2662 :format "%v"
2639 :value-create 'widget-group-value-create 2663 :value-create 'widget-group-value-create
2640 :value-delete 'widget-children-value-delete
2641 :value-get 'widget-editable-list-value-get 2664 :value-get 'widget-editable-list-value-get
2642 :default-get 'widget-group-default-get 2665 :default-get 'widget-group-default-get
2643 :validate 'widget-children-validate 2666 :validate 'widget-children-validate
@@ -2803,7 +2826,6 @@ link for that string."
2803 "A documentation string." 2826 "A documentation string."
2804 :format "%v" 2827 :format "%v"
2805 :action 'widget-documentation-string-action 2828 :action 'widget-documentation-string-action
2806 :value-delete 'widget-children-value-delete
2807 :value-create 'widget-documentation-string-value-create) 2829 :value-create 'widget-documentation-string-value-create)
2808 2830
2809(defun widget-documentation-string-value-create (widget) 2831(defun widget-documentation-string-value-create (widget)
@@ -3250,6 +3272,62 @@ To use this type, you must define :match or :match-alternatives."
3250 (widget-group-match widget 3272 (widget-group-match widget
3251 (widget-apply widget :value-to-internal value)))) 3273 (widget-apply widget :value-to-internal value))))
3252 3274
3275;;; The `lazy' Widget.
3276;;
3277;; Recursive datatypes.
3278
3279(define-widget 'lazy 'default
3280 "Base widget for recursive datastructures.
3281
3282The `lazy' widget will, when instantiated, contain a single inferior
3283widget, of the widget type specified by the :type parameter. The
3284value of the `lazy' widget is the same as the value of the inferior
3285widget. When deriving a new widget from the 'lazy' widget, the :type
3286parameter is allowed to refer to the widget currently being defined,
3287thus allowing recursive datastructures to be described.
3288
3289The :type parameter takes the same arguments as the defcustom
3290parameter with the same name.
3291
3292Most composite widgets, i.e. widgets containing other widgets, does
3293not allow recursion. That is, when you define a new widget type, none
3294of the inferior widgets may be of the same type you are currently
3295defining.
3296
3297In Lisp, however, it is custom to define datastructures in terms of
3298themselves. A list, for example, is defined as either nil, or a cons
3299cell whose cdr itself is a list. The obvious way to translate this
3300into a widget type would be
3301
3302 (define-widget 'my-list 'choice
3303 \"A list of sexps.\"
3304 :tag \"Sexp list\"
3305 :args '((const nil) (cons :value (nil) sexp my-list)))
3306
3307Here we attempt to define my-list as a choice of either the constant
3308nil, or a cons-cell containing a sexp and my-lisp. This will not work
3309because the `choice' widget does not allow recursion.
3310
3311Using the `lazy' widget you can overcome this problem, as in this
3312example:
3313
3314 (define-widget 'sexp-list 'lazy
3315 \"A list of sexps.\"
3316 :tag \"Sexp list\"
3317 :type '(choice (const nil) (cons :value (nil) sexp sexp-list)))"
3318 :format "%{%t%}: %v"
3319 ;; We don't convert :type because we want to allow recursive
3320 ;; datastructures. This is slow, so we should not create speed
3321 ;; critical widgets by deriving from this.
3322 :convert-widget 'widget-value-convert-widget
3323 :value-create 'widget-type-value-create
3324 :value-get 'widget-child-value-get
3325 :value-inline 'widget-child-value-inline
3326 :default-get 'widget-type-default-get
3327 :match 'widget-type-match
3328 :validate 'widget-child-validate)
3329
3330
3253;;; The `plist' Widget. 3331;;; The `plist' Widget.
3254;; 3332;;
3255;; Property lists. 3333;; Property lists.
diff --git a/lispref/ChangeLog b/lispref/ChangeLog
index 85a5f506739..1b9aabffe46 100644
--- a/lispref/ChangeLog
+++ b/lispref/ChangeLog
@@ -1,3 +1,51 @@
12003-12-25 Markus Rost <rost@mathematik.uni-bielefeld.de>
2
3 * display.texi (Fringes): Fix typo "set-buffer-window".
4
52003-12-24 Luc Teirlinck <teirllm@auburn.edu>
6
7 * display.texi, eval.texi, help.texi, internals.texi, loading.texi:
8 * nonascii.texi, processes.texi, tips.texi, variables.texi:
9 Add or change various xrefs and anchors.
10
11 * commands.texi: Replace all occurrences of @acronym{CAR} with
12 @sc{car}, for consistency with the rest of the Elisp manual.
13 `car' and `cdr' are historically acronyms, but are no longer
14 widely thought of as such.
15
16 * internals.texi (Pure Storage): Mention that `purecopy' does not
17 copy text properties.
18 (Object Internals): Now 29 bits are used (in most implementations)
19 to address Lisp objects.
20
21 * variables.texi (Variables with Restricted Values): New node.
22
23 * objects.texi (Lisp Data Types): Mention that certain variables
24 can only take on a restricted set of values and add an xref to
25 the new node "Variables with Restricted Values".
26
27 * eval.texi (Function Indirection): Describe the errors that
28 `indirect-function' can signal.
29 (Eval): Clarify the descriptions of `eval-region' and `values'.
30 Describe `eval-buffer' instead of `eval-current-buffer' and
31 mention `eval-current-buffer' as an alias for `current-buffer'.
32 Correct the description and mention all optional arguments.
33
34 * nonascii.texi : Various small changes in addition to the
35 following.
36 (Converting Representations): Clarify behavior of
37 `string-make-multibyte' and `string-to-multibyte' for unibyte all
38 ASCII arguments.
39 (Character Sets): Document the variable `charset-list' and adapt
40 the definition of the function `charset-list' accordingly.
41 (Translation of Characters): Clarify use of generic characters in
42 `make-translation-table'. Clarify and correct the description of
43 the use of translation tables in encoding and decoding.
44 (User-Chosen Coding Systems): Correct and clarify the description
45 of `select-safe-coding-system'.
46 (Default Coding Systems): Clarify description of
47 `file-coding-system-alist'.
48
12003-11-30 Luc Teirlinck <teirllm@auburn.edu> 492003-11-30 Luc Teirlinck <teirllm@auburn.edu>
2 50
3 * strings.texi (Text Comparison): Correctly describe when two 51 * strings.texi (Text Comparison): Correctly describe when two
@@ -42,7 +90,7 @@
42 90
432003-11-20 Luc Teirlinck <teirllm@auburn.edu> 912003-11-20 Luc Teirlinck <teirllm@auburn.edu>
44 92
45 * positions.texi (Positions): Mention that, if a marker is used a 93 * positions.texi (Positions): Mention that, if a marker is used as
46 a position, its buffer is ignored. 94 a position, its buffer is ignored.
47 95
48 * markers.texi (Overview of Markers): Mention it here too. 96 * markers.texi (Overview of Markers): Mention it here too.
diff --git a/lispref/commands.texi b/lispref/commands.texi
index a2838c68bb9..a8350b88d82 100644
--- a/lispref/commands.texi
+++ b/lispref/commands.texi
@@ -1096,7 +1096,7 @@ arguments to the key-binding lookup and modification functions.
1096 1096
1097Emacs supports four kinds of mouse events: click events, drag events, 1097Emacs supports four kinds of mouse events: click events, drag events,
1098button-down events, and motion events. All mouse events are represented 1098button-down events, and motion events. All mouse events are represented
1099as lists. The @acronym{CAR} of the list is the event type; this says which 1099as lists. The @sc{car} of the list is the event type; this says which
1100mouse button was involved, and which modifier keys were used with it. 1100mouse button was involved, and which modifier keys were used with it.
1101The event type can also distinguish double or triple button presses 1101The event type can also distinguish double or triple button presses
1102(@pxref{Repeat Events}). The rest of the list elements give position 1102(@pxref{Repeat Events}). The rest of the list elements give position
@@ -1172,7 +1172,7 @@ which the click occurred. It is one of the symbols @code{mode-line},
1172 1172
1173@item @var{x}, @var{y} 1173@item @var{x}, @var{y}
1174These are the pixel-denominated coordinates of the click, relative to 1174These are the pixel-denominated coordinates of the click, relative to
1175the top left corner of @var{window}, which is @code{(0 . 0)}. 1175the top left corner of @var{window}, which is @code{(0 . 0)}.
1176For the mode or header line, @var{y} does not have meaningful data. 1176For the mode or header line, @var{y} does not have meaningful data.
1177For the vertical line, @var{x} does not have meaningful data. 1177For the vertical line, @var{x} does not have meaningful data.
1178 1178
@@ -1188,7 +1188,7 @@ an image object as returned by @code{find-image} if click was in an image.
1188 1188
1189@item @var{string} 1189@item @var{string}
1190This is the string on which the click occurred, including any 1190This is the string on which the click occurred, including any
1191properties. 1191properties.
1192 1192
1193@item @var{string-pos} 1193@item @var{string-pos}
1194This is the position in the string on which the click occurred, 1194This is the position in the string on which the click occurred,
@@ -1560,7 +1560,7 @@ into another window. That produces a pair of events like these:
1560key binding purposes. For a keyboard event, the event type equals the 1560key binding purposes. For a keyboard event, the event type equals the
1561event value; thus, the event type for a character is the character, and 1561event value; thus, the event type for a character is the character, and
1562the event type for a function key symbol is the symbol itself. For 1562the event type for a function key symbol is the symbol itself. For
1563events that are lists, the event type is the symbol in the @acronym{CAR} of 1563events that are lists, the event type is the symbol in the @sc{car} of
1564the list. Thus, the event type is always a symbol or a character. 1564the list. Thus, the event type is always a symbol or a character.
1565 1565
1566 Two events of the same type are equivalent where key bindings are 1566 Two events of the same type are equivalent where key bindings are
@@ -2583,7 +2583,7 @@ This function returns the numeric meaning of a valid raw prefix argument
2583value, @var{arg}. The argument may be a symbol, a number, or a list. 2583value, @var{arg}. The argument may be a symbol, a number, or a list.
2584If it is @code{nil}, the value 1 is returned; if it is @code{-}, the 2584If it is @code{nil}, the value 1 is returned; if it is @code{-}, the
2585value @minus{}1 is returned; if it is a number, that number is returned; 2585value @minus{}1 is returned; if it is a number, that number is returned;
2586if it is a list, the @acronym{CAR} of that list (which should be a number) is 2586if it is a list, the @sc{car} of that list (which should be a number) is
2587returned. 2587returned.
2588@end defun 2588@end defun
2589 2589
diff --git a/lispref/customize.texi b/lispref/customize.texi
index 8621cb65662..90600f410b7 100644
--- a/lispref/customize.texi
+++ b/lispref/customize.texi
@@ -1,6 +1,6 @@
1@c -*-texinfo-*- 1@c -*-texinfo-*-
2@c This is part of the GNU Emacs Lisp Reference Manual. 2@c This is part of the GNU Emacs Lisp Reference Manual.
3@c Copyright (C) 1997, 1998, 1999, 2000, 2002 Free Software Foundation, Inc. 3@c Copyright (C) 1997, 1998, 1999, 2000, 2002, 2003 Free Software Foundation, Inc.
4@c See the file elisp.texi for copying conditions. 4@c See the file elisp.texi for copying conditions.
5@setfilename ../info/customize 5@setfilename ../info/customize
6@node Customization, Loading, Macros, Top 6@node Customization, Loading, Macros, Top
@@ -373,6 +373,7 @@ equivalent to @code{(string)}.
373* Composite Types:: 373* Composite Types::
374* Splicing into Lists:: 374* Splicing into Lists::
375* Type Keywords:: 375* Type Keywords::
376* Defining New Types::
376@end menu 377@end menu
377 378
378All customization types are implemented as widgets; see @ref{Top, , 379All customization types are implemented as widgets; see @ref{Top, ,
@@ -1056,6 +1057,76 @@ arguments, which will be used when creating the @code{radio-button} or
1056@end ignore 1057@end ignore
1057@end table 1058@end table
1058 1059
1060@node Defining New Types
1061@subsection Defining New Types
1062
1063In the previous sections we have described how to construct elaborate
1064type specifications for @code{defcustom}. In some cases you may want to
1065give such a type specification a name. The obvious case is when you are
1066using the same type for many user options, rather than repeat the
1067specification for each option, you can give the type specification a
1068name once, and use that name each @code{defcustom}. The other case is
1069when a user option accept a recursive datastructure. To make it
1070possible for a datatype to refer to itself, it needs to have a name.
1071
1072Since custom types are implemented as widgets, the way to define a new
1073customize type is to define a new widget. We are not going to describe
1074the widget interface here in details, see @ref{Top, , Introduction,
1075widget, The Emacs Widget Library}, for that. Instead we are going to
1076demonstrate the minimal functionality needed for defining new customize
1077types by a simple example.
1078
1079@example
1080(define-widget 'binary-tree-of-string 'lazy
1081 "A binary tree made of cons-cells and strings."
1082 :offset 4
1083 :tag "Node"
1084 :type '(choice (string :tag "Leaf" :value "")
1085 (cons :tag "Interior"
1086 :value ("" . "")
1087 binary-tree-of-string
1088 binary-tree-of-string)))
1089
1090(defcustom foo-bar ""
1091 "Sample variable holding a binary tree of strings."
1092 :type 'binary-tree-of-string)
1093@end example
1094
1095The function to define a new widget is name @code{define-widget}. The
1096first argument is the symbol we want to make a new widget type. The
1097second argument is a symbol representing an existing widget, the new
1098widget is going to be defined in terms of difference from the existing
1099widget. For the purpose of defining new customization types, the
1100@code{lazy} widget is perfect, because it accept a @code{:type} keyword
1101argument with the same syntax as the keyword argument to
1102@code{defcustom} with the same name. The third argument is a
1103documentation string for the new widget. You will be able to see that
1104string with the @kbd{M-x widget-browse @key{ret} binary-tree-of-string
1105@key{ret}} command.
1106
1107After these mandatory arguments follows the keyword arguments. The most
1108important is @code{:type}, which describes the datatype we want to match
1109with this widget. Here a @code{binary-tree-of-string} is described as
1110being either a string, or a cons-cell whose car and cdr are themselves
1111both @code{binary-tree-of-string}. Note the reference to the widget
1112type we are currently in the process of defining. The @code{:tag}
1113attribute is a string to name the widget in the user interface, and the
1114@code{:offset} argument are there to ensure that child nodes are
1115indented four spaces relatively to the parent node, making the tree
1116structure apparent in the customization buffer.
1117
1118The @code{defcustom} shows how the new widget can be used as an ordinary
1119customization type.
1120
1121If you wonder about the name @code{lazy}, know that the other composite
1122widgets convert their inferior widgets to internal form when the widget
1123is instantiated in a buffer. This conversion is recursive, so the
1124inferior widgets will convert @emph{their} inferior widgets. If the
1125datastructure is itself recursive, this conversion will go on forever,
1126or at least until Emacs run out of stack space. The @code{lazy} widget
1127stop this recursion, it will only convert its @code{:type} argument when
1128needed.
1129
1059@ignore 1130@ignore
1060 arch-tag: d1b8fad3-f48c-4ce4-a402-f73b5ef19bd2 1131 arch-tag: d1b8fad3-f48c-4ce4-a402-f73b5ef19bd2
1061@end ignore 1132@end ignore
diff --git a/lispref/display.texi b/lispref/display.texi
index 186703b13b0..abbbab0ce79 100644
--- a/lispref/display.texi
+++ b/lispref/display.texi
@@ -805,8 +805,9 @@ If the @var{forms} do not change the major mode in the output buffer,
805so that it is still Help mode at the end of their execution, then 805so that it is still Help mode at the end of their execution, then
806@code{with-output-to-temp-buffer} makes this buffer read-only at the 806@code{with-output-to-temp-buffer} makes this buffer read-only at the
807end, and also scans it for function and variable names to make them 807end, and also scans it for function and variable names to make them
808into clickable cross-references. @xref{Documentation Tips, , Tips for 808into clickable cross-references. @xref{Docstring hyperlinks, , Tips
809Documentation Strings}. 809for Documentation Strings}, in particular the item on hyperlinks in
810documentation strings, for more details.
810 811
811The string @var{buffer-name} specifies the temporary buffer, which 812The string @var{buffer-name} specifies the temporary buffer, which
812need not already exist. The argument must be a string, not a buffer. 813need not already exist. The argument must be a string, not a buffer.
@@ -2527,7 +2528,7 @@ fringe in pixels.
2527 2528
2528 The values of these variables take effect when you display the 2529 The values of these variables take effect when you display the
2529buffer in a window. If you change them while the buffer is visible, 2530buffer in a window. If you change them while the buffer is visible,
2530you can call @code{set-buffer-window} to display it in a window again. 2531you can call @code{set-window-buffer} to display it in a window again.
2531 2532
2532@defun set-window-fringes window left &optional right outside-margins 2533@defun set-window-fringes window left &optional right outside-margins
2533This function sets the fringe widthes of window @var{window}. 2534This function sets the fringe widthes of window @var{window}.
diff --git a/lispref/eval.texi b/lispref/eval.texi
index 165889e75ed..fcfde5849dd 100644
--- a/lispref/eval.texi
+++ b/lispref/eval.texi
@@ -319,6 +319,10 @@ This function returns the meaning of @var{function} as a function. If
319definition and starts over with that value. If @var{function} is not a 319definition and starts over with that value. If @var{function} is not a
320symbol, then it returns @var{function} itself. 320symbol, then it returns @var{function} itself.
321 321
322This function signals a @code{void-function} error if the final
323symbol is unbound and a @code{cyclic-function-indirection} error if
324there is a loop in the chain of symbols.
325
322Here is how you could define @code{indirect-function} in Lisp: 326Here is how you could define @code{indirect-function} in Lisp:
323 327
324@smallexample 328@smallexample
@@ -625,32 +629,51 @@ The number of currently active calls to @code{eval} is limited to
625@code{max-lisp-eval-depth} (see below). 629@code{max-lisp-eval-depth} (see below).
626@end defun 630@end defun
627 631
632@anchor{Definition of eval-region}
628@deffn Command eval-region start end &optional stream read-function 633@deffn Command eval-region start end &optional stream read-function
629This function evaluates the forms in the current buffer in the region 634This function evaluates the forms in the current buffer in the region
630defined by the positions @var{start} and @var{end}. It reads forms from 635defined by the positions @var{start} and @var{end}. It reads forms from
631the region and calls @code{eval} on them until the end of the region is 636the region and calls @code{eval} on them until the end of the region is
632reached, or until an error is signaled and not handled. 637reached, or until an error is signaled and not handled.
633 638
634If @var{stream} is non-@code{nil}, the values that result from 639By default, @code{eval-region} does not produce any output. However,
635evaluating the expressions in the region are printed using @var{stream}. 640if @var{stream} is non-@code{nil}, any output produced by output
636@xref{Output Streams}. 641functions (@pxref{Output Functions}), as well as the values that
637 642result from evaluating the expressions in the region are printed using
638If @var{read-function} is non-@code{nil}, it should be a function, which 643@var{stream}. @xref{Output Streams}.
639is used instead of @code{read} to read expressions one by one. This 644
640function is called with one argument, the stream for reading input. You 645If @var{read-function} is non-@code{nil}, it should be a function,
641can also use the variable @code{load-read-function} (@pxref{How Programs 646which is used instead of @code{read} to read expressions one by one.
642Do Loading}) to specify this function, but it is more robust to use the 647This function is called with one argument, the stream for reading
648input. You can also use the variable @code{load-read-function}
649(@pxref{Definition of load-read-function,, How Programs Do Loading})
650to specify this function, but it is more robust to use the
643@var{read-function} argument. 651@var{read-function} argument.
644 652
645@code{eval-region} always returns @code{nil}. 653@code{eval-region} does not move point. It always returns @code{nil}.
646@end deffn 654@end deffn
647 655
648@cindex evaluation of buffer contents 656@cindex evaluation of buffer contents
649@deffn Command eval-current-buffer &optional stream 657@deffn Command eval-buffer &optional buffer-or-name stream filename unibyte print
650This is like @code{eval-region} except that it operates on the whole 658This is similar to @code{eval-region}, but the arguments provide
651buffer. 659different optional features. @code{eval-buffer} operates on the
660entire accessible portion of buffer @var{buffer-or-name}.
661@var{buffer-or-name} can be a buffer, a buffer name (a string), or
662@code{nil} (or omitted), which means to use the current buffer.
663@var{stream} is used as in @code{eval-region}, unless @var{stream} is
664@code{nil} and @var{print} non-@code{nil}. In that case, values that
665result from evaluating the expressions are still discarded, but the
666output of the output functions is printed in the echo area.
667@var{filename} is the file name to use for @code{load-history}
668(@pxref{Unloading}), and defaults to @code{buffer-file-name}
669(@pxref{Buffer File Name}). If @var{unibyte} is non-@code{nil},
670@code{read} converts strings to unibyte whenever possible.
671
672@findex eval-current-buffer
673@code{eval-current-buffer} is an alias for this command.
652@end deffn 674@end deffn
653 675
676@anchor{Definition of max-lisp-eval-depth}
654@defvar max-lisp-eval-depth 677@defvar max-lisp-eval-depth
655This variable defines the maximum depth allowed in calls to @code{eval}, 678This variable defines the maximum depth allowed in calls to @code{eval},
656@code{apply}, and @code{funcall} before an error is signaled (with error 679@code{apply}, and @code{funcall} before an error is signaled (with error
@@ -670,14 +693,17 @@ Entry to the Lisp debugger increases the value, if there is little room
670left, to make sure the debugger itself has room to execute. 693left, to make sure the debugger itself has room to execute.
671 694
672@code{max-specpdl-size} provides another limit on nesting. 695@code{max-specpdl-size} provides another limit on nesting.
673@xref{Local Variables}. 696@xref{Definition of max-specpdl-size,, Local Variables}.
674@end defvar 697@end defvar
675 698
676@defvar values 699@defvar values
677The value of this variable is a list of the values returned by all the 700The value of this variable is a list of the values returned by all the
678expressions that were read, evaluated, and printed from buffers 701expressions that were read, evaluated, and printed from buffers
679(including the minibuffer) by the standard Emacs commands which do this. 702(including the minibuffer) by the standard Emacs commands which do
680The elements are ordered most recent first. 703this. (Note that this does @emph{not} include evaluation in
704@samp{*ielm*} buffers, nor evaluation using @kbd{C-j} in
705@code{lisp-interaction-mode}.) The elements are ordered most recent
706first.
681 707
682@example 708@example
683@group 709@group
diff --git a/lispref/help.texi b/lispref/help.texi
index 7675e38e81e..343ffb66078 100644
--- a/lispref/help.texi
+++ b/lispref/help.texi
@@ -259,6 +259,7 @@ as shown above for the @code{goal-column} variable, means that it is a
259user option; see the description of @code{defvar} in @ref{Defining 259user option; see the description of @code{defvar} in @ref{Defining
260Variables}. 260Variables}.
261 261
262@anchor{Definition of Snarf-documentation}
262@defun Snarf-documentation filename 263@defun Snarf-documentation filename
263This function is used only during Emacs initialization, just before 264This function is used only during Emacs initialization, just before
264the runnable Emacs is dumped. It finds the file offsets of the 265the runnable Emacs is dumped. It finds the file offsets of the
diff --git a/lispref/internals.texi b/lispref/internals.texi
index c8cf5ed0f7c..2a4572560a7 100644
--- a/lispref/internals.texi
+++ b/lispref/internals.texi
@@ -81,8 +81,9 @@ faster. On modern machines, it is usually not advisable.
81 81
82 After @file{loadup.el} reads @file{site-load.el}, it finds the 82 After @file{loadup.el} reads @file{site-load.el}, it finds the
83documentation strings for primitive and preloaded functions (and 83documentation strings for primitive and preloaded functions (and
84variables) in the file @file{etc/DOC} where they are stored, by calling 84variables) in the file @file{etc/DOC} where they are stored, by
85@code{Snarf-documentation} (@pxref{Accessing Documentation}). 85calling @code{Snarf-documentation} (@pxref{Definition of
86Snarf-documentation,, Accessing Documentation}).
86 87
87@cindex @file{site-init.el} 88@cindex @file{site-init.el}
88 You can specify other Lisp expressions to execute just before dumping 89 You can specify other Lisp expressions to execute just before dumping
@@ -151,10 +152,10 @@ preload additional libraries or add features to the standard ones.
151@defun purecopy object 152@defun purecopy object
152This function makes a copy in pure storage of @var{object}, and returns 153This function makes a copy in pure storage of @var{object}, and returns
153it. It copies a string by simply making a new string with the same 154it. It copies a string by simply making a new string with the same
154characters in pure storage. It recursively copies the contents of 155characters, but without text properties, in pure storage. It
155vectors and cons cells. It does not make copies of other objects such 156recursively copies the contents of vectors and cons cells. It does
156as symbols, but just returns them unchanged. It signals an error if 157not make copies of other objects such as symbols, but just returns
157asked to copy markers. 158them unchanged. It signals an error if asked to copy markers.
158 159
159This function is a no-op except while Emacs is being built and dumped; 160This function is a no-op except while Emacs is being built and dumped;
160it is usually called only in the file @file{emacs/lisp/loaddefs.el}, but 161it is usually called only in the file @file{emacs/lisp/loaddefs.el}, but
@@ -367,7 +368,7 @@ until the subsequent garbage collection, at which time
367@code{garbage-collect} will set the threshold back to 10,000. 368@code{garbage-collect} will set the threshold back to 10,000.
368@end defopt 369@end defopt
369 370
370 The value return by @code{garbage-collect} describes the amount of 371 The value returned by @code{garbage-collect} describes the amount of
371memory used by Lisp data, broken down by data type. By contrast, the 372memory used by Lisp data, broken down by data type. By contrast, the
372function @code{memory-limit} provides information on the total amount of 373function @code{memory-limit} provides information on the total amount of
373memory Emacs is currently using. 374memory Emacs is currently using.
@@ -595,9 +596,9 @@ protected in the current function. It is necessary to do this explicitly.
595GC-protected; as long as the object is not recycled, all pointers to 596GC-protected; as long as the object is not recycled, all pointers to
596it remain valid. So if you are sure that a local variable points to 597it remain valid. So if you are sure that a local variable points to
597an object that will be preserved by some other pointer, that local 598an object that will be preserved by some other pointer, that local
598variable does not need a GCPRO. (Formerly, strings were an exception 599variable does not need a @code{GCPRO}. (Formerly, strings were an
599to this rule; in older Emacs versions, every pointer to a string 600exception to this rule; in older Emacs versions, every pointer to a
600needed to be marked by GC.) 601string needed to be marked by GC.)
601 602
602 The macro @code{GCPRO1} protects just one local variable. If you 603 The macro @code{GCPRO1} protects just one local variable. If you
603want to protect two, use @code{GCPRO2} instead; repeating 604want to protect two, use @code{GCPRO2} instead; repeating
@@ -612,7 +613,7 @@ Alas, we can't explain all the tricky details here.
612accept two arguments at the C level: the number of Lisp arguments, and 613accept two arguments at the C level: the number of Lisp arguments, and
613a @code{Lisp_Object *} pointer to a C vector containing those Lisp 614a @code{Lisp_Object *} pointer to a C vector containing those Lisp
614arguments. This C vector may be part of a Lisp vector, but it need 615arguments. This C vector may be part of a Lisp vector, but it need
615not be. The responsibility for using GCPRO to protecting the Lisp 616not be. The responsibility for using @code{GCPRO} to protect the Lisp
616arguments from GC if necessary rests with the caller in this case, 617arguments from GC if necessary rests with the caller in this case,
617since the caller allocated or found the storage for them. 618since the caller allocated or found the storage for them.
618 619
@@ -651,6 +652,7 @@ file, add to it a @code{syms_of_@var{filename}} (e.g.,
651of these functions are called, and add a call to 652of these functions are called, and add a call to
652@code{syms_of_@var{filename}} there. 653@code{syms_of_@var{filename}} there.
653 654
655@anchor{Defining Lisp variables in C}
654@vindex byte-boolean-vars 656@vindex byte-boolean-vars
655 The function @code{syms_of_@var{filename}} is also the place to define 657 The function @code{syms_of_@var{filename}} is also the place to define
656any C variables that are to be visible as Lisp variables. 658any C variables that are to be visible as Lisp variables.
@@ -761,9 +763,9 @@ knows about it.
761data are stored in a heap and the only access that programs have to it 763data are stored in a heap and the only access that programs have to it
762is through pointers. Pointers are thirty-two bits wide in most 764is through pointers. Pointers are thirty-two bits wide in most
763implementations. Depending on the operating system and type of machine 765implementations. Depending on the operating system and type of machine
764for which you compile Emacs, twenty-eight bits are used to address the 766for which you compile Emacs, twenty-nine bits are used to address the
765object, and the remaining four bits are used for a GC mark bit and the 767object, and the remaining three bits are used for the tag that
766tag that identifies the object's type. 768identifies the object's type.
767 769
768 Because Lisp objects are represented as tagged pointers, it is always 770 Because Lisp objects are represented as tagged pointers, it is always
769possible to determine the Lisp data type of any object. The C data type 771possible to determine the Lisp data type of any object. The C data type
diff --git a/lispref/loading.texi b/lispref/loading.texi
index 0865914c45d..e171fc70fdf 100644
--- a/lispref/loading.texi
+++ b/lispref/loading.texi
@@ -140,6 +140,7 @@ This variable is non-@code{nil} if Emacs is in the process of loading a
140file, and it is @code{nil} otherwise. 140file, and it is @code{nil} otherwise.
141@end defvar 141@end defvar
142 142
143@anchor{Definition of load-read-function}
143@defvar load-read-function 144@defvar load-read-function
144This variable specifies an alternate expression-reading function for 145This variable specifies an alternate expression-reading function for
145@code{load} and @code{eval-region} to use instead of @code{read}. 146@code{load} and @code{eval-region} to use instead of @code{read}.
@@ -150,7 +151,7 @@ functions should use @code{read}.
150 151
151Instead of using this variable, it is cleaner to use another, newer 152Instead of using this variable, it is cleaner to use another, newer
152feature: to pass the function as the @var{read-function} argument to 153feature: to pass the function as the @var{read-function} argument to
153@code{eval-region}. @xref{Eval}. 154@code{eval-region}. @xref{Definition of eval-region,, Eval}.
154@end defvar 155@end defvar
155 156
156 For information about how @code{load} is used in building Emacs, see 157 For information about how @code{load} is used in building Emacs, see
diff --git a/lispref/nonascii.texi b/lispref/nonascii.texi
index 72dd46d19eb..e66c7d15757 100644
--- a/lispref/nonascii.texi
+++ b/lispref/nonascii.texi
@@ -96,13 +96,15 @@ default value to @code{nil} early in startup.
96@defun position-bytes position 96@defun position-bytes position
97@tindex position-bytes 97@tindex position-bytes
98Return the byte-position corresponding to buffer position @var{position} 98Return the byte-position corresponding to buffer position @var{position}
99in the current buffer. 99in the current buffer. If @var{position} is out of range, the value
100is @code{nil}.
100@end defun 101@end defun
101 102
102@defun byte-to-position byte-position 103@defun byte-to-position byte-position
103@tindex byte-to-position 104@tindex byte-to-position
104Return the buffer position corresponding to byte-position 105Return the buffer position corresponding to byte-position
105@var{byte-position} in the current buffer. 106@var{byte-position} in the current buffer. If @var{byte-position} is
107out of range, the value is @code{nil}.
106@end defun 108@end defun
107 109
108@defun multibyte-string-p string 110@defun multibyte-string-p string
@@ -173,6 +175,9 @@ multibyte character. The value should be a char-table, or @code{nil}.
173If this is non-@code{nil}, it overrides @code{nonascii-insert-offset}. 175If this is non-@code{nil}, it overrides @code{nonascii-insert-offset}.
174@end defvar 176@end defvar
175 177
178The next three functions either return the argument @var{string}, or a
179newly created string with no text properties.
180
176@defun string-make-unibyte string 181@defun string-make-unibyte string
177This function converts the text of @var{string} to unibyte 182This function converts the text of @var{string} to unibyte
178representation, if it isn't already, and returns the result. If 183representation, if it isn't already, and returns the result. If
@@ -186,15 +191,23 @@ fails, this function takes just the low 8 bits of each character.
186@defun string-make-multibyte string 191@defun string-make-multibyte string
187This function converts the text of @var{string} to multibyte 192This function converts the text of @var{string} to multibyte
188representation, if it isn't already, and returns the result. If 193representation, if it isn't already, and returns the result. If
189@var{string} is a multibyte string, it is returned unchanged. 194@var{string} is a multibyte string or consists entirely of
190The function @code{unibyte-char-to-multibyte} is used to convert 195@acronym{ASCII} characters, it is returned unchanged. In particular,
191each unibyte character to a multibyte character. 196if @var{string} is unibyte and entirely @acronym{ASCII}, the returned
197string is unibyte. (When the characters are all @acronym{ASCII},
198Emacs primitives will treat the string the same way whether it is
199unibyte or multibyte.) If @var{string} is unibyte and contains
200non-@acronym{ASCII} characters, the function
201@code{unibyte-char-to-multibyte} is used to convert each unibyte
202character to a multibyte character.
192@end defun 203@end defun
193 204
194@defun string-to-multibyte string 205@defun string-to-multibyte string
195This function returns a multibyte string containing the same sequence 206This function returns a multibyte string containing the same sequence
196of character codes as @var{string}. If @var{string} is a multibyte 207of character codes as @var{string}. Unlike
197string, the value is the equal to @var{string}. 208@code{string-make-multibyte}, this function unconditionally returns a
209multibyte string. If @var{string} is a multibyte string, it is
210returned unchanged.
198@end defun 211@end defun
199 212
200@node Selecting a Representation 213@node Selecting a Representation
@@ -280,8 +293,8 @@ text representations.
280@end example 293@end example
281 294
282If the optional argument @var{genericp} is non-@code{nil}, this 295If the optional argument @var{genericp} is non-@code{nil}, this
283function returns @code{t} if @var{charcode} is a generic character 296function also returns @code{t} if @var{charcode} is a generic
284(@pxref{Splitting Characters}). 297character (@pxref{Splitting Characters}).
285@end defun 298@end defun
286 299
287@node Character Sets 300@node Character Sets
@@ -311,13 +324,19 @@ Returns @code{t} if @var{object} is a symbol that names a character set,
311@code{nil} otherwise. 324@code{nil} otherwise.
312@end defun 325@end defun
313 326
327@defvar charset-list
328The value is a list of all defined character set names.
329@end defvar
330
314@defun charset-list 331@defun charset-list
315This function returns a list of all defined character set names. 332This function returns the value of @code{charset-list}. It is only
333provided for backward compatibility.
316@end defun 334@end defun
317 335
318@defun char-charset character 336@defun char-charset character
319This function returns the name of the character set that @var{character} 337This function returns the name of the character set that @var{character}
320belongs to. 338belongs to, or the symbol @code{unknown} if @var{character} is not a
339valid character.
321@end defun 340@end defun
322 341
323@defun charset-plist charset 342@defun charset-plist charset
@@ -378,6 +397,9 @@ Return a list containing the name of the character set of
378identify @var{character} within that character set. The number of byte 397identify @var{character} within that character set. The number of byte
379values is the character set's dimension. 398values is the character set's dimension.
380 399
400If @var{character} is invalid as a character code, @code{split-char}
401returns a list consisting of the symbol @code{unknown} and @var{character}.
402
381@example 403@example
382(split-char 2248) 404(split-char 2248)
383 @result{} (latin-iso8859-1 72) 405 @result{} (latin-iso8859-1 72)
@@ -463,11 +485,11 @@ current buffer.
463@cindex character translation tables 485@cindex character translation tables
464@cindex translation tables 486@cindex translation tables
465 487
466 A @dfn{translation table} specifies a mapping of characters 488 A @dfn{translation table} is a char-table that specifies a mapping
467into characters. These tables are used in encoding and decoding, and 489of characters into characters. These tables are used in encoding and
468for other purposes. Some coding systems specify their own particular 490decoding, and for other purposes. Some coding systems specify their
469translation tables; there are also default translation tables which 491own particular translation tables; there are also default translation
470apply to all other coding systems. 492tables which apply to all other coding systems.
471 493
472@defun make-translation-table &rest translations 494@defun make-translation-table &rest translations
473This function returns a translation table based on the argument 495This function returns a translation table based on the argument
@@ -483,24 +505,30 @@ character, say @var{to-alt}, @var{from} is also translated to
483You can also map one whole character set into another character set with 505You can also map one whole character set into another character set with
484the same dimension. To do this, you specify a generic character (which 506the same dimension. To do this, you specify a generic character (which
485designates a character set) for @var{from} (@pxref{Splitting Characters}). 507designates a character set) for @var{from} (@pxref{Splitting Characters}).
486In this case, @var{to} should also be a generic character, for another 508In this case, if @var{to} is also a generic character, its character
487character set of the same dimension. Then the translation table 509set should have the same dimension as @var{from}'s. Then the
488translates each character of @var{from}'s character set into the 510translation table translates each character of @var{from}'s character
489corresponding character of @var{to}'s character set. 511set into the corresponding character of @var{to}'s character set. If
512@var{from} is a generic character and @var{to} is an ordinary
513character, then the translation table translates every character of
514@var{from}'s character set into @var{to}.
490@end defun 515@end defun
491 516
492 In decoding, the translation table's translations are applied to the 517 In decoding, the translation table's translations are applied to the
493characters that result from ordinary decoding. If a coding system has 518characters that result from ordinary decoding. If a coding system has
494property @code{character-translation-table-for-decode}, that specifies 519property @code{translation-table-for-decode}, that specifies the
495the translation table to use. Otherwise, if 520translation table to use. (This is a property of the coding system,
496@code{standard-translation-table-for-decode} is non-@code{nil}, decoding 521as returned by @code{coding-system-get}, not a property of the symbol
497uses that table. 522that is the coding system's name. @xref{Coding System Basics,, Basic
523Concepts of Coding Systems}.) Otherwise, if
524@code{standard-translation-table-for-decode} is non-@code{nil},
525decoding uses that table.
498 526
499 In encoding, the translation table's translations are applied to the 527 In encoding, the translation table's translations are applied to the
500characters in the buffer, and the result of translation is actually 528characters in the buffer, and the result of translation is actually
501encoded. If a coding system has property 529encoded. If a coding system has property
502@code{character-translation-table-for-encode}, that specifies the 530@code{translation-table-for-encode}, that specifies the translation
503translation table to use. Otherwise the variable 531table to use. Otherwise the variable
504@code{standard-translation-table-for-encode} specifies the translation 532@code{standard-translation-table-for-encode} specifies the translation
505table. 533table.
506 534
@@ -516,7 +544,8 @@ coding systems that don't specify any other translation table.
516 544
517@defvar translation-table-for-input 545@defvar translation-table-for-input
518Self-inserting characters are translated through this translation 546Self-inserting characters are translated through this translation
519table before they are inserted. 547table before they are inserted. This variable automatically becomes
548buffer-local when set.
520@end defvar 549@end defvar
521 550
522@node Coding Systems 551@node Coding Systems
@@ -686,7 +715,7 @@ systems as well.
686 715
687@defun coding-system-p object 716@defun coding-system-p object
688This function returns @code{t} if @var{object} is a coding system 717This function returns @code{t} if @var{object} is a coding system
689name. 718name or @code{nil}.
690@end defun 719@end defun
691 720
692@defun check-coding-system coding-system 721@defun check-coding-system coding-system
@@ -701,6 +730,9 @@ except for its eol conversion, which is specified by @code{eol-type}.
701@var{eol-type} should be @code{unix}, @code{dos}, @code{mac}, or 730@var{eol-type} should be @code{unix}, @code{dos}, @code{mac}, or
702@code{nil}. If it is @code{nil}, the returned coding system determines 731@code{nil}. If it is @code{nil}, the returned coding system determines
703the end-of-line conversion from the data. 732the end-of-line conversion from the data.
733
734@var{eol-type} may also be 0, 1 or 2, standing for @code{unix},
735@code{dos} and @code{mac}, respectively.
704@end defun 736@end defun
705 737
706@defun coding-system-change-text-conversion eol-coding text-coding 738@defun coding-system-change-text-conversion eol-coding text-coding
@@ -745,55 +777,79 @@ return value is just one coding system, the one that is highest in
745priority. 777priority.
746 778
747If the region contains only @acronym{ASCII} characters, the value 779If the region contains only @acronym{ASCII} characters, the value
748is @code{undecided} or @code{(undecided)}. 780is @code{undecided} or @code{(undecided)}, or a variant specifying
781end-of-line conversion, if that can be deduced from the text.
749@end defun 782@end defun
750 783
751@defun detect-coding-string string highest 784@defun detect-coding-string string &optional highest
752This function is like @code{detect-coding-region} except that it 785This function is like @code{detect-coding-region} except that it
753operates on the contents of @var{string} instead of bytes in the buffer. 786operates on the contents of @var{string} instead of bytes in the buffer.
754@end defun 787@end defun
755 788
756 @xref{Process Information}, for how to examine or set the coding 789 @xref{Coding systems for a subprocess,, Process Information}, in
757systems used for I/O to a subprocess. 790particular the description of the functions
791@code{process-coding-system} and @code{set-process-coding-system}, for
792how to examine or set the coding systems used for I/O to a subprocess.
758 793
759@node User-Chosen Coding Systems 794@node User-Chosen Coding Systems
760@subsection User-Chosen Coding Systems 795@subsection User-Chosen Coding Systems
761 796
762@cindex select safe coding system 797@cindex select safe coding system
763@defun select-safe-coding-system from to &optional default-coding-system accept-default-p 798@defun select-safe-coding-system from to &optional default-coding-system accept-default-p file
764This function selects a coding system for encoding specified text, 799This function selects a coding system for encoding specified text,
765asking the user to choose if necessary. Normally the specified text 800asking the user to choose if necessary. Normally the specified text
766is the text in the current buffer between @var{from} and @var{to}, 801is the text in the current buffer between @var{from} and @var{to}. If
767defaulting to the whole buffer if they are @code{nil}. If @var{from} 802@var{from} is a string, the string specifies the text to encode, and
768is a string, the string specifies the text to encode, and @var{to} is 803@var{to} is ignored.
769ignored.
770 804
771If @var{default-coding-system} is non-@code{nil}, that is the first 805If @var{default-coding-system} is non-@code{nil}, that is the first
772coding system to try; if that can handle the text, 806coding system to try; if that can handle the text,
773@code{select-safe-coding-system} returns that coding system. It can 807@code{select-safe-coding-system} returns that coding system. It can
774also be a list of coding systems; then the function tries each of them 808also be a list of coding systems; then the function tries each of them
775one by one. After trying all of them, it next tries the user's most 809one by one. After trying all of them, it next tries the current
776preferred coding system (@pxref{Recognize Coding, 810buffer's value of @code{buffer-file-coding-system} (if it is not
777prefer-coding-system, the description of @code{prefer-coding-system}, 811@code{undecided}), then the value of
778emacs, GNU Emacs Manual}), and after that the current buffer's value 812@code{default-buffer-file-coding-system} and finally the user's most
779of @code{buffer-file-coding-system} (if it is not @code{undecided}). 813preferred coding system, which the user can set using the command
814@code{prefer-coding-system} (@pxref{Recognize Coding,, Recognizing
815Coding Systems, emacs, The GNU Emacs Manual}).
780 816
781If one of those coding systems can safely encode all the specified 817If one of those coding systems can safely encode all the specified
782text, @code{select-safe-coding-system} chooses it and returns it. 818text, @code{select-safe-coding-system} chooses it and returns it.
783Otherwise, it asks the user to choose from a list of coding systems 819Otherwise, it asks the user to choose from a list of coding systems
784which can encode all the text, and returns the user's choice. 820which can encode all the text, and returns the user's choice.
785 821
822@var{default-coding-system} can also be a list whose first element is
823t and whose other elements are coding systems. Then, if no coding
824system in the list can handle the text, @code{select-safe-coding-system}
825queries the user immediately, without trying any of the three
826alternatives described above.
827
786The optional argument @var{accept-default-p}, if non-@code{nil}, 828The optional argument @var{accept-default-p}, if non-@code{nil},
787should be a function to determine whether the coding system selected 829should be a function to determine whether a coding system selected
788without user interaction is acceptable. If this function returns 830without user interaction is acceptable. @code{select-safe-coding-system}
789@code{nil}, the silently selected coding system is rejected, and the 831calls this function with one argument, the base coding system of the
790user is asked to select a coding system from a list of possible 832selected coding system. If @var{accept-default-p} returns @code{nil},
791candidates. 833@code{select-safe-coding-system} rejects the silently selected coding
834system, and asks the user to select a coding system from a list of
835possible candidates.
792 836
793@vindex select-safe-coding-system-accept-default-p 837@vindex select-safe-coding-system-accept-default-p
794If the variable @code{select-safe-coding-system-accept-default-p} is 838If the variable @code{select-safe-coding-system-accept-default-p} is
795non-@code{nil}, its value overrides the value of 839non-@code{nil}, its value overrides the value of
796@var{accept-default-p}. 840@var{accept-default-p}.
841
842As a final step, before returning the chosen coding system,
843@code{select-safe-coding-system} checks whether that coding system is
844consistent with what would be selected if the contents of the region
845were read from a file. (If not, this could lead to data corruption in
846a file subsequently re-visited and edited.) Normally,
847@code{select-safe-coding-system} uses @code{buffer-file-name} as the
848file for this purpose, but if @var{file} is non-@code{nil}, it uses
849that file instead (this can be relevant for @code{write-region} and
850similar functions). If it detects an apparent inconsistency,
851@code{select-safe-coding-system} queries the user before selecting the
852coding system.
797@end defun 853@end defun
798 854
799 Here are two functions you can use to let the user specify a coding 855 Here are two functions you can use to let the user specify a coding
@@ -846,17 +902,19 @@ reading and writing particular files. Each element has the form
846expression that matches certain file names. The element applies to file 902expression that matches certain file names. The element applies to file
847names that match @var{pattern}. 903names that match @var{pattern}.
848 904
849The @acronym{CDR} of the element, @var{coding}, should be either a coding 905The @sc{cdr} of the element, @var{coding}, should be either a coding
850system, a cons cell containing two coding systems, or a function name (a 906system, a cons cell containing two coding systems, or a function name (a
851symbol with a function definition). If @var{coding} is a coding system, 907symbol with a function definition). If @var{coding} is a coding system,
852that coding system is used for both reading the file and writing it. If 908that coding system is used for both reading the file and writing it. If
853@var{coding} is a cons cell containing two coding systems, its @acronym{CAR} 909@var{coding} is a cons cell containing two coding systems, its @sc{car}
854specifies the coding system for decoding, and its @acronym{cdr} specifies the 910specifies the coding system for decoding, and its @sc{cdr} specifies the
855coding system for encoding. 911coding system for encoding.
856 912
857If @var{coding} is a function name, the function must return a coding 913If @var{coding} is a function name, the function should take one
858system or a cons cell containing two coding systems. This value is used 914argument, a list of all arguments passed to
859as described above. 915@code{find-operation-coding-system}. It must return a coding system
916or a cons cell containing two coding systems. This value has the same
917meaning as described above.
860@end defvar 918@end defvar
861 919
862@defvar process-coding-system-alist 920@defvar process-coding-system-alist
@@ -923,7 +981,7 @@ performing @var{operation} with @var{arguments}. The value has this
923form: 981form:
924 982
925@example 983@example
926(@var{decoding-system} @var{encoding-system}) 984(@var{decoding-system} . @var{encoding-system})
927@end example 985@end example
928 986
929The first element, @var{decoding-system}, is the coding system to use 987The first element, @var{decoding-system}, is the coding system to use
@@ -948,7 +1006,6 @@ or port number.
948This function looks up the target in @code{file-coding-system-alist}, 1006This function looks up the target in @code{file-coding-system-alist},
949@code{process-coding-system-alist}, or 1007@code{process-coding-system-alist}, or
950@code{network-coding-system-alist}, depending on @var{operation}. 1008@code{network-coding-system-alist}, depending on @var{operation}.
951@xref{Default Coding Systems}.
952@end defun 1009@end defun
953 1010
954@node Specifying Coding Systems 1011@node Specifying Coding Systems
@@ -1040,33 +1097,41 @@ decoding functions produce sequences of bytes; the encoding functions
1040are meant to operate on sequences of bytes. All of these functions 1097are meant to operate on sequences of bytes. All of these functions
1041discard text properties. 1098discard text properties.
1042 1099
1043@defun encode-coding-region start end coding-system 1100@deffn Command encode-coding-region start end coding-system
1044This function encodes the text from @var{start} to @var{end} according 1101This command encodes the text from @var{start} to @var{end} according
1045to coding system @var{coding-system}. The encoded text replaces the 1102to coding system @var{coding-system}. The encoded text replaces the
1046original text in the buffer. The result of encoding is logically a 1103original text in the buffer. The result of encoding is logically a
1047sequence of bytes, but the buffer remains multibyte if it was multibyte 1104sequence of bytes, but the buffer remains multibyte if it was multibyte
1048before. 1105before.
1049@end defun
1050 1106
1051@defun encode-coding-string string coding-system 1107This command returns the length of the encoded text.
1108@end deffn
1109
1110@defun encode-coding-string string coding-system &optional nocopy
1052This function encodes the text in @var{string} according to coding 1111This function encodes the text in @var{string} according to coding
1053system @var{coding-system}. It returns a new string containing the 1112system @var{coding-system}. It returns a new string containing the
1054encoded text. The result of encoding is a unibyte string. 1113encoded text, except when @var{nocopy} is non-@code{nil}, in which
1114case the function may return @var{string} itself if the encoding
1115operation is trivial. The result of encoding is a unibyte string.
1055@end defun 1116@end defun
1056 1117
1057@defun decode-coding-region start end coding-system 1118@deffn Command decode-coding-region start end coding-system
1058This function decodes the text from @var{start} to @var{end} according 1119This command decodes the text from @var{start} to @var{end} according
1059to coding system @var{coding-system}. The decoded text replaces the 1120to coding system @var{coding-system}. The decoded text replaces the
1060original text in the buffer. To make explicit decoding useful, the text 1121original text in the buffer. To make explicit decoding useful, the text
1061before decoding ought to be a sequence of byte values, but both 1122before decoding ought to be a sequence of byte values, but both
1062multibyte and unibyte buffers are acceptable. 1123multibyte and unibyte buffers are acceptable.
1063@end defun
1064 1124
1065@defun decode-coding-string string coding-system 1125This command returns the length of the decoded text.
1126@end deffn
1127
1128@defun decode-coding-string string coding-system &optional nocopy
1066This function decodes the text in @var{string} according to coding 1129This function decodes the text in @var{string} according to coding
1067system @var{coding-system}. It returns a new string containing the 1130system @var{coding-system}. It returns a new string containing the
1068decoded text. To make explicit decoding useful, the contents of 1131decoded text, except when @var{nocopy} is non-@code{nil}, in which
1069@var{string} ought to be a sequence of byte values, but a multibyte 1132case the function may return @var{string} itself if the decoding
1133operation is trivial. To make explicit decoding useful, the contents
1134of @var{string} ought to be a sequence of byte values, but a multibyte
1070string is acceptable. 1135string is acceptable.
1071@end defun 1136@end defun
1072 1137
@@ -1095,22 +1160,22 @@ This function returns the coding system that is in use for decoding
1095keyboard input---or @code{nil} if no coding system is to be used. 1160keyboard input---or @code{nil} if no coding system is to be used.
1096@end defun 1161@end defun
1097 1162
1098@defun set-keyboard-coding-system coding-system 1163@deffn Command set-keyboard-coding-system coding-system
1099This function specifies @var{coding-system} as the coding system to 1164This command specifies @var{coding-system} as the coding system to
1100use for decoding keyboard input. If @var{coding-system} is @code{nil}, 1165use for decoding keyboard input. If @var{coding-system} is @code{nil},
1101that means do not decode keyboard input. 1166that means do not decode keyboard input.
1102@end defun 1167@end deffn
1103 1168
1104@defun terminal-coding-system 1169@defun terminal-coding-system
1105This function returns the coding system that is in use for encoding 1170This function returns the coding system that is in use for encoding
1106terminal output---or @code{nil} for no encoding. 1171terminal output---or @code{nil} for no encoding.
1107@end defun 1172@end defun
1108 1173
1109@defun set-terminal-coding-system coding-system 1174@deffn Command set-terminal-coding-system coding-system
1110This function specifies @var{coding-system} as the coding system to use 1175This command specifies @var{coding-system} as the coding system to use
1111for encoding terminal output. If @var{coding-system} is @code{nil}, 1176for encoding terminal output. If @var{coding-system} is @code{nil},
1112that means do not encode terminal output. 1177that means do not encode terminal output.
1113@end defun 1178@end deffn
1114 1179
1115@node MS-DOS File Types 1180@node MS-DOS File Types
1116@subsection MS-DOS File Types 1181@subsection MS-DOS File Types
@@ -1193,18 +1258,18 @@ in any fashion.) It is @code{nil} if no input method is active in the
1193buffer now. 1258buffer now.
1194@end defvar 1259@end defvar
1195 1260
1196@defvar default-input-method 1261@defopt default-input-method
1197This variable holds the default input method for commands that choose an 1262This variable holds the default input method for commands that choose an
1198input method. Unlike @code{current-input-method}, this variable is 1263input method. Unlike @code{current-input-method}, this variable is
1199normally global. 1264normally global.
1200@end defvar 1265@end defopt
1201 1266
1202@defun set-input-method input-method 1267@deffn Command set-input-method input-method
1203This function activates input method @var{input-method} for the current 1268This command activates input method @var{input-method} for the current
1204buffer. It also sets @code{default-input-method} to @var{input-method}. 1269buffer. It also sets @code{default-input-method} to @var{input-method}.
1205If @var{input-method} is @code{nil}, this function deactivates any input 1270If @var{input-method} is @code{nil}, this command deactivates any input
1206method for the current buffer. 1271method for the current buffer.
1207@end defun 1272@end deffn
1208 1273
1209@defun read-input-method-name prompt &optional default inhibit-null 1274@defun read-input-method-name prompt &optional default inhibit-null
1210This function reads an input method name with the minibuffer, prompting 1275This function reads an input method name with the minibuffer, prompting
@@ -1240,7 +1305,8 @@ it is good for.
1240@end defvar 1305@end defvar
1241 1306
1242 The fundamental interface to input methods is through the 1307 The fundamental interface to input methods is through the
1243variable @code{input-method-function}. @xref{Reading One Event}. 1308variable @code{input-method-function}. @xref{Reading One Event},
1309and @ref{Invoking the Input Method}.
1244 1310
1245@node Locales 1311@node Locales
1246@section Locales 1312@section Locales
@@ -1294,14 +1360,14 @@ through @code{MON_12}).
1294 1360
1295@item paper 1361@item paper
1296Return a list @code{(@var{width} @var{height})} for the default paper 1362Return a list @code{(@var{width} @var{height})} for the default paper
1297size measured in milimeters (locale items @code{PAPER_WIDTH} and 1363size measured in millimeters (locale items @code{PAPER_WIDTH} and
1298@code{PAPER_HEIGHT}). 1364@code{PAPER_HEIGHT}).
1299@end table 1365@end table
1300 1366
1301If the system can't provide the requested information, or if 1367If the system can't provide the requested information, or if
1302@var{item} is not one of those symbols, the value is @code{nil}. All 1368@var{item} is not one of those symbols, the value is @code{nil}. All
1303strings in the return value are decoded using 1369strings in the return value are decoded using
1304@code{locale-coding-system}. @xref{Locales,,, libc, GNU Libc Manual}, 1370@code{locale-coding-system}. @xref{Locales,,, libc, The GNU Libc Manual},
1305for more information about locales and locale items. 1371for more information about locales and locale items.
1306@end defun 1372@end defun
1307 1373
diff --git a/lispref/objects.texi b/lispref/objects.texi
index 4c905cb969e..6cb5adb72b8 100644
--- a/lispref/objects.texi
+++ b/lispref/objects.texi
@@ -42,7 +42,9 @@ it as a number; Lisp knows it is a vector, not a number.
42variable, and the type is known by the compiler but not represented in 42variable, and the type is known by the compiler but not represented in
43the data. Such type declarations do not exist in Emacs Lisp. A Lisp 43the data. Such type declarations do not exist in Emacs Lisp. A Lisp
44variable can have any type of value, and it remembers whatever value 44variable can have any type of value, and it remembers whatever value
45you store in it, type and all. 45you store in it, type and all. (Actually, a small number of Emacs
46Lisp variables can only take on values of a certain type.
47@xref{Variables with Restricted Values}.)
46 48
47 This chapter describes the purpose, printed representation, and read 49 This chapter describes the purpose, printed representation, and read
48syntax of each of the standard types in GNU Emacs Lisp. Details on how 50syntax of each of the standard types in GNU Emacs Lisp. Details on how
diff --git a/lispref/processes.texi b/lispref/processes.texi
index c991cf300e3..8e32962de67 100644
--- a/lispref/processes.texi
+++ b/lispref/processes.texi
@@ -676,6 +676,7 @@ instead of a terminal (see @code{process-connection-type} in
676@ref{Asynchronous Processes}). 676@ref{Asynchronous Processes}).
677@end defun 677@end defun
678 678
679@anchor{Coding systems for a subprocess}
679@defun process-coding-system process 680@defun process-coding-system process
680This function returns a cons cell describing the coding systems in use 681This function returns a cons cell describing the coding systems in use
681for decoding output from @var{process} and for encoding input to 682for decoding output from @var{process} and for encoding input to
diff --git a/lispref/tips.texi b/lispref/tips.texi
index 1b40685ba5d..ec53dc420dd 100644
--- a/lispref/tips.texi
+++ b/lispref/tips.texi
@@ -647,6 +647,7 @@ The argument FOO can be either a number
647This prevents the open-parenthesis from being treated as the start of a 647This prevents the open-parenthesis from being treated as the start of a
648defun (@pxref{Defuns,, Defuns, emacs, The GNU Emacs Manual}). 648defun (@pxref{Defuns,, Defuns, emacs, The GNU Emacs Manual}).
649 649
650@anchor{Docstring hyperlinks}
650@item 651@item
651@iftex 652@iftex
652When a documentation string refers to a Lisp symbol, write it as it 653When a documentation string refers to a Lisp symbol, write it as it
diff --git a/lispref/variables.texi b/lispref/variables.texi
index 36cc2e47fe4..bbe7358b5d7 100644
--- a/lispref/variables.texi
+++ b/lispref/variables.texi
@@ -43,6 +43,8 @@ variable.
43* Future Local Variables:: New kinds of local values we might add some day. 43* Future Local Variables:: New kinds of local values we might add some day.
44* Variable Aliases:: Variables that are aliases for other variables. 44* Variable Aliases:: Variables that are aliases for other variables.
45* File Local Variables:: Handling local variable lists in files. 45* File Local Variables:: Handling local variable lists in files.
46* Variables with Restricted Values:: Non-constant variables whose value can
47 @emph{not} be an arbitrary Lisp object.
46@end menu 48@end menu
47 49
48@node Global Variables 50@node Global Variables
@@ -258,19 +260,21 @@ These kinds of bindings work somewhat like ordinary local bindings, but
258they are localized depending on ``where'' you are in Emacs, rather than 260they are localized depending on ``where'' you are in Emacs, rather than
259localized in time. 261localized in time.
260 262
263@anchor{Definition of max-specpdl-size}
261@defvar max-specpdl-size 264@defvar max-specpdl-size
262@cindex variable limit error 265@cindex variable limit error
263@cindex evaluation error 266@cindex evaluation error
264@cindex infinite recursion 267@cindex infinite recursion
265This variable defines the limit on the total number of local variable 268This variable defines the limit on the total number of local variable
266bindings and @code{unwind-protect} cleanups (@pxref{Nonlocal Exits}) 269bindings and @code{unwind-protect} cleanups (@pxref{Cleanups,,
267that are allowed before signaling an error (with data @code{"Variable 270Cleaning Up from Nonlocal Exits}) that are allowed before signaling an
268binding depth exceeds max-specpdl-size"}). 271error (with data @code{"Variable binding depth exceeds
272max-specpdl-size"}).
269 273
270This limit, with the associated error when it is exceeded, is one way 274This limit, with the associated error when it is exceeded, is one way
271that Lisp avoids infinite recursion on an ill-defined function. 275that Lisp avoids infinite recursion on an ill-defined function.
272@code{max-lisp-eval-depth} provides another limit on depth of nesting. 276@code{max-lisp-eval-depth} provides another limit on depth of nesting.
273@xref{Eval}. 277@xref{Definition of max-lisp-eval-depth,, Eval}.
274 278
275The default value is 600. Entry to the Lisp debugger increases the 279The default value is 600. Entry to the Lisp debugger increases the
276value, if there is little room left, to make sure the debugger itself 280value, if there is little room left, to make sure the debugger itself
@@ -1813,6 +1817,41 @@ could include functions to call. So Emacs discards all text
1813properties from string values specified in a file's local variables 1817properties from string values specified in a file's local variables
1814list. 1818list.
1815 1819
1820@node Variables with Restricted Values
1821@section Variables with Restricted Values
1822
1823 Ordinary Lisp variables can be assigned any value that is a valid
1824Lisp object. However, certain Lisp variables are not defined in Lisp,
1825but in C. Most of these variables are defined in the C code using
1826@code{DEFVAR_LISP}. Like variables defined in Lisp, these can take on
1827any value. However, some variables are defined using
1828@code{DEFVAR_INT} or @code{DEFVAR_BOOL}. @xref{Defining Lisp
1829variables in C,, Writing Emacs Primitives}, in particular the
1830description of functions of the type @code{syms_of_@var{filename}},
1831for a brief discussion of the C implementation.
1832
1833 Variables of type @code{DEFVAR_BOOL} can only take on the values
1834@code{nil} or @code{t}. Attempting to assign them any other value
1835will set them to @code{t}:
1836
1837@example
1838(let ((display-hourglass 5))
1839 display-hourglass)
1840 @result{} t
1841@end example
1842
1843@defvar byte-boolean-vars
1844This variable holds a list of all variables of type @code{DEFVAR_BOOL}.
1845@end defvar
1846
1847 Variables of type @code{DEFVAR_INT} can only take on integer values.
1848Attempting to assign them any other value will result in an error:
1849
1850@example
1851(setq window-min-height 5.0)
1852@error{} Wrong type argument: integerp, 5.0
1853@end example
1854
1816@ignore 1855@ignore
1817 arch-tag: 5ff62c44-2b51-47bb-99d4-fea5aeec5d3e 1856 arch-tag: 5ff62c44-2b51-47bb-99d4-fea5aeec5d3e
1818@end ignore 1857@end ignore
diff --git a/src/ChangeLog b/src/ChangeLog
index 4adadd84db1..53cc3b8ad2f 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,94 @@
12003-12-28 Kim F. Storm <storm@cua.dk>
2
3 * Makefile.in (eval.o): Depend on dispextern.h.
4
5 * dispnew.c (buffer_posn_from_coords): Fix calculation of dy for
6 image glyph using image's ascent.
7 (mode_line_string): Return image glyph as object clicked on.
8 Adjust y0 for image glyph using image's ascent.
9
10 * dispextern.h (FACE_ID_BITS, MAX_FACE_ID): New defines.
11 (struct glyph): New members, ascent and descent. Used to save
12 this glyph's ascent and descent, instead of having.
13 (struct glyph): Declare member face_id using FACE_ID_BITS.
14 (find_hot_spot): Add prototype.
15
16 * keyboard.c (Qimage): Remove extern (now in lisp.h).
17 (QCmap): Declare extern.
18 (make_lispy_position): When position is inside image hot-spot,
19 use hot-spot element's id as posn element.
20
21 * lisp.h (IMAGEP): New macro to test for image object type.
22 (Qimage): Declare extern.
23
24 * macfns.c (Qimage): Remove extern (now in lisp.h).
25 (valid_image_p, parse_image_spec): Use IMAGEP macro.
26
27 * macterm.c (Qface, Qmouse_face): Remove unused externs.
28
29 * w32fns.c (Qimage): Remove extern (now in lisp.h).
30 (valid_image_p, parse_image_spec): Use IMAGEP macro.
31
32 * w32menu.c (Qmouse_click, Qevent_kind): Remove unused externs.
33
34 * w32term.c (Qface, Qmouse_face): Remove unused externs.
35
36 * xdisp.c (Qarrow, Qhand, Qtext, Qpointer): New variables for
37 pointer types.
38 (Qrelative_width, Qalign_to): Remove unused variables.
39 (Vvoid_text_area_pointer): Replace Vshow_text_cursor_in_void.
40 (QCmap, QCpointer, Qrect, Qcircle, Qpoly): New variables for
41 image maps.
42 (x_y_to_hpos_vpos): Return glyph relative coordinates through
43 new dx and dy args.
44 Remove buffer_only_p arg (always 0). Simplify code accordingly.
45 (get_glyph_string_clip_rect): Draw cursor using glyph's rather
46 than row's ascent and height, to get sensible height on tall rows.
47 (build_desired_tool_bar_string): Remove Qimage extern.
48 (get_tool_bar_item): Fix call to x_y_to_hpos_vpos.
49 (produce_image_glyph): Adjust it.ascent to minimum row ascent if
50 image glyph is alone on the last line.
51 (append_glyph, append_composite_glyph, produce_image_glyph)
52 (append_stretch_glyph): Set glyph's ascent and descent.
53 (on_hot_spot_p): New function to check if position is inside an
54 rectangular, circular, or polygon-shaped image hot-spot,
55 (find_hot_spot): New function to search for image hot-spot.
56 (Flookup_image_map): New defun to search for image hot-spot.
57 (define_frame_cursor1): New aux function to determine frame pointer.
58 (note_mode_line_or_margin_highlight, note_mouse_highlight):
59 Handle `pointer' text property and :pointer image property to
60 control frame pointer shape. Detect image hot-spots for pointer
61 and help_echo properties. Use define_frame_cursor1.
62 (note_mouse_highlight): Use Vvoid_text_area_pointer.
63 (syms_of_xdisp): Defsubr new defun. Intern and staticpro new variables.
64 DEFVAR_LISP Vvoid_text_area_pointer instead of Vshow_text_cursor_in_void.
65
66 * xfaces.c (cache_face): Abort if c->size exceeds MAX_FACE_ID.
67
68 * xfns.c (x_set_mouse_color): Remove bogus x_check_errors call.
69 (Qimage): Remove extern (now in lisp.h).
70 (valid_image_p, parse_image_spec): Use IMAGEP macro.
71
72 * xmenu.c (show_help_event): Remove unused code.
73
74 * xterm.c (Qface, Qmouse_face): Remove unused externs.
75 (x_draw_hollow_cursor): Draw cursor using glyph's rather than
76 row's ascent and descent, to get a sensible height on tall rows.
77
782003-12-25 Luc Teirlinck <teirllm@auburn.edu>
79
80 * minibuf.c (Fcompleting_read): Undo previous change.
81
822003-12-25 Lars Hansen <larsh@math.ku.dk>
83
84 * dired.c (Fdirectory_files, Fdirectory_files_and_attributes):
85 Arguments GCPRO'ed in call to file name handler.
86
872003-12-25 Thien-Thi Nguyen <ttn@gnu.org>
88
89 * termcap.c (tgetst1): Scan for "%pN"; if all
90 N are continuous in [1,9], remove all "%pN".
91
12003-12-24 Jan Dj,Ad(Brv <jan.h.d@swipnet.se> 922003-12-24 Jan Dj,Ad(Brv <jan.h.d@swipnet.se>
2 93
3 * gtkutil.c (xg_frame_set_char_size): Call x_wm_set_size_hint. 94 * gtkutil.c (xg_frame_set_char_size): Call x_wm_set_size_hint.
diff --git a/src/Makefile.in b/src/Makefile.in
index c3b7541e7df..467ad5156bd 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -1172,7 +1172,7 @@ alloc.o: alloc.c process.h frame.h window.h buffer.h puresize.h syssignal.h key
1172bytecode.o: bytecode.c buffer.h syntax.h charset.h window.h $(config_h) 1172bytecode.o: bytecode.c buffer.h syntax.h charset.h window.h $(config_h)
1173data.o: data.c buffer.h puresize.h charset.h syssignal.h keyboard.h $(config_h) 1173data.o: data.c buffer.h puresize.h charset.h syssignal.h keyboard.h $(config_h)
1174eval.o: eval.c commands.h keyboard.h blockinput.h atimer.h systime.h \ 1174eval.o: eval.c commands.h keyboard.h blockinput.h atimer.h systime.h \
1175 $(config_h) 1175 dispextern.h $(config_h)
1176floatfns.o: floatfns.c $(config_h) 1176floatfns.o: floatfns.c $(config_h)
1177fns.o: fns.c commands.h $(config_h) frame.h buffer.h charset.h keyboard.h \ 1177fns.o: fns.c commands.h $(config_h) frame.h buffer.h charset.h keyboard.h \
1178 frame.h window.h dispextern.h $(INTERVAL_SRC) coding.h md5.h 1178 frame.h window.h dispextern.h $(INTERVAL_SRC) coding.h md5.h
diff --git a/src/composite.c b/src/composite.c
index b4e931c6a20..f8e655a3685 100644
--- a/src/composite.c
+++ b/src/composite.c
@@ -842,9 +842,12 @@ syms_of_composite ()
842 842
843 args[0] = QCtest; 843 args[0] = QCtest;
844 args[1] = Qequal; 844 args[1] = Qequal;
845 /* We used to make the hash table weak so that unreferenced
846 compostions can be garbage-collected. But, usually once
847 created compositions are repeatedly used in an Emacs session,
848 and thus it's not worth to save memory in such a way. So, we
849 make the table not weak. */
845 args[2] = QCweakness; 850 args[2] = QCweakness;
846 /* Fixme: It seems that a weak hash table leads to segfault in GC,
847 but I have not yet found why. -- handa@m17n.org */
848 args[3] = Qnil; 851 args[3] = Qnil;
849 args[4] = QCsize; 852 args[4] = QCsize;
850 args[5] = make_number (311); 853 args[5] = make_number (311);
diff --git a/src/dired.c b/src/dired.c
index 52a19f4fdc6..3bcd3051c25 100644
--- a/src/dired.c
+++ b/src/dired.c
@@ -359,17 +359,8 @@ If NOSORT is non-nil, the list is not sorted--its order is unpredictable.
359 call the corresponding file handler. */ 359 call the corresponding file handler. */
360 handler = Ffind_file_name_handler (directory, Qdirectory_files); 360 handler = Ffind_file_name_handler (directory, Qdirectory_files);
361 if (!NILP (handler)) 361 if (!NILP (handler))
362 { 362 return call5 (handler, Qdirectory_files, directory,
363 Lisp_Object args[6]; 363 full, match, nosort);
364
365 args[0] = handler;
366 args[1] = Qdirectory_files;
367 args[2] = directory;
368 args[3] = full;
369 args[4] = match;
370 args[5] = nosort;
371 return Ffuncall (6, args);
372 }
373 364
374 return directory_files_internal (directory, full, match, nosort, 0, Qnil); 365 return directory_files_internal (directory, full, match, nosort, 0, Qnil);
375} 366}
@@ -395,18 +386,8 @@ ID-FORMAT specifies the preferred format of attributes uid and gid, see
395 call the corresponding file handler. */ 386 call the corresponding file handler. */
396 handler = Ffind_file_name_handler (directory, Qdirectory_files_and_attributes); 387 handler = Ffind_file_name_handler (directory, Qdirectory_files_and_attributes);
397 if (!NILP (handler)) 388 if (!NILP (handler))
398 { 389 return call6 (handler, Qdirectory_files_and_attributes,
399 Lisp_Object args[7]; 390 directory, full, match, nosort, id_format);
400
401 args[0] = handler;
402 args[1] = Qdirectory_files_and_attributes;
403 args[2] = directory;
404 args[3] = full;
405 args[4] = match;
406 args[5] = nosort;
407 args[6] = id_format;
408 return Ffuncall (7, args);
409 }
410 391
411 return directory_files_internal (directory, full, match, nosort, 1, id_format); 392 return directory_files_internal (directory, full, match, nosort, 1, id_format);
412} 393}
diff --git a/src/dispextern.h b/src/dispextern.h
index 7148c68859c..06b52cf9ee4 100644
--- a/src/dispextern.h
+++ b/src/dispextern.h
@@ -321,6 +321,9 @@ struct glyph
321 /* Width in pixels. */ 321 /* Width in pixels. */
322 short pixel_width; 322 short pixel_width;
323 323
324 /* Ascent and descent in pixels. */
325 short ascent, descent;
326
324 /* Vertical offset. If < 0, the glyph is displayed raised, if > 0 327 /* Vertical offset. If < 0, the glyph is displayed raised, if > 0
325 the glyph is displayed lowered. */ 328 the glyph is displayed lowered. */
326 short voffset; 329 short voffset;
@@ -359,8 +362,10 @@ struct glyph
359 doesn't have a glyph in a font. */ 362 doesn't have a glyph in a font. */
360 unsigned glyph_not_available_p : 1; 363 unsigned glyph_not_available_p : 1;
361 364
365#define FACE_ID_BITS 21
366
362 /* Face of the glyph. */ 367 /* Face of the glyph. */
363 unsigned face_id : 21; 368 unsigned face_id : FACE_ID_BITS;
364 369
365 /* Type of font used to display the character glyph. May be used to 370 /* Type of font used to display the character glyph. May be used to
366 determine which set of functions to use to obtain font metrics 371 determine which set of functions to use to obtain font metrics
@@ -1493,6 +1498,7 @@ enum face_id
1493 BASIC_FACE_ID_SENTINEL 1498 BASIC_FACE_ID_SENTINEL
1494}; 1499};
1495 1500
1501#define MAX_FACE_ID ((1 << FACE_ID_BITS) - 1)
1496 1502
1497/* A cache of realized faces. Each frame has its own cache because 1503/* A cache of realized faces. Each frame has its own cache because
1498 Emacs allows different frame-local face definitions. */ 1504 Emacs allows different frame-local face definitions. */
@@ -2536,6 +2542,7 @@ extern void x_draw_vertical_border P_ ((struct window *w));
2536extern void frame_to_window_pixel_xy P_ ((struct window *, int *, int *)); 2542extern void frame_to_window_pixel_xy P_ ((struct window *, int *, int *));
2537extern void get_glyph_string_clip_rect P_ ((struct glyph_string *, 2543extern void get_glyph_string_clip_rect P_ ((struct glyph_string *,
2538 NativeRectangle *nr)); 2544 NativeRectangle *nr));
2545extern Lisp_Object find_hot_spot P_ ((Lisp_Object, int, int));
2539extern void note_mouse_highlight P_ ((struct frame *, int, int)); 2546extern void note_mouse_highlight P_ ((struct frame *, int, int));
2540extern void x_clear_window_mouse_face P_ ((struct window *)); 2547extern void x_clear_window_mouse_face P_ ((struct window *));
2541extern void cancel_mouse_face P_ ((struct frame *)); 2548extern void cancel_mouse_face P_ ((struct frame *));
diff --git a/src/dispnew.c b/src/dispnew.c
index b4aa9698937..afde7bd80e6 100644
--- a/src/dispnew.c
+++ b/src/dispnew.c
@@ -5700,8 +5700,6 @@ buffer_posn_from_coords (w, x, y, dx, dy, object, pos)
5700 struct it it; 5700 struct it it;
5701 struct buffer *old_current_buffer = current_buffer; 5701 struct buffer *old_current_buffer = current_buffer;
5702 struct text_pos startp; 5702 struct text_pos startp;
5703 struct glyph_row *row;
5704 struct image *img;
5705 int x0, x1; 5703 int x0, x1;
5706 5704
5707 current_buffer = XBUFFER (w->buffer); 5705 current_buffer = XBUFFER (w->buffer);
@@ -5714,25 +5712,44 @@ buffer_posn_from_coords (w, x, y, dx, dy, object, pos)
5714 move_it_to (&it, -1, x0 + it.first_visible_x, *y, -1, 5712 move_it_to (&it, -1, x0 + it.first_visible_x, *y, -1,
5715 MOVE_TO_X | MOVE_TO_Y); 5713 MOVE_TO_X | MOVE_TO_Y);
5716 5714
5717 /* Add extra (default width) columns if clicked after EOL. */
5718 x1 = max(0, it.current_x + it.pixel_width - it.first_visible_x);
5719 if (x0 > x1)
5720 it.hpos += (x0 - x1) / WINDOW_FRAME_COLUMN_WIDTH (w);
5721
5722 current_buffer = old_current_buffer; 5715 current_buffer = old_current_buffer;
5723 5716
5724 *dx = x0 + it.first_visible_x - it.current_x; 5717 *dx = x0 + it.first_visible_x - it.current_x;
5725 *dy = *y - it.current_y; 5718 *dy = *y - it.current_y;
5726 5719
5720 *object = w->buffer;
5721
5727#ifdef HAVE_WINDOW_SYSTEM 5722#ifdef HAVE_WINDOW_SYSTEM
5728 if (it.what == IT_IMAGE 5723 if (it.what == IT_IMAGE)
5729 && (img = IMAGE_FROM_ID (it.f, it.image_id)) != NULL 5724 {
5730 && !NILP (img->spec)) 5725 struct image *img;
5731 *object = img->spec; 5726 if ((img = IMAGE_FROM_ID (it.f, it.image_id)) != NULL
5727 && !NILP (img->spec))
5728 {
5729 struct glyph_row *row = MATRIX_ROW (w->current_matrix, it.vpos);
5730 struct glyph *glyph;
5731
5732 if (it.hpos < row->used[TEXT_AREA]
5733 && (glyph = row->glyphs[TEXT_AREA] + it.hpos,
5734 glyph->type == IMAGE_GLYPH))
5735 {
5736 *dy -= row->ascent - glyph->ascent;
5737 *object = img->spec;
5738 }
5739 }
5740 }
5732 else 5741 else
5733#endif 5742#endif
5734 *object = STRINGP (it.string) ? it.string : w->buffer; 5743 if (STRINGP (it.string))
5744 *object = it.string;
5745
5735 *pos = it.current; 5746 *pos = it.current;
5747
5748 /* Add extra (default width) columns if clicked after EOL. */
5749 x1 = max(0, it.current_x + it.pixel_width - it.first_visible_x);
5750 if (x0 > x1)
5751 it.hpos += (x0 - x1) / WINDOW_FRAME_COLUMN_WIDTH (w);
5752
5736 *x = it.hpos; 5753 *x = it.hpos;
5737 *y = it.vpos; 5754 *y = it.vpos;
5738} 5755}
@@ -5852,6 +5869,16 @@ marginal_area_string (w, x, y, dx, dy, part, charpos)
5852 { 5869 {
5853 string = glyph->object; 5870 string = glyph->object;
5854 *charpos = glyph->charpos; 5871 *charpos = glyph->charpos;
5872#ifdef HAVE_WINDOW_SYSTEM
5873 if (glyph->type == IMAGE_GLYPH)
5874 {
5875 struct image *img;
5876 img = IMAGE_FROM_ID (WINDOW_XFRAME (w), glyph->u.img_id);
5877 if (img != NULL)
5878 string = img->spec;
5879 y0 -= row->ascent - glyph->ascent;
5880 }
5881#endif
5855 } 5882 }
5856 else 5883 else
5857 /* Add extra (default width) columns if clicked after EOL. */ 5884 /* Add extra (default width) columns if clicked after EOL. */
diff --git a/src/keyboard.c b/src/keyboard.c
index f1e19079733..20b7242cbcb 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -579,7 +579,7 @@ Lisp_Object Qvertical_scroll_bar;
579Lisp_Object Qmenu_bar; 579Lisp_Object Qmenu_bar;
580extern Lisp_Object Qleft_margin, Qright_margin; 580extern Lisp_Object Qleft_margin, Qright_margin;
581extern Lisp_Object Qleft_fringe, Qright_fringe; 581extern Lisp_Object Qleft_fringe, Qright_fringe;
582extern Lisp_Object Qimage; 582extern Lisp_Object QCmap;
583 583
584Lisp_Object recursive_edit_unwind (), command_loop (); 584Lisp_Object recursive_edit_unwind (), command_loop ();
585Lisp_Object Fthis_command_keys (); 585Lisp_Object Fthis_command_keys ();
@@ -5016,6 +5016,19 @@ make_lispy_position (f, x, y, time)
5016 string = marginal_area_string (w, &rx, &ry, &dx, &dy, part, &charpos); 5016 string = marginal_area_string (w, &rx, &ry, &dx, &dy, part, &charpos);
5017 if (STRINGP (string)) 5017 if (STRINGP (string))
5018 object = Fcons (string, make_number (charpos)); 5018 object = Fcons (string, make_number (charpos));
5019#ifdef HAVE_WINDOW_SYSTEM
5020 else if (IMAGEP (string))
5021 {
5022 Lisp_Object image_map, hotspot;
5023 object = string;
5024 if ((image_map = Fplist_get (XCDR (object), QCmap),
5025 !NILP (image_map))
5026 && (hotspot = find_hot_spot (image_map, dx, dy),
5027 CONSP (hotspot))
5028 && (hotspot = XCDR (hotspot), CONSP (hotspot)))
5029 posn = XCAR (hotspot);
5030 }
5031#endif
5019 } 5032 }
5020 else if (part == ON_LEFT_FRINGE || part == ON_RIGHT_FRINGE) 5033 else if (part == ON_LEFT_FRINGE || part == ON_RIGHT_FRINGE)
5021 { 5034 {
@@ -5051,8 +5064,19 @@ make_lispy_position (f, x, y, time)
5051 if (STRINGP (string)) 5064 if (STRINGP (string))
5052 object = Fcons (string, 5065 object = Fcons (string,
5053 make_number (CHARPOS (p.string_pos))); 5066 make_number (CHARPOS (p.string_pos)));
5054 else if (CONSP (string) && EQ (XCAR (string), Qimage)) 5067#ifdef HAVE_WINDOW_SYSTEM
5055 object = string; 5068 else if (IMAGEP (string))
5069 {
5070 Lisp_Object image_map, hotspot;
5071 object = string;
5072 if ((image_map = Fplist_get (XCDR (object), QCmap),
5073 !NILP (image_map))
5074 && (hotspot = find_hot_spot (image_map, dx, dy),
5075 CONSP (hotspot))
5076 && (hotspot = XCDR (hotspot), CONSP (hotspot)))
5077 posn = XCAR (hotspot);
5078 }
5079#endif
5056 } 5080 }
5057 } 5081 }
5058 5082
diff --git a/src/lisp.h b/src/lisp.h
index de71cf7f7c9..c7a4065a96c 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -1381,6 +1381,10 @@ typedef unsigned char UCHAR;
1381#define GC_FRAMEP(x) GC_PSEUDOVECTORP (x, PVEC_FRAME) 1381#define GC_FRAMEP(x) GC_PSEUDOVECTORP (x, PVEC_FRAME)
1382 1382
1383#define SUB_CHAR_TABLE_P(x) (CHAR_TABLE_P (x) && NILP (XCHAR_TABLE (x)->top)) 1383#define SUB_CHAR_TABLE_P(x) (CHAR_TABLE_P (x) && NILP (XCHAR_TABLE (x)->top))
1384
1385/* Test for image (image . spec) */
1386#define IMAGEP(x) (CONSP (x) && EQ (XCAR (x), Qimage))
1387
1384 1388
1385#define GC_EQ(x, y) EQ (x, y) 1389#define GC_EQ(x, y) EQ (x, y)
1386 1390
@@ -2283,6 +2287,7 @@ extern Lisp_Object Qinhibit_point_motion_hooks;
2283extern Lisp_Object Qinhibit_redisplay, Qdisplay; 2287extern Lisp_Object Qinhibit_redisplay, Qdisplay;
2284extern Lisp_Object Qinhibit_eval_during_redisplay; 2288extern Lisp_Object Qinhibit_eval_during_redisplay;
2285extern Lisp_Object Qmessage_truncate_lines; 2289extern Lisp_Object Qmessage_truncate_lines;
2290extern Lisp_Object Qimage;
2286extern Lisp_Object Vmessage_log_max; 2291extern Lisp_Object Vmessage_log_max;
2287extern int message_enable_multibyte; 2292extern int message_enable_multibyte;
2288extern Lisp_Object echo_area_buffer[2]; 2293extern Lisp_Object echo_area_buffer[2];
diff --git a/src/macfns.c b/src/macfns.c
index 1634809ca3e..0f87556fb1e 100644
--- a/src/macfns.c
+++ b/src/macfns.c
@@ -3460,11 +3460,6 @@ If DISPLAY is omitted or nil, that stands for the selected frame's display. */)
3460 3460
3461static struct image_type *image_types; 3461static struct image_type *image_types;
3462 3462
3463/* The symbol `image' which is the car of the lists used to represent
3464 images in Lisp. */
3465
3466extern Lisp_Object Qimage;
3467
3468/* The symbol `xbm' which is used as the type symbol for XBM images. */ 3463/* The symbol `xbm' which is used as the type symbol for XBM images. */
3469 3464
3470Lisp_Object Qxbm; 3465Lisp_Object Qxbm;
@@ -3543,7 +3538,7 @@ valid_image_p (object)
3543{ 3538{
3544 int valid_p = 0; 3539 int valid_p = 0;
3545 3540
3546 if (CONSP (object) && EQ (XCAR (object), Qimage)) 3541 if (IMAGEP (object))
3547 { 3542 {
3548 Lisp_Object symbol = Fplist_get (XCDR (object), QCtype); 3543 Lisp_Object symbol = Fplist_get (XCDR (object), QCtype);
3549 struct image_type *type = lookup_image_type (symbol); 3544 struct image_type *type = lookup_image_type (symbol);
@@ -3633,7 +3628,7 @@ parse_image_spec (spec, keywords, nkeywords, type)
3633 int i; 3628 int i;
3634 Lisp_Object plist; 3629 Lisp_Object plist;
3635 3630
3636 if (!CONSP (spec) || !EQ (XCAR (spec), Qimage)) 3631 if (!IMAGEP (spec))
3637 return 0; 3632 return 0;
3638 3633
3639 plist = XCDR (spec); 3634 plist = XCDR (spec);
diff --git a/src/macterm.c b/src/macterm.c
index 39dfb8cb9a7..7dffaf6e442 100644
--- a/src/macterm.c
+++ b/src/macterm.c
@@ -253,8 +253,6 @@ extern Lisp_Object Vcommand_line_args, Vsystem_name;
253 253
254extern Lisp_Object Vx_no_window_manager; 254extern Lisp_Object Vx_no_window_manager;
255 255
256extern Lisp_Object Qface, Qmouse_face;
257
258extern int errno; 256extern int errno;
259 257
260/* A mask of extra modifier bits to put into every keyboard char. */ 258/* A mask of extra modifier bits to put into every keyboard char. */
diff --git a/src/minibuf.c b/src/minibuf.c
index 4c98f7ba708..baeb0cef7b5 100644
--- a/src/minibuf.c
+++ b/src/minibuf.c
@@ -1578,10 +1578,13 @@ Completion ignores case if the ambient value of
1578 Lisp_Object prompt, table, predicate, require_match, initial_input; 1578 Lisp_Object prompt, table, predicate, require_match, initial_input;
1579 Lisp_Object hist, def, inherit_input_method; 1579 Lisp_Object hist, def, inherit_input_method;
1580{ 1580{
1581 Lisp_Object val, histvar, histpos; 1581 Lisp_Object val, histvar, histpos, position;
1582 Lisp_Object init;
1583 int pos = 0;
1582 int count = SPECPDL_INDEX (); 1584 int count = SPECPDL_INDEX ();
1583 struct gcpro gcpro1; 1585 struct gcpro gcpro1;
1584 1586
1587 init = initial_input;
1585 GCPRO1 (def); 1588 GCPRO1 (def);
1586 1589
1587 specbind (Qminibuffer_completion_table, table); 1590 specbind (Qminibuffer_completion_table, table);
@@ -1590,6 +1593,23 @@ Completion ignores case if the ambient value of
1590 EQ (require_match, Qt) ? Qnil : require_match); 1593 EQ (require_match, Qt) ? Qnil : require_match);
1591 last_exact_completion = Qnil; 1594 last_exact_completion = Qnil;
1592 1595
1596 position = Qnil;
1597 if (!NILP (init))
1598 {
1599 if (CONSP (init))
1600 {
1601 position = Fcdr (init);
1602 init = Fcar (init);
1603 }
1604 CHECK_STRING (init);
1605 if (!NILP (position))
1606 {
1607 CHECK_NUMBER (position);
1608 /* Convert to distance from end of input. */
1609 pos = XINT (position) - SCHARS (init);
1610 }
1611 }
1612
1593 if (SYMBOLP (hist)) 1613 if (SYMBOLP (hist))
1594 { 1614 {
1595 histvar = hist; 1615 histvar = hist;
@@ -1608,7 +1628,7 @@ Completion ignores case if the ambient value of
1608 val = read_minibuf (NILP (require_match) 1628 val = read_minibuf (NILP (require_match)
1609 ? Vminibuffer_local_completion_map 1629 ? Vminibuffer_local_completion_map
1610 : Vminibuffer_local_must_match_map, 1630 : Vminibuffer_local_must_match_map,
1611 initial_input, prompt, Qnil, 0, 1631 init, prompt, make_number (pos), 0,
1612 histvar, histpos, def, 0, 1632 histvar, histpos, def, 0,
1613 !NILP (inherit_input_method)); 1633 !NILP (inherit_input_method));
1614 1634
diff --git a/src/regex.c b/src/regex.c
new file mode 100644
index 00000000000..a145183510d
--- /dev/null
+++ b/src/regex.c
@@ -0,0 +1,6335 @@
1/* Extended regular expression matching and search library, version
2 0.12. (Implements POSIX draft P1003.2/D11.2, except for some of the
3 internationalization features.)
4
5 Copyright (C) 1993,94,95,96,97,98,99,2000 Free Software Foundation, Inc.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20 USA. */
21
22/* TODO:
23 - structure the opcode space into opcode+flag.
24 - merge with glibc's regex.[ch].
25 - replace (succeed_n + jump_n + set_number_at) with something that doesn't
26 need to modify the compiled regexp so that re_match can be reentrant.
27 - get rid of on_failure_jump_smart by doing the optimization in re_comp
28 rather than at run-time, so that re_match can be reentrant.
29*/
30
31/* AIX requires this to be the first thing in the file. */
32#if defined _AIX && !defined REGEX_MALLOC
33 #pragma alloca
34#endif
35
36#ifdef HAVE_CONFIG_H
37# include <config.h>
38#endif
39
40#if defined STDC_HEADERS && !defined emacs
41# include <stddef.h>
42#else
43/* We need this for `regex.h', and perhaps for the Emacs include files. */
44# include <sys/types.h>
45#endif
46
47/* Whether to use ISO C Amendment 1 wide char functions.
48 Those should not be used for Emacs since it uses its own. */
49#if defined _LIBC
50#define WIDE_CHAR_SUPPORT 1
51#else
52#define WIDE_CHAR_SUPPORT \
53 (HAVE_WCTYPE_H && HAVE_WCHAR_H && HAVE_BTOWC && !emacs)
54#endif
55
56/* For platform which support the ISO C amendement 1 functionality we
57 support user defined character classes. */
58#if WIDE_CHAR_SUPPORT
59/* Solaris 2.5 has a bug: <wchar.h> must be included before <wctype.h>. */
60# include <wchar.h>
61# include <wctype.h>
62#endif
63
64#ifdef _LIBC
65/* We have to keep the namespace clean. */
66# define regfree(preg) __regfree (preg)
67# define regexec(pr, st, nm, pm, ef) __regexec (pr, st, nm, pm, ef)
68# define regcomp(preg, pattern, cflags) __regcomp (preg, pattern, cflags)
69# define regerror(errcode, preg, errbuf, errbuf_size) \
70 __regerror(errcode, preg, errbuf, errbuf_size)
71# define re_set_registers(bu, re, nu, st, en) \
72 __re_set_registers (bu, re, nu, st, en)
73# define re_match_2(bufp, string1, size1, string2, size2, pos, regs, stop) \
74 __re_match_2 (bufp, string1, size1, string2, size2, pos, regs, stop)
75# define re_match(bufp, string, size, pos, regs) \
76 __re_match (bufp, string, size, pos, regs)
77# define re_search(bufp, string, size, startpos, range, regs) \
78 __re_search (bufp, string, size, startpos, range, regs)
79# define re_compile_pattern(pattern, length, bufp) \
80 __re_compile_pattern (pattern, length, bufp)
81# define re_set_syntax(syntax) __re_set_syntax (syntax)
82# define re_search_2(bufp, st1, s1, st2, s2, startpos, range, regs, stop) \
83 __re_search_2 (bufp, st1, s1, st2, s2, startpos, range, regs, stop)
84# define re_compile_fastmap(bufp) __re_compile_fastmap (bufp)
85
86/* Make sure we call libc's function even if the user overrides them. */
87# define btowc __btowc
88# define iswctype __iswctype
89# define wctype __wctype
90
91# define WEAK_ALIAS(a,b) weak_alias (a, b)
92
93/* We are also using some library internals. */
94# include <locale/localeinfo.h>
95# include <locale/elem-hash.h>
96# include <langinfo.h>
97#else
98# define WEAK_ALIAS(a,b)
99#endif
100
101/* This is for other GNU distributions with internationalized messages. */
102#if HAVE_LIBINTL_H || defined _LIBC
103# include <libintl.h>
104#else
105# define gettext(msgid) (msgid)
106#endif
107
108#ifndef gettext_noop
109/* This define is so xgettext can find the internationalizable
110 strings. */
111# define gettext_noop(String) String
112#endif
113
114/* The `emacs' switch turns on certain matching commands
115 that make sense only in Emacs. */
116#ifdef emacs
117
118# include "lisp.h"
119# include "buffer.h"
120
121/* Make syntax table lookup grant data in gl_state. */
122# define SYNTAX_ENTRY_VIA_PROPERTY
123
124# include "syntax.h"
125# include "charset.h"
126# include "category.h"
127
128# ifdef malloc
129# undef malloc
130# endif
131# define malloc xmalloc
132# ifdef realloc
133# undef realloc
134# endif
135# define realloc xrealloc
136# ifdef free
137# undef free
138# endif
139# define free xfree
140
141/* Converts the pointer to the char to BEG-based offset from the start. */
142# define PTR_TO_OFFSET(d) POS_AS_IN_BUFFER (POINTER_TO_OFFSET (d))
143# define POS_AS_IN_BUFFER(p) ((p) + (NILP (re_match_object) || BUFFERP (re_match_object)))
144
145# define RE_MULTIBYTE_P(bufp) ((bufp)->multibyte)
146# define RE_STRING_CHAR(p, s) \
147 (multibyte ? (STRING_CHAR (p, s)) : (*(p)))
148# define RE_STRING_CHAR_AND_LENGTH(p, s, len) \
149 (multibyte ? (STRING_CHAR_AND_LENGTH (p, s, len)) : ((len) = 1, *(p)))
150
151/* Set C a (possibly multibyte) character before P. P points into a
152 string which is the virtual concatenation of STR1 (which ends at
153 END1) or STR2 (which ends at END2). */
154# define GET_CHAR_BEFORE_2(c, p, str1, end1, str2, end2) \
155 do { \
156 if (multibyte) \
157 { \
158 re_char *dtemp = (p) == (str2) ? (end1) : (p); \
159 re_char *dlimit = ((p) > (str2) && (p) <= (end2)) ? (str2) : (str1); \
160 re_char *d0 = dtemp; \
161 PREV_CHAR_BOUNDARY (d0, dlimit); \
162 c = STRING_CHAR (d0, dtemp - d0); \
163 } \
164 else \
165 (c = ((p) == (str2) ? (end1) : (p))[-1]); \
166 } while (0)
167
168
169#else /* not emacs */
170
171/* If we are not linking with Emacs proper,
172 we can't use the relocating allocator
173 even if config.h says that we can. */
174# undef REL_ALLOC
175
176# if defined STDC_HEADERS || defined _LIBC
177# include <stdlib.h>
178# else
179char *malloc ();
180char *realloc ();
181# endif
182
183/* When used in Emacs's lib-src, we need to get bzero and bcopy somehow.
184 If nothing else has been done, use the method below. */
185# ifdef INHIBIT_STRING_HEADER
186# if !(defined HAVE_BZERO && defined HAVE_BCOPY)
187# if !defined bzero && !defined bcopy
188# undef INHIBIT_STRING_HEADER
189# endif
190# endif
191# endif
192
193/* This is the normal way of making sure we have memcpy, memcmp and bzero.
194 This is used in most programs--a few other programs avoid this
195 by defining INHIBIT_STRING_HEADER. */
196# ifndef INHIBIT_STRING_HEADER
197# if defined HAVE_STRING_H || defined STDC_HEADERS || defined _LIBC
198# include <string.h>
199# ifndef bzero
200# ifndef _LIBC
201# define bzero(s, n) (memset (s, '\0', n), (s))
202# else
203# define bzero(s, n) __bzero (s, n)
204# endif
205# endif
206# else
207# include <strings.h>
208# ifndef memcmp
209# define memcmp(s1, s2, n) bcmp (s1, s2, n)
210# endif
211# ifndef memcpy
212# define memcpy(d, s, n) (bcopy (s, d, n), (d))
213# endif
214# endif
215# endif
216
217/* Define the syntax stuff for \<, \>, etc. */
218
219/* Sword must be nonzero for the wordchar pattern commands in re_match_2. */
220enum syntaxcode { Swhitespace = 0, Sword = 1 };
221
222# ifdef SWITCH_ENUM_BUG
223# define SWITCH_ENUM_CAST(x) ((int)(x))
224# else
225# define SWITCH_ENUM_CAST(x) (x)
226# endif
227
228/* Dummy macros for non-Emacs environments. */
229# define BASE_LEADING_CODE_P(c) (0)
230# define CHAR_CHARSET(c) 0
231# define CHARSET_LEADING_CODE_BASE(c) 0
232# define MAX_MULTIBYTE_LENGTH 1
233# define RE_MULTIBYTE_P(x) 0
234# define WORD_BOUNDARY_P(c1, c2) (0)
235# define CHAR_HEAD_P(p) (1)
236# define SINGLE_BYTE_CHAR_P(c) (1)
237# define SAME_CHARSET_P(c1, c2) (1)
238# define MULTIBYTE_FORM_LENGTH(p, s) (1)
239# define PREV_CHAR_BOUNDARY(p, limit) ((p)--)
240# define STRING_CHAR(p, s) (*(p))
241# define RE_STRING_CHAR STRING_CHAR
242# define CHAR_STRING(c, s) (*(s) = (c), 1)
243# define STRING_CHAR_AND_LENGTH(p, s, actual_len) ((actual_len) = 1, *(p))
244# define RE_STRING_CHAR_AND_LENGTH STRING_CHAR_AND_LENGTH
245# define GET_CHAR_BEFORE_2(c, p, str1, end1, str2, end2) \
246 (c = ((p) == (str2) ? *((end1) - 1) : *((p) - 1)))
247# define MAKE_CHAR(charset, c1, c2) (c1)
248#endif /* not emacs */
249
250#ifndef RE_TRANSLATE
251# define RE_TRANSLATE(TBL, C) ((unsigned char)(TBL)[C])
252# define RE_TRANSLATE_P(TBL) (TBL)
253#endif
254
255/* Get the interface, including the syntax bits. */
256#include "regex.h"
257
258/* isalpha etc. are used for the character classes. */
259#include <ctype.h>
260
261#ifdef emacs
262
263/* 1 if C is an ASCII character. */
264# define IS_REAL_ASCII(c) ((c) < 0200)
265
266/* 1 if C is a unibyte character. */
267# define ISUNIBYTE(c) (SINGLE_BYTE_CHAR_P ((c)))
268
269/* The Emacs definitions should not be directly affected by locales. */
270
271/* In Emacs, these are only used for single-byte characters. */
272# define ISDIGIT(c) ((c) >= '0' && (c) <= '9')
273# define ISCNTRL(c) ((c) < ' ')
274# define ISXDIGIT(c) (((c) >= '0' && (c) <= '9') \
275 || ((c) >= 'a' && (c) <= 'f') \
276 || ((c) >= 'A' && (c) <= 'F'))
277
278/* This is only used for single-byte characters. */
279# define ISBLANK(c) ((c) == ' ' || (c) == '\t')
280
281/* The rest must handle multibyte characters. */
282
283# define ISGRAPH(c) (SINGLE_BYTE_CHAR_P (c) \
284 ? (c) > ' ' && !((c) >= 0177 && (c) <= 0237) \
285 : 1)
286
287# define ISPRINT(c) (SINGLE_BYTE_CHAR_P (c) \
288 ? (c) >= ' ' && !((c) >= 0177 && (c) <= 0237) \
289 : 1)
290
291# define ISALNUM(c) (IS_REAL_ASCII (c) \
292 ? (((c) >= 'a' && (c) <= 'z') \
293 || ((c) >= 'A' && (c) <= 'Z') \
294 || ((c) >= '0' && (c) <= '9')) \
295 : SYNTAX (c) == Sword)
296
297# define ISALPHA(c) (IS_REAL_ASCII (c) \
298 ? (((c) >= 'a' && (c) <= 'z') \
299 || ((c) >= 'A' && (c) <= 'Z')) \
300 : SYNTAX (c) == Sword)
301
302# define ISLOWER(c) (LOWERCASEP (c))
303
304# define ISPUNCT(c) (IS_REAL_ASCII (c) \
305 ? ((c) > ' ' && (c) < 0177 \
306 && !(((c) >= 'a' && (c) <= 'z') \
307 || ((c) >= 'A' && (c) <= 'Z') \
308 || ((c) >= '0' && (c) <= '9'))) \
309 : SYNTAX (c) != Sword)
310
311# define ISSPACE(c) (SYNTAX (c) == Swhitespace)
312
313# define ISUPPER(c) (UPPERCASEP (c))
314
315# define ISWORD(c) (SYNTAX (c) == Sword)
316
317#else /* not emacs */
318
319/* Jim Meyering writes:
320
321 "... Some ctype macros are valid only for character codes that
322 isascii says are ASCII (SGI's IRIX-4.0.5 is one such system --when
323 using /bin/cc or gcc but without giving an ansi option). So, all
324 ctype uses should be through macros like ISPRINT... If
325 STDC_HEADERS is defined, then autoconf has verified that the ctype
326 macros don't need to be guarded with references to isascii. ...
327 Defining isascii to 1 should let any compiler worth its salt
328 eliminate the && through constant folding."
329 Solaris defines some of these symbols so we must undefine them first. */
330
331# undef ISASCII
332# if defined STDC_HEADERS || (!defined isascii && !defined HAVE_ISASCII)
333# define ISASCII(c) 1
334# else
335# define ISASCII(c) isascii(c)
336# endif
337
338/* 1 if C is an ASCII character. */
339# define IS_REAL_ASCII(c) ((c) < 0200)
340
341/* This distinction is not meaningful, except in Emacs. */
342# define ISUNIBYTE(c) 1
343
344# ifdef isblank
345# define ISBLANK(c) (ISASCII (c) && isblank (c))
346# else
347# define ISBLANK(c) ((c) == ' ' || (c) == '\t')
348# endif
349# ifdef isgraph
350# define ISGRAPH(c) (ISASCII (c) && isgraph (c))
351# else
352# define ISGRAPH(c) (ISASCII (c) && isprint (c) && !isspace (c))
353# endif
354
355# undef ISPRINT
356# define ISPRINT(c) (ISASCII (c) && isprint (c))
357# define ISDIGIT(c) (ISASCII (c) && isdigit (c))
358# define ISALNUM(c) (ISASCII (c) && isalnum (c))
359# define ISALPHA(c) (ISASCII (c) && isalpha (c))
360# define ISCNTRL(c) (ISASCII (c) && iscntrl (c))
361# define ISLOWER(c) (ISASCII (c) && islower (c))
362# define ISPUNCT(c) (ISASCII (c) && ispunct (c))
363# define ISSPACE(c) (ISASCII (c) && isspace (c))
364# define ISUPPER(c) (ISASCII (c) && isupper (c))
365# define ISXDIGIT(c) (ISASCII (c) && isxdigit (c))
366
367# define ISWORD(c) ISALPHA(c)
368
369# ifdef _tolower
370# define TOLOWER(c) _tolower(c)
371# else
372# define TOLOWER(c) tolower(c)
373# endif
374
375/* How many characters in the character set. */
376# define CHAR_SET_SIZE 256
377
378# ifdef SYNTAX_TABLE
379
380extern char *re_syntax_table;
381
382# else /* not SYNTAX_TABLE */
383
384static char re_syntax_table[CHAR_SET_SIZE];
385
386static void
387init_syntax_once ()
388{
389 register int c;
390 static int done = 0;
391
392 if (done)
393 return;
394
395 bzero (re_syntax_table, sizeof re_syntax_table);
396
397 for (c = 0; c < CHAR_SET_SIZE; ++c)
398 if (ISALNUM (c))
399 re_syntax_table[c] = Sword;
400
401 re_syntax_table['_'] = Sword;
402
403 done = 1;
404}
405
406# endif /* not SYNTAX_TABLE */
407
408# define SYNTAX(c) re_syntax_table[(c)]
409
410#endif /* not emacs */
411
412#ifndef NULL
413# define NULL (void *)0
414#endif
415
416/* We remove any previous definition of `SIGN_EXTEND_CHAR',
417 since ours (we hope) works properly with all combinations of
418 machines, compilers, `char' and `unsigned char' argument types.
419 (Per Bothner suggested the basic approach.) */
420#undef SIGN_EXTEND_CHAR
421#if __STDC__
422# define SIGN_EXTEND_CHAR(c) ((signed char) (c))
423#else /* not __STDC__ */
424/* As in Harbison and Steele. */
425# define SIGN_EXTEND_CHAR(c) ((((unsigned char) (c)) ^ 128) - 128)
426#endif
427
428/* Should we use malloc or alloca? If REGEX_MALLOC is not defined, we
429 use `alloca' instead of `malloc'. This is because using malloc in
430 re_search* or re_match* could cause memory leaks when C-g is used in
431 Emacs; also, malloc is slower and causes storage fragmentation. On
432 the other hand, malloc is more portable, and easier to debug.
433
434 Because we sometimes use alloca, some routines have to be macros,
435 not functions -- `alloca'-allocated space disappears at the end of the
436 function it is called in. */
437
438#ifdef REGEX_MALLOC
439
440# define REGEX_ALLOCATE malloc
441# define REGEX_REALLOCATE(source, osize, nsize) realloc (source, nsize)
442# define REGEX_FREE free
443
444#else /* not REGEX_MALLOC */
445
446/* Emacs already defines alloca, sometimes. */
447# ifndef alloca
448
449/* Make alloca work the best possible way. */
450# ifdef __GNUC__
451# define alloca __builtin_alloca
452# else /* not __GNUC__ */
453# if HAVE_ALLOCA_H
454# include <alloca.h>
455# endif /* HAVE_ALLOCA_H */
456# endif /* not __GNUC__ */
457
458# endif /* not alloca */
459
460# define REGEX_ALLOCATE alloca
461
462/* Assumes a `char *destination' variable. */
463# define REGEX_REALLOCATE(source, osize, nsize) \
464 (destination = (char *) alloca (nsize), \
465 memcpy (destination, source, osize))
466
467/* No need to do anything to free, after alloca. */
468# define REGEX_FREE(arg) ((void)0) /* Do nothing! But inhibit gcc warning. */
469
470#endif /* not REGEX_MALLOC */
471
472/* Define how to allocate the failure stack. */
473
474#if defined REL_ALLOC && defined REGEX_MALLOC
475
476# define REGEX_ALLOCATE_STACK(size) \
477 r_alloc (&failure_stack_ptr, (size))
478# define REGEX_REALLOCATE_STACK(source, osize, nsize) \
479 r_re_alloc (&failure_stack_ptr, (nsize))
480# define REGEX_FREE_STACK(ptr) \
481 r_alloc_free (&failure_stack_ptr)
482
483#else /* not using relocating allocator */
484
485# ifdef REGEX_MALLOC
486
487# define REGEX_ALLOCATE_STACK malloc
488# define REGEX_REALLOCATE_STACK(source, osize, nsize) realloc (source, nsize)
489# define REGEX_FREE_STACK free
490
491# else /* not REGEX_MALLOC */
492
493# define REGEX_ALLOCATE_STACK alloca
494
495# define REGEX_REALLOCATE_STACK(source, osize, nsize) \
496 REGEX_REALLOCATE (source, osize, nsize)
497/* No need to explicitly free anything. */
498# define REGEX_FREE_STACK(arg) ((void)0)
499
500# endif /* not REGEX_MALLOC */
501#endif /* not using relocating allocator */
502
503
504/* True if `size1' is non-NULL and PTR is pointing anywhere inside
505 `string1' or just past its end. This works if PTR is NULL, which is
506 a good thing. */
507#define FIRST_STRING_P(ptr) \
508 (size1 && string1 <= (ptr) && (ptr) <= string1 + size1)
509
510/* (Re)Allocate N items of type T using malloc, or fail. */
511#define TALLOC(n, t) ((t *) malloc ((n) * sizeof (t)))
512#define RETALLOC(addr, n, t) ((addr) = (t *) realloc (addr, (n) * sizeof (t)))
513#define RETALLOC_IF(addr, n, t) \
514 if (addr) RETALLOC((addr), (n), t); else (addr) = TALLOC ((n), t)
515#define REGEX_TALLOC(n, t) ((t *) REGEX_ALLOCATE ((n) * sizeof (t)))
516
517#define BYTEWIDTH 8 /* In bits. */
518
519#define STREQ(s1, s2) ((strcmp (s1, s2) == 0))
520
521#undef MAX
522#undef MIN
523#define MAX(a, b) ((a) > (b) ? (a) : (b))
524#define MIN(a, b) ((a) < (b) ? (a) : (b))
525
526/* Type of source-pattern and string chars. */
527typedef const unsigned char re_char;
528
529typedef char boolean;
530#define false 0
531#define true 1
532
533static int re_match_2_internal _RE_ARGS ((struct re_pattern_buffer *bufp,
534 re_char *string1, int size1,
535 re_char *string2, int size2,
536 int pos,
537 struct re_registers *regs,
538 int stop));
539
540/* These are the command codes that appear in compiled regular
541 expressions. Some opcodes are followed by argument bytes. A
542 command code can specify any interpretation whatsoever for its
543 arguments. Zero bytes may appear in the compiled regular expression. */
544
545typedef enum
546{
547 no_op = 0,
548
549 /* Succeed right away--no more backtracking. */
550 succeed,
551
552 /* Followed by one byte giving n, then by n literal bytes. */
553 exactn,
554
555 /* Matches any (more or less) character. */
556 anychar,
557
558 /* Matches any one char belonging to specified set. First
559 following byte is number of bitmap bytes. Then come bytes
560 for a bitmap saying which chars are in. Bits in each byte
561 are ordered low-bit-first. A character is in the set if its
562 bit is 1. A character too large to have a bit in the map is
563 automatically not in the set.
564
565 If the length byte has the 0x80 bit set, then that stuff
566 is followed by a range table:
567 2 bytes of flags for character sets (low 8 bits, high 8 bits)
568 See RANGE_TABLE_WORK_BITS below.
569 2 bytes, the number of pairs that follow (upto 32767)
570 pairs, each 2 multibyte characters,
571 each multibyte character represented as 3 bytes. */
572 charset,
573
574 /* Same parameters as charset, but match any character that is
575 not one of those specified. */
576 charset_not,
577
578 /* Start remembering the text that is matched, for storing in a
579 register. Followed by one byte with the register number, in
580 the range 0 to one less than the pattern buffer's re_nsub
581 field. */
582 start_memory,
583
584 /* Stop remembering the text that is matched and store it in a
585 memory register. Followed by one byte with the register
586 number, in the range 0 to one less than `re_nsub' in the
587 pattern buffer. */
588 stop_memory,
589
590 /* Match a duplicate of something remembered. Followed by one
591 byte containing the register number. */
592 duplicate,
593
594 /* Fail unless at beginning of line. */
595 begline,
596
597 /* Fail unless at end of line. */
598 endline,
599
600 /* Succeeds if at beginning of buffer (if emacs) or at beginning
601 of string to be matched (if not). */
602 begbuf,
603
604 /* Analogously, for end of buffer/string. */
605 endbuf,
606
607 /* Followed by two byte relative address to which to jump. */
608 jump,
609
610 /* Followed by two-byte relative address of place to resume at
611 in case of failure. */
612 on_failure_jump,
613
614 /* Like on_failure_jump, but pushes a placeholder instead of the
615 current string position when executed. */
616 on_failure_keep_string_jump,
617
618 /* Just like `on_failure_jump', except that it checks that we
619 don't get stuck in an infinite loop (matching an empty string
620 indefinitely). */
621 on_failure_jump_loop,
622
623 /* Just like `on_failure_jump_loop', except that it checks for
624 a different kind of loop (the kind that shows up with non-greedy
625 operators). This operation has to be immediately preceded
626 by a `no_op'. */
627 on_failure_jump_nastyloop,
628
629 /* A smart `on_failure_jump' used for greedy * and + operators.
630 It analyses the loop before which it is put and if the
631 loop does not require backtracking, it changes itself to
632 `on_failure_keep_string_jump' and short-circuits the loop,
633 else it just defaults to changing itself into `on_failure_jump'.
634 It assumes that it is pointing to just past a `jump'. */
635 on_failure_jump_smart,
636
637 /* Followed by two-byte relative address and two-byte number n.
638 After matching N times, jump to the address upon failure.
639 Does not work if N starts at 0: use on_failure_jump_loop
640 instead. */
641 succeed_n,
642
643 /* Followed by two-byte relative address, and two-byte number n.
644 Jump to the address N times, then fail. */
645 jump_n,
646
647 /* Set the following two-byte relative address to the
648 subsequent two-byte number. The address *includes* the two
649 bytes of number. */
650 set_number_at,
651
652 wordbeg, /* Succeeds if at word beginning. */
653 wordend, /* Succeeds if at word end. */
654
655 wordbound, /* Succeeds if at a word boundary. */
656 notwordbound, /* Succeeds if not at a word boundary. */
657
658 /* Matches any character whose syntax is specified. Followed by
659 a byte which contains a syntax code, e.g., Sword. */
660 syntaxspec,
661
662 /* Matches any character whose syntax is not that specified. */
663 notsyntaxspec
664
665#ifdef emacs
666 ,before_dot, /* Succeeds if before point. */
667 at_dot, /* Succeeds if at point. */
668 after_dot, /* Succeeds if after point. */
669
670 /* Matches any character whose category-set contains the specified
671 category. The operator is followed by a byte which contains a
672 category code (mnemonic ASCII character). */
673 categoryspec,
674
675 /* Matches any character whose category-set does not contain the
676 specified category. The operator is followed by a byte which
677 contains the category code (mnemonic ASCII character). */
678 notcategoryspec
679#endif /* emacs */
680} re_opcode_t;
681
682/* Common operations on the compiled pattern. */
683
684/* Store NUMBER in two contiguous bytes starting at DESTINATION. */
685
686#define STORE_NUMBER(destination, number) \
687 do { \
688 (destination)[0] = (number) & 0377; \
689 (destination)[1] = (number) >> 8; \
690 } while (0)
691
692/* Same as STORE_NUMBER, except increment DESTINATION to
693 the byte after where the number is stored. Therefore, DESTINATION
694 must be an lvalue. */
695
696#define STORE_NUMBER_AND_INCR(destination, number) \
697 do { \
698 STORE_NUMBER (destination, number); \
699 (destination) += 2; \
700 } while (0)
701
702/* Put into DESTINATION a number stored in two contiguous bytes starting
703 at SOURCE. */
704
705#define EXTRACT_NUMBER(destination, source) \
706 do { \
707 (destination) = *(source) & 0377; \
708 (destination) += SIGN_EXTEND_CHAR (*((source) + 1)) << 8; \
709 } while (0)
710
711#ifdef DEBUG
712static void extract_number _RE_ARGS ((int *dest, re_char *source));
713static void
714extract_number (dest, source)
715 int *dest;
716 re_char *source;
717{
718 int temp = SIGN_EXTEND_CHAR (*(source + 1));
719 *dest = *source & 0377;
720 *dest += temp << 8;
721}
722
723# ifndef EXTRACT_MACROS /* To debug the macros. */
724# undef EXTRACT_NUMBER
725# define EXTRACT_NUMBER(dest, src) extract_number (&dest, src)
726# endif /* not EXTRACT_MACROS */
727
728#endif /* DEBUG */
729
730/* Same as EXTRACT_NUMBER, except increment SOURCE to after the number.
731 SOURCE must be an lvalue. */
732
733#define EXTRACT_NUMBER_AND_INCR(destination, source) \
734 do { \
735 EXTRACT_NUMBER (destination, source); \
736 (source) += 2; \
737 } while (0)
738
739#ifdef DEBUG
740static void extract_number_and_incr _RE_ARGS ((int *destination,
741 re_char **source));
742static void
743extract_number_and_incr (destination, source)
744 int *destination;
745 re_char **source;
746{
747 extract_number (destination, *source);
748 *source += 2;
749}
750
751# ifndef EXTRACT_MACROS
752# undef EXTRACT_NUMBER_AND_INCR
753# define EXTRACT_NUMBER_AND_INCR(dest, src) \
754 extract_number_and_incr (&dest, &src)
755# endif /* not EXTRACT_MACROS */
756
757#endif /* DEBUG */
758
759/* Store a multibyte character in three contiguous bytes starting
760 DESTINATION, and increment DESTINATION to the byte after where the
761 character is stored. Therefore, DESTINATION must be an lvalue. */
762
763#define STORE_CHARACTER_AND_INCR(destination, character) \
764 do { \
765 (destination)[0] = (character) & 0377; \
766 (destination)[1] = ((character) >> 8) & 0377; \
767 (destination)[2] = (character) >> 16; \
768 (destination) += 3; \
769 } while (0)
770
771/* Put into DESTINATION a character stored in three contiguous bytes
772 starting at SOURCE. */
773
774#define EXTRACT_CHARACTER(destination, source) \
775 do { \
776 (destination) = ((source)[0] \
777 | ((source)[1] << 8) \
778 | ((source)[2] << 16)); \
779 } while (0)
780
781
782/* Macros for charset. */
783
784/* Size of bitmap of charset P in bytes. P is a start of charset,
785 i.e. *P is (re_opcode_t) charset or (re_opcode_t) charset_not. */
786#define CHARSET_BITMAP_SIZE(p) ((p)[1] & 0x7F)
787
788/* Nonzero if charset P has range table. */
789#define CHARSET_RANGE_TABLE_EXISTS_P(p) ((p)[1] & 0x80)
790
791/* Return the address of range table of charset P. But not the start
792 of table itself, but the before where the number of ranges is
793 stored. `2 +' means to skip re_opcode_t and size of bitmap,
794 and the 2 bytes of flags at the start of the range table. */
795#define CHARSET_RANGE_TABLE(p) (&(p)[4 + CHARSET_BITMAP_SIZE (p)])
796
797/* Extract the bit flags that start a range table. */
798#define CHARSET_RANGE_TABLE_BITS(p) \
799 ((p)[2 + CHARSET_BITMAP_SIZE (p)] \
800 + (p)[3 + CHARSET_BITMAP_SIZE (p)] * 0x100)
801
802/* Test if C is listed in the bitmap of charset P. */
803#define CHARSET_LOOKUP_BITMAP(p, c) \
804 ((c) < CHARSET_BITMAP_SIZE (p) * BYTEWIDTH \
805 && (p)[2 + (c) / BYTEWIDTH] & (1 << ((c) % BYTEWIDTH)))
806
807/* Return the address of end of RANGE_TABLE. COUNT is number of
808 ranges (which is a pair of (start, end)) in the RANGE_TABLE. `* 2'
809 is start of range and end of range. `* 3' is size of each start
810 and end. */
811#define CHARSET_RANGE_TABLE_END(range_table, count) \
812 ((range_table) + (count) * 2 * 3)
813
814/* Test if C is in RANGE_TABLE. A flag NOT is negated if C is in.
815 COUNT is number of ranges in RANGE_TABLE. */
816#define CHARSET_LOOKUP_RANGE_TABLE_RAW(not, c, range_table, count) \
817 do \
818 { \
819 re_wchar_t range_start, range_end; \
820 re_char *p; \
821 re_char *range_table_end \
822 = CHARSET_RANGE_TABLE_END ((range_table), (count)); \
823 \
824 for (p = (range_table); p < range_table_end; p += 2 * 3) \
825 { \
826 EXTRACT_CHARACTER (range_start, p); \
827 EXTRACT_CHARACTER (range_end, p + 3); \
828 \
829 if (range_start <= (c) && (c) <= range_end) \
830 { \
831 (not) = !(not); \
832 break; \
833 } \
834 } \
835 } \
836 while (0)
837
838/* Test if C is in range table of CHARSET. The flag NOT is negated if
839 C is listed in it. */
840#define CHARSET_LOOKUP_RANGE_TABLE(not, c, charset) \
841 do \
842 { \
843 /* Number of ranges in range table. */ \
844 int count; \
845 re_char *range_table = CHARSET_RANGE_TABLE (charset); \
846 \
847 EXTRACT_NUMBER_AND_INCR (count, range_table); \
848 CHARSET_LOOKUP_RANGE_TABLE_RAW ((not), (c), range_table, count); \
849 } \
850 while (0)
851
852/* If DEBUG is defined, Regex prints many voluminous messages about what
853 it is doing (if the variable `debug' is nonzero). If linked with the
854 main program in `iregex.c', you can enter patterns and strings
855 interactively. And if linked with the main program in `main.c' and
856 the other test files, you can run the already-written tests. */
857
858#ifdef DEBUG
859
860/* We use standard I/O for debugging. */
861# include <stdio.h>
862
863/* It is useful to test things that ``must'' be true when debugging. */
864# include <assert.h>
865
866static int debug = -100000;
867
868# define DEBUG_STATEMENT(e) e
869# define DEBUG_PRINT1(x) if (debug > 0) printf (x)
870# define DEBUG_PRINT2(x1, x2) if (debug > 0) printf (x1, x2)
871# define DEBUG_PRINT3(x1, x2, x3) if (debug > 0) printf (x1, x2, x3)
872# define DEBUG_PRINT4(x1, x2, x3, x4) if (debug > 0) printf (x1, x2, x3, x4)
873# define DEBUG_PRINT_COMPILED_PATTERN(p, s, e) \
874 if (debug > 0) print_partial_compiled_pattern (s, e)
875# define DEBUG_PRINT_DOUBLE_STRING(w, s1, sz1, s2, sz2) \
876 if (debug > 0) print_double_string (w, s1, sz1, s2, sz2)
877
878
879/* Print the fastmap in human-readable form. */
880
881void
882print_fastmap (fastmap)
883 char *fastmap;
884{
885 unsigned was_a_range = 0;
886 unsigned i = 0;
887
888 while (i < (1 << BYTEWIDTH))
889 {
890 if (fastmap[i++])
891 {
892 was_a_range = 0;
893 putchar (i - 1);
894 while (i < (1 << BYTEWIDTH) && fastmap[i])
895 {
896 was_a_range = 1;
897 i++;
898 }
899 if (was_a_range)
900 {
901 printf ("-");
902 putchar (i - 1);
903 }
904 }
905 }
906 putchar ('\n');
907}
908
909
910/* Print a compiled pattern string in human-readable form, starting at
911 the START pointer into it and ending just before the pointer END. */
912
913void
914print_partial_compiled_pattern (start, end)
915 re_char *start;
916 re_char *end;
917{
918 int mcnt, mcnt2;
919 re_char *p = start;
920 re_char *pend = end;
921
922 if (start == NULL)
923 {
924 fprintf (stderr, "(null)\n");
925 return;
926 }
927
928 /* Loop over pattern commands. */
929 while (p < pend)
930 {
931 fprintf (stderr, "%d:\t", p - start);
932
933 switch ((re_opcode_t) *p++)
934 {
935 case no_op:
936 fprintf (stderr, "/no_op");
937 break;
938
939 case succeed:
940 fprintf (stderr, "/succeed");
941 break;
942
943 case exactn:
944 mcnt = *p++;
945 fprintf (stderr, "/exactn/%d", mcnt);
946 do
947 {
948 fprintf (stderr, "/%c", *p++);
949 }
950 while (--mcnt);
951 break;
952
953 case start_memory:
954 fprintf (stderr, "/start_memory/%d", *p++);
955 break;
956
957 case stop_memory:
958 fprintf (stderr, "/stop_memory/%d", *p++);
959 break;
960
961 case duplicate:
962 fprintf (stderr, "/duplicate/%d", *p++);
963 break;
964
965 case anychar:
966 fprintf (stderr, "/anychar");
967 break;
968
969 case charset:
970 case charset_not:
971 {
972 register int c, last = -100;
973 register int in_range = 0;
974 int length = CHARSET_BITMAP_SIZE (p - 1);
975 int has_range_table = CHARSET_RANGE_TABLE_EXISTS_P (p - 1);
976
977 fprintf (stderr, "/charset [%s",
978 (re_opcode_t) *(p - 1) == charset_not ? "^" : "");
979
980 if (p + *p >= pend)
981 fprintf (stderr, " !extends past end of pattern! ");
982
983 for (c = 0; c < 256; c++)
984 if (c / 8 < length
985 && (p[1 + (c/8)] & (1 << (c % 8))))
986 {
987 /* Are we starting a range? */
988 if (last + 1 == c && ! in_range)
989 {
990 fprintf (stderr, "-");
991 in_range = 1;
992 }
993 /* Have we broken a range? */
994 else if (last + 1 != c && in_range)
995 {
996 fprintf (stderr, "%c", last);
997 in_range = 0;
998 }
999
1000 if (! in_range)
1001 fprintf (stderr, "%c", c);
1002
1003 last = c;
1004 }
1005
1006 if (in_range)
1007 fprintf (stderr, "%c", last);
1008
1009 fprintf (stderr, "]");
1010
1011 p += 1 + length;
1012
1013 if (has_range_table)
1014 {
1015 int count;
1016 fprintf (stderr, "has-range-table");
1017
1018 /* ??? Should print the range table; for now, just skip it. */
1019 p += 2; /* skip range table bits */
1020 EXTRACT_NUMBER_AND_INCR (count, p);
1021 p = CHARSET_RANGE_TABLE_END (p, count);
1022 }
1023 }
1024 break;
1025
1026 case begline:
1027 fprintf (stderr, "/begline");
1028 break;
1029
1030 case endline:
1031 fprintf (stderr, "/endline");
1032 break;
1033
1034 case on_failure_jump:
1035 extract_number_and_incr (&mcnt, &p);
1036 fprintf (stderr, "/on_failure_jump to %d", p + mcnt - start);
1037 break;
1038
1039 case on_failure_keep_string_jump:
1040 extract_number_and_incr (&mcnt, &p);
1041 fprintf (stderr, "/on_failure_keep_string_jump to %d", p + mcnt - start);
1042 break;
1043
1044 case on_failure_jump_nastyloop:
1045 extract_number_and_incr (&mcnt, &p);
1046 fprintf (stderr, "/on_failure_jump_nastyloop to %d", p + mcnt - start);
1047 break;
1048
1049 case on_failure_jump_loop:
1050 extract_number_and_incr (&mcnt, &p);
1051 fprintf (stderr, "/on_failure_jump_loop to %d", p + mcnt - start);
1052 break;
1053
1054 case on_failure_jump_smart:
1055 extract_number_and_incr (&mcnt, &p);
1056 fprintf (stderr, "/on_failure_jump_smart to %d", p + mcnt - start);
1057 break;
1058
1059 case jump:
1060 extract_number_and_incr (&mcnt, &p);
1061 fprintf (stderr, "/jump to %d", p + mcnt - start);
1062 break;
1063
1064 case succeed_n:
1065 extract_number_and_incr (&mcnt, &p);
1066 extract_number_and_incr (&mcnt2, &p);
1067 fprintf (stderr, "/succeed_n to %d, %d times", p - 2 + mcnt - start, mcnt2);
1068 break;
1069
1070 case jump_n:
1071 extract_number_and_incr (&mcnt, &p);
1072 extract_number_and_incr (&mcnt2, &p);
1073 fprintf (stderr, "/jump_n to %d, %d times", p - 2 + mcnt - start, mcnt2);
1074 break;
1075
1076 case set_number_at:
1077 extract_number_and_incr (&mcnt, &p);
1078 extract_number_and_incr (&mcnt2, &p);
1079 fprintf (stderr, "/set_number_at location %d to %d", p - 2 + mcnt - start, mcnt2);
1080 break;
1081
1082 case wordbound:
1083 fprintf (stderr, "/wordbound");
1084 break;
1085
1086 case notwordbound:
1087 fprintf (stderr, "/notwordbound");
1088 break;
1089
1090 case wordbeg:
1091 fprintf (stderr, "/wordbeg");
1092 break;
1093
1094 case wordend:
1095 fprintf (stderr, "/wordend");
1096
1097 case syntaxspec:
1098 fprintf (stderr, "/syntaxspec");
1099 mcnt = *p++;
1100 fprintf (stderr, "/%d", mcnt);
1101 break;
1102
1103 case notsyntaxspec:
1104 fprintf (stderr, "/notsyntaxspec");
1105 mcnt = *p++;
1106 fprintf (stderr, "/%d", mcnt);
1107 break;
1108
1109# ifdef emacs
1110 case before_dot:
1111 fprintf (stderr, "/before_dot");
1112 break;
1113
1114 case at_dot:
1115 fprintf (stderr, "/at_dot");
1116 break;
1117
1118 case after_dot:
1119 fprintf (stderr, "/after_dot");
1120 break;
1121
1122 case categoryspec:
1123 fprintf (stderr, "/categoryspec");
1124 mcnt = *p++;
1125 fprintf (stderr, "/%d", mcnt);
1126 break;
1127
1128 case notcategoryspec:
1129 fprintf (stderr, "/notcategoryspec");
1130 mcnt = *p++;
1131 fprintf (stderr, "/%d", mcnt);
1132 break;
1133# endif /* emacs */
1134
1135 case begbuf:
1136 fprintf (stderr, "/begbuf");
1137 break;
1138
1139 case endbuf:
1140 fprintf (stderr, "/endbuf");
1141 break;
1142
1143 default:
1144 fprintf (stderr, "?%d", *(p-1));
1145 }
1146
1147 fprintf (stderr, "\n");
1148 }
1149
1150 fprintf (stderr, "%d:\tend of pattern.\n", p - start);
1151}
1152
1153
1154void
1155print_compiled_pattern (bufp)
1156 struct re_pattern_buffer *bufp;
1157{
1158 re_char *buffer = bufp->buffer;
1159
1160 print_partial_compiled_pattern (buffer, buffer + bufp->used);
1161 printf ("%ld bytes used/%ld bytes allocated.\n",
1162 bufp->used, bufp->allocated);
1163
1164 if (bufp->fastmap_accurate && bufp->fastmap)
1165 {
1166 printf ("fastmap: ");
1167 print_fastmap (bufp->fastmap);
1168 }
1169
1170 printf ("re_nsub: %d\t", bufp->re_nsub);
1171 printf ("regs_alloc: %d\t", bufp->regs_allocated);
1172 printf ("can_be_null: %d\t", bufp->can_be_null);
1173 printf ("no_sub: %d\t", bufp->no_sub);
1174 printf ("not_bol: %d\t", bufp->not_bol);
1175 printf ("not_eol: %d\t", bufp->not_eol);
1176 printf ("syntax: %lx\n", bufp->syntax);
1177 fflush (stdout);
1178 /* Perhaps we should print the translate table? */
1179}
1180
1181
1182void
1183print_double_string (where, string1, size1, string2, size2)
1184 re_char *where;
1185 re_char *string1;
1186 re_char *string2;
1187 int size1;
1188 int size2;
1189{
1190 int this_char;
1191
1192 if (where == NULL)
1193 printf ("(null)");
1194 else
1195 {
1196 if (FIRST_STRING_P (where))
1197 {
1198 for (this_char = where - string1; this_char < size1; this_char++)
1199 putchar (string1[this_char]);
1200
1201 where = string2;
1202 }
1203
1204 for (this_char = where - string2; this_char < size2; this_char++)
1205 putchar (string2[this_char]);
1206 }
1207}
1208
1209#else /* not DEBUG */
1210
1211# undef assert
1212# define assert(e)
1213
1214# define DEBUG_STATEMENT(e)
1215# define DEBUG_PRINT1(x)
1216# define DEBUG_PRINT2(x1, x2)
1217# define DEBUG_PRINT3(x1, x2, x3)
1218# define DEBUG_PRINT4(x1, x2, x3, x4)
1219# define DEBUG_PRINT_COMPILED_PATTERN(p, s, e)
1220# define DEBUG_PRINT_DOUBLE_STRING(w, s1, sz1, s2, sz2)
1221
1222#endif /* not DEBUG */
1223
1224/* Set by `re_set_syntax' to the current regexp syntax to recognize. Can
1225 also be assigned to arbitrarily: each pattern buffer stores its own
1226 syntax, so it can be changed between regex compilations. */
1227/* This has no initializer because initialized variables in Emacs
1228 become read-only after dumping. */
1229reg_syntax_t re_syntax_options;
1230
1231
1232/* Specify the precise syntax of regexps for compilation. This provides
1233 for compatibility for various utilities which historically have
1234 different, incompatible syntaxes.
1235
1236 The argument SYNTAX is a bit mask comprised of the various bits
1237 defined in regex.h. We return the old syntax. */
1238
1239reg_syntax_t
1240re_set_syntax (syntax)
1241 reg_syntax_t syntax;
1242{
1243 reg_syntax_t ret = re_syntax_options;
1244
1245 re_syntax_options = syntax;
1246 return ret;
1247}
1248WEAK_ALIAS (__re_set_syntax, re_set_syntax)
1249
1250/* This table gives an error message for each of the error codes listed
1251 in regex.h. Obviously the order here has to be same as there.
1252 POSIX doesn't require that we do anything for REG_NOERROR,
1253 but why not be nice? */
1254
1255static const char *re_error_msgid[] =
1256 {
1257 gettext_noop ("Success"), /* REG_NOERROR */
1258 gettext_noop ("No match"), /* REG_NOMATCH */
1259 gettext_noop ("Invalid regular expression"), /* REG_BADPAT */
1260 gettext_noop ("Invalid collation character"), /* REG_ECOLLATE */
1261 gettext_noop ("Invalid character class name"), /* REG_ECTYPE */
1262 gettext_noop ("Trailing backslash"), /* REG_EESCAPE */
1263 gettext_noop ("Invalid back reference"), /* REG_ESUBREG */
1264 gettext_noop ("Unmatched [ or [^"), /* REG_EBRACK */
1265 gettext_noop ("Unmatched ( or \\("), /* REG_EPAREN */
1266 gettext_noop ("Unmatched \\{"), /* REG_EBRACE */
1267 gettext_noop ("Invalid content of \\{\\}"), /* REG_BADBR */
1268 gettext_noop ("Invalid range end"), /* REG_ERANGE */
1269 gettext_noop ("Memory exhausted"), /* REG_ESPACE */
1270 gettext_noop ("Invalid preceding regular expression"), /* REG_BADRPT */
1271 gettext_noop ("Premature end of regular expression"), /* REG_EEND */
1272 gettext_noop ("Regular expression too big"), /* REG_ESIZE */
1273 gettext_noop ("Unmatched ) or \\)"), /* REG_ERPAREN */
1274 };
1275
1276/* Avoiding alloca during matching, to placate r_alloc. */
1277
1278/* Define MATCH_MAY_ALLOCATE unless we need to make sure that the
1279 searching and matching functions should not call alloca. On some
1280 systems, alloca is implemented in terms of malloc, and if we're
1281 using the relocating allocator routines, then malloc could cause a
1282 relocation, which might (if the strings being searched are in the
1283 ralloc heap) shift the data out from underneath the regexp
1284 routines.
1285
1286 Here's another reason to avoid allocation: Emacs
1287 processes input from X in a signal handler; processing X input may
1288 call malloc; if input arrives while a matching routine is calling
1289 malloc, then we're scrod. But Emacs can't just block input while
1290 calling matching routines; then we don't notice interrupts when
1291 they come in. So, Emacs blocks input around all regexp calls
1292 except the matching calls, which it leaves unprotected, in the
1293 faith that they will not malloc. */
1294
1295/* Normally, this is fine. */
1296#define MATCH_MAY_ALLOCATE
1297
1298/* When using GNU C, we are not REALLY using the C alloca, no matter
1299 what config.h may say. So don't take precautions for it. */
1300#ifdef __GNUC__
1301# undef C_ALLOCA
1302#endif
1303
1304/* The match routines may not allocate if (1) they would do it with malloc
1305 and (2) it's not safe for them to use malloc.
1306 Note that if REL_ALLOC is defined, matching would not use malloc for the
1307 failure stack, but we would still use it for the register vectors;
1308 so REL_ALLOC should not affect this. */
1309#if (defined C_ALLOCA || defined REGEX_MALLOC) && defined emacs
1310# undef MATCH_MAY_ALLOCATE
1311#endif
1312
1313
1314/* Failure stack declarations and macros; both re_compile_fastmap and
1315 re_match_2 use a failure stack. These have to be macros because of
1316 REGEX_ALLOCATE_STACK. */
1317
1318
1319/* Approximate number of failure points for which to initially allocate space
1320 when matching. If this number is exceeded, we allocate more
1321 space, so it is not a hard limit. */
1322#ifndef INIT_FAILURE_ALLOC
1323# define INIT_FAILURE_ALLOC 20
1324#endif
1325
1326/* Roughly the maximum number of failure points on the stack. Would be
1327 exactly that if always used TYPICAL_FAILURE_SIZE items each time we failed.
1328 This is a variable only so users of regex can assign to it; we never
1329 change it ourselves. We always multiply it by TYPICAL_FAILURE_SIZE
1330 before using it, so it should probably be a byte-count instead. */
1331# if defined MATCH_MAY_ALLOCATE
1332/* Note that 4400 was enough to cause a crash on Alpha OSF/1,
1333 whose default stack limit is 2mb. In order for a larger
1334 value to work reliably, you have to try to make it accord
1335 with the process stack limit. */
1336size_t re_max_failures = 40000;
1337# else
1338size_t re_max_failures = 4000;
1339# endif
1340
1341union fail_stack_elt
1342{
1343 re_char *pointer;
1344 /* This should be the biggest `int' that's no bigger than a pointer. */
1345 long integer;
1346};
1347
1348typedef union fail_stack_elt fail_stack_elt_t;
1349
1350typedef struct
1351{
1352 fail_stack_elt_t *stack;
1353 size_t size;
1354 size_t avail; /* Offset of next open position. */
1355 size_t frame; /* Offset of the cur constructed frame. */
1356} fail_stack_type;
1357
1358#define FAIL_STACK_EMPTY() (fail_stack.frame == 0)
1359#define FAIL_STACK_FULL() (fail_stack.avail == fail_stack.size)
1360
1361
1362/* Define macros to initialize and free the failure stack.
1363 Do `return -2' if the alloc fails. */
1364
1365#ifdef MATCH_MAY_ALLOCATE
1366# define INIT_FAIL_STACK() \
1367 do { \
1368 fail_stack.stack = (fail_stack_elt_t *) \
1369 REGEX_ALLOCATE_STACK (INIT_FAILURE_ALLOC * TYPICAL_FAILURE_SIZE \
1370 * sizeof (fail_stack_elt_t)); \
1371 \
1372 if (fail_stack.stack == NULL) \
1373 return -2; \
1374 \
1375 fail_stack.size = INIT_FAILURE_ALLOC; \
1376 fail_stack.avail = 0; \
1377 fail_stack.frame = 0; \
1378 } while (0)
1379
1380# define RESET_FAIL_STACK() REGEX_FREE_STACK (fail_stack.stack)
1381#else
1382# define INIT_FAIL_STACK() \
1383 do { \
1384 fail_stack.avail = 0; \
1385 fail_stack.frame = 0; \
1386 } while (0)
1387
1388# define RESET_FAIL_STACK() ((void)0)
1389#endif
1390
1391
1392/* Double the size of FAIL_STACK, up to a limit
1393 which allows approximately `re_max_failures' items.
1394
1395 Return 1 if succeeds, and 0 if either ran out of memory
1396 allocating space for it or it was already too large.
1397
1398 REGEX_REALLOCATE_STACK requires `destination' be declared. */
1399
1400/* Factor to increase the failure stack size by
1401 when we increase it.
1402 This used to be 2, but 2 was too wasteful
1403 because the old discarded stacks added up to as much space
1404 were as ultimate, maximum-size stack. */
1405#define FAIL_STACK_GROWTH_FACTOR 4
1406
1407#define GROW_FAIL_STACK(fail_stack) \
1408 (((fail_stack).size * sizeof (fail_stack_elt_t) \
1409 >= re_max_failures * TYPICAL_FAILURE_SIZE) \
1410 ? 0 \
1411 : ((fail_stack).stack \
1412 = (fail_stack_elt_t *) \
1413 REGEX_REALLOCATE_STACK ((fail_stack).stack, \
1414 (fail_stack).size * sizeof (fail_stack_elt_t), \
1415 MIN (re_max_failures * TYPICAL_FAILURE_SIZE, \
1416 ((fail_stack).size * sizeof (fail_stack_elt_t) \
1417 * FAIL_STACK_GROWTH_FACTOR))), \
1418 \
1419 (fail_stack).stack == NULL \
1420 ? 0 \
1421 : ((fail_stack).size \
1422 = (MIN (re_max_failures * TYPICAL_FAILURE_SIZE, \
1423 ((fail_stack).size * sizeof (fail_stack_elt_t) \
1424 * FAIL_STACK_GROWTH_FACTOR)) \
1425 / sizeof (fail_stack_elt_t)), \
1426 1)))
1427
1428
1429/* Push a pointer value onto the failure stack.
1430 Assumes the variable `fail_stack'. Probably should only
1431 be called from within `PUSH_FAILURE_POINT'. */
1432#define PUSH_FAILURE_POINTER(item) \
1433 fail_stack.stack[fail_stack.avail++].pointer = (item)
1434
1435/* This pushes an integer-valued item onto the failure stack.
1436 Assumes the variable `fail_stack'. Probably should only
1437 be called from within `PUSH_FAILURE_POINT'. */
1438#define PUSH_FAILURE_INT(item) \
1439 fail_stack.stack[fail_stack.avail++].integer = (item)
1440
1441/* Push a fail_stack_elt_t value onto the failure stack.
1442 Assumes the variable `fail_stack'. Probably should only
1443 be called from within `PUSH_FAILURE_POINT'. */
1444#define PUSH_FAILURE_ELT(item) \
1445 fail_stack.stack[fail_stack.avail++] = (item)
1446
1447/* These three POP... operations complement the three PUSH... operations.
1448 All assume that `fail_stack' is nonempty. */
1449#define POP_FAILURE_POINTER() fail_stack.stack[--fail_stack.avail].pointer
1450#define POP_FAILURE_INT() fail_stack.stack[--fail_stack.avail].integer
1451#define POP_FAILURE_ELT() fail_stack.stack[--fail_stack.avail]
1452
1453/* Individual items aside from the registers. */
1454#define NUM_NONREG_ITEMS 3
1455
1456/* Used to examine the stack (to detect infinite loops). */
1457#define FAILURE_PAT(h) fail_stack.stack[(h) - 1].pointer
1458#define FAILURE_STR(h) (fail_stack.stack[(h) - 2].pointer)
1459#define NEXT_FAILURE_HANDLE(h) fail_stack.stack[(h) - 3].integer
1460#define TOP_FAILURE_HANDLE() fail_stack.frame
1461
1462
1463#define ENSURE_FAIL_STACK(space) \
1464while (REMAINING_AVAIL_SLOTS <= space) { \
1465 if (!GROW_FAIL_STACK (fail_stack)) \
1466 return -2; \
1467 DEBUG_PRINT2 ("\n Doubled stack; size now: %d\n", (fail_stack).size);\
1468 DEBUG_PRINT2 (" slots available: %d\n", REMAINING_AVAIL_SLOTS);\
1469}
1470
1471/* Push register NUM onto the stack. */
1472#define PUSH_FAILURE_REG(num) \
1473do { \
1474 char *destination; \
1475 ENSURE_FAIL_STACK(3); \
1476 DEBUG_PRINT4 (" Push reg %d (spanning %p -> %p)\n", \
1477 num, regstart[num], regend[num]); \
1478 PUSH_FAILURE_POINTER (regstart[num]); \
1479 PUSH_FAILURE_POINTER (regend[num]); \
1480 PUSH_FAILURE_INT (num); \
1481} while (0)
1482
1483/* Change the counter's value to VAL, but make sure that it will
1484 be reset when backtracking. */
1485#define PUSH_NUMBER(ptr,val) \
1486do { \
1487 char *destination; \
1488 int c; \
1489 ENSURE_FAIL_STACK(3); \
1490 EXTRACT_NUMBER (c, ptr); \
1491 DEBUG_PRINT4 (" Push number %p = %d -> %d\n", ptr, c, val); \
1492 PUSH_FAILURE_INT (c); \
1493 PUSH_FAILURE_POINTER (ptr); \
1494 PUSH_FAILURE_INT (-1); \
1495 STORE_NUMBER (ptr, val); \
1496} while (0)
1497
1498/* Pop a saved register off the stack. */
1499#define POP_FAILURE_REG_OR_COUNT() \
1500do { \
1501 int reg = POP_FAILURE_INT (); \
1502 if (reg == -1) \
1503 { \
1504 /* It's a counter. */ \
1505 /* Here, we discard `const', making re_match non-reentrant. */ \
1506 unsigned char *ptr = (unsigned char*) POP_FAILURE_POINTER (); \
1507 reg = POP_FAILURE_INT (); \
1508 STORE_NUMBER (ptr, reg); \
1509 DEBUG_PRINT3 (" Pop counter %p = %d\n", ptr, reg); \
1510 } \
1511 else \
1512 { \
1513 regend[reg] = POP_FAILURE_POINTER (); \
1514 regstart[reg] = POP_FAILURE_POINTER (); \
1515 DEBUG_PRINT4 (" Pop reg %d (spanning %p -> %p)\n", \
1516 reg, regstart[reg], regend[reg]); \
1517 } \
1518} while (0)
1519
1520/* Check that we are not stuck in an infinite loop. */
1521#define CHECK_INFINITE_LOOP(pat_cur, string_place) \
1522do { \
1523 int failure = TOP_FAILURE_HANDLE (); \
1524 /* Check for infinite matching loops */ \
1525 while (failure > 0 \
1526 && (FAILURE_STR (failure) == string_place \
1527 || FAILURE_STR (failure) == NULL)) \
1528 { \
1529 assert (FAILURE_PAT (failure) >= bufp->buffer \
1530 && FAILURE_PAT (failure) <= bufp->buffer + bufp->used); \
1531 if (FAILURE_PAT (failure) == pat_cur) \
1532 { \
1533 cycle = 1; \
1534 break; \
1535 } \
1536 DEBUG_PRINT2 (" Other pattern: %p\n", FAILURE_PAT (failure)); \
1537 failure = NEXT_FAILURE_HANDLE(failure); \
1538 } \
1539 DEBUG_PRINT2 (" Other string: %p\n", FAILURE_STR (failure)); \
1540} while (0)
1541
1542/* Push the information about the state we will need
1543 if we ever fail back to it.
1544
1545 Requires variables fail_stack, regstart, regend and
1546 num_regs be declared. GROW_FAIL_STACK requires `destination' be
1547 declared.
1548
1549 Does `return FAILURE_CODE' if runs out of memory. */
1550
1551#define PUSH_FAILURE_POINT(pattern, string_place) \
1552do { \
1553 char *destination; \
1554 /* Must be int, so when we don't save any registers, the arithmetic \
1555 of 0 + -1 isn't done as unsigned. */ \
1556 \
1557 DEBUG_STATEMENT (nfailure_points_pushed++); \
1558 DEBUG_PRINT1 ("\nPUSH_FAILURE_POINT:\n"); \
1559 DEBUG_PRINT2 (" Before push, next avail: %d\n", (fail_stack).avail); \
1560 DEBUG_PRINT2 (" size: %d\n", (fail_stack).size);\
1561 \
1562 ENSURE_FAIL_STACK (NUM_NONREG_ITEMS); \
1563 \
1564 DEBUG_PRINT1 ("\n"); \
1565 \
1566 DEBUG_PRINT2 (" Push frame index: %d\n", fail_stack.frame); \
1567 PUSH_FAILURE_INT (fail_stack.frame); \
1568 \
1569 DEBUG_PRINT2 (" Push string %p: `", string_place); \
1570 DEBUG_PRINT_DOUBLE_STRING (string_place, string1, size1, string2, size2);\
1571 DEBUG_PRINT1 ("'\n"); \
1572 PUSH_FAILURE_POINTER (string_place); \
1573 \
1574 DEBUG_PRINT2 (" Push pattern %p: ", pattern); \
1575 DEBUG_PRINT_COMPILED_PATTERN (bufp, pattern, pend); \
1576 PUSH_FAILURE_POINTER (pattern); \
1577 \
1578 /* Close the frame by moving the frame pointer past it. */ \
1579 fail_stack.frame = fail_stack.avail; \
1580} while (0)
1581
1582/* Estimate the size of data pushed by a typical failure stack entry.
1583 An estimate is all we need, because all we use this for
1584 is to choose a limit for how big to make the failure stack. */
1585/* BEWARE, the value `20' is hard-coded in emacs.c:main(). */
1586#define TYPICAL_FAILURE_SIZE 20
1587
1588/* How many items can still be added to the stack without overflowing it. */
1589#define REMAINING_AVAIL_SLOTS ((fail_stack).size - (fail_stack).avail)
1590
1591
1592/* Pops what PUSH_FAIL_STACK pushes.
1593
1594 We restore into the parameters, all of which should be lvalues:
1595 STR -- the saved data position.
1596 PAT -- the saved pattern position.
1597 REGSTART, REGEND -- arrays of string positions.
1598
1599 Also assumes the variables `fail_stack' and (if debugging), `bufp',
1600 `pend', `string1', `size1', `string2', and `size2'. */
1601
1602#define POP_FAILURE_POINT(str, pat) \
1603do { \
1604 assert (!FAIL_STACK_EMPTY ()); \
1605 \
1606 /* Remove failure points and point to how many regs pushed. */ \
1607 DEBUG_PRINT1 ("POP_FAILURE_POINT:\n"); \
1608 DEBUG_PRINT2 (" Before pop, next avail: %d\n", fail_stack.avail); \
1609 DEBUG_PRINT2 (" size: %d\n", fail_stack.size); \
1610 \
1611 /* Pop the saved registers. */ \
1612 while (fail_stack.frame < fail_stack.avail) \
1613 POP_FAILURE_REG_OR_COUNT (); \
1614 \
1615 pat = POP_FAILURE_POINTER (); \
1616 DEBUG_PRINT2 (" Popping pattern %p: ", pat); \
1617 DEBUG_PRINT_COMPILED_PATTERN (bufp, pat, pend); \
1618 \
1619 /* If the saved string location is NULL, it came from an \
1620 on_failure_keep_string_jump opcode, and we want to throw away the \
1621 saved NULL, thus retaining our current position in the string. */ \
1622 str = POP_FAILURE_POINTER (); \
1623 DEBUG_PRINT2 (" Popping string %p: `", str); \
1624 DEBUG_PRINT_DOUBLE_STRING (str, string1, size1, string2, size2); \
1625 DEBUG_PRINT1 ("'\n"); \
1626 \
1627 fail_stack.frame = POP_FAILURE_INT (); \
1628 DEBUG_PRINT2 (" Popping frame index: %d\n", fail_stack.frame); \
1629 \
1630 assert (fail_stack.avail >= 0); \
1631 assert (fail_stack.frame <= fail_stack.avail); \
1632 \
1633 DEBUG_STATEMENT (nfailure_points_popped++); \
1634} while (0) /* POP_FAILURE_POINT */
1635
1636
1637
1638/* Registers are set to a sentinel when they haven't yet matched. */
1639#define REG_UNSET(e) ((e) == NULL)
1640
1641/* Subroutine declarations and macros for regex_compile. */
1642
1643static reg_errcode_t regex_compile _RE_ARGS ((re_char *pattern, size_t size,
1644 reg_syntax_t syntax,
1645 struct re_pattern_buffer *bufp));
1646static void store_op1 _RE_ARGS ((re_opcode_t op, unsigned char *loc, int arg));
1647static void store_op2 _RE_ARGS ((re_opcode_t op, unsigned char *loc,
1648 int arg1, int arg2));
1649static void insert_op1 _RE_ARGS ((re_opcode_t op, unsigned char *loc,
1650 int arg, unsigned char *end));
1651static void insert_op2 _RE_ARGS ((re_opcode_t op, unsigned char *loc,
1652 int arg1, int arg2, unsigned char *end));
1653static boolean at_begline_loc_p _RE_ARGS ((re_char *pattern,
1654 re_char *p,
1655 reg_syntax_t syntax));
1656static boolean at_endline_loc_p _RE_ARGS ((re_char *p,
1657 re_char *pend,
1658 reg_syntax_t syntax));
1659static re_char *skip_one_char _RE_ARGS ((re_char *p));
1660static int analyse_first _RE_ARGS ((re_char *p, re_char *pend,
1661 char *fastmap, const int multibyte));
1662
1663/* Fetch the next character in the uncompiled pattern, with no
1664 translation. */
1665#define PATFETCH(c) \
1666 do { \
1667 int len; \
1668 if (p == pend) return REG_EEND; \
1669 c = RE_STRING_CHAR_AND_LENGTH (p, pend - p, len); \
1670 p += len; \
1671 } while (0)
1672
1673
1674/* If `translate' is non-null, return translate[D], else just D. We
1675 cast the subscript to translate because some data is declared as
1676 `char *', to avoid warnings when a string constant is passed. But
1677 when we use a character as a subscript we must make it unsigned. */
1678#ifndef TRANSLATE
1679# define TRANSLATE(d) \
1680 (RE_TRANSLATE_P (translate) ? RE_TRANSLATE (translate, (d)) : (d))
1681#endif
1682
1683
1684/* Macros for outputting the compiled pattern into `buffer'. */
1685
1686/* If the buffer isn't allocated when it comes in, use this. */
1687#define INIT_BUF_SIZE 32
1688
1689/* Make sure we have at least N more bytes of space in buffer. */
1690#define GET_BUFFER_SPACE(n) \
1691 while ((size_t) (b - bufp->buffer + (n)) > bufp->allocated) \
1692 EXTEND_BUFFER ()
1693
1694/* Make sure we have one more byte of buffer space and then add C to it. */
1695#define BUF_PUSH(c) \
1696 do { \
1697 GET_BUFFER_SPACE (1); \
1698 *b++ = (unsigned char) (c); \
1699 } while (0)
1700
1701
1702/* Ensure we have two more bytes of buffer space and then append C1 and C2. */
1703#define BUF_PUSH_2(c1, c2) \
1704 do { \
1705 GET_BUFFER_SPACE (2); \
1706 *b++ = (unsigned char) (c1); \
1707 *b++ = (unsigned char) (c2); \
1708 } while (0)
1709
1710
1711/* As with BUF_PUSH_2, except for three bytes. */
1712#define BUF_PUSH_3(c1, c2, c3) \
1713 do { \
1714 GET_BUFFER_SPACE (3); \
1715 *b++ = (unsigned char) (c1); \
1716 *b++ = (unsigned char) (c2); \
1717 *b++ = (unsigned char) (c3); \
1718 } while (0)
1719
1720
1721/* Store a jump with opcode OP at LOC to location TO. We store a
1722 relative address offset by the three bytes the jump itself occupies. */
1723#define STORE_JUMP(op, loc, to) \
1724 store_op1 (op, loc, (to) - (loc) - 3)
1725
1726/* Likewise, for a two-argument jump. */
1727#define STORE_JUMP2(op, loc, to, arg) \
1728 store_op2 (op, loc, (to) - (loc) - 3, arg)
1729
1730/* Like `STORE_JUMP', but for inserting. Assume `b' is the buffer end. */
1731#define INSERT_JUMP(op, loc, to) \
1732 insert_op1 (op, loc, (to) - (loc) - 3, b)
1733
1734/* Like `STORE_JUMP2', but for inserting. Assume `b' is the buffer end. */
1735#define INSERT_JUMP2(op, loc, to, arg) \
1736 insert_op2 (op, loc, (to) - (loc) - 3, arg, b)
1737
1738
1739/* This is not an arbitrary limit: the arguments which represent offsets
1740 into the pattern are two bytes long. So if 2^15 bytes turns out to
1741 be too small, many things would have to change. */
1742# define MAX_BUF_SIZE (1L << 15)
1743
1744#if 0 /* This is when we thought it could be 2^16 bytes. */
1745/* Any other compiler which, like MSC, has allocation limit below 2^16
1746 bytes will have to use approach similar to what was done below for
1747 MSC and drop MAX_BUF_SIZE a bit. Otherwise you may end up
1748 reallocating to 0 bytes. Such thing is not going to work too well.
1749 You have been warned!! */
1750#if defined _MSC_VER && !defined WIN32
1751/* Microsoft C 16-bit versions limit malloc to approx 65512 bytes. */
1752# define MAX_BUF_SIZE 65500L
1753#else
1754# define MAX_BUF_SIZE (1L << 16)
1755#endif
1756#endif /* 0 */
1757
1758/* Extend the buffer by twice its current size via realloc and
1759 reset the pointers that pointed into the old block to point to the
1760 correct places in the new one. If extending the buffer results in it
1761 being larger than MAX_BUF_SIZE, then flag memory exhausted. */
1762#if __BOUNDED_POINTERS__
1763# define SET_HIGH_BOUND(P) (__ptrhigh (P) = __ptrlow (P) + bufp->allocated)
1764# define MOVE_BUFFER_POINTER(P) \
1765 (__ptrlow (P) += incr, SET_HIGH_BOUND (P), __ptrvalue (P) += incr)
1766# define ELSE_EXTEND_BUFFER_HIGH_BOUND \
1767 else \
1768 { \
1769 SET_HIGH_BOUND (b); \
1770 SET_HIGH_BOUND (begalt); \
1771 if (fixup_alt_jump) \
1772 SET_HIGH_BOUND (fixup_alt_jump); \
1773 if (laststart) \
1774 SET_HIGH_BOUND (laststart); \
1775 if (pending_exact) \
1776 SET_HIGH_BOUND (pending_exact); \
1777 }
1778#else
1779# define MOVE_BUFFER_POINTER(P) (P) += incr
1780# define ELSE_EXTEND_BUFFER_HIGH_BOUND
1781#endif
1782#define EXTEND_BUFFER() \
1783 do { \
1784 re_char *old_buffer = bufp->buffer; \
1785 if (bufp->allocated == MAX_BUF_SIZE) \
1786 return REG_ESIZE; \
1787 bufp->allocated <<= 1; \
1788 if (bufp->allocated > MAX_BUF_SIZE) \
1789 bufp->allocated = MAX_BUF_SIZE; \
1790 RETALLOC (bufp->buffer, bufp->allocated, unsigned char); \
1791 if (bufp->buffer == NULL) \
1792 return REG_ESPACE; \
1793 /* If the buffer moved, move all the pointers into it. */ \
1794 if (old_buffer != bufp->buffer) \
1795 { \
1796 int incr = bufp->buffer - old_buffer; \
1797 MOVE_BUFFER_POINTER (b); \
1798 MOVE_BUFFER_POINTER (begalt); \
1799 if (fixup_alt_jump) \
1800 MOVE_BUFFER_POINTER (fixup_alt_jump); \
1801 if (laststart) \
1802 MOVE_BUFFER_POINTER (laststart); \
1803 if (pending_exact) \
1804 MOVE_BUFFER_POINTER (pending_exact); \
1805 } \
1806 ELSE_EXTEND_BUFFER_HIGH_BOUND \
1807 } while (0)
1808
1809
1810/* Since we have one byte reserved for the register number argument to
1811 {start,stop}_memory, the maximum number of groups we can report
1812 things about is what fits in that byte. */
1813#define MAX_REGNUM 255
1814
1815/* But patterns can have more than `MAX_REGNUM' registers. We just
1816 ignore the excess. */
1817typedef int regnum_t;
1818
1819
1820/* Macros for the compile stack. */
1821
1822/* Since offsets can go either forwards or backwards, this type needs to
1823 be able to hold values from -(MAX_BUF_SIZE - 1) to MAX_BUF_SIZE - 1. */
1824/* int may be not enough when sizeof(int) == 2. */
1825typedef long pattern_offset_t;
1826
1827typedef struct
1828{
1829 pattern_offset_t begalt_offset;
1830 pattern_offset_t fixup_alt_jump;
1831 pattern_offset_t laststart_offset;
1832 regnum_t regnum;
1833} compile_stack_elt_t;
1834
1835
1836typedef struct
1837{
1838 compile_stack_elt_t *stack;
1839 unsigned size;
1840 unsigned avail; /* Offset of next open position. */
1841} compile_stack_type;
1842
1843
1844#define INIT_COMPILE_STACK_SIZE 32
1845
1846#define COMPILE_STACK_EMPTY (compile_stack.avail == 0)
1847#define COMPILE_STACK_FULL (compile_stack.avail == compile_stack.size)
1848
1849/* The next available element. */
1850#define COMPILE_STACK_TOP (compile_stack.stack[compile_stack.avail])
1851
1852/* Explicit quit checking is only used on NTemacs. */
1853#if defined WINDOWSNT && defined emacs && defined QUIT
1854extern int immediate_quit;
1855# define IMMEDIATE_QUIT_CHECK \
1856 do { \
1857 if (immediate_quit) QUIT; \
1858 } while (0)
1859#else
1860# define IMMEDIATE_QUIT_CHECK ((void)0)
1861#endif
1862
1863/* Structure to manage work area for range table. */
1864struct range_table_work_area
1865{
1866 int *table; /* actual work area. */
1867 int allocated; /* allocated size for work area in bytes. */
1868 int used; /* actually used size in words. */
1869 int bits; /* flag to record character classes */
1870};
1871
1872/* Make sure that WORK_AREA can hold more N multibyte characters.
1873 This is used only in set_image_of_range and set_image_of_range_1.
1874 It expects WORK_AREA to be a pointer.
1875 If it can't get the space, it returns from the surrounding function. */
1876
1877#define EXTEND_RANGE_TABLE(work_area, n) \
1878 do { \
1879 if (((work_area)->used + (n)) * sizeof (int) > (work_area)->allocated) \
1880 { \
1881 extend_range_table_work_area (work_area); \
1882 if ((work_area)->table == 0) \
1883 return (REG_ESPACE); \
1884 } \
1885 } while (0)
1886
1887#define SET_RANGE_TABLE_WORK_AREA_BIT(work_area, bit) \
1888 (work_area).bits |= (bit)
1889
1890/* Bits used to implement the multibyte-part of the various character classes
1891 such as [:alnum:] in a charset's range table. */
1892#define BIT_WORD 0x1
1893#define BIT_LOWER 0x2
1894#define BIT_PUNCT 0x4
1895#define BIT_SPACE 0x8
1896#define BIT_UPPER 0x10
1897#define BIT_MULTIBYTE 0x20
1898
1899/* Set a range START..END to WORK_AREA.
1900 The range is passed through TRANSLATE, so START and END
1901 should be untranslated. */
1902#define SET_RANGE_TABLE_WORK_AREA(work_area, start, end) \
1903 do { \
1904 int tem; \
1905 tem = set_image_of_range (&work_area, start, end, translate); \
1906 if (tem > 0) \
1907 FREE_STACK_RETURN (tem); \
1908 } while (0)
1909
1910/* Free allocated memory for WORK_AREA. */
1911#define FREE_RANGE_TABLE_WORK_AREA(work_area) \
1912 do { \
1913 if ((work_area).table) \
1914 free ((work_area).table); \
1915 } while (0)
1916
1917#define CLEAR_RANGE_TABLE_WORK_USED(work_area) ((work_area).used = 0, (work_area).bits = 0)
1918#define RANGE_TABLE_WORK_USED(work_area) ((work_area).used)
1919#define RANGE_TABLE_WORK_BITS(work_area) ((work_area).bits)
1920#define RANGE_TABLE_WORK_ELT(work_area, i) ((work_area).table[i])
1921
1922
1923/* Set the bit for character C in a list. */
1924#define SET_LIST_BIT(c) (b[((c)) / BYTEWIDTH] |= 1 << ((c) % BYTEWIDTH))
1925
1926
1927/* Get the next unsigned number in the uncompiled pattern. */
1928#define GET_UNSIGNED_NUMBER(num) \
1929 do { if (p != pend) \
1930 { \
1931 PATFETCH (c); \
1932 if (c == ' ') \
1933 FREE_STACK_RETURN (REG_BADBR); \
1934 while ('0' <= c && c <= '9') \
1935 { \
1936 int prev; \
1937 if (num < 0) \
1938 num = 0; \
1939 prev = num; \
1940 num = num * 10 + c - '0'; \
1941 if (num / 10 != prev) \
1942 FREE_STACK_RETURN (REG_BADBR); \
1943 if (p == pend) \
1944 break; \
1945 PATFETCH (c); \
1946 } \
1947 if (c == ' ') \
1948 FREE_STACK_RETURN (REG_BADBR); \
1949 } \
1950 } while (0)
1951
1952#if WIDE_CHAR_SUPPORT
1953/* The GNU C library provides support for user-defined character classes
1954 and the functions from ISO C amendement 1. */
1955# ifdef CHARCLASS_NAME_MAX
1956# define CHAR_CLASS_MAX_LENGTH CHARCLASS_NAME_MAX
1957# else
1958/* This shouldn't happen but some implementation might still have this
1959 problem. Use a reasonable default value. */
1960# define CHAR_CLASS_MAX_LENGTH 256
1961# endif
1962typedef wctype_t re_wctype_t;
1963typedef wchar_t re_wchar_t;
1964# define re_wctype wctype
1965# define re_iswctype iswctype
1966# define re_wctype_to_bit(cc) 0
1967#else
1968# define CHAR_CLASS_MAX_LENGTH 9 /* Namely, `multibyte'. */
1969# define btowc(c) c
1970
1971/* Character classes. */
1972typedef enum { RECC_ERROR = 0,
1973 RECC_ALNUM, RECC_ALPHA, RECC_WORD,
1974 RECC_GRAPH, RECC_PRINT,
1975 RECC_LOWER, RECC_UPPER,
1976 RECC_PUNCT, RECC_CNTRL,
1977 RECC_DIGIT, RECC_XDIGIT,
1978 RECC_BLANK, RECC_SPACE,
1979 RECC_MULTIBYTE, RECC_NONASCII,
1980 RECC_ASCII, RECC_UNIBYTE
1981} re_wctype_t;
1982
1983typedef int re_wchar_t;
1984
1985/* Map a string to the char class it names (if any). */
1986static re_wctype_t
1987re_wctype (str)
1988 re_char *str;
1989{
1990 const char *string = str;
1991 if (STREQ (string, "alnum")) return RECC_ALNUM;
1992 else if (STREQ (string, "alpha")) return RECC_ALPHA;
1993 else if (STREQ (string, "word")) return RECC_WORD;
1994 else if (STREQ (string, "ascii")) return RECC_ASCII;
1995 else if (STREQ (string, "nonascii")) return RECC_NONASCII;
1996 else if (STREQ (string, "graph")) return RECC_GRAPH;
1997 else if (STREQ (string, "lower")) return RECC_LOWER;
1998 else if (STREQ (string, "print")) return RECC_PRINT;
1999 else if (STREQ (string, "punct")) return RECC_PUNCT;
2000 else if (STREQ (string, "space")) return RECC_SPACE;
2001 else if (STREQ (string, "upper")) return RECC_UPPER;
2002 else if (STREQ (string, "unibyte")) return RECC_UNIBYTE;
2003 else if (STREQ (string, "multibyte")) return RECC_MULTIBYTE;
2004 else if (STREQ (string, "digit")) return RECC_DIGIT;
2005 else if (STREQ (string, "xdigit")) return RECC_XDIGIT;
2006 else if (STREQ (string, "cntrl")) return RECC_CNTRL;
2007 else if (STREQ (string, "blank")) return RECC_BLANK;
2008 else return 0;
2009}
2010
2011/* True iff CH is in the char class CC. */
2012static boolean
2013re_iswctype (ch, cc)
2014 int ch;
2015 re_wctype_t cc;
2016{
2017 switch (cc)
2018 {
2019 case RECC_ALNUM: return ISALNUM (ch);
2020 case RECC_ALPHA: return ISALPHA (ch);
2021 case RECC_BLANK: return ISBLANK (ch);
2022 case RECC_CNTRL: return ISCNTRL (ch);
2023 case RECC_DIGIT: return ISDIGIT (ch);
2024 case RECC_GRAPH: return ISGRAPH (ch);
2025 case RECC_LOWER: return ISLOWER (ch);
2026 case RECC_PRINT: return ISPRINT (ch);
2027 case RECC_PUNCT: return ISPUNCT (ch);
2028 case RECC_SPACE: return ISSPACE (ch);
2029 case RECC_UPPER: return ISUPPER (ch);
2030 case RECC_XDIGIT: return ISXDIGIT (ch);
2031 case RECC_ASCII: return IS_REAL_ASCII (ch);
2032 case RECC_NONASCII: return !IS_REAL_ASCII (ch);
2033 case RECC_UNIBYTE: return ISUNIBYTE (ch);
2034 case RECC_MULTIBYTE: return !ISUNIBYTE (ch);
2035 case RECC_WORD: return ISWORD (ch);
2036 case RECC_ERROR: return false;
2037 default:
2038 abort();
2039 }
2040}
2041
2042/* Return a bit-pattern to use in the range-table bits to match multibyte
2043 chars of class CC. */
2044static int
2045re_wctype_to_bit (cc)
2046 re_wctype_t cc;
2047{
2048 switch (cc)
2049 {
2050 case RECC_NONASCII: case RECC_PRINT: case RECC_GRAPH:
2051 case RECC_MULTIBYTE: return BIT_MULTIBYTE;
2052 case RECC_ALPHA: case RECC_ALNUM: case RECC_WORD: return BIT_WORD;
2053 case RECC_LOWER: return BIT_LOWER;
2054 case RECC_UPPER: return BIT_UPPER;
2055 case RECC_PUNCT: return BIT_PUNCT;
2056 case RECC_SPACE: return BIT_SPACE;
2057 case RECC_ASCII: case RECC_DIGIT: case RECC_XDIGIT: case RECC_CNTRL:
2058 case RECC_BLANK: case RECC_UNIBYTE: case RECC_ERROR: return 0;
2059 default:
2060 abort();
2061 }
2062}
2063#endif
2064
2065/* Filling in the work area of a range. */
2066
2067/* Actually extend the space in WORK_AREA. */
2068
2069static void
2070extend_range_table_work_area (work_area)
2071 struct range_table_work_area *work_area;
2072{
2073 work_area->allocated += 16 * sizeof (int);
2074 if (work_area->table)
2075 work_area->table
2076 = (int *) realloc (work_area->table, work_area->allocated);
2077 else
2078 work_area->table
2079 = (int *) malloc (work_area->allocated);
2080}
2081
2082#ifdef emacs
2083
2084/* Carefully find the ranges of codes that are equivalent
2085 under case conversion to the range start..end when passed through
2086 TRANSLATE. Handle the case where non-letters can come in between
2087 two upper-case letters (which happens in Latin-1).
2088 Also handle the case of groups of more than 2 case-equivalent chars.
2089
2090 The basic method is to look at consecutive characters and see
2091 if they can form a run that can be handled as one.
2092
2093 Returns -1 if successful, REG_ESPACE if ran out of space. */
2094
2095static int
2096set_image_of_range_1 (work_area, start, end, translate)
2097 RE_TRANSLATE_TYPE translate;
2098 struct range_table_work_area *work_area;
2099 re_wchar_t start, end;
2100{
2101 /* `one_case' indicates a character, or a run of characters,
2102 each of which is an isolate (no case-equivalents).
2103 This includes all ASCII non-letters.
2104
2105 `two_case' indicates a character, or a run of characters,
2106 each of which has two case-equivalent forms.
2107 This includes all ASCII letters.
2108
2109 `strange' indicates a character that has more than one
2110 case-equivalent. */
2111
2112 enum case_type {one_case, two_case, strange};
2113
2114 /* Describe the run that is in progress,
2115 which the next character can try to extend.
2116 If run_type is strange, that means there really is no run.
2117 If run_type is one_case, then run_start...run_end is the run.
2118 If run_type is two_case, then the run is run_start...run_end,
2119 and the case-equivalents end at run_eqv_end. */
2120
2121 enum case_type run_type = strange;
2122 int run_start, run_end, run_eqv_end;
2123
2124 Lisp_Object eqv_table;
2125
2126 if (!RE_TRANSLATE_P (translate))
2127 {
2128 EXTEND_RANGE_TABLE (work_area, 2);
2129 work_area->table[work_area->used++] = (start);
2130 work_area->table[work_area->used++] = (end);
2131 return -1;
2132 }
2133
2134 eqv_table = XCHAR_TABLE (translate)->extras[2];
2135
2136 for (; start <= end; start++)
2137 {
2138 enum case_type this_type;
2139 int eqv = RE_TRANSLATE (eqv_table, start);
2140 int minchar, maxchar;
2141
2142 /* Classify this character */
2143 if (eqv == start)
2144 this_type = one_case;
2145 else if (RE_TRANSLATE (eqv_table, eqv) == start)
2146 this_type = two_case;
2147 else
2148 this_type = strange;
2149
2150 if (start < eqv)
2151 minchar = start, maxchar = eqv;
2152 else
2153 minchar = eqv, maxchar = start;
2154
2155 /* Can this character extend the run in progress? */
2156 if (this_type == strange || this_type != run_type
2157 || !(minchar == run_end + 1
2158 && (run_type == two_case
2159 ? maxchar == run_eqv_end + 1 : 1)))
2160 {
2161 /* No, end the run.
2162 Record each of its equivalent ranges. */
2163 if (run_type == one_case)
2164 {
2165 EXTEND_RANGE_TABLE (work_area, 2);
2166 work_area->table[work_area->used++] = run_start;
2167 work_area->table[work_area->used++] = run_end;
2168 }
2169 else if (run_type == two_case)
2170 {
2171 EXTEND_RANGE_TABLE (work_area, 4);
2172 work_area->table[work_area->used++] = run_start;
2173 work_area->table[work_area->used++] = run_end;
2174 work_area->table[work_area->used++]
2175 = RE_TRANSLATE (eqv_table, run_start);
2176 work_area->table[work_area->used++]
2177 = RE_TRANSLATE (eqv_table, run_end);
2178 }
2179 run_type = strange;
2180 }
2181
2182 if (this_type == strange)
2183 {
2184 /* For a strange character, add each of its equivalents, one
2185 by one. Don't start a range. */
2186 do
2187 {
2188 EXTEND_RANGE_TABLE (work_area, 2);
2189 work_area->table[work_area->used++] = eqv;
2190 work_area->table[work_area->used++] = eqv;
2191 eqv = RE_TRANSLATE (eqv_table, eqv);
2192 }
2193 while (eqv != start);
2194 }
2195
2196 /* Add this char to the run, or start a new run. */
2197 else if (run_type == strange)
2198 {
2199 /* Initialize a new range. */
2200 run_type = this_type;
2201 run_start = start;
2202 run_end = start;
2203 run_eqv_end = RE_TRANSLATE (eqv_table, run_end);
2204 }
2205 else
2206 {
2207 /* Extend a running range. */
2208 run_end = minchar;
2209 run_eqv_end = RE_TRANSLATE (eqv_table, run_end);
2210 }
2211 }
2212
2213 /* If a run is still in progress at the end, finish it now
2214 by recording its equivalent ranges. */
2215 if (run_type == one_case)
2216 {
2217 EXTEND_RANGE_TABLE (work_area, 2);
2218 work_area->table[work_area->used++] = run_start;
2219 work_area->table[work_area->used++] = run_end;
2220 }
2221 else if (run_type == two_case)
2222 {
2223 EXTEND_RANGE_TABLE (work_area, 4);
2224 work_area->table[work_area->used++] = run_start;
2225 work_area->table[work_area->used++] = run_end;
2226 work_area->table[work_area->used++]
2227 = RE_TRANSLATE (eqv_table, run_start);
2228 work_area->table[work_area->used++]
2229 = RE_TRANSLATE (eqv_table, run_end);
2230 }
2231
2232 return -1;
2233}
2234
2235#endif /* emacs */
2236
2237/* Record the the image of the range start..end when passed through
2238 TRANSLATE. This is not necessarily TRANSLATE(start)..TRANSLATE(end)
2239 and is not even necessarily contiguous.
2240 Normally we approximate it with the smallest contiguous range that contains
2241 all the chars we need. However, for Latin-1 we go to extra effort
2242 to do a better job.
2243
2244 This function is not called for ASCII ranges.
2245
2246 Returns -1 if successful, REG_ESPACE if ran out of space. */
2247
2248static int
2249set_image_of_range (work_area, start, end, translate)
2250 RE_TRANSLATE_TYPE translate;
2251 struct range_table_work_area *work_area;
2252 re_wchar_t start, end;
2253{
2254 re_wchar_t cmin, cmax;
2255
2256#ifdef emacs
2257 /* For Latin-1 ranges, use set_image_of_range_1
2258 to get proper handling of ranges that include letters and nonletters.
2259 For a range that includes the whole of Latin-1, this is not necessary.
2260 For other character sets, we don't bother to get this right. */
2261 if (RE_TRANSLATE_P (translate) && start < 04400
2262 && !(start < 04200 && end >= 04377))
2263 {
2264 int newend;
2265 int tem;
2266 newend = end;
2267 if (newend > 04377)
2268 newend = 04377;
2269 tem = set_image_of_range_1 (work_area, start, newend, translate);
2270 if (tem > 0)
2271 return tem;
2272
2273 start = 04400;
2274 if (end < 04400)
2275 return -1;
2276 }
2277#endif
2278
2279 EXTEND_RANGE_TABLE (work_area, 2);
2280 work_area->table[work_area->used++] = (start);
2281 work_area->table[work_area->used++] = (end);
2282
2283 cmin = -1, cmax = -1;
2284
2285 if (RE_TRANSLATE_P (translate))
2286 {
2287 int ch;
2288
2289 for (ch = start; ch <= end; ch++)
2290 {
2291 re_wchar_t c = TRANSLATE (ch);
2292 if (! (start <= c && c <= end))
2293 {
2294 if (cmin == -1)
2295 cmin = c, cmax = c;
2296 else
2297 {
2298 cmin = MIN (cmin, c);
2299 cmax = MAX (cmax, c);
2300 }
2301 }
2302 }
2303
2304 if (cmin != -1)
2305 {
2306 EXTEND_RANGE_TABLE (work_area, 2);
2307 work_area->table[work_area->used++] = (cmin);
2308 work_area->table[work_area->used++] = (cmax);
2309 }
2310 }
2311
2312 return -1;
2313}
2314
2315#ifndef MATCH_MAY_ALLOCATE
2316
2317/* If we cannot allocate large objects within re_match_2_internal,
2318 we make the fail stack and register vectors global.
2319 The fail stack, we grow to the maximum size when a regexp
2320 is compiled.
2321 The register vectors, we adjust in size each time we
2322 compile a regexp, according to the number of registers it needs. */
2323
2324static fail_stack_type fail_stack;
2325
2326/* Size with which the following vectors are currently allocated.
2327 That is so we can make them bigger as needed,
2328 but never make them smaller. */
2329static int regs_allocated_size;
2330
2331static re_char ** regstart, ** regend;
2332static re_char **best_regstart, **best_regend;
2333
2334/* Make the register vectors big enough for NUM_REGS registers,
2335 but don't make them smaller. */
2336
2337static
2338regex_grow_registers (num_regs)
2339 int num_regs;
2340{
2341 if (num_regs > regs_allocated_size)
2342 {
2343 RETALLOC_IF (regstart, num_regs, re_char *);
2344 RETALLOC_IF (regend, num_regs, re_char *);
2345 RETALLOC_IF (best_regstart, num_regs, re_char *);
2346 RETALLOC_IF (best_regend, num_regs, re_char *);
2347
2348 regs_allocated_size = num_regs;
2349 }
2350}
2351
2352#endif /* not MATCH_MAY_ALLOCATE */
2353
2354static boolean group_in_compile_stack _RE_ARGS ((compile_stack_type
2355 compile_stack,
2356 regnum_t regnum));
2357
2358/* `regex_compile' compiles PATTERN (of length SIZE) according to SYNTAX.
2359 Returns one of error codes defined in `regex.h', or zero for success.
2360
2361 Assumes the `allocated' (and perhaps `buffer') and `translate'
2362 fields are set in BUFP on entry.
2363
2364 If it succeeds, results are put in BUFP (if it returns an error, the
2365 contents of BUFP are undefined):
2366 `buffer' is the compiled pattern;
2367 `syntax' is set to SYNTAX;
2368 `used' is set to the length of the compiled pattern;
2369 `fastmap_accurate' is zero;
2370 `re_nsub' is the number of subexpressions in PATTERN;
2371 `not_bol' and `not_eol' are zero;
2372
2373 The `fastmap' field is neither examined nor set. */
2374
2375/* Insert the `jump' from the end of last alternative to "here".
2376 The space for the jump has already been allocated. */
2377#define FIXUP_ALT_JUMP() \
2378do { \
2379 if (fixup_alt_jump) \
2380 STORE_JUMP (jump, fixup_alt_jump, b); \
2381} while (0)
2382
2383
2384/* Return, freeing storage we allocated. */
2385#define FREE_STACK_RETURN(value) \
2386 do { \
2387 FREE_RANGE_TABLE_WORK_AREA (range_table_work); \
2388 free (compile_stack.stack); \
2389 return value; \
2390 } while (0)
2391
2392static reg_errcode_t
2393regex_compile (pattern, size, syntax, bufp)
2394 re_char *pattern;
2395 size_t size;
2396 reg_syntax_t syntax;
2397 struct re_pattern_buffer *bufp;
2398{
2399 /* We fetch characters from PATTERN here. */
2400 register re_wchar_t c, c1;
2401
2402 /* A random temporary spot in PATTERN. */
2403 re_char *p1;
2404
2405 /* Points to the end of the buffer, where we should append. */
2406 register unsigned char *b;
2407
2408 /* Keeps track of unclosed groups. */
2409 compile_stack_type compile_stack;
2410
2411 /* Points to the current (ending) position in the pattern. */
2412#ifdef AIX
2413 /* `const' makes AIX compiler fail. */
2414 unsigned char *p = pattern;
2415#else
2416 re_char *p = pattern;
2417#endif
2418 re_char *pend = pattern + size;
2419
2420 /* How to translate the characters in the pattern. */
2421 RE_TRANSLATE_TYPE translate = bufp->translate;
2422
2423 /* Address of the count-byte of the most recently inserted `exactn'
2424 command. This makes it possible to tell if a new exact-match
2425 character can be added to that command or if the character requires
2426 a new `exactn' command. */
2427 unsigned char *pending_exact = 0;
2428
2429 /* Address of start of the most recently finished expression.
2430 This tells, e.g., postfix * where to find the start of its
2431 operand. Reset at the beginning of groups and alternatives. */
2432 unsigned char *laststart = 0;
2433
2434 /* Address of beginning of regexp, or inside of last group. */
2435 unsigned char *begalt;
2436
2437 /* Place in the uncompiled pattern (i.e., the {) to
2438 which to go back if the interval is invalid. */
2439 re_char *beg_interval;
2440
2441 /* Address of the place where a forward jump should go to the end of
2442 the containing expression. Each alternative of an `or' -- except the
2443 last -- ends with a forward jump of this sort. */
2444 unsigned char *fixup_alt_jump = 0;
2445
2446 /* Counts open-groups as they are encountered. Remembered for the
2447 matching close-group on the compile stack, so the same register
2448 number is put in the stop_memory as the start_memory. */
2449 regnum_t regnum = 0;
2450
2451 /* Work area for range table of charset. */
2452 struct range_table_work_area range_table_work;
2453
2454 /* If the object matched can contain multibyte characters. */
2455 const boolean multibyte = RE_MULTIBYTE_P (bufp);
2456
2457#ifdef DEBUG
2458 debug++;
2459 DEBUG_PRINT1 ("\nCompiling pattern: ");
2460 if (debug > 0)
2461 {
2462 unsigned debug_count;
2463
2464 for (debug_count = 0; debug_count < size; debug_count++)
2465 putchar (pattern[debug_count]);
2466 putchar ('\n');
2467 }
2468#endif /* DEBUG */
2469
2470 /* Initialize the compile stack. */
2471 compile_stack.stack = TALLOC (INIT_COMPILE_STACK_SIZE, compile_stack_elt_t);
2472 if (compile_stack.stack == NULL)
2473 return REG_ESPACE;
2474
2475 compile_stack.size = INIT_COMPILE_STACK_SIZE;
2476 compile_stack.avail = 0;
2477
2478 range_table_work.table = 0;
2479 range_table_work.allocated = 0;
2480
2481 /* Initialize the pattern buffer. */
2482 bufp->syntax = syntax;
2483 bufp->fastmap_accurate = 0;
2484 bufp->not_bol = bufp->not_eol = 0;
2485
2486 /* Set `used' to zero, so that if we return an error, the pattern
2487 printer (for debugging) will think there's no pattern. We reset it
2488 at the end. */
2489 bufp->used = 0;
2490
2491 /* Always count groups, whether or not bufp->no_sub is set. */
2492 bufp->re_nsub = 0;
2493
2494#if !defined emacs && !defined SYNTAX_TABLE
2495 /* Initialize the syntax table. */
2496 init_syntax_once ();
2497#endif
2498
2499 if (bufp->allocated == 0)
2500 {
2501 if (bufp->buffer)
2502 { /* If zero allocated, but buffer is non-null, try to realloc
2503 enough space. This loses if buffer's address is bogus, but
2504 that is the user's responsibility. */
2505 RETALLOC (bufp->buffer, INIT_BUF_SIZE, unsigned char);
2506 }
2507 else
2508 { /* Caller did not allocate a buffer. Do it for them. */
2509 bufp->buffer = TALLOC (INIT_BUF_SIZE, unsigned char);
2510 }
2511 if (!bufp->buffer) FREE_STACK_RETURN (REG_ESPACE);
2512
2513 bufp->allocated = INIT_BUF_SIZE;
2514 }
2515
2516 begalt = b = bufp->buffer;
2517
2518 /* Loop through the uncompiled pattern until we're at the end. */
2519 while (p != pend)
2520 {
2521 PATFETCH (c);
2522
2523 switch (c)
2524 {
2525 case '^':
2526 {
2527 if ( /* If at start of pattern, it's an operator. */
2528 p == pattern + 1
2529 /* If context independent, it's an operator. */
2530 || syntax & RE_CONTEXT_INDEP_ANCHORS
2531 /* Otherwise, depends on what's come before. */
2532 || at_begline_loc_p (pattern, p, syntax))
2533 BUF_PUSH ((syntax & RE_NO_NEWLINE_ANCHOR) ? begbuf : begline);
2534 else
2535 goto normal_char;
2536 }
2537 break;
2538
2539
2540 case '$':
2541 {
2542 if ( /* If at end of pattern, it's an operator. */
2543 p == pend
2544 /* If context independent, it's an operator. */
2545 || syntax & RE_CONTEXT_INDEP_ANCHORS
2546 /* Otherwise, depends on what's next. */
2547 || at_endline_loc_p (p, pend, syntax))
2548 BUF_PUSH ((syntax & RE_NO_NEWLINE_ANCHOR) ? endbuf : endline);
2549 else
2550 goto normal_char;
2551 }
2552 break;
2553
2554
2555 case '+':
2556 case '?':
2557 if ((syntax & RE_BK_PLUS_QM)
2558 || (syntax & RE_LIMITED_OPS))
2559 goto normal_char;
2560 handle_plus:
2561 case '*':
2562 /* If there is no previous pattern... */
2563 if (!laststart)
2564 {
2565 if (syntax & RE_CONTEXT_INVALID_OPS)
2566 FREE_STACK_RETURN (REG_BADRPT);
2567 else if (!(syntax & RE_CONTEXT_INDEP_OPS))
2568 goto normal_char;
2569 }
2570
2571 {
2572 /* 1 means zero (many) matches is allowed. */
2573 boolean zero_times_ok = 0, many_times_ok = 0;
2574 boolean greedy = 1;
2575
2576 /* If there is a sequence of repetition chars, collapse it
2577 down to just one (the right one). We can't combine
2578 interval operators with these because of, e.g., `a{2}*',
2579 which should only match an even number of `a's. */
2580
2581 for (;;)
2582 {
2583 if ((syntax & RE_FRUGAL)
2584 && c == '?' && (zero_times_ok || many_times_ok))
2585 greedy = 0;
2586 else
2587 {
2588 zero_times_ok |= c != '+';
2589 many_times_ok |= c != '?';
2590 }
2591
2592 if (p == pend)
2593 break;
2594 else if (*p == '*'
2595 || (!(syntax & RE_BK_PLUS_QM)
2596 && (*p == '+' || *p == '?')))
2597 ;
2598 else if (syntax & RE_BK_PLUS_QM && *p == '\\')
2599 {
2600 if (p+1 == pend)
2601 FREE_STACK_RETURN (REG_EESCAPE);
2602 if (p[1] == '+' || p[1] == '?')
2603 PATFETCH (c); /* Gobble up the backslash. */
2604 else
2605 break;
2606 }
2607 else
2608 break;
2609 /* If we get here, we found another repeat character. */
2610 PATFETCH (c);
2611 }
2612
2613 /* Star, etc. applied to an empty pattern is equivalent
2614 to an empty pattern. */
2615 if (!laststart || laststart == b)
2616 break;
2617
2618 /* Now we know whether or not zero matches is allowed
2619 and also whether or not two or more matches is allowed. */
2620 if (greedy)
2621 {
2622 if (many_times_ok)
2623 {
2624 boolean simple = skip_one_char (laststart) == b;
2625 unsigned int startoffset = 0;
2626 re_opcode_t ofj =
2627 /* Check if the loop can match the empty string. */
2628 (simple || !analyse_first (laststart, b, NULL, 0))
2629 ? on_failure_jump : on_failure_jump_loop;
2630 assert (skip_one_char (laststart) <= b);
2631
2632 if (!zero_times_ok && simple)
2633 { /* Since simple * loops can be made faster by using
2634 on_failure_keep_string_jump, we turn simple P+
2635 into PP* if P is simple. */
2636 unsigned char *p1, *p2;
2637 startoffset = b - laststart;
2638 GET_BUFFER_SPACE (startoffset);
2639 p1 = b; p2 = laststart;
2640 while (p2 < p1)
2641 *b++ = *p2++;
2642 zero_times_ok = 1;
2643 }
2644
2645 GET_BUFFER_SPACE (6);
2646 if (!zero_times_ok)
2647 /* A + loop. */
2648 STORE_JUMP (ofj, b, b + 6);
2649 else
2650 /* Simple * loops can use on_failure_keep_string_jump
2651 depending on what follows. But since we don't know
2652 that yet, we leave the decision up to
2653 on_failure_jump_smart. */
2654 INSERT_JUMP (simple ? on_failure_jump_smart : ofj,
2655 laststart + startoffset, b + 6);
2656 b += 3;
2657 STORE_JUMP (jump, b, laststart + startoffset);
2658 b += 3;
2659 }
2660 else
2661 {
2662 /* A simple ? pattern. */
2663 assert (zero_times_ok);
2664 GET_BUFFER_SPACE (3);
2665 INSERT_JUMP (on_failure_jump, laststart, b + 3);
2666 b += 3;
2667 }
2668 }
2669 else /* not greedy */
2670 { /* I wish the greedy and non-greedy cases could be merged. */
2671
2672 GET_BUFFER_SPACE (7); /* We might use less. */
2673 if (many_times_ok)
2674 {
2675 boolean emptyp = analyse_first (laststart, b, NULL, 0);
2676
2677 /* The non-greedy multiple match looks like
2678 a repeat..until: we only need a conditional jump
2679 at the end of the loop. */
2680 if (emptyp) BUF_PUSH (no_op);
2681 STORE_JUMP (emptyp ? on_failure_jump_nastyloop
2682 : on_failure_jump, b, laststart);
2683 b += 3;
2684 if (zero_times_ok)
2685 {
2686 /* The repeat...until naturally matches one or more.
2687 To also match zero times, we need to first jump to
2688 the end of the loop (its conditional jump). */
2689 INSERT_JUMP (jump, laststart, b);
2690 b += 3;
2691 }
2692 }
2693 else
2694 {
2695 /* non-greedy a?? */
2696 INSERT_JUMP (jump, laststart, b + 3);
2697 b += 3;
2698 INSERT_JUMP (on_failure_jump, laststart, laststart + 6);
2699 b += 3;
2700 }
2701 }
2702 }
2703 pending_exact = 0;
2704 break;
2705
2706
2707 case '.':
2708 laststart = b;
2709 BUF_PUSH (anychar);
2710 break;
2711
2712
2713 case '[':
2714 {
2715 CLEAR_RANGE_TABLE_WORK_USED (range_table_work);
2716
2717 if (p == pend) FREE_STACK_RETURN (REG_EBRACK);
2718
2719 /* Ensure that we have enough space to push a charset: the
2720 opcode, the length count, and the bitset; 34 bytes in all. */
2721 GET_BUFFER_SPACE (34);
2722
2723 laststart = b;
2724
2725 /* We test `*p == '^' twice, instead of using an if
2726 statement, so we only need one BUF_PUSH. */
2727 BUF_PUSH (*p == '^' ? charset_not : charset);
2728 if (*p == '^')
2729 p++;
2730
2731 /* Remember the first position in the bracket expression. */
2732 p1 = p;
2733
2734 /* Push the number of bytes in the bitmap. */
2735 BUF_PUSH ((1 << BYTEWIDTH) / BYTEWIDTH);
2736
2737 /* Clear the whole map. */
2738 bzero (b, (1 << BYTEWIDTH) / BYTEWIDTH);
2739
2740 /* charset_not matches newline according to a syntax bit. */
2741 if ((re_opcode_t) b[-2] == charset_not
2742 && (syntax & RE_HAT_LISTS_NOT_NEWLINE))
2743 SET_LIST_BIT ('\n');
2744
2745 /* Read in characters and ranges, setting map bits. */
2746 for (;;)
2747 {
2748 boolean escaped_char = false;
2749 const unsigned char *p2 = p;
2750
2751 if (p == pend) FREE_STACK_RETURN (REG_EBRACK);
2752
2753 /* Don't translate yet. The range TRANSLATE(X..Y) cannot
2754 always be determined from TRANSLATE(X) and TRANSLATE(Y)
2755 So the translation is done later in a loop. Example:
2756 (let ((case-fold-search t)) (string-match "[A-_]" "A")) */
2757 PATFETCH (c);
2758
2759 /* \ might escape characters inside [...] and [^...]. */
2760 if ((syntax & RE_BACKSLASH_ESCAPE_IN_LISTS) && c == '\\')
2761 {
2762 if (p == pend) FREE_STACK_RETURN (REG_EESCAPE);
2763
2764 PATFETCH (c);
2765 escaped_char = true;
2766 }
2767 else
2768 {
2769 /* Could be the end of the bracket expression. If it's
2770 not (i.e., when the bracket expression is `[]' so
2771 far), the ']' character bit gets set way below. */
2772 if (c == ']' && p2 != p1)
2773 break;
2774 }
2775
2776 /* What should we do for the character which is
2777 greater than 0x7F, but not BASE_LEADING_CODE_P?
2778 XXX */
2779
2780 /* See if we're at the beginning of a possible character
2781 class. */
2782
2783 if (!escaped_char &&
2784 syntax & RE_CHAR_CLASSES && c == '[' && *p == ':')
2785 {
2786 /* Leave room for the null. */
2787 unsigned char str[CHAR_CLASS_MAX_LENGTH + 1];
2788 const unsigned char *class_beg;
2789
2790 PATFETCH (c);
2791 c1 = 0;
2792 class_beg = p;
2793
2794 /* If pattern is `[[:'. */
2795 if (p == pend) FREE_STACK_RETURN (REG_EBRACK);
2796
2797 for (;;)
2798 {
2799 PATFETCH (c);
2800 if ((c == ':' && *p == ']') || p == pend)
2801 break;
2802 if (c1 < CHAR_CLASS_MAX_LENGTH)
2803 str[c1++] = c;
2804 else
2805 /* This is in any case an invalid class name. */
2806 str[0] = '\0';
2807 }
2808 str[c1] = '\0';
2809
2810 /* If isn't a word bracketed by `[:' and `:]':
2811 undo the ending character, the letters, and
2812 leave the leading `:' and `[' (but set bits for
2813 them). */
2814 if (c == ':' && *p == ']')
2815 {
2816 re_wchar_t ch;
2817 re_wctype_t cc;
2818
2819 cc = re_wctype (str);
2820
2821 if (cc == 0)
2822 FREE_STACK_RETURN (REG_ECTYPE);
2823
2824 /* Throw away the ] at the end of the character
2825 class. */
2826 PATFETCH (c);
2827
2828 if (p == pend) FREE_STACK_RETURN (REG_EBRACK);
2829
2830 /* Most character classes in a multibyte match
2831 just set a flag. Exceptions are is_blank,
2832 is_digit, is_cntrl, and is_xdigit, since
2833 they can only match ASCII characters. We
2834 don't need to handle them for multibyte.
2835 They are distinguished by a negative wctype. */
2836
2837 if (multibyte)
2838 SET_RANGE_TABLE_WORK_AREA_BIT (range_table_work,
2839 re_wctype_to_bit (cc));
2840
2841 for (ch = 0; ch < 1 << BYTEWIDTH; ++ch)
2842 {
2843 int translated = TRANSLATE (ch);
2844 if (re_iswctype (btowc (ch), cc))
2845 SET_LIST_BIT (translated);
2846 }
2847
2848 /* Repeat the loop. */
2849 continue;
2850 }
2851 else
2852 {
2853 /* Go back to right after the "[:". */
2854 p = class_beg;
2855 SET_LIST_BIT ('[');
2856
2857 /* Because the `:' may starts the range, we
2858 can't simply set bit and repeat the loop.
2859 Instead, just set it to C and handle below. */
2860 c = ':';
2861 }
2862 }
2863
2864 if (p < pend && p[0] == '-' && p[1] != ']')
2865 {
2866
2867 /* Discard the `-'. */
2868 PATFETCH (c1);
2869
2870 /* Fetch the character which ends the range. */
2871 PATFETCH (c1);
2872
2873 if (SINGLE_BYTE_CHAR_P (c))
2874 {
2875 if (! SINGLE_BYTE_CHAR_P (c1))
2876 {
2877 /* Handle a range starting with a
2878 character of less than 256, and ending
2879 with a character of not less than 256.
2880 Split that into two ranges, the low one
2881 ending at 0377, and the high one
2882 starting at the smallest character in
2883 the charset of C1 and ending at C1. */
2884 int charset = CHAR_CHARSET (c1);
2885 re_wchar_t c2 = MAKE_CHAR (charset, 0, 0);
2886
2887 SET_RANGE_TABLE_WORK_AREA (range_table_work,
2888 c2, c1);
2889 c1 = 0377;
2890 }
2891 }
2892 else if (!SAME_CHARSET_P (c, c1))
2893 FREE_STACK_RETURN (REG_ERANGE);
2894 }
2895 else
2896 /* Range from C to C. */
2897 c1 = c;
2898
2899 /* Set the range ... */
2900 if (SINGLE_BYTE_CHAR_P (c))
2901 /* ... into bitmap. */
2902 {
2903 re_wchar_t this_char;
2904 re_wchar_t range_start = c, range_end = c1;
2905
2906 /* If the start is after the end, the range is empty. */
2907 if (range_start > range_end)
2908 {
2909 if (syntax & RE_NO_EMPTY_RANGES)
2910 FREE_STACK_RETURN (REG_ERANGE);
2911 /* Else, repeat the loop. */
2912 }
2913 else
2914 {
2915 for (this_char = range_start; this_char <= range_end;
2916 this_char++)
2917 SET_LIST_BIT (TRANSLATE (this_char));
2918 }
2919 }
2920 else
2921 /* ... into range table. */
2922 SET_RANGE_TABLE_WORK_AREA (range_table_work, c, c1);
2923 }
2924
2925 /* Discard any (non)matching list bytes that are all 0 at the
2926 end of the map. Decrease the map-length byte too. */
2927 while ((int) b[-1] > 0 && b[b[-1] - 1] == 0)
2928 b[-1]--;
2929 b += b[-1];
2930
2931 /* Build real range table from work area. */
2932 if (RANGE_TABLE_WORK_USED (range_table_work)
2933 || RANGE_TABLE_WORK_BITS (range_table_work))
2934 {
2935 int i;
2936 int used = RANGE_TABLE_WORK_USED (range_table_work);
2937
2938 /* Allocate space for COUNT + RANGE_TABLE. Needs two
2939 bytes for flags, two for COUNT, and three bytes for
2940 each character. */
2941 GET_BUFFER_SPACE (4 + used * 3);
2942
2943 /* Indicate the existence of range table. */
2944 laststart[1] |= 0x80;
2945
2946 /* Store the character class flag bits into the range table.
2947 If not in emacs, these flag bits are always 0. */
2948 *b++ = RANGE_TABLE_WORK_BITS (range_table_work) & 0xff;
2949 *b++ = RANGE_TABLE_WORK_BITS (range_table_work) >> 8;
2950
2951 STORE_NUMBER_AND_INCR (b, used / 2);
2952 for (i = 0; i < used; i++)
2953 STORE_CHARACTER_AND_INCR
2954 (b, RANGE_TABLE_WORK_ELT (range_table_work, i));
2955 }
2956 }
2957 break;
2958
2959
2960 case '(':
2961 if (syntax & RE_NO_BK_PARENS)
2962 goto handle_open;
2963 else
2964 goto normal_char;
2965
2966
2967 case ')':
2968 if (syntax & RE_NO_BK_PARENS)
2969 goto handle_close;
2970 else
2971 goto normal_char;
2972
2973
2974 case '\n':
2975 if (syntax & RE_NEWLINE_ALT)
2976 goto handle_alt;
2977 else
2978 goto normal_char;
2979
2980
2981 case '|':
2982 if (syntax & RE_NO_BK_VBAR)
2983 goto handle_alt;
2984 else
2985 goto normal_char;
2986
2987
2988 case '{':
2989 if (syntax & RE_INTERVALS && syntax & RE_NO_BK_BRACES)
2990 goto handle_interval;
2991 else
2992 goto normal_char;
2993
2994
2995 case '\\':
2996 if (p == pend) FREE_STACK_RETURN (REG_EESCAPE);
2997
2998 /* Do not translate the character after the \, so that we can
2999 distinguish, e.g., \B from \b, even if we normally would
3000 translate, e.g., B to b. */
3001 PATFETCH (c);
3002
3003 switch (c)
3004 {
3005 case '(':
3006 if (syntax & RE_NO_BK_PARENS)
3007 goto normal_backslash;
3008
3009 handle_open:
3010 {
3011 int shy = 0;
3012 if (p+1 < pend)
3013 {
3014 /* Look for a special (?...) construct */
3015 if ((syntax & RE_SHY_GROUPS) && *p == '?')
3016 {
3017 PATFETCH (c); /* Gobble up the '?'. */
3018 PATFETCH (c);
3019 switch (c)
3020 {
3021 case ':': shy = 1; break;
3022 default:
3023 /* Only (?:...) is supported right now. */
3024 FREE_STACK_RETURN (REG_BADPAT);
3025 }
3026 }
3027 }
3028
3029 if (!shy)
3030 {
3031 bufp->re_nsub++;
3032 regnum++;
3033 }
3034
3035 if (COMPILE_STACK_FULL)
3036 {
3037 RETALLOC (compile_stack.stack, compile_stack.size << 1,
3038 compile_stack_elt_t);
3039 if (compile_stack.stack == NULL) return REG_ESPACE;
3040
3041 compile_stack.size <<= 1;
3042 }
3043
3044 /* These are the values to restore when we hit end of this
3045 group. They are all relative offsets, so that if the
3046 whole pattern moves because of realloc, they will still
3047 be valid. */
3048 COMPILE_STACK_TOP.begalt_offset = begalt - bufp->buffer;
3049 COMPILE_STACK_TOP.fixup_alt_jump
3050 = fixup_alt_jump ? fixup_alt_jump - bufp->buffer + 1 : 0;
3051 COMPILE_STACK_TOP.laststart_offset = b - bufp->buffer;
3052 COMPILE_STACK_TOP.regnum = shy ? -regnum : regnum;
3053
3054 /* Do not push a
3055 start_memory for groups beyond the last one we can
3056 represent in the compiled pattern. */
3057 if (regnum <= MAX_REGNUM && !shy)
3058 BUF_PUSH_2 (start_memory, regnum);
3059
3060 compile_stack.avail++;
3061
3062 fixup_alt_jump = 0;
3063 laststart = 0;
3064 begalt = b;
3065 /* If we've reached MAX_REGNUM groups, then this open
3066 won't actually generate any code, so we'll have to
3067 clear pending_exact explicitly. */
3068 pending_exact = 0;
3069 break;
3070 }
3071
3072 case ')':
3073 if (syntax & RE_NO_BK_PARENS) goto normal_backslash;
3074
3075 if (COMPILE_STACK_EMPTY)
3076 {
3077 if (syntax & RE_UNMATCHED_RIGHT_PAREN_ORD)
3078 goto normal_backslash;
3079 else
3080 FREE_STACK_RETURN (REG_ERPAREN);
3081 }
3082
3083 handle_close:
3084 FIXUP_ALT_JUMP ();
3085
3086 /* See similar code for backslashed left paren above. */
3087 if (COMPILE_STACK_EMPTY)
3088 {
3089 if (syntax & RE_UNMATCHED_RIGHT_PAREN_ORD)
3090 goto normal_char;
3091 else
3092 FREE_STACK_RETURN (REG_ERPAREN);
3093 }
3094
3095 /* Since we just checked for an empty stack above, this
3096 ``can't happen''. */
3097 assert (compile_stack.avail != 0);
3098 {
3099 /* We don't just want to restore into `regnum', because
3100 later groups should continue to be numbered higher,
3101 as in `(ab)c(de)' -- the second group is #2. */
3102 regnum_t this_group_regnum;
3103
3104 compile_stack.avail--;
3105 begalt = bufp->buffer + COMPILE_STACK_TOP.begalt_offset;
3106 fixup_alt_jump
3107 = COMPILE_STACK_TOP.fixup_alt_jump
3108 ? bufp->buffer + COMPILE_STACK_TOP.fixup_alt_jump - 1
3109 : 0;
3110 laststart = bufp->buffer + COMPILE_STACK_TOP.laststart_offset;
3111 this_group_regnum = COMPILE_STACK_TOP.regnum;
3112 /* If we've reached MAX_REGNUM groups, then this open
3113 won't actually generate any code, so we'll have to
3114 clear pending_exact explicitly. */
3115 pending_exact = 0;
3116
3117 /* We're at the end of the group, so now we know how many
3118 groups were inside this one. */
3119 if (this_group_regnum <= MAX_REGNUM && this_group_regnum > 0)
3120 BUF_PUSH_2 (stop_memory, this_group_regnum);
3121 }
3122 break;
3123
3124
3125 case '|': /* `\|'. */
3126 if (syntax & RE_LIMITED_OPS || syntax & RE_NO_BK_VBAR)
3127 goto normal_backslash;
3128 handle_alt:
3129 if (syntax & RE_LIMITED_OPS)
3130 goto normal_char;
3131
3132 /* Insert before the previous alternative a jump which
3133 jumps to this alternative if the former fails. */
3134 GET_BUFFER_SPACE (3);
3135 INSERT_JUMP (on_failure_jump, begalt, b + 6);
3136 pending_exact = 0;
3137 b += 3;
3138
3139 /* The alternative before this one has a jump after it
3140 which gets executed if it gets matched. Adjust that
3141 jump so it will jump to this alternative's analogous
3142 jump (put in below, which in turn will jump to the next
3143 (if any) alternative's such jump, etc.). The last such
3144 jump jumps to the correct final destination. A picture:
3145 _____ _____
3146 | | | |
3147 | v | v
3148 a | b | c
3149
3150 If we are at `b', then fixup_alt_jump right now points to a
3151 three-byte space after `a'. We'll put in the jump, set
3152 fixup_alt_jump to right after `b', and leave behind three
3153 bytes which we'll fill in when we get to after `c'. */
3154
3155 FIXUP_ALT_JUMP ();
3156
3157 /* Mark and leave space for a jump after this alternative,
3158 to be filled in later either by next alternative or
3159 when know we're at the end of a series of alternatives. */
3160 fixup_alt_jump = b;
3161 GET_BUFFER_SPACE (3);
3162 b += 3;
3163
3164 laststart = 0;
3165 begalt = b;
3166 break;
3167
3168
3169 case '{':
3170 /* If \{ is a literal. */
3171 if (!(syntax & RE_INTERVALS)
3172 /* If we're at `\{' and it's not the open-interval
3173 operator. */
3174 || (syntax & RE_NO_BK_BRACES))
3175 goto normal_backslash;
3176
3177 handle_interval:
3178 {
3179 /* If got here, then the syntax allows intervals. */
3180
3181 /* At least (most) this many matches must be made. */
3182 int lower_bound = 0, upper_bound = -1;
3183
3184 beg_interval = p;
3185
3186 if (p == pend)
3187 FREE_STACK_RETURN (REG_EBRACE);
3188
3189 GET_UNSIGNED_NUMBER (lower_bound);
3190
3191 if (c == ',')
3192 GET_UNSIGNED_NUMBER (upper_bound);
3193 else
3194 /* Interval such as `{1}' => match exactly once. */
3195 upper_bound = lower_bound;
3196
3197 if (lower_bound < 0 || upper_bound > RE_DUP_MAX
3198 || (upper_bound >= 0 && lower_bound > upper_bound))
3199 FREE_STACK_RETURN (REG_BADBR);
3200
3201 if (!(syntax & RE_NO_BK_BRACES))
3202 {
3203 if (c != '\\')
3204 FREE_STACK_RETURN (REG_BADBR);
3205
3206 PATFETCH (c);
3207 }
3208
3209 if (c != '}')
3210 FREE_STACK_RETURN (REG_BADBR);
3211
3212 /* We just parsed a valid interval. */
3213
3214 /* If it's invalid to have no preceding re. */
3215 if (!laststart)
3216 {
3217 if (syntax & RE_CONTEXT_INVALID_OPS)
3218 FREE_STACK_RETURN (REG_BADRPT);
3219 else if (syntax & RE_CONTEXT_INDEP_OPS)
3220 laststart = b;
3221 else
3222 goto unfetch_interval;
3223 }
3224
3225 if (upper_bound == 0)
3226 /* If the upper bound is zero, just drop the sub pattern
3227 altogether. */
3228 b = laststart;
3229 else if (lower_bound == 1 && upper_bound == 1)
3230 /* Just match it once: nothing to do here. */
3231 ;
3232
3233 /* Otherwise, we have a nontrivial interval. When
3234 we're all done, the pattern will look like:
3235 set_number_at <jump count> <upper bound>
3236 set_number_at <succeed_n count> <lower bound>
3237 succeed_n <after jump addr> <succeed_n count>
3238 <body of loop>
3239 jump_n <succeed_n addr> <jump count>
3240 (The upper bound and `jump_n' are omitted if
3241 `upper_bound' is 1, though.) */
3242 else
3243 { /* If the upper bound is > 1, we need to insert
3244 more at the end of the loop. */
3245 unsigned int nbytes = (upper_bound < 0 ? 3
3246 : upper_bound > 1 ? 5 : 0);
3247 unsigned int startoffset = 0;
3248
3249 GET_BUFFER_SPACE (20); /* We might use less. */
3250
3251 if (lower_bound == 0)
3252 {
3253 /* A succeed_n that starts with 0 is really a
3254 a simple on_failure_jump_loop. */
3255 INSERT_JUMP (on_failure_jump_loop, laststart,
3256 b + 3 + nbytes);
3257 b += 3;
3258 }
3259 else
3260 {
3261 /* Initialize lower bound of the `succeed_n', even
3262 though it will be set during matching by its
3263 attendant `set_number_at' (inserted next),
3264 because `re_compile_fastmap' needs to know.
3265 Jump to the `jump_n' we might insert below. */
3266 INSERT_JUMP2 (succeed_n, laststart,
3267 b + 5 + nbytes,
3268 lower_bound);
3269 b += 5;
3270
3271 /* Code to initialize the lower bound. Insert
3272 before the `succeed_n'. The `5' is the last two
3273 bytes of this `set_number_at', plus 3 bytes of
3274 the following `succeed_n'. */
3275 insert_op2 (set_number_at, laststart, 5, lower_bound, b);
3276 b += 5;
3277 startoffset += 5;
3278 }
3279
3280 if (upper_bound < 0)
3281 {
3282 /* A negative upper bound stands for infinity,
3283 in which case it degenerates to a plain jump. */
3284 STORE_JUMP (jump, b, laststart + startoffset);
3285 b += 3;
3286 }
3287 else if (upper_bound > 1)
3288 { /* More than one repetition is allowed, so
3289 append a backward jump to the `succeed_n'
3290 that starts this interval.
3291
3292 When we've reached this during matching,
3293 we'll have matched the interval once, so
3294 jump back only `upper_bound - 1' times. */
3295 STORE_JUMP2 (jump_n, b, laststart + startoffset,
3296 upper_bound - 1);
3297 b += 5;
3298
3299 /* The location we want to set is the second
3300 parameter of the `jump_n'; that is `b-2' as
3301 an absolute address. `laststart' will be
3302 the `set_number_at' we're about to insert;
3303 `laststart+3' the number to set, the source
3304 for the relative address. But we are
3305 inserting into the middle of the pattern --
3306 so everything is getting moved up by 5.
3307 Conclusion: (b - 2) - (laststart + 3) + 5,
3308 i.e., b - laststart.
3309
3310 We insert this at the beginning of the loop
3311 so that if we fail during matching, we'll
3312 reinitialize the bounds. */
3313 insert_op2 (set_number_at, laststart, b - laststart,
3314 upper_bound - 1, b);
3315 b += 5;
3316 }
3317 }
3318 pending_exact = 0;
3319 beg_interval = NULL;
3320 }
3321 break;
3322
3323 unfetch_interval:
3324 /* If an invalid interval, match the characters as literals. */
3325 assert (beg_interval);
3326 p = beg_interval;
3327 beg_interval = NULL;
3328
3329 /* normal_char and normal_backslash need `c'. */
3330 c = '{';
3331
3332 if (!(syntax & RE_NO_BK_BRACES))
3333 {
3334 assert (p > pattern && p[-1] == '\\');
3335 goto normal_backslash;
3336 }
3337 else
3338 goto normal_char;
3339
3340#ifdef emacs
3341 /* There is no way to specify the before_dot and after_dot
3342 operators. rms says this is ok. --karl */
3343 case '=':
3344 BUF_PUSH (at_dot);
3345 break;
3346
3347 case 's':
3348 laststart = b;
3349 PATFETCH (c);
3350 BUF_PUSH_2 (syntaxspec, syntax_spec_code[c]);
3351 break;
3352
3353 case 'S':
3354 laststart = b;
3355 PATFETCH (c);
3356 BUF_PUSH_2 (notsyntaxspec, syntax_spec_code[c]);
3357 break;
3358
3359 case 'c':
3360 laststart = b;
3361 PATFETCH (c);
3362 BUF_PUSH_2 (categoryspec, c);
3363 break;
3364
3365 case 'C':
3366 laststart = b;
3367 PATFETCH (c);
3368 BUF_PUSH_2 (notcategoryspec, c);
3369 break;
3370#endif /* emacs */
3371
3372
3373 case 'w':
3374 if (syntax & RE_NO_GNU_OPS)
3375 goto normal_char;
3376 laststart = b;
3377 BUF_PUSH_2 (syntaxspec, Sword);
3378 break;
3379
3380
3381 case 'W':
3382 if (syntax & RE_NO_GNU_OPS)
3383 goto normal_char;
3384 laststart = b;
3385 BUF_PUSH_2 (notsyntaxspec, Sword);
3386 break;
3387
3388
3389 case '<':
3390 if (syntax & RE_NO_GNU_OPS)
3391 goto normal_char;
3392 BUF_PUSH (wordbeg);
3393 break;
3394
3395 case '>':
3396 if (syntax & RE_NO_GNU_OPS)
3397 goto normal_char;
3398 BUF_PUSH (wordend);
3399 break;
3400
3401 case 'b':
3402 if (syntax & RE_NO_GNU_OPS)
3403 goto normal_char;
3404 BUF_PUSH (wordbound);
3405 break;
3406
3407 case 'B':
3408 if (syntax & RE_NO_GNU_OPS)
3409 goto normal_char;
3410 BUF_PUSH (notwordbound);
3411 break;
3412
3413 case '`':
3414 if (syntax & RE_NO_GNU_OPS)
3415 goto normal_char;
3416 BUF_PUSH (begbuf);
3417 break;
3418
3419 case '\'':
3420 if (syntax & RE_NO_GNU_OPS)
3421 goto normal_char;
3422 BUF_PUSH (endbuf);
3423 break;
3424
3425 case '1': case '2': case '3': case '4': case '5':
3426 case '6': case '7': case '8': case '9':
3427 {
3428 regnum_t reg;
3429
3430 if (syntax & RE_NO_BK_REFS)
3431 goto normal_backslash;
3432
3433 reg = c - '0';
3434
3435 /* Can't back reference to a subexpression before its end. */
3436 if (reg > regnum || group_in_compile_stack (compile_stack, reg))
3437 FREE_STACK_RETURN (REG_ESUBREG);
3438
3439 laststart = b;
3440 BUF_PUSH_2 (duplicate, reg);
3441 }
3442 break;
3443
3444
3445 case '+':
3446 case '?':
3447 if (syntax & RE_BK_PLUS_QM)
3448 goto handle_plus;
3449 else
3450 goto normal_backslash;
3451
3452 default:
3453 normal_backslash:
3454 /* You might think it would be useful for \ to mean
3455 not to translate; but if we don't translate it
3456 it will never match anything. */
3457 goto normal_char;
3458 }
3459 break;
3460
3461
3462 default:
3463 /* Expects the character in `c'. */
3464 normal_char:
3465 /* If no exactn currently being built. */
3466 if (!pending_exact
3467
3468 /* If last exactn not at current position. */
3469 || pending_exact + *pending_exact + 1 != b
3470
3471 /* We have only one byte following the exactn for the count. */
3472 || *pending_exact >= (1 << BYTEWIDTH) - MAX_MULTIBYTE_LENGTH
3473
3474 /* If followed by a repetition operator. */
3475 || (p != pend && (*p == '*' || *p == '^'))
3476 || ((syntax & RE_BK_PLUS_QM)
3477 ? p + 1 < pend && *p == '\\' && (p[1] == '+' || p[1] == '?')
3478 : p != pend && (*p == '+' || *p == '?'))
3479 || ((syntax & RE_INTERVALS)
3480 && ((syntax & RE_NO_BK_BRACES)
3481 ? p != pend && *p == '{'
3482 : p + 1 < pend && p[0] == '\\' && p[1] == '{')))
3483 {
3484 /* Start building a new exactn. */
3485
3486 laststart = b;
3487
3488 BUF_PUSH_2 (exactn, 0);
3489 pending_exact = b - 1;
3490 }
3491
3492 GET_BUFFER_SPACE (MAX_MULTIBYTE_LENGTH);
3493 {
3494 int len;
3495
3496 c = TRANSLATE (c);
3497 if (multibyte)
3498 len = CHAR_STRING (c, b);
3499 else
3500 *b = c, len = 1;
3501 b += len;
3502 (*pending_exact) += len;
3503 }
3504
3505 break;
3506 } /* switch (c) */
3507 } /* while p != pend */
3508
3509
3510 /* Through the pattern now. */
3511
3512 FIXUP_ALT_JUMP ();
3513
3514 if (!COMPILE_STACK_EMPTY)
3515 FREE_STACK_RETURN (REG_EPAREN);
3516
3517 /* If we don't want backtracking, force success
3518 the first time we reach the end of the compiled pattern. */
3519 if (syntax & RE_NO_POSIX_BACKTRACKING)
3520 BUF_PUSH (succeed);
3521
3522 /* We have succeeded; set the length of the buffer. */
3523 bufp->used = b - bufp->buffer;
3524
3525#ifdef DEBUG
3526 if (debug > 0)
3527 {
3528 re_compile_fastmap (bufp);
3529 DEBUG_PRINT1 ("\nCompiled pattern: \n");
3530 print_compiled_pattern (bufp);
3531 }
3532 debug--;
3533#endif /* DEBUG */
3534
3535#ifndef MATCH_MAY_ALLOCATE
3536 /* Initialize the failure stack to the largest possible stack. This
3537 isn't necessary unless we're trying to avoid calling alloca in
3538 the search and match routines. */
3539 {
3540 int num_regs = bufp->re_nsub + 1;
3541
3542 if (fail_stack.size < re_max_failures * TYPICAL_FAILURE_SIZE)
3543 {
3544 fail_stack.size = re_max_failures * TYPICAL_FAILURE_SIZE;
3545
3546 if (! fail_stack.stack)
3547 fail_stack.stack
3548 = (fail_stack_elt_t *) malloc (fail_stack.size
3549 * sizeof (fail_stack_elt_t));
3550 else
3551 fail_stack.stack
3552 = (fail_stack_elt_t *) realloc (fail_stack.stack,
3553 (fail_stack.size
3554 * sizeof (fail_stack_elt_t)));
3555 }
3556
3557 regex_grow_registers (num_regs);
3558 }
3559#endif /* not MATCH_MAY_ALLOCATE */
3560
3561 FREE_STACK_RETURN (REG_NOERROR);
3562} /* regex_compile */
3563
3564/* Subroutines for `regex_compile'. */
3565
3566/* Store OP at LOC followed by two-byte integer parameter ARG. */
3567
3568static void
3569store_op1 (op, loc, arg)
3570 re_opcode_t op;
3571 unsigned char *loc;
3572 int arg;
3573{
3574 *loc = (unsigned char) op;
3575 STORE_NUMBER (loc + 1, arg);
3576}
3577
3578
3579/* Like `store_op1', but for two two-byte parameters ARG1 and ARG2. */
3580
3581static void
3582store_op2 (op, loc, arg1, arg2)
3583 re_opcode_t op;
3584 unsigned char *loc;
3585 int arg1, arg2;
3586{
3587 *loc = (unsigned char) op;
3588 STORE_NUMBER (loc + 1, arg1);
3589 STORE_NUMBER (loc + 3, arg2);
3590}
3591
3592
3593/* Copy the bytes from LOC to END to open up three bytes of space at LOC
3594 for OP followed by two-byte integer parameter ARG. */
3595
3596static void
3597insert_op1 (op, loc, arg, end)
3598 re_opcode_t op;
3599 unsigned char *loc;
3600 int arg;
3601 unsigned char *end;
3602{
3603 register unsigned char *pfrom = end;
3604 register unsigned char *pto = end + 3;
3605
3606 while (pfrom != loc)
3607 *--pto = *--pfrom;
3608
3609 store_op1 (op, loc, arg);
3610}
3611
3612
3613/* Like `insert_op1', but for two two-byte parameters ARG1 and ARG2. */
3614
3615static void
3616insert_op2 (op, loc, arg1, arg2, end)
3617 re_opcode_t op;
3618 unsigned char *loc;
3619 int arg1, arg2;
3620 unsigned char *end;
3621{
3622 register unsigned char *pfrom = end;
3623 register unsigned char *pto = end + 5;
3624
3625 while (pfrom != loc)
3626 *--pto = *--pfrom;
3627
3628 store_op2 (op, loc, arg1, arg2);
3629}
3630
3631
3632/* P points to just after a ^ in PATTERN. Return true if that ^ comes
3633 after an alternative or a begin-subexpression. We assume there is at
3634 least one character before the ^. */
3635
3636static boolean
3637at_begline_loc_p (pattern, p, syntax)
3638 re_char *pattern, *p;
3639 reg_syntax_t syntax;
3640{
3641 re_char *prev = p - 2;
3642 boolean prev_prev_backslash = prev > pattern && prev[-1] == '\\';
3643
3644 return
3645 /* After a subexpression? */
3646 (*prev == '(' && (syntax & RE_NO_BK_PARENS || prev_prev_backslash))
3647 /* After an alternative? */
3648 || (*prev == '|' && (syntax & RE_NO_BK_VBAR || prev_prev_backslash))
3649 /* After a shy subexpression? */
3650 || ((syntax & RE_SHY_GROUPS) && prev - 2 >= pattern
3651 && prev[-1] == '?' && prev[-2] == '('
3652 && (syntax & RE_NO_BK_PARENS
3653 || (prev - 3 >= pattern && prev[-3] == '\\')));
3654}
3655
3656
3657/* The dual of at_begline_loc_p. This one is for $. We assume there is
3658 at least one character after the $, i.e., `P < PEND'. */
3659
3660static boolean
3661at_endline_loc_p (p, pend, syntax)
3662 re_char *p, *pend;
3663 reg_syntax_t syntax;
3664{
3665 re_char *next = p;
3666 boolean next_backslash = *next == '\\';
3667 re_char *next_next = p + 1 < pend ? p + 1 : 0;
3668
3669 return
3670 /* Before a subexpression? */
3671 (syntax & RE_NO_BK_PARENS ? *next == ')'
3672 : next_backslash && next_next && *next_next == ')')
3673 /* Before an alternative? */
3674 || (syntax & RE_NO_BK_VBAR ? *next == '|'
3675 : next_backslash && next_next && *next_next == '|');
3676}
3677
3678
3679/* Returns true if REGNUM is in one of COMPILE_STACK's elements and
3680 false if it's not. */
3681
3682static boolean
3683group_in_compile_stack (compile_stack, regnum)
3684 compile_stack_type compile_stack;
3685 regnum_t regnum;
3686{
3687 int this_element;
3688
3689 for (this_element = compile_stack.avail - 1;
3690 this_element >= 0;
3691 this_element--)
3692 if (compile_stack.stack[this_element].regnum == regnum)
3693 return true;
3694
3695 return false;
3696}
3697
3698/* analyse_first.
3699 If fastmap is non-NULL, go through the pattern and fill fastmap
3700 with all the possible leading chars. If fastmap is NULL, don't
3701 bother filling it up (obviously) and only return whether the
3702 pattern could potentially match the empty string.
3703
3704 Return 1 if p..pend might match the empty string.
3705 Return 0 if p..pend matches at least one char.
3706 Return -1 if fastmap was not updated accurately. */
3707
3708static int
3709analyse_first (p, pend, fastmap, multibyte)
3710 re_char *p, *pend;
3711 char *fastmap;
3712 const int multibyte;
3713{
3714 int j, k;
3715 boolean not;
3716
3717 /* If all elements for base leading-codes in fastmap is set, this
3718 flag is set true. */
3719 boolean match_any_multibyte_characters = false;
3720
3721 assert (p);
3722
3723 /* The loop below works as follows:
3724 - It has a working-list kept in the PATTERN_STACK and which basically
3725 starts by only containing a pointer to the first operation.
3726 - If the opcode we're looking at is a match against some set of
3727 chars, then we add those chars to the fastmap and go on to the
3728 next work element from the worklist (done via `break').
3729 - If the opcode is a control operator on the other hand, we either
3730 ignore it (if it's meaningless at this point, such as `start_memory')
3731 or execute it (if it's a jump). If the jump has several destinations
3732 (i.e. `on_failure_jump'), then we push the other destination onto the
3733 worklist.
3734 We guarantee termination by ignoring backward jumps (more or less),
3735 so that `p' is monotonically increasing. More to the point, we
3736 never set `p' (or push) anything `<= p1'. */
3737
3738 while (p < pend)
3739 {
3740 /* `p1' is used as a marker of how far back a `on_failure_jump'
3741 can go without being ignored. It is normally equal to `p'
3742 (which prevents any backward `on_failure_jump') except right
3743 after a plain `jump', to allow patterns such as:
3744 0: jump 10
3745 3..9: <body>
3746 10: on_failure_jump 3
3747 as used for the *? operator. */
3748 re_char *p1 = p;
3749
3750 switch (SWITCH_ENUM_CAST ((re_opcode_t) *p++))
3751 {
3752 case succeed:
3753 return 1;
3754 continue;
3755
3756 case duplicate:
3757 /* If the first character has to match a backreference, that means
3758 that the group was empty (since it already matched). Since this
3759 is the only case that interests us here, we can assume that the
3760 backreference must match the empty string. */
3761 p++;
3762 continue;
3763
3764
3765 /* Following are the cases which match a character. These end
3766 with `break'. */
3767
3768 case exactn:
3769 if (fastmap)
3770 {
3771 int c = RE_STRING_CHAR (p + 1, pend - p);
3772
3773 if (SINGLE_BYTE_CHAR_P (c))
3774 fastmap[c] = 1;
3775 else
3776 fastmap[p[1]] = 1;
3777 }
3778 break;
3779
3780
3781 case anychar:
3782 /* We could put all the chars except for \n (and maybe \0)
3783 but we don't bother since it is generally not worth it. */
3784 if (!fastmap) break;
3785 return -1;
3786
3787
3788 case charset_not:
3789 /* Chars beyond end of bitmap are possible matches.
3790 All the single-byte codes can occur in multibyte buffers.
3791 So any that are not listed in the charset
3792 are possible matches, even in multibyte buffers. */
3793 if (!fastmap) break;
3794 for (j = CHARSET_BITMAP_SIZE (&p[-1]) * BYTEWIDTH;
3795 j < (1 << BYTEWIDTH); j++)
3796 fastmap[j] = 1;
3797 /* Fallthrough */
3798 case charset:
3799 if (!fastmap) break;
3800 not = (re_opcode_t) *(p - 1) == charset_not;
3801 for (j = CHARSET_BITMAP_SIZE (&p[-1]) * BYTEWIDTH - 1, p++;
3802 j >= 0; j--)
3803 if (!!(p[j / BYTEWIDTH] & (1 << (j % BYTEWIDTH))) ^ not)
3804 fastmap[j] = 1;
3805
3806 if ((not && multibyte)
3807 /* Any character set can possibly contain a character
3808 which doesn't match the specified set of characters. */
3809 || (CHARSET_RANGE_TABLE_EXISTS_P (&p[-2])
3810 && CHARSET_RANGE_TABLE_BITS (&p[-2]) != 0))
3811 /* If we can match a character class, we can match
3812 any character set. */
3813 {
3814 set_fastmap_for_multibyte_characters:
3815 if (match_any_multibyte_characters == false)
3816 {
3817 for (j = 0x80; j < 0xA0; j++) /* XXX */
3818 if (BASE_LEADING_CODE_P (j))
3819 fastmap[j] = 1;
3820 match_any_multibyte_characters = true;
3821 }
3822 }
3823
3824 else if (!not && CHARSET_RANGE_TABLE_EXISTS_P (&p[-2])
3825 && match_any_multibyte_characters == false)
3826 {
3827 /* Set fastmap[I] 1 where I is a base leading code of each
3828 multibyte character in the range table. */
3829 int c, count;
3830
3831 /* Make P points the range table. `+ 2' is to skip flag
3832 bits for a character class. */
3833 p += CHARSET_BITMAP_SIZE (&p[-2]) + 2;
3834
3835 /* Extract the number of ranges in range table into COUNT. */
3836 EXTRACT_NUMBER_AND_INCR (count, p);
3837 for (; count > 0; count--, p += 2 * 3) /* XXX */
3838 {
3839 /* Extract the start of each range. */
3840 EXTRACT_CHARACTER (c, p);
3841 j = CHAR_CHARSET (c);
3842 fastmap[CHARSET_LEADING_CODE_BASE (j)] = 1;
3843 }
3844 }
3845 break;
3846
3847 case syntaxspec:
3848 case notsyntaxspec:
3849 if (!fastmap) break;
3850#ifndef emacs
3851 not = (re_opcode_t)p[-1] == notsyntaxspec;
3852 k = *p++;
3853 for (j = 0; j < (1 << BYTEWIDTH); j++)
3854 if ((SYNTAX (j) == (enum syntaxcode) k) ^ not)
3855 fastmap[j] = 1;
3856 break;
3857#else /* emacs */
3858 /* This match depends on text properties. These end with
3859 aborting optimizations. */
3860 return -1;
3861
3862 case categoryspec:
3863 case notcategoryspec:
3864 if (!fastmap) break;
3865 not = (re_opcode_t)p[-1] == notcategoryspec;
3866 k = *p++;
3867 for (j = 0; j < (1 << BYTEWIDTH); j++)
3868 if ((CHAR_HAS_CATEGORY (j, k)) ^ not)
3869 fastmap[j] = 1;
3870
3871 if (multibyte)
3872 /* Any character set can possibly contain a character
3873 whose category is K (or not). */
3874 goto set_fastmap_for_multibyte_characters;
3875 break;
3876
3877 /* All cases after this match the empty string. These end with
3878 `continue'. */
3879
3880 case before_dot:
3881 case at_dot:
3882 case after_dot:
3883#endif /* !emacs */
3884 case no_op:
3885 case begline:
3886 case endline:
3887 case begbuf:
3888 case endbuf:
3889 case wordbound:
3890 case notwordbound:
3891 case wordbeg:
3892 case wordend:
3893 continue;
3894
3895
3896 case jump:
3897 EXTRACT_NUMBER_AND_INCR (j, p);
3898 if (j < 0)
3899 /* Backward jumps can only go back to code that we've already
3900 visited. `re_compile' should make sure this is true. */
3901 break;
3902 p += j;
3903 switch (SWITCH_ENUM_CAST ((re_opcode_t) *p))
3904 {
3905 case on_failure_jump:
3906 case on_failure_keep_string_jump:
3907 case on_failure_jump_loop:
3908 case on_failure_jump_nastyloop:
3909 case on_failure_jump_smart:
3910 p++;
3911 break;
3912 default:
3913 continue;
3914 };
3915 /* Keep `p1' to allow the `on_failure_jump' we are jumping to
3916 to jump back to "just after here". */
3917 /* Fallthrough */
3918
3919 case on_failure_jump:
3920 case on_failure_keep_string_jump:
3921 case on_failure_jump_nastyloop:
3922 case on_failure_jump_loop:
3923 case on_failure_jump_smart:
3924 EXTRACT_NUMBER_AND_INCR (j, p);
3925 if (p + j <= p1)
3926 ; /* Backward jump to be ignored. */
3927 else
3928 { /* We have to look down both arms.
3929 We first go down the "straight" path so as to minimize
3930 stack usage when going through alternatives. */
3931 int r = analyse_first (p, pend, fastmap, multibyte);
3932 if (r) return r;
3933 p += j;
3934 }
3935 continue;
3936
3937
3938 case jump_n:
3939 /* This code simply does not properly handle forward jump_n. */
3940 DEBUG_STATEMENT (EXTRACT_NUMBER (j, p); assert (j < 0));
3941 p += 4;
3942 /* jump_n can either jump or fall through. The (backward) jump
3943 case has already been handled, so we only need to look at the
3944 fallthrough case. */
3945 continue;
3946
3947 case succeed_n:
3948 /* If N == 0, it should be an on_failure_jump_loop instead. */
3949 DEBUG_STATEMENT (EXTRACT_NUMBER (j, p + 2); assert (j > 0));
3950 p += 4;
3951 /* We only care about one iteration of the loop, so we don't
3952 need to consider the case where this behaves like an
3953 on_failure_jump. */
3954 continue;
3955
3956
3957 case set_number_at:
3958 p += 4;
3959 continue;
3960
3961
3962 case start_memory:
3963 case stop_memory:
3964 p += 1;
3965 continue;
3966
3967
3968 default:
3969 abort (); /* We have listed all the cases. */
3970 } /* switch *p++ */
3971
3972 /* Getting here means we have found the possible starting
3973 characters for one path of the pattern -- and that the empty
3974 string does not match. We need not follow this path further. */
3975 return 0;
3976 } /* while p */
3977
3978 /* We reached the end without matching anything. */
3979 return 1;
3980
3981} /* analyse_first */
3982
3983/* re_compile_fastmap computes a ``fastmap'' for the compiled pattern in
3984 BUFP. A fastmap records which of the (1 << BYTEWIDTH) possible
3985 characters can start a string that matches the pattern. This fastmap
3986 is used by re_search to skip quickly over impossible starting points.
3987
3988 Character codes above (1 << BYTEWIDTH) are not represented in the
3989 fastmap, but the leading codes are represented. Thus, the fastmap
3990 indicates which character sets could start a match.
3991
3992 The caller must supply the address of a (1 << BYTEWIDTH)-byte data
3993 area as BUFP->fastmap.
3994
3995 We set the `fastmap', `fastmap_accurate', and `can_be_null' fields in
3996 the pattern buffer.
3997
3998 Returns 0 if we succeed, -2 if an internal error. */
3999
4000int
4001re_compile_fastmap (bufp)
4002 struct re_pattern_buffer *bufp;
4003{
4004 char *fastmap = bufp->fastmap;
4005 int analysis;
4006
4007 assert (fastmap && bufp->buffer);
4008
4009 bzero (fastmap, 1 << BYTEWIDTH); /* Assume nothing's valid. */
4010 bufp->fastmap_accurate = 1; /* It will be when we're done. */
4011
4012 analysis = analyse_first (bufp->buffer, bufp->buffer + bufp->used,
4013 fastmap, RE_MULTIBYTE_P (bufp));
4014 bufp->can_be_null = (analysis != 0);
4015 return 0;
4016} /* re_compile_fastmap */
4017
4018/* Set REGS to hold NUM_REGS registers, storing them in STARTS and
4019 ENDS. Subsequent matches using PATTERN_BUFFER and REGS will use
4020 this memory for recording register information. STARTS and ENDS
4021 must be allocated using the malloc library routine, and must each
4022 be at least NUM_REGS * sizeof (regoff_t) bytes long.
4023
4024 If NUM_REGS == 0, then subsequent matches should allocate their own
4025 register data.
4026
4027 Unless this function is called, the first search or match using
4028 PATTERN_BUFFER will allocate its own register data, without
4029 freeing the old data. */
4030
4031void
4032re_set_registers (bufp, regs, num_regs, starts, ends)
4033 struct re_pattern_buffer *bufp;
4034 struct re_registers *regs;
4035 unsigned num_regs;
4036 regoff_t *starts, *ends;
4037{
4038 if (num_regs)
4039 {
4040 bufp->regs_allocated = REGS_REALLOCATE;
4041 regs->num_regs = num_regs;
4042 regs->start = starts;
4043 regs->end = ends;
4044 }
4045 else
4046 {
4047 bufp->regs_allocated = REGS_UNALLOCATED;
4048 regs->num_regs = 0;
4049 regs->start = regs->end = (regoff_t *) 0;
4050 }
4051}
4052WEAK_ALIAS (__re_set_registers, re_set_registers)
4053
4054/* Searching routines. */
4055
4056/* Like re_search_2, below, but only one string is specified, and
4057 doesn't let you say where to stop matching. */
4058
4059int
4060re_search (bufp, string, size, startpos, range, regs)
4061 struct re_pattern_buffer *bufp;
4062 const char *string;
4063 int size, startpos, range;
4064 struct re_registers *regs;
4065{
4066 return re_search_2 (bufp, NULL, 0, string, size, startpos, range,
4067 regs, size);
4068}
4069WEAK_ALIAS (__re_search, re_search)
4070
4071/* Head address of virtual concatenation of string. */
4072#define HEAD_ADDR_VSTRING(P) \
4073 (((P) >= size1 ? string2 : string1))
4074
4075/* End address of virtual concatenation of string. */
4076#define STOP_ADDR_VSTRING(P) \
4077 (((P) >= size1 ? string2 + size2 : string1 + size1))
4078
4079/* Address of POS in the concatenation of virtual string. */
4080#define POS_ADDR_VSTRING(POS) \
4081 (((POS) >= size1 ? string2 - size1 : string1) + (POS))
4082
4083/* Using the compiled pattern in BUFP->buffer, first tries to match the
4084 virtual concatenation of STRING1 and STRING2, starting first at index
4085 STARTPOS, then at STARTPOS + 1, and so on.
4086
4087 STRING1 and STRING2 have length SIZE1 and SIZE2, respectively.
4088
4089 RANGE is how far to scan while trying to match. RANGE = 0 means try
4090 only at STARTPOS; in general, the last start tried is STARTPOS +
4091 RANGE.
4092
4093 In REGS, return the indices of the virtual concatenation of STRING1
4094 and STRING2 that matched the entire BUFP->buffer and its contained
4095 subexpressions.
4096
4097 Do not consider matching one past the index STOP in the virtual
4098 concatenation of STRING1 and STRING2.
4099
4100 We return either the position in the strings at which the match was
4101 found, -1 if no match, or -2 if error (such as failure
4102 stack overflow). */
4103
4104int
4105re_search_2 (bufp, str1, size1, str2, size2, startpos, range, regs, stop)
4106 struct re_pattern_buffer *bufp;
4107 const char *str1, *str2;
4108 int size1, size2;
4109 int startpos;
4110 int range;
4111 struct re_registers *regs;
4112 int stop;
4113{
4114 int val;
4115 re_char *string1 = (re_char*) str1;
4116 re_char *string2 = (re_char*) str2;
4117 register char *fastmap = bufp->fastmap;
4118 register RE_TRANSLATE_TYPE translate = bufp->translate;
4119 int total_size = size1 + size2;
4120 int endpos = startpos + range;
4121 boolean anchored_start;
4122
4123 /* Nonzero if we have to concern multibyte character. */
4124 const boolean multibyte = RE_MULTIBYTE_P (bufp);
4125
4126 /* Check for out-of-range STARTPOS. */
4127 if (startpos < 0 || startpos > total_size)
4128 return -1;
4129
4130 /* Fix up RANGE if it might eventually take us outside
4131 the virtual concatenation of STRING1 and STRING2.
4132 Make sure we won't move STARTPOS below 0 or above TOTAL_SIZE. */
4133 if (endpos < 0)
4134 range = 0 - startpos;
4135 else if (endpos > total_size)
4136 range = total_size - startpos;
4137
4138 /* If the search isn't to be a backwards one, don't waste time in a
4139 search for a pattern anchored at beginning of buffer. */
4140 if (bufp->used > 0 && (re_opcode_t) bufp->buffer[0] == begbuf && range > 0)
4141 {
4142 if (startpos > 0)
4143 return -1;
4144 else
4145 range = 0;
4146 }
4147
4148#ifdef emacs
4149 /* In a forward search for something that starts with \=.
4150 don't keep searching past point. */
4151 if (bufp->used > 0 && (re_opcode_t) bufp->buffer[0] == at_dot && range > 0)
4152 {
4153 range = PT_BYTE - BEGV_BYTE - startpos;
4154 if (range < 0)
4155 return -1;
4156 }
4157#endif /* emacs */
4158
4159 /* Update the fastmap now if not correct already. */
4160 if (fastmap && !bufp->fastmap_accurate)
4161 re_compile_fastmap (bufp);
4162
4163 /* See whether the pattern is anchored. */
4164 anchored_start = (bufp->buffer[0] == begline);
4165
4166#ifdef emacs
4167 gl_state.object = re_match_object;
4168 {
4169 int charpos = SYNTAX_TABLE_BYTE_TO_CHAR (POS_AS_IN_BUFFER (startpos));
4170
4171 SETUP_SYNTAX_TABLE_FOR_OBJECT (re_match_object, charpos, 1);
4172 }
4173#endif
4174
4175 /* Loop through the string, looking for a place to start matching. */
4176 for (;;)
4177 {
4178 /* If the pattern is anchored,
4179 skip quickly past places we cannot match.
4180 We don't bother to treat startpos == 0 specially
4181 because that case doesn't repeat. */
4182 if (anchored_start && startpos > 0)
4183 {
4184 if (! ((startpos <= size1 ? string1[startpos - 1]
4185 : string2[startpos - size1 - 1])
4186 == '\n'))
4187 goto advance;
4188 }
4189
4190 /* If a fastmap is supplied, skip quickly over characters that
4191 cannot be the start of a match. If the pattern can match the
4192 null string, however, we don't need to skip characters; we want
4193 the first null string. */
4194 if (fastmap && startpos < total_size && !bufp->can_be_null)
4195 {
4196 register re_char *d;
4197 register re_wchar_t buf_ch;
4198
4199 d = POS_ADDR_VSTRING (startpos);
4200
4201 if (range > 0) /* Searching forwards. */
4202 {
4203 register int lim = 0;
4204 int irange = range;
4205
4206 if (startpos < size1 && startpos + range >= size1)
4207 lim = range - (size1 - startpos);
4208
4209 /* Written out as an if-else to avoid testing `translate'
4210 inside the loop. */
4211 if (RE_TRANSLATE_P (translate))
4212 {
4213 if (multibyte)
4214 while (range > lim)
4215 {
4216 int buf_charlen;
4217
4218 buf_ch = STRING_CHAR_AND_LENGTH (d, range - lim,
4219 buf_charlen);
4220
4221 buf_ch = RE_TRANSLATE (translate, buf_ch);
4222 if (buf_ch >= 0400
4223 || fastmap[buf_ch])
4224 break;
4225
4226 range -= buf_charlen;
4227 d += buf_charlen;
4228 }
4229 else
4230 while (range > lim
4231 && !fastmap[RE_TRANSLATE (translate, *d)])
4232 {
4233 d++;
4234 range--;
4235 }
4236 }
4237 else
4238 while (range > lim && !fastmap[*d])
4239 {
4240 d++;
4241 range--;
4242 }
4243
4244 startpos += irange - range;
4245 }
4246 else /* Searching backwards. */
4247 {
4248 int room = (startpos >= size1
4249 ? size2 + size1 - startpos
4250 : size1 - startpos);
4251 buf_ch = RE_STRING_CHAR (d, room);
4252 buf_ch = TRANSLATE (buf_ch);
4253
4254 if (! (buf_ch >= 0400
4255 || fastmap[buf_ch]))
4256 goto advance;
4257 }
4258 }
4259
4260 /* If can't match the null string, and that's all we have left, fail. */
4261 if (range >= 0 && startpos == total_size && fastmap
4262 && !bufp->can_be_null)
4263 return -1;
4264
4265 val = re_match_2_internal (bufp, string1, size1, string2, size2,
4266 startpos, regs, stop);
4267#ifndef REGEX_MALLOC
4268# ifdef C_ALLOCA
4269 alloca (0);
4270# endif
4271#endif
4272
4273 if (val >= 0)
4274 return startpos;
4275
4276 if (val == -2)
4277 return -2;
4278
4279 advance:
4280 if (!range)
4281 break;
4282 else if (range > 0)
4283 {
4284 /* Update STARTPOS to the next character boundary. */
4285 if (multibyte)
4286 {
4287 re_char *p = POS_ADDR_VSTRING (startpos);
4288 re_char *pend = STOP_ADDR_VSTRING (startpos);
4289 int len = MULTIBYTE_FORM_LENGTH (p, pend - p);
4290
4291 range -= len;
4292 if (range < 0)
4293 break;
4294 startpos += len;
4295 }
4296 else
4297 {
4298 range--;
4299 startpos++;
4300 }
4301 }
4302 else
4303 {
4304 range++;
4305 startpos--;
4306
4307 /* Update STARTPOS to the previous character boundary. */
4308 if (multibyte)
4309 {
4310 re_char *p = POS_ADDR_VSTRING (startpos) + 1;
4311 re_char *p0 = p;
4312 re_char *phead = HEAD_ADDR_VSTRING (startpos);
4313
4314 /* Find the head of multibyte form. */
4315 PREV_CHAR_BOUNDARY (p, phead);
4316 range += p0 - 1 - p;
4317 if (range > 0)
4318 break;
4319
4320 startpos -= p0 - 1 - p;
4321 }
4322 }
4323 }
4324 return -1;
4325} /* re_search_2 */
4326WEAK_ALIAS (__re_search_2, re_search_2)
4327
4328/* Declarations and macros for re_match_2. */
4329
4330static int bcmp_translate _RE_ARGS((re_char *s1, re_char *s2,
4331 register int len,
4332 RE_TRANSLATE_TYPE translate,
4333 const int multibyte));
4334
4335/* This converts PTR, a pointer into one of the search strings `string1'
4336 and `string2' into an offset from the beginning of that string. */
4337#define POINTER_TO_OFFSET(ptr) \
4338 (FIRST_STRING_P (ptr) \
4339 ? ((regoff_t) ((ptr) - string1)) \
4340 : ((regoff_t) ((ptr) - string2 + size1)))
4341
4342/* Call before fetching a character with *d. This switches over to
4343 string2 if necessary.
4344 Check re_match_2_internal for a discussion of why end_match_2 might
4345 not be within string2 (but be equal to end_match_1 instead). */
4346#define PREFETCH() \
4347 while (d == dend) \
4348 { \
4349 /* End of string2 => fail. */ \
4350 if (dend == end_match_2) \
4351 goto fail; \
4352 /* End of string1 => advance to string2. */ \
4353 d = string2; \
4354 dend = end_match_2; \
4355 }
4356
4357/* Call before fetching a char with *d if you already checked other limits.
4358 This is meant for use in lookahead operations like wordend, etc..
4359 where we might need to look at parts of the string that might be
4360 outside of the LIMITs (i.e past `stop'). */
4361#define PREFETCH_NOLIMIT() \
4362 if (d == end1) \
4363 { \
4364 d = string2; \
4365 dend = end_match_2; \
4366 } \
4367
4368/* Test if at very beginning or at very end of the virtual concatenation
4369 of `string1' and `string2'. If only one string, it's `string2'. */
4370#define AT_STRINGS_BEG(d) ((d) == (size1 ? string1 : string2) || !size2)
4371#define AT_STRINGS_END(d) ((d) == end2)
4372
4373
4374/* Test if D points to a character which is word-constituent. We have
4375 two special cases to check for: if past the end of string1, look at
4376 the first character in string2; and if before the beginning of
4377 string2, look at the last character in string1. */
4378#define WORDCHAR_P(d) \
4379 (SYNTAX ((d) == end1 ? *string2 \
4380 : (d) == string2 - 1 ? *(end1 - 1) : *(d)) \
4381 == Sword)
4382
4383/* Disabled due to a compiler bug -- see comment at case wordbound */
4384
4385/* The comment at case wordbound is following one, but we don't use
4386 AT_WORD_BOUNDARY anymore to support multibyte form.
4387
4388 The DEC Alpha C compiler 3.x generates incorrect code for the
4389 test WORDCHAR_P (d - 1) != WORDCHAR_P (d) in the expansion of
4390 AT_WORD_BOUNDARY, so this code is disabled. Expanding the
4391 macro and introducing temporary variables works around the bug. */
4392
4393#if 0
4394/* Test if the character before D and the one at D differ with respect
4395 to being word-constituent. */
4396#define AT_WORD_BOUNDARY(d) \
4397 (AT_STRINGS_BEG (d) || AT_STRINGS_END (d) \
4398 || WORDCHAR_P (d - 1) != WORDCHAR_P (d))
4399#endif
4400
4401/* Free everything we malloc. */
4402#ifdef MATCH_MAY_ALLOCATE
4403# define FREE_VAR(var) if (var) { REGEX_FREE (var); var = NULL; } else
4404# define FREE_VARIABLES() \
4405 do { \
4406 REGEX_FREE_STACK (fail_stack.stack); \
4407 FREE_VAR (regstart); \
4408 FREE_VAR (regend); \
4409 FREE_VAR (best_regstart); \
4410 FREE_VAR (best_regend); \
4411 } while (0)
4412#else
4413# define FREE_VARIABLES() ((void)0) /* Do nothing! But inhibit gcc warning. */
4414#endif /* not MATCH_MAY_ALLOCATE */
4415
4416
4417/* Optimization routines. */
4418
4419/* If the operation is a match against one or more chars,
4420 return a pointer to the next operation, else return NULL. */
4421static re_char *
4422skip_one_char (p)
4423 re_char *p;
4424{
4425 switch (SWITCH_ENUM_CAST (*p++))
4426 {
4427 case anychar:
4428 break;
4429
4430 case exactn:
4431 p += *p + 1;
4432 break;
4433
4434 case charset_not:
4435 case charset:
4436 if (CHARSET_RANGE_TABLE_EXISTS_P (p - 1))
4437 {
4438 int mcnt;
4439 p = CHARSET_RANGE_TABLE (p - 1);
4440 EXTRACT_NUMBER_AND_INCR (mcnt, p);
4441 p = CHARSET_RANGE_TABLE_END (p, mcnt);
4442 }
4443 else
4444 p += 1 + CHARSET_BITMAP_SIZE (p - 1);
4445 break;
4446
4447 case syntaxspec:
4448 case notsyntaxspec:
4449#ifdef emacs
4450 case categoryspec:
4451 case notcategoryspec:
4452#endif /* emacs */
4453 p++;
4454 break;
4455
4456 default:
4457 p = NULL;
4458 }
4459 return p;
4460}
4461
4462
4463/* Jump over non-matching operations. */
4464static re_char *
4465skip_noops (p, pend)
4466 re_char *p, *pend;
4467{
4468 int mcnt;
4469 while (p < pend)
4470 {
4471 switch (SWITCH_ENUM_CAST ((re_opcode_t) *p))
4472 {
4473 case start_memory:
4474 case stop_memory:
4475 p += 2; break;
4476 case no_op:
4477 p += 1; break;
4478 case jump:
4479 p += 1;
4480 EXTRACT_NUMBER_AND_INCR (mcnt, p);
4481 p += mcnt;
4482 break;
4483 default:
4484 return p;
4485 }
4486 }
4487 assert (p == pend);
4488 return p;
4489}
4490
4491/* Non-zero if "p1 matches something" implies "p2 fails". */
4492static int
4493mutually_exclusive_p (bufp, p1, p2)
4494 struct re_pattern_buffer *bufp;
4495 re_char *p1, *p2;
4496{
4497 re_opcode_t op2;
4498 const boolean multibyte = RE_MULTIBYTE_P (bufp);
4499 unsigned char *pend = bufp->buffer + bufp->used;
4500
4501 assert (p1 >= bufp->buffer && p1 < pend
4502 && p2 >= bufp->buffer && p2 <= pend);
4503
4504 /* Skip over open/close-group commands.
4505 If what follows this loop is a ...+ construct,
4506 look at what begins its body, since we will have to
4507 match at least one of that. */
4508 p2 = skip_noops (p2, pend);
4509 /* The same skip can be done for p1, except that this function
4510 is only used in the case where p1 is a simple match operator. */
4511 /* p1 = skip_noops (p1, pend); */
4512
4513 assert (p1 >= bufp->buffer && p1 < pend
4514 && p2 >= bufp->buffer && p2 <= pend);
4515
4516 op2 = p2 == pend ? succeed : *p2;
4517
4518 switch (SWITCH_ENUM_CAST (op2))
4519 {
4520 case succeed:
4521 case endbuf:
4522 /* If we're at the end of the pattern, we can change. */
4523 if (skip_one_char (p1))
4524 {
4525 DEBUG_PRINT1 (" End of pattern: fast loop.\n");
4526 return 1;
4527 }
4528 break;
4529
4530 case endline:
4531 case exactn:
4532 {
4533 register re_wchar_t c
4534 = (re_opcode_t) *p2 == endline ? '\n'
4535 : RE_STRING_CHAR (p2 + 2, pend - p2 - 2);
4536
4537 if ((re_opcode_t) *p1 == exactn)
4538 {
4539 if (c != RE_STRING_CHAR (p1 + 2, pend - p1 - 2))
4540 {
4541 DEBUG_PRINT3 (" '%c' != '%c' => fast loop.\n", c, p1[2]);
4542 return 1;
4543 }
4544 }
4545
4546 else if ((re_opcode_t) *p1 == charset
4547 || (re_opcode_t) *p1 == charset_not)
4548 {
4549 int not = (re_opcode_t) *p1 == charset_not;
4550
4551 /* Test if C is listed in charset (or charset_not)
4552 at `p1'. */
4553 if (SINGLE_BYTE_CHAR_P (c))
4554 {
4555 if (c < CHARSET_BITMAP_SIZE (p1) * BYTEWIDTH
4556 && p1[2 + c / BYTEWIDTH] & (1 << (c % BYTEWIDTH)))
4557 not = !not;
4558 }
4559 else if (CHARSET_RANGE_TABLE_EXISTS_P (p1))
4560 CHARSET_LOOKUP_RANGE_TABLE (not, c, p1);
4561
4562 /* `not' is equal to 1 if c would match, which means
4563 that we can't change to pop_failure_jump. */
4564 if (!not)
4565 {
4566 DEBUG_PRINT1 (" No match => fast loop.\n");
4567 return 1;
4568 }
4569 }
4570 else if ((re_opcode_t) *p1 == anychar
4571 && c == '\n')
4572 {
4573 DEBUG_PRINT1 (" . != \\n => fast loop.\n");
4574 return 1;
4575 }
4576 }
4577 break;
4578
4579 case charset:
4580 {
4581 if ((re_opcode_t) *p1 == exactn)
4582 /* Reuse the code above. */
4583 return mutually_exclusive_p (bufp, p2, p1);
4584
4585 /* It is hard to list up all the character in charset
4586 P2 if it includes multibyte character. Give up in
4587 such case. */
4588 else if (!multibyte || !CHARSET_RANGE_TABLE_EXISTS_P (p2))
4589 {
4590 /* Now, we are sure that P2 has no range table.
4591 So, for the size of bitmap in P2, `p2[1]' is
4592 enough. But P1 may have range table, so the
4593 size of bitmap table of P1 is extracted by
4594 using macro `CHARSET_BITMAP_SIZE'.
4595
4596 Since we know that all the character listed in
4597 P2 is ASCII, it is enough to test only bitmap
4598 table of P1. */
4599
4600 if ((re_opcode_t) *p1 == charset)
4601 {
4602 int idx;
4603 /* We win if the charset inside the loop
4604 has no overlap with the one after the loop. */
4605 for (idx = 0;
4606 (idx < (int) p2[1]
4607 && idx < CHARSET_BITMAP_SIZE (p1));
4608 idx++)
4609 if ((p2[2 + idx] & p1[2 + idx]) != 0)
4610 break;
4611
4612 if (idx == p2[1]
4613 || idx == CHARSET_BITMAP_SIZE (p1))
4614 {
4615 DEBUG_PRINT1 (" No match => fast loop.\n");
4616 return 1;
4617 }
4618 }
4619 else if ((re_opcode_t) *p1 == charset_not)
4620 {
4621 int idx;
4622 /* We win if the charset_not inside the loop lists
4623 every character listed in the charset after. */
4624 for (idx = 0; idx < (int) p2[1]; idx++)
4625 if (! (p2[2 + idx] == 0
4626 || (idx < CHARSET_BITMAP_SIZE (p1)
4627 && ((p2[2 + idx] & ~ p1[2 + idx]) == 0))))
4628 break;
4629
4630 if (idx == p2[1])
4631 {
4632 DEBUG_PRINT1 (" No match => fast loop.\n");
4633 return 1;
4634 }
4635 }
4636 }
4637 }
4638 break;
4639
4640 case charset_not:
4641 switch (SWITCH_ENUM_CAST (*p1))
4642 {
4643 case exactn:
4644 case charset:
4645 /* Reuse the code above. */
4646 return mutually_exclusive_p (bufp, p2, p1);
4647 case charset_not:
4648 /* When we have two charset_not, it's very unlikely that
4649 they don't overlap. The union of the two sets of excluded
4650 chars should cover all possible chars, which, as a matter of
4651 fact, is virtually impossible in multibyte buffers. */
4652 break;
4653 }
4654 break;
4655
4656 case wordend:
4657 case notsyntaxspec:
4658 return ((re_opcode_t) *p1 == syntaxspec
4659 && p1[1] == (op2 == wordend ? Sword : p2[1]));
4660
4661 case wordbeg:
4662 case syntaxspec:
4663 return ((re_opcode_t) *p1 == notsyntaxspec
4664 && p1[1] == (op2 == wordend ? Sword : p2[1]));
4665
4666 case wordbound:
4667 return (((re_opcode_t) *p1 == notsyntaxspec
4668 || (re_opcode_t) *p1 == syntaxspec)
4669 && p1[1] == Sword);
4670
4671#ifdef emacs
4672 case categoryspec:
4673 return ((re_opcode_t) *p1 == notcategoryspec && p1[1] == p2[1]);
4674 case notcategoryspec:
4675 return ((re_opcode_t) *p1 == categoryspec && p1[1] == p2[1]);
4676#endif /* emacs */
4677
4678 default:
4679 ;
4680 }
4681
4682 /* Safe default. */
4683 return 0;
4684}
4685
4686
4687/* Matching routines. */
4688
4689#ifndef emacs /* Emacs never uses this. */
4690/* re_match is like re_match_2 except it takes only a single string. */
4691
4692int
4693re_match (bufp, string, size, pos, regs)
4694 struct re_pattern_buffer *bufp;
4695 const char *string;
4696 int size, pos;
4697 struct re_registers *regs;
4698{
4699 int result = re_match_2_internal (bufp, NULL, 0, (re_char*) string, size,
4700 pos, regs, size);
4701# if defined C_ALLOCA && !defined REGEX_MALLOC
4702 alloca (0);
4703# endif
4704 return result;
4705}
4706WEAK_ALIAS (__re_match, re_match)
4707#endif /* not emacs */
4708
4709#ifdef emacs
4710/* In Emacs, this is the string or buffer in which we
4711 are matching. It is used for looking up syntax properties. */
4712Lisp_Object re_match_object;
4713#endif
4714
4715/* re_match_2 matches the compiled pattern in BUFP against the
4716 the (virtual) concatenation of STRING1 and STRING2 (of length SIZE1
4717 and SIZE2, respectively). We start matching at POS, and stop
4718 matching at STOP.
4719
4720 If REGS is non-null and the `no_sub' field of BUFP is nonzero, we
4721 store offsets for the substring each group matched in REGS. See the
4722 documentation for exactly how many groups we fill.
4723
4724 We return -1 if no match, -2 if an internal error (such as the
4725 failure stack overflowing). Otherwise, we return the length of the
4726 matched substring. */
4727
4728int
4729re_match_2 (bufp, string1, size1, string2, size2, pos, regs, stop)
4730 struct re_pattern_buffer *bufp;
4731 const char *string1, *string2;
4732 int size1, size2;
4733 int pos;
4734 struct re_registers *regs;
4735 int stop;
4736{
4737 int result;
4738
4739#ifdef emacs
4740 int charpos;
4741 gl_state.object = re_match_object;
4742 charpos = SYNTAX_TABLE_BYTE_TO_CHAR (POS_AS_IN_BUFFER (pos));
4743 SETUP_SYNTAX_TABLE_FOR_OBJECT (re_match_object, charpos, 1);
4744#endif
4745
4746 result = re_match_2_internal (bufp, (re_char*) string1, size1,
4747 (re_char*) string2, size2,
4748 pos, regs, stop);
4749#if defined C_ALLOCA && !defined REGEX_MALLOC
4750 alloca (0);
4751#endif
4752 return result;
4753}
4754WEAK_ALIAS (__re_match_2, re_match_2)
4755
4756/* This is a separate function so that we can force an alloca cleanup
4757 afterwards. */
4758static int
4759re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop)
4760 struct re_pattern_buffer *bufp;
4761 re_char *string1, *string2;
4762 int size1, size2;
4763 int pos;
4764 struct re_registers *regs;
4765 int stop;
4766{
4767 /* General temporaries. */
4768 int mcnt;
4769 size_t reg;
4770 boolean not;
4771
4772 /* Just past the end of the corresponding string. */
4773 re_char *end1, *end2;
4774
4775 /* Pointers into string1 and string2, just past the last characters in
4776 each to consider matching. */
4777 re_char *end_match_1, *end_match_2;
4778
4779 /* Where we are in the data, and the end of the current string. */
4780 re_char *d, *dend;
4781
4782 /* Used sometimes to remember where we were before starting matching
4783 an operator so that we can go back in case of failure. This "atomic"
4784 behavior of matching opcodes is indispensable to the correctness
4785 of the on_failure_keep_string_jump optimization. */
4786 re_char *dfail;
4787
4788 /* Where we are in the pattern, and the end of the pattern. */
4789 re_char *p = bufp->buffer;
4790 re_char *pend = p + bufp->used;
4791
4792 /* We use this to map every character in the string. */
4793 RE_TRANSLATE_TYPE translate = bufp->translate;
4794
4795 /* Nonzero if we have to concern multibyte character. */
4796 const boolean multibyte = RE_MULTIBYTE_P (bufp);
4797
4798 /* Failure point stack. Each place that can handle a failure further
4799 down the line pushes a failure point on this stack. It consists of
4800 regstart, and regend for all registers corresponding to
4801 the subexpressions we're currently inside, plus the number of such
4802 registers, and, finally, two char *'s. The first char * is where
4803 to resume scanning the pattern; the second one is where to resume
4804 scanning the strings. */
4805#ifdef MATCH_MAY_ALLOCATE /* otherwise, this is global. */
4806 fail_stack_type fail_stack;
4807#endif
4808#ifdef DEBUG
4809 unsigned nfailure_points_pushed = 0, nfailure_points_popped = 0;
4810#endif
4811
4812#if defined REL_ALLOC && defined REGEX_MALLOC
4813 /* This holds the pointer to the failure stack, when
4814 it is allocated relocatably. */
4815 fail_stack_elt_t *failure_stack_ptr;
4816#endif
4817
4818 /* We fill all the registers internally, independent of what we
4819 return, for use in backreferences. The number here includes
4820 an element for register zero. */
4821 size_t num_regs = bufp->re_nsub + 1;
4822
4823 /* Information on the contents of registers. These are pointers into
4824 the input strings; they record just what was matched (on this
4825 attempt) by a subexpression part of the pattern, that is, the
4826 regnum-th regstart pointer points to where in the pattern we began
4827 matching and the regnum-th regend points to right after where we
4828 stopped matching the regnum-th subexpression. (The zeroth register
4829 keeps track of what the whole pattern matches.) */
4830#ifdef MATCH_MAY_ALLOCATE /* otherwise, these are global. */
4831 re_char **regstart, **regend;
4832#endif
4833
4834 /* The following record the register info as found in the above
4835 variables when we find a match better than any we've seen before.
4836 This happens as we backtrack through the failure points, which in
4837 turn happens only if we have not yet matched the entire string. */
4838 unsigned best_regs_set = false;
4839#ifdef MATCH_MAY_ALLOCATE /* otherwise, these are global. */
4840 re_char **best_regstart, **best_regend;
4841#endif
4842
4843 /* Logically, this is `best_regend[0]'. But we don't want to have to
4844 allocate space for that if we're not allocating space for anything
4845 else (see below). Also, we never need info about register 0 for
4846 any of the other register vectors, and it seems rather a kludge to
4847 treat `best_regend' differently than the rest. So we keep track of
4848 the end of the best match so far in a separate variable. We
4849 initialize this to NULL so that when we backtrack the first time
4850 and need to test it, it's not garbage. */
4851 re_char *match_end = NULL;
4852
4853#ifdef DEBUG
4854 /* Counts the total number of registers pushed. */
4855 unsigned num_regs_pushed = 0;
4856#endif
4857
4858 DEBUG_PRINT1 ("\n\nEntering re_match_2.\n");
4859
4860 INIT_FAIL_STACK ();
4861
4862#ifdef MATCH_MAY_ALLOCATE
4863 /* Do not bother to initialize all the register variables if there are
4864 no groups in the pattern, as it takes a fair amount of time. If
4865 there are groups, we include space for register 0 (the whole
4866 pattern), even though we never use it, since it simplifies the
4867 array indexing. We should fix this. */
4868 if (bufp->re_nsub)
4869 {
4870 regstart = REGEX_TALLOC (num_regs, re_char *);
4871 regend = REGEX_TALLOC (num_regs, re_char *);
4872 best_regstart = REGEX_TALLOC (num_regs, re_char *);
4873 best_regend = REGEX_TALLOC (num_regs, re_char *);
4874
4875 if (!(regstart && regend && best_regstart && best_regend))
4876 {
4877 FREE_VARIABLES ();
4878 return -2;
4879 }
4880 }
4881 else
4882 {
4883 /* We must initialize all our variables to NULL, so that
4884 `FREE_VARIABLES' doesn't try to free them. */
4885 regstart = regend = best_regstart = best_regend = NULL;
4886 }
4887#endif /* MATCH_MAY_ALLOCATE */
4888
4889 /* The starting position is bogus. */
4890 if (pos < 0 || pos > size1 + size2)
4891 {
4892 FREE_VARIABLES ();
4893 return -1;
4894 }
4895
4896 /* Initialize subexpression text positions to -1 to mark ones that no
4897 start_memory/stop_memory has been seen for. Also initialize the
4898 register information struct. */
4899 for (reg = 1; reg < num_regs; reg++)
4900 regstart[reg] = regend[reg] = NULL;
4901
4902 /* We move `string1' into `string2' if the latter's empty -- but not if
4903 `string1' is null. */
4904 if (size2 == 0 && string1 != NULL)
4905 {
4906 string2 = string1;
4907 size2 = size1;
4908 string1 = 0;
4909 size1 = 0;
4910 }
4911 end1 = string1 + size1;
4912 end2 = string2 + size2;
4913
4914 /* `p' scans through the pattern as `d' scans through the data.
4915 `dend' is the end of the input string that `d' points within. `d'
4916 is advanced into the following input string whenever necessary, but
4917 this happens before fetching; therefore, at the beginning of the
4918 loop, `d' can be pointing at the end of a string, but it cannot
4919 equal `string2'. */
4920 if (pos >= size1)
4921 {
4922 /* Only match within string2. */
4923 d = string2 + pos - size1;
4924 dend = end_match_2 = string2 + stop - size1;
4925 end_match_1 = end1; /* Just to give it a value. */
4926 }
4927 else
4928 {
4929 if (stop < size1)
4930 {
4931 /* Only match within string1. */
4932 end_match_1 = string1 + stop;
4933 /* BEWARE!
4934 When we reach end_match_1, PREFETCH normally switches to string2.
4935 But in the present case, this means that just doing a PREFETCH
4936 makes us jump from `stop' to `gap' within the string.
4937 What we really want here is for the search to stop as
4938 soon as we hit end_match_1. That's why we set end_match_2
4939 to end_match_1 (since PREFETCH fails as soon as we hit
4940 end_match_2). */
4941 end_match_2 = end_match_1;
4942 }
4943 else
4944 { /* It's important to use this code when stop == size so that
4945 moving `d' from end1 to string2 will not prevent the d == dend
4946 check from catching the end of string. */
4947 end_match_1 = end1;
4948 end_match_2 = string2 + stop - size1;
4949 }
4950 d = string1 + pos;
4951 dend = end_match_1;
4952 }
4953
4954 DEBUG_PRINT1 ("The compiled pattern is: ");
4955 DEBUG_PRINT_COMPILED_PATTERN (bufp, p, pend);
4956 DEBUG_PRINT1 ("The string to match is: `");
4957 DEBUG_PRINT_DOUBLE_STRING (d, string1, size1, string2, size2);
4958 DEBUG_PRINT1 ("'\n");
4959
4960 /* This loops over pattern commands. It exits by returning from the
4961 function if the match is complete, or it drops through if the match
4962 fails at this starting point in the input data. */
4963 for (;;)
4964 {
4965 DEBUG_PRINT2 ("\n%p: ", p);
4966
4967 if (p == pend)
4968 { /* End of pattern means we might have succeeded. */
4969 DEBUG_PRINT1 ("end of pattern ... ");
4970
4971 /* If we haven't matched the entire string, and we want the
4972 longest match, try backtracking. */
4973 if (d != end_match_2)
4974 {
4975 /* 1 if this match ends in the same string (string1 or string2)
4976 as the best previous match. */
4977 boolean same_str_p = (FIRST_STRING_P (match_end)
4978 == FIRST_STRING_P (d));
4979 /* 1 if this match is the best seen so far. */
4980 boolean best_match_p;
4981
4982 /* AIX compiler got confused when this was combined
4983 with the previous declaration. */
4984 if (same_str_p)
4985 best_match_p = d > match_end;
4986 else
4987 best_match_p = !FIRST_STRING_P (d);
4988
4989 DEBUG_PRINT1 ("backtracking.\n");
4990
4991 if (!FAIL_STACK_EMPTY ())
4992 { /* More failure points to try. */
4993
4994 /* If exceeds best match so far, save it. */
4995 if (!best_regs_set || best_match_p)
4996 {
4997 best_regs_set = true;
4998 match_end = d;
4999
5000 DEBUG_PRINT1 ("\nSAVING match as best so far.\n");
5001
5002 for (reg = 1; reg < num_regs; reg++)
5003 {
5004 best_regstart[reg] = regstart[reg];
5005 best_regend[reg] = regend[reg];
5006 }
5007 }
5008 goto fail;
5009 }
5010
5011 /* If no failure points, don't restore garbage. And if
5012 last match is real best match, don't restore second
5013 best one. */
5014 else if (best_regs_set && !best_match_p)
5015 {
5016 restore_best_regs:
5017 /* Restore best match. It may happen that `dend ==
5018 end_match_1' while the restored d is in string2.
5019 For example, the pattern `x.*y.*z' against the
5020 strings `x-' and `y-z-', if the two strings are
5021 not consecutive in memory. */
5022 DEBUG_PRINT1 ("Restoring best registers.\n");
5023
5024 d = match_end;
5025 dend = ((d >= string1 && d <= end1)
5026 ? end_match_1 : end_match_2);
5027
5028 for (reg = 1; reg < num_regs; reg++)
5029 {
5030 regstart[reg] = best_regstart[reg];
5031 regend[reg] = best_regend[reg];
5032 }
5033 }
5034 } /* d != end_match_2 */
5035
5036 succeed_label:
5037 DEBUG_PRINT1 ("Accepting match.\n");
5038
5039 /* If caller wants register contents data back, do it. */
5040 if (regs && !bufp->no_sub)
5041 {
5042 /* Have the register data arrays been allocated? */
5043 if (bufp->regs_allocated == REGS_UNALLOCATED)
5044 { /* No. So allocate them with malloc. We need one
5045 extra element beyond `num_regs' for the `-1' marker
5046 GNU code uses. */
5047 regs->num_regs = MAX (RE_NREGS, num_regs + 1);
5048 regs->start = TALLOC (regs->num_regs, regoff_t);
5049 regs->end = TALLOC (regs->num_regs, regoff_t);
5050 if (regs->start == NULL || regs->end == NULL)
5051 {
5052 FREE_VARIABLES ();
5053 return -2;
5054 }
5055 bufp->regs_allocated = REGS_REALLOCATE;
5056 }
5057 else if (bufp->regs_allocated == REGS_REALLOCATE)
5058 { /* Yes. If we need more elements than were already
5059 allocated, reallocate them. If we need fewer, just
5060 leave it alone. */
5061 if (regs->num_regs < num_regs + 1)
5062 {
5063 regs->num_regs = num_regs + 1;
5064 RETALLOC (regs->start, regs->num_regs, regoff_t);
5065 RETALLOC (regs->end, regs->num_regs, regoff_t);
5066 if (regs->start == NULL || regs->end == NULL)
5067 {
5068 FREE_VARIABLES ();
5069 return -2;
5070 }
5071 }
5072 }
5073 else
5074 {
5075 /* These braces fend off a "empty body in an else-statement"
5076 warning under GCC when assert expands to nothing. */
5077 assert (bufp->regs_allocated == REGS_FIXED);
5078 }
5079
5080 /* Convert the pointer data in `regstart' and `regend' to
5081 indices. Register zero has to be set differently,
5082 since we haven't kept track of any info for it. */
5083 if (regs->num_regs > 0)
5084 {
5085 regs->start[0] = pos;
5086 regs->end[0] = POINTER_TO_OFFSET (d);
5087 }
5088
5089 /* Go through the first `min (num_regs, regs->num_regs)'
5090 registers, since that is all we initialized. */
5091 for (reg = 1; reg < MIN (num_regs, regs->num_regs); reg++)
5092 {
5093 if (REG_UNSET (regstart[reg]) || REG_UNSET (regend[reg]))
5094 regs->start[reg] = regs->end[reg] = -1;
5095 else
5096 {
5097 regs->start[reg]
5098 = (regoff_t) POINTER_TO_OFFSET (regstart[reg]);
5099 regs->end[reg]
5100 = (regoff_t) POINTER_TO_OFFSET (regend[reg]);
5101 }
5102 }
5103
5104 /* If the regs structure we return has more elements than
5105 were in the pattern, set the extra elements to -1. If
5106 we (re)allocated the registers, this is the case,
5107 because we always allocate enough to have at least one
5108 -1 at the end. */
5109 for (reg = num_regs; reg < regs->num_regs; reg++)
5110 regs->start[reg] = regs->end[reg] = -1;
5111 } /* regs && !bufp->no_sub */
5112
5113 DEBUG_PRINT4 ("%u failure points pushed, %u popped (%u remain).\n",
5114 nfailure_points_pushed, nfailure_points_popped,
5115 nfailure_points_pushed - nfailure_points_popped);
5116 DEBUG_PRINT2 ("%u registers pushed.\n", num_regs_pushed);
5117
5118 mcnt = POINTER_TO_OFFSET (d) - pos;
5119
5120 DEBUG_PRINT2 ("Returning %d from re_match_2.\n", mcnt);
5121
5122 FREE_VARIABLES ();
5123 return mcnt;
5124 }
5125
5126 /* Otherwise match next pattern command. */
5127 switch (SWITCH_ENUM_CAST ((re_opcode_t) *p++))
5128 {
5129 /* Ignore these. Used to ignore the n of succeed_n's which
5130 currently have n == 0. */
5131 case no_op:
5132 DEBUG_PRINT1 ("EXECUTING no_op.\n");
5133 break;
5134
5135 case succeed:
5136 DEBUG_PRINT1 ("EXECUTING succeed.\n");
5137 goto succeed_label;
5138
5139 /* Match the next n pattern characters exactly. The following
5140 byte in the pattern defines n, and the n bytes after that
5141 are the characters to match. */
5142 case exactn:
5143 mcnt = *p++;
5144 DEBUG_PRINT2 ("EXECUTING exactn %d.\n", mcnt);
5145
5146 /* Remember the start point to rollback upon failure. */
5147 dfail = d;
5148
5149 /* This is written out as an if-else so we don't waste time
5150 testing `translate' inside the loop. */
5151 if (RE_TRANSLATE_P (translate))
5152 {
5153 if (multibyte)
5154 do
5155 {
5156 int pat_charlen, buf_charlen;
5157 unsigned int pat_ch, buf_ch;
5158
5159 PREFETCH ();
5160 pat_ch = STRING_CHAR_AND_LENGTH (p, pend - p, pat_charlen);
5161 buf_ch = STRING_CHAR_AND_LENGTH (d, dend - d, buf_charlen);
5162
5163 if (RE_TRANSLATE (translate, buf_ch)
5164 != pat_ch)
5165 {
5166 d = dfail;
5167 goto fail;
5168 }
5169
5170 p += pat_charlen;
5171 d += buf_charlen;
5172 mcnt -= pat_charlen;
5173 }
5174 while (mcnt > 0);
5175 else
5176 do
5177 {
5178 PREFETCH ();
5179 if (RE_TRANSLATE (translate, *d) != *p++)
5180 {
5181 d = dfail;
5182 goto fail;
5183 }
5184 d++;
5185 }
5186 while (--mcnt);
5187 }
5188 else
5189 {
5190 do
5191 {
5192 PREFETCH ();
5193 if (*d++ != *p++)
5194 {
5195 d = dfail;
5196 goto fail;
5197 }
5198 }
5199 while (--mcnt);
5200 }
5201 break;
5202
5203
5204 /* Match any character except possibly a newline or a null. */
5205 case anychar:
5206 {
5207 int buf_charlen;
5208 re_wchar_t buf_ch;
5209
5210 DEBUG_PRINT1 ("EXECUTING anychar.\n");
5211
5212 PREFETCH ();
5213 buf_ch = RE_STRING_CHAR_AND_LENGTH (d, dend - d, buf_charlen);
5214 buf_ch = TRANSLATE (buf_ch);
5215
5216 if ((!(bufp->syntax & RE_DOT_NEWLINE)
5217 && buf_ch == '\n')
5218 || ((bufp->syntax & RE_DOT_NOT_NULL)
5219 && buf_ch == '\000'))
5220 goto fail;
5221
5222 DEBUG_PRINT2 (" Matched `%d'.\n", *d);
5223 d += buf_charlen;
5224 }
5225 break;
5226
5227
5228 case charset:
5229 case charset_not:
5230 {
5231 register unsigned int c;
5232 boolean not = (re_opcode_t) *(p - 1) == charset_not;
5233 int len;
5234
5235 /* Start of actual range_table, or end of bitmap if there is no
5236 range table. */
5237 re_char *range_table;
5238
5239 /* Nonzero if there is a range table. */
5240 int range_table_exists;
5241
5242 /* Number of ranges of range table. This is not included
5243 in the initial byte-length of the command. */
5244 int count = 0;
5245
5246 DEBUG_PRINT2 ("EXECUTING charset%s.\n", not ? "_not" : "");
5247
5248 range_table_exists = CHARSET_RANGE_TABLE_EXISTS_P (&p[-1]);
5249
5250 if (range_table_exists)
5251 {
5252 range_table = CHARSET_RANGE_TABLE (&p[-1]); /* Past the bitmap. */
5253 EXTRACT_NUMBER_AND_INCR (count, range_table);
5254 }
5255
5256 PREFETCH ();
5257 c = RE_STRING_CHAR_AND_LENGTH (d, dend - d, len);
5258 c = TRANSLATE (c); /* The character to match. */
5259
5260 if (SINGLE_BYTE_CHAR_P (c))
5261 { /* Lookup bitmap. */
5262 /* Cast to `unsigned' instead of `unsigned char' in
5263 case the bit list is a full 32 bytes long. */
5264 if (c < (unsigned) (CHARSET_BITMAP_SIZE (&p[-1]) * BYTEWIDTH)
5265 && p[1 + c / BYTEWIDTH] & (1 << (c % BYTEWIDTH)))
5266 not = !not;
5267 }
5268#ifdef emacs
5269 else if (range_table_exists)
5270 {
5271 int class_bits = CHARSET_RANGE_TABLE_BITS (&p[-1]);
5272
5273 if ( (class_bits & BIT_LOWER && ISLOWER (c))
5274 | (class_bits & BIT_MULTIBYTE)
5275 | (class_bits & BIT_PUNCT && ISPUNCT (c))
5276 | (class_bits & BIT_SPACE && ISSPACE (c))
5277 | (class_bits & BIT_UPPER && ISUPPER (c))
5278 | (class_bits & BIT_WORD && ISWORD (c)))
5279 not = !not;
5280 else
5281 CHARSET_LOOKUP_RANGE_TABLE_RAW (not, c, range_table, count);
5282 }
5283#endif /* emacs */
5284
5285 if (range_table_exists)
5286 p = CHARSET_RANGE_TABLE_END (range_table, count);
5287 else
5288 p += CHARSET_BITMAP_SIZE (&p[-1]) + 1;
5289
5290 if (!not) goto fail;
5291
5292 d += len;
5293 break;
5294 }
5295
5296
5297 /* The beginning of a group is represented by start_memory.
5298 The argument is the register number. The text
5299 matched within the group is recorded (in the internal
5300 registers data structure) under the register number. */
5301 case start_memory:
5302 DEBUG_PRINT2 ("EXECUTING start_memory %d:\n", *p);
5303
5304 /* In case we need to undo this operation (via backtracking). */
5305 PUSH_FAILURE_REG ((unsigned int)*p);
5306
5307 regstart[*p] = d;
5308 regend[*p] = NULL; /* probably unnecessary. -sm */
5309 DEBUG_PRINT2 (" regstart: %d\n", POINTER_TO_OFFSET (regstart[*p]));
5310
5311 /* Move past the register number and inner group count. */
5312 p += 1;
5313 break;
5314
5315
5316 /* The stop_memory opcode represents the end of a group. Its
5317 argument is the same as start_memory's: the register number. */
5318 case stop_memory:
5319 DEBUG_PRINT2 ("EXECUTING stop_memory %d:\n", *p);
5320
5321 assert (!REG_UNSET (regstart[*p]));
5322 /* Strictly speaking, there should be code such as:
5323
5324 assert (REG_UNSET (regend[*p]));
5325 PUSH_FAILURE_REGSTOP ((unsigned int)*p);
5326
5327 But the only info to be pushed is regend[*p] and it is known to
5328 be UNSET, so there really isn't anything to push.
5329 Not pushing anything, on the other hand deprives us from the
5330 guarantee that regend[*p] is UNSET since undoing this operation
5331 will not reset its value properly. This is not important since
5332 the value will only be read on the next start_memory or at
5333 the very end and both events can only happen if this stop_memory
5334 is *not* undone. */
5335
5336 regend[*p] = d;
5337 DEBUG_PRINT2 (" regend: %d\n", POINTER_TO_OFFSET (regend[*p]));
5338
5339 /* Move past the register number and the inner group count. */
5340 p += 1;
5341 break;
5342
5343
5344 /* \<digit> has been turned into a `duplicate' command which is
5345 followed by the numeric value of <digit> as the register number. */
5346 case duplicate:
5347 {
5348 register re_char *d2, *dend2;
5349 int regno = *p++; /* Get which register to match against. */
5350 DEBUG_PRINT2 ("EXECUTING duplicate %d.\n", regno);
5351
5352 /* Can't back reference a group which we've never matched. */
5353 if (REG_UNSET (regstart[regno]) || REG_UNSET (regend[regno]))
5354 goto fail;
5355
5356 /* Where in input to try to start matching. */
5357 d2 = regstart[regno];
5358
5359 /* Remember the start point to rollback upon failure. */
5360 dfail = d;
5361
5362 /* Where to stop matching; if both the place to start and
5363 the place to stop matching are in the same string, then
5364 set to the place to stop, otherwise, for now have to use
5365 the end of the first string. */
5366
5367 dend2 = ((FIRST_STRING_P (regstart[regno])
5368 == FIRST_STRING_P (regend[regno]))
5369 ? regend[regno] : end_match_1);
5370 for (;;)
5371 {
5372 /* If necessary, advance to next segment in register
5373 contents. */
5374 while (d2 == dend2)
5375 {
5376 if (dend2 == end_match_2) break;
5377 if (dend2 == regend[regno]) break;
5378
5379 /* End of string1 => advance to string2. */
5380 d2 = string2;
5381 dend2 = regend[regno];
5382 }
5383 /* At end of register contents => success */
5384 if (d2 == dend2) break;
5385
5386 /* If necessary, advance to next segment in data. */
5387 PREFETCH ();
5388
5389 /* How many characters left in this segment to match. */
5390 mcnt = dend - d;
5391
5392 /* Want how many consecutive characters we can match in
5393 one shot, so, if necessary, adjust the count. */
5394 if (mcnt > dend2 - d2)
5395 mcnt = dend2 - d2;
5396
5397 /* Compare that many; failure if mismatch, else move
5398 past them. */
5399 if (RE_TRANSLATE_P (translate)
5400 ? bcmp_translate (d, d2, mcnt, translate, multibyte)
5401 : memcmp (d, d2, mcnt))
5402 {
5403 d = dfail;
5404 goto fail;
5405 }
5406 d += mcnt, d2 += mcnt;
5407 }
5408 }
5409 break;
5410
5411
5412 /* begline matches the empty string at the beginning of the string
5413 (unless `not_bol' is set in `bufp'), and after newlines. */
5414 case begline:
5415 DEBUG_PRINT1 ("EXECUTING begline.\n");
5416
5417 if (AT_STRINGS_BEG (d))
5418 {
5419 if (!bufp->not_bol) break;
5420 }
5421 else
5422 {
5423 unsigned char c;
5424 GET_CHAR_BEFORE_2 (c, d, string1, end1, string2, end2);
5425 if (c == '\n')
5426 break;
5427 }
5428 /* In all other cases, we fail. */
5429 goto fail;
5430
5431
5432 /* endline is the dual of begline. */
5433 case endline:
5434 DEBUG_PRINT1 ("EXECUTING endline.\n");
5435
5436 if (AT_STRINGS_END (d))
5437 {
5438 if (!bufp->not_eol) break;
5439 }
5440 else
5441 {
5442 PREFETCH_NOLIMIT ();
5443 if (*d == '\n')
5444 break;
5445 }
5446 goto fail;
5447
5448
5449 /* Match at the very beginning of the data. */
5450 case begbuf:
5451 DEBUG_PRINT1 ("EXECUTING begbuf.\n");
5452 if (AT_STRINGS_BEG (d))
5453 break;
5454 goto fail;
5455
5456
5457 /* Match at the very end of the data. */
5458 case endbuf:
5459 DEBUG_PRINT1 ("EXECUTING endbuf.\n");
5460 if (AT_STRINGS_END (d))
5461 break;
5462 goto fail;
5463
5464
5465 /* on_failure_keep_string_jump is used to optimize `.*\n'. It
5466 pushes NULL as the value for the string on the stack. Then
5467 `POP_FAILURE_POINT' will keep the current value for the
5468 string, instead of restoring it. To see why, consider
5469 matching `foo\nbar' against `.*\n'. The .* matches the foo;
5470 then the . fails against the \n. But the next thing we want
5471 to do is match the \n against the \n; if we restored the
5472 string value, we would be back at the foo.
5473
5474 Because this is used only in specific cases, we don't need to
5475 check all the things that `on_failure_jump' does, to make
5476 sure the right things get saved on the stack. Hence we don't
5477 share its code. The only reason to push anything on the
5478 stack at all is that otherwise we would have to change
5479 `anychar's code to do something besides goto fail in this
5480 case; that seems worse than this. */
5481 case on_failure_keep_string_jump:
5482 EXTRACT_NUMBER_AND_INCR (mcnt, p);
5483 DEBUG_PRINT3 ("EXECUTING on_failure_keep_string_jump %d (to %p):\n",
5484 mcnt, p + mcnt);
5485
5486 PUSH_FAILURE_POINT (p - 3, NULL);
5487 break;
5488
5489 /* A nasty loop is introduced by the non-greedy *? and +?.
5490 With such loops, the stack only ever contains one failure point
5491 at a time, so that a plain on_failure_jump_loop kind of
5492 cycle detection cannot work. Worse yet, such a detection
5493 can not only fail to detect a cycle, but it can also wrongly
5494 detect a cycle (between different instantiations of the same
5495 loop).
5496 So the method used for those nasty loops is a little different:
5497 We use a special cycle-detection-stack-frame which is pushed
5498 when the on_failure_jump_nastyloop failure-point is *popped*.
5499 This special frame thus marks the beginning of one iteration
5500 through the loop and we can hence easily check right here
5501 whether something matched between the beginning and the end of
5502 the loop. */
5503 case on_failure_jump_nastyloop:
5504 EXTRACT_NUMBER_AND_INCR (mcnt, p);
5505 DEBUG_PRINT3 ("EXECUTING on_failure_jump_nastyloop %d (to %p):\n",
5506 mcnt, p + mcnt);
5507
5508 assert ((re_opcode_t)p[-4] == no_op);
5509 {
5510 int cycle = 0;
5511 CHECK_INFINITE_LOOP (p - 4, d);
5512 if (!cycle)
5513 /* If there's a cycle, just continue without pushing
5514 this failure point. The failure point is the "try again"
5515 option, which shouldn't be tried.
5516 We want (x?)*?y\1z to match both xxyz and xxyxz. */
5517 PUSH_FAILURE_POINT (p - 3, d);
5518 }
5519 break;
5520
5521 /* Simple loop detecting on_failure_jump: just check on the
5522 failure stack if the same spot was already hit earlier. */
5523 case on_failure_jump_loop:
5524 on_failure:
5525 EXTRACT_NUMBER_AND_INCR (mcnt, p);
5526 DEBUG_PRINT3 ("EXECUTING on_failure_jump_loop %d (to %p):\n",
5527 mcnt, p + mcnt);
5528 {
5529 int cycle = 0;
5530 CHECK_INFINITE_LOOP (p - 3, d);
5531 if (cycle)
5532 /* If there's a cycle, get out of the loop, as if the matching
5533 had failed. We used to just `goto fail' here, but that was
5534 aborting the search a bit too early: we want to keep the
5535 empty-loop-match and keep matching after the loop.
5536 We want (x?)*y\1z to match both xxyz and xxyxz. */
5537 p += mcnt;
5538 else
5539 PUSH_FAILURE_POINT (p - 3, d);
5540 }
5541 break;
5542
5543
5544 /* Uses of on_failure_jump:
5545
5546 Each alternative starts with an on_failure_jump that points
5547 to the beginning of the next alternative. Each alternative
5548 except the last ends with a jump that in effect jumps past
5549 the rest of the alternatives. (They really jump to the
5550 ending jump of the following alternative, because tensioning
5551 these jumps is a hassle.)
5552
5553 Repeats start with an on_failure_jump that points past both
5554 the repetition text and either the following jump or
5555 pop_failure_jump back to this on_failure_jump. */
5556 case on_failure_jump:
5557 IMMEDIATE_QUIT_CHECK;
5558 EXTRACT_NUMBER_AND_INCR (mcnt, p);
5559 DEBUG_PRINT3 ("EXECUTING on_failure_jump %d (to %p):\n",
5560 mcnt, p + mcnt);
5561
5562 PUSH_FAILURE_POINT (p -3, d);
5563 break;
5564
5565 /* This operation is used for greedy *.
5566 Compare the beginning of the repeat with what in the
5567 pattern follows its end. If we can establish that there
5568 is nothing that they would both match, i.e., that we
5569 would have to backtrack because of (as in, e.g., `a*a')
5570 then we can use a non-backtracking loop based on
5571 on_failure_keep_string_jump instead of on_failure_jump. */
5572 case on_failure_jump_smart:
5573 IMMEDIATE_QUIT_CHECK;
5574 EXTRACT_NUMBER_AND_INCR (mcnt, p);
5575 DEBUG_PRINT3 ("EXECUTING on_failure_jump_smart %d (to %p).\n",
5576 mcnt, p + mcnt);
5577 {
5578 re_char *p1 = p; /* Next operation. */
5579 /* Here, we discard `const', making re_match non-reentrant. */
5580 unsigned char *p2 = (unsigned char*) p + mcnt; /* Jump dest. */
5581 unsigned char *p3 = (unsigned char*) p - 3; /* opcode location. */
5582
5583 p -= 3; /* Reset so that we will re-execute the
5584 instruction once it's been changed. */
5585
5586 EXTRACT_NUMBER (mcnt, p2 - 2);
5587
5588 /* Ensure this is a indeed the trivial kind of loop
5589 we are expecting. */
5590 assert (skip_one_char (p1) == p2 - 3);
5591 assert ((re_opcode_t) p2[-3] == jump && p2 + mcnt == p);
5592 DEBUG_STATEMENT (debug += 2);
5593 if (mutually_exclusive_p (bufp, p1, p2))
5594 {
5595 /* Use a fast `on_failure_keep_string_jump' loop. */
5596 DEBUG_PRINT1 (" smart exclusive => fast loop.\n");
5597 *p3 = (unsigned char) on_failure_keep_string_jump;
5598 STORE_NUMBER (p2 - 2, mcnt + 3);
5599 }
5600 else
5601 {
5602 /* Default to a safe `on_failure_jump' loop. */
5603 DEBUG_PRINT1 (" smart default => slow loop.\n");
5604 *p3 = (unsigned char) on_failure_jump;
5605 }
5606 DEBUG_STATEMENT (debug -= 2);
5607 }
5608 break;
5609
5610 /* Unconditionally jump (without popping any failure points). */
5611 case jump:
5612 unconditional_jump:
5613 IMMEDIATE_QUIT_CHECK;
5614 EXTRACT_NUMBER_AND_INCR (mcnt, p); /* Get the amount to jump. */
5615 DEBUG_PRINT2 ("EXECUTING jump %d ", mcnt);
5616 p += mcnt; /* Do the jump. */
5617 DEBUG_PRINT2 ("(to %p).\n", p);
5618 break;
5619
5620
5621 /* Have to succeed matching what follows at least n times.
5622 After that, handle like `on_failure_jump'. */
5623 case succeed_n:
5624 /* Signedness doesn't matter since we only compare MCNT to 0. */
5625 EXTRACT_NUMBER (mcnt, p + 2);
5626 DEBUG_PRINT2 ("EXECUTING succeed_n %d.\n", mcnt);
5627
5628 /* Originally, mcnt is how many times we HAVE to succeed. */
5629 if (mcnt != 0)
5630 {
5631 /* Here, we discard `const', making re_match non-reentrant. */
5632 unsigned char *p2 = (unsigned char*) p + 2; /* counter loc. */
5633 mcnt--;
5634 p += 4;
5635 PUSH_NUMBER (p2, mcnt);
5636 }
5637 else
5638 /* The two bytes encoding mcnt == 0 are two no_op opcodes. */
5639 goto on_failure;
5640 break;
5641
5642 case jump_n:
5643 /* Signedness doesn't matter since we only compare MCNT to 0. */
5644 EXTRACT_NUMBER (mcnt, p + 2);
5645 DEBUG_PRINT2 ("EXECUTING jump_n %d.\n", mcnt);
5646
5647 /* Originally, this is how many times we CAN jump. */
5648 if (mcnt != 0)
5649 {
5650 /* Here, we discard `const', making re_match non-reentrant. */
5651 unsigned char *p2 = (unsigned char*) p + 2; /* counter loc. */
5652 mcnt--;
5653 PUSH_NUMBER (p2, mcnt);
5654 goto unconditional_jump;
5655 }
5656 /* If don't have to jump any more, skip over the rest of command. */
5657 else
5658 p += 4;
5659 break;
5660
5661 case set_number_at:
5662 {
5663 unsigned char *p2; /* Location of the counter. */
5664 DEBUG_PRINT1 ("EXECUTING set_number_at.\n");
5665
5666 EXTRACT_NUMBER_AND_INCR (mcnt, p);
5667 /* Here, we discard `const', making re_match non-reentrant. */
5668 p2 = (unsigned char*) p + mcnt;
5669 /* Signedness doesn't matter since we only copy MCNT's bits . */
5670 EXTRACT_NUMBER_AND_INCR (mcnt, p);
5671 DEBUG_PRINT3 (" Setting %p to %d.\n", p2, mcnt);
5672 PUSH_NUMBER (p2, mcnt);
5673 break;
5674 }
5675
5676 case wordbound:
5677 case notwordbound:
5678 not = (re_opcode_t) *(p - 1) == notwordbound;
5679 DEBUG_PRINT2 ("EXECUTING %swordbound.\n", not?"not":"");
5680
5681 /* We SUCCEED (or FAIL) in one of the following cases: */
5682
5683 /* Case 1: D is at the beginning or the end of string. */
5684 if (AT_STRINGS_BEG (d) || AT_STRINGS_END (d))
5685 not = !not;
5686 else
5687 {
5688 /* C1 is the character before D, S1 is the syntax of C1, C2
5689 is the character at D, and S2 is the syntax of C2. */
5690 re_wchar_t c1, c2;
5691 int s1, s2;
5692#ifdef emacs
5693 int offset = PTR_TO_OFFSET (d - 1);
5694 int charpos = SYNTAX_TABLE_BYTE_TO_CHAR (offset);
5695 UPDATE_SYNTAX_TABLE (charpos);
5696#endif
5697 GET_CHAR_BEFORE_2 (c1, d, string1, end1, string2, end2);
5698 s1 = SYNTAX (c1);
5699#ifdef emacs
5700 UPDATE_SYNTAX_TABLE_FORWARD (charpos + 1);
5701#endif
5702 PREFETCH_NOLIMIT ();
5703 c2 = RE_STRING_CHAR (d, dend - d);
5704 s2 = SYNTAX (c2);
5705
5706 if (/* Case 2: Only one of S1 and S2 is Sword. */
5707 ((s1 == Sword) != (s2 == Sword))
5708 /* Case 3: Both of S1 and S2 are Sword, and macro
5709 WORD_BOUNDARY_P (C1, C2) returns nonzero. */
5710 || ((s1 == Sword) && WORD_BOUNDARY_P (c1, c2)))
5711 not = !not;
5712 }
5713 if (not)
5714 break;
5715 else
5716 goto fail;
5717
5718 case wordbeg:
5719 DEBUG_PRINT1 ("EXECUTING wordbeg.\n");
5720
5721 /* We FAIL in one of the following cases: */
5722
5723 /* Case 1: D is at the end of string. */
5724 if (AT_STRINGS_END (d))
5725 goto fail;
5726 else
5727 {
5728 /* C1 is the character before D, S1 is the syntax of C1, C2
5729 is the character at D, and S2 is the syntax of C2. */
5730 re_wchar_t c1, c2;
5731 int s1, s2;
5732#ifdef emacs
5733 int offset = PTR_TO_OFFSET (d);
5734 int charpos = SYNTAX_TABLE_BYTE_TO_CHAR (offset);
5735 UPDATE_SYNTAX_TABLE (charpos);
5736#endif
5737 PREFETCH ();
5738 c2 = RE_STRING_CHAR (d, dend - d);
5739 s2 = SYNTAX (c2);
5740
5741 /* Case 2: S2 is not Sword. */
5742 if (s2 != Sword)
5743 goto fail;
5744
5745 /* Case 3: D is not at the beginning of string ... */
5746 if (!AT_STRINGS_BEG (d))
5747 {
5748 GET_CHAR_BEFORE_2 (c1, d, string1, end1, string2, end2);
5749#ifdef emacs
5750 UPDATE_SYNTAX_TABLE_BACKWARD (charpos - 1);
5751#endif
5752 s1 = SYNTAX (c1);
5753
5754 /* ... and S1 is Sword, and WORD_BOUNDARY_P (C1, C2)
5755 returns 0. */
5756 if ((s1 == Sword) && !WORD_BOUNDARY_P (c1, c2))
5757 goto fail;
5758 }
5759 }
5760 break;
5761
5762 case wordend:
5763 DEBUG_PRINT1 ("EXECUTING wordend.\n");
5764
5765 /* We FAIL in one of the following cases: */
5766
5767 /* Case 1: D is at the beginning of string. */
5768 if (AT_STRINGS_BEG (d))
5769 goto fail;
5770 else
5771 {
5772 /* C1 is the character before D, S1 is the syntax of C1, C2
5773 is the character at D, and S2 is the syntax of C2. */
5774 re_wchar_t c1, c2;
5775 int s1, s2;
5776#ifdef emacs
5777 int offset = PTR_TO_OFFSET (d) - 1;
5778 int charpos = SYNTAX_TABLE_BYTE_TO_CHAR (offset);
5779 UPDATE_SYNTAX_TABLE (charpos);
5780#endif
5781 GET_CHAR_BEFORE_2 (c1, d, string1, end1, string2, end2);
5782 s1 = SYNTAX (c1);
5783
5784 /* Case 2: S1 is not Sword. */
5785 if (s1 != Sword)
5786 goto fail;
5787
5788 /* Case 3: D is not at the end of string ... */
5789 if (!AT_STRINGS_END (d))
5790 {
5791 PREFETCH_NOLIMIT ();
5792 c2 = RE_STRING_CHAR (d, dend - d);
5793#ifdef emacs
5794 UPDATE_SYNTAX_TABLE_FORWARD (charpos);
5795#endif
5796 s2 = SYNTAX (c2);
5797
5798 /* ... and S2 is Sword, and WORD_BOUNDARY_P (C1, C2)
5799 returns 0. */
5800 if ((s2 == Sword) && !WORD_BOUNDARY_P (c1, c2))
5801 goto fail;
5802 }
5803 }
5804 break;
5805
5806 case syntaxspec:
5807 case notsyntaxspec:
5808 not = (re_opcode_t) *(p - 1) == notsyntaxspec;
5809 mcnt = *p++;
5810 DEBUG_PRINT3 ("EXECUTING %ssyntaxspec %d.\n", not?"not":"", mcnt);
5811 PREFETCH ();
5812#ifdef emacs
5813 {
5814 int offset = PTR_TO_OFFSET (d);
5815 int pos1 = SYNTAX_TABLE_BYTE_TO_CHAR (offset);
5816 UPDATE_SYNTAX_TABLE (pos1);
5817 }
5818#endif
5819 {
5820 int len;
5821 re_wchar_t c;
5822
5823 c = RE_STRING_CHAR_AND_LENGTH (d, dend - d, len);
5824
5825 if ((SYNTAX (c) != (enum syntaxcode) mcnt) ^ not)
5826 goto fail;
5827 d += len;
5828 }
5829 break;
5830
5831#ifdef emacs
5832 case before_dot:
5833 DEBUG_PRINT1 ("EXECUTING before_dot.\n");
5834 if (PTR_BYTE_POS (d) >= PT_BYTE)
5835 goto fail;
5836 break;
5837
5838 case at_dot:
5839 DEBUG_PRINT1 ("EXECUTING at_dot.\n");
5840 if (PTR_BYTE_POS (d) != PT_BYTE)
5841 goto fail;
5842 break;
5843
5844 case after_dot:
5845 DEBUG_PRINT1 ("EXECUTING after_dot.\n");
5846 if (PTR_BYTE_POS (d) <= PT_BYTE)
5847 goto fail;
5848 break;
5849
5850 case categoryspec:
5851 case notcategoryspec:
5852 not = (re_opcode_t) *(p - 1) == notcategoryspec;
5853 mcnt = *p++;
5854 DEBUG_PRINT3 ("EXECUTING %scategoryspec %d.\n", not?"not":"", mcnt);
5855 PREFETCH ();
5856 {
5857 int len;
5858 re_wchar_t c;
5859
5860 c = RE_STRING_CHAR_AND_LENGTH (d, dend - d, len);
5861
5862 if ((!CHAR_HAS_CATEGORY (c, mcnt)) ^ not)
5863 goto fail;
5864 d += len;
5865 }
5866 break;
5867
5868#endif /* emacs */
5869
5870 default:
5871 abort ();
5872 }
5873 continue; /* Successfully executed one pattern command; keep going. */
5874
5875
5876 /* We goto here if a matching operation fails. */
5877 fail:
5878 IMMEDIATE_QUIT_CHECK;
5879 if (!FAIL_STACK_EMPTY ())
5880 {
5881 re_char *str, *pat;
5882 /* A restart point is known. Restore to that state. */
5883 DEBUG_PRINT1 ("\nFAIL:\n");
5884 POP_FAILURE_POINT (str, pat);
5885 switch (SWITCH_ENUM_CAST ((re_opcode_t) *pat++))
5886 {
5887 case on_failure_keep_string_jump:
5888 assert (str == NULL);
5889 goto continue_failure_jump;
5890
5891 case on_failure_jump_nastyloop:
5892 assert ((re_opcode_t)pat[-2] == no_op);
5893 PUSH_FAILURE_POINT (pat - 2, str);
5894 /* Fallthrough */
5895
5896 case on_failure_jump_loop:
5897 case on_failure_jump:
5898 case succeed_n:
5899 d = str;
5900 continue_failure_jump:
5901 EXTRACT_NUMBER_AND_INCR (mcnt, pat);
5902 p = pat + mcnt;
5903 break;
5904
5905 case no_op:
5906 /* A special frame used for nastyloops. */
5907 goto fail;
5908
5909 default:
5910 abort();
5911 }
5912
5913 assert (p >= bufp->buffer && p <= pend);
5914
5915 if (d >= string1 && d <= end1)
5916 dend = end_match_1;
5917 }
5918 else
5919 break; /* Matching at this starting point really fails. */
5920 } /* for (;;) */
5921
5922 if (best_regs_set)
5923 goto restore_best_regs;
5924
5925 FREE_VARIABLES ();
5926
5927 return -1; /* Failure to match. */
5928} /* re_match_2 */
5929
5930/* Subroutine definitions for re_match_2. */
5931
5932/* Return zero if TRANSLATE[S1] and TRANSLATE[S2] are identical for LEN
5933 bytes; nonzero otherwise. */
5934
5935static int
5936bcmp_translate (s1, s2, len, translate, multibyte)
5937 re_char *s1, *s2;
5938 register int len;
5939 RE_TRANSLATE_TYPE translate;
5940 const int multibyte;
5941{
5942 register re_char *p1 = s1, *p2 = s2;
5943 re_char *p1_end = s1 + len;
5944 re_char *p2_end = s2 + len;
5945
5946 /* FIXME: Checking both p1 and p2 presumes that the two strings might have
5947 different lengths, but relying on a single `len' would break this. -sm */
5948 while (p1 < p1_end && p2 < p2_end)
5949 {
5950 int p1_charlen, p2_charlen;
5951 re_wchar_t p1_ch, p2_ch;
5952
5953 p1_ch = RE_STRING_CHAR_AND_LENGTH (p1, p1_end - p1, p1_charlen);
5954 p2_ch = RE_STRING_CHAR_AND_LENGTH (p2, p2_end - p2, p2_charlen);
5955
5956 if (RE_TRANSLATE (translate, p1_ch)
5957 != RE_TRANSLATE (translate, p2_ch))
5958 return 1;
5959
5960 p1 += p1_charlen, p2 += p2_charlen;
5961 }
5962
5963 if (p1 != p1_end || p2 != p2_end)
5964 return 1;
5965
5966 return 0;
5967}
5968
5969/* Entry points for GNU code. */
5970
5971/* re_compile_pattern is the GNU regular expression compiler: it
5972 compiles PATTERN (of length SIZE) and puts the result in BUFP.
5973 Returns 0 if the pattern was valid, otherwise an error string.
5974
5975 Assumes the `allocated' (and perhaps `buffer') and `translate' fields
5976 are set in BUFP on entry.
5977
5978 We call regex_compile to do the actual compilation. */
5979
5980const char *
5981re_compile_pattern (pattern, length, bufp)
5982 const char *pattern;
5983 size_t length;
5984 struct re_pattern_buffer *bufp;
5985{
5986 reg_errcode_t ret;
5987
5988 /* GNU code is written to assume at least RE_NREGS registers will be set
5989 (and at least one extra will be -1). */
5990 bufp->regs_allocated = REGS_UNALLOCATED;
5991
5992 /* And GNU code determines whether or not to get register information
5993 by passing null for the REGS argument to re_match, etc., not by
5994 setting no_sub. */
5995 bufp->no_sub = 0;
5996
5997 ret = regex_compile ((re_char*) pattern, length, re_syntax_options, bufp);
5998
5999 if (!ret)
6000 return NULL;
6001 return gettext (re_error_msgid[(int) ret]);
6002}
6003WEAK_ALIAS (__re_compile_pattern, re_compile_pattern)
6004
6005/* Entry points compatible with 4.2 BSD regex library. We don't define
6006 them unless specifically requested. */
6007
6008#if defined _REGEX_RE_COMP || defined _LIBC
6009
6010/* BSD has one and only one pattern buffer. */
6011static struct re_pattern_buffer re_comp_buf;
6012
6013char *
6014# ifdef _LIBC
6015/* Make these definitions weak in libc, so POSIX programs can redefine
6016 these names if they don't use our functions, and still use
6017 regcomp/regexec below without link errors. */
6018weak_function
6019# endif
6020re_comp (s)
6021 const char *s;
6022{
6023 reg_errcode_t ret;
6024
6025 if (!s)
6026 {
6027 if (!re_comp_buf.buffer)
6028 /* Yes, we're discarding `const' here if !HAVE_LIBINTL. */
6029 return (char *) gettext ("No previous regular expression");
6030 return 0;
6031 }
6032
6033 if (!re_comp_buf.buffer)
6034 {
6035 re_comp_buf.buffer = (unsigned char *) malloc (200);
6036 if (re_comp_buf.buffer == NULL)
6037 /* Yes, we're discarding `const' here if !HAVE_LIBINTL. */
6038 return (char *) gettext (re_error_msgid[(int) REG_ESPACE]);
6039 re_comp_buf.allocated = 200;
6040
6041 re_comp_buf.fastmap = (char *) malloc (1 << BYTEWIDTH);
6042 if (re_comp_buf.fastmap == NULL)
6043 /* Yes, we're discarding `const' here if !HAVE_LIBINTL. */
6044 return (char *) gettext (re_error_msgid[(int) REG_ESPACE]);
6045 }
6046
6047 /* Since `re_exec' always passes NULL for the `regs' argument, we
6048 don't need to initialize the pattern buffer fields which affect it. */
6049
6050 ret = regex_compile (s, strlen (s), re_syntax_options, &re_comp_buf);
6051
6052 if (!ret)
6053 return NULL;
6054
6055 /* Yes, we're discarding `const' here if !HAVE_LIBINTL. */
6056 return (char *) gettext (re_error_msgid[(int) ret]);
6057}
6058
6059
6060int
6061# ifdef _LIBC
6062weak_function
6063# endif
6064re_exec (s)
6065 const char *s;
6066{
6067 const int len = strlen (s);
6068 return
6069 0 <= re_search (&re_comp_buf, s, len, 0, len, (struct re_registers *) 0);
6070}
6071#endif /* _REGEX_RE_COMP */
6072
6073/* POSIX.2 functions. Don't define these for Emacs. */
6074
6075#ifndef emacs
6076
6077/* regcomp takes a regular expression as a string and compiles it.
6078
6079 PREG is a regex_t *. We do not expect any fields to be initialized,
6080 since POSIX says we shouldn't. Thus, we set
6081
6082 `buffer' to the compiled pattern;
6083 `used' to the length of the compiled pattern;
6084 `syntax' to RE_SYNTAX_POSIX_EXTENDED if the
6085 REG_EXTENDED bit in CFLAGS is set; otherwise, to
6086 RE_SYNTAX_POSIX_BASIC;
6087 `fastmap' to an allocated space for the fastmap;
6088 `fastmap_accurate' to zero;
6089 `re_nsub' to the number of subexpressions in PATTERN.
6090
6091 PATTERN is the address of the pattern string.
6092
6093 CFLAGS is a series of bits which affect compilation.
6094
6095 If REG_EXTENDED is set, we use POSIX extended syntax; otherwise, we
6096 use POSIX basic syntax.
6097
6098 If REG_NEWLINE is set, then . and [^...] don't match newline.
6099 Also, regexec will try a match beginning after every newline.
6100
6101 If REG_ICASE is set, then we considers upper- and lowercase
6102 versions of letters to be equivalent when matching.
6103
6104 If REG_NOSUB is set, then when PREG is passed to regexec, that
6105 routine will report only success or failure, and nothing about the
6106 registers.
6107
6108 It returns 0 if it succeeds, nonzero if it doesn't. (See regex.h for
6109 the return codes and their meanings.) */
6110
6111int
6112regcomp (preg, pattern, cflags)
6113 regex_t *__restrict preg;
6114 const char *__restrict pattern;
6115 int cflags;
6116{
6117 reg_errcode_t ret;
6118 reg_syntax_t syntax
6119 = (cflags & REG_EXTENDED) ?
6120 RE_SYNTAX_POSIX_EXTENDED : RE_SYNTAX_POSIX_BASIC;
6121
6122 /* regex_compile will allocate the space for the compiled pattern. */
6123 preg->buffer = 0;
6124 preg->allocated = 0;
6125 preg->used = 0;
6126
6127 /* Try to allocate space for the fastmap. */
6128 preg->fastmap = (char *) malloc (1 << BYTEWIDTH);
6129
6130 if (cflags & REG_ICASE)
6131 {
6132 unsigned i;
6133
6134 preg->translate
6135 = (RE_TRANSLATE_TYPE) malloc (CHAR_SET_SIZE
6136 * sizeof (*(RE_TRANSLATE_TYPE)0));
6137 if (preg->translate == NULL)
6138 return (int) REG_ESPACE;
6139
6140 /* Map uppercase characters to corresponding lowercase ones. */
6141 for (i = 0; i < CHAR_SET_SIZE; i++)
6142 preg->translate[i] = ISUPPER (i) ? TOLOWER (i) : i;
6143 }
6144 else
6145 preg->translate = NULL;
6146
6147 /* If REG_NEWLINE is set, newlines are treated differently. */
6148 if (cflags & REG_NEWLINE)
6149 { /* REG_NEWLINE implies neither . nor [^...] match newline. */
6150 syntax &= ~RE_DOT_NEWLINE;
6151 syntax |= RE_HAT_LISTS_NOT_NEWLINE;
6152 }
6153 else
6154 syntax |= RE_NO_NEWLINE_ANCHOR;
6155
6156 preg->no_sub = !!(cflags & REG_NOSUB);
6157
6158 /* POSIX says a null character in the pattern terminates it, so we
6159 can use strlen here in compiling the pattern. */
6160 ret = regex_compile ((re_char*) pattern, strlen (pattern), syntax, preg);
6161
6162 /* POSIX doesn't distinguish between an unmatched open-group and an
6163 unmatched close-group: both are REG_EPAREN. */
6164 if (ret == REG_ERPAREN)
6165 ret = REG_EPAREN;
6166
6167 if (ret == REG_NOERROR && preg->fastmap)
6168 { /* Compute the fastmap now, since regexec cannot modify the pattern
6169 buffer. */
6170 re_compile_fastmap (preg);
6171 if (preg->can_be_null)
6172 { /* The fastmap can't be used anyway. */
6173 free (preg->fastmap);
6174 preg->fastmap = NULL;
6175 }
6176 }
6177 return (int) ret;
6178}
6179WEAK_ALIAS (__regcomp, regcomp)
6180
6181
6182/* regexec searches for a given pattern, specified by PREG, in the
6183 string STRING.
6184
6185 If NMATCH is zero or REG_NOSUB was set in the cflags argument to
6186 `regcomp', we ignore PMATCH. Otherwise, we assume PMATCH has at
6187 least NMATCH elements, and we set them to the offsets of the
6188 corresponding matched substrings.
6189
6190 EFLAGS specifies `execution flags' which affect matching: if
6191 REG_NOTBOL is set, then ^ does not match at the beginning of the
6192 string; if REG_NOTEOL is set, then $ does not match at the end.
6193
6194 We return 0 if we find a match and REG_NOMATCH if not. */
6195
6196int
6197regexec (preg, string, nmatch, pmatch, eflags)
6198 const regex_t *__restrict preg;
6199 const char *__restrict string;
6200 size_t nmatch;
6201 regmatch_t pmatch[__restrict_arr];
6202 int eflags;
6203{
6204 int ret;
6205 struct re_registers regs;
6206 regex_t private_preg;
6207 int len = strlen (string);
6208 boolean want_reg_info = !preg->no_sub && nmatch > 0 && pmatch;
6209
6210 private_preg = *preg;
6211
6212 private_preg.not_bol = !!(eflags & REG_NOTBOL);
6213 private_preg.not_eol = !!(eflags & REG_NOTEOL);
6214
6215 /* The user has told us exactly how many registers to return
6216 information about, via `nmatch'. We have to pass that on to the
6217 matching routines. */
6218 private_preg.regs_allocated = REGS_FIXED;
6219
6220 if (want_reg_info)
6221 {
6222 regs.num_regs = nmatch;
6223 regs.start = TALLOC (nmatch * 2, regoff_t);
6224 if (regs.start == NULL)
6225 return (int) REG_NOMATCH;
6226 regs.end = regs.start + nmatch;
6227 }
6228
6229 /* Instead of using not_eol to implement REG_NOTEOL, we could simply
6230 pass (&private_preg, string, len + 1, 0, len, ...) pretending the string
6231 was a little bit longer but still only matching the real part.
6232 This works because the `endline' will check for a '\n' and will find a
6233 '\0', correctly deciding that this is not the end of a line.
6234 But it doesn't work out so nicely for REG_NOTBOL, since we don't have
6235 a convenient '\0' there. For all we know, the string could be preceded
6236 by '\n' which would throw things off. */
6237
6238 /* Perform the searching operation. */
6239 ret = re_search (&private_preg, string, len,
6240 /* start: */ 0, /* range: */ len,
6241 want_reg_info ? &regs : (struct re_registers *) 0);
6242
6243 /* Copy the register information to the POSIX structure. */
6244 if (want_reg_info)
6245 {
6246 if (ret >= 0)
6247 {
6248 unsigned r;
6249
6250 for (r = 0; r < nmatch; r++)
6251 {
6252 pmatch[r].rm_so = regs.start[r];
6253 pmatch[r].rm_eo = regs.end[r];
6254 }
6255 }
6256
6257 /* If we needed the temporary register info, free the space now. */
6258 free (regs.start);
6259 }
6260
6261 /* We want zero return to mean success, unlike `re_search'. */
6262 return ret >= 0 ? (int) REG_NOERROR : (int) REG_NOMATCH;
6263}
6264WEAK_ALIAS (__regexec, regexec)
6265
6266
6267/* Returns a message corresponding to an error code, ERRCODE, returned
6268 from either regcomp or regexec. We don't use PREG here. */
6269
6270size_t
6271regerror (errcode, preg, errbuf, errbuf_size)
6272 int errcode;
6273 const regex_t *preg;
6274 char *errbuf;
6275 size_t errbuf_size;
6276{
6277 const char *msg;
6278 size_t msg_size;
6279
6280 if (errcode < 0
6281 || errcode >= (sizeof (re_error_msgid) / sizeof (re_error_msgid[0])))
6282 /* Only error codes returned by the rest of the code should be passed
6283 to this routine. If we are given anything else, or if other regex
6284 code generates an invalid error code, then the program has a bug.
6285 Dump core so we can fix it. */
6286 abort ();
6287
6288 msg = gettext (re_error_msgid[errcode]);
6289
6290 msg_size = strlen (msg) + 1; /* Includes the null. */
6291
6292 if (errbuf_size != 0)
6293 {
6294 if (msg_size > errbuf_size)
6295 {
6296 strncpy (errbuf, msg, errbuf_size - 1);
6297 errbuf[errbuf_size - 1] = 0;
6298 }
6299 else
6300 strcpy (errbuf, msg);
6301 }
6302
6303 return msg_size;
6304}
6305WEAK_ALIAS (__regerror, regerror)
6306
6307
6308/* Free dynamically allocated space used by PREG. */
6309
6310void
6311regfree (preg)
6312 regex_t *preg;
6313{
6314 if (preg->buffer != NULL)
6315 free (preg->buffer);
6316 preg->buffer = NULL;
6317
6318 preg->allocated = 0;
6319 preg->used = 0;
6320
6321 if (preg->fastmap != NULL)
6322 free (preg->fastmap);
6323 preg->fastmap = NULL;
6324 preg->fastmap_accurate = 0;
6325
6326 if (preg->translate != NULL)
6327 free (preg->translate);
6328 preg->translate = NULL;
6329}
6330WEAK_ALIAS (__regfree, regfree)
6331
6332#endif /* not emacs */
6333
6334/* arch-tag: 4ffd68ba-2a9e-435b-a21a-018990f9eeb2
6335 (do not change this comment) */
diff --git a/src/regex.h b/src/regex.h
new file mode 100644
index 00000000000..1818d5f9681
--- /dev/null
+++ b/src/regex.h
@@ -0,0 +1,576 @@
1/* Definitions for data structures and routines for the regular
2 expression library, version 0.12.
3
4 Copyright (C) 1985,89,90,91,92,93,95,2000 Free Software Foundation, Inc.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 USA. */
20
21#ifndef _REGEX_H
22#define _REGEX_H 1
23
24/* Allow the use in C++ code. */
25#ifdef __cplusplus
26extern "C" {
27#endif
28
29/* POSIX says that <sys/types.h> must be included (by the caller) before
30 <regex.h>. */
31
32#if !defined _POSIX_C_SOURCE && !defined _POSIX_SOURCE && defined VMS
33/* VMS doesn't have `size_t' in <sys/types.h>, even though POSIX says it
34 should be there. */
35# include <stddef.h>
36#endif
37
38/* The following bits are used to determine the regexp syntax we
39 recognize. The set/not-set meanings where historically chosen so
40 that Emacs syntax had the value 0.
41 The bits are given in alphabetical order, and
42 the definitions shifted by one from the previous bit; thus, when we
43 add or remove a bit, only one other definition need change. */
44typedef unsigned long int reg_syntax_t;
45
46/* If this bit is not set, then \ inside a bracket expression is literal.
47 If set, then such a \ quotes the following character. */
48#define RE_BACKSLASH_ESCAPE_IN_LISTS ((unsigned long int) 1)
49
50/* If this bit is not set, then + and ? are operators, and \+ and \? are
51 literals.
52 If set, then \+ and \? are operators and + and ? are literals. */
53#define RE_BK_PLUS_QM (RE_BACKSLASH_ESCAPE_IN_LISTS << 1)
54
55/* If this bit is set, then character classes are supported. They are:
56 [:alpha:], [:upper:], [:lower:], [:digit:], [:alnum:], [:xdigit:],
57 [:space:], [:print:], [:punct:], [:graph:], and [:cntrl:].
58 If not set, then character classes are not supported. */
59#define RE_CHAR_CLASSES (RE_BK_PLUS_QM << 1)
60
61/* If this bit is set, then ^ and $ are always anchors (outside bracket
62 expressions, of course).
63 If this bit is not set, then it depends:
64 ^ is an anchor if it is at the beginning of a regular
65 expression or after an open-group or an alternation operator;
66 $ is an anchor if it is at the end of a regular expression, or
67 before a close-group or an alternation operator.
68
69 This bit could be (re)combined with RE_CONTEXT_INDEP_OPS, because
70 POSIX draft 11.2 says that * etc. in leading positions is undefined.
71 We already implemented a previous draft which made those constructs
72 invalid, though, so we haven't changed the code back. */
73#define RE_CONTEXT_INDEP_ANCHORS (RE_CHAR_CLASSES << 1)
74
75/* If this bit is set, then special characters are always special
76 regardless of where they are in the pattern.
77 If this bit is not set, then special characters are special only in
78 some contexts; otherwise they are ordinary. Specifically,
79 * + ? and intervals are only special when not after the beginning,
80 open-group, or alternation operator. */
81#define RE_CONTEXT_INDEP_OPS (RE_CONTEXT_INDEP_ANCHORS << 1)
82
83/* If this bit is set, then *, +, ?, and { cannot be first in an re or
84 immediately after an alternation or begin-group operator. */
85#define RE_CONTEXT_INVALID_OPS (RE_CONTEXT_INDEP_OPS << 1)
86
87/* If this bit is set, then . matches newline.
88 If not set, then it doesn't. */
89#define RE_DOT_NEWLINE (RE_CONTEXT_INVALID_OPS << 1)
90
91/* If this bit is set, then . doesn't match NUL.
92 If not set, then it does. */
93#define RE_DOT_NOT_NULL (RE_DOT_NEWLINE << 1)
94
95/* If this bit is set, nonmatching lists [^...] do not match newline.
96 If not set, they do. */
97#define RE_HAT_LISTS_NOT_NEWLINE (RE_DOT_NOT_NULL << 1)
98
99/* If this bit is set, either \{...\} or {...} defines an
100 interval, depending on RE_NO_BK_BRACES.
101 If not set, \{, \}, {, and } are literals. */
102#define RE_INTERVALS (RE_HAT_LISTS_NOT_NEWLINE << 1)
103
104/* If this bit is set, +, ? and | aren't recognized as operators.
105 If not set, they are. */
106#define RE_LIMITED_OPS (RE_INTERVALS << 1)
107
108/* If this bit is set, newline is an alternation operator.
109 If not set, newline is literal. */
110#define RE_NEWLINE_ALT (RE_LIMITED_OPS << 1)
111
112/* If this bit is set, then `{...}' defines an interval, and \{ and \}
113 are literals.
114 If not set, then `\{...\}' defines an interval. */
115#define RE_NO_BK_BRACES (RE_NEWLINE_ALT << 1)
116
117/* If this bit is set, (...) defines a group, and \( and \) are literals.
118 If not set, \(...\) defines a group, and ( and ) are literals. */
119#define RE_NO_BK_PARENS (RE_NO_BK_BRACES << 1)
120
121/* If this bit is set, then \<digit> matches <digit>.
122 If not set, then \<digit> is a back-reference. */
123#define RE_NO_BK_REFS (RE_NO_BK_PARENS << 1)
124
125/* If this bit is set, then | is an alternation operator, and \| is literal.
126 If not set, then \| is an alternation operator, and | is literal. */
127#define RE_NO_BK_VBAR (RE_NO_BK_REFS << 1)
128
129/* If this bit is set, then an ending range point collating higher
130 than the starting range point, as in [z-a], is invalid.
131 If not set, then when ending range point collates higher than the
132 starting range point, the range is ignored. */
133#define RE_NO_EMPTY_RANGES (RE_NO_BK_VBAR << 1)
134
135/* If this bit is set, then an unmatched ) is ordinary.
136 If not set, then an unmatched ) is invalid. */
137#define RE_UNMATCHED_RIGHT_PAREN_ORD (RE_NO_EMPTY_RANGES << 1)
138
139/* If this bit is set, succeed as soon as we match the whole pattern,
140 without further backtracking. */
141#define RE_NO_POSIX_BACKTRACKING (RE_UNMATCHED_RIGHT_PAREN_ORD << 1)
142
143/* If this bit is set, do not process the GNU regex operators.
144 If not set, then the GNU regex operators are recognized. */
145#define RE_NO_GNU_OPS (RE_NO_POSIX_BACKTRACKING << 1)
146
147/* If this bit is set, then *?, +? and ?? match non greedily. */
148#define RE_FRUGAL (RE_NO_GNU_OPS << 1)
149
150/* If this bit is set, then (?:...) is treated as a shy group. */
151#define RE_SHY_GROUPS (RE_FRUGAL << 1)
152
153/* If this bit is set, ^ and $ only match at beg/end of buffer. */
154#define RE_NO_NEWLINE_ANCHOR (RE_SHY_GROUPS << 1)
155
156/* If this bit is set, turn on internal regex debugging.
157 If not set, and debugging was on, turn it off.
158 This only works if regex.c is compiled -DDEBUG.
159 We define this bit always, so that all that's needed to turn on
160 debugging is to recompile regex.c; the calling code can always have
161 this bit set, and it won't affect anything in the normal case. */
162#define RE_DEBUG (RE_NO_NEWLINE_ANCHOR << 1)
163
164/* This global variable defines the particular regexp syntax to use (for
165 some interfaces). When a regexp is compiled, the syntax used is
166 stored in the pattern buffer, so changing this does not affect
167 already-compiled regexps. */
168extern reg_syntax_t re_syntax_options;
169
170#ifdef emacs
171/* In Emacs, this is the string or buffer in which we
172 are matching. It is used for looking up syntax properties. */
173extern Lisp_Object re_match_object;
174#endif
175
176
177/* Define combinations of the above bits for the standard possibilities.
178 (The [[[ comments delimit what gets put into the Texinfo file, so
179 don't delete them!) */
180/* [[[begin syntaxes]]] */
181#define RE_SYNTAX_EMACS \
182 (RE_CHAR_CLASSES | RE_INTERVALS | RE_SHY_GROUPS | RE_FRUGAL)
183
184#define RE_SYNTAX_AWK \
185 (RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DOT_NOT_NULL \
186 | RE_NO_BK_PARENS | RE_NO_BK_REFS \
187 | RE_NO_BK_VBAR | RE_NO_EMPTY_RANGES \
188 | RE_DOT_NEWLINE | RE_CONTEXT_INDEP_ANCHORS \
189 | RE_UNMATCHED_RIGHT_PAREN_ORD | RE_NO_GNU_OPS)
190
191#define RE_SYNTAX_GNU_AWK \
192 ((RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DEBUG) \
193 & ~(RE_DOT_NOT_NULL | RE_INTERVALS | RE_CONTEXT_INDEP_OPS))
194
195#define RE_SYNTAX_POSIX_AWK \
196 (RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS \
197 | RE_INTERVALS | RE_NO_GNU_OPS)
198
199#define RE_SYNTAX_GREP \
200 (RE_BK_PLUS_QM | RE_CHAR_CLASSES \
201 | RE_HAT_LISTS_NOT_NEWLINE | RE_INTERVALS \
202 | RE_NEWLINE_ALT)
203
204#define RE_SYNTAX_EGREP \
205 (RE_CHAR_CLASSES | RE_CONTEXT_INDEP_ANCHORS \
206 | RE_CONTEXT_INDEP_OPS | RE_HAT_LISTS_NOT_NEWLINE \
207 | RE_NEWLINE_ALT | RE_NO_BK_PARENS \
208 | RE_NO_BK_VBAR)
209
210#define RE_SYNTAX_POSIX_EGREP \
211 (RE_SYNTAX_EGREP | RE_INTERVALS | RE_NO_BK_BRACES)
212
213/* P1003.2/D11.2, section 4.20.7.1, lines 5078ff. */
214#define RE_SYNTAX_ED RE_SYNTAX_POSIX_BASIC
215
216#define RE_SYNTAX_SED RE_SYNTAX_POSIX_BASIC
217
218/* Syntax bits common to both basic and extended POSIX regex syntax. */
219#define _RE_SYNTAX_POSIX_COMMON \
220 (RE_CHAR_CLASSES | RE_DOT_NEWLINE | RE_DOT_NOT_NULL \
221 | RE_INTERVALS | RE_NO_EMPTY_RANGES)
222
223#define RE_SYNTAX_POSIX_BASIC \
224 (_RE_SYNTAX_POSIX_COMMON | RE_BK_PLUS_QM)
225
226/* Differs from ..._POSIX_BASIC only in that RE_BK_PLUS_QM becomes
227 RE_LIMITED_OPS, i.e., \? \+ \| are not recognized. Actually, this
228 isn't minimal, since other operators, such as \`, aren't disabled. */
229#define RE_SYNTAX_POSIX_MINIMAL_BASIC \
230 (_RE_SYNTAX_POSIX_COMMON | RE_LIMITED_OPS)
231
232#define RE_SYNTAX_POSIX_EXTENDED \
233 (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \
234 | RE_CONTEXT_INDEP_OPS | RE_NO_BK_BRACES \
235 | RE_NO_BK_PARENS | RE_NO_BK_VBAR \
236 | RE_CONTEXT_INVALID_OPS | RE_UNMATCHED_RIGHT_PAREN_ORD)
237
238/* Differs from ..._POSIX_EXTENDED in that RE_CONTEXT_INDEP_OPS is
239 removed and RE_NO_BK_REFS is added. */
240#define RE_SYNTAX_POSIX_MINIMAL_EXTENDED \
241 (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \
242 | RE_CONTEXT_INVALID_OPS | RE_NO_BK_BRACES \
243 | RE_NO_BK_PARENS | RE_NO_BK_REFS \
244 | RE_NO_BK_VBAR | RE_UNMATCHED_RIGHT_PAREN_ORD)
245/* [[[end syntaxes]]] */
246
247/* Maximum number of duplicates an interval can allow. Some systems
248 (erroneously) define this in other header files, but we want our
249 value, so remove any previous define. */
250#ifdef RE_DUP_MAX
251# undef RE_DUP_MAX
252#endif
253/* If sizeof(int) == 2, then ((1 << 15) - 1) overflows. */
254#define RE_DUP_MAX (0x7fff)
255
256
257/* POSIX `cflags' bits (i.e., information for `regcomp'). */
258
259/* If this bit is set, then use extended regular expression syntax.
260 If not set, then use basic regular expression syntax. */
261#define REG_EXTENDED 1
262
263/* If this bit is set, then ignore case when matching.
264 If not set, then case is significant. */
265#define REG_ICASE (REG_EXTENDED << 1)
266
267/* If this bit is set, then anchors do not match at newline
268 characters in the string.
269 If not set, then anchors do match at newlines. */
270#define REG_NEWLINE (REG_ICASE << 1)
271
272/* If this bit is set, then report only success or fail in regexec.
273 If not set, then returns differ between not matching and errors. */
274#define REG_NOSUB (REG_NEWLINE << 1)
275
276
277/* POSIX `eflags' bits (i.e., information for regexec). */
278
279/* If this bit is set, then the beginning-of-line operator doesn't match
280 the beginning of the string (presumably because it's not the
281 beginning of a line).
282 If not set, then the beginning-of-line operator does match the
283 beginning of the string. */
284#define REG_NOTBOL 1
285
286/* Like REG_NOTBOL, except for the end-of-line. */
287#define REG_NOTEOL (1 << 1)
288
289
290/* If any error codes are removed, changed, or added, update the
291 `re_error_msg' table in regex.c. */
292typedef enum
293{
294#ifdef _XOPEN_SOURCE
295 REG_ENOSYS = -1, /* This will never happen for this implementation. */
296#endif
297
298 REG_NOERROR = 0, /* Success. */
299 REG_NOMATCH, /* Didn't find a match (for regexec). */
300
301 /* POSIX regcomp return error codes. (In the order listed in the
302 standard.) */
303 REG_BADPAT, /* Invalid pattern. */
304 REG_ECOLLATE, /* Not implemented. */
305 REG_ECTYPE, /* Invalid character class name. */
306 REG_EESCAPE, /* Trailing backslash. */
307 REG_ESUBREG, /* Invalid back reference. */
308 REG_EBRACK, /* Unmatched left bracket. */
309 REG_EPAREN, /* Parenthesis imbalance. */
310 REG_EBRACE, /* Unmatched \{. */
311 REG_BADBR, /* Invalid contents of \{\}. */
312 REG_ERANGE, /* Invalid range end. */
313 REG_ESPACE, /* Ran out of memory. */
314 REG_BADRPT, /* No preceding re for repetition op. */
315
316 /* Error codes we've added. */
317 REG_EEND, /* Premature end. */
318 REG_ESIZE, /* Compiled pattern bigger than 2^16 bytes. */
319 REG_ERPAREN /* Unmatched ) or \); not returned from regcomp. */
320} reg_errcode_t;
321
322/* This data structure represents a compiled pattern. Before calling
323 the pattern compiler, the fields `buffer', `allocated', `fastmap',
324 `translate', and `no_sub' can be set. After the pattern has been
325 compiled, the `re_nsub' field is available. All other fields are
326 private to the regex routines. */
327
328#ifndef RE_TRANSLATE_TYPE
329# define RE_TRANSLATE_TYPE char *
330#endif
331
332struct re_pattern_buffer
333{
334/* [[[begin pattern_buffer]]] */
335 /* Space that holds the compiled pattern. It is declared as
336 `unsigned char *' because its elements are
337 sometimes used as array indexes. */
338 unsigned char *buffer;
339
340 /* Number of bytes to which `buffer' points. */
341 size_t allocated;
342
343 /* Number of bytes actually used in `buffer'. */
344 size_t used;
345
346 /* Syntax setting with which the pattern was compiled. */
347 reg_syntax_t syntax;
348
349 /* Pointer to a fastmap, if any, otherwise zero. re_search uses
350 the fastmap, if there is one, to skip over impossible
351 starting points for matches. */
352 char *fastmap;
353
354 /* Either a translate table to apply to all characters before
355 comparing them, or zero for no translation. The translation
356 is applied to a pattern when it is compiled and to a string
357 when it is matched. */
358 RE_TRANSLATE_TYPE translate;
359
360 /* Number of subexpressions found by the compiler. */
361 size_t re_nsub;
362
363 /* Zero if this pattern cannot match the empty string, one else.
364 Well, in truth it's used only in `re_search_2', to see
365 whether or not we should use the fastmap, so we don't set
366 this absolutely perfectly; see `re_compile_fastmap'. */
367 unsigned can_be_null : 1;
368
369 /* If REGS_UNALLOCATED, allocate space in the `regs' structure
370 for `max (RE_NREGS, re_nsub + 1)' groups.
371 If REGS_REALLOCATE, reallocate space if necessary.
372 If REGS_FIXED, use what's there. */
373#define REGS_UNALLOCATED 0
374#define REGS_REALLOCATE 1
375#define REGS_FIXED 2
376 unsigned regs_allocated : 2;
377
378 /* Set to zero when `regex_compile' compiles a pattern; set to one
379 by `re_compile_fastmap' if it updates the fastmap. */
380 unsigned fastmap_accurate : 1;
381
382 /* If set, `re_match_2' does not return information about
383 subexpressions. */
384 unsigned no_sub : 1;
385
386 /* If set, a beginning-of-line anchor doesn't match at the
387 beginning of the string. */
388 unsigned not_bol : 1;
389
390 /* Similarly for an end-of-line anchor. */
391 unsigned not_eol : 1;
392
393#ifdef emacs
394 /* If true, multi-byte form in the `buffer' should be recognized as a
395 multibyte character. */
396 unsigned multibyte : 1;
397#endif
398
399/* [[[end pattern_buffer]]] */
400};
401
402typedef struct re_pattern_buffer regex_t;
403
404/* Type for byte offsets within the string. POSIX mandates this. */
405typedef int regoff_t;
406
407
408/* This is the structure we store register match data in. See
409 regex.texinfo for a full description of what registers match. */
410struct re_registers
411{
412 unsigned num_regs;
413 regoff_t *start;
414 regoff_t *end;
415};
416
417
418/* If `regs_allocated' is REGS_UNALLOCATED in the pattern buffer,
419 `re_match_2' returns information about at least this many registers
420 the first time a `regs' structure is passed. */
421#ifndef RE_NREGS
422# define RE_NREGS 30
423#endif
424
425
426/* POSIX specification for registers. Aside from the different names than
427 `re_registers', POSIX uses an array of structures, instead of a
428 structure of arrays. */
429typedef struct
430{
431 regoff_t rm_so; /* Byte offset from string's start to substring's start. */
432 regoff_t rm_eo; /* Byte offset from string's start to substring's end. */
433} regmatch_t;
434
435/* Declarations for routines. */
436
437/* To avoid duplicating every routine declaration -- once with a
438 prototype (if we are ANSI), and once without (if we aren't) -- we
439 use the following macro to declare argument types. This
440 unfortunately clutters up the declarations a bit, but I think it's
441 worth it. */
442
443#if defined __STDC__ || defined PROTOTYPES
444
445# define _RE_ARGS(args) args
446
447#else /* not __STDC__ || PROTOTYPES */
448
449# define _RE_ARGS(args) ()
450
451#endif /* not __STDC__ || PROTOTYPES */
452
453/* Sets the current default syntax to SYNTAX, and return the old syntax.
454 You can also simply assign to the `re_syntax_options' variable. */
455extern reg_syntax_t re_set_syntax _RE_ARGS ((reg_syntax_t syntax));
456
457/* Compile the regular expression PATTERN, with length LENGTH
458 and syntax given by the global `re_syntax_options', into the buffer
459 BUFFER. Return NULL if successful, and an error string if not. */
460extern const char *re_compile_pattern
461 _RE_ARGS ((const char *pattern, size_t length,
462 struct re_pattern_buffer *buffer));
463
464
465/* Compile a fastmap for the compiled pattern in BUFFER; used to
466 accelerate searches. Return 0 if successful and -2 if was an
467 internal error. */
468extern int re_compile_fastmap _RE_ARGS ((struct re_pattern_buffer *buffer));
469
470
471/* Search in the string STRING (with length LENGTH) for the pattern
472 compiled into BUFFER. Start searching at position START, for RANGE
473 characters. Return the starting position of the match, -1 for no
474 match, or -2 for an internal error. Also return register
475 information in REGS (if REGS and BUFFER->no_sub are nonzero). */
476extern int re_search
477 _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string,
478 int length, int start, int range, struct re_registers *regs));
479
480
481/* Like `re_search', but search in the concatenation of STRING1 and
482 STRING2. Also, stop searching at index START + STOP. */
483extern int re_search_2
484 _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string1,
485 int length1, const char *string2, int length2,
486 int start, int range, struct re_registers *regs, int stop));
487
488
489/* Like `re_search', but return how many characters in STRING the regexp
490 in BUFFER matched, starting at position START. */
491extern int re_match
492 _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string,
493 int length, int start, struct re_registers *regs));
494
495
496/* Relates to `re_match' as `re_search_2' relates to `re_search'. */
497extern int re_match_2
498 _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string1,
499 int length1, const char *string2, int length2,
500 int start, struct re_registers *regs, int stop));
501
502
503/* Set REGS to hold NUM_REGS registers, storing them in STARTS and
504 ENDS. Subsequent matches using BUFFER and REGS will use this memory
505 for recording register information. STARTS and ENDS must be
506 allocated with malloc, and must each be at least `NUM_REGS * sizeof
507 (regoff_t)' bytes long.
508
509 If NUM_REGS == 0, then subsequent matches should allocate their own
510 register data.
511
512 Unless this function is called, the first search or match using
513 PATTERN_BUFFER will allocate its own register data, without
514 freeing the old data. */
515extern void re_set_registers
516 _RE_ARGS ((struct re_pattern_buffer *buffer, struct re_registers *regs,
517 unsigned num_regs, regoff_t *starts, regoff_t *ends));
518
519#if defined _REGEX_RE_COMP || defined _LIBC
520# ifndef _CRAY
521/* 4.2 bsd compatibility. */
522extern char *re_comp _RE_ARGS ((const char *));
523extern int re_exec _RE_ARGS ((const char *));
524# endif
525#endif
526
527/* GCC 2.95 and later have "__restrict"; C99 compilers have
528 "restrict", and "configure" may have defined "restrict". */
529#ifndef __restrict
530# if ! (2 < __GNUC__ || (2 == __GNUC__ && 95 <= __GNUC_MINOR__))
531# if defined restrict || 199901L <= __STDC_VERSION__
532# define __restrict restrict
533# else
534# define __restrict
535# endif
536# endif
537#endif
538/* For now conditionally define __restrict_arr to expand to nothing.
539 Ideally we would have a test for the compiler which allows defining
540 it to restrict. */
541#ifndef __restrict_arr
542# define __restrict_arr
543#endif
544
545/* POSIX compatibility. */
546extern int regcomp _RE_ARGS ((regex_t *__restrict __preg,
547 const char *__restrict __pattern,
548 int __cflags));
549
550extern int regexec _RE_ARGS ((const regex_t *__restrict __preg,
551 const char *__restrict __string, size_t __nmatch,
552 regmatch_t __pmatch[__restrict_arr],
553 int __eflags));
554
555extern size_t regerror _RE_ARGS ((int __errcode, const regex_t *__preg,
556 char *__errbuf, size_t __errbuf_size));
557
558extern void regfree _RE_ARGS ((regex_t *__preg));
559
560
561#ifdef __cplusplus
562}
563#endif /* C++ */
564
565#endif /* regex.h */
566
567/*
568Local variables:
569make-backup-files: t
570version-control: t
571trim-versions-without-asking: nil
572End:
573*/
574
575/* arch-tag: bda6e3ec-3c02-4237-a55a-01ad2e120083
576 (do not change this comment) */
diff --git a/src/termcap.c b/src/termcap.c
index b1e0a87936e..a1c068e0964 100644
--- a/src/termcap.c
+++ b/src/termcap.c
@@ -284,6 +284,52 @@ tgetst1 (ptr, area)
284 } 284 }
285 *r++ = c; 285 *r++ = c;
286 } 286 }
287
288 /* Sometimes entries have "%pN" which means use parameter N in the
289 next %-substitution. If all such N are continuous in the range
290 [1,9] we can remove each "%pN" because they are redundant, thus
291 reducing bandwidth requirements. True, Emacs is well beyond the
292 days of 150baud teletypes, but some of its users aren't much so.
293
294 This pass could probably be integrated into the one above but
295 abbreviation expansion makes that effort a little more hairy than
296 its worth; this is cleaner. */
297 {
298 register int last_p_param = 0;
299 int remove_p_params = 1;
300 struct { char *beg; int len; } cut[11];
301
302 for (cut[0].beg = p = ret; p < r - 3; p++)
303 {
304 if (!remove_p_params)
305 break;
306 if (*p == '%' && *(p + 1) == 'p')
307 {
308 if (*(p + 2) - '0' == 1 + last_p_param)
309 {
310 cut[last_p_param].len = p - cut[last_p_param].beg;
311 last_p_param++;
312 p += 3;
313 cut[last_p_param].beg = p;
314 }
315 else /* not continuous: bail */
316 remove_p_params = 0;
317 if (last_p_param > 10) /* too many: bail */
318 remove_p_params = 0;
319 }
320 }
321 if (remove_p_params && last_p_param)
322 {
323 register int i;
324 char *wp;
325
326 cut[last_p_param].len = r - cut[last_p_param].beg;
327 for (i = 0, wp = ret; i <= last_p_param; wp += cut[i++].len)
328 bcopy (cut[i].beg, wp, cut[i].len);
329 r = wp;
330 }
331 }
332
287 *r = '\0'; 333 *r = '\0';
288 /* Update *AREA. */ 334 /* Update *AREA. */
289 if (area) 335 if (area)
diff --git a/src/w32fns.c b/src/w32fns.c
index d8572265bef..7bffea34a28 100644
--- a/src/w32fns.c
+++ b/src/w32fns.c
@@ -6937,11 +6937,6 @@ DEFUN ("x-synchronize", Fx_synchronize, Sx_synchronize, 1, 2, 0,
6937 6937
6938static struct image_type *image_types; 6938static struct image_type *image_types;
6939 6939
6940/* The symbol `image' which is the car of the lists used to represent
6941 images in Lisp. */
6942
6943extern Lisp_Object Qimage;
6944
6945/* The symbol `xbm' which is used as the type symbol for XBM images. */ 6940/* The symbol `xbm' which is used as the type symbol for XBM images. */
6946 6941
6947Lisp_Object Qxbm; 6942Lisp_Object Qxbm;
@@ -7021,7 +7016,7 @@ valid_image_p (object)
7021{ 7016{
7022 int valid_p = 0; 7017 int valid_p = 0;
7023 7018
7024 if (CONSP (object) && EQ (XCAR (object), Qimage)) 7019 if (IMAGEP (object))
7025 { 7020 {
7026 Lisp_Object tem; 7021 Lisp_Object tem;
7027 7022
@@ -7123,7 +7118,7 @@ parse_image_spec (spec, keywords, nkeywords, type)
7123 int i; 7118 int i;
7124 Lisp_Object plist; 7119 Lisp_Object plist;
7125 7120
7126 if (!CONSP (spec) || !EQ (XCAR (spec), Qimage)) 7121 if (!IMAGEP (spec))
7127 return 0; 7122 return 0;
7128 7123
7129 plist = XCDR (spec); 7124 plist = XCDR (spec);
diff --git a/src/w32menu.c b/src/w32menu.c
index 49ced7fd11c..5f8f8a4e5e0 100644
--- a/src/w32menu.c
+++ b/src/w32menu.c
@@ -153,7 +153,6 @@ Lisp_Object Vmenu_updating_frame;
153Lisp_Object Qdebug_on_next_call; 153Lisp_Object Qdebug_on_next_call;
154 154
155extern Lisp_Object Qmenu_bar; 155extern Lisp_Object Qmenu_bar;
156extern Lisp_Object Qmouse_click, Qevent_kind;
157 156
158extern Lisp_Object QCtoggle, QCradio; 157extern Lisp_Object QCtoggle, QCradio;
159 158
diff --git a/src/w32term.c b/src/w32term.c
index 7f29cfe0869..6da7f612ec9 100644
--- a/src/w32term.c
+++ b/src/w32term.c
@@ -221,8 +221,6 @@ static int input_signal_count;
221 221
222extern Lisp_Object Vcommand_line_args, Vsystem_name; 222extern Lisp_Object Vcommand_line_args, Vsystem_name;
223 223
224extern Lisp_Object Qface, Qmouse_face;
225
226#ifndef USE_CRT_DLL 224#ifndef USE_CRT_DLL
227extern int errno; 225extern int errno;
228#endif 226#endif
diff --git a/src/xdisp.c b/src/xdisp.c
index 020f5736d31..2c83246b9f4 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -243,6 +243,9 @@ Lisp_Object Qbuffer_position, Qposition, Qobject;
243/* Cursor shapes */ 243/* Cursor shapes */
244Lisp_Object Qbar, Qhbar, Qbox, Qhollow; 244Lisp_Object Qbar, Qhbar, Qbox, Qhollow;
245 245
246/* Pointer shapes */
247Lisp_Object Qarrow, Qhand, Qtext;
248
246Lisp_Object Qrisky_local_variable; 249Lisp_Object Qrisky_local_variable;
247 250
248/* Holds the list (error). */ 251/* Holds the list (error). */
@@ -291,7 +294,7 @@ int inhibit_eval_during_redisplay;
291 294
292/* Names of text properties relevant for redisplay. */ 295/* Names of text properties relevant for redisplay. */
293 296
294Lisp_Object Qdisplay, Qrelative_width, Qalign_to; 297Lisp_Object Qdisplay;
295extern Lisp_Object Qface, Qinvisible, Qwidth; 298extern Lisp_Object Qface, Qinvisible, Qwidth;
296 299
297/* Symbols used in text property values. */ 300/* Symbols used in text property values. */
@@ -299,7 +302,7 @@ extern Lisp_Object Qface, Qinvisible, Qwidth;
299Lisp_Object Vdisplay_pixels_per_inch; 302Lisp_Object Vdisplay_pixels_per_inch;
300Lisp_Object Qspace, QCalign_to, QCrelative_width, QCrelative_height; 303Lisp_Object Qspace, QCalign_to, QCrelative_width, QCrelative_height;
301Lisp_Object Qleft_margin, Qright_margin, Qspace_width, Qraise; 304Lisp_Object Qleft_margin, Qright_margin, Qspace_width, Qraise;
302Lisp_Object Qmargin; 305Lisp_Object Qmargin, Qpointer;
303extern Lisp_Object Qheight; 306extern Lisp_Object Qheight;
304extern Lisp_Object QCwidth, QCheight, QCascent; 307extern Lisp_Object QCwidth, QCheight, QCascent;
305extern Lisp_Object Qscroll_bar; 308extern Lisp_Object Qscroll_bar;
@@ -312,7 +315,7 @@ Lisp_Object Vshow_trailing_whitespace;
312 i.e. in blank areas after eol and eob. This used to be 315 i.e. in blank areas after eol and eob. This used to be
313 the default in 21.3. */ 316 the default in 21.3. */
314 317
315Lisp_Object Vshow_text_cursor_in_void; 318Lisp_Object Vvoid_text_area_pointer;
316 319
317/* Name of the face used to highlight trailing whitespace. */ 320/* Name of the face used to highlight trailing whitespace. */
318 321
@@ -323,6 +326,10 @@ Lisp_Object Qtrailing_whitespace;
323 326
324Lisp_Object Qimage; 327Lisp_Object Qimage;
325 328
329/* The image map types. */
330Lisp_Object QCmap, QCpointer;
331Lisp_Object Qrect, Qcircle, Qpoly;
332
326/* Non-zero means print newline to stdout before next mini-buffer 333/* Non-zero means print newline to stdout before next mini-buffer
327 message. */ 334 message. */
328 335
@@ -1579,11 +1586,10 @@ glyph_to_pixel_coords (w, hpos, vpos, frame_x, frame_y)
1579 date. */ 1586 date. */
1580 1587
1581static struct glyph * 1588static struct glyph *
1582x_y_to_hpos_vpos (w, x, y, hpos, vpos, area, buffer_only_p) 1589x_y_to_hpos_vpos (w, x, y, hpos, vpos, dx, dy, area)
1583 struct window *w; 1590 struct window *w;
1584 int x, y; 1591 int x, y;
1585 int *hpos, *vpos, *area; 1592 int *hpos, *vpos, *dx, *dy, *area;
1586 int buffer_only_p;
1587{ 1593{
1588 struct glyph *glyph, *end; 1594 struct glyph *glyph, *end;
1589 struct glyph_row *row = NULL; 1595 struct glyph_row *row = NULL;
@@ -1634,23 +1640,22 @@ x_y_to_hpos_vpos (w, x, y, hpos, vpos, area, buffer_only_p)
1634 /* Find glyph containing X. */ 1640 /* Find glyph containing X. */
1635 glyph = row->glyphs[*area]; 1641 glyph = row->glyphs[*area];
1636 end = glyph + row->used[*area]; 1642 end = glyph + row->used[*area];
1637 while (glyph < end) 1643 x -= x0;
1644 while (glyph < end && x >= glyph->pixel_width)
1638 { 1645 {
1639 if (x < x0 + glyph->pixel_width) 1646 x -= glyph->pixel_width;
1640 {
1641 if (w->pseudo_window_p)
1642 break;
1643 else if (!buffer_only_p || BUFFERP (glyph->object))
1644 break;
1645 }
1646
1647 x0 += glyph->pixel_width;
1648 ++glyph; 1647 ++glyph;
1649 } 1648 }
1650 1649
1651 if (glyph == end) 1650 if (glyph == end)
1652 return NULL; 1651 return NULL;
1653 1652
1653 if (dx)
1654 {
1655 *dx = x;
1656 *dy = y - (row->y + row->ascent - glyph->ascent);
1657 }
1658
1654 *hpos = glyph - row->glyphs[*area]; 1659 *hpos = glyph - row->glyphs[*area];
1655 return glyph; 1660 return glyph;
1656} 1661}
@@ -1738,20 +1743,28 @@ get_glyph_string_clip_rect (s, nr)
1738 1743
1739 r.y = WINDOW_TO_FRAME_PIXEL_Y (s->w, r.y); 1744 r.y = WINDOW_TO_FRAME_PIXEL_Y (s->w, r.y);
1740 1745
1741#ifdef HAVE_NTGUI
1742 /* ++KFS: From W32 port, but it looks ok for all platforms to me. */
1743 /* If drawing the cursor, don't let glyph draw outside its 1746 /* If drawing the cursor, don't let glyph draw outside its
1744 advertised boundaries. Cleartype does this under some circumstances. */ 1747 advertised boundaries. Cleartype does this under some circumstances. */
1745 if (s->hl == DRAW_CURSOR) 1748 if (s->hl == DRAW_CURSOR)
1746 { 1749 {
1750 struct glyph *glyph = s->first_glyph;
1751 int height;
1752
1747 if (s->x > r.x) 1753 if (s->x > r.x)
1748 { 1754 {
1749 r.width -= s->x - r.x; 1755 r.width -= s->x - r.x;
1750 r.x = s->x; 1756 r.x = s->x;
1751 } 1757 }
1752 r.width = min (r.width, s->first_glyph->pixel_width); 1758 r.width = min (r.width, glyph->pixel_width);
1759
1760 /* Don't draw cursor glyph taller than our actual glyph. */
1761 height = max (FRAME_LINE_HEIGHT (s->f), glyph->ascent + glyph->descent);
1762 if (height < r.height)
1763 {
1764 r.y = s->ybase + glyph->descent - height;
1765 r.height = height;
1766 }
1753 } 1767 }
1754#endif
1755 1768
1756#ifdef CONVERT_FROM_XRECT 1769#ifdef CONVERT_FROM_XRECT
1757 CONVERT_FROM_XRECT (r, *nr); 1770 CONVERT_FROM_XRECT (r, *nr);
@@ -8276,7 +8289,7 @@ build_desired_tool_bar_string (f)
8276 int enabled_p = !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P)); 8289 int enabled_p = !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P));
8277 int selected_p = !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P)); 8290 int selected_p = !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P));
8278 int hmargin, vmargin, relief, idx, end; 8291 int hmargin, vmargin, relief, idx, end;
8279 extern Lisp_Object QCrelief, QCmargin, QCconversion, Qimage; 8292 extern Lisp_Object QCrelief, QCmargin, QCconversion;
8280 8293
8281 /* If image is a vector, choose the image according to the 8294 /* If image is a vector, choose the image according to the
8282 button state. */ 8295 button state. */
@@ -8693,7 +8706,7 @@ get_tool_bar_item (f, x, y, glyph, hpos, vpos, prop_idx)
8693 int area; 8706 int area;
8694 8707
8695 /* Find the glyph under X/Y. */ 8708 /* Find the glyph under X/Y. */
8696 *glyph = x_y_to_hpos_vpos (w, x, y, hpos, vpos, &area, 0); 8709 *glyph = x_y_to_hpos_vpos (w, x, y, hpos, vpos, 0, 0, &area);
8697 if (*glyph == NULL) 8710 if (*glyph == NULL)
8698 return -1; 8711 return -1;
8699 8712
@@ -17682,6 +17695,8 @@ append_glyph (it)
17682 glyph->charpos = CHARPOS (it->position); 17695 glyph->charpos = CHARPOS (it->position);
17683 glyph->object = it->object; 17696 glyph->object = it->object;
17684 glyph->pixel_width = it->pixel_width; 17697 glyph->pixel_width = it->pixel_width;
17698 glyph->ascent = it->ascent;
17699 glyph->descent = it->descent;
17685 glyph->voffset = it->voffset; 17700 glyph->voffset = it->voffset;
17686 glyph->type = CHAR_GLYPH; 17701 glyph->type = CHAR_GLYPH;
17687 glyph->multibyte_p = it->multibyte_p; 17702 glyph->multibyte_p = it->multibyte_p;
@@ -17716,6 +17731,8 @@ append_composite_glyph (it)
17716 glyph->charpos = CHARPOS (it->position); 17731 glyph->charpos = CHARPOS (it->position);
17717 glyph->object = it->object; 17732 glyph->object = it->object;
17718 glyph->pixel_width = it->pixel_width; 17733 glyph->pixel_width = it->pixel_width;
17734 glyph->ascent = it->ascent;
17735 glyph->descent = it->descent;
17719 glyph->voffset = it->voffset; 17736 glyph->voffset = it->voffset;
17720 glyph->type = COMPOSITE_GLYPH; 17737 glyph->type = COMPOSITE_GLYPH;
17721 glyph->multibyte_p = it->multibyte_p; 17738 glyph->multibyte_p = it->multibyte_p;
@@ -17764,6 +17781,7 @@ produce_image_glyph (it)
17764{ 17781{
17765 struct image *img; 17782 struct image *img;
17766 struct face *face; 17783 struct face *face;
17784 int face_ascent, glyph_ascent;
17767 17785
17768 xassert (it->what == IT_IMAGE); 17786 xassert (it->what == IT_IMAGE);
17769 17787
@@ -17775,10 +17793,15 @@ produce_image_glyph (it)
17775 PREPARE_FACE_FOR_DISPLAY (it->f, face); 17793 PREPARE_FACE_FOR_DISPLAY (it->f, face);
17776 prepare_image_for_display (it->f, img); 17794 prepare_image_for_display (it->f, img);
17777 17795
17778 it->ascent = it->phys_ascent = image_ascent (img, face); 17796 it->ascent = it->phys_ascent = glyph_ascent = image_ascent (img, face);
17779 it->descent = it->phys_descent = img->height + 2 * img->vmargin - it->ascent; 17797 it->descent = it->phys_descent = img->height + 2 * img->vmargin - it->ascent;
17780 it->pixel_width = img->width + 2 * img->hmargin; 17798 it->pixel_width = img->width + 2 * img->hmargin;
17781 17799
17800 /* If this glyph is alone on the last line, adjust it.ascent to minimum row ascent. */
17801 face_ascent = face->font ? FONT_BASE (face->font) : FRAME_BASELINE_OFFSET (it->f);
17802 if (face_ascent > it->ascent)
17803 it->ascent = it->phys_ascent = face_ascent;
17804
17782 it->nglyphs = 1; 17805 it->nglyphs = 1;
17783 17806
17784 if (face->box != FACE_NO_BOX) 17807 if (face->box != FACE_NO_BOX)
@@ -17808,6 +17831,8 @@ produce_image_glyph (it)
17808 glyph->charpos = CHARPOS (it->position); 17831 glyph->charpos = CHARPOS (it->position);
17809 glyph->object = it->object; 17832 glyph->object = it->object;
17810 glyph->pixel_width = it->pixel_width; 17833 glyph->pixel_width = it->pixel_width;
17834 glyph->ascent = glyph_ascent;
17835 glyph->descent = it->descent;
17811 glyph->voffset = it->voffset; 17836 glyph->voffset = it->voffset;
17812 glyph->type = IMAGE_GLYPH; 17837 glyph->type = IMAGE_GLYPH;
17813 glyph->multibyte_p = it->multibyte_p; 17838 glyph->multibyte_p = it->multibyte_p;
@@ -17847,6 +17872,8 @@ append_stretch_glyph (it, object, width, height, ascent)
17847 glyph->charpos = CHARPOS (it->position); 17872 glyph->charpos = CHARPOS (it->position);
17848 glyph->object = object; 17873 glyph->object = object;
17849 glyph->pixel_width = width; 17874 glyph->pixel_width = width;
17875 glyph->ascent = ascent;
17876 glyph->descent = height - ascent;
17850 glyph->voffset = it->voffset; 17877 glyph->voffset = it->voffset;
17851 glyph->type = STRETCH_GLYPH; 17878 glyph->type = STRETCH_GLYPH;
17852 glyph->multibyte_p = it->multibyte_p; 17879 glyph->multibyte_p = it->multibyte_p;
@@ -19942,6 +19969,189 @@ fast_find_string_pos (w, pos, object, hpos, vpos, x, y, right_p)
19942} 19969}
19943 19970
19944 19971
19972/* See if position X, Y is within a hot-spot of an image. */
19973
19974static int
19975on_hot_spot_p (hot_spot, x, y)
19976 Lisp_Object hot_spot;
19977 int x, y;
19978{
19979 if (!CONSP (hot_spot))
19980 return 0;
19981
19982 if (EQ (XCAR (hot_spot), Qrect))
19983 {
19984 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
19985 Lisp_Object rect = XCDR (hot_spot);
19986 Lisp_Object tem;
19987 if (!CONSP (rect))
19988 return 0;
19989 if (!CONSP (XCAR (rect)))
19990 return 0;
19991 if (!CONSP (XCDR (rect)))
19992 return 0;
19993 if (!(tem = XCAR (XCAR (rect)), INTEGERP (tem) && x >= XINT (tem)))
19994 return 0;
19995 if (!(tem = XCDR (XCAR (rect)), INTEGERP (tem) && y >= XINT (tem)))
19996 return 0;
19997 if (!(tem = XCAR (XCDR (rect)), INTEGERP (tem) && x <= XINT (tem)))
19998 return 0;
19999 if (!(tem = XCDR (XCDR (rect)), INTEGERP (tem) && y <= XINT (tem)))
20000 return 0;
20001 return 1;
20002 }
20003 else if (EQ (XCAR (hot_spot), Qcircle))
20004 {
20005 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
20006 Lisp_Object circ = XCDR (hot_spot);
20007 Lisp_Object lr, lx0, ly0;
20008 if (CONSP (circ)
20009 && CONSP (XCAR (circ))
20010 && (lr = XCDR (circ), INTEGERP (lr) || FLOATP (lr))
20011 && (lx0 = XCAR (XCAR (circ)), INTEGERP (lx0))
20012 && (ly0 = XCDR (XCAR (circ)), INTEGERP (ly0)))
20013 {
20014 double r = XFLOATINT (lr);
20015 double dx = XINT (lx0) - x;
20016 double dy = XINT (ly0) - y;
20017 return (dx * dx + dy * dy <= r * r);
20018 }
20019 }
20020 else if (EQ (XCAR (hot_spot), Qpoly))
20021 {
20022 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
20023 if (VECTORP (XCDR (hot_spot)))
20024 {
20025 struct Lisp_Vector *v = XVECTOR (XCDR (hot_spot));
20026 Lisp_Object *poly = v->contents;
20027 int n = v->size;
20028 int i;
20029 int inside = 0;
20030 Lisp_Object lx, ly;
20031 int x0, y0;
20032
20033 /* Need an even number of coordinates, and at least 3 edges. */
20034 if (n < 6 || n & 1)
20035 return 0;
20036
20037 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
20038 If count is odd, we are inside polygon. Pixels on edges
20039 may or may not be included depending on actual geometry of the
20040 polygon. */
20041 if ((lx = poly[n-2], !INTEGERP (lx))
20042 || (ly = poly[n-1], !INTEGERP (lx)))
20043 return 0;
20044 x0 = XINT (lx), y0 = XINT (ly);
20045 for (i = 0; i < n; i += 2)
20046 {
20047 int x1 = x0, y1 = y0;
20048 if ((lx = poly[i], !INTEGERP (lx))
20049 || (ly = poly[i+1], !INTEGERP (ly)))
20050 return 0;
20051 x0 = XINT (lx), y0 = XINT (ly);
20052
20053 /* Does this segment cross the X line? */
20054 if (x0 >= x)
20055 {
20056 if (x1 >= x)
20057 continue;
20058 }
20059 else if (x1 < x)
20060 continue;
20061 if (y > y0 && y > y1)
20062 continue;
20063 if (y < y0 + ((y1 - y0) * (x - x0)) / (x1 - x0))
20064 inside = !inside;
20065 }
20066 return inside;
20067 }
20068 }
20069 else
20070 return 0;
20071}
20072
20073Lisp_Object
20074find_hot_spot (map, x, y)
20075 Lisp_Object map;
20076 int x, y;
20077{
20078 while (CONSP (map))
20079 {
20080 if (CONSP (XCAR (map))
20081 && on_hot_spot_p (XCAR (XCAR (map)), x, y))
20082 return XCAR (map);
20083 map = XCDR (map);
20084 }
20085
20086 return Qnil;
20087}
20088
20089DEFUN ("lookup-image-map", Flookup_image_map, Slookup_image_map,
20090 3, 3, 0,
20091 doc: /* Lookup in image map MAP coordinates X and Y.
20092An image map is an alist where each element has the format (AREA ID PLIST).
20093An AREA is specified as either a rectangle, a circle, or a polygon:
20094A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
20095pixel coordinates of the upper left and bottom right corners.
20096A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
20097and the radius of the circle; r may be a float or integer.
20098A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
20099vector describes one corner in the polygon.
20100Returns the alist element for the first matching AREA in MAP. */)
20101 (map, x, y)
20102 Lisp_Object map;
20103 Lisp_Object x, y;
20104{
20105 int ix, iy;
20106 if (NILP (map))
20107 return Qnil;
20108
20109 if (!INTEGERP (x))
20110 wrong_type_argument (Qintegerp, x);
20111 if (!INTEGERP (y))
20112 wrong_type_argument (Qintegerp, y);
20113
20114 return find_hot_spot (map, XINT (x), XINT (y));
20115}
20116
20117
20118/* Display frame CURSOR, optionally using shape defined by POINTER. */
20119static void
20120define_frame_cursor1 (f, cursor, pointer)
20121 struct frame *f;
20122 Cursor cursor;
20123 Lisp_Object pointer;
20124{
20125 if (!NILP (pointer))
20126 {
20127 if (EQ (pointer, Qarrow))
20128 cursor = FRAME_X_OUTPUT (f)->nontext_cursor;
20129 else if (EQ (pointer, Qhand))
20130 cursor = FRAME_X_OUTPUT (f)->hand_cursor;
20131 else if (EQ (pointer, Qtext))
20132 cursor = FRAME_X_OUTPUT (f)->text_cursor;
20133 else if (EQ (pointer, intern ("hdrag")))
20134 cursor = FRAME_X_OUTPUT (f)->horizontal_drag_cursor;
20135#ifdef HAVE_X_WINDOWS
20136 else if (EQ (pointer, intern ("vdrag")))
20137 cursor = FRAME_X_DISPLAY_INFO (f)->vertical_scroll_bar_cursor;
20138#endif
20139 else if (EQ (pointer, intern ("hourglass")))
20140 cursor = FRAME_X_OUTPUT (f)->hourglass_cursor;
20141 else if (EQ (pointer, Qmodeline))
20142 cursor = FRAME_X_OUTPUT (f)->modeline_cursor;
20143 else
20144 cursor = FRAME_X_OUTPUT (f)->nontext_cursor;
20145 }
20146
20147#ifndef HAVE_CARBON
20148 if (cursor != No_Cursor)
20149#else
20150 if (bcmp (&cursor, &No_Cursor, sizeof (Cursor)))
20151#endif
20152 rif->define_frame_cursor (f, cursor);
20153}
20154
19945/* Take proper action when mouse has moved to the mode or header line 20155/* Take proper action when mouse has moved to the mode or header line
19946 or marginal area AREA of window W, x-position X and y-position Y. 20156 or marginal area AREA of window W, x-position X and y-position Y.
19947 X is relative to the start of the text display area of W, so the 20157 X is relative to the start of the text display area of W, so the
@@ -19957,18 +20167,24 @@ note_mode_line_or_margin_highlight (w, x, y, area)
19957 struct frame *f = XFRAME (w->frame); 20167 struct frame *f = XFRAME (w->frame);
19958 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f); 20168 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
19959 Cursor cursor = FRAME_X_OUTPUT (f)->nontext_cursor; 20169 Cursor cursor = FRAME_X_OUTPUT (f)->nontext_cursor;
19960 int charpos; 20170 Lisp_Object pointer = Qnil;
19961 Lisp_Object string, help, map, pos; 20171 int charpos, dx, dy;
20172 Lisp_Object string;
20173 Lisp_Object pos, help, image;
19962 20174
19963 if (area == ON_MODE_LINE || area == ON_HEADER_LINE) 20175 if (area == ON_MODE_LINE || area == ON_HEADER_LINE)
19964 string = mode_line_string (w, &x, &y, 0, 0, area, &charpos); 20176 string = mode_line_string (w, &x, &y, 0, 0, area, &charpos);
19965 else 20177 else
19966 string = marginal_area_string (w, &x, &y, 0, 0, area, &charpos); 20178 {
20179 x -= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w);
20180 string = marginal_area_string (w, &x, &y, &dx, &dy, area, &charpos);
20181 }
20182
20183 help = Qnil;
19967 20184
19968 if (STRINGP (string)) 20185 if (STRINGP (string))
19969 { 20186 {
19970 pos = make_number (charpos); 20187 pos = make_number (charpos);
19971
19972 /* If we're on a string with `help-echo' text property, arrange 20188 /* If we're on a string with `help-echo' text property, arrange
19973 for the help to be displayed. This is done by setting the 20189 for the help to be displayed. This is done by setting the
19974 global variable help_echo_string to the help string. */ 20190 global variable help_echo_string to the help string. */
@@ -19981,9 +20197,13 @@ note_mode_line_or_margin_highlight (w, x, y, area)
19981 help_echo_pos = charpos; 20197 help_echo_pos = charpos;
19982 } 20198 }
19983 20199
20200 if (NILP (pointer))
20201 pointer = Fget_text_property (pos, Qpointer, string);
20202
19984 /* Change the mouse pointer according to what is under X/Y. */ 20203 /* Change the mouse pointer according to what is under X/Y. */
19985 if (area == ON_MODE_LINE) 20204 if (NILP (pointer) && area == ON_MODE_LINE)
19986 { 20205 {
20206 Lisp_Object map;
19987 map = Fget_text_property (pos, Qlocal_map, string); 20207 map = Fget_text_property (pos, Qlocal_map, string);
19988 if (!KEYMAPP (map)) 20208 if (!KEYMAPP (map))
19989 map = Fget_text_property (pos, Qkeymap, string); 20209 map = Fget_text_property (pos, Qkeymap, string);
@@ -19991,8 +20211,42 @@ note_mode_line_or_margin_highlight (w, x, y, area)
19991 cursor = dpyinfo->vertical_scroll_bar_cursor; 20211 cursor = dpyinfo->vertical_scroll_bar_cursor;
19992 } 20212 }
19993 } 20213 }
20214 else if (IMAGEP (string))
20215 {
20216 Lisp_Object image_map, hotspot;
20217 if ((image_map = Fplist_get (XCDR (string), QCmap),
20218 !NILP (image_map))
20219 && (hotspot = find_hot_spot (image_map, dx, dy),
20220 CONSP (hotspot))
20221 && (hotspot = XCDR (hotspot), CONSP (hotspot)))
20222 {
20223 Lisp_Object area_id, plist;
19994 20224
19995 rif->define_frame_cursor (f, cursor); 20225 area_id = XCAR (hotspot);
20226 /* Could check AREA_ID to see if we enter/leave this hot-spot.
20227 If so, we could look for mouse-enter, mouse-leave
20228 properties in PLIST (and do something...). */
20229 if ((plist = XCDR (hotspot), CONSP (plist)))
20230 {
20231 pointer = Fplist_get (plist, Qpointer);
20232 if (NILP (pointer))
20233 pointer = Qhand;
20234 help = Fplist_get (plist, Qhelp_echo);
20235 if (!NILP (help))
20236 {
20237 help_echo_string = help;
20238 /* Is this correct? ++kfs */
20239 XSETWINDOW (help_echo_window, w);
20240 help_echo_object = w->buffer;
20241 help_echo_pos = charpos;
20242 }
20243 }
20244 if (NILP (pointer))
20245 pointer = Fplist_get (XCDR (string), QCpointer);
20246 }
20247 }
20248
20249 define_frame_cursor1 (f, cursor, pointer);
19996} 20250}
19997 20251
19998 20252
@@ -20012,6 +20266,7 @@ note_mouse_highlight (f, x, y)
20012 Lisp_Object window; 20266 Lisp_Object window;
20013 struct window *w; 20267 struct window *w;
20014 Cursor cursor = No_Cursor; 20268 Cursor cursor = No_Cursor;
20269 Lisp_Object pointer = Qnil; /* Takes precedence over cursor! */
20015 struct buffer *b; 20270 struct buffer *b;
20016 20271
20017 /* When a menu is active, don't highlight because this looks odd. */ 20272 /* When a menu is active, don't highlight because this looks odd. */
@@ -20049,7 +20304,6 @@ note_mouse_highlight (f, x, y)
20049 return; 20304 return;
20050 20305
20051 /* Reset help_echo_string. It will get recomputed below. */ 20306 /* Reset help_echo_string. It will get recomputed below. */
20052 /* ++KFS: X version didn't do this, but it looks harmless. */
20053 help_echo_string = Qnil; 20307 help_echo_string = Qnil;
20054 20308
20055 /* Convert to window-relative pixel coordinates. */ 20309 /* Convert to window-relative pixel coordinates. */
@@ -20087,7 +20341,7 @@ note_mouse_highlight (f, x, y)
20087 && XFASTINT (w->last_modified) == BUF_MODIFF (b) 20341 && XFASTINT (w->last_modified) == BUF_MODIFF (b)
20088 && XFASTINT (w->last_overlay_modified) == BUF_OVERLAY_MODIFF (b)) 20342 && XFASTINT (w->last_overlay_modified) == BUF_OVERLAY_MODIFF (b))
20089 { 20343 {
20090 int hpos, vpos, pos, i, area; 20344 int hpos, vpos, pos, i, dx, dy, area;
20091 struct glyph *glyph; 20345 struct glyph *glyph;
20092 Lisp_Object object; 20346 Lisp_Object object;
20093 Lisp_Object mouse_face = Qnil, overlay = Qnil, position; 20347 Lisp_Object mouse_face = Qnil, overlay = Qnil, position;
@@ -20097,7 +20351,45 @@ note_mouse_highlight (f, x, y)
20097 int obegv, ozv, same_region; 20351 int obegv, ozv, same_region;
20098 20352
20099 /* Find the glyph under X/Y. */ 20353 /* Find the glyph under X/Y. */
20100 glyph = x_y_to_hpos_vpos (w, x, y, &hpos, &vpos, &area, 0); 20354 glyph = x_y_to_hpos_vpos (w, x, y, &hpos, &vpos, &dx, &dy, &area);
20355
20356 /* Look for :pointer property on image. */
20357 if (glyph != NULL && glyph->type == IMAGE_GLYPH)
20358 {
20359 struct image *img = IMAGE_FROM_ID (f, glyph->u.img_id);
20360 if (img != NULL && IMAGEP (img->spec))
20361 {
20362 Lisp_Object image_map, hotspot;
20363 if ((image_map = Fplist_get (XCDR (img->spec), QCmap),
20364 !NILP (image_map))
20365 && (hotspot = find_hot_spot (image_map, dx, dy),
20366 CONSP (hotspot))
20367 && (hotspot = XCDR (hotspot), CONSP (hotspot)))
20368 {
20369 Lisp_Object area_id, plist;
20370
20371 area_id = XCAR (hotspot);
20372 /* Could check AREA_ID to see if we enter/leave this hot-spot.
20373 If so, we could look for mouse-enter, mouse-leave
20374 properties in PLIST (and do something...). */
20375 if ((plist = XCDR (hotspot), CONSP (plist)))
20376 {
20377 pointer = Fplist_get (plist, Qpointer);
20378 if (NILP (pointer))
20379 pointer = Qhand;
20380 help_echo_string = Fplist_get (plist, Qhelp_echo);
20381 if (!NILP (help_echo_string))
20382 {
20383 help_echo_window = window;
20384 help_echo_object = glyph->object;
20385 help_echo_pos = glyph->charpos;
20386 }
20387 }
20388 }
20389 if (NILP (pointer))
20390 pointer = Fplist_get (XCDR (img->spec), QCpointer);
20391 }
20392 }
20101 20393
20102 /* Clear mouse face if X/Y not over text. */ 20394 /* Clear mouse face if X/Y not over text. */
20103 if (glyph == NULL 20395 if (glyph == NULL
@@ -20106,8 +20398,13 @@ note_mouse_highlight (f, x, y)
20106 { 20398 {
20107 if (clear_mouse_face (dpyinfo)) 20399 if (clear_mouse_face (dpyinfo))
20108 cursor = No_Cursor; 20400 cursor = No_Cursor;
20109 if (NILP (Vshow_text_cursor_in_void)) 20401 if (NILP (pointer))
20110 cursor = FRAME_X_OUTPUT (f)->nontext_cursor; 20402 {
20403 if (area != TEXT_AREA)
20404 cursor = FRAME_X_OUTPUT (f)->nontext_cursor;
20405 else
20406 pointer = Vvoid_text_area_pointer;
20407 }
20111 goto set_cursor; 20408 goto set_cursor;
20112 } 20409 }
20113 20410
@@ -20120,9 +20417,6 @@ note_mouse_highlight (f, x, y)
20120 if (BUFFERP (object) && pos > BUF_Z (b)) 20417 if (BUFFERP (object) && pos > BUF_Z (b))
20121 goto set_cursor; 20418 goto set_cursor;
20122 20419
20123 if (glyph->type == IMAGE_GLYPH)
20124 cursor = FRAME_X_OUTPUT (f)->nontext_cursor;
20125
20126 /* Make the window's buffer temporarily current for 20420 /* Make the window's buffer temporarily current for
20127 overlays_at and compute_char_face. */ 20421 overlays_at and compute_char_face. */
20128 obuf = current_buffer; 20422 obuf = current_buffer;
@@ -20366,7 +20660,7 @@ note_mouse_highlight (f, x, y)
20366 check_help_echo: 20660 check_help_echo:
20367 20661
20368 /* Look for a `help-echo' property. */ 20662 /* Look for a `help-echo' property. */
20369 { 20663 if (NILP (help_echo_string)) {
20370 Lisp_Object help, overlay; 20664 Lisp_Object help, overlay;
20371 20665
20372 /* Check overlays first. */ 20666 /* Check overlays first. */
@@ -20432,6 +20726,46 @@ note_mouse_highlight (f, x, y)
20432 } 20726 }
20433 } 20727 }
20434 20728
20729 /* Look for a `pointer' property. */
20730 if (NILP (pointer))
20731 {
20732 /* Check overlays first. */
20733 for (i = noverlays - 1; i >= 0 && NILP (pointer); --i)
20734 pointer = Foverlay_get (overlay_vec[i], Qpointer);
20735
20736 if (NILP (pointer))
20737 {
20738 Lisp_Object object = glyph->object;
20739 int charpos = glyph->charpos;
20740
20741 /* Try text properties. */
20742 if (STRINGP (object)
20743 && charpos >= 0
20744 && charpos < SCHARS (object))
20745 {
20746 pointer = Fget_text_property (make_number (charpos),
20747 Qpointer, object);
20748 if (NILP (pointer))
20749 {
20750 /* If the string itself doesn't specify a pointer,
20751 see if the buffer text ``under'' it does. */
20752 struct glyph_row *r
20753 = MATRIX_ROW (w->current_matrix, vpos);
20754 int start = MATRIX_ROW_START_CHARPOS (r);
20755 int pos = string_buffer_position (w, object, start);
20756 if (pos > 0)
20757 pointer = Fget_char_property (make_number (pos),
20758 Qpointer, w->buffer);
20759 }
20760 }
20761 else if (BUFFERP (object)
20762 && charpos >= BEGV
20763 && charpos < ZV)
20764 pointer = Fget_text_property (make_number (charpos),
20765 Qpointer, object);
20766 }
20767 }
20768
20435 BEGV = obegv; 20769 BEGV = obegv;
20436 ZV = ozv; 20770 ZV = ozv;
20437 current_buffer = obuf; 20771 current_buffer = obuf;
@@ -20439,12 +20773,7 @@ note_mouse_highlight (f, x, y)
20439 20773
20440 set_cursor: 20774 set_cursor:
20441 20775
20442#ifndef HAVE_CARBON 20776 define_frame_cursor1 (f, cursor, pointer);
20443 if (cursor != No_Cursor)
20444#else
20445 if (bcmp (&cursor, &No_Cursor, sizeof (Cursor)))
20446#endif
20447 rif->define_frame_cursor (f, cursor);
20448} 20777}
20449 20778
20450 20779
@@ -21040,6 +21369,7 @@ syms_of_xdisp ()
21040#endif 21369#endif
21041#ifdef HAVE_WINDOW_SYSTEM 21370#ifdef HAVE_WINDOW_SYSTEM
21042 defsubr (&Stool_bar_lines_needed); 21371 defsubr (&Stool_bar_lines_needed);
21372 defsubr (&Slookup_image_map);
21043#endif 21373#endif
21044 defsubr (&Sformat_mode_line); 21374 defsubr (&Sformat_mode_line);
21045 21375
@@ -21073,16 +21403,14 @@ syms_of_xdisp ()
21073 staticpro (&Qspace); 21403 staticpro (&Qspace);
21074 Qmargin = intern ("margin"); 21404 Qmargin = intern ("margin");
21075 staticpro (&Qmargin); 21405 staticpro (&Qmargin);
21406 Qpointer = intern ("pointer");
21407 staticpro (&Qpointer);
21076 Qleft_margin = intern ("left-margin"); 21408 Qleft_margin = intern ("left-margin");
21077 staticpro (&Qleft_margin); 21409 staticpro (&Qleft_margin);
21078 Qright_margin = intern ("right-margin"); 21410 Qright_margin = intern ("right-margin");
21079 staticpro (&Qright_margin); 21411 staticpro (&Qright_margin);
21080 Qalign_to = intern ("align-to");
21081 staticpro (&Qalign_to);
21082 QCalign_to = intern (":align-to"); 21412 QCalign_to = intern (":align-to");
21083 staticpro (&QCalign_to); 21413 staticpro (&QCalign_to);
21084 Qrelative_width = intern ("relative-width");
21085 staticpro (&Qrelative_width);
21086 QCrelative_width = intern (":relative-width"); 21414 QCrelative_width = intern (":relative-width");
21087 staticpro (&QCrelative_width); 21415 staticpro (&QCrelative_width);
21088 QCrelative_height = intern (":relative-height"); 21416 QCrelative_height = intern (":relative-height");
@@ -21101,6 +21429,16 @@ syms_of_xdisp ()
21101 staticpro (&Qtrailing_whitespace); 21429 staticpro (&Qtrailing_whitespace);
21102 Qimage = intern ("image"); 21430 Qimage = intern ("image");
21103 staticpro (&Qimage); 21431 staticpro (&Qimage);
21432 QCmap = intern (":map");
21433 staticpro (&QCmap);
21434 QCpointer = intern (":pointer");
21435 staticpro (&QCpointer);
21436 Qrect = intern ("rect");
21437 staticpro (&Qrect);
21438 Qcircle = intern ("circle");
21439 staticpro (&Qcircle);
21440 Qpoly = intern ("poly");
21441 staticpro (&Qpoly);
21104 Qmessage_truncate_lines = intern ("message-truncate-lines"); 21442 Qmessage_truncate_lines = intern ("message-truncate-lines");
21105 staticpro (&Qmessage_truncate_lines); 21443 staticpro (&Qmessage_truncate_lines);
21106 Qcursor_in_non_selected_windows = intern ("cursor-in-non-selected-windows"); 21444 Qcursor_in_non_selected_windows = intern ("cursor-in-non-selected-windows");
@@ -21125,6 +21463,12 @@ syms_of_xdisp ()
21125 staticpro (&Qbox); 21463 staticpro (&Qbox);
21126 Qhollow = intern ("hollow"); 21464 Qhollow = intern ("hollow");
21127 staticpro (&Qhollow); 21465 staticpro (&Qhollow);
21466 Qhand = intern ("hand");
21467 staticpro (&Qhand);
21468 Qarrow = intern ("arrow");
21469 staticpro (&Qarrow);
21470 Qtext = intern ("text");
21471 staticpro (&Qtext);
21128 Qrisky_local_variable = intern ("risky-local-variable"); 21472 Qrisky_local_variable = intern ("risky-local-variable");
21129 staticpro (&Qrisky_local_variable); 21473 staticpro (&Qrisky_local_variable);
21130 Qinhibit_free_realized_faces = intern ("inhibit-free-realized-faces"); 21474 Qinhibit_free_realized_faces = intern ("inhibit-free-realized-faces");
@@ -21178,10 +21522,11 @@ wide as that tab on the display. */);
21178The face used for trailing whitespace is `trailing-whitespace'. */); 21522The face used for trailing whitespace is `trailing-whitespace'. */);
21179 Vshow_trailing_whitespace = Qnil; 21523 Vshow_trailing_whitespace = Qnil;
21180 21524
21181 DEFVAR_LISP ("show-text-cursor-in-void", &Vshow_text_cursor_in_void, 21525 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer,
21182 doc: /* Non-nil means show the text cursor in void text areas. 21526 doc: /* The pointer shape to show in void text areas.
21183The default is to show the non-text (typically arrow) cursor. */); 21527Nil means to show the text pointer. Other options are `arrow', `text',
21184 Vshow_text_cursor_in_void = Qnil; 21528`hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
21529 Vvoid_text_area_pointer = Qarrow;
21185 21530
21186 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay, 21531 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay,
21187 doc: /* Non-nil means don't actually do any redisplay. 21532 doc: /* Non-nil means don't actually do any redisplay.
diff --git a/src/xfaces.c b/src/xfaces.c
index fecd8e546cf..84d49e30a9b 100644
--- a/src/xfaces.c
+++ b/src/xfaces.c
@@ -5579,12 +5579,19 @@ cache_face (c, face, hash)
5579 face->id = i; 5579 face->id = i;
5580 5580
5581 /* Maybe enlarge C->faces_by_id. */ 5581 /* Maybe enlarge C->faces_by_id. */
5582 if (i == c->used && c->used == c->size) 5582 if (i == c->used)
5583 { 5583 {
5584 int new_size = 2 * c->size; 5584 if (c->used == c->size)
5585 int sz = new_size * sizeof *c->faces_by_id; 5585 {
5586 c->faces_by_id = (struct face **) xrealloc (c->faces_by_id, sz); 5586 int new_size, sz;
5587 c->size = new_size; 5587 new_size = min (2 * c->size, MAX_FACE_ID);
5588 if (new_size == c->size)
5589 abort (); /* Alternatives? ++kfs */
5590 sz = new_size * sizeof *c->faces_by_id;
5591 c->faces_by_id = (struct face **) xrealloc (c->faces_by_id, sz);
5592 c->size = new_size;
5593 }
5594 c->used++;
5588 } 5595 }
5589 5596
5590#if GLYPH_DEBUG 5597#if GLYPH_DEBUG
@@ -5603,8 +5610,6 @@ cache_face (c, face, hash)
5603#endif /* GLYPH_DEBUG */ 5610#endif /* GLYPH_DEBUG */
5604 5611
5605 c->faces_by_id[i] = face; 5612 c->faces_by_id[i] = face;
5606 if (i == c->used)
5607 ++c->used;
5608} 5613}
5609 5614
5610 5615
diff --git a/src/xfns.c b/src/xfns.c
index 94a74417983..4d9733bdc95 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -1302,7 +1302,6 @@ x_set_mouse_color (f, arg, oldval)
1302 hourglass_cursor = XCreateFontCursor (dpy, XC_watch); 1302 hourglass_cursor = XCreateFontCursor (dpy, XC_watch);
1303 x_check_errors (dpy, "bad hourglass pointer cursor: %s"); 1303 x_check_errors (dpy, "bad hourglass pointer cursor: %s");
1304 1304
1305 x_check_errors (dpy, "bad nontext pointer cursor: %s");
1306 if (!NILP (Vx_mode_pointer_shape)) 1305 if (!NILP (Vx_mode_pointer_shape))
1307 { 1306 {
1308 CHECK_NUMBER (Vx_mode_pointer_shape); 1307 CHECK_NUMBER (Vx_mode_pointer_shape);
@@ -4418,11 +4417,6 @@ the excessive values are ignored. */)
4418 4417
4419static struct image_type *image_types; 4418static struct image_type *image_types;
4420 4419
4421/* The symbol `image' which is the car of the lists used to represent
4422 images in Lisp. */
4423
4424extern Lisp_Object Qimage;
4425
4426/* The symbol `xbm' which is used as the type symbol for XBM images. */ 4420/* The symbol `xbm' which is used as the type symbol for XBM images. */
4427 4421
4428Lisp_Object Qxbm; 4422Lisp_Object Qxbm;
@@ -4502,7 +4496,7 @@ valid_image_p (object)
4502{ 4496{
4503 int valid_p = 0; 4497 int valid_p = 0;
4504 4498
4505 if (CONSP (object) && EQ (XCAR (object), Qimage)) 4499 if (IMAGEP (object))
4506 { 4500 {
4507 Lisp_Object tem; 4501 Lisp_Object tem;
4508 4502
@@ -4604,7 +4598,7 @@ parse_image_spec (spec, keywords, nkeywords, type)
4604 int i; 4598 int i;
4605 Lisp_Object plist; 4599 Lisp_Object plist;
4606 4600
4607 if (!CONSP (spec) || !EQ (XCAR (spec), Qimage)) 4601 if (!IMAGEP (spec))
4608 return 0; 4602 return 0;
4609 4603
4610 plist = XCDR (spec); 4604 plist = XCDR (spec);
diff --git a/src/xmenu.c b/src/xmenu.c
index 3e99a1c506d..669d8177c15 100644
--- a/src/xmenu.c
+++ b/src/xmenu.c
@@ -99,7 +99,6 @@ Lisp_Object Vmenu_updating_frame;
99Lisp_Object Qdebug_on_next_call; 99Lisp_Object Qdebug_on_next_call;
100 100
101extern Lisp_Object Qmenu_bar; 101extern Lisp_Object Qmenu_bar;
102extern Lisp_Object Qmouse_click, Qevent_kind;
103 102
104extern Lisp_Object QCtoggle, QCradio; 103extern Lisp_Object QCtoggle, QCradio;
105 104
@@ -1304,6 +1303,7 @@ show_help_event (f, widget, help)
1304 } 1303 }
1305 else 1304 else
1306 { 1305 {
1306#if 0 /* This code doesn't do anything useful. ++kfs */
1307 /* WIDGET is the popup menu. It's parent is the frame's 1307 /* WIDGET is the popup menu. It's parent is the frame's
1308 widget. See which frame that is. */ 1308 widget. See which frame that is. */
1309 xt_or_gtk_widget frame_widget = XtParent (widget); 1309 xt_or_gtk_widget frame_widget = XtParent (widget);
@@ -1317,7 +1317,7 @@ show_help_event (f, widget, help)
1317 FRAME_X_P (f) && f->output_data.x->widget == frame_widget)) 1317 FRAME_X_P (f) && f->output_data.x->widget == frame_widget))
1318 break; 1318 break;
1319 } 1319 }
1320 1320#endif
1321 show_help_echo (help, Qnil, Qnil, Qnil, 1); 1321 show_help_echo (help, Qnil, Qnil, Qnil, 1);
1322 } 1322 }
1323} 1323}
diff --git a/src/xterm.c b/src/xterm.c
index 30de48aa5e7..e01a5e540fd 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -287,7 +287,7 @@ extern Lisp_Object Vcommand_line_args, Vsystem_name;
287 287
288extern Lisp_Object Vx_no_window_manager; 288extern Lisp_Object Vx_no_window_manager;
289 289
290extern Lisp_Object Qface, Qmouse_face, Qeql; 290extern Lisp_Object Qeql;
291 291
292extern int errno; 292extern int errno;
293 293
@@ -7270,13 +7270,6 @@ x_draw_hollow_cursor (w, row)
7270 struct glyph *cursor_glyph; 7270 struct glyph *cursor_glyph;
7271 GC gc; 7271 GC gc;
7272 7272
7273 /* Compute frame-relative coordinates from window-relative
7274 coordinates. */
7275 x = WINDOW_TEXT_TO_FRAME_PIXEL_X (w, w->phys_cursor.x);
7276 y = (WINDOW_TO_FRAME_PIXEL_Y (w, w->phys_cursor.y)
7277 + row->ascent - w->phys_cursor_ascent);
7278 h = row->height - 1;
7279
7280 /* Get the glyph the cursor is on. If we can't tell because 7273 /* Get the glyph the cursor is on. If we can't tell because
7281 the current matrix is invalid or such, give up. */ 7274 the current matrix is invalid or such, give up. */
7282 cursor_glyph = get_phys_cursor_glyph (w); 7275 cursor_glyph = get_phys_cursor_glyph (w);
@@ -7293,6 +7286,19 @@ x_draw_hollow_cursor (w, row)
7293 wd = min (FRAME_COLUMN_WIDTH (f), wd); 7286 wd = min (FRAME_COLUMN_WIDTH (f), wd);
7294 w->phys_cursor_width = wd; 7287 w->phys_cursor_width = wd;
7295 7288
7289 /* Compute frame-relative coordinates from window-relative
7290 coordinates. */
7291 x = WINDOW_TEXT_TO_FRAME_PIXEL_X (w, w->phys_cursor.x);
7292 y = WINDOW_TO_FRAME_PIXEL_Y (w, w->phys_cursor.y);
7293
7294 /* Compute the proper height and ascent of the rectangle, based
7295 on the actual glyph. Using the full height of the row looks
7296 bad when there are tall images on that row. */
7297 h = max (FRAME_LINE_HEIGHT (f), cursor_glyph->ascent + cursor_glyph->descent);
7298 if (h < row->height)
7299 y += row->ascent /* - w->phys_cursor_ascent */ + cursor_glyph->descent - h;
7300 h--;
7301
7296 /* The foreground of cursor_gc is typically the same as the normal 7302 /* The foreground of cursor_gc is typically the same as the normal
7297 background color, which can cause the cursor box to be invisible. */ 7303 background color, which can cause the cursor box to be invisible. */
7298 xgcv.foreground = f->output_data.x->cursor_pixel; 7304 xgcv.foreground = f->output_data.x->cursor_pixel;