forked from OE4T/tegra-eeprom-tool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtegra-boardspec.c
96 lines (79 loc) · 1.59 KB
/
tegra-boardspec.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
/*
* tegra-boardspec
*
* Extracts board information from the CVM EEPROM.
*
* Copyright (c) 2020 Matthew Madison
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <getopt.h>
#include <errno.h>
#include <libgen.h>
#include "boardspec.h"
static struct option options[] = {
{ "help", no_argument, 0, 'h' },
{ 0, 0, 0, 0 }
};
static const char *shortopts = ":h";
static char *optarghelp[] = {
"--help ",
};
static char *opthelp[] = {
"display this help text",
};
static char *progname;
static void
print_usage (void)
{
int i;
printf("\nOptions:\n");
for (i = 0; i < sizeof(options)/sizeof(options[0]) && options[i].name != 0; i++) {
printf(" %s\t%c%c\t%s\n",
optarghelp[i],
(options[i].val == 0 ? ' ' : '-'),
(options[i].val == 0 ? ' ' : options[i].val),
opthelp[i]);
}
} /* print_usage */
/*
* main program
*/
int
main (int argc, char * const argv[])
{
int c, which, ret, len;
char specbuf[128];
char *argv0_copy = strdup(argv[0]);
progname = basename(argv0_copy);
for (;;) {
c = getopt_long_only(argc, argv, shortopts, options, &which);
if (c == -1)
break;
switch (c) {
case 'h':
print_usage();
ret = 0;
goto depart;
default:
fprintf(stderr, "Error: unrecognized option\n");
print_usage();
ret = 1;
goto depart;
}
}
argc -= optind;
argv += optind;
len = tegra_boardspec(specbuf, sizeof(specbuf)-1);
if (len < 0) {
perror("tegra_boardspec");
ret = 1;
}
specbuf[len] = '\0';
printf("%s\n", specbuf);
ret = 0;
depart:
free(argv0_copy);
return ret;
} /* main */