/*
* tkArgv.c --
*
* This file contains a procedure that handles table-based
* argv-argc parsing.
*
* Copyright (c) 1990-1994 The Regents of the University of California.
* Copyright (c) 1994 Sun Microsystems, Inc.
*
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
* SCCS: @(#) tkArgv.c 1.20 96/02/15 18:51:32
*/
#include "tkInt.h"
/*
* Default table of argument descriptors. These are normally available
* in every application.
*/
"Print summary of command-line options and abort"},
(char *) NULL}
};
/*
* Forward declarations for procedures defined in this file:
*/
/*
*----------------------------------------------------------------------
*
* Tk_ParseArgv --
*
* Process an argv array according to a table of expected
* command-line options. See the manual page for more details.
*
* Results:
* The return value is a standard Tcl return value. If an
* error occurs then an error message is left in interp->result.
* Under normal conditions, both *argcPtr and *argv are modified
* to return the arguments that couldn't be processed here (they
* didn't match the option table, or followed an TK_ARGV_REST
* argument).
*
* Side effects:
* Variables may be modified, resources may be entered for tkwin,
* or procedures may be called. It all depends on the arguments
* and their entries in argTable. See the user documentation
* for details.
*
*----------------------------------------------------------------------
*/
int
* NULL means ignore Tk option specs. */
int *argcPtr; /* Number of arguments in argv. Modified
* to hold # args left in argv at end. */
char **argv; /* Array of arguments. Modified to hold
* those that couldn't be processed here. */
int flags; /* Or'ed combination of various flag bits,
* such as TK_ARGV_NO_DEFAULTS. */
{
/* Pointer to the current entry in the
* table of argument descriptions. */
register char c; /* Second character of current arg (used for
* quick check for matching; use 2nd char.
* because first char. will almost always
* be '-'). */
* from argv. */
* argument should be copied (never greater
* than srcIndex). */
int i;
if (flags & TK_ARGV_DONT_SKIP_FIRST_ARG) {
} else {
}
while (argc > 0) {
srcIndex++;
argc--;
if (length > 0) {
c = curArg[1];
} else {
c = 0;
}
/*
* Loop throught the argument descriptors searching for one with
* the matching key string. If found, leave a pointer to it in
* matchPtr.
*/
for (i = 0; i < 2; i++) {
if (i == 0) {
} else {
}
infoPtr++) {
continue;
}
continue;
}
continue;
}
goto gotMatch;
}
if (flags & TK_ARGV_NO_ABBREV) {
continue;
}
"\"", (char *) NULL);
return TCL_ERROR;
}
}
}
/*
* Unrecognized argument. Just copy it down, unless the caller
* prefers an error to be registered.
*/
if (flags & TK_ARGV_NO_LEFTOVERS) {
return TCL_ERROR;
}
dstIndex++;
continue;
}
/*
* Take the appropriate action based on the option type
*/
case TK_ARGV_CONSTANT:
break;
case TK_ARGV_INT:
if (argc == 0) {
goto missingArg;
} else {
char *endPtr;
return TCL_ERROR;
}
srcIndex++;
argc--;
}
break;
case TK_ARGV_STRING:
if (argc == 0) {
goto missingArg;
} else {
srcIndex++;
argc--;
}
break;
case TK_ARGV_UID:
if (argc == 0) {
goto missingArg;
} else {
srcIndex++;
argc--;
}
break;
case TK_ARGV_REST:
goto argsDone;
case TK_ARGV_FLOAT:
if (argc == 0) {
goto missingArg;
} else {
char *endPtr;
(char *) NULL);
return TCL_ERROR;
}
srcIndex++;
argc--;
}
break;
case TK_ARGV_FUNC: {
int (*handlerProc)();
srcIndex += 1;
argc -= 1;
}
break;
}
case TK_ARGV_GENFUNC: {
int (*handlerProc)();
if (argc < 0) {
return TCL_ERROR;
}
break;
}
case TK_ARGV_HELP:
return TCL_ERROR;
case TK_ARGV_CONST_OPTION:
break;
case TK_ARGV_OPTION_VALUE:
if (argc < 1) {
goto missingArg;
}
srcIndex++;
argc--;
break;
if (argc < 2) {
"\" option requires two following arguments",
(char *) NULL);
return TCL_ERROR;
}
srcIndex += 2;
argc -= 2;
break;
default:
return TCL_ERROR;
}
}
/*
* If we broke out of the loop because of an OPT_REST argument,
* copy the remaining arguments down.
*/
while (argc) {
srcIndex++;
dstIndex++;
argc--;
}
return TCL_OK;
"\" option requires an additional argument", (char *) NULL);
return TCL_ERROR;
}
/*
*----------------------------------------------------------------------
*
* PrintUsage --
*
* Generate a help string describing command-line options.
*
* Results:
* Interp->result will be modified to hold a help string
* describing all the options in argTable, plus all those
* in the default table unless TK_ARGV_NO_DEFAULTS is
* specified in flags.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
static void
* result area. */
* descriptions. */
int flags; /* If the TK_ARGV_NO_DEFAULTS bit is set
* in this word, then don't generate
* information for default options. */
{
/*
* First, compute the width of the widest option key, so that we
* can make everything line up.
*/
width = 4;
for (i = 0; i < 2; i++) {
int length;
continue;
}
}
}
}
for (i = 0; ; i++) {
continue;
}
while (numSpaces > 0) {
if (numSpaces >= NUM_SPACES) {
} else {
(char *) NULL);
}
numSpaces -= NUM_SPACES;
}
case TK_ARGV_INT: {
break;
}
case TK_ARGV_FLOAT: {
break;
}
case TK_ARGV_STRING: {
char *string;
}
break;
}
default: {
break;
}
}
}
if ((flags & TK_ARGV_NO_DEFAULTS) || (i > 0)) {
break;
}
(char *) NULL);
}
}