From ffeabaef68b8beec85ef60a3f1a9a2343ae939f2 Mon Sep 17 00:00:00 2001 From: Teemu Murtola Date: Mon, 26 Apr 2010 17:28:22 +0200 Subject: [PATCH] Added some synonyms for common selection keywords. --- src/gmxlib/selection/selhelp.c | 9 ++++- src/gmxlib/selection/selmethod.c | 86 ++++++++++++++++++++++++++-------------- 2 files changed, 64 insertions(+), 31 deletions(-) diff --git a/src/gmxlib/selection/selhelp.c b/src/gmxlib/selection/selhelp.c index 74e77e8d18..6245f084cf 100644 --- a/src/gmxlib/selection/selhelp.c +++ b/src/gmxlib/selection/selhelp.c @@ -325,7 +325,14 @@ print_keyword_list(struct gmx_ana_selcollection_t *sc, e_selvalue_t type, } else { - fprintf(stderr, "%s\n", method->name); + const char *symname = _gmx_sel_sym_name(symbol); + + fprintf(stderr, "%s", symname); + if (strcmp(symname, method->name) != 0) + { + fprintf(stderr, " (synonym for %s)", method->name); + } + fprintf(stderr, "\n"); } } symbol = _gmx_sel_next_symbol(symbol, SYMBOL_METHOD); diff --git a/src/gmxlib/selection/selmethod.c b/src/gmxlib/selection/selmethod.c index 72466402b9..d4899068bf 100644 --- a/src/gmxlib/selection/selmethod.c +++ b/src/gmxlib/selection/selmethod.c @@ -102,39 +102,56 @@ extern gmx_ana_selmethod_t sm_plus; /* From sm_permute.c */ extern gmx_ana_selmethod_t sm_permute; +/*! \brief + * Helper structure for defining selection methods. + */ +typedef struct { + /*! \brief + * Name to register the method under. + * + * If NULL, use the actual name of the method. + * This field is used for defining synonyms. + */ + const char *name; + /** Method data structure to register. */ + gmx_ana_selmethod_t *method; +} t_register_method; + /** Array of selection methods defined in the library. */ -static gmx_ana_selmethod_t *const smtable_def[] = { - &sm_cog, - &sm_com, +static const t_register_method smtable_def[] = { + {NULL, &sm_cog}, + {NULL, &sm_com}, - &sm_all, - &sm_none, - &sm_atomnr, - &sm_resnr, - &sm_resind, - &sm_atomname, - &sm_atomtype, - &sm_resname, - &sm_insertcode, - &sm_chain, - &sm_mass, - &sm_charge, - &sm_altloc, - &sm_occupancy, - &sm_betafactor, - &sm_x, - &sm_y, - &sm_z, + {NULL, &sm_all}, + {NULL, &sm_none}, + {NULL, &sm_atomnr}, + {NULL, &sm_resnr}, + {"resid", &sm_resnr}, + {NULL, &sm_resind}, + {"residue", &sm_resind}, + {NULL, &sm_atomname}, + {NULL, &sm_atomtype}, + {NULL, &sm_resname}, + {NULL, &sm_insertcode}, + {NULL, &sm_chain}, + {NULL, &sm_mass}, + {NULL, &sm_charge}, + {NULL, &sm_altloc}, + {NULL, &sm_occupancy}, + {NULL, &sm_betafactor}, + {NULL, &sm_x}, + {NULL, &sm_y}, + {NULL, &sm_z}, - &sm_distance, - &sm_mindistance, - &sm_within, - &sm_insolidangle, - &sm_same, + {NULL, &sm_distance}, + {NULL, &sm_mindistance}, + {NULL, &sm_within}, + {NULL, &sm_insolidangle}, + {NULL, &sm_same}, - &sm_merge, - &sm_plus, - &sm_permute, + {NULL, &sm_merge}, + {NULL, &sm_plus}, + {NULL, &sm_permute}, }; /*! \brief @@ -651,7 +668,16 @@ gmx_ana_selmethod_register_defaults(struct gmx_ana_selcollection_t *sc) bOk = TRUE; for (i = 0; i < asize(smtable_def); ++i) { - rc = gmx_ana_selmethod_register(sc, smtable_def[i]->name, smtable_def[i]); + gmx_ana_selmethod_t *method = smtable_def[i].method; + + if (smtable_def[i].name == NULL) + { + rc = gmx_ana_selmethod_register(sc, method->name, method); + } + else + { + rc = gmx_ana_selmethod_register(sc, smtable_def[i].name, method); + } if (rc != 0) { bOk = FALSE; -- 2.11.4.GIT