int WikiManage::wiki_view_index(int idx, char **buf, int *size) { int n; char tmp[256]; wiki_title_t *p; WikiIndex *wiki_index; if (idx >= m_match_title_total) { *buf = m_buf; *size = wiki_not_found(buf, size, NOT_FOUND); return 0; } p = &m_match_title[idx]; wiki_index = p->which->index; m_curr_lang = p->which; wiki_index->wi_get_key(&p->idx, tmp); if ((n = wiki_read_data(&p->idx, buf, tmp)) > 0) { wiki_push_back(STATUS_MATCH_KEY, m_curr_match_key, 0, NULL); wiki_push_back(STATUS_CONTENT, wiki_curr_title(), n, &p->idx); *size = n; return n; } *buf = m_buf; *size = wiki_not_found(buf, size, "Data file error."); return 0; }
int WikiManage::wiki_page_last_read(char **buf, int *size) { struct one_lang *which; history_key_t key; history_value_t value; m_wiki_history->wh_get_last_record(&key, &value); wiki_init_one_lang(key.lang, 0); if ((which = wiki_get_lang_addr(key.lang)) == NULL) return -1; m_curr_lang = which; int n, len; sort_idx_t sort_idx[MAX_FIND_RECORD + 1]; if (which->index->wi_find(key.title, WK_LIKE_FIND, -1, sort_idx, &len) == -1) return -1; if ((n = wiki_read_data(&sort_idx[0], buf, key.title)) > 0) { *size = n; return n; } return -1; }
int WikiManage::wiki_random_select_lang(char **buf, int *size) { sort_idx_t idx; int n = rand() % m_select_lang_total; struct one_lang *which; if (m_select_lang_total <= 0) /* TODO */ return wiki_not_found(buf, size, "I'm Blank"); if ((which = wiki_get_lang_addr(m_select_lang[n])) == NULL) { wiki_init_one_lang(m_select_lang[n], 0); if ((which = wiki_get_lang_addr(m_select_lang[n])) == NULL) { return wiki_not_found(buf, size, "Not found"); } } m_curr_lang = which; for (int i = 0; i < 100; i++) { which->index->wi_random_key(&idx); if ((n = wiki_read_data(&idx, buf, NULL)) > 0) { wiki_push_back(STATUS_CONTENT, wiki_curr_title(), n, &idx); *size = n; return n; } } return -1; }
int WikiManage::wiki_curr(char **buf, int *size) { int n; const cache_t *p = m_wiki_history->wh_curr_cache(); if (p == NULL) return wiki_index_msg(buf, size); if ((n = wiki_read_data(&p->idx, buf, NULL)) > 0) { *size = n; return n; } return 0; }
int WikiManage::wiki_curr(char **buf, int *size) { int n; const cache_t *p = m_wiki_history->wh_curr_cache(); if (p == NULL) return wiki_index_msg(buf, size); if (p->flag == STATUS_FULL_TEXT) { return wiki_full_search(p->key.title, buf, size, m_search_buf.curr_page); } if ((n = wiki_read_data(&p->idx, buf, NULL)) > 0) { *size = n; return n; } return 0; }
int WikiManage::wiki_href(int href_idx, char **buf, int *size, const char *title) { int n, total; sort_idx_t idx[MAX_FIND_RECORD + 1]; WikiIndex *wiki_index = CURR_WIKI(index); if (wiki_index->wi_find(NULL, WK_INDEX_FIND, href_idx, idx, &total) == -1) { wiki_not_found(buf, size, _("WIKI_HREF_NOTFOUND")); /* TODO */ return -1; } if ((n = wiki_read_data(&idx[0], buf, title)) > 0) { wiki_push_back(STATUS_CONTENT, wiki_curr_title(), n, &idx[0]); *size = n; return 0; } wiki_not_found(buf, size, NOT_FOUND); return -1; }
int WikiManage::wiki_find_key(const char *key, char **buf, int *size) { int total, n; sort_idx_t idx[MAX_FIND_RECORD + 1]; WikiIndex *wiki_index; if (m_init_flag == 0) return -1; wiki_index = CURR_WIKI(index); if (wiki_index->wi_find(key, WK_KEY_FIND, -1, idx, &total) == -1) return -1; if ((n = wiki_read_data(&idx[0], buf, key)) > 0) { wiki_push_back(STATUS_CONTENT, wiki_curr_title(), n, &idx[0]); *size = n; return 0; } return -1; }
int WikiManage::wiki_random_all_lang(char **buf, int *size) { int total = 0; struct lang_list lang[128]; struct one_lang *which; sort_idx_t idx; memset(lang, 0, sizeof(lang)); wiki_get_lang_list(lang, &total); if (total <= 0) return -1; int n = rand() % total; if ((which = wiki_get_lang_addr(lang[n].lang)) == NULL) { wiki_init_one_lang(lang[n].lang, 0); if ((which = wiki_get_lang_addr(lang[n].lang)) == NULL) { return wiki_not_found(buf, size, "Not found"); } } m_curr_lang = which; for (int i = 0; i < 100; i++) { which->index->wi_random_key(&idx); if ((n = wiki_read_data(&idx, buf, NULL)) > 0) { wiki_push_back(STATUS_CONTENT, wiki_curr_title(), n, &idx); *size = n; return n; } } return -1; }