File: jx_getopt.h

package info (click to toggle)
cctools 9.9-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 44,624 kB
  • sloc: ansic: 192,539; python: 20,827; cpp: 20,199; sh: 11,719; perl: 4,106; xml: 3,688; makefile: 1,224
file content (44 lines) | stat: -rw-r--r-- 1,507 bytes parent folder | download | duplicates (3)
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
34
35
36
37
38
39
40
41
42
43
44
/*
Copyright (C) 2018- The University of Notre Dame
This software is distributed under the GNU General Public License.
See the file COPYING for details.
*/

/** @file jx_getopt.h Pull command line args from a JSON document.
 *
 * This is a wrapper around getopt_long that supports reading arguments
 * from a JX object during command line parsing. The object's keys are
 * interpreted as long option names, and the values are stored in optarg.
 * Currently only string, integer, float, and boolean values are written
 * to optarg. Other value types result in optarg being set to NULL. To
 * access the raw JX struture provided as an option argument, callers
 * can inspect jx_optarg. JX-aware programs can check jx_optarg when
 * reading JX values from the command line to simplify parsing and avoid
 * quoting issues.
 */

#ifndef JX_GETOPT_H
#define JX_GETOPT_H

#include <unistd.h>
#include <getopt.h>

#include "jx.h"

extern struct jx *jx_optarg;

/** Process command lines from a JX document.
 * The pushed args will be processesed next, before any remaining command line
 * args or previously pushed JX args.
 * @param j The args to process.
 */
void jx_getopt_push(struct jx *j);

/** Parse the next argument.
 * If there are no JX args to be processed, this is the same as calling
 * getopt_long() directly.
 * @returns 0 on error. Do not use this as a valid option val.
 */
int jx_getopt(int argc, char *const argv[], const char *optstring, const struct option *longopts, int *longindex);

#endif