1 /* flex - tool to generate fast lexical analyzers */
3 /* Copyright (c) 1990 The Regents of the University of California. */
4 /* All rights reserved. */
6 /* This code is derived from software contributed to Berkeley by */
9 /* The United States Government has rights in this work pursuant */
10 /* to contract no. DE-AC03-76SF00098 between the United States */
11 /* Department of Energy and the University of California. */
13 /* This file is part of flex. */
15 /* Redistribution and use in source and binary forms, with or without */
16 /* modification, are permitted provided that the following conditions */
19 /* 1. Redistributions of source code must retain the above copyright */
20 /* notice, this list of conditions and the following disclaimer. */
21 /* 2. Redistributions in binary form must reproduce the above copyright */
22 /* notice, this list of conditions and the following disclaimer in the */
23 /* documentation and/or other materials provided with the distribution. */
25 /* Neither the name of the University nor the names of its contributors */
26 /* may be used to endorse or promote products derived from this software */
27 /* without specific prior written permission. */
29 /* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR */
30 /* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED */
31 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */
40 #ifndef NO_SCANOPT_USAGE
41 /* Used by scanopt_usage for pretty-printing. */
51 #define PROTO(args) args
53 /* Error codes. */ enum scanopt_err_t
{
54 SCANOPT_ERR_OPT_UNRECOGNIZED
= -1, /* Unrecognized option. */
55 SCANOPT_ERR_OPT_AMBIGUOUS
= -2, /* It matched more than one option name. */
56 SCANOPT_ERR_ARG_NOT_FOUND
= -3, /* The required arg was not found. */
57 SCANOPT_ERR_ARG_NOT_ALLOWED
= -4 /* Option does not take an argument. */
61 /* flags passed to scanopt_init */
63 SCANOPT_NO_ERR_MSG
= 0x01 /* Suppress printing to stderr. */
66 /* Specification for a single option. */
68 const char *opt_fmt
; /* e.g., "--foo=FILE", "-f FILE", "-n [NUM]" */
69 int r_val
; /* Value to be returned by scanopt_ex(). */
70 const char *desc
; /* Brief description of this option, or NULL. */
72 typedef struct optspec_t optspec_t
;
75 /* Used internally by scanopt() to maintain state. */
76 /* Never modify these value directly. */
77 typedef void *scanopt_t
;
80 /* Initializes scanner and checks option list for errors.
82 * options - Array of options.
83 * argc - Same as passed to main().
84 * argv - Same as passed to main(). First element is skipped.
85 * flags - Control behavior.
86 * Return: A malloc'd pointer .
88 scanopt_t
*scanopt_init
PROTO ((const optspec_t
* options
,
89 int argc
, char **argv
, int flags
));
91 /* Frees memory used by scanner.
92 * Always returns 0. */
93 int scanopt_destroy
PROTO ((scanopt_t
* scanner
));
95 #ifndef NO_SCANOPT_USAGE
96 /* Prints a usage message based on contents of optlist.
98 * scanner - The scanner, already initialized with scanopt_init().
99 * fp - The file stream to write to.
100 * usage - Text to be prepended to option list. May be NULL.
101 * Return: Always returns 0 (zero).
105 (scanopt_t
* scanner
, FILE * fp
,
109 /* Scans command-line options in argv[].
111 * scanner - The scanner, already initialized with scanopt_init().
112 * optarg - Return argument, may be NULL.
113 * On success, it points to start of an argument.
114 * optindex - Return argument, may be NULL.
115 * On success or failure, it is the index of this option.
116 * If return is zero, then optindex is the NEXT valid option index.
118 * Return: > 0 on success. Return value is from optspec_t->rval.
119 * == 0 if at end of options.
120 * < 0 on error (return value is an error code).
125 (scanopt_t
* scanner
, char **optarg
,
132 /* vim:set tabstop=8 softtabstop=4 shiftwidth=4: */