@@ -99,76 +99,88 @@ get_select_ex_ranges(struct sequence* sequ, struct command_list* select, struct
9999
100100// public interface
101101
102+ static int _pass_select_pat (const char * name , struct command * sc );
103+
102104int
103- pass_select (char * name , struct command * sc )
105+ pass_select (const char * name , struct command * sc )
104106 /* checks name against class (if element) and pattern that may
105107 (but need not) be contained in command sc;
106108 0: does not pass, 1: passes */
107109 /* Don't use for selecting elements. It may not find all elements. */
108110{
109111 struct element * el = find_element (strip (name ), element_list );
110- return pass_select_el (el , sc );
112+ return el ? pass_select_el (el , sc ) : pass_select_str ( name , sc );
111113}
112114
113-
114115int
115116pass_select_el (struct element * el , struct command * sc )
116- /* checks name against class (if element) and pattern that may
117+ /* checks element against class and pattern that may
117118 (but need not) be contained in command sc;
118119 0: does not pass, 1: passes */
119120 /* Should use this function in favor of `pass_select` where possible. It
120121 works for all elements and is faster if knowing the element in advance. */
121122{
122123 struct name_list * nl = sc -> par_names ;
123124 struct command_parameter_list * pl = sc -> par ;
124- int pos , in = 0 , any = 0 ;
125- char * class , * pattern ;
126-
127- pos = name_list_pos ("class" , nl );
125+ int pos = name_list_pos ("class" , nl );
128126 if (pos > -1 && nl -> inform [pos ]) /* parameter has been read */
129127 {
130- if (el != NULL )
131- {
132- class = pl -> parameters [pos ]-> string ;
133- in = belongs_to_class (el , class );
134- if (in == 0 ) return 0 ;
135- }
128+ char * class = pl -> parameters [pos ]-> string ;
129+ if (!belongs_to_class (el , class ))
130+ return 0 ;
136131 }
137- any = in = 0 ;
138- pos = name_list_pos ("pattern" , nl );
132+ return _pass_select_pat (el -> name , sc );
133+ }
134+
135+ int pass_select_str (const char * name , struct command * sc )
136+ {
137+ /* checks name against pattern that may
138+ (but need not) be contained in command sc;
139+ considers only SELECT commands *without CLASS*!
140+ 0: does not pass, 1: passes */
141+ // if the command has CLASS attribute, it is supposed to match elements:
142+ if (par_present ("class" , sc , NULL )) /* parameter has been read */
143+ return 0 ;
144+ return _pass_select_pat (name , sc );
145+ }
146+
147+ int _pass_select_pat (const char * name , struct command * sc )
148+ {
149+ /* used internally. */
150+ struct name_list * nl = sc -> par_names ;
151+ struct command_parameter_list * pl = sc -> par ;
152+ int pos = name_list_pos ("pattern" , nl );
139153 if (pos > -1 && nl -> inform [pos ]) /* parameter has been read */
140154 {
141- any = 1 ;
142- pattern = stolower (pl -> parameters [pos ]-> string );
143- if (myregex (pattern , strip (el -> name )) == 0 ) in = 1 ;
155+ char * pattern = stolower (pl -> parameters [pos ]-> string );
156+ return myregex (pattern , strip (name )) == 0 ;
144157 }
145- if (any == 0 ) return 1 ;
146- else return in ;
158+ return 1 ;
147159}
148160
149161int
150- pass_select_list ( char * name , struct command_list * cl )
162+ pass_select_list_str ( const char * name , struct command_list * cl )
151163 /* returns 0 (does not pass) or 1 (passes) for a list of selects */
152- /* Don't use for selecting elements. It may not find all elements. */
164+ /* Don't use for selecting elements! It may not find all elements. */
153165{
154- struct element * el = find_element (strip (name ), element_list );
155- return pass_select_list_el (el , cl );
166+ for (int i = 0 ; i < cl -> curr ; i ++ ) {
167+ if (pass_select_str (name , cl -> commands [i ]))
168+ return 1 ;
169+ }
170+ return cl -> curr == 0 ;
156171}
157172
158-
159173int
160174pass_select_list_el (struct element * el , struct command_list * cl )
161175 /* returns 0 (does not pass) or 1 (passes) for a list of selects */
162176 /* Should use this function in favor of `pass_select_list` where possible. It
163177 works for all elements and is faster if knowing the element in advance. */
164178{
165- int i , ret = 0 ;
166- if (cl -> curr == 0 ) return 1 ;
167- for (i = 0 ; i < cl -> curr ; i ++ )
168- {
169- if ((ret = pass_select_el (el , cl -> commands [i ]))) break ;
179+ for (int i = 0 ; i < cl -> curr ; i ++ ) {
180+ if (pass_select_el (el , cl -> commands [i ]))
181+ return 1 ;
170182 }
171- return ret ;
183+ return cl -> curr == 0 ;
172184}
173185
174186int
0 commit comments