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 "../newstr.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(0, newstr(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( PARSE *parse, FRAME *frame ) |
---|
45 | { |
---|
46 | LIST* properties = lol_get( frame->args, 0 ); |
---|
47 | LIST* sorted = 0; |
---|
48 | LIST* order_sensitive = 0; |
---|
49 | LIST* unique; |
---|
50 | LIST* tmp; |
---|
51 | LIST* val; |
---|
52 | string var[1]; |
---|
53 | |
---|
54 | #if 0 |
---|
55 | /* Sort all properties which are not order sensitive */ |
---|
56 | for(tmp = properties; tmp; tmp = tmp->next) { |
---|
57 | LIST* g = get_grist(tmp->string); |
---|
58 | LIST* att = call_rule("feature.attributes", frame, g, 0); |
---|
59 | if (list_in(att, "order-sensitive")) { |
---|
60 | order_sensitive = list_new( order_sensitive, tmp->string); |
---|
61 | } else { |
---|
62 | sorted = list_new( sorted, tmp->string); |
---|
63 | } |
---|
64 | list_free(att); |
---|
65 | } |
---|
66 | |
---|
67 | sorted = list_sort(sorted); |
---|
68 | sorted = list_append(sorted, order_sensitive); |
---|
69 | unique = list_unique(sorted); |
---|
70 | #endif |
---|
71 | sorted = list_sort(properties); |
---|
72 | unique = list_unique(sorted); |
---|
73 | |
---|
74 | string_new(var); |
---|
75 | string_append(var, ".ps."); |
---|
76 | |
---|
77 | for(tmp = unique; tmp; tmp = tmp->next) { |
---|
78 | string_append(var, tmp->string); |
---|
79 | string_push_back(var, '-'); |
---|
80 | } |
---|
81 | val = var_get(var->value); |
---|
82 | if (val == 0) |
---|
83 | { |
---|
84 | val = call_rule("new", frame, |
---|
85 | list_append(list_new(0, "property-set"), unique), 0); |
---|
86 | |
---|
87 | var_set(newstr(var->value), list_copy(0, val), VAR_SET); |
---|
88 | } |
---|
89 | else |
---|
90 | { |
---|
91 | val = list_copy(0, val); |
---|
92 | } |
---|
93 | |
---|
94 | string_free(var); |
---|
95 | /* The 'unique' variable is freed in 'call_rule'. */ |
---|
96 | list_free(sorted); |
---|
97 | |
---|
98 | return val; |
---|
99 | |
---|
100 | } |
---|
101 | |
---|
102 | void init_property_set() |
---|
103 | { |
---|
104 | { |
---|
105 | char* args[] = { "raw-properties", "*", 0 }; |
---|
106 | declare_native_rule("property-set", "create", args, property_set_create); |
---|
107 | } |
---|
108 | |
---|
109 | } |
---|