From: Rene S. <sa...@us...> - 2005-12-13 00:03:49
|
Update of /cvsroot/jake2/jake2/src/jake2/util In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3069/src/jake2/util Modified Files: Lib.java Log Message: applied almost final beautification Index: Lib.java =================================================================== RCS file: /cvsroot/jake2/jake2/src/jake2/util/Lib.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** Lib.java 12 Dec 2005 21:50:02 -0000 1.14 --- Lib.java 13 Dec 2005 00:03:41 -0000 1.15 *************** *** 34,72 **** ! /* ! ============= ! VectorToString ! ! This is just a convenience function ! for printing vectors ! ============= ! */ public static String vtos(float[] v) { return (int) v[0] + " " + (int) v[1] + " " + (int) v[2]; } public static String vtofs(float[] v) { return v[0] + " " + v[1] + " " + v[2]; } public static String vtofsbeaty(float[] v) { return Com.sprintf("%8.2f %8.2f %8.2f", new Vargs().add(v[0]).add(v[1]).add(v[2])); } public static short rand() { - //return (short) (Math.random() * 0x8000); return (short)Globals.rnd.nextInt(Short.MAX_VALUE+1); } public static float crandom() { return (Globals.rnd.nextFloat() - 0.5f) * 2.0f; - //return (float) (Math.random() - 0.5) * 2.0f; } public static float random() { return Globals.rnd.nextFloat(); } public static float crand() { return (Globals.rnd.nextFloat() - 0.5f) * 2.0f; } public static int strcmp(String in1, String in2) { return in1.compareTo(in2); } public static float atof(String in) { float res = 0; --- 34,78 ---- ! /** Converts a vector to a string. */ public static String vtos(float[] v) { return (int) v[0] + " " + (int) v[1] + " " + (int) v[2]; } + + /** Converts a vector to a string. */ public static String vtofs(float[] v) { return v[0] + " " + v[1] + " " + v[2]; } + + /** Converts a vector to a beatiful string. */ public static String vtofsbeaty(float[] v) { return Com.sprintf("%8.2f %8.2f %8.2f", new Vargs().add(v[0]).add(v[1]).add(v[2])); } + + /** Like in libc. */ public static short rand() { return (short)Globals.rnd.nextInt(Short.MAX_VALUE+1); } + + /** Like in libc. */ public static float crandom() { return (Globals.rnd.nextFloat() - 0.5f) * 2.0f; } + + /** Like in libc. */ public static float random() { return Globals.rnd.nextFloat(); } + + /** Like in libc. */ public static float crand() { return (Globals.rnd.nextFloat() - 0.5f) * 2.0f; } + + /** Like in libc. */ public static int strcmp(String in1, String in2) { return in1.compareTo(in2); } + /** Like in libc. */ public static float atof(String in) { float res = 0; *************** *** 80,88 **** return res; } public static int Q_stricmp(String in1, String in2) { return in1.compareToIgnoreCase(in2); } - // ================================================================================= public static int atoi(String in) { try { --- 86,96 ---- return res; } + + /** Like in quake2. */ public static int Q_stricmp(String in1, String in2) { return in1.compareToIgnoreCase(in2); } + /** Like in libc. */ public static int atoi(String in) { try { *************** *** 98,101 **** --- 106,110 ---- } + /** Converts a string to a vector. Needs improvement. */ public static float[] atov(String v) { float[] res = { 0, 0, 0 }; *************** *** 108,111 **** --- 117,121 ---- } + /** Like in libc. */ public static int strlen(char in[]) { for (int i = 0; i < in.length; i++) *************** *** 115,118 **** --- 125,129 ---- } + /** Like in libc. */ public static int strlen(byte in[]) { for (int i = 0; i < in.length; i++) *************** *** 122,125 **** --- 133,137 ---- } + /** Converts memory to a memory dump string. */ public static String hexdumpfile(ByteBuffer bb, int len) throws IOException { *************** *** 133,137 **** } ! // dump data as hexstring public static String hexDump(byte data1[], int len, boolean showAddress) { StringBuffer result = new StringBuffer(); --- 145,149 ---- } ! /** Converts memory to a memory dump string. */ public static String hexDump(byte data1[], int len, boolean showAddress) { StringBuffer result = new StringBuffer(); *************** *** 167,175 **** return result.toString(); } ! //formats an hex byte public static String hex2(int i) { String val = Integer.toHexString(i & 0xff); ! return ("00".substring(0, 2 - val.length()) + val).toUpperCase(); } public static char readableChar(int i) { if ((i < 0x20) || (i > 0x7f)) --- 179,190 ---- return result.toString(); } ! ! /** Formats an hex byte. */ public static String hex2(int i) { String val = Integer.toHexString(i & 0xff); ! return ("00".substring(0, 2 - val.length()) + val).toUpperCase(); } + + /** Returns true if the char is alphanumeric. */ public static char readableChar(int i) { if ((i < 0x20) || (i > 0x7f)) *************** *** 178,181 **** --- 193,198 ---- return (char) i; } + + /** Prints a vector to the quake console. */ public static void printv(String in, float arr[]) { for (int n = 0; n < arr.length; n++) { *************** *** 183,187 **** --- 200,207 ---- } } + static final byte nullfiller[] = new byte[8192]; + + /** Like in libc. */ public static void fwriteString(String s, int len, RandomAccessFile f) throws IOException { if (s == null) *************** *** 196,199 **** --- 216,221 ---- f.write(s.getBytes(), 0, len); } + + /** Like in libc */ public static RandomAccessFile fopen(String name, String mode) { try { *************** *** 205,208 **** --- 227,232 ---- } } + + /** Like in libc */ public static void fclose(RandomAccessFile f) { try { *************** *** 212,215 **** --- 236,241 ---- } } + + /** Like in libc */ public static String freadString(RandomAccessFile f, int len) { byte buffer[] = new byte[len]; *************** *** 218,221 **** --- 244,249 ---- return Lib.CtoJava(buffer); } + + /** Returns the right part of the string from the last occruence of c. */ public static String rightFrom(String in, char c) { int pos = in.lastIndexOf(c); *************** *** 226,229 **** --- 254,259 ---- return ""; } + + /** Returns the left part of the string from the last occruence of c. */ public static String leftFrom(String in, char c) { int pos = in.lastIndexOf(c); *************** *** 235,238 **** --- 265,269 ---- } + /** Renames a file. */ public static int rename(String oldn, String newn) { try { *************** *** 246,249 **** --- 277,282 ---- } } + + /** Converts an int to 4 bytes java representation. */ public static byte[] getIntBytes(int c) { byte b[] = new byte[4]; *************** *** 254,260 **** --- 287,297 ---- return b; } + + /** Converts an 4 bytes java int representation to an int. */ public static int getInt(byte b[]) { return (b[0] & 0xff) | ((b[1] & 0xff) << 8) | ((b[2] & 0xff) << 16) | ((b[3] & 0xff) << 24); } + + /** Duplicates a float array. */ public static float[] clone(float in[]) { float out[] = new float[in.length]; *************** *** 266,269 **** --- 303,307 ---- } + /** Helper method that savely handles the null termination of old C String data. */ public static String CtoJava(String old) { int index = old.indexOf('\0'); *************** *** 272,279 **** --- 310,319 ---- } + /** Helper method that savely handles the null termination of old C String data. */ public static String CtoJava(byte[] old) { return CtoJava(old, 0, old.length); } + /** Helper method that savely handles the null termination of old C String data. */ public static String CtoJava(byte[] old, int offset, int maxLenght) { if (old.length == 0 || old[0] == 0) return ""; *************** *** 284,290 **** ! /* ! * java.nio.* Buffer util functions ! */ public static final int SIZEOF_FLOAT = 4; --- 324,328 ---- ! /* java.nio.* Buffer util functions */ public static final int SIZEOF_FLOAT = 4; |