1 package acl2s.lib.certify;
2
3 import java.io.BufferedReader;
4 import java.io.BufferedWriter;
5 import java.io.FileReader;
6 import java.io.IOException;
7 import java.io.InputStreamReader;
8 import java.io.OutputStreamWriter;
9
10 public class ReadPreamble {
11 static final String oldprefix = "#|$ACL2-A2S-PREAMBLE$;";
12 static final String prefix = "#|$ACL2s-Preamble$;";
13 static final String oldpostfix = ";$ACL2-A2S-PREAMBLE$|#";
14 static final String postfix = ";$ACL2s-Preamble$|#";
15
16 static void go(BufferedReader br, BufferedWriter bw) throws IOException {
17 String line;
18
19 for (;;) {
20 line = br.readLine();
21 if (line == null) {
22 bw.write("(begin-book)\n"); // default preamble
23 return;
24 }
25 if (line.endsWith(prefix)) break;
26 if (line.endsWith(oldprefix)) break;
27 }
28
29 for(;;) {
30 line = br.readLine();
31 if (line == null) return;
32 if (line.endsWith(postfix)) {
33 bw.write(line.substring(0, line.length() - postfix.length()));
34 bw.write('\n');
35 break;
36 }
37 if (line.endsWith(oldpostfix)) {
38 bw.write(line.substring(0, line.length() - oldpostfix.length()));
39 bw.write('\n');
40 break;
41 }
42 bw.write(line);
43 bw.write("\n");
44 }
45
46 }
47
48 public static void main(String[] args) throws IOException {
49 BufferedReader br;
50 BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
51
52 if (args.length == 0) {
|
Event do_not_call: |
"java.io.InputStreamReader(java.io.InputStream arg1)" implicitly uses the environment's default character set, which might lead to unexpected behavior. Consider using InputStreamReader(InputStream in, String charsetName). |
53 br = new BufferedReader(new InputStreamReader(System.in));
54 } else if (args.length == 1) {
55 br = new BufferedReader(new FileReader(args[0]));
56 } else {
57 throw new IllegalArgumentException("Must specify one file to read or none for stdin.");
58 }
59
60 go(br,bw);
61
62 if (args.length == 0) {
63 String line;
64 do {
65 line = br.readLine();
66 } while (line != null);
67 }
68
69 bw.flush();
70 bw.close();
71 br.close();
72 }
73 }