fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The contents of this file are subject to the terms of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Common Development and Distribution License (the "License").
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You may not use this file except in compliance with the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or http://www.opensolaris.org/os/licensing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If applicable, add the following below this CDDL HEADER, with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifndef _CMDPARSE_H
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define _CMDPARSE_H
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef __cplusplus
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern "C" {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <getopt.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* subcommands must have a single bit on and must have exclusive values */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SUBCOMMAND_BASE 1
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SUBCOMMAND(x) (SUBCOMMAND_BASE << x)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define OBJECT_BASE 1
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define OBJECT(x) (OBJECT_BASE << x)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* maximum length of an option argument */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define MAXOPTARGLEN 256
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Add objects here
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * EXAMPLE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * object_t object[] = {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * {"target", TARGET},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * {NULL, 0}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * };
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct _object {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *name;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint_t value;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} object_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This structure is passed into the caller's callback function and
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * will contain a list of all options entered and their associated
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * option arguments if applicable
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct _cmdOptions {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int optval;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char optarg[MAXOPTARGLEN + 1];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} cmdOptions_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * list of objects, subcommands, valid short options, required flag and
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * exlusive option string
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * objectValue -> object
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * subcommandValue -> subcommand value
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * optionProp.optionString -> short options that are valid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * optionProp.required -> flag indicating whether at least one option is
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * required
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * optionProp.exclusive -> short options that are required to be exclusively
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * entered
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If it's not here, there are no options for that object.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The long options table specifies whether an option argument is required.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * EXAMPLE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Based on DISCOVERY entry below:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * MODIFY DISCOVERY accepts -i, -s, -t and -l
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * MODIFY DISCOVERY requires at least one option
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * MODIFY DISCOVERY has no exclusive options
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * optionRules_t optionRules[] = {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * {DISCOVERY, MODIFY, "istl", B_TRUE, NULL},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * {0, 0, NULL, 0, NULL}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * };
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct _optionProp {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *optionString;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte boolean_t required;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *exclusive;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} optionProp_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct _optionRules {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint_t objectValue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint_t subcommandValue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte optionProp_t optionProp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} optionRules_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Rules for subcommands and object operands
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Every object requires an entry
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * value, reqOpCmd, optOpCmd, noOpCmd, invCmd, multOpCmd
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * value -> numeric value of object
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The following five fields are comprised of values that are
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * a bitwise OR of the subcommands related to the object
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * reqOpCmd -> subcommands that must have an operand
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * optOpCmd -> subcommands that may have an operand
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * noOpCmd -> subcommands that will have no operand
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * invCmd -> subcommands that are invalid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * multOpCmd -> subcommands that can accept multiple operands
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * operandDefinition -> Usage definition for the operand of this object
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * EXAMPLE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * based on TARGET entry below:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * MODIFY and DELETE subcomamnds require an operand
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * LIST optionally requires an operand
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * There are no subcommands that requires that no operand is specified
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ADD and REMOVE are invalid subcommands for this operand
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * DELETE can accept multiple operands
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * objectRules_t objectRules[] = {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * {TARGET, MODIFY|DELETE, LIST, 0, ADD|REMOVE, DELETE,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * "target-name"},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * {0, 0, 0, 0, 0, NULL}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * };
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct _opCmd {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint_t reqOpCmd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint_t optOpCmd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint_t noOpCmd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint_t invOpCmd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint_t multOpCmd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} opCmd_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct _objectRules {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint_t value;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte opCmd_t opCmd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *operandDefinition;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} objectRules_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * subcommand callback function
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * argc - number of arguments in argv
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * argv - operand arguments
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * options - options entered on command line
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * callData - pointer to caller data to be passed to subcommand function
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef int (*handler_t)(int argc, char *argv[], int, cmdOptions_t *options,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte void *callData, int *funtRet);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Add new subcommands here
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * EXAMPLE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * subcommand_t subcommands[] = {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * {"add", ADD, addFunc},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * {NULL, 0, NULL}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * };
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct _subcommand {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *name;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint_t value;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handler_t handler;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} subcommand_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define required_arg required_argument
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define no_arg no_argument
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Add short options and long options here
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * name -> long option name
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * has_arg -> required_arg, no_arg
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * val -> short option character
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * argDesc -> description of option argument
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Note: This structure may not be used if your CLI has no
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * options. However, -?, --help and -V, --version will still be supported
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * as they are standard for every CLI.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * EXAMPLE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * optionTbl_t options[] = {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * {"filename", arg_required, 'f', "out-filename"},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * {NULL, 0, 0}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * };
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct _optionTbl {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *name;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int has_arg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int val;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *argDesc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} optionTbl_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * After tables are set, assign them to this structure
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * for passing into cmdparse()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct _synTables {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *versionString;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte optionTbl_t *longOptionTbl;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte subcommand_t *subcommandTbl;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte object_t *objectTbl;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte objectRules_t *objectRulesTbl;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte optionRules_t *optionRulesTbl;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} synTables_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cmdParse is a parser that checks syntax of the input command against
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * various rules tables.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When syntax is successfully validated, the function associated with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * subcommand is called using the subcommands table functions.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Syntax for the command is as follows:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * command subcommand [<options>] object [<operand ...>]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * There are two standard short and long options assumed:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * -?, --help Provides usage on a command or subcommand
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and stops further processing of the arguments
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * -V, --version Provides version information on the command
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and stops further processing of the arguments
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * These options are loaded by this function.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * input:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * argc, argv from main
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * syntax rules tables (synTables_t structure)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * callArgs - void * passed by caller to be passed to subcommand function
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * output:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * funcRet - pointer to int that holds subcommand function return value
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Returns:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * zero on successful syntax parse and function call
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 1 on unsuccessful syntax parse (no function has been called)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This could be due to a version or help call or simply a
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * general usage call.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * -1 check errno, call failed
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint cmdParse(int numOperands, char *operands[], synTables_t synTables,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte void *callerArgs, int *funcRet);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef __cplusplus
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* _CMDPARSE_H */