Blame src/scanopt.h

Packit f00812
/* flex - tool to generate fast lexical analyzers */
Packit f00812
Packit f00812
/*  Copyright (c) 1990 The Regents of the University of California. */
Packit f00812
/*  All rights reserved. */
Packit f00812
Packit f00812
/*  This code is derived from software contributed to Berkeley by */
Packit f00812
/*  Vern Paxson. */
Packit f00812
Packit f00812
/*  The United States Government has rights in this work pursuant */
Packit f00812
/*  to contract no. DE-AC03-76SF00098 between the United States */
Packit f00812
/*  Department of Energy and the University of California. */
Packit f00812
Packit f00812
/*  This file is part of flex. */
Packit f00812
Packit f00812
/*  Redistribution and use in source and binary forms, with or without */
Packit f00812
/*  modification, are permitted provided that the following conditions */
Packit f00812
/*  are met: */
Packit f00812
Packit f00812
/*  1. Redistributions of source code must retain the above copyright */
Packit f00812
/*     notice, this list of conditions and the following disclaimer. */
Packit f00812
/*  2. Redistributions in binary form must reproduce the above copyright */
Packit f00812
/*     notice, this list of conditions and the following disclaimer in the */
Packit f00812
/*     documentation and/or other materials provided with the distribution. */
Packit f00812
Packit f00812
/*  Neither the name of the University nor the names of its contributors */
Packit f00812
/*  may be used to endorse or promote products derived from this software */
Packit f00812
/*  without specific prior written permission. */
Packit f00812
Packit f00812
/*  THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR */
Packit f00812
/*  IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED */
Packit f00812
/*  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */
Packit f00812
/*  PURPOSE. */
Packit f00812

Packit f00812
#ifndef SCANOPT_H
Packit f00812
#define SCANOPT_H
Packit f00812
Packit f00812
#include "flexdef.h"
Packit f00812
Packit f00812
Packit f00812
#ifndef NO_SCANOPT_USAGE
Packit f00812
/* Used by scanopt_usage for pretty-printing. */
Packit f00812
#ifdef HAVE_NCURSES_H
Packit f00812
#include <ncurses.h>
Packit f00812
#endif
Packit f00812
#endif
Packit f00812
Packit f00812
#ifdef __cplusplus
Packit f00812
extern  "C" {
Packit f00812
#endif
Packit f00812
/* Error codes. */ enum scanopt_err_t {
Packit f00812
		SCANOPT_ERR_OPT_UNRECOGNIZED = -1,	/* Unrecognized option. */
Packit f00812
		SCANOPT_ERR_OPT_AMBIGUOUS = -2,	/* It matched more than one option name. */
Packit f00812
		SCANOPT_ERR_ARG_NOT_FOUND = -3,	/* The required arg was not found. */
Packit f00812
		SCANOPT_ERR_ARG_NOT_ALLOWED = -4	/* Option does not take an argument. */
Packit f00812
	};
Packit f00812
Packit f00812
Packit f00812
/* flags passed to scanopt_init */
Packit f00812
	enum scanopt_flag_t {
Packit f00812
		SCANOPT_NO_ERR_MSG = 0x01	/* Suppress printing to stderr. */
Packit f00812
	};
Packit f00812
Packit f00812
/* Specification for a single option. */
Packit f00812
	struct optspec_t {
Packit f00812
		const char *opt_fmt;	/* e.g., "--foo=FILE", "-f FILE", "-n [NUM]" */
Packit f00812
		int     r_val;	/* Value to be returned by scanopt_ex(). */
Packit f00812
		const char *desc;	/* Brief description of this option, or NULL. */
Packit f00812
	};
Packit f00812
	typedef struct optspec_t optspec_t;
Packit f00812
Packit f00812
Packit f00812
/* Used internally by scanopt() to maintain state. */
Packit f00812
/* Never modify these value directly. */
Packit f00812
	typedef void *scanopt_t;
Packit f00812

Packit f00812
Packit f00812
/* Initializes scanner and checks option list for errors.
Packit f00812
 * Parameters:
Packit f00812
 *   options - Array of options.
Packit f00812
 *   argc    - Same as passed to main().
Packit f00812
 *   argv    - Same as passed to main(). First element is skipped.
Packit f00812
 *   flags   - Control behavior.
Packit f00812
 * Return:  A malloc'd pointer .
Packit f00812
 */
Packit f00812
	scanopt_t *scanopt_init (const optspec_t * options, int argc,
Packit f00812
				 char **argv, int flags);
Packit f00812
Packit f00812
/* Frees memory used by scanner.
Packit f00812
 * Always returns 0. */
Packit f00812
	int scanopt_destroy (scanopt_t * scanner);
Packit f00812
Packit f00812
#ifndef NO_SCANOPT_USAGE
Packit f00812
/* Prints a usage message based on contents of optlist.
Packit f00812
 * Parameters:
Packit f00812
 *   scanner  - The scanner, already initialized with scanopt_init().
Packit f00812
 *   fp       - The file stream to write to.
Packit f00812
 *   usage    - Text to be prepended to option list. May be NULL.
Packit f00812
 * Return:  Always returns 0 (zero).
Packit f00812
 */
Packit f00812
	int scanopt_usage (scanopt_t * scanner, FILE * fp, const char *usage);
Packit f00812
#endif
Packit f00812
Packit f00812
/* Scans command-line options in argv[].
Packit f00812
 * Parameters:
Packit f00812
 *   scanner  - The scanner, already initialized with scanopt_init().
Packit f00812
 *   optarg   - Return argument, may be NULL.
Packit f00812
 *              On success, it points to start of an argument.
Packit f00812
 *   optindex - Return argument, may be NULL.
Packit f00812
 *              On success or failure, it is the index of this option.
Packit f00812
 *              If return is zero, then optindex is the NEXT valid option index.
Packit f00812
 *
Packit f00812
 * Return:  > 0 on success. Return value is from optspec_t->rval.
Packit f00812
 *         == 0 if at end of options.
Packit f00812
 *          < 0 on error (return value is an error code).
Packit f00812
 *
Packit f00812
 */
Packit f00812
	int scanopt (scanopt_t * scanner, char **optarg, int *optindex);
Packit f00812
Packit f00812
#ifdef __cplusplus
Packit f00812
}
Packit f00812
#endif
Packit f00812
#endif
Packit f00812
/* vim:set tabstop=8 softtabstop=4 shiftwidth=4: */