Skip to content

Commit 556a550

Browse files
committed
Cleanup
1 parent 699f1d1 commit 556a550

File tree

2 files changed

+15
-32
lines changed

2 files changed

+15
-32
lines changed

src/mad_select.c

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ get_select_ex_ranges(struct sequence* sequ, struct command_list* select, struct
102102
static int _pass_select_pat(const char* name, struct command* sc);
103103

104104
int
105-
pass_select(char* name, struct command* sc)
105+
pass_select(const char* name, struct command* sc)
106106
/* checks name against class (if element) and pattern that may
107107
(but need not) be contained in command sc;
108108
0: does not pass, 1: passes */
@@ -122,18 +122,12 @@ pass_select_el(struct element* el, struct command* sc)
122122
{
123123
struct name_list* nl = sc->par_names;
124124
struct command_parameter_list* pl = sc->par;
125-
int pos, in = 0, any = 0;
126-
char *class, *pattern;
127-
128-
pos = name_list_pos("class", nl);
125+
int pos = name_list_pos("class", nl);
129126
if (pos > -1 && nl->inform[pos]) /* parameter has been read */
130127
{
131-
if (el != NULL)
132-
{
133-
class = pl->parameters[pos]->string;
134-
in = belongs_to_class(el, class);
135-
if (in == 0) return 0;
136-
}
128+
char* class = pl->parameters[pos]->string;
129+
if (!belongs_to_class(el, class))
130+
return 0;
137131
}
138132
return _pass_select_pat(el->name, sc);
139133
}
@@ -144,11 +138,8 @@ int pass_select_str(const char* name, struct command* sc)
144138
(but need not) be contained in command sc;
145139
considers only SELECT commands *without CLASS*!
146140
0: does not pass, 1: passes */
147-
struct name_list* nl = sc->par_names;
148-
int pos;
149141
// if the command has CLASS attribute, it is supposed to match elements:
150-
pos = name_list_pos("class", nl);
151-
if (pos > -1 && nl->inform[pos]) /* parameter has been read */
142+
if (par_present("class", sc, NULL)) /* parameter has been read */
152143
return 0;
153144
return _pass_select_pat(name, sc);
154145
}
@@ -158,19 +149,13 @@ int _pass_select_pat(const char* name, struct command* sc)
158149
/* used internally. */
159150
struct name_list* nl = sc->par_names;
160151
struct command_parameter_list* pl = sc->par;
161-
int pos, in = 0, any = 0;
162-
char *pattern;
163-
164-
any = in = 0;
165-
pos = name_list_pos("pattern", nl);
152+
int pos = name_list_pos("pattern", nl);
166153
if (pos > -1 && nl->inform[pos]) /* parameter has been read */
167154
{
168-
any = 1;
169-
pattern = stolower(pl->parameters[pos]->string);
170-
if(myregex(pattern, strip(name)) == 0) in = 1;
155+
char* pattern = stolower(pl->parameters[pos]->string);
156+
return myregex(pattern, strip(name)) == 0;
171157
}
172-
if (any == 0) return 1;
173-
else return in;
158+
return 1;
174159
}
175160

176161
int
@@ -191,13 +176,11 @@ pass_select_list_el(struct element* el, struct command_list* cl)
191176
/* Should use this function in favor of `pass_select_list` where possible. It
192177
works for all elements and is faster if knowing the element in advance. */
193178
{
194-
int i, ret = 0;
195-
if (cl->curr == 0) return 1;
196-
for (i = 0; i < cl->curr; i++)
197-
{
198-
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;
199182
}
200-
return ret;
183+
return cl->curr == 0;
201184
}
202185

203186
int

src/mad_select.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ struct element;
1818

1919
void store_select(struct in_cmd*);
2020
void store_deselect(struct in_cmd*);
21-
int pass_select(char* name, struct command*); // deprecated
21+
int pass_select(const char* name, struct command*); // deprecated
2222
int pass_select_str(const char* name, struct command*); // not for elements!
2323
int pass_select_el(struct element* el, struct command*);
2424
int pass_select_list_str(const char* name, struct command_list*); // not for elements!

0 commit comments

Comments
 (0)