File: cmdln_parse.c

package info (click to toggle)
sphinxbase 0.8%2B5prealpha-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 10,592 kB
  • ctags: 3,296
  • sloc: ansic: 29,950; sh: 11,802; makefile: 679; python: 335; perl: 121; yacc: 93; lex: 50
file content (31 lines) | stat: -rw-r--r-- 831 bytes parent folder | download | duplicates (6)
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
/* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */

#include <stdio.h>
#include <string.h>

#include "cmd_ln.h"
#include "ckd_alloc.h"

const arg_t defs[] = {
    { "-a", ARG_INT32, "42", "This is the first argument." },
    { "-b", ARG_STRING, NULL, "This is the second argument." },
    { "-c", ARG_BOOLEAN, "no", "This is the third argument." },
    { "-d", ARG_FLOAT64, "1e-50", "This is the fourth argument." },
    { "-l", ARG_STRING_LIST, NULL, "This is the fifth argument." },
    { NULL, 0, NULL, NULL }
};

int
main(int argc, char *argv[])
{
    cmd_ln_parse(defs, argc, argv, TRUE);
    printf("%d %s %d %f\n",
           cmd_ln_int32("-a"),
           cmd_ln_str("-b") ? cmd_ln_str("-b") : "(null)",
           cmd_ln_boolean("-c"),
           cmd_ln_float64("-d"));
           
    cmd_ln_free();

    return 0;
}