Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[wiki-app] 64 bit fixes

pack structures an change (u)long to (u)int32_t
so that 64 bit OS can run the simulator

Signed-off-by: Christopher Hall <hsw@openmoko.com>
  • Loading branch information...
commit 4b41f1f64dd4661cd49efb71d2bb253eb8a742bb 1 parent 116bf3d
@hxw hxw authored
View
7 wiki-app/history.h
@@ -21,6 +21,7 @@
#ifndef WL_HISTORY_H
#define WL_HISTORY_H
+#include <inttypes.h>
#include "search.h"
#define HISTORY_RESULT_START 31
@@ -47,9 +48,9 @@ long history_get_y_pos();
void draw_clear_history(int bFlag);
long history_get_previous_idx(long current_idx_article, int b_drop_from_list);
-typedef struct _HISTORY {
- long idx_article;
- long last_y_pos;
+typedef struct __attribute__ ((packed)) _HISTORY {
+ int32_t idx_article;
+ int32_t last_y_pos;
char title[MAX_TITLE_SEARCH];
} HISTORY;
View
8 wiki-app/lcd_buf_draw.h
@@ -247,26 +247,26 @@ typedef struct _LCD_DRAW_BUF
/* section for a number of EXTERNAL_LINK blocks */
/* section for a number of external link strings */
/* section for the article string */
-typedef struct _ARTICLE_HEADER
+typedef struct __attribute__ ((packed)) _ARTICLE_HEADER
{
uint32_t offset_article;
uint16_t article_link_count;
uint16_t external_link_count;
} ARTICLE_HEADER;
-typedef struct _ARTICLE_LINK
+typedef struct __attribute__ ((packed)) _ARTICLE_LINK
{
uint32_t start_xy; /* byte 0: x; byte 1~3: y */
uint32_t end_xy;
uint32_t article_id;
} ARTICLE_LINK;
-typedef struct _EXTERNAL_LINK
+typedef struct __attribute__ ((packed)) _EXTERNAL_LINK
{
char *link_str;
} EXTERNAL_LINK;
-typedef struct _CONCAT_ARTICLE_INFO
+typedef struct __attribute__ ((packed)) _CONCAT_ARTICLE_INFO
{
uint32_t article_id;
uint32_t offset_article;
View
16 wiki-app/search.c
@@ -708,7 +708,7 @@ struct _hiragana_english_mapping {
{"-", "" },
};
-#define SIZE_PREFIX_INDEX_TABLE SEARCH_CHR_COUNT * SEARCH_CHR_COUNT * SEARCH_CHR_COUNT * sizeof(long)
+//#define SIZE_PREFIX_INDEX_TABLE SEARCH_CHR_COUNT * SEARCH_CHR_COUNT * SEARCH_CHR_COUNT * sizeof(long)
//static struct search_state state;
//static struct search_state last_first_hit;
@@ -1187,8 +1187,10 @@ int fetch_search_result(long input_offset_fnd_start, long input_offset_fnd_end,
offsetNextTitleSearch = 0;
pTitleSearch = (TITLE_SEARCH *)&search_info[nCurrentWiki].buf[offsetNextTitleSearch];
}
+ // use memcpy to avoid "Unaligned data access"
memcpy((void *)&result_list->idx_article[result_list->count],
- (void *)&pTitleSearch->idxArticle, sizeof(long)); // use memcpy to avoid "Unaligned data access"
+ (void *)&pTitleSearch->idxArticle,
+ sizeof(result_list->idx_article[result_list->count]));
result_list->offset_list[result_list->count] = offset_fnd_start + offsetNextTitleSearch;
offsetNextTitleSearch += sizeof(pTitleSearch->idxArticle) + strlen(pTitleSearch->sTitleSearch) +
strlen(&pTitleSearch->sTitleSearch[strlen(pTitleSearch->sTitleSearch) + 1]) + 3;
@@ -2050,7 +2052,7 @@ void search_hiragana_add_char()
i = search_str_converted_len;
if (search_str_len - i > LONGEST_HIRAGANA_ENGLISH_CHARS)
i = search_str_len - LONGEST_HIRAGANA_ENGLISH_CHARS;
- while (i < search_str_len && (search_string[i] == ' ' ||
+ while (i < search_str_len && (search_string[i] == ' ' ||
!(pHiragana = get_hiragana(&search_string[i], search_str_len - i, &used_len, &pEnglish))))
i++;
if (pHiragana)
@@ -2136,7 +2138,7 @@ int hiragana_to_english(char *sEnglish, char *sHiragana, int lenHiragana)
int i = 0;
char *pEnglish;
int used_len;
-
+
while (i < lenHiragana)
{
pEnglish = get_english(&sHiragana[i], lenHiragana - i, &used_len);
@@ -2174,7 +2176,7 @@ int search_remove_char(int bPopulate, unsigned long ev_time)
}
else
{
- while (search_str_hiragana_len > 0 &&
+ while (search_str_hiragana_len > 0 &&
((search_string_hiragana[search_str_hiragana_len - 1] & 0x80) &&
!(search_string_hiragana[search_str_hiragana_len - 1] & 0x40)))
search_str_hiragana_len--;
@@ -2210,11 +2212,11 @@ TITLE_SEARCH *locate_previous_title(char *buf, int len)
{
p = buf + len - 2;
len--;
- while (!bFound && len > sizeof(long))
+ while (!bFound && len > sizeof(uint32_t))
{
if (!*p) {
bFound = 1;
- p -= sizeof(long);
+ p -= sizeof(uint32_t);
}
else
{
View
16 wiki-app/search_hash.c
@@ -59,7 +59,7 @@ int *bHashBlockLoaded[MAX_WIKIS];
#define ENTRIES_PER_HASH_BLOCK 256
// FND_BUF_BLOCK_SIZE needs to be larger than MAX_RESULTS * sizeof(TITLE_SEARCH)
#define FND_BUF_BLOCK_SIZE 2048
-struct _fnd_buf {
+struct __attribute__ ((packed)) _fnd_buf {
uint32_t offset;
uint32_t len;
uint32_t used_seq;
@@ -320,7 +320,8 @@ int copy_fnd_to_buf(long offset, char *buf, int len)
{
blocked_offset = ((offset - SIZE_BIGRAM_BUF) / FND_BUF_BLOCK_SIZE) * FND_BUF_BLOCK_SIZE + SIZE_BIGRAM_BUF;
wl_seek(fdFnd[nCurrentWiki], blocked_offset);
- fnd_bufs[nCurrentWiki][i].len = wl_read(fdFnd[nCurrentWiki], fnd_bufs[nCurrentWiki][i].buf, FND_BUF_BLOCK_SIZE);
+ fnd_bufs[nCurrentWiki][i].len = wl_read(fdFnd[nCurrentWiki], &fnd_bufs[nCurrentWiki][i].buf,
+ sizeof(fnd_bufs[nCurrentWiki][i].buf));
#ifdef INCLUDED_FROM_KERNEL
if (wl_input_event_pending())
{
@@ -350,7 +351,8 @@ int copy_fnd_to_buf(long offset, char *buf, int len)
i = iLeastUsed;
blocked_offset = ((offset - SIZE_BIGRAM_BUF) / FND_BUF_BLOCK_SIZE) * FND_BUF_BLOCK_SIZE + SIZE_BIGRAM_BUF;
wl_seek(fdFnd[nCurrentWiki], blocked_offset);
- fnd_bufs[nCurrentWiki][i].len = wl_read(fdFnd[nCurrentWiki], fnd_bufs[nCurrentWiki][i].buf, FND_BUF_BLOCK_SIZE);
+ fnd_bufs[nCurrentWiki][i].len = wl_read(fdFnd[nCurrentWiki], fnd_bufs[nCurrentWiki][i].buf,
+ sizeof(fnd_bufs[nCurrentWiki][i].buf));
#ifdef INCLUDED_FROM_KERNEL
if (wl_input_event_pending())
{
@@ -404,13 +406,13 @@ long locate_previous_title_search(long offset_fnd)
copy_fnd_to_buf(offset_fnd, buf, len_buf);
i = len_buf - 1;
nZeros = 0;
- while (i >= sizeof(long) && nZeros < 3)
+ while (i >= sizeof(uint32_t) && nZeros < 3)
{
if (!buf[i])
nZeros++;
i--;
}
- i -= sizeof(long) - 1;
+ i -= sizeof(uint32_t) - 1;
return offset_fnd + i;
}
@@ -427,7 +429,7 @@ void retrieve_titles_from_fnd(long offset_fnd, unsigned char *sTitleSearchOut, u
// Find the title that is fully spelled out.
// The repeated characters with the previous title at the beginning of the current title will be replace by
// a character whose binary value is the number of the repeated characters.
- while ((!bFound1 || !bFound2) && offset_fnd >= SIZE_BIGRAM_BUF + sizeof(long) && nTitleSearch < SEARCH_HASH_SEQUENTIAL_SEARCH_THRESHOLD)
+ while ((!bFound1 || !bFound2) && offset_fnd >= SIZE_BIGRAM_BUF + sizeof(uint32_t) && nTitleSearch < SEARCH_HASH_SEQUENTIAL_SEARCH_THRESHOLD)
{
char *p;
@@ -470,7 +472,7 @@ void retrieve_titles_from_fnd(long offset_fnd, unsigned char *sTitleSearchOut, u
}
}
bigram_decode(sTitleSearchOut, sTitleSearch, MAX_TITLE_SEARCH);
-
+
sTitleActual[0] = '\0';
if (bFound2)
{
View
4 wiki-app/search_hash.h
@@ -28,12 +28,12 @@
#define MAX_SEARCH_STRING_ALL_HASHED_LEN 5
#define SEARCH_HASH_SEQUENTIAL_SEARCH_THRESHOLD 64
-typedef struct _search_hash_table {
+typedef struct __attribute__ ((packed)) _search_hash_table {
uint32_t offset_fnd; // offset to pedia.fnd for the search title hashed
uint32_t next_entry_idx; // byte 1: length of hash string byte 2~4: index (of struct hash_table array) of the next entry with the same hash key
} SEARCH_HASH_TABLE;
-typedef struct _search_hash_string {
+typedef struct __attribute__ ((packed)) _search_hash_string {
char str[MAX_SEARCH_STRING_HASHED_LEN + 1];
} SEARCH_HASH_STRING;
Please sign in to comment.
Something went wrong with that request. Please try again.