]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/tools/build/src/engine/modules/sequence.c
Add patch for failing prerm scripts
[ceph.git] / ceph / src / boost / tools / build / src / engine / modules / sequence.c
1 /*
2 * Copyright Vladimir Prus 2003.
3 * Distributed under the Boost Software License, Version 1.0.
4 * (See accompanying file LICENSE_1_0.txt or copy at
5 * http://www.boost.org/LICENSE_1_0.txt)
6 */
7
8 #include "../native.h"
9 #include "../object.h"
10 #include "../lists.h"
11 #include "../compile.h"
12
13 #include <stdlib.h>
14
15
16 #ifndef max
17 # define max(a,b) ((a)>(b)?(a):(b))
18 #endif
19
20
21 LIST * sequence_select_highest_ranked( FRAME * frame, int flags )
22 {
23 /* Returns all of 'elements' for which corresponding element in parallel */
24 /* list 'rank' is equal to the maximum value in 'rank'. */
25
26 LIST * const elements = lol_get( frame->args, 0 );
27 LIST * const rank = lol_get( frame->args, 1 );
28
29 LIST * result = L0;
30 int highest_rank = -1;
31
32 {
33 LISTITER iter = list_begin( rank );
34 LISTITER const end = list_end( rank );
35 for ( ; iter != end; iter = list_next( iter ) )
36 {
37 int const current = atoi( object_str( list_item( iter ) ) );
38 highest_rank = max( highest_rank, current );
39 }
40 }
41
42 {
43 LISTITER iter = list_begin( rank );
44 LISTITER const end = list_end( rank );
45 LISTITER elements_iter = list_begin( elements );
46 LISTITER const elements_end = list_end( elements );
47 for ( ; iter != end; iter = list_next( iter ), elements_iter =
48 list_next( elements_iter ) )
49 if ( atoi( object_str( list_item( iter ) ) ) == highest_rank )
50 result = list_push_back( result, object_copy( list_item(
51 elements_iter ) ) );
52 }
53
54 return result;
55 }
56
57 LIST * sequence_transform( FRAME * frame, int flags )
58 {
59 LIST * function = lol_get( frame->args, 0 );
60 LIST * sequence = lol_get( frame->args, 1 );
61 LIST * result = L0;
62 OBJECT * function_name = list_front( function );
63 LISTITER args_begin = list_next( list_begin( function ) ), args_end = list_end( function );
64 LISTITER iter = list_begin( sequence ), end = list_end( sequence );
65 RULE * rule = bindrule( function_name, frame->prev->module );
66
67 for ( ; iter != end; iter = list_next( iter ) )
68 {
69 FRAME inner[ 1 ];
70
71 frame_init( inner );
72 inner->prev = frame;
73 inner->prev_user = frame->prev_user;
74 inner->module = frame->prev->module;
75
76 lol_add( inner->args, list_push_back( list_copy_range( function, args_begin, args_end ), object_copy( list_item( iter ) ) ) );
77 result = list_append( result, evaluate_rule( rule, function_name, inner ) );
78
79 frame_free( inner );
80 }
81
82 return result;
83 }
84
85 void init_sequence()
86 {
87 {
88 char const * args[] = { "elements", "*", ":", "rank", "*", 0 };
89 declare_native_rule( "sequence", "select-highest-ranked", args,
90 sequence_select_highest_ranked, 1 );
91 }
92 {
93 char const * args[] = { "function", "+", ":", "sequence", "*", 0 };
94 declare_native_rule( "sequence", "transform", args,
95 sequence_transform, 1 );
96 }
97 }