Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: def99c7968228eaca78150d636e7b1352860e3f3
Ticket: 1446696fffffffffffffffffffffffffffffffff
Tcl_ParseArgv as a useful non-Tk version of Tk_ParseArgv
User & Date: sbromle on 2006-03-09 19:29:43
Changes

  1. assignee changed to: "dgp"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    In porting an existing package based on C to one
    that uses Tcl as the glue, I've had the desire to
    have the Tk_ParseArgv functionality without Tk.
    This lead me to find the following old conversation
    regarding this:
    
    http://www.google.com/url?sa=D&q=http://groups.google.ca/group/comp.lang.tcl/browse_thread/thread/c4fea8f0346cf8ae/036961bf476a3b99%3Flnk%3Dst%26q%3DTcl_ParseArgv%26rnum%3D1%23036961bf476a3b99
    
    The arguments against Tcl_ParseArgv is that if you are
    using tcl, then just use it as the main loop, and call
    out to special function C codes as necessary. By doing
    so, you can use one of the many Tcl Command line
    parsing tools listed at http://wiki.tcl.tk/1730.
    
    Now while the arguments against this functionality are
    valid within the context of the process' main loop, it
    breaks down when you want to parse options in
    stand-alone commands. At least this is how I see
    it.
    
    To be more precise, I have a C library to which I want
    to provide a Tcl interface.
    So for each of the functions in the library, I need to
    write a wrapper in C, to provide that command to Tcl.
    If I want these commands to have libpopt or Tk-like
    command options I either have to
      1) Parse the command arguments myself (on the C side); or
      2) Write additional wrappers to the commands in Tcl,
    to pre-parse the options.
    So in the case of (2), I'm making work for myself, when
    all I really want to be able to do is call
    Tcl_ParseArgv and be done with it in the original C
    command wrapper.
    
    NEWays, to get things working quickly, I wrote a
    Tcl_ParseArgv routine, based (of course)
    heavily on the tkArgv.c source (which implements
    Tk_ParseArgv), but with all the Tk specific bits taken
    out.  So now my wrappers can be ported very quickly
    from their current libpopt handled options, to the
    Tcl_ParseArgv.
    
    Summary:
     1) Provide a Tcl_ParseArgv routine that can parse
        a standard argc,argv[] pair.
     2) Useful when functions other than main() wish
        to parse arguments in argc, argv[] format.
     3) Useful when one wishes to have libpopt style
        command line arguments to functions.
       3a) Build argc,argv from objc,objv.
       3b) Parse using Tcl_ParseArgv.
       3c) Parse remaining arguments in familiar C fashion.
     4) Makes re-writing of C-based wrappers written using
        libpopt trivial.
    
    Code (which can be used as a shared library),
    is attached.
    
    
  4. foundin changed to: "None"
  5. priority changed to: "5 Medium"
  6. resolution changed to: "None"
  7. status changed to: "Open"
  8. submitter changed to: "sbromle"
  9. subsystem changed to: ""
  10. title changed to:
    Tcl_ParseArgv as a useful non-Tk version of Tk_ParseArgv
    
  11. type changed to: "Support"