[1] | 1 | #include <stdio.h> |
---|
| 2 | #include <stdlib.h> |
---|
| 3 | #include <string.h> |
---|
| 4 | #include <ctype.h> |
---|
| 5 | |
---|
| 6 | #include "cmt_include.h" |
---|
| 7 | #include "cmt_use.h" |
---|
| 8 | |
---|
| 9 | /*----------------------------------------------------------*/ |
---|
| 10 | /* */ |
---|
| 11 | /* Operations on Include */ |
---|
| 12 | /* */ |
---|
| 13 | /*----------------------------------------------------------*/ |
---|
| 14 | |
---|
| 15 | /*----------------------------------------------------------*/ |
---|
| 16 | void Include::action (const CmtSystem::cmt_string_vector& words, Use* use) |
---|
| 17 | /*----------------------------------------------------------*/ |
---|
| 18 | { |
---|
| 19 | cmt_string name; |
---|
| 20 | |
---|
| 21 | if (use == 0) use = &(Use::current()); |
---|
| 22 | |
---|
| 23 | for (int i = 1; i < words.size (); i++) |
---|
| 24 | { |
---|
| 25 | name = words[i]; |
---|
| 26 | if (name == "") return; |
---|
| 27 | add (name, use); |
---|
| 28 | } |
---|
| 29 | } |
---|
| 30 | |
---|
| 31 | /*----------------------------------------------------------*/ |
---|
| 32 | Include* Include::find (const cmt_string& name, Use* use) |
---|
| 33 | /*----------------------------------------------------------*/ |
---|
| 34 | { |
---|
| 35 | int include_index; |
---|
| 36 | |
---|
| 37 | if (use == 0) use = &(Use::current()); |
---|
| 38 | |
---|
| 39 | if (use->includes.size () == 0) return (0); |
---|
| 40 | |
---|
| 41 | for (include_index = 0; |
---|
| 42 | include_index < use->includes.size (); |
---|
| 43 | include_index++) |
---|
| 44 | { |
---|
| 45 | Include& incl = use->includes[include_index]; |
---|
| 46 | |
---|
| 47 | if (incl.use != use) continue; |
---|
| 48 | |
---|
| 49 | if (incl.name == name) |
---|
| 50 | { |
---|
| 51 | return (&incl); |
---|
| 52 | } |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | return (0); |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | /*----------------------------------------------------------*/ |
---|
| 59 | Include* Include::add (const cmt_string& name, Use* use) |
---|
| 60 | /*----------------------------------------------------------*/ |
---|
| 61 | { |
---|
| 62 | if (name == "") return (0); |
---|
| 63 | |
---|
| 64 | if (use == 0) use = &(Use::current()); |
---|
| 65 | |
---|
| 66 | { |
---|
| 67 | Include* incl; |
---|
| 68 | |
---|
| 69 | incl = find (name, use); |
---|
| 70 | if (incl != 0) return (incl); |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | Include& incl = use->includes.add (); |
---|
| 74 | |
---|
| 75 | incl.name = name; |
---|
| 76 | incl.use = use; |
---|
| 77 | |
---|
| 78 | return (&incl); |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | /*----------------------------------------------------------*/ |
---|
| 82 | void Include::print_all (PrintMode mode) |
---|
| 83 | /*----------------------------------------------------------*/ |
---|
| 84 | { |
---|
| 85 | int number; |
---|
| 86 | int include_number; |
---|
| 87 | Use::UsePtrVector& uses = Use::uses (); |
---|
| 88 | |
---|
| 89 | if (uses.size () > 0) |
---|
| 90 | { |
---|
| 91 | for (number = 0; number < uses.size (); number++) |
---|
| 92 | { |
---|
| 93 | const Use* use = uses[number]; |
---|
| 94 | |
---|
| 95 | if (use->package == "CMT") continue; |
---|
| 96 | |
---|
| 97 | cout << "-I${" << use->prefix << "ROOT}/src "; |
---|
| 98 | |
---|
| 99 | for (include_number = 0; |
---|
| 100 | include_number < use->includes.size (); |
---|
| 101 | include_number++) |
---|
| 102 | { |
---|
| 103 | const Include& incl = use->includes[include_number]; |
---|
| 104 | |
---|
| 105 | cout << "-I" << incl.name << " "; |
---|
| 106 | } |
---|
| 107 | } |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | for (include_number = 0; |
---|
| 111 | include_number < (Use::current()).includes.size (); |
---|
| 112 | include_number++) |
---|
| 113 | { |
---|
| 114 | const Include& incl = (Use::current()).includes[include_number]; |
---|
| 115 | |
---|
| 116 | cout << "-I" << incl.name << " "; |
---|
| 117 | } |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | /*----------------------------------------------------------*/ |
---|
| 121 | void Include::print_filters (PrintMode mode) |
---|
| 122 | /*----------------------------------------------------------*/ |
---|
| 123 | { |
---|
| 124 | int number; |
---|
| 125 | int include_number; |
---|
| 126 | Use::UsePtrVector& uses = Use::uses (); |
---|
| 127 | |
---|
| 128 | if (uses.size () > 0) |
---|
| 129 | { |
---|
| 130 | for (number = 0; number < uses.size (); number++) |
---|
| 131 | { |
---|
| 132 | Use* use = uses[number]; |
---|
| 133 | |
---|
| 134 | cout << "s#" << |
---|
| 135 | ".*" << SLASH << |
---|
| 136 | use->package << SLASH << |
---|
| 137 | use->version << SLASH << |
---|
| 138 | "#$(" << use->prefix << "ROOT)" << SLASH << |
---|
| 139 | "#g" << endl; |
---|
| 140 | |
---|
| 141 | for (include_number = 0; |
---|
| 142 | include_number < use->includes.size (); |
---|
| 143 | include_number++) |
---|
| 144 | { |
---|
| 145 | Include& incl = use->includes[include_number]; |
---|
| 146 | |
---|
| 147 | const cmt_string& d = Cmt::filter_dir (incl.name); |
---|
| 148 | |
---|
| 149 | if (d.size () > 0) |
---|
| 150 | { |
---|
| 151 | cout << "s#" << d << "#" << |
---|
| 152 | incl.name << "#g" << endl; |
---|
| 153 | } |
---|
| 154 | } |
---|
| 155 | } |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | { |
---|
| 159 | const Use* use = &(Use::current()); |
---|
| 160 | |
---|
| 161 | cout << "s#" << ".*" << SLASH << |
---|
| 162 | use->package << SLASH << |
---|
| 163 | use->version << SLASH << |
---|
| 164 | "#$(" << use->prefix << "ROOT)" << SLASH << |
---|
| 165 | "#g" << endl; |
---|
| 166 | |
---|
| 167 | for (include_number = 0; |
---|
| 168 | include_number < use->includes.size (); |
---|
| 169 | include_number++) |
---|
| 170 | { |
---|
| 171 | const Include& incl = use->includes[include_number]; |
---|
| 172 | |
---|
| 173 | const cmt_string& d = Cmt::filter_dir (incl.name); |
---|
| 174 | |
---|
| 175 | if (d.size () > 0) |
---|
| 176 | { |
---|
| 177 | cout << "s#" << d << "#" << |
---|
| 178 | incl.name << "#g" << endl; |
---|
| 179 | } |
---|
| 180 | } |
---|
| 181 | } |
---|
| 182 | } |
---|
| 183 | |
---|
| 184 | /*----------------------------------------------------------*/ |
---|
| 185 | void Include::clear_all () |
---|
| 186 | /*----------------------------------------------------------*/ |
---|
| 187 | { |
---|
| 188 | } |
---|
| 189 | |
---|
| 190 | /*----------------------------------------------------------*/ |
---|
| 191 | Include::Include () |
---|
| 192 | /*----------------------------------------------------------*/ |
---|
| 193 | { |
---|
| 194 | use = 0; |
---|
| 195 | } |
---|
| 196 | |
---|
| 197 | /*----------------------------------------------------------*/ |
---|
| 198 | Include::~Include () |
---|
| 199 | /*----------------------------------------------------------*/ |
---|
| 200 | { |
---|
| 201 | use = 0; |
---|
| 202 | } |
---|
| 203 | |
---|