Diffstat (limited to 'noncore/apps/opie-reader/Navigation.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/Navigation.cpp | 79 |
1 files changed, 0 insertions, 79 deletions
diff --git a/noncore/apps/opie-reader/Navigation.cpp b/noncore/apps/opie-reader/Navigation.cpp index 36e33b4..a886d88 100644 --- a/noncore/apps/opie-reader/Navigation.cpp +++ b/noncore/apps/opie-reader/Navigation.cpp | |||
@@ -1,122 +1,43 @@ | |||
1 | #ifdef _WINDOWS | 1 | #ifdef _WINDOWS |
2 | #include <string.h> | 2 | #include <string.h> |
3 | #endif | 3 | #endif |
4 | #include "Navigation.h" | 4 | #include "Navigation.h" |
5 | //#include <stdio.h> | ||
6 | |||
7 | /* | ||
8 | void saveposn(size_t posn) | ||
9 | save/push position to history buffer for future use of back() function | ||
10 | */ | ||
11 | void CNavigation::saveposn(size_t posn) | ||
12 | { | ||
13 | //printf("saving position %u, depth %u\n",posn,historycurrent); | ||
14 | history[historycurrent] = posn; | ||
15 | historycurrent=(historycurrent+1)%NAVIGATION_HISTORY_SIZE; | ||
16 | if (historycurrent==historystart) | ||
17 | // circular buffer full, forget oldest record | ||
18 | historystart=(historystart+1)%NAVIGATION_HISTORY_SIZE; | ||
19 | // no forward possible after saveposn | ||
20 | historyend = historycurrent; | ||
21 | } | ||
22 | |||
23 | /* | ||
24 | void writeposn(size_t posn) | ||
25 | overwrite current (unused) position | ||
26 | useful for saving current position before using back button | ||
27 | */ | ||
28 | void CNavigation::writeposn(size_t posn) | ||
29 | { | ||
30 | //printf("witing position %u, depth %u\n",posn,historycurrent); | ||
31 | history[historycurrent] = posn; | ||
32 | } | ||
33 | |||
34 | /* | ||
35 | bool back(size_t& posn) | ||
36 | go back in history | ||
37 | restore last position saved with saveposn() and return true | ||
38 | return false if there is nothing saved in history | ||
39 | */ | ||
40 | bool CNavigation::back(size_t& posn) | ||
41 | { | ||
42 | if (historycurrent!=historystart) { | ||
43 | // buffer is not empty | ||
44 | if (historycurrent==0) | ||
45 | historycurrent=NAVIGATION_HISTORY_SIZE-1; | ||
46 | else | ||
47 | historycurrent--; | ||
48 | posn=history[historycurrent]; | ||
49 | //printf("back(): going back to %u depth %u\n",posn,historycurrent); | ||
50 | return true; | ||
51 | |||
52 | } else { | ||
53 | // circular buffer empty | ||
54 | //printf("back(): empty history\n"); | ||
55 | return false; | ||
56 | } | ||
57 | } | ||
58 | |||
59 | /* | ||
60 | bool forward(size_t& posn) | ||
61 | go forward in history, if possible | ||
62 | undo calling of back() | ||
63 | */ | ||
64 | bool CNavigation::forward(size_t& posn) | ||
65 | { | ||
66 | if (historycurrent!=historyend) { | ||
67 | // [historycurrent] = current position | ||
68 | // [historycurrent+1] = position we need | ||
69 | historycurrent=(historycurrent+1)%NAVIGATION_HISTORY_SIZE; | ||
70 | posn = history[historycurrent]; | ||
71 | //printf("forward(): going to position %d\n",posn); | ||
72 | return true; | ||
73 | } else { | ||
74 | //printf("forward(): there is no future :)\n"); | ||
75 | return false; | ||
76 | } | ||
77 | } | ||
78 | 5 | ||
79 | void CNavigation::setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen) | 6 | void CNavigation::setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen) |
80 | { | 7 | { |
81 | len = srclen+sizeof(size_t)*(3+NAVIGATION_HISTORY_SIZE); | 8 | len = srclen+sizeof(size_t)*(3+NAVIGATION_HISTORY_SIZE); |
82 | data = new unsigned char[len]; | 9 | data = new unsigned char[len]; |
83 | unsigned char* p = data; | 10 | unsigned char* p = data; |
84 | memcpy(p, src, srclen); | 11 | memcpy(p, src, srclen); |
85 | p += srclen; | 12 | p += srclen; |
86 | memcpy(p, &historystart, sizeof(size_t)); | 13 | memcpy(p, &historystart, sizeof(size_t)); |
87 | p += sizeof(size_t); | 14 | p += sizeof(size_t); |
88 | memcpy(p, &historyend, sizeof(size_t)); | 15 | memcpy(p, &historyend, sizeof(size_t)); |
89 | p += sizeof(size_t); | 16 | p += sizeof(size_t); |
90 | memcpy(p, &historycurrent, sizeof(size_t)); | 17 | memcpy(p, &historycurrent, sizeof(size_t)); |
91 | p += sizeof(size_t); | 18 | p += sizeof(size_t); |
92 | memcpy(p, history, sizeof(size_t)*NAVIGATION_HISTORY_SIZE); | 19 | memcpy(p, history, sizeof(size_t)*NAVIGATION_HISTORY_SIZE); |
93 | /* | ||
94 | printf("<%u,%u,%u>\n", historystart, historyend, historycurrent); | ||
95 | for (int i = historystart; i <= historyend; i++) | ||
96 | printf("<%u> ", history[i]); | ||
97 | printf("\n"); | ||
98 | */ | ||
99 | } | 20 | } |
100 | 21 | ||
101 | void CNavigation::putSaveData(unsigned char*& src, unsigned short& srclen) | 22 | void CNavigation::putSaveData(unsigned char*& src, unsigned short& srclen) |
102 | { | 23 | { |
103 | if (srclen >= sizeof(size_t)*(3+NAVIGATION_HISTORY_SIZE)) | 24 | if (srclen >= sizeof(size_t)*(3+NAVIGATION_HISTORY_SIZE)) |
104 | { | 25 | { |
105 | unsigned char* p = src; | 26 | unsigned char* p = src; |
106 | memcpy(&historystart, p, sizeof(size_t)); | 27 | memcpy(&historystart, p, sizeof(size_t)); |
107 | p += sizeof(size_t); | 28 | p += sizeof(size_t); |
108 | memcpy(&historyend, p, sizeof(size_t)); | 29 | memcpy(&historyend, p, sizeof(size_t)); |
109 | p += sizeof(size_t); | 30 | p += sizeof(size_t); |
110 | memcpy(&historycurrent, p, sizeof(size_t)); | 31 | memcpy(&historycurrent, p, sizeof(size_t)); |
111 | p += sizeof(size_t); | 32 | p += sizeof(size_t); |
112 | memcpy(history, p, sizeof(size_t)*NAVIGATION_HISTORY_SIZE); | 33 | memcpy(history, p, sizeof(size_t)*NAVIGATION_HISTORY_SIZE); |
113 | src = p + sizeof(size_t)*NAVIGATION_HISTORY_SIZE; | 34 | src = p + sizeof(size_t)*NAVIGATION_HISTORY_SIZE; |
114 | srclen -= sizeof(size_t)*(3+NAVIGATION_HISTORY_SIZE); | 35 | srclen -= sizeof(size_t)*(3+NAVIGATION_HISTORY_SIZE); |
115 | } | 36 | } |
116 | /* | 37 | /* |
117 | printf("<%u,%u,%u>\n", historystart, historyend, historycurrent); | 38 | printf("<%u,%u,%u>\n", historystart, historyend, historycurrent); |
118 | for (int i = historystart; i <= historyend; i++) | 39 | for (int i = historystart; i <= historyend; i++) |
119 | printf("<%u> ", history[i]); | 40 | printf("<%u> ", history[i]); |
120 | printf("\n"); | 41 | printf("\n"); |
121 | */ | 42 | */ |
122 | } | 43 | } |