aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/anarres/cpp/CppTask.java36
-rw-r--r--src/main/java/org/anarres/cpp/FileLexerSource.java37
-rw-r--r--src/main/java/org/anarres/cpp/InputLexerSource.java26
-rw-r--r--src/main/java/org/anarres/cpp/LexerSource.java8
4 files changed, 64 insertions, 43 deletions
diff --git a/src/main/java/org/anarres/cpp/CppTask.java b/src/main/java/org/anarres/cpp/CppTask.java
index a569054..cc9c4d3 100644
--- a/src/main/java/org/anarres/cpp/CppTask.java
+++ b/src/main/java/org/anarres/cpp/CppTask.java
@@ -25,8 +25,6 @@ import java.util.Enumeration;
import java.util.List;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.taskdefs.Copy;
-import org.apache.tools.ant.types.FilterSet;
-import org.apache.tools.ant.types.FilterSetCollection;
import org.apache.tools.ant.types.Path;
/**
@@ -117,6 +115,11 @@ public class CppTask extends Copy {
}
*/
private void preprocess(File input, File output) throws Exception {
+ if (input == null)
+ throw new BuildException("Input not specified");
+ if (output == null)
+ throw new BuildException("Output not specified");
+
Preprocessor cpp = new Preprocessor();
cpp.setListener(listener);
for (Macro macro : macros)
@@ -135,10 +138,6 @@ public class CppTask extends Copy {
}
FileWriter writer = null;
try {
- if (input == null)
- throw new BuildException("Input not specified");
- if (output == null)
- throw new BuildException("Output not specified");
cpp.addInput(input);
writer = new FileWriter(output);
for (;;) {
@@ -181,18 +180,19 @@ public class CppTask extends Copy {
try {
log("Copying " + fromFile + " to " + toFile, verbosity);
- FilterSetCollection executionFilters
- = new FilterSetCollection();
- if (filtering) {
- executionFilters
- .addFilterSet(getProject().getGlobalFilterSet());
- }
- for (Enumeration filterEnum = getFilterSets().elements();
- filterEnum.hasMoreElements();) {
- executionFilters
- .addFilterSet((FilterSet) filterEnum.nextElement());
- }
-
+ /*
+ FilterSetCollection executionFilters
+ = new FilterSetCollection();
+ if (filtering) {
+ executionFilters
+ .addFilterSet(getProject().getGlobalFilterSet());
+ }
+ for (Enumeration filterEnum = getFilterSets().elements();
+ filterEnum.hasMoreElements();) {
+ executionFilters
+ .addFilterSet((FilterSet) filterEnum.nextElement());
+ }
+ */
File srcFile = new File(fromFile);
File dstFile = new File(toFile);
preprocess(srcFile, dstFile);
diff --git a/src/main/java/org/anarres/cpp/FileLexerSource.java b/src/main/java/org/anarres/cpp/FileLexerSource.java
index b3b3e88..7dc883a 100644
--- a/src/main/java/org/anarres/cpp/FileLexerSource.java
+++ b/src/main/java/org/anarres/cpp/FileLexerSource.java
@@ -18,8 +18,10 @@ package org.anarres.cpp;
import java.io.BufferedReader;
import java.io.File;
+import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
+import java.nio.charset.Charset;
import javax.annotation.Nonnull;
/**
@@ -29,7 +31,7 @@ import javax.annotation.Nonnull;
*
* @see Source
*/
-public class FileLexerSource extends LexerSource {
+public class FileLexerSource extends InputLexerSource {
private final String path;
private final File file;
@@ -39,29 +41,38 @@ public class FileLexerSource extends LexerSource {
*
* Preprocessor directives are honoured within the file.
*/
- public FileLexerSource(@Nonnull File file, String path)
+ public FileLexerSource(@Nonnull File file, @Nonnull Charset charset, @Nonnull String path)
throws IOException {
- super(
- new BufferedReader(
- new FileReader(
- file
- )
- ),
- true
- );
-
+ super(new FileInputStream(file), charset);
this.file = file;
this.path = path;
}
+ public FileLexerSource(@Nonnull File file, @Nonnull String path)
+ throws IOException {
+ this(file, Charset.defaultCharset(), path);
+ }
+
+ public FileLexerSource(@Nonnull File file, @Nonnull Charset charset)
+ throws IOException {
+ this(file, charset, file.getPath());
+ }
+
+ @Deprecated
public FileLexerSource(@Nonnull File file)
throws IOException {
- this(file, file.getPath());
+ this(file, Charset.defaultCharset());
+ }
+
+ public FileLexerSource(@Nonnull String path, @Nonnull Charset charset)
+ throws IOException {
+ this(new File(path), charset, path);
}
+ @Deprecated
public FileLexerSource(@Nonnull String path)
throws IOException {
- this(new File(path), path);
+ this(path, Charset.defaultCharset());
}
@Nonnull
diff --git a/src/main/java/org/anarres/cpp/InputLexerSource.java b/src/main/java/org/anarres/cpp/InputLexerSource.java
index 1e5b410..4f7c03d 100644
--- a/src/main/java/org/anarres/cpp/InputLexerSource.java
+++ b/src/main/java/org/anarres/cpp/InputLexerSource.java
@@ -16,10 +16,11 @@
*/
package org.anarres.cpp;
-import java.io.BufferedReader;
-import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.io.Reader;
+import java.nio.charset.Charset;
+import javax.annotation.Nonnull;
/**
* A {@link Source} which lexes a file.
@@ -30,21 +31,22 @@ import java.io.InputStreamReader;
*/
public class InputLexerSource extends LexerSource {
+ @Deprecated
+ public InputLexerSource(@Nonnull InputStream input) {
+ this(input, Charset.defaultCharset());
+ }
+
/**
* Creates a new Source for lexing the given Reader.
*
* Preprocessor directives are honoured within the file.
*/
- public InputLexerSource(InputStream input)
- throws IOException {
- super(
- new BufferedReader(
- new InputStreamReader(
- input
- )
- ),
- true
- );
+ public InputLexerSource(@Nonnull InputStream input, Charset charset) {
+ this(new InputStreamReader(input, charset));
+ }
+
+ public InputLexerSource(@Nonnull Reader input) {
+ super(toBufferedReader(input), true);
}
@Override
diff --git a/src/main/java/org/anarres/cpp/LexerSource.java b/src/main/java/org/anarres/cpp/LexerSource.java
index 7e39a21..cf4296f 100644
--- a/src/main/java/org/anarres/cpp/LexerSource.java
+++ b/src/main/java/org/anarres/cpp/LexerSource.java
@@ -16,6 +16,7 @@
*/
package org.anarres.cpp;
+import java.io.BufferedReader;
import java.io.IOException;
import java.io.Reader;
import javax.annotation.Nonnull;
@@ -24,6 +25,13 @@ import static org.anarres.cpp.Token.*;
/** Does not handle digraphs. */
public class LexerSource extends Source {
+ @Nonnull
+ protected static BufferedReader toBufferedReader(@Nonnull Reader r) {
+ if (r instanceof BufferedReader)
+ return (BufferedReader) r;
+ return new BufferedReader(r);
+ }
+
private static final boolean DEBUG = false;
private JoinReader reader;