2 * This file is part of DisOrder
3 * Copyright (C) 2005, 2006, 2007 Richard Kettlewell
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
26 #include "trackname.h"
27 #include "configuration.h"
33 const struct collection *find_track_collection(const char *track) {
35 size_t l, tl = strlen(track);
37 for(n = 0; n < config->collection.n; ++n) {
38 l = strlen(config->collection.s[n].root);
40 && !strncmp(track, config->collection.s[n].root, l)
44 if(n < config->collection.n)
45 return &config->collection.s[n];
50 const char *find_track_root(const char *track) {
51 const struct collection *c = find_track_collection(track);
54 error(0, "found track in no collection '%s'", track);
58 const char *track_rootless(const char *track) {
61 if(!(root = find_track_root(track))) return 0;
62 return track + strlen(root);
65 const char *trackname_part(const char *track,
69 const char *replaced, *rootless;
72 if(!strcmp(part, "path")) return track;
73 if(!strcmp(part, "ext")) return extension(track);
74 if((rootless = track_rootless(track))) track = rootless;
75 for(n = 0; n < config->namepart.n; ++n) {
76 if(!strcmp(config->namepart.s[n].part, part)
77 && fnmatch(config->namepart.s[n].context, context, 0) == 0) {
78 if((replaced = regsub(config->namepart.s[n].re,
80 config->namepart.s[n].replace,
81 config->namepart.s[n].reflags
90 const char *trackname_transform(const char *type,
92 const char *context) {
95 const struct transform *k;
97 for(n = 0; n < config->transform.n; ++n) {
98 k = &config->transform.t[n];
99 if(strcmp(k->type, type))
101 if(fnmatch(k->context, context, 0) != 0)
103 if((replaced = regsub(k->re, subject, k->replace, k->flags)))