# HG changeset patch # User Markus Bröker # Date 1239878953 -7200 # Node ID 2a20d0184041ded8c991507ac25e793001e3fcfc # Parent c064ce9f40f530a3bf4157090f06b4102efc2253 Console aborts with return code -1 on error committer: Markus Bröker diff --git a/libConsole/Console.java b/libConsole/Console.java --- a/libConsole/Console.java +++ b/libConsole/Console.java @@ -1,6 +1,21 @@ public class Console { public static native int getch (); + private static void help () { + String p = System.getProperty ("java.library.path"); + String[] msg = p.split (":"); + System.err.printf ("Console Error:\n"); + + for (int i = 0; i < msg.length; i++) + System.err.printf ("\t%s\n", msg[i]); + System.exit (-1); + }; + static { - System.loadLibrary ("Console"); - } + try { + System.loadLibrary ("Console"); + } catch (UnsatisfiedLinkError ule) { + System.err.println (ule.getLocalizedMessage ()); + help (); + } + }; } diff --git a/libConsole/Getch.java b/libConsole/Getch.java --- a/libConsole/Getch.java +++ b/libConsole/Getch.java @@ -5,6 +5,7 @@ int c; System.out.println ("Press q or ESCAPE to quit"); + for (;;) { c = Console.getch (); switch (c) { @@ -14,7 +15,8 @@ break; default: System.out.printf ("KEY: %c (%d)\n", c, c); + break; } } }; -}; +} diff --git a/libConsole/Makefile b/libConsole/Makefile --- a/libConsole/Makefile +++ b/libConsole/Makefile @@ -43,5 +43,4 @@ LD_LIBRARY_PATH=lib $(JAVA) -cp . Getch run: Getch.class $(LIB) - @echo "You need to copy libConsole.(so|dll) to $(JAVA_DIR)/jre/lib/i386" $(JAVA) -cp . Getch