From: Holger Z. <hz...@us...> - 2004-07-28 11:54:58
|
Update of /cvsroot/jake2/jake2/src/jake2/qcommon In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28905/src/jake2/qcommon Modified Files: Com.java Log Message: fix parser bug Index: Com.java =================================================================== RCS file: /cvsroot/jake2/jake2/src/jake2/qcommon/Com.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Com.java 23 Jul 2004 22:38:52 -0000 1.4 --- Com.java 28 Jul 2004 11:54:43 -0000 1.5 *************** *** 87,96 **** public static class ParseHelp { - - public ParseHelp(String in, int offset) - { - this(in.toCharArray(), offset); - } - public ParseHelp(String in) { --- 87,90 ---- *************** *** 113,120 **** public ParseHelp(char in[], int offset) { ! if (in == null || in.length == 0) ! data= null; ! else ! data= in; index= offset; } --- 107,111 ---- public ParseHelp(char in[], int offset) { ! data= in; index= offset; } *************** *** 152,155 **** --- 143,155 ---- } } + + public char prevchar() { + if (index > 0) + { + index--; + return data[index]; + } + return 0; + } public boolean isEof() *************** *** 189,247 **** // See GameSpanw.ED_ParseEdict() to see how to use it now. ! // works perfect ! ! public static String Parse(ParseHelp hlp) ! { ! int c; ! int len= 0; ! len= 0; ! ! com_token[0]= 0; ! if (hlp.data == null) ! { return ""; } ! // skip whitespace ! hlp.skipwhites(); ! ! if (hlp.isEof()) ! { ! return ""; ! } ! // skip // comments ! if (hlp.getchar() == '/') ! { ! if (hlp.nextchar() == '/') ! { ! if ((hlp.skiptoeol() == 0) || (hlp.skipwhites() == 0)) ! { return ""; } ! } ! else ! { ! com_token[len]= '/'; ! len++; ! } } - // handle quoted strings specially - if (hlp.getchar() == '\"') - { - while (true) - { - c= hlp.nextchar(); - if (c == '\"' || c == 0) - { ! hlp.nextchar(); ! com_token[len]= '?'; return new String(com_token, 0, len); } ! if (len < Defines.MAX_TOKEN_CHARS) ! { ! com_token[len]= hlp.getchar(); len++; } --- 189,230 ---- // See GameSpanw.ED_ParseEdict() to see how to use it now. ! public static String Parse(ParseHelp hlp) { int c; ! int len = 0; ! if (hlp.data == null) { return ""; } ! while (true) { ! // skip whitespace ! hlp.skipwhites(); ! if (hlp.isEof()) ! return ""; ! // skip // comments ! if (hlp.getchar() == '/') { ! if (hlp.nextchar() == '/') { ! hlp.skipwhitestoeol(); return ""; + } else { + hlp.prevchar(); + break; } ! } else ! break; } ! // handle quoted strings specially ! if (hlp.getchar() == '\"') { ! hlp.nextchar(); ! while (true) { ! c = hlp.getchar(); ! hlp.nextchar(); ! if (c == '\"' || c == 0) { return new String(com_token, 0, len); } ! if (len < Defines.MAX_TOKEN_CHARS) { ! com_token[len] = (char) c; len++; } *************** *** 249,275 **** } ! // parse a regular word ! do ! { ! if (len < Defines.MAX_TOKEN_CHARS) ! { ! com_token[len]= hlp.getchar(); len++; } ! c= hlp.nextchar(); ! } ! while (c > 32); ! ! if (len == Defines.MAX_TOKEN_CHARS) ! { ! Printf("Token exceeded " + Defines.MAX_TOKEN_CHARS + " chars, discarded.\n"); ! len= 0; } - // trigger the eof - hlp.skipwhites(); - - com_token[len]= 0; return new String(com_token, 0, len); } --- 232,250 ---- } ! // parse a regular word ! c = hlp.getchar(); ! do { ! if (len < Defines.MAX_TOKEN_CHARS) { ! com_token[len] = (char) c; len++; } + c = hlp.nextchar(); + } while (c > 32); ! if (len == Defines.MAX_TOKEN_CHARS) { ! Com.Printf("Token exceeded " + Defines.MAX_TOKEN_CHARS + " chars, discarded.\n"); ! len = 0; } return new String(com_token, 0, len); } |