Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

cmt_fragment.cxx

Go to the documentation of this file.
00001 
00002 #include <stdio.h>
00003 #include <stdlib.h>
00004 #include <string.h>
00005 #include <ctype.h>
00006 
00007 #include "cmt_fragment.h"
00008 #include "cmt_use.h"
00009 #include "cmt_symbol.h"
00010 #include "cmt_system.h"
00011 #include "cmt_database.h"
00012 
00013 /*----------------------------------------------------------*/
00014 /*                                                          */
00015 /*  Operations on Variables                                 */
00016 /*                                                          */
00017 /*----------------------------------------------------------*/
00018 
00019 //----------------------------------------------------------
00020 Variable* Variable::find (VariableVector& vector, 
00021                           const cmt_string& name)
00022 {
00023   for (int i = 0; i < vector.size (); i++)
00024     {
00025       Variable& v = vector[i];
00026 
00027       if (v.name == name) return (&v);
00028     }
00029 
00030   return (0);
00031 }
00032 
00033 //----------------------------------------------------------
00034 Variable::Variable ()
00035 {
00036 }
00037 
00038 //----------------------------------------------------------
00039 Variable::Variable (const cmt_string& n) : name (n)
00040 {
00041   m_macro_braces = "${";
00042   m_macro_braces += name;
00043   m_macro_braces += "}";
00044 
00045   m_macro_pars = "$(";
00046   m_macro_pars += name;
00047   m_macro_pars += ")";
00048 }
00049 
00050 //----------------------------------------------------------
00051 const cmt_string& Variable::macro_braces () const
00052 {
00053   return (m_macro_braces);
00054 }
00055 
00056 //----------------------------------------------------------
00057 const cmt_string& Variable::macro_pars () const
00058 {
00059   return (m_macro_pars);
00060 }
00061 
00062 //----------------------------------------------------------
00063 void Variable::set (const cmt_string& new_name,
00064                     const cmt_string& new_value)
00065 {
00066   name = new_name;
00067   value = new_value;
00068 
00069   m_macro_braces = "${";
00070   m_macro_braces += name;
00071   m_macro_braces += "}";
00072 
00073   m_macro_pars = "$(";
00074   m_macro_pars += name;
00075   m_macro_pars += ")";
00076 }
00077 
00078 //----------------------------------------------------------
00079 Variable& Variable::operator = (const Variable& other)
00080 {
00081   value = other.value;
00082   return (*this);
00083 }
00084 
00085 //----------------------------------------------------------
00086 Variable& Variable::operator = (const cmt_string& v)
00087 {
00088   value = v;
00089   return (*this);
00090 }
00091 
00092 //----------------------------------------------------------
00093 void Variable::operator += (const cmt_string& v)
00094 {
00095   value += v;
00096 }
00097 
00098 //----------------------------------------------------------
00099 cmt_string Variable::operator + (const cmt_string& v) const
00100 {
00101   return (value + v);
00102 }
00103 
00104 //----------------------------------------------------------
00105 Variable::operator const cmt_string& () const
00106 {
00107   return (value);
00108 }
00109 
00110 //----------------------------------------------------------
00111 bool Variable::operator == (const cmt_string& v) const
00112 {
00113   return ((value == v));
00114 }
00115 
00116 //----------------------------------------------------------
00117 bool Variable::operator != (const cmt_string& v) const
00118 {
00119   return ((value != v));
00120 }
00121 
00122 /*----------------------------------------------------------*/
00123 /*                                                          */
00124 /*  Operations on Fragments                                 */
00125 /*                                                          */
00126 /*----------------------------------------------------------*/
00127 
00128 /*----------------------------------------------------------*/
00129 void Fragment::show (const cmt_string& name)
00130 {
00131   Fragment* fragment = Fragment::find (name);
00132   if (fragment == 0)
00133     {
00134       cout << "Fragment " << name << " not found" << endl;
00135     }
00136   else
00137     {
00138       fragment->print ();
00139     }
00140 }
00141 
00142 /*----------------------------------------------------------*/
00143 void Fragment::show_all ()
00144 {
00145   static FragmentVector& Fragments = fragments ();
00146 
00147   int number;
00148 
00149   for (number = 0; number < Fragments.size (); number++)
00150     {
00151       Fragment& fragment = Fragments[number];
00152 
00153       fragment.print ();
00154     }
00155 }
00156 
00157 /*----------------------------------------------------------*/
00158 void Fragment::action (const CmtSystem::cmt_string_vector& words,
00159                        Use* use)
00160 {
00161   if (words.size () > 1)
00162     {
00163       cmt_string suffix;
00164       cmt_string header;
00165       cmt_string trailer;
00166       bool need_dependencies = false;
00167 
00168       cmt_string name = words[1];
00169 
00170       for (int i = 2; i < words.size (); i++)
00171         {
00172           const cmt_string& word = words[i];
00173 
00174           if (word.find ("-suffix=") != cmt_string::npos)
00175             {
00176               suffix = word;
00177               suffix.replace ("-suffix=", "");
00178             }
00179           else if (word.find ("-dependencies") != cmt_string::npos)
00180             {
00181               need_dependencies = true;
00182             }
00183           else if (word.find ("-header=") != cmt_string::npos)
00184             {
00185               header = word;
00186               header.replace ("-header=", "");
00187 
00188               if (find (header) == 0)
00189                 {
00190                   add (header, "", "", "", false, use);
00191                 }
00192             }
00193           else if (word.find ("-trailer=") != cmt_string::npos)
00194             {
00195               trailer = word;
00196               trailer.replace ("-trailer=", "");
00197 
00198               if (find (trailer) == 0)
00199                 {
00200                   add (trailer, "", "", "", false, use);
00201                 }
00202             }
00203         }
00204 
00205       add (name, suffix, header, trailer, need_dependencies, use);
00206     }
00207 }
00208 
00209 /*----------------------------------------------------------*/
00210 Fragment* Fragment::find (const cmt_string& name)
00211 {
00212   static FragmentVector& Fragments = fragments ();
00213 
00214   int fragment_index;
00215 
00216   if (Fragments.size () == 0) return (0);
00217 
00218   for (fragment_index = 0;
00219        fragment_index < Fragments.size ();
00220        fragment_index++)
00221     {
00222       Fragment& fragment = Fragments[fragment_index];
00223 
00224       if (fragment.name == name)
00225         {
00226           return (&fragment);
00227         }
00228     }
00229 
00230   return (0);
00231 }
00232 
00233 /*----------------------------------------------------------*/
00234 void Fragment::add (const cmt_string& name,
00235                     const cmt_string& suffix,
00236                     const cmt_string& header,
00237                     const cmt_string& trailer,
00238                     bool need_dependencies,
00239                     Use* use)
00240 {
00241   static FragmentVector& Fragments = fragments ();
00242 
00243   {
00244     Fragment* fragment;
00245 
00246     if (name == "") return;
00247 
00248     fragment = find (name);
00249     if (fragment != 0)
00250       {
00251         if (suffix != "")
00252           {
00253             fragment->suffix = suffix;
00254           }
00255 
00256         if (header != "")
00257           {
00258             fragment->header = header;
00259           }
00260 
00261         if (trailer != "")
00262           {
00263             fragment->trailer = trailer;
00264           }
00265 
00266         fragment->need_dependencies = need_dependencies;
00267 
00268         fragment->use = use;
00269         return;
00270       }
00271   }
00272 
00273   Fragment& fragment = Fragments.add ();
00274 
00275   fragment.name              = name;
00276   fragment.suffix            = suffix;
00277   fragment.header            = header;
00278   fragment.trailer           = trailer;
00279   fragment.need_dependencies = need_dependencies;
00280   fragment.use               = use;
00281 }
00282 
00283 /*----------------------------------------------------------*/
00284 void Fragment::clear_all ()
00285 {
00286   static FragmentVector& Fragments = fragments ();
00287 
00288   for (int i = 0; i < Fragments.size (); i++)
00289     {
00290       Fragment& f = Fragments[i];
00291       f.clear ();
00292     }
00293 
00294   Fragments.clear ();
00295 }
00296 
00297 /*----------------------------------------------------------*/
00298 Fragment::FragmentVector& Fragment::fragments ()
00299 {
00300   static Database& db = Database::instance ();
00301   static FragmentVector& Fragments = db.fragments ();
00302 
00303   return (Fragments);
00304 }
00305 
00306 /*----------------------------------------------------------*/
00307 Fragment::Fragment ()
00308 {
00309   use = 0;
00310 }
00311 
00312 /*----------------------------------------------------------*/
00313 Fragment::Fragment (const cmt_string& fragment_name)
00314 {
00315   name = fragment_name;
00316   use = 0;
00317   path = "";
00318 }
00319 
00320 /*----------------------------------------------------------*/
00321 Fragment::~Fragment ()
00322 {
00323   use = 0;
00324 }
00325 
00326 /*----------------------------------------------------------*/
00327 void Fragment::clear ()
00328 {
00329   name    = "";
00330   suffix  = "";
00331   header  = "";
00332   trailer = "";
00333   need_dependencies = false;
00334   path = "";
00335   use  = 0;
00336 }
00337 
00338 /*----------------------------------------------------------*/
00339 int Fragment::print ()
00340 {
00341   int result = 1;
00342 
00343   if (name == "") return (0);
00344   
00345   locate ();
00346 
00347   if (use == 0)
00348     {
00349       Use& u = Use::current();
00350       use = &u;
00351     }
00352   
00353   cmt_string the_path = path;
00354 
00355   use->reduce_path (the_path);
00356 
00357   cout << the_path;
00358 
00359   if (suffix != "")
00360     {
00361       cout << "->" << suffix;
00362     }
00363 
00364   cout << endl;
00365 
00366   return (result);
00367 }
00368 
00369 /*----------------------------------------------------------*/
00370 bool Fragment::locate ()
00371 {
00372   cmt_string root_path;
00373 
00374   if (use == 0)
00375     {
00376       // Assume CMT
00377       use = Use::find ("CMT");
00378     }
00379 
00380   use->get_full_path (root_path);
00381 
00382   if (path != "") return (true);
00383 
00384   // First try <root>/fragments/<name> or <root>/fragments/nmake/<name>
00385 
00386   path = root_path;
00387   path += CmtSystem::file_separator ();
00388   path += "fragments";
00389   path += CmtSystem::file_separator ();
00390   
00391   if (Cmt::build_nmake ())
00392     {
00393       path += "nmake";
00394       path += CmtSystem::file_separator ();
00395     }
00396   
00397   path += name;
00398 
00399   if (CmtSystem::test_file (path)) return (true);
00400 
00401   // Then try <root>/fragments/<name> for both Win and Unix
00402 
00403   path = root_path;
00404   path += CmtSystem::file_separator ();
00405   path += "fragments";
00406   path += CmtSystem::file_separator ();
00407   path += name;
00408 
00409   if (CmtSystem::test_file (path)) return (true);
00410 
00411   // Then try <root>/cmt/fragments/<name> or <root>/cmt/fragments/nmake/<name>
00412 
00413   root_path += CmtSystem::file_separator ();
00414 
00415   if (use->style == mgr_style) root_path += "mgr";
00416   else root_path += "cmt";
00417   
00418   root_path += CmtSystem::file_separator ();
00419   root_path += "fragments";
00420   root_path += CmtSystem::file_separator ();
00421   
00422   path = root_path;
00423   
00424   if (Cmt::build_nmake ())
00425     {
00426       path += "nmake";
00427       path += CmtSystem::file_separator ();
00428     }
00429   
00430   path += name;
00431   
00432   if (CmtSystem::test_file (path)) return (true);
00433 
00434   // Then try <root>/cmt/fragments/<name> for both Win and Unix
00435 
00436   path = root_path;
00437   
00438   path += name;
00439 
00440   if (CmtSystem::test_file (path)) return (true);
00441 
00442   return (false);
00443 }
00444 
00445 //--------------------------------------------------
00446 bool Fragment::copy (FILE* out,
00447                      const cmt_string& name,
00448                      int variables, ...)
00449 {
00450   va_list ids;
00451 
00452   Fragment* fragment = Fragment::find (name);
00453   if (fragment == 0) return (false);
00454 
00455   va_start (ids, variables);
00456   bool result = fragment->copy (out, variables, ids);
00457   va_end (ids);
00458 
00459   return (result);
00460 }
00461 
00462 //--------------------------------------------------
00463 bool Fragment::copy (cmt_string& out,
00464                      const cmt_string& name,
00465                      int variables, ...)
00466 {
00467   va_list ids;
00468 
00469   Fragment* fragment = Fragment::find (name);
00470   if (fragment == 0) return (false);
00471 
00472   va_start (ids, variables);
00473   bool result = fragment->copy (out, variables, ids);
00474   va_end (ids);
00475 
00476   return (result);
00477 }
00478 
00479 //--------------------------------------------------
00480 bool Fragment::copy (FILE* out, int variables, ...)
00481 {
00482   va_list ids;
00483 
00484   va_start (ids, variables);
00485   bool result = copy (out, variables, ids);
00486   va_end (ids);
00487 
00488   return (result);
00489 }
00490 
00491 //--------------------------------------------------
00492 bool Fragment::copy (cmt_string& out, int variables, ...)
00493 {
00494   va_list ids;
00495 
00496   va_start (ids, variables);
00497   bool result = copy (out, variables, ids);
00498   va_end (ids);
00499 
00500   return (result);
00501 }
00502 
00503 //--------------------------------------------------
00504 bool Fragment::copy (FILE* out, int variables, va_list ids)
00505 {
00506   static cmt_string cline;
00507 
00508   bool result = copy (cline, variables, ids);
00509   if (result)
00510     {
00511       cline.write (out);
00512       return (true);
00513     }
00514   else
00515     {
00516       return (false);
00517     }
00518 }
00519 
00520 //--------------------------------------------------
00521 bool Fragment::copy (cmt_string& out, int variables, va_list ids)
00522 {
00523   int i;
00524 
00525   if (!locate ()) return (false);
00526 
00527   out.read (path);
00528 
00529   Variable* var = 0;
00530   for (i = 0; i < variables; i++)
00531     {
00532       var = va_arg (ids, Variable*);
00533       out.replace_all (var->macro_braces (), var->value);
00534       out.replace_all (var->macro_pars (), var->value);
00535     }
00536 
00537   return (true);
00538 }
00539 
00540 //--------------------------------------------------
00541 bool Fragment::wincopy (FILE* out, int variables, va_list ids)
00542 {
00543   static cmt_string cline;
00544 
00545   bool result = wincopy (cline, variables, ids);
00546 
00547   if (result)
00548     {
00549       cline.write (out);
00550       return (true);
00551     }
00552   else
00553     {
00554       return (false);
00555     }
00556 }
00557 
00558 //--------------------------------------------------
00559 bool Fragment::wincopy (cmt_string& out, int variables, va_list ids)
00560 {
00561   int i;
00562 
00563   if (!locate ()) return (false);
00564 
00565   out.read (path);
00566 
00567   Variable* var = 0;
00568   for (i = 0; i < variables; i++)
00569     {
00570       var = va_arg (ids, Variable*);
00571       out.replace_all (var->macro_braces (), var->value);
00572       out.replace_all (var->macro_pars (), var->value);
00573     }
00574 
00575   cmt_string pattern;
00576   cmt_string macro_name;
00577   char end_pattern;
00578 
00579   int start = 0;
00580 
00581   for (;;)
00582     {
00583       //
00584       // Try and substitute all ${xxx} or $(xxx) patterns
00585       // using symbol values.
00586       //
00587       int par;
00588       int brace;
00589       int begin;
00590 
00591       par = out.find (start, "$(");
00592       brace = out.find (start, "${");
00593 
00594       if (par == cmt_string::npos)
00595         {
00596           // No parentheses. Look for brace
00597           if (brace == cmt_string::npos)
00598             {
00599               // No pattern, finish the scan.
00600               break;
00601             }
00602 
00603           // Brace found
00604           end_pattern = '}';
00605           begin = brace;
00606         }
00607       else
00608         {
00609           // Parenthese found. Look for closest from {par, brace}
00610           if ((brace == cmt_string::npos) ||
00611               (brace > par))
00612             {
00613               end_pattern = ')';
00614               begin = par;
00615             }
00616           else
00617             {
00618               end_pattern = '}';
00619               begin = brace;
00620             }
00621         }
00622 
00623       // Skip the pattern intro.
00624       start = begin + 2;
00625 
00626       int end;
00627       end = out.find (start, end_pattern);
00628       if (end == cmt_string::npos)
00629         {
00630           // The pattern is a fake one (no ending!)
00631           break;
00632         }
00633 
00634       // This should never happen...
00635       if (end < begin) break;
00636 
00637       // Extract the complete pattern
00638       out.substr (begin, end - begin + 1, pattern);
00639 
00640       // Then only the macro name
00641       out.substr (begin + 2, end - begin - 2, macro_name);
00642 
00643       if (macro_name == "CFG")
00644         {
00645           // This is a Windows reserved keyword...
00646           start = end + 1;
00647         }
00648       else
00649         {
00650           Symbol* macro = Symbol::find (macro_name);
00651           if (macro != 0)
00652             {
00653               // Macro found
00654               cmt_string value = macro->resolve_macro_value ();
00655               //cout << "resolve_macro_value2> value=" << value << endl;
00656               out.replace_all (pattern, value);
00657 
00658               // The substitution will restart from the same place
00659               // allowing for recursive replacements
00660               start = begin;
00661             }
00662           else
00663             {
00664               // Macro not found. Look for env. variable
00665               cmt_string value = CmtSystem::getenv (macro_name);
00666               //cout << "resolve_macro_value3> " << macro_name << "=" << value << endl;
00667               out.replace_all (pattern, value);
00668 
00669               // The substitution will restart from the same place
00670               // allowing for recursive replacements
00671               start = begin;
00672             }
00673         }
00674     }
00675 
00676   // Uniformly install CR-LF doublets.
00677 
00678   out.replace_all ("\r\n", "\n");
00679   out.replace_all ("\n", "\r\n");
00680 
00681   return (true);
00682 }
00683 
00684 
00685 
00686 
00687 
00688 
00689 
00690 
00691 //--------------------------------------------------
00692 bool Fragment::copy (FILE* out,
00693                      const cmt_string& name,
00694                      const Variable::VariableVector& vector, 
00695                      int variables, ...)
00696 {
00697   va_list ids;
00698 
00699   Fragment* fragment = Fragment::find (name);
00700   if (fragment == 0) return (false);
00701 
00702   va_start (ids, variables);
00703   bool result = fragment->copy (out, vector, variables, ids);
00704   va_end (ids);
00705 
00706   return (result);
00707 }
00708 
00709 //--------------------------------------------------
00710 bool Fragment::copy (cmt_string& out,
00711                      const cmt_string& name,
00712                      const Variable::VariableVector& vector, 
00713                      int variables, ...)
00714 {
00715   va_list ids;
00716 
00717   Fragment* fragment = Fragment::find (name);
00718   if (fragment == 0) return (false);
00719 
00720   va_start (ids, variables);
00721   bool result = fragment->copy (out, vector, variables, ids);
00722   va_end (ids);
00723 
00724   return (result);
00725 }
00726 
00727 //--------------------------------------------------
00728 bool Fragment::copy (FILE* out, const Variable::VariableVector& vector, int variables, ...)
00729 {
00730   va_list ids;
00731 
00732   va_start (ids, variables);
00733   bool result = copy (out, vector, variables, ids);
00734   va_end (ids);
00735 
00736   return (result);
00737 }
00738 
00739 //--------------------------------------------------
00740 bool Fragment::copy (cmt_string& out, const Variable::VariableVector& vector, int variables, ...)
00741 {
00742   va_list ids;
00743 
00744   va_start (ids, variables);
00745   bool result = copy (out, vector, variables, ids);
00746   va_end (ids);
00747 
00748   return (result);
00749 }
00750 
00751 //--------------------------------------------------
00752 bool Fragment::copy (FILE* out, const Variable::VariableVector& vector, int variables, va_list ids)
00753 {
00754   static cmt_string cline;
00755 
00756   bool result = copy (cline, vector, variables, ids);
00757   if (result)
00758     {
00759       cline.write (out);
00760       return (true);
00761     }
00762   else
00763     {
00764       return (false);
00765     }
00766 }
00767 
00768 //--------------------------------------------------
00769 bool Fragment::copy (cmt_string& out, const Variable::VariableVector& vector, int variables, va_list ids)
00770 {
00771   int i;
00772 
00773   if (!locate ()) return (false);
00774 
00775   out.read (path);
00776 
00777   Variable* var = 0;
00778 
00779   for (i = 0; i < vector.size (); i++)
00780     {
00781       var = &(vector[i]);
00782       out.replace_all (var->macro_braces (), var->value);
00783       out.replace_all (var->macro_pars (), var->value);
00784     }
00785 
00786   for (i = 0; i < variables; i++)
00787     {
00788       var = va_arg (ids, Variable*);
00789       out.replace_all (var->macro_braces (), var->value);
00790       out.replace_all (var->macro_pars (), var->value);
00791     }
00792 
00793   return (true);
00794 }
00795 
00796 //--------------------------------------------------
00797 bool Fragment::wincopy (FILE* out, const Variable::VariableVector& vector, int variables, va_list ids)
00798 {
00799   static cmt_string cline;
00800 
00801   bool result = wincopy (cline, vector, variables, ids);
00802   if (result)
00803     {
00804       cline.write (out);
00805       return (true);
00806     }
00807   else
00808     {
00809       return (false);
00810     }
00811 }
00812 
00813 //--------------------------------------------------
00814 bool Fragment::wincopy (cmt_string& out, const Variable::VariableVector& vector, 
00815                         int variables, va_list ids)
00816 {
00817   int i;
00818 
00819   if (!locate ()) return (false);
00820 
00821   out.read (path);
00822 
00823   Variable* var = 0;
00824 
00825   for (i = 0; i < vector.size (); i++)
00826     {
00827       var = &(vector[i]);
00828       out.replace_all (var->macro_braces (), var->value);
00829       out.replace_all (var->macro_pars (), var->value);
00830     }
00831 
00832   for (i = 0; i < variables; i++)
00833     {
00834       var = va_arg (ids, Variable*);
00835       out.replace_all (var->macro_braces (), var->value);
00836       out.replace_all (var->macro_pars (), var->value);
00837     }
00838 
00839   cmt_string pattern;
00840   cmt_string macro_name;
00841   char end_pattern;
00842 
00843   int start = 0;
00844 
00845   for (;;)
00846     {
00847       //
00848       // Try and substitute all ${xxx} or $(xxx) patterns
00849       // using symbol values.
00850       //
00851       int par;
00852       int brace;
00853       int begin;
00854 
00855       par = out.find (start, "$(");
00856       brace = out.find (start, "${");
00857 
00858       if (par == cmt_string::npos)
00859         {
00860           // No parentheses. Look for brace
00861           if (brace == cmt_string::npos)
00862             {
00863               // No pattern, finish the scan.
00864               break;
00865             }
00866 
00867           // Brace found
00868           end_pattern = '}';
00869           begin = brace;
00870         }
00871       else
00872         {
00873           // Parenthese found. Look for closest from {par, brace}
00874           if ((brace == cmt_string::npos) ||
00875               (brace > par))
00876             {
00877               end_pattern = ')';
00878               begin = par;
00879             }
00880           else
00881             {
00882               end_pattern = '}';
00883               begin = brace;
00884             }
00885         }
00886 
00887       // Skip the pattern intro.
00888       start = begin + 2;
00889 
00890       int end;
00891       end = out.find (start, end_pattern);
00892       if (end == cmt_string::npos)
00893         {
00894           // The pattern is a fake one (no ending!)
00895           break;
00896         }
00897 
00898       // This should never happen...
00899       if (end < begin) break;
00900 
00901       // Extract the complete pattern
00902       out.substr (begin, end - begin + 1, pattern);
00903 
00904       // Then only the macro name
00905       out.substr (begin + 2, end - begin - 2, macro_name);
00906 
00907       if (macro_name == "CFG")
00908         {
00909           // This is a Windows reserved keyword...
00910           start = end + 1;
00911         }
00912       else
00913         {
00914           Symbol* macro = Symbol::find (macro_name);
00915           if (macro != 0)
00916             {
00917               // Macro found
00918               cmt_string value = macro->resolve_macro_value ();
00919               //cout << "resolve_macro_value2> value=" << value << endl;
00920               out.replace_all (pattern, value);
00921 
00922               // The substitution will restart from the same place
00923               // allowing for recursive replacements
00924               start = begin;
00925             }
00926           else
00927             {
00928               // Macro not found. Look for env. variable
00929               cmt_string value = CmtSystem::getenv (macro_name);
00930               //cout << "resolve_macro_value3> " << macro_name << "=" << value << endl;
00931               out.replace_all (pattern, value);
00932 
00933               // The substitution will restart from the same place
00934               // allowing for recursive replacements
00935               start = begin;
00936             }
00937         }
00938     }
00939 
00940   // Uniformly install CR-LF doublets.
00941 
00942   out.replace_all ("\r\n", "\n");
00943   out.replace_all ("\n", "\r\n");
00944 
00945   return (true);
00946 }
00947 
00948 //--------------------------------------------------
00949 FragmentHandle::FragmentHandle ()
00950 {
00951   _fragment = 0;
00952   _initialized = false;
00953 }
00954 
00955 //--------------------------------------------------
00956 FragmentHandle::FragmentHandle (const cmt_string name) : _name(name)
00957 {
00958   _fragment = 0;
00959   _initialized = false;
00960 }
00961 
00962 //--------------------------------------------------
00963 FragmentHandle& FragmentHandle::operator = (const FragmentHandle& other)
00964 {
00965   _name = other._name;
00966   _fragment = 0;
00967   _initialized = false;
00968 
00969   return (*this);
00970 }
00971 
00972 //--------------------------------------------------
00973 void FragmentHandle::reset ()
00974 {
00975   _fragment = 0;
00976   _initialized = false;
00977 }
00978 
00979 //--------------------------------------------------
00980 void FragmentHandle::set (const cmt_string name)
00981 {
00982   _name = name;
00983   _fragment = 0;
00984   _initialized = false;
00985 }
00986 
00987 //--------------------------------------------------
00988 cmt_string& FragmentHandle::name ()
00989 {
00990   static cmt_string null_string;
00991 
00992   if (!setup ()) return (null_string);
00993 
00994   return (_fragment->name);
00995 }
00996 
00997 //--------------------------------------------------
00998 cmt_string& FragmentHandle::suffix ()
00999 {
01000   static cmt_string null_string;
01001 
01002   if (!setup ()) return (null_string);
01003 
01004   return (_fragment->suffix);
01005 }
01006 
01007 //--------------------------------------------------
01008 cmt_string& FragmentHandle::header ()
01009 {
01010   static cmt_string null_string;
01011 
01012   if (!setup ()) return (null_string);
01013 
01014   return (_fragment->header);
01015 }
01016 
01017 //--------------------------------------------------
01018 cmt_string& FragmentHandle::trailer ()
01019 {
01020   static cmt_string null_string;
01021 
01022   if (!setup ()) return (null_string);
01023 
01024   return (_fragment->trailer);
01025 }
01026 
01027 //--------------------------------------------------
01028 bool FragmentHandle::need_dependencies ()
01029 {
01030   if (!setup ()) return (false);
01031 
01032   return (_fragment->need_dependencies);
01033 }
01034 
01035 //--------------------------------------------------
01036 bool FragmentHandle::copy (FILE* out, int variables, ...)
01037 {
01038   if (!setup ()) return (false);
01039 
01040   va_list ids;
01041 
01042   va_start (ids, variables);
01043   bool result = _fragment->copy (out, variables, ids);
01044   va_end (ids);
01045 
01046   if (!result)
01047     {
01048       cout << "#CMT> Fragment " << _name << " not found" << endl;
01049       _fragment = 0;
01050     }
01051 
01052   return (result);
01053 }
01054 
01055 //--------------------------------------------------
01056 bool FragmentHandle::copy (cmt_string& out, int variables, ...)
01057 {
01058   if (!setup ()) return (false);
01059 
01060   va_list ids;
01061 
01062   va_start (ids, variables);
01063   bool result = _fragment->copy (out, variables, ids);
01064   va_end (ids);
01065 
01066   if (!result)
01067     {
01068       cout << "#CMT> Fragment " << _name << " not found" << endl;
01069       _fragment = 0;
01070     }
01071 
01072   return (result);
01073 }
01074 
01075 //--------------------------------------------------
01076 bool FragmentHandle::wincopy (FILE* out, int variables, ...)
01077 {
01078   if (!setup ()) return (false);
01079 
01080   va_list ids;
01081 
01082   va_start (ids, variables);
01083   bool result = _fragment->wincopy (out, variables, ids);
01084   va_end (ids);
01085 
01086   if (!result)
01087     {
01088       cout << "#CMT> Fragment " << _name << " not found" << endl;
01089       _fragment = 0;
01090     }
01091 
01092   return (result);
01093 }
01094 
01095 //--------------------------------------------------
01096 bool FragmentHandle::wincopy (cmt_string& out, int variables, ...)
01097 {
01098   if (!setup ()) return (false);
01099 
01100   va_list ids;
01101 
01102   va_start (ids, variables);
01103   bool result = _fragment->wincopy (out, variables, ids);
01104   va_end (ids);
01105 
01106   if (!result)
01107     {
01108       cout << "#CMT> Fragment " << _name << " not found" << endl;
01109       _fragment = 0;
01110     }
01111 
01112   return (result);
01113 }
01114 
01115 
01116 
01117 
01118 //--------------------------------------------------
01119 bool FragmentHandle::copy (FILE* out, const Variable::VariableVector& vector, int variables, ...)
01120 {
01121   if (!setup ()) return (false);
01122 
01123   va_list ids;
01124 
01125   va_start (ids, variables);
01126   bool result = _fragment->copy (out, vector, variables, ids);
01127   va_end (ids);
01128 
01129   if (!result)
01130     {
01131       cout << "#CMT> Fragment " << _name << " not found" << endl;
01132       _fragment = 0;
01133     }
01134 
01135   return (result);
01136 }
01137 
01138 //--------------------------------------------------
01139 bool FragmentHandle::copy (cmt_string& out, const Variable::VariableVector& vector, int variables, ...)
01140 {
01141   if (!setup ()) return (false);
01142 
01143   va_list ids;
01144 
01145   va_start (ids, variables);
01146   bool result = _fragment->copy (out, vector, variables, ids);
01147   va_end (ids);
01148 
01149   if (!result)
01150     {
01151       cout << "#CMT> Fragment " << _name << " not found" << endl;
01152       _fragment = 0;
01153     }
01154 
01155   return (result);
01156 }
01157 
01158 //--------------------------------------------------
01159 bool FragmentHandle::wincopy (FILE* out, const Variable::VariableVector& vector, int variables, ...)
01160 {
01161   if (!setup ()) return (false);
01162 
01163   va_list ids;
01164 
01165   va_start (ids, variables);
01166   bool result = _fragment->wincopy (out, vector, variables, ids);
01167   va_end (ids);
01168 
01169   if (!result)
01170     {
01171       cout << "#CMT> Fragment " << _name << " not found" << endl;
01172       _fragment = 0;
01173     }
01174 
01175   return (result);
01176 }
01177 
01178 //--------------------------------------------------
01179 bool FragmentHandle::wincopy (cmt_string& out, 
01180                               const Variable::VariableVector& vector, 
01181                               int variables, ...)
01182 {
01183   if (!setup ()) return (false);
01184 
01185   va_list ids;
01186 
01187   va_start (ids, variables);
01188   bool result = _fragment->wincopy (out, vector, variables, ids);
01189   va_end (ids);
01190 
01191   if (!result)
01192     {
01193       cout << "#CMT> Fragment " << _name << " not found" << endl;
01194       _fragment = 0;
01195     }
01196 
01197   return (result);
01198 }
01199 
01200 //--------------------------------------------------
01201 bool FragmentHandle::setup ()
01202 {
01203   if (!_initialized)
01204     {
01205       _initialized = true;
01206 
01207       _fragment = Fragment::find (_name);
01208       if (_fragment == 0)
01209         {
01210           cout << "#CMT> Fragment " << _name << " not found" << endl;
01211         }
01212     }
01213 
01214   if (_fragment == 0)
01215     {
01216       return (false);
01217     }
01218   else
01219     {
01220       return (true);
01221     }
01222 }

Generated at Mon Jun 10 17:57:46 2002 for CMT by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000