From a4f7f33b748840f9aa93d6cdee9e6cbd54737606 Mon Sep 17 00:00:00 2001 From: nvt-se Date: Tue, 4 Aug 2009 15:19:07 +0000 Subject: [PATCH] simplified the argument interface. cleaned up some code --- tools/coffee-manager/README.TXT | 5 +- .../se/sics/coffee/CoffeeFS.java | 8 +- .../se/sics/coffee/CoffeeManager.java | 81 +++++++++---------- 3 files changed, 43 insertions(+), 51 deletions(-) diff --git a/tools/coffee-manager/README.TXT b/tools/coffee-manager/README.TXT index 0af184596..abef724e2 100644 --- a/tools/coffee-manager/README.TXT +++ b/tools/coffee-manager/README.TXT @@ -8,8 +8,7 @@ Building: Usage: -java -jar coffee.jar [-i|e ] [-r ] - [-l|s] +java -jar coffee.jar [-i|e|r ] [-l|s] Options: @@ -21,4 +20,4 @@ Options: Author: -Nicols Tsiftes +Nicolas Tsiftes diff --git a/tools/coffee-manager/se/sics/coffee/CoffeeFS.java b/tools/coffee-manager/se/sics/coffee/CoffeeFS.java index e423fb8d6..cd5889298 100644 --- a/tools/coffee-manager/se/sics/coffee/CoffeeFS.java +++ b/tools/coffee-manager/se/sics/coffee/CoffeeFS.java @@ -28,7 +28,7 @@ * * This file is part of the Contiki operating system. * - * $Id: CoffeeFS.java,v 1.2 2009/08/04 10:39:13 nvt-se Exp $ + * $Id: CoffeeFS.java,v 1.3 2009/08/04 15:19:08 nvt-se Exp $ * * @author Nicolas Tsiftes * @@ -178,14 +178,14 @@ public class CoffeeFS { files.remove(file.getName()); } - public boolean extractFile(String inputFile, String outputFile) throws IOException { - CoffeeFile file = files.get(inputFile); + public boolean extractFile(String filename) throws IOException { + CoffeeFile file = files.get(filename); if(file == null) { return false; } - file.saveContents(outputFile); + file.saveContents(filename); return true; } } diff --git a/tools/coffee-manager/se/sics/coffee/CoffeeManager.java b/tools/coffee-manager/se/sics/coffee/CoffeeManager.java index 581cb3f80..c65a6f7ad 100644 --- a/tools/coffee-manager/se/sics/coffee/CoffeeManager.java +++ b/tools/coffee-manager/se/sics/coffee/CoffeeManager.java @@ -28,7 +28,7 @@ * * This file is part of the Contiki operating system. * - * $Id: CoffeeManager.java,v 1.1 2009/08/04 10:36:53 nvt-se Exp $ + * $Id: CoffeeManager.java,v 1.2 2009/08/04 15:19:08 nvt-se Exp $ * * @author Nicolas Tsiftes * @@ -44,23 +44,16 @@ import java.util.regex.Pattern; public class CoffeeManager { private static CoffeeFS coffeeFS; - private static final int COMMAND_NULL = 0; - private static final int COMMAND_INSERT = 1; - private static final int COMMAND_EXTRACT = 2; - private static final int COMMAND_REMOVE = 3; - private static final int COMMAND_LIST = 4; - private static final int COMMAND_STATS = 5; + public enum Command { INSERT, EXTRACT, REMOVE, LIST, STATS }; public static void main(String args[]) { String platform = "sky"; String usage = "Usage: java -jar coffee.jar "; - int command = COMMAND_NULL; - String coffeeFile = ""; - String localFile = ""; + Command command = Command.STATS; + String filename = ""; String fsImage = ""; - usage += "[-i|e ] "; - usage += "[-r ] "; + usage += "[-i|e|r ] "; usage += "[-l|s] "; usage += ""; @@ -77,26 +70,19 @@ public class CoffeeManager { System.exit(1); } - if(args[0].equals("-i") || args[0].equals("-e")) { - if(args.length != 4) { - System.err.println(usage); - System.exit(1); - } - if(args[0].equals("-i")) { - command = COMMAND_INSERT; - } else { - command = COMMAND_EXTRACT; - } - coffeeFile = args[1]; - localFile = args[2]; - fsImage = args[3]; - } else if (args[0].equals("-r")) { + if(args[0].equals("-i") || args[0].equals("-e") || args[0].equals("-r")) { if(args.length != 3) { System.err.println(usage); System.exit(1); } - command = COMMAND_REMOVE; - coffeeFile = args[1]; + if(args[0].equals("-i")) { + command = Command.INSERT; + } else if (args[0].equals("-r")) { + command = Command.REMOVE; + } else { + command = Command.EXTRACT; + } + filename = args[1]; fsImage = args[2]; } else { if(args.length != 2) { @@ -104,9 +90,9 @@ public class CoffeeManager { System.exit(1); } if(args[0].equals("-l")) { - command = COMMAND_LIST; + command = Command.LIST; } else { - command = COMMAND_STATS; + command = Command.STATS; } fsImage = args[1]; } @@ -116,30 +102,37 @@ public class CoffeeManager { CoffeeConfiguration conf = new CoffeeConfiguration(platform + ".properties"); coffeeFS = new CoffeeFS(new CoffeeImageFile(fsImage, conf)); switch (command) { - case COMMAND_INSERT: - if(coffeeFS.getFiles().get(localFile) != null) { - System.err.println("error: file \"" + localFile + "\" already exists"); + case INSERT: + if(coffeeFS.getFiles().get(filename) != null) { + System.err.println("error: file \"" + + filename + "\" already exists"); break; } - if(coffeeFS.insertFile(localFile) != null) { - System.out.println("Inserted the local file \"" + localFile + "\" into the file system image"); + if(coffeeFS.insertFile(filename) != null) { + System.out.println("Inserted the local file \"" + + filename + + "\" into the file system image"); } break; - case COMMAND_EXTRACT: - if(coffeeFS.extractFile(coffeeFile, localFile) == false) { - System.err.println("Inexistent file: " + coffeeFile); + case EXTRACT: + if(coffeeFS.extractFile(filename) == false) { + System.err.println("Inexistent file: " + + filename); System.exit(1); } - System.out.println("Saved the file \"" + coffeeFile + "\" from the system image into the local file \"" + localFile + "\""); + System.out.println("Saved the file \"" + + filename + "\""); break; - case COMMAND_REMOVE: - coffeeFS.removeFile(coffeeFile); - System.out.println("Removed the file \"" + coffeeFile + "\" from the Coffee file system image"); + case REMOVE: + coffeeFS.removeFile(filename); + System.out.println("Removed the file \"" + + filename + + "\" from the Coffee file system image"); break; - case COMMAND_LIST: + case LIST: printFiles(coffeeFS.getFiles()); break; - case COMMAND_STATS: + case STATS: printStatistics(coffeeFS); break; default: