c-argh/example.c

23 lines
685 B
C
Raw Normal View History

2020-07-12 21:23:05 +02:00
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "argh.h"
2020-07-12 21:27:35 +02:00
#define USAGE "example [-l|--lz4] [-h N|--head N] [-p|--prefix] POS1 ... POSN"
2020-07-12 21:23:05 +02:00
int main(int argc, char **argv) {
bool prefix = false;
bool lz4 = false;
int head = 0;
ARGH_PARSE {
ARGH_NEXT();
if ARGH_BOOL("-p", "--prefix") { prefix = true;}
else if ARGH_BOOL("-l", "--lz4") { lz4 = true; }
else if ARGH_FLAG("-h", "--head") { head = atoi(ARGH_VAL()); }
2020-07-12 21:23:05 +02:00
}
printf("head: %d, prefix: %d, lz4: %d\n", head, prefix, lz4);
for (int i = 0; i < ARGH_ARGC; i++)
printf("positional arg %d: %s\n", i, ARGH_ARGV[i]);
}