[go: up one dir, main page]

Menu

[c11636]: / src / ext.c  Maximize  Restore  History

Download this file

116 lines (91 with data), 3.0 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
* Hamlib Interface - extrq parameter interface
* Copyright (c) 2000,2001,2002 by Stephane Fillod
*
* $Id: ext.c,v 1.2 2002-09-18 21:19:39 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 <stdlib.h>
#include <stdarg.h>
#include <stdio.h> /* Standard input/output definitions */
#include <string.h> /* String function definitions */
#include <unistd.h> /* UNIX standard function definitions */
#include <hamlib/rig.h>
#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 && 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;
}