httpsrv

httpsrv.git
git clone git://git.lenczewski.org/httpsrv.git
Log | Files | Refs

tlsterm.c (842B)


      1 #include <assert.h>
      2 #include <stdbool.h>
      3 #include <stddef.h>
      4 #include <stdint.h>
      5 #include <stdio.h>
      6 #include <stdlib.h>
      7 #include <unistd.h>
      8 
      9 struct opts {
     10 	bool verbose;
     11 };
     12 
     13 static struct opts opts;
     14 static char const *optstr = "hv";
     15 
     16 static void
     17 usage(char *program)
     18 {
     19 	fprintf(stderr, "Usage: %s [-h] [-v]\n", program);
     20 	fprintf(stderr, "\t-h : display this help message\n");
     21 	fprintf(stderr, "\t-v : enable verbose logging\n");
     22 }
     23 
     24 static bool
     25 try_parse_args(int argc, char **argv)
     26 {
     27 	int chr;
     28 	while ((chr = getopt(argc, argv, optstr)) != -1) {
     29 		switch (chr) {
     30 		case 'v':
     31 			opts.verbose = true;
     32 			break;
     33 
     34 		default:
     35 			return false;
     36 		}
     37 	}
     38 
     39 	return true;
     40 }
     41 
     42 int
     43 main(int argc, char **argv)
     44 {
     45 	if (!try_parse_args(argc, argv)) {
     46 		usage(argv[0]);
     47 		exit(EXIT_FAILURE);
     48 	}
     49 
     50 	printf("Verbose? %d\n", opts.verbose);
     51 
     52 	exit(EXIT_SUCCESS);
     53 }