diff --git a/historic/jam/src/build.bat b/historic/jam/src/build.bat index f76bb86b1..8579cf50f 100644 --- a/historic/jam/src/build.bat +++ b/historic/jam/src/build.bat @@ -319,7 +319,7 @@ set BJAM_SOURCES=%BJAM_SOURCES% hdrmacro.c headers.c jam.c jambase.c jamgram.c l set BJAM_SOURCES=%BJAM_SOURCES% newstr.c option.c parse.c pathunix.c pathvms.c regexp.c set BJAM_SOURCES=%BJAM_SOURCES% rules.c scan.c search.c subst.c timestamp.c variable.c modules.c set BJAM_SOURCES=%BJAM_SOURCES% strings.c filesys.c builtins.c pwd.c class.c w32_getreg.c native.c -set BJAM_SOURCES=%BJAM_SOURCES% modules/set.c modules/path.c +set BJAM_SOURCES=%BJAM_SOURCES% modules/set.c modules/path.c modules/regex.c @echo ON rd /S /Q bootstrap.%BOOST_JAM_TOOLSET% diff --git a/historic/jam/src/build.jam b/historic/jam/src/build.jam index 6863a3959..8176c5500 100644 --- a/historic/jam/src/build.jam +++ b/historic/jam/src/build.jam @@ -276,7 +276,7 @@ jam.source = scan.c search.c subst.c timestamp.c variable.c modules.c strings.c filesys.c builtins.c pwd.c class.c native.c modules/set.c - modules/path.c + modules/path.c modules/regex.c ; if $(NT) { diff --git a/historic/jam/src/build.sh b/historic/jam/src/build.sh index 0524d52c0..78f6ca0e8 100644 --- a/historic/jam/src/build.sh +++ b/historic/jam/src/build.sh @@ -192,7 +192,7 @@ BJAM_SOURCES="\ newstr.c option.c parse.c pathunix.c pathvms.c regexp.c\ rules.c scan.c search.c subst.c timestamp.c variable.c modules.c\ strings.c filesys.c builtins.c pwd.c class.c native.c modules/set.c\ - modules/path.c" + modules/path.c modules/regex.c" echo_run rm -rf bootstrap.$BOOST_JAM_TOOLSET echo_run mkdir bootstrap.$BOOST_JAM_TOOLSET diff --git a/historic/jam/src/builtins.c b/historic/jam/src/builtins.c index a4d882c12..e269b0647 100644 --- a/historic/jam/src/builtins.c +++ b/historic/jam/src/builtins.c @@ -274,6 +274,7 @@ load_builtins() /* Initialize builtin modules */ init_set(); init_path(); + init_regex(); } /* diff --git a/historic/jam/src/modules/regex.c b/historic/jam/src/modules/regex.c new file mode 100644 index 000000000..b6cbd3818 --- /dev/null +++ b/historic/jam/src/modules/regex.c @@ -0,0 +1,60 @@ + +#include "../native.h" +#include "../timestamp.h" +#include "../newstr.h" +#include "../strings.h" +#include "../regexp.h" +#include "../compile.h" + +/* +rule transform ( list * : pattern ) +{ + local result ; + for local e in $(list) + { + local m = [ MATCH $(pattern) : $(e) ] ; + if $(m) + { + result += $(m[1]) ; + } + } + return $(result) ; +} +*/ +LIST *regex_transform( PARSE *parse, FRAME *frame ) +{ + LIST* l = lol_get( frame->args, 0 ); + LIST* pattern = lol_get( frame->args, 1 ); + LIST* result = 0; + + string buf[1]; + string_new(buf); + + + /* Result is cached and intentionally never freed */ + regexp *re = regex_compile( pattern->string ); + + for(; l; l = l->next) + { + if( regexec( re, l->string ) ) + { + if (re->startp[1]) + { + string_append_range( buf, re->startp[1], re->endp[1] ); + result = list_new( result, newstr( buf->value ) ); + string_truncate( buf, 0 ); + } + } + } + string_free( buf ); + + return result; +} + +void init_regex() +{ + { + char* args[] = { "list", "*", ":", "pattern", 0 }; + declare_native_rule("regex", "transform", args, regex_transform); + } +} diff --git a/jam_src/build.bat b/jam_src/build.bat index f76bb86b1..8579cf50f 100644 --- a/jam_src/build.bat +++ b/jam_src/build.bat @@ -319,7 +319,7 @@ set BJAM_SOURCES=%BJAM_SOURCES% hdrmacro.c headers.c jam.c jambase.c jamgram.c l set BJAM_SOURCES=%BJAM_SOURCES% newstr.c option.c parse.c pathunix.c pathvms.c regexp.c set BJAM_SOURCES=%BJAM_SOURCES% rules.c scan.c search.c subst.c timestamp.c variable.c modules.c set BJAM_SOURCES=%BJAM_SOURCES% strings.c filesys.c builtins.c pwd.c class.c w32_getreg.c native.c -set BJAM_SOURCES=%BJAM_SOURCES% modules/set.c modules/path.c +set BJAM_SOURCES=%BJAM_SOURCES% modules/set.c modules/path.c modules/regex.c @echo ON rd /S /Q bootstrap.%BOOST_JAM_TOOLSET% diff --git a/jam_src/build.jam b/jam_src/build.jam index 6863a3959..8176c5500 100644 --- a/jam_src/build.jam +++ b/jam_src/build.jam @@ -276,7 +276,7 @@ jam.source = scan.c search.c subst.c timestamp.c variable.c modules.c strings.c filesys.c builtins.c pwd.c class.c native.c modules/set.c - modules/path.c + modules/path.c modules/regex.c ; if $(NT) { diff --git a/jam_src/build.sh b/jam_src/build.sh index 0524d52c0..78f6ca0e8 100644 --- a/jam_src/build.sh +++ b/jam_src/build.sh @@ -192,7 +192,7 @@ BJAM_SOURCES="\ newstr.c option.c parse.c pathunix.c pathvms.c regexp.c\ rules.c scan.c search.c subst.c timestamp.c variable.c modules.c\ strings.c filesys.c builtins.c pwd.c class.c native.c modules/set.c\ - modules/path.c" + modules/path.c modules/regex.c" echo_run rm -rf bootstrap.$BOOST_JAM_TOOLSET echo_run mkdir bootstrap.$BOOST_JAM_TOOLSET diff --git a/jam_src/builtins.c b/jam_src/builtins.c index a4d882c12..e269b0647 100644 --- a/jam_src/builtins.c +++ b/jam_src/builtins.c @@ -274,6 +274,7 @@ load_builtins() /* Initialize builtin modules */ init_set(); init_path(); + init_regex(); } /* diff --git a/jam_src/modules/regex.c b/jam_src/modules/regex.c new file mode 100644 index 000000000..b6cbd3818 --- /dev/null +++ b/jam_src/modules/regex.c @@ -0,0 +1,60 @@ + +#include "../native.h" +#include "../timestamp.h" +#include "../newstr.h" +#include "../strings.h" +#include "../regexp.h" +#include "../compile.h" + +/* +rule transform ( list * : pattern ) +{ + local result ; + for local e in $(list) + { + local m = [ MATCH $(pattern) : $(e) ] ; + if $(m) + { + result += $(m[1]) ; + } + } + return $(result) ; +} +*/ +LIST *regex_transform( PARSE *parse, FRAME *frame ) +{ + LIST* l = lol_get( frame->args, 0 ); + LIST* pattern = lol_get( frame->args, 1 ); + LIST* result = 0; + + string buf[1]; + string_new(buf); + + + /* Result is cached and intentionally never freed */ + regexp *re = regex_compile( pattern->string ); + + for(; l; l = l->next) + { + if( regexec( re, l->string ) ) + { + if (re->startp[1]) + { + string_append_range( buf, re->startp[1], re->endp[1] ); + result = list_new( result, newstr( buf->value ) ); + string_truncate( buf, 0 ); + } + } + } + string_free( buf ); + + return result; +} + +void init_regex() +{ + { + char* args[] = { "list", "*", ":", "pattern", 0 }; + declare_native_rule("regex", "transform", args, regex_transform); + } +} diff --git a/v2/util/regex.jam b/v2/util/regex.jam index 657b2b4da..74ebc1528 100644 --- a/v2/util/regex.jam +++ b/v2/util/regex.jam @@ -57,6 +57,7 @@ rule transform ( list * : pattern ) } return $(result) ; } +NATIVE_RULE regex : transform ; # Escapes all of the characters in symbols using the escape symbol # escape-symbol for the given string, and returns the escaped string