-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.c
105 lines (96 loc) · 3.15 KB
/
helper.c
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
#ifdef __cplusplus
using namespace oyranos;
extern "C" {
#endif /* __cplusplus */
#include <sane/sane.h>
#include <oyranos/oyranos_cmm.h>
#include <oyranos/oyranos_alpha.h>
static const char *oyValueTypeText( oyVALUETYPE_e type )
{
switch(type)
{
case oyVAL_INT: return "Int";
case oyVAL_DOUBLE: return "Double";
case oyVAL_INT_LIST: return "IntList";
case oyVAL_DOUBLE_LIST: return "DoubleList";
case oyVAL_STRING: return "String";
case oyVAL_STRING_LIST: return "StringList";
case oyVAL_STRUCT: return "Struct";
}
return 0;
}
static void print_option(oyOption_s * opt, int j)
{
int id = oyOption_GetId(opt);
if (opt->value_type == oyVAL_STRUCT) {
oyStruct_s *opt_struct = opt->value->oy_struct;
oyCMMptr_s *cmm = NULL;
oyBlob_s *blob = NULL;
switch (opt_struct->type_) {
case oyOBJECT_CMM_POINTER_S:
cmm = (oyCMMptr_s*)opt_struct;
if (strcmp(cmm->lib_name,"SANE") == 0)
printf("\t\t[%s]\n\t\tOption[%d] ID=%d\tCMMptr{%p,%s}\n\n",
opt->registration, j, id, cmm->ptr, cmm->lib_name);
break;
case oyOBJECT_BLOB_S:
blob = (oyBlob_s *)opt_struct;
printf("\t\t[%s]\n\t\tOption[%d] ID=%d\tblob{%p,%d}\n\n",
opt->registration, j, id, blob->ptr, blob->size);
break;
default:
printf("\t\tCan't handle struct of type %d\n", opt_struct->type_);
break;
}
} else {
char *text = oyOption_GetValueText(opt, malloc);
const char *type = oyValueTypeText(opt->value_type);
printf("\t\t[%s]\n\t\tOption[%d] ID=%d\t%s{%s}\n\n",
opt->registration, j, id, type, text);
free(text);
}
}
static int print_options(oyOptions_s * options)
{
int j;
int num_options = oyOptions_Count(options);
printf("Found %d option%s\n", num_options, num_options > 1 ? "s" : "");
for (j = 0; j < num_options; j++) {
oyOption_s *opt = oyOptions_Get(options, j);
print_option(opt, j);
oyOption_Release(&opt);
}
return num_options;
}
static void print_device(oyConfig_s *device)
{
int j;
int num_options = oyConfig_Count(device);
printf("\tFound %d option%s for device\n", num_options, num_options > 1 ? "s" : "");
for (j = 0; j < num_options; j++) {
oyOption_s *opt = oyConfig_Get(device, j);
print_option(opt, j);
oyOption_Release(&opt);
}
}
static int print_devices(oyConfigs_s * devices, const char *name)
{
int i,j;
int num_devices = oyConfigs_Count(devices);
printf("Found %d %s device%s\n", num_devices, name, num_devices > 1 ? "s" : "");
for (i = 0; i < num_devices; i++) {
oyConfig_s *device = oyConfigs_Get(devices, i);
int num_options = oyConfig_Count(device);
printf("\tFound %d option%s for device %d\n", num_options, num_options > 1 ? "s" : "", i);
for (j = 0; j < num_options; j++) {
oyOption_s *opt = oyConfig_Get(device, j);
print_option(opt, j);
oyOption_Release(&opt);
}
oyConfig_Release(&device);
}
return num_devices;
}
#ifdef __cplusplus
} /* extern "C" */
#endif /* __cplusplus */