| 215 | //----------------------------------------------------------------------------- |
| 216 | |
| 217 | bool expandOldScriptFilename(char *filename, U32 size, const char *src) |
| 218 | { |
| 219 | const StringTableEntry cbName = CodeBlock::getCurrentCodeBlockName(); |
| 220 | if (!cbName) |
| 221 | { |
| 222 | dStrcpy(filename, src); |
| 223 | return true; |
| 224 | } |
| 225 | |
| 226 | const char *slash; |
| 227 | if (dStrncmp(src, "~/", 2) == 0) |
| 228 | // tilde path means load from current codeblock/mod root |
| 229 | slash = dStrchr(cbName, '/'); |
| 230 | else if (dStrncmp(src, "./", 2) == 0) |
| 231 | // dot path means load from current codeblock/mod path |
| 232 | slash = dStrrchr(cbName, '/'); |
| 233 | else if (dStrncmp(src, "^", 1) == 0) |
| 234 | { |
| 235 | Platform::makeFullPathName(src + 1, filename, size); |
| 236 | return true; |
| 237 | } |
| 238 | else |
| 239 | { |
| 240 | // otherwise path must be fully specified |
| 241 | if (dStrlen(src) > size) |
| 242 | { |
| 243 | Con::errorf("Buffer overflow attempting to expand filename: %s", src); |
| 244 | *filename = 0; |
| 245 | return false; |
| 246 | } |
| 247 | dStrcpy(filename, src); |
| 248 | return true; |
| 249 | } |
| 250 | |
| 251 | if (slash == NULL) |
| 252 | { |
| 253 | Con::errorf("Illegal CodeBlock path detected (no mod directory): %s", cbName); |
| 254 | *filename = 0; |
| 255 | return false; |
| 256 | } |
| 257 | |
| 258 | U32 length = slash-cbName; |
| 259 | if ((length+dStrlen(src)) > size) |
| 260 | { |
| 261 | Con::errorf("Buffer overflow attempting to expand filename: %s", src); |
| 262 | *filename = 0; |
| 263 | return false; |
| 264 | } |
| 265 | |
| 266 | dStrncpy(filename, cbName, length); |
| 267 | dStrcpy(filename+length, src+1); |
| 268 | return true; |
| 269 | } |
| 270 | |
| 271 | //----------------------------------------------------------------------------- |
| 272 | |