Skip to content

Commit

Permalink
path.h: introduce path_basename()
Browse files Browse the repository at this point in the history
Signed-off-by: Gregory Petrosyan <[email protected]>
  • Loading branch information
flyingmutant committed Sep 30, 2011
1 parent bb41709 commit a0fe4cf
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
9 changes: 9 additions & 0 deletions path.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@
#include <stdlib.h>
#include <unistd.h>

const char *path_basename(const char *path)
{
const char *f;

f = strrchr(path, '/');

return f ? f + 1 : path;
}

void path_strip(char *str)
{
int i, s, d;
Expand Down
1 change: 1 addition & 0 deletions path.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#ifndef _PATH_H
#define _PATH_H

const char *path_basename(const char *path);
void path_strip(char *str);
char *path_absolute_cwd(const char *src, const char *cwd);
char *path_absolute(const char *src);
Expand Down
10 changes: 4 additions & 6 deletions track_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,11 @@ int track_info_matches_full(const struct track_info *ti, const char *text,
matched = 1;
} else {
/* compare with url or filename without path */
char *filename = ti->filename;
const char *filename = ti->filename;

if (!is_url(filename))
filename = path_basename(filename);

if (!is_url(filename)) {
char *slash = strrchr(ti->filename, '/');
if (slash)
filename = slash + 1;
}
if (u_strcasestr_filename(filename, word))
matched = 1;
}
Expand Down
10 changes: 2 additions & 8 deletions ui_curses.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include "worker.h"
#include "input.h"
#include "file.h"
#include "path.h"
#include "mixer.h"
#include "config/curses.h"
#include "config/iconv.h"
Expand Down Expand Up @@ -572,14 +573,7 @@ static void fill_track_fopts_track_info(struct track_info *info)
if (is_http_url(info->filename)) {
fopt_set_str(&track_fopts[TF_FILE], filename);
} else {
const char *f;

f = strrchr(filename, '/');
if (f) {
fopt_set_str(&track_fopts[TF_FILE], f + 1);
} else {
fopt_set_str(&track_fopts[TF_FILE], filename);
}
fopt_set_str(&track_fopts[TF_FILE], path_basename(filename));
}
}

Expand Down

0 comments on commit a0fe4cf

Please sign in to comment.