Error Buddy

Do you have an error message from your application? Then find the answer with Error Buddy. You can search over 40000 source code files and troubleshooting documents using our beta lucene/nutch search interface or if you prefer, search as normal using google. With LXR technology you can drill right down into the line of source code where it came from with full cross-referencing.

If after searching you didn't get your ideal answer, or you are still unclear what the error means, you can choose to post that question to the community forums following the link included in the search results.

corestack/ readline-5.0/ parens.c [1.6]
001 /* parens.c -- Implementation of matching parentheses feature. */
002 
003 /* Copyright (C) 1987, 1989, 1992 Free Software Foundation, Inc.
004 
005    This file is part of the GNU Readline Library, a library for
006    reading lines of text with interactive input and history editing.
007 
008    The GNU Readline Library is free software; you can redistribute it
009    and/or modify it under the terms of the GNU General Public License
010    as published by the Free Software Foundation; either version 2, or
011    (at your option) any later version.
012 
013    The GNU Readline Library is distributed in the hope that it will be
014    useful, but WITHOUT ANY WARRANTY; without even the implied warranty
015    of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016    GNU General Public License for more details.
017 
018    The GNU General Public License is often shipped with GNU software, and
019    is generally kept in a file called COPYING or LICENSE.  If you do not
020    have a copy of the license, write to the Free Software Foundation,
021    59 Temple Place, Suite 330, Boston, MA 02111 USA. */
022 #define READLINE_LIBRARY
023 
024 #if defined (__TANDEM)
025 #  include <floss.h>
026 #endif
027 
028 #include "rlconf.h"
029 
030 #if defined (HAVE_CONFIG_H)
031 #  include <config.h>
032 #endif
033 
034 #include <stdio.h>
035 #include <sys/types.h>
036 
037 #if defined (HAVE_UNISTD_H)
038 #  include <unistd.h>
039 #endif
040 
041 #if defined (FD_SET) && !defined (HAVE_SELECT)
042 #  define HAVE_SELECT
043 #endif
044 
045 #if defined (HAVE_SELECT)
046 #  include <sys/time.h>
047 #endif /* HAVE_SELECT */
048 #if defined (HAVE_SYS_SELECT_H)
049 #  include <sys/select.h>
050 #endif
051 
052 #if defined (HAVE_STRING_H)
053 #  include <string.h>
054 #else /* !HAVE_STRING_H */
055 #  include <strings.h>
056 #endif /* !HAVE_STRING_H */
057 
058 #if !defined (strchr) && !defined (__STDC__)
059 extern char *strchr (), *strrchr ();
060 #endif /* !strchr && !__STDC__ */
061 
062 #include "readline.h"
063 #include "rlprivate.h"
064 
065 static int find_matching_open PARAMS((char *, int, int));
066 
067 /* Non-zero means try to blink the matching open parenthesis when the
068    close parenthesis is inserted. */
069 #if defined (HAVE_SELECT)
070 int rl_blink_matching_paren = 1;
071 #else /* !HAVE_SELECT */
072 int rl_blink_matching_paren = 0;
073 #endif /* !HAVE_SELECT */
074 
075 static int _paren_blink_usec = 500000;
076 
077 /* Change emacs_standard_keymap to have bindings for paren matching when
078    ON_OR_OFF is 1, change them back to self_insert when ON_OR_OFF == 0. */
079 void
080 _rl_enable_paren_matching (on_or_off)
081      int on_or_off;
082 {
083   if (on_or_off)
084     {   /* ([{ */
085       rl_bind_key_in_map (')', rl_insert_close, emacs_standard_keymap);
086       rl_bind_key_in_map (']', rl_insert_close, emacs_standard_keymap);
087       rl_bind_key_in_map ('}', rl_insert_close, emacs_standard_keymap);
088     }
089   else
090     {   /* ([{ */
091       rl_bind_key_in_map (')', rl_insert, emacs_standard_keymap);
092       rl_bind_key_in_map (']', rl_insert, emacs_standard_keymap);
093       rl_bind_key_in_map ('}', rl_insert, emacs_standard_keymap);
094     }
095 }
096 
097 int
098 rl_set_paren_blink_timeout (u)
099      int u;
100 {
101   int o;
102 
103   o = _paren_blink_usec;
104   if (u > 0)
105     _paren_blink_usec = u;
106   return (o);
107 }
108 
109 int
110 rl_insert_close (count, invoking_key)
111      int count, invoking_key;
112 {
113   if (rl_explicit_arg || !rl_blink_matching_paren)
114     _rl_insert_char (count, invoking_key);
115   else
116     {
117 #if defined (HAVE_SELECT)
118       int orig_point, match_point, ready;
119       struct timeval timer;
120       fd_set readfds;
121 
122       _rl_insert_char (1, invoking_key);
123       (*rl_redisplay_function) ();
124       match_point =
125         find_matching_open (rl_line_buffer, rl_point - 2, invoking_key);
126 
127       /* Emacs might message or ring the bell here, but I don't. */
128       if (match_point < 0)
129         return -1;
130 
131       FD_ZERO (&readfds);
132       FD_SET (fileno (rl_instream), &readfds);
133       timer.tv_sec = 0;
134       timer.tv_usec = _paren_blink_usec;
135 
136       orig_point = rl_point;
137       rl_point = match_point;
138       (*rl_redisplay_function) ();
139       ready = select (1, &readfds, (fd_set *)NULL, (fd_set *)NULL, &timer);
140       rl_point = orig_point;
141 #else /* !HAVE_SELECT */
142       _rl_insert_char (count, invoking_key);
143 #endif /* !HAVE_SELECT */
144     }
145   return 0;
146 }
147 
148 static int
149 find_matching_open (string, from, closer)
150      char *string;
151      int from, closer;
152 {
153   register int i;
154   int opener, level, delimiter;
155 
156   switch (closer)
157     {
158     case ']': opener = '['; break;
159     case '}': opener = '{'; break;
160     case ')': opener = '('; break;
161     default:
162       return (-1);
163     }
164 
165   level = 1;                    /* The closer passed in counts as 1. */
166   delimiter = 0;                /* Delimited state unknown. */
167 
168   for (i = from; i > -1; i--)
169     {
170       if (delimiter && (string[i] == delimiter))
171         delimiter = 0;
172       else if (rl_basic_quote_characters && strchr (rl_basic_quote_characters, string[i]))
173         delimiter = string[i];
174       else if (!delimiter && (string[i] == closer))
175         level++;
176       else if (!delimiter && (string[i] == opener))
177         level--;
178 
179       if (!level)
180         break;
181     }
182   return (i);
183 }

Powered by Lucene and the LXR engine.