00001
00002
00003
00004
00005
00006
00007 #include
00008 #include
00009 #include
00010 #include
00011
00012 #include "cmt_script.h"
00013 #include "cmt_use.h"
00014
00015
00016
00017
00018
00019
00020
00021
00022 void Script::action (const CmtSystem::cmt_string_vector& words,
00023 ScriptType type,
00024 Use* use)
00025 {
00026 cmt_string name;
00027 Script* script;
00028
00029 if (use == 0) use = &(Use::current());
00030
00031 name = words[1];
00032 if (name == "") return;
00033
00034 script = add (name, type, use);
00035 }
00036
00037
00038 Script* Script::find (const cmt_string& name, Use* use)
00039 {
00040 int script_index;
00041
00042 if (use == 0) use = &(Use::current());
00043
00044 if (use->scripts.size () == 0) return (0);
00045
00046 for (script_index = 0;
00047 script_index < use->scripts.size ();
00048 script_index++)
00049 {
00050 Script& script = use->scripts[script_index];
00051
00052 if (script.name == name)
00053 {
00054 return (&script);
00055 }
00056 }
00057
00058 return (0);
00059 }
00060
00061
00062 Script* Script::add (const cmt_string& name, ScriptType type, Use* use)
00063 {
00064 cmt_string short_name = name;
00065
00066 if (use == 0) use = &(Use::current());
00067
00068 int pos;
00069
00070 pos = short_name.find (".csh");
00071 if (pos != cmt_string::npos)
00072 {
00073 short_name.erase (pos);
00074 }
00075
00076 pos = short_name.find (".sh");
00077 if (pos != cmt_string::npos)
00078 {
00079 short_name.erase (pos);
00080 }
00081
00082 {
00083 Script* script;
00084
00085 if (short_name == "") return (0);
00086 script = find (short_name, use);
00087 if (script != 0)
00088 {
00089 script->type = type;
00090 return (script);
00091 }
00092 }
00093
00094 Script& script = use->scripts.add ();
00095
00096 script.name = short_name;
00097 script.type = type;
00098
00099 return (&script);
00100 }
00101
00102
00103 void Script::all_print_clean (PrintMode mode)
00104 {
00105 int number;
00106 int script_number;
00107 Use::UsePtrVector& uses = Use::get_ordered_uses ();
00108
00109 if (uses.size () > 0)
00110 {
00111 for (number = 0; number < uses.size (); number++)
00112 {
00113 const Use* use = uses[number];
00114
00115 Package* p = use->get_package ();
00116 if (p->is_cmt ()) continue;
00117
00118 for (script_number = 0;
00119 script_number < use->scripts.size ();
00120 script_number++)
00121 {
00122 Script& script = use->scripts[script_number];
00123
00124 if (script.type == CleanupScript)
00125 {
00126 if (script.print (mode, use)) cout << "; ";
00127 }
00128 }
00129 }
00130 }
00131 }
00132
00133
00134 void Script::all_print (PrintMode mode)
00135 {
00136 int number;
00137 int script_number;
00138 Use::UsePtrVector& uses = Use::get_ordered_uses ();
00139
00140 if (uses.size () > 0)
00141 {
00142 for (number = 0; number < uses.size (); number++)
00143 {
00144 const Use* use = uses[number];
00145
00146 Package* p = use->get_package ();
00147 if (p->is_cmt ()) continue;
00148
00149 for (script_number = 0;
00150 script_number < use->scripts.size ();
00151 script_number++)
00152 {
00153 Script& script = use->scripts[script_number];
00154
00155 if (script.type == SetupScript)
00156 {
00157 if (script.print (mode, use)) cout << "; ";
00158 }
00159 }
00160 }
00161 }
00162
00163 {
00164 const Use& use = Use::current ();
00165
00166 for (script_number = 0;
00167 script_number < use.scripts.size ();
00168 script_number++)
00169 {
00170 Script& script = use.scripts[script_number];
00171
00172 if (script.type == SetupScript)
00173 {
00174 if (script.print (mode, &use)) cout << "; ";
00175 }
00176 }
00177 }
00178 }
00179
00180
00181 void Script::clear_all ()
00182 {
00183 }
00184
00185
00186 Script::Script ()
00187 {
00188 }
00189
00190
00191 Script::~Script ()
00192 {
00193 }
00194
00195
00196 int Script::print (PrintMode mode, const Use* use)
00197 {
00198 int result = 1;
00199 cmt_string suffix;
00200
00201 if (name == "") return (0);
00202
00203 switch (mode)
00204 {
00205 case Csh :
00206 suffix = ".csh";
00207 cout << "source ";
00208 break;
00209 case Sh :
00210 suffix = ".sh";
00211 cout << ". ";
00212 break;
00213 }
00214
00215 if (name.find (SLASH) == cmt_string::npos)
00216 {
00217 cout << "${" << use->prefix << "ROOT}/";
00218 if (use->style == cmt_style) cout << "cmt/";
00219 else cout << "mgr/";
00220 }
00221
00222 cout << name << suffix;
00223
00224 return (result);
00225 }