Add a plumbing option to dicttool info.
Also align the `porcelain' option to the diff command that was used mistakenly. Bug: 7388665 Change-Id: Ic0e1b98c62ce37b2e909384a0370af4458563703
This commit is contained in:
parent
a8058d169d
commit
51a0ef8c59
3 changed files with 31 additions and 15 deletions
|
@ -290,19 +290,23 @@ public final class FusionDictionary implements Iterable<Word> {
|
|||
}
|
||||
@Override
|
||||
public String toString() { // Convenience method
|
||||
return toString(0);
|
||||
return toString(0, false);
|
||||
}
|
||||
public String toString(final int indentCount) {
|
||||
public String toString(final int indentCount, final boolean plumbing) {
|
||||
final StringBuilder indent = new StringBuilder();
|
||||
if (plumbing) {
|
||||
indent.append("H:");
|
||||
} else {
|
||||
for (int i = 0; i < indentCount; ++i) {
|
||||
indent.append(" ");
|
||||
}
|
||||
}
|
||||
final StringBuilder s = new StringBuilder();
|
||||
for (final String optionKey : mAttributes.keySet()) {
|
||||
s.append(indent);
|
||||
s.append(optionKey);
|
||||
s.append(" = ");
|
||||
if ("date".equals(optionKey)) {
|
||||
if ("date".equals(optionKey) && !plumbing) {
|
||||
// Date needs a number of milliseconds, but the dictionary contains seconds
|
||||
s.append(new Date(
|
||||
1000 * Long.parseLong(mAttributes.get(optionKey))).toString());
|
||||
|
|
|
@ -34,7 +34,7 @@ public class Diff extends Dicttool.Command {
|
|||
@Override
|
||||
public String getHelp() {
|
||||
return COMMAND + " [-p] <dict> <dict> : shows differences between two dictionaries.\n"
|
||||
+ " If -p (porcelain) option is given, produce output suitable for a script";
|
||||
+ " If -p (plumbing) option is given, produce output suitable for a script";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -42,15 +42,15 @@ public class Diff extends Dicttool.Command {
|
|||
if (mArgs.length < 2) {
|
||||
throw new RuntimeException("Not enough arguments for command " + COMMAND);
|
||||
}
|
||||
final boolean porcelain;
|
||||
final boolean plumbing;
|
||||
if ("-p".equals(mArgs[0])) {
|
||||
porcelain = true;
|
||||
plumbing = true;
|
||||
mArgs = Arrays.copyOfRange(mArgs, 1, mArgs.length);
|
||||
if (mArgs.length != 2) { // There should be only 2 arguments left
|
||||
throw new RuntimeException("Wrong number of arguments for command " + COMMAND);
|
||||
}
|
||||
} else {
|
||||
porcelain = false;
|
||||
plumbing = false;
|
||||
}
|
||||
final FusionDictionary dict0 =
|
||||
BinaryDictOffdeviceUtils.getDictionary(mArgs[0], false /* report */);
|
||||
|
@ -58,7 +58,7 @@ public class Diff extends Dicttool.Command {
|
|||
final FusionDictionary dict1 =
|
||||
BinaryDictOffdeviceUtils.getDictionary(mArgs[1], false /* report */);
|
||||
if (null == dict1) throw new RuntimeException("Can't read dictionary " + mArgs[1]);
|
||||
if (!porcelain) {
|
||||
if (!plumbing) {
|
||||
System.out.println("Header :");
|
||||
diffHeaders(dict0, dict1);
|
||||
if (languageDiffers(dict0, dict1)) {
|
||||
|
|
|
@ -22,6 +22,7 @@ import com.android.inputmethod.latin.makedict.FusionDictionary.CharGroup;
|
|||
import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString;
|
||||
import com.android.inputmethod.latin.makedict.Word;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Info extends Dicttool.Command {
|
||||
|
@ -35,9 +36,9 @@ public class Info extends Dicttool.Command {
|
|||
return COMMAND + " <filename>: prints various information about a dictionary file";
|
||||
}
|
||||
|
||||
private static void showInfo(final FusionDictionary dict) {
|
||||
private static void showInfo(final FusionDictionary dict, final boolean plumbing) {
|
||||
System.out.println("Header attributes :");
|
||||
System.out.print(dict.mOptions.toString(2));
|
||||
System.out.print(dict.mOptions.toString(2, plumbing));
|
||||
int wordCount = 0;
|
||||
int bigramCount = 0;
|
||||
int shortcutCount = 0;
|
||||
|
@ -62,7 +63,8 @@ public class Info extends Dicttool.Command {
|
|||
+ " whitelist entries)");
|
||||
}
|
||||
|
||||
private static void showWordInfo(final FusionDictionary dict, final String word) {
|
||||
private static void showWordInfo(final FusionDictionary dict, final String word,
|
||||
final boolean plumbing) {
|
||||
final CharGroup group = FusionDictionary.findWordInTree(dict.mRoot, word);
|
||||
if (null == group) {
|
||||
System.out.println(word + " is not in the dictionary");
|
||||
|
@ -101,15 +103,25 @@ public class Info extends Dicttool.Command {
|
|||
if (mArgs.length < 1) {
|
||||
throw new RuntimeException("Not enough arguments for command " + COMMAND);
|
||||
}
|
||||
final boolean plumbing;
|
||||
if ("-p".equals(mArgs[0])) {
|
||||
plumbing = true;
|
||||
mArgs = Arrays.copyOfRange(mArgs, 1, mArgs.length);
|
||||
if (mArgs.length != 1) { // There should be only 1 argument left
|
||||
throw new RuntimeException("Wrong number of arguments for command " + COMMAND);
|
||||
}
|
||||
} else {
|
||||
plumbing = false;
|
||||
}
|
||||
final String filename = mArgs[0];
|
||||
final boolean hasWordArguments = (1 == mArgs.length);
|
||||
final FusionDictionary dict = BinaryDictOffdeviceUtils.getDictionary(filename,
|
||||
hasWordArguments /* report */);
|
||||
if (hasWordArguments) {
|
||||
showInfo(dict);
|
||||
showInfo(dict, plumbing);
|
||||
} else {
|
||||
for (int i = 1; i < mArgs.length; ++i) {
|
||||
showWordInfo(dict, mArgs[i]);
|
||||
showWordInfo(dict, mArgs[i], plumbing);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue