Files
mars-nwe/include/core/include/parse.h
Mario Fetka 3acba014e3
All checks were successful
Source release / source-package (push) Successful in 1m20s
0506 core: import NSS parse command-line runtime
2026-06-14 08:11:06 +02:00

415 lines
19 KiB
C

/****************************************************************************
|
| (C) Copyright 1985, 1991, 1993, 1996 Novell, Inc.
| All Rights Reserved.
|
| This program is free software; you can redistribute it and/or
| modify it under the terms of version 2 of the GNU General Public
| License as published by the Free Software Foundation.
|
| This program is distributed in the hope that it will be useful,
| but WITHOUT ANY WARRANTY; without even the implied warranty of
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
| GNU General Public License for more details.
|
| You should have received a copy of the GNU General Public License
| along with this program; if not, contact Novell, Inc.
|
| To contact Novell about this file by physical or electronic mail,
| you may find current contact information at www.novell.com
|
|***************************************************************************
|
| NetWare Advance File Services (NSS) module
|
|---------------------------------------------------------------------------
|
| $Author: taysom $
| $Date: 2004-12-31 01:10:58 +0530 (Fri, 31 Dec 2004) $
|
| $RCSfile$
| $Revision: 465 $
|
|---------------------------------------------------------------------------
| This module is used to:
| NSS Library source for Parsing Routines
|
| WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING!
|
| This header file should ONLY be used for NSS internal development.
| This includes Semantic Agents (SA) and Loadable Storage Services (LSS).
| Any other use may cause conflicts which NSS will NOT fix.
+-------------------------------------------------------------------------*/
#ifndef _PARSE_H_
#define _PARSE_H_
#ifndef _OMNI_H_
# include <library/omni.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
/* Pre-define struct(s) so Linux compiler doesn't complain */
struct PCLSwitchDef_s;
#define MAX_TOKEN zMAX_FULL_NAME /* maximum size of individual token string*/
/*========================================================================
* Command Line Parsing Structures
*
* This is used to parse command line strings and extract all of the
* switch values.
*========================================================================*/
/*-------------------------------------------------------------------------
* Typedef for the routine that may be called to finish processing an
* individual switch. It receives a pointer to the PCLSwitchDef_s
* structure for this given switch value along with it's index into the
* original array of PCLSwitchDef_s structure that the user passed
* in. This returns zOK if everything is fine with the switch. It returns
* zFAILURE if something is wrong with it. Returning zFAILURE will cause
* the command line parser to fail. It is up to the "process" routine to
* report what is wrong with the switch value. All process routines will
* be called even if an error is reported for one of them.
*-------------------------------------------------------------------------*/
typedef STATUS (*PCLFunction_t)(
struct PCLSwitchDef_s *switchDef,
NINT parseOptions, /* parse options given to parse routine */
void *userParm);
/*-------------------------------------------------------------------------
* You need to create an array of this structure which defines all of the
* switch values that are valid for this parsing sequence. Anywhere in
* this document where it refers the the "switch array" it is refereing to
* and array of this structure. The array MUST be terminated by a TYPE
* field value of SWTYPE_ENDOFLIST.
*-------------------------------------------------------------------------*/
typedef struct PCLSwitchDef_s
{
char *name; /* The name of this switch*/
char *setParmName; /* The name of this switch in set parameters
* Set to NULL if the option does not require
* a OS set parameter entry
*/
NINT type; /* Type and options for the switch (see below) */
NINT setParmType; /* Type of the switch as passed to setParms */
NINT setParmFlags; /* Optional flags as defined in setparms.h */
/* Currently we don't support the process
* option for set parameters. Another
* setParmProcess field will need to be
* added to do this.
*/
PCLFunction_t process; /* Routine that is called to finish
* processing the switch value, set to NULL
* if no routine needs to be called. Note
* that this routine will be called only
* after all values in the switch array have
* been parsed and placed into the given
* "ret_value" fields. This means that this
* routine may look at any of the fields.
* This routine will be called on ALL
* switches that are given.*/
void *ret_value; /* Address of where to put the value of
* this switch. If NULL the value is stored
* in a MALLOCed array that is freed before
* the "ParseCmdline" routine returns. This
* means that it will only be filled in
* while the "process" routines are being
* called. Note that the "process" routines
* are called ONLY after ALL switches have
* been parsed and all the "ret_value" fields
* have been set. */
union
{
struct
{
NINT ret_valueSize; /* Contains size of "ret_value" buffer in
* characters, only used for CHAR and UNICODE
* types when a non-null "ret_value" field is
* given. This is given in characters.*/
NINT ret_valueLen; /* Receives the length of the given string in
* characters. Only used for CHAR and UNICODE
* types when a valid value has been set. This
* is given in characters.*/
} string;
struct
{
NINT minValue; /* Defines the minimum numeric value */
NINT maxValue; /* Defines the maximum maximum value */
} numeric;
} vtype; /* value type*/
NINT groupValue; /* This is used to group sub-switches with
* a parent switch. This can be any non-zero
* value and all switches with the same
* non-zero value will be in the same group.
* The first switch in the switch array with
* a given value will be the parent switch.
* All other array elements with the same
* value (they do not have to be contiguous
* in the array) will be sub-switches. This
* means that the parent switch must be
* encountered in the command line string
* before the sub-switches will be valid.
* You can have multiple parent/sub switch
* groupings as long as the group value is
* different*/
ADDR userInfo; /* field for user specific info about this switch*/
LangEnabledStruct_s helpStr;/* This contains the HELP strings, they are in
* a languaged enabled form */
PCLFunction_t PCLSD_PreFunction;
/* Function to call before ANY process
* functions are called. Called in the
* same order as process functions. If any
* PreFunction returns an error then no
* process function will be called. On an
* error the rest of the pre functions will
* be called.
*/
PCLFunction_t PCLSD_PostFunction;
/* Function to call after all process
* functions are called. Called in the
* same order as process functions. If we
* call a PRE function then we will call
* the POST function in all cases. This
* includes the PRE or process function
* returning an error.
*/
} PCLSwitchDef_s;
#define PCMDLINE_ENDOFLIST 0 /* defines the end of the switches array*/
extern LONG NSSSetParmCategory;
/*-------------------------------------------------------------------------
* This defines the different types of switches there are. These
* options are ORED with each other. Note that the "process" routine will
* is always called on all switch types of the routine is defined and
* the given switch is specified.
*-------------------------------------------------------------------------*/
#define SWTYPE_REQUIRED 0 /* this is a position dependent parameter
* that is required, if not given it will
* be promted for. This value may be
* enclosed in double quotes which are
* stripped by this parser. */
#define SWTYPE_OPTIONAL 1 /* this is a position dependent parameter
* that is optional, if not given nothing
* will happen. This value may be
* enclosed in double quotes which are
* stripped by this parser. */
#define SWTYPE_NAME 2 /* this is a NAMED parameter. This has
* no value. It only makes sense to use
* this type with a "process" routine.
* The command line syntax has just the
* switch name optionally preceded by a
* '/' or '-'. No value is place in
* the ret_value field for this type of
* switch.*/
#define SWTYPE_BOOLEAN 3 /* this is a boolean switch. It defines
* a TRUE(1)/FALSE(0) state. The command
* line syntax has just the name being
* TRUE and the name preceded by NO
* being FALSE. The switch name must be
* preceded by a '/' or '-'*/
#define SWTYPE_VALUE 4 /* this is a valued parameter. This has
* an arbitrary value. The command line
* syntax is the switch name followed
* by '=' and then the switch value. The
* switch value may be enclosed in double
* quotes which are stripped by this
* parser. The switch name must be
* preceded by a '/' or '-'*/
#define SWTYPE_MASK 0x0000000f /* range of type values*/
#define GET_SWTYPE(value) ((value) & SWTYPE_MASK)
/*-------------------------------------------------------------------------
* This defines the datatypes that can be returned for the switch values.
* All binary data types will convert the given string to binary and return
* it. You can give binary values in decimal or hex. It follows the
* standard parsing guidelines define by the ansii standard library
* routine "strtol".
*-------------------------------------------------------------------------*/
#define SWVAL_NINT 0x00000000 /* a binary NINT will be returned*/
#define SWVAL_SNINT 0x00000010 /* a binary SNINT will be returned*/
#define SWVAL_QUAD 0x00000020 /* a binary QUAD will be returned*/
#define SWVAL_SQUAD 0x00000030 /* a binary SQUAD will be returned*/
#define SWVAL_LONG 0x00000040 /* a binary LONG will be returned*/
#define SWVAL_SLONG 0x00000050 /* a binary SLONG will be returned*/
#define SWVAL_WORD 0x00000060 /* a binary WORD will be returned*/
#define SWVAL_SWORD 0x00000070 /* a binary SWORD will be returned*/
#define SWVAL_BYTE 0x00000080 /* a binary BYTE will be returned*/
#define SWVAL_SBYTE 0x00000090 /* a binary SBYTE will be returned*/
#define SWVAL_CHAR 0x000000a0 /* an ASCII string will be returned*/
#define SWVAL_UNICODE 0x000000b0 /* a UNICODE string will be returned*/
#define SWVAL_BOOL 0x000000c0 /* a binary BOOLEAN will be returned*/
#define SWVAL_MASK 0x000000f0 /* range of data values*/
#define GET_SWVAL(value) ((value) & SWVAL_MASK)
/*-------------------------------------------------------------------------
* These are additional options that may be defined.
*-------------------------------------------------------------------------*/
#define SWOPT_MAPUPPER 0x00010000 /* if SET do map value string to
* UPPPER case, by default strings
* are NOT mapped to upper case*/
#define SWOPT_HELP_ADD_SLASH 0x00020000 /* for NAME switches add '/'on HELP*/
#define SWOPT_IGNORE_STATUS 0x00040000 /* if SET, the process function does
* not return a status value*/
#define SWOPT_HAS_NUMERIC_RANGE 0x00080000 /* if set, use the given numeric
* range limits*/
#define SWOPT_DEBUG 0x00100000 /* this is a DEBUG time switch */
#define SWOPT_NO_HELP_VALUE 0x00200000 /* if set, don't display the value
* when displaying help */
#define SWOPT_HIDDEN 0x00400000 /* if set, don't display the switch
* when displaying help */
/*-------------------------------------------------------------------------
* The following bits define a display category for each help parameter.
* Help commands may be a member of more than one group, in which case
* they will appear under each category during a help display. If no bit
* is set, the command line will not appear in the help list(s). If additional
* categories are added, additional titles must be added to the array
* CmdLineCategories in pcmdline.c. These bits MUST be contiguouos if new
* categories are added.
*-------------------------------------------------------------------------*/
#define SWHELP_CAT_MAINT 0x01000000 /* if set, display switch in the
* maintenance category */
#define SWHELP_CAT_STATUS 0x02000000 /* if set, display switch in the
* status category */
#define SWHELP_CAT_CONTROL 0x04000000 /* if set, display switch in the
* control category */
#define SWHELP_CAT_TUNING 0x08000000 /* if set, display switch in the
* tuning category */
#define SWHELP_CAT_MISC 0x10000000 /* if set, display switch in the
* maintenance category */
#define SWHELP_CAT_FIRST SWHELP_CAT_MAINT
#define SWHELP_CAT_COUNT 5 /* number of help categories */
#if zLINUX
/* This bit is used to tell Linux that these command lines are to be parsed at
* the end of comnStart, but NOT at the beginning. If this bit is not present,
* it is assumed that SWOPT_RUNTIME_ONLY and SWOPT_STARTUP_ONLY dictate when
* the command line is valid.
*/
#define SWOPT_FINISHOFSTARTUP 0x20000000 /* command is valid at startup finish */
#endif
/* The system defines two different times when the command line parser is
* called: STARTUP (when the app loads) and RUNTIME (while the app is running).
* These two options allow you to specify when a given switch is enabled. By
* default the switch is enabled for both types. You can suppress it for either
* mode. I suppose you can suppress them at both time but then what would be
* the point of the switch? */
#define SWOPT_RUNTIME_ONLY 0x40000000 /* suppress switch at RUNTIME */
#define SWOPT_STARTUP_ONLY 0x80000000 /* suppress switch at STARTUP time*/
#define SWOPT_MASK_VALUES 0xffff0000 /* mask for switch options from the
* user */
/*-------------------------------------------------------------------------
* These are internal switch values. These values are cleared upon entry
* into the parsing routines.
*-------------------------------------------------------------------------*/
#define SWPRV_MALLOCED 0x00000100 /* if SET we malloced the structure*/
#define SWPRV_GROUP_CHILD 0x00000200 /* if SET this is a child of a group,
* if not set this is the parent of
* the group*/
#define SWPRV_GROUP_ACTIVE 0x00000400 /* if SET this group switch is now
* active, only set on child members*/
#define SWPRV_SPECIFIED 0x00000800 /* this is SET by the parsing routine
* for each switch that has a value
* it is cleared for each switch that
* does NOT have a value.*/
/*-------------------------------------------------------------------------
* This is a mask that is used to set the TYPE field to the list of
* valid defined external values. (preserve these bits)
*-------------------------------------------------------------------------*/
#define SWTYPE_SET_START (SWTYPE_MASK | \
SWVAL_MASK | \
SWOPT_MASK_VALUES)
/*-------------------------------------------------------------------------
* When you have multiple comand line definition list (which could happen
* if you have multiple NLMs that want to share the command line), you
* must fill out an array of this structure which identifies each switch
* list and a module name for each switch list.
*-------------------------------------------------------------------------*/
typedef struct PCLMultiSwitchList_s
{
PCLSwitchDef_s *swList/*[]*/; /* pointer to switch arrays */
char *moduleName; /* module name */
char **messageTable; /* message table for this module
* (may be NULL if not language enabled) */
} PCLMultiSwitchList_s;
/*-------------------------------------------------------------------------
* Function prototypes
*-------------------------------------------------------------------------*/
extern STATUS LB_ParseCmdlineMulti(
PCLMultiSwitchList_s *multiSwitchDef,/* pointer to array of switch
* definitions for multiple modules */
NINT parseOptions, /* specify parsing options */
char *parseStr, /* the string to parse*/
void *userParm, /* a parameter defined by the user that
* is passed to the "process" routines*/
BOOL (*validateswlist)(PCLSwitchDef_s *checkswdef));
/* used as a callback to validate if the
* module for the switch settings is still
* loaded*/
extern STATUS LB_ParseCmdline(
PCLSwitchDef_s *swDef, /* pointer to array of switch definitions*/
NINT parseOptions, /* specify parsing options */
char *parseStr, /* the string to parse*/
void *userParm); /* a parameter defined by the user that
* is passed to the "process" routines*/
#define POPT_AT_RUNTIME 0x00000000 /* Defines we are at RUNTIME */
#define POPT_NO_UNKNOWN_SWITCH_ERRORS 0x00000001 /* Defines we don't want to
* report unknown switch
* errors */
#define POPT_AT_STARTUP 0x00000002 /* Defines we are at STARTUP TIME */
#define POPT_FIRST_PARSE 0x00000004 /* Defines we are PARSING the cmdline the first time */
#define POPT_AT_FINISH_STARTUP 0x00000008 /* Defines we are on the finishup parse of STARTUP TIME */
#define POPT_NO_PARSE_TIME_ERRORS 0x00000010 /* Tells parser to ignore errors caused by parsing a command at the wrong time */
extern void LB_DisplayCmdlineHelpMulti(
PCLMultiSwitchList_s *multiSwitchDef,/* pointer to array of switch
* definitions for multiple modules */
NINT options, /* specify parsing options */
NINT hiddenFlag, /* if true, display hidden switches, if false, display visible only */
char *title, /* title string for help */
...); /* parameters to TITLE string*/
extern void LB_DisplayCmdlineHelp(
PCLSwitchDef_s *swdefp, /* switch definition array*/
char **messageTable, /* language enabled message table
* (may be NULL if not language enabled) */
NINT options, /* specify parsing options */
char *title, /* title string for help*/
...); /* parameters to TITLE string*/
extern void LB_RegisterSetParmsForNSS(
PCLSwitchDef_s *swlist,
char **msgTable);
extern void LB_UnRegisterSetParmsForNSS(
PCLSwitchDef_s *swlist);
#ifdef __cplusplus
}
#endif
#endif