summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorLucas De Marchi <lucas.demarchi@intel.com>2024-05-01 12:33:01 -0500
committerLucas De Marchi <lucas.demarchi@intel.com>2024-05-08 05:31:56 -0700
commit268e107e4eb5a321094f49501ea9a549e508543b (patch)
tree87df4244dcb2e5e8cecceaad6f95ae67adf8a2f5 /tools
parente8861cad28fdd4c9fe6ef712cb9ad16eb2fcaff5 (diff)
gputop: Add option parsing
Add skeleton for option parsing, with just a -h/--help to be used for additional options later. Reviewed-by: Kamil Konieczny <kamil.konieczny@linux.intel.com> Link: https://lore.kernel.org/r/20240501173303.115737-3-lucas.demarchi@intel.com Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/gputop.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/tools/gputop.c b/tools/gputop.c
index 7fd9e9790..481e79753 100644
--- a/tools/gputop.c
+++ b/tools/gputop.c
@@ -292,11 +292,62 @@ static void clrscr(void)
printf("\033[H\033[J");
}
+struct gputop_args {
+};
+
+static void help(void)
+{
+ printf("Usage:\n"
+ "\t%s [options]\n\n"
+ "Options:\n"
+ "\t-h, --help show this help\n"
+ , program_invocation_short_name);
+}
+
+static int parse_args(int argc, char * const argv[], struct gputop_args *args)
+{
+ static const char cmdopts_s[] = "h";
+ static const struct option cmdopts[] = {
+ {"help", no_argument, 0, 'h'},
+ { }
+ };
+
+ /* defaults */
+ memset(args, 0, sizeof(*args));
+
+ for (;;) {
+ int c, idx = 0;
+
+ c = getopt_long(argc, argv, cmdopts_s, cmdopts, &idx);
+ if (c == -1)
+ break;
+
+ switch (c) {
+ case 'h':
+ help();
+ return 0;
+ default:
+ fprintf(stderr, "Unkonwn option '%c'.\n", c);
+ return -1;
+ }
+ }
+
+ return 1;
+}
+
int main(int argc, char **argv)
{
+ struct gputop_args args;
unsigned int period_us = 2e6;
struct igt_drm_clients *clients = NULL;
int con_w = -1, con_h = -1;
+ int ret;
+
+ ret = parse_args(argc, argv, &args);
+ if (ret < 0)
+ return EXIT_FAILURE;
+ if (!ret)
+ return EXIT_SUCCESS;
clients = igt_drm_clients_init(NULL);
if (!clients)