dwmblocks

Kris's build of dwmblocks
git clone git clone https://git.krisyotam.com/krisyotam/dwmblocks.git
Log | Files | Refs | README | LICENSE

cli.c (860B)


      1 #include "cli.h"
      2 
      3 #include <errno.h>
      4 #include <getopt.h>
      5 #include <stdbool.h>
      6 #include <stdio.h>
      7 
      8 cli_arguments cli_parse_arguments(const char* const argv[], const int argc) {
      9     errno = 0;
     10     cli_arguments args = {
     11         .is_debug_mode = false,
     12     };
     13 
     14     int opt = -1;
     15     opterr = 0;  // Suppress getopt's built-in invalid opt message
     16     while ((opt = getopt(argc, (char* const*)argv, "dh")) != -1) {
     17         switch (opt) {
     18             case 'd':
     19                 args.is_debug_mode = true;
     20                 break;
     21             case '?':
     22                 (void)fprintf(stderr, "error: unknown option `-%c'\n", optopt);
     23                 // fall through
     24             case 'h':
     25                 // fall through
     26             default:
     27                 (void)fprintf(stderr, "usage: %s [-d]\n", BINARY);
     28                 errno = 1;
     29         }
     30     }
     31 
     32     return args;
     33 }