diff options
Diffstat (limited to 'apps/plugins/disktidy.c')
-rw-r--r-- | apps/plugins/disktidy.c | 51 |
1 files changed, 37 insertions, 14 deletions
diff --git a/apps/plugins/disktidy.c b/apps/plugins/disktidy.c index df0076f93d..92232bf17a 100644 --- a/apps/plugins/disktidy.c +++ b/apps/plugins/disktidy.c | |||
@@ -36,6 +36,8 @@ enum tidy_return | |||
36 | #define MAX_TYPES 64 | 36 | #define MAX_TYPES 64 |
37 | struct tidy_type { | 37 | struct tidy_type { |
38 | char filestring[64]; | 38 | char filestring[64]; |
39 | int pre; | ||
40 | int post; | ||
39 | bool directory; | 41 | bool directory; |
40 | bool remove; | 42 | bool remove; |
41 | } tidy_types[MAX_TYPES]; | 43 | } tidy_types[MAX_TYPES]; |
@@ -46,6 +48,7 @@ bool tidy_loaded_and_changed = false; | |||
46 | #define CUSTOM_FILES PLUGIN_APPS_DIR "/disktidy_custom.config" | 48 | #define CUSTOM_FILES PLUGIN_APPS_DIR "/disktidy_custom.config" |
47 | void add_item(const char* name, int index) | 49 | void add_item(const char* name, int index) |
48 | { | 50 | { |
51 | char *a; | ||
49 | rb->strcpy(tidy_types[index].filestring, name); | 52 | rb->strcpy(tidy_types[index].filestring, name); |
50 | if (name[rb->strlen(name)-1] == '/') | 53 | if (name[rb->strlen(name)-1] == '/') |
51 | { | 54 | { |
@@ -54,6 +57,17 @@ void add_item(const char* name, int index) | |||
54 | } | 57 | } |
55 | else | 58 | else |
56 | tidy_types[index].directory = false; | 59 | tidy_types[index].directory = false; |
60 | a = rb->strchr(name, '*'); | ||
61 | if (a) | ||
62 | { | ||
63 | tidy_types[index].pre = a - name; | ||
64 | tidy_types[index].post = rb->strlen(a+1); | ||
65 | } | ||
66 | else | ||
67 | { | ||
68 | tidy_types[index].pre = -1; | ||
69 | tidy_types[index].post = -1; | ||
70 | } | ||
57 | } | 71 | } |
58 | static int find_file_string(const char *file, char *last_group) | 72 | static int find_file_string(const char *file, char *last_group) |
59 | { | 73 | { |
@@ -89,9 +103,7 @@ static int find_file_string(const char *file, char *last_group) | |||
89 | /* shift items up one */ | 103 | /* shift items up one */ |
90 | for (i=tidy_type_count;i>idx_last_group;i--) | 104 | for (i=tidy_type_count;i>idx_last_group;i--) |
91 | { | 105 | { |
92 | rb->strcpy(tidy_types[i].filestring, tidy_types[i-1].filestring); | 106 | rb->memcpy(&tidy_types[i], &tidy_types[i-1], sizeof(struct tidy_type)); |
93 | tidy_types[i].directory = tidy_types[i-1].directory; | ||
94 | tidy_types[i].remove = tidy_types[i-1].remove; | ||
95 | } | 107 | } |
96 | tidy_type_count++; | 108 | tidy_type_count++; |
97 | add_item(file, idx_last_group+1); | 109 | add_item(file, idx_last_group+1); |
@@ -132,22 +144,33 @@ bool tidy_load_file(const char* file) | |||
132 | return true; | 144 | return true; |
133 | } | 145 | } |
134 | 146 | ||
147 | static bool match(struct tidy_type *tidy_type, char *string, int len) | ||
148 | { | ||
149 | char *pattern = tidy_type->filestring; | ||
150 | if (tidy_type->pre < 0) | ||
151 | { | ||
152 | /* no '*', just compare. */ | ||
153 | return (rb->strcmp(pattern, string) == 0); | ||
154 | } | ||
155 | /* pattern is too long for the string. avoid 'ab*bc' matching 'abc'. */ | ||
156 | if (len < tidy_type->pre + tidy_type->post) | ||
157 | return false; | ||
158 | /* pattern has '*', compare former part of '*' to the begining of | ||
159 | the string and compare next part of '*' to the end of string. */ | ||
160 | return (rb->strncmp(pattern, string, tidy_type->pre) == 0 && | ||
161 | rb->strcmp(pattern + tidy_type->pre + 1, | ||
162 | string + len - tidy_type->post) == 0); | ||
163 | } | ||
164 | |||
135 | bool tidy_remove_item(char *item, int attr) | 165 | bool tidy_remove_item(char *item, int attr) |
136 | { | 166 | { |
137 | int i; | 167 | int i; |
138 | char *file; | 168 | int len; |
139 | bool ret = false, rem = false; | 169 | bool ret = false; |
170 | len = rb->strlen(item); | ||
140 | for (i=0; ret == false && i < tidy_type_count; i++) | 171 | for (i=0; ret == false && i < tidy_type_count; i++) |
141 | { | 172 | { |
142 | file = tidy_types[i].filestring; | 173 | if (match(&tidy_types[i], item, len)) |
143 | if (file[rb->strlen(file)-1] == '*') | ||
144 | { | ||
145 | if (!rb->strncmp(file, item, rb->strlen(file)-1)) | ||
146 | rem = true; | ||
147 | } | ||
148 | else if (!rb->strcmp(file, item)) | ||
149 | rem = true; | ||
150 | if (rem) | ||
151 | { | 174 | { |
152 | if (!tidy_types[i].remove) | 175 | if (!tidy_types[i].remove) |
153 | return false; | 176 | return false; |