summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/bookmark.c81
1 files changed, 22 insertions, 59 deletions
diff --git a/apps/bookmark.c b/apps/bookmark.c
index d0cecf0b7a..687290b901 100644
--- a/apps/bookmark.c
+++ b/apps/bookmark.c
@@ -63,26 +63,17 @@ struct bookmark_list
63 63
64/* bookmark flags */ 64/* bookmark flags */
65#define F_BMFILES 0x001 65#define F_BMFILES 0x001
66#define F_RES_IND 0x002 66
67#define F_RES_OFF 0x004 67/* bookmark values */
68#define F_RES_SED 0x008 68static struct {
69#define F_RES_1ST 0x010 69 int resume_index;
70#define F_RES_TIM 0x020 70 unsigned long resume_offset;
71#define F_REP_MOD 0x040 71 int resume_seed;
72#define F_SHUFFLE 0x080
73
74static struct bookmark_values
75{
76 int resume_index;
77 int resume_offset;
78 int resume_seed;
79 int resume_first_index; /* ?? */
80 long resume_time; 72 long resume_time;
81 int repeat_mode; 73 int repeat_mode;
82 bool shuffle; 74 bool shuffle;
83} bm; 75} bm;
84 76
85#define CHECK_BOOKMARK(bookmark) parse_bookmark(bookmark, 0)
86static bool add_bookmark(const char* bookmark_file_name, const char* bookmark, 77static bool add_bookmark(const char* bookmark_file_name, const char* bookmark,
87 bool most_recent); 78 bool most_recent);
88static char* create_bookmark(void); 79static char* create_bookmark(void);
@@ -294,7 +285,7 @@ static bool add_bookmark(const char* bookmark_file_name, const char* bookmark,
294 285
295 cp = strchr(global_read_buffer,'/'); 286 cp = strchr(global_read_buffer,'/');
296 tmp = strrchr(global_read_buffer,';'); 287 tmp = strrchr(global_read_buffer,';');
297 if (CHECK_BOOKMARK(global_read_buffer) && 288 if (parse_bookmark(global_read_buffer, 0) &&
298 (!unique || len != tmp -cp || strncmp(playlist,cp,len))) 289 (!unique || len != tmp -cp || strncmp(playlist,cp,len)))
299 { 290 {
300 bookmark_count++; 291 bookmark_count++;
@@ -356,7 +347,7 @@ static char* create_bookmark()
356 file+1); 347 file+1);
357 348
358 /* checking to see if the bookmark is valid */ 349 /* checking to see if the bookmark is valid */
359 if (CHECK_BOOKMARK(global_bookmark)) 350 if (parse_bookmark(global_bookmark, 0))
360 return global_bookmark; 351 return global_bookmark;
361 else 352 else
362 return NULL; 353 return NULL;
@@ -572,7 +563,7 @@ static const char* get_bookmark_info(int list_index,
572 } 563 }
573 } 564 }
574 565
575 const int flags = F_BMFILES | F_RES_IND | F_RES_TIM | F_SHUFFLE; 566 const int flags = F_BMFILES;
576 567
577 if (!parse_bookmark(bookmarks->items[index - bookmarks->start], flags)) 568 if (!parse_bookmark(bookmarks->items[index - bookmarks->start], flags))
578 { 569 {
@@ -841,7 +832,7 @@ static void say_bookmark(const char* bookmark,
841{ 832{
842 bool is_dir; 833 bool is_dir;
843 834
844 const int flags = F_BMFILES | F_RES_IND | F_RES_TIM | F_SHUFFLE; 835 const int flags = F_BMFILES;
845 836
846 if (!parse_bookmark(bookmark, flags)) 837 if (!parse_bookmark(bookmark, flags))
847 { 838 {
@@ -897,8 +888,7 @@ static void say_bookmark(const char* bookmark,
897/* ------------------------------------------------------------------------*/ 888/* ------------------------------------------------------------------------*/
898static bool play_bookmark(const char* bookmark) 889static bool play_bookmark(const char* bookmark)
899{ 890{
900 const int flags = F_BMFILES | F_RES_IND | F_RES_OFF | F_RES_SED | 891 const int flags = F_BMFILES;
901 F_REP_MOD | F_SHUFFLE;
902 892
903 if (parse_bookmark(bookmark, flags)) 893 if (parse_bookmark(bookmark, flags))
904 { 894 {
@@ -926,36 +916,6 @@ static const char* skip_token(const char* s)
926 return s; 916 return s;
927} 917}
928 918
929static const char* int_token(const char* s, bool parse, int* dest)
930{
931 if (parse)
932 {
933 *dest = atoi(s);
934 }
935
936 return skip_token(s);
937}
938
939static const char* long_token(const char* s, bool parse, long* dest)
940{
941 if (parse)
942 {
943 *dest = atoi(s); /* Should be atol, but we don't have it. */
944 }
945
946 return skip_token(s);
947}
948
949static const char* bool_token(const char* s, bool parse, bool* dest)
950{
951 if (parse)
952 {
953 *dest = atoi(s) != 0;
954 }
955
956 return skip_token(s);
957}
958
959/* ----------------------------------------------------------------------- */ 919/* ----------------------------------------------------------------------- */
960/* This function takes a bookmark and parses it. This function also */ 920/* This function takes a bookmark and parses it. This function also */
961/* validates the bookmark. Flags are set to indicate which bookmark */ 921/* validates the bookmark. Flags are set to indicate which bookmark */
@@ -967,15 +927,18 @@ static bool parse_bookmark(const char *bookmark, const int flags)
967 const char* end; 927 const char* end;
968 928
969#define FLAG(a) (flags & a) 929#define FLAG(a) (flags & a)
930#define GET_INT_TOKEN(var) var = atoi(s); s = skip_token(s)
931#define GET_BOOL_TOKEN(var) var = (atoi(s)!=0); s = skip_token(s)
932
933 GET_INT_TOKEN(bm.resume_index);
934 GET_INT_TOKEN(bm.resume_offset);
935 GET_INT_TOKEN(bm.resume_seed);
936 /* skip deprecated token */
937 s = skip_token(s);
938 GET_INT_TOKEN(bm.resume_time);
939 GET_INT_TOKEN(bm.repeat_mode);
940 GET_BOOL_TOKEN(bm.shuffle);
970 941
971 s = int_token(s, FLAG(F_RES_IND), &bm.resume_index);
972 s = int_token(s, FLAG(F_RES_OFF), &bm.resume_offset);
973 s = int_token(s, FLAG(F_RES_SED), &bm.resume_seed);
974 s = int_token(s, FLAG(F_RES_1ST), &bm.resume_first_index);
975 s = long_token(s, FLAG(F_RES_TIM), &bm.resume_time);
976 s = int_token(s, FLAG(F_REP_MOD), &bm.repeat_mode);
977 s = bool_token(s, FLAG(F_SHUFFLE), &bm.shuffle);
978
979 if (*s == 0) 942 if (*s == 0)
980 { 943 {
981 return false; 944 return false;