diff --git a/pom.xml b/pom.xml
index 85be88ab..f9650b81 100644
--- a/pom.xml
+++ b/pom.xml
@@ -306,6 +306,7 @@
IrpProtocols2html.xsl
${project.artifactId}.xml
irp-protocols.xsd
+ rawgirr2named.xsl
diff --git a/src/main/java/org/harctoolbox/cmdline/CommandAnalyze.java b/src/main/java/org/harctoolbox/cmdline/CommandAnalyze.java
index 2cf68117..2a5b3dec 100644
--- a/src/main/java/org/harctoolbox/cmdline/CommandAnalyze.java
+++ b/src/main/java/org/harctoolbox/cmdline/CommandAnalyze.java
@@ -20,6 +20,7 @@
import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import java.io.IOException;
+import java.io.InputStream;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
@@ -66,6 +67,10 @@
@Parameters(commandNames = {"analyze"}, commandDescription = "Analyze signal: tries to find an IRP form with parameters.")
public class CommandAnalyze extends AbstractCommand {
+ /**
+ * Path name, as found in the jar, of the XSLT style sheet taking raw girr to named input format.
+ */
+ public static final String RAWGIRR2NAMEINPUT = "/rawgirr2named.xsl";
private static final Logger logger = Logger.getLogger(CommandAnalyze.class.getName());
@Parameter(names = {"-a", "--all"}, description = "List all decoder outcomes, instead of only the one with lowest weight.")
@@ -96,9 +101,12 @@ public class CommandAnalyze extends AbstractCommand {
@Parameter(names = {"-f", "--frequency"}, converter = FrequencyParser.class, description = "Modulation frequency of raw signal.")
private Double frequency = null;
- @Parameter(names = {"-g", "--girr"}, description = "Generate Girr file. Inhibits all other output.")
+ @Parameter(names = {"-g", "--girroutput"}, description = "Generate Girr file. Inhibits all other output.")
private boolean girr = false;
+ @Parameter(names = {"-G", "--girrinput"}, description = "Read raw input in Girr format.")
+ private String girrInput = null;
+
@Parameter(names = {"-i", "--input"}, description = "File/URL from which to take inputs, one sequence per line.")
private String input = null;
@@ -241,8 +249,8 @@ private void analyze() throws IrpException, IrCoreException, NoDecoderMatchExcep
if (parameterTable && eliminateVars)
throw new UsageException("Parameter table is meaninless together with --eliminate-vars");
- if (IrCoreUtils.numberTrue(input != null, namedInput != null, args != null) != 1)
- throw new UsageException("Must use exactly one of --input, --namedinput, and non-empty arguments");
+ if (IrCoreUtils.numberTrue(input != null, namedInput != null, girrInput != null, args != null) != 1)
+ throw new UsageException("Must use exactly one of --input, --namedinput, --girrinput and non-empty arguments");
if (maxParameterWidth > FiniteBitField.MAXWIDTH) {
logger.log(Level.WARNING, "The given value of --maxparameterwidth ({0}) is larger than {1}. This is using unspecified behavior, and the correct execution is not guaranteed.",
@@ -276,6 +284,22 @@ private void analyze() throws IrpException, IrCoreException, NoDecoderMatchExcep
if (signals.isEmpty())
throw new InvalidArgumentException("No parseable sequences found.");
analyze(signals);
+ } else if (girrInput != null) {
+ if (validate)
+ throw new UsageException("Cannot use --validate with --girrinput.");
+
+ ThingsLineParser thingsLineParser = new ThingsLineParser<>(
+ (List line) -> {
+ return (MultiParser.newIrCoreParser(line)).toModulatedIrSequence(frequency, trailingGap);
+ }, commandLineArgs.commentStart
+ );
+ InputStream xsltStream = CommandAnalyze.class.getResourceAsStream(RAWGIRR2NAMEINPUT);
+ Document xsltDoc = XmlUtils.openXmlStream(xsltStream, null, true, true);
+ Map signals = thingsLineParser.readNamedThings(girrInput, xsltDoc, commandLineArgs.inputEncoding);
+ if (signals.isEmpty()) {
+ throw new InvalidArgumentException("No parseable sequences found.");
+ }
+ analyze(signals);
} else {
MultiParser parser = MultiParser.newIrCoreParser(args);
if (introRepeatEnding) {
diff --git a/src/main/java/org/harctoolbox/cmdline/CommandDecode.java b/src/main/java/org/harctoolbox/cmdline/CommandDecode.java
index ecb5cb35..c554fc4e 100644
--- a/src/main/java/org/harctoolbox/cmdline/CommandDecode.java
+++ b/src/main/java/org/harctoolbox/cmdline/CommandDecode.java
@@ -19,6 +19,7 @@
import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import java.io.IOException;
+import java.io.InputStream;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.util.Arrays;
@@ -66,9 +67,12 @@ public class CommandDecode extends AbstractCommand {
@Parameter(names = {"-f", "--frequency"}, converter = FrequencyParser.class, description = "Set modulation frequency.")
private Double frequency = null;
- @Parameter(names = {"-g", "--girr"}, description = "Generate output in Girr format (only)")
+ @Parameter(names = {"-g", "--girroutput"}, description = "Generate output in Girr format (only)")
private boolean girr = false;
+ @Parameter(names = {"-G", "--girrinput"}, description = "Read raw input in Girr format.")
+ private String girrInput = null;
+
@Parameter(names = {"-l", "--ignoreleadinggarbage"}, description = "Accept decodes starting with undecodable pairs.")
private boolean ignoreLeadingGarbage = false;
@@ -153,8 +157,8 @@ private class DecodeClass {
private void decode() throws UsageException, IrpParseException, IOException, InvalidArgumentException, SAXException, TransformerException {
CmdUtils.checkForOption("decode", args);
- if (IrCoreUtils.numberTrue(input != null, namedInput != null, args != null) != 1)
- throw new UsageException("Must use exactly one of --input, --namedinput, and non-empty arguments");
+ if (IrCoreUtils.numberTrue(input != null, namedInput != null, girrInput != null, args != null) != 1)
+ throw new UsageException("Must use exactly one of --input, --namedinput, --girrinput and non-empty arguments");
if (ignoreLeadingGarbage && strict)
throw new UsageException("--strict and --ignoreleadinggarbage may not be used together.");
@@ -181,6 +185,14 @@ private void decode() throws UsageException, IrpParseException, IOException, Inv
? irSignalParser.readNamedThings(namedInput, commandLineArgs.inputEncoding)
: irSignalParser.readNamedThings(namedInput, xslt, commandLineArgs.inputEncoding);
decode(signals);
+ } else if (girrInput != null) {
+ ThingsLineParser irSignalParser = new ThingsLineParser<>((List line) -> {
+ return (MultiParser.newIrCoreParser(line)).toIrSignal(frequency, trailingGap);
+ }, commandLineArgs.commentStart);
+ InputStream xsltStream = CommandAnalyze.class.getResourceAsStream(CommandAnalyze.RAWGIRR2NAMEINPUT);
+ Document xsltDoc = XmlUtils.openXmlStream(xsltStream, null, true, true);
+ Map signals = irSignalParser.readNamedThings(girrInput, xsltDoc, commandLineArgs.inputEncoding);
+ decode(signals);
} else {
MultiParser prontoRawParser = MultiParser.newIrCoreParser(args);
IrSignal irSignal = prontoRawParser.toIrSignal(frequency, trailingGap);
diff --git a/src/main/java/org/harctoolbox/ircore/ThingsLineParser.java b/src/main/java/org/harctoolbox/ircore/ThingsLineParser.java
index a8a3841f..d2b9e505 100644
--- a/src/main/java/org/harctoolbox/ircore/ThingsLineParser.java
+++ b/src/main/java/org/harctoolbox/ircore/ThingsLineParser.java
@@ -31,6 +31,7 @@
import java.util.logging.Logger;
import javax.xml.transform.TransformerException;
import org.harctoolbox.xml.XmlUtils;
+import org.w3c.dom.Document;
import org.xml.sax.SAXException;
public class ThingsLineParser {
@@ -94,6 +95,13 @@ public Map readNamedThings(String namedInput, String xslt, String enc
}
}
+ public Map readNamedThings(String namedInput, Document stylesheet, String encoding) throws SAXException, IOException, TransformerException {
+ Objects.requireNonNull(stylesheet);
+ try (InputStreamReader reader = XmlUtils.mkReaderXml(namedInput, stylesheet, encoding)) {
+ return readNamedThings(reader);
+ }
+ }
+
public Map readNamedThings(Reader reader) throws IOException {
BufferedReader in = new BufferedReader(reader);
Map map = new LinkedHashMap<>(4);
diff --git a/src/main/java/org/harctoolbox/xml/XmlUtils.java b/src/main/java/org/harctoolbox/xml/XmlUtils.java
index 14dd297d..a7e3cbba 100644
--- a/src/main/java/org/harctoolbox/xml/XmlUtils.java
+++ b/src/main/java/org/harctoolbox/xml/XmlUtils.java
@@ -325,8 +325,12 @@ public static ByteArrayInputStream renderDOM(Document document, Document xslt, S
}
public static InputStreamReader mkReaderXml(String docu, String xslt, String encoding) throws SAXException, UnsupportedEncodingException, TransformerException, IOException {
- Document document = XmlUtils.openXmlThing(docu, null, true, true);
Document stylesheet = XmlUtils.openXmlThing(xslt, null, true, true);
+ return mkReaderXml(docu, stylesheet, encoding);
+ }
+
+ public static InputStreamReader mkReaderXml(String docu, Document stylesheet, String encoding) throws SAXException, UnsupportedEncodingException, TransformerException, IOException {
+ Document document = XmlUtils.openXmlThing(docu, null, true, true);
InputStream inputStream = XmlUtils.renderDOM(document, stylesheet, encoding);
return new InputStreamReader(inputStream, encoding);
}
diff --git a/contributed/input-filters/rawgirr2named.xsl b/src/main/resources/rawgirr2named.xsl
similarity index 100%
rename from contributed/input-filters/rawgirr2named.xsl
rename to src/main/resources/rawgirr2named.xsl