source: trunk/dll/assoc.c@ 1009

Last change on this file since 1009 was 1009, checked in by Steven Levine, 17 years ago

Add xfree xstrdup Fortify support
Add MT capable Fortify scope logic

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