source: trunk/dll/avl.c@ 1616

Last change on this file since 1616 was 1616, checked in by Gregg Young, 14 years ago

Updated a*.c files to Doxygen commenting style. (Ticket 55)

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