summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/misc.c19
-rw-r--r--apps/misc.h5
-rw-r--r--apps/recorder/albumart.c30
-rw-r--r--apps/tree.c19
4 files changed, 25 insertions, 48 deletions
diff --git a/apps/misc.c b/apps/misc.c
index 85ab396754..a85169598f 100644
--- a/apps/misc.c
+++ b/apps/misc.c
@@ -1120,3 +1120,22 @@ bool dir_exists(const char *path)
1120 closedir(d); 1120 closedir(d);
1121 return true; 1121 return true;
1122} 1122}
1123
1124/*
1125 * removes the extension of filename (if it doesn't start with a .)
1126 * puts the result in buffer
1127 */
1128char *strip_extension(const char *filename, char *buffer)
1129{
1130 int dotpos;
1131 char *dot = strrchr(filename, '.');
1132 if (dot != 0 && filename[0] != '.')
1133 {
1134 dotpos = dot - filename;
1135 strncpy(buffer, filename, dotpos);
1136 buffer[dotpos] = '\0';
1137 }
1138 else
1139 strcpy(buffer, filename);
1140 return buffer;
1141}
diff --git a/apps/misc.h b/apps/misc.h
index 590ccf013f..99eadc443a 100644
--- a/apps/misc.h
+++ b/apps/misc.h
@@ -118,5 +118,10 @@ char* strrsplt(char* str, int c);
118bool file_exists(const char *file); 118bool file_exists(const char *file);
119bool dir_exists(const char *path); 119bool dir_exists(const char *path);
120 120
121/*
122 * removes the extension of filename (if it doesn't start with a .)
123 * puts the result in buffer
124 */
125char *strip_extension(const char *filename, char *buffer);
121 126
122#endif /* MISC_H */ 127#endif /* MISC_H */
diff --git a/apps/recorder/albumart.c b/apps/recorder/albumart.c
index 6761cfc67a..0e45d9a935 100644
--- a/apps/recorder/albumart.c
+++ b/apps/recorder/albumart.c
@@ -62,34 +62,6 @@ static char* strip_filename(char* buf, int buf_size, const char* fullpath)
62 return (sep + 1); 62 return (sep + 1);
63} 63}
64 64
65/* Strip extension from a filename.
66 *
67 * buf - buffer to output the result to.
68 * buf_size - size of the output buffer buffer.
69 * file - filename to strip extension from.
70 *
71 * Return value is a pointer to buf, which contains the result.
72 */
73static char* strip_extension(char* buf, int buf_size, const char* file)
74{
75 char* sep;
76 int len;
77
78 if (!buf || buf_size <= 0 || !file)
79 return NULL;
80
81 buf[0] = 0;
82
83 sep = strrchr(file,'.');
84 if (sep == NULL)
85 return NULL;
86
87 len = MIN(sep - file, buf_size - 1);
88 strncpy(buf, file, len);
89 buf[len] = 0;
90 return buf;
91}
92
93/* Make sure part of path only contain chars valid for a FAT32 long name. 65/* Make sure part of path only contain chars valid for a FAT32 long name.
94 * Double quotes are replaced with single quotes, other unsupported chars 66 * Double quotes are replaced with single quotes, other unsupported chars
95 * are replaced with an underscore. 67 * are replaced with an underscore.
@@ -144,7 +116,7 @@ bool search_albumart_files(const struct mp3entry *id3, const char *size_string,
144 albumlen = id3->album ? strlen(id3->album) : 0; 116 albumlen = id3->album ? strlen(id3->album) : 0;
145 117
146 /* the first file we look for is one specific to the track playing */ 118 /* the first file we look for is one specific to the track playing */
147 strip_extension(path, sizeof(path) - strlen(size_string) - 4, trackname); 119 strip_extension(trackname, path);
148 strcat(path, size_string); 120 strcat(path, size_string);
149 strcat(path, ".bmp"); 121 strcat(path, ".bmp");
150 found = file_exists(path); 122 found = file_exists(path);
diff --git a/apps/tree.c b/apps/tree.c
index 09c70f0684..6ee242ba38 100644
--- a/apps/tree.c
+++ b/apps/tree.c
@@ -115,25 +115,6 @@ static int ft_play_dirname(char* name);
115static void ft_play_filename(char *dir, char *file); 115static void ft_play_filename(char *dir, char *file);
116static void say_filetype(int attr); 116static void say_filetype(int attr);
117 117
118/*
119 * removes the extension of filename (if it doesn't start with a .)
120 * puts the result in buffer
121 */
122static char * strip_extension(char * filename, char * buffer)
123{
124 int dotpos;
125 char * dot=strrchr(filename, '.');
126 if(dot!=0 && filename[0]!='.')
127 {
128 dotpos = dot-filename;
129 strncpy(buffer, filename, dotpos);
130 buffer[dotpos]='\0';
131 return(buffer);
132 }
133 else
134 return(filename);
135}
136
137static char * tree_get_filename(int selected_item, void * data, char *buffer) 118static char * tree_get_filename(int selected_item, void * data, char *buffer)
138{ 119{
139 struct tree_context * local_tc=(struct tree_context *)data; 120 struct tree_context * local_tc=(struct tree_context *)data;