From fed31d2af9e9b43616be2a1b89ba972db0fd25fc Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Wed, 19 Feb 2003 16:43:55 +0000 Subject: [PATCH] Use downcased globbing on NT/Cygwin [SVN r17537] --- historic/jam/src/Jam.html | 11 ++++- historic/jam/src/builtins.c | 98 +++++++++++++++++++++++-------------- jam_src/Jam.html | 11 ++++- jam_src/builtins.c | 98 +++++++++++++++++++++++-------------- new/msvc.jam | 11 +++-- v2/msvc.jam | 11 +++-- 6 files changed, 150 insertions(+), 90 deletions(-) diff --git a/historic/jam/src/Jam.html b/historic/jam/src/Jam.html index 24e73ed86..a81b98426 100644 --- a/historic/jam/src/Jam.html +++ b/historic/jam/src/Jam.html @@ -632,7 +632,7 @@ jam [ -a ] [ -n ] [ -v ] [ -q ]

- GLOB directories : patterns + GLOB directories : patterns : downcase-opt
Using the same wildcards as for the patterns in the If downcase-opt is supplied, filenames are converted to + all-lowercase before matching against the pattern; you can use + this to do case-insensitive matching using lowercase patterns. + The paths returned will still have mixed case if the OS supplies + them. On Windows NT and Cygwin, filenames are always downcased + before matching.
diff --git a/historic/jam/src/builtins.c b/historic/jam/src/builtins.c index 27ecae3a4..4e4a40512 100644 --- a/historic/jam/src/builtins.c +++ b/historic/jam/src/builtins.c @@ -19,6 +19,7 @@ # include "pwd.h" # include "pathsys.h" # include "make.h" +# include /* * builtins.c - builtin jam rules @@ -93,9 +94,13 @@ load_builtins() bind_builtin( "EXIT" , builtin_exit, 0, 0 ) ) ); - duplicate_rule( "Glob" , - bind_builtin( "GLOB" , - builtin_glob, 0, 0 ) ); + { + char * args[] = { "directories", "*", ":", "patterns", "*", ":", "downcase-filenames", "?", 0 }; + duplicate_rule( + "Glob" , + bind_builtin( "GLOB" , builtin_glob, 0, args ) + ); + } duplicate_rule( "Includes" , bind_builtin( "INCLUDES" , @@ -284,56 +289,73 @@ builtin_flags( */ struct globbing { - LIST *patterns; - LIST *results; + LIST *patterns; + LIST *results; + LIST *downcase; } ; static void builtin_glob_back( - void *closure, - char *file, - int status, - time_t time ) + void *closure, + char *file, + int status, + time_t time ) { - struct globbing *globbing = (struct globbing *)closure; - LIST *l; - PATHNAME f; - string buf[1]; + struct globbing *globbing = (struct globbing *)closure; + LIST *l; + PATHNAME f; + string buf[1]; - /* Null out directory for matching. */ - /* We wish we had file_dirscan() pass up a PATHNAME. */ + /* Null out directory for matching. */ + /* We wish we had file_dirscan() pass up a PATHNAME. */ - path_parse( file, &f ); - f.f_dir.len = 0; - string_new( buf ); - path_build( &f, buf, 0 ); + path_parse( file, &f ); + f.f_dir.len = 0; + string_new( buf ); + path_build( &f, buf, 0 ); - for( l = globbing->patterns; l; l = l->next ) - if( !glob( l->string, buf->value ) ) - { - globbing->results = list_new( globbing->results, newstr( file ) ); - break; - } - string_free( buf ); + if (globbing->downcase) + { + char* p; + for ( p = buf->value; *p; ++p ) + { + *p = tolower(*p); + } + } + + for( l = globbing->patterns; l; l = l->next ) + if( !glob( l->string, buf->value ) ) + { + globbing->results = list_new( globbing->results, newstr( file ) ); + break; + } + string_free( buf ); } LIST * builtin_glob( - PARSE *parse, - FRAME *frame ) + PARSE *parse, + FRAME *frame ) { - LIST *l = lol_get( frame->args, 0 ); - LIST *r = lol_get( frame->args, 1 ); + LIST *l = lol_get( frame->args, 0 ); + LIST *r = lol_get( frame->args, 1 ); + + struct globbing globbing; - struct globbing globbing; + globbing.results = L0; + globbing.patterns = r; + + globbing.downcase +# if defined( OS_NT ) || defined( OS_CYGWIN ) + = l; /* always downcase filenames if any files can be found */ +# else + = lol_get( frame->args, 2 ); /* conditionally downcase filenames */ +# endif + + for( ; l; l = list_next( l ) ) + file_dirscan( l->string, builtin_glob_back, &globbing ); - globbing.results = L0; - globbing.patterns = r; - - for( ; l; l = list_next( l ) ) - file_dirscan( l->string, builtin_glob_back, &globbing ); - - return globbing.results; + return globbing.results; } /* diff --git a/jam_src/Jam.html b/jam_src/Jam.html index 24e73ed86..a81b98426 100644 --- a/jam_src/Jam.html +++ b/jam_src/Jam.html @@ -632,7 +632,7 @@ jam [ -a ] [ -n ] [ -v ] [ -q ]

