2 * Copyright (C) 1995-2007, Index Data ApS
3 * See the file LICENSE for details.
5 * $Id: options.c,v 1.7 2008-02-20 10:03:42 adam Exp $
9 * \brief Implements command line options parsing
17 #include <yaz/options.h>
19 static int arg_no = 1;
20 static int arg_off = 0;
22 int options (const char *desc, char **argv, int argc, char **arg)
24 const char *opt_buf = 0;
32 while (argv[arg_no][0] == '\0')
38 if (argv[arg_no][0] != '-' || argv[arg_no][1] == '\0')
40 *arg = argv[arg_no++];
43 arg_off++; /* skip - */
45 if (argv[arg_no][1] == '-')
47 opt_buf = argv[arg_no]+2;
48 arg_off = strlen(argv[arg_no]);
51 { /* single char opt */
52 ch = argv[arg_no][arg_off++];
56 int desc_char = desc[i++];
58 while (desc[i] == '{')
61 while (desc[i] && desc[i] != '}')
63 if (opt_buf && (i - i0) == strlen(opt_buf) &&
64 memcmp(opt_buf, desc+i0, i - i0) == 0)
70 { /* option with string argument */
75 if (type) /* option with argument */
77 if (argv[arg_no][arg_off])
79 *arg = argv[arg_no]+arg_off;
88 *arg = argv[arg_no++];
93 else /* option with no argument */
95 if (argv[arg_no][arg_off])
106 *arg = argv[arg_no]+arg_off-1;
114 * indent-tabs-mode: nil
116 * vim: shiftwidth=4 tabstop=8 expandtab