1228072Sbapt/* flex - tool to generate fast lexical analyzers */ 2228072Sbapt 3228072Sbapt/* Copyright (c) 1990 The Regents of the University of California. */ 4228072Sbapt/* All rights reserved. */ 5228072Sbapt 6228072Sbapt/* This code is derived from software contributed to Berkeley by */ 7228072Sbapt/* Vern Paxson. */ 8228072Sbapt 9228072Sbapt/* The United States Government has rights in this work pursuant */ 10228072Sbapt/* to contract no. DE-AC03-76SF00098 between the United States */ 11228072Sbapt/* Department of Energy and the University of California. */ 12228072Sbapt 13228072Sbapt/* This file is part of flex. */ 14228072Sbapt 15228072Sbapt/* Redistribution and use in source and binary forms, with or without */ 16228072Sbapt/* modification, are permitted provided that the following conditions */ 17228072Sbapt/* are met: */ 18228072Sbapt 19228072Sbapt/* 1. Redistributions of source code must retain the above copyright */ 20228072Sbapt/* notice, this list of conditions and the following disclaimer. */ 21228072Sbapt/* 2. Redistributions in binary form must reproduce the above copyright */ 22228072Sbapt/* notice, this list of conditions and the following disclaimer in the */ 23228072Sbapt/* documentation and/or other materials provided with the distribution. */ 24228072Sbapt 25228072Sbapt/* Neither the name of the University nor the names of its contributors */ 26228072Sbapt/* may be used to endorse or promote products derived from this software */ 27228072Sbapt/* without specific prior written permission. */ 28228072Sbapt 29228072Sbapt/* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR */ 30228072Sbapt/* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED */ 31228072Sbapt/* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ 32228072Sbapt/* PURPOSE. */ 33228072Sbapt 34228072Sbapt#ifndef SCANOPT_H 35228072Sbapt#define SCANOPT_H 36228072Sbapt 37228072Sbapt#include "flexdef.h" 38228072Sbapt 39228072Sbapt 40228072Sbapt#ifndef NO_SCANOPT_USAGE 41228072Sbapt/* Used by scanopt_usage for pretty-printing. */ 42228072Sbapt#ifdef HAVE_NCURSES_H 43228072Sbapt#include <ncurses.h> 44228072Sbapt#endif 45228072Sbapt#endif 46228072Sbapt 47228072Sbapt#ifdef __cplusplus 48228072Sbaptextern "C" { 49228072Sbapt#endif 50228072Sbapt#ifndef PROTO 51228072Sbapt#define PROTO(args) args 52228072Sbapt#endif 53228072Sbapt/* Error codes. */ enum scanopt_err_t { 54228072Sbapt SCANOPT_ERR_OPT_UNRECOGNIZED = -1, /* Unrecognized option. */ 55228072Sbapt SCANOPT_ERR_OPT_AMBIGUOUS = -2, /* It matched more than one option name. */ 56228072Sbapt SCANOPT_ERR_ARG_NOT_FOUND = -3, /* The required arg was not found. */ 57228072Sbapt SCANOPT_ERR_ARG_NOT_ALLOWED = -4 /* Option does not take an argument. */ 58228072Sbapt }; 59228072Sbapt 60228072Sbapt 61228072Sbapt/* flags passed to scanopt_init */ 62228072Sbapt enum scanopt_flag_t { 63228072Sbapt SCANOPT_NO_ERR_MSG = 0x01 /* Suppress printing to stderr. */ 64228072Sbapt }; 65228072Sbapt 66228072Sbapt/* Specification for a single option. */ 67228072Sbapt struct optspec_t { 68228072Sbapt const char *opt_fmt; /* e.g., "--foo=FILE", "-f FILE", "-n [NUM]" */ 69228072Sbapt int r_val; /* Value to be returned by scanopt_ex(). */ 70228072Sbapt const char *desc; /* Brief description of this option, or NULL. */ 71228072Sbapt }; 72228072Sbapt typedef struct optspec_t optspec_t; 73228072Sbapt 74228072Sbapt 75228072Sbapt/* Used internally by scanopt() to maintain state. */ 76228072Sbapt/* Never modify these value directly. */ 77228072Sbapt typedef void *scanopt_t; 78228072Sbapt 79228072Sbapt 80228072Sbapt/* Initializes scanner and checks option list for errors. 81228072Sbapt * Parameters: 82228072Sbapt * options - Array of options. 83228072Sbapt * argc - Same as passed to main(). 84228072Sbapt * argv - Same as passed to main(). First element is skipped. 85228072Sbapt * flags - Control behavior. 86228072Sbapt * Return: A malloc'd pointer . 87228072Sbapt */ 88228072Sbapt scanopt_t *scanopt_init PROTO ((const optspec_t * options, 89228072Sbapt int argc, char **argv, int flags)); 90228072Sbapt 91228072Sbapt/* Frees memory used by scanner. 92228072Sbapt * Always returns 0. */ 93228072Sbapt int scanopt_destroy PROTO ((scanopt_t * scanner)); 94228072Sbapt 95228072Sbapt#ifndef NO_SCANOPT_USAGE 96228072Sbapt/* Prints a usage message based on contents of optlist. 97228072Sbapt * Parameters: 98228072Sbapt * scanner - The scanner, already initialized with scanopt_init(). 99228072Sbapt * fp - The file stream to write to. 100228072Sbapt * usage - Text to be prepended to option list. May be NULL. 101228072Sbapt * Return: Always returns 0 (zero). 102228072Sbapt */ 103228072Sbapt int scanopt_usage 104228072Sbapt PROTO ( 105228072Sbapt (scanopt_t * scanner, FILE * fp, 106228072Sbapt const char *usage)); 107228072Sbapt#endif 108228072Sbapt 109228072Sbapt/* Scans command-line options in argv[]. 110228072Sbapt * Parameters: 111228072Sbapt * scanner - The scanner, already initialized with scanopt_init(). 112228072Sbapt * optarg - Return argument, may be NULL. 113228072Sbapt * On success, it points to start of an argument. 114228072Sbapt * optindex - Return argument, may be NULL. 115228072Sbapt * On success or failure, it is the index of this option. 116228072Sbapt * If return is zero, then optindex is the NEXT valid option index. 117228072Sbapt * 118228072Sbapt * Return: > 0 on success. Return value is from optspec_t->rval. 119228072Sbapt * == 0 if at end of options. 120228072Sbapt * < 0 on error (return value is an error code). 121228072Sbapt * 122228072Sbapt */ 123228072Sbapt int scanopt 124228072Sbapt PROTO ( 125228072Sbapt (scanopt_t * scanner, char **optarg, 126228072Sbapt int *optindex)); 127228072Sbapt 128228072Sbapt#ifdef __cplusplus 129228072Sbapt} 130228072Sbapt#endif 131228072Sbapt#endif 132228072Sbapt/* vim:set tabstop=8 softtabstop=4 shiftwidth=4: */ 133