- GLOB directories : patterns + GLOB directories : patterns : downcase-opt
Using the same wildcards as for the patterns in the If downcase-opt is supplied, filenames are converted to + all-lowercase before matching against the pattern; you can use + this to do case-insensitive matching using lowercase patterns. + The paths returned will still have mixed case if the OS supplies + them. On Windows NT and Cygwin, filenames are always downcased + before matching.
diff --git a/jam_src/builtins.c b/jam_src/builtins.c index 27ecae3a4..4e4a40512 100644 --- a/jam_src/builtins.c +++ b/jam_src/builtins.c @@ -19,6 +19,7 @@ # include "pwd.h" # include "pathsys.h" # include "make.h" +# include /* * builtins.c - builtin jam rules @@ -93,9 +94,13 @@ load_builtins() bind_builtin( "EXIT" , builtin_exit, 0, 0 ) ) ); - duplicate_rule( "Glob" , - bind_builtin( "GLOB" , - builtin_glob, 0, 0 ) ); + { + char * args[] = { "directories", "*", ":", "patterns", "*", ":", "downcase-filenames", "?", 0 }; + duplicate_rule( + "Glob" , + bind_builtin( "GLOB" , builtin_glob, 0, args ) + ); + } duplicate_rule( "Includes" , bind_builtin( "INCLUDES" , @@ -284,56 +289,73 @@ builtin_flags( */ struct globbing { - LIST *patterns; - LIST *results; + LIST *patterns; + LIST *results; + LIST *downcase; } ; static void builtin_glob_back( - void *closure, - char *file, - int status, - time_t time ) + void *closure, + char *file, + int status, + time_t time ) { - struct globbing *globbing = (struct globbing *)closure; - LIST *l; - PATHNAME f; - string buf[1]; + struct globbing *globbing = (struct globbing *)closure; + LIST *l; + PATHNAME f; + string buf[1]; - /* Null out directory for matching. */ - /* We wish we had file_dirscan() pass up a PATHNAME. */ + /* Null out directory for matching. */ + /* We wish we had file_dirscan() pass up a PATHNAME. */ - path_parse( file, &f ); - f.f_dir.len = 0; - string_new( buf ); - path_build( &f, buf, 0 ); + path_parse( file, &f ); + f.f_dir.len = 0; + string_new( buf ); + path_build( &f, buf, 0 ); - for( l = globbing->patterns; l; l = l->next ) - if( !glob( l->string, buf->value ) ) - { - globbing->results = list_new( globbing->results, newstr( file ) ); - break; - } - string_free( buf ); + if (globbing->downcase) + { + char* p; + for ( p = buf->value; *p; ++p ) + { + *p = tolower(*p); + } + } + + for( l = globbing->patterns; l; l = l->next ) + if( !glob( l->string, buf->value ) ) + { + globbing->results = list_new( globbing->results, newstr( file ) ); + break; + } + string_free( buf ); } LIST * builtin_glob( - PARSE *parse, - FRAME *frame ) + PARSE *parse, + FRAME *frame ) { - LIST *l = lol_get( frame->args, 0 ); - LIST *r = lol_get( frame->args, 1 ); + LIST *l = lol_get( frame->args, 0 ); + LIST *r = lol_get( frame->args, 1 ); + + struct globbing globbing; - struct globbing globbing; + globbing.results = L0; + globbing.patterns = r; + + globbing.downcase +# if defined( OS_NT ) || defined( OS_CYGWIN ) + = l; /* always downcase filenames if any files can be found */ +# else + = lol_get( frame->args, 2 ); /* conditionally downcase filenames */ +# endif + + for( ; l; l = list_next( l ) ) + file_dirscan( l->string, builtin_glob_back, &globbing ); - globbing.results = L0; - globbing.patterns = r; - - for( ; l; l = list_next( l ) ) - file_dirscan( l->string, builtin_glob_back, &globbing ); - - return globbing.results; + return globbing.results; } /* diff --git a/new/msvc.jam b/new/msvc.jam index f5ea18825..bc5fcb585 100755 --- a/new/msvc.jam +++ b/new/msvc.jam @@ -49,23 +49,24 @@ rule init ( version ? path ? : vendor ? : setup ? compiler ? linker ? ) { local v = [ MATCH ^(6|[^6].*) : $(version) ] ; local version-6-path = "c:\\Program Files\\Microsoft Visual Studio\\VC98" ; - local version-7.0-path = "c:\\Program Files\\Microsoft Visual Studio .NET\\VC7" ; + local version-7-path = "c:\\Program Files\\Microsoft Visual Studio .NET\\VC7" ; + local version-7.0-path = $(version-7-path) ; local version-7.1-path = "c:\\Program Files\\Microsoft Visual Studio .NET 2003\\VC7" ; local default-path = $(version-$(v)-path) ; # look for the setup program in both the system PATH and in # its default installation location based on version local env-PATH = [ modules.peek : PATH ] ; - local PATH-setup = [ GLOB $(env-PATH) : $(setup) $(setup:U) ] ; - local default-setup = [ GLOB $(default-path)\\bin : $(setup) $(setup:U) ] ; + local PATH-setup = [ GLOB $(env-PATH) : $(setup:L) ] ; + local default-setup = [ GLOB $(default-path)\\bin : $(setup:L) ] ; if $(default-setup) && $(PATH-setup) != $(default-setup) { path = $(default-path) ; } - compiler = $(compiler:U) ; - if ! [ GLOB $(path)\\bin $(env-PATH) : $(compiler:E=CL).EXE $(compiler:E=cl).exe ] + compiler = $(compiler:L) ; + if ! [ GLOB $(path)\\bin $(env-PATH) : $(compiler:E=cl).exe ] { error $(condition) initialization: : couldn't find compiler \"$(compiler:E=CL)\" in PATH or "known default" diff --git a/v2/msvc.jam b/v2/msvc.jam index f5ea18825..bc5fcb585 100755 --- a/v2/msvc.jam +++ b/v2/msvc.jam @@ -49,23 +49,24 @@ rule init ( version ? path ? : vendor ? : setup ? compiler ? linker ? ) { local v = [ MATCH ^(6|[^6].*) : $(version) ] ; local version-6-path = "c:\\Program Files\\Microsoft Visual Studio\\VC98" ; - local version-7.0-path = "c:\\Program Files\\Microsoft Visual Studio .NET\\VC7" ; + local version-7-path = "c:\\Program Files\\Microsoft Visual Studio .NET\\VC7" ; + local version-7.0-path = $(version-7-path) ; local version-7.1-path = "c:\\Program Files\\Microsoft Visual Studio .NET 2003\\VC7" ; local default-path = $(version-$(v)-path) ; # look for the setup program in both the system PATH and in # its default installation location based on version local env-PATH = [ modules.peek : PATH ] ; - local PATH-setup = [ GLOB $(env-PATH) : $(setup) $(setup:U) ] ; - local default-setup = [ GLOB $(default-path)\\bin : $(setup) $(setup:U) ] ; + local PATH-setup = [ GLOB $(env-PATH) : $(setup:L) ] ; + local default-setup = [ GLOB $(default-path)\\bin : $(setup:L) ] ; if $(default-setup) && $(PATH-setup) != $(default-setup) { path = $(default-path) ; } - compiler = $(compiler:U) ; - if ! [ GLOB $(path)\\bin $(env-PATH) : $(compiler:E=CL).EXE $(compiler:E=cl).exe ] + compiler = $(compiler:L) ; + if ! [ GLOB $(path)\\bin $(env-PATH) : $(compiler:E=cl).exe ] { error $(condition) initialization: : couldn't find compiler \"$(compiler:E=CL)\" in PATH or "known default"