File: cli_arg.h

package info (click to toggle)
staden 2.0.0%2Bb11-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 21,584 kB
  • sloc: ansic: 240,605; tcl: 65,360; cpp: 12,854; makefile: 11,203; sh: 3,023; fortran: 2,033; perl: 63; awk: 46
file content (33 lines) | stat: -rw-r--r-- 949 bytes parent folder | download | duplicates (5)
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
#ifndef _CLI_ARG_H_
#define _CLI_ARG_H_

#include <stddef.h>

#define ARG_INT    1
#define ARG_STR    2
#define ARG_IO     3
#define ARG_ARR    4
#define ARG_FLOAT  5
#define ARG_DOUBLE 6

#define offsetofa(type, field) ((int) ((char *) ((type *)0)->field))

typedef struct {
    char *command;	/* What to recognise, including the '-' symbol */
    int type;		/* ARG_??? */
    int value;		/* Set if this argument takes an argument */
    char *def;		/* NULL if non optional argument */
    int offset;		/* Offset into the 'store' address */
} cli_args;


/*
 * Parses command line arguments.
 * 'args' specifies an array cli_args. Each cli_arg contains a default. Each
 * argument with a default of NULL are non optional. This function will return
 * -1 if any of these arguments aren't specified, or if unknown arguments
 * are specified. Returns 0 otherwise.
 */
extern int parse_args(cli_args *args, void *store, int argc, char **argv);

#endif