Imported Upstream version 1.51.0
[platform/upstream/boost.git] / tools / build / v2 / engine / modules / property-set.c
1 /* Copyright Vladimir Prus 2003. Distributed under the Boost */
2 /* Software License, Version 1.0. (See accompanying */
3 /* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */
4
5 #include "../native.h"
6 #include "../timestamp.h"
7 #include "../object.h"
8 #include "../strings.h"
9 #include "../lists.h"
10 #include "../variable.h"
11 #include "../compile.h"
12
13 LIST* get_grist(char* f)
14 {
15     char* end = strchr(f, '>');
16     string s[1];
17     LIST* result;
18
19     string_new(s);
20
21     string_append_range(s, f, end+1);
22     result = list_new(object_new(s->value));
23
24     string_free(s);
25     return result;
26 }
27
28 /*
29 rule create ( raw-properties * )
30 {
31     raw-properties = [ sequence.unique
32         [ sequence.insertion-sort $(raw-properties) ] ] ;
33
34     local key = $(raw-properties:J=-:E=) ;
35
36     if ! $(.ps.$(key))
37     {
38         .ps.$(key) = [ new property-set $(raw-properties) ] ;
39     }
40     return $(.ps.$(key)) ;
41 }
42 */
43
44 LIST *property_set_create( FRAME *frame, int flags )
45 {
46     LIST* properties = lol_get( frame->args, 0 );
47     LIST* sorted = L0;
48 #if 0
49     LIST* order_sensitive = 0;
50 #endif
51     LIST* unique;
52     LIST* val;
53     string var[1];
54     OBJECT* name;
55     LISTITER iter, end;
56
57 #if 0
58     /* Sort all properties which are not order sensitive */
59     for(tmp = properties; tmp; tmp = tmp->next) {
60         LIST* g = get_grist(tmp->string);
61         LIST* att = call_rule("feature.attributes", frame, g, 0);
62         if (list_in(att, "order-sensitive")) {
63             order_sensitive = list_new( order_sensitive, copystr(tmp->string));
64         } else {
65             sorted = list_new( sorted, copystr(tmp->string));
66         }
67         list_free(att);
68     }
69
70     sorted = list_sort(sorted);
71     sorted = list_append(sorted, order_sensitive);
72     unique = list_unique(sorted);
73 #endif
74     sorted = list_sort(properties);
75     unique = list_unique(sorted);
76
77     string_new(var);
78     string_append(var, ".ps.");
79
80     iter = list_begin( unique ), end = list_end( unique );
81     for( ; iter != end; iter = list_next( iter ) ) {
82         string_append(var, object_str( list_item( iter ) ));
83         string_push_back(var, '-');
84     }
85     name = object_new(var->value);
86     val = var_get(frame->module, name);
87     if (list_empty(val))
88     {
89         OBJECT* rulename = object_new("new");
90         val = call_rule(rulename, frame,
91                         list_append(list_new(object_new("property-set")), unique), 0);
92         object_free(rulename);
93
94         var_set(frame->module, name, list_copy(val), VAR_SET);
95     }
96     else
97     {
98         list_free(unique);
99         val = list_copy(val);
100     }
101     object_free(name);
102
103     string_free(var);
104     /* The 'unique' variable is freed in 'call_rule'. */
105     list_free(sorted);
106
107     return val;
108
109 }
110
111 void init_property_set()
112 {
113     {
114         const char* args[] = { "raw-properties", "*", 0 };
115         declare_native_rule("property-set", "create", args, property_set_create, 1);
116     }
117 }