chiark / gitweb /
Synchronize from trunk
[disorder] / lib / trackorder.c
CommitLineData
e307c6fe
RK
1/*
2 * This file is part of DisOrder
3 * Copyright (C) 2005, 2006, 2007 Richard Kettlewell
4 *
e7eb3a27 5 * This program is free software: you can redistribute it and/or modify
e307c6fe 6 * it under the terms of the GNU General Public License as published by
e7eb3a27 7 * the Free Software Foundation, either version 3 of the License, or
e307c6fe 8 * (at your option) any later version.
e7eb3a27
RK
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
e307c6fe 15 * You should have received a copy of the GNU General Public License
e7eb3a27 16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
e307c6fe 17 */
132a5a4a
RK
18/** @file lib/trackorder.c
19 * @brief Track ordering
20 */
05b75f8d 21#include "common.h"
e307c6fe
RK
22
23#include <pcre.h>
24#include <fnmatch.h>
e307c6fe
RK
25
26#include "trackname.h"
27#include "log.h"
28#include "unicode.h"
29
30int compare_tracks(const char *sa, const char *sb,
31 const char *da, const char *db,
32 const char *ta, const char *tb) {
33 int c;
34
35 if((c = strcmp(utf8_casefold_canon(sa, strlen(sa), 0),
36 utf8_casefold_canon(sb, strlen(sb), 0))))
37 return c;
38 if((c = strcmp(sa, sb))) return c;
39 if((c = strcmp(utf8_casefold_canon(da, strlen(da), 0),
40 utf8_casefold_canon(db, strlen(db), 0))))
41 return c;
42 if((c = strcmp(da, db))) return c;
43 return compare_path(ta, tb);
44}
45
46int compare_path_raw(const unsigned char *ap, size_t an,
47 const unsigned char *bp, size_t bn) {
48 /* Don't change this function! The database sort order depends on it */
49 while(an > 0 && bn > 0) {
50 if(*ap == *bp) {
51 ap++;
52 bp++;
53 an--;
54 bn--;
55 } else if(*ap == '/') {
56 return -1; /* /a/b < /aa/ */
57 } else if(*bp == '/') {
58 return 1; /* /aa > /a/b */
59 } else
60 return *ap - *bp;
61 }
62 if(an > 0)
63 return 1; /* /a/b > /a and /ab > /a */
64 else if(bn > 0)
65 return -1; /* /a < /ab and /a < /a/b */
66 else
67 return 0;
68}
69
70/*
71Local Variables:
72c-basic-offset:2
73comment-column:40
74fill-column:79
75End:
76*/