-
Notifications
You must be signed in to change notification settings - Fork 10
/
opkinfo.c
49 lines (39 loc) · 957 Bytes
/
opkinfo.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
#include "opk.h"
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
static bool display_info(char *package_path) {
printf("=== %s\n", package_path);
struct OPK *opk = opk_open(package_path);
if (!opk) {
fprintf(stderr, "Failed to open %s\n", package_path);
printf("\n");
return false;
}
bool ok = true;
while (true) {
const char *metadata_name;
if (opk_open_metadata(opk, &metadata_name) <= 0)
break;
const char *key, *val;
size_t skey, sval;
printf("\n");
printf("Metadata file: %s\n\n", metadata_name);
while(opk_read_pair(opk, &key, &skey, &val, &sval) && key)
printf("%.*s: %.*s\n", (int) skey, key, (int) sval, val);
}
opk_close(opk);
printf("\n");
return ok;
}
int main(int argc, char **argv) {
if (argc == 1) {
fprintf(stderr, "Usage: opkinfo app1.opk [app2.opk ...]\n");
exit(2);
}
bool ok = true;
for (int i = 1; i < argc; i++) {
ok &= display_info(argv[i]);
}
exit(ok ? 0 : 1);
}