simplified the argument interface. cleaned up some code
This commit is contained in:
parent
6612a77d66
commit
a4f7f33b74
|
@ -8,8 +8,7 @@ Building:
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
|
|
||||||
java -jar coffee.jar [-i|e <Coffee file> <file>] [-r <Coffee file>]
|
java -jar coffee.jar [-i|e|r <file>] [-l|s] <file system image>
|
||||||
[-l|s] <file system image>
|
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
|
|
||||||
|
@ -21,4 +20,4 @@ Options:
|
||||||
|
|
||||||
Author:
|
Author:
|
||||||
|
|
||||||
Nicols Tsiftes <nvt@sics.se>
|
Nicolas Tsiftes <nvt@sics.se>
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
*
|
*
|
||||||
* This file is part of the Contiki operating system.
|
* 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
|
* @author Nicolas Tsiftes
|
||||||
*
|
*
|
||||||
|
@ -178,14 +178,14 @@ public class CoffeeFS {
|
||||||
files.remove(file.getName());
|
files.remove(file.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean extractFile(String inputFile, String outputFile) throws IOException {
|
public boolean extractFile(String filename) throws IOException {
|
||||||
CoffeeFile file = files.get(inputFile);
|
CoffeeFile file = files.get(filename);
|
||||||
|
|
||||||
if(file == null) {
|
if(file == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
file.saveContents(outputFile);
|
file.saveContents(filename);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
*
|
*
|
||||||
* This file is part of the Contiki operating system.
|
* 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
|
* @author Nicolas Tsiftes
|
||||||
*
|
*
|
||||||
|
@ -44,23 +44,16 @@ import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class CoffeeManager {
|
public class CoffeeManager {
|
||||||
private static CoffeeFS coffeeFS;
|
private static CoffeeFS coffeeFS;
|
||||||
private static final int COMMAND_NULL = 0;
|
public enum Command { INSERT, EXTRACT, REMOVE, LIST, STATS };
|
||||||
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 static void main(String args[]) {
|
public static void main(String args[]) {
|
||||||
String platform = "sky";
|
String platform = "sky";
|
||||||
String usage = "Usage: java -jar coffee.jar ";
|
String usage = "Usage: java -jar coffee.jar ";
|
||||||
int command = COMMAND_NULL;
|
Command command = Command.STATS;
|
||||||
String coffeeFile = "";
|
String filename = "";
|
||||||
String localFile = "";
|
|
||||||
String fsImage = "";
|
String fsImage = "";
|
||||||
|
|
||||||
usage += "[-i|e <Coffee file> <file>] ";
|
usage += "[-i|e|r <file>] ";
|
||||||
usage += "[-r <Coffee file>] ";
|
|
||||||
usage += "[-l|s] ";
|
usage += "[-l|s] ";
|
||||||
usage += "<file system image>";
|
usage += "<file system image>";
|
||||||
|
|
||||||
|
@ -77,26 +70,19 @@ public class CoffeeManager {
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(args[0].equals("-i") || args[0].equals("-e")) {
|
if(args[0].equals("-i") || args[0].equals("-e") || args[0].equals("-r")) {
|
||||||
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.length != 3) {
|
if(args.length != 3) {
|
||||||
System.err.println(usage);
|
System.err.println(usage);
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
command = COMMAND_REMOVE;
|
if(args[0].equals("-i")) {
|
||||||
coffeeFile = args[1];
|
command = Command.INSERT;
|
||||||
|
} else if (args[0].equals("-r")) {
|
||||||
|
command = Command.REMOVE;
|
||||||
|
} else {
|
||||||
|
command = Command.EXTRACT;
|
||||||
|
}
|
||||||
|
filename = args[1];
|
||||||
fsImage = args[2];
|
fsImage = args[2];
|
||||||
} else {
|
} else {
|
||||||
if(args.length != 2) {
|
if(args.length != 2) {
|
||||||
|
@ -104,9 +90,9 @@ public class CoffeeManager {
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
if(args[0].equals("-l")) {
|
if(args[0].equals("-l")) {
|
||||||
command = COMMAND_LIST;
|
command = Command.LIST;
|
||||||
} else {
|
} else {
|
||||||
command = COMMAND_STATS;
|
command = Command.STATS;
|
||||||
}
|
}
|
||||||
fsImage = args[1];
|
fsImage = args[1];
|
||||||
}
|
}
|
||||||
|
@ -116,30 +102,37 @@ public class CoffeeManager {
|
||||||
CoffeeConfiguration conf = new CoffeeConfiguration(platform + ".properties");
|
CoffeeConfiguration conf = new CoffeeConfiguration(platform + ".properties");
|
||||||
coffeeFS = new CoffeeFS(new CoffeeImageFile(fsImage, conf));
|
coffeeFS = new CoffeeFS(new CoffeeImageFile(fsImage, conf));
|
||||||
switch (command) {
|
switch (command) {
|
||||||
case COMMAND_INSERT:
|
case INSERT:
|
||||||
if(coffeeFS.getFiles().get(localFile) != null) {
|
if(coffeeFS.getFiles().get(filename) != null) {
|
||||||
System.err.println("error: file \"" + localFile + "\" already exists");
|
System.err.println("error: file \"" +
|
||||||
|
filename + "\" already exists");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(coffeeFS.insertFile(localFile) != null) {
|
if(coffeeFS.insertFile(filename) != null) {
|
||||||
System.out.println("Inserted the local file \"" + localFile + "\" into the file system image");
|
System.out.println("Inserted the local file \"" +
|
||||||
|
filename +
|
||||||
|
"\" into the file system image");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case COMMAND_EXTRACT:
|
case EXTRACT:
|
||||||
if(coffeeFS.extractFile(coffeeFile, localFile) == false) {
|
if(coffeeFS.extractFile(filename) == false) {
|
||||||
System.err.println("Inexistent file: " + coffeeFile);
|
System.err.println("Inexistent file: " +
|
||||||
|
filename);
|
||||||
System.exit(1);
|
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;
|
break;
|
||||||
case COMMAND_REMOVE:
|
case REMOVE:
|
||||||
coffeeFS.removeFile(coffeeFile);
|
coffeeFS.removeFile(filename);
|
||||||
System.out.println("Removed the file \"" + coffeeFile + "\" from the Coffee file system image");
|
System.out.println("Removed the file \"" +
|
||||||
|
filename +
|
||||||
|
"\" from the Coffee file system image");
|
||||||
break;
|
break;
|
||||||
case COMMAND_LIST:
|
case LIST:
|
||||||
printFiles(coffeeFS.getFiles());
|
printFiles(coffeeFS.getFiles());
|
||||||
break;
|
break;
|
||||||
case COMMAND_STATS:
|
case STATS:
|
||||||
printStatistics(coffeeFS);
|
printStatistics(coffeeFS);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in a new issue