annotate SMART/Java/PythonHelperReader.java @ 34:529e3e6a0954

Deleted selected files
author m-zytnicki
date Tue, 30 Apr 2013 14:35:27 -0400
parents 769e306b7933
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
1 /**
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
2 *
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
3 * Copyright INRA-URGI 2009-2010
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
4 *
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
5 * This software is governed by the CeCILL license under French law and
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
6 * abiding by the rules of distribution of free software. You can use,
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
7 * modify and/ or redistribute the software under the terms of the CeCILL
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
8 * license as circulated by CEA, CNRS and INRIA at the following URL
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
9 * "http://www.cecill.info".
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
10 *
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
11 * As a counterpart to the access to the source code and rights to copy,
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
12 * modify and redistribute granted by the license, users are provided only
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
13 * with a limited warranty and the software's author, the holder of the
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
14 * economic rights, and the successive licensors have only limited
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
15 * liability.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
16 *
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
17 * In this respect, the user's attention is drawn to the risks associated
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
18 * with loading, using, modifying and/or developing or reproducing the
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
19 * software by the user in light of its specific status of free software,
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
20 * that may mean that it is complicated to manipulate, and that also
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
21 * therefore means that it is reserved for developers and experienced
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
22 * professionals having in-depth computer knowledge. Users are therefore
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
23 * encouraged to load and test the software's suitability as regards their
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
24 * requirements in conditions enabling the security of their systems and/or
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
25 * data to be ensured and, more generally, to use and operate it in the
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
26 * same conditions as regards security.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
27 *
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
28 * The fact that you are presently reading this means that you have had
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
29 * knowledge of the CeCILL license and that you accept its terms.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
30 *
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
31 */
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
32 import java.util.*;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
33 import java.io.File;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
34 import java.io.*;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
35 import java.util.regex.*;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
36
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
37 public class PythonHelperReader {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
38
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
39 String fileName;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
40 Program program;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
41 BufferedReader reader;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
42 String message;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
43
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
44 public PythonHelperReader(String fileName) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
45 this.fileName = fileName;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
46 this.reader = reader;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
47 this.message = null;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
48 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
49
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
50 public void setReader(BufferedReader reader) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
51 this.reader = reader;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
52 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
53
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
54 public void run() {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
55 this.program = new Program();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
56 boolean inBeginning = true;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
57 boolean inUsage = false;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
58 boolean afterUsage = false;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
59 boolean inDescription = false;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
60 boolean afterDescription = false;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
61 boolean inOptions = false;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
62 boolean inOptionBlank = false;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
63 boolean inError = false;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
64 String usage = null;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
65 String description = null;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
66 String option = null;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
67 Vector <String> options = new Vector < String > ();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
68 String[] optionSplitted;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
69
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
70 // Parse file
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
71 try {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
72 String line = null;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
73
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
74 while ((line = reader.readLine()) != null) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
75 line = line.trim();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
76 if (line.startsWith("Traceback")) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
77 this.message = "Problem with header of '" + this.fileName + "':\n" + line + "\n";
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
78 inError = true;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
79 inBeginning = false;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
80 inUsage = false;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
81 afterUsage = false;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
82 inDescription = false;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
83 afterDescription = false;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
84 inOptions = false;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
85 inOptionBlank = false;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
86 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
87 else if (inError) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
88 this.message += line + "\n";
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
89 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
90 else if (inBeginning) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
91 if (line.startsWith("Usage:")) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
92 inUsage = true;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
93 inBeginning = false;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
94 usage = line;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
95 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
96 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
97 else if (inUsage) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
98 if ("".equals(line)) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
99 inUsage = false;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
100 afterUsage = true;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
101 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
102 else {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
103 usage += " " + line;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
104 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
105 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
106 else if (afterUsage) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
107 if (! "".equals(line)) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
108 description = line;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
109 afterUsage = false;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
110 inDescription = true;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
111 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
112 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
113 else if (inDescription) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
114 if ("".equals(line)) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
115 inDescription = false;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
116 afterDescription = true;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
117 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
118 else {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
119 description += " " + line;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
120 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
121 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
122 else if (afterDescription) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
123 if (! "".equals(line)) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
124 afterDescription = false;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
125 inOptions = true;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
126 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
127 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
128 else if (inOptions) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
129 if ("".equals(line)) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
130 inOptions = false;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
131 inOptionBlank = true;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
132 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
133 else {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
134 if (option == null) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
135 option = line;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
136 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
137 else {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
138 if (line.charAt(0) == '-') {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
139 options.add(option);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
140 option = line;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
141 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
142 else {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
143 option += " " + line;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
144 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
145 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
146 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
147 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
148 else if (inOptionBlank) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
149 if (! "".equals(line)) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
150 inOptionBlank = false;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
151 inOptions = true;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
152 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
153 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
154 else {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
155 this.message = "Something is wrong in the file '" + this.fileName + "'.\n";
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
156 return;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
157 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
158 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
159
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
160 reader.close();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
161 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
162 catch (FileNotFoundException e) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
163 this.message = "File " + this.fileName + " not found.\n";
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
164 return;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
165 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
166 catch (IOException e) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
167 this.message = "IOException while reading file " + this.fileName;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
168 return;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
169 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
170
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
171 if (inError) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
172 return;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
173 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
174
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
175 if (option != null) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
176 options.add(option);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
177 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
178
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
179 HashMap < String, ProgramOption > identifierToOptions = new HashMap < String, ProgramOption > ();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
180 HashMap < ProgramOption, String > associatedOption = new HashMap < ProgramOption, String > ();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
181
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
182 if (usage == null) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
183 this.message = "Cannot read the usage of file " + this.fileName + ".\n";
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
184 return;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
185 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
186 program.setShortName(usage.split(" ")[1].trim());
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
187 program.setName(description.split(":")[0].trim());
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
188
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
189 Pattern pattern = Pattern.compile("\\[Category: .*\\]");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
190 Matcher matcher = pattern.matcher(description);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
191 if (matcher.find()) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
192 program.setSection(description.substring(matcher.start() + "[Category: ".length(), matcher.end() - 1));
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
193 program.setDescription(description.substring(0, matcher.start() - 1).trim());
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
194 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
195 else {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
196 this.message = "Cannot find category in description '" + description + "' in file " + this.fileName + ".\n";
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
197 return;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
198 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
199 for (int i = 0; i < options.size(); i++) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
200 option = options.get(i).replace("\t", " ");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
201 optionSplitted = option.split(" ");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
202 option = "";
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
203 for (int j = 3; j < optionSplitted.length; j++) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
204 option += optionSplitted[j] + " ";
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
205 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
206
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
207 String identifier = optionSplitted[0].replace("-", "").replace(",", "");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
208 // Skip -h and -v options
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
209 if (("h".equals(identifier)) || ("v".equals(identifier)))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
210 continue;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
211
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
212 ProgramOption programOption = new ProgramOption();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
213 programOption.setIdentifier("-" + identifier);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
214 int commentEnd = option.indexOf("[");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
215 if (commentEnd == -1) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
216 this.message = "Do not understand option line '" + option + "' in file " + this.fileName + ".\n";
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
217 return;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
218 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
219 programOption.setComment(option.substring(0, commentEnd).trim());
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
220 identifierToOptions.put(identifier, programOption);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
221
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
222 pattern = Pattern.compile("\\[[^\\]]*\\]");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
223 matcher = pattern.matcher(option);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
224 while (matcher.find()) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
225 String inner = option.substring(matcher.start()+1, matcher.end()-1);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
226 if (inner.contains(":")) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
227 String type = inner.substring(0, inner.indexOf(":")).trim();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
228 String value = inner.substring(inner.indexOf(":")+1).trim();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
229 // Types of the options
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
230 if ("format".compareToIgnoreCase(type) == 0) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
231 String currentWord = "";
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
232 String rest = "";
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
233 if (value.contains(" ")) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
234 int pos = value.indexOf(" ");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
235 currentWord = value.substring(0, pos);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
236 rest = value.substring(pos+1);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
237 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
238 else {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
239 currentWord = value;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
240 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
241 // Output file type
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
242 if ("output".compareToIgnoreCase(currentWord) == 0) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
243 programOption.setInput(false);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
244 int pos = rest.indexOf(" ");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
245 currentWord = rest.substring(0, pos).trim();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
246 rest = rest.substring(pos+1).trim();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
247 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
248 // File (input or output file)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
249 if ("file".compareToIgnoreCase(currentWord) == 0) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
250 programOption.setType("file");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
251 // Format given by an associated option (to be found later)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
252 if (rest.startsWith("in format given by ")) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
253 associatedOption.put(programOption, rest.substring(rest.indexOf("format given by ") + "format given by ".length() + 1).trim());
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
254 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
255 else {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
256 if (! rest.startsWith("in ")) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
257 this.message = "Descriptor " + option + " does not have a proper format.\n";
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
258 return;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
259 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
260 rest = rest.substring("in ".length());
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
261 int pos = rest.indexOf(" format");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
262 if (pos == -1) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
263 this.message = "Descriptor " + option + " does not have a proper format.\n";
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
264 return;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
265 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
266 programOption.setFormat(rest.substring(0, pos).trim().toLowerCase().split(" or "));
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
267 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
268 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
269 // Format type
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
270 else if (rest.endsWith("file format")) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
271 programOption.setFormat((currentWord + " " + rest.substring(0, rest.indexOf("file format"))).trim().toLowerCase().split(" or "));
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
272 programOption.setType("format");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
273 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
274 // Choice type
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
275 else if ("choice".compareToIgnoreCase(currentWord) == 0) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
276 programOption.setChoices(rest.replace("(", "").replace(")", "").split(", "));
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
277 programOption.setType("choice");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
278 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
279 // Boolean type
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
280 else if ("bool".compareToIgnoreCase(currentWord) == 0) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
281 programOption.setType("boolean");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
282 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
283 // Other type
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
284 else {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
285 if (currentWord == null) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
286 this.message = "Program '" + this.fileName + "' has a problem concerning the type of option '" + identifier + "'.\n";
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
287 return;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
288 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
289 programOption.setType(currentWord);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
290 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
291 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
292 // Default value
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
293 else if ("default".compareToIgnoreCase(type) == 0) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
294 programOption.setDefault(value);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
295 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
296 else {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
297 this.message = "Do not understand option descriptor '" + inner + "'.\n";
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
298 return;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
299 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
300 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
301 else {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
302 // Compulsory option
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
303 if ("compulsory".compareToIgnoreCase(inner) == 0) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
304 programOption.setCompulsory(true);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
305 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
306 else {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
307 this.message = "Do not understand option descriptor '" + inner + "'.\n";
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
308 return;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
309 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
310 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
311 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
312 if (! programOption.checkSettings()) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
313 this.message = "Program '" + this.fileName + "' has a problem concerning option '" + identifier + "'.\n";
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
314 return;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
315 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
316 program.addOption(programOption);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
317 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
318
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
319 // Set associated option
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
320 Iterator it = associatedOption.keySet().iterator();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
321 while (it.hasNext()) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
322 ProgramOption programOption = (ProgramOption) it.next();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
323 programOption.setAssociatedOption(identifierToOptions.get(associatedOption.get(programOption)));
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
324 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
325 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
326
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
327 public String getMessage () {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
328 return this.message;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
329 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
330
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
331 public Program getProgram () {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
332 return this.program;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
333 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
334 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
335
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
336