source: trunk/dll/assoc.c@ 793

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

Move #pragma alloc_text to end for OpenWatcom compat

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 23.4 KB
Line 
1
2/**************************************************************************************
3
4 $Id: assoc.c 793 2007-08-21 02:53:38Z 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 didmatch = wildcard((strchr(p, '\\') ||
365 strchr(p, ':')) ? datafile : file, p, FALSE);
366 if (exclude && didmatch)
367 didmatch = FALSE;
368 if (didmatch) {
369 if (info->sig && *info->sig) {
370 strcpy(sigl, info->sig);
371 literal(sigl);
372 fp = _fsopen(datafile, "rb", SH_DENYNO);
373 if (fp) {
374 if (info->offset < 0L) {
375 fseek(fp, 0L, SEEK_END);
376 offset = ftell(fp) + info->offset;
377 }
378 else
379 offset = info->offset;
380 fseek(fp, offset, SEEK_SET);
381 if (fread(sig,
382 1,
383 strlen(sigl),
384 fp) != strlen(sigl) || strncmp(sigl, sig, strlen(sigl)))
385 didmatch = FALSE;
386 fclose(fp);
387 }
388 }
389 }
390 if (didmatch) { /* got a match; do it... */
391
392 CHAR *list[2];
393 INT flags, rc;
394 BOOL dieafter = FALSE;
395
396 if (fAmAV2) {
397 if (stristr(info->cl, "AV2.EXE") ||
398 stristr(info->cl, "AV2.CMD") || stristr(info->cl, "<>"))
399 return -1;
400 }
401 if (!strcmp(info->cl, "<>")) {
402 OpenObject(datafile, Default, hwnd);
403 return 0;
404 }
405 list[0] = datafile;
406 list[1] = NULL;
407 flags = info->flags;
408 if (!(flags & FULLSCREEN))
409 flags |= WINDOWED;
410 if (flags & KEEP)
411 flags |= SEPARATEKEEP;
412 else
413 flags |= SEPARATE;
414 flags &= (~KEEP);
415 if (flags & DIEAFTER)
416 dieafter = TRUE;
417 flags &= (~DIEAFTER);
418 rc = ExecOnList(hwnd,
419 info->cl,
420 flags,
421 NULL, list, GetPString(IDS_EXECASSOCTITLETEXT));
422 if (rc != -1 && dieafter)
423 PostMsg((HWND) 0, WM_QUIT, MPVOID, MPVOID);
424 return rc;
425 }
426 p = strtok(0, ";");
427 }
428 info = info->next;
429 }
430 return -1;
431}
432
433MRESULT EXPENTRY AssocDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
434{
435 LINKASSOC *info;
436 SHORT x, y;
437
438 switch (msg) {
439 case WM_INITDLG:
440 WinSendDlgItemMsg(hwnd, ASS_LISTBOX, LM_DELETEALL, MPVOID, MPVOID);
441 WinSendDlgItemMsg(hwnd, ASS_MASK, EM_SETTEXTLIMIT,
442 MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
443 WinSendDlgItemMsg(hwnd, ASS_CL, EM_SETTEXTLIMIT,
444 MPFROM2SHORT(1000, 0), MPVOID);
445 WinSendDlgItemMsg(hwnd, ASS_SIG, EM_SETTEXTLIMIT,
446 MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
447 WinSendDlgItemMsg(hwnd, ASS_OFFSET, EM_SETTEXTLIMIT,
448 MPFROM2SHORT(34, 0), MPVOID);
449 WinSetDlgItemText(hwnd, ASS_MASK, NullStr);
450 WinSetDlgItemText(hwnd, ASS_CL, NullStr);
451 WinSetDlgItemText(hwnd, ASS_SIG, NullStr);
452 WinSetDlgItemText(hwnd, ASS_OFFSET, "0");
453 WinCheckButton(hwnd, ASS_DEFAULT, TRUE);
454 WinCheckButton(hwnd, ASS_PROMPT, FALSE);
455 WinCheckButton(hwnd, ASS_KEEP, FALSE);
456 WinCheckButton(hwnd, ASS_DIEAFTER, FALSE);
457 PostMsg(hwnd, UM_UNDO, MPVOID, MPVOID);
458 {
459 PFNWP oldproc;
460
461 oldproc = WinSubclassWindow(WinWindowFromID(hwnd, ASS_CL),
462 (PFNWP) AssocTextProc);
463 if (oldproc)
464 WinSetWindowPtr(WinWindowFromID(hwnd, ASS_CL), QWL_USER,
465 (PVOID) oldproc);
466 }
467 break;
468
469 case UM_UNDO:
470 {
471 CHAR s[1002 + CCHMAXPATH + 6];
472
473 WinSendDlgItemMsg(hwnd, ASS_LISTBOX, LM_DELETEALL, MPVOID, MPVOID);
474 info = asshead;
475 while (info) {
476 sprintf(s,
477 "%-12s \x1a %-24s %s%s%s",
478 info->mask,
479 info->cl,
480 (info->sig && *info->sig) ?
481 "[" : NullStr,
482 (info->sig && *info->sig) ? info->sig : NullStr,
483 (info->sig && *info->sig) ? "]" : NullStr);
484 x = (SHORT) WinSendDlgItemMsg(hwnd,
485 ASS_LISTBOX,
486 LM_INSERTITEM,
487 MPFROM2SHORT(LIT_END, 0), MPFROMP(s));
488 if (x >= 0)
489 WinSendDlgItemMsg(hwnd,
490 ASS_LISTBOX,
491 LM_SETITEMHANDLE, MPFROMSHORT(x), MPFROMP(info));
492 info = info->next;
493 }
494 WinSendDlgItemMsg(hwnd,
495 ASS_LISTBOX,
496 LM_SELECTITEM, MPFROMSHORT(0), MPFROMSHORT(TRUE));
497 }
498 return 0;
499
500 case WM_CONTROL:
501 if (SHORT1FROMMP(mp1) == ASS_LISTBOX) {
502 switch (SHORT2FROMMP(mp1)) {
503 case LN_ENTER:
504 case LN_SELECT:
505 x = (SHORT) WinSendDlgItemMsg(hwnd,
506 ASS_LISTBOX,
507 LM_QUERYSELECTION,
508 MPFROMSHORT(LIT_FIRST), MPVOID);
509 if (x >= 0) {
510
511 CHAR s[36];
512
513 info = (LINKASSOC *) WinSendDlgItemMsg(hwnd,
514 ASS_LISTBOX,
515 LM_QUERYITEMHANDLE,
516 MPFROMSHORT(x), MPVOID);
517 if (!info) {
518 Runtime_Error(pszSrcFile, __LINE__, "Query item handle failed");
519 break;
520 }
521 WinSetDlgItemText(hwnd, ASS_MASK, info->mask);
522 WinSetDlgItemText(hwnd, ASS_CL, info->cl);
523 WinSetDlgItemText(hwnd, ASS_SIG,
524 (info->sig && *info->sig) ? info->sig : NullStr);
525 sprintf(s, "%ld", info->offset);
526 WinSetDlgItemText(hwnd, ASS_OFFSET, s);
527 if (!(info->flags & 1023))
528 WinCheckButton(hwnd, ASS_DEFAULT, TRUE);
529 else {
530 if (info->flags & FULLSCREEN)
531 WinCheckButton(hwnd, ASS_FULLSCREEN, TRUE);
532 else if (info->flags & MINIMIZED)
533 WinCheckButton(hwnd, ASS_MINIMIZED, TRUE);
534 else if (info->flags & MAXIMIZED)
535 WinCheckButton(hwnd, ASS_MAXIMIZED, TRUE);
536 else if (info->flags & INVISIBLE)
537 WinCheckButton(hwnd, ASS_INVISIBLE, TRUE);
538 }
539 WinCheckButton(hwnd, ASS_KEEP, ((info->flags & KEEP) != 0));
540 WinCheckButton(hwnd, ASS_DIEAFTER, ((info->flags & DIEAFTER) != 0));
541 WinCheckButton(hwnd, ASS_PROMPT, ((info->flags & PROMPT) != 0));
542 {
543 CHAR env[1002];
544 ULONG size;
545
546 *env = 0;
547 size = sizeof(env) - 1;
548 if (PrfQueryProfileData(fmprof,
549 FM3Str, info->cl, env, &size) && *env)
550 WinSetDlgItemText(hwnd, ASS_ENVIRON, env);
551 else
552 WinSetDlgItemText(hwnd, ASS_ENVIRON, NullStr);
553 }
554 }
555 break;
556 }
557 }
558 return 0;
559
560 case WM_COMMAND:
561 switch (SHORT1FROMMP(mp1)) {
562 case ASS_TOP:
563 x = (SHORT) WinSendDlgItemMsg(hwnd, ASS_LISTBOX,
564 LM_QUERYSELECTION,
565 MPFROMSHORT(LIT_FIRST), MPVOID);
566 if (x >= 0) {
567 info = (LINKASSOC *) WinSendDlgItemMsg(hwnd, ASS_LISTBOX,
568 LM_QUERYITEMHANDLE,
569 MPFROMSHORT(x), MPVOID);
570 if (info) {
571 if (info != asshead) {
572 if (info->prev)
573 info->prev->next = info->next;
574 if (info->next)
575 info->next->prev = info->prev;
576 if (info == asstail)
577 asstail = info->prev;
578 info->prev = NULL;
579 info->next = asshead;
580 asshead->prev = info;
581 asshead = info;
582 WinSendMsg(hwnd, UM_UNDO, MPVOID, MPVOID);
583 }
584 }
585 }
586 break;
587
588 case ASS_BOTTOM:
589 x = (SHORT) WinSendDlgItemMsg(hwnd, ASS_LISTBOX,
590 LM_QUERYSELECTION,
591 MPFROMSHORT(LIT_FIRST), MPVOID);
592 if (x >= 0) {
593 info = (LINKASSOC *) WinSendDlgItemMsg(hwnd, ASS_LISTBOX,
594 LM_QUERYITEMHANDLE,
595 MPFROMSHORT(x), MPVOID);
596 if (info) {
597 if (info != asstail) {
598 if (info->next)
599 info->next->prev = info->prev;
600 if (info->prev)
601 info->prev->next = info->next;
602 if (info == asshead)
603 asshead = info->next;
604 info->next = NULL;
605 info->prev = asstail;
606 asstail->next = info;
607 asstail = info;
608 WinSendMsg(hwnd, UM_UNDO, MPVOID, MPVOID);
609 }
610 }
611 }
612 break;
613 case ASS_FIND:
614 {
615 CHAR filename[CCHMAXPATH + 9];
616
617 *filename = 0;
618 if (insert_filename(hwnd, filename, 2, FALSE) && *filename) {
619 strcat(filename, " %a");
620 WinSetDlgItemText(hwnd, ASS_CL, filename);
621 }
622 }
623 break;
624
625 case DID_OK:
626 {
627 ASSOC temp;
628 CHAR dummy[34];
629
630 replace = FALSE;
631 {
632 x = (SHORT) WinSendDlgItemMsg(hwnd,
633 ASS_LISTBOX,
634 LM_QUERYSELECTION, MPVOID, MPVOID);
635 if (x == LIT_NONE)
636 x = (SHORT) WinSendDlgItemMsg(hwnd,
637 ASS_LISTBOX,
638 LM_SELECTITEM,
639 MPFROMSHORT(0), MPFROMSHORT(TRUE));
640 }
641 memset(&temp, 0, sizeof(ASSOC));
642 WinQueryDlgItemText(hwnd, ASS_MASK, sizeof(temp.mask), temp.mask);
643 WinQueryDlgItemText(hwnd, ASS_CL, sizeof(temp.cl), temp.cl);
644 WinQueryDlgItemText(hwnd, ASS_SIG, sizeof(temp.sig), temp.sig);
645 rstrip(temp.sig);
646 if (*temp.sig) {
647 WinQueryDlgItemText(hwnd, ASS_OFFSET, sizeof(dummy), dummy);
648 temp.offset = atol(dummy);
649 }
650 bstrip(temp.mask);
651 bstrip(temp.cl);
652 if (WinQueryButtonCheckstate(hwnd, ASS_DEFAULT))
653 temp.flags = 0;
654 else if (WinQueryButtonCheckstate(hwnd, ASS_FULLSCREEN))
655 temp.flags = FULLSCREEN;
656 else if (WinQueryButtonCheckstate(hwnd, ASS_MINIMIZED))
657 temp.flags = MINIMIZED;
658 else if (WinQueryButtonCheckstate(hwnd, ASS_MAXIMIZED))
659 temp.flags = MAXIMIZED;
660 else if (WinQueryButtonCheckstate(hwnd, ASS_INVISIBLE))
661 temp.flags = INVISIBLE;
662 if (WinQueryButtonCheckstate(hwnd, ASS_KEEP))
663 temp.flags |= KEEP;
664 if (WinQueryButtonCheckstate(hwnd, ASS_DIEAFTER))
665 temp.flags |= DIEAFTER;
666 if (WinQueryButtonCheckstate(hwnd, ASS_PROMPT))
667 temp.flags |= PROMPT;
668 info = add_association(&temp);
669 if (!info)
670 WinDismissDlg(hwnd, 1); /* Runtime_Error(pszSrcFile, __LINE__, "add_association"); */
671 else {
672
673 CHAR s[1002 + CCHMAXPATH + 6];
674
675 *s = 0;
676 WinQueryDlgItemText(hwnd, ASS_ENVIRON, 1000, s);
677 bstripcr(s);
678 if (*s)
679 PrfWriteProfileString(fmprof, FM3Str, temp.cl, s);
680 sprintf(s, "%-12s \x1a %-24s %s%s%s", temp.mask,
681 temp.cl, (*temp.sig) ?
682 "[" : NullStr, (*temp.sig) ? temp.sig : NullStr,
683 (*temp.sig) ? "]" : NullStr);
684 x = (SHORT) WinSendDlgItemMsg(hwnd,
685 ASS_LISTBOX,
686 LM_INSERTITEM,
687 MPFROM2SHORT(LIT_END, 0), MPFROMP(s));
688 if (x >= 0) {
689 WinSendDlgItemMsg(hwnd,
690 ASS_LISTBOX,
691 LM_SETITEMHANDLE,
692 MPFROMSHORT(x), MPFROMP(info));
693 WinSendDlgItemMsg(hwnd,
694 ASS_LISTBOX,
695 LM_SELECTITEM,
696 MPFROMSHORT(x), MPFROMSHORT(TRUE));
697 }
698 save_associations();
699 }
700 }
701 WinDismissDlg(hwnd, 1);
702 break;
703
704 case DID_CANCEL:
705 WinDismissDlg(hwnd, 0);
706 break;
707
708 case IDM_HELP:
709 if (hwndHelp)
710 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
711 MPFROM2SHORT(HELP_ASSOC, 0), MPFROMSHORT(HM_RESOURCEID));
712 break;
713
714 case ASS_ADD:
715 {
716 ASSOC temp;
717 CHAR dummy[34];
718
719 replace = FALSE;
720
721 memset(&temp, 0, sizeof(ASSOC));
722 WinQueryDlgItemText(hwnd, ASS_MASK, sizeof(temp.mask), temp.mask);
723 WinQueryDlgItemText(hwnd, ASS_CL, sizeof(temp.cl), temp.cl);
724 WinQueryDlgItemText(hwnd, ASS_SIG, sizeof(temp.sig), temp.sig);
725 rstrip(temp.sig);
726 if (*temp.sig) {
727 WinQueryDlgItemText(hwnd, ASS_OFFSET, sizeof(dummy), dummy);
728 temp.offset = atol(dummy);
729 }
730 bstrip(temp.mask);
731 bstrip(temp.cl);
732 if (WinQueryButtonCheckstate(hwnd, ASS_DEFAULT))
733 temp.flags = 0;
734 else if (WinQueryButtonCheckstate(hwnd, ASS_FULLSCREEN))
735 temp.flags = FULLSCREEN;
736 else if (WinQueryButtonCheckstate(hwnd, ASS_MINIMIZED))
737 temp.flags = MINIMIZED;
738 else if (WinQueryButtonCheckstate(hwnd, ASS_MAXIMIZED))
739 temp.flags = MAXIMIZED;
740 else if (WinQueryButtonCheckstate(hwnd, ASS_INVISIBLE))
741 temp.flags = INVISIBLE;
742 if (WinQueryButtonCheckstate(hwnd, ASS_KEEP))
743 temp.flags |= KEEP;
744 if (WinQueryButtonCheckstate(hwnd, ASS_DIEAFTER))
745 temp.flags |= DIEAFTER;
746 if (WinQueryButtonCheckstate(hwnd, ASS_PROMPT))
747 temp.flags |= PROMPT;
748 info = add_association(&temp);
749 //Add will fail if mask is not changed
750 if (info) {
751
752 CHAR s[1002 + CCHMAXPATH + 6];
753
754 *s = 0;
755 WinQueryDlgItemText(hwnd, ASS_ENVIRON, 1000, s);
756 bstripcr(s);
757 if (*s)
758 PrfWriteProfileString(fmprof, FM3Str, temp.cl, s);
759 sprintf(s, "%-12s \x1a %-24s %s%s%s", temp.mask,
760 temp.cl, (*temp.sig) ?
761 "[" : NullStr, (*temp.sig) ? temp.sig : NullStr,
762 (*temp.sig) ? "]" : NullStr);
763 x = (SHORT) WinSendDlgItemMsg(hwnd,
764 ASS_LISTBOX,
765 LM_INSERTITEM,
766 MPFROM2SHORT(LIT_END, 0), MPFROMP(s));
767 if (x >= 0) {
768 WinSendDlgItemMsg(hwnd,
769 ASS_LISTBOX,
770 LM_SETITEMHANDLE,
771 MPFROMSHORT(x), MPFROMP(info));
772 WinSendDlgItemMsg(hwnd,
773 ASS_LISTBOX,
774 LM_SELECTITEM,
775 MPFROMSHORT(x), MPFROMSHORT(TRUE));
776 }
777 save_associations();
778 }
779 }
780 break;
781
782 case ASS_DELETE:
783 {
784 ASSOC temp;
785 CHAR dummy[34];
786
787 memset(&temp, 0, sizeof(ASSOC));
788 WinQueryDlgItemText(hwnd, ASS_MASK, sizeof(temp.mask), temp.mask);
789 WinQueryDlgItemText(hwnd, ASS_SIG, sizeof(temp.sig), temp.sig);
790 rstrip(temp.sig);
791 if (*temp.sig) {
792 WinQueryDlgItemText(hwnd, ASS_OFFSET, sizeof(dummy), dummy);
793 temp.offset = atol(dummy);
794 }
795 bstrip(temp.mask);
796 PrfWriteProfileData(fmprof, FM3Str, temp.mask, NULL, 0L);
797 if (kill_association(&temp))
798 /* Runtime_Error(pszSrcFile, __LINE__, "kill_association");
799 else */{
800 x = (SHORT) WinSendDlgItemMsg(hwnd,
801 ASS_LISTBOX,
802 LM_QUERYSELECTION,
803 MPFROMSHORT(LIT_FIRST), MPVOID);
804 if (x >= 0) {
805 WinSendDlgItemMsg(hwnd,
806 ASS_LISTBOX,
807 LM_DELETEITEM, MPFROMSHORT(x), MPVOID);
808 WinSendDlgItemMsg(hwnd, ASS_LISTBOX, LM_SELECTITEM,
809 MPFROMSHORT(LIT_NONE), MPFROMSHORT(FALSE));
810 }
811 save_associations();
812 }
813 }
814 break;
815 case ASS_REPLACE:
816
817 {
818 ASSOC temp;
819 CHAR dummy[34];
820
821 replace = TRUE;
822
823 y = (SHORT) WinSendDlgItemMsg(hwnd,
824 ASS_LISTBOX,
825 LM_QUERYSELECTION,
826 MPFROMSHORT(LIT_CURSOR), MPVOID);
827 memset(&temp, 0, sizeof(ASSOC));
828 WinQueryDlgItemText(hwnd, ASS_MASK, sizeof(temp.mask), temp.mask);
829 WinQueryDlgItemText(hwnd, ASS_CL, sizeof(temp.cl), temp.cl);
830 WinQueryDlgItemText(hwnd, ASS_SIG, sizeof(temp.sig), temp.sig);
831 rstrip(temp.sig);
832 if (*temp.sig) {
833 WinQueryDlgItemText(hwnd, ASS_OFFSET, sizeof(dummy), dummy);
834 temp.offset = atol(dummy);
835 }
836 bstrip(temp.mask);
837 bstrip(temp.cl);
838 if (WinQueryButtonCheckstate(hwnd, ASS_DEFAULT))
839 temp.flags = 0;
840 else if (WinQueryButtonCheckstate(hwnd, ASS_FULLSCREEN))
841 temp.flags = FULLSCREEN;
842 else if (WinQueryButtonCheckstate(hwnd, ASS_MINIMIZED))
843 temp.flags = MINIMIZED;
844 else if (WinQueryButtonCheckstate(hwnd, ASS_MAXIMIZED))
845 temp.flags = MAXIMIZED;
846 else if (WinQueryButtonCheckstate(hwnd, ASS_INVISIBLE))
847 temp.flags = INVISIBLE;
848 if (WinQueryButtonCheckstate(hwnd, ASS_KEEP))
849 temp.flags |= KEEP;
850 if (WinQueryButtonCheckstate(hwnd, ASS_DIEAFTER))
851 temp.flags |= DIEAFTER;
852 if (WinQueryButtonCheckstate(hwnd, ASS_PROMPT))
853 temp.flags |= PROMPT;
854 info = add_association(&temp);
855 //Add will fail if mask is not changed
856 if (info) {
857
858 CHAR s[1002 + CCHMAXPATH + 6];
859
860 *s = 0;
861 WinQueryDlgItemText(hwnd, ASS_ENVIRON, 1000, s);
862 bstripcr(s);
863 if (*s)
864 PrfWriteProfileString(fmprof, FM3Str, temp.cl, s);
865 sprintf(s, "%-12s \x1a %-24s %s%s%s", temp.mask,
866 temp.cl, (*temp.sig) ?
867 "[" : NullStr, (*temp.sig) ? temp.sig : NullStr,
868 (*temp.sig) ? "]" : NullStr);
869 x = (SHORT) WinSendDlgItemMsg(hwnd,
870 ASS_LISTBOX,
871 LM_INSERTITEM,
872 MPFROM2SHORT(LIT_END, 0), MPFROMP(s));
873 if (x >= 0) {
874 WinSendDlgItemMsg(hwnd,
875 ASS_LISTBOX,
876 LM_SETITEMHANDLE,
877 MPFROMSHORT(x), MPFROMP(info));
878 WinSendDlgItemMsg(hwnd,
879 ASS_LISTBOX,
880 LM_SELECTITEM,
881 MPFROMSHORT(x), MPFROMSHORT(TRUE));
882 }
883 save_associations();
884 }
885 }
886 {
887 ASSOC temp;
888 CHAR dummy[34];
889
890 WinSendDlgItemMsg(hwnd,
891 ASS_LISTBOX,
892 LM_SELECTITEM, MPFROMSHORT(y), MPFROMSHORT(TRUE));
893 memset(&temp, 0, sizeof(ASSOC));
894 WinQueryDlgItemText(hwnd, ASS_MASK, sizeof(temp.mask), temp.mask);
895 WinQueryDlgItemText(hwnd, ASS_SIG, sizeof(temp.sig), temp.sig);
896 rstrip(temp.sig);
897 if (*temp.sig) {
898 WinQueryDlgItemText(hwnd, ASS_OFFSET, sizeof(dummy), dummy);
899 temp.offset = atol(dummy);
900 }
901 bstrip(temp.mask);
902 PrfWriteProfileData(fmprof, FM3Str, temp.mask, NULL, 0L);
903 if (!kill_association(&temp))
904 Runtime_Error(pszSrcFile, __LINE__, "kill_association");
905 else {
906
907 if (y >= 0) {
908 WinSendDlgItemMsg(hwnd,
909 ASS_LISTBOX,
910 LM_DELETEITEM, MPFROMSHORT(y), MPVOID);
911 WinSendDlgItemMsg(hwnd, ASS_LISTBOX, LM_SELECTITEM,
912 MPFROMSHORT(x - 1), MPFROMSHORT(TRUE));
913 }
914 save_associations();
915 }
916 }
917 break;
918 }
919 return 0;
920 }
921 return WinDefDlgProc(hwnd, msg, mp1, mp2);
922}
923
924VOID EditAssociations(HWND hwnd)
925{
926 static CHAR stop = 0;
927
928 if (stop)
929 return;
930 stop++;
931 if (!assloaded)
932 load_associations();
933 WinDlgBox(HWND_DESKTOP, hwnd, AssocDlgProc, FM3ModHandle, ASS_FRAME, NULL);
934 stop = 0;
935}
936
937#pragma alloc_text(ASSOC2,free_commands,load_associations,save_associations)
938#pragma alloc_text(ASSOC2,ExecAssociation,AssocTextProc)
939#pragma alloc_text(ASSOC,add_association,kill_association,AssocDlgProc,EditAssociations)
Note: See TracBrowser for help on using the repository browser.