From 27b67a82da3136ab726fe673567677ce9ea28da5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Fillod=2C=20F8CFE?= Date: Tue, 9 Jul 2002 20:36:07 +0000 Subject: [PATCH] Initial release git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@1110 7ae35d74-ebe9-4afe-98af-79ac388436b8 --- src/ext.c | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 src/ext.c diff --git a/src/ext.c b/src/ext.c new file mode 100644 index 000000000..3925eb918 --- /dev/null +++ b/src/ext.c @@ -0,0 +1,115 @@ +/* + * Hamlib Interface - extrq parameter interface + * Copyright (c) 2000,2001,2002 by Stephane Fillod + * + * $Id: ext.c,v 1.1 2002-07-09 20:36:07 fillods Exp $ + * + * This library is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include /* Standard input/output definitions */ +#include /* String function definitions */ +#include /* UNIX standard function definitions */ + +#include + +#include "token.h" + + + +/* + * rig_ext_level_foreach + * executes cfunc on all the elements stored in the extlevels table + */ +int rig_ext_level_foreach(RIG *rig, int (*cfunc)(RIG *, const struct confparams *, rig_ptr_t), rig_ptr_t data) +{ + const struct confparams *cfp; + + if (!rig || !rig->caps || !cfunc) + return -RIG_EINVAL; + + for (cfp = rig->caps->extlevels; cfp && cfp->name; cfp++) + if ((*cfunc)(rig, cfp, data) == 0) + return RIG_OK; + + return RIG_OK; +} + +/* + * rig_ext_parm_foreach + * executes cfunc on all the elements stored in the extparms table + */ +int rig_ext_parm_foreach(RIG *rig, int (*cfunc)(RIG *, const struct confparams *, rig_ptr_t), rig_ptr_t data) +{ + const struct confparams *cfp; + + if (!rig || !rig->caps || !cfunc) + return -RIG_EINVAL; + + for (cfp = rig->caps->extparms; cfp && cfp->name; cfp++) + if ((*cfunc)(rig, cfp, data) == 0) + return RIG_OK; + + return RIG_OK; +} + + + +/* + * lookup ext token by its name, return pointer to confparams struct. + * + * lookup extlevels table first, then fall back to extparms. + * + * Returns NULL if nothing found + * TODO: should use Lex to speed it up, strcmp hurts! + */ +const struct confparams *rig_ext_lookup(RIG *rig, const char *name) +{ + const struct confparams *cfp; + + if (!rig || !rig->caps) + return NULL; + + for (cfp = rig->caps->extlevels; cfp && cfp->name; cfp++) + if (!strcmp(cfp->name, name)) + return cfp; + for (cfp = rig->caps->extparms; cfp->name; cfp++) + if (!strcmp(cfp->name, name)) + return cfp; + return NULL; +} + +/* + * Simple lookup returning token id assicated with name + */ +token_t rig_ext_token_lookup(RIG *rig, const char *name) +{ + const struct confparams *cfp; + + cfp = rig_ext_lookup(rig, name); + if (!cfp) + return RIG_CONF_END; + + return cfp->token; +} + +