source: trunk/dll/assoc.c@ 832

Last change on this file since 832 was 832, checked in by Gregg Young, 18 years ago

Initial implimentation of a more flexible mask matching system to address multiple "." in file names

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 23.6 KB
Line 
1
2/**************************************************************************************
3
4 $Id: assoc.c 832 2007-09-05 02:09:22Z gyoung $
5
6 Copyright (c) 1993-98 M. Kimes
7 Copyright (c) 2004, 2007 Steven H.Levine
8
9 01 Aug 04 SHL Rework lstrip/rstrip usage
10 14 Jul 06 SHL Use Runtime_Error
11 29 Jul 06 SHL Use xfgets, xfgets_bstripcr
12 10 Sep 06 GKY Add Move to last, Okay adds if new, Replace Current in Listbox Dialog
13 19 Oct 06 GKY Rework replace logic
14 18 Feb 07 GKY Move error messages etc to string file
15 19 Apr 07 SHL Sync with AcceptOneDrop GetOneDrop mods
16 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
17
18**************************************************************************************/
19
20#define INCL_DOS
21#define INCL_WIN
22#define INCL_PM
23#define INCL_WINHOOKS
24
25#include <os2.h>
26#include <stdio.h>
27#include <stdlib.h>
28#include <string.h>
29#include <ctype.h>
30#include <share.h>
31#include "fm3dll.h"
32#include "fm3dlg.h"
33#include "fm3str.h"
34
35#pragma data_seg(DATA1)
36
37typedef struct
38{
39 CHAR mask[CCHMAXPATH];
40 CHAR cl[1001];
41 CHAR sig[CCHMAXPATH];
42 LONG offset;
43 ULONG flags;
44}
45ASSOC;
46
47typedef struct LINKASSOC
48{
49 CHAR *mask;
50 CHAR *cl;
51 CHAR *sig;
52 LONG offset;
53 ULONG flags;
54 struct LINKASSOC *prev;
55 struct LINKASSOC *next;
56}
57LINKASSOC;
58
59static LINKASSOC *asshead = NULL, *asstail = NULL;
60static BOOL assloaded = FALSE, replace = FALSE;
61
62static PSZ pszSrcFile = __FILE__;
63
64MRESULT EXPENTRY AssocTextProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
65{
66 PFNWP oldproc = (PFNWP) WinQueryWindowPtr(hwnd, QWL_USER);
67 static BOOL emphasized = FALSE;
68
69 switch (msg) {
70 case DM_DRAGOVER:
71 if (!emphasized) {
72 emphasized = TRUE;
73 DrawTargetEmphasis(hwnd, emphasized);
74 }
75 if (AcceptOneDrop(hwnd, mp1, mp2))
76 return MRFROM2SHORT(DOR_DROP, DO_MOVE);
77 return MRFROM2SHORT(DOR_NEVERDROP, 0);
78
79 case DM_DRAGLEAVE:
80 if (emphasized) {
81 emphasized = FALSE;
82 DrawTargetEmphasis(hwnd, emphasized);
83 }
84 break;
85
86 case DM_DROPHELP:
87 DropHelp(mp1, mp2, hwnd, GetPString(IDS_ASSOCDROPHELPTEXT));
88 return 0;
89
90 case DM_DROP:
91 {
92 char szFrom[CCHMAXPATH + 5];
93
94 if (emphasized) {
95 emphasized = FALSE;
96 DrawTargetEmphasis(hwnd, emphasized);
97 }
98 if (GetOneDrop(hwnd, mp1, mp2, szFrom, CCHMAXPATH)) {
99 strcat(szFrom, " %a");
100 WinSetWindowText(hwnd, szFrom);
101 }
102 }
103 return 0;
104 }
105 return (oldproc) ? oldproc(hwnd, msg, mp1, mp2) :
106 WinDefWindowProc(hwnd, msg, mp1, mp2);
107}
108
109VOID free_associations(VOID)
110{
111 LINKASSOC *info, *next;
112
113 info = asshead;
114 while (info) {
115 next = info->next;
116 free(info->mask);
117 free(info->cl);
118 if (info->sig)
119 free(info->sig);
120 free(info);
121 info = next;
122 }
123 asshead = asstail = NULL;
124}
125
126VOID load_associations(VOID)
127{
128 FILE *fp;
129 LINKASSOC *info;
130 CHAR cl[1024];
131 CHAR mask[CCHMAXPATH + 24];
132 CHAR sig[CCHMAXPATH + 24];
133 CHAR offset[72];
134 CHAR flags[72];
135
136 if (asshead)
137 free_associations();
138 assloaded = TRUE;
139 save_dir2(mask);
140 if (mask[strlen(mask) - 1] != '\\')
141 strcat(mask, "\\");
142 strcat(mask, "ASSOC.DAT");
143 fp = _fsopen(mask, "r", SH_DENYWR);
144 if (fp) {
145 while (!feof(fp)) {
146 if (!xfgets(mask, sizeof(mask), fp, pszSrcFile, __LINE__)) // fixme why +24?
147 break;
148 mask[CCHMAXPATH] = 0;
149 bstripcr(mask);
150 if (!*mask || *mask == ';')
151 continue;
152 if (!xfgets(cl, sizeof(cl), fp, pszSrcFile, __LINE__) ||
153 !xfgets(sig, CCHMAXPATH + 24, fp, pszSrcFile, __LINE__) ||
154 !xfgets(offset, sizeof(offset), fp, pszSrcFile, __LINE__) ||
155 !xfgets(flags, sizeof(flags), fp, pszSrcFile, __LINE__))
156 break; /* error! */
157 cl[1000] = 0;
158 bstripcr(cl);
159 sig[CCHMAXPATH] = 0;
160 bstripcr(sig);
161 offset[34] = 0;
162 bstripcr(offset);
163 flags[34] = 0;
164 bstripcr(flags);
165 if (!*cl)
166 continue;
167 info = xmallocz(sizeof(LINKASSOC), pszSrcFile, __LINE__);
168 if (info) {
169 info->cl = xstrdup(cl, pszSrcFile, __LINE__);
170 info->mask = xstrdup(mask, pszSrcFile, __LINE__);
171 if (*sig)
172 info->sig = xstrdup(sig, pszSrcFile, __LINE__);
173 info->offset = atol(offset);
174 info->flags = atol(flags);
175 if (!info->cl || !info->mask) {
176 if (info->cl)
177 free(info->cl);
178 if (info->mask)
179 free(info->mask);
180 free(info);
181 break;
182 }
183 if (!asshead)
184 asshead = info;
185 else {
186 asstail->next = info;
187 info->prev = asstail;
188 }
189 asstail = info;
190 }
191 }
192 fclose(fp);
193 }
194}
195
196VOID save_associations(VOID)
197{
198 LINKASSOC *info;
199 FILE *fp;
200 CHAR s[CCHMAXPATH + 14];
201
202 if (!assloaded || !asshead)
203 return;
204 info = asshead;
205#ifdef NEVER
206 while (info) {
207 next = info->next;
208 if (!strcmp("*", info->mask)) {
209 if (info != asshead) { /* already top record */
210 if (info->prev)
211 (info->prev)->next = info->next;
212 if (info->next)
213 (info->next)->prev = info->prev;
214 if (info == asstail)
215 asstail = info->prev;
216 info->next = asshead->next;
217 info->prev = NULL;
218 asshead = info;
219 }
220 }
221 info = next;
222 }
223#endif
224 save_dir2(s);
225 if (s[strlen(s) - 1] != '\\')
226 strcat(s, "\\");
227 strcat(s, "ASSOC.DAT");
228 fp = xfopen(s, "w", pszSrcFile, __LINE__);
229 if (fp) {
230 fputs(GetPString(IDS_ASSOCFILETEXT), fp);
231 info = asshead;
232 while (info) {
233 fprintf(fp,
234 ";\n%0.*s\n%0.1000s\n%0.*s\n%lu\n%lu\n",
235 CCHMAXPATH,
236 info->mask,
237 info->cl,
238 CCHMAXPATH,
239 (info->sig) ? info->sig : NullStr, info->offset, info->flags);
240 info = info->next;
241 }
242 fclose(fp);
243 }
244}
245
246LINKASSOC *add_association(ASSOC * addme)
247{
248 LINKASSOC *info;
249
250 if (addme && *addme->cl && *addme->mask) {
251 info = asshead;
252 while (info) {
253 if ((!replace) && (!stricmp(info->mask, addme->mask) &&
254 ((!info->sig && !*addme->sig) || (!replace) &&
255 (info->sig && !strcmp(addme->sig, info->sig)))))
256 return NULL;
257 info = info->next;
258 }
259 if (!info) {
260 info = xmallocz(sizeof(LINKASSOC), pszSrcFile, __LINE__);
261 if (info) {
262 info->cl = xstrdup(addme->cl, pszSrcFile, __LINE__);
263 info->mask = xstrdup(addme->mask, pszSrcFile, __LINE__);
264 if (*addme->sig)
265 info->sig = xstrdup(addme->sig, pszSrcFile, __LINE__);
266 if (addme->offset)
267 info->offset = addme->offset;
268 if (addme->flags)
269 info->flags = addme->flags;
270 if (!info->cl || !info->mask) {
271 if (info->cl)
272 free(info->cl);
273 if (info->mask)
274 free(info->mask);
275 free(info);
276 }
277 else {
278 if (!asshead) /* only item in list */
279 asshead = asstail = info;
280 else {
281 if (asstail) { /* place at tail */
282 asstail->next = info;
283 info->prev = asstail;
284 }
285 asstail = info;
286 }
287 return info;
288 }
289 }
290 }
291 }
292 return NULL;
293}
294
295BOOL kill_association(ASSOC * killme)
296{
297 LINKASSOC *info;
298
299 if (killme && *killme->mask) {
300 info = asshead;
301 while (info) {
302 if (!stricmp(info->mask, killme->mask) &&
303 info->offset == killme->offset &&
304 (((!info->sig || !*info->sig) && !*killme->sig) ||
305 (info->sig && !strcmp(killme->sig, info->sig)))) {
306 if (info == asshead) {
307 asshead = info->next;
308 if (info == asstail)
309 asstail = info->prev;
310 }
311 else {
312 if (info->next)
313 (info->next)->prev = info->prev;
314 if (info->prev)
315 (info->prev)->next = info->next;
316 if (info == asstail)
317 asstail = info->prev;
318 }
319 free(info->cl);
320 free(info->mask);
321 if (info->sig)
322 free(info->sig);
323 free(info);
324 return TRUE;
325 }
326 info = info->next;
327 }
328 }
329 return FALSE;
330}
331
332INT ExecAssociation(HWND hwnd, CHAR * datafile)
333{
334 CHAR *file, sig[CCHMAXPATH], sigl[CCHMAXPATH], mask[CCHMAXPATH], *p;
335 FILE *fp;
336 BOOL didmatch, exclude;
337 ULONG offset;
338 LINKASSOC *info;
339
340 if (!assloaded)
341 load_associations();
342 if (!asshead)
343 return -1;
344 if (!datafile || !*datafile)
345 return -1;
346 file = strrchr(datafile, '\\');
347 if (!file)
348 file = strrchr(datafile, ':');
349 if (file)
350 file++;
351 else
352 file = datafile;
353 info = asshead;
354 while (info) {
355 strcpy(mask, info->mask);
356 p = strtok(mask, ";");
357 while (p) {
358 if (*p == '/') {
359 p++;
360 exclude = TRUE;
361 }
362 else
363 exclude = FALSE;
364 if ((*p == '*') &&
365 !((p[strlen(p) - 1]) == '*'))
366 didmatch = wildcard((strchr(p, '\\') ||
367 strchr(p, ':')) ? datafile : file, p, FALSE);
368 else
369 didmatch = wildcard2((strchr(p, '\\') ||
370 strchr(p, ':')) ? datafile : file, p, FALSE);
371 if (exclude && didmatch)
372 didmatch = FALSE;
373 if (didmatch) {
374 if (info->sig && *info->sig) {
375 strcpy(sigl, info->sig);
376 literal(sigl);
377 fp = _fsopen(datafile, "rb", SH_DENYNO);
378 if (fp) {
379 if (info->offset < 0L) {
380 fseek(fp, 0L, SEEK_END);
381 offset = ftell(fp) + info->offset;
382 }
383 else
384 offset = info->offset;
385 fseek(fp, offset, SEEK_SET);
386 if (fread(sig,
387 1,
388 strlen(sigl),
389 fp) != strlen(sigl) || strncmp(sigl, sig, strlen(sigl)))
390 didmatch = FALSE;
391 fclose(fp);
392 }
393 }
394 }
395 if (didmatch) { /* got a match; do it... */
396
397 CHAR *list[2];
398 INT flags, rc;
399 BOOL dieafter = FALSE;
400
401 if (fAmAV2) {
402 if (stristr(info->cl, "AV2.EXE") ||
403 stristr(info->cl, "AV2.CMD") || stristr(info->cl, "<>"))
404 return -1;
405 }
406 if (!strcmp(info->cl, "<>")) {
407 OpenObject(datafile, Default, hwnd);
408 return 0;
409 }
410 list[0] = datafile;
411 list[1] = NULL;
412 flags = info->flags;
413 if (!(flags & FULLSCREEN))
414 flags |= WINDOWED;
415 if (flags & KEEP)
416 flags |= SEPARATEKEEP;
417 else
418 flags |= SEPARATE;
419 flags &= (~KEEP);
420 if (flags & DIEAFTER)
421 dieafter = TRUE;
422 flags &= (~DIEAFTER);
423 rc = ExecOnList(hwnd,
424 info->cl,
425 flags,
426 NULL, list, GetPString(IDS_EXECASSOCTITLETEXT));
427 if (rc != -1 && dieafter)
428 PostMsg((HWND) 0, WM_QUIT, MPVOID, MPVOID);
429 return rc;
430 }
431 p = strtok(0, ";");
432 }
433 info = info->next;
434 }
435 return -1;
436}
437
438MRESULT EXPENTRY AssocDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
439{
440 LINKASSOC *info;
441 SHORT x, y;
442
443 switch (msg) {
444 case WM_INITDLG:
445 WinSendDlgItemMsg(hwnd, ASS_LISTBOX, LM_DELETEALL, MPVOID, MPVOID);
446 WinSendDlgItemMsg(hwnd, ASS_MASK, EM_SETTEXTLIMIT,
447 MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
448 WinSendDlgItemMsg(hwnd, ASS_CL, EM_SETTEXTLIMIT,
449 MPFROM2SHORT(1000, 0), MPVOID);
450 WinSendDlgItemMsg(hwnd, ASS_SIG, EM_SETTEXTLIMIT,
451 MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
452 WinSendDlgItemMsg(hwnd, ASS_OFFSET, EM_SETTEXTLIMIT,
453 MPFROM2SHORT(34, 0), MPVOID);
454 WinSetDlgItemText(hwnd, ASS_MASK, NullStr);
455 WinSetDlgItemText(hwnd, ASS_CL, NullStr);
456 WinSetDlgItemText(hwnd, ASS_SIG, NullStr);
457 WinSetDlgItemText(hwnd, ASS_OFFSET, "0");
458 WinCheckButton(hwnd, ASS_DEFAULT, TRUE);
459 WinCheckButton(hwnd, ASS_PROMPT, FALSE);
460 WinCheckButton(hwnd, ASS_KEEP, FALSE);
461 WinCheckButton(hwnd, ASS_DIEAFTER, FALSE);
462 PostMsg(hwnd, UM_UNDO, MPVOID, MPVOID);
463 {
464 PFNWP oldproc;
465
466 oldproc = WinSubclassWindow(WinWindowFromID(hwnd, ASS_CL),
467 (PFNWP) AssocTextProc);
468 if (oldproc)
469 WinSetWindowPtr(WinWindowFromID(hwnd, ASS_CL), QWL_USER,
470 (PVOID) oldproc);
471 }
472 break;
473
474 case UM_UNDO:
475 {
476 CHAR s[1002 + CCHMAXPATH + 6];
477
478 WinSendDlgItemMsg(hwnd, ASS_LISTBOX, LM_DELETEALL, MPVOID, MPVOID);
479 info = asshead;
480 while (info) {
481 sprintf(s,
482 "%-12s \x1a %-24s %s%s%s",
483 info->mask,
484 info->cl,
485 (info->sig && *info->sig) ?
486 "[" : NullStr,
487 (info->sig && *info->sig) ? info->sig : NullStr,
488 (info->sig && *info->sig) ? "]" : NullStr);
489 x = (SHORT) WinSendDlgItemMsg(hwnd,
490 ASS_LISTBOX,
491 LM_INSERTITEM,
492 MPFROM2SHORT(LIT_END, 0), MPFROMP(s));
493 if (x >= 0)
494 WinSendDlgItemMsg(hwnd,
495 ASS_LISTBOX,
496 LM_SETITEMHANDLE, MPFROMSHORT(x), MPFROMP(info));
497 info = info->next;
498 }
499 WinSendDlgItemMsg(hwnd,
500 ASS_LISTBOX,
501 LM_SELECTITEM, MPFROMSHORT(0), MPFROMSHORT(TRUE));
502 }
503 return 0;
504
505 case WM_CONTROL:
506 if (SHORT1FROMMP(mp1) == ASS_LISTBOX) {
507 switch (SHORT2FROMMP(mp1)) {
508 case LN_ENTER:
509 case LN_SELECT:
510 x = (SHORT) WinSendDlgItemMsg(hwnd,
511 ASS_LISTBOX,
512 LM_QUERYSELECTION,
513 MPFROMSHORT(LIT_FIRST), MPVOID);
514 if (x >= 0) {
515
516 CHAR s[36];
517
518 info = (LINKASSOC *) WinSendDlgItemMsg(hwnd,
519 ASS_LISTBOX,
520 LM_QUERYITEMHANDLE,
521 MPFROMSHORT(x), MPVOID);
522 if (!info) {
523 Runtime_Error(pszSrcFile, __LINE__, "Query item handle failed");
524 break;
525 }
526 WinSetDlgItemText(hwnd, ASS_MASK, info->mask);
527 WinSetDlgItemText(hwnd, ASS_CL, info->cl);
528 WinSetDlgItemText(hwnd, ASS_SIG,
529 (info->sig && *info->sig) ? info->sig : NullStr);
530 sprintf(s, "%ld", info->offset);
531 WinSetDlgItemText(hwnd, ASS_OFFSET, s);
532 if (!(info->flags & 1023))
533 WinCheckButton(hwnd, ASS_DEFAULT, TRUE);
534 else {
535 if (info->flags & FULLSCREEN)
536 WinCheckButton(hwnd, ASS_FULLSCREEN, TRUE);
537 else if (info->flags & MINIMIZED)
538 WinCheckButton(hwnd, ASS_MINIMIZED, TRUE);
539 else if (info->flags & MAXIMIZED)
540 WinCheckButton(hwnd, ASS_MAXIMIZED, TRUE);
541 else if (info->flags & INVISIBLE)
542 WinCheckButton(hwnd, ASS_INVISIBLE, TRUE);
543 }
544 WinCheckButton(hwnd, ASS_KEEP, ((info->flags & KEEP) != 0));
545 WinCheckButton(hwnd, ASS_DIEAFTER, ((info->flags & DIEAFTER) != 0));
546 WinCheckButton(hwnd, ASS_PROMPT, ((info->flags & PROMPT) != 0));
547 {
548 CHAR env[1002];
549 ULONG size;
550
551 *env = 0;
552 size = sizeof(env) - 1;
553 if (PrfQueryProfileData(fmprof,
554 FM3Str, info->cl, env, &size) && *env)
555 WinSetDlgItemText(hwnd, ASS_ENVIRON, env);
556 else
557 WinSetDlgItemText(hwnd, ASS_ENVIRON, NullStr);
558 }
559 }
560 break;
561 }
562 }
563 return 0;
564
565 case WM_COMMAND:
566 switch (SHORT1FROMMP(mp1)) {
567 case ASS_TOP:
568 x = (SHORT) WinSendDlgItemMsg(hwnd, ASS_LISTBOX,
569 LM_QUERYSELECTION,
570 MPFROMSHORT(LIT_FIRST), MPVOID);
571 if (x >= 0) {
572 info = (LINKASSOC *) WinSendDlgItemMsg(hwnd, ASS_LISTBOX,
573 LM_QUERYITEMHANDLE,
574 MPFROMSHORT(x), MPVOID);
575 if (info) {
576 if (info != asshead) {
577 if (info->prev)
578 info->prev->next = info->next;
579 if (info->next)
580 info->next->prev = info->prev;
581 if (info == asstail)
582 asstail = info->prev;
583 info->prev = NULL;
584 info->next = asshead;
585 asshead->prev = info;
586 asshead = info;
587 WinSendMsg(hwnd, UM_UNDO, MPVOID, MPVOID);
588 }
589 }
590 }
591 break;
592
593 case ASS_BOTTOM:
594 x = (SHORT) WinSendDlgItemMsg(hwnd, ASS_LISTBOX,
595 LM_QUERYSELECTION,
596 MPFROMSHORT(LIT_FIRST), MPVOID);
597 if (x >= 0) {
598 info = (LINKASSOC *) WinSendDlgItemMsg(hwnd, ASS_LISTBOX,
599 LM_QUERYITEMHANDLE,
600 MPFROMSHORT(x), MPVOID);
601 if (info) {
602 if (info != asstail) {
603 if (info->next)
604 info->next->prev = info->prev;
605 if (info->prev)
606 info->prev->next = info->next;
607 if (info == asshead)
608 asshead = info->next;
609 info->next = NULL;
610 info->prev = asstail;
611 asstail->next = info;
612 asstail = info;
613 WinSendMsg(hwnd, UM_UNDO, MPVOID, MPVOID);
614 }
615 }
616 }
617 break;
618 case ASS_FIND:
619 {
620 CHAR filename[CCHMAXPATH + 9];
621
622 *filename = 0;
623 if (insert_filename(hwnd, filename, 2, FALSE) && *filename) {
624 strcat(filename, " %a");
625 WinSetDlgItemText(hwnd, ASS_CL, filename);
626 }
627 }
628 break;
629
630 case DID_OK:
631 {
632 ASSOC temp;
633 CHAR dummy[34];
634
635 replace = FALSE;
636 {
637 x = (SHORT) WinSendDlgItemMsg(hwnd,
638 ASS_LISTBOX,
639 LM_QUERYSELECTION, MPVOID, MPVOID);
640 if (x == LIT_NONE)
641 x = (SHORT) WinSendDlgItemMsg(hwnd,
642 ASS_LISTBOX,
643 LM_SELECTITEM,
644 MPFROMSHORT(0), MPFROMSHORT(TRUE));
645 }
646 memset(&temp, 0, sizeof(ASSOC));
647 WinQueryDlgItemText(hwnd, ASS_MASK, sizeof(temp.mask), temp.mask);
648 WinQueryDlgItemText(hwnd, ASS_CL, sizeof(temp.cl), temp.cl);
649 WinQueryDlgItemText(hwnd, ASS_SIG, sizeof(temp.sig), temp.sig);
650 rstrip(temp.sig);
651 if (*temp.sig) {
652 WinQueryDlgItemText(hwnd, ASS_OFFSET, sizeof(dummy), dummy);
653 temp.offset = atol(dummy);
654 }
655 bstrip(temp.mask);
656 bstrip(temp.cl);
657 if (WinQueryButtonCheckstate(hwnd, ASS_DEFAULT))
658 temp.flags = 0;
659 else if (WinQueryButtonCheckstate(hwnd, ASS_FULLSCREEN))
660 temp.flags = FULLSCREEN;
661 else if (WinQueryButtonCheckstate(hwnd, ASS_MINIMIZED))
662 temp.flags = MINIMIZED;
663 else if (WinQueryButtonCheckstate(hwnd, ASS_MAXIMIZED))
664 temp.flags = MAXIMIZED;
665 else if (WinQueryButtonCheckstate(hwnd, ASS_INVISIBLE))
666 temp.flags = INVISIBLE;
667 if (WinQueryButtonCheckstate(hwnd, ASS_KEEP))
668 temp.flags |= KEEP;
669 if (WinQueryButtonCheckstate(hwnd, ASS_DIEAFTER))
670 temp.flags |= DIEAFTER;
671 if (WinQueryButtonCheckstate(hwnd, ASS_PROMPT))
672 temp.flags |= PROMPT;
673 info = add_association(&temp);
674 if (!info)
675 WinDismissDlg(hwnd, 1); /* Runtime_Error(pszSrcFile, __LINE__, "add_association"); */
676 else {
677
678 CHAR s[1002 + CCHMAXPATH + 6];
679
680 *s = 0;
681 WinQueryDlgItemText(hwnd, ASS_ENVIRON, 1000, s);
682 bstripcr(s);
683 if (*s)
684 PrfWriteProfileString(fmprof, FM3Str, temp.cl, s);
685 sprintf(s, "%-12s \x1a %-24s %s%s%s", temp.mask,
686 temp.cl, (*temp.sig) ?
687 "[" : NullStr, (*temp.sig) ? temp.sig : NullStr,
688 (*temp.sig) ? "]" : NullStr);
689 x = (SHORT) WinSendDlgItemMsg(hwnd,
690 ASS_LISTBOX,
691 LM_INSERTITEM,
692 MPFROM2SHORT(LIT_END, 0), MPFROMP(s));
693 if (x >= 0) {
694 WinSendDlgItemMsg(hwnd,
695 ASS_LISTBOX,
696 LM_SETITEMHANDLE,
697 MPFROMSHORT(x), MPFROMP(info));
698 WinSendDlgItemMsg(hwnd,
699 ASS_LISTBOX,
700 LM_SELECTITEM,
701 MPFROMSHORT(x), MPFROMSHORT(TRUE));
702 }
703 save_associations();
704 }
705 }
706 WinDismissDlg(hwnd, 1);
707 break;
708
709 case DID_CANCEL:
710 WinDismissDlg(hwnd, 0);
711 break;
712
713 case IDM_HELP:
714 if (hwndHelp)
715 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
716 MPFROM2SHORT(HELP_ASSOC, 0), MPFROMSHORT(HM_RESOURCEID));
717 break;
718
719 case ASS_ADD:
720 {
721 ASSOC temp;
722 CHAR dummy[34];
723
724 replace = FALSE;
725
726 memset(&temp, 0, sizeof(ASSOC));
727 WinQueryDlgItemText(hwnd, ASS_MASK, sizeof(temp.mask), temp.mask);
728 WinQueryDlgItemText(hwnd, ASS_CL, sizeof(temp.cl), temp.cl);
729 WinQueryDlgItemText(hwnd, ASS_SIG, sizeof(temp.sig), temp.sig);
730 rstrip(temp.sig);
731 if (*temp.sig) {
732 WinQueryDlgItemText(hwnd, ASS_OFFSET, sizeof(dummy), dummy);
733 temp.offset = atol(dummy);
734 }
735 bstrip(temp.mask);
736 bstrip(temp.cl);
737 if (WinQueryButtonCheckstate(hwnd, ASS_DEFAULT))
738 temp.flags = 0;
739 else if (WinQueryButtonCheckstate(hwnd, ASS_FULLSCREEN))
740 temp.flags = FULLSCREEN;
741 else if (WinQueryButtonCheckstate(hwnd, ASS_MINIMIZED))
742 temp.flags = MINIMIZED;
743 else if (WinQueryButtonCheckstate(hwnd, ASS_MAXIMIZED))
744 temp.flags = MAXIMIZED;
745 else if (WinQueryButtonCheckstate(hwnd, ASS_INVISIBLE))
746 temp.flags = INVISIBLE;
747 if (WinQueryButtonCheckstate(hwnd, ASS_KEEP))
748 temp.flags |= KEEP;
749 if (WinQueryButtonCheckstate(hwnd, ASS_DIEAFTER))
750 temp.flags |= DIEAFTER;
751 if (WinQueryButtonCheckstate(hwnd, ASS_PROMPT))
752 temp.flags |= PROMPT;
753 info = add_association(&temp);
754 //Add will fail if mask is not changed
755 if (info) {
756
757 CHAR s[1002 + CCHMAXPATH + 6];
758
759 *s = 0;
760 WinQueryDlgItemText(hwnd, ASS_ENVIRON, 1000, s);
761 bstripcr(s);
762 if (*s)
763 PrfWriteProfileString(fmprof, FM3Str, temp.cl, s);
764 sprintf(s, "%-12s \x1a %-24s %s%s%s", temp.mask,
765 temp.cl, (*temp.sig) ?
766 "[" : NullStr, (*temp.sig) ? temp.sig : NullStr,
767 (*temp.sig) ? "]" : NullStr);
768 x = (SHORT) WinSendDlgItemMsg(hwnd,
769 ASS_LISTBOX,
770 LM_INSERTITEM,
771 MPFROM2SHORT(LIT_END, 0), MPFROMP(s));
772 if (x >= 0) {
773 WinSendDlgItemMsg(hwnd,
774 ASS_LISTBOX,
775 LM_SETITEMHANDLE,
776 MPFROMSHORT(x), MPFROMP(info));
777 WinSendDlgItemMsg(hwnd,
778 ASS_LISTBOX,
779 LM_SELECTITEM,
780 MPFROMSHORT(x), MPFROMSHORT(TRUE));
781 }
782 save_associations();
783 }
784 }
785 break;
786
787 case ASS_DELETE:
788 {
789 ASSOC temp;
790 CHAR dummy[34];
791
792 memset(&temp, 0, sizeof(ASSOC));
793 WinQueryDlgItemText(hwnd, ASS_MASK, sizeof(temp.mask), temp.mask);
794 WinQueryDlgItemText(hwnd, ASS_SIG, sizeof(temp.sig), temp.sig);
795 rstrip(temp.sig);
796 if (*temp.sig) {
797 WinQueryDlgItemText(hwnd, ASS_OFFSET, sizeof(dummy), dummy);
798 temp.offset = atol(dummy);
799 }
800 bstrip(temp.mask);
801 PrfWriteProfileData(fmprof, FM3Str, temp.mask, NULL, 0L);
802 if (kill_association(&temp))
803 /* Runtime_Error(pszSrcFile, __LINE__, "kill_association");
804 else */{
805 x = (SHORT) WinSendDlgItemMsg(hwnd,
806 ASS_LISTBOX,
807 LM_QUERYSELECTION,
808 MPFROMSHORT(LIT_FIRST), MPVOID);
809 if (x >= 0) {
810 WinSendDlgItemMsg(hwnd,
811 ASS_LISTBOX,
812 LM_DELETEITEM, MPFROMSHORT(x), MPVOID);
813 WinSendDlgItemMsg(hwnd, ASS_LISTBOX, LM_SELECTITEM,
814 MPFROMSHORT(LIT_NONE), MPFROMSHORT(FALSE));
815 }
816 save_associations();
817 }
818 }
819 break;
820 case ASS_REPLACE:
821
822 {
823 ASSOC temp;
824 CHAR dummy[34];
825
826 replace = TRUE;
827
828 y = (SHORT) WinSendDlgItemMsg(hwnd,
829 ASS_LISTBOX,
830 LM_QUERYSELECTION,
831 MPFROMSHORT(LIT_CURSOR), MPVOID);
832 memset(&temp, 0, sizeof(ASSOC));
833 WinQueryDlgItemText(hwnd, ASS_MASK, sizeof(temp.mask), temp.mask);
834 WinQueryDlgItemText(hwnd, ASS_CL, sizeof(temp.cl), temp.cl);
835 WinQueryDlgItemText(hwnd, ASS_SIG, sizeof(temp.sig), temp.sig);
836 rstrip(temp.sig);
837 if (*temp.sig) {
838 WinQueryDlgItemText(hwnd, ASS_OFFSET, sizeof(dummy), dummy);
839 temp.offset = atol(dummy);
840 }
841 bstrip(temp.mask);
842 bstrip(temp.cl);
843 if (WinQueryButtonCheckstate(hwnd, ASS_DEFAULT))
844 temp.flags = 0;
845 else if (WinQueryButtonCheckstate(hwnd, ASS_FULLSCREEN))
846 temp.flags = FULLSCREEN;
847 else if (WinQueryButtonCheckstate(hwnd, ASS_MINIMIZED))
848 temp.flags = MINIMIZED;
849 else if (WinQueryButtonCheckstate(hwnd, ASS_MAXIMIZED))
850 temp.flags = MAXIMIZED;
851 else if (WinQueryButtonCheckstate(hwnd, ASS_INVISIBLE))
852 temp.flags = INVISIBLE;
853 if (WinQueryButtonCheckstate(hwnd, ASS_KEEP))
854 temp.flags |= KEEP;
855 if (WinQueryButtonCheckstate(hwnd, ASS_DIEAFTER))
856 temp.flags |= DIEAFTER;
857 if (WinQueryButtonCheckstate(hwnd, ASS_PROMPT))
858 temp.flags |= PROMPT;
859 info = add_association(&temp);
860 //Add will fail if mask is not changed
861 if (info) {
862
863 CHAR s[1002 + CCHMAXPATH + 6];
864
865 *s = 0;
866 WinQueryDlgItemText(hwnd, ASS_ENVIRON, 1000, s);
867 bstripcr(s);
868 if (*s)
869 PrfWriteProfileString(fmprof, FM3Str, temp.cl, s);
870 sprintf(s, "%-12s \x1a %-24s %s%s%s", temp.mask,
871 temp.cl, (*temp.sig) ?
872 "[" : NullStr, (*temp.sig) ? temp.sig : NullStr,
873 (*temp.sig) ? "]" : NullStr);
874 x = (SHORT) WinSendDlgItemMsg(hwnd,
875 ASS_LISTBOX,
876 LM_INSERTITEM,
877 MPFROM2SHORT(LIT_END, 0), MPFROMP(s));
878 if (x >= 0) {
879 WinSendDlgItemMsg(hwnd,
880 ASS_LISTBOX,
881 LM_SETITEMHANDLE,
882 MPFROMSHORT(x), MPFROMP(info));
883 WinSendDlgItemMsg(hwnd,
884 ASS_LISTBOX,
885 LM_SELECTITEM,
886 MPFROMSHORT(x), MPFROMSHORT(TRUE));
887 }
888 save_associations();
889 }
890 }
891 {
892 ASSOC temp;
893 CHAR dummy[34];
894
895 WinSendDlgItemMsg(hwnd,
896 ASS_LISTBOX,
897 LM_SELECTITEM, MPFROMSHORT(y), MPFROMSHORT(TRUE));
898 memset(&temp, 0, sizeof(ASSOC));
899 WinQueryDlgItemText(hwnd, ASS_MASK, sizeof(temp.mask), temp.mask);
900 WinQueryDlgItemText(hwnd, ASS_SIG, sizeof(temp.sig), temp.sig);
901 rstrip(temp.sig);
902 if (*temp.sig) {
903 WinQueryDlgItemText(hwnd, ASS_OFFSET, sizeof(dummy), dummy);
904 temp.offset = atol(dummy);
905 }
906 bstrip(temp.mask);
907 PrfWriteProfileData(fmprof, FM3Str, temp.mask, NULL, 0L);
908 if (!kill_association(&temp))
909 Runtime_Error(pszSrcFile, __LINE__, "kill_association");
910 else {
911
912 if (y >= 0) {
913 WinSendDlgItemMsg(hwnd,
914 ASS_LISTBOX,
915 LM_DELETEITEM, MPFROMSHORT(y), MPVOID);
916 WinSendDlgItemMsg(hwnd, ASS_LISTBOX, LM_SELECTITEM,
917 MPFROMSHORT(x - 1), MPFROMSHORT(TRUE));
918 }
919 save_associations();
920 }
921 }
922 break;
923 }
924 return 0;
925 }
926 return WinDefDlgProc(hwnd, msg, mp1, mp2);
927}
928
929VOID EditAssociations(HWND hwnd)
930{
931 static CHAR stop = 0;
932
933 if (stop)
934 return;
935 stop++;
936 if (!assloaded)
937 load_associations();
938 WinDlgBox(HWND_DESKTOP, hwnd, AssocDlgProc, FM3ModHandle, ASS_FRAME, NULL);
939 stop = 0;
940}
941
942#pragma alloc_text(ASSOC2,free_commands,load_associations,save_associations)
943#pragma alloc_text(ASSOC2,ExecAssociation,AssocTextProc)
944#pragma alloc_text(ASSOC,add_association,kill_association,AssocDlgProc,EditAssociations)
Note: See TracBrowser for help on using the repository browser.