|
40 | 40 | import java.io.FileOutputStream; |
41 | 41 | import java.io.IOException; |
42 | 42 | import java.io.InputStream; |
| 43 | +import java.io.IOError; |
43 | 44 | import java.io.InputStreamReader; |
44 | 45 | import java.io.OutputStream; |
| 46 | +import java.nio.file.InvalidPathException; |
45 | 47 | import java.nio.file.Path; |
46 | 48 | import java.nio.file.Paths; |
47 | 49 | import java.util.ArrayList; |
@@ -299,7 +301,11 @@ else if (arg.equals("-I")) |
299 | 301 | { |
300 | 302 | if (count < args.length) |
301 | 303 | { |
302 | | - m_includePaths.add("-I".concat(args[count++])); |
| 304 | + String pathStr = args[count++]; |
| 305 | + if (!isIncludePathDuplicated(pathStr)) |
| 306 | + { |
| 307 | + m_includePaths.add("-I".concat(pathStr)); |
| 308 | + } |
303 | 309 | } |
304 | 310 | else |
305 | 311 | { |
@@ -542,6 +548,42 @@ private void showVersion() |
542 | 548 | System.out.println(m_appName + " version " + version); |
543 | 549 | } |
544 | 550 |
|
| 551 | + private boolean isIncludePathDuplicated(String pathToCheck) |
| 552 | + { |
| 553 | + try |
| 554 | + { |
| 555 | + Path path = Paths.get(pathToCheck); |
| 556 | + String absPath = path.toAbsolutePath().toString(); |
| 557 | + boolean isDuplicateFound = false; |
| 558 | + for (String includePath : m_includePaths) |
| 559 | + { |
| 560 | + // include paths are prefixed with "-I" |
| 561 | + if (includePath.length() <= 2) |
| 562 | + { |
| 563 | + continue; |
| 564 | + } |
| 565 | + String absIncludePath = Paths.get(includePath.substring(2)).toAbsolutePath().toString(); |
| 566 | + if (absPath.toLowerCase().equals(absIncludePath.toLowerCase())) |
| 567 | + { |
| 568 | + isDuplicateFound = true; |
| 569 | + break; |
| 570 | + } |
| 571 | + } |
| 572 | + |
| 573 | + if (isDuplicateFound) |
| 574 | + { |
| 575 | + return true; |
| 576 | + } |
| 577 | + |
| 578 | + } |
| 579 | + catch (InvalidPathException | IOError | SecurityException ex) |
| 580 | + { |
| 581 | + // path operations failed, just returning false |
| 582 | + } |
| 583 | + |
| 584 | + return false; |
| 585 | + } |
| 586 | + |
545 | 587 | public static void printHelp() |
546 | 588 | { |
547 | 589 | System.out.println(m_appName + " usage:"); |
|
0 commit comments