------------------------------------------------------------------------
| 214 | |
| 215 | //------------------------------------------------------------------------ |
| 216 | void parser::parse(const char* fname) |
| 217 | { |
| 218 | char msg[1024]; |
| 219 | XML_Parser p = XML_ParserCreate(NULL); |
| 220 | if(p == 0) |
| 221 | { |
| 222 | throw exception("Couldn't allocate memory for parser"); |
| 223 | } |
| 224 | |
| 225 | XML_SetUserData(p, this); |
| 226 | XML_SetElementHandler(p, start_element, end_element); |
| 227 | XML_SetCharacterDataHandler(p, content); |
| 228 | |
| 229 | FILE* fd = fopen(fname, "r"); |
| 230 | if(fd == 0) |
| 231 | { |
| 232 | sprintf(msg, "Couldn't open file %s", fname); |
| 233 | throw exception(msg); |
| 234 | } |
| 235 | |
| 236 | bool done = false; |
| 237 | do |
| 238 | { |
| 239 | size_t len = fread(m_buf, 1, buf_size, fd); |
| 240 | done = len < buf_size; |
| 241 | if(!XML_Parse(p, m_buf, len, done)) |
| 242 | { |
| 243 | sprintf(msg, |
| 244 | "%s at line %d\n", |
| 245 | XML_ErrorString(XML_GetErrorCode(p)), |
| 246 | (int)XML_GetCurrentLineNumber(p)); |
| 247 | throw exception(msg); |
| 248 | } |
| 249 | } |
| 250 | while(!done); |
| 251 | fclose(fd); |
| 252 | XML_ParserFree(p); |
| 253 | |
| 254 | char* ts = m_title; |
| 255 | while(*ts) |
| 256 | { |
| 257 | if(*ts < ' ') *ts = ' '; |
| 258 | ++ts; |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | |
| 263 | //------------------------------------------------------------------------ |
no test coverage detected