1 |
|
---|
2 | /***********************************************************************
|
---|
3 |
|
---|
4 | $Id: avl.c 1220 2008-09-13 23:09:45Z jbs $
|
---|
5 |
|
---|
6 | archiver.bb2 search, load, save and date parse
|
---|
7 |
|
---|
8 | Copyright (c) 1993, 1998 M. Kimes
|
---|
9 | Copyright (c) 2004, 2008 Steven H.Levine
|
---|
10 |
|
---|
11 | 01 Aug 04 SHL Rework lstrip/rstrip usage
|
---|
12 | 13 Aug 05 SHL Beautify with indent
|
---|
13 | 13 Aug 05 SHL find_type: correct no sig exists bypass logic
|
---|
14 | 13 Aug 05 SHL SBoxDlgProc: avoid dereferencing NULL signature
|
---|
15 | 18 Aug 05 SHL Comments
|
---|
16 | 31 Dec 05 SHL indent -i2
|
---|
17 | 08 Dec 05 SHL load_archivers: allow empty startlist
|
---|
18 | 30 Dec 05 SHL load_archivers: use get_archiver_line?(), clean nits
|
---|
19 | 29 May 06 SHL SBoxDlgProc: support move, add, delete
|
---|
20 | 30 May 06 SHL load_archivers: add reload support
|
---|
21 | 16 Jun 06 SHL load_archivers: support signatures containing 0s
|
---|
22 | 26 Jun 06 SHL load_archivers: remember where comments are
|
---|
23 | 14 Jul 06 SHL Use Runtime_Error
|
---|
24 | 29 Jul 06 SHL Use xfgets, xfgets_bstripcr
|
---|
25 | 15 Aug 06 SHL Use Runtime_Error more
|
---|
26 | 01 Nov 06 SHL Turn off leftover debug code
|
---|
27 | 06 Apr 07 GKY Work around PM DragInfo and DrgFreeDISH limit
|
---|
28 | 19 Apr 07 SHL Use FreeDragInfoData
|
---|
29 | 19 Apr 07 SHL Add more drag/drop error checking
|
---|
30 | 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
|
---|
31 | 25 Aug 07 SHL load_archivers: add missing close on error path
|
---|
32 | 29 Feb 08 GKY Use xfree where appropriate
|
---|
33 | 22 Jun 08 GKY Added free_archivers for fortify checking
|
---|
34 | 19 Jul 08 GKY ifdef Fortify free_archivers
|
---|
35 |
|
---|
36 | ***********************************************************************/
|
---|
37 |
|
---|
38 | #include <stdlib.h>
|
---|
39 | #include <string.h>
|
---|
40 | #include <ctype.h>
|
---|
41 | #include <share.h>
|
---|
42 |
|
---|
43 | #define INCL_DOS
|
---|
44 | #define INCL_WIN
|
---|
45 | #define INCL_WINSTDDRAG
|
---|
46 | #define INCL_LONGLONG
|
---|
47 |
|
---|
48 | #include "fm3dll.h"
|
---|
49 | #include "fm3dll2.h" // #define's for UM_*, control id's, etc.
|
---|
50 | #include "notebook.h" // Data declaration(s)
|
---|
51 | #include "init.h" // Data declaration(s)
|
---|
52 | #include "valid.h" // Data declaration(s)
|
---|
53 | #include "mainwnd.h" // Data declaration(s)
|
---|
54 | #include "fm3dlg.h"
|
---|
55 | #include "fm3str.h"
|
---|
56 | #include "avl.h"
|
---|
57 | #include "strutil.h" // GetPString
|
---|
58 | #include "errutil.h" // Runtime_Error
|
---|
59 | #include "avv.h" // ArcReviewDlgProc, rewrite_archiverbb2
|
---|
60 | #include "droplist.h" // DropHelp, FullDrgName
|
---|
61 | #include "misc.h" // DrawTargetEmphasis
|
---|
62 | #include "draglist.h" // FreeDragInfoData
|
---|
63 | #include "chklist.h" // PosOverOkay
|
---|
64 | #include "literal.h" // literal
|
---|
65 | #include "wrappers.h" // xfgets
|
---|
66 | #include "strips.h" // bstrip
|
---|
67 | #include "srchpath.h" // searchpath
|
---|
68 | #include "stristr.h" // stristr
|
---|
69 | #include "delims.h" // to_delim
|
---|
70 | #include "fortify.h"
|
---|
71 |
|
---|
72 | // Data definitions
|
---|
73 | static PSZ pszSrcFile = __FILE__;
|
---|
74 | static void fill_listbox(HWND hwnd, BOOL fShowAll, SHORT sOldSelect);
|
---|
75 |
|
---|
76 | #pragma data_seg(GLOBAL1)
|
---|
77 | ARC_TYPE *arcsighead;
|
---|
78 | UINT arcsigs_header_lines; // Header comments line count in archiver.bb2
|
---|
79 | UINT arcsigs_trailer_line_num; // Trailer comments start line number (1..n)
|
---|
80 | BOOL arcsigsloaded;
|
---|
81 | BOOL arcsigsmodified;
|
---|
82 |
|
---|
83 | //=== quick_find_type() ===
|
---|
84 | ARC_TYPE *quick_find_type(CHAR * filespec, ARC_TYPE * topsig)
|
---|
85 | {
|
---|
86 | ARC_TYPE *info, *found = NULL;
|
---|
87 | CHAR *p;
|
---|
88 |
|
---|
89 | if (!arcsigsloaded)
|
---|
90 | load_archivers();
|
---|
91 | p = strrchr(filespec, '.');
|
---|
92 | if (p) {
|
---|
93 | p++;
|
---|
94 | info = (topsig) ? topsig : arcsighead;
|
---|
95 | while (info) {
|
---|
96 | if (info->ext && *(info->ext) && !stricmp(p, info->ext)) {
|
---|
97 | found = find_type(filespec, topsig);
|
---|
98 | break;
|
---|
99 | }
|
---|
100 | info = info->next;
|
---|
101 | }
|
---|
102 | }
|
---|
103 | return found;
|
---|
104 | }
|
---|
105 |
|
---|
106 | //=== fill_listbox() fill or refill listbox from current archiver definitions ===
|
---|
107 |
|
---|
108 | static VOID fill_listbox(HWND hwnd, BOOL fShowAll, SHORT sOldSelect)
|
---|
109 | {
|
---|
110 | ARC_TYPE *pat;
|
---|
111 | BOOL found = FALSE;
|
---|
112 | SHORT sSelect;
|
---|
113 |
|
---|
114 | WinSendDlgItemMsg(hwnd, ASEL_LISTBOX, LM_DELETEALL, MPVOID, MPVOID);
|
---|
115 |
|
---|
116 | for (pat = arcsighead; pat; pat = pat->next) {
|
---|
117 | /*
|
---|
118 | * this inner loop tests for a dup signature entry and assures
|
---|
119 | * that only the entry at the top of the list gets used for
|
---|
120 | * conversion; editing any is okay
|
---|
121 | */
|
---|
122 | if (!fShowAll) {
|
---|
123 | ARC_TYPE *pat2;
|
---|
124 | BOOL isDup = FALSE;
|
---|
125 |
|
---|
126 | for (pat2 = arcsighead;
|
---|
127 | pat2 && pat->siglen && pat2 != pat && !isDup; pat2 = pat2->next) {
|
---|
128 | isDup = pat2->siglen == pat->siglen &&
|
---|
129 | !memcmp(pat2->signature, pat->signature, pat->siglen);
|
---|
130 | } // for
|
---|
131 | if (isDup)
|
---|
132 | continue;
|
---|
133 | }
|
---|
134 |
|
---|
135 | // If caller is editing archivers or entry useful to caller, show in listbox
|
---|
136 | if (fShowAll || (pat->id && pat->extract && pat->create)) {
|
---|
137 | sSelect = (SHORT) WinSendDlgItemMsg(hwnd, ASEL_LISTBOX, LM_INSERTITEM,
|
---|
138 | MPFROM2SHORT(LIT_END, 0),
|
---|
139 | MPFROMP(pat->id ? pat->id : "?"));
|
---|
140 | if (!found && *szDefArc && pat->id && !strcmp(szDefArc, pat->id)) {
|
---|
141 | // Highlight default
|
---|
142 | WinSendDlgItemMsg(hwnd, ASEL_LISTBOX, LM_SELECTITEM,
|
---|
143 | MPFROMSHORT(sSelect), MPFROMSHORT(TRUE));
|
---|
144 | found = TRUE;
|
---|
145 | }
|
---|
146 | }
|
---|
147 | else {
|
---|
148 | // Complain about odd entry
|
---|
149 | if (!pat->id || !*pat->id) {
|
---|
150 | WinSendDlgItemMsg(hwnd, ASEL_LISTBOX, LM_INSERTITEM,
|
---|
151 | MPFROM2SHORT(LIT_END, 0),
|
---|
152 | MPFROMP(GetPString(IDS_UNKNOWNUNUSABLETEXT)));
|
---|
153 | }
|
---|
154 | else {
|
---|
155 | CHAR s[81];
|
---|
156 |
|
---|
157 | sprintf(s, "%0.12s %s", pat->id, GetPString(IDS_UNUSABLETEXT));
|
---|
158 | WinSendDlgItemMsg(hwnd, ASEL_LISTBOX, LM_INSERTITEM,
|
---|
159 | MPFROM2SHORT(LIT_END, 0), MPFROMP(s));
|
---|
160 | }
|
---|
161 | }
|
---|
162 | } // while scanning
|
---|
163 |
|
---|
164 | // Try to reselect last selection unless user wants default selection
|
---|
165 | if (sOldSelect != LIT_NONE && !found) {
|
---|
166 | SHORT sItemCount =
|
---|
167 | (SHORT) WinSendDlgItemMsg(hwnd, ASEL_LISTBOX, LM_QUERYITEMCOUNT,
|
---|
168 | MPVOID, MPVOID);
|
---|
169 |
|
---|
170 | if (sOldSelect >= sItemCount)
|
---|
171 | sOldSelect = sItemCount - 1;
|
---|
172 | if (sOldSelect >= 0) {
|
---|
173 | WinSendDlgItemMsg(hwnd, ASEL_LISTBOX, LM_SELECTITEM,
|
---|
174 | MPFROMSHORT(sOldSelect), MPFROMSHORT(TRUE));
|
---|
175 | }
|
---|
176 | }
|
---|
177 |
|
---|
178 | if (found)
|
---|
179 | PosOverOkay(hwnd);
|
---|
180 | }
|
---|
181 |
|
---|
182 | ARC_TYPE *find_type(CHAR * filespec, ARC_TYPE * topsig)
|
---|
183 | {
|
---|
184 | HFILE handle;
|
---|
185 | ULONG action;
|
---|
186 | ULONG len;
|
---|
187 | ULONG l;
|
---|
188 | ARC_TYPE *info;
|
---|
189 | CHAR *p;
|
---|
190 | // CHAR buffer[80];
|
---|
191 | CHAR buffer[4096]; // 06 Oct 07 SHL Protect against NTFS defect
|
---|
192 |
|
---|
193 | if (!arcsigsloaded)
|
---|
194 | load_archivers();
|
---|
195 | if (!topsig)
|
---|
196 | topsig = arcsighead;
|
---|
197 | DosError(FERR_DISABLEHARDERR);
|
---|
198 | if (DosOpen(filespec,
|
---|
199 | &handle,
|
---|
200 | &action,
|
---|
201 | 0,
|
---|
202 | 0,
|
---|
203 | OPEN_ACTION_FAIL_IF_NEW |
|
---|
204 | OPEN_ACTION_OPEN_IF_EXISTS,
|
---|
205 | OPEN_FLAGS_FAIL_ON_ERROR |
|
---|
206 | OPEN_FLAGS_NOINHERIT |
|
---|
207 | OPEN_FLAGS_RANDOMSEQUENTIAL |
|
---|
208 | OPEN_SHARE_DENYNONE | OPEN_ACCESS_READONLY, 0))
|
---|
209 | return NULL;
|
---|
210 | // Scan signatures
|
---|
211 | for (info = topsig; info; info = info->next) {
|
---|
212 | if (info->siglen == 0) {
|
---|
213 | // No signature -- check extension
|
---|
214 | p = strrchr(filespec, '.');
|
---|
215 | if (p) {
|
---|
216 | p++;
|
---|
217 | if (info->ext && *(info->ext) && !stricmp(p, info->ext))
|
---|
218 | break; // Matched
|
---|
219 |
|
---|
220 | }
|
---|
221 | continue; // Next sig
|
---|
222 |
|
---|
223 | }
|
---|
224 | // Try signature match
|
---|
225 | l = info->siglen;
|
---|
226 | l = min(l, 79);
|
---|
227 | if (!DosChgFilePtr(handle,
|
---|
228 | abs(info->file_offset),
|
---|
229 | (info->file_offset >= 0) ?
|
---|
230 | FILE_BEGIN : FILE_END, &len)) {
|
---|
231 | if (!DosRead(handle, buffer, l, &len) && len == l) {
|
---|
232 | if (!memcmp(info->signature, buffer, l))
|
---|
233 | break; // Matched
|
---|
234 |
|
---|
235 | }
|
---|
236 | }
|
---|
237 | } // for
|
---|
238 |
|
---|
239 | DosClose(handle); /* Either way, we're done for now */
|
---|
240 | return info; /* Return signature, if any */
|
---|
241 | }
|
---|
242 |
|
---|
243 | # ifdef FORTIFY
|
---|
244 |
|
---|
245 | VOID free_archivers(VOID)
|
---|
246 | {
|
---|
247 | ARC_TYPE *pat, *next;
|
---|
248 |
|
---|
249 | pat = arcsighead;
|
---|
250 | while (pat) {
|
---|
251 | next = pat->next;
|
---|
252 | xfree(pat->id, pszSrcFile, __LINE__);
|
---|
253 | xfree(pat->ext, pszSrcFile, __LINE__);
|
---|
254 | xfree(pat->list, pszSrcFile, __LINE__);
|
---|
255 | xfree(pat->extract, pszSrcFile, __LINE__);
|
---|
256 | xfree(pat->create, pszSrcFile, __LINE__);
|
---|
257 | xfree(pat->move, pszSrcFile, __LINE__);
|
---|
258 | xfree(pat->delete, pszSrcFile, __LINE__);
|
---|
259 | xfree(pat->signature, pszSrcFile, __LINE__);
|
---|
260 | xfree(pat->startlist, pszSrcFile, __LINE__);
|
---|
261 | xfree(pat->endlist, pszSrcFile, __LINE__);
|
---|
262 | xfree(pat->exwdirs, pszSrcFile, __LINE__);
|
---|
263 | xfree(pat->test, pszSrcFile, __LINE__);
|
---|
264 | xfree(pat->createrecurse, pszSrcFile, __LINE__);
|
---|
265 | xfree(pat->createwdirs, pszSrcFile, __LINE__);
|
---|
266 | xfree(pat->movewdirs, pszSrcFile, __LINE__);
|
---|
267 | xfree(pat, pszSrcFile, __LINE__);
|
---|
268 | pat = next;
|
---|
269 | }
|
---|
270 | arcsighead = NULL;
|
---|
271 | }
|
---|
272 |
|
---|
273 | //=== free_arc_type() free allocated ARC_TYPE ===
|
---|
274 |
|
---|
275 | # endif
|
---|
276 |
|
---|
277 | VOID free_arc_type(ARC_TYPE * pat)
|
---|
278 | {
|
---|
279 | if (pat) {
|
---|
280 | xfree(pat->id, pszSrcFile, __LINE__);
|
---|
281 | xfree(pat->ext, pszSrcFile, __LINE__);
|
---|
282 | xfree(pat->list, pszSrcFile, __LINE__);
|
---|
283 | xfree(pat->extract, pszSrcFile, __LINE__);
|
---|
284 | xfree(pat->create, pszSrcFile, __LINE__);
|
---|
285 | xfree(pat->move, pszSrcFile, __LINE__);
|
---|
286 | xfree(pat->delete, pszSrcFile, __LINE__);
|
---|
287 | xfree(pat->signature, pszSrcFile, __LINE__);
|
---|
288 | xfree(pat->startlist, pszSrcFile, __LINE__);
|
---|
289 | xfree(pat->endlist, pszSrcFile, __LINE__);
|
---|
290 | xfree(pat->exwdirs, pszSrcFile, __LINE__);
|
---|
291 | xfree(pat->test, pszSrcFile, __LINE__);
|
---|
292 | xfree(pat->createrecurse, pszSrcFile, __LINE__);
|
---|
293 | xfree(pat->createwdirs, pszSrcFile, __LINE__);
|
---|
294 | xfree(pat->movewdirs, pszSrcFile, __LINE__);
|
---|
295 | free(pat);
|
---|
296 | }
|
---|
297 | }
|
---|
298 |
|
---|
299 | static UINT cur_line_num; // Input file line counter
|
---|
300 |
|
---|
301 | //=== get_line_strip_comments() read line, strip comments and whitespace ===
|
---|
302 |
|
---|
303 | #define ARCHIVER_LINE_BYTES 256
|
---|
304 |
|
---|
305 | static PSZ get_line_strip_comments(PSZ pszIn, FILE * fp)
|
---|
306 | {
|
---|
307 | PSZ psz = xfgets(pszIn, ARCHIVER_LINE_BYTES, fp, pszSrcFile, __LINE__);
|
---|
308 | PSZ psz2;
|
---|
309 |
|
---|
310 | if (psz) {
|
---|
311 | cur_line_num++;
|
---|
312 | psz2 = strchr(pszIn, ';');
|
---|
313 | if (psz2)
|
---|
314 | *psz2 = 0; // Chop comment
|
---|
315 | bstripcr(pszIn); // Strip leading white and trailing white and CR/LF
|
---|
316 |
|
---|
317 | }
|
---|
318 | return psz;
|
---|
319 | }
|
---|
320 |
|
---|
321 | //=== get_line_strip_white() read line, strip whitespace ===
|
---|
322 |
|
---|
323 | static PSZ get_line_strip_white(PSZ pszIn, FILE * fp)
|
---|
324 | {
|
---|
325 | PSZ psz =
|
---|
326 | xfgets_bstripcr(pszIn, ARCHIVER_LINE_BYTES, fp, pszSrcFile, __LINE__);
|
---|
327 |
|
---|
328 | if (psz)
|
---|
329 | cur_line_num++;
|
---|
330 |
|
---|
331 | return psz;
|
---|
332 | }
|
---|
333 |
|
---|
334 | //=== load_archivers() load or reload archive definitions from archiver.bb2 ===
|
---|
335 |
|
---|
336 | INT load_archivers(VOID)
|
---|
337 | {
|
---|
338 | FILE *fp;
|
---|
339 | CHAR sz[ARCHIVER_LINE_BYTES + 1];
|
---|
340 | CHAR *psz;
|
---|
341 | ARC_TYPE *pat = NULL;
|
---|
342 | ARC_TYPE *patLast = NULL;
|
---|
343 | UINT lines_per_arcsig = LINES_PER_ARCSIG;
|
---|
344 | UINT per_sig_comment_line_num = 0;
|
---|
345 | INT i;
|
---|
346 |
|
---|
347 | // Free current signatures
|
---|
348 | if (arcsighead) {
|
---|
349 | for (pat = arcsighead; pat;) {
|
---|
350 | patLast = pat;
|
---|
351 | pat = pat->next;
|
---|
352 | free_arc_type(patLast);
|
---|
353 | }
|
---|
354 | arcsighead = NULL;
|
---|
355 | }
|
---|
356 |
|
---|
357 | arcsigsmodified = FALSE;
|
---|
358 | arcsigs_header_lines = 0;
|
---|
359 | arcsigs_trailer_line_num = 0;
|
---|
360 |
|
---|
361 | DosEnterCritSec();
|
---|
362 | psz = searchpath(GetPString(IDS_ARCHIVERBB2));
|
---|
363 | if (!psz || !*psz) {
|
---|
364 | DosExitCritSec();
|
---|
365 | return -1;
|
---|
366 | }
|
---|
367 | fp = _fsopen(psz, "r", SH_DENYWR);
|
---|
368 | DosExitCritSec();
|
---|
369 | if (!fp)
|
---|
370 | return -2;
|
---|
371 | strcpy(archiverbb2, psz); // Remember full path
|
---|
372 |
|
---|
373 | cur_line_num = 0;
|
---|
374 |
|
---|
375 | // Line 1 must contain number of lines per signature definition
|
---|
376 | if (!get_line_strip_comments(sz, fp)) {
|
---|
377 | fclose(fp);
|
---|
378 | return -3;
|
---|
379 | }
|
---|
380 | if (*sz)
|
---|
381 | lines_per_arcsig = atoi(sz);
|
---|
382 | if (!*sz || lines_per_arcsig < LINES_PER_ARCSIG) {
|
---|
383 | fclose(fp); // 25 Aug 07 SHL
|
---|
384 | return -3;
|
---|
385 | }
|
---|
386 |
|
---|
387 | // Parse rest of file
|
---|
388 | // 1st non-blank line starts definition
|
---|
389 | // Need to determine header size and start of trailer
|
---|
390 |
|
---|
391 | while (!feof(fp)) {
|
---|
392 | // If reading header
|
---|
393 | if (!arcsigs_header_lines) {
|
---|
394 | // Reading header - find header size and start of signtures
|
---|
395 | if (!get_line_strip_white(sz, fp))
|
---|
396 | break; // Unexpected EOF
|
---|
397 | if (stristr(sz, "-- Current Archivers --")) {
|
---|
398 | arcsigs_header_lines = cur_line_num;
|
---|
399 | continue;
|
---|
400 | }
|
---|
401 | if (!*sz || *sz == ';')
|
---|
402 | continue; // Header comment or blank line
|
---|
403 | else {
|
---|
404 | // Not a comment, must be start of signatures
|
---|
405 | PSZ psz2 = strchr(sz, ';');
|
---|
406 |
|
---|
407 | if (psz2) {
|
---|
408 | *psz2 = 0; // Chop trailing comment
|
---|
409 | bstripcr(sz); // Strip leading white and trailing white and CR/LF
|
---|
410 | }
|
---|
411 | arcsigs_header_lines = cur_line_num - 1;
|
---|
412 | }
|
---|
413 | }
|
---|
414 | else {
|
---|
415 | // Reading defintiions
|
---|
416 | if (!get_line_strip_comments(sz, fp))
|
---|
417 | break; // EOF
|
---|
418 | }
|
---|
419 |
|
---|
420 | // fixme to avoid allocating empty fields
|
---|
421 |
|
---|
422 | // Remember start of per sig comments for next definition
|
---|
423 | if (per_sig_comment_line_num == 0)
|
---|
424 | per_sig_comment_line_num = cur_line_num;
|
---|
425 |
|
---|
426 | if (*sz) {
|
---|
427 | // At start of defintion
|
---|
428 |
|
---|
429 | pat = xmallocz(sizeof(ARC_TYPE), pszSrcFile, __LINE__);
|
---|
430 | if (!pat)
|
---|
431 | break;
|
---|
432 | pat->id = xstrdup(sz, pszSrcFile, __LINE__);
|
---|
433 |
|
---|
434 | pat->comment_line_num = per_sig_comment_line_num;
|
---|
435 | pat->defn_line_num = cur_line_num;
|
---|
436 |
|
---|
437 | if (!get_line_strip_comments(sz, fp)) // line 2 - extension
|
---|
438 | break;
|
---|
439 | if (*sz)
|
---|
440 | pat->ext = xstrdup(sz, pszSrcFile, __LINE__);
|
---|
441 | else
|
---|
442 | pat->ext = NULL;
|
---|
443 | if (!get_line_strip_comments(sz, fp)) // line 3 - offset to signature
|
---|
444 | break;
|
---|
445 | pat->file_offset = atol(sz);
|
---|
446 | if (!get_line_strip_comments(sz, fp)) // line 4 - list command
|
---|
447 | break;
|
---|
448 | if (*sz)
|
---|
449 | pat->list = xstrdup(sz, pszSrcFile, __LINE__);
|
---|
450 | else
|
---|
451 | pat->list = NULL;
|
---|
452 | if (!pat->list)
|
---|
453 | break; // Must have list command - fixme to complain
|
---|
454 | if (!get_line_strip_comments(sz, fp)) // line 5
|
---|
455 | break;
|
---|
456 | if (*sz)
|
---|
457 | pat->extract = xstrdup(sz, pszSrcFile, __LINE__);
|
---|
458 | else
|
---|
459 | pat->extract = NULL;
|
---|
460 | if (!get_line_strip_comments(sz, fp)) // line 6
|
---|
461 | break;
|
---|
462 | if (*sz)
|
---|
463 | pat->exwdirs = xstrdup(sz, pszSrcFile, __LINE__);
|
---|
464 | else
|
---|
465 | pat->exwdirs = NULL;
|
---|
466 | if (!get_line_strip_comments(sz, fp)) // line 7
|
---|
467 | break;
|
---|
468 | if (*sz)
|
---|
469 | pat->test = xstrdup(sz, pszSrcFile, __LINE__);
|
---|
470 | else
|
---|
471 | pat->test = NULL;
|
---|
472 | if (!get_line_strip_comments(sz, fp)) // line 8
|
---|
473 | break;
|
---|
474 | if (*sz)
|
---|
475 | pat->create = xstrdup(sz, pszSrcFile, __LINE__);
|
---|
476 | else
|
---|
477 | pat->create = NULL;
|
---|
478 | if (!get_line_strip_comments(sz, fp)) // line 9
|
---|
479 | break;
|
---|
480 | if (*sz)
|
---|
481 | pat->createwdirs = xstrdup(sz, pszSrcFile, __LINE__);
|
---|
482 | else
|
---|
483 | pat->createwdirs = NULL;
|
---|
484 | if (!get_line_strip_comments(sz, fp)) // line 10
|
---|
485 | break;
|
---|
486 | if (*sz)
|
---|
487 | pat->createrecurse = xstrdup(sz, pszSrcFile, __LINE__);
|
---|
488 | else
|
---|
489 | pat->createrecurse = NULL;
|
---|
490 | if (!get_line_strip_comments(sz, fp)) // line 11
|
---|
491 | break;
|
---|
492 | if (*sz)
|
---|
493 | pat->move = xstrdup(sz, pszSrcFile, __LINE__);
|
---|
494 | else
|
---|
495 | pat->move = NULL;
|
---|
496 | if (!get_line_strip_comments(sz, fp)) // line 12
|
---|
497 | break;
|
---|
498 | if (*sz)
|
---|
499 | pat->movewdirs = xstrdup(sz, pszSrcFile, __LINE__);
|
---|
500 | else
|
---|
501 | pat->movewdirs = NULL;
|
---|
502 | if (!get_line_strip_comments(sz, fp)) // line 13
|
---|
503 | break;
|
---|
504 | if (*sz)
|
---|
505 | pat->delete = xstrdup(sz, pszSrcFile, __LINE__);
|
---|
506 | else
|
---|
507 | pat->delete = NULL;
|
---|
508 | if (!get_line_strip_white(sz, fp)) // line 14
|
---|
509 | break;
|
---|
510 | i = literal(sz); // Translate \ escapes
|
---|
511 | if (i) {
|
---|
512 | pat->siglen = i;
|
---|
513 | pat->signature = xmalloc(i, pszSrcFile, __LINE__);
|
---|
514 | if (!pat->signature)
|
---|
515 | break;
|
---|
516 | memcpy(pat->signature, sz, i); // signature may not be a string
|
---|
517 | }
|
---|
518 | else {
|
---|
519 | pat->siglen = 0;
|
---|
520 | pat->signature = NULL;
|
---|
521 | }
|
---|
522 | if (!get_line_strip_white(sz, fp)) // line 15
|
---|
523 | break;
|
---|
524 | if (*sz)
|
---|
525 | pat->startlist = xstrdup(sz, pszSrcFile, __LINE__);
|
---|
526 | else
|
---|
527 | pat->startlist = NULL;
|
---|
528 | if (!get_line_strip_white(sz, fp)) // line 16
|
---|
529 | break;
|
---|
530 | if (*sz)
|
---|
531 | pat->endlist = xstrdup(sz, pszSrcFile, __LINE__);
|
---|
532 | else
|
---|
533 | pat->endlist = NULL;
|
---|
534 | if (!get_line_strip_comments(sz, fp)) // line 17
|
---|
535 | break;
|
---|
536 | pat->osizepos = atoi(sz);
|
---|
537 | if (!get_line_strip_comments(sz, fp)) // line 18
|
---|
538 | break;
|
---|
539 | pat->nsizepos = atoi(sz);
|
---|
540 | if (!get_line_strip_comments(sz, fp)) // line 19
|
---|
541 | break;
|
---|
542 | pat->fdpos = atoi(sz);
|
---|
543 | psz = strchr(sz, ',');
|
---|
544 | if (psz) {
|
---|
545 | psz++;
|
---|
546 | pat->datetype = atoi(psz);
|
---|
547 | }
|
---|
548 | if (!get_line_strip_comments(sz, fp)) // line 20
|
---|
549 | break;
|
---|
550 | pat->fdflds = atoi(sz);
|
---|
551 | if (!get_line_strip_comments(sz, fp)) // line 21
|
---|
552 | break;
|
---|
553 | pat->fnpos = atoi(sz);
|
---|
554 | psz = strchr(sz, ',');
|
---|
555 | if (psz) {
|
---|
556 | psz++;
|
---|
557 | pat->nameislast = (BOOL) (*psz && atol(psz) == 0) ? FALSE : TRUE;
|
---|
558 | psz = strchr(psz, ',');
|
---|
559 | if (psz) {
|
---|
560 | psz++;
|
---|
561 | pat->nameisnext = (BOOL) (*psz && atol(psz) == 0) ? FALSE : TRUE;
|
---|
562 | psz = strchr(psz, ',');
|
---|
563 | if (psz) {
|
---|
564 | psz++;
|
---|
565 | pat->nameisfirst = (BOOL) (*psz && atol(psz) == 0) ? FALSE : TRUE;
|
---|
566 | }
|
---|
567 | }
|
---|
568 | }
|
---|
569 | // Ignore unknown lines - must be newer file format
|
---|
570 | for (i = LINES_PER_ARCSIG; i < lines_per_arcsig; i++) {
|
---|
571 | if (!get_line_strip_comments(sz, fp))
|
---|
572 | break; // Unexpected EOF - fixme to complain
|
---|
573 | }
|
---|
574 |
|
---|
575 | // Add to list, assume next and prev already NULL
|
---|
576 | if (!arcsighead)
|
---|
577 | arcsighead = patLast = pat;
|
---|
578 | else {
|
---|
579 | patLast->next = pat;
|
---|
580 | pat->prev = patLast;
|
---|
581 | patLast = pat;
|
---|
582 | }
|
---|
583 | pat = NULL; // Done with this defintion
|
---|
584 |
|
---|
585 | arcsigs_trailer_line_num = cur_line_num + 1; // In case this is last defintion
|
---|
586 | per_sig_comment_line_num = 0;
|
---|
587 | } // if got definition
|
---|
588 |
|
---|
589 | } // while more lines
|
---|
590 |
|
---|
591 | fclose(fp);
|
---|
592 |
|
---|
593 | free_arc_type(pat); // In case partial definition in progress
|
---|
594 |
|
---|
595 | if (!arcsighead)
|
---|
596 | return -4;
|
---|
597 |
|
---|
598 | arcsigsloaded = TRUE;
|
---|
599 |
|
---|
600 | return 0;
|
---|
601 | }
|
---|
602 |
|
---|
603 | #define TEST_DRAG 0 // fixme to be gone or to work
|
---|
604 |
|
---|
605 | static MRESULT EXPENTRY SDlgListboxSubclassProc(HWND hwnd, ULONG msg,
|
---|
606 | MPARAM mp1, MPARAM mp2)
|
---|
607 | {
|
---|
608 | PFNWP pfnOldProc = (PFNWP) WinQueryWindowPtr(hwnd, QWL_USER);
|
---|
609 |
|
---|
610 | PDRAGITEM pDItem;
|
---|
611 | PDRAGINFO pDInfo;
|
---|
612 | BOOL ok;
|
---|
613 |
|
---|
614 | static BOOL emphasized = FALSE;
|
---|
615 | static PSZ DRMDRF_LBOX = "<DRM_LBOX,DRF_UNKNOWN>";
|
---|
616 | static PSZ DRM_LBOX = "DRM_LBOX";
|
---|
617 |
|
---|
618 | switch (msg) {
|
---|
619 | case WM_BEGINDRAG:
|
---|
620 | {
|
---|
621 | LONG cur_ndx;
|
---|
622 | DRAGITEM ditem;
|
---|
623 | DRAGIMAGE dimage;
|
---|
624 | HWND hwndDrop;
|
---|
625 |
|
---|
626 | // fprintf(stderr, "SDlgListboxSubclassProc: BEGINDRAG\n");
|
---|
627 | cur_ndx = WinQueryLboxSelectedItem(hwnd);
|
---|
628 |
|
---|
629 | if (cur_ndx != LIT_NONE) {
|
---|
630 | pDInfo = DrgAllocDraginfo(1);
|
---|
631 | if (pDInfo) {
|
---|
632 | pDInfo->usOperation = DO_DEFAULT;
|
---|
633 | pDInfo->hwndSource = hwnd;
|
---|
634 |
|
---|
635 | memset(&ditem, 0, sizeof(DRAGITEM));
|
---|
636 | ditem.hwndItem = hwnd;
|
---|
637 | ditem.ulItemID = 1;
|
---|
638 | ditem.hstrType = DrgAddStrHandle(DRT_UNKNOWN);
|
---|
639 | ditem.hstrRMF = DrgAddStrHandle(DRMDRF_LBOX);
|
---|
640 | ditem.hstrContainerName = DrgAddStrHandle("");
|
---|
641 | ditem.hstrSourceName = DrgAddStrHandle("");
|
---|
642 | ditem.hstrTargetName = DrgAddStrHandle("");
|
---|
643 | // ditem.fsControl = 0;
|
---|
644 | ditem.fsSupportedOps = DO_MOVEABLE;
|
---|
645 |
|
---|
646 | memset(&dimage, 0, sizeof(DRAGIMAGE));
|
---|
647 | dimage.cb = sizeof(DRAGIMAGE);
|
---|
648 | dimage.hImage = hptrFile;
|
---|
649 | dimage.cptl = 0;
|
---|
650 | dimage.fl = DRG_ICON;
|
---|
651 | dimage.sizlStretch.cx = 32;
|
---|
652 | dimage.sizlStretch.cy = 32;
|
---|
653 | dimage.cxOffset = -16;
|
---|
654 | dimage.cyOffset = 0;
|
---|
655 | DrgSetDragitem(pDInfo, &ditem, sizeof(DRAGITEM), 0); /* Index of DRAGITEM */
|
---|
656 | hwndDrop = DrgDrag(hwnd, pDInfo, &dimage, 1, /* One DRAGIMAGE */
|
---|
657 | VK_ENDDRAG, NULL);
|
---|
658 | if (!hwndDrop)
|
---|
659 | Win_Error(hwnd, hwnd, pszSrcFile, __LINE__, "DrgDrag");
|
---|
660 |
|
---|
661 | DrgFreeDraginfo(pDInfo);
|
---|
662 | // WinSetWindowPos(hwnd,HWND_TOP,0,0,0,0,SWP_ACTIVATE);
|
---|
663 | }
|
---|
664 | }
|
---|
665 | break;
|
---|
666 | }
|
---|
667 |
|
---|
668 | case DM_DRAGOVER:
|
---|
669 | ok = FALSE;
|
---|
670 | if (!emphasized) {
|
---|
671 | POINTL ptl;
|
---|
672 | POINTL ptl2;
|
---|
673 |
|
---|
674 | emphasized = TRUE;
|
---|
675 | ptl.x = SHORT1FROMMP(mp2);
|
---|
676 | ptl.y = SHORT2FROMMP(mp2);
|
---|
677 | ptl2 = ptl;
|
---|
678 | WinMapWindowPoints(HWND_DESKTOP, hwnd, &ptl2, 1);
|
---|
679 | // fprintf(stderr, "DRAGOVER mapped x y %d %d to %d %d\n", ptl.x, ptl.y, ptl2.x, ptl2.y);
|
---|
680 | WinPostMsg(hwnd, WM_BUTTON1CLICK,
|
---|
681 | MPFROM2SHORT((SHORT) ptl2.x, (SHORT) ptl2.y),
|
---|
682 | MPFROM2SHORT(HT_NORMAL, KC_NONE));
|
---|
683 | // fprintf(stderr, "DRAGOVER posted 0x%x WM_BUTTON1CLICK x y %d %d\n", hwnd, ptl2.x, ptl2.y);
|
---|
684 | }
|
---|
685 | pDInfo = (PDRAGINFO) mp1; /* Get DRAGINFO pointer */
|
---|
686 | if (pDInfo) {
|
---|
687 | if (!DrgAccessDraginfo(pDInfo)) {
|
---|
688 | Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
|
---|
689 | "DrgAccessDraginfo");
|
---|
690 | }
|
---|
691 | else {
|
---|
692 | pDItem = DrgQueryDragitemPtr(pDInfo, 0);
|
---|
693 | /* Check valid rendering mechanisms and data format */
|
---|
694 | ok = DrgVerifyRMF(pDItem, DRM_LBOX, NULL);
|
---|
695 | DrgFreeDraginfo(pDInfo);
|
---|
696 | }
|
---|
697 | }
|
---|
698 | return ok ? MRFROM2SHORT(DOR_DROP, DO_MOVE) :
|
---|
699 | MRFROM2SHORT(DOR_NEVERDROP, 0);
|
---|
700 |
|
---|
701 | case DM_DRAGLEAVE:
|
---|
702 | if (emphasized) {
|
---|
703 | emphasized = FALSE;
|
---|
704 | // fixme to draw listbox item emphasized
|
---|
705 | // DrawTargetEmphasis(hwnd, emphasized);
|
---|
706 | // fprintf(stderr, "DRAGLEAVE\n");
|
---|
707 | fflush(stderr);
|
---|
708 | }
|
---|
709 | return 0;
|
---|
710 |
|
---|
711 | case DM_DROPHELP:
|
---|
712 | DropHelp(mp1, mp2, hwnd, "fixme to give some help");
|
---|
713 | return 0;
|
---|
714 |
|
---|
715 | case DM_DROP:
|
---|
716 | ok = FALSE;
|
---|
717 | if (emphasized) {
|
---|
718 | emphasized = FALSE;
|
---|
719 | // DrawTargetEmphasis(hwnd, emphasized);
|
---|
720 | }
|
---|
721 | pDInfo = (PDRAGINFO) mp1; /* Get DRAGINFO pointer */
|
---|
722 | if (pDInfo) {
|
---|
723 | if (!DrgAccessDraginfo(pDInfo)) {
|
---|
724 | Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
|
---|
725 | "DrgAccessDraginfo");
|
---|
726 | }
|
---|
727 | else {
|
---|
728 | pDItem = DrgQueryDragitemPtr(pDInfo, 0);
|
---|
729 | if (!pDItem)
|
---|
730 | Win_Error(hwnd, hwnd, pszSrcFile, __LINE__, "DM_DROP");
|
---|
731 | /* Check valid rendering mechanisms and data */
|
---|
732 | ok = DrgVerifyRMF(pDItem, DRM_LBOX, NULL)
|
---|
733 | && ~pDItem->fsControl & DC_PREPARE;
|
---|
734 | if (ok) {
|
---|
735 | // ret = FullDrgName(pDItem,buffer,buflen);
|
---|
736 | /* note: targetfail is returned to source for all items */
|
---|
737 | DrgSendTransferMsg(pDInfo->hwndSource, DM_ENDCONVERSATION,
|
---|
738 | MPFROMLONG(pDItem->ulItemID),
|
---|
739 | MPFROMLONG(DMFL_TARGETSUCCESSFUL));
|
---|
740 | }
|
---|
741 | FreeDragInfoData(hwnd, pDInfo);
|
---|
742 | }
|
---|
743 | }
|
---|
744 | return 0;
|
---|
745 | } // switch
|
---|
746 | return pfnOldProc ? pfnOldProc(hwnd, msg, mp1, mp2) :
|
---|
747 | WinDefWindowProc(hwnd, msg, mp1, mp2);
|
---|
748 | }
|
---|
749 |
|
---|
750 | //=== SBoxDlgProc() Select archiver to use or edit, supports list reorder too ===
|
---|
751 |
|
---|
752 | static PSZ pszCantFindMsg = "Can't find item %d";
|
---|
753 |
|
---|
754 | MRESULT EXPENTRY SBoxDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
|
---|
755 | {
|
---|
756 | ARC_TYPE **ppatReturn; // Where to return selected archiver
|
---|
757 | ARC_TYPE *pat;
|
---|
758 | SHORT sSelect;
|
---|
759 | SHORT sItemCount;
|
---|
760 | CHAR szItemText[256];
|
---|
761 | CHAR szPCItemText[256]; // Parent or child item text
|
---|
762 | SHORT i;
|
---|
763 | BOOL fShowAll;
|
---|
764 |
|
---|
765 | static SHORT sLastSelect = LIT_NONE;
|
---|
766 |
|
---|
767 | switch (msg) {
|
---|
768 | case WM_INITDLG:
|
---|
769 | if (!arcsigsloaded)
|
---|
770 | load_archivers();
|
---|
771 | if (!(ARC_TYPE **) mp2) {
|
---|
772 | Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
|
---|
773 | WinDismissDlg(hwnd, 0);
|
---|
774 | break;
|
---|
775 | }
|
---|
776 | /* Passed arg points to where to return selected archiver definition
|
---|
777 | * On input arg value controls selection list content
|
---|
778 | * If non-NULL, dup names are suppressed
|
---|
779 | * If NULL, all definitions are shown
|
---|
780 | */
|
---|
781 | ppatReturn = (ARC_TYPE **) mp2;
|
---|
782 | fShowAll = *ppatReturn == NULL;
|
---|
783 | if (*ppatReturn)
|
---|
784 | *ppatReturn = arcsighead; // Preset to first
|
---|
785 | WinSetWindowPtr(hwnd, QWL_USER, (PVOID) ppatReturn);
|
---|
786 | fill_listbox(hwnd, fShowAll, sLastSelect);
|
---|
787 |
|
---|
788 | #ifdef TEST_DRAG // fixme
|
---|
789 | {
|
---|
790 | HWND hwnd2 = WinWindowFromID(hwnd, ASEL_LISTBOX);
|
---|
791 | PFNWP pfn = WinSubclassWindow(hwnd2,
|
---|
792 | SDlgListboxSubclassProc);
|
---|
793 |
|
---|
794 | WinSetWindowPtr(hwnd2, QWL_USER, (PVOID) pfn);
|
---|
795 | }
|
---|
796 | #endif // TEST_DRAG fixme
|
---|
797 |
|
---|
798 | break;
|
---|
799 |
|
---|
800 | case WM_COMMAND:
|
---|
801 | ppatReturn = (ARC_TYPE **) WinQueryWindowPtr(hwnd, QWL_USER);
|
---|
802 | switch (SHORT1FROMMP(mp1)) {
|
---|
803 | case DID_OK:
|
---|
804 | sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
|
---|
805 | ASEL_LISTBOX,
|
---|
806 | LM_QUERYSELECTION,
|
---|
807 | MPFROMSHORT(LIT_FIRST), MPVOID);
|
---|
808 | if (sSelect == LIT_NONE) {
|
---|
809 | Runtime_Error(pszSrcFile, __LINE__, "list empty");
|
---|
810 | return 0;
|
---|
811 | }
|
---|
812 | pat = arcsighead;
|
---|
813 | if (*ppatReturn) {
|
---|
814 | // If dups hidden, find archiver with matching id
|
---|
815 | *szItemText = 0;
|
---|
816 | WinSendDlgItemMsg(hwnd, ASEL_LISTBOX, LM_QUERYITEMTEXT,
|
---|
817 | MPFROM2SHORT(sSelect, 255), MPFROMP(szItemText));
|
---|
818 | if (!*szItemText)
|
---|
819 | pat = NULL;
|
---|
820 | else {
|
---|
821 | for (; pat; pat = pat->next) {
|
---|
822 | if (pat->id && !strcmp(szItemText, pat->id))
|
---|
823 | break; // Found it
|
---|
824 | }
|
---|
825 | }
|
---|
826 | }
|
---|
827 | else {
|
---|
828 | // If dups not hidden, lookup by count
|
---|
829 | for (i = 0; pat && i < sSelect; i++, pat = pat->next) ; // Scan
|
---|
830 | }
|
---|
831 | if (pat && (!*ppatReturn || (pat->id && pat->extract && pat->create))) {
|
---|
832 | *ppatReturn = pat;
|
---|
833 | }
|
---|
834 | else {
|
---|
835 | Runtime_Error(pszSrcFile, __LINE__, "no match");
|
---|
836 | // Refuse to select
|
---|
837 | WinSendDlgItemMsg(hwnd, ASEL_LISTBOX, LM_SELECTITEM,
|
---|
838 | MPFROMSHORT(LIT_NONE), FALSE);
|
---|
839 | return 0;
|
---|
840 | }
|
---|
841 | sLastSelect = sSelect;
|
---|
842 | WinDismissDlg(hwnd, TRUE);
|
---|
843 | return 0;
|
---|
844 |
|
---|
845 | case DID_CANCEL:
|
---|
846 | if (arcsigsmodified) {
|
---|
847 | if (saymsg(MB_YESNO,
|
---|
848 | hwnd,
|
---|
849 | GetPString(IDS_ADCHANGESINMEMTEXT),
|
---|
850 | GetPString(IDS_ADREWRITETEXT), NullStr) == MBID_YES) {
|
---|
851 | PSZ ab2 = searchpath(GetPString(IDS_ARCHIVERBB2)); // Rewrite without prompting
|
---|
852 |
|
---|
853 | rewrite_archiverbb2(ab2);
|
---|
854 | }
|
---|
855 | }
|
---|
856 | sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
|
---|
857 | ASEL_LISTBOX,
|
---|
858 | LM_QUERYSELECTION,
|
---|
859 | MPFROMSHORT(LIT_FIRST), MPVOID);
|
---|
860 | if (sSelect != LIT_NONE)
|
---|
861 | sLastSelect = sSelect;
|
---|
862 | *ppatReturn = NULL;
|
---|
863 | PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID); // fixme to understand why needed
|
---|
864 | return 0;
|
---|
865 |
|
---|
866 | case ASEL_PB_ADD:
|
---|
867 | sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
|
---|
868 | ASEL_LISTBOX,
|
---|
869 | LM_QUERYSELECTION,
|
---|
870 | MPFROMSHORT(LIT_FIRST), MPVOID);
|
---|
871 | if (sSelect != LIT_NONE) {
|
---|
872 | ARCDUMP ad;
|
---|
873 |
|
---|
874 | memset(&ad, 0, sizeof(ARCDUMP));
|
---|
875 | ad.info = xmallocz(sizeof(ARC_TYPE), pszSrcFile, __LINE__);
|
---|
876 | if (ad.info) {
|
---|
877 | if (!WinDlgBox(HWND_DESKTOP,
|
---|
878 | hwnd,
|
---|
879 | ArcReviewDlgProc,
|
---|
880 | FM3ModHandle, AD_FRAME, MPFROMP(&ad))) {
|
---|
881 | free(ad.info);
|
---|
882 | }
|
---|
883 | else {
|
---|
884 | // Find self - assume all archivers listed since we are editing
|
---|
885 | for (i = 0, pat = arcsighead; pat && i < sSelect; pat = pat->next, i++) ; // Find self
|
---|
886 |
|
---|
887 | if (!pat) {
|
---|
888 | if (arcsighead)
|
---|
889 | Runtime_Error(pszSrcFile, __LINE__, pszCantFindMsg, sSelect);
|
---|
890 | else
|
---|
891 | arcsighead = ad.info;
|
---|
892 | }
|
---|
893 | else {
|
---|
894 | // Insert before
|
---|
895 | if (pat->prev) {
|
---|
896 | ad.info->next = pat;
|
---|
897 | ad.info->prev = pat->prev;
|
---|
898 | pat->prev->next = ad.info;
|
---|
899 | pat->prev = ad.info;
|
---|
900 | }
|
---|
901 | else {
|
---|
902 | arcsighead = ad.info;
|
---|
903 | ad.info->next = pat;
|
---|
904 | pat->prev = ad.info;
|
---|
905 | }
|
---|
906 | }
|
---|
907 | WinSendDlgItemMsg(hwnd, ASEL_LISTBOX, LM_INSERTITEM,
|
---|
908 | MPFROM2SHORT(sSelect, 0),
|
---|
909 | MPFROMP(ad.info->id ? ad.info->id : "?"));
|
---|
910 | WinSendDlgItemMsg(hwnd, ASEL_LISTBOX, LM_SELECTITEM,
|
---|
911 | MPFROMSHORT(sSelect - 1), MPFROMSHORT(TRUE));
|
---|
912 | arcsigsmodified = TRUE;
|
---|
913 | }
|
---|
914 | }
|
---|
915 | }
|
---|
916 | return 0;
|
---|
917 | case ASEL_PB_DELETE:
|
---|
918 | sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
|
---|
919 | ASEL_LISTBOX,
|
---|
920 | LM_QUERYSELECTION,
|
---|
921 | MPFROMSHORT(LIT_FIRST), MPVOID);
|
---|
922 | if (sSelect != LIT_NONE) {
|
---|
923 | // Find self - assume all archivers listed since we are editing
|
---|
924 | for (i = 0, pat = arcsighead; pat && i < sSelect; pat = pat->next, i++) ; // Find self
|
---|
925 |
|
---|
926 | if (!pat)
|
---|
927 | Runtime_Error(pszSrcFile, __LINE__, pszCantFindMsg, sSelect);
|
---|
928 | else {
|
---|
929 | // Delete current
|
---|
930 | if (pat->prev) {
|
---|
931 | pat->prev->next = pat->next;
|
---|
932 | if (pat->next)
|
---|
933 | pat->next->prev = pat->prev;
|
---|
934 | }
|
---|
935 | else {
|
---|
936 | arcsighead = pat->next;
|
---|
937 | if (pat->next)
|
---|
938 | pat->next->prev = pat->prev;
|
---|
939 | }
|
---|
940 | }
|
---|
941 | free_arc_type(pat);
|
---|
942 | arcsigsmodified = TRUE;
|
---|
943 | WinSendDlgItemMsg(hwnd, ASEL_LISTBOX, LM_DELETEITEM,
|
---|
944 | MPFROM2SHORT(sSelect, 0), MPVOID);
|
---|
945 | sItemCount =
|
---|
946 | (SHORT) WinSendDlgItemMsg(hwnd, ASEL_LISTBOX, LM_QUERYITEMCOUNT,
|
---|
947 | MPVOID, MPVOID);
|
---|
948 | if (sSelect >= sItemCount)
|
---|
949 | sSelect--;
|
---|
950 | if (sSelect >= 0) {
|
---|
951 | WinSendDlgItemMsg(hwnd, ASEL_LISTBOX, LM_SELECTITEM,
|
---|
952 | MPFROMSHORT(sSelect), MPFROMSHORT(TRUE));
|
---|
953 | }
|
---|
954 | }
|
---|
955 | return 0;
|
---|
956 | case ASEL_PB_UP:
|
---|
957 | sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
|
---|
958 | ASEL_LISTBOX,
|
---|
959 | LM_QUERYSELECTION,
|
---|
960 | MPFROMSHORT(LIT_FIRST), MPVOID);
|
---|
961 | if (sSelect != LIT_NONE && sSelect > 0) {
|
---|
962 | // Find self - assume all archivers listed since we are editing
|
---|
963 | for (i = 0, pat = arcsighead; pat && i < sSelect; pat = pat->next, i++) ; // Find self
|
---|
964 | if (!pat || !pat->prev)
|
---|
965 | Runtime_Error(pszSrcFile, __LINE__, pszCantFindMsg, sSelect);
|
---|
966 | else {
|
---|
967 | ARC_TYPE *patGDad;
|
---|
968 | ARC_TYPE *patDad;
|
---|
969 | ARC_TYPE *patChild;
|
---|
970 |
|
---|
971 | patChild = pat->next;
|
---|
972 | patDad = pat->prev;
|
---|
973 | patGDad = patDad->prev;
|
---|
974 | patDad->next = patChild;
|
---|
975 | if (patChild)
|
---|
976 | patChild->prev = patDad;
|
---|
977 | patDad->prev = pat;
|
---|
978 | pat->next = patDad;
|
---|
979 | if (patGDad) {
|
---|
980 | patGDad->next = pat;
|
---|
981 | pat->prev = patGDad;
|
---|
982 | }
|
---|
983 | else {
|
---|
984 | arcsighead = pat;
|
---|
985 | pat->prev = NULL;
|
---|
986 | }
|
---|
987 |
|
---|
988 | WinSendDlgItemMsg(hwnd, ASEL_LISTBOX, LM_QUERYITEMTEXT,
|
---|
989 | MPFROM2SHORT(sSelect, 255), MPFROMP(szItemText));
|
---|
990 | WinSendDlgItemMsg(hwnd, ASEL_LISTBOX, LM_QUERYITEMTEXT,
|
---|
991 | MPFROM2SHORT(sSelect - 1, 255),
|
---|
992 | MPFROMP(szPCItemText));
|
---|
993 | WinSendDlgItemMsg(hwnd, ASEL_LISTBOX, LM_SETITEMTEXT,
|
---|
994 | MPFROMSHORT(sSelect), MPFROMP(szPCItemText));
|
---|
995 | WinSendDlgItemMsg(hwnd, ASEL_LISTBOX, LM_SETITEMTEXT,
|
---|
996 | MPFROMSHORT(sSelect - 1), MPFROMP(szItemText));
|
---|
997 | WinSendDlgItemMsg(hwnd, ASEL_LISTBOX, LM_SELECTITEM,
|
---|
998 | MPFROMSHORT(sSelect - 1), MPFROMSHORT(TRUE));
|
---|
999 | arcsigsmodified = TRUE;
|
---|
1000 | }
|
---|
1001 | }
|
---|
1002 | return 0;
|
---|
1003 | case ASEL_PB_DOWN:
|
---|
1004 | sSelect =
|
---|
1005 | (SHORT) WinSendDlgItemMsg(hwnd, ASEL_LISTBOX, LM_QUERYSELECTION,
|
---|
1006 | MPFROMSHORT(LIT_FIRST), MPVOID);
|
---|
1007 | sItemCount =
|
---|
1008 | (SHORT) WinSendDlgItemMsg(hwnd, ASEL_LISTBOX, LM_QUERYITEMCOUNT,
|
---|
1009 | MPVOID, MPVOID);
|
---|
1010 | if (sSelect != LIT_NONE && sSelect < sItemCount - 1) {
|
---|
1011 | // Find self - assume all archivers listed since we are editing
|
---|
1012 | for (i = 0, pat = arcsighead; pat && i < sSelect; pat = pat->next, i++) ; // Find self
|
---|
1013 | if (!pat || !pat->next)
|
---|
1014 | Runtime_Error(pszSrcFile, __LINE__, "Can't find item %d of %d",
|
---|
1015 | sSelect, sItemCount);
|
---|
1016 | else {
|
---|
1017 | ARC_TYPE *patDad;
|
---|
1018 | ARC_TYPE *patChild;
|
---|
1019 |
|
---|
1020 | patDad = pat->prev;
|
---|
1021 | patChild = pat->next;
|
---|
1022 | pat->next = patChild->next;
|
---|
1023 | patChild->next = pat;
|
---|
1024 | pat->prev = patChild;
|
---|
1025 | patChild->prev = patDad;
|
---|
1026 | if (patDad) {
|
---|
1027 | patDad->next = patChild;
|
---|
1028 | patChild->prev = patDad;
|
---|
1029 | }
|
---|
1030 | else {
|
---|
1031 | arcsighead = patChild;
|
---|
1032 | patChild->prev = NULL;
|
---|
1033 | }
|
---|
1034 |
|
---|
1035 | WinSendDlgItemMsg(hwnd, ASEL_LISTBOX, LM_QUERYITEMTEXT,
|
---|
1036 | MPFROM2SHORT(sSelect, 255), MPFROMP(szItemText));
|
---|
1037 | WinSendDlgItemMsg(hwnd, ASEL_LISTBOX, LM_QUERYITEMTEXT,
|
---|
1038 | MPFROM2SHORT(sSelect + 1, 255),
|
---|
1039 | MPFROMP(szPCItemText));
|
---|
1040 | WinSendDlgItemMsg(hwnd, ASEL_LISTBOX, LM_SETITEMTEXT,
|
---|
1041 | MPFROMSHORT(sSelect), MPFROMP(szPCItemText));
|
---|
1042 | WinSendDlgItemMsg(hwnd, ASEL_LISTBOX, LM_SETITEMTEXT,
|
---|
1043 | MPFROMSHORT(sSelect + 1), MPFROMP(szItemText));
|
---|
1044 | WinSendDlgItemMsg(hwnd, ASEL_LISTBOX, LM_SELECTITEM,
|
---|
1045 | MPFROMSHORT(sSelect + 1), MPFROMSHORT(TRUE));
|
---|
1046 | arcsigsmodified = TRUE;
|
---|
1047 | }
|
---|
1048 | }
|
---|
1049 | return 0;
|
---|
1050 |
|
---|
1051 | case ASEL_PB_REVERT:
|
---|
1052 | // Reload without checking in case changed outside
|
---|
1053 | sSelect =
|
---|
1054 | (SHORT) WinSendDlgItemMsg(hwnd, ASEL_LISTBOX, LM_QUERYSELECTION,
|
---|
1055 | MPFROMSHORT(LIT_FIRST), MPVOID);
|
---|
1056 | load_archivers();
|
---|
1057 | fill_listbox(hwnd, TRUE, sSelect);
|
---|
1058 | return 0;
|
---|
1059 |
|
---|
1060 | case IDM_HELP:
|
---|
1061 | if (hwndHelp) {
|
---|
1062 | WinSendMsg(hwndHelp, HM_DISPLAY_HELP, MPFROM2SHORT(HELP_EDITARC, 0), // fixme to be HELP_SELARC
|
---|
1063 | MPFROMSHORT(HM_RESOURCEID));
|
---|
1064 | }
|
---|
1065 | }
|
---|
1066 | return 0; // WM_COMMAND
|
---|
1067 |
|
---|
1068 | case WM_CONTROL:
|
---|
1069 | if (SHORT1FROMMP(mp1) == ASEL_LISTBOX && SHORT2FROMMP(mp1) == LN_ENTER)
|
---|
1070 | PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(DID_OK, 0), MPVOID);
|
---|
1071 | return 0;
|
---|
1072 |
|
---|
1073 | case WM_CLOSE:
|
---|
1074 | WinDismissDlg(hwnd, FALSE);
|
---|
1075 | return 0;
|
---|
1076 |
|
---|
1077 | default:
|
---|
1078 | break;
|
---|
1079 | }
|
---|
1080 | return WinDefDlgProc(hwnd, msg, mp1, mp2);
|
---|
1081 | }
|
---|
1082 |
|
---|
1083 | /*
|
---|
1084 | see archiver.tmp
|
---|
1085 | 02-08-96 23:55 1
|
---|
1086 | 8 Feb 96 23:55:32 2
|
---|
1087 | 8 Feb 96 11:55p 3
|
---|
1088 | 96-02-08 23:55:32 4
|
---|
1089 | 31-02-98 23:55 5
|
---|
1090 | */
|
---|
1091 |
|
---|
1092 | BOOL ArcDateTime(CHAR * dt, INT type, CDATE * cdate, CTIME * ctime)
|
---|
1093 | {
|
---|
1094 | INT x;
|
---|
1095 | BOOL ret = FALSE;
|
---|
1096 | CHAR *p, *pp, *pd;
|
---|
1097 |
|
---|
1098 | if (dt && cdate && ctime) {
|
---|
1099 | memset(cdate, 0, sizeof(CDATE));
|
---|
1100 | memset(ctime, 0, sizeof(CTIME));
|
---|
1101 | if (type) {
|
---|
1102 | p = dt;
|
---|
1103 | while (*p && *p == ' ')
|
---|
1104 | p++;
|
---|
1105 | pd = dt;
|
---|
1106 | switch (type) {
|
---|
1107 | case 1:
|
---|
1108 | cdate->month = atoi(pd);
|
---|
1109 | p = to_delim(pd, "-/.");
|
---|
1110 | if (p) {
|
---|
1111 | p++;
|
---|
1112 | cdate->day = atoi(p);
|
---|
1113 | pd = p;
|
---|
1114 | p = to_delim(pd, "-/.");
|
---|
1115 | if (p) {
|
---|
1116 | p++;
|
---|
1117 | cdate->year = atoi(p);
|
---|
1118 | if (cdate->year > 80 && cdate->year < 1900)
|
---|
1119 | cdate->year += 1900;
|
---|
1120 | else if (cdate->year < 1900)
|
---|
1121 | cdate->year += 2000;
|
---|
1122 | ret = TRUE;
|
---|
1123 | p = strchr(p, ' ');
|
---|
1124 | if (p) {
|
---|
1125 | while (*p && *p == ' ')
|
---|
1126 | p++;
|
---|
1127 | ctime->hours = atoi(p);
|
---|
1128 | p = to_delim(pd, ":.");
|
---|
1129 | if (p) {
|
---|
1130 | p++;
|
---|
1131 | ctime->minutes = atoi(p);
|
---|
1132 | p = to_delim(pd, ":.");
|
---|
1133 | if (p) {
|
---|
1134 | p++;
|
---|
1135 | ctime->seconds = atoi(p);
|
---|
1136 | }
|
---|
1137 | }
|
---|
1138 | }
|
---|
1139 | }
|
---|
1140 | }
|
---|
1141 | break;
|
---|
1142 |
|
---|
1143 | case 2:
|
---|
1144 | cdate->day = atoi(p);
|
---|
1145 | p = strchr(p, ' ');
|
---|
1146 | if (p) {
|
---|
1147 | p++;
|
---|
1148 | for (x = 0; x < 12; x++) {
|
---|
1149 | if (!strnicmp(p, GetPString(IDS_JANUARY + x), 3))
|
---|
1150 | break;
|
---|
1151 | }
|
---|
1152 | if (x < 12) {
|
---|
1153 | cdate->month = x;
|
---|
1154 | p = strchr(p, ' ');
|
---|
1155 | if (p) {
|
---|
1156 | p++;
|
---|
1157 | cdate->year = atoi(p);
|
---|
1158 | if (cdate->year > 80 && cdate->year < 1900)
|
---|
1159 | cdate->year += 1900;
|
---|
1160 | else if (cdate->year < 1900)
|
---|
1161 | cdate->year += 2000;
|
---|
1162 | ret = TRUE;
|
---|
1163 | p = strchr(p, ' ');
|
---|
1164 | if (p) {
|
---|
1165 | while (*p && *p == ' ')
|
---|
1166 | p++;
|
---|
1167 | ctime->hours = atoi(p);
|
---|
1168 | p = to_delim(pd, ":.");
|
---|
1169 | if (p) {
|
---|
1170 | p++;
|
---|
1171 | ctime->minutes = atoi(p);
|
---|
1172 | p = to_delim(pd, ":.");
|
---|
1173 | if (p) {
|
---|
1174 | p++;
|
---|
1175 | ctime->seconds = atoi(p);
|
---|
1176 | }
|
---|
1177 | }
|
---|
1178 | }
|
---|
1179 | }
|
---|
1180 | }
|
---|
1181 | }
|
---|
1182 | break;
|
---|
1183 |
|
---|
1184 | case 3:
|
---|
1185 | cdate->day = atoi(p);
|
---|
1186 | p = strchr(p, ' ');
|
---|
1187 | if (p) {
|
---|
1188 | p++;
|
---|
1189 | for (x = 0; x < 12; x++) {
|
---|
1190 | if (!strnicmp(p, GetPString(IDS_JANUARY + x), 3))
|
---|
1191 | break;
|
---|
1192 | }
|
---|
1193 | if (x < 12) {
|
---|
1194 | cdate->month = x;
|
---|
1195 | p = strchr(p, ' ');
|
---|
1196 | if (p) {
|
---|
1197 | p++;
|
---|
1198 | cdate->year = atoi(p);
|
---|
1199 | if (cdate->year > 80 && cdate->year < 1900)
|
---|
1200 | cdate->year += 1900;
|
---|
1201 | else if (cdate->year < 1900)
|
---|
1202 | cdate->year += 2000;
|
---|
1203 | ret = TRUE;
|
---|
1204 | p = strchr(p, ' ');
|
---|
1205 | if (p) {
|
---|
1206 | while (*p && *p == ' ')
|
---|
1207 | p++;
|
---|
1208 | ctime->hours = atoi(p);
|
---|
1209 | p = to_delim(pd, ":.");
|
---|
1210 | if (p) {
|
---|
1211 | p++;
|
---|
1212 | pp = p;
|
---|
1213 | ctime->minutes = atoi(p);
|
---|
1214 | p = to_delim(pd, ":.");
|
---|
1215 | if (p) {
|
---|
1216 | p++;
|
---|
1217 | ctime->seconds = atoi(p);
|
---|
1218 | p += 2;
|
---|
1219 | if (toupper(*p) == 'P')
|
---|
1220 | ctime->hours += 12;
|
---|
1221 | }
|
---|
1222 | else {
|
---|
1223 | p = pp;
|
---|
1224 | p += 2;
|
---|
1225 | if (toupper(*p) == 'P')
|
---|
1226 | ctime->hours += 12;
|
---|
1227 | }
|
---|
1228 | }
|
---|
1229 | }
|
---|
1230 | }
|
---|
1231 | }
|
---|
1232 | }
|
---|
1233 | break;
|
---|
1234 |
|
---|
1235 | case 4:
|
---|
1236 | cdate->year = atoi(p);
|
---|
1237 | if (cdate->year > 80 && cdate->year < 1900)
|
---|
1238 | cdate->year += 1900;
|
---|
1239 | else if (cdate->year < 1900)
|
---|
1240 | cdate->year += 2000;
|
---|
1241 | p = to_delim(pd, "-/.");
|
---|
1242 | if (p) {
|
---|
1243 | p++;
|
---|
1244 | cdate->month = atoi(p);
|
---|
1245 | pd = p;
|
---|
1246 | p = to_delim(pd, "-/.");
|
---|
1247 | if (p) {
|
---|
1248 | p++;
|
---|
1249 | cdate->day = atoi(p);
|
---|
1250 | ret = TRUE;
|
---|
1251 | p = strchr(p, ' ');
|
---|
1252 | if (p) {
|
---|
1253 | while (*p && *p == ' ')
|
---|
1254 | p++;
|
---|
1255 | ctime->hours = atoi(p);
|
---|
1256 | p = to_delim(pd, ":.");
|
---|
1257 | if (p) {
|
---|
1258 | p++;
|
---|
1259 | ctime->minutes = atoi(p);
|
---|
1260 | p = to_delim(pd, ":.");
|
---|
1261 | if (p) {
|
---|
1262 | p++;
|
---|
1263 | ctime->seconds = atoi(p);
|
---|
1264 | }
|
---|
1265 | }
|
---|
1266 | }
|
---|
1267 | }
|
---|
1268 | }
|
---|
1269 | break;
|
---|
1270 |
|
---|
1271 | case 5:
|
---|
1272 | cdate->day = atoi(pd);
|
---|
1273 | p = to_delim(pd, "-/.");
|
---|
1274 | if (p) {
|
---|
1275 | p++;
|
---|
1276 | cdate->month = atoi(p);
|
---|
1277 | pd = p;
|
---|
1278 | p = to_delim(pd, "-/.");
|
---|
1279 | if (p) {
|
---|
1280 | p++;
|
---|
1281 | cdate->year = atoi(p);
|
---|
1282 | if (cdate->year > 80 && cdate->year < 1900)
|
---|
1283 | cdate->year += 1900;
|
---|
1284 | else if (cdate->year < 1900)
|
---|
1285 | cdate->year += 2000;
|
---|
1286 | ret = TRUE;
|
---|
1287 | p = strchr(p, ' ');
|
---|
1288 | if (p) {
|
---|
1289 | while (*p && *p == ' ')
|
---|
1290 | p++;
|
---|
1291 | ctime->hours = atoi(p);
|
---|
1292 | p = to_delim(pd, ":.");
|
---|
1293 | if (p) {
|
---|
1294 | p++;
|
---|
1295 | ctime->minutes = atoi(p);
|
---|
1296 | p = to_delim(pd, ":.");
|
---|
1297 | if (p) {
|
---|
1298 | p++;
|
---|
1299 | ctime->seconds = atoi(p);
|
---|
1300 | }
|
---|
1301 | }
|
---|
1302 | }
|
---|
1303 | }
|
---|
1304 | }
|
---|
1305 | break;
|
---|
1306 |
|
---|
1307 | default:
|
---|
1308 | break;
|
---|
1309 | }
|
---|
1310 | }
|
---|
1311 | }
|
---|
1312 | return ret;
|
---|
1313 | }
|
---|
1314 |
|
---|
1315 | #pragma alloc_text(MISC9,quick_find_type,find_type)
|
---|
1316 | #pragma alloc_text(AVL,load_archivers, get_line_strip_comments, get_line_strip_white, free_archivers)
|
---|
1317 | #pragma alloc_text(FMARCHIVE,SBoxDlgProc,SDlgListboxSubclassProc)
|
---|
1318 | #pragma alloc_text(ARCCNRS,ArcDateTime)
|
---|