|
Packit |
5bd3a9 |
|
|
Packit |
5bd3a9 |
/***********************************************************
|
|
Packit |
5bd3a9 |
|
|
Packit |
5bd3a9 |
Copyright 1987, 1988, 1998 The Open Group
|
|
Packit |
5bd3a9 |
|
|
Packit |
5bd3a9 |
Permission to use, copy, modify, distribute, and sell this software and its
|
|
Packit |
5bd3a9 |
documentation for any purpose is hereby granted without fee, provided that
|
|
Packit |
5bd3a9 |
the above copyright notice appear in all copies and that both that
|
|
Packit |
5bd3a9 |
copyright notice and this permission notice appear in supporting
|
|
Packit |
5bd3a9 |
documentation.
|
|
Packit |
5bd3a9 |
|
|
Packit |
5bd3a9 |
The above copyright notice and this permission notice shall be included in
|
|
Packit |
5bd3a9 |
all copies or substantial portions of the Software.
|
|
Packit |
5bd3a9 |
|
|
Packit |
5bd3a9 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
Packit |
5bd3a9 |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
Packit |
5bd3a9 |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
Packit |
5bd3a9 |
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
|
Packit |
5bd3a9 |
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
Packit |
5bd3a9 |
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
Packit |
5bd3a9 |
|
|
Packit |
5bd3a9 |
Except as contained in this notice, the name of The Open Group shall not be
|
|
Packit |
5bd3a9 |
used in advertising or otherwise to promote the sale, use or other dealings
|
|
Packit |
5bd3a9 |
in this Software without prior written authorization from The Open Group.
|
|
Packit |
5bd3a9 |
|
|
Packit |
5bd3a9 |
|
|
Packit |
5bd3a9 |
Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts.
|
|
Packit |
5bd3a9 |
|
|
Packit |
5bd3a9 |
All Rights Reserved
|
|
Packit |
5bd3a9 |
|
|
Packit |
5bd3a9 |
Permission to use, copy, modify, and distribute this software and its
|
|
Packit |
5bd3a9 |
documentation for any purpose and without fee is hereby granted,
|
|
Packit |
5bd3a9 |
provided that the above copyright notice appear in all copies and that
|
|
Packit |
5bd3a9 |
both that copyright notice and this permission notice appear in
|
|
Packit |
5bd3a9 |
supporting documentation, and that the name of Digital not be
|
|
Packit |
5bd3a9 |
used in advertising or publicity pertaining to distribution of the
|
|
Packit |
5bd3a9 |
software without specific, written prior permission.
|
|
Packit |
5bd3a9 |
|
|
Packit |
5bd3a9 |
DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
|
Packit |
5bd3a9 |
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
|
|
Packit |
5bd3a9 |
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
|
|
Packit |
5bd3a9 |
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
|
Packit |
5bd3a9 |
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
|
Packit |
5bd3a9 |
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
|
Packit |
5bd3a9 |
SOFTWARE.
|
|
Packit |
5bd3a9 |
|
|
Packit |
5bd3a9 |
******************************************************************/
|
|
Packit |
5bd3a9 |
|
|
Packit |
5bd3a9 |
/* XrmParseCommand()
|
|
Packit |
5bd3a9 |
|
|
Packit |
5bd3a9 |
Parse command line and store argument values into resource database
|
|
Packit |
5bd3a9 |
|
|
Packit |
5bd3a9 |
Allows any un-ambiguous abbreviation for an option name, but requires
|
|
Packit |
5bd3a9 |
that the table be ordered with any options that are prefixes of
|
|
Packit |
5bd3a9 |
other options appearing before the longer version in the table.
|
|
Packit |
5bd3a9 |
*/
|
|
Packit |
5bd3a9 |
|
|
Packit |
5bd3a9 |
#ifdef HAVE_CONFIG_H
|
|
Packit |
5bd3a9 |
#include <config.h>
|
|
Packit |
5bd3a9 |
#endif
|
|
Packit |
5bd3a9 |
#include "Xlibint.h"
|
|
Packit |
5bd3a9 |
#include <X11/Xresource.h>
|
|
Packit |
5bd3a9 |
#include <stdio.h>
|
|
Packit |
5bd3a9 |
|
|
Packit |
5bd3a9 |
|
|
Packit |
5bd3a9 |
static void _XReportParseError(XrmOptionDescRec *arg, const char *msg)
|
|
Packit |
5bd3a9 |
{
|
|
Packit |
5bd3a9 |
(void) fprintf(stderr, "Error parsing argument \"%s\" (%s); %s\n",
|
|
Packit |
5bd3a9 |
arg->option, arg->specifier, msg);
|
|
Packit |
5bd3a9 |
exit(1);
|
|
Packit |
5bd3a9 |
}
|
|
Packit |
5bd3a9 |
|
|
Packit |
5bd3a9 |
void
|
|
Packit |
5bd3a9 |
XrmParseCommand(
|
|
Packit |
5bd3a9 |
XrmDatabase *pdb, /* data base */
|
|
Packit |
5bd3a9 |
register XrmOptionDescList options, /* pointer to table of valid options */
|
|
Packit |
5bd3a9 |
int num_options, /* number of options */
|
|
Packit |
5bd3a9 |
_Xconst char *prefix, /* name to prefix resources with */
|
|
Packit |
5bd3a9 |
int *argc, /* address of argument count */
|
|
Packit |
5bd3a9 |
char **argv) /* argument list (command line) */
|
|
Packit |
5bd3a9 |
{
|
|
Packit |
5bd3a9 |
int foundOption;
|
|
Packit |
5bd3a9 |
char **argsave;
|
|
Packit |
5bd3a9 |
register int i, myargc;
|
|
Packit |
5bd3a9 |
XrmBinding bindings[100];
|
|
Packit |
5bd3a9 |
XrmQuark quarks[100];
|
|
Packit |
5bd3a9 |
XrmBinding *start_bindings;
|
|
Packit |
5bd3a9 |
XrmQuark *start_quarks;
|
|
Packit |
5bd3a9 |
char *optP, *argP = NULL, optchar, argchar = 0;
|
|
Packit |
5bd3a9 |
int matches;
|
|
Packit |
5bd3a9 |
enum {DontCare, Check, NotSorted, Sorted} table_is_sorted;
|
|
Packit |
5bd3a9 |
char **argend;
|
|
Packit |
5bd3a9 |
|
|
Packit |
5bd3a9 |
#define PutCommandResource(value_str) \
|
|
Packit |
5bd3a9 |
{ \
|
|
Packit |
5bd3a9 |
XrmStringToBindingQuarkList( \
|
|
Packit |
5bd3a9 |
options[i].specifier, start_bindings, start_quarks); \
|
|
Packit |
5bd3a9 |
XrmQPutStringResource(pdb, bindings, quarks, value_str); \
|
|
Packit |
5bd3a9 |
} /* PutCommandResource */
|
|
Packit |
5bd3a9 |
|
|
Packit |
5bd3a9 |
myargc = (*argc);
|
|
Packit |
5bd3a9 |
argend = argv + myargc;
|
|
Packit |
5bd3a9 |
argsave = ++argv;
|
|
Packit |
5bd3a9 |
|
|
Packit |
5bd3a9 |
/* Initialize bindings/quark list with prefix (typically app name). */
|
|
Packit |
5bd3a9 |
quarks[0] = XrmStringToName(prefix);
|
|
Packit |
5bd3a9 |
bindings[0] = XrmBindTightly;
|
|
Packit |
5bd3a9 |
start_quarks = quarks+1;
|
|
Packit |
5bd3a9 |
start_bindings = bindings+1;
|
|
Packit |
5bd3a9 |
|
|
Packit |
5bd3a9 |
table_is_sorted = (myargc > 2) ? Check : DontCare;
|
|
Packit |
5bd3a9 |
for (--myargc; myargc > 0; --myargc, ++argv) {
|
|
Packit |
5bd3a9 |
foundOption = False;
|
|
Packit |
5bd3a9 |
matches = 0;
|
|
Packit |
5bd3a9 |
for (i=0; i < num_options; ++i) {
|
|
Packit |
5bd3a9 |
/* checking the sort order first insures we don't have to
|
|
Packit |
5bd3a9 |
re-do the check if the arg hits on the last entry in
|
|
Packit |
5bd3a9 |
the table. Useful because usually '=' is the last entry
|
|
Packit |
5bd3a9 |
and users frequently specify geometry early in the command */
|
|
Packit |
5bd3a9 |
if (table_is_sorted == Check && i > 0 &&
|
|
Packit |
5bd3a9 |
strcmp(options[i].option, options[i-1].option) < 0) {
|
|
Packit |
5bd3a9 |
table_is_sorted = NotSorted;
|
|
Packit |
5bd3a9 |
}
|
|
Packit |
5bd3a9 |
for (argP = *argv, optP = options[i].option;
|
|
Packit |
5bd3a9 |
(optchar = *optP++) &&
|
|
Packit |
5bd3a9 |
(argchar = *argP++) &&
|
|
Packit |
5bd3a9 |
argchar == optchar;);
|
|
Packit |
5bd3a9 |
if (!optchar) {
|
|
Packit |
5bd3a9 |
if (!*argP ||
|
|
Packit |
5bd3a9 |
options[i].argKind == XrmoptionStickyArg ||
|
|
Packit |
5bd3a9 |
options[i].argKind == XrmoptionIsArg) {
|
|
Packit |
5bd3a9 |
/* give preference to exact matches, StickyArg and IsArg */
|
|
Packit |
5bd3a9 |
matches = 1;
|
|
Packit |
5bd3a9 |
foundOption = i;
|
|
Packit |
5bd3a9 |
break;
|
|
Packit |
5bd3a9 |
}
|
|
Packit |
5bd3a9 |
}
|
|
Packit |
5bd3a9 |
else if (!argchar) {
|
|
Packit |
5bd3a9 |
/* may be an abbreviation for this option */
|
|
Packit |
5bd3a9 |
matches++;
|
|
Packit |
5bd3a9 |
foundOption = i;
|
|
Packit |
5bd3a9 |
}
|
|
Packit |
5bd3a9 |
else if (table_is_sorted == Sorted && optchar > argchar) {
|
|
Packit |
5bd3a9 |
break;
|
|
Packit |
5bd3a9 |
}
|
|
Packit |
5bd3a9 |
if (table_is_sorted == Check && i > 0 &&
|
|
Packit |
5bd3a9 |
strcmp(options[i].option, options[i-1].option) < 0) {
|
|
Packit |
5bd3a9 |
table_is_sorted = NotSorted;
|
|
Packit |
5bd3a9 |
}
|
|
Packit |
5bd3a9 |
}
|
|
Packit |
5bd3a9 |
if (table_is_sorted == Check && i >= (num_options-1))
|
|
Packit |
5bd3a9 |
table_is_sorted = Sorted;
|
|
Packit |
5bd3a9 |
if (matches == 1) {
|
|
Packit |
5bd3a9 |
i = foundOption;
|
|
Packit |
5bd3a9 |
switch (options[i].argKind){
|
|
Packit |
5bd3a9 |
case XrmoptionNoArg:
|
|
Packit |
5bd3a9 |
--(*argc);
|
|
Packit |
5bd3a9 |
PutCommandResource(options[i].value);
|
|
Packit |
5bd3a9 |
break;
|
|
Packit |
5bd3a9 |
|
|
Packit |
5bd3a9 |
case XrmoptionIsArg:
|
|
Packit |
5bd3a9 |
--(*argc);
|
|
Packit |
5bd3a9 |
PutCommandResource(*argv);
|
|
Packit |
5bd3a9 |
break;
|
|
Packit |
5bd3a9 |
|
|
Packit |
5bd3a9 |
case XrmoptionStickyArg:
|
|
Packit |
5bd3a9 |
--(*argc);
|
|
Packit |
5bd3a9 |
PutCommandResource(argP);
|
|
Packit |
5bd3a9 |
break;
|
|
Packit |
5bd3a9 |
|
|
Packit |
5bd3a9 |
case XrmoptionSepArg:
|
|
Packit |
5bd3a9 |
if (myargc > 1) {
|
|
Packit |
5bd3a9 |
++argv; --myargc; --(*argc); --(*argc);
|
|
Packit |
5bd3a9 |
PutCommandResource(*argv);
|
|
Packit |
5bd3a9 |
} else
|
|
Packit |
5bd3a9 |
(*argsave++) = (*argv);
|
|
Packit |
5bd3a9 |
break;
|
|
Packit |
5bd3a9 |
|
|
Packit |
5bd3a9 |
case XrmoptionResArg:
|
|
Packit |
5bd3a9 |
if (myargc > 1) {
|
|
Packit |
5bd3a9 |
++argv; --myargc; --(*argc); --(*argc);
|
|
Packit |
5bd3a9 |
XrmPutLineResource(pdb, *argv);
|
|
Packit |
5bd3a9 |
} else
|
|
Packit |
5bd3a9 |
(*argsave++) = (*argv);
|
|
Packit |
5bd3a9 |
break;
|
|
Packit |
5bd3a9 |
|
|
Packit |
5bd3a9 |
case XrmoptionSkipArg:
|
|
Packit |
5bd3a9 |
if (myargc > 1) {
|
|
Packit |
5bd3a9 |
--myargc;
|
|
Packit |
5bd3a9 |
(*argsave++) = (*argv++);
|
|
Packit |
5bd3a9 |
}
|
|
Packit |
5bd3a9 |
(*argsave++) = (*argv);
|
|
Packit |
5bd3a9 |
break;
|
|
Packit |
5bd3a9 |
|
|
Packit |
5bd3a9 |
case XrmoptionSkipLine:
|
|
Packit |
5bd3a9 |
for (; myargc > 0; myargc--)
|
|
Packit |
5bd3a9 |
(*argsave++) = (*argv++);
|
|
Packit |
5bd3a9 |
break;
|
|
Packit |
5bd3a9 |
|
|
Packit |
5bd3a9 |
case XrmoptionSkipNArgs:
|
|
Packit |
5bd3a9 |
{
|
|
Packit |
5bd3a9 |
register int j = 1 + (long) options[i].value;
|
|
Packit |
5bd3a9 |
|
|
Packit |
5bd3a9 |
if (j > myargc) j = myargc;
|
|
Packit |
5bd3a9 |
for (; j > 0; j--) {
|
|
Packit |
5bd3a9 |
(*argsave++) = (*argv++);
|
|
Packit |
5bd3a9 |
myargc--;
|
|
Packit |
5bd3a9 |
}
|
|
Packit |
5bd3a9 |
argv--; /* went one too far before */
|
|
Packit |
5bd3a9 |
myargc++;
|
|
Packit |
5bd3a9 |
}
|
|
Packit |
5bd3a9 |
break;
|
|
Packit |
5bd3a9 |
|
|
Packit |
5bd3a9 |
default:
|
|
Packit |
5bd3a9 |
_XReportParseError (&options[i], "unknown kind");
|
|
Packit |
5bd3a9 |
break;
|
|
Packit |
5bd3a9 |
}
|
|
Packit |
5bd3a9 |
}
|
|
Packit |
5bd3a9 |
else
|
|
Packit |
5bd3a9 |
(*argsave++) = (*argv); /*compress arglist*/
|
|
Packit |
5bd3a9 |
}
|
|
Packit |
5bd3a9 |
|
|
Packit |
5bd3a9 |
if (argsave < argend)
|
|
Packit |
5bd3a9 |
(*argsave)=NULL; /* put NULL terminator on compressed argv */
|
|
Packit |
5bd3a9 |
}
|