source: trunk/dll/assoc.c@ 959

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

Use xfree where appropriate. Check that buffer exists following all xmallocs. Stopped at eas.c with xfree checking. One remaining xmalloc without test in dirsize.c

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