| 1 | /* |
| 2 | * This file is part of DisOrder |
| 3 | * Copyright (C) 2005, 2006, 2007 Richard Kettlewell |
| 4 | * |
| 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. |
| 9 | * |
| 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. |
| 14 | * |
| 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 |
| 18 | * USA |
| 19 | */ |
| 20 | |
| 21 | #include <config.h> |
| 22 | #include "types.h" |
| 23 | |
| 24 | #include <pcre.h> |
| 25 | #include <fnmatch.h> |
| 26 | #include <string.h> |
| 27 | #include <assert.h> |
| 28 | |
| 29 | #include "trackname.h" |
| 30 | #include "log.h" |
| 31 | #include "unicode.h" |
| 32 | |
| 33 | int compare_tracks(const char *sa, const char *sb, |
| 34 | const char *da, const char *db, |
| 35 | const char *ta, const char *tb) { |
| 36 | int c; |
| 37 | |
| 38 | if((c = strcmp(utf8_casefold_canon(sa, strlen(sa), 0), |
| 39 | utf8_casefold_canon(sb, strlen(sb), 0)))) |
| 40 | return c; |
| 41 | if((c = strcmp(sa, sb))) return c; |
| 42 | if((c = strcmp(utf8_casefold_canon(da, strlen(da), 0), |
| 43 | utf8_casefold_canon(db, strlen(db), 0)))) |
| 44 | return c; |
| 45 | if((c = strcmp(da, db))) return c; |
| 46 | return compare_path(ta, tb); |
| 47 | } |
| 48 | |
| 49 | int compare_path_raw(const unsigned char *ap, size_t an, |
| 50 | const unsigned char *bp, size_t bn) { |
| 51 | /* Don't change this function! The database sort order depends on it */ |
| 52 | while(an > 0 && bn > 0) { |
| 53 | if(*ap == *bp) { |
| 54 | ap++; |
| 55 | bp++; |
| 56 | an--; |
| 57 | bn--; |
| 58 | } else if(*ap == '/') { |
| 59 | return -1; /* /a/b < /aa/ */ |
| 60 | } else if(*bp == '/') { |
| 61 | return 1; /* /aa > /a/b */ |
| 62 | } else |
| 63 | return *ap - *bp; |
| 64 | } |
| 65 | if(an > 0) |
| 66 | return 1; /* /a/b > /a and /ab > /a */ |
| 67 | else if(bn > 0) |
| 68 | return -1; /* /a < /ab and /a < /a/b */ |
| 69 | else |
| 70 | return 0; |
| 71 | } |
| 72 | |
| 73 | /* |
| 74 | Local Variables: |
| 75 | c-basic-offset:2 |
| 76 | comment-column:40 |
| 77 | fill-column:79 |
| 78 | End: |
| 79 | */ |