source: CMT/v1r20p20090520/source/cmt_fragment.cxx @ 595

Last change on this file since 595 was 459, checked in by rybkin, 16 years ago

See C.L. 360

  • Property svn:eol-style set to native
File size: 28.0 KB
Line 
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_fragment.h"
13#include "cmt_use.h"
14#include "cmt_symbol.h"
15#include "cmt_system.h"
16#include "cmt_database.h"
17#include "cmt_log.h"
18
19/*----------------------------------------------------------*/
20/*                                                          */
21/*  Operations on Variables                                 */
22/*                                                          */
23/*----------------------------------------------------------*/
24
25//----------------------------------------------------------
26Variable* Variable::find (VariableVector& vector, 
27                          const cmt_string& name)
28{
29  for (int i = 0; i < vector.size (); i++)
30    {
31      Variable& v = vector[i];
32
33      if (v.name == name) return (&v);
34    }
35
36  return (0);
37}
38
39//----------------------------------------------------------
40Variable::Variable ()
41{
42}
43
44//----------------------------------------------------------
45Variable::Variable (const cmt_string& n) : name (n)
46{
47  m_macro_braces = "${";
48  m_macro_braces += name;
49  m_macro_braces += "}";
50
51  m_macro_pars = "$(";
52  m_macro_pars += name;
53  m_macro_pars += ")";
54}
55
56//----------------------------------------------------------
57const cmt_string& Variable::macro_braces () const
58{
59  return (m_macro_braces);
60}
61
62//----------------------------------------------------------
63const cmt_string& Variable::macro_pars () const
64{
65  return (m_macro_pars);
66}
67
68//----------------------------------------------------------
69void Variable::set (const cmt_string& new_name,
70                    const cmt_string& new_value)
71{
72  name = new_name;
73  value = new_value;
74
75  m_macro_braces = "${";
76  m_macro_braces += name;
77  m_macro_braces += "}";
78
79  m_macro_pars = "$(";
80  m_macro_pars += name;
81  m_macro_pars += ")";
82}
83
84//----------------------------------------------------------
85Variable& Variable::operator = (const Variable& other)
86{
87  value = other.value;
88  return (*this);
89}
90
91//----------------------------------------------------------
92Variable& Variable::operator = (const cmt_string& v)
93{
94  value = v;
95  return (*this);
96}
97
98//----------------------------------------------------------
99void Variable::operator += (const cmt_string& v)
100{
101  value += v;
102}
103
104//----------------------------------------------------------
105cmt_string Variable::operator + (const cmt_string& v) const
106{
107  return (value + v);
108}
109
110//----------------------------------------------------------
111Variable::operator const cmt_string& () const
112{
113  return (value);
114}
115
116//----------------------------------------------------------
117bool Variable::operator == (const cmt_string& v) const
118{
119  return ((value == v));
120}
121
122//----------------------------------------------------------
123bool Variable::operator != (const cmt_string& v) const
124{
125  return ((value != v));
126}
127
128/*----------------------------------------------------------*/
129/*                                                          */
130/*  Operations on Fragments                                 */
131/*                                                          */
132/*----------------------------------------------------------*/
133
134/*----------------------------------------------------------*/
135void Fragment::show (const cmt_string& name)
136{
137  Fragment* fragment = Fragment::find (name);
138  if (fragment == 0)
139    {
140      CmtMessage::info ("Fragment " + name + " not found");
141      //      cerr << "Fragment " << name << " not found" << endl;
142    }
143  else
144    {
145      fragment->print ();
146    }
147}
148
149/*----------------------------------------------------------*/
150void Fragment::show_all ()
151{
152  static FragmentVector& Fragments = fragments ();
153
154  int number;
155
156  for (number = 0; number < Fragments.size (); number++)
157    {
158      Fragment& fragment = Fragments[number];
159
160      fragment.print ();
161    }
162}
163
164class fragment_action_iterator
165{
166public:
167
168  fragment_action_iterator (Use* use) :
169    m_need_dependencies (false),
170    m_state (need_name),
171    m_use (use)
172  {
173  }
174
175  void add_word (const cmt_string& w)
176  {
177    switch (m_state)
178      {
179      case need_name:
180        m_name = w;
181        m_state = need_options;
182        break;
183      case need_options:
184        if (w.find ("-suffix=") != cmt_string::npos)
185          {
186            m_suffix = w;
187            m_suffix.replace ("-suffix=", "");
188          }
189        else if (w.find ("-dependencies") != cmt_string::npos)
190          {
191            m_need_dependencies = true;
192          }
193        else if (w.find ("-header=") != cmt_string::npos)
194          {
195            m_header = w;
196            m_header.replace ("-header=", "");
197
198            if (Fragment::find (m_header) == 0)
199              {
200                Fragment::add (m_header, "", "", "", false, m_use);
201              }
202          }
203        else if (w.find ("-trailer=") != cmt_string::npos)
204          {
205            m_trailer = w;
206            m_trailer.replace ("-trailer=", "");
207           
208            if (Fragment::find (m_trailer) == 0)
209              {
210                Fragment::add (m_trailer, "", "", "", false, m_use);
211              }
212          }
213        break;
214      }
215  }
216
217  void commit ()
218  {
219    Fragment::add (m_name, m_suffix, m_header, m_trailer, m_need_dependencies, m_use);
220  }
221
222private:
223
224  enum
225    {
226      need_name,
227      need_options
228    } m_state;
229
230  cmt_string m_name;
231  cmt_string m_suffix;
232  cmt_string m_header;
233  cmt_string m_trailer;
234  bool m_need_dependencies;
235  Use* m_use;
236};
237
238
239/*----------------------------------------------------------*/
240void Fragment::action (const CmtSystem::cmt_string_vector& words,
241                       Use* use)
242{
243  if ((Cmt::get_current_access () == UserMode) &&
244      (use->get_current_scope () == ScopePrivate)) return;
245
246  if (words.size () <= 1) return;
247
248  fragment_action_iterator it (use);
249
250  for (int i = 1; i < words.size (); i++)
251    {
252      const cmt_string& w = words[i];
253      cmt_string ew = w;
254
255      Symbol::expand (ew);
256      if (ew != w)
257        {
258          CmtSystem::cmt_string_vector ws;
259
260          CmtSystem::split (ew, " ", ws);
261
262          for (int j = 0; j < ws.size (); ++j)
263            {
264              const cmt_string& ww = ws[j];
265              it.add_word (ww);
266            }
267        }
268      else
269        {
270          it.add_word (ew);
271        }
272    }
273
274  it.commit ();
275}
276
277/*----------------------------------------------------------*/
278Fragment* Fragment::find (const cmt_string& name)
279{
280  static FragmentVector& Fragments = fragments ();
281
282  int fragment_index;
283
284  if (Fragments.size () == 0) return (0);
285
286  for (fragment_index = 0;
287       fragment_index < Fragments.size ();
288       fragment_index++)
289    {
290      Fragment& fragment = Fragments[fragment_index];
291
292      if (fragment.name == name)
293        {
294          return (&fragment);
295        }
296    }
297
298  return (0);
299}
300
301/*----------------------------------------------------------*/
302void Fragment::add (const cmt_string& name,
303                    const cmt_string& suffix,
304                    const cmt_string& header,
305                    const cmt_string& trailer,
306                    bool need_dependencies,
307                    Use* use)
308{
309  static FragmentVector& Fragments = fragments ();
310
311  {
312    Fragment* fragment;
313
314    if (name == "") return;
315
316    fragment = find (name);
317    if (fragment != 0)
318      {
319        if (suffix != "")
320          {
321            fragment->suffix = suffix;
322          }
323
324        if (header != "")
325          {
326            fragment->header = header;
327          }
328
329        if (trailer != "")
330          {
331            fragment->trailer = trailer;
332          }
333
334        fragment->need_dependencies = need_dependencies;
335
336        fragment->use = use;
337        return;
338      }
339  }
340
341  Fragment& fragment = Fragments.add ();
342
343  fragment.name              = name;
344  fragment.suffix            = suffix;
345  fragment.header            = header;
346  fragment.trailer           = trailer;
347  fragment.need_dependencies = need_dependencies;
348  fragment.use               = use;
349}
350
351/*----------------------------------------------------------*/
352void Fragment::clear_all ()
353{
354  static FragmentVector& Fragments = fragments ();
355
356  for (int i = 0; i < Fragments.size (); i++)
357    {
358      Fragment& f = Fragments[i];
359      f.clear ();
360    }
361
362  Fragments.clear ();
363}
364
365/*----------------------------------------------------------*/
366Fragment::FragmentVector& Fragment::fragments ()
367{
368  static Database& db = Database::instance ();
369  static FragmentVector& Fragments = db.fragments ();
370
371  return (Fragments);
372}
373
374/*----------------------------------------------------------*/
375Fragment::Fragment ()
376{
377  use = 0;
378}
379
380/*----------------------------------------------------------*/
381Fragment::Fragment (const cmt_string& fragment_name)
382{
383  name = fragment_name;
384  use = 0;
385  path = "";
386}
387
388/*----------------------------------------------------------*/
389Fragment::~Fragment ()
390{
391  use = 0;
392}
393
394/*----------------------------------------------------------*/
395void Fragment::clear ()
396{
397  name    = "";
398  suffix  = "";
399  header  = "";
400  trailer = "";
401  need_dependencies = false;
402  path = "";
403  use  = 0;
404}
405
406/*----------------------------------------------------------*/
407int Fragment::print ()
408{
409  int result = 1;
410
411  if (name == "") return (0);
412 
413  locate ();
414
415  if (use == 0)
416    {
417      Use& u = Use::current();
418      use = &u;
419    }
420 
421  cmt_string the_path = path;
422
423  use->reduce_path (the_path);
424
425  cout << the_path;
426
427  if (suffix != "")
428    {
429      cout << "->" << suffix;
430    }
431
432  cout << endl;
433
434  return (result);
435}
436
437/*----------------------------------------------------------*/
438bool Fragment::locate ()
439{
440  cmt_string root_path;
441
442  if (use == 0)
443    {
444      // Assume CMT
445      use = Use::find ("CMT");
446    }
447
448  use->get_full_path (root_path);
449
450  if (path != "") return (true);
451
452  // First try <root>/fragments/<name> or <root>/fragments/nmake/<name>
453
454  path = root_path;
455  path += CmtSystem::file_separator ();
456  path += "fragments";
457  path += CmtSystem::file_separator ();
458 
459  if (Cmt::build_nmake ())
460    {
461      path += "nmake";
462      path += CmtSystem::file_separator ();
463    }
464 
465  path += name;
466
467  if (CmtSystem::test_file (path)) return (true);
468
469  // Then try <root>/fragments/<name> for both Win and Unix
470
471  path = root_path;
472  path += CmtSystem::file_separator ();
473  path += "fragments";
474  path += CmtSystem::file_separator ();
475  path += name;
476
477  if (CmtSystem::test_file (path)) return (true);
478
479  // Then try <root>/cmt/fragments/<name> or <root>/cmt/fragments/nmake/<name>
480
481  root_path += CmtSystem::file_separator ();
482
483  if (use->style == mgr_style) root_path += "mgr";
484  else root_path += "cmt";
485 
486  root_path += CmtSystem::file_separator ();
487  root_path += "fragments";
488  root_path += CmtSystem::file_separator ();
489 
490  path = root_path;
491 
492  if (Cmt::build_nmake ())
493    {
494      path += "nmake";
495      path += CmtSystem::file_separator ();
496    }
497 
498  path += name;
499 
500  if (CmtSystem::test_file (path)) return (true);
501
502  // Then try <root>/cmt/fragments/<name> for both Win and Unix
503
504  path = root_path;
505 
506  path += name;
507
508  if (CmtSystem::test_file (path)) return (true);
509
510  return (false);
511}
512
513//--------------------------------------------------
514bool Fragment::copy (FILE* out,
515                     const cmt_string& name,
516                     int variables, ...)
517{
518  va_list ids;
519
520  Fragment* fragment = Fragment::find (name);
521  if (fragment == 0) return (false);
522
523  va_start (ids, variables);
524  bool result = fragment->copy (out, variables, ids);
525  va_end (ids);
526
527  return (result);
528}
529
530//--------------------------------------------------
531bool Fragment::copy (cmt_string& out,
532                     const cmt_string& name,
533                     int variables, ...)
534{
535  va_list ids;
536
537  Fragment* fragment = Fragment::find (name);
538  if (fragment == 0) return (false);
539
540  va_start (ids, variables);
541  bool result = fragment->copy (out, variables, ids);
542  va_end (ids);
543
544  return (result);
545}
546
547//--------------------------------------------------
548bool Fragment::copy (FILE* out, int variables, ...)
549{
550  va_list ids;
551
552  va_start (ids, variables);
553  bool result = copy (out, variables, ids);
554  va_end (ids);
555
556  return (result);
557}
558
559//--------------------------------------------------
560bool Fragment::copy (cmt_string& out, int variables, ...)
561{
562  va_list ids;
563
564  va_start (ids, variables);
565  bool result = copy (out, variables, ids);
566  va_end (ids);
567
568  return (result);
569}
570
571//--------------------------------------------------
572bool Fragment::copy (FILE* out, int variables, va_list ids)
573{
574  static cmt_string cline;
575
576  bool result = copy (cline, variables, ids);
577  if (result)
578    {
579      cline.write (out);
580      return (true);
581    }
582  else
583    {
584      return (false);
585    }
586}
587
588//--------------------------------------------------
589bool Fragment::copy (cmt_string& out, int variables, va_list ids)
590{
591  int i;
592
593  if (!locate ()) return (false);
594
595  out.read (path);
596
597  Variable* var = 0;
598  for (i = 0; i < variables; i++)
599    {
600      var = va_arg (ids, Variable*);
601      out.replace_all (var->macro_braces (), var->value);
602      out.replace_all (var->macro_pars (), var->value);
603    }
604
605  return (true);
606}
607
608//--------------------------------------------------
609bool Fragment::wincopy (FILE* out, int variables, va_list ids)
610{
611  static cmt_string cline;
612
613  bool result = wincopy (cline, variables, ids);
614
615  if (result)
616    {
617      cline.write (out);
618      return (true);
619    }
620  else
621    {
622      return (false);
623    }
624}
625
626//--------------------------------------------------
627bool Fragment::wincopy (cmt_string& out, int variables, va_list ids)
628{
629  int i;
630
631  if (!locate ()) return (false);
632
633  out.read (path);
634
635  Variable* var = 0;
636  for (i = 0; i < variables; i++)
637    {
638      var = va_arg (ids, Variable*);
639      out.replace_all (var->macro_braces (), var->value);
640      out.replace_all (var->macro_pars (), var->value);
641    }
642
643  cmt_string pattern;
644  cmt_string macro_name;
645  char end_pattern;
646
647  int start = 0;
648
649  for (;;)
650    {
651      //
652      // Try and substitute all ${xxx} or $(xxx) patterns
653      // using symbol values.
654      //
655      int par;
656      int brace;
657      int begin;
658
659      par = out.find (start, "$(");
660      brace = out.find (start, "${");
661
662      if (par == cmt_string::npos)
663        {
664          // No parentheses. Look for brace
665          if (brace == cmt_string::npos)
666            {
667              // No pattern, finish the scan.
668              break;
669            }
670
671          // Brace found
672          end_pattern = '}';
673          begin = brace;
674        }
675      else
676        {
677          // Parenthese found. Look for closest from {par, brace}
678          if ((brace == cmt_string::npos) ||
679              (brace > par))
680            {
681              end_pattern = ')';
682              begin = par;
683            }
684          else
685            {
686              end_pattern = '}';
687              begin = brace;
688            }
689        }
690
691      // Skip the pattern intro.
692      start = begin + 2;
693
694      int end;
695      end = out.find (start, end_pattern);
696      if (end == cmt_string::npos)
697        {
698          // The pattern is a fake one (no ending!)
699          break;
700        }
701
702      // This should never happen...
703      if (end < begin) break;
704
705      // Extract the complete pattern
706      out.substr (begin, end - begin + 1, pattern);
707
708      // Then only the macro name
709      out.substr (begin + 2, end - begin - 2, macro_name);
710
711      if (macro_name == "CFG")
712        {
713          // This is a Windows reserved keyword...
714          start = end + 1;
715        }
716      else
717        {
718          Symbol* macro = Symbol::find (macro_name);
719          if (macro != 0)
720            {
721              // Macro found
722              cmt_string value = macro->resolve_macro_value ();
723
724              out.replace_all (pattern, value);
725
726              // The substitution will restart from the same place
727              // allowing for recursive replacements
728              start = begin;
729            }
730          else
731            {
732              // Macro not found. Look for env. variable
733              cmt_string value = CmtSystem::getenv (macro_name);
734
735              out.replace_all (pattern, value);
736
737              // The substitution will restart from the same place
738              // allowing for recursive replacements
739              start = begin;
740            }
741        }
742    }
743
744  // Uniformly install CR-LF doublets.
745
746  out.replace_all ("\r\n", "\n");
747  out.replace_all ("\n", "\r\n");
748
749  return (true);
750}
751
752
753
754
755
756
757
758
759//--------------------------------------------------
760bool Fragment::copy (FILE* out,
761                     const cmt_string& name,
762                     const Variable::VariableVector& vector, 
763                     int variables, ...)
764{
765  va_list ids;
766
767  Fragment* fragment = Fragment::find (name);
768  if (fragment == 0) return (false);
769
770  va_start (ids, variables);
771  bool result = fragment->copy (out, vector, variables, ids);
772  va_end (ids);
773
774  return (result);
775}
776
777//--------------------------------------------------
778bool Fragment::copy (cmt_string& out,
779                     const cmt_string& name,
780                     const Variable::VariableVector& vector, 
781                     int variables, ...)
782{
783  va_list ids;
784
785  Fragment* fragment = Fragment::find (name);
786  if (fragment == 0) return (false);
787
788  va_start (ids, variables);
789  bool result = fragment->copy (out, vector, variables, ids);
790  va_end (ids);
791
792  return (result);
793}
794
795//--------------------------------------------------
796bool Fragment::copy (FILE* out, const Variable::VariableVector& vector, int variables, ...)
797{
798  va_list ids;
799
800  va_start (ids, variables);
801  bool result = copy (out, vector, variables, ids);
802  va_end (ids);
803
804  return (result);
805}
806
807//--------------------------------------------------
808bool Fragment::copy (cmt_string& out, const Variable::VariableVector& vector, int variables, ...)
809{
810  va_list ids;
811
812  va_start (ids, variables);
813  bool result = copy (out, vector, variables, ids);
814  va_end (ids);
815
816  return (result);
817}
818
819//--------------------------------------------------
820bool Fragment::copy (FILE* out, const Variable::VariableVector& vector, int variables, va_list ids)
821{
822  static cmt_string cline;
823
824  bool result = copy (cline, vector, variables, ids);
825  if (result)
826    {
827      cline.write (out);
828      return (true);
829    }
830  else
831    {
832      return (false);
833    }
834}
835
836//--------------------------------------------------
837bool Fragment::copy (cmt_string& out, const Variable::VariableVector& vector, int variables, va_list ids)
838{
839  int i;
840
841  if (!locate ()) return (false);
842
843  out.read (path);
844
845  Variable* var = 0;
846
847  for (i = 0; i < vector.size (); i++)
848    {
849      var = &(vector[i]);
850      out.replace_all (var->macro_braces (), var->value);
851      out.replace_all (var->macro_pars (), var->value);
852    }
853
854  for (i = 0; i < variables; i++)
855    {
856      var = va_arg (ids, Variable*);
857      out.replace_all (var->macro_braces (), var->value);
858      out.replace_all (var->macro_pars (), var->value);
859    }
860
861  return (true);
862}
863
864//--------------------------------------------------
865bool Fragment::wincopy (FILE* out, const Variable::VariableVector& vector, int variables, va_list ids)
866{
867  static cmt_string cline;
868
869  bool result = wincopy (cline, vector, variables, ids);
870  if (result)
871    {
872      cline.write (out);
873      return (true);
874    }
875  else
876    {
877      return (false);
878    }
879}
880
881//--------------------------------------------------
882bool Fragment::wincopy (cmt_string& out, const Variable::VariableVector& vector, 
883                        int variables, va_list ids)
884{
885  int i;
886
887  if (!locate ()) return (false);
888
889  out.read (path);
890
891  Variable* var = 0;
892
893  for (i = 0; i < vector.size (); i++)
894    {
895      var = &(vector[i]);
896      out.replace_all (var->macro_braces (), var->value);
897      out.replace_all (var->macro_pars (), var->value);
898    }
899
900  for (i = 0; i < variables; i++)
901    {
902      var = va_arg (ids, Variable*);
903      out.replace_all (var->macro_braces (), var->value);
904      out.replace_all (var->macro_pars (), var->value);
905    }
906
907  cmt_string pattern;
908  cmt_string macro_name;
909  char end_pattern;
910
911  int start = 0;
912
913  for (;;)
914    {
915      //
916      // Try and substitute all ${xxx} or $(xxx) patterns
917      // using symbol values.
918      //
919      int par;
920      int brace;
921      int begin;
922
923      par = out.find (start, "$(");
924      brace = out.find (start, "${");
925
926      if (par == cmt_string::npos)
927        {
928          // No parentheses. Look for brace
929          if (brace == cmt_string::npos)
930            {
931              // No pattern, finish the scan.
932              break;
933            }
934
935          // Brace found
936          end_pattern = '}';
937          begin = brace;
938        }
939      else
940        {
941          // Parenthese found. Look for closest from {par, brace}
942          if ((brace == cmt_string::npos) ||
943              (brace > par))
944            {
945              end_pattern = ')';
946              begin = par;
947            }
948          else
949            {
950              end_pattern = '}';
951              begin = brace;
952            }
953        }
954
955      // Skip the pattern intro.
956      start = begin + 2;
957
958      int end;
959      end = out.find (start, end_pattern);
960      if (end == cmt_string::npos)
961        {
962          // The pattern is a fake one (no ending!)
963          break;
964        }
965
966      // This should never happen...
967      if (end < begin) break;
968
969      // Extract the complete pattern
970      out.substr (begin, end - begin + 1, pattern);
971
972      // Then only the macro name
973      out.substr (begin + 2, end - begin - 2, macro_name);
974
975      if (macro_name == "CFG")
976        {
977          // This is a Windows reserved keyword...
978          start = end + 1;
979        }
980      else
981        {
982          Symbol* macro = Symbol::find (macro_name);
983          if (macro != 0)
984            {
985              // Macro found
986              cmt_string value = macro->resolve_macro_value ();
987              out.replace_all (pattern, value);
988
989              // The substitution will restart from the same place
990              // allowing for recursive replacements
991              start = begin;
992            }
993          else
994            {
995              // Macro not found. Look for env. variable
996              cmt_string value = CmtSystem::getenv (macro_name);
997              out.replace_all (pattern, value);
998
999              // The substitution will restart from the same place
1000              // allowing for recursive replacements
1001              start = begin;
1002            }
1003        }
1004    }
1005
1006  // Uniformly install CR-LF doublets.
1007
1008  out.replace_all ("\r\n", "\n");
1009  out.replace_all ("\n", "\r\n");
1010
1011  return (true);
1012}
1013
1014//--------------------------------------------------
1015FragmentHandle::FragmentHandle ()
1016{
1017  _fragment = 0;
1018  _initialized = false;
1019}
1020
1021//--------------------------------------------------
1022FragmentHandle::FragmentHandle (const cmt_string name) : _name(name)
1023{
1024  _fragment = 0;
1025  _initialized = false;
1026}
1027
1028//--------------------------------------------------
1029FragmentHandle& FragmentHandle::operator = (const FragmentHandle& other)
1030{
1031  _name = other._name;
1032  _fragment = 0;
1033  _initialized = false;
1034
1035  return (*this);
1036}
1037
1038//--------------------------------------------------
1039void FragmentHandle::reset ()
1040{
1041  _fragment = 0;
1042  _initialized = false;
1043}
1044
1045//--------------------------------------------------
1046void FragmentHandle::set (const cmt_string name)
1047{
1048  _name = name;
1049  _fragment = 0;
1050  _initialized = false;
1051}
1052
1053//--------------------------------------------------
1054cmt_string& FragmentHandle::name ()
1055{
1056  static cmt_string null_string;
1057
1058  if (!setup ()) return (null_string);
1059
1060  return (_fragment->name);
1061}
1062
1063//--------------------------------------------------
1064cmt_string& FragmentHandle::suffix ()
1065{
1066  static cmt_string null_string;
1067
1068  if (!setup ()) return (null_string);
1069
1070  return (_fragment->suffix);
1071}
1072
1073//--------------------------------------------------
1074cmt_string& FragmentHandle::header ()
1075{
1076  static cmt_string null_string;
1077
1078  if (!setup ()) return (null_string);
1079
1080  return (_fragment->header);
1081}
1082
1083//--------------------------------------------------
1084cmt_string& FragmentHandle::trailer ()
1085{
1086  static cmt_string null_string;
1087
1088  if (!setup ()) return (null_string);
1089
1090  return (_fragment->trailer);
1091}
1092
1093//--------------------------------------------------
1094bool FragmentHandle::need_dependencies ()
1095{
1096  if (!setup ()) return (false);
1097
1098  return (_fragment->need_dependencies);
1099}
1100
1101//--------------------------------------------------
1102bool FragmentHandle::copy (FILE* out, int variables, ...)
1103{
1104  if (!setup ()) return (false);
1105
1106  va_list ids;
1107
1108  va_start (ids, variables);
1109  bool result = _fragment->copy (out, variables, ids);
1110  va_end (ids);
1111
1112  if (!result)
1113    {
1114      CmtMessage::info ("Fragment " + _name + " not found");
1115      //      cerr << "#CMT> Fragment " << _name << " not found" << endl;
1116      _fragment = 0;
1117    }
1118
1119  return (result);
1120}
1121
1122//--------------------------------------------------
1123bool FragmentHandle::copy (cmt_string& out, int variables, ...)
1124{
1125  if (!setup ()) return (false);
1126
1127  va_list ids;
1128
1129  va_start (ids, variables);
1130  bool result = _fragment->copy (out, variables, ids);
1131  va_end (ids);
1132
1133  if (!result)
1134    {
1135      CmtMessage::info ("Fragment " + _name + " not found");
1136      //      cerr << "#CMT> Fragment " << _name << " not found" << endl;
1137      _fragment = 0;
1138    }
1139
1140  return (result);
1141}
1142
1143//--------------------------------------------------
1144bool FragmentHandle::wincopy (FILE* out, int variables, ...)
1145{
1146  if (!setup ()) return (false);
1147
1148  va_list ids;
1149
1150  va_start (ids, variables);
1151  bool result = _fragment->wincopy (out, variables, ids);
1152  va_end (ids);
1153
1154  if (!result)
1155    {
1156      CmtMessage::info ("Fragment " + _name + " not found");
1157      //      cerr << "#CMT> Fragment " << _name << " not found" << endl;
1158      _fragment = 0;
1159    }
1160
1161  return (result);
1162}
1163
1164//--------------------------------------------------
1165bool FragmentHandle::wincopy (cmt_string& out, int variables, ...)
1166{
1167  if (!setup ()) return (false);
1168
1169  va_list ids;
1170
1171  va_start (ids, variables);
1172  bool result = _fragment->wincopy (out, variables, ids);
1173  va_end (ids);
1174
1175  if (!result)
1176    {
1177      CmtMessage::info ("Fragment " + _name + " not found");
1178      //      cerr << "#CMT> Fragment " << _name << " not found" << endl;
1179      _fragment = 0;
1180    }
1181
1182  return (result);
1183}
1184
1185
1186
1187
1188//--------------------------------------------------
1189bool FragmentHandle::copy (FILE* out, const Variable::VariableVector& vector, int variables, ...)
1190{
1191  if (!setup ()) return (false);
1192
1193  va_list ids;
1194
1195  va_start (ids, variables);
1196  bool result = _fragment->copy (out, vector, variables, ids);
1197  va_end (ids);
1198
1199  if (!result)
1200    {
1201      CmtMessage::info ("Fragment " + _name + " not found");
1202      //      cerr << "#CMT> Fragment " << _name << " not found" << endl;
1203      _fragment = 0;
1204    }
1205
1206  return (result);
1207}
1208
1209//--------------------------------------------------
1210bool FragmentHandle::copy (cmt_string& out, const Variable::VariableVector& vector, int variables, ...)
1211{
1212  if (!setup ()) return (false);
1213
1214  va_list ids;
1215
1216  va_start (ids, variables);
1217  bool result = _fragment->copy (out, vector, variables, ids);
1218  va_end (ids);
1219
1220  if (!result)
1221    {
1222      CmtMessage::info ("Fragment " + _name + " not found");
1223      //      cerr << "#CMT> Fragment " << _name << " not found" << endl;
1224      _fragment = 0;
1225    }
1226
1227  return (result);
1228}
1229
1230//--------------------------------------------------
1231bool FragmentHandle::wincopy (FILE* out, const Variable::VariableVector& vector, int variables, ...)
1232{
1233  if (!setup ()) return (false);
1234
1235  va_list ids;
1236
1237  va_start (ids, variables);
1238  bool result = _fragment->wincopy (out, vector, variables, ids);
1239  va_end (ids);
1240
1241  if (!result)
1242    {
1243      CmtMessage::info ("Fragment " + _name + " not found");
1244      //      cerr << "#CMT> Fragment " << _name << " not found" << endl;
1245      _fragment = 0;
1246    }
1247
1248  return (result);
1249}
1250
1251//--------------------------------------------------
1252bool FragmentHandle::wincopy (cmt_string& out, 
1253                              const Variable::VariableVector& vector, 
1254                              int variables, ...)
1255{
1256  if (!setup ()) return (false);
1257
1258  va_list ids;
1259
1260  va_start (ids, variables);
1261  bool result = _fragment->wincopy (out, vector, variables, ids);
1262  va_end (ids);
1263
1264  if (!result)
1265    {
1266      CmtMessage::info ("Fragment " + _name + " not found");
1267      //      cerr << "#CMT> Fragment " << _name << " not found" << endl;
1268      _fragment = 0;
1269    }
1270
1271  return (result);
1272}
1273
1274//--------------------------------------------------
1275bool FragmentHandle::setup ()
1276{
1277  if (!_initialized)
1278    {
1279      _initialized = true;
1280
1281      _fragment = Fragment::find (_name);
1282      if (_fragment == 0)
1283        {
1284          CmtMessage::info ("Fragment " + _name + " not found");
1285          //          cerr << "#CMT> Fragment " << _name << " not found" << endl;
1286        }
1287    }
1288
1289  if (_fragment == 0)
1290    {
1291      return (false);
1292    }
1293  else
1294    {
1295      return (true);
1296    }
1297}
Note: See TracBrowser for help on using the repository browser.