Пример #1
0
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;
}
Пример #2
0
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;
}
Пример #3
0
int WikiManage::wiki_parse_url_full_search(const char *url, char *flag, char *title, char **data)
{
	full_search_t *fs = &m_search_buf;
	
	int size, i = atoi(url);
	struct one_lang *p = wiki_full_search_find_lang(i);

	strcpy(flag, "1");
	strcpy(title, fs->key);

	if (p == NULL)
		return wiki_not_found(data, &size, "Not Found.");

	int len;
	sort_idx_t idx;

	if (p->index->wi_find(NULL, WK_INDEX_FIND, fs->page_idx[i], &idx, &len) == 0) {
		if ((len = p->data->wd_sys_read(idx.data_file_idx,
							idx.data_pos, idx.data_len, m_curr_content, _MAX_ONE_PAGE_SIZE)) > 0) {
			m_curr_content[len] = 0;

			if (m_wiki_config->wc_get_audio_flag()) {
				len = wiki_parse_audio_flag(m_curr_content, len, m_curr_page);
				memcpy(m_curr_content, m_curr_page, len);
				m_curr_content[len] = 0;
			}

			if (m_wiki_config->wc_get_need_translate()) {
				len = wiki_translate_format(m_curr_content, len, m_curr_page);
				memcpy(m_curr_content, m_curr_page, len);
				m_curr_content[len] = 0;
			}

			int size = convert_page_simple(m_curr_page, m_curr_content, len, fs->key);
			m_curr_page[size] = 0;

			char tmp[256];

			p->index->wi_get_key(&idx, tmp);
			m_curr_lang = p;
			wiki_push_back(STATUS_CONTENT, tmp, len, &idx);

			return wiki_not_found(data, &size, m_curr_page, size);
		}
	}

	return wiki_not_found(data, &size, "Not Found.");
}
Пример #4
0
int WikiManage::wiki_full_search(const char *key, char **buf, int *size, int page)
{
	struct one_lang *which;

	SET_CURR_TITLE(key);

	if (wiki_check_full_search(key) == 0) 
		wiki_full_search_update(key);

	if (m_search_buf.page_total == 0)
		return wiki_not_found(buf, size, "Not found");

	if (page == 0) {
		m_curr_lang = &m_all_lang[0];
		wiki_push_back(STATUS_FULL_TEXT, key, 0, NULL);
	}

	return wiki_full_search_one_page(buf, size, page);
}
Пример #5
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;
}
Пример #6
0
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;
}
Пример #7
0
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;
}