import java.io.IOException; public class GetInput { public final static int LINE = 70; static String buf = new String(); static int getinp(String prompt, String[] list) { int i = 0; int n_match = 0; int match = 0; String sp = null; while (true) { while (true) { System.out.print(prompt); try { buf = CIOUtils.stdin.readLine() + '\n'; } catch (IOException e) { System.err.println("IO Exception:" + e); } break; } if (buf.charAt(0) == '?' && buf.charAt(1) == '\n') { System.out.print("Valid inputs are: "); i = 0; for (match = 18;list[i] != null;i++) { if ((match += (n_match = list[i].length())) > LINE) { System.out.print("\n\t"); match = n_match + 8; } if (list[i].length() == 0) { match += 8; System.out.print(""); } else { System.out.print(list[i]); } if (list[i + 1] != null) { System.out.print(", "); } else { System.out.println(); } match += 2; } continue; } sp = ""; buf = buf.toLowerCase(); n_match = 0; for (i = n_match;list[i] != null;i++) { if (comp(list[i])) { n_match++; match = i; } } if (n_match == 1) { return match; } else if (buf.length() != 0) { System.out.println("Illegal response: \"" + buf + "\". Use '?' to get list of valid answers"); } } } static boolean comp(String s1) { return buf.length() > 0 && buf.toLowerCase().startsWith(s1.toLowerCase()); } }