-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathFilter.c
220 lines (198 loc) · 4.85 KB
/
Filter.c
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/*
* CLCL
*
* Filter.c
*
* Copyright (C) 1996-2019 by Ohno Tomoaki. All rights reserved.
* https://www.nakka.com/
*/
/* Include Files */
#define _INC_OLE
#include <windows.h>
#undef _INC_OLE
#include "General.h"
#include "Memory.h"
#include "String.h"
#include "Data.h"
#include "Ini.h"
#include "Message.h"
#include "Filter.h"
/* Define */
/* Global Variables */
// オプション
extern OPTION_INFO option;
/* Local Function Prototypes */
static BOOL filter_save_check(const TCHAR *format_name);
static DATA_INFO *filter_item_copy(const DATA_INFO *di, TCHAR *err_str);
/*
* filter_get_index - フィルタ情報のインデックスを取得
*/
int filter_get_index(const TCHAR *format_name, const int name_hash)
{
TCHAR *buf;
int hash;
int i, j;
if (format_name == NULL || (buf = alloc_copy(format_name)) == NULL) {
return -1;
}
Trim(buf);
hash = (name_hash == 0) ? str2hash(buf) : name_hash;
for (i = 0; i < option.filter_cnt; i++) {
if ((option.filter_info + i)->fn == NULL) {
continue;
}
for (j = 0; j < (option.filter_info + i)->fn_cnt; j++) {
if (hash == ((option.filter_info + i)->fn + j)->format_name_hash &&
lstrcmpi(buf, ((option.filter_info + i)->fn + j)->format_name) == 0) {
mem_free(&buf);
return i;
}
}
}
mem_free(&buf);
return -1;
}
/*
* filter_format_check - 形式のチェック
*/
BOOL filter_format_check(const TCHAR *format_name)
{
int i;
if ((i = filter_get_index(format_name, 0)) == -1) {
return ((option.filter_all_action == FILTER_ACTION_ADD) ? TRUE : FALSE);
}
return (((option.filter_info + i)->action == FILTER_ACTION_ADD) ? TRUE : FALSE);
}
/*
* filter_size_check - サイズのチェック
*/
BOOL filter_size_check(const TCHAR *format_name, const DWORD size)
{
int i;
if ((i = filter_get_index(format_name, 0)) == -1) {
return TRUE;
}
if ((option.filter_info + i)->limit_size <= 0) {
return TRUE;
}
if (size > (option.filter_info + i)->limit_size) {
return FALSE;
}
return TRUE;
}
/*
* filter_save_check - 形式の保存チェック
*/
static BOOL filter_save_check(const TCHAR *format_name)
{
int i;
if ((i = filter_get_index(format_name, 0)) == -1) {
return ((option.filter_all_action == FILTER_ACTION_ADD) ? TRUE : FALSE);
}
return (((option.filter_info + i)->action == FILTER_ACTION_IGNORE ||
(option.filter_info + i)->save == FILTER_SAVE_NOSAVE) ? FALSE : TRUE);
}
/*
* filter_list_save_check - 保存フィルタが有効がチェック
*/
BOOL filter_list_save_check(DATA_INFO *di)
{
DATA_INFO *cdi;
for (; di != NULL; di = di->next) {
switch (di->type) {
case TYPE_FOLDER:
if (filter_list_save_check(di->child) == TRUE) {
return TRUE;
}
break;
case TYPE_ITEM:
for (cdi = di->child; cdi != NULL; cdi = cdi->next) {
// 保存フィルタのチェック
if (filter_save_check(cdi->format_name) == FALSE) {
return TRUE;
}
}
break;
}
}
return FALSE;
}
/*
* filter_item_copy - フィルタをかけてアイテムのコピー
*/
static DATA_INFO *filter_item_copy(const DATA_INFO *di, TCHAR *err_str)
{
DATA_INFO *new_item = NULL;
DATA_INFO *copy_di;
DATA_INFO *cdi;
DATA_INFO *wk_di;
switch (di->type) {
case TYPE_FOLDER:
if ((new_item = data_create_folder(di->title, err_str)) == NULL) {
return NULL;
}
if ((new_item->child = filter_list_copy(di->child, err_str)) == NULL && *err_str != TEXT('\0')) {
data_free(new_item);
return NULL;
}
break;
case TYPE_ITEM:
if ((new_item = data_create_item(di->title, FALSE, err_str)) == NULL) {
return NULL;
}
new_item->modified.dwLowDateTime = di->modified.dwLowDateTime;
new_item->modified.dwHighDateTime = di->modified.dwHighDateTime;
new_item->window_name = alloc_copy(di->window_name);
new_item->plugin_string = alloc_copy(di->plugin_string);
new_item->plugin_param = di->plugin_param;
for (cdi = di->child; cdi != NULL; cdi = cdi->next) {
// 保存フィルタのチェック
if (filter_save_check(cdi->format_name) == TRUE) {
if ((copy_di = data_item_copy(cdi, FALSE, FALSE, err_str)) == NULL) {
data_free(new_item);
return NULL;
}
if (new_item->child == NULL) {
new_item->child = copy_di;
} else {
for (wk_di = new_item->child; wk_di->next != NULL; wk_di = wk_di->next)
;
wk_di->next = copy_di;
}
}
}
if (new_item->child == NULL) {
data_free(new_item);
return NULL;
}
break;
}
return new_item;
}
/*
* filter_list_copy - フィルタをかけてアイテムリストのコピー
*/
DATA_INFO *filter_list_copy(DATA_INFO *di, TCHAR *err_str)
{
DATA_INFO *root_item = NULL;
DATA_INFO *new_item;
DATA_INFO *cdi;
*err_str = TEXT('\0');
for (; di != NULL; di = di->next) {
if ((new_item = filter_item_copy(di, err_str)) == NULL && *err_str != TEXT('\0')) {
data_free(root_item);
return NULL;
}
if (new_item != NULL) {
if (root_item == NULL) {
root_item = new_item;
} else {
cdi->next = new_item;
}
cdi = new_item;
}
}
return root_item;
}
/* End of source */