~ubuntu-branches/ubuntu/maverick/kdeutils/maverick-proposed

« back to all changes in this revision

Viewing changes to ark/plugins/bk/bkSort.c

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-05-28 09:49:30 UTC
  • mfrom: (1.2.44 upstream)
  • Revision ID: james.westby@ubuntu.com-20100528094930-jzynf0obv1n2v13a
Tags: 4:4.4.80-0ubuntu1~ppa1
New upstream beta release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/******************************* LICENSE **************************************
2
 
* Any code in this file may be redistributed or modified under the terms of
3
 
* the GNU General Public License as published by the Free Software
4
 
* Foundation; version 2 of the license.
5
 
****************************** END LICENSE ***********************************/
6
 
 
7
 
/******************************************************************************
8
 
* Author:
9
 
* Andrew Smith, http://littlesvr.ca/misc/contactandrew.php
10
 
*
11
 
* Copyright 2005-2007 Andrew Smith <andrew-smith@mail.ru>
12
 
*
13
 
* Contributors:
14
 
*
15
 
******************************************************************************/
16
 
 
17
 
#include <string.h>
18
 
#include <sys/types.h>
19
 
 
20
 
#include "bk.h"
21
 
#include "bkInternal.h"
22
 
#include "bkSort.h"
23
 
 
24
 
/* strings cannot be equal */
25
 
bool rightIsBigger(char* leftStr, char* rightStr)
26
 
{
27
 
    int leftLen;
28
 
    int rightLen;
29
 
    int count;
30
 
    bool resultFound;
31
 
    bool rc;
32
 
 
33
 
    leftLen = strlen(leftStr);
34
 
    rightLen = strlen(rightStr);
35
 
 
36
 
    resultFound = false;
37
 
    for (count = 0; count < leftLen && count < rightLen && !resultFound; count++) {
38
 
        if (rightStr[count] > leftStr[count]) {
39
 
            resultFound = true;
40
 
            rc = true;
41
 
        } else if (rightStr[count] < leftStr[count]) {
42
 
            resultFound = true;
43
 
            rc = false;
44
 
        }
45
 
    }
46
 
 
47
 
    if (!resultFound)
48
 
        /* strings are the same up to the length of the shorter one */
49
 
    {
50
 
        if (rightLen > leftLen)
51
 
            rc = true;
52
 
        else
53
 
            rc = false;
54
 
    }
55
 
 
56
 
    return rc;
57
 
}
58
 
 
59
 
void sortDir(DirToWrite* dir, int filenameType)
60
 
{
61
 
    BaseToWrite* child;
62
 
 
63
 
    child = dir->children;
64
 
    while (child != NULL) {
65
 
        if (IS_DIR(child->posixFileMode))
66
 
            sortDir(DIRTW_PTR(child), filenameType);
67
 
 
68
 
        child = child->next;
69
 
    }
70
 
 
71
 
    BaseToWrite** outerPtr;
72
 
    BaseToWrite** innerPtr;
73
 
 
74
 
    outerPtr = &(dir->children);
75
 
    while (*outerPtr != NULL) {
76
 
        innerPtr = &((*outerPtr)->next);
77
 
        while (*innerPtr != NULL) {
78
 
            if ((filenameType & FNTYPE_JOLIET &&
79
 
                    rightIsBigger((*innerPtr)->nameJoliet, (*outerPtr)->nameJoliet)) ||
80
 
                    (filenameType & FNTYPE_9660 &&
81
 
                     rightIsBigger((*innerPtr)->name9660, (*outerPtr)->name9660))) {
82
 
                BaseToWrite* outer = *outerPtr;
83
 
                BaseToWrite* inner = *innerPtr;
84
 
 
85
 
                if ((*outerPtr)->next != *innerPtr) {
86
 
                    *outerPtr = inner;
87
 
                    *innerPtr = outer;
88
 
 
89
 
                    BaseToWrite* oldInnerNext = inner->next;
90
 
                    inner->next = outer->next;
91
 
                    outer->next = oldInnerNext;
92
 
                } else {
93
 
                    *outerPtr = inner;
94
 
                    innerPtr = &(inner->next);
95
 
 
96
 
                    BaseToWrite* oldInnerNext = inner->next;
97
 
                    inner->next = outer;
98
 
                    outer->next = oldInnerNext;
99
 
                }
100
 
            }
101
 
 
102
 
            innerPtr = &((*innerPtr)->next);
103
 
        }
104
 
 
105
 
        outerPtr = &((*outerPtr)->next);
106
 
    }
107
 
}