cleanup after MetaTags patch:
authorOzkan Sezer <sezeroz@gmail.com>
Mon, 23 Dec 2019 14:01:02 +0300
changeset 112057a746548d9e
parent 1119 24ca9a03d51c
child 1121 71510d620652
cleanup after MetaTags patch:

- music_flac.c (flac_metadata_music_cb): remove unnecessary style change
- music.c: fix typo utiltiy -> utility
- music.c (meta_tags_set): remove unnecessary memset(0)
- music.c (struct _Mix_Music): rename music_filename to filename
- music.c: add get_last_dirsep() inline to OS-specifically get the
last directory separator.
- music.c (Mix_LoadMUS): use get_last_dirsep() for music->filename
src/codecs/music_flac.c
src/music.c
     1.1 --- a/src/codecs/music_flac.c	Mon Dec 23 14:01:02 2019 +0300
     1.2 +++ b/src/codecs/music_flac.c	Mon Dec 23 14:01:02 2019 +0300
     1.3 @@ -462,8 +462,7 @@
     1.4              /* Want to match LOOP-START, LOOP_START, etc. Remove - or _ from
     1.5               * string if it is present at position 4. */
     1.6              if (is_loop_tag(argument) && ((argument[4] == '_') || (argument[4] == '-'))) {
     1.7 -                SDL_memmove(argument + 4, argument + 5,
     1.8 -                           SDL_strlen(argument) - 4);
     1.9 +                SDL_memmove(argument + 4, argument + 5, SDL_strlen(argument) - 4);
    1.10              }
    1.11  
    1.12              if (SDL_strcasecmp(argument, "LOOPSTART") == 0)
     2.1 --- a/src/music.c	Mon Dec 23 14:01:02 2019 +0300
     2.2 +++ b/src/music.c	Mon Dec 23 14:01:02 2019 +0300
     2.3 @@ -66,7 +66,7 @@
     2.4      int fade_step;
     2.5      int fade_steps;
     2.6  
     2.7 -    char music_filename[1024];
     2.8 +    char filename[1024];
     2.9  };
    2.10  
    2.11  /* Used to calculate fading steps */
    2.12 @@ -82,7 +82,7 @@
    2.13  /* full path of timidity config file */
    2.14  static char* timidity_cfg = NULL;
    2.15  
    2.16 -/* Meta-Tags utiltiy */
    2.17 +/* Meta-Tags utility */
    2.18  void meta_tags_init(Mix_MusicMetaTags *tags)
    2.19  {
    2.20      SDL_memset(tags, 0, sizeof(Mix_MusicMetaTags));
    2.21 @@ -113,7 +113,6 @@
    2.22  
    2.23      len = SDL_strlen(value);
    2.24      out = (char *)SDL_malloc(sizeof(char) * len + 1);
    2.25 -    SDL_memset(out, 0, len + 1);
    2.26      SDL_strlcpy(out, value, len +1);
    2.27  
    2.28      if (tags->tags[type]) {
    2.29 @@ -138,6 +137,21 @@
    2.30      return "";
    2.31  }
    2.32  
    2.33 +/* for music->filename */
    2.34 +#if defined(__WIN32__)||defined(__OS2__)
    2.35 +static SDL_INLINE const char *get_last_dirsep (const char *p) {
    2.36 +    const char *p1 = SDL_strrchr(p, '/');
    2.37 +    const char *p2 = SDL_strrchr(p, '\\');
    2.38 +    if (!p1) return p2;
    2.39 +    if (!p2) return p1;
    2.40 +    return (p1 > p2)? p1 : p2;
    2.41 +}
    2.42 +#else /* unix */
    2.43 +static SDL_INLINE const char *get_last_dirsep (const char *p) {
    2.44 +    return SDL_strrchr(p, '/');
    2.45 +}
    2.46 +#endif
    2.47 +
    2.48  
    2.49  /* Interfaces for the various music interfaces, ordered by priority */
    2.50  static Mix_MusicInterface *s_music_interfaces[] =
    2.51 @@ -543,6 +557,7 @@
    2.52  
    2.53          context = interface->CreateFromFile(file);
    2.54          if (context) {
    2.55 +            const char *p;
    2.56              /* Allocate memory for the music structure */
    2.57              Mix_Music *music = (Mix_Music *)SDL_calloc(1, sizeof(Mix_Music));
    2.58              if (music == NULL) {
    2.59 @@ -551,7 +566,8 @@
    2.60              }
    2.61              music->interface = interface;
    2.62              music->context = context;
    2.63 -            SDL_strlcpy(music->music_filename, (SDL_strstr(file, "/")) ? (SDL_strrchr(file, '/') + 1) : file, 1024);
    2.64 +            p = get_last_dirsep(file);
    2.65 +            SDL_strlcpy(music->filename, (p != NULL)? p + 1 : file, 1024);
    2.66              return music;
    2.67          }
    2.68      }
    2.69 @@ -755,10 +771,10 @@
    2.70          return tag;
    2.71      }
    2.72      if (music) {
    2.73 -        return music->music_filename;
    2.74 +        return music->filename;
    2.75      }
    2.76      if (music_playing) {
    2.77 -        return music_playing->music_filename;
    2.78 +        return music_playing->filename;
    2.79      }
    2.80      return "";
    2.81  }