1 | //----------------------------------------------------------- |
---|
2 | // Copyright Christian Arnault LAL-Orsay CNRS |
---|
3 | // arnault@lal.in2p3.fr |
---|
4 | // See the complete license in cmt_license.txt "http://www.cecill.info". |
---|
5 | //----------------------------------------------------------- |
---|
6 | |
---|
7 | #include <stdio.h> |
---|
8 | #include <stdlib.h> |
---|
9 | #include <string.h> |
---|
10 | #include <ctype.h> |
---|
11 | |
---|
12 | #include "cmt_use.h" |
---|
13 | #include "cmt_symbol.h" |
---|
14 | #include "cmt_system.h" |
---|
15 | #include "cmt_database.h" |
---|
16 | #include "cmt_log.h" |
---|
17 | |
---|
18 | // Global inhibitor of any display |
---|
19 | bool Symbol::m_inhibit_display = false; |
---|
20 | |
---|
21 | //------------------------------------------------------------- |
---|
22 | class SetBuilder : public ValueBuilder |
---|
23 | { |
---|
24 | public: |
---|
25 | const cmt_string build (const Symbol& symbol, |
---|
26 | const cmt_string& tag_name = ""); |
---|
27 | const cmt_string clean (const Symbol& symbol, |
---|
28 | const cmt_string& tag_name = "") |
---|
29 | { |
---|
30 | static const cmt_string empty = ""; |
---|
31 | return (empty); |
---|
32 | } |
---|
33 | }; |
---|
34 | //------------------------------------------------------------- |
---|
35 | |
---|
36 | //------------------------------------------------------------- |
---|
37 | class PathBuilder : public ValueBuilder |
---|
38 | { |
---|
39 | public: |
---|
40 | const cmt_string build (const Symbol& symbol, |
---|
41 | const cmt_string& tag_name = ""); |
---|
42 | const cmt_string clean (const Symbol& symbol, |
---|
43 | const cmt_string& tag_name = ""); |
---|
44 | }; |
---|
45 | //------------------------------------------------------------- |
---|
46 | |
---|
47 | //------------------------------------------------------------- |
---|
48 | class MacroBuilder : public ValueBuilder |
---|
49 | { |
---|
50 | public: |
---|
51 | const cmt_string build (const Symbol& symbol, |
---|
52 | const cmt_string& tag_name = ""); |
---|
53 | const cmt_string clean (const Symbol& symbol, |
---|
54 | const cmt_string& tag_name = "") |
---|
55 | { |
---|
56 | static const cmt_string empty = ""; |
---|
57 | return (empty); |
---|
58 | } |
---|
59 | }; |
---|
60 | //------------------------------------------------------------- |
---|
61 | |
---|
62 | //------------------------------------------------------------- |
---|
63 | class ScriptBuilder : public ValueBuilder |
---|
64 | { |
---|
65 | public: |
---|
66 | const cmt_string build (const Symbol& symbol, |
---|
67 | const cmt_string& tag_name = ""); |
---|
68 | const cmt_string clean (const Symbol& symbol, |
---|
69 | const cmt_string& tag_name = "") |
---|
70 | { |
---|
71 | static const cmt_string empty = ""; |
---|
72 | return (empty); |
---|
73 | } |
---|
74 | }; |
---|
75 | //------------------------------------------------------------- |
---|
76 | |
---|
77 | //------------------------------------------------------------- |
---|
78 | class ActionBuilder : public ValueBuilder |
---|
79 | { |
---|
80 | public: |
---|
81 | const cmt_string build (const Symbol& symbol, |
---|
82 | const cmt_string& tag_name = ""); |
---|
83 | const cmt_string clean (const Symbol& symbol, |
---|
84 | const cmt_string& tag_name = "") |
---|
85 | { |
---|
86 | static const cmt_string empty = ""; |
---|
87 | return (empty); |
---|
88 | } |
---|
89 | }; |
---|
90 | //------------------------------------------------------------- |
---|
91 | |
---|
92 | //------------------------------------------------------------- |
---|
93 | class symbol_marker |
---|
94 | { |
---|
95 | public: |
---|
96 | symbol_marker () |
---|
97 | { |
---|
98 | ptr = cmt_string::npos; |
---|
99 | pattern = 0; |
---|
100 | intro = 0; |
---|
101 | } |
---|
102 | |
---|
103 | symbol_marker (int a_ptr, char a_pattern, int a_intro) |
---|
104 | { |
---|
105 | ptr = a_ptr; |
---|
106 | pattern = a_pattern; |
---|
107 | intro = a_intro; |
---|
108 | } |
---|
109 | |
---|
110 | symbol_marker (const symbol_marker& other) |
---|
111 | { |
---|
112 | ptr = other.ptr; |
---|
113 | pattern = other.pattern; |
---|
114 | intro = other.intro; |
---|
115 | } |
---|
116 | |
---|
117 | void set (int a_ptr, char a_pattern, int a_intro) |
---|
118 | { |
---|
119 | ptr = a_ptr; |
---|
120 | pattern = a_pattern; |
---|
121 | intro = a_intro; |
---|
122 | } |
---|
123 | |
---|
124 | static symbol_marker& get_lowest (symbol_marker markers[], int count) |
---|
125 | { |
---|
126 | static symbol_marker result; |
---|
127 | int real_count = 0; |
---|
128 | int i; |
---|
129 | |
---|
130 | // Check that at least one marker has result |
---|
131 | |
---|
132 | for (i = 0; i < count; i++) |
---|
133 | { |
---|
134 | if (markers[i].ptr != cmt_string::npos) real_count++; |
---|
135 | } |
---|
136 | |
---|
137 | if (real_count == 0) return (result); |
---|
138 | |
---|
139 | // since we've passed the previous test, |
---|
140 | // at least one entry is not npos. |
---|
141 | // Now discards other npos by moving them to the end |
---|
142 | |
---|
143 | for (i = 0; i < count;) |
---|
144 | { |
---|
145 | if (markers[i].ptr == cmt_string::npos) |
---|
146 | { |
---|
147 | markers[i] = markers[count-1]; |
---|
148 | count--; |
---|
149 | if (count == 0) break; |
---|
150 | } |
---|
151 | else |
---|
152 | { |
---|
153 | i++; |
---|
154 | } |
---|
155 | } |
---|
156 | |
---|
157 | if (count == 0) return (result); |
---|
158 | |
---|
159 | // now all entries in [0, count-1] are not npos |
---|
160 | // let's sort the lowest one in [0] |
---|
161 | |
---|
162 | for (i = 1; i < count;) |
---|
163 | { |
---|
164 | if (markers[0].ptr > markers[i].ptr) |
---|
165 | { |
---|
166 | symbol_marker temp = markers[0]; |
---|
167 | markers[0] = markers[i]; |
---|
168 | markers[i] = temp; |
---|
169 | i = 1; |
---|
170 | } |
---|
171 | else |
---|
172 | { |
---|
173 | i++; |
---|
174 | } |
---|
175 | } |
---|
176 | |
---|
177 | return (markers[0]); |
---|
178 | } |
---|
179 | |
---|
180 | int ptr; |
---|
181 | char pattern; |
---|
182 | int intro; |
---|
183 | }; |
---|
184 | //------------------------------------------------------------- |
---|
185 | |
---|
186 | /** |
---|
187 | |
---|
188 | Attempt to substitute all occurrences of |
---|
189 | |
---|
190 | ${<symbol_name>} |
---|
191 | $(<symbol_name>) |
---|
192 | %<symbol_name>% [on Windows only] |
---|
193 | |
---|
194 | by the specified value in the given text. |
---|
195 | |
---|
196 | This is for one symbol only |
---|
197 | |
---|
198 | */ |
---|
199 | static void resolve_value (cmt_string& text, |
---|
200 | const cmt_string& symbol_name, |
---|
201 | const cmt_string& value) |
---|
202 | { |
---|
203 | static cmt_string pattern; |
---|
204 | |
---|
205 | pattern = "${"; |
---|
206 | pattern += symbol_name; |
---|
207 | pattern += "}"; |
---|
208 | |
---|
209 | text.replace_all (pattern, value); |
---|
210 | |
---|
211 | pattern = "$("; |
---|
212 | pattern += symbol_name; |
---|
213 | pattern += ")"; |
---|
214 | |
---|
215 | text.replace_all (pattern, value); |
---|
216 | |
---|
217 | #ifdef WIN32 |
---|
218 | pattern = "%"; |
---|
219 | pattern += symbol_name; |
---|
220 | pattern += "%"; |
---|
221 | |
---|
222 | text.replace_all (pattern, value); |
---|
223 | #endif |
---|
224 | } |
---|
225 | |
---|
226 | /** |
---|
227 | |
---|
228 | Attempt to substitute into the specified text all occurrences of |
---|
229 | |
---|
230 | ${xxx} |
---|
231 | $(xxx) |
---|
232 | `xxx` |
---|
233 | %xxx% [on Windows only] |
---|
234 | |
---|
235 | by the appropriate value: |
---|
236 | |
---|
237 | for `xxx` : |
---|
238 | |
---|
239 | xxx is considered as a shell command. Value is the result of its execution |
---|
240 | |
---|
241 | for other patterns: |
---|
242 | |
---|
243 | if xxx is a symbol name, its value is substituted to the pattern |
---|
244 | otherwise, xxx is tried as an environment variable |
---|
245 | |
---|
246 | |
---|
247 | ===> In all cases, the pattern is filtered away. |
---|
248 | |
---|
249 | |
---|
250 | */ |
---|
251 | static void resolve_value (cmt_string& text) |
---|
252 | { |
---|
253 | //static cmt_regexp reg ("[$%`]"); |
---|
254 | |
---|
255 | //if (!reg.match (text)) return; |
---|
256 | |
---|
257 | cmt_string pattern; |
---|
258 | cmt_string symbol_name; |
---|
259 | char end_pattern; |
---|
260 | |
---|
261 | int start = 0; |
---|
262 | |
---|
263 | for (;;) |
---|
264 | { |
---|
265 | int begin; |
---|
266 | int end; |
---|
267 | |
---|
268 | symbol_marker markers[4]; |
---|
269 | int num = 0; |
---|
270 | |
---|
271 | markers[num].set (text.find (start, "$("), ')', 2); num++; |
---|
272 | markers[num].set (text.find (start, "${"), '}', 2); num++; |
---|
273 | markers[num].set (text.find (start, "`"), '`', 1); num++; |
---|
274 | |
---|
275 | #ifdef WIN32 |
---|
276 | markers[num].set (text.find (start, "%"), '%', 1); num++; |
---|
277 | #endif |
---|
278 | |
---|
279 | // Find the first matching pattern |
---|
280 | |
---|
281 | symbol_marker& marker = symbol_marker::get_lowest (markers, num); |
---|
282 | |
---|
283 | begin = marker.ptr; |
---|
284 | |
---|
285 | if (begin == cmt_string::npos) break; |
---|
286 | |
---|
287 | end_pattern = marker.pattern; |
---|
288 | start = begin + marker.intro; |
---|
289 | |
---|
290 | end = text.find (start, end_pattern); |
---|
291 | if (end == cmt_string::npos) |
---|
292 | { |
---|
293 | // The pattern is a fake one (no ending!) |
---|
294 | start++; |
---|
295 | continue; |
---|
296 | } |
---|
297 | |
---|
298 | // This should never happen... |
---|
299 | if (end < begin) break; |
---|
300 | |
---|
301 | // Extract the complete pattern |
---|
302 | text.substr (begin, end - begin + 1, pattern); |
---|
303 | |
---|
304 | // Then only the symbol name |
---|
305 | text.substr (begin + marker.intro, end - begin - marker.intro, symbol_name); |
---|
306 | |
---|
307 | if (text[begin] == '`') |
---|
308 | { |
---|
309 | cmt_string command = symbol_name; |
---|
310 | resolve_value (command); |
---|
311 | |
---|
312 | // The value is a shell command that first needs |
---|
313 | // to be applied. The output of the command is then substituted |
---|
314 | |
---|
315 | cmt_string result; |
---|
316 | |
---|
317 | Symbol::all_set (); |
---|
318 | CmtSystem::execute (command, result); |
---|
319 | |
---|
320 | int pos; |
---|
321 | pos = result.find ('\n'); |
---|
322 | if (pos != cmt_string::npos) result.erase (pos); |
---|
323 | pos = result.find ('\r'); |
---|
324 | if (pos != cmt_string::npos) result.erase (pos); |
---|
325 | |
---|
326 | if (Cmt::get_debug ()) |
---|
327 | { |
---|
328 | cout << " Executing [" << command << "] to expand a symbol value =>[" |
---|
329 | << result << "]" << endl; |
---|
330 | } |
---|
331 | |
---|
332 | text.replace_all (pattern, result); |
---|
333 | |
---|
334 | // The substitution will restart from the same place |
---|
335 | // allowing for recursive replacements |
---|
336 | start = begin; |
---|
337 | } |
---|
338 | else |
---|
339 | { |
---|
340 | Symbol* symbol = Symbol::find (symbol_name); |
---|
341 | if (symbol != 0) |
---|
342 | { |
---|
343 | // Symbol found |
---|
344 | cmt_string value = symbol->resolve_macro_value (); |
---|
345 | text.replace_all (pattern, value); |
---|
346 | |
---|
347 | // The substitution will restart from the same place |
---|
348 | // allowing for recursive replacements |
---|
349 | start = begin; |
---|
350 | } |
---|
351 | else |
---|
352 | { |
---|
353 | // Symbol not found. Look for env. variable |
---|
354 | cmt_string value = CmtSystem::getenv (symbol_name); |
---|
355 | |
---|
356 | // When the env. variable is not defined, the replacement is empty |
---|
357 | // thus all $(xxx) ${xxx} %xxx% patterns are always filtered away. |
---|
358 | text.replace_all (pattern, value); |
---|
359 | |
---|
360 | // The substitution will restart from the same place |
---|
361 | // allowing for recursive replacements |
---|
362 | start = begin; |
---|
363 | } |
---|
364 | } |
---|
365 | } |
---|
366 | } |
---|
367 | |
---|
368 | /** |
---|
369 | |
---|
370 | Attempt to substitute all occurrences of |
---|
371 | |
---|
372 | ${xxx} |
---|
373 | $(xxx) |
---|
374 | `xxx` |
---|
375 | %xxx% [on Windows only] |
---|
376 | |
---|
377 | by the appropriate value: |
---|
378 | |
---|
379 | for `xxx` : |
---|
380 | |
---|
381 | xxx is considered as a shell command. Value is the result of its execution |
---|
382 | |
---|
383 | for other patterns: |
---|
384 | |
---|
385 | if xxx is a macro name, its value is substituted to the pattern |
---|
386 | |
---|
387 | if xxx is a set or a path, it is kept in place (after fixing the pattern |
---|
388 | according to the OS style) |
---|
389 | |
---|
390 | otherwise it is simply kept in place |
---|
391 | |
---|
392 | */ |
---|
393 | static void resolve_value_for_macros (cmt_string& text) |
---|
394 | { |
---|
395 | cmt_string pattern; |
---|
396 | cmt_string symbol_name; |
---|
397 | char end_pattern; |
---|
398 | |
---|
399 | int start = 0; |
---|
400 | |
---|
401 | for (;;) |
---|
402 | { |
---|
403 | // |
---|
404 | // Try and substitute all ${xxx} $(xxx) or %xxx% patterns |
---|
405 | // using symbol values, only when the symbol is a macro. |
---|
406 | // |
---|
407 | |
---|
408 | int begin; |
---|
409 | int end; |
---|
410 | |
---|
411 | symbol_marker markers[4]; |
---|
412 | int num = 0; |
---|
413 | |
---|
414 | markers[num].set (text.find (start, "$("), ')', 2); num++; |
---|
415 | markers[num].set (text.find (start, "${"), '}', 2); num++; |
---|
416 | |
---|
417 | #ifdef WIN32 |
---|
418 | markers[num].set (text.find (start, "%"), '%', 1); num++; |
---|
419 | #endif |
---|
420 | |
---|
421 | markers[num].set (text.find (start, "`"), '`', 1); num++; |
---|
422 | |
---|
423 | // Find the first of three patterns |
---|
424 | |
---|
425 | symbol_marker& marker = symbol_marker::get_lowest (markers, num); |
---|
426 | |
---|
427 | begin = marker.ptr; |
---|
428 | |
---|
429 | if (begin == cmt_string::npos) break; |
---|
430 | |
---|
431 | end_pattern = marker.pattern; |
---|
432 | start = begin + marker.intro; |
---|
433 | |
---|
434 | end = text.find (start, end_pattern); |
---|
435 | if (end == cmt_string::npos) |
---|
436 | { |
---|
437 | // The pattern is a fake one (no ending!) |
---|
438 | start++; |
---|
439 | continue; |
---|
440 | } |
---|
441 | |
---|
442 | // This should never happen... |
---|
443 | if (end < begin) break; |
---|
444 | |
---|
445 | // Extract the complete pattern |
---|
446 | text.substr (begin, end - begin + 1, pattern); |
---|
447 | |
---|
448 | // Then only the macro name |
---|
449 | text.substr (begin + marker.intro, end - begin - marker.intro, symbol_name); |
---|
450 | |
---|
451 | if (text[begin] == '`') |
---|
452 | { |
---|
453 | cmt_string command = symbol_name; |
---|
454 | resolve_value (command); |
---|
455 | |
---|
456 | // The macro value is a shell command that first needs |
---|
457 | // to be applied. The output of the command is substituted |
---|
458 | |
---|
459 | cmt_string result; |
---|
460 | |
---|
461 | Symbol::all_set (); |
---|
462 | CmtSystem::execute (command, result); |
---|
463 | |
---|
464 | int pos; |
---|
465 | pos = result.find ('\n'); |
---|
466 | if (pos != cmt_string::npos) result.erase (pos); |
---|
467 | pos = result.find ('\r'); |
---|
468 | if (pos != cmt_string::npos) result.erase (pos); |
---|
469 | |
---|
470 | if (Cmt::get_debug ()) |
---|
471 | { |
---|
472 | cout << " Executing [" << command << "] to expand a macro value =>[" |
---|
473 | << result << "]" << endl; |
---|
474 | } |
---|
475 | |
---|
476 | text.replace_all (pattern, result); |
---|
477 | |
---|
478 | // The substitution will restart from the same place |
---|
479 | // allowing for recursive replacements |
---|
480 | start = begin; |
---|
481 | } |
---|
482 | else |
---|
483 | { |
---|
484 | Symbol* macro = Symbol::find (symbol_name); |
---|
485 | if ((macro != 0) && |
---|
486 | (macro->type == Symbol::SymbolMacro)) |
---|
487 | { |
---|
488 | // Macro found |
---|
489 | cmt_string value = macro->resolve_macro_value (); |
---|
490 | text.replace_all (pattern, value); |
---|
491 | |
---|
492 | // The substitution will restart from the same place |
---|
493 | // allowing for recursive replacements |
---|
494 | start = begin; |
---|
495 | } |
---|
496 | else if ((macro == 0) || |
---|
497 | ((macro->type == Symbol::SymbolSet) || (macro->type == Symbol::SymbolPath))) |
---|
498 | { |
---|
499 | // Set found |
---|
500 | // ensure that the delimiters will match the OS dependent |
---|
501 | // delimiters. |
---|
502 | |
---|
503 | cmt_string pattern_close = marker.pattern; |
---|
504 | |
---|
505 | if (pattern_close != CmtSystem::ev_close ()) |
---|
506 | { |
---|
507 | cmt_string new_pattern; |
---|
508 | |
---|
509 | new_pattern = CmtSystem::ev_open (); |
---|
510 | new_pattern += symbol_name; |
---|
511 | new_pattern += CmtSystem::ev_close (); |
---|
512 | |
---|
513 | text.replace (pattern, new_pattern); |
---|
514 | } |
---|
515 | |
---|
516 | start = end + 1; |
---|
517 | } |
---|
518 | else |
---|
519 | { |
---|
520 | start = end + 1; |
---|
521 | } |
---|
522 | } |
---|
523 | } |
---|
524 | } |
---|
525 | |
---|
526 | /** |
---|
527 | |
---|
528 | This function suppress all OS delimiters ie ${ } or % % and replaces them |
---|
529 | by the pure macro delimiters $( ) |
---|
530 | |
---|
531 | `xxx` pattern is replaced by the result of the execution of the command |
---|
532 | |
---|
533 | */ |
---|
534 | static void suppress_OS_delimiters (cmt_string& text) |
---|
535 | { |
---|
536 | cmt_string pattern; |
---|
537 | cmt_string symbol_name; |
---|
538 | char end_pattern; |
---|
539 | |
---|
540 | int start = 0; |
---|
541 | |
---|
542 | for (;;) |
---|
543 | { |
---|
544 | int begin; |
---|
545 | int end; |
---|
546 | |
---|
547 | symbol_marker markers[3]; |
---|
548 | int num = 0; |
---|
549 | |
---|
550 | markers[num].set (text.find (start, "${"), '}', 2); num++; |
---|
551 | markers[num].set (text.find (start, "`"), '`', 1); num++; |
---|
552 | |
---|
553 | #ifdef WIN32 |
---|
554 | markers[num].set (text.find (start, "%"), '%', 1); num++; |
---|
555 | #endif |
---|
556 | |
---|
557 | // Find the first of three patterns |
---|
558 | |
---|
559 | symbol_marker& marker = symbol_marker::get_lowest (markers, num); |
---|
560 | |
---|
561 | begin = marker.ptr; |
---|
562 | |
---|
563 | if (begin == cmt_string::npos) break; |
---|
564 | |
---|
565 | end_pattern = marker.pattern; |
---|
566 | start = begin + marker.intro; |
---|
567 | |
---|
568 | end = text.find (start, end_pattern); |
---|
569 | if (end == cmt_string::npos) |
---|
570 | { |
---|
571 | // The pattern is a fake one (no ending!) |
---|
572 | start++; |
---|
573 | continue; |
---|
574 | } |
---|
575 | |
---|
576 | // This should never happen... |
---|
577 | if (end < begin) break; |
---|
578 | |
---|
579 | // Extract the complete pattern |
---|
580 | text.substr (begin, end - begin + 1, pattern); |
---|
581 | |
---|
582 | // Then only the macro name |
---|
583 | text.substr (begin + marker.intro, end - begin - marker.intro, symbol_name); |
---|
584 | |
---|
585 | if (text[begin] == '`') |
---|
586 | { |
---|
587 | cmt_string command = symbol_name; |
---|
588 | resolve_value (command); |
---|
589 | |
---|
590 | // The macro value is a shell command that first needs |
---|
591 | // to be applied. The output of the command is substituted |
---|
592 | |
---|
593 | cmt_string result; |
---|
594 | |
---|
595 | Symbol::all_set (); |
---|
596 | CmtSystem::execute (command, result); |
---|
597 | |
---|
598 | int pos; |
---|
599 | pos = result.find ('\n'); |
---|
600 | if (pos != cmt_string::npos) result.erase (pos); |
---|
601 | pos = result.find ('\r'); |
---|
602 | if (pos != cmt_string::npos) result.erase (pos); |
---|
603 | |
---|
604 | if (Cmt::get_debug ()) |
---|
605 | { |
---|
606 | cout << " Executing [" << command << "] to expand a macro value =>[" |
---|
607 | << result << "]" << endl; |
---|
608 | } |
---|
609 | |
---|
610 | text.replace_all (pattern, result); |
---|
611 | |
---|
612 | // The substitution will restart from the same place |
---|
613 | // allowing for recursive replacements |
---|
614 | start = begin; |
---|
615 | } |
---|
616 | else |
---|
617 | { |
---|
618 | cmt_string new_pattern; |
---|
619 | |
---|
620 | new_pattern = "$("; |
---|
621 | new_pattern += symbol_name; |
---|
622 | new_pattern += ")"; |
---|
623 | |
---|
624 | text.replace (pattern, new_pattern); |
---|
625 | |
---|
626 | start = begin; |
---|
627 | } |
---|
628 | } |
---|
629 | } |
---|
630 | |
---|
631 | //------------------------------------------------------------- |
---|
632 | /* */ |
---|
633 | /* Operations on SymbolValues */ |
---|
634 | /* */ |
---|
635 | //------------------------------------------------------------- |
---|
636 | |
---|
637 | //------------------------------------------------------------- |
---|
638 | SymbolValue::SymbolValue () |
---|
639 | { |
---|
640 | tag = 0; |
---|
641 | } |
---|
642 | |
---|
643 | //------------------------------------------------------------- |
---|
644 | SymbolValue::~SymbolValue () |
---|
645 | { |
---|
646 | tag = 0; |
---|
647 | } |
---|
648 | |
---|
649 | //------------------------------------------------------------- |
---|
650 | /* */ |
---|
651 | /* Operations on Symbols */ |
---|
652 | /* */ |
---|
653 | //------------------------------------------------------------- |
---|
654 | |
---|
655 | //------------------------------------------------------------- |
---|
656 | Symbol* Symbol::create (const cmt_string& name, |
---|
657 | CommandType command, |
---|
658 | Use* use) |
---|
659 | { |
---|
660 | static SetBuilder Set; |
---|
661 | static PathBuilder Path; |
---|
662 | static MacroBuilder Macro; |
---|
663 | static ScriptBuilder Script; |
---|
664 | static ActionBuilder Action; |
---|
665 | |
---|
666 | static SymbolVector& Symbols = symbols (); |
---|
667 | static SymbolMap& SymbolMap = symbol_map (); |
---|
668 | |
---|
669 | SymbolType type = SymbolUndefined; |
---|
670 | |
---|
671 | switch (command) |
---|
672 | { |
---|
673 | case CommandSet: |
---|
674 | case CommandSetAppend: |
---|
675 | case CommandSetPrepend: |
---|
676 | case CommandSetRemove: |
---|
677 | case CommandSetRemoveRegexp: |
---|
678 | type = SymbolSet; |
---|
679 | break; |
---|
680 | case CommandPath: |
---|
681 | case CommandPathAppend: |
---|
682 | case CommandPathPrepend: |
---|
683 | case CommandPathRemove: |
---|
684 | case CommandPathRemoveRegexp: |
---|
685 | type = SymbolPath; |
---|
686 | break; |
---|
687 | case CommandMacro: |
---|
688 | case CommandMacroAppend: |
---|
689 | case CommandMacroPrepend: |
---|
690 | case CommandMacroRemove: |
---|
691 | case CommandMacroRemoveRegexp: |
---|
692 | case CommandMacroRemoveAll: |
---|
693 | case CommandMacroRemoveAllRegexp: |
---|
694 | type = SymbolMacro; |
---|
695 | break; |
---|
696 | case CommandAction: |
---|
697 | type = SymbolAction; |
---|
698 | break; |
---|
699 | case CommandAlias: |
---|
700 | type = SymbolAlias; |
---|
701 | break; |
---|
702 | case CommandSetupScript: |
---|
703 | type = SymbolSetupScript; |
---|
704 | break; |
---|
705 | case CommandCleanupScript: |
---|
706 | type = SymbolCleanupScript; |
---|
707 | break; |
---|
708 | } |
---|
709 | |
---|
710 | { |
---|
711 | Symbol* symbol; |
---|
712 | |
---|
713 | symbol = find (name); |
---|
714 | if (symbol != 0) |
---|
715 | { |
---|
716 | if (symbol->type != type) |
---|
717 | { |
---|
718 | ActionType action = Cmt::get_action (); |
---|
719 | |
---|
720 | if ((!Cmt::get_quiet ()) && |
---|
721 | (action != action_build_constituents_config) && |
---|
722 | (action != action_build_constituent_config)) |
---|
723 | { |
---|
724 | cmt_string s1; |
---|
725 | cmt_string s2; |
---|
726 | |
---|
727 | switch (symbol->type) |
---|
728 | { |
---|
729 | case SymbolSet: |
---|
730 | s1 = "set"; |
---|
731 | break; |
---|
732 | case SymbolPath: |
---|
733 | s1 = "path"; |
---|
734 | break; |
---|
735 | case SymbolMacro: |
---|
736 | s1 = "macro"; |
---|
737 | break; |
---|
738 | case SymbolSetupScript: |
---|
739 | s1 = "setup_script"; |
---|
740 | break; |
---|
741 | case SymbolCleanupScript: |
---|
742 | s1 = "cleanup_script"; |
---|
743 | break; |
---|
744 | case SymbolAction: |
---|
745 | s1 = "action"; |
---|
746 | break; |
---|
747 | case SymbolAlias: |
---|
748 | s1 = "alias"; |
---|
749 | break; |
---|
750 | } |
---|
751 | |
---|
752 | switch (type) |
---|
753 | { |
---|
754 | case SymbolSet: |
---|
755 | s2 = "set"; |
---|
756 | break; |
---|
757 | case SymbolPath: |
---|
758 | s2 = "path"; |
---|
759 | break; |
---|
760 | case SymbolMacro: |
---|
761 | s2 = "macro"; |
---|
762 | break; |
---|
763 | case SymbolSetupScript: |
---|
764 | s2 = "setup_script"; |
---|
765 | break; |
---|
766 | case SymbolCleanupScript: |
---|
767 | s2 = "cleanup_script"; |
---|
768 | break; |
---|
769 | case SymbolAction: |
---|
770 | s2 = "action"; |
---|
771 | break; |
---|
772 | case SymbolAlias: |
---|
773 | s2 = "alias"; |
---|
774 | break; |
---|
775 | } |
---|
776 | // <PACKAGE>ROOT macro is defined in |
---|
777 | // Use::fill_standard_macros <- SyntaxParser::parse_requirements |
---|
778 | // "cmt -requirements setup" may generate <PACKAGE>ROOT set |
---|
779 | // hence, warning |
---|
780 | // Symbol <PACKAGE>ROOT inconsistently redeclared from macro to set in package <package> |
---|
781 | // below, we suppress the warning for current package |
---|
782 | if (use != &(Use::current()) || |
---|
783 | (Use::current().prefix + "ROOT") != name || |
---|
784 | symbol->type != SymbolMacro || |
---|
785 | type != SymbolSet) |
---|
786 | CmtMessage::warning ("Symbol " + name |
---|
787 | + " inconsistently redeclared from " + s1 |
---|
788 | + " to " + s2 |
---|
789 | + ( (use != 0) ? |
---|
790 | " in package " + use->get_package_name () : |
---|
791 | "" ) |
---|
792 | ); |
---|
793 | /* |
---|
794 | cerr << "#CMT> Warning: Symbol " << name |
---|
795 | << " inconsistently redeclared from " << s1 << " to " << s2; |
---|
796 | if (use != 0) cerr << " in package " << use->get_package_name (); |
---|
797 | cerr << endl; |
---|
798 | */ |
---|
799 | } |
---|
800 | } |
---|
801 | |
---|
802 | return (symbol); |
---|
803 | } |
---|
804 | } |
---|
805 | |
---|
806 | Symbol& symbol = Symbols.add (); |
---|
807 | SymbolMap.add (name, symbol); |
---|
808 | |
---|
809 | symbol.name = name; |
---|
810 | symbol.scope = use->get_current_scope (); |
---|
811 | symbol.type = type; |
---|
812 | |
---|
813 | symbol.value_lists.clear (); |
---|
814 | |
---|
815 | switch (type) |
---|
816 | { |
---|
817 | case SymbolSet: |
---|
818 | symbol.builder = &Set; |
---|
819 | break; |
---|
820 | case SymbolPath: |
---|
821 | symbol.builder = &Path; |
---|
822 | break; |
---|
823 | case SymbolAlias: |
---|
824 | symbol.builder = &Set; |
---|
825 | break; |
---|
826 | case SymbolMacro: |
---|
827 | symbol.builder = &Macro; |
---|
828 | break; |
---|
829 | case SymbolSetupScript: |
---|
830 | case SymbolCleanupScript: |
---|
831 | symbol.builder = &Script; |
---|
832 | break; |
---|
833 | case SymbolAction: |
---|
834 | symbol.builder = &Action; |
---|
835 | break; |
---|
836 | } |
---|
837 | |
---|
838 | symbol.selected_value = -1; |
---|
839 | symbol.printed = false; |
---|
840 | |
---|
841 | return (&symbol); |
---|
842 | } |
---|
843 | |
---|
844 | //------------------------------------------------------------- |
---|
845 | Symbol* Symbol::find (const cmt_string& name) |
---|
846 | { |
---|
847 | static SymbolMap& SymbolMap = symbol_map (); |
---|
848 | |
---|
849 | Symbol* result = 0; |
---|
850 | |
---|
851 | result = SymbolMap.find (name); |
---|
852 | |
---|
853 | return (result); |
---|
854 | } |
---|
855 | |
---|
856 | //------------------------------------------------------------- |
---|
857 | int Symbol::symbol_number () |
---|
858 | { |
---|
859 | static SymbolVector& Symbols = symbols (); |
---|
860 | |
---|
861 | return (Symbols.size ()); |
---|
862 | } |
---|
863 | |
---|
864 | //------------------------------------------------------------- |
---|
865 | Symbol::SymbolVector& Symbol::symbols () |
---|
866 | { |
---|
867 | static Database& db = Database::instance (); |
---|
868 | static SymbolVector& Symbols = db.symbols (); |
---|
869 | |
---|
870 | return (Symbols); |
---|
871 | } |
---|
872 | |
---|
873 | //------------------------------------------------------------- |
---|
874 | Symbol::SymbolMap& Symbol::symbol_map () |
---|
875 | { |
---|
876 | static Database& db = Database::instance (); |
---|
877 | static SymbolMap& SymbolMap = db.symbol_map (); |
---|
878 | |
---|
879 | return (SymbolMap); |
---|
880 | } |
---|
881 | |
---|
882 | /** |
---|
883 | Filter out faulty items of a path-like symbol value |
---|
884 | */ |
---|
885 | void Symbol::filter_path_value (const cmt_string& name, cmt_string& text) |
---|
886 | { |
---|
887 | |
---|
888 | CmtSystem::cmt_string_vector paths; |
---|
889 | CmtSystem::cmt_string_vector normalyzed_paths; |
---|
890 | |
---|
891 | CmtSystem::split (text, CmtSystem::path_separator (), paths); |
---|
892 | |
---|
893 | for (int j = 0; j < paths.size (); ++j) |
---|
894 | { |
---|
895 | cmt_string& t = paths[j]; |
---|
896 | |
---|
897 | if (!CmtSystem::test_directory (t)) |
---|
898 | { |
---|
899 | if (CmtMessage::active (Verbose)) |
---|
900 | CmtMessage::warning ("Non-existent directory " + t + " in " + name); |
---|
901 | /* |
---|
902 | if (Cmt::get_warnings ()) |
---|
903 | { |
---|
904 | cerr << "#CMT> Warning: Wrong path item " << t << " in " << name << endl; |
---|
905 | } |
---|
906 | */ |
---|
907 | } |
---|
908 | |
---|
909 | int exist = 0; |
---|
910 | for (int i = 0; i < j; ++i) |
---|
911 | { |
---|
912 | cmt_string& u = paths[i]; |
---|
913 | if (u == t) |
---|
914 | exist = 1; |
---|
915 | } |
---|
916 | if (exist==0) |
---|
917 | { |
---|
918 | cmt_string& s = normalyzed_paths.add (); |
---|
919 | s = t; |
---|
920 | } |
---|
921 | } |
---|
922 | |
---|
923 | Cmt::vector_to_string (normalyzed_paths, CmtSystem::path_separator (), text); |
---|
924 | |
---|
925 | for (;;) |
---|
926 | { |
---|
927 | int sz = text.size (); |
---|
928 | |
---|
929 | if (sz == 0) break; |
---|
930 | |
---|
931 | if ((text[0] == ';') || (text[0] == ':')) |
---|
932 | { |
---|
933 | text.erase (0, 1); |
---|
934 | } |
---|
935 | else if ((text[sz-1] == ';') || (text[sz-1] == ':')) |
---|
936 | { |
---|
937 | text.erase (sz-1, 1); |
---|
938 | } |
---|
939 | else |
---|
940 | { |
---|
941 | break; |
---|
942 | } |
---|
943 | } |
---|
944 | |
---|
945 | text.replace_all ("::", ":"); |
---|
946 | text.replace_all (";;", ";"); |
---|
947 | } |
---|
948 | |
---|
949 | |
---|
950 | //------------------------------------------------------------- |
---|
951 | Symbol& Symbol::symbol (int index) |
---|
952 | { |
---|
953 | static SymbolVector& Symbols = symbols (); |
---|
954 | |
---|
955 | return (Symbols[index]); |
---|
956 | } |
---|
957 | |
---|
958 | //------------------------------------------------------------- |
---|
959 | void Symbol::action (const CmtSystem::cmt_string_vector& words, |
---|
960 | CommandType command_type, |
---|
961 | Use* use) |
---|
962 | { |
---|
963 | int number; |
---|
964 | Symbol* symbol; |
---|
965 | Tag* tag; |
---|
966 | |
---|
967 | if (words.size () < 1) return; |
---|
968 | cmt_string name = words[1]; |
---|
969 | |
---|
970 | if ((command_type == CommandSetupScript) || |
---|
971 | (command_type == CommandCleanupScript)) |
---|
972 | { |
---|
973 | cmt_string full_name; |
---|
974 | |
---|
975 | Symbol::expand (name); |
---|
976 | |
---|
977 | if (name != "") |
---|
978 | { |
---|
979 | if (CmtSystem::absolute_path (name)) |
---|
980 | { |
---|
981 | full_name = name; |
---|
982 | } |
---|
983 | else |
---|
984 | { |
---|
985 | if (use->get_strategy ("SetupRoot") && |
---|
986 | use->get_package_name () != "cmt_standalone") |
---|
987 | { |
---|
988 | #ifdef WIN32 |
---|
989 | full_name = "%"; |
---|
990 | #else |
---|
991 | full_name = "${"; |
---|
992 | #endif |
---|
993 | full_name += CmtSystem::mangle (use->prefix); |
---|
994 | full_name += "ROOT"; |
---|
995 | #ifdef WIN32 |
---|
996 | full_name += "%"; |
---|
997 | #else |
---|
998 | full_name += "}"; |
---|
999 | #endif |
---|
1000 | } |
---|
1001 | else |
---|
1002 | { |
---|
1003 | full_name = use->get_full_path (); |
---|
1004 | } |
---|
1005 | if (use->style == cmt_style) |
---|
1006 | { |
---|
1007 | full_name += CmtSystem::file_separator (); |
---|
1008 | full_name += "cmt"; |
---|
1009 | } |
---|
1010 | else if (use->style == mgr_style) |
---|
1011 | { |
---|
1012 | full_name += CmtSystem::file_separator (); |
---|
1013 | full_name += "mgr"; |
---|
1014 | } |
---|
1015 | // else if (use->style == no_version_style) full_name += "cmt"; |
---|
1016 | // else full_name += "mgr"; |
---|
1017 | full_name += CmtSystem::file_separator (); |
---|
1018 | full_name += name; |
---|
1019 | } |
---|
1020 | |
---|
1021 | symbol = create (full_name, command_type, use); |
---|
1022 | symbol->add_value_to_list (command_type, use, |
---|
1023 | Tag::get_default (), full_name); |
---|
1024 | } |
---|
1025 | } |
---|
1026 | else |
---|
1027 | { |
---|
1028 | if (words.size () < 2) return; |
---|
1029 | const cmt_string& default_value = words[2]; |
---|
1030 | |
---|
1031 | Cmt::reset_all_sets_done (); |
---|
1032 | |
---|
1033 | if (Cmt::get_debug ()) |
---|
1034 | { |
---|
1035 | cout << "Symbol::action> name:" << name |
---|
1036 | << " access:" << Cmt::get_current_access () |
---|
1037 | << " scope:" << use->get_current_scope () << endl; |
---|
1038 | } |
---|
1039 | |
---|
1040 | if (Cmt::get_current_access () == UserMode) |
---|
1041 | { |
---|
1042 | /* |
---|
1043 | The following statements mean that some symbols are |
---|
1044 | always private. |
---|
1045 | This list is hardcoded. This should be replaced by a |
---|
1046 | database of "private" symbols. |
---|
1047 | */ |
---|
1048 | if (name == "constituents") return; |
---|
1049 | if (name == "constituentscclean") return; |
---|
1050 | |
---|
1051 | if (use->get_current_scope () == ScopePrivate) return; |
---|
1052 | } |
---|
1053 | |
---|
1054 | symbol = create (name, command_type, use); |
---|
1055 | |
---|
1056 | /* |
---|
1057 | Parse the default value. |
---|
1058 | */ |
---|
1059 | |
---|
1060 | symbol->add_value_to_list (command_type, use, |
---|
1061 | Tag::get_default (), default_value); |
---|
1062 | |
---|
1063 | /* |
---|
1064 | Then parse all specific values |
---|
1065 | |
---|
1066 | <tag> <value> |
---|
1067 | ... |
---|
1068 | */ |
---|
1069 | |
---|
1070 | number = 3; |
---|
1071 | while (number < (words.size () - 1)) |
---|
1072 | { |
---|
1073 | cmt_string tag_name = words[number]; |
---|
1074 | const cmt_string& value = words[number + 1]; |
---|
1075 | |
---|
1076 | expand (tag_name); |
---|
1077 | |
---|
1078 | if (Cmt::get_debug ()) |
---|
1079 | { |
---|
1080 | cout << "Symbol::action> tag_name=" << tag_name << endl; |
---|
1081 | } |
---|
1082 | |
---|
1083 | tag = Tag::find (tag_name); |
---|
1084 | if (tag == 0) |
---|
1085 | { |
---|
1086 | tag = Tag::add (tag_name, PriorityUserTag, "use", use); |
---|
1087 | } |
---|
1088 | |
---|
1089 | symbol->add_value_to_list (command_type, use, tag, value); |
---|
1090 | |
---|
1091 | number += 2; |
---|
1092 | } |
---|
1093 | |
---|
1094 | if (name == "CMTPATH") |
---|
1095 | { |
---|
1096 | Cmt::configure_cmt_path (use); |
---|
1097 | } |
---|
1098 | else if (name == "CMTPROJECTPATH") |
---|
1099 | { |
---|
1100 | Cmt::configure_cmt_path (use); |
---|
1101 | } |
---|
1102 | else if (name == "CMTSITE") |
---|
1103 | { |
---|
1104 | Cmt::configure_site_tag (use); |
---|
1105 | } |
---|
1106 | else if (name == "CMTCONFIG") |
---|
1107 | { |
---|
1108 | //cerr << "redefining CMTCONFIG" << endl; |
---|
1109 | Cmt::configure_tags (use); |
---|
1110 | } |
---|
1111 | else if (name == "CMTHOME") |
---|
1112 | { |
---|
1113 | Cmt::configure_home (use); |
---|
1114 | } |
---|
1115 | else if (name == "CMTUSERCONTEXT") |
---|
1116 | { |
---|
1117 | Cmt::configure_user_context (use); |
---|
1118 | } |
---|
1119 | else if (name.find ("_native_version") != cmt_string::npos) |
---|
1120 | { |
---|
1121 | cmt_string n = use->get_package_name (); |
---|
1122 | n += "_native_version"; |
---|
1123 | |
---|
1124 | if (name == n) |
---|
1125 | { |
---|
1126 | use->set_native_version (true); |
---|
1127 | } |
---|
1128 | } |
---|
1129 | } |
---|
1130 | } |
---|
1131 | |
---|
1132 | //------------------------------------------------------------- |
---|
1133 | int Symbol::is_selected (const cmt_string& name) |
---|
1134 | { |
---|
1135 | Symbol* symbol; |
---|
1136 | int number; |
---|
1137 | int value_number; |
---|
1138 | |
---|
1139 | symbol = find (name); |
---|
1140 | if (symbol == 0) return (0); |
---|
1141 | |
---|
1142 | if (symbol->value_lists.size () == 0) return (0); |
---|
1143 | |
---|
1144 | for (number = 0; |
---|
1145 | number < symbol->value_lists.size (); |
---|
1146 | number++) |
---|
1147 | { |
---|
1148 | const SymbolValueList& value_list = symbol->value_lists[number]; |
---|
1149 | |
---|
1150 | if (value_list.discarded) continue; |
---|
1151 | |
---|
1152 | if ((value_list.command_type == CommandMacro) || |
---|
1153 | (value_list.command_type == CommandSet) || |
---|
1154 | (value_list.command_type == CommandSetAppend) || |
---|
1155 | (value_list.command_type == CommandSetPrepend) || |
---|
1156 | (value_list.command_type == CommandSetRemove) || |
---|
1157 | (value_list.command_type == CommandSetRemoveRegexp) || |
---|
1158 | (value_list.command_type == CommandAlias) || |
---|
1159 | (value_list.command_type == CommandAction)) |
---|
1160 | { |
---|
1161 | for (value_number = 0; |
---|
1162 | value_number < value_list.values.size (); |
---|
1163 | value_number++) |
---|
1164 | { |
---|
1165 | Tag* tag; |
---|
1166 | |
---|
1167 | SymbolValue& value = value_list.values[value_number]; |
---|
1168 | |
---|
1169 | tag = value.tag; |
---|
1170 | if ((tag == 0) || |
---|
1171 | (tag == Tag::get_default ()) || |
---|
1172 | (tag->is_selected () != 0)) |
---|
1173 | { |
---|
1174 | return (1); |
---|
1175 | } |
---|
1176 | } |
---|
1177 | } |
---|
1178 | } |
---|
1179 | |
---|
1180 | return (0); |
---|
1181 | } |
---|
1182 | |
---|
1183 | //------------------------------------------------------------- |
---|
1184 | Symbol::Symbol () |
---|
1185 | { |
---|
1186 | name = ""; |
---|
1187 | } |
---|
1188 | |
---|
1189 | //------------------------------------------------------------- |
---|
1190 | Symbol::~Symbol () |
---|
1191 | { |
---|
1192 | } |
---|
1193 | |
---|
1194 | /** |
---|
1195 | * Characterizes if a value is provided as the reference to itself. |
---|
1196 | */ |
---|
1197 | bool Symbol::value_is_reflexive (const cmt_string& text) const |
---|
1198 | { |
---|
1199 | bool result = false; |
---|
1200 | int text_length = text.size (); |
---|
1201 | |
---|
1202 | if (text_length == (name.size () + 3)) |
---|
1203 | { |
---|
1204 | static cmt_string temp; |
---|
1205 | |
---|
1206 | if (text[0] == '$') |
---|
1207 | { |
---|
1208 | if (text[1] == '(') |
---|
1209 | { |
---|
1210 | temp = "$("; |
---|
1211 | temp += name; |
---|
1212 | temp += ")"; |
---|
1213 | |
---|
1214 | if (text == temp) |
---|
1215 | { |
---|
1216 | result = true; |
---|
1217 | } |
---|
1218 | } |
---|
1219 | else if (text[1] == '{') |
---|
1220 | { |
---|
1221 | temp = "${"; |
---|
1222 | temp += name; |
---|
1223 | temp += "}"; |
---|
1224 | |
---|
1225 | if (text == temp) |
---|
1226 | { |
---|
1227 | result = true; |
---|
1228 | } |
---|
1229 | } |
---|
1230 | } |
---|
1231 | } |
---|
1232 | else if (text_length == (name.size () + 2)) |
---|
1233 | { |
---|
1234 | static cmt_string temp; |
---|
1235 | |
---|
1236 | temp = "%"; |
---|
1237 | temp += name; |
---|
1238 | temp += "%"; |
---|
1239 | |
---|
1240 | if (text == temp) |
---|
1241 | { |
---|
1242 | result = true; |
---|
1243 | } |
---|
1244 | } |
---|
1245 | |
---|
1246 | return (result); |
---|
1247 | } |
---|
1248 | |
---|
1249 | //------------------------------------------------------------- |
---|
1250 | void Symbol::add_value_to_list (CommandType command_type, |
---|
1251 | Use* use, |
---|
1252 | Tag* tag, |
---|
1253 | const cmt_string& text) |
---|
1254 | { |
---|
1255 | SymbolValueList* value_list = 0; |
---|
1256 | bool is_reflexive = false; |
---|
1257 | |
---|
1258 | // |
---|
1259 | // First pickup the most recent value_list |
---|
1260 | // |
---|
1261 | if (value_lists.size () > 0) value_list = &(value_lists.back ()); |
---|
1262 | |
---|
1263 | // |
---|
1264 | // Create a new value list is we switch to another use or |
---|
1265 | // if we switch to a new command_type (eg. switching from |
---|
1266 | // macro to macro_append). |
---|
1267 | // |
---|
1268 | if ((value_list == 0) || |
---|
1269 | (use != value_list->use) || |
---|
1270 | (command_type != value_list->command_type) || |
---|
1271 | (tag == Tag::get_default ())) |
---|
1272 | { |
---|
1273 | value_list = &(value_lists.add ()); |
---|
1274 | value_list->use = use; |
---|
1275 | value_list->command_type = command_type; |
---|
1276 | value_list->values.clear (); |
---|
1277 | value_list->discarded = false; |
---|
1278 | value_list->is_reflexive = false; |
---|
1279 | } |
---|
1280 | |
---|
1281 | /* |
---|
1282 | else |
---|
1283 | { |
---|
1284 | value_list = &(value_lists[value_lists.size () - 1]); |
---|
1285 | } |
---|
1286 | */ |
---|
1287 | |
---|
1288 | is_reflexive = value_list->is_reflexive; |
---|
1289 | |
---|
1290 | // |
---|
1291 | // If the command_type is command_macro or command_set, |
---|
1292 | // this is considered as a full re-set of this symbol |
---|
1293 | // In this case, we have to discard all previous values |
---|
1294 | // |
---|
1295 | // However, we'd like to exclude from this logic the cases where |
---|
1296 | // the value is **exactly* |
---|
1297 | // |
---|
1298 | // $(<symbol>) |
---|
1299 | // ${<symbol>} |
---|
1300 | // %<symbol>% |
---|
1301 | // |
---|
1302 | // which would then mean that we do not reset the value but rather |
---|
1303 | // override it. |
---|
1304 | // |
---|
1305 | |
---|
1306 | // |
---|
1307 | // Inside this value_list, we add this new tag-value pair. |
---|
1308 | // |
---|
1309 | |
---|
1310 | if ((command_type == CommandMacro) || |
---|
1311 | (command_type == CommandSet) || |
---|
1312 | (command_type == CommandPath) || |
---|
1313 | (command_type == CommandAction)) |
---|
1314 | { |
---|
1315 | // |
---|
1316 | // Check whether we have to hide previous settings by this new definition |
---|
1317 | // (of course this is only useful if there WERE previous settings) |
---|
1318 | // |
---|
1319 | if ((value_lists.size () >= 1) && (!is_reflexive)) |
---|
1320 | { |
---|
1321 | if (value_is_reflexive (text)) |
---|
1322 | { |
---|
1323 | value_list->is_reflexive = true; |
---|
1324 | is_reflexive = true; |
---|
1325 | } |
---|
1326 | else |
---|
1327 | { |
---|
1328 | //cerr << "...discarding old values for symbol " << name << " text=[" << text << "]" << endl; |
---|
1329 | |
---|
1330 | for (int i = 0; i < (value_lists.size () - 1); i++) |
---|
1331 | { |
---|
1332 | SymbolValueList& vl = value_lists[i]; |
---|
1333 | |
---|
1334 | if ((vl.use != 0) && |
---|
1335 | (vl.use->discarded)) |
---|
1336 | { |
---|
1337 | //vl.discarded = true; |
---|
1338 | } |
---|
1339 | } |
---|
1340 | } |
---|
1341 | } |
---|
1342 | } |
---|
1343 | |
---|
1344 | SymbolValue& value = value_list->values.add (); |
---|
1345 | |
---|
1346 | value.tag = tag; |
---|
1347 | value.text = text; |
---|
1348 | value.selected = 0; |
---|
1349 | } |
---|
1350 | |
---|
1351 | /** |
---|
1352 | Compute the current value of all environment variables and set them to the |
---|
1353 | shell |
---|
1354 | */ |
---|
1355 | void Symbol::all_set () |
---|
1356 | { |
---|
1357 | //cerr << "all_set" << endl; |
---|
1358 | |
---|
1359 | static bool running = false; |
---|
1360 | |
---|
1361 | |
---|
1362 | if (Cmt::get_debug ()) |
---|
1363 | { |
---|
1364 | cout << "\nSymbol::all_set> done=" << running << endl; |
---|
1365 | } |
---|
1366 | |
---|
1367 | if (Cmt::get_all_sets_done ()) return; |
---|
1368 | |
---|
1369 | if (running) return; |
---|
1370 | |
---|
1371 | running = true; |
---|
1372 | Cmt::set_all_sets_done (); |
---|
1373 | |
---|
1374 | static SymbolVector& Symbols = symbols (); |
---|
1375 | Use::UsePtrVector& Uses = Use::get_ordered_uses (); |
---|
1376 | |
---|
1377 | int number; |
---|
1378 | |
---|
1379 | if (Symbols.size () == 0) |
---|
1380 | { |
---|
1381 | running = false; |
---|
1382 | return; |
---|
1383 | } |
---|
1384 | |
---|
1385 | cmt_string value; |
---|
1386 | |
---|
1387 | for (number = 0; number < Symbol::symbol_number (); number++) |
---|
1388 | { |
---|
1389 | Symbol& symbol = Symbol::symbol (number); |
---|
1390 | |
---|
1391 | if (symbol.type != SymbolSet) continue; |
---|
1392 | |
---|
1393 | value = symbol.build_macro_value (); |
---|
1394 | if (value != "") |
---|
1395 | { |
---|
1396 | Symbol::expand (value); |
---|
1397 | |
---|
1398 | CmtSystem::putenv (symbol.name, value); |
---|
1399 | } |
---|
1400 | } |
---|
1401 | |
---|
1402 | cmt_string cmtconfig = CmtSystem::get_cmt_config (); |
---|
1403 | |
---|
1404 | if (Uses.size () > 0) |
---|
1405 | { |
---|
1406 | int number; |
---|
1407 | |
---|
1408 | for (number = 0; number < Uses.size (); number++) |
---|
1409 | { |
---|
1410 | Use& use = *(Uses[number]); |
---|
1411 | |
---|
1412 | if (use.discarded) continue; |
---|
1413 | |
---|
1414 | if (use.get_package_name () == "cmt_standalone") continue; |
---|
1415 | |
---|
1416 | if (use.get_strategy ("SetupConfig")) |
---|
1417 | { |
---|
1418 | cmt_string temp; |
---|
1419 | |
---|
1420 | temp = use.prefix; |
---|
1421 | temp += "CONFIG"; |
---|
1422 | |
---|
1423 | CmtSystem::putenv (temp, cmtconfig); |
---|
1424 | } |
---|
1425 | |
---|
1426 | if (use.get_strategy ("SetupRoot")) |
---|
1427 | { |
---|
1428 | cmt_string temp; |
---|
1429 | |
---|
1430 | temp = use.prefix; |
---|
1431 | temp += "ROOT"; |
---|
1432 | |
---|
1433 | CmtSystem::putenv (temp, use.get_full_path ()); |
---|
1434 | } |
---|
1435 | } |
---|
1436 | } |
---|
1437 | |
---|
1438 | { |
---|
1439 | Use& use = Use::current (); |
---|
1440 | |
---|
1441 | if (use.get_package_name () != "cmt_standalone") |
---|
1442 | { |
---|
1443 | if (use.get_strategy ("SetupConfig")) |
---|
1444 | { |
---|
1445 | cmt_string temp; |
---|
1446 | |
---|
1447 | temp = use.prefix; |
---|
1448 | temp += "CONFIG"; |
---|
1449 | |
---|
1450 | CmtSystem::putenv (temp, cmtconfig); |
---|
1451 | } |
---|
1452 | |
---|
1453 | if (use.get_strategy ("SetupRoot")) |
---|
1454 | { |
---|
1455 | cmt_string temp; |
---|
1456 | |
---|
1457 | temp = use.prefix; |
---|
1458 | temp += "ROOT"; |
---|
1459 | |
---|
1460 | CmtSystem::putenv (temp, use.get_full_path ()); |
---|
1461 | } |
---|
1462 | } |
---|
1463 | } |
---|
1464 | |
---|
1465 | for (number = 0; number < Symbol::symbol_number (); number++) |
---|
1466 | { |
---|
1467 | Symbol& symbol = Symbol::symbol (number); |
---|
1468 | |
---|
1469 | if ((symbol.type != SymbolPath)) continue; |
---|
1470 | |
---|
1471 | value = symbol.build_macro_value (); |
---|
1472 | if (value != "") |
---|
1473 | { |
---|
1474 | Symbol::expand (value); |
---|
1475 | filter_path_value (symbol.name, value); |
---|
1476 | |
---|
1477 | #ifdef WIN32 |
---|
1478 | value.replace_all ("/", "\\"); |
---|
1479 | #endif |
---|
1480 | |
---|
1481 | if (Cmt::get_debug ()) |
---|
1482 | { |
---|
1483 | cerr << "Symbol::all_set-2> " << symbol.name << " = " << value << endl; |
---|
1484 | } |
---|
1485 | |
---|
1486 | CmtSystem::putenv (symbol.name, value); |
---|
1487 | } |
---|
1488 | } |
---|
1489 | |
---|
1490 | running = false; |
---|
1491 | } |
---|
1492 | |
---|
1493 | //------------------------------------------------------------- |
---|
1494 | void Symbol::all_print (PrintMode mode) |
---|
1495 | { |
---|
1496 | static SymbolVector& Symbols = symbols (); |
---|
1497 | |
---|
1498 | int number; |
---|
1499 | |
---|
1500 | if (Symbols.size () == 0) return; |
---|
1501 | |
---|
1502 | switch (mode) |
---|
1503 | { |
---|
1504 | case Requirements : |
---|
1505 | for (number = 0; number < Symbol::symbol_number (); number++) |
---|
1506 | { |
---|
1507 | Symbol& symbol = Symbol::symbol (number); |
---|
1508 | |
---|
1509 | if ((symbol.type == SymbolSet) || |
---|
1510 | (symbol.type == SymbolAlias) || |
---|
1511 | (symbol.type == SymbolSetupScript) || |
---|
1512 | (symbol.type == SymbolPath) || |
---|
1513 | (symbol.type == SymbolMacro)) |
---|
1514 | { |
---|
1515 | if (symbol.print_macro (mode)) |
---|
1516 | { |
---|
1517 | // cout << endl; |
---|
1518 | } |
---|
1519 | } |
---|
1520 | } |
---|
1521 | break; |
---|
1522 | default : |
---|
1523 | for (number = 0; number < Symbol::symbol_number (); number++) |
---|
1524 | { |
---|
1525 | Symbol& symbol = Symbol::symbol (number); |
---|
1526 | |
---|
1527 | if ((symbol.type == SymbolSet) || |
---|
1528 | (symbol.type == SymbolAlias) || |
---|
1529 | (symbol.type == SymbolSetupScript) || |
---|
1530 | (symbol.type == SymbolPath)) |
---|
1531 | { |
---|
1532 | if (symbol.print (mode)) |
---|
1533 | { |
---|
1534 | if (mode == Bat) |
---|
1535 | { |
---|
1536 | cout << endl; |
---|
1537 | } |
---|
1538 | else if (mode == Xml) |
---|
1539 | { |
---|
1540 | // cout << endl; |
---|
1541 | } |
---|
1542 | else |
---|
1543 | { |
---|
1544 | cout << endl; |
---|
1545 | } |
---|
1546 | } |
---|
1547 | } |
---|
1548 | } |
---|
1549 | break; |
---|
1550 | } |
---|
1551 | } |
---|
1552 | |
---|
1553 | //------------------------------------------------------------- |
---|
1554 | void Symbol::check_all_paths () |
---|
1555 | { |
---|
1556 | static SymbolVector& Symbols = symbols (); |
---|
1557 | |
---|
1558 | int number; |
---|
1559 | |
---|
1560 | if (Symbols.size () == 0) return; |
---|
1561 | |
---|
1562 | for (number = 0; number < Symbol::symbol_number (); number++) |
---|
1563 | { |
---|
1564 | Symbol& symbol = Symbol::symbol (number); |
---|
1565 | |
---|
1566 | if (symbol.type == SymbolPath) |
---|
1567 | { |
---|
1568 | cmt_string temp; |
---|
1569 | |
---|
1570 | temp = symbol.build_macro_value (); |
---|
1571 | expand (temp); |
---|
1572 | |
---|
1573 | Symbol::filter_path_value (symbol.name, temp); |
---|
1574 | } |
---|
1575 | } |
---|
1576 | } |
---|
1577 | |
---|
1578 | //------------------------------------------------------------- |
---|
1579 | void Symbol::all_print_clean (PrintMode mode) |
---|
1580 | { |
---|
1581 | static SymbolVector& Symbols = symbols (); |
---|
1582 | |
---|
1583 | int number; |
---|
1584 | |
---|
1585 | if (Symbols.size () == 0) return; |
---|
1586 | |
---|
1587 | for (number = Symbols.size () - 1; number >= 0; number--) |
---|
1588 | { |
---|
1589 | Symbol& symbol = Symbols[number]; |
---|
1590 | |
---|
1591 | if ((symbol.type == SymbolSet) || |
---|
1592 | (symbol.type == SymbolAlias) || |
---|
1593 | (symbol.type == SymbolCleanupScript)) |
---|
1594 | { |
---|
1595 | if (symbol.print_clean (mode)) |
---|
1596 | { |
---|
1597 | cout << endl; |
---|
1598 | } |
---|
1599 | } |
---|
1600 | } |
---|
1601 | |
---|
1602 | for (number = Symbols.size () - 1; number >= 0; number--) |
---|
1603 | { |
---|
1604 | Symbol& symbol = Symbols[number]; |
---|
1605 | |
---|
1606 | if ((symbol.type != SymbolPath)) continue; |
---|
1607 | |
---|
1608 | if (symbol.print_clean (mode)) |
---|
1609 | { |
---|
1610 | cout << endl; |
---|
1611 | } |
---|
1612 | } |
---|
1613 | } |
---|
1614 | |
---|
1615 | //------------------------------------------------------------- |
---|
1616 | int Symbol::print_clean (PrintMode mode) |
---|
1617 | { |
---|
1618 | int result = 0; |
---|
1619 | static cmt_string temp; |
---|
1620 | |
---|
1621 | if (name == "CMTCONFIG") return (0); |
---|
1622 | |
---|
1623 | cmt_string _name; |
---|
1624 | switch (type) |
---|
1625 | { |
---|
1626 | case SymbolSet : |
---|
1627 | case SymbolPath : |
---|
1628 | if (0 != CmtSystem::mangle (name, _name)) |
---|
1629 | CmtMessage::info ("Replace " + name + " with " + _name); |
---|
1630 | break; |
---|
1631 | } |
---|
1632 | |
---|
1633 | switch (type) |
---|
1634 | { |
---|
1635 | case SymbolSet : |
---|
1636 | switch (mode) |
---|
1637 | { |
---|
1638 | case Csh : |
---|
1639 | cout << "unsetenv " << _name; |
---|
1640 | result = 1; |
---|
1641 | break; |
---|
1642 | case Sh : |
---|
1643 | cout << "[ -z ${" << _name << "+CMT} ] || unset " << _name; |
---|
1644 | // cout << "unset " << _name; |
---|
1645 | result = 1; |
---|
1646 | break; |
---|
1647 | case Bat : |
---|
1648 | cout << "set " << _name << "="; |
---|
1649 | result = 1; |
---|
1650 | break; |
---|
1651 | } |
---|
1652 | break; |
---|
1653 | case SymbolAlias : |
---|
1654 | switch (mode) |
---|
1655 | { |
---|
1656 | case Csh : |
---|
1657 | cout << "unalias " << name; |
---|
1658 | result = 1; |
---|
1659 | break; |
---|
1660 | case Sh : |
---|
1661 | cout << "[ -z ${" << name << "+CMT} ] || unset " << name; |
---|
1662 | // cout << "unset " << name; |
---|
1663 | result = 1; |
---|
1664 | break; |
---|
1665 | } |
---|
1666 | break; |
---|
1667 | case SymbolPath : |
---|
1668 | temp = clean_macro_value (); |
---|
1669 | switch (mode) |
---|
1670 | { |
---|
1671 | case Csh : |
---|
1672 | if (temp == "") |
---|
1673 | { |
---|
1674 | cout << "unsetenv " << _name; |
---|
1675 | } |
---|
1676 | else |
---|
1677 | { |
---|
1678 | cout << "setenv " << _name << " " << CmtSystem::quote (temp, " \t"); |
---|
1679 | } |
---|
1680 | result = 1; |
---|
1681 | break; |
---|
1682 | case Sh : |
---|
1683 | cout << _name << "=" << CmtSystem::quote (temp, " \t") << "; export " << _name; |
---|
1684 | result = 1; |
---|
1685 | break; |
---|
1686 | case Bat : |
---|
1687 | cout << "set " << _name << "=" << CmtSystem::quote (temp, " \t"); |
---|
1688 | result = 1; |
---|
1689 | break; |
---|
1690 | } |
---|
1691 | break; |
---|
1692 | case SymbolCleanupScript : |
---|
1693 | switch (mode) |
---|
1694 | { |
---|
1695 | case Csh : |
---|
1696 | cout << "if ( -f " << CmtSystem::quote (name, " \t") << ".csh ) then" << endl; |
---|
1697 | cout << " source " << CmtSystem::quote (name, " \t") << ".csh" << endl; |
---|
1698 | cout << |
---|
1699 | "if ( $status != 0 ) then\n" |
---|
1700 | " set cmtcleanupstatus=1\n" |
---|
1701 | "endif\n"; |
---|
1702 | cout << "endif" << endl; |
---|
1703 | result = 1; |
---|
1704 | break; |
---|
1705 | case Sh : |
---|
1706 | cout << "if test -f " << CmtSystem::quote (name, " \t") << ".sh; then" << endl; |
---|
1707 | cout << " . " << CmtSystem::quote (name, " \t") << ".sh" << endl; |
---|
1708 | cout << |
---|
1709 | "if test $? != 0; then\n" |
---|
1710 | " cmtcleanupstatus=1\n" |
---|
1711 | "fi\n"; |
---|
1712 | cout << "fi" << endl; |
---|
1713 | result = 1; |
---|
1714 | break; |
---|
1715 | case Bat : |
---|
1716 | cout << "call " << CmtSystem::quote (name, " \t"); |
---|
1717 | result = 1; |
---|
1718 | break; |
---|
1719 | } |
---|
1720 | break; |
---|
1721 | } |
---|
1722 | |
---|
1723 | return (result); |
---|
1724 | } |
---|
1725 | |
---|
1726 | //------------------------------------------------------------- |
---|
1727 | int Symbol::print (PrintMode mode) |
---|
1728 | { |
---|
1729 | int result = 0; |
---|
1730 | |
---|
1731 | cmt_string temp = build_macro_value (); |
---|
1732 | bool empty = (temp.size () == 0) ? true : false; |
---|
1733 | |
---|
1734 | if (type == SymbolPath) |
---|
1735 | { |
---|
1736 | expand (temp); |
---|
1737 | Symbol::filter_path_value (name, temp); |
---|
1738 | } |
---|
1739 | |
---|
1740 | cmt_string _name; |
---|
1741 | switch (type) |
---|
1742 | { |
---|
1743 | case SymbolSet : |
---|
1744 | case SymbolPath : |
---|
1745 | if (0 != CmtSystem::mangle (name, _name)) |
---|
1746 | CmtMessage::info ("Replace " + name + " with " + _name); |
---|
1747 | switch (mode) |
---|
1748 | { |
---|
1749 | case Csh : |
---|
1750 | if (empty) cout << "unsetenv " << _name; |
---|
1751 | else cout << "setenv " << _name << " \"" << temp << "\""; |
---|
1752 | //else cout << "setenv " << name << " " << CmtSystem::quote (temp, " \t"); |
---|
1753 | |
---|
1754 | result = 1; |
---|
1755 | break; |
---|
1756 | case Sh : |
---|
1757 | if (empty) cout << "[ -z ${" << _name << "+CMT} ] || unset " << _name; |
---|
1758 | // if (empty) cout << "unset " << _name; |
---|
1759 | else cout << _name << "=\"" << temp << "\"; export " << _name; |
---|
1760 | //else cout << name << "=" << CmtSystem::quote (temp, " \t") << "; export " << name; |
---|
1761 | |
---|
1762 | result = 1; |
---|
1763 | break; |
---|
1764 | case Bat : |
---|
1765 | temp.replace_all ("/", "\\"); |
---|
1766 | cout << "set " << _name << "=" << CmtSystem::quote (temp, " \t"); |
---|
1767 | //cout << "set " << name << "=" << temp; |
---|
1768 | result = 1; |
---|
1769 | break; |
---|
1770 | case Xml : |
---|
1771 | cout << "<variable><name>" << _name << "</name>" |
---|
1772 | << "<value>" << temp << "</value></variable>"; |
---|
1773 | result = 1; |
---|
1774 | break; |
---|
1775 | } |
---|
1776 | break; |
---|
1777 | case SymbolAlias : |
---|
1778 | switch (mode) |
---|
1779 | { |
---|
1780 | case Csh : |
---|
1781 | cout << "alias " << name << |
---|
1782 | " \"" << temp << "\""; |
---|
1783 | //CmtSystem::quote (temp, " \t"); |
---|
1784 | result = 1; |
---|
1785 | break; |
---|
1786 | case Sh : |
---|
1787 | cout << "alias " << name << |
---|
1788 | "=\"" << temp << "\""; |
---|
1789 | //"=" << CmtSystem::quote (temp, " \t"); |
---|
1790 | result = 1; |
---|
1791 | break; |
---|
1792 | case Bat : |
---|
1793 | cout << "set " << name << |
---|
1794 | "=" << CmtSystem::quote (temp, " \t"); |
---|
1795 | //"=" << temp; |
---|
1796 | result = 1; |
---|
1797 | break; |
---|
1798 | case Xml : |
---|
1799 | cout << "<alias><name>" << name << "</name>" |
---|
1800 | << "<value>" << temp << "</value></alias>"; |
---|
1801 | result = 1; |
---|
1802 | break; |
---|
1803 | } |
---|
1804 | break; |
---|
1805 | default : |
---|
1806 | break; |
---|
1807 | } |
---|
1808 | |
---|
1809 | if (temp != "") |
---|
1810 | { |
---|
1811 | switch (type) |
---|
1812 | { |
---|
1813 | case SymbolSetupScript : |
---|
1814 | switch (mode) |
---|
1815 | { |
---|
1816 | case Csh : |
---|
1817 | cout << "if ( -f " << CmtSystem::quote (name, " \t") << ".csh ) then" << endl; |
---|
1818 | cout << " source " << CmtSystem::quote (name, " \t") << ".csh" << endl; |
---|
1819 | cout << |
---|
1820 | "if ( $status != 0 ) then\n" |
---|
1821 | " set cmtsetupstatus=1\n" |
---|
1822 | "endif\n"; |
---|
1823 | cout << "endif" << endl; |
---|
1824 | result = 1; |
---|
1825 | break; |
---|
1826 | case Sh : |
---|
1827 | cout << "if test -f " << CmtSystem::quote (name, " \t") << ".sh; then" << endl; |
---|
1828 | cout << " . " << CmtSystem::quote (name, " \t") << ".sh" << endl; |
---|
1829 | cout << |
---|
1830 | "if test $? != 0; then\n" |
---|
1831 | " cmtsetupstatus=1\n" |
---|
1832 | "fi\n"; |
---|
1833 | cout << "fi" << endl; |
---|
1834 | result = 1; |
---|
1835 | break; |
---|
1836 | case Bat : |
---|
1837 | cout << "call " << CmtSystem::quote (name, " \t"); |
---|
1838 | result = 1; |
---|
1839 | break; |
---|
1840 | case Xml : |
---|
1841 | cout << "<script>" << name << "</script>"; |
---|
1842 | result = 1; |
---|
1843 | break; |
---|
1844 | } |
---|
1845 | break; |
---|
1846 | default: |
---|
1847 | break; |
---|
1848 | } |
---|
1849 | } |
---|
1850 | |
---|
1851 | return (result); |
---|
1852 | } |
---|
1853 | |
---|
1854 | //------------------------------------------------------------- |
---|
1855 | cmt_string Symbol::build_macro_value (bool display_it) const |
---|
1856 | { |
---|
1857 | cmt_string temp; |
---|
1858 | |
---|
1859 | if (display_it) |
---|
1860 | { |
---|
1861 | temp = builder->build_and_display (*this); |
---|
1862 | } |
---|
1863 | else |
---|
1864 | { |
---|
1865 | temp = builder->build (*this); |
---|
1866 | } |
---|
1867 | |
---|
1868 | return (temp); |
---|
1869 | } |
---|
1870 | |
---|
1871 | //------------------------------------------------------------- |
---|
1872 | int Symbol::print_macro (PrintMode mode, ostream& out) const |
---|
1873 | { |
---|
1874 | if (mode != Requirements || printed) return 0; |
---|
1875 | return builder->print (*this, out); |
---|
1876 | } |
---|
1877 | |
---|
1878 | //------------------------------------------------------------- |
---|
1879 | cmt_string Symbol::clean_macro_value () const |
---|
1880 | { |
---|
1881 | cmt_string temp; |
---|
1882 | |
---|
1883 | temp = builder->clean (*this); |
---|
1884 | |
---|
1885 | return (temp); |
---|
1886 | } |
---|
1887 | |
---|
1888 | /** |
---|
1889 | |
---|
1890 | Attempt to substitute into the symbol value all occurrences of |
---|
1891 | |
---|
1892 | ${xxx} |
---|
1893 | $(xxx) |
---|
1894 | `xxx` |
---|
1895 | %xxx% [on Windows only] |
---|
1896 | |
---|
1897 | by the appropriate value: |
---|
1898 | |
---|
1899 | for `xxx` : |
---|
1900 | |
---|
1901 | xxx is considered as a shell command. Value is the result of its execution |
---|
1902 | |
---|
1903 | for other patterns: |
---|
1904 | |
---|
1905 | if xxx is a symbol name, its value is substituted to the pattern |
---|
1906 | otherwise, xxx is tried as an environment variable |
---|
1907 | |
---|
1908 | |
---|
1909 | ===> In all cases, the pattern is filtered away. |
---|
1910 | |
---|
1911 | */ |
---|
1912 | cmt_string Symbol::resolve_macro_value (const cmt_string& tag_name) const |
---|
1913 | { |
---|
1914 | cmt_string temp = builder->build (*this, tag_name); |
---|
1915 | |
---|
1916 | resolve_value (temp); |
---|
1917 | |
---|
1918 | return (temp); |
---|
1919 | } |
---|
1920 | |
---|
1921 | //------------------------------------------------------------- |
---|
1922 | void Symbol::show_macro (PrintMode mode, ostream& out) |
---|
1923 | //void Symbol::show_macro (PrintMode mode) |
---|
1924 | { |
---|
1925 | if (Cmt::get_debug ()) |
---|
1926 | { |
---|
1927 | cout << "Symbol::show_macro> " << name << endl; |
---|
1928 | } |
---|
1929 | |
---|
1930 | ActionType action = Cmt::get_action (); |
---|
1931 | |
---|
1932 | cmt_string value = build_macro_value (true); |
---|
1933 | |
---|
1934 | if ((!Cmt::get_quiet ()) && |
---|
1935 | (action != action_build_tag_makefile) && |
---|
1936 | (action != action_build_constituents_config) && |
---|
1937 | (action != action_build_constituent_config) && |
---|
1938 | (action != action_build_broadcast_config) && |
---|
1939 | (action != action_show_macros) && |
---|
1940 | (action != action_show_actions) && |
---|
1941 | (action != action_show_sets)) |
---|
1942 | { |
---|
1943 | out << "#" << endl; |
---|
1944 | out << "# Selection : " << endl; |
---|
1945 | } |
---|
1946 | |
---|
1947 | if (value.size () > 0) |
---|
1948 | { |
---|
1949 | if ((action == action_show_macro) || |
---|
1950 | (action == action_show_macros) || |
---|
1951 | (action == action_show_sets) || |
---|
1952 | (action == action_show_set) || |
---|
1953 | (action == action_show_actions) || |
---|
1954 | (action == action_show_action) || |
---|
1955 | (action == action_build_tag_makefile) || |
---|
1956 | (action == action_build_constituents_config) || |
---|
1957 | (action == action_build_constituent_config) || |
---|
1958 | (action == action_build_broadcast_config) || |
---|
1959 | (action == action_load) || |
---|
1960 | (!Cmt::get_quiet ())) |
---|
1961 | { |
---|
1962 | if (mode == Make) |
---|
1963 | { |
---|
1964 | out << name << "="; |
---|
1965 | } |
---|
1966 | else |
---|
1967 | { |
---|
1968 | out << name << "='"; |
---|
1969 | } |
---|
1970 | } |
---|
1971 | |
---|
1972 | if ((action == action_show_macro_value) || |
---|
1973 | (action == action_show_set_value) || |
---|
1974 | (action == action_show_action_value)) |
---|
1975 | { |
---|
1976 | expand (value); |
---|
1977 | } |
---|
1978 | else if (action == action_build_tag_makefile || |
---|
1979 | action == action_build_constituents_config || |
---|
1980 | action == action_build_constituent_config || |
---|
1981 | action == action_build_broadcast_config) |
---|
1982 | { |
---|
1983 | /* |
---|
1984 | Unfortunately, the %xxx% pattern has to be kept on Unix. Therefore |
---|
1985 | we cannot force all patterns to become $(xxx) |
---|
1986 | |
---|
1987 | This was useful on Windows so as to only keep $(xxx) |
---|
1988 | */ |
---|
1989 | #ifdef WIN32 |
---|
1990 | suppress_OS_delimiters (value); |
---|
1991 | #endif |
---|
1992 | } |
---|
1993 | |
---|
1994 | out << value; |
---|
1995 | |
---|
1996 | if ((action == action_show_macro) || |
---|
1997 | (action == action_show_macros) || |
---|
1998 | (action == action_show_sets) || |
---|
1999 | (action == action_show_set) || |
---|
2000 | (action == action_show_actions) || |
---|
2001 | (action == action_show_action) || |
---|
2002 | (action == action_build_tag_makefile) || |
---|
2003 | (action == action_build_constituents_config) || |
---|
2004 | (action == action_build_constituent_config) || |
---|
2005 | (action == action_build_broadcast_config) || |
---|
2006 | (action == action_load) || |
---|
2007 | (!Cmt::get_quiet ())) |
---|
2008 | { |
---|
2009 | if (mode != Make) |
---|
2010 | { |
---|
2011 | out << "'"; |
---|
2012 | } |
---|
2013 | #ifdef WIN32 |
---|
2014 | else |
---|
2015 | { |
---|
2016 | out << " "; |
---|
2017 | } |
---|
2018 | #endif |
---|
2019 | } |
---|
2020 | |
---|
2021 | out << endl; |
---|
2022 | } |
---|
2023 | } |
---|
2024 | |
---|
2025 | //------------------------------------------------------------- |
---|
2026 | void Symbol::clear_all () |
---|
2027 | { |
---|
2028 | static SymbolVector& Symbols = symbols (); |
---|
2029 | static SymbolMap& SymbolMap = symbol_map (); |
---|
2030 | |
---|
2031 | SymbolMap.clear (); |
---|
2032 | Symbols.clear (); |
---|
2033 | } |
---|
2034 | |
---|
2035 | //------------------------------------------------------------- |
---|
2036 | void Symbol::expand (cmt_string& text) |
---|
2037 | { |
---|
2038 | static cmt_regexp reg ("[$%`]"); |
---|
2039 | |
---|
2040 | if (!reg.match (text)) return; |
---|
2041 | |
---|
2042 | resolve_value (text); |
---|
2043 | } |
---|
2044 | |
---|
2045 | //------------------------------------------------------------- |
---|
2046 | ValueBuilder::ValueBuilder () |
---|
2047 | { |
---|
2048 | m_display_it = false; |
---|
2049 | } |
---|
2050 | |
---|
2051 | //------------------------------------------------------------- |
---|
2052 | const cmt_string ValueBuilder::build_and_display (const Symbol& symbol) |
---|
2053 | { |
---|
2054 | cmt_string temp; |
---|
2055 | |
---|
2056 | m_display_it = true; |
---|
2057 | temp = build (symbol); |
---|
2058 | m_display_it = false; |
---|
2059 | |
---|
2060 | return (temp); |
---|
2061 | } |
---|
2062 | |
---|
2063 | //------------------------------------------------------------- |
---|
2064 | int ValueBuilder::print (const Symbol& symbol, ostream& out) |
---|
2065 | { |
---|
2066 | int result (0); |
---|
2067 | |
---|
2068 | bool first_definition = true; |
---|
2069 | |
---|
2070 | for (int i = 0; i < symbol.value_lists.size (); i++) |
---|
2071 | { |
---|
2072 | const SymbolValueList& value_list = symbol.value_lists[i]; |
---|
2073 | |
---|
2074 | if ((value_list.use != 0) && |
---|
2075 | (value_list.use->discarded)) continue; |
---|
2076 | |
---|
2077 | const int selected = value_list.select_first (); |
---|
2078 | |
---|
2079 | if (selected < 0) continue; |
---|
2080 | |
---|
2081 | SymbolValue& value = value_list.values[selected]; |
---|
2082 | |
---|
2083 | result += value_list.print (symbol, value, first_definition); |
---|
2084 | } |
---|
2085 | |
---|
2086 | return result; |
---|
2087 | } |
---|
2088 | |
---|
2089 | //------------------------------------------------------------- |
---|
2090 | const cmt_string SetBuilder::build (const Symbol& symbol, |
---|
2091 | const cmt_string& /*tag_name*/) |
---|
2092 | { |
---|
2093 | // Control of recursivity |
---|
2094 | static int level = 0; |
---|
2095 | |
---|
2096 | bool show_it = false; |
---|
2097 | |
---|
2098 | cmt_string temp; |
---|
2099 | cmt_string previous_temp; |
---|
2100 | cmt_string new_value; |
---|
2101 | static const cmt_string empty; |
---|
2102 | |
---|
2103 | ActionType action = Cmt::get_action (); |
---|
2104 | |
---|
2105 | if (action == action_show_set) |
---|
2106 | { |
---|
2107 | if (symbol.name == Cmt::get_current_target ()) |
---|
2108 | { |
---|
2109 | // Should not display on recursive calls |
---|
2110 | if (level == 0) show_it = m_display_it; |
---|
2111 | } |
---|
2112 | } |
---|
2113 | |
---|
2114 | level++; |
---|
2115 | |
---|
2116 | temp = ""; |
---|
2117 | |
---|
2118 | bool first_definition = true; |
---|
2119 | |
---|
2120 | for (int i = 0; i < symbol.value_lists.size (); i++) |
---|
2121 | { |
---|
2122 | const SymbolValueList& value_list = symbol.value_lists[i]; |
---|
2123 | |
---|
2124 | if ((value_list.use != 0) && |
---|
2125 | (value_list.use->discarded)) continue; |
---|
2126 | |
---|
2127 | const int selected = value_list.select_first (); |
---|
2128 | |
---|
2129 | if (selected < 0) continue; |
---|
2130 | |
---|
2131 | SymbolValue& value = value_list.values[selected]; |
---|
2132 | |
---|
2133 | if (show_it && !Symbol::get_inhibit_display()) |
---|
2134 | { |
---|
2135 | value_list.show (symbol, value, first_definition); |
---|
2136 | } |
---|
2137 | |
---|
2138 | if (value_list.discarded) continue; |
---|
2139 | |
---|
2140 | // |
---|
2141 | // One should accumulate values if it refers to |
---|
2142 | // itself. |
---|
2143 | // |
---|
2144 | |
---|
2145 | new_value = value.text; |
---|
2146 | |
---|
2147 | resolve_value_for_macros (new_value); |
---|
2148 | |
---|
2149 | switch (value_list.command_type) |
---|
2150 | { |
---|
2151 | case CommandSet : |
---|
2152 | |
---|
2153 | if (!value_list.is_reflexive || |
---|
2154 | !symbol.value_is_reflexive (value.text)) |
---|
2155 | { |
---|
2156 | resolve_value (new_value, symbol.name, temp); |
---|
2157 | temp = new_value; |
---|
2158 | } |
---|
2159 | else if (temp == "") |
---|
2160 | { |
---|
2161 | temp = CmtSystem::getenv (symbol.name); |
---|
2162 | } |
---|
2163 | |
---|
2164 | break; |
---|
2165 | case CommandSetAppend : |
---|
2166 | |
---|
2167 | if (new_value != "") |
---|
2168 | { |
---|
2169 | temp += new_value; |
---|
2170 | } |
---|
2171 | |
---|
2172 | break; |
---|
2173 | case CommandSetPrepend : |
---|
2174 | |
---|
2175 | if (new_value != "") |
---|
2176 | { |
---|
2177 | previous_temp = temp; |
---|
2178 | temp = new_value; |
---|
2179 | temp += previous_temp; |
---|
2180 | } |
---|
2181 | |
---|
2182 | break; |
---|
2183 | case CommandSetRemove : |
---|
2184 | |
---|
2185 | if (new_value != "") |
---|
2186 | { |
---|
2187 | temp.replace_all (new_value, empty); |
---|
2188 | } |
---|
2189 | |
---|
2190 | break; |
---|
2191 | case CommandSetRemoveRegexp : |
---|
2192 | |
---|
2193 | if (new_value != "") |
---|
2194 | { |
---|
2195 | cmt_regexp e (new_value); |
---|
2196 | cmt_regexp::iterator it; |
---|
2197 | |
---|
2198 | for (;;) |
---|
2199 | { |
---|
2200 | it = e.begin (temp); |
---|
2201 | if (it == e.end ()) break; |
---|
2202 | |
---|
2203 | temp.erase (it._pos, it._length); |
---|
2204 | } |
---|
2205 | } |
---|
2206 | |
---|
2207 | break; |
---|
2208 | case CommandAlias : |
---|
2209 | |
---|
2210 | resolve_value (new_value, symbol.name, temp); |
---|
2211 | temp = new_value; |
---|
2212 | |
---|
2213 | break; |
---|
2214 | } |
---|
2215 | } |
---|
2216 | |
---|
2217 | level--; |
---|
2218 | |
---|
2219 | return (temp); |
---|
2220 | } |
---|
2221 | |
---|
2222 | static bool find_path_entry (const cmt_string& paths, const cmt_string& value) |
---|
2223 | { |
---|
2224 | static const cmt_string path_separator = CmtSystem::path_separator (); |
---|
2225 | |
---|
2226 | cmt_string here = CmtSystem::pwd (); |
---|
2227 | cmt_string rvalue = value; |
---|
2228 | |
---|
2229 | if (CmtSystem::cd (value)) |
---|
2230 | { |
---|
2231 | rvalue = CmtSystem::pwd (); |
---|
2232 | } |
---|
2233 | else |
---|
2234 | { |
---|
2235 | CmtSystem::compress_path (rvalue); |
---|
2236 | } |
---|
2237 | |
---|
2238 | CmtSystem::cmt_string_vector items; |
---|
2239 | CmtSystem::split (paths, path_separator, items); |
---|
2240 | |
---|
2241 | bool found = false; |
---|
2242 | |
---|
2243 | for (int i = 0; i < items.size (); i++) |
---|
2244 | { |
---|
2245 | const cmt_string& item = items[i]; |
---|
2246 | cmt_string ritem = item; |
---|
2247 | if (CmtSystem::cd (item)) |
---|
2248 | { |
---|
2249 | ritem = CmtSystem::pwd (); |
---|
2250 | } |
---|
2251 | else |
---|
2252 | { |
---|
2253 | CmtSystem::compress_path (ritem); |
---|
2254 | } |
---|
2255 | |
---|
2256 | if (ritem == rvalue) |
---|
2257 | { |
---|
2258 | found = true; |
---|
2259 | break; |
---|
2260 | } |
---|
2261 | } |
---|
2262 | |
---|
2263 | CmtSystem::cd (here); |
---|
2264 | return (found); |
---|
2265 | } |
---|
2266 | |
---|
2267 | //------------------------------------------------------------- |
---|
2268 | const cmt_string PathBuilder::build (const Symbol& symbol, |
---|
2269 | const cmt_string& /*tag_name*/) |
---|
2270 | { |
---|
2271 | // Control of recursivity |
---|
2272 | static int level = 0; |
---|
2273 | |
---|
2274 | bool show_it = false; |
---|
2275 | |
---|
2276 | cmt_string temp; |
---|
2277 | cmt_string previous_temp; |
---|
2278 | cmt_string new_value; |
---|
2279 | static const cmt_string empty; |
---|
2280 | |
---|
2281 | static cmt_string path_separator = CmtSystem::path_separator (); |
---|
2282 | |
---|
2283 | ActionType action = Cmt::get_action (); |
---|
2284 | |
---|
2285 | if (action == action_show_set) |
---|
2286 | { |
---|
2287 | if (symbol.name == Cmt::get_current_target ()) |
---|
2288 | { |
---|
2289 | // Should not display on recursive calls |
---|
2290 | if (level == 0) show_it = m_display_it; |
---|
2291 | } |
---|
2292 | } |
---|
2293 | |
---|
2294 | level++; |
---|
2295 | |
---|
2296 | temp = CmtSystem::getenv (symbol.name); |
---|
2297 | |
---|
2298 | bool first_definition = true; |
---|
2299 | |
---|
2300 | for (int i = 0; i < symbol.value_lists.size (); i++) |
---|
2301 | { |
---|
2302 | const SymbolValueList& value_list = symbol.value_lists[i]; |
---|
2303 | |
---|
2304 | if ((value_list.use != 0) && |
---|
2305 | (value_list.use->discarded)) continue; |
---|
2306 | |
---|
2307 | const int selected = value_list.select_first (); |
---|
2308 | |
---|
2309 | if (selected < 0) continue; |
---|
2310 | |
---|
2311 | SymbolValue& value = value_list.values[selected]; |
---|
2312 | |
---|
2313 | if (show_it && !Symbol::get_inhibit_display()) |
---|
2314 | { |
---|
2315 | value_list.show (symbol, value, first_definition); |
---|
2316 | } |
---|
2317 | |
---|
2318 | if (value_list.discarded) continue; |
---|
2319 | |
---|
2320 | new_value = value.text; |
---|
2321 | |
---|
2322 | //resolve_value (new_value); |
---|
2323 | resolve_value_for_macros (new_value); |
---|
2324 | |
---|
2325 | switch (value_list.command_type) |
---|
2326 | { |
---|
2327 | case CommandPath : |
---|
2328 | |
---|
2329 | if (!value_list.is_reflexive || |
---|
2330 | !symbol.value_is_reflexive (value.text)) |
---|
2331 | { |
---|
2332 | resolve_value (new_value, symbol.name, temp); |
---|
2333 | temp = new_value; |
---|
2334 | } |
---|
2335 | |
---|
2336 | break; |
---|
2337 | case CommandPathAppend : |
---|
2338 | |
---|
2339 | if (new_value != "") |
---|
2340 | { |
---|
2341 | if (!find_path_entry (temp, new_value)) |
---|
2342 | { |
---|
2343 | if (temp != "") temp += path_separator; |
---|
2344 | |
---|
2345 | temp += new_value; |
---|
2346 | } |
---|
2347 | } |
---|
2348 | |
---|
2349 | break; |
---|
2350 | case CommandPathPrepend : |
---|
2351 | |
---|
2352 | if (new_value != "") |
---|
2353 | { |
---|
2354 | if (!find_path_entry (temp, new_value)) |
---|
2355 | { |
---|
2356 | previous_temp = temp; |
---|
2357 | temp = new_value; |
---|
2358 | if (previous_temp != "") temp += path_separator; |
---|
2359 | temp += previous_temp; |
---|
2360 | } |
---|
2361 | } |
---|
2362 | |
---|
2363 | break; |
---|
2364 | case CommandPathRemove : |
---|
2365 | |
---|
2366 | if (new_value != "") |
---|
2367 | { |
---|
2368 | CmtSystem::cmt_string_vector paths; |
---|
2369 | |
---|
2370 | CmtSystem::split (temp, path_separator, paths); |
---|
2371 | |
---|
2372 | for (int j = 0; j < paths.size (); ++j) |
---|
2373 | { |
---|
2374 | cmt_string& s = paths[j]; |
---|
2375 | |
---|
2376 | if (s.find (new_value) != cmt_string::npos) |
---|
2377 | { |
---|
2378 | s = ""; |
---|
2379 | } |
---|
2380 | } |
---|
2381 | |
---|
2382 | Cmt::vector_to_string (paths, path_separator, temp); |
---|
2383 | } |
---|
2384 | |
---|
2385 | break; |
---|
2386 | case CommandPathRemoveRegexp : |
---|
2387 | |
---|
2388 | if (new_value != "") |
---|
2389 | { |
---|
2390 | cmt_regexp e (new_value); |
---|
2391 | |
---|
2392 | CmtSystem::cmt_string_vector paths; |
---|
2393 | |
---|
2394 | CmtSystem::split (temp, path_separator, paths); |
---|
2395 | |
---|
2396 | for (int j = 0; j < paths.size (); ++j) |
---|
2397 | { |
---|
2398 | cmt_string& s = paths[j]; |
---|
2399 | |
---|
2400 | if (CmtSystem::getenv ("TESTPRR") != "") |
---|
2401 | { |
---|
2402 | cerr << "PRR> s=[" << s << "]"; |
---|
2403 | } |
---|
2404 | |
---|
2405 | if (e.match (s)) |
---|
2406 | { |
---|
2407 | s = ""; |
---|
2408 | |
---|
2409 | if (CmtSystem::getenv ("TESTPRR") != "") |
---|
2410 | { |
---|
2411 | cerr << " match "; |
---|
2412 | } |
---|
2413 | } |
---|
2414 | else |
---|
2415 | { |
---|
2416 | if (CmtSystem::getenv ("TESTPRR") != "") |
---|
2417 | { |
---|
2418 | cerr << " no match "; |
---|
2419 | } |
---|
2420 | } |
---|
2421 | |
---|
2422 | if (CmtSystem::getenv ("TESTPRR") != "") |
---|
2423 | { |
---|
2424 | cerr << endl; |
---|
2425 | } |
---|
2426 | } |
---|
2427 | |
---|
2428 | Cmt::vector_to_string (paths, path_separator, temp); |
---|
2429 | } |
---|
2430 | |
---|
2431 | break; |
---|
2432 | } |
---|
2433 | |
---|
2434 | } |
---|
2435 | |
---|
2436 | level--; |
---|
2437 | |
---|
2438 | for (;;) |
---|
2439 | { |
---|
2440 | int sz = temp.size (); |
---|
2441 | |
---|
2442 | if (sz == 0) break; |
---|
2443 | |
---|
2444 | if ((temp[0] == ';') || (temp[0] == ':')) |
---|
2445 | { |
---|
2446 | temp.erase (0, 1); |
---|
2447 | } |
---|
2448 | else if ((temp[sz-1] == ';') || (temp[sz-1] == ':')) |
---|
2449 | { |
---|
2450 | temp.erase (sz-1, 1); |
---|
2451 | } |
---|
2452 | else |
---|
2453 | { |
---|
2454 | break; |
---|
2455 | } |
---|
2456 | } |
---|
2457 | |
---|
2458 | temp.replace_all ("::", ":"); |
---|
2459 | temp.replace_all (";;", ";"); |
---|
2460 | |
---|
2461 | return (temp); |
---|
2462 | } |
---|
2463 | |
---|
2464 | //------------------------------------------------------------- |
---|
2465 | const cmt_string PathBuilder::clean (const Symbol& symbol, |
---|
2466 | const cmt_string& /*tag_name*/) |
---|
2467 | { |
---|
2468 | // Control of recursivity |
---|
2469 | static int level = 0; |
---|
2470 | |
---|
2471 | cmt_string temp; |
---|
2472 | cmt_string new_value; |
---|
2473 | static const cmt_string empty; |
---|
2474 | |
---|
2475 | static cmt_string path_separator = CmtSystem::path_separator (); |
---|
2476 | |
---|
2477 | temp = CmtSystem::getenv (symbol.name); |
---|
2478 | |
---|
2479 | //cerr << "#####1 temp=" << temp << endl; |
---|
2480 | |
---|
2481 | for (int i = 0; i < symbol.value_lists.size (); i++) |
---|
2482 | { |
---|
2483 | const SymbolValueList& value_list = symbol.value_lists[i]; |
---|
2484 | |
---|
2485 | if (value_list.discarded) continue; |
---|
2486 | |
---|
2487 | if ((value_list.use != 0) && |
---|
2488 | (value_list.use->discarded)) continue; |
---|
2489 | |
---|
2490 | const int selected = value_list.select_first (); |
---|
2491 | |
---|
2492 | if (selected < 0) continue; |
---|
2493 | |
---|
2494 | SymbolValue& value = value_list.values[selected]; |
---|
2495 | |
---|
2496 | new_value = value.text; |
---|
2497 | |
---|
2498 | //resolve_value (new_value); |
---|
2499 | |
---|
2500 | //cerr << "#####1 new_value=" << new_value << endl; |
---|
2501 | |
---|
2502 | resolve_value_for_macros (new_value); |
---|
2503 | resolve_value (new_value); |
---|
2504 | |
---|
2505 | //cerr << "#####2 new_value=" << new_value << endl; |
---|
2506 | |
---|
2507 | switch (value_list.command_type) |
---|
2508 | { |
---|
2509 | case CommandPath : |
---|
2510 | |
---|
2511 | temp = ""; |
---|
2512 | |
---|
2513 | break; |
---|
2514 | case CommandPathAppend : |
---|
2515 | case CommandPathPrepend : |
---|
2516 | case CommandPathRemove : |
---|
2517 | |
---|
2518 | if (new_value != "") |
---|
2519 | { |
---|
2520 | CmtSystem::cmt_string_vector paths; |
---|
2521 | |
---|
2522 | CmtSystem::split (temp, path_separator, paths); |
---|
2523 | |
---|
2524 | for (int j = 0; j < paths.size (); ++j) |
---|
2525 | { |
---|
2526 | cmt_string& s = paths[j]; |
---|
2527 | |
---|
2528 | if (s.find (new_value) != cmt_string::npos) |
---|
2529 | { |
---|
2530 | s = ""; |
---|
2531 | } |
---|
2532 | |
---|
2533 | if (j > 0) |
---|
2534 | { |
---|
2535 | cmt_string& s2 = paths[j-1]; |
---|
2536 | if (s2 == s) |
---|
2537 | { |
---|
2538 | s2 = ""; |
---|
2539 | } |
---|
2540 | } |
---|
2541 | } |
---|
2542 | |
---|
2543 | Cmt::vector_to_string (paths, path_separator, temp); |
---|
2544 | temp.replace_all ("::", ":"); |
---|
2545 | temp.replace_all (";;", ";"); |
---|
2546 | } |
---|
2547 | |
---|
2548 | break; |
---|
2549 | case CommandPathRemoveRegexp : |
---|
2550 | |
---|
2551 | if (new_value != "") |
---|
2552 | { |
---|
2553 | cmt_regexp e (new_value); |
---|
2554 | |
---|
2555 | CmtSystem::cmt_string_vector paths; |
---|
2556 | |
---|
2557 | CmtSystem::split (temp, path_separator, paths); |
---|
2558 | |
---|
2559 | for (int j = 0; j < paths.size (); ++j) |
---|
2560 | { |
---|
2561 | cmt_string& s = paths[j]; |
---|
2562 | |
---|
2563 | if (e.match (s)) |
---|
2564 | { |
---|
2565 | s = ""; |
---|
2566 | } |
---|
2567 | |
---|
2568 | if (j > 0) |
---|
2569 | { |
---|
2570 | cmt_string& s2 = paths[j-1]; |
---|
2571 | if (s2 == s) |
---|
2572 | { |
---|
2573 | s2 = ""; |
---|
2574 | } |
---|
2575 | } |
---|
2576 | } |
---|
2577 | |
---|
2578 | Cmt::vector_to_string (paths, path_separator, temp); |
---|
2579 | temp.replace_all ("::", ":"); |
---|
2580 | temp.replace_all (";;", ";"); |
---|
2581 | } |
---|
2582 | |
---|
2583 | break; |
---|
2584 | } |
---|
2585 | } |
---|
2586 | |
---|
2587 | //cerr << "#####2 temp=" << temp << endl; |
---|
2588 | |
---|
2589 | return (temp); |
---|
2590 | } |
---|
2591 | |
---|
2592 | //------------------------------------------------------------- |
---|
2593 | const cmt_string MacroBuilder::build (const Symbol& symbol, |
---|
2594 | const cmt_string& tag_name) |
---|
2595 | { |
---|
2596 | // Control of recursivity |
---|
2597 | static int level = 0; |
---|
2598 | |
---|
2599 | cmt_string temp; |
---|
2600 | cmt_string previous_temp; |
---|
2601 | static const cmt_string empty; |
---|
2602 | bool show_it = false; |
---|
2603 | |
---|
2604 | ActionType action = Cmt::get_action (); |
---|
2605 | |
---|
2606 | if (action == action_show_macro) |
---|
2607 | { |
---|
2608 | if (symbol.name == Cmt::get_current_target ()) |
---|
2609 | { |
---|
2610 | // Should not display on recursive calls |
---|
2611 | if (level == 0) show_it = m_display_it; |
---|
2612 | } |
---|
2613 | } |
---|
2614 | |
---|
2615 | level++; |
---|
2616 | |
---|
2617 | temp = ""; |
---|
2618 | |
---|
2619 | int i; |
---|
2620 | |
---|
2621 | bool first_definition = true; |
---|
2622 | |
---|
2623 | for (i = 0; i < symbol.value_lists.size (); i++) |
---|
2624 | { |
---|
2625 | const SymbolValueList& value_list = symbol.value_lists[i]; |
---|
2626 | |
---|
2627 | if ((value_list.use != 0) && |
---|
2628 | (value_list.use->discarded)) continue; |
---|
2629 | |
---|
2630 | if (value_list.command_type != CommandMacroPrepend) continue; |
---|
2631 | |
---|
2632 | const int selected = value_list.select_first (tag_name); |
---|
2633 | |
---|
2634 | if (selected < 0) continue; |
---|
2635 | |
---|
2636 | SymbolValue& value = value_list.values[selected]; |
---|
2637 | |
---|
2638 | if (show_it && !Symbol::get_inhibit_display()) |
---|
2639 | { |
---|
2640 | value_list.show (symbol, value, first_definition); |
---|
2641 | } |
---|
2642 | |
---|
2643 | if (value_list.discarded) continue; |
---|
2644 | |
---|
2645 | previous_temp = temp; |
---|
2646 | temp = value.text; |
---|
2647 | temp += previous_temp; |
---|
2648 | } |
---|
2649 | |
---|
2650 | previous_temp = temp; |
---|
2651 | temp = ""; |
---|
2652 | |
---|
2653 | first_definition = true; |
---|
2654 | |
---|
2655 | for (i = 0; i < symbol.value_lists.size (); i++) |
---|
2656 | { |
---|
2657 | const SymbolValueList& value_list = symbol.value_lists[i]; |
---|
2658 | |
---|
2659 | if ((value_list.use != 0) && |
---|
2660 | (value_list.use->discarded)) continue; |
---|
2661 | |
---|
2662 | if (value_list.command_type != CommandMacro) continue; |
---|
2663 | |
---|
2664 | const int selected = value_list.select_first (tag_name); |
---|
2665 | |
---|
2666 | if (selected < 0) continue; |
---|
2667 | |
---|
2668 | SymbolValue& value = value_list.values[selected]; |
---|
2669 | |
---|
2670 | if (show_it && !Symbol::get_inhibit_display()) |
---|
2671 | { |
---|
2672 | value_list.show (symbol, value, first_definition); |
---|
2673 | } |
---|
2674 | |
---|
2675 | // WARNING: |
---|
2676 | // Commented just for a test : should be uncommented after the test |
---|
2677 | if (value_list.discarded) continue; |
---|
2678 | |
---|
2679 | if (!value_list.is_reflexive || |
---|
2680 | !symbol.value_is_reflexive (value.text)) |
---|
2681 | { |
---|
2682 | temp = value.text; |
---|
2683 | } |
---|
2684 | } |
---|
2685 | |
---|
2686 | previous_temp += temp; |
---|
2687 | temp = previous_temp; |
---|
2688 | |
---|
2689 | for (i = 0; i < symbol.value_lists.size (); i++) |
---|
2690 | { |
---|
2691 | const SymbolValueList& value_list = symbol.value_lists[i]; |
---|
2692 | |
---|
2693 | if ((value_list.use != 0) && |
---|
2694 | (value_list.use->discarded)) continue; |
---|
2695 | |
---|
2696 | if (value_list.command_type != CommandMacroAppend) continue; |
---|
2697 | |
---|
2698 | const int selected = value_list.select_first (tag_name); |
---|
2699 | |
---|
2700 | if (selected < 0) continue; |
---|
2701 | |
---|
2702 | SymbolValue& value = value_list.values[selected]; |
---|
2703 | |
---|
2704 | if (show_it && !Symbol::get_inhibit_display()) |
---|
2705 | { |
---|
2706 | value_list.show (symbol, value, first_definition); |
---|
2707 | } |
---|
2708 | |
---|
2709 | if (value_list.discarded) continue; |
---|
2710 | |
---|
2711 | temp += value.text; |
---|
2712 | } |
---|
2713 | |
---|
2714 | for (i = 0; i < symbol.value_lists.size (); i++) |
---|
2715 | { |
---|
2716 | const SymbolValueList& value_list = symbol.value_lists[i]; |
---|
2717 | |
---|
2718 | if ((value_list.use != 0) && |
---|
2719 | (value_list.use->discarded)) continue; |
---|
2720 | |
---|
2721 | if ((value_list.command_type != CommandMacroRemove) && |
---|
2722 | (value_list.command_type != CommandMacroRemoveRegexp) && |
---|
2723 | (value_list.command_type != CommandMacroRemoveAll) && |
---|
2724 | (value_list.command_type != CommandMacroRemoveAllRegexp)) continue; |
---|
2725 | |
---|
2726 | const int selected = value_list.select_first (tag_name); |
---|
2727 | |
---|
2728 | if (selected < 0) continue; |
---|
2729 | |
---|
2730 | SymbolValue& value = value_list.values[selected]; |
---|
2731 | |
---|
2732 | if (show_it && !Symbol::get_inhibit_display()) |
---|
2733 | { |
---|
2734 | value_list.show (symbol, value, first_definition); |
---|
2735 | } |
---|
2736 | |
---|
2737 | if (value_list.discarded) continue; |
---|
2738 | |
---|
2739 | switch (value_list.command_type) |
---|
2740 | { |
---|
2741 | case CommandMacroRemove : |
---|
2742 | temp.replace (value.text, empty); |
---|
2743 | break; |
---|
2744 | case CommandMacroRemoveRegexp : |
---|
2745 | if (value.text != "") |
---|
2746 | { |
---|
2747 | cmt_regexp e (value.text); |
---|
2748 | cmt_regexp::iterator it; |
---|
2749 | |
---|
2750 | it = e.begin (temp); |
---|
2751 | if (it != e.end ()) |
---|
2752 | { |
---|
2753 | temp.erase (it._pos, it._length); |
---|
2754 | } |
---|
2755 | } |
---|
2756 | break; |
---|
2757 | case CommandMacroRemoveAll : |
---|
2758 | temp.replace_all (value.text, empty); |
---|
2759 | break; |
---|
2760 | case CommandMacroRemoveAllRegexp : |
---|
2761 | if (value.text != "") |
---|
2762 | { |
---|
2763 | cmt_regexp e (value.text); |
---|
2764 | cmt_regexp::iterator it; |
---|
2765 | |
---|
2766 | for (;;) |
---|
2767 | { |
---|
2768 | it = e.begin (temp); |
---|
2769 | if (it != e.end ()) |
---|
2770 | { |
---|
2771 | temp.erase (it._pos, it._length); |
---|
2772 | } |
---|
2773 | else |
---|
2774 | { |
---|
2775 | break; |
---|
2776 | } |
---|
2777 | } |
---|
2778 | } |
---|
2779 | break; |
---|
2780 | } |
---|
2781 | } |
---|
2782 | |
---|
2783 | level--; |
---|
2784 | |
---|
2785 | return (temp); |
---|
2786 | } |
---|
2787 | |
---|
2788 | //------------------------------------------------------------- |
---|
2789 | const cmt_string ScriptBuilder::build (const Symbol& symbol, |
---|
2790 | const cmt_string& tag_name) |
---|
2791 | { |
---|
2792 | // Control of recursivity |
---|
2793 | static int level = 0; |
---|
2794 | |
---|
2795 | static const cmt_string empty = ""; |
---|
2796 | |
---|
2797 | if (symbol.value_lists.size () > 0) |
---|
2798 | { |
---|
2799 | const SymbolValueList& value_list = symbol.value_lists[0]; |
---|
2800 | |
---|
2801 | if (value_list.discarded) return (empty); |
---|
2802 | |
---|
2803 | if ((value_list.use != 0) && |
---|
2804 | (value_list.use->discarded)) return (empty); |
---|
2805 | } |
---|
2806 | |
---|
2807 | return (symbol.name); |
---|
2808 | } |
---|
2809 | |
---|
2810 | //------------------------------------------------------------- |
---|
2811 | const cmt_string ActionBuilder::build (const Symbol& symbol, |
---|
2812 | const cmt_string& tag_name) |
---|
2813 | { |
---|
2814 | // Control of recursivity |
---|
2815 | static int level = 0; |
---|
2816 | |
---|
2817 | cmt_string temp; |
---|
2818 | cmt_string previous_temp; |
---|
2819 | static const cmt_string empty; |
---|
2820 | bool show_it = false; |
---|
2821 | |
---|
2822 | ActionType action = Cmt::get_action (); |
---|
2823 | |
---|
2824 | if (action == action_show_action) |
---|
2825 | { |
---|
2826 | if (symbol.name == Cmt::get_current_target ()) |
---|
2827 | { |
---|
2828 | // Should not display on recursive calls |
---|
2829 | if (level == 0) show_it = m_display_it; |
---|
2830 | } |
---|
2831 | } |
---|
2832 | |
---|
2833 | level++; |
---|
2834 | |
---|
2835 | int i; |
---|
2836 | |
---|
2837 | bool first_definition = true; |
---|
2838 | |
---|
2839 | temp = ""; |
---|
2840 | |
---|
2841 | for (i = 0; i < symbol.value_lists.size (); i++) |
---|
2842 | { |
---|
2843 | const SymbolValueList& value_list = symbol.value_lists[i]; |
---|
2844 | |
---|
2845 | if ((value_list.use != 0) && |
---|
2846 | (value_list.use->discarded)) continue; |
---|
2847 | |
---|
2848 | if (value_list.command_type != CommandAction) continue; |
---|
2849 | |
---|
2850 | const int selected = value_list.select_first (tag_name); |
---|
2851 | |
---|
2852 | if (selected < 0) continue; |
---|
2853 | |
---|
2854 | SymbolValue& value = value_list.values[selected]; |
---|
2855 | |
---|
2856 | if (show_it && !Symbol::get_inhibit_display()) |
---|
2857 | { |
---|
2858 | value_list.show (symbol, value, first_definition); |
---|
2859 | } |
---|
2860 | |
---|
2861 | // WARNING: |
---|
2862 | // Commented just for a test : should be uncommented after the test |
---|
2863 | if (value_list.discarded) continue; |
---|
2864 | |
---|
2865 | if (!value_list.is_reflexive || |
---|
2866 | !symbol.value_is_reflexive (value.text)) |
---|
2867 | { |
---|
2868 | temp = value.text; |
---|
2869 | } |
---|
2870 | } |
---|
2871 | |
---|
2872 | level--; |
---|
2873 | |
---|
2874 | return (temp); |
---|
2875 | } |
---|
2876 | |
---|
2877 | //------------------------------------------------------------- |
---|
2878 | int SymbolValueList::select_first (const cmt_string& tag_name) const |
---|
2879 | { |
---|
2880 | int priority = 0; |
---|
2881 | int value_number; |
---|
2882 | int selected = -1; |
---|
2883 | |
---|
2884 | Tag* the_tag = 0; |
---|
2885 | |
---|
2886 | if (tag_name != "") the_tag = Tag::find (tag_name); |
---|
2887 | |
---|
2888 | for (value_number = 0; |
---|
2889 | value_number < values.size (); |
---|
2890 | value_number++) |
---|
2891 | { |
---|
2892 | const SymbolValue& value = values[value_number]; |
---|
2893 | |
---|
2894 | const Tag* tag = value.tag; |
---|
2895 | |
---|
2896 | if (the_tag == 0) |
---|
2897 | { |
---|
2898 | if (!tag->is_selected ()) continue; |
---|
2899 | selected = value_number; |
---|
2900 | if (tag == Tag::get_default ()) |
---|
2901 | continue; |
---|
2902 | } |
---|
2903 | else |
---|
2904 | { |
---|
2905 | if (tag != the_tag) continue; |
---|
2906 | selected = value_number; |
---|
2907 | } |
---|
2908 | |
---|
2909 | // |
---|
2910 | // Only the value for the first alternative (i.e. non-default) |
---|
2911 | // matching tag expression is |
---|
2912 | // selected (which means the selection stops here) |
---|
2913 | // |
---|
2914 | break; |
---|
2915 | |
---|
2916 | // |
---|
2917 | // Only the first value at a given priority is |
---|
2918 | // selected (which implies the '>' test instead |
---|
2919 | // of '>=') |
---|
2920 | // |
---|
2921 | /* |
---|
2922 | if (tag->get_priority () > priority) |
---|
2923 | { |
---|
2924 | priority = tag->get_priority (); |
---|
2925 | selected = value_number; |
---|
2926 | } |
---|
2927 | */ |
---|
2928 | } |
---|
2929 | |
---|
2930 | return (selected); |
---|
2931 | } |
---|
2932 | |
---|
2933 | //------------------------------------------------------------- |
---|
2934 | int SymbolValueList::select_last () const |
---|
2935 | { |
---|
2936 | int priority = 0; |
---|
2937 | int value_number; |
---|
2938 | int selected = -1; |
---|
2939 | |
---|
2940 | for (value_number = 0; |
---|
2941 | value_number < values.size (); |
---|
2942 | value_number++) |
---|
2943 | { |
---|
2944 | SymbolValue& value = values[value_number]; |
---|
2945 | |
---|
2946 | const Tag* tag = value.tag; |
---|
2947 | |
---|
2948 | if (tag->is_selected ()) |
---|
2949 | { |
---|
2950 | // |
---|
2951 | // The last value at a given priority is |
---|
2952 | // selected (which implies the '>=' test instead |
---|
2953 | // of '>') |
---|
2954 | // |
---|
2955 | |
---|
2956 | if (tag->get_priority () >= priority) |
---|
2957 | { |
---|
2958 | priority = tag->get_priority (); |
---|
2959 | selected = value_number; |
---|
2960 | } |
---|
2961 | } |
---|
2962 | } |
---|
2963 | |
---|
2964 | return (selected); |
---|
2965 | } |
---|
2966 | |
---|
2967 | //------------------------------------------------------------- |
---|
2968 | void SymbolValueList::show (const Symbol& symbol, |
---|
2969 | const SymbolValue& value, |
---|
2970 | bool& first_definition) const |
---|
2971 | { |
---|
2972 | cmt_string discarded_text; |
---|
2973 | cmt_string define_text; |
---|
2974 | ActionType action = Cmt::get_action (); |
---|
2975 | |
---|
2976 | switch (command_type) |
---|
2977 | { |
---|
2978 | //case CommandSet : |
---|
2979 | case CommandSetAppend : |
---|
2980 | case CommandSetPrepend : |
---|
2981 | case CommandSetRemove : |
---|
2982 | case CommandSetRemoveRegexp : |
---|
2983 | //case CommandAlias : |
---|
2984 | //case CommandPath : |
---|
2985 | case CommandPathAppend : |
---|
2986 | case CommandPathPrepend : |
---|
2987 | case CommandPathRemove : |
---|
2988 | case CommandPathRemoveRegexp : |
---|
2989 | case CommandMacroPrepend : |
---|
2990 | //case CommandMacro : |
---|
2991 | case CommandMacroAppend : |
---|
2992 | case CommandMacroRemove : |
---|
2993 | case CommandMacroRemoveRegexp : |
---|
2994 | case CommandMacroRemoveAll : |
---|
2995 | case CommandMacroRemoveAllRegexp : |
---|
2996 | //case CommandAction : |
---|
2997 | if (value.text == "") return; |
---|
2998 | break; |
---|
2999 | } |
---|
3000 | |
---|
3001 | if (discarded) discarded_text = " (discarded by override)"; |
---|
3002 | else discarded_text = ""; |
---|
3003 | |
---|
3004 | if (first_definition) define_text = "defines"; |
---|
3005 | else define_text = "overrides"; |
---|
3006 | |
---|
3007 | cout << "# Package "; |
---|
3008 | if (use != 0) |
---|
3009 | { |
---|
3010 | cout << use->get_package_name () << " " << use->version; |
---|
3011 | } |
---|
3012 | |
---|
3013 | switch (command_type) |
---|
3014 | { |
---|
3015 | case CommandSet : |
---|
3016 | cout << " " << define_text << " set " << symbol.name << " as "; |
---|
3017 | first_definition = false; |
---|
3018 | break; |
---|
3019 | case CommandSetAppend : |
---|
3020 | cout << " appends to set " << symbol.name << " : "; |
---|
3021 | break; |
---|
3022 | case CommandSetPrepend : |
---|
3023 | cout << " prepends to set " << symbol.name << " : "; |
---|
3024 | break; |
---|
3025 | case CommandSetRemove : |
---|
3026 | cout << " removes from set " << symbol.name << " : "; |
---|
3027 | break; |
---|
3028 | case CommandSetRemoveRegexp : |
---|
3029 | cout << " removes RE from set " << symbol.name << " : "; |
---|
3030 | break; |
---|
3031 | case CommandAlias : |
---|
3032 | cout << " " << define_text << " alias " << symbol.name << " as "; |
---|
3033 | first_definition = false; |
---|
3034 | break; |
---|
3035 | case CommandPath : |
---|
3036 | cout << " " << define_text << " path " << symbol.name << " as "; |
---|
3037 | first_definition = false; |
---|
3038 | break; |
---|
3039 | case CommandPathAppend : |
---|
3040 | cout << " appends to path " << symbol.name << " : "; |
---|
3041 | break; |
---|
3042 | case CommandPathPrepend : |
---|
3043 | cout << " prepends to path " << symbol.name << " : "; |
---|
3044 | break; |
---|
3045 | case CommandPathRemove : |
---|
3046 | cout << " removes from path " << symbol.name << " : "; |
---|
3047 | break; |
---|
3048 | case CommandPathRemoveRegexp : |
---|
3049 | cout << " removes RE from path " << symbol.name << " : "; |
---|
3050 | break; |
---|
3051 | case CommandMacroPrepend : |
---|
3052 | cout << " prepends to macro " << symbol.name << " : "; |
---|
3053 | break; |
---|
3054 | case CommandMacro : |
---|
3055 | cout << " " << define_text << " macro " << symbol.name << " as "; |
---|
3056 | break; |
---|
3057 | case CommandMacroAppend : |
---|
3058 | cout << " appends to macro " << symbol.name << " : "; |
---|
3059 | break; |
---|
3060 | case CommandMacroRemove : |
---|
3061 | cout << " remove from macro " << symbol.name << " : "; |
---|
3062 | break; |
---|
3063 | case CommandMacroRemoveRegexp : |
---|
3064 | cout << " remove RE from macro " << symbol.name << " : "; |
---|
3065 | break; |
---|
3066 | case CommandMacroRemoveAll : |
---|
3067 | cout << " remove all from macro " << symbol.name << " : "; |
---|
3068 | break; |
---|
3069 | case CommandMacroRemoveAllRegexp : |
---|
3070 | cout << " remove all RE from macro " << symbol.name << " : "; |
---|
3071 | break; |
---|
3072 | case CommandAction : |
---|
3073 | cout << " " << define_text << " action " << symbol.name << " as "; |
---|
3074 | first_definition = false; |
---|
3075 | break; |
---|
3076 | } |
---|
3077 | |
---|
3078 | cout << "'" << value.text << "'"; |
---|
3079 | |
---|
3080 | Tag* selected_tag = value.tag; |
---|
3081 | |
---|
3082 | if ((selected_tag == 0) || |
---|
3083 | (selected_tag == Tag::get_default ())) |
---|
3084 | { |
---|
3085 | cout << " for default tag"; |
---|
3086 | } |
---|
3087 | else |
---|
3088 | { |
---|
3089 | cout << " for tag '" << selected_tag->get_name () << "'"; |
---|
3090 | } |
---|
3091 | |
---|
3092 | cout << discarded_text << endl; |
---|
3093 | } |
---|
3094 | |
---|
3095 | //------------------------------------------------------------- |
---|
3096 | int SymbolValueList::print (const Symbol& symbol, |
---|
3097 | const SymbolValue& value, |
---|
3098 | bool& first_definition) const |
---|
3099 | { |
---|
3100 | int result (0); |
---|
3101 | |
---|
3102 | //if (use->get_package_name () == "CMT") return result; |
---|
3103 | |
---|
3104 | cmt_string discarded_text; |
---|
3105 | cmt_string define_text; |
---|
3106 | ActionType action = Cmt::get_action (); |
---|
3107 | |
---|
3108 | switch (command_type) |
---|
3109 | { |
---|
3110 | //case CommandSet : |
---|
3111 | case CommandSetAppend : |
---|
3112 | case CommandSetPrepend : |
---|
3113 | case CommandSetRemove : |
---|
3114 | case CommandSetRemoveRegexp : |
---|
3115 | //case CommandAlias : |
---|
3116 | //case CommandPath : |
---|
3117 | case CommandPathAppend : |
---|
3118 | case CommandPathPrepend : |
---|
3119 | case CommandPathRemove : |
---|
3120 | case CommandPathRemoveRegexp : |
---|
3121 | case CommandMacroPrepend : |
---|
3122 | //case CommandMacro : |
---|
3123 | case CommandMacroAppend : |
---|
3124 | case CommandMacroRemove : |
---|
3125 | case CommandMacroRemoveRegexp : |
---|
3126 | case CommandMacroRemoveAll : |
---|
3127 | case CommandMacroRemoveAllRegexp : |
---|
3128 | //case CommandAction : |
---|
3129 | if (value.text == "") return result; |
---|
3130 | break; |
---|
3131 | } |
---|
3132 | |
---|
3133 | if (discarded) discarded_text = " (discarded by override)"; |
---|
3134 | else discarded_text = ""; |
---|
3135 | |
---|
3136 | if (first_definition) define_text = "defines"; |
---|
3137 | else define_text = "overrides"; |
---|
3138 | |
---|
3139 | if (CmtMessage::active (Verbose)) |
---|
3140 | cout << "# Package " << (use != 0 ? use->get_package_name () + " " + use->version : ""); |
---|
3141 | /* |
---|
3142 | if (use != 0) |
---|
3143 | { |
---|
3144 | cout << use->get_package_name () << " " << use->version; |
---|
3145 | } |
---|
3146 | */ |
---|
3147 | |
---|
3148 | switch (command_type) |
---|
3149 | { |
---|
3150 | case CommandSet : |
---|
3151 | if (CmtMessage::active (Verbose)) |
---|
3152 | cout << " " << define_text << " set " << symbol.name << " as " << endl; |
---|
3153 | // cout << " " << define_text << " set " << symbol.name << " as "; |
---|
3154 | cout << "set " << symbol.name; |
---|
3155 | first_definition = false; |
---|
3156 | result = 1; |
---|
3157 | break; |
---|
3158 | case CommandSetAppend : |
---|
3159 | if (CmtMessage::active (Verbose)) |
---|
3160 | cout << " appends to set " << symbol.name << " : " << endl; |
---|
3161 | // cout << " appends to set " << symbol.name << " : "; |
---|
3162 | cout << "set_append " << symbol.name; |
---|
3163 | result = 1; |
---|
3164 | break; |
---|
3165 | case CommandSetPrepend : |
---|
3166 | if (CmtMessage::active (Verbose)) |
---|
3167 | cout << " prepends to set " << symbol.name << " : " << endl; |
---|
3168 | // cout << " prepends to set " << symbol.name << " : "; |
---|
3169 | cout << "set_prepend " << symbol.name; |
---|
3170 | result = 1; |
---|
3171 | break; |
---|
3172 | case CommandSetRemove : |
---|
3173 | if (CmtMessage::active (Verbose)) |
---|
3174 | cout << " removes from set " << symbol.name << " : " << endl; |
---|
3175 | // cout << " removes from set " << symbol.name << " : "; |
---|
3176 | cout << "set_remove " << symbol.name; |
---|
3177 | result = 1; |
---|
3178 | break; |
---|
3179 | case CommandSetRemoveRegexp : |
---|
3180 | if (CmtMessage::active (Verbose)) |
---|
3181 | cout << " removes RE from set " << symbol.name << " : " << endl; |
---|
3182 | // cout << " removes RE from set " << symbol.name << " : "; |
---|
3183 | cout << "set_remove_regexp " << symbol.name; |
---|
3184 | result = 1; |
---|
3185 | break; |
---|
3186 | case CommandAlias : |
---|
3187 | if (CmtMessage::active (Verbose)) |
---|
3188 | cout << " " << define_text << " alias " << symbol.name << endl; |
---|
3189 | // cout << " " << define_text << " alias " << symbol.name << " as "; |
---|
3190 | cout << "alias " << symbol.name; |
---|
3191 | first_definition = false; |
---|
3192 | result = 1; |
---|
3193 | break; |
---|
3194 | case CommandPath : |
---|
3195 | if (CmtMessage::active (Verbose)) |
---|
3196 | cout << " " << define_text << " path " << symbol.name << endl; |
---|
3197 | // cout << " " << define_text << " path " << symbol.name << " as "; |
---|
3198 | cout << "path " << symbol.name; |
---|
3199 | first_definition = false; |
---|
3200 | result = 1; |
---|
3201 | break; |
---|
3202 | case CommandPathAppend : |
---|
3203 | if (CmtMessage::active (Verbose)) |
---|
3204 | cout << " appends to path " << symbol.name << endl; |
---|
3205 | // cout << " appends to path " << symbol.name << " : "; |
---|
3206 | cout << "path_append " << symbol.name; |
---|
3207 | result = 1; |
---|
3208 | break; |
---|
3209 | case CommandPathPrepend : |
---|
3210 | if (CmtMessage::active (Verbose)) |
---|
3211 | cout << " prepends to path " << symbol.name << " : " << endl; |
---|
3212 | // cout << " prepends to path " << symbol.name << " : "; |
---|
3213 | cout << "path_prepend " << symbol.name; |
---|
3214 | result = 1; |
---|
3215 | break; |
---|
3216 | case CommandPathRemove : |
---|
3217 | if (CmtMessage::active (Verbose)) |
---|
3218 | cout << " removes from path " << symbol.name << " : " << endl; |
---|
3219 | // cout << " removes from path " << symbol.name << " : "; |
---|
3220 | cout << "path_remove " << symbol.name; |
---|
3221 | result = 1; |
---|
3222 | break; |
---|
3223 | case CommandPathRemoveRegexp : |
---|
3224 | if (CmtMessage::active (Verbose)) |
---|
3225 | cout << " removes RE from path " << symbol.name << " : " << endl; |
---|
3226 | // cout << " removes RE from path " << symbol.name << " : "; |
---|
3227 | cout << "path_remove_regexp " << symbol.name; |
---|
3228 | result = 1; |
---|
3229 | break; |
---|
3230 | case CommandMacro : |
---|
3231 | if (CmtMessage::active (Verbose)) |
---|
3232 | cout << " " << define_text << " macro " << symbol.name << " as " << endl; |
---|
3233 | // cout << " " << define_text << " macro " << symbol.name << " as "; |
---|
3234 | cout << "macro " << symbol.name; |
---|
3235 | result = 1; |
---|
3236 | break; |
---|
3237 | case CommandMacroPrepend : |
---|
3238 | if (CmtMessage::active (Verbose)) |
---|
3239 | cout << " prepends to macro " << symbol.name << " : " << endl; |
---|
3240 | // cout << " prepends to macro " << symbol.name << " : "; |
---|
3241 | cout << "macro_prepend " << symbol.name; |
---|
3242 | result = 1; |
---|
3243 | break; |
---|
3244 | case CommandMacroAppend : |
---|
3245 | if (CmtMessage::active (Verbose)) |
---|
3246 | cout << " appends to macro " << symbol.name << " : " << endl; |
---|
3247 | // cout << " appends to macro " << symbol.name << " : "; |
---|
3248 | cout << "macro_append " << symbol.name; |
---|
3249 | result = 1; |
---|
3250 | break; |
---|
3251 | case CommandMacroRemove : |
---|
3252 | if (CmtMessage::active (Verbose)) |
---|
3253 | cout << " remove from macro " << symbol.name << " : " << endl; |
---|
3254 | // cout << " remove from macro " << symbol.name << " : "; |
---|
3255 | cout << "macro_remove " << symbol.name; |
---|
3256 | result = 1; |
---|
3257 | break; |
---|
3258 | case CommandMacroRemoveRegexp : |
---|
3259 | if (CmtMessage::active (Verbose)) |
---|
3260 | cout << " remove RE from macro " << symbol.name << " : " << endl; |
---|
3261 | // cout << " remove RE from macro " << symbol.name << " : "; |
---|
3262 | cout << "macro_remove_regexp " << symbol.name; |
---|
3263 | result = 1; |
---|
3264 | break; |
---|
3265 | case CommandMacroRemoveAll : |
---|
3266 | if (CmtMessage::active (Verbose)) |
---|
3267 | cout << " remove all from macro " << symbol.name << " : " << endl; |
---|
3268 | // cout << " remove all from macro " << symbol.name << " : "; |
---|
3269 | cout << "macro_remove_all " << symbol.name; |
---|
3270 | result = 1; |
---|
3271 | break; |
---|
3272 | case CommandMacroRemoveAllRegexp : |
---|
3273 | if (CmtMessage::active (Verbose)) |
---|
3274 | cout << " remove all RE from macro " << symbol.name << " : " << endl; |
---|
3275 | // cout << " remove all RE from macro " << symbol.name << " : "; |
---|
3276 | cout << "macro_remove_all_regexp " << symbol.name; |
---|
3277 | result = 1; |
---|
3278 | break; |
---|
3279 | case CommandSetupScript : |
---|
3280 | if (CmtMessage::active (Verbose)) |
---|
3281 | cout << " " << define_text << " setup script " << symbol.name << endl; |
---|
3282 | // cout << " " << define_text << " action " << symbol.name << " as "; |
---|
3283 | cout << "setup_script" /* << symbol.name */; |
---|
3284 | first_definition = false; |
---|
3285 | result = 1; |
---|
3286 | break; |
---|
3287 | /* |
---|
3288 | case CommandAction : |
---|
3289 | cout << " " << define_text << " action " << symbol.name << " as "; |
---|
3290 | first_definition = false; |
---|
3291 | break; |
---|
3292 | */ |
---|
3293 | } |
---|
3294 | |
---|
3295 | cout << " " << CmtSystem::quote (value.text, " \t"); |
---|
3296 | // cout << "'" << value.text << "'"; |
---|
3297 | |
---|
3298 | /* |
---|
3299 | Tag* selected_tag = value.tag; |
---|
3300 | |
---|
3301 | if ((selected_tag == 0) || |
---|
3302 | (selected_tag == Tag::get_default ())) |
---|
3303 | { |
---|
3304 | cout << " for default tag"; |
---|
3305 | } |
---|
3306 | else |
---|
3307 | { |
---|
3308 | cout << " for tag '" << selected_tag->get_name () << "'"; |
---|
3309 | } |
---|
3310 | */ |
---|
3311 | |
---|
3312 | cout << endl; |
---|
3313 | // cout << discarded_text << endl; |
---|
3314 | return result; |
---|
3315 | } |
---|
3316 | |
---|
3317 | //------------------------------------------------------------- |
---|
3318 | bool Symbol::check_tag_used (const Tag* tag) |
---|
3319 | { |
---|
3320 | if (tag == 0) return (false); |
---|
3321 | |
---|
3322 | static SymbolVector& Symbols = symbols (); |
---|
3323 | |
---|
3324 | if (Symbols.size () == 0) |
---|
3325 | { |
---|
3326 | return (false); |
---|
3327 | } |
---|
3328 | |
---|
3329 | for (int number = 0; number < Symbol::symbol_number (); number++) |
---|
3330 | { |
---|
3331 | Symbol& symbol = Symbol::symbol (number); |
---|
3332 | |
---|
3333 | for (int i = 0; i < symbol.value_lists.size (); i++) |
---|
3334 | { |
---|
3335 | const SymbolValueList& value_list = symbol.value_lists[i]; |
---|
3336 | |
---|
3337 | for (int j = 0; j < value_list.values.size (); j++) |
---|
3338 | { |
---|
3339 | const SymbolValue& value = value_list.values[j]; |
---|
3340 | Tag* t = value.tag; |
---|
3341 | |
---|
3342 | if (t != 0) |
---|
3343 | { |
---|
3344 | if (t->use_operand (tag)) return (true); |
---|
3345 | } |
---|
3346 | } |
---|
3347 | } |
---|
3348 | } |
---|
3349 | |
---|
3350 | return (false); |
---|
3351 | } |
---|
3352 | |
---|
3353 | //------------------------------------------------------------- |
---|
3354 | cmt_string Symbol::get_env_value (const cmt_string& name) |
---|
3355 | { |
---|
3356 | cmt_string s; |
---|
3357 | |
---|
3358 | Symbol* symbol = Symbol::find (name); |
---|
3359 | if (symbol != 0) |
---|
3360 | { |
---|
3361 | m_inhibit_display = true; |
---|
3362 | |
---|
3363 | s = symbol->build_macro_value (); |
---|
3364 | Symbol::expand (s); |
---|
3365 | |
---|
3366 | m_inhibit_display = false; |
---|
3367 | } |
---|
3368 | else |
---|
3369 | { |
---|
3370 | s = CmtSystem::getenv (name); |
---|
3371 | } |
---|
3372 | |
---|
3373 | return (s); |
---|
3374 | } |
---|
3375 | |
---|
3376 | bool Symbol::get_inhibit_display () |
---|
3377 | { |
---|
3378 | return (m_inhibit_display); |
---|
3379 | } |
---|
3380 | |
---|