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