source: trunk/dll/command.c@ 1780

Last change on this file since 1780 was 1780, checked in by Gregg Young, 11 years ago

Fixed errors found by cppcheck. Most had the potential to cause difficult to reproduce traps. Also fixed retry code for failure to create an archive work directory and the failure of the mailto code to drop trailing >.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 40.8 KB
Line 
1
2/***********************************************************************
3
4 $Id: command.c 1780 2014-06-28 18:05:22Z gyoung $
5
6 Custom commands
7
8 Copyright (c) 1993-98 M. Kimes
9 Copyright (c) 2004, 2010 Steven H. Levine
10
11 01 Aug 04 SHL Rework lstrip/rstrip usage
12 06 Jun 05 SHL Drop unused code
13 14 Jul 06 SHL Use Runtime_Error
14 29 Jul 06 SHL Use xfgets_bstripcr
15 15 Aug 06 SHL Better can't add message
16 18 Sep 06 GKY Add replace command and update okay to add if changed
17 17 Feb 07 GKY Move error messages etc to string file
18 22 Mar 07 GKY Use QWL_USER
19 23 Mar 07 GKY Replace doesn't change item position
20 23 Mar 07 GKY Okay fails silently when item not changed
21 19 Apr 07 SHL Sync with AcceptOneDrop GetOneDrop mods
22 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
23 06 Jan 08 GKY Use NormalizeCmdLine to check program strings on entry
24 29 Feb 08 GKY Changes to enable user settable command line length
25 29 Feb 08 GKY Use xfree where appropriate
26 18 Jul 08 SHL Add Fortify support
27 19 Jul 08 GKY Replace save_dir2(dir) with pFM2SaveDirectory and use BldFullPathName
28 24 Aug 08 GKY Warn full drive on save of .DAT file; prevent loss of existing file
29 15 Oct 08 GKY Prevent asking to add %a on NormalizeCmdLine abort
30 21 Dec 09 GKY Fix the environment so it can be saved, deleted and used consistently.
31 21 Dec 09 GKY Allow command menu reorder without changing the "ID" or hot key for a command.
32 Added load_inicommand to load the IDs from the ini file.
33 21 Dec 09 GKY Added 20 new hot keys for commands.
34 21 Dec 09 GKY Added CheckExecutibleFlags to streamline code in command.c assoc.c & cmdline.c
35 27 Dec 09 GKY Moved Commands to the INI file this makes commands.dat obsolete
36 27 Dec 09 GKY Added QueryCommandSettings to streamline code
37 27 Dec 09 GKY Made command hotkeys user selectable.
38 17 JAN 10 GKY Changes to get working with Watcom 1.9 Beta (1/16/10).
39 Mostly cast CHAR CONSTANT * as CHAR *.
40 01 May 10 GKY Add ENVIRONMENT_SIZE variable to standardize this size everywhere.
41 01 May 10 GKY Changes to move environment storage to INI file
42 03 Jul 11 GKY Fixed problem with creation of duplicate command IDs.
43 24 Sep 11 GKY Fixed trap caused by selecting cancel from duplicate hotkey dialog if adding or replacing a command
44 28 Jun 14 GKY Fix errors identified with CPPCheck
45
46***********************************************************************/
47
48#include <stdlib.h>
49#include <string.h>
50#include <share.h>
51
52#define INCL_DOS
53#define INCL_WIN
54#define INCL_LONGLONG // dircnrs.h
55
56#include "fm3dll.h"
57#include "fm3dll2.h" // #define's for UM_*, control id's, etc.
58#include "notebook.h" // Data declaration(s)
59#include "init.h" // Data declaration(s)
60#include "mainwnd.h" // Data declaration(s)
61#include "newview.h" // Data declarations
62#include "fm3dlg.h"
63#include "fm3str.h"
64#include "tools.h"
65#include "arccnrs.h" // BldQuotedFileName
66#include "errutil.h" // Dos_Error...
67#include "strutil.h" // GetPString
68#include "droplist.h" // AcceptOneDrop, DropHelp, GetOneDrop
69#include "misc.h" // DrawTargetEmphasis
70#include "systemf.h" // ExecOnList
71#include "getnames.h" // insert_filename
72#include "wrappers.h" // xfgets
73#include "pathutil.h" // NormalizeCmdLine
74#include "command.h"
75#include "strips.h" // bstrip
76#include "dirs.h" // save_dir2
77#include "fortify.h"
78
79VOID load_inicommands(VOID);
80
81typedef struct
82{
83 PSZ pszCmdLine;
84 CHAR title[100];
85 CHAR env[ENVIRONMENT_SIZE];
86 ULONG flags;
87 ULONG ID;
88 ULONG HotKeyID;
89}
90COMMAND;
91
92BOOL QueryCommandSettings(HWND hwnd, COMMAND *temp);
93VOID save_commands(VOID);
94
95// Data defintions
96#pragma data_seg(DATA1)
97
98static PSZ pszSrcFile = __FILE__;
99static LINKCMDS *cmdtail;
100static BOOL UsedCommandIDs[300] = {FALSE};
101static BOOL UsedHotKeyIDs[40] = {FALSE};
102static PSZ pszCommandsList;
103static ULONG ulSizeCommandsList = 10000;
104static BOOL fLoadCommandsFromINI = FALSE;
105
106#pragma data_seg(GLOBAL2)
107LINKCMDS *cmdhead;
108BOOL cmdloaded;
109
110MRESULT EXPENTRY CommandTextProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
111{
112 PFNWP oldproc = (PFNWP) WinQueryWindowPtr(hwnd, QWL_USER);
113 static BOOL emphasized = FALSE;
114
115 switch (msg) {
116 case DM_DRAGOVER:
117 if (!emphasized) {
118 emphasized = TRUE;
119 DrawTargetEmphasis(hwnd, emphasized);
120 }
121 if (AcceptOneDrop(hwnd, mp1, mp2))
122 return MRFROM2SHORT(DOR_DROP, DO_MOVE);
123 return MRFROM2SHORT(DOR_NEVERDROP, 0);
124
125 case DM_DRAGLEAVE:
126 if (emphasized) {
127 emphasized = FALSE;
128 DrawTargetEmphasis(hwnd, emphasized);
129 }
130 break;
131
132 case DM_DROPHELP:
133 DropHelp(mp1, mp2, hwnd, GetPString(IDS_DROPCMDHELPTEXT));
134 return 0;
135
136 case DM_DROP:
137 {
138 char szFrom[CCHMAXPATH + 5];
139
140 if (emphasized) {
141 emphasized = FALSE;
142 DrawTargetEmphasis(hwnd, emphasized);
143 }
144 if (GetOneDrop(hwnd, mp1, mp2, szFrom, CCHMAXPATH)) {
145 strcat(szFrom, " %a");
146 WinSetWindowText(hwnd, szFrom);
147 }
148 }
149 return 0;
150 }
151 return (oldproc) ? oldproc(hwnd, msg, mp1, mp2) :
152 WinDefWindowProc(hwnd, msg, mp1, mp2);
153}
154
155MRESULT EXPENTRY ReOrderProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
156{
157 switch (msg) {
158 case WM_INITDLG:
159 if (!cmdhead) {
160 WinDismissDlg(hwnd, 0);
161 break;
162 }
163 {
164 LINKCMDS *info;
165 SHORT x;
166
167 info = cmdhead;
168 while (info) {
169 x = (SHORT) WinSendDlgItemMsg(hwnd, RE_ADDLISTBOX, LM_INSERTITEM,
170 MPFROMSHORT(LIT_END),
171 MPFROMP(info->title));
172 if (x < 0) {
173 Runtime_Error(pszSrcFile, __LINE__, "no cmd");
174 WinDismissDlg(hwnd, 0);
175 }
176 else {
177 WinSendDlgItemMsg(hwnd, RE_ADDLISTBOX, LM_SETITEMHANDLE,
178 MPFROMSHORT(x), MPFROMP(info));
179 }
180 info = info->next;
181 }
182 }
183 break;
184
185 case WM_CONTROL:
186 return 0;
187
188 case WM_COMMAND:
189 switch (SHORT1FROMMP(mp1)) {
190 case DID_CANCEL:
191 WinDismissDlg(hwnd, 0);
192 break;
193
194 case DID_OK:
195 {
196 LINKCMDS *temphead = NULL, *info, *last = NULL, *temptail = NULL;
197 SHORT sSelect, numitems;
198
199 sSelect = 0;
200 numitems = (SHORT) WinSendDlgItemMsg(hwnd, RE_REMOVELISTBOX,
201 LM_QUERYITEMCOUNT,
202 MPVOID, MPVOID);
203 while (numitems) {
204 info = (LINKCMDS *) WinSendDlgItemMsg(hwnd, RE_REMOVELISTBOX,
205 LM_QUERYITEMHANDLE,
206 MPFROMSHORT(sSelect++),
207 MPVOID);
208 if (info) {
209 if (!temphead) {
210 temphead = info;
211 info->prev = NULL;
212 }
213 else {
214 last->next = info;
215 info->prev = last;
216 }
217 temptail = info;
218 last = info;
219 info->next = NULL;
220 }
221 numitems--;
222 }
223 sSelect = 0;
224 numitems = (SHORT) WinSendDlgItemMsg(hwnd, RE_ADDLISTBOX,
225 LM_QUERYITEMCOUNT,
226 MPVOID, MPVOID);
227 while (numitems) {
228 info = (LINKCMDS *) WinSendDlgItemMsg(hwnd, RE_ADDLISTBOX,
229 LM_QUERYITEMHANDLE,
230 MPFROMSHORT(sSelect++),
231 MPVOID);
232 if (info) {
233 if (!temphead) {
234 temphead = info;
235 info->prev = NULL;
236 }
237 else {
238 last->next = info;
239 info->prev = last;
240 }
241 temptail = info;
242 last = info;
243 info->next = NULL;
244 }
245 numitems--;
246 }
247 cmdhead = temphead;
248 cmdtail = temptail;
249 }
250 WinDismissDlg(hwnd, 1);
251 break;
252
253 case IDM_HELP:
254 if (hwndHelp)
255 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
256 MPFROM2SHORT(HELP_REORDERCOMMANDS, 0),
257 MPFROMSHORT(HM_RESOURCEID));
258 break;
259
260 case RE_ADD:
261 {
262 SHORT sSelect, x;
263 LINKCMDS *info;
264
265 sSelect = (SHORT) WinSendDlgItemMsg(hwnd, RE_ADDLISTBOX,
266 LM_QUERYSELECTION,
267 MPFROMSHORT(LIT_FIRST), MPVOID);
268 while (sSelect >= 0) {
269 info = (LINKCMDS *) WinSendDlgItemMsg(hwnd, RE_ADDLISTBOX,
270 LM_QUERYITEMHANDLE,
271 MPFROMSHORT(sSelect), MPVOID);
272 if (info) {
273 x = (SHORT) WinSendDlgItemMsg(hwnd, RE_REMOVELISTBOX,
274 LM_INSERTITEM,
275 MPFROM2SHORT(LIT_END, 0),
276 MPFROMP(info->title));
277 if (x >= 0) {
278 WinSendDlgItemMsg(hwnd, RE_REMOVELISTBOX,
279 LM_SETITEMHANDLE,
280 MPFROMSHORT(x), MPFROMP(info));
281 WinSendDlgItemMsg(hwnd, RE_ADDLISTBOX, LM_DELETEITEM,
282 MPFROMSHORT(sSelect), MPVOID);
283 }
284 }
285 else
286 WinSendDlgItemMsg(hwnd, RE_ADDLISTBOX, LM_SELECTITEM,
287 MPFROMSHORT(sSelect), MPFROMSHORT(FALSE));
288 sSelect = (USHORT) WinSendDlgItemMsg(hwnd, RE_ADDLISTBOX,
289 LM_QUERYSELECTION,
290 MPFROMSHORT(LIT_FIRST),
291 MPVOID);
292 }
293 }
294 break;
295
296 case RE_REMOVE:
297 {
298 SHORT sSelect, x;
299 LINKCMDS *info;
300
301 sSelect = (SHORT) WinSendDlgItemMsg(hwnd, RE_REMOVELISTBOX,
302 LM_QUERYSELECTION,
303 MPFROMSHORT(LIT_FIRST), MPVOID);
304 while (sSelect >= 0) {
305 info = (LINKCMDS *) WinSendDlgItemMsg(hwnd, RE_REMOVELISTBOX,
306 LM_QUERYITEMHANDLE,
307 MPFROMSHORT(sSelect), MPVOID);
308 if (info) {
309 x = (SHORT) WinSendDlgItemMsg(hwnd, RE_ADDLISTBOX,
310 LM_INSERTITEM,
311 MPFROM2SHORT(LIT_END, 0),
312 MPFROMP(info->title));
313 if (x >= 0) {
314 WinSendDlgItemMsg(hwnd, RE_ADDLISTBOX,
315 LM_SETITEMHANDLE,
316 MPFROMSHORT(x), MPFROMP(info));
317 WinSendDlgItemMsg(hwnd, RE_REMOVELISTBOX, LM_DELETEITEM,
318 MPFROMSHORT(sSelect), MPVOID);
319 }
320 }
321 else
322 WinSendDlgItemMsg(hwnd, RE_REMOVELISTBOX, LM_SELECTITEM,
323 MPFROMSHORT(sSelect), MPFROMSHORT(FALSE));
324 sSelect = (USHORT) WinSendDlgItemMsg(hwnd, RE_REMOVELISTBOX,
325 LM_QUERYSELECTION,
326 MPFROMSHORT(LIT_FIRST),
327 MPVOID);
328 }
329 }
330 break;
331 }
332 return 0;
333 }
334 return WinDefDlgProc(hwnd, msg, mp1, mp2);
335}
336
337CHAR *command_title(INT cx)
338{
339 static CHAR duh[] = "???";
340 LINKCMDS *info;
341 INT x = 0;
342
343 if (!cmdloaded)
344 load_commands();
345 info = cmdhead;
346 while (info) {
347 if (x == cx)
348 return info->title;
349 info = info->next;
350 }
351 return duh;
352}
353
354VOID free_commands(VOID)
355{
356 LINKCMDS *info, *next;
357
358 info = cmdhead;
359 while (info) {
360 next = info->next;
361 xfree(info->title, pszSrcFile, __LINE__);
362 xfree(info->pszCmdLine, pszSrcFile, __LINE__);
363 xfree(info->env, pszSrcFile, __LINE__);
364 free(info);
365 info = next;
366 }
367 free(pszCommandsList);
368 cmdhead = cmdtail = NULL;
369}
370
371VOID load_commands(VOID)
372{
373 FILE *fp;
374 LINKCMDS *info;
375 PSZ pszCmdLine;
376 CHAR title[100];
377 CHAR flags[34];
378 CHAR *moder = "r";
379 ULONG size;
380
381 size = sizeof(BOOL);
382 PrfQueryProfileData(fmprof, FM3Str, "COMMANDS.LoadCommandsFromINI",
383 &fLoadCommandsFromINI, &size);
384 if (!fLoadCommandsFromINI) {
385 if (cmdhead)
386 free_commands();
387 cmdloaded = TRUE;
388 pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
389 pszCommandsList = xmallocz(ulSizeCommandsList, pszSrcFile, __LINE__);
390 if (pszCmdLine) {
391 BldFullPathName(pszCmdLine, pFM2SaveDirectory, PCSZ_COMMANDSDAT);
392 fp = xfsopen(pszCmdLine, moder, SH_DENYWR, pszSrcFile, __LINE__, TRUE);
393 if (fp) {
394 while (!feof(fp)) {
395 if (!xfgets_bstripcr(title, sizeof(title), fp, pszSrcFile, __LINE__))
396 break;
397 if (!*title || *title == ';')
398 continue;
399 if (!xfgets_bstripcr(pszCmdLine, MaxComLineStrg, fp, pszSrcFile, __LINE__))
400 break; // error!
401 if (!xfgets_bstripcr(flags, sizeof(flags), fp, pszSrcFile, __LINE__))
402 break;
403 flags[33] = 0;
404 if (!pszCmdLine)
405 continue;
406 info = xmallocz(sizeof(LINKCMDS), pszSrcFile, __LINE__);
407 if (info) {
408 # ifdef FORTIFY
409 Fortify_SetOwner(info, 1);
410 Fortify_SetScope(info, 1);
411 # endif
412 info->pszCmdLine = xstrdup(pszCmdLine, pszSrcFile, __LINE__);
413
414 if (pszCommandsList) {
415 strcpy(pszCommandsList + strlen(pszCommandsList), title);
416 strcpy(pszCommandsList + strlen(pszCommandsList), ";");
417 }
418 info->title = xstrdup(title, pszSrcFile, __LINE__);
419 info->flags = atol(flags);
420 if (!info->pszCmdLine || !info->title) {
421 xfree(info->pszCmdLine, pszSrcFile, __LINE__);
422 xfree(info->title, pszSrcFile, __LINE__);
423 free(info);
424 break;
425 }
426 # ifdef FORTIFY
427 Fortify_SetOwner(info->pszCmdLine, 1);
428 Fortify_SetScope(info->pszCmdLine, 1);
429 Fortify_SetOwner(info->title, 1);
430 Fortify_SetScope(info->title, 1);
431 # endif
432 if (!cmdhead)
433 cmdhead = info;
434 else {
435 cmdtail->next = info;
436 info->prev = cmdtail;
437 }
438 cmdtail = info;
439 }
440 }
441 free(pszCmdLine);
442 fclose(fp);
443 if (pszCommandsList) {
444 ulSizeCommandsList = strlen(pszCommandsList) + 1;
445 }
446 }
447 }
448 }
449 load_inicommands();
450}
451
452/**
453 * load_inicommand loads the data from the ini file into an info struct
454 * after COMMANDS.DAT has been loaded; It generates new IDs where necessary
455 * it saves the environment from the old ini key and deletes it as needed
456 **/
457
458VOID load_inicommands(VOID)
459{
460 LINKCMDS *info;;
461 INT x = 0;
462 INT y = 0;
463 ULONG ID = 0;
464 ULONG HotKeyID = 0;
465 CHAR env[ENVIRONMENT_SIZE];
466 CHAR key[120];
467 CHAR szTitle[100];
468 ULONG size;
469 CHAR *p, *pp;
470 PSZ pszCmdLine;
471 ULONG flags;
472
473# ifdef FORTIFY
474 Fortify_EnterScope();
475# endif
476 pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
477 if (pszCmdLine) {
478 if (fLoadCommandsFromINI) {
479 if (cmdhead)
480 free_commands();
481 cmdloaded = TRUE;
482 size = sizeof(ULONG);
483 PrfQueryProfileData(fmprof, FM3Str, "COMMANDS.SizeSortOrder",
484 &ulSizeCommandsList, &size);
485 pszCommandsList = xmallocz(ulSizeCommandsList, pszSrcFile, __LINE__);
486 if (pszCommandsList) {
487 PrfQueryProfileString(fmprof, FM3Str, "COMMANDS.SortOrder",
488 NullStr, pszCommandsList, ulSizeCommandsList);
489 p = pszCommandsList;
490 while (*p == ';')
491 p++;
492 while (*p) {
493 *szTitle = 0;
494 pp = szTitle;
495 while (*p && *p != ';')
496 *pp++ = *p++;
497 *pp = 0;
498 while (*p == ';')
499 p++;
500 if (*szTitle) {
501 bstripcr(szTitle);
502 sprintf(key, "COMMAND.%sID", szTitle);
503 size = sizeof(ULONG);
504 PrfQueryProfileData(fmprof, FM3Str, key, &ID, &size);
505 UsedCommandIDs[ID - IDM_COMMANDSTART] = TRUE; // No need to use profile just count them GKY 02 JUL 11
506 sprintf(key, "COMMAND.%sHotKeyID", szTitle);
507 size = sizeof(ULONG);
508 PrfQueryProfileData(fmprof, FM3Str, key, &HotKeyID, &size);
509 UsedHotKeyIDs[HotKeyID - IDM_COMMANDNUM0] = TRUE; // No need to use profile just count them GKY 02 JUL 11
510 sprintf(key, "COMMAND.%sflags", szTitle);
511 size = sizeof(ULONG);
512 PrfQueryProfileData(fmprof, FM3Str, key, &flags, &size);
513 sprintf(key, "COMMAND.%senv", szTitle);
514 PrfQueryProfileString(fmprof, FM3Str, key, NullStr, env, sizeof(env));
515 sprintf(key, "COMMAND.%sCmdLine", szTitle);
516 PrfQueryProfileString(fmprof, FM3Str, key, NullStr, pszCmdLine, MaxComLineStrg);
517 }
518 info = xmallocz(sizeof(LINKCMDS), pszSrcFile, __LINE__);
519 if (info) {
520 # ifdef FORTIFY
521 Fortify_SetOwner(info, 1);
522 Fortify_SetScope(info, 1);
523 # endif
524 info->pszCmdLine = xstrdup(pszCmdLine, pszSrcFile, __LINE__);
525 info->title = xstrdup(szTitle, pszSrcFile, __LINE__);
526 info->flags = flags;
527 if (env != NullStr)
528 info->env = xstrdup(env, pszSrcFile, __LINE__);
529 info->ID = ID;
530 info->HotKeyID = HotKeyID;
531 if (!info->pszCmdLine || !info->title) {
532 xfree(info->pszCmdLine, pszSrcFile, __LINE__);
533 xfree(info->title, pszSrcFile, __LINE__);
534 xfree(info->env, pszSrcFile, __LINE__);
535 free(info);
536 break;
537 }
538 if (!cmdhead)
539 cmdhead = info;
540 else {
541 cmdtail->next = info;
542 info->prev = cmdtail;
543 }
544 cmdtail = info;
545 }
546 }
547 }
548 }
549 else {
550 info = cmdhead;
551 while (info) {
552 bstripcr(info->title);
553 sprintf(key, "COMMAND.%sID", info->title);
554 size = sizeof(ULONG);
555 PrfQueryProfileData(fmprof, FM3Str, key, &ID, &size);
556 sprintf(key, "COMMAND.%sHotKeyID", info->title);
557 size = sizeof(ULONG);
558 PrfQueryProfileData(fmprof, FM3Str, key, &HotKeyID, &size);
559 sprintf(key, "COMMAND.%senv", info->title);
560 PrfQueryProfileString(fmprof, FM3Str, key, NullStr, env, sizeof(env));
561 if (ID != 0) {
562 if (env != NullStr)
563 info->env = xstrdup(env, pszSrcFile, __LINE__);
564 info->ID = ID;
565 info->HotKeyID = HotKeyID;
566 }
567 //This updates the old commands.dat file to the new format
568 //assigning the IDs based on file order or on next available ID
569 else {
570 for (x = 0; x < 300; x++) {
571 if (!UsedCommandIDs[x]) {
572 ID = info->ID = IDM_COMMANDSTART + x;
573 UsedCommandIDs[x] = TRUE;
574 for (y = 0; y < 40; y++) {
575 if (!UsedHotKeyIDs[y]) {
576 HotKeyID = info->HotKeyID = IDM_COMMANDNUM0 + y;
577 UsedHotKeyIDs[y] = TRUE;
578 break;
579 }
580 }
581 break;
582 }
583 if (x == 299)
584 saymsg(MB_OK | MB_ICONEXCLAMATION , HWND_DESKTOP,
585 GetPString(IDS_COMMANDSLIMITTITLETEXT),
586 GetPString(IDS_COMMANDSLIMITREACHEDTEXT ));
587 }
588 PrfQueryProfileString(fmprof, FM3Str, info->pszCmdLine, NullStr, env, sizeof(env));
589 info->env = xstrdup(env, pszSrcFile, __LINE__);
590 }
591 ID = 0;
592 HotKeyID = 0;
593 info = info->next;
594 }
595 fLoadCommandsFromINI = TRUE;
596 save_commands();
597 }
598 free(pszCmdLine);
599 }
600}
601
602VOID save_commands(VOID)
603{
604 LINKCMDS *info;
605 CHAR key[120];
606
607 if (!cmdloaded || !cmdhead)
608 return;
609
610 info = cmdhead;
611 pszCommandsList[0] = 0;
612 while (info) {
613 sprintf(key, "COMMAND.%sflags", info->title);
614 PrfWriteProfileData(fmprof, FM3Str, key, &info->flags, sizeof(ULONG));
615 sprintf(key, "COMMAND.%sCmdLine", info->title);
616 PrfWriteProfileString(fmprof, FM3Str, key, info->pszCmdLine);
617 bstripcr(info->title);
618 sprintf(key, "COMMAND.%sID", info->title);
619 PrfWriteProfileData(fmprof, FM3Str, key, &info->ID, sizeof(INT));
620 UsedCommandIDs[info->ID - IDM_COMMANDSTART] = TRUE;
621 sprintf(key, "COMMAND.%sHotKeyID", info->title);
622 PrfWriteProfileData(fmprof, FM3Str, key, &info->HotKeyID, sizeof(INT));
623 UsedHotKeyIDs[info->HotKeyID - IDM_COMMANDNUM0] = TRUE;
624 if (info->env != NullStr) {
625 sprintf(key, "COMMAND.%senv", info->title);
626 PrfWriteProfileString(fmprof, FM3Str, key, info->env);
627 }
628 if ((strlen(pszCommandsList) + strlen(info->title) + 1) > ulSizeCommandsList)
629 pszCommandsList = xrealloc(pszCommandsList,
630 ulSizeCommandsList + strlen(info->title) + 1,
631 pszSrcFile, __LINE__);
632 strcpy(pszCommandsList + strlen(pszCommandsList), info->title);
633 strcpy(pszCommandsList + strlen(pszCommandsList), ";");
634 info = info->next;
635 } // while info
636 PrfWriteProfileData(fmprof, FM3Str, "COMMANDS.UsedCommandIDs", &UsedCommandIDs,
637 sizeof(BOOL) * 300); // left for backward compatability GKY 02 Jul 11
638 PrfWriteProfileData(fmprof, FM3Str, "COMMANDS.UsedHotKeyIDs", &UsedHotKeyIDs,
639 sizeof(BOOL) * 40);// left for backward compatability GKY 02 Jul 11
640 ulSizeCommandsList = strlen(pszCommandsList) + 1;
641 PrfWriteProfileData(fmprof, FM3Str, "COMMANDS.SizeSortOrder",
642 &ulSizeCommandsList, sizeof(ULONG));
643 PrfWriteProfileString(fmprof, FM3Str, "COMMANDS.SortOrder", pszCommandsList);
644 PrfWriteProfileData(fmprof, FM3Str, "COMMANDS.LoadCommandsFromINI",
645 &fLoadCommandsFromINI, sizeof(BOOL));
646}
647
648//== add_command() Add command to list ==
649
650LINKCMDS *add_command(COMMAND *addme, BOOL fDontCheckHotKey)
651{
652 LINKCMDS *info;
653 INT x;
654 INT y;
655 APIRET ret;
656
657 if (!addme || !*addme->pszCmdLine || !*addme->title)
658 return NULL; // No data
659# ifdef FORTIFY
660 Fortify_EnterScope();
661# endif
662 info = cmdhead;
663 while (info) {
664 if (!stricmp(info->title, addme->title))
665 return NULL; // Got a dup
666 info = info->next;
667 }
668 if (!fDontCheckHotKey && UsedHotKeyIDs[addme->HotKeyID - IDM_COMMANDNUM0]) {
669 info = cmdhead;
670 while (info) {
671 if (info->HotKeyID == addme->HotKeyID) { //avoid assigning hot key to multiple commands
672 ret = saymsg(MB_YESNOCANCEL, HWND_DESKTOP, NullStr,
673 GetPString(IDS_DUPLICATEHOTKEYTEXT));
674 if (ret == MBID_YES) {
675 info->HotKeyID = 0;
676 UsedHotKeyIDs[addme->HotKeyID - IDM_COMMANDNUM0] = FALSE;
677 break;
678 }
679 else if (ret == MBID_NO) {
680 addme->HotKeyID = 0;
681 break;
682 }
683 else
684 return (LINKCMDS *) -1;
685 }
686 info = info->next;
687 }
688 }
689 info = xmallocz(sizeof(LINKCMDS), pszSrcFile, __LINE__);
690 if (!info)
691 return NULL;
692 info->pszCmdLine = xstrdup(addme->pszCmdLine, pszSrcFile, __LINE__);
693 info->title = xstrdup(addme->title, pszSrcFile, __LINE__);
694 info->HotKeyID = addme->HotKeyID;
695 info->ID = addme->ID;
696 if (info->HotKeyID >= IDM_COMMANDNUM0 && info->HotKeyID <= IDM_COMMANDNUM39) {
697 UsedHotKeyIDs[info->HotKeyID - IDM_COMMANDNUM0] = TRUE;
698 }
699 else
700 info->HotKeyID = 0;
701 if (!info->ID) {
702 //profile updated by save_commands
703 for (x = 0; x < 300; x++) {
704 if (!UsedCommandIDs[x]) {
705 info->ID = IDM_COMMANDSTART + x;
706 UsedCommandIDs[x] = TRUE;
707 if (!info->HotKeyID && !fDontCheckHotKey) {
708 for (y = 0; y < 40; y++) {
709 if (!UsedHotKeyIDs[y]) {
710 info->HotKeyID = IDM_COMMANDNUM0 + y;
711 UsedHotKeyIDs[y] = TRUE;
712 break;
713 }
714 }
715 }
716 break;
717 }
718 if (x == 299)
719 saymsg(MB_OK | MB_ICONEXCLAMATION , HWND_DESKTOP,
720 GetPString(IDS_COMMANDSLIMITTITLETEXT),
721 GetPString(IDS_COMMANDSLIMITREACHEDTEXT ));
722 }
723 }
724 if (addme->flags)
725 info->flags = addme->flags;
726 if (addme->env)
727 info->env = xstrdup(addme->env, pszSrcFile, __LINE__);
728 if (!info->pszCmdLine || !info->title || !info->ID) {
729 xfree(info->pszCmdLine, pszSrcFile, __LINE__);
730 xfree(info->title, pszSrcFile, __LINE__);
731 xfree(info->env, pszSrcFile, __LINE__);
732 free(info);
733 return NULL;
734 }
735 if (!cmdhead) // only item in list
736 cmdhead = cmdtail = info;
737 else {
738 // place at tail
739 cmdtail->next = info;
740 info->prev = cmdtail;
741 cmdtail = info;
742 }
743 pszCommandsList = xrealloc(pszCommandsList, ulSizeCommandsList + strlen(info->title) + 1,
744 pszSrcFile, __LINE__);
745 if (pszCommandsList) {
746 strcpy(pszCommandsList + strlen(pszCommandsList), info->title);
747 strcpy(pszCommandsList + strlen(pszCommandsList), ";");
748 ulSizeCommandsList = ulSizeCommandsList + strlen(info->title) + 1;
749 }
750 else {
751 pszCommandsList = xmallocz(ulSizeCommandsList, pszSrcFile, __LINE__);
752 if (pszCommandsList)
753 PrfQueryProfileString(fmprof, FM3Str, "COMMANDS.SortOrder",
754 NullStr, pszCommandsList, ulSizeCommandsList);
755 return 0;
756 }
757 return info;
758}
759
760BOOL kill_command(CHAR * killme)
761{
762 LINKCMDS *info;
763
764 if (killme && *killme) {
765 info = cmdhead;
766 while (info) {
767 if (!stricmp(info->title, killme)) {
768 UsedCommandIDs[info->ID - IDM_COMMANDSTART] = FALSE;
769 if (info->HotKeyID)
770 UsedHotKeyIDs[info->HotKeyID - IDM_COMMANDNUM0] = FALSE;
771 if (info == cmdhead) {
772 cmdhead = info->next;
773 if (info == cmdtail)
774 cmdtail = info->prev;
775 }
776 else {
777 if (info->next)
778 (info->next)->prev = info->prev;
779 if (info->prev)
780 (info->prev)->next = info->next;
781 if (info == cmdtail)
782 cmdtail = info->prev;
783 }
784 xfree(info->pszCmdLine, pszSrcFile, __LINE__);
785 xfree(info->title, pszSrcFile, __LINE__);
786 xfree(info->env, pszSrcFile, __LINE__);
787 free(info);
788 return TRUE;
789 }
790 info = info->next;
791 }
792 }
793# ifdef FORTIFY
794 Fortify_LeaveScope();
795# endif
796 return FALSE;
797}
798
799BOOL QueryCommandSettings(HWND hwnd, COMMAND *temp)
800{
801 PSZ pszWorkBuf;
802 APIRET ret;
803 CHAR env[ENVIRONMENT_SIZE];
804 INT x;
805
806 pszWorkBuf = xmalloc(MaxComLineStrg, pszSrcFile, __LINE__);
807 if (!pszWorkBuf) {
808 return FALSE; //already complained
809 }
810 WinQueryDlgItemText(hwnd, CMD_CL, MaxComLineStrg, temp->pszCmdLine);
811 NormalizeCmdLine(pszWorkBuf, temp->pszCmdLine);
812 memcpy(temp->pszCmdLine, pszWorkBuf, strlen(pszWorkBuf) + 1);
813 free(pszWorkBuf);
814 if (fCancelAction) {
815 fCancelAction = FALSE;
816 return FALSE;
817 }
818 if (!strchr(temp->pszCmdLine, '%')) {
819 ret = saymsg(MB_YESNO,
820 HWND_DESKTOP,
821 NullStr,
822 GetPString(IDS_TOACTONSELECTEDTEXT));
823 if (ret == MBID_YES)
824 strcat(temp->pszCmdLine, " %a");
825 }
826 WinQueryDlgItemText(hwnd, CMD_TITLE, sizeof(temp->title), temp->title);
827 bstripcr(temp->title);
828 temp->flags = CheckExecutibleFlags(hwnd, 3);
829 *env = 0;
830 WinQueryDlgItemText(hwnd, CMD_ENVIRON, ENVIRONMENT_SIZE - 1, env);
831 bstripcr(env);
832 if (*env)
833 strcpy(temp->env, env);
834 x = (SHORT) WinSendDlgItemMsg(hwnd, CMD_HOTKEY,
835 LM_QUERYSELECTION,
836 MPFROMSHORT(LIT_FIRST), MPVOID);
837 if (x < 40)
838 temp->HotKeyID = x + IDM_COMMANDNUM0;
839 else
840 temp->HotKeyID = 0;
841 //DbgMsg(pszSrcFile, __LINE__, "info %i", temp->HotKeyID);
842 return TRUE;
843}
844
845MRESULT EXPENTRY CommandDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
846{
847 SHORT x, y;
848 LINKCMDS *info;
849
850# ifdef FORTIFY
851 Fortify_EnterScope();
852# endif
853 switch (msg) {
854 case WM_INITDLG:
855 WinSendDlgItemMsg(hwnd, CMD_LISTBOX, LM_DELETEALL, MPVOID, MPVOID);
856 WinSendDlgItemMsg(hwnd, CMD_CL, EM_SETTEXTLIMIT,
857 MPFROM2SHORT(MaxComLineStrg - 1, 0), MPVOID);
858 WinSendDlgItemMsg(hwnd, CMD_TITLE, EM_SETTEXTLIMIT,
859 MPFROM2SHORT(99, 0), MPVOID);
860 WinSetDlgItemText(hwnd, CMD_CL, NullStr);
861 WinSetDlgItemText(hwnd, CMD_TITLE, NullStr);
862 WinCheckButton(hwnd, CMD_DEFAULT, TRUE);
863 WinCheckButton(hwnd, CMD_PROMPT, FALSE);
864 WinCheckButton(hwnd, CMD_ONCE, FALSE);
865 info = cmdhead;
866 while (info) {
867 x = (SHORT) WinSendDlgItemMsg(hwnd, CMD_LISTBOX, LM_INSERTITEM,
868 MPFROM2SHORT(LIT_END, 0),
869 MPFROMP(info->title));
870 if (x >= 0)
871 WinSendDlgItemMsg(hwnd, CMD_LISTBOX, LM_SETITEMHANDLE,
872 MPFROMSHORT(x), MPFROMP(info));
873 info = info->next;
874 }
875 WinSendDlgItemMsg(hwnd, CMD_LISTBOX, LM_SELECTITEM,
876 MPFROMSHORT(0), MPFROMSHORT(TRUE));
877 {
878 PFNWP oldproc;
879
880 oldproc = WinSubclassWindow(WinWindowFromID(hwnd, CMD_CL),
881 (PFNWP) CommandTextProc);
882 if (oldproc)
883 WinSetWindowPtr(WinWindowFromID(hwnd, CMD_CL), QWL_USER, (PVOID) oldproc);
884 }
885 break;
886
887 case WM_CONTROL:
888 if (SHORT1FROMMP(mp1) == CMD_LISTBOX) {
889 switch (SHORT2FROMMP(mp1)) {
890 case LN_ENTER:
891 case LN_SELECT:
892 x = (SHORT) WinSendDlgItemMsg(hwnd, CMD_LISTBOX,
893 LM_QUERYSELECTION,
894 MPFROMSHORT(LIT_FIRST), MPVOID);
895 if (x >= 0) {
896 info = (LINKCMDS *) WinSendDlgItemMsg(hwnd, CMD_LISTBOX,
897 LM_QUERYITEMHANDLE,
898 MPFROMSHORT(x), MPVOID);
899 if (!info) {
900 Runtime_Error(pszSrcFile, __LINE__, "LM_QUERYITEMHANDLE");
901 break;
902 }
903 WinSetDlgItemText(hwnd, CMD_CL, info->pszCmdLine);
904 if (!(info->flags & 1023))
905 WinCheckButton(hwnd, CMD_DEFAULT, TRUE);
906 else {
907 if (info->flags & FULLSCREEN)
908 WinCheckButton(hwnd, CMD_FULLSCREEN, TRUE);
909 else if (info->flags & MINIMIZED)
910 WinCheckButton(hwnd, CMD_MINIMIZED, TRUE);
911 else if (info->flags & MAXIMIZED)
912 WinCheckButton(hwnd, CMD_MAXIMIZED, TRUE);
913 else if (info->flags & INVISIBLE)
914 WinCheckButton(hwnd, CMD_INVISIBLE, TRUE);
915 }
916 WinCheckButton(hwnd, CMD_PROMPT, ((info->flags & PROMPT) != 0));
917 WinCheckButton(hwnd, CMD_KEEP, ((info->flags & KEEP) != 0));
918 WinCheckButton(hwnd, CMD_ONCE, ((info->flags & ONCE) != 0));
919 WinSetDlgItemText(hwnd, CMD_TITLE, info->title);
920 if (info->env)
921 WinSetDlgItemText(hwnd, CMD_ENVIRON, info->env);
922 else
923 WinSetDlgItemText(hwnd, CMD_ENVIRON, NullStr);
924 for (x = 0; x < 40; x++) {
925 CHAR s[CCHMAXPATH + 24];
926
927 sprintf(s, "%s%s%s",
928 x < IDM_COMMANDNUM20 - IDM_COMMANDNUM0 ? "Ctrl+" : NullStr,
929 x > IDM_COMMANDNUM19 - IDM_COMMANDNUM0 ? "Alt+" : NullStr,
930 (x > IDM_COMMANDNUM9 - IDM_COMMANDNUM0 &&
931 x < IDM_COMMANDNUM20 - IDM_COMMANDNUM0) ||
932 x > IDM_COMMANDNUM29 - IDM_COMMANDNUM0 ? "Shift+" : NullStr);
933 sprintf(&s[strlen(s)], "%d", (x % 10) + 1 == 10 ? 0 : (x % 10) + 1);
934 sprintf(&s[strlen(s)], " %s", UsedHotKeyIDs[x] ? "(in use)" : NullStr);
935 WinSendMsg(WinWindowFromID(hwnd, CMD_HOTKEY), LM_INSERTITEM,
936 MPFROM2SHORT(LIT_END, 0), MPFROMP(s));
937 if (x == 39)
938 WinSendMsg(WinWindowFromID(hwnd, CMD_HOTKEY), LM_INSERTITEM,
939 MPFROM2SHORT(LIT_END, 0), MPFROMP("none"));
940 if (info->HotKeyID == x + IDM_COMMANDNUM0)
941 WinSendMsg(WinWindowFromID(hwnd, CMD_HOTKEY), LM_SELECTITEM,
942 MPFROM2SHORT(x, 0), MPFROMLONG(TRUE));
943 if (x == 39 && info->HotKeyID == 0)
944 WinSendMsg(WinWindowFromID(hwnd, CMD_HOTKEY), LM_SELECTITEM,
945 MPFROM2SHORT(x + 1, 0), MPFROMLONG(TRUE));
946 } // for
947 }
948 break;
949 }
950 }
951 return 0;
952
953 case WM_COMMAND:
954 switch (SHORT1FROMMP(mp1)) {
955 case CMD_FIND:
956 {
957 CHAR filename[CCHMAXPATH + 9], szfilename[CCHMAXPATH + 9];
958
959 *filename = 0;
960 if (insert_filename(hwnd, filename, 2, FALSE) && *filename) {
961 BldQuotedFileName(szfilename, filename);
962 WinSetDlgItemText(hwnd, CMD_CL, szfilename);
963 }
964 }
965 break;
966
967 case CMD_REORDER:
968 if (!cmdhead || !cmdhead->next) {
969 Runtime_Error(pszSrcFile, __LINE__, "no cmd");
970 break;
971 }
972 if (WinDlgBox(HWND_DESKTOP, hwnd, ReOrderProc, FM3ModHandle,
973 RE_FRAME, MPVOID)) {
974 WinSendDlgItemMsg(hwnd, CMD_LISTBOX, LM_DELETEALL, MPVOID, MPVOID);
975 WinSetDlgItemText(hwnd, CMD_CL, NullStr);
976 WinSetDlgItemText(hwnd, CMD_TITLE, NullStr);
977 info = cmdhead;
978 while (info) {
979 x = (SHORT) WinSendDlgItemMsg(hwnd,
980 CMD_LISTBOX,
981 LM_INSERTITEM,
982 MPFROM2SHORT(LIT_END, 0),
983 MPFROMP(info->title));
984 if (x >= 0)
985 WinSendDlgItemMsg(hwnd,
986 CMD_LISTBOX,
987 LM_SETITEMHANDLE,
988 MPFROMSHORT(x), MPFROMP(info));
989 info = info->next;
990 }
991 WinSendDlgItemMsg(hwnd,
992 CMD_LISTBOX,
993 LM_SELECTITEM, MPFROMSHORT(0), MPFROMSHORT(TRUE));
994 WinCheckButton(hwnd, CMD_DEFAULT, TRUE);
995 WinCheckButton(hwnd, CMD_PROMPT, FALSE);
996 WinCheckButton(hwnd, CMD_ONCE, FALSE);
997 save_commands();
998 }
999 break;
1000
1001 case DID_OK:
1002 {
1003 COMMAND *temp;
1004 BOOL fDontCheckHotKey = FALSE;
1005
1006 temp = xmallocz(sizeof(COMMAND), pszSrcFile, __LINE__);
1007 if (!temp)
1008 break; //already complained
1009 temp->pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
1010 if (!temp->pszCmdLine) {
1011 free (temp);
1012 break; //already complained
1013 }
1014 if (QueryCommandSettings(hwnd, temp)){
1015 if (temp->HotKeyID == 0)
1016 fDontCheckHotKey = TRUE;
1017 info = add_command(temp, fDontCheckHotKey);
1018 if (info == (LINKCMDS *) -1) {
1019 free(temp->pszCmdLine);
1020 free(temp);
1021 break;
1022 }
1023 }
1024 else {
1025 free(temp->pszCmdLine);
1026 free(temp);
1027 break;
1028 }
1029 free(temp->pszCmdLine);
1030 free(temp);
1031 save_commands();
1032 WinDismissDlg(hwnd, 0);
1033 break;
1034 }
1035
1036 case DID_CANCEL:
1037 WinDismissDlg(hwnd, 0);
1038 break;
1039
1040 case IDM_HELP:
1041 if (hwndHelp)
1042 WinSendMsg(hwndHelp,
1043 HM_DISPLAY_HELP,
1044 MPFROM2SHORT(HELP_COMMAND, 0), MPFROMSHORT(HM_RESOURCEID));
1045 break;
1046
1047 case CMD_ADD:
1048 {
1049 COMMAND *temp;
1050 BOOL fDontCheckHotKey = FALSE;
1051
1052 temp = xmallocz(sizeof(COMMAND), pszSrcFile, __LINE__);
1053 if (!temp)
1054 break; //already complained
1055 temp->pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
1056 if (!temp->pszCmdLine) {
1057 free (temp);
1058 break; //already complained
1059 }
1060 if (!QueryCommandSettings(hwnd, temp)) {
1061 free(temp->pszCmdLine);
1062 free(temp);
1063 break;
1064 }
1065 else {
1066 if (temp->HotKeyID == 0)
1067 fDontCheckHotKey = TRUE;
1068 info = add_command(temp, fDontCheckHotKey);
1069 if (!info) {
1070 saymsg(MB_ENTER, hwnd, GetPString(IDS_ERRORTEXT),
1071 GetPString(IDS_CANTADDCOMMANDTEXTDUP), temp->title);
1072 free(temp->pszCmdLine);
1073 free(temp);
1074 break;
1075 }
1076 if (info == (LINKCMDS *) -1) {
1077 free(temp->pszCmdLine);
1078 free(temp);
1079 break;
1080 }
1081 x = (SHORT) WinSendDlgItemMsg(hwnd,
1082 CMD_LISTBOX,
1083 LM_INSERTITEM,
1084 MPFROM2SHORT(LIT_END, 0),
1085 MPFROMP(temp->title));
1086 if (x >= 0) {
1087 WinSendDlgItemMsg(hwnd,
1088 CMD_LISTBOX,
1089 LM_SETITEMHANDLE,
1090 MPFROMSHORT(x), MPFROMP(info));
1091 WinSendDlgItemMsg(hwnd,
1092 CMD_LISTBOX,
1093 LM_SELECTITEM,
1094 MPFROMSHORT(x), MPFROMSHORT(TRUE));
1095 }
1096 save_commands();
1097 }
1098 free(temp->pszCmdLine);
1099 free(temp);
1100 break;
1101 }
1102
1103 case CMD_DELETE:
1104 {
1105 CHAR temp[100];
1106 CHAR key[120];
1107
1108 WinQueryDlgItemText(hwnd, CMD_TITLE, 100, temp);
1109 bstripcr(temp);
1110 if (!kill_command(temp))
1111 Runtime_Error(pszSrcFile, __LINE__, "kill_command");
1112 else {
1113 sprintf(key, "COMMAND.%sID", temp);
1114 PrfWriteProfileData(fmprof, FM3Str, key, NULL, 0);
1115 sprintf(key, "COMMAND.%sHotKeyID", temp);
1116 PrfWriteProfileData(fmprof, FM3Str, key, NULL, 0);
1117 sprintf(key, "COMMAND.%senv", temp);
1118 PrfWriteProfileData(fmprof, FM3Str, key, NULL, 0);
1119 sprintf(key, "COMMAND.%sflags", temp);
1120 PrfWriteProfileData(fmprof, FM3Str, key, NULL, 0);
1121 sprintf(key, "COMMAND.%sCmdLine", temp);
1122 PrfWriteProfileData(fmprof, FM3Str, key, NULL, 0);
1123 x = (SHORT) WinSendDlgItemMsg(hwnd,
1124 CMD_LISTBOX,
1125 LM_QUERYSELECTION,
1126 MPFROMSHORT(LIT_FIRST), MPVOID);
1127 if (x >= 0) {
1128 WinSendDlgItemMsg(hwnd,
1129 CMD_LISTBOX,
1130 LM_DELETEITEM, MPFROMSHORT(x), MPVOID);
1131 WinSendDlgItemMsg(hwnd,
1132 CMD_LISTBOX,
1133 LM_SELECTITEM,
1134 MPFROMSHORT(0), MPFROMSHORT(TRUE));
1135 }
1136 save_commands();
1137 }
1138 }
1139 break;
1140
1141 case CMD_REPLACE:
1142 {
1143 COMMAND *temp;
1144 CHAR keyID[120];
1145 CHAR keyHotKeyID[120];
1146 CHAR keyenv[120];
1147 INT ID = 0;
1148 INT HotKeyID = 0;
1149 ULONG size;
1150 BOOL fDontCheckHotKey = FALSE;
1151
1152 // Query the dialog
1153 temp = xmallocz(sizeof(COMMAND), pszSrcFile, __LINE__);
1154 if (!temp)
1155 break; //already complained
1156 temp->pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
1157 if (!temp->pszCmdLine) {
1158 free (temp);
1159 break; //already complained
1160 }
1161 if (!QueryCommandSettings(hwnd, temp)) {
1162 free(temp->pszCmdLine);
1163 free(temp);
1164 break;
1165 }
1166 //remember item location in the list
1167 y = (SHORT) WinSendDlgItemMsg(hwnd,
1168 CMD_LISTBOX,
1169 LM_QUERYSELECTION,
1170 MPFROMSHORT(LIT_CURSOR), MPVOID);
1171 //Delete
1172 sprintf(keyID, "COMMAND.%sID", temp->title);
1173 sprintf(keyHotKeyID, "COMMAND.%sHotKeyID", temp->title);
1174 sprintf(keyenv, "COMMAND.%senv", temp->title);
1175 PrfQueryProfileData(fmprof, FM3Str, keyID, &ID, &size);
1176 PrfQueryProfileData(fmprof, FM3Str, keyHotKeyID, &HotKeyID, &size);
1177 temp->ID = ID;
1178 if (temp->HotKeyID == HotKeyID || temp->HotKeyID == 0)
1179 fDontCheckHotKey = TRUE;
1180 if (kill_command(temp->title)) {
1181 PrfWriteProfileData(fmprof, FM3Str, keyID, NULL, 0);
1182 PrfWriteProfileData(fmprof, FM3Str, keyHotKeyID, NULL, 0);
1183 PrfWriteProfileString(fmprof, FM3Str, keyenv, NULL);
1184 x = (SHORT) WinSendDlgItemMsg(hwnd,
1185 CMD_LISTBOX,
1186 LM_QUERYSELECTION,
1187 MPFROMSHORT(LIT_FIRST), MPVOID);
1188 if (x >= 0) {
1189 WinSendDlgItemMsg(hwnd,
1190 CMD_LISTBOX,
1191 LM_DELETEITEM, MPFROMSHORT(x), MPVOID);
1192 WinSendDlgItemMsg(hwnd,
1193 CMD_LISTBOX,
1194 LM_SELECTITEM,
1195 MPFROMSHORT(LIT_NONE), MPFROMSHORT(FALSE));
1196 }
1197 } // then do an add
1198 info = add_command(temp, fDontCheckHotKey);
1199 if (!info || info == (LINKCMDS *) -1) {
1200 if (!info)
1201 saymsg(MB_ENTER, hwnd, GetPString(IDS_ERRORTEXT),
1202 GetPString(IDS_CANTADDCOMMANDTEXT),
1203 temp->title);
1204 }
1205 else {
1206 //put item back in original place
1207 x = (SHORT) WinSendDlgItemMsg(hwnd,
1208 CMD_LISTBOX,
1209 LM_INSERTITEM,
1210 MPFROM2SHORT(y, 0),
1211 MPFROMP(temp->title));
1212 if (x >= 0) {
1213 LINKCMDS *temphead = NULL,*last = NULL, *temptail = NULL;
1214 SHORT numitems, sSelect = 0;
1215
1216 WinSendDlgItemMsg(hwnd,
1217 CMD_LISTBOX,
1218 LM_SETITEMHANDLE,
1219 MPFROMSHORT(x), MPFROMP(info));
1220 WinSendDlgItemMsg(hwnd,
1221 CMD_LISTBOX,
1222 LM_SELECTITEM,
1223 MPFROMSHORT(x), MPFROMSHORT(TRUE));
1224 //then reorder
1225 numitems = (SHORT) WinSendDlgItemMsg(hwnd, CMD_LISTBOX,
1226 LM_QUERYITEMCOUNT,
1227 MPVOID, MPVOID);
1228
1229 while (numitems) {
1230
1231
1232 info = (LINKCMDS *) WinSendDlgItemMsg(hwnd, CMD_LISTBOX,
1233 LM_QUERYITEMHANDLE,
1234 MPFROMSHORT(sSelect++),
1235 MPVOID);
1236 if (info) {
1237 if (!temphead) {
1238 temphead = info;
1239 info->prev = NULL;
1240 }
1241 else {
1242 last->next = info;
1243 info->prev = last;
1244 }
1245 temptail = info;
1246 last = info;
1247 info->next = NULL;
1248 }
1249 numitems--;
1250 }
1251 cmdhead = temphead;
1252 cmdtail = temptail;
1253 save_commands();
1254 }
1255 }
1256 xfree(temp->pszCmdLine, pszSrcFile, __LINE__);
1257 xfree(temp, pszSrcFile, __LINE__);
1258 }
1259 break;
1260 }
1261 return 0;
1262 }
1263# ifdef FORTIFY
1264 Fortify_LeaveScope();
1265# endif
1266 return WinDefDlgProc(hwnd, msg, mp1, mp2);
1267}
1268
1269VOID RunCommand(HWND hwnd, INT cx)
1270{
1271 INT x;
1272 CHAR **list;
1273 LINKCMDS *info;
1274
1275 list = BuildList(hwnd);
1276 x = 0;
1277 info = cmdhead;
1278 while (info) {
1279 if (cx < 4300) {
1280 if (info->ID == cx)
1281 break;
1282 }
1283 else {
1284 if (info->HotKeyID == cx)
1285 break;
1286 }
1287 info = info->next;
1288 }
1289 if (info) {
1290
1291 INT flags;
1292
1293 x--;
1294 flags = info->flags;
1295 if (!(flags & FULLSCREEN))
1296 flags |= WINDOWED;
1297 if (flags & KEEP)
1298 flags |= SEPARATEKEEP;
1299 else
1300 flags |= SEPARATE;
1301 flags &= ~(KEEP | DIEAFTER);
1302 if (!strchr(info->pszCmdLine, '%')) {
1303 CHAR *fakelist[2];
1304
1305 *fakelist = "C";
1306 fakelist[1] = NULL;
1307 ExecOnList(hwnd,
1308 info->pszCmdLine,
1309 flags, NULL, info->env != NullStr ? info->env : NULL,
1310 fakelist, GetPString(IDS_EXECCMDTITLETEXT),
1311 pszSrcFile, __LINE__);
1312 }
1313 else if ((flags & ONCE) && list && list[0]) {
1314
1315 CHAR *fakelist[2];
1316 INT cntr;
1317
1318 flags &= (~ONCE);
1319 for (cntr = 0; list[cntr]; cntr++) {
1320 *fakelist = list[cntr];
1321 fakelist[1] = NULL;
1322 ExecOnList(hwnd,
1323 info->pszCmdLine,
1324 flags, NULL, info->env != NullStr ? info->env : NULL,
1325 fakelist, GetPString(IDS_EXECCMDTITLETEXT),
1326 pszSrcFile, __LINE__);
1327 }
1328 }
1329 else if (list && list[0])
1330 ExecOnList(hwnd,
1331 info->pszCmdLine,
1332 flags, NULL, info->env != NullStr ? info->env : NULL,
1333 list, GetPString(IDS_EXECCMDTITLETEXT),
1334 pszSrcFile, __LINE__);
1335 else
1336 return;
1337 }
1338 FreeList(list);
1339 DosPostEventSem(CompactSem);
1340}
1341
1342VOID EditCommands(HWND hwnd)
1343{
1344 static CHAR stop = 0;
1345
1346 if (stop)
1347 return;
1348 stop++;
1349 if (!cmdloaded)
1350 load_commands();
1351 WinDlgBox(HWND_DESKTOP,
1352 hwnd, CommandDlgProc, FM3ModHandle, CMD_FRAME, MPFROMP(&hwnd));
1353 stop = 0;
1354}
1355
1356#pragma alloc_text(COMMAND,command_title,free_commands,add_command,kill_command)
1357#pragma alloc_text(COMMAND,CommandDlgProc,EditCommands,ReOrderProc,CommandTextProc)
Note: See TracBrowser for help on using the repository browser.