bool chapter_range_parse(char *str, chapter_range *range) { if (!str || !range || !read_book(str, &str, range->book)) { return false; } long chapter = strtol(str, &str, 10); if (chapter < 1 || chapter > 256) { return false; } while (isspace(*str)) { str++; } range->chapter_start = (uint8_t)(chapter - 1); if (!*str) { range->chapter_end = (uint8_t)(chapter - 1); return true; } if (*str != '-') { return false; } str++; while (isspace(*str)) { str++; } char book2[NTREF_BOOK_LEN]; if (read_book(str, &str, book2) && strcmp(range->book, book2)) { return false; } chapter = strtol(str, &str, 10); if (chapter <= range->chapter_start || chapter > 256) { return false; } while (isspace(*str)) { str++; } if (*str) { return false; } range->chapter_end = (uint8_t)(chapter - 1); return true; }
void parse_knowledge_item(xmlNode *in) { xmlNode * cur; int id = -1; char * strID=NULL; char * string=NULL; for(cur=in;cur;cur=cur->next){ if(cur->type == XML_ELEMENT_NODE){ if(!xmlStrcasecmp(cur->name,(xmlChar*)"Knowledge")){ if ((strID=(char*)xmlGetProp(cur,(xmlChar*)"ID"))==NULL){ LOG_ERROR("Knowledge Item does not contain an ID property."); } else { id = atoi(strID); if(cur->children && cur->children->content && MY_XMLSTRCPY(&string, (char*)cur->children->content)!=-1){ if (read_book(string, 2, id + KNOWLEDGE_BOOK_OFFSET) != NULL) { knowledge_list[id].has_book = 1; } } else { #ifndef OSX LOG_ERROR("An error occured when parsing the content of the <%s>-tag on line %d - Check it for letters that cannot be translated into iso8859-1\n", cur->name, cur->line); #else LOG_ERROR("An error occured when parsing the content of the <%s>-tag - Check it for letters that cannot be translated into iso8859-1\n", cur->name); #endif } xmlFree(strID); free(string); string = NULL; } } } } return; }
bool word_ref_parse(char *str, word_ref *ref) { if (!str || !ref || !read_book(str, &str, ref->book)) { return false; } long chapter = strtol(str, &str, 10); if (chapter < 1 || chapter > 256) { return false; } if (*str != ':') { return false; } str++; long verse = strtol(str, &str, 10); if (verse < 1 || verse > 256) { return false; } if (*str != '+') { return false; } str++; long word = strtol(str, &str, 10); if (word < 0 || word > 255) { return false; } while (isspace(*str)) { str++; } if (*str) { return false; } ref->chapter = (uint8_t)(chapter - 1); ref->verse = (uint8_t)(verse - 1); ref->word = (uint8_t)word; return true; }
void read_local_book (const char *data, int len) { char file_name[200]; book *b; safe_snprintf (file_name, sizeof(file_name), "%.*s", len-3, data+3); b = get_book (SDL_SwapLE16 (*((Uint16*)(data+1)))); if (b == NULL) { b = read_book (file_name, data[0], SDL_SwapLE16 (*((Uint16*)(data+1)))); if (b == NULL) { char str[200]; safe_snprintf (str, sizeof(str), book_open_err_str, file_name); LOG_TO_CONSOLE(c_red1, str); return; } } display_book_window (b); // Otherwise there's no point... }
bool chapter_ref_parse(char *str, chapter_ref *ref) { if (!str || !ref || !read_book(str, &str, ref->book)) { return false; } long chapter = strtol(str, &str, 10); if (chapter < 1 || chapter > 256) { return false; } while (isspace(*str)) { str++; } if (*str) { return false; } ref->chapter = (uint8_t)(chapter - 1); return true; }
void init_books() { #ifdef NEW_TEXTURES paper1_text = load_texture_cached ("textures/paper1.dds", tt_image); book1_text = load_texture_cached ("textures/book1.dds", tt_image); #else /* NEW_TEXTURES */ paper1_text = load_texture_cache_deferred ("./textures/paper1.bmp", 0); book1_text = load_texture_cache_deferred ("./textures/book1.bmp", 0); #endif /* NEW_TEXTURES */ read_book("books/races/human.xml", 2, book_human); read_book("books/races/gnome.xml", 2, book_gnome); //Adding books out of order helps slightly for our tree. read_book("books/races/dwarf.xml", 2, book_dwarf); read_book("books/races/elf.xml", 2, book_elf); read_book("books/races/orchan.xml", 2, book_orchan); read_book("books/races/draegoni.xml", 2, book_draegoni); read_knowledge_book_index(); }
bool word_range_parse(char *str, word_range *range) { if (!str || !range || !read_book(str, &str, range->book)) { return false; } char *rem; long chapter = strtol(str, &str, 10); if (chapter < 1 || chapter > 256) { return false; } if (*str != ':') { return false; } str++; long verse = strtol(str, &str, 10); if (verse < 1 || verse > 256) { return false; } if (*str != '+') { return false; } str++; long word = strtol(str, &rem, 10); if (str == rem || word < 0 || word > 255) { return false; } str = rem; // allow us to read the old format if (islower(*str)) { str++; } while (isspace(*str)) { str++; } range->chapter_start = (uint8_t)(chapter - 1); range->verse_start = (uint8_t)(verse - 1); range->word_start = (uint8_t)word; if (!*str) { range->chapter_end = (uint8_t)(chapter - 1); range->verse_end = (uint8_t)(verse - 1); range->word_end = (uint8_t)word; return true; } if (*str != '-') { return false; } str++; while (isspace(*str)) { str++; } char book2[NTREF_BOOK_LEN]; bool repeat_book = read_book(str, &rem, book2) && *rem; if (repeat_book) { if (strcmp(range->book, book2)) { return false; } else { str = rem; } } word = strtol(str, &rem, 10); if (str == rem) { return false; } str = rem; if (*str == ':') { chapter = word; str++; verse = strtol(str, &str, 10); if (verse < 1 || verse > 256) { return false; } if (*str != '+') { return false; } word = strtol(str, &str, 10); if (word < 0 || word > 255) { return false; } if (chapter <= range->chapter_start || chapter > 256) { return false; } else if (chapter == range->chapter_start + 1) { if (verse <= range->verse_start) { return false; } else if (verse == range->verse_start + 1 && word < range->word_start) { return false; } } } else if (repeat_book) { return false; } else if (*str == '+') { verse = word; str++; word = strtol(str, &str, 10); if (word < 0 || word > 255) { return false; } if (verse <= range->verse_start || verse > 256) { return false; } else if (verse == range->verse_start + 1 && word < range->word_start) { return false; } } else { if (word < 0 || word > 255) { return false; } } // allow us to read the old format if (islower(*str)) { str++; } while (isspace(*str)) { str++; } if (*str) { return false; } range->chapter_end = (uint8_t)(chapter - 1); range->verse_end = (uint8_t)(verse - 1); range->word_end = (uint8_t)word; return true; }
bool verse_range_parse(char *str, verse_range *range) { if (!str || !range || !read_book(str, &str, range->book)) { return false; } long chapter = strtol(str, &str, 10); if (chapter < 1 || chapter > 256) { return false; } if (*str != ':') { return false; } str++; long verse = strtol(str, &str, 10); if (verse < 1 || verse > 256) { return false; } while (isspace(*str)) { str++; } range->chapter_start = (uint8_t)(chapter - 1); range->verse_start = (uint8_t)(verse - 1); if (!*str) { range->chapter_end = (uint8_t)(chapter - 1); range->verse_end = (uint8_t)(verse - 1); return true; } if (*str != '-') { return false; } str++; while (isspace(*str)) { str++; } char book2[NTREF_BOOK_LEN]; bool repeat_book = read_book(str, &str, book2); if (repeat_book && strcmp(range->book, book2)) { return false; } verse = strtol(str, &str, 10); if (*str == ':') { chapter = verse; str++; verse = strtol(str, &str, 10); if (verse < 1 || verse > 256) { return false; } if (chapter <= range->chapter_start || chapter > 256) { return false; } else if (chapter == range->chapter_start + 1 && verse <= range->verse_start) { return false; } } else { if (repeat_book) { return false; } if (verse <= range->verse_start || verse > 256) { return false; } } while (isspace(*str)) { str++; } if (*str) { return false; } range->chapter_end = (uint8_t)(chapter - 1); range->verse_end = (uint8_t)(verse - 1); return true; }