Improving Seaspider's recursive method.
authorSafey A.Halim <safey.allah@gmail.com>
Thu, 28 Oct 2010 17:38:58 +0000 (17:38 +0000)
committerSafey A.Halim <safey.allah@gmail.com>
Thu, 28 Oct 2010 17:38:58 +0000 (17:38 +0000)
src/monkey/seaspider/org/gnunet/seaspider/Seaspider.java

index 0c1968eaf2d81c40b26d7b106e32d980625421fd..c9b54c6d5ad37e364fde124815ba5981eb80a162 100644 (file)
@@ -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");
                 }
         }
      }