diff options
Diffstat (limited to 'apps/bookmark.c')
-rw-r--r-- | apps/bookmark.c | 56 |
1 files changed, 21 insertions, 35 deletions
diff --git a/apps/bookmark.c b/apps/bookmark.c index d7fb8f8ebb..5905fdcd7a 100644 --- a/apps/bookmark.c +++ b/apps/bookmark.c | |||
@@ -59,7 +59,8 @@ | |||
59 | #define MAX_BOOKMARK_SIZE 350 | 59 | #define MAX_BOOKMARK_SIZE 350 |
60 | #define RECENT_BOOKMARK_FILE ROCKBOX_DIR "/most-recent.bmark" | 60 | #define RECENT_BOOKMARK_FILE ROCKBOX_DIR "/most-recent.bmark" |
61 | 61 | ||
62 | static bool add_bookmark(const char* bookmark_file_name, const char* bookmark); | 62 | static bool add_bookmark(const char* bookmark_file_name, const char* bookmark, |
63 | bool most_recent); | ||
63 | static bool check_bookmark(const char* bookmark); | 64 | static bool check_bookmark(const char* bookmark); |
64 | static char* create_bookmark(void); | 65 | static char* create_bookmark(void); |
65 | static bool delete_bookmark(const char* bookmark_file_name, int bookmark_id); | 66 | static bool delete_bookmark(const char* bookmark_file_name, int bookmark_id); |
@@ -211,7 +212,7 @@ static bool write_bookmark(bool create_bookmark_file) | |||
211 | return false; /* something didn't happen correctly, do nothing */ | 212 | return false; /* something didn't happen correctly, do nothing */ |
212 | 213 | ||
213 | if (global_settings.usemrb) | 214 | if (global_settings.usemrb) |
214 | success = add_bookmark(RECENT_BOOKMARK_FILE, bookmark); | 215 | success = add_bookmark(RECENT_BOOKMARK_FILE, bookmark, true); |
215 | 216 | ||
216 | 217 | ||
217 | /* writing the bookmark */ | 218 | /* writing the bookmark */ |
@@ -221,7 +222,7 @@ static bool write_bookmark(bool create_bookmark_file) | |||
221 | sizeof(global_temp_buffer)); | 222 | sizeof(global_temp_buffer)); |
222 | if (generate_bookmark_file_name(name)) | 223 | if (generate_bookmark_file_name(name)) |
223 | { | 224 | { |
224 | success = add_bookmark(global_bookmark_file_name, bookmark); | 225 | success = add_bookmark(global_bookmark_file_name, bookmark, false); |
225 | } | 226 | } |
226 | } | 227 | } |
227 | 228 | ||
@@ -234,7 +235,8 @@ static bool write_bookmark(bool create_bookmark_file) | |||
234 | /* ----------------------------------------------------------------------- */ | 235 | /* ----------------------------------------------------------------------- */ |
235 | /* This function adds a bookmark to a file. */ | 236 | /* This function adds a bookmark to a file. */ |
236 | /* ------------------------------------------------------------------------*/ | 237 | /* ------------------------------------------------------------------------*/ |
237 | static bool add_bookmark(const char* bookmark_file_name, const char* bookmark) | 238 | static bool add_bookmark(const char* bookmark_file_name, const char* bookmark, |
239 | bool most_recent) | ||
238 | { | 240 | { |
239 | int temp_bookmark_file = 0; | 241 | int temp_bookmark_file = 0; |
240 | int bookmark_file = 0; | 242 | int bookmark_file = 0; |
@@ -253,8 +255,7 @@ static bool add_bookmark(const char* bookmark_file_name, const char* bookmark) | |||
253 | if (temp_bookmark_file < 0) | 255 | if (temp_bookmark_file < 0) |
254 | return false; /* can't open the temp file */ | 256 | return false; /* can't open the temp file */ |
255 | 257 | ||
256 | if (!strcmp(bookmark_file_name,RECENT_BOOKMARK_FILE) && | 258 | if (most_recent && (global_settings.usemrb == BOOKMARK_UNIQUE_ONLY)) |
257 | (global_settings.usemrb == BOOKMARK_UNIQUE_ONLY)) | ||
258 | { | 259 | { |
259 | playlist = strchr(bookmark,'/'); | 260 | playlist = strchr(bookmark,'/'); |
260 | cp = strrchr(bookmark,';'); | 261 | cp = strrchr(bookmark,';'); |
@@ -272,15 +273,12 @@ static bool add_bookmark(const char* bookmark_file_name, const char* bookmark) | |||
272 | if (bookmark_file >= 0) | 273 | if (bookmark_file >= 0) |
273 | { | 274 | { |
274 | while (read_line(bookmark_file, global_read_buffer, | 275 | while (read_line(bookmark_file, global_read_buffer, |
275 | sizeof(global_read_buffer))) | 276 | sizeof(global_read_buffer)) > 0) |
276 | { | 277 | { |
277 | /* The MRB has a max of MAX_BOOKMARKS in it */ | 278 | /* The MRB has a max of MAX_BOOKMARKS in it */ |
278 | /* This keeps it from getting too large */ | 279 | /* This keeps it from getting too large */ |
279 | if ((strcmp(bookmark_file_name,RECENT_BOOKMARK_FILE)==0)) | 280 | if (most_recent && (bookmark_count >= MAX_BOOKMARKS)) |
280 | { | ||
281 | if(bookmark_count >= MAX_BOOKMARKS) | ||
282 | break; | 281 | break; |
283 | } | ||
284 | 282 | ||
285 | cp = strchr(global_read_buffer,'/'); | 283 | cp = strchr(global_read_buffer,'/'); |
286 | tmp = strrchr(global_read_buffer,';'); | 284 | tmp = strrchr(global_read_buffer,';'); |
@@ -442,7 +440,7 @@ bool bookmark_load(const char* file, bool autoload) | |||
442 | fd = open(file, O_RDONLY); | 440 | fd = open(file, O_RDONLY); |
443 | if(fd >= 0) | 441 | if(fd >= 0) |
444 | { | 442 | { |
445 | if(read_line(fd, global_read_buffer, sizeof(global_read_buffer))) | 443 | if(read_line(fd, global_read_buffer, sizeof(global_read_buffer)) > 0) |
446 | bookmark=global_read_buffer; | 444 | bookmark=global_read_buffer; |
447 | close(fd); | 445 | close(fd); |
448 | } | 446 | } |
@@ -471,10 +469,9 @@ static int get_bookmark_count(const char* bookmark_file_name) | |||
471 | return -1; | 469 | return -1; |
472 | 470 | ||
473 | /* Get the requested bookmark */ | 471 | /* Get the requested bookmark */ |
474 | while(read_line(file, global_read_buffer, sizeof(global_read_buffer))) | 472 | while(read_line(file, global_read_buffer, sizeof(global_read_buffer)) > 0) |
475 | { | 473 | { |
476 | if(check_bookmark(global_read_buffer)) | 474 | read_count++; |
477 | read_count++; | ||
478 | } | 475 | } |
479 | 476 | ||
480 | close(file); | 477 | close(file); |
@@ -532,6 +529,7 @@ static char* select_bookmark(const char* bookmark_file_name) | |||
532 | { | 529 | { |
533 | bookmark_id_prev = bookmark_id; | 530 | bookmark_id_prev = bookmark_id; |
534 | bookmark_id--; | 531 | bookmark_id--; |
532 | continue; | ||
535 | } | 533 | } |
536 | } | 534 | } |
537 | else | 535 | else |
@@ -602,24 +600,16 @@ static bool delete_bookmark(const char* bookmark_file_name, int bookmark_id) | |||
602 | "%s.tmp", bookmark_file_name); | 600 | "%s.tmp", bookmark_file_name); |
603 | temp_bookmark_file = open(global_temp_buffer, | 601 | temp_bookmark_file = open(global_temp_buffer, |
604 | O_WRONLY | O_CREAT | O_TRUNC); | 602 | O_WRONLY | O_CREAT | O_TRUNC); |
605 | bookmark_file = open(bookmark_file_name, O_RDONLY); | ||
606 | 603 | ||
607 | if (temp_bookmark_file < 0 || bookmark_file < 0) | 604 | if (temp_bookmark_file < 0) |
608 | return false; /* can't open one of the files */ | 605 | return false; /* can't open the temp file */ |
609 | 606 | ||
610 | /* Reading in the previous bookmarks and writing them to the temp file */ | 607 | /* Reading in the previous bookmarks and writing them to the temp file */ |
611 | while (read_line(bookmark_file, global_read_buffer, | 608 | bookmark_file = open(bookmark_file_name, O_RDONLY); |
612 | sizeof(global_read_buffer))) | 609 | if (bookmark_file >= 0) |
613 | { | 610 | { |
614 | /* The MRB has a max of MAX_BOOKMARKS in it */ | 611 | while (read_line(bookmark_file, global_read_buffer, |
615 | /* This keeps it from getting too large */ | 612 | sizeof(global_read_buffer)) > 0) |
616 | if ((strcmp(bookmark_file_name,RECENT_BOOKMARK_FILE)==0)) | ||
617 | { | ||
618 | if(bookmark_count >= MAX_BOOKMARKS) | ||
619 | break; | ||
620 | } | ||
621 | |||
622 | if (check_bookmark(global_read_buffer)) | ||
623 | { | 613 | { |
624 | if (bookmark_id != bookmark_count) | 614 | if (bookmark_id != bookmark_count) |
625 | { | 615 | { |
@@ -629,9 +619,8 @@ static bool delete_bookmark(const char* bookmark_file_name, int bookmark_id) | |||
629 | } | 619 | } |
630 | bookmark_count++; | 620 | bookmark_count++; |
631 | } | 621 | } |
622 | close(bookmark_file); | ||
632 | } | 623 | } |
633 | |||
634 | close(bookmark_file); | ||
635 | close(temp_bookmark_file); | 624 | close(temp_bookmark_file); |
636 | 625 | ||
637 | remove(bookmark_file_name); | 626 | remove(bookmark_file_name); |
@@ -834,9 +823,6 @@ static char* get_bookmark(const char* bookmark_file, int bookmark_count) | |||
834 | if (file < 0) | 823 | if (file < 0) |
835 | return NULL; | 824 | return NULL; |
836 | 825 | ||
837 | if (bookmark_count < 0) | ||
838 | return NULL; | ||
839 | |||
840 | /* Get the requested bookmark */ | 826 | /* Get the requested bookmark */ |
841 | while (read_count < bookmark_count) | 827 | while (read_count < bookmark_count) |
842 | { | 828 | { |
@@ -854,7 +840,7 @@ static char* get_bookmark(const char* bookmark_file, int bookmark_count) | |||
854 | } | 840 | } |
855 | 841 | ||
856 | close(file); | 842 | close(file); |
857 | if (read_count == bookmark_count) | 843 | if ((read_count >= 0) && (read_count == bookmark_count)) |
858 | return global_read_buffer; | 844 | return global_read_buffer; |
859 | else | 845 | else |
860 | return NULL; | 846 | return NULL; |