|
41 | 41 | import java.io.FileOutputStream; |
42 | 42 | import java.io.IOException; |
43 | 43 | import java.io.InputStream; |
| 44 | +import java.io.IOError; |
44 | 45 | import java.io.InputStreamReader; |
45 | 46 | import java.io.OutputStream; |
| 47 | +import java.nio.file.InvalidPathException; |
46 | 48 | import java.nio.file.Files; |
47 | 49 | import java.nio.file.Path; |
48 | 50 | import java.nio.file.Paths; |
@@ -310,7 +312,11 @@ else if (arg.equals("-I")) |
310 | 312 | { |
311 | 313 | if (count < args.length) |
312 | 314 | { |
313 | | - m_includePaths.add("-I".concat(args[count++])); |
| 315 | + String pathStr = args[count++]; |
| 316 | + if (!isIncludePathDuplicated(pathStr)) |
| 317 | + { |
| 318 | + m_includePaths.add("-I".concat(pathStr)); |
| 319 | + } |
314 | 320 | } |
315 | 321 | else |
316 | 322 | { |
@@ -551,6 +557,42 @@ private void showVersion() |
551 | 557 | System.out.println(m_appName + " version " + version); |
552 | 558 | } |
553 | 559 |
|
| 560 | + private boolean isIncludePathDuplicated(String pathToCheck) |
| 561 | + { |
| 562 | + try |
| 563 | + { |
| 564 | + Path path = Paths.get(pathToCheck); |
| 565 | + tring absPath = path.toAbsolutePath().toString(); |
| 566 | + boolean isDuplicateFound = false; |
| 567 | + for (String includePath : m_includePaths) |
| 568 | + { |
| 569 | + // include paths are prefixed with "-I" |
| 570 | + if (includePath.length() <= 2) |
| 571 | + { |
| 572 | + continue; |
| 573 | + } |
| 574 | + String absIncludePath = Paths.get(includePath.substring(2)).toAbsolutePath().toString(); |
| 575 | + if (absPath.toLowerCase().equals(absIncludePath.toLowerCase())) |
| 576 | + { |
| 577 | + isDuplicateFound = true; |
| 578 | + break; |
| 579 | + } |
| 580 | + } |
| 581 | + |
| 582 | + if (isDuplicateFound) |
| 583 | + { |
| 584 | + return true; |
| 585 | + } |
| 586 | + |
| 587 | + } |
| 588 | + catch (InvalidPathException | IOError | SecurityException ex) |
| 589 | + { |
| 590 | + // path operations failed, just returning false |
| 591 | + } |
| 592 | + |
| 593 | + return false; |
| 594 | + } |
| 595 | + |
554 | 596 | public static void printHelp() |
555 | 597 | { |
556 | 598 | System.out.println(m_appName + " usage:"); |
|
0 commit comments