-rw-r--r-- | noncore/apps/opie-reader/Navigation.cpp | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/noncore/apps/opie-reader/Navigation.cpp b/noncore/apps/opie-reader/Navigation.cpp index 7b392ba..4f11887 100644 --- a/noncore/apps/opie-reader/Navigation.cpp +++ b/noncore/apps/opie-reader/Navigation.cpp | |||
@@ -1,98 +1,100 @@ | |||
1 | #include "Navigation.h" | 1 | #include "Navigation.h" |
2 | 2 | ||
3 | #include <string.h> | ||
4 | |||
3 | void CNavigation::saveposn(size_t posn) | 5 | void CNavigation::saveposn(size_t posn) |
4 | { | 6 | { |
5 | // qDebug("Saved:%u [%u,%u,%u]", posn, historystart, historycurrent, historyend); | 7 | // qDebug("Saved:%u [%u,%u,%u]", posn, historystart, historycurrent, historyend); |
6 | historycurrent = historyend = (historycurrent+1)%NAVIGATION_HISTORY_SIZE; | 8 | historycurrent = historyend = (historycurrent+1)%NAVIGATION_HISTORY_SIZE; |
7 | history[historycurrent] = posn; | 9 | history[historycurrent] = posn; |
8 | if (historystart == historyend) historystart = (historystart+1)%NAVIGATION_HISTORY_SIZE; | 10 | if (historystart == historyend) historystart = (historystart+1)%NAVIGATION_HISTORY_SIZE; |
9 | // qDebug("Saved:%u [%u,%u,%u]", posn, historystart, historycurrent, historyend); | 11 | // qDebug("Saved:%u [%u,%u,%u]", posn, historystart, historycurrent, historyend); |
10 | } | 12 | } |
11 | 13 | ||
12 | bool CNavigation::forward(size_t& loc) | 14 | bool CNavigation::forward(size_t& loc) |
13 | { | 15 | { |
14 | if (historycurrent != historyend) | 16 | if (historycurrent != historyend) |
15 | { | 17 | { |
16 | historycurrent = (historycurrent + 1)%NAVIGATION_HISTORY_SIZE; | 18 | historycurrent = (historycurrent + 1)%NAVIGATION_HISTORY_SIZE; |
17 | loc = history[historycurrent]; | 19 | loc = history[historycurrent]; |
18 | //qDebug("Forward:%u [%u,%u,%u]", loc, historystart, historycurrent, historyend); | 20 | //qDebug("Forward:%u [%u,%u,%u]", loc, historystart, historycurrent, historyend); |
19 | return true; | 21 | return true; |
20 | } | 22 | } |
21 | else | 23 | else |
22 | { | 24 | { |
23 | return false; | 25 | return false; |
24 | } | 26 | } |
25 | } | 27 | } |
26 | 28 | ||
27 | bool CNavigation::back(size_t& loc) | 29 | bool CNavigation::back(size_t& loc) |
28 | { | 30 | { |
29 | if (historyend != historystart) | 31 | if (historyend != historystart) |
30 | { | 32 | { |
31 | //qDebug("Back:%u [%u,%u,%u]", loc, historystart, historycurrent, historyend); | 33 | //qDebug("Back:%u [%u,%u,%u]", loc, historystart, historycurrent, historyend); |
32 | if (historycurrent == historyend && history[historycurrent] != loc) | 34 | if (historycurrent == historyend && history[historycurrent] != loc) |
33 | { | 35 | { |
34 | historyend = (historyend+1) % NAVIGATION_HISTORY_SIZE; | 36 | historyend = (historyend+1) % NAVIGATION_HISTORY_SIZE; |
35 | history[historyend] = loc; | 37 | history[historyend] = loc; |
36 | } | 38 | } |
37 | else | 39 | else |
38 | { | 40 | { |
39 | size_t sv = historycurrent; | 41 | size_t sv = historycurrent; |
40 | historycurrent = (historycurrent + NAVIGATION_HISTORY_SIZE - 1) % NAVIGATION_HISTORY_SIZE; | 42 | historycurrent = (historycurrent + NAVIGATION_HISTORY_SIZE - 1) % NAVIGATION_HISTORY_SIZE; |
41 | if (historycurrent == historystart) | 43 | if (historycurrent == historystart) |
42 | { | 44 | { |
43 | historycurrent = sv; | 45 | historycurrent = sv; |
44 | return false; | 46 | return false; |
45 | } | 47 | } |
46 | } | 48 | } |
47 | loc = history[historycurrent]; | 49 | loc = history[historycurrent]; |
48 | //qDebug("Back:%u [%u,%u,%u]", loc, historystart, historycurrent, historyend); | 50 | //qDebug("Back:%u [%u,%u,%u]", loc, historystart, historycurrent, historyend); |
49 | return true; | 51 | return true; |
50 | } | 52 | } |
51 | else | 53 | else |
52 | { | 54 | { |
53 | return false; | 55 | return false; |
54 | } | 56 | } |
55 | } | 57 | } |
56 | 58 | ||
57 | #include <stdio.h> | 59 | #include <stdio.h> |
58 | 60 | ||
59 | void CNavigation::setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen) | 61 | void CNavigation::setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen) |
60 | { | 62 | { |
61 | len = srclen+sizeof(size_t)*(3+NAVIGATION_HISTORY_SIZE); | 63 | len = srclen+sizeof(size_t)*(3+NAVIGATION_HISTORY_SIZE); |
62 | data = new unsigned char[len]; | 64 | data = new unsigned char[len]; |
63 | unsigned char* p = data; | 65 | unsigned char* p = data; |
64 | memcpy(p, src, srclen); | 66 | memcpy(p, src, srclen); |
65 | p += srclen; | 67 | p += srclen; |
66 | memcpy(p, &historystart, sizeof(size_t)); | 68 | memcpy(p, &historystart, sizeof(size_t)); |
67 | p += sizeof(size_t); | 69 | p += sizeof(size_t); |
68 | memcpy(p, &historyend, sizeof(size_t)); | 70 | memcpy(p, &historyend, sizeof(size_t)); |
69 | p += sizeof(size_t); | 71 | p += sizeof(size_t); |
70 | memcpy(p, &historycurrent, sizeof(size_t)); | 72 | memcpy(p, &historycurrent, sizeof(size_t)); |
71 | p += sizeof(size_t); | 73 | p += sizeof(size_t); |
72 | memcpy(p, history, sizeof(size_t)*NAVIGATION_HISTORY_SIZE); | 74 | memcpy(p, history, sizeof(size_t)*NAVIGATION_HISTORY_SIZE); |
73 | printf("<%u,%u,%u>\n", historystart, historyend, historycurrent); | 75 | printf("<%u,%u,%u>\n", historystart, historyend, historycurrent); |
74 | for (int i = historystart; i <= historyend; i++) | 76 | for (int i = historystart; i <= historyend; i++) |
75 | printf("<%u> ", history[i]); | 77 | printf("<%u> ", history[i]); |
76 | printf("\n"); | 78 | printf("\n"); |
77 | } | 79 | } |
78 | 80 | ||
79 | void CNavigation::putSaveData(unsigned char*& src, unsigned short& srclen) | 81 | void CNavigation::putSaveData(unsigned char*& src, unsigned short& srclen) |
80 | { | 82 | { |
81 | if (srclen >= sizeof(size_t)*(3+NAVIGATION_HISTORY_SIZE)) | 83 | if (srclen >= sizeof(size_t)*(3+NAVIGATION_HISTORY_SIZE)) |
82 | { | 84 | { |
83 | unsigned char* p = src; | 85 | unsigned char* p = src; |
84 | memcpy(&historystart, p, sizeof(size_t)); | 86 | memcpy(&historystart, p, sizeof(size_t)); |
85 | p += sizeof(size_t); | 87 | p += sizeof(size_t); |
86 | memcpy(&historyend, p, sizeof(size_t)); | 88 | memcpy(&historyend, p, sizeof(size_t)); |
87 | p += sizeof(size_t); | 89 | p += sizeof(size_t); |
88 | memcpy(&historycurrent, p, sizeof(size_t)); | 90 | memcpy(&historycurrent, p, sizeof(size_t)); |
89 | p += sizeof(size_t); | 91 | p += sizeof(size_t); |
90 | memcpy(history, p, sizeof(size_t)*NAVIGATION_HISTORY_SIZE); | 92 | memcpy(history, p, sizeof(size_t)*NAVIGATION_HISTORY_SIZE); |
91 | src = p + sizeof(size_t)*NAVIGATION_HISTORY_SIZE; | 93 | src = p + sizeof(size_t)*NAVIGATION_HISTORY_SIZE; |
92 | srclen -= sizeof(size_t)*(3+NAVIGATION_HISTORY_SIZE); | 94 | srclen -= sizeof(size_t)*(3+NAVIGATION_HISTORY_SIZE); |
93 | } | 95 | } |
94 | printf("<%u,%u,%u>\n", historystart, historyend, historycurrent); | 96 | printf("<%u,%u,%u>\n", historystart, historyend, historycurrent); |
95 | for (int i = historystart; i <= historyend; i++) | 97 | for (int i = historystart; i <= historyend; i++) |
96 | printf("<%u> ", history[i]); | 98 | printf("<%u> ", history[i]); |
97 | printf("\n"); | 99 | printf("\n"); |
98 | } | 100 | } |