From 6789d36f3d5e226c39457e36fc6c6887ead826d1 Mon Sep 17 00:00:00 2001 From: "Safey A.Halim" Date: Thu, 28 Oct 2010 17:38:58 +0000 Subject: Improving Seaspider's recursive method. --- .../seaspider/org/gnunet/seaspider/Seaspider.java | 32 ++++++++++------------ 1 file changed, 15 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/monkey/seaspider/org/gnunet/seaspider/Seaspider.java b/src/monkey/seaspider/org/gnunet/seaspider/Seaspider.java index 0c1968eaf..c9b54c6d5 100644 --- a/src/monkey/seaspider/org/gnunet/seaspider/Seaspider.java +++ b/src/monkey/seaspider/org/gnunet/seaspider/Seaspider.java @@ -65,28 +65,24 @@ public class Seaspider { } - private static void parseRecursively(String dirPath) + private static void parseRecursively(String path) { - File dir = new File(dirPath); + File file = new File(path); - if (!dir.isDirectory()) { - if (dirPath.endsWith(".c")) { - doParseFile(dirPath); - return; - } else /* Probably the Database file */ + if (!file.isDirectory()) { + if (path.endsWith(".db")) return; + /* A source file */ + doParseFile(path); + return; } - System.out.println("Reading from: " + dirPath + " source directory..."); - String[] dirContents = dir.list(filter);/* Only directories and .c files */ + /* A source directory */ + System.out.println("Reading from: " + path + " source directory..."); + String[] dirContents = file.list(filter);/* Only directories and .c files */ for (int i = 0; i < dirContents.length; i++) { - String fullPath = dirPath + "/" + dirContents[i]; - File file = new File(fullPath); - - if (file.isDirectory()) - parseRecursively(fullPath); - else - doParseFile(fullPath); /* Path is for a file */ + String fullPath = path + "/" + dirContents[i]; + parseRecursively(fullPath); } } @@ -109,8 +105,10 @@ public class Seaspider { /* Should be a valid path for a file or a directory */ File file = new File(args[i]); if (!file.exists()) { - System.err.println("\"" + args[i]+ "\" is an invalid file or directory location"); + System.err.println("\"" + args[i] + "\" is an invalid file or directory location"); System.exit(1); + } else if (!file.isDirectory() && !args[i].endsWith(".c")) { + System.err.println("\"" + args[i] + "\" only source files can be parsed"); } } } -- cgit v1.2.3