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
RevLine 
[123]1
[506]2/**************************************************************************************
[123]3
4 $Id: assoc.c 1009 2008-05-10 07:51:58Z stevenhl $
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
[985]18 29 Feb 08 GKY Changes to enable user settable command line length
19 29 Feb 08 GKY Use xfree where appropriate
[123]20
[506]21**************************************************************************************/
[123]22
[907]23#include <stdlib.h>
24#include <string.h>
25#include <share.h>
26
[2]27#define INCL_DOS
28#define INCL_WIN
[506]29#define INCL_PM
30#define INCL_WINHOOKS
[907]31#define INCL_LONGLONG // dircnrs.h
[2]32
33#include "fm3dlg.h"
34#include "fm3str.h"
[907]35#include "pathutil.h" // BldQuotedFileName
36#include "errutil.h" // Dos_Error...
37#include "strutil.h" // GetPString
38#include "fm3dll.h"
[2]39
40#pragma data_seg(DATA1)
41
[551]42typedef struct
43{
[985]44 LONG offset;
45 ULONG flags;
46 PSZ pszCmdLine;
[551]47 CHAR mask[CCHMAXPATH];
48 CHAR sig[CCHMAXPATH];
49}
50ASSOC;
[2]51
[551]52typedef struct LINKASSOC
53{
54 CHAR *mask;
[985]55 PSZ pszCmdLine;
[551]56 CHAR *sig;
57 LONG offset;
58 ULONG flags;
[2]59 struct LINKASSOC *prev;
60 struct LINKASSOC *next;
[551]61}
62LINKASSOC;
[2]63
[551]64static LINKASSOC *asshead = NULL, *asstail = NULL;
65static BOOL assloaded = FALSE, replace = FALSE;
[506]66
[342]67static PSZ pszSrcFile = __FILE__;
68
[551]69MRESULT EXPENTRY AssocTextProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
[342]70{
[551]71 PFNWP oldproc = (PFNWP) WinQueryWindowPtr(hwnd, QWL_USER);
[2]72 static BOOL emphasized = FALSE;
73
[551]74 switch (msg) {
75 case DM_DRAGOVER:
76 if (!emphasized) {
77 emphasized = TRUE;
78 DrawTargetEmphasis(hwnd, emphasized);
79 }
[618]80 if (AcceptOneDrop(hwnd, mp1, mp2))
[551]81 return MRFROM2SHORT(DOR_DROP, DO_MOVE);
82 return MRFROM2SHORT(DOR_NEVERDROP, 0);
[2]83
[551]84 case DM_DRAGLEAVE:
85 if (emphasized) {
86 emphasized = FALSE;
87 DrawTargetEmphasis(hwnd, emphasized);
88 }
89 break;
[2]90
[551]91 case DM_DROPHELP:
92 DropHelp(mp1, mp2, hwnd, GetPString(IDS_ASSOCDROPHELPTEXT));
93 return 0;
[2]94
[551]95 case DM_DROP:
96 {
97 char szFrom[CCHMAXPATH + 5];
[2]98
[551]99 if (emphasized) {
100 emphasized = FALSE;
101 DrawTargetEmphasis(hwnd, emphasized);
[2]102 }
[618]103 if (GetOneDrop(hwnd, mp1, mp2, szFrom, CCHMAXPATH)) {
[551]104 strcat(szFrom, " %a");
105 WinSetWindowText(hwnd, szFrom);
106 }
107 }
108 return 0;
[2]109 }
[551]110 return (oldproc) ? oldproc(hwnd, msg, mp1, mp2) :
111 WinDefWindowProc(hwnd, msg, mp1, mp2);
[2]112}
113
[551]114VOID free_associations(VOID)
[342]115{
[551]116 LINKASSOC *info, *next;
[2]117
118 info = asshead;
[551]119 while (info) {
[2]120 next = info->next;
[1009]121 xfree(info->mask, pszSrcFile, __LINE__);
122 xfree(info->pszCmdLine, pszSrcFile, __LINE__);
123 xfree(info->sig, pszSrcFile, __LINE__);
124 xfree(info, pszSrcFile, __LINE__);
[2]125 info = next;
126 }
127 asshead = asstail = NULL;
128}
129
[551]130VOID load_associations(VOID)
[342]131{
[551]132 FILE *fp;
[2]133 LINKASSOC *info;
[985]134 PSZ pszCmdLine;
[551]135 CHAR mask[CCHMAXPATH + 24];
136 CHAR sig[CCHMAXPATH + 24];
137 CHAR offset[72];
138 CHAR flags[72];
[2]139
[551]140 if (asshead)
[2]141 free_associations();
142 assloaded = TRUE;
143 save_dir2(mask);
[551]144 if (mask[strlen(mask) - 1] != '\\')
145 strcat(mask, "\\");
146 strcat(mask, "ASSOC.DAT");
147 fp = _fsopen(mask, "r", SH_DENYWR);
[985]148 pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
149 if (!pszCmdLine) {
150 if (fp)
151 fclose(fp); //already complained
152 }
[342]153 if (fp) {
[551]154 while (!feof(fp)) {
155 if (!xfgets(mask, sizeof(mask), fp, pszSrcFile, __LINE__)) // fixme why +24?
156 break;
[2]157 mask[CCHMAXPATH] = 0;
[123]158 bstripcr(mask);
[551]159 if (!*mask || *mask == ';')
160 continue;
[985]161 if (!xfgets(pszCmdLine, MaxComLineStrg, fp, pszSrcFile, __LINE__) ||
[551]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! */
[985]166 pszCmdLine[MaxComLineStrg - 1] = 0;
167 bstripcr(pszCmdLine);
[2]168 sig[CCHMAXPATH] = 0;
[405]169 bstripcr(sig);
[2]170 offset[34] = 0;
[405]171 bstripcr(offset);
[2]172 flags[34] = 0;
[123]173 bstripcr(flags);
[985]174 if (!*pszCmdLine)
[551]175 continue;
176 info = xmallocz(sizeof(LINKASSOC), pszSrcFile, __LINE__);
[342]177 if (info) {
[985]178 info->pszCmdLine = xstrdup(pszCmdLine, pszSrcFile, __LINE__);
[551]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);
[985]184 if (!info->pszCmdLine || !info->mask) {
[1009]185 xfree(info->pszCmdLine, pszSrcFile, __LINE__);
186 xfree(info->mask, pszSrcFile, __LINE__);
187 xfree(info, pszSrcFile, __LINE__);
[551]188 break;
189 }
190 if (!asshead)
191 asshead = info;
192 else {
193 asstail->next = info;
194 info->prev = asstail;
195 }
196 asstail = info;
[2]197 }
198 }
199 fclose(fp);
200 }
201}
202
[985]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 }
[1009]235 xfree(pszDisplayStr, pszSrcFile, __LINE__);
[985]236 }
237}
238
[551]239VOID save_associations(VOID)
[342]240{
[2]241 LINKASSOC *info;
[551]242 FILE *fp;
243 CHAR s[CCHMAXPATH + 14];
[2]244
[551]245 if (!assloaded || !asshead)
[2]246 return;
247 info = asshead;
248#ifdef NEVER
[551]249 while (info) {
[2]250 next = info->next;
[551]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;
[2]262 }
263 }
264 info = next;
265 }
266#endif
267 save_dir2(s);
[551]268 if (s[strlen(s) - 1] != '\\')
269 strcat(s, "\\");
270 strcat(s, "ASSOC.DAT");
271 fp = xfopen(s, "w", pszSrcFile, __LINE__);
[342]272 if (fp) {
[551]273 fputs(GetPString(IDS_ASSOCFILETEXT), fp);
[2]274 info = asshead;
[551]275 while (info) {
[2]276 fprintf(fp,
[989]277 ";\n%0.*s\n%0.*s\n%0.*s\n%lu\n%lu\n",
[551]278 CCHMAXPATH,
[989]279 info->mask,
280 MaxComLineStrg,
[985]281 info->pszCmdLine,
[551]282 CCHMAXPATH,
283 (info->sig) ? info->sig : NullStr, info->offset, info->flags);
[2]284 info = info->next;
285 }
286 fclose(fp);
287 }
288}
289
[551]290LINKASSOC *add_association(ASSOC * addme)
[342]291{
[2]292 LINKASSOC *info;
293
[985]294 if (addme && *addme->pszCmdLine && *addme->mask) {
[2]295 info = asshead;
[551]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;
[2]301 info = info->next;
302 }
[551]303 if (!info) {
304 info = xmallocz(sizeof(LINKASSOC), pszSrcFile, __LINE__);
305 if (info) {
[985]306 info->pszCmdLine = xstrdup(addme->pszCmdLine, pszSrcFile, __LINE__);
[551]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;
[985]314 if (!info->pszCmdLine || !info->mask) {
[1009]315 xfree(info->pszCmdLine, pszSrcFile, __LINE__);
316 xfree(info->mask, pszSrcFile, __LINE__);
317 xfree(info, pszSrcFile, __LINE__);
[551]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 }
[2]331 }
332 }
333 }
334 return NULL;
335}
336
[551]337BOOL kill_association(ASSOC * killme)
[342]338{
[2]339 LINKASSOC *info;
340
[551]341 if (killme && *killme->mask) {
[2]342 info = asshead;
[551]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 }
[1009]361 xfree(info->pszCmdLine, pszSrcFile, __LINE__);
362 xfree(info->mask, pszSrcFile, __LINE__);
363 xfree(info->sig, pszSrcFile, __LINE__);
364 xfree(info, pszSrcFile, __LINE__);
[551]365 return TRUE;
[2]366 }
367 info = info->next;
368 }
369 }
370 return FALSE;
371}
372
[551]373INT ExecAssociation(HWND hwnd, CHAR * datafile)
[342]374{
[551]375 CHAR *file, sig[CCHMAXPATH], sigl[CCHMAXPATH], mask[CCHMAXPATH], *p;
376 FILE *fp;
377 BOOL didmatch, exclude;
378 ULONG offset;
[2]379 LINKASSOC *info;
380
[551]381 if (!assloaded)
[2]382 load_associations();
[551]383 if (!asshead)
[2]384 return -1;
[551]385 if (!datafile || !*datafile)
[2]386 return -1;
[551]387 file = strrchr(datafile, '\\');
388 if (!file)
389 file = strrchr(datafile, ':');
390 if (file)
[2]391 file++;
392 else
393 file = datafile;
394 info = asshead;
[551]395 while (info) {
396 strcpy(mask, info->mask);
397 p = strtok(mask, ";");
398 while (p) {
399 if (*p == '/') {
400 p++;
401 exclude = TRUE;
[2]402 }
403 else
[834]404 exclude = FALSE;
[832]405 didmatch = wildcard((strchr(p, '\\') ||
406 strchr(p, ':')) ? datafile : file, p, FALSE);
[551]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 }
[2]430 }
[551]431 if (didmatch) { /* got a match; do it... */
[2]432
[551]433 CHAR *list[2];
434 INT flags, rc;
435 BOOL dieafter = FALSE;
[2]436
[551]437 if (fAmAV2) {
[985]438 if (stristr(info->pszCmdLine, "AV2.EXE") ||
439 stristr(info->pszCmdLine, "AV2.CMD") || stristr(info->pszCmdLine, "<>"))
[551]440 return -1;
441 }
[985]442 if (!strcmp(info->pszCmdLine, "<>")) {
[551]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,
[985]460 info->pszCmdLine,
[551]461 flags,
[888]462 NULL, list, GetPString(IDS_EXECASSOCTITLETEXT),
463 pszSrcFile, __LINE__);
[551]464 if (rc != -1 && dieafter)
465 PostMsg((HWND) 0, WM_QUIT, MPVOID, MPVOID);
466 return rc;
[2]467 }
[551]468 p = strtok(0, ";");
[2]469 }
470 info = info->next;
471 }
472 return -1;
473}
474
[551]475MRESULT EXPENTRY AssocDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
[342]476{
[2]477 LINKASSOC *info;
[551]478 SHORT x, y;
[2]479
[551]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;
[2]502
[551]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;
[2]510
[551]511 case UM_UNDO:
512 {
[989]513 PSZ pszDisplayStr;
[2]514
[989]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));
[1009]542 xfree(pszDisplayStr, pszSrcFile, __LINE__);
[2]543 }
[551]544 }
545 return 0;
[2]546
[551]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) {
[2]557
[551]558 CHAR s[36];
[2]559
[551]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);
[985]569 WinSetDlgItemText(hwnd, ASS_CL, info->pszCmdLine);
[551]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;
[2]592
[551]593 *env = 0;
594 size = sizeof(env) - 1;
595 if (PrfQueryProfileData(fmprof,
[985]596 FM3Str, info->pszCmdLine, env, &size) && *env)
[551]597 WinSetDlgItemText(hwnd, ASS_ENVIRON, env);
598 else
599 WinSetDlgItemText(hwnd, ASS_ENVIRON, NullStr);
600 }
601 }
602 break;
[2]603 }
[551]604 }
605 return 0;
[2]606
[551]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;
[2]634
[551]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 {
[888]662 CHAR filename[CCHMAXPATH + 9], szfilename[CCHMAXPATH + 9];
[2]663
[551]664 *filename = 0;
[888]665 if (insert_filename(hwnd, filename, 2, FALSE) && *filename) {
666 BldQuotedFileName(szfilename, filename);
667 strcat(szfilename, " %a");
668 WinSetDlgItemText(hwnd, ASS_CL, szfilename);
[551]669 }
670 }
671 break;
[2]672
[551]673 case DID_OK:
674 {
675 ASSOC temp;
[918]676 CHAR dummy[34];
[920]677 PSZ pszWorkBuf;
[918]678 replace = FALSE;
[506]679
[985]680 memset(&temp, 0, sizeof(ASSOC));
681 temp.pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
682 if (!temp.pszCmdLine)
683 break; //already complained
684
[551]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));
[918]694 }
[985]695 pszWorkBuf = xmalloc(MaxComLineStrg, pszSrcFile, __LINE__);
696 if (!pszWorkBuf) {
[1009]697 xfree(temp.pszCmdLine, pszSrcFile, __LINE__);
[959]698 break; //already complained
[985]699 }
[551]700 WinQueryDlgItemText(hwnd, ASS_MASK, sizeof(temp.mask), temp.mask);
[985]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 }
[1009]706 xfree(pszWorkBuf, pszSrcFile, __LINE__);
[551]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);
[985]714 bstrip(temp.pszCmdLine);
[551]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))
[909]730 temp.flags |= PROMPT;
731 if (fCancelAction){
732 fCancelAction = FALSE;
[1009]733 xfree(temp.pszCmdLine, pszSrcFile, __LINE__);
[909]734 break;
735 }
736 else
[551]737 info = add_association(&temp);
738 if (!info)
739 WinDismissDlg(hwnd, 1); /* Runtime_Error(pszSrcFile, __LINE__, "add_association"); */
[985]740 else {
741 display_associations(hwnd, &temp, info);
[551]742 save_associations();
[985]743 }
[1009]744 xfree(temp.pszCmdLine, pszSrcFile, __LINE__);
[551]745 }
746 WinDismissDlg(hwnd, 1);
747 break;
[2]748
[551]749 case DID_CANCEL:
750 WinDismissDlg(hwnd, 0);
751 break;
[2]752
[551]753 case IDM_HELP:
754 if (hwndHelp)
755 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
756 MPFROM2SHORT(HELP_ASSOC, 0), MPFROMSHORT(HM_RESOURCEID));
757 break;
[2]758
[551]759 case ASS_ADD:
760 {
761 ASSOC temp;
[918]762 CHAR dummy[34];
[920]763 PSZ pszWorkBuf;
[985]764 replace = FALSE;
[2]765
[985]766 memset(&temp, 0, sizeof(ASSOC));
767 temp.pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
768 if (!temp.pszCmdLine)
[959]769 break; //already complained
[985]770 pszWorkBuf = xmalloc(MaxComLineStrg, pszSrcFile, __LINE__);
771 if (!pszWorkBuf) {
[1009]772 xfree(temp.pszCmdLine, pszSrcFile, __LINE__);
[985]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 }
[1009]781 xfree(pszWorkBuf, pszSrcFile, __LINE__);
[551]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);
[985]789 bstrip(temp.pszCmdLine);
[551]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))
[909]805 temp.flags |= PROMPT;
806 if (fCancelAction){
807 fCancelAction = FALSE;
[1009]808 xfree(temp.pszCmdLine, pszSrcFile, __LINE__);
[909]809 break;
810 }
811 else
812 info = add_association(&temp);
[551]813 //Add will fail if mask is not changed
814 if (info) {
[985]815 display_associations(hwnd, &temp, info);
[551]816 save_associations();
817 }
[1009]818 xfree(temp.pszCmdLine, pszSrcFile, __LINE__);
[551]819 }
820 break;
[506]821
[551]822 case ASS_DELETE:
823 {
824 ASSOC temp;
[985]825 CHAR dummy[34];
[506]826
[985]827 memset(&temp, 0, sizeof(ASSOC));
828 temp.pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
829 if (!temp.pszCmdLine)
830 break; //already complained
[551]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);
[985]840 if (kill_association(&temp)) {
[551]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();
[985]853 }
[1009]854 xfree(temp.pszCmdLine, pszSrcFile, __LINE__);
[551]855 }
[985]856
[551]857 break;
858 case ASS_REPLACE:
[506]859
[551]860 {
861 ASSOC temp;
[918]862 CHAR dummy[34];
[920]863 PSZ pszWorkBuf;
[985]864 replace = TRUE;
[506]865
[985]866 memset(&temp, 0, sizeof(ASSOC));
867 temp.pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
868 if (!temp.pszCmdLine)
869 break; //already complained
[551]870 y = (SHORT) WinSendDlgItemMsg(hwnd,
871 ASS_LISTBOX,
872 LM_QUERYSELECTION,
[918]873 MPFROMSHORT(LIT_CURSOR), MPVOID);
[985]874 pszWorkBuf = xmalloc(MaxComLineStrg, pszSrcFile, __LINE__);
875 if (!pszWorkBuf) {
[1009]876 xfree(temp.pszCmdLine, pszSrcFile, __LINE__);
[959]877 break; //already complained
[985]878 }
[551]879 WinQueryDlgItemText(hwnd, ASS_MASK, sizeof(temp.mask), temp.mask);
[985]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 }
[1009]885 xfree(pszWorkBuf, pszSrcFile, __LINE__);
[551]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);
[985]893 bstrip(temp.pszCmdLine);
[551]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]909 temp.flags |= PROMPT;
910 if (fCancelAction){
911 fCancelAction = FALSE;
[1009]912 xfree(temp.pszCmdLine, pszSrcFile, __LINE__);
[909]913 break;
914 }
915 else
916 info = add_association(&temp);
[551]917 if (info) {
[985]918 display_associations(hwnd, &temp, info);
[551]919 save_associations();
[985]920 }
[1009]921 xfree(temp.pszCmdLine, pszSrcFile, __LINE__);
[2]922 }
[551]923 {
924 ASSOC temp;
[985]925 CHAR dummy[34];
[551]926
[985]927 temp.pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
928 if (!temp.pszCmdLine)
929 break; //already complained
[551]930 WinSendDlgItemMsg(hwnd,
931 ASS_LISTBOX,
932 LM_SELECTITEM, MPFROMSHORT(y), MPFROMSHORT(TRUE));
[985]933 memset(temp.sig, 0, sizeof(temp.sig));
934 memset(temp.mask, 0, sizeof(temp.mask));
935 temp.offset = 0;
[551]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();
[985]957 }
[1009]958 xfree(temp.pszCmdLine, pszSrcFile, __LINE__);
[551]959 }
960 break;
961 }
962 return 0;
963 }
964 return WinDefDlgProc(hwnd, msg, mp1, mp2);
[2]965}
966
[551]967VOID EditAssociations(HWND hwnd)
[342]968{
[2]969 static CHAR stop = 0;
970
[551]971 if (stop)
[2]972 return;
973 stop++;
[551]974 if (!assloaded)
[2]975 load_associations();
[551]976 WinDlgBox(HWND_DESKTOP, hwnd, AssocDlgProc, FM3ModHandle, ASS_FRAME, NULL);
[2]977 stop = 0;
978}
[793]979
[985]980#pragma alloc_text(ASSOC2,free_commands,load_associations,save_associations,display_associations)
[793]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.