+ public abstract void execute(Writer w, String[] args) throws IOException;
+
+
+ /** Returns single-line of usage information, eg. <tt>usage: ls [pattern]</tt> */
+ public void usage(Writer w) throws IOException {
+ w.write("usage: ");
+ w.write(name());
+ w.write(" ");
+ w.write(params());
+ w.write("\n");
+ }
+
+ public List fromShellPath(String s) throws Shell.NoSuchPathException {
+ return fromShellPath(s, null);
+ }
+
+ /** Converts a shell path "/foo/etc/../bar" to its component form,
+ * { "foo", "bar" } and loads it into the returned list.
+ * Handles relative positioning to shell.getPath(). */
+ public List fromShellPath(String s, List l) throws Shell.NoSuchPathException {
+ if (s == null) return null;
+ if (l == null) l = new ArrayList();
+
+ s = s.trim().replace("/+", "/");
+ if (s.charAt(0) != '/') l.addAll(Arrays.asList(shell.getPath()));
+
+ StringTokenizer st = new StringTokenizer(s, "/");
+ while (st.hasMoreTokens()) {
+ String part = st.nextToken();
+ if (part == null || part.equals("") || part.equals(".")) continue;
+ else if (part.equals("..")) { if (l.size() > 0) l.remove(l.size() - 1); }
+ else l.add(part);
+ }
+
+ return l;
+ }