File: hamlibmodels.c

package info (click to toggle)
hamlib 4.6.5-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 17,984 kB
  • sloc: ansic: 262,996; sh: 6,135; cpp: 1,578; perl: 876; makefile: 855; python: 148; awk: 58; xml: 26
file content (38 lines) | stat: -rw-r--r-- 930 bytes parent folder | download | duplicates (2)
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
/* Example showing host to list all models */
#include <stdio.h>
#include <stdlib.h>
#include <hamlib/rig.h>

char *list[1000]; // as of 2023-01-17 we have 275 rigs so this should cover us for long time

int nmodels = 0;

static int hash_model_list(const struct rig_caps *caps, void *data)
{
    char s[256];
    sprintf(s, "%s %s", caps->mfg_name, caps->model_name);
    list[nmodels] = strdup(s);
    ++nmodels;
    return 1;  /* !=0, we want them all ! */
}

int mycmp(const void *p1, const void *p2)
{
    const  char **s1 = (const char **)p1;
    const  char **s2 = (const char **)p2;
    return strcasecmp(*s1, *s2);
}

int main()
{
    rig_set_debug_level(RIG_DEBUG_NONE);
    rig_load_all_backends();
    rig_list_foreach(hash_model_list, NULL);
    qsort(list, nmodels, sizeof(list) / 1000, mycmp);

    for (int i = 0; i < nmodels; ++i) { printf("%s\n", list[i]); }

    printf("%d models\n", nmodels);

    return 0;
}