home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / man / cat.3 / ParseArgv.3 < prev    next >
Encoding:
Text File  |  1995-07-26  |  27.7 KB  |  526 lines

  1.  
  2.  
  3.  
  4.      TTTTkkkk____PPPPaaaarrrrsssseeeeAAAArrrrggggvvvv((((3333))))              TTTTkkkk (((( ))))               TTTTkkkk____PPPPaaaarrrrsssseeeeAAAArrrrggggvvvv((((3333))))
  5.  
  6.  
  7.  
  8.      _________________________________________________________________
  9.  
  10.      NNNNAAAAMMMMEEEE
  11.           Tk_ParseArgv - process command-line options
  12.  
  13.      SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  14.           ####iiiinnnncccclllluuuuddddeeee <<<<ttttkkkk....hhhh>>>>
  15.  
  16.           int
  17.           TTTTkkkk____PPPPaaaarrrrsssseeeeAAAArrrrggggvvvv(_i_n_t_e_r_p, _t_k_w_i_n, _a_r_g_c_P_t_r, _a_r_g_v, _a_r_g_T_a_b_l_e, _f_l_a_g_s)
  18.  
  19.      AAAARRRRGGGGUUUUMMMMEEEENNNNTTTTSSSS
  20.           Tcl_Interp    *_i_n_t_e_r_p     (in)      Interpreter to  use  for
  21.                                               returning          error
  22.                                               messages.
  23.  
  24.           Tk_Window     _t_k_w_i_n       (in)      Window   to   use   when
  25.                                               arguments   specify   Tk
  26.                                               options.  If NULL,  then
  27.                                               no  Tk  options  will be
  28.                                               processed.
  29.  
  30.           int           _a_r_g_c_P_t_r     (in/out)  Pointer  to  number   of
  31.                                               arguments in argv;  gets
  32.                                               modified to hold  number
  33.                                               of unprocessed arguments
  34.                                               that  remain  after  the
  35.                                               call.
  36.  
  37.           char          **_a_r_g_v      (in/out)  Command  line  arguments
  38.                                               passed  to main program.
  39.                                               Modified     to     hold
  40.                                               unprocessed    arguments
  41.                                               that  remain  after  the
  42.                                               call.
  43.  
  44.           Tk_ArgvInfo   *_a_r_g_T_a_b_l_e   (in)      Array    of     argument
  45.                                               descriptors,  terminated
  46.                                               by  element  with   type
  47.                                               TK_ARGV_END.
  48.  
  49.           int           _f_l_a_g_s       (in)      If  non-zero,  then   it
  50.                                               specifies  one  or  more
  51.                                               flags that  control  the
  52.                                               parsing   of  arguments.
  53.                                               Different flags  may  be
  54.                                               OR'ed together.  The
  55.                                               flags currently defined
  56.                                               are
  57.                                               TK_ARGV_DONT_SKIP_FIRST_ARG,
  58.                                               TK_ARGV_NO_ABBREV,
  59.                                               TK_ARGV_NO_LEFTOVERS,
  60.  
  61.  
  62.  
  63.      Page 1                                          (printed 7/23/95)
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.      TTTTkkkk____PPPPaaaarrrrsssseeeeAAAArrrrggggvvvv((((3333))))              TTTTkkkk (((( ))))               TTTTkkkk____PPPPaaaarrrrsssseeeeAAAArrrrggggvvvv((((3333))))
  71.  
  72.  
  73.  
  74.                                               and TK_ARGV_NO_DEFAULTS.
  75.      _________________________________________________________________
  76.  
  77.      DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  78.           TTTTkkkk____PPPPaaaarrrrsssseeeeAAAArrrrggggvvvv processes an array  of  command-line  arguments
  79.           according  to a table describing the kinds of arguments that
  80.           are expected.  Each of the arguments in _a_r_g_v is processed in
  81.           turn:   if  it  matches  one of the entries in _a_r_g_T_a_b_l_e, the
  82.           argument is processed according to that entry and discarded.
  83.           The  arguments  that  do  not match anything in _a_r_g_T_a_b_l_e are
  84.           copied down  to  the  beginning  of  _a_r_g_v  (retaining  their
  85.           original  order)  and returned to the caller.  At the end of
  86.           the call TTTTkkkk____PPPPaaaarrrrsssseeeeAAAArrrrggggvvvv sets *_a_r_g_c_P_t_r to hold  the  number  of
  87.           arguments  that  are  left  in _a_r_g_v, and _a_r_g_v[*_a_r_g_c_P_t_r] will
  88.           hold the value NULL.  Normally,  TTTTkkkk____PPPPaaaarrrrsssseeeeAAAArrrrggggvvvv  assumes  that
  89.           _a_r_g_v[_0] is a command name, so it is treated like an argument
  90.           that doesn't match _a_r_g_T_a_b_l_e  and  returned  to  the  caller;
  91.           however,  if  the  TK_ARGV_DONT_SKIP_FIRST_ARG bit is set in
  92.           _f_l_a_g_s then _a_r_g_v[_0] will be processed  just  like  the  other
  93.           elements of _a_r_g_v.
  94.  
  95.           TTTTkkkk____PPPPaaaarrrrsssseeeeAAAArrrrggggvvvv normally returns the value TCL_OK.  If an error
  96.           occurs  while  parsing  the  arguments,  then  TCL_ERROR  is
  97.           returned and TTTTkkkk____PPPPaaaarrrrsssseeeeAAAArrrrggggvvvv will leave  an  error  message  in
  98.           _i_n_t_e_r_p->_r_e_s_u_l_t in the standard Tcl fashion.  In the event of
  99.           an error return, *_a_r_g_v_P_t_r will not have been  modified,  but
  100.           _a_r_g_v  could  have  been  partially  modified.   The possible
  101.           causes of errors are explained below.
  102.  
  103.           The _a_r_g_T_a_b_l_e array specifies the kinds of arguments that are
  104.           expected;  each of its entries has the following structure:
  105.  
  106.                ttttyyyyppppeeeeddddeeeeffff ssssttttrrrruuuucccctttt {
  107.                    cccchhhhaaaarrrr*_k_e_y;
  108.                    iiiinnnntttt _t_y_p_e;
  109.                    cccchhhhaaaarrrr*_s_r_c;
  110.                    cccchhhhaaaarrrr*_d_s_t;
  111.                    cccchhhhaaaarrrr*_h_e_l_p;
  112.                }}}} TTTTkkkk____AAAArrrrggggvvvvIIIInnnnffffoooo;;;;
  113.           The _k_e_y field is a string such as  ``-display''  or  ``-bg''
  114.           that  is  compared  with the values in _a_r_g_v.  _T_y_p_e indicates
  115.           how to process an argument that matches _k_e_y  (more  on  this
  116.           below).    _S_r_c   and  _d_s_t  are  additional  values  used  in
  117.           processing the argument.  Their exact usage depends on _t_y_p_e,
  118.           but  typically _s_r_c indicates a value and _d_s_t indicates where
  119.           to store the value.  The cccchhhhaaaarrrr **** declarations for _s_r_c and _d_s_t
  120.           are  placeholders:   the  actual  types  may  be  different.
  121.           Lastly, _h_e_l_p is a string giving a brief description of  this
  122.           option;   this  string  is  printed  when users ask for help
  123.           about command-line options.
  124.  
  125.  
  126.      Page 2                                          (printed 7/23/95)
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.      TTTTkkkk____PPPPaaaarrrrsssseeeeAAAArrrrggggvvvv((((3333))))              TTTTkkkk (((( ))))               TTTTkkkk____PPPPaaaarrrrsssseeeeAAAArrrrggggvvvv((((3333))))
  134.  
  135.  
  136.  
  137.           When processing an argument in _a_r_g_v,  TTTTkkkk____PPPPaaaarrrrsssseeeeAAAArrrrggggvvvv  compares
  138.           the argument to each of the _k_e_y's in _a_r_g_T_a_b_l_e.  TTTTkkkk____PPPPaaaarrrrsssseeeeAAAArrrrggggvvvv
  139.           selects the first specifier whose _k_e_y matches  the  argument
  140.           exactly, if such a specifier exists.  Otherwise TTTTkkkk____PPPPaaaarrrrsssseeeeAAAArrrrggggvvvv
  141.           selects a specifier for  which  the  argument  is  a  unique
  142.           abbreviation.   If the argument is a unique abbreviation for
  143.           more than one specifier, then  an  error  is  returned.   If
  144.           there is no matching entry in _a_r_g_T_a_b_l_e, then the argument is
  145.           skipped and returned to the caller.
  146.  
  147.           Once a matching argument specifier  is  found,  TTTTkkkk____PPPPaaaarrrrsssseeeeAAAArrrrggggvvvv
  148.           processes  the  argument  according to the _t_y_p_e field of the
  149.           specifier.  The argument that matched _k_e_y  is  called  ``the
  150.           matching  argument''  in the descriptions below.  As part of
  151.           the processing, TTTTkkkk____PPPPaaaarrrrsssseeeeAAAArrrrggggvvvv may also use the next  argument
  152.           in  _a_r_g_v  after the matching argument, which is called ``the
  153.           following argument''.  The legal values for  _t_y_p_e,  and  the
  154.           processing that they cause, are as follows:
  155.  
  156.           TTTTKKKK____AAAARRRRGGGGVVVV____EEEENNNNDDDD
  157.                Marks the end of the table.  The last entry in _a_r_g_T_a_b_l_e
  158.                must  have  this  type;   all  of  its other fields are
  159.                ignored and it will never match any arguments.
  160.  
  161.           TTTTKKKK____AAAARRRRGGGGVVVV____CCCCOOOONNNNSSSSTTTTAAAANNNNTTTT
  162.                _S_r_c is treated as an integer and _d_s_t is  treated  as  a
  163.                pointer  to  an  integer.   _S_r_c is stored at *_d_s_t.  The
  164.                matching argument is discarded.
  165.  
  166.           TTTTKKKK____AAAARRRRGGGGVVVV____IIIINNNNTTTT
  167.                The following argument must contain an  integer  string
  168.                in the format accepted by ssssttttrrrrttttoooollll (e.g. ``0'' and ``0x''
  169.                prefixes may be used to specify  octal  or  hexadecimal
  170.                numbers, respectively).  _D_s_t is treated as a pointer to
  171.                an integer;  the following argument is converted to  an
  172.                integer value and stored at *_d_s_t.  _S_r_c is ignored.  The
  173.                matching and following  arguments  are  discarded  from
  174.                _a_r_g_v.
  175.  
  176.           TTTTKKKK____AAAARRRRGGGGVVVV____FFFFLLLLOOOOAAAATTTT
  177.                The following argument must  contain  a  floating-point
  178.                number  in  the  format  accepted  by  ssssttttrrrrttttoooollll.   _D_s_t is
  179.                treated as the address of an double-precision  floating
  180.                point  value;  the following argument is converted to a
  181.                double-precision  value  and  stored  at   *_d_s_t.    The
  182.                matching  and  following  arguments  are discarded from
  183.                _a_r_g_v.
  184.  
  185.           TTTTKKKK____AAAARRRRGGGGVVVV____SSSSTTTTRRRRIIIINNNNGGGG
  186.                In this form, _d_s_t is treated as a pointer  to  a  (char
  187.                *);  TTTTkkkk____PPPPaaaarrrrsssseeeeAAAArrrrggggvvvv  stores  at  *_d_s_t  a  pointer  to the
  188.                following  argument,  and  discards  the  matching  and
  189.  
  190.  
  191.  
  192.      Page 3                                          (printed 7/23/95)
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.      TTTTkkkk____PPPPaaaarrrrsssseeeeAAAArrrrggggvvvv((((3333))))              TTTTkkkk (((( ))))               TTTTkkkk____PPPPaaaarrrrsssseeeeAAAArrrrggggvvvv((((3333))))
  200.  
  201.  
  202.  
  203.                following arguments from _a_r_g_v.  _S_r_c is ignored.
  204.  
  205.           TTTTKKKK____AAAARRRRGGGGVVVV____UUUUIIIIDDDD
  206.                This form is similar to TK_ARGV_STRING, except that the
  207.                argument  is turned into a Tk_Uid by calling TTTTkkkk____GGGGeeeettttUUUUiiiidddd.
  208.                _D_s_t is treated as a pointer to a  Tk_Uid;  TTTTkkkk____PPPPaaaarrrrsssseeeeAAAArrrrggggvvvv
  209.                stores   at   *_d_s_t  the  Tk_Uid  corresponding  to  the
  210.                following  argument,  and  discards  the  matching  and
  211.                following arguments from _a_r_g_v.  _S_r_c is ignored.
  212.  
  213.           TTTTKKKK____AAAARRRRGGGGVVVV____CCCCOOOONNNNSSSSTTTT____OOOOPPPPTTTTIIIIOOOONNNN
  214.                This form causes a Tk option  to  be  set  (as  if  the
  215.                ooooppppttttiiiioooonnnn  command  had  been  invoked).  The _s_r_c field is
  216.                treated as a pointer to a string giving the value of an
  217.                option,  and _d_s_t is treated as a pointer to the name of
  218.                the option.  The matching argument  is  discarded.   If
  219.                _t_k_w_i_n  is  NULL,  then argument specifiers of this type
  220.                are ignored (as if they did not exist).
  221.  
  222.           TTTTKKKK____AAAARRRRGGGGVVVV____OOOOPPPPTTTTIIIIOOOONNNN____VVVVAAAALLLLUUUUEEEE
  223.                This form is similar  to  TK_ARGV_CONST_OPTION,  except
  224.                that  the  value  of  the  option  is  taken  from  the
  225.                following argument instead of from _s_r_c.  _D_s_t is used as
  226.                the  name of the option.  _S_r_c is ignored.  The matching
  227.                and following arguments are  discarded.   If  _t_k_w_i_n  is
  228.                NULL, then argument specifiers of this type are ignored
  229.                (as if they did not exist).
  230.  
  231.           TTTTKKKK____AAAARRRRGGGGVVVV____OOOOPPPPTTTTIIIIOOOONNNN____NNNNAAAAMMMMEEEE____VVVVAAAALLLLUUUUEEEE
  232.                In this case the following argument  is  taken  as  the
  233.                name  of  a  Tk  option  and the argument after that is
  234.                taken as the value for that option.  Both _s_r_c  and  _d_s_t
  235.                are  ignored.   All  three arguments are discarded from
  236.                _a_r_g_v.  If _t_k_w_i_n is NULL, then  argument  specifiers  of
  237.                this type are ignored (as if they did not exist).
  238.  
  239.           TTTTKKKK____AAAARRRRGGGGVVVV____HHHHEEEELLLLPPPP
  240.                When this kind of option is  encountered,  TTTTkkkk____PPPPaaaarrrrsssseeeeAAAArrrrggggvvvv
  241.                uses  the  _h_e_l_p  fields of _a_r_g_T_a_b_l_e to format a message
  242.                describing all the valid  arguments.   The  message  is
  243.                placed   in  _i_n_t_e_r_p->_r_e_s_u_l_t  and  TTTTkkkk____PPPPaaaarrrrsssseeeeAAAArrrrggggvvvv  returns
  244.                TCL_ERROR.  When  this  happens,  the  caller  normally
  245.                prints  the  help message and aborts.  If the _k_e_y field
  246.                of a TK_ARGV_HELP specifier is NULL, then the specifier
  247.                will  never  match  any  arguments;   in  this case the
  248.                specifier simply provides  extra  documentation,  which
  249.                will  be  included  when  some other TK_ARGV_HELP entry
  250.                causes help information to be returned.
  251.  
  252.           TTTTKKKK____AAAARRRRGGGGVVVV____RRRREEEESSSSTTTT
  253.                This option is used by programs or commands that  allow
  254.                the last several of their options to be the name and/or
  255.  
  256.  
  257.  
  258.      Page 4                                          (printed 7/23/95)
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.      TTTTkkkk____PPPPaaaarrrrsssseeeeAAAArrrrggggvvvv((((3333))))              TTTTkkkk (((( ))))               TTTTkkkk____PPPPaaaarrrrsssseeeeAAAArrrrggggvvvv((((3333))))
  266.  
  267.  
  268.  
  269.                options for some  other  program.   If  a  TTTTKKKK____AAAARRRRGGGGVVVV____RRRREEEESSSSTTTT
  270.                argument  is  found,  then TTTTkkkk____PPPPaaaarrrrsssseeeeAAAArrrrggggvvvv doesn't process
  271.                any of the remaining arguments;  it returns them all at
  272.                the beginning of _a_r_g_v (along with any other unprocessed
  273.                arguments).  In addition, TTTTkkkk____PPPPaaaarrrrsssseeeeAAAArrrrggggvvvv  treats  _d_s_t  as
  274.                the address of an integer value, and stores at *_d_s_t the
  275.                index of the first of the TTTTKKKK____AAAARRRRGGGGVVVV____RRRREEEESSSSTTTT options  in  the
  276.                returned  _a_r_g_v.  This allows the program to distinguish
  277.                the TTTTKKKK____AAAARRRRGGGGVVVV____RRRREEEESSSSTTTT options from other unprocessed options
  278.                that preceeded the TTTTKKKK____AAAARRRRGGGGVVVV____RRRREEEESSSSTTTT.
  279.  
  280.           TTTTKKKK____AAAARRRRGGGGVVVV____FFFFUUUUNNNNCCCC
  281.                For this kind  of  argument,  _s_r_c  is  treated  as  the
  282.                address of a procedure, which is invoked to process the
  283.                following argument.   The  procedure  should  have  the
  284.                following structure:
  285.  
  286.                iiiinnnntttt
  287.                _f_u_n_c(_d_s_t, _k_e_y, _n_e_x_t_A_r_g)
  288.                    cccchhhhaaaarrrr    *_d_s_t;
  289.                    cccchhhhaaaarrrr    *_k_e_y;
  290.                    cccchhhhaaaarrrr    *_n_e_x_t_A_r_g;
  291.                {
  292.                }
  293.                The  _d_s_t  and   _k_e_y   parameters   will   contain   the
  294.                corresponding  fields  from  the  _a_r_g_T_a_b_l_e  entry,  and
  295.                _n_e_x_t_A_r_g will point to the following argument from  _a_r_g_v
  296.                (or  NULL  if  there  aren't any more arguments left in
  297.                _a_r_g_v).  If _f_u_n_c  uses  _n_e_x_t_A_r_g  (so  that  TTTTkkkk____PPPPaaaarrrrsssseeeeAAAArrrrggggvvvv
  298.                should discard it), then it should return 1.  Otherwise
  299.                it should return 0 and  TTTTkkkkPPPPaaaarrrrsssseeeeAAAArrrrggggvvvv  will  process  the
  300.                following  argument  in  the normal fashion.  In either
  301.                event the matching argument is discarded.
  302.  
  303.           TTTTKKKK____AAAARRRRGGGGVVVV____GGGGEEEENNNNFFFFUUUUNNNNCCCC
  304.                This form provides a more  general  procedural  escape.
  305.                It treats _s_r_c as the address of a procedure, and passes
  306.                that procedure all of  the  remaining  arguments.   The
  307.                procedure should have the following form:
  308.  
  309.                iiiinnnntttt
  310.                _g_e_n_f_u_n_c(_d_s_t, _i_n_t_e_r_p, _k_e_y, _a_r_g_c, _a_r_g_v)
  311.                    cccchhhhaaaarrrr    *_d_s_t;
  312.                    TTTTccccllll____IIIInnnntttteeeerrrrpppp  *_i_n_t_e_r_p;
  313.                    cccchhhhaaaarrrr    *_k_e_y;
  314.                    iiiinnnntttt _a_r_g_c;
  315.                    cccchhhhaaaarrrr    **_a_r_g_v;
  316.                {
  317.                }
  318.  
  319.  
  320.  
  321.      Page 5                                          (printed 7/23/95)
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.      TTTTkkkk____PPPPaaaarrrrsssseeeeAAAArrrrggggvvvv((((3333))))              TTTTkkkk (((( ))))               TTTTkkkk____PPPPaaaarrrrsssseeeeAAAArrrrggggvvvv((((3333))))
  329.  
  330.  
  331.  
  332.                The  _d_s_t  and   _k_e_y   parameters   will   contain   the
  333.                corresponding  fields  from the _a_r_g_T_a_b_l_e entry.  _I_n_t_e_r_p
  334.                will  be  the  same   as   the   _i_n_t_e_r_p   argument   to
  335.                TTTTccccllll____PPPPaaaarrrrsssseeeeAAAArrrrggggvvvv.   _A_r_g_c  and  _a_r_g_v  refer  to  all of the
  336.                options after the matching one.  _G_e_n_f_u_n_c should  behave
  337.                in a fashion similar to TTTTkkkk____PPPPaaaarrrrsssseeeeAAAArrrrggggvvvv:  parse as many of
  338.                the remaining arguments as it can, then return any that
  339.                are  left  by  compacting them to the beginning of _a_r_g_v
  340.                (starting at _a_r_g_v[0]).  _G_e_n_f_u_n_c should return  a  count
  341.                of  how  many  arguments are left in _a_r_g_v; TTTTkkkk____PPPPaaaarrrrsssseeeeAAAArrrrggggvvvv
  342.                will process them.  If _g_e_n_f_u_n_c encounters an error then
  343.                it  should leave an error message in _i_n_t_e_r_p->_r_e_s_u_l_t, in
  344.                the usual  Tcl  fashion,  and  return  -1;   when  this
  345.                happens  TTTTkkkk____PPPPaaaarrrrsssseeeeAAAArrrrggggvvvv  will  abort  its  processing and
  346.                return TCL_ERROR.
  347.  
  348.  
  349.      FFFFLLLLAAAAGGGGSSSS
  350.           TTTTKKKK____AAAARRRRGGGGVVVV____DDDDOOOONNNNTTTT____SSSSKKKKIIIIPPPP____FFFFIIIIRRRRSSSSTTTT____AAAARRRRGGGG
  351.                TTTTkkkk____PPPPaaaarrrrsssseeeeAAAArrrrggggvvvv normally treats _a_r_g_v[_0] as  a  program  or
  352.                command  name,  and returns it to the caller just as if
  353.                it hadn't matched _a_r_g_T_a_b_l_e.  If  this  flag  is  given,
  354.                then _a_r_g_v[_0] is not given special treatment.
  355.  
  356.           TTTTKKKK____AAAARRRRGGGGVVVV____NNNNOOOO____AAAABBBBBBBBRRRREEEEVVVV
  357.                Normally, TTTTkkkk____PPPPaaaarrrrsssseeeeAAAArrrrggggvvvv accepts unique abbreviations for
  358.                _k_e_y  values  in  _a_r_g_T_a_b_l_e.   If this flag is given then
  359.                only exact matches will be acceptable.
  360.  
  361.           TTTTKKKK____AAAARRRRGGGGVVVV____NNNNOOOO____LLLLEEEEFFFFTTTTOOOOVVVVEEEERRRRSSSS
  362.                Normally, TTTTkkkk____PPPPaaaarrrrsssseeeeAAAArrrrggggvvvv returns  unrecognized  arguments
  363.                to  the  caller.   If  this  bit  is  set in _f_l_a_g_s then
  364.                TTTTkkkk____PPPPaaaarrrrsssseeeeAAAArrrrggggvvvv will return an error if it encounters  any
  365.                argument   that   doesn't  match  _a_r_g_T_a_b_l_e.   The  only
  366.                exception to  this  rule  is  _a_r_g_v[_0],  which  will  be
  367.                returned  to  the  caller  with  no  errors  as long as
  368.                TK_ARGV_DONT_SKIP_FIRST_ARG isn't specified.
  369.  
  370.           TTTTKKKK____AAAARRRRGGGGVVVV____NNNNOOOO____DDDDEEEEFFFFAAAAUUUULLLLTTTTSSSS
  371.                Normally, TTTTkkkk____PPPPaaaarrrrsssseeeeAAAArrrrggggvvvv searches an  internal  table  of
  372.                standard  argument  specifiers in addition to _a_r_g_T_a_b_l_e.
  373.                If this bit is set in _f_l_a_g_s, then TTTTkkkk____PPPPaaaarrrrsssseeeeAAAArrrrggggvvvv will use
  374.                only _a_r_g_T_a_b_l_e and not its default table.
  375.  
  376.  
  377.      EEEEXXXXAAAAMMMMPPPPLLLLEEEE
  378.           Here is an example definition of an _a_r_g_T_a_b_l_e and some sample
  379.           command lines that use the options.  Note the effect on _a_r_g_c
  380.           and  _a_r_g_v;   arguments   processed   by   TTTTkkkk____PPPPaaaarrrrsssseeeeAAAArrrrggggvvvv   are
  381.           eliminated from _a_r_g_v, and _a_r_g_c is updated to reflect reduced
  382.           number of arguments.
  383.  
  384.  
  385.  
  386.  
  387.      Page 6                                          (printed 7/23/95)
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394.      TTTTkkkk____PPPPaaaarrrrsssseeeeAAAArrrrggggvvvv((((3333))))              TTTTkkkk (((( ))))               TTTTkkkk____PPPPaaaarrrrsssseeeeAAAArrrrggggvvvv((((3333))))
  395.  
  396.  
  397.  
  398.                /*
  399.                 * Define and set default values for globals.
  400.                 */
  401.                int debugFlag = 0;
  402.                int numReps = 100;
  403.                char defaultFileName[] = "out";
  404.                char *fileName = defaultFileName;
  405.                Boolean exec = FALSE;
  406.  
  407.                /*
  408.                 * Define option descriptions.
  409.                 */
  410.                Tk_ArgvInfo argTable[] = {
  411.                    {"-X", TK_ARGV_CONSTANT, (char *) 1, (char *) &debugFlag,
  412.                        "Turn on debugging printfs"},
  413.                    {"-N", TK_ARGV_INT, (char *) NULL, (char *) &numReps,
  414.                        "Number of repetitions"},
  415.                    {"-of", TK_ARGV_STRING, (char *) NULL, (char *) &fileName,
  416.                        "Name of file for output"},
  417.                    {"x", TK_ARGV_REST, (char *) NULL, (char *) &exec,
  418.                        "File to exec, followed by any arguments (must be last argument)."},
  419.                    {(char *) NULL, TK_ARGV_END, (char *) NULL, (char *) NULL,
  420.                        (char *) NULL}
  421.                };
  422.  
  423.                main(argc, argv)
  424.                    int argc;
  425.                    char *argv[];
  426.                {
  427.                    ...
  428.  
  429.                    if (Tk_ParseArgv(interp, tkwin, &argc, argv, argTable, 0) != TCL_OK) {
  430.                        fprintf(stderr, "%s\n", interp->result);
  431.                        exit(1);
  432.                    }
  433.  
  434.                    /*
  435.                     * Remainder of the program.
  436.                     */
  437.                }
  438.           Note that default values can be assigned to variables  named
  439.           in  _a_r_g_T_a_b_l_e:  the variables will only be overwritten if the
  440.           particular arguments are present in  _a_r_g_v.   Here  are  some
  441.           example command lines and their effects.
  442.  
  443.                prog -N 200 infile      # just sets the numReps variable to 200
  444.                prog -of out200 infile  # sets fileName to reference "out200"
  445.                prog -XN 10 infile      # sets the debug flag, also sets numReps
  446.           In  all  of  the  above  examples,  _a_r_g_c  will  be  set   by
  447.           TTTTkkkk____PPPPaaaarrrrsssseeeeAAAArrrrggggvvvv to 2, _a_r_g_v[0] will be ``prog'', _a_r_g_v[1] will be
  448.  
  449.  
  450.  
  451.      Page 7                                          (printed 7/23/95)
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.      TTTTkkkk____PPPPaaaarrrrsssseeeeAAAArrrrggggvvvv((((3333))))              TTTTkkkk (((( ))))               TTTTkkkk____PPPPaaaarrrrsssseeeeAAAArrrrggggvvvv((((3333))))
  459.  
  460.  
  461.  
  462.           ``infile'', and _a_r_g_v[2] will be NULL.
  463.  
  464.  
  465.      KKKKEEEEYYYYWWWWOOOORRRRDDDDSSSS
  466.           arguments, command line, options
  467.  
  468.  
  469.  
  470.  
  471.  
  472.  
  473.  
  474.  
  475.  
  476.  
  477.  
  478.  
  479.  
  480.  
  481.  
  482.  
  483.  
  484.  
  485.  
  486.  
  487.  
  488.  
  489.  
  490.  
  491.  
  492.  
  493.  
  494.  
  495.  
  496.  
  497.  
  498.  
  499.  
  500.  
  501.  
  502.  
  503.  
  504.  
  505.  
  506.  
  507.  
  508.  
  509.  
  510.  
  511.  
  512.  
  513.  
  514.  
  515.  
  516.  
  517.      Page 8                                          (printed 7/23/95)
  518.  
  519.  
  520.  
  521.