diff options
author | Patrick Simianer <simianer@cl.uni-heidelberg.de> | 2012-05-13 03:35:30 +0200 |
---|---|---|
committer | Patrick Simianer <simianer@cl.uni-heidelberg.de> | 2012-05-13 03:35:30 +0200 |
commit | d94373453c69c6cfec952a0f7b427cacc78654d8 (patch) | |
tree | 43febdf719c103d19bd5d22d0be734e1574bc1e9 /jam-files/engine/modules/sequence.c | |
parent | cc9650b8b664d1f6836a0fa86a012401b51aafa0 (diff) | |
parent | a65a80c5d5b6fc4cbd32280f07cae9be71551b70 (diff) |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'jam-files/engine/modules/sequence.c')
-rw-r--r-- | jam-files/engine/modules/sequence.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/jam-files/engine/modules/sequence.c b/jam-files/engine/modules/sequence.c new file mode 100644 index 00000000..bda80d94 --- /dev/null +++ b/jam-files/engine/modules/sequence.c @@ -0,0 +1,42 @@ +/* Copyright Vladimir Prus 2003. Distributed under the Boost */ +/* Software License, Version 1.0. (See accompanying */ +/* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */ + +#include "../native.h" + +# ifndef max +# define max( a,b ) ((a)>(b)?(a):(b)) +# endif + + +LIST *sequence_select_highest_ranked( PARSE *parse, FRAME *frame ) +{ + /* Returns all of 'elements' for which corresponding element in parallel */ + /* list 'rank' is equal to the maximum value in 'rank'. */ + + LIST* elements = lol_get( frame->args, 0 ); + LIST* rank = lol_get( frame->args, 1 ); + + LIST* result = 0; + LIST* tmp; + int highest_rank = -1; + + for (tmp = rank; tmp; tmp = tmp->next) + highest_rank = max(highest_rank, atoi(tmp->string)); + + for (; rank; rank = rank->next, elements = elements->next) + if (atoi(rank->string) == highest_rank) + result = list_new(result, elements->string); + + return result; +} + +void init_sequence() +{ + { + char* args[] = { "elements", "*", ":", "rank", "*", 0 }; + declare_native_rule("sequence", "select-highest-ranked", args, + sequence_select_highest_ranked, 1); + } + +} |