forked from Bs0Dd/Coverett
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathldevmet.c
71 lines (63 loc) · 1.66 KB
/
ldevmet.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
#include <stdio.h>
#include "coverett.h"
int main(int argc, char* argv[]){
if (argc < 2){
puts("List DEVice METhods");
puts("Usage: ldevmet <devname>");
return 0;
}
bus_t stdbus = openBus("/dev/hvc0");
device_t dev = findDev(stdbus, argv[1]);
if (!dev.exists){
fprintf(stderr, "Device \"%s\" is not found.\n", argv[1]);
closeBus(stdbus);
return -1;
}
list_t meth = getMethods(&dev);
if (meth.type == CO_ERROR){
fputs("Failed to get methods list.\n", stderr);
closeBus(stdbus);
return -1;
}
closeBus(stdbus);
int msiz;
method_t* mes = parseMethods(meth, &msiz);
deleteList(&meth);
if (mes == NULL){
fputs("Failed to parse methods list.\n", stderr);
return -1;
}
printf("Methods for device \"%s\":\n", argv[1]);
for (int i = 0; i < msiz; i++){
printf(" - %s(",mes[i].name);
int narg = 1;
for (int j = 0; j < mes[i].paramNum; j++){
if (mes[i].parameters[j].name){
printf("%s: ", mes[i].parameters[j].name);
} else{
printf("arg%d: ", narg++);
}
printf("%s", mes[i].parameters[j].type);
if (j+1 < mes[i].paramNum) printf(", ");
}
printf("): %s\n", mes[i].returnType);
if (mes[i].description != NULL){
printf(" %s", mes[i].description);
if (mes[i].description[strlen(mes[i].description)-1] != '\n') printf("\n");
}
narg = 1;
for (int j = 0; j < mes[i].paramNum; j++){
if (mes[i].parameters[j].description != NULL){
if (mes[i].parameters[j].name){
printf(" '%s' - ", mes[i].parameters[j].name);
} else{
printf(" 'arg%d' - ", narg++);
}
printf("%s\n", mes[i].parameters[j].description);
}
}
printf("\n");
}
deleteParsedMethods(mes, msiz);
return 0;
}