home *** CD-ROM | disk | FTP | other *** search
- /* Copyright (c) 1995 by Oracle Corporation. All Rights Reserved.
- *
- * ysr.h - OMX Resource Management
- */
-
- #ifndef YSR_ORACLE
- #define YSR_ORACLE
-
- #ifndef SYSX_ORACLE
- #include <sysx.h>
- #endif
- #ifndef YS_ORACLE
- #include <ys.h>
- #endif
-
- EXTC_START
-
- /*
- * Resource Descriptor
- *
- * A resource descriptor is an element in the resource database of the
- * process. Each resource descriptor is identified by a name and has
- * associated with it one or more values; these values are represented
- * as character strings.
- *
- * The name of a resource must observe the following syntax:
- *
- * resource_name ::= [ binding ] component_name { binding component_name }
- * binding ::= '.' | '*'
- * component_name::= { 'A'-'Z' | 'a'-'z' | '0'-'9' | '_' | '-' }
- *
- * The '.' binding specifies a tight binding which is used to separate
- * immediately adjacent components. The '*' binding specifies a loose
- * binding which represents any number of intervening components, including
- * none.
- *
- * Associated with a resource name is a list of values. Any resource
- * may have multiple values associated with it. Every time the same
- * resource name is set, the new value is appended to the end of the
- * list. Individual applications may implement there own semantics
- * as to whether multiple values is meaningful, or whether the first
- * value or the last value set should be used (by simply extracting
- * head or the tail of the list).
- */
-
- /*
- * ysResGet, ysResGetLast, ysResGetBool - get a resource descriptor
- *
- * DESCRIPTION
- * ysResGet() gets a resource descriptor. The resource name must
- * be specified completely using only tight bindings. Thus, a resource
- * name is formatted as
- *
- * name ::= component_name { '.' component_name }
- *
- * The given resource name is matched up against the resource database
- * by finding the resource entry that most closely matches the given
- * resource name. Entries are matched up by choosing those resource
- * names that contain a matching component before those that omit it
- * (using a loose binding); then, they are matched up by those which
- * specify a tight binding over those that match a loose binding.
- * All component name comparisons are done in a case-insenstive manner.
- *
- * If a resource entry is found, the list of resource values is
- * returned. This list is a pointer directly into the resource
- * database and thus, if the list is altered, this directly alters
- * the resource database.
- *
- * ysResGetLast() retrieves the same resource entry as ysResGet(),
- * except that it returns only the last element of the list that
- * would be returned. This is convenient for most resources where
- * only one value (the last one assigned) is relevant.
- *
- * If no resource entry is found, both of these routines return null.
- *
- * ysResGetBool() retrieves a resource and tests to see if its value
- * is not false. The value is false if a) the resource is not defined,
- * or b) the value of the resource is "false" (case-insensitive). Otherwise,
- * this routine returns TRUE.
- */
- yslst *ysResGet(CONST char *name);
- char *ysResGetLast(CONST char *name);
- boolean ysResGetBool(CONST char *name);
-
- /*
- * ysResSet - set a resource descriptor
- *
- * DESCRIPTION
- * ysResSet() sets a value for a resource descriptor. The name given
- * here must observe the semantics specified under the description of
- * the resource descriptor. If there is already an entry in the
- * database that matches this name EXACTLY (ignoring case), then the
- * given value will appended to the list of values for that resource.
- * Otherwise, a new entry is created.
- */
- void ysResSet(CONST char *name, CONST char *val);
-
- /*
- * ysargmap - argument-to-resource mapping
- *
- * DESCRIPTION
- * Argument maps are used by ysArgParse() to map command-line options and
- * operands (positional arguments) to resource names and values. Each map
- * element describes a single option or operand. An array of map elements
- * forms the argument map. Ordering of the map elements among the options
- * doesn't matter, but does among the operands, since it is positional.
- *
- * The opt field contains one of: (a) the character value identifying an
- * option; (b) the value YSARG_PARAM identifying a mandatory operand;
- * (c) YSARG_OPTPARAM identifying an optional operand; or (d) zero,
- * terminating a vector of ysargmap elements.
- *
- * The cnt field specifies number of arguments to allow for the option. If
- * cnt is zero, no arguments are allowed. If cnt is one, exactly one
- * argument is allowed. If cnt is YSARG_MANY, then any number of arguments
- * (but at least one) is allowed. In the case of many arguments, they may
- * appear separately or together. When option arguments are expected,
- * ysResSet() is called once for each option argument, with the name field
- * as the resource name and the argument as the resource value. When no
- * option arguments are expected, ysResParse() is called with the name
- * field. Calling ysResParse() allows the existence of an argument to
- * cause a particular value for a particular resource to be set.
-
- * All elements with opt valuess of YSARG_PARAM or YSARG_OPTPARAM are treated
- * as positional operands. YSARG_PARAM denotes an element that is required;
- * YSARG_OPTPARAM denotes an element that is optional. Optional parameters
- * must follow required parameters. Multiple elements may be given and they
- * are matched up with the arguments in the order in which they appear in the
- * argument map array. If cnt is one, the element matches the next argument.
- * If cnt is YSARG_MANY, then the element will match all remaining argument
- * (but at least one will be required if this is a required element).
- * ysResSet() is called once for each matching operand, with the name field
- * as the resource name and the operand as the resource value.
- */
-
- typedef struct ysargmap ysargmap; /* argument map descriptor */
-
- #define YSARG_MANY (2) /* cnt: used to indicate more than one argument */
-
- #define YSARG_PARAM (-1) /* opt: mandatory positional parameter */
- #define YSARG_OPTPARAM (-2) /* opt: opt trailing positional parameter */
-
- /* DISABLE check_naming */
- struct ysargmap
- {
- sword opt; /* name of option */
- CONST char *name; /* name of resource */
- sword cnt; /* number of option arguments */
- };
- /* ENABLE check_naming */
-
- /*
- * ysArgMapConcat, ysArgMapFree - concatenate argument lists
- *
- * DESCRIPTION
- * Sometimes, it is necessary to combine more than one argument list to
- * be passed to ysArgParse(). ysArgMapConcat() may be used to concatenate
- * two argument maps. It returns a new argument map that is the combination
- * of the two. ysArgMapFree() must be used to free an argument map obtained
- * from ysArgMapConcat().
- */
- ysargmap *ysArgMapConcat(CONST ysargmap *m1, CONST ysargmap *m2);
- void ysArgMapFree(ysargmap *map);
-
- /*
- * ysArgParse - parse command-line arguments
- *
- * DESCRIPTION
- * ysArgParse() parses an argument list, maps the arguments on to
- * resources, and adds the resources to the resource database. map
- * is an argument map to use.
- *
- * To be legally formed, the argument list must observe the following
- * rules:
- * 1) Option names must be one character long.
- * 2) All options must be preceded by a '-'.
- * 3) Options with no arguments may be grouped after a single '-'.
- * 4) The first option argument following an option must be preceded
- * by white space.
- * 5) Option arguments cannot be optional.
- * 6) Groups of option arguments following an option must either be
- * separated by commas or separated by white space and quoted.
- * 7) All options must precede operands on the command line.
- * 8) "--" may be used to indicate the end of the options.
- *
- * Whenever more than one option argument is permitted, this routine
- * will attempt to parse groups of option arguments according to rule 6.
- * All option arguments are then added as individual values for the
- * given resource. Note that '-I . -I ..' is considered equivalent
- * to '-I ". .."'.
- *
- * This routine also intercepts and automatically recognizes the following
- * flags:
- *
- * -h, -H show usage
- * -V print version
- * -T verbose
- * -R <resource> set resource
- * -P <parameter-file> load parameter file
- *
- * The option -h prints a usage banner and returns YSARG_HELP.
- * The option -V returns YSARG_VERSION.
- * The option -T adds the resource entry "*verbose" with the value "true".
- * The option -R calls ysResParse() on the option argument.
- * The option -P reads a file containing resources to be added.
-
- * This routine also supplements the given argument map with an argument
- * map that includes platform-specific extensions.
- *
- * If the argument list is not legally formed, one or more errors is
- * reported via yslError() and YSARG_ERROR is returned. Otherwise,
- * the resource database is updated. and YSARG_NORMAL (0) is returned.
- * The program should not continue unless YSARG_NORMAL is returned.
- *
- * Note that most argument lists include the program name as the zeroeth
- * argument. This should be skipped in the argument list passed to
- * ysArgParse().
- */
- #define YSARG_NORMAL 0
- #define YSARG_ERROR 1
- #define YSARG_VERSION 2
- #define YSARG_HELP 3
-
- sword ysArgParse(sword argc, char **argv, CONST ysargmap *map);
-
- /*
- * ysResParse - parse a resource line
- *
- * DESCRIPTION
- * ysResParse() parses a resource line and adds the result to the
- * resource database. The syntax of a resource line is shown:
- *
- * resource_line ::= comment | resource_spec
- * comment ::= '#' <rest-of-string>
- * resource_spec ::= resource_name { ':' | '=' } value
- * value ::= <rest-of-string>
- *
- * Whitespace before and after the resource name and the value are
- * deleted. After this, ysResSet() is called with the resource
- * name and value. The usual use for this function is to read a
- * resource file and parse it line-by-line. nm indicates the file name
- * and ln indicates the line number in the file. If there is a syntax
- * error, an error is reported using yslError() and FALSE is returned.
- * If the line is not being read from a file, nm and ln should be zero.
- */
- boolean ysResParse(CONST char *nm, sword ln, CONST char *res);
-
- /*
- * ysResWalk - walk the resource database
- *
- * DESCRIPTION
- * ysResWalk() walks the resource database, invoking the callback function
- * for each defined resource. The callback function is passed the name of
- * the resource and the ordered list of the values for that resource. All
- * resource values are 'char *' strings. ysResWalk() continues to walk the
- * hash table until all resources have been processed, or the callback
- * routine returns FALSE. Thus, it should return TRUE as long as processing
- * should continue.
- */
- typedef boolean (*ysreswcb)(dvoid *usrp, char *nm, yslst *vals);
- void ysResWalk(ysreswcb walkcb, dvoid *usrp);
-
- /*
- * ysResDefaults - add default resource values
- *
- * DESCRIPTION
- * ysResDefaults() take a null-terminated char * array, where each string
- * in the array is a resource line expressed in a form suitable for
- * ysResParse() (see above). If ysResGet() on the resource name succeeds,
- * no action is taken; otherwise, the resource name with value supplied is
- * added to the resource database.
- */
- void ysResDefaults(char **dflts);
-
- /*
- * ysResPfile - read a resource file
- *
- * DESCRIPTION
- * Using the host file I/O package, ysResPfile() reads the text file named
- * by fn for resources. Each line is assumed to observe the syntax shown
- * for resource_line above. If no errors were encountered, TRUE is returned;
- * otherwise, diagnostics are written to yslError() and FALSE is returned.
- */
- boolean ysResPfile(CONST char *fn);
-
- EXTC_END
- #endif /* YSR_ORACLE */
-