Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix selecting by class=variable or class=sequence #699

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/latexuguide/control.tex
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ \section{SELECT}
SELECT, FLAG=SAVE, CLASS=variable, PATTERN="abc.*"; \\
SAVE, FILE=mysave;
}
saves all variables (and sequences) containing "abc" in their name,
saves all variables containing "abc" in their name,
but does not save elements with names containing "abc" since the class
"variable" does not exist.

Expand Down
6 changes: 3 additions & 3 deletions doc/latexuguide/tables.tex
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ \section{SHRINK}
%% select, flag=save, class=variable, pattern="abc.*";
%% save, file=mysave;
%% \end{verbatim}
%% will save all variables (and sequences) containing "abc" in their name.
%% will save all variables containing "abc" in their name.
%% However note that since the element class "variable" does not exist, any
%% element with name containing "abc" will not be saved.

Expand Down Expand Up @@ -437,7 +437,7 @@ \section{SHRINK}
%% select, flag=save, class=variable, pattern="abc.*";
%% save, file=mysave;
%% \end{verbatim}
%% will save all variables (and sequences) containing "abc" in their name,
%% will save all variables containing "abc" in their name,
%% but not elements with names containing "abc" since the class "variable"
%% does not exist (astucieux, non ?).

Expand Down Expand Up @@ -830,7 +830,7 @@ \section{SHRINK}
%% select, flag=save, class=variable, pattern="abc.*";
%% save, file=mysave;
%% \end{verbatim}
%% will save all variables (and sequences) containing "abc" in their name,
%% will save all variables containing "abc" in their name,
%% but not elements with names containing "abc" since the class "variable"
%% does not exist (astucieux, non ?).

Expand Down
14 changes: 7 additions & 7 deletions src/mad_select.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ pass_select(const char* name, struct command* sc)
/* Don't use for selecting elements. It may not find all elements. */
{
struct element* el = find_element(strip(name), element_list);
return el ? pass_select_el(el, sc) : pass_select_str(name, sc);
return el ? pass_select_el(el, sc) : pass_select_str(name, NULL, sc);
}

int
Expand All @@ -126,14 +126,14 @@ pass_select_el(struct element* el, struct command* sc)
return _pass_select_pat(el->name, sc);
}

int pass_select_str(const char* name, struct command* sc)
int pass_select_str(const char* name, const char* class, struct command* sc)
{
/* checks name against pattern that may
(but need not) be contained in command sc;
considers only SELECT commands *without CLASS*!
considers only SELECT commands with the given class!
0: does not pass, 1: passes */
// if the command has CLASS attribute, it is supposed to match elements:
if (par_present("class", sc)) /* parameter has been read */
char* selected_class = command_par_string_user("class", sc);
if (selected_class && class && strcmp(selected_class, class) != 0)
return 0;
return _pass_select_pat(name, sc);
}
Expand All @@ -146,12 +146,12 @@ int _pass_select_pat(const char* name, struct command* sc)
}

int
pass_select_list_str(const char* name, struct command_list* cl)
pass_select_list_str(const char* name, const char* class, struct command_list* cl)
/* returns 0 (does not pass) or 1 (passes) for a list of selects */
/* Don't use for selecting elements! It may not find all elements. */
{
for (int i = 0; i < cl->curr; i++) {
if (pass_select_str(name, cl->commands[i]))
if (pass_select_str(name, class, cl->commands[i]))
return 1;
}
return cl->curr == 0;
Expand Down
4 changes: 2 additions & 2 deletions src/mad_select.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ struct element;
void store_select(struct in_cmd*);
void store_deselect(struct in_cmd*);
int pass_select(const char* name, struct command*); // deprecated
int pass_select_str(const char* name, struct command*); // not for elements!
int pass_select_str(const char* name, const char* class_, struct command*); // not for elements!
int pass_select_el(struct element* el, struct command*);
int pass_select_list_str(const char* name, struct command_list*); // not for elements!
int pass_select_list_str(const char* name, const char* class_, struct command_list*); // not for elements!
int pass_select_list_el(struct element* el, struct command_list*);
void get_select_t_ranges(struct command_list* select, struct command_list* deselect, struct table*);
int get_select_ranges(struct sequence* sequ, struct command_list* select, struct node_list* s_ranges);
Expand Down
4 changes: 2 additions & 2 deletions src/mad_seq.c
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ export_sequ_8(struct sequence* sequ, struct command_list* cl, FILE* file)

seqref = sequ->ref_flag; /* uncomment line to get entry or exit */

if (pass_select_list_str(sequ->name, cl) == 0) return;
if (pass_select_list_str(sequ->name, "sequence", cl) == 0) return;

*c_dum->c = '\0';
strcat(c_dum->c, sequ->export_name);
Expand Down Expand Up @@ -816,7 +816,7 @@ write_sequs(struct sequence_list* sql,struct command_list* cl, FILE* file, int n
for (i = 0; i < sql->curr; i++)
if(sql->sequs[i]->nested == j)
{
if (pass_select_list_str(sql->sequs[i]->name, cl))
if (pass_select_list_str(sql->sequs[i]->name, "sequence", cl))
export_sequence(sql->sequs[i], file, noexpr);
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/mad_var.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ void
write_vars(struct var_list* varl, struct command_list* cl, FILE* file, int noexpr)
{
for (int i = 0; i < varl->curr; i++) {
if (predef_var(varl->vars[i]) == 0 && pass_select_list_str(varl->vars[i]->name, cl))
if (predef_var(varl->vars[i]) == 0 &&
pass_select_list_str(varl->vars[i]->name, "variable", cl))
export_variable(varl->vars[i], file, noexpr);
}
}
Expand All @@ -265,7 +266,7 @@ write_vars_8(struct var_list* varl, struct command_list* cl, FILE* file)
for (i = 0; i < varl->curr; i++)
{
if (predef_var(varl->vars[i]) == 0
&& pass_select_list_str(varl->vars[i]->name, cl))
&& pass_select_list_str(varl->vars[i]->name, "variable", cl))
export_var_8(varl->vars[i], file);
}
}
Expand Down