#include <cmt_fragment.h>
Collaboration diagram for Fragment:
Public Types | |
typedef cmt_vector<Fragment> | FragmentVector |
Public Methods | |
Fragment () | |
Fragment (const cmt_string& fragment_name) | |
~Fragment () | |
void | clear () |
int | print () |
bool | locate () |
bool | copy (FILE* out, int variables, ...) |
bool | copy (cmt_string& out, int variables, ...) |
bool | copy (FILE* out, int variables, va_list ids) |
bool | copy (cmt_string& out, int variables, va_list ids) |
bool | wincopy (FILE* out, int variables, va_list ids) |
bool | wincopy (cmt_string& out, int variables, va_list ids) |
bool | copy (FILE* out, const Variable::VariableVector& vector, int variables, ...) |
bool | copy (cmt_string& out, const Variable::VariableVector& vector, int variables, ...) |
bool | copy (FILE* out, const Variable::VariableVector& vector, int variables, va_list ids) |
bool | copy (cmt_string& out, const Variable::VariableVector& vector, int variables, va_list ids) |
bool | wincopy (FILE* out, const Variable::VariableVector& vector, int variables, va_list ids) |
bool | wincopy (cmt_string& out, const Variable::VariableVector& vector, int variables, va_list ids) |
Public Attributes | |
cmt_string | name |
cmt_string | suffix |
cmt_string | header |
cmt_string | trailer |
bool | need_dependencies |
cmt_string | path |
UseRef | use |
Static Public Methods | |
void | action (const CmtSystem::cmt_string_vector& words, Use* use) |
Fragment* | find (const cmt_string& name) |
void | add (const cmt_string& name, const cmt_string& suffix, const cmt_string& header, const cmt_string& trailer, bool need_dependencies, Use* use) |
void | show (const cmt_string& name) |
void | show_all () |
void | clear_all () |
bool | copy (FILE* out, const cmt_string& name, int variables, ...) |
bool | copy (cmt_string& out, const cmt_string& name, int variables, ...) |
bool | copy (FILE* out, const cmt_string& name, const Variable::VariableVector& vector, int variables, ...) |
bool | copy (cmt_string& out, const cmt_string& name, const Variable::VariableVector& vector, int variables, ...) |
FragmentVector& | fragments () |
|
Definition at line 47 of file cmt_fragment.h. |
|
Definition at line 307 of file cmt_fragment.cxx. 00308 { 00309 use = 0; 00310 } |
|
Definition at line 313 of file cmt_fragment.cxx. 00314 { 00315 name = fragment_name; 00316 use = 0; 00317 path = ""; 00318 } |
|
Definition at line 321 of file cmt_fragment.cxx. 00322 { 00323 use = 0; 00324 } |
|
Definition at line 158 of file cmt_fragment.cxx. Referenced by Cmt::select(). 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 } |
|
Definition at line 234 of file cmt_fragment.cxx. Referenced by action(). 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 } |
|
Definition at line 327 of file cmt_fragment.cxx. Referenced by clear_all(). 00328 { 00329 name = ""; 00330 suffix = ""; 00331 header = ""; 00332 trailer = ""; 00333 need_dependencies = false; 00334 path = ""; 00335 use = 0; 00336 } |
|
Definition at line 284 of file cmt_fragment.cxx. Referenced by Database::clear(). |
|
Definition at line 769 of file cmt_fragment.cxx. 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 } |
|
Definition at line 752 of file cmt_fragment.cxx. 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 } |
|
Definition at line 740 of file cmt_fragment.cxx. 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 } |
|
Definition at line 728 of file cmt_fragment.cxx. 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 } |
|
Definition at line 521 of file cmt_fragment.cxx. 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 } |
|
Definition at line 504 of file cmt_fragment.cxx. 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 } |
|
Definition at line 492 of file cmt_fragment.cxx. 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 } |
|
Definition at line 480 of file cmt_fragment.cxx. 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 } |
|
Definition at line 710 of file cmt_fragment.cxx. 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 } |
|
Definition at line 692 of file cmt_fragment.cxx. 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 } |
|
Definition at line 463 of file cmt_fragment.cxx. 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 } |
|
Definition at line 446 of file cmt_fragment.cxx. Referenced by FragmentHandle::copy(), and copy(). 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 } |
|
Definition at line 210 of file cmt_fragment.cxx. Referenced by action(), add(), copy(), FragmentHandle::setup(), and show(). 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 } |
|
Definition at line 298 of file cmt_fragment.cxx. Referenced by add(), clear_all(), find(), and show_all(). 00299 { 00300 static Database& db = Database::instance (); 00301 static FragmentVector& Fragments = db.fragments (); 00302 00303 return (Fragments); 00304 } |
|
Definition at line 370 of file cmt_fragment.cxx. Referenced by copy(), print(), and wincopy(). 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 } |
|
Definition at line 339 of file cmt_fragment.cxx. Referenced by show(), and show_all(). 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 } |
|
Definition at line 129 of file cmt_fragment.cxx. Referenced by Cmt::do_show_fragment(). 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 } |
|
Definition at line 143 of file cmt_fragment.cxx. Referenced by Cmt::do_show_fragments(). 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 } |
|
Definition at line 814 of file cmt_fragment.cxx. 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 } |
|
Definition at line 797 of file cmt_fragment.cxx. 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 } |
|
Definition at line 559 of file cmt_fragment.cxx. 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 } |
|
Definition at line 541 of file cmt_fragment.cxx. Referenced by FragmentHandle::wincopy(), and wincopy(). 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 } |
|
Definition at line 94 of file cmt_fragment.h. |
|
Definition at line 92 of file cmt_fragment.h. |
|
Definition at line 96 of file cmt_fragment.h. |
|
Definition at line 97 of file cmt_fragment.h. |
|
Definition at line 93 of file cmt_fragment.h. |
|
Definition at line 95 of file cmt_fragment.h. |
|
Definition at line 98 of file cmt_fragment.h. |