protected String nextToken ( ) throws IOException { String token = "" ; int ch , nextch ; if ( ! tokenStack . empty ( ) ) { return ( String ) tokenStack . pop ( ) ; } // Skip over leading whitespace and comments while ( true ) { // skip leading whitespace ch = catfile . read ( ) ; while ( ch <= ' ' ) { // all ctrls are whitespace ch = catfile . read ( ) ; if ( ch < 0 ) { return null ; } } // now 'ch' is the current char from the file nextch = catfile . read ( ) ; if ( nextch < 0 ) { return null ; } if ( ch == ' ' && nextch == ' ' ) { // we've found a comment, skip it... ch = ' ' ; nextch = nextChar ( ) ; while ( ch != ' ' || nextch != ' ' ) { ch = nextch ; nextch = nextChar ( ) ; } // Ok, we've found the end of the comment, // loop back to the top and start again... } else { stack [ ++ top ] = nextch ; stack [ ++ top ] = ch ; break ; } } ch = nextChar ( ) ; if ( ch == ' ' || ch == ' ' ) { int quote = ch ; while ( ( ch = nextChar ( ) ) != quote ) { char [ ] chararr = new char [ 1 ] ; chararr [ 0 ] = ( char ) ch ; String s = new String ( chararr ) ; token = token . concat ( s ) ; } return token ; } else { // return the next whitespace or comment delimited // string while ( ch > ' ' ) { nextch = nextChar ( ) ; if ( ch == ' ' && nextch == ' ' ) { stack [ ++ top ] = ch ; stack [ ++ top ] = nextch ; return token ; } else { char [ ] chararr = new char [ 1 ] ; chararr [ 0 ] = ( char ) ch ; String s = new String ( chararr ) ; token = token . concat ( s ) ; ch = nextch ; } } return token ; } }
Return the next token in the catalog file .