static void readCell( FILE *in, FILE *out ) { Cell cell; uint8_t *text = NULL; uint16_t dict[ 256 ]; uint8_t size; uint8_t type; uint16_t offset; fread( &cell, sizeof( Cell ), 1, in ); fprintf(out, " Flags: %8.2x (%u)\n", cell.zero, cell.zero); fprintf(out, " Dictionary: %8.8x (%lu)\n", cell.dictOffset, cell.dictOffset); fprintf(out, " Dict size: %8.2x (%u)\n", cell.dictCount, cell.dictCount); fprintf(out, " Text size: %8.4x (%u)\n", cell.textCount, cell.textCount); text = calloc( cell.textCount, sizeof( uint8_t ) ); if( text != NULL ) { size_t count1; size_t count2 = 1; fread( text, cell.textCount, sizeof( uint8_t ), in ); fseek( in, cell.dictOffset, SEEK_SET ); memset( dict, 0, 256 * sizeof( uint16_t ) ); fread( dict, cell.dictCount, sizeof( uint16_t ), in ); for(count1 = 0; count1 < cell.textCount; count1++, count2++) { switch( text[ count1 ] ) { case 0xFA: fprintf(out, "[(fa) </p>]"); break; case 0xFB: fprintf(out, "[(fb) <center>]"); break; case 0xFC: fprintf(out, "[(fc) <~spacing>]"); break; case 0xFD: fprintf(out, "[(fd) <br />]"); break; case 0xFE: fprintf(out, "[(fe) \" \"]"); break; case 0xFF: size = text[ ++count1 ]; type = text[ ++count1 ]; fprintf(out, "[(ff) <ESC: "); count1 = readEscape( out, text, type, size, count1 ); break; default: offset = dict[text[count1]]; #ifdef DICT_TRACE fprintf(out, "[(%2.2x -> %4.4x) %ls]", text[count1], dict[text[count1]], Vocabulary[dict[text[count1]]]); #else fprintf(out, "[%ls]", Vocabulary[dict[text[count1]]]); #endif } if (!(count2 & 7)) fputc('\n', out); } if ((count2 - 1) & 7) fputc('\n', out); } free(text); }
bool CssTokenizer::readString() { if (!lastReadEq('"') && !lastReadEq('\'')) return false; char delim = lastRead; currentToken.add(lastRead); readChar(); while (in != NULL) { if (lastReadEq(delim)) { currentToken.add(lastRead); readChar(); return true; } else if (lastReadEq('\n') || lastReadEq('\r') || lastReadEq('\f')) { throw new ParseException("end of line", "end of string"); } else if (lastReadEq('\\')) // note that even though readEscape() returns false it still // eats the '\'. readEscape() || readNewline(); else { currentToken.add(lastRead); readChar(); } } throw new ParseException("end of input", "end of string"); return false; }
bool CssTokenizer::readNMStart () { if (in == NULL) return false; if (lastReadEq('_') || lastReadInRange('a', 'z') || lastReadInRange('A', 'Z')) { currentToken.add(lastRead); readChar(); return true; } else return (readNonAscii() || readEscape()); }
bool CssTokenizer::readUrl() { string urlchars = "!#$%&*-[]-~"; if (!lastReadEq('(')) return false; currentToken.add(lastRead); readChar(); while(readWhitespace()) {}; if (readString()) { if (lastReadEq(')')) { currentToken.add(lastRead); readChar(); return true; } else { throw new ParseException(&lastRead, "end of url (')')"); } } while (in != NULL) { if (readWhitespace() || lastReadEq(')')) { while (readWhitespace()) {}; if (lastReadEq(')')) { currentToken.add(lastRead); readChar(); return true; } else { throw new ParseException(&lastRead, "end of url (')')"); } } else if (in != NULL && urlchars.find(lastRead)) { currentToken.add(lastRead); readChar(); } else if (!readNonAscii() && !readEscape()) { throw new ParseException(&lastRead, "end of url (')')"); } } throw new ParseException(&lastRead, "end of url (')')"); return false; }