Skip to content
Tcl Source Code View Ticket
Login

View Ticket

Patch to 'glob' for improved speed and cross-platform operab

Closed / Fixed217880ffffffffffffffffffffffffffffffffffCreated 26 years agoUpdated 26 years ago
Descriptionplain2000-10-26 00:45:19
OriginalBugID: 2258 RFE
Version: 8.1.1
SubmitDate: '1999-06-21'
LastModified: '1999-08-06'
Severity: MED
Status: Closed
Submitter: techsupp
ChangedBy: hobbs
RelatedBugIDs: 2363
OS: Windows NT
OSVersion: 4.0sp3
Machine: X86
FixedDate: '2000-10-25'
ClosedDate: '1999-08-06'


Name:
vince darley

CVS:
RCS: @(#) $Id: changes,v 1.45 1999/05/26 02:39:12 stanton Exp $

CustomShell:
none.

DesiredBehavior:
Changes to glob (Vince Darley, June 1999):
    
    Note: this patch includes additions to the test suite for the new
    features.
    It does not include changes to the man pages, but a reasonably detailed
    
    description follows:
    
     # Backwards compatible extensions to the 'glob' command to address
     # some current issues:
     # 
     # The current glob uses 'Tcl_AppendElement' internally; this has
     # been changed to the Object APIs.
     # 
     # 'file join' is incompatible with backslash-quoted directory paths,
     # so it is very difficult to deal with paths containing
     # glob-sensitive characters in a cross-platform way.  E.g. the user
     # selects a directory in a directory-chooser, and I wish to find (i)
     # all html files in that directory; (ii) all html files in any
     # sub-directory of that directory; (iii) all subdirectories of that
     # directory which contain the word 'hello'.  With the new glob, this
     # can be achieved in a simple, cross-platform way as follows:
     # 
     # (i) 
     # 
     # set dir [tk_chooseDirectory]
     # set html_files [glob -dir $dir *.html]
     # 
     # (ii)
     # 
     # set dir [tk_chooseDirectory]
     # set sub_dir_html_files [glob -join -dir $dir * *.html]
     # 
     # (iii)
     # 
     # set dir [tk_chooseDirectory]
     # set sub_dirs [glob -type d -dir $dir *hello*]
     # 
     # These will work even if '$dir' contains []{}*+\?  characters,
     # which would be difficult to achieve using the old glob, without
     # explicit backslash quoting of 'dir', and without explicit use of
     # the current platform's directory separator (':' on MacOS,
     # backslash or forward slash on other platforms).  Using this
     # version of glob has allowed me to simplify otherwise messy code,
     # and remove bugs caused by user-selected paths containing bad
     # characters.
     # 
     # Syntax:
     #   
     #   glob ?switches? name ?name ...?
     #   
     # Switches:
     # 
     #   -nocomplain:   if no files are found, return an empty string,
    rather
     #                  than signal an error.
     #     
     #   -join:         the remaining 'name' arguments are treated as 
     #                  a path specification to be handled with 'file
     #                  join'.
     #                  
     #   -dir <pat>:    search for patterns starting in this directory
     #                  
     #   -path <path>:  search for patterns starting with this path
     #                  prefix (i.e. a directory and a file prefix).
     #   
     #   -types <list of types>: only list files/directories of one of
     #                  the types listed.  Currently only type 'd' is
     #                  supported, which lists only directories (hence
     #                  avoiding the need to specify a platform specific
     #                  separator char), but in the future, more types
     #                  (possibly platform specific) will be supported:
     #                  e.g. on MacOS types such as 'TEXT', 'APPL' will be
     #                  supported.  Unrecognised types are ignored by glob.
     #   
     #   --             signals the end of switches, even if the next 
     #                  argument starts with a '-'.
     # 
     # Each name argument is handled separately, unless '-join' is
     # present.  Note the the '-dir' and '-path' flags are mutually
     # exclusive.
    
    Added cross platform test cases for -dir, -path, -join, -types to
    fileName.test,
    and fixed a few old tests whose results changed as a result of this
    code.
    
    Introduced a new function TclpMatchFilesTypes which effectively
    replaces
    TclpMatchFiles.  It currently has the same functionality, but takes an
    extra argument which will be used to match file type information.  This
    will allow specification of, e.g., executable files, MacOS file types,
    invisible files etc.  At the moment only '-types d' is recognised.  All
    other arguments to -types are simply ignored.
    
    Objectified the build up of the list of files to be returned by glob.
    This involves 
    minor changes to each platform specific TclpMatchFiles function, so that
    Tcl_AppendElement
    is not used (instead Tcl_ListObjAppendElement on Tcl_GetObjResult is
    used).  I've
    tested this so during 'set f [glob *] ; set f {}' the function
    UpdateStringOfList
    is never called.  However this only seems to achieve a 5% speedup, which
    is rather
    surprising (to me!).  The test case I used was:
    
    cd Tcl/lib
    time {set blah {} ; foreach f [glob *8.1/*] { lappend blah $f } ; set
    blah {}} 100

Patch:
ftp://ftp.ucsd.edu/pub/alpha/tcl/extensions/glob.patch

PatchFiles:
$ diff -c3 -r -X patchignore -q tcl8.1 tcl8.1orig
    Files tcl8.1/generic/tclEncoding.c and tcl8.1orig/generic/tclEncoding.c
    differ
    Files tcl8.1/generic/tclFileName.c and tcl8.1orig/generic/tclFileName.c
    differ
    Files tcl8.1/generic/tclInt.decls and tcl8.1orig/generic/tclInt.decls
    differ
    Files tcl8.1/generic/tclInt.h and tcl8.1orig/generic/tclInt.h differ
    Files tcl8.1/mac/tclMacFile.c and tcl8.1orig/mac/tclMacFile.c differ
    Files tcl8.1/tests/fileName.test and tcl8.1orig/tests/fileName.test
    differ
    Files tcl8.1/unix/tclUnixFile.c and tcl8.1orig/unix/tclUnixFile.c differ
    Files tcl8.1/win/tclWinFile.c and tcl8.1orig/win/tclWinFile.c differ



Tcl 8.1.1 Request

Name:  vince darley
email:  [email protected]
Support:  None
Severity:  3
Synopsis:  patch for glob continued

DesiredBehavior:
    I've now updated the man page for my changes to glob.  My patch now
    includes:
    (i) improvements to glob for better cross-platform functionality
    (ii) speedups (use list-obj operations internally)
    (iii) test suite for all new features
    (iv) man page
    
    

Patch:
Here's the patch (same as posted before)
ftp://ftp.ucsd.edu/pub/alpha/tcl/extensions/glob.patch
Here's the new man page:
ftp://ftp.ucsd.edu/pub/alpha/tcl/extensions/glob.n

Posted To comp.lang.tcl: Posted Successfully

 
-- 07/19/1999 jenn
welch Closed ticket [217880ffff]. [History diff]2000-10-26 08:09:10
dgp Open ticket [217880ffff]. [History diff]2001-04-13 23:43:24
dgp Closed ticket [217880ffff]. [History diff]2001-04-13 23:43:48
Log in (anonymous is fine) to add a comment.