soc.2012.android: 9658ab92: Improved constant extraction program.
michael at soc.pidgin.im
michael at soc.pidgin.im
Wed May 23 06:57:05 EDT 2012
----------------------------------------------------------------------
Revision: 9658ab92f703368529fb545ca2816e0b1e50d464
Parent: e5c3faab901ad36a96095fb8b006b5b839fe1f81
Author: michael at soc.pidgin.im
Date: 05/23/12 06:46:10
Branch: im.pidgin.soc.2012.android
URL: http://d.pidgin.im/viewmtn/revision/info/9658ab92f703368529fb545ca2816e0b1e50d464
Changelog:
Improved constant extraction program.
Changes against parent e5c3faab901ad36a96095fb8b006b5b839fe1f81
patched android/workspace/im.pidgin.libpurple.build/src/im/pidgin/libpurple/build/constants/ConstantExtractor.java
patched android/workspace/im.pidgin.libpurple.build/src/im/pidgin/libpurple/build/constants/EnumObject.java
patched android/workspace/im.pidgin.libpurple.build/src/im/pidgin/libpurple/build/constants/ExtractConstants.java
-------------- next part --------------
============================================================
--- android/workspace/im.pidgin.libpurple.build/src/im/pidgin/libpurple/build/constants/ConstantExtractor.java b366175274d7fc88396a2ad956e380f47535c7de
+++ android/workspace/im.pidgin.libpurple.build/src/im/pidgin/libpurple/build/constants/ConstantExtractor.java 815d61da9a16639811d957677192574f53c4ff2e
@@ -62,15 +62,28 @@ public class ConstantExtractor {
*/
private void foundDefine(String name, String value) {
try {
- int intValue = Integer.parseInt(value);
+ int intValue = parseInteger(value);
foundIntConstants.put(name, intValue);
} catch (NumberFormatException e) {
- String stringValue = getStringValue(value);
- foundStringConstants.put(name, stringValue);
+ // just silently ignore it.
+ //String stringValue = getStringValue(value);
+ //foundStringConstants.put(name, stringValue);
}
}
+ protected static int parseInteger(String value) {
+ int intValue;
+ if (value.startsWith("0x")) {
+ intValue = Integer.parseInt(value.substring(2), 16);
+ } else if (value.startsWith("0")) {
+ intValue = Integer.parseInt(value, 8);
+ } else {
+ intValue = Integer.parseInt(value);
+ }
+ return intValue;
+ }
+
/**
* Converts a Source string to a real java string
*
@@ -108,7 +121,7 @@ public class ConstantExtractor {
}
value = value.substring(0, matcher.start())
+ Character.toString(replacement)
- + value.substring(matcher.end());
+ + value.substring(matcher.end() + 1);
}
return value;
============================================================
--- android/workspace/im.pidgin.libpurple.build/src/im/pidgin/libpurple/build/constants/EnumObject.java 29fe374c35a22922025c3f25a19cd79d1e8353f6
+++ android/workspace/im.pidgin.libpurple.build/src/im/pidgin/libpurple/build/constants/EnumObject.java abf381881d98656c8177474d0b06294431eee761
@@ -16,9 +16,9 @@ public class EnumObject {
public static final String ENUM_PATTERN_STRING =
"\\s*typedef\\s+enum\\s+\\{\\s*([^\\}]*?)\\s*,?\\s*\\}\\s*(\\w+)\\s*;";
private static final Pattern ENUM_PATTERN = Pattern.compile(ENUM_PATTERN_STRING);
- private String name;
- private EnumItem[] items;
- private String commonString;
+ private final String name;
+ private final EnumItem[] items;
+ private final String commonString;
public EnumObject(String enumSource) {
String uncommentedSource = enumSource.replaceAll(IGNORED_ENUM_PARTS, "");
@@ -44,10 +44,7 @@ public class EnumObject {
}
String valueString = m2.group(2);
if (valueString != null && !valueString.isEmpty()) {
- nextValue =
- valueString.startsWith("0x") ? Integer.parseInt(
- valueString.substring(2), 16) : Integer
- .parseInt(valueString);
+ nextValue = ConstantExtractor.parseInteger(valueString);
}
items[i] = new EnumItem(m2.group(1), nextValue);
nextValue++;
============================================================
--- android/workspace/im.pidgin.libpurple.build/src/im/pidgin/libpurple/build/constants/ExtractConstants.java 53d710d594d5f93298083c72aa5e335941797f77
+++ android/workspace/im.pidgin.libpurple.build/src/im/pidgin/libpurple/build/constants/ExtractConstants.java b80d1c4cc11655193c25c09fb9e8731a29c7cc62
@@ -45,42 +45,50 @@ public class ExtractConstants {
* @throws ExtractorException
*/
public void execute() throws ExtractorException {
- File in = new File(input);
-
- File out = new File(output);
-
- ConstantExtractor extractor = new ConstantExtractor();
-
- extractor.parseFile(in);
-
- PrintWriter writer;
- try {
- writer = new PrintWriter(out);
- } catch (FileNotFoundException e) {
- throw new ExtractorException(e.getMessage());
- }
-
- writeFileHeader(writer);
-
- for (EnumName name : enums) {
- EnumObject e = extractor.getEnum(name.getName());
- if (e == null) {
- throw new ExtractorException("Enum " + name.getName() + " not found.");
+ try {
+ File in = new File(input);
+
+ File out = new File(output);
+
+ ConstantExtractor extractor = new ConstantExtractor();
+
+ extractor.parseFile(in);
+
+ PrintWriter writer;
+ try {
+ writer = new PrintWriter(out);
+ } catch (FileNotFoundException e) {
+ throw new ExtractorException(e.getMessage());
+ }
+
+ writeFileHeader(writer);
+
+ for (EnumName name : enums) {
+ EnumObject e = extractor.getEnum(name.getName());
+ if (e == null) {
+ throw new ExtractorException("Enum " + name.getName() + " not found.");
+ }
+
+ for (EnumItem item : e.getItems()) {
+ String itemName = item.getName();
+ int value = item.getValue();
+ writeIntConstant(writer, itemName, value);
+ }
+ System.out.println("Enum " + name.getName() + " extracted.");
}
- for (EnumItem item : e.getItems()) {
- String itemName = item.getName();
- int value = item.getValue();
- writeIntConstant(writer, itemName, value);
+ for (ConstantName name : constants) {
+ int value = extractor.getIntegerConstant(name.getName());
+ writeIntConstant(writer, name.getName(), value);
+ System.out.println("Constant " + name.getName() + " extracted.");
}
+ writeFooter(writer);
+ writer.close();
+
+ } catch (RuntimeException t) {
+ t.printStackTrace();
+ throw t;
}
-
- for (ConstantName name : constants) {
- int value = extractor.getIntegerConstant(name.getName());
- writeIntConstant(writer, name.getName(), value);
- }
- writeFooter(writer);
- writer.close();
}
private void writeFileHeader(PrintWriter writer) {
More information about the Commits
mailing list