summaryrefslogtreecommitdiff
path: root/src/c_fl_filename.cpp
blob: 39af3d1e6bf8190387aa100d73982f644d130dbd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127


//  Programmed by Jedidiah Barber
//  Released into the public domain


#include <FL/filename.H>
#include <string.h>
#include "c_fl_filename.h"




const int fl_path_max = FL_PATH_MAX;




void free_filename_file_list(void * l, int n) {
    struct dirent ** p = reinterpret_cast<struct dirent **>(l);
    fl_filename_free_list(&p, n);
}

const char * filename_dname(void * l, int n) {
    return (reinterpret_cast<struct dirent **>(l)[n])->d_name;
}




void filename_decode_uri(char *uri) {
    fl_decode_uri(uri);
}

int filename_absolute(char * to, int tolen, const char * from) {
    return fl_filename_absolute(to, tolen, from);
}

int filename_expand(char * to, int tolen, const char * from) {
    return fl_filename_expand(to, tolen, from);
}

const char * filename_ext(const char * buf) {
    return fl_filename_ext(buf);
}

int filename_isdir(const char * name) {
    return fl_filename_isdir(name);
}

int filename_list(const char * d, void * l, void * f) {
    return fl_filename_list(d, reinterpret_cast<struct dirent ***>(l),
        reinterpret_cast<Fl_File_Sort_F*>(f));
}

int filename_match(const char * name, const char * pattern) {
    return fl_filename_match(name, pattern);
}

const char * filename_name(const char * name) {
    return fl_filename_name(name);
}

int filename_relative(char * to, int tolen, const char * from) {
    return fl_filename_relative(to, tolen, from);
}

char * filename_setext(char * to, int tolen, const char * ext) {
    return fl_filename_setext(to, tolen, ext);
}

int filename_open_uri(const char * uri, char * msg, int msglen) {
    return fl_open_uri(uri, msg, msglen);
}




int filename_alphasort(char * a, char * b) {
    struct dirent d_aye, d_bee;
    d_aye.d_name[0] = '\0';
    strncat (d_aye.d_name, a, 255);
    d_bee.d_name[0] = '\0';
    strncat (d_bee.d_name, b, 255);
    struct dirent * dp_aye = &d_aye;
    struct dirent * dp_bee = &d_bee;
    int result = fl_alphasort(&dp_aye, &dp_bee);
    return result < 0 ? 0 : result == 0 ? 1 : 2;
}

int filename_casealphasort(char * a, char * b) {
    struct dirent d_aye, d_bee;
    d_aye.d_name[0] = '\0';
    strncat (d_aye.d_name, a, 255);
    d_bee.d_name[0] = '\0';
    strncat (d_bee.d_name, b, 255);
    struct dirent * dp_aye = &d_aye;
    struct dirent * dp_bee = &d_bee;
    int result = fl_casealphasort(&dp_aye, &dp_bee);
    return result < 0 ? 0 : result == 0 ? 1 : 2;
}

int filename_numericsort(char * a, char * b) {
    struct dirent d_aye, d_bee;
    d_aye.d_name[0] = '\0';
    strncat (d_aye.d_name, a, 255);
    d_bee.d_name[0] = '\0';
    strncat (d_bee.d_name, b, 255);
    struct dirent * dp_aye = &d_aye;
    struct dirent * dp_bee = &d_bee;
    int result = fl_numericsort(&dp_aye, &dp_bee);
    return result < 0 ? 0 : result == 0 ? 1 : 2;
}

int filename_casenumericsort(char * a, char * b) {
    struct dirent d_aye, d_bee;
    d_aye.d_name[0] = '\0';
    strncat (d_aye.d_name, a, 255);
    d_bee.d_name[0] = '\0';
    strncat (d_bee.d_name, b, 255);
    struct dirent * dp_aye = &d_aye;
    struct dirent * dp_bee = &d_bee;
    int result = fl_casenumericsort(&dp_aye, &dp_bee);
    return result < 0 ? 0 : result == 0 ? 1 : 2;
}