diff options
author | Melanie Thielker | 2009-07-06 23:53:47 +0000 |
---|---|---|
committer | Melanie Thielker | 2009-07-06 23:53:47 +0000 |
commit | 7d5b620e6ba9315a777d7c1b2dee370a3c3707df (patch) | |
tree | 349bbaa62183fd9ddf782a4d11c83959dbc34d8a /Prebuild/src | |
parent | Change fields and methods in LSL API from private to protected, make some (diff) | |
download | opensim-SC_OLD-7d5b620e6ba9315a777d7c1b2dee370a3c3707df.zip opensim-SC_OLD-7d5b620e6ba9315a777d7c1b2dee370a3c3707df.tar.gz opensim-SC_OLD-7d5b620e6ba9315a777d7c1b2dee370a3c3707df.tar.bz2 opensim-SC_OLD-7d5b620e6ba9315a777d7c1b2dee370a3c3707df.tar.xz |
Thank you, mcortez, for a patch to prebuild to allow includes with wildcards.
Fixes Mantis #3860
Diffstat (limited to 'Prebuild/src')
-rw-r--r-- | Prebuild/src/Core/Parse/Preprocessor.cs | 97 |
1 files changed, 86 insertions, 11 deletions
diff --git a/Prebuild/src/Core/Parse/Preprocessor.cs b/Prebuild/src/Core/Parse/Preprocessor.cs index 013f8e1..9ac07b9 100644 --- a/Prebuild/src/Core/Parse/Preprocessor.cs +++ b/Prebuild/src/Core/Parse/Preprocessor.cs | |||
@@ -449,22 +449,36 @@ namespace Prebuild.Core.Parse | |||
449 | throw new WarningException("An <?include ?> node was found, but it did not specify the file attribute."); | 449 | throw new WarningException("An <?include ?> node was found, but it did not specify the file attribute."); |
450 | } | 450 | } |
451 | 451 | ||
452 | // Push current reader back onto the stack. | ||
453 | readerStack.Push(reader); | ||
454 | |||
452 | // Pull the file out from the regex and make sure it is a valid file before using it. | 455 | // Pull the file out from the regex and make sure it is a valid file before using it. |
453 | string filename = matches[0].Groups[1].Value; | 456 | string filename = matches[0].Groups[1].Value; |
454 | FileInfo includeFile = new FileInfo(filename); | ||
455 | 457 | ||
456 | if(!includeFile.Exists) | 458 | filename = String.Join(Path.DirectorySeparatorChar.ToString(), filename.Split(new char[] { '/', '\\' })); |
457 | { | ||
458 | throw new WarningException("Cannot include file: " + includeFile.FullName); | ||
459 | } | ||
460 | 459 | ||
461 | // Create a new reader object for this file. Then put the old reader back on the stack and start | 460 | if (!filename.Contains("*")) |
462 | // processing using this new XML reader. | 461 | { |
463 | XmlReader newReader = new XmlTextReader(includeFile.Open(FileMode.Open, FileAccess.Read, FileShare.Read)); | 462 | FileInfo includeFile = new FileInfo(filename); |
463 | |||
464 | if (!includeFile.Exists) | ||
465 | { | ||
466 | throw new WarningException("Cannot include file: " + includeFile.FullName); | ||
467 | } | ||
468 | |||
469 | // Create a new reader object for this file, and push it onto the stack | ||
470 | XmlReader newReader = new XmlTextReader(includeFile.Open(FileMode.Open, FileAccess.Read, FileShare.Read)); | ||
471 | readerStack.Push(newReader); | ||
472 | } | ||
473 | else | ||
474 | { | ||
475 | WildCardInclude(readerStack, filename); | ||
476 | } | ||
477 | |||
478 | // continue reading with whatever reader is on the top of the stack | ||
479 | reader = (XmlReader)readerStack.Pop(); | ||
480 | ignore = true; | ||
464 | 481 | ||
465 | readerStack.Push(reader); | ||
466 | reader = newReader; | ||
467 | ignore = true; | ||
468 | break; | 482 | break; |
469 | 483 | ||
470 | case "if": | 484 | case "if": |
@@ -577,6 +591,67 @@ namespace Prebuild.Core.Parse | |||
577 | return xmlText.ToString(); | 591 | return xmlText.ToString(); |
578 | } | 592 | } |
579 | 593 | ||
594 | private static void WildCardInclude(Stack readerStack, string include) | ||
595 | { | ||
596 | if (!include.Contains("*")) | ||
597 | { | ||
598 | return; | ||
599 | } | ||
600 | |||
601 | // Console.WriteLine("Processing {0}", include); | ||
602 | |||
603 | // Break up the include into pre and post wildcard sections | ||
604 | string preWildcard = include.Substring(0, include.IndexOf("*")); | ||
605 | string postWildcard = include.Substring(include.IndexOf("*") + 2); | ||
606 | |||
607 | // If preWildcard is a directory, recurse | ||
608 | if (Directory.Exists(preWildcard)) | ||
609 | { | ||
610 | foreach (string dirPath in Directory.GetDirectories(preWildcard)) | ||
611 | { | ||
612 | Console.WriteLine("Scanning : {0}", dirPath); | ||
613 | |||
614 | string includeFile = Path.Combine(dirPath, postWildcard); | ||
615 | if (includeFile.Contains("*")) | ||
616 | { | ||
617 | // postWildcard included another wildcard, recurse. | ||
618 | WildCardInclude(readerStack, includeFile); | ||
619 | } | ||
620 | else | ||
621 | { | ||
622 | FileInfo file = new FileInfo(includeFile); | ||
623 | if (file.Exists) | ||
624 | { | ||
625 | Console.WriteLine("Including File: {0}", includeFile); | ||
626 | XmlReader newReader = new XmlTextReader(file.Open(FileMode.Open, FileAccess.Read, FileShare.Read)); | ||
627 | readerStack.Push(newReader); | ||
628 | } | ||
629 | } | ||
630 | } | ||
631 | } | ||
632 | else | ||
633 | { | ||
634 | // preWildcard is not a path to a directory, so the wildcard is in the filename | ||
635 | string searchFilename = Path.GetFileName(preWildcard.Substring(preWildcard.IndexOf("/") + 1) + "*" + postWildcard); | ||
636 | // Console.WriteLine("searchFilename: {0}", searchFilename); | ||
637 | |||
638 | string searchDirectory = Path.GetDirectoryName(preWildcard); | ||
639 | // Console.WriteLine("searchDirectory: {0}", searchDirectory); | ||
640 | |||
641 | foreach (string includeFile in Directory.GetFiles(searchDirectory, searchFilename)) | ||
642 | { | ||
643 | FileInfo file = new FileInfo(includeFile); | ||
644 | if (file.Exists) | ||
645 | { | ||
646 | Console.WriteLine("Including File: {0}", includeFile); | ||
647 | XmlReader newReader = new XmlTextReader(file.Open(FileMode.Open, FileAccess.Read, FileShare.Read)); | ||
648 | readerStack.Push(newReader); | ||
649 | } | ||
650 | } | ||
651 | } | ||
652 | |||
653 | } | ||
654 | |||
580 | #endregion | 655 | #endregion |
581 | } | 656 | } |
582 | } | 657 | } |