# Copyright (c) 1990-1992 The Regents of the University of California. # Copyright (c) 1994-1996 Sun Microsystems, Inc. # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # # =head1 NAME Tk_ParseArgv - process command-line options =for category C Programming =head1 SYNOPSIS B<#include Etk.hE> int B(I) =head1 ARGUMENTS =over 4 =item Tcl_Interp *interp (in) Interpreter to use for returning error messages. =item Tk_Window tkwin (in) Window to use when arguments specify Tk options. If NULL, then no Tk options will be processed. =item int argcPtr (in/out) Pointer to number of arguments in argv; gets modified to hold number of unprocessed arguments that remain after the call. =item char **argv (in/out) Command line arguments passed to main program. Modified to hold unprocessed arguments that remain after the call. =item Tk_ArgvInfo *argTable (in) Array of argument descriptors, terminated by element with type TK_ARGV_END. =item int flags (in) If non-zero, then it specifies one or more flags that control the parsing of arguments. Different flags may be OR'ed together. The flags currently defined are TK_ARGV_DONT_SKIP_FIRST_ARG, TK_ARGV_NO_ABBREV, TK_ARGV_NO_LEFTOVERS, and TK_ARGV_NO_DEFAULTS. =back =head1 DESCRIPTION B processes an array of command-line arguments according to a table describing the kinds of arguments that are expected. Each of the arguments in I is processed in turn: if it matches one of the entries in I, the argument is processed according to that entry and discarded. The arguments that do not match anything in I are copied down to the beginning of I (retaining their original order) and returned to the caller. At the end of the call B sets I<*argcPtr> to hold the number of arguments that are left in I, and I will hold the value NULL. Normally, B assumes that I is a command name, so it is treated like an argument that doesn't match I and returned to the caller; however, if the TK_ARGV_DONT_SKIP_FIRST_ARG bit is set in I then I will be processed just like the other elements of I. B normally returns the value TCL_OK. If an error occurs while parsing the arguments, then TCL_ERROR is returned and B will leave an error message in Iresult> in the standard Tcl fashion. In the event of an error return, I<*argvPtr> will not have been modified, but I could have been partially modified. The possible causes of errors are explained below. The I array specifies the kinds of arguments that are expected; each of its entries has the following structure: typedef struct { char *key; int type; char *src; char *dst; char *help; } Tk_ArgvInfo; The I field is a string such as ``-display'' or ``-bg'' that is compared with the values in I. I indicates how to process an argument that matches I (more on this below). I and I are additional values used in processing the argument. Their exact usage depends on I, but typically I indicates a value and I indicates where to store the value. The B declarations for I and I are placeholders: the actual types may be different. Lastly, I is a string giving a brief description of this option; this string is printed when users ask for help about command-line options. When processing an argument in I, B compares the argument to each of the I's in I. B selects the first specifier whose I matches the argument exactly, if such a specifier exists. Otherwise B selects a specifier for which the argument is a unique abbreviation. If the argument is a unique abbreviation for more than one specifier, then an error is returned. If there is no matching entry in I, then the argument is skipped and returned to the caller. Once a matching argument specifier is found, B processes the argument according to the I field of the specifier. The argument that matched I is called ``the matching argument'' in the descriptions below. As part of the processing, B may also use the next argument in I after the matching argument, which is called ``the following argument''. The legal values for I, and the processing that they cause, are as follows: =over 4 =item B Marks the end of the table. The last entry in I must have this type; all of its other fields are ignored and it will never match any arguments. =item B I is treated as an integer and I is treated as a pointer to an integer. I is stored at I<*dst>. The matching argument is discarded. =item B The following argument must contain an integer string in the format accepted by B (e.g. ``0'' and ``0x'' prefixes may be used to specify octal or hexadecimal numbers, respectively). I is treated as a pointer to an integer; the following argument is converted to an integer value and stored at I<*dst>. I is ignored. The matching and following arguments are discarded from I. =item B The following argument must contain a floating-point number in the format accepted by B. I is treated as the address of an double-precision floating point value; the following argument is converted to a double-precision value and stored at I<*dst>. The matching and following arguments are discarded from I. =item B In this form, I is treated as a pointer to a (char *); B stores at I<*dst> a pointer to the following argument, and discards the matching and following arguments from I. I is ignored. =item B This form is similar to TK_ARGV_STRING, except that the argument is turned into a Tk_Uid by calling B. I is treated as a pointer to a Tk_Uid; B stores at I<*dst> the Tk_Uid corresponding to the following argument, and discards the matching and following arguments from I. I is ignored. =item B This form causes a Tk option to be set (as if the B