Example #1
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;
}
Example #2
0
/*
 * parse "lang:dictionary:title"
 */
int WikiManage::wiki_parse_url_lang(const char *url, char *flag, char *title, char **data)
{
	int ret_size;
	char *p, tmp[128];
	struct one_lang *which;

	strcpy(tmp, url);
	url_convert(tmp);

	if ((p = strchr(tmp, ':')) == NULL)
		return -1;

	*p++ = 0;

	if ((which = wiki_get_lang_addr(tmp)) == NULL) {
		wiki_init_one_lang(tmp, 0);
		if ((which = wiki_get_lang_addr(tmp)) == NULL)
			return -1;
	}

	m_curr_lang = which;

	if (wiki_find_key(p, data, &ret_size) == 0) {
		strcpy(title, p);
		strcpy(flag, "1");
		return 0;
	}

	return -1;
}
Example #3
0
int WikiManage::wiki_sys_translate(const char *key, const char *lang, char **buf)
{
	struct one_lang *p = wiki_get_lang_addr(lang);

	if (p == NULL) {
		wiki_init_one_lang(lang, 0);
		if ((p = wiki_get_lang_addr(lang)) == NULL) {
			sprintf(m_trans_buf, "Not found %s.<br/>\nRead data file error.", key);
			*buf = m_trans_buf;
			return -1;
		}
	}

	char tmp[1024];
	int x = 0;

	for (const char *t = key; *t; t++) {
		if (*t >= 'A' && *t <= 'Z') {
			tmp[x++] = *t + 'a' - 'A';
		} else {
			tmp[x++] = *t;
		}
	}
	tmp[x] = 0;

	*buf = m_trans_buf;

	wiki_translate2(p, tmp, x, m_trans_buf);

	return 0;
}
Example #4
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;
}
Example #5
0
int WikiManage::wiki_random_favorite(char **buf, int *size)
{
	struct one_lang *which;

	struct fav_key key;
	struct fav_value value;

	if (!m_wiki_favorite->wf_random(&key, &value))
		return wiki_not_found(buf, size, _("FW_RANDOM_RETRY"));

	if ((which = wiki_get_lang_addr(key.lang)) == NULL) {
		wiki_init_one_lang(key.lang, 0);
		if ((which = wiki_get_lang_addr(key.lang)) == NULL) {
			return wiki_not_found(buf, size, "Not found");
		}
	}
	m_curr_lang = which;

	return wiki_find_key(key.title, buf, size);
}
Example #6
0
int WikiManage::wiki_curr_date_home_page(char **buf, int *size)
{
	int pos = 0, total = 0;
	char *lang, date[128], tmp[4096], save_date[128];
	struct one_lang *which;

	pos += sprintf(tmp, "<table cellspacing=0.5 width=100%% border=1>\n"
					"<tr><td width=30%%>%s</td><td width=70%%>%s</td></tr>\n",
					_("FW_HP_DICT"), _("FW_HP_CURR_DATE"));

	for (int i = 0; i < m_select_lang_total; i++) {
		lang = m_select_lang[i];
		get_month_day_from_lang(date, lang);

		if (date[0] == 0)
			continue;

		if ((which = wiki_get_lang_addr(lang)) == NULL) {
			wiki_init_one_lang(lang, 0);
			if ((which = wiki_get_lang_addr(lang)) == NULL) {
				continue;
			}
		}

		total++;
		strcpy(save_date, date);
		m_curr_lang = which;
		pos += snprintf(tmp + pos, sizeof(tmp) - pos,
					"<tr><td width=30%%>%s</td><td width=70%%><a href='lang:%s:%s'>%s</a></td></tr>\n",
					lang, lang, date, date);
	}

	if (total == 0)
		strcpy(tmp, _("CANNT_FIND_CURR_DATE"));
	else if (total == 1)
		return wiki_find_key(save_date, buf, size);
	else
		pos += snprintf(tmp + pos, sizeof(tmp) - pos, "%s", "</table>\n");

	return wiki_not_found(buf, size, tmp);
}
Example #7
0
int WikiManage::wiki_init_all_lang()
{
	struct one_lang *which;

	for (int i = 0; i < m_select_lang_total; i++) {
		if ((which = wiki_get_lang_addr(m_select_lang[i])) == NULL) {
			wiki_init_one_lang(m_select_lang[i], 0);
		}
	}

	return 0;
}
Example #8
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;
}
Example #9
0
int WikiManage::wiki_match(const char *start, wiki_title_t **buf, int *total)
{
	m_match_title_total = 0;
	m_match_title_flag = 0;
	*total = 0;

	if (m_init_flag == 0)
		return 0;

	/* TODO */
	strncpy(m_curr_match_key, start, sizeof(m_curr_match_key) - 1);

	int len, flag;
	struct one_lang *which;
	WikiIndex *wiki_index;
	sort_idx_t sort_idx[MAX_FIND_RECORD + 1];

	char key[512], tmp[2048];
	char *title;

	for (int i = 0; i < m_select_lang_total; i++) {
		if ((which = wiki_get_lang_addr(m_select_lang[i])) == NULL) {
			wiki_init_one_lang(m_select_lang[i], 0);
			if ((which = wiki_get_lang_addr(m_select_lang[i])) == NULL) {
				return -1;
			}
		}
		wiki_index = which->index;

		flag = 0;
		if (wiki_index->wi_find(start, WK_LIKE_FIND, -1, sort_idx, &len) == -1) {
			flag = 1;
			if (wiki_index->wi_find(start, WK_MATCH_FIND, -1, sort_idx, &len) == -1) {
				continue;
			}
		}
		m_match_title_flag++;

		for (int j = 0; j < len; j++) {
			sort_idx_t *p = &sort_idx[j];
			wiki_index->wi_get_key(p, key);

			if (flag) {
				wiki_conv_key(wiki_index, start, key, (int)p->key_len, tmp);
				title = tmp;
			} else
				title = key;

			if (m_match_title_total >= MAX_MATCH_TITLE_TOTAL)
				goto out;

			wiki_title_t *wt = &m_match_title[m_match_title_total++];

			strncpy(wt->title, title, sizeof(wt->title) - 1);
			memcpy(&wt->idx, p, sizeof(wt->idx));
			wt->which = which;
		}
	}

out:

	if (m_wiki_config->wc_get_mutil_lang_list_mode()) {
		qsort(m_match_title, m_match_title_total, sizeof(wiki_title_t), _match_title_cmp);
	}

	if (m_match_title_total >= 256)
		m_match_title_total = 256;

	*buf = m_match_title;
	*total = m_match_title_total;

	return m_match_title_total;
